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