4
from structs import unions, structs, defines;
6
# command line arguments
9
infiles = sys.argv[3:];
12
###########################################################################
13
# configuration #2: architecture information
20
inttypes["x86_32"] = {
21
"unsigned long" : "uint32_t",
23
"xen_pfn_t" : "uint32_t",
25
header["x86_32"] = """
26
#define __i386___X86_32 1
29
footer["x86_32"] = """
34
inttypes["x86_64"] = {
35
"unsigned long" : "__align8__ uint64_t",
36
"long" : "__align8__ uint64_t",
37
"xen_pfn_t" : "__align8__ uint64_t",
39
header["x86_64"] = """
40
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
41
# define __DECL_REG(name) union { uint64_t r ## name, e ## name; }
42
# define __align8__ __attribute__((aligned (8)))
44
# define __DECL_REG(name) uint64_t r ## name
45
# define __align8__ FIXME
47
#define __x86_64___X86_64 1
52
"unsigned long" : "__align8__ uint64_t",
53
"long" : "__align8__ uint64_t",
54
"xen_pfn_t" : "__align8__ uint64_t",
55
"long double" : "__align16__ ldouble_t",
58
#define __align8__ __attribute__((aligned (8)))
59
#define __align16__ __attribute__((aligned (16)))
60
typedef unsigned char ldouble_t[16];
64
###########################################################################
69
fileid = re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper());
71
# read input header files
80
* public xen defines and struct for %s
81
* generated by %s -- DO NOT EDIT
87
""" % (arch, sys.argv[0], fileid, fileid)
90
output += header[arch];
93
# add defines to output
94
for line in re.findall("#define[^\n]+", input):
95
for define in defines:
96
regex = "#define\s+%s\\b" % define;
97
match = re.search(regex, line);
100
if define.upper()[0] == define[0]:
101
replace = define + "_" + arch.upper();
103
replace = define + "_" + arch;
104
regex = "\\b%s\\b" % define;
105
output += re.sub(regex, replace, line) + "\n";
108
# delete defines, comments, empty lines
109
input = re.sub("#define[^\n]+\n", "", input);
110
input = re.compile("/\*(.*?)\*/", re.S).sub("", input)
111
input = re.compile("\n\s*\n", re.S).sub("\n", input);
113
# add unions to output
115
regex = "union\s+%s\s*\{(.*?)\n\};" % union;
116
match = re.search(regex, input, re.S)
118
output += "#define %s_has_no_%s 1\n" % (arch, union);
120
output += "union %s_%s {%s\n};\n" % (union, arch, match.group(1));
123
# add structs to output
124
for struct in structs:
125
regex = "struct\s+%s\s*\{(.*?)\n\};" % struct;
126
match = re.search(regex, input, re.S)
128
output += "#define %s_has_no_%s 1\n" % (arch, struct);
130
output += "struct %s_%s {%s\n};\n" % (struct, arch, match.group(1));
131
output += "typedef struct %s_%s %s_%s_t;\n" % (struct, arch, struct, arch);
136
output += footer[arch];
138
output += "#endif /* %s */\n" % fileid;
141
for define in defines:
142
if define.upper()[0] == define[0]:
143
replace = define + "_" + arch.upper();
145
replace = define + "_" + arch;
146
output = re.sub("\\b%s\\b" % define, replace, output);
150
output = re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, output);
152
# replace: structs + struct typedefs
153
for struct in structs:
154
output = re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, output);
155
output = re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output);
157
# replace: integer types
158
integers = inttypes[arch].keys();
159
integers.sort(lambda a, b: cmp(len(b),len(a)));
160
for type in integers:
161
output = re.sub("\\b%s\\b" % type, inttypes[arch][type], output);
164
f = open(outfile, "w");