add support for unions in sysv abi

This commit is contained in:
Quentin Carbonneaux 2016-08-16 13:26:16 -07:00
parent fbbb8e4d78
commit cad13d0dce
4 changed files with 67 additions and 40 deletions

View file

@ -8,6 +8,8 @@ type :st5 = { s, l }
type :st6 = { b 16 }
type :st7 = { s, d }
type :st8 = { w 4 }
type :un9 = { { b } { s } }
type :st9 = { w, :un9 }
data $fmt1 = { b "t1: %s\n", b 0 }
data $fmt2 = { b "t2: %d\n", b 0 }
@ -17,6 +19,7 @@ data $fmt5 = { b "t5: %f %lld\n", b 0 }
data $fmt6 = { b "t6: %s\n", b 0 }
data $fmt7 = { b "t7: %f %f\n", b 0 }
data $fmt8 = { b "t8: %d %d %d %d\n", b 0 }
data $fmt9 = { b "t9: %d %f\n", b 0 }
export
function $test() {
@ -68,6 +71,13 @@ function $test() {
%w84 =w loadw %r812
%i8 =w call $printf(l $fmt8, w %w81, w %w82, w %w83, w %w84)
%r9 =:st9 call $t9()
%r94 =l add 4, %r9
%w9 =w loadw %r9
%s9 =s loads %r94
%d9 =d exts %s9
%i9 =w call $printf(l $fmt9, w %w9, d %d9)
ret
}
@ -82,6 +92,7 @@ function $test() {
# typedef struct { char t[16]; } st6;
# typedef struct { float f; double d; } st7;
# typedef struct { int i[4]; } st8;
# typedef struct { int i; union { char c; float f; } u; } st9;
# extern void test(void);
# st1 t1() { return (st1){"abcdefghijklmnop"}; }
# st2 t2() { return (st2){2}; }
@ -91,6 +102,7 @@ function $test() {
# st6 t6() { return (st6){"abcdefghijklmno"}; }
# st7 t7() { return (st7){7.77,77.7}; }
# st8 t8() { return (st8){-8,88,-888,8888}; }
# st9 t9() { return (st9){9,{.f=9.9}}; }
# int main() { test(); return 0; }
# <<<
@ -103,4 +115,5 @@ function $test() {
# t6: abcdefghijklmno
# t7: 7.770000 77.700000
# t8: -8 88 -888 8888
# t9: 9 9.900000
# <<<