From 0f38c9398c21e756a834140fbe6f023de51ef527 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 6 Oct 2019 15:40:35 -0400 Subject: Add gen_code src files, with gen_label func implemented --- gen_code.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ gen_code.h | 10 ++++++++++ 2 files changed, 55 insertions(+) create mode 100644 gen_code.c create mode 100644 gen_code.h diff --git a/gen_code.c b/gen_code.c new file mode 100644 index 0000000..7471e8f --- /dev/null +++ b/gen_code.c @@ -0,0 +1,45 @@ +#include "gen_code.h" +#include "pc.h" + +int gen_label(t) +ptree *t; +{ + int tmp; + + if (!(t->l && t->r)) + return 0; + + if (t->l) { + tmp = gen_label(t->l); + t->l->label = (!tmp ? 1 : tmp); + } else + yyerror("GEN_LABEL: left child NULL, shouldn't happen!\n"); + + + if (t->r) + t->r->label = gen_label(t->r); + else + t->r->label = 0; + + + + + if (t->r->label == t->l->label) { + return 1 + t->l->label; + } else { + return t->r->label > t->l->label ? t->r->label : t->l->label; + } + +} + + +void gen_code(t) +ptree *t; +{ + /*Test gen_label*/ + if (t->type == ASSIGNOP){ + gen_label(t->r); + print_tree(t->r); + } +} + diff --git a/gen_code.h b/gen_code.h new file mode 100644 index 0000000..8c9ad00 --- /dev/null +++ b/gen_code.h @@ -0,0 +1,10 @@ +#ifndef GEN_CODEH +#define GEN_CODEH + +#include "tree.h" +void gen_code(ptree*); + +void gen_expr(ptree*); +void gen_statement(ptree*); + +#endif -- cgit v1.1