aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-10-08 22:25:04 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-10-08 22:34:00 -0400
commit3aedb2dba1343172ebca96ffd181c96cdaddd698 (patch)
tree96941f15bb2ddbbce4dc6fd5aed6a63c6512a3d2
parent57bc5ca2c7044658f446036cc5b75bf50de5bd24 (diff)
Fix gen_label/gen_expr for right leafs
-rw-r--r--gen_code.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/gen_code.c b/gen_code.c
index 52aac28..e967929 100644
--- a/gen_code.c
+++ b/gen_code.c
@@ -24,8 +24,10 @@ ptree *t;
{
int tmp;
- if (!(t->l && t->r))
+ if (!(t->l && t->r)) {
+ t->label = 0;
return 0;
+ }
if (t->l) {
tmp = gen_label(t->l);
@@ -56,9 +58,23 @@ ptree *t;
return;
}
+ if ((!t->r) && (!t->l) && t->label == 0){
+ switch (t->type) {
+ case ID:
+ fprintf(stdout, "mov\t%d(%%rbp), %s\n",
+ - t->attr.nval->offset * OFFSET_SIZE, *reg_ptr);
+ break;
+ case INUM:
+ fprintf(stdout, "mov\t$%d, %s\n",t->attr.ival, *reg_ptr);
+ break;
+ default:
+ fprintf(stdout, "mov OTHER");
+ }
+ }
/*case 0
* t is a left leaf*/
- if ((!t->r) && (!t->l) && t->label != 0) {
+ else if ((!t->r) && (!t->l) && t->label != 0) {
+ /*TODO check if correct*/
switch (t->type) {
case ID:
fprintf(stdout, "mov\t%s, %s\n",t->attr.nval->name, *reg_ptr);