From e96b0e885aecc66377fc020a74169ceaea450a38 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 9 Oct 2019 09:53:21 -0400 Subject: Fix save stack now resets reginster stack --- gen_code.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gen_code.c b/gen_code.c index e4f7936..45dbf6c 100644 --- a/gen_code.c +++ b/gen_code.c @@ -6,6 +6,9 @@ #include "pc.h" #include "scope.h" +char **stack_reg[1024]; +char ***reg_stack_save; + #define FLOAT_ERROR "Cannot produce code with reals\n" scope *cur_scope; @@ -40,6 +43,8 @@ int reg_cnt; "pushq\t%%r14\n"\ "pushq\t%%r15\n"\ );\ + *reg_stack_save = reg_ptr;\ + reg_stack_save++;\ } #define STACK_LOAD {\ @@ -58,6 +63,8 @@ int reg_cnt; "popq\t%%rcx\n"\ "popq\t%%rax\n"\ );\ + reg_stack_save--;\ + reg_ptr = *reg_stack_save;\ } int gen_label(t) @@ -404,6 +411,10 @@ char *name; reg_ptr = reg_stack; reg_cnt = 13; + reg_stack_save = stack_reg; + fprintf(stderr, "%p\n", reg_stack_save); + + fprintf(stdout, "\n.globl %s\n", name); fprintf(stdout, ".type %s, @function\n%s:\n", name, name); -- cgit v1.1