diff options
author | Nihal Jere <nihal@nihaljere.xyz> | 2024-04-27 14:47:15 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2024-04-27 15:34:03 -0700 |
commit | 4f206ac1ea1b20400fa242f2f3be86237c4ba3bf (patch) | |
tree | 2dc2742c051e6601874fc699265da40fd51bd5e5 /test/vla-nested.qbe | |
parent | 487079af3d6f39b379f52f7e0ea6edec63587e5b (diff) |
Implement variable length arrays
Variably modified types are required for C23.
Since QBE doesn't currently support saving and restoring the stack
pointer, a current limitation is that we can't reclaim stack space
from VLAs that go out of scope. This is potentially problematic for
VLAs appearing in a loop, but this case is uncommon enough that it
is silently ignored for now.
Implements: https://todo.sr.ht/~mcf/cproc/1
References: https://todo.sr.ht/~mcf/cproc/88
Co-authored-by: Michael Forney <mforney@mforney.org>
Diffstat (limited to 'test/vla-nested.qbe')
-rw-r--r-- | test/vla-nested.qbe | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/vla-nested.qbe b/test/vla-nested.qbe new file mode 100644 index 0000000..b01c24c --- /dev/null +++ b/test/vla-nested.qbe @@ -0,0 +1,44 @@ +export +function w $f(w %.1) { +@start.1 + %.2 =l alloc4 4 + storew %.1, %.2 +@body.2 + %.3 =w loadw $l + %.4 =w loadw %.2 + %.5 =w add %.3, %.4 + storew %.5, $l + %.6 =w loadw %.2 + ret %.6 +} +export +function w $main() { +@start.3 + %.1 =l alloc4 4 +@body.4 + storew 0, %.1 + %.2 =w call $f(w 3) + %.3 =l extsw %.2 + %.4 =l mul %.3, 4 + %.5 =w call $f(w 2) + %.6 =l extsw %.5 + %.7 =l mul %.6, 8 + %.8 =l alloc8 %.7 + %.9 =w loadw %.1 + %.10 =w loadw $l + %.11 =w cnew %.10, 5 + %.12 =w add %.9, %.11 + storew %.12, %.1 + %.13 =w loadw %.1 + %.14 =w cnel %.7, 16 + %.15 =w add %.13, %.14 + storew %.15, %.1 + %.16 =w loadw %.1 + %.17 =l loadl %.8 + %.18 =w cnel %.4, 12 + %.19 =w add %.16, %.18 + storew %.19, %.1 + %.20 =w loadw %.1 + ret %.20 +} +export data $l = align 4 { z 4 } |