aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-10-09 09:53:21 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-10-09 09:53:21 -0400
commite96b0e885aecc66377fc020a74169ceaea450a38 (patch)
tree5783660741ebbabcf8042db1675aa111aba1356c
parent13fbc5bf019d635926f1a49ff70843897375eee1 (diff)
Fix save stack now resets reginster stack
-rw-r--r--gen_code.c11
1 files changed, 11 insertions, 0 deletions
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);