qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

abi5.ssa (3496B)


      1 # returning structs from C
      2 
      3 type :st1 = { b 17 }
      4 type :st2 = { w }
      5 type :st3 = { s, w }
      6 type :st4 = { w, d }
      7 type :st5 = { s, l }
      8 type :st6 = { b 16 }
      9 type :st7 = { s, d }
     10 type :st8 = { w 4 }
     11 type :un9 = { { b } { s } }
     12 type :st9 = { w, :un9 }
     13 type :sta = { b, s }
     14 type :stb = { b, b, s }
     15 
     16 data $fmt1 = { b "t1: %s\n", b 0 }
     17 data $fmt2 = { b "t2: %d\n", b 0 }
     18 data $fmt3 = { b "t3: %f %d\n", b 0 }
     19 data $fmt4 = { b "t4: %d %f\n", b 0 }
     20 data $fmt5 = { b "t5: %f %lld\n", b 0 }
     21 data $fmt6 = { b "t6: %s\n", b 0 }
     22 data $fmt7 = { b "t7: %f %f\n", b 0 }
     23 data $fmt8 = { b "t8: %d %d %d %d\n", b 0 }
     24 data $fmt9 = { b "t9: %d %f\n", b 0 }
     25 data $fmta = { b "ta: %d %f\n", b 0 }
     26 data $fmtb = { b "tb: %d %d %f\n", b 0 }
     27 
     28 export
     29 function $test() {
     30 @start
     31 	%r1 =:st1 call $t1()
     32 	%i1 =w call $printf(l $fmt1, ..., l %r1)
     33 
     34 	%r2 =:st2 call $t2()
     35 	%w2 =w loadw %r2
     36 	%i2 =w call $printf(l $fmt2, ..., w %w2)
     37 
     38 	%r3 =:st3 call $t3()
     39 	%s3 =s loads %r3
     40 	%r34 =l add %r3, 4
     41 	%w3 =w loadw %r34
     42 	%p3 =d exts %s3
     43 	%i3 =w call $printf(l $fmt3, ..., d %p3, w %w3)
     44 
     45 	%r4 =:st4 call $t4()
     46 	%w4 =w loadw %r4
     47 	%r48 =l add 8, %r4
     48 	%d4 =d loadd %r48
     49 	%i4 =w call $printf(l $fmt4, ..., w %w4, d %d4)
     50 
     51 	%r5 =:st5 call $t5()
     52 	%s5 =s loads %r5
     53 	%d5 =d exts %s5
     54 	%r58 =l add %r5, 8
     55 	%l5 =l loadl %r58
     56 	%i5 =w call $printf(l $fmt5, ..., d %d5, l %l5)
     57 
     58 	%r6 =:st6 call $t6()
     59 	%i6 =w call $printf(l $fmt6, ..., l %r6)
     60 
     61 	%r7 =:st7 call $t7()
     62 	%s7 =s loads %r7
     63 	%d71 =d exts %s7
     64 	%r78 =l add %r7, 8
     65 	%d72 =d loadd %r78
     66 	%i7 =w call $printf(l $fmt7, ..., d %d71, d %d72)
     67 
     68 	%r8 =:st8 call $t8()
     69 	%r84 =l add 4, %r8
     70 	%r88 =l add 4, %r84
     71 	%r812 =l add 4, %r88
     72 	%w81 =w loadw %r8
     73 	%w82 =w loadw %r84
     74 	%w83 =w loadw %r88
     75 	%w84 =w loadw %r812
     76 	%i8 =w call $printf(l $fmt8, ..., w %w81, w %w82, w %w83, w %w84)
     77 
     78 	%r9 =:st9 call $t9()
     79 	%r94 =l add 4, %r9
     80 	%w9 =w loadw %r9
     81 	%s9 =s loads %r94
     82 	%d9 =d exts %s9
     83 	%i9 =w call $printf(l $fmt9, ..., w %w9, d %d9)
     84 
     85 	%ra =:sta call $ta()
     86 	%ra4 =l add 4, %ra
     87 	%wa =w loadsb %ra
     88 	%sa =s loads %ra4
     89 	%da =d exts %sa
     90 	%ia =w call $printf(l $fmta, ..., w %wa, d %da)
     91 
     92 	%rb =:stb call $tb()
     93 	%rb1 =l add 1, %rb
     94 	%rb4 =l add 4, %rb
     95 	%w0b =w loadsb %rb
     96 	%w1b =w loadsb %rb1
     97 	%sb =s loads %rb4
     98 	%db =d exts %sb
     99 	%ib =w call $printf(l $fmtb, ..., w %w0b, w %w1b, d %db)
    100 
    101 	ret
    102 }
    103 
    104 
    105 # >>> driver
    106 # typedef struct { char t[17]; } st1;
    107 # typedef struct { int i; } st2;
    108 # typedef struct { float f; int i; } st3;
    109 # typedef struct { int i; double d; } st4;
    110 # typedef struct { float f; long l; } st5;
    111 # typedef struct { char t[16]; } st6;
    112 # typedef struct { float f; double d; } st7;
    113 # typedef struct { int i[4]; } st8;
    114 # typedef struct { int i; union { char c; float f; } u; } st9;
    115 # typedef struct { char c; float f; } sta;
    116 # typedef struct { char c0, c1; float f; } stb;
    117 # extern void test(void);
    118 # st1 t1() { return (st1){"abcdefghijklmnop"}; }
    119 # st2 t2() { return (st2){2}; }
    120 # st3 t3() { return (st3){3.0,30}; }
    121 # st4 t4() { return (st4){4,-40}; }
    122 # st5 t5() { return (st5){5.5,-55}; }
    123 # st6 t6() { return (st6){"abcdefghijklmno"}; }
    124 # st7 t7() { return (st7){7.77,77.7}; }
    125 # st8 t8() { return (st8){-8,88,-888,8888}; }
    126 # st9 t9() { return (st9){9,{.f=9.9}}; }
    127 # sta ta() { return (sta){-10,10.1}; }
    128 # stb tb() { return (stb){-1,11,11.11}; }
    129 # int main() { test(); return 0; }
    130 # <<<
    131 
    132 # >>> output
    133 # t1: abcdefghijklmnop
    134 # t2: 2
    135 # t3: 3.000000 30
    136 # t4: 4 -40.000000
    137 # t5: 5.500000 -55
    138 # t6: abcdefghijklmno
    139 # t7: 7.770000 77.700000
    140 # t8: -8 88 -888 8888
    141 # t9: 9 9.900000
    142 # ta: -10 10.100000
    143 # tb: -1 11 11.110000
    144 # <<<