mkchecker.py revision 183375
1#!/usr/bin/python
2
3import sys;
4from structs import structs;
5
6# command line arguments
7arch    = sys.argv[1];
8outfile = sys.argv[2];
9archs   = sys.argv[3:];
10
11f = open(outfile, "w");
12f.write('''
13/*
14 * sanity checks for generated foreign headers:
15 *  - verify struct sizes
16 *
17 * generated by %s -- DO NOT EDIT
18 */
19#include <stdio.h>
20#include <stdlib.h>
21#include <stddef.h>
22#include <inttypes.h>
23#include "../xen.h"
24''');
25
26for a in archs:
27    f.write('#include "%s.h"\n' % a);
28
29f.write('int main(int argc, char *argv[])\n{\n');
30
31f.write('\tprintf("\\n");');
32f.write('printf("%-25s |", "structs");\n');
33for a in archs:
34    f.write('\tprintf("%%8s", "%s");\n' % a);
35f.write('\tprintf("\\n");');
36
37f.write('\tprintf("\\n");');
38for struct in structs:
39    f.write('\tprintf("%%-25s |", "%s");\n' % struct);
40    for a in archs:
41        if a == arch:
42            s = struct; # native
43        else:
44            s = struct + "_" + a;
45        f.write('#ifdef %s_has_no_%s\n' % (a, struct));
46        f.write('\tprintf("%8s", "-");\n');
47        f.write("#else\n");
48        f.write('\tprintf("%%8zd", sizeof(struct %s));\n' % s);
49        f.write("#endif\n");
50
51    f.write('\tprintf("\\n");\n\n');
52
53f.write('\tprintf("\\n");\n');
54f.write('\texit(0);\n');
55f.write('}\n');
56
57f.close();
58
59