forked from linux-rdma/rdma-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibtypes.py
61 lines (55 loc) · 1.85 KB
/
ibtypes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import re
import sys
def global_ln(ln):
g = re.match(r"^#define\s+(\S+)\s+CL_HTON(\d+)\((.*)\)",ln)
if g:
print("#define %s htobe%s(%s)"%(g.group(1),g.group(2),g.group(3)))
return global_ln
g = re.match(r"^#define\s+(\S+)\s+\(CL_HTON(\d+)\((.*)\)\)",ln)
if g:
print("#define %s htobe%s(%s)"%(g.group(1),g.group(2),g.group(3)))
return global_ln
g = re.match(r"^#define\s+(\S+)\s+(0x\w+)",ln)
if g:
print("#define %s %s"%(g.group(1),g.group(2)))
return global_ln
g = re.match(r"^#define\s+(\S+)\s+\((0x\w+)\)",ln)
if g:
print("#define %s %s"%(g.group(1),g.group(2)))
return global_ln
g = re.match(r"^#define\s+(\S+)\s+(\d+)",ln)
if g:
print("#define %s %s"%(g.group(1),g.group(2)))
return global_ln
g = re.match(r"^#define\s+(\S+)\s+\((\d+)\)",ln)
if g:
print("#define %s %s"%(g.group(1),g.group(2)))
return global_ln
g = re.match(r"^typedef\s+(union|struct)\s+_\S+\s+{",ln);
if g:
print("typedef %s {"%(g.group(1)));
return in_struct;
print(ln,file=FO);
return global_ln
def in_struct(ln):
g = re.match(r"^}\s+PACK_SUFFIX\s+(\S+);",ln);
if g:
print("} __attribute__((packed)) %s;"%(g.group(1)));
return global_ln;
g = re.match(r"^}\s+(\S+);",ln);
if g:
print("} %s;"%(g.group(1)));
return global_ln;
ln = ln.replace("PACK_SUFFIX","__attribute__((packed))");
ln = ln.replace("ib_gid_prefix_t","__be64");
ln = ln.replace("ib_net64_t","__be64");
ln = ln.replace("ib_net32_t","__be32");
ln = ln.replace("ib_net16_t","__be16");
ln = ln.replace("boolean_t","bool");
print(ln)
return in_struct;
mode = global_ln
with open(sys.argv[1]) as FI, open(sys.argv[2],"wt") as FO:
for ln in FI:
ln = ln.rstrip();
mode = mode(ln);