diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-07 23:59:11 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-08 22:33:49 -0400 |
commit | e11eda53660f19bcbcede3bb25b09a71363cef21 (patch) | |
tree | ef8eb830df6620bbf0a5c29b4ae643ef6d3ed1e1 | |
parent | eee77999764131bd35ce2c471d32cd0b6e85f598 (diff) |
Add scope based stack offsets for variables
-rw-r--r-- | gen_code.c | 3 | ||||
-rw-r--r-- | node.h | 1 | ||||
-rw-r--r-- | pc.h | 2 | ||||
-rw-r--r-- | pc.y | 2 | ||||
-rw-r--r-- | scope.c | 2 | ||||
-rw-r--r-- | scope.h | 1 |
6 files changed, 10 insertions, 1 deletions
@@ -123,7 +123,8 @@ ptree *t; switch (t->type){ case ASSIGNOP: if (t->l->ret_type == INT) { - fprintf(stderr, "ASSIGN (INT) %s\n", t->l->attr.nval->name); + GEN_EXPR(t->r); + fprintf(stdout, "mov %s, ADDR\n", *reg_ptr); } else { fprintf(stderr, "ASSIGN (REAL) %s\n", t->l->attr.nval->name); } @@ -17,6 +17,7 @@ typedef struct node_s { char *name; struct node_s *next; int var_type; + int offset; struct fi* func_info; struct ai* array_info; @@ -13,5 +13,7 @@ int yyerror(char*); int count_args(ptree*); int set_func_types(ptree*, int*, int); int get_call_types(ptree*, int*, int); + +#define OFFSET_SIZE 8 #endif @@ -133,6 +133,7 @@ id_list check_id(cur_scope, $1); tmp = scope_insert(cur_scope, $1); + tmp->offset = cur_scope->offset++; $$ = mkid(tmp); } |id_list ',' ID @@ -141,6 +142,7 @@ id_list check_id(cur_scope, $3); tmp = scope_insert(cur_scope, $3); + tmp->offset = cur_scope->offset++; $$ = mktree(LIST, $1, mkid(tmp)); } ; @@ -21,6 +21,8 @@ scope* mkscope() p->prev = NULL; p->ret_var= NULL; + p->offset = 2; + return p; } @@ -9,6 +9,7 @@ typedef struct hash { node* table[HASH_SIZE]; struct hash *prev; node* ret_var; + int offset; } scope; scope* mkscope(); |