From 3aedb2dba1343172ebca96ffd181c96cdaddd698 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Tue, 8 Oct 2019 22:25:04 -0400 Subject: Fix gen_label/gen_expr for right leafs --- gen_code.c | 20 ++++++++++++++++++-- 1 file 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); -- cgit v1.1