commit f5ad580886b2fd759c9d1790268964b3399ee3e2
parent c8cd2824eae0137505fe46530c3a8e9788ab9a63
Author: Quentin Carbonneaux <quentin@c9x.me>
Date: Fri, 26 Aug 2022 10:15:33 +0200
regenerate test/vararg2.ssa
- update the test generation script to
match some manual changes
- fix some variadic calls to printf
- add a test case where an odd number of
slots is used on the stack before varargs
Diffstat:
2 files changed, 98 insertions(+), 10 deletions(-)
diff --git a/test/vararg2.ssa b/test/vararg2.ssa
@@ -278,6 +278,46 @@ export function $qbecall6(w %argw0, w %argw1, w %argw2, w %argw3, w %argw4, w %a
ret
}
+export function $qbeprint7(w %argw0, w %argw1, w %argw2, w %argw3, w %argw4, w %argw5, w %argw6, w %argw7, w %argw8, l %fmt, ...) {
+@start
+ %fmtdbl =l alloc4 4
+ %fmtint =l alloc4 4
+ %emptys =l alloc4 4
+ storew 2122789, %fmtint
+ storew 2123557, %fmtdbl
+ storew 0, %emptys
+ %vp =l alloc8 32
+ %fmt1 =l add 1, %fmt
+ vastart %vp
+@loop
+ %p =l phi @start %fmt1, @casef %p1, @cased %p1
+ %c =w loadsb %p
+ %p1 =l add 3, %p
+ jnz %c, @loop1, @end
+@loop1
+ %isg =w ceqw %c, 103
+ jnz %isg, @casef, @cased
+@casef
+ %dbl =d vaarg %vp
+ %r =w call $printf(l %fmtdbl, ..., d %dbl)
+ jmp @loop
+@cased
+ %int =w vaarg %vp
+ %r =w call $printf(l %fmtint, ..., w %int)
+ jmp @loop
+@end
+ %r =w call $puts(l %emptys)
+ ret
+}
+
+export function $qbecall7(w %argw0, w %argw1, w %argw2, w %argw3, w %argw4, w %argw5, w %argw6, w %argw7, w %argw8, l %fmt, ...) {
+@start
+ %vp =l alloc8 32
+ vastart %vp
+ %r =w call $print(l %fmt, l %vp)
+ ret
+}
+
# >>> driver
# #include <stdarg.h>
# #include <stdio.h>
@@ -295,8 +335,10 @@ export function $qbecall6(w %argw0, w %argw1, w %argw2, w %argw3, w %argw4, w %a
# extern void qbecall5(int argw0, int argw1, int argw2, int argw3, int argw4, double argd0, double argd1, double argd2, double argd3, double argd4, double argd5, double argd6, char *, ...);
# extern void qbeprint6(int argw0, int argw1, int argw2, int argw3, int argw4, int argw5, int argw6, int argw7, int argw8, int argw9, double argd0, double argd1, double argd2, double argd3, double argd4, double argd5, double argd6, double argd7, double argd8, double argd9, char *, ...);
# extern void qbecall6(int argw0, int argw1, int argw2, int argw3, int argw4, int argw5, int argw6, int argw7, int argw8, int argw9, double argd0, double argd1, double argd2, double argd3, double argd4, double argd5, double argd6, double argd7, double argd8, double argd9, char *, ...);
-# int print(const char *fmt, va_list *ap) {
-# return vprintf(fmt, *ap);
+# extern void qbeprint7(int argw0, int argw1, int argw2, int argw3, int argw4, int argw5, int argw6, int argw7, int argw8, char *, ...);
+# extern void qbecall7(int argw0, int argw1, int argw2, int argw3, int argw4, int argw5, int argw6, int argw7, int argw8, char *, ...);
+# int print(char *fmt, va_list *ap) {
+# return vprintf(fmt, *ap);
# }
# int main() {
# puts("# (0 int, 0 double)");
@@ -446,6 +488,27 @@ export function $qbecall6(w %argw0, w %argw1, w %argw2, w %argw3, w %argw4, w %a
# qbecall6(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %d %g %g \n", -2, -1, 4.582, 3.467);
# qbeprint6(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "\n");
# qbecall6(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "\n");
+# puts("# (9 int, 0 double)");
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d \n", 10);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d \n", 10);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g \n", -8.032);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g \n", -8.032);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %g \n", -2, -3.214);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %g \n", -2, -3.214);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g %g \n", 7.233, -5.027);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g %g \n", 7.233, -5.027);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %d %d %d \n", -7, -1, -2, -5);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %d %d %d \n", -7, -1, -2, -5);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g %g %g %g \n", -5.004, 8.465, -1.137, 7.227);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g %g %g %g \n", -5.004, 8.465, -1.137, 7.227);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %g %d %g \n", 1, -8.988, 10, 6.721);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %g %d %g \n", 1, -8.988, 10, 6.721);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g %g %d %d \n", 9.38, 8.527, 7, -7);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%g %g %d %d \n", 9.38, 8.527, 7, -7);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %d %g %g \n", 0, -6, -1.979, -8.827);
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "%d %d %g %g \n", 0, -6, -1.979, -8.827);
+# qbeprint7(0, 0, 0, 0, 0, 0, 0, 0, 0, "\n");
+# qbecall7(0, 0, 0, 0, 0, 0, 0, 0, 0, "\n");
# }
# <<<
@@ -597,4 +660,25 @@ export function $qbecall6(w %argw0, w %argw1, w %argw2, w %argw3, w %argw4, w %a
# -2 -1 4.582 3.467
#
#
+# # (9 int, 0 double)
+# 10
+# 10
+# -8.032
+# -8.032
+# -2 -3.214
+# -2 -3.214
+# 7.233 -5.027
+# 7.233 -5.027
+# -7 -1 -2 -5
+# -7 -1 -2 -5
+# -5.004 8.465 -1.137 7.227
+# -5.004 8.465 -1.137 7.227
+# 1 -8.988 10 6.721
+# 1 -8.988 10 6.721
+# 9.38 8.527 7 -7
+# 9.38 8.527 7 -7
+# 0 -6 -1.979 -8.827
+# 0 -6 -1.979 -8.827
+#
+#
# <<<
diff --git a/tools/vatest.py b/tools/vatest.py
@@ -7,7 +7,7 @@ from struct import unpack
I, D = 'd', 'g'
formats = [
- # list of format to tests
+ # list of formats to test
[I],
[D],
[I,D],
@@ -25,7 +25,7 @@ generate = [
# floating point arguments to
# test
(0, 0), (1, 0), (0, 1), (4, 0),
- (0, 6), (5, 7), (10, 10),
+ (0, 6), (5, 7), (10, 10), (9, 0),
]
def mkargs(nargs, type, name):
@@ -63,6 +63,7 @@ def genssa(qbeprint, qbecall):
def gendriver():
print('# >>> driver')
+ print('# #include <stdarg.h>')
print('# #include <stdio.h>')
for fnum, (nia, nfa) in enumerate(generate):
@@ -76,6 +77,9 @@ def gendriver():
)
output = ''
+ print('# int print(char *fmt, va_list *ap) {')
+ print('# return vprintf(fmt, *ap);');
+ print('# }')
print('# int main() {')
for fnum, (nia, nfa) in enumerate(generate):
@@ -113,7 +117,7 @@ qbeprint="""{{
storew {}, %fmtint
storew {}, %fmtdbl
storew 0, %emptys
- %vp =l alloc8 24
+ %vp =l alloc8 32
%fmt1 =l add 1, %fmt
vastart %vp
@loop
@@ -126,14 +130,14 @@ qbeprint="""{{
jnz %isg, @casef, @cased
@casef
%dbl =d vaarg %vp
- call $printf(l %fmtdbl, d %dbl, ...)
+ %r =w call $printf(l %fmtdbl, ..., d %dbl)
jmp @loop
@cased
%int =w vaarg %vp
- call $printf(l %fmtint, w %int, ...)
+ %r =w call $printf(l %fmtint, ..., w %int)
jmp @loop
@end
- call $puts(l %emptys)
+ %r =w call $puts(l %emptys)
ret
}}
""".format(
@@ -143,9 +147,9 @@ qbeprint="""{{
qbecall="""{
@start
- %vp =l alloc8 24
+ %vp =l alloc8 32
vastart %vp
- call $vprintf(l %fmt, l %vp)
+ %r =w call $print(l %fmt, l %vp)
ret
}
"""