aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ir_stack.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-03-17 13:22:00 +0100
committerlemon <lsof@mailbox.org>2026-03-17 13:22:00 +0100
commita8d6f8bf30c07edb775e56889f568ca20240bedf (patch)
treeb5a452b2675b2400f15013617291fe6061180bbf /src/ir_stack.c
parent24f14b7ad1af08d872971d72ce089a529911f657 (diff)
REFACTOR: move sources to src/
Diffstat (limited to 'src/ir_stack.c')
-rw-r--r--src/ir_stack.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/ir_stack.c b/src/ir_stack.c
new file mode 100644
index 0000000..40a7b1d
--- /dev/null
+++ b/src/ir_stack.c
@@ -0,0 +1,33 @@
+#include "ir.h"
+
+void
+lowerstack(struct function *fn)
+{
+ fn->stksiz = 0;
+ FREQUIRE(FNUSE);
+
+ struct block *blk = fn->entry;
+ do {
+ for (int i = 0; i < blk->ins.n; ++i) {
+ int t = blk->ins.p[i];
+ struct instr *ins = &instrtab[t];
+ if (oisalloca(ins->op)) {
+ uint alignlog2 = ins->op - Oalloca1;
+ assert(ins->l.i > 0);
+ uint siz = ins->l.i << alignlog2;
+ fn->stksiz += siz;
+ fn->stksiz = alignup(fn->stksiz, 1 << alignlog2);
+ if (fn->stksiz > (1<<20)-1) error(NULL, "'%s' stack frame too big", fn->name);
+ *ins = mkinstr(Onop,0,);
+ replcuses(mkref(RTMP, t), mkref(RSTACK, fn->stksiz));
+ }
+ }
+ } while ((blk = blk->lnext) != fn->entry);
+
+ if (ccopt.dbg.s) {
+ bfmt(ccopt.dbgout, "<< After stack >>\n");
+ irdump(fn);
+ }
+}
+
+/* vim:set ts=3 sw=3 expandtab: */