From ef25180600e74dfe1453ab4dbd68df43c11688a6 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 6 Oct 2019 21:35:04 -0400 Subject: Add gen_statement base code to code generation --- gen_code.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/gen_code.c b/gen_code.c index 22d1e76..30975f0 100644 --- a/gen_code.c +++ b/gen_code.c @@ -1,3 +1,4 @@ +#include #include "gen_code.h" #include "pc.h" @@ -37,13 +38,45 @@ ptree *t; { } -void gen_code(t, name) +void gen_statement(t) ptree *t; { - /*Test gen_label*/ - if (t->type == ASSIGNOP){ - gen_label(t->r); - print_tree(t->r); + char buf[100]; + + if (!t) + return; + + switch (t->type){ + case ASSIGNOP: + + break; + case PCALL: + + break; + case LIST: + + break; + case IF: + + break; + case WHILE: + + break; + + case FOR: + break; + default: + snprintf(buf, 100, "Unknown statement type: %d\n", t->type); + yyerror(buf); } } +void gen_code(t, name) +ptree *t; +char *name; +{ + printf("\n.globl %s\n.type %s, @function\n%s:\n", name, name, name); + + /*TODO call gen_statement on all statements in LIST t*/ + /*Look at set_type for list traverseal code*/ +} -- cgit v1.1