From 1fc88ae00940e04ee76cbdf13a5df429faf72451 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 24 Jan 2018 23:00:31 +0100 Subject: Also do the BP dance if no spills occur This is because arguments are annoyingly generated relative to BP, which fails completely if the stack frame is not set up nicely. TODO do stuff relative to SP so BP is just a general purpose register. --- to_assembly.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'to_assembly.c') diff --git a/to_assembly.c b/to_assembly.c index bd680b3..6f40e2d 100644 --- a/to_assembly.c +++ b/to_assembly.c @@ -81,13 +81,18 @@ static void fix_function(struct ir *ir, int startidx, struct allocation *ral) { } free(offsets); - - if (spillspace == 0) return; + + // TODO: Really, nothing should be relative to BP, instead everything should use SP. That + // would completely eliminate this BP dance anyway. + + // if (spillspace == 0) return; ir_insert_before(ir, startidx + 0, irins_make_1(INS_PUSH, ref_reg(REG_BP))); ir_insert_before(ir, startidx + 1, irins_make_01(INS_MOV, ref_reg(REG_BP), ref_reg(REG_SP))); - ir_insert_before(ir, startidx + 2, - irins_make_012(INS_SUB, ref_reg(REG_SP), ref_reg(REG_SP), ref_imm(spillspace))); + if (spillspace != 0) { + ir_insert_before(ir, startidx + 2, + irins_make_012(INS_SUB, ref_reg(REG_SP), ref_reg(REG_SP), ref_imm(spillspace))); + } for (int idx = startidx + 1; idx < ir->len; idx++) { struct irins *ins = ir->inss[idx]; -- cgit v1.2.3-54-g00ecf