3 # support script to create
7 if arg
[0] == 'p': return ctype(arg
[1:])
8 if arg
[0] == ':': return 'S' + arg
[1:]
9 return {'w':'int', 'l':'long',
10 's':'float', 'd':'double'}[arg
]
13 return ctype(iarg
[1]) + ' p' + str(iarg
[0])
16 out
= '# extern void qfn' + id + '('
17 out
+= ', '.join(map(ctype
, args
)) + ');\n'
18 out
+= '# void cfn' + id + '('
19 out
+= ', '.join(map(cparam
, enumerate(args
)))
21 out
+= '# \tprintf("qbe->c(%d)", ' + id + ');\n'
23 for (i
, arg
) in enumerate(args
):
24 if arg
[0] != 'p': continue
27 out
+= 'p' + ty
[1:] + '(&'
30 out
+= 'p' + str(i
) + '); '
32 out
+= '# \tqfn' + id + '('
33 out
+= ', '.join('p'+str(i
) for i
in range(len(args
)))
39 ty
= iarg
[1][1:] if iarg
[1][0] == 'p' else iarg
[1]
40 return ty
+ ' %p' + str(iarg
[0])
43 out
= 'export\nfunction $qfn' + id + '('
44 out
+= ', '.join(map(qparam
, enumerate(args
)))
47 out
+= '\t%r0 =w call $printf(l $ctoqbestr, w ' + id + ')\n'
48 for (i
, arg
) in enumerate(args
):
49 if arg
[0] != 'p': continue
52 out
+= '\tcall $p' + ty
[1:]
53 out
+= '(l %p' + str(i
) + ')\n'
55 out
+= '\tcall $p' + ty
56 out
+= '(' + ty
+ ' %p' + str(i
) + ')\n'
57 out
+= '\t%r1 =w call $puts(l $emptystr)\n'
65 ty
= arg
if not print else arg
[1:]
68 return ty
+ ' $' + ty
[1:]
70 return ty
+ ' $z' + ty
[1:]
73 if ty
== 'w' or ty
== 'l':
74 return ty
+ ' ' + str(i
+1)
75 if ty
== 's' or ty
== 'd':
76 flt
= str(i
+1) + '.' + str(i
+1)
77 return ty
+ ' ' + ty
+ '_' + flt
79 def genmaincall(id, args
):
80 out
= '\tcall $cfn' + id + '('
81 out
+= ', '.join(map(carg
, enumerate(args
)))
86 for i
, t
in enumerate(tvec
):
87 print(genqfn(str(i
), t
), end
='')
89 for i
, t
in enumerate(tvec
):
90 print(genmaincall(str(i
), t
), end
='')
92 for i
, t
in enumerate(tvec
):
93 print(gencfn(str(i
), t
), end
='')
97 ['pw', 'ps', 'p:fi1'],
98 ['pw', 'p:fi2', 'ps'],
99 ['pw', 'ps', 'p:fi3'],
101 ['d']*7 + ['p:ss', 'ps', 'pl'],
106 ['w']*8 + ['p:big', 'ps', 'pl'],
109 if __name__
== '__main__':