From 01406ad25ff49d5c5f722f34187d2063cefea5ed Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 6 Jun 2018 14:14:55 +0200 Subject: require main func and rename tests --- src/generator.c | 5 ++++- src/generator.h | 2 +- src/tpc.y | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/generator.c b/src/generator.c index bb95e08..44fdeab 100644 --- a/src/generator.c +++ b/src/generator.c @@ -79,7 +79,7 @@ void gen_prologue_continue(int *bss_done) { *bss_done = 1; } -void gen_const_declaration() { +void gen_epilogue() { fprintf(output, "\n_start:\n"); fprintf(output, "push rbp\nmov rbp, rsp\n\n"); fprintf(output, "call main\n"); @@ -92,6 +92,9 @@ void gen_const_declaration() { loc_display_table(); fprintf(output, ";function table\n"); fun_display_table(); + + // require a main function + fun_lookup("main", 0); } void gen_const(const char name[], int value, Scope scope) { diff --git a/src/generator.h b/src/generator.h index 20a83f9..9d6dd65 100644 --- a/src/generator.h +++ b/src/generator.h @@ -16,7 +16,7 @@ FILE *output; void gen_prologue(); void gen_prologue_continue(int *bss_done); -void gen_const_declaration(); +void gen_epilogue(); void gen_const(const char name[], int value, Scope scope); Type gen_function_declaration(const char name[], int return_type); diff --git a/src/tpc.y b/src/tpc.y index 59fa9d1..74d31c6 100644 --- a/src/tpc.y +++ b/src/tpc.y @@ -58,7 +58,7 @@ static char fname[64]; %% Prog: { gen_prologue(); } - DeclConsts DeclVars DeclFoncts { gen_const_declaration(); } + DeclConsts DeclVars DeclFoncts { gen_epilogue(); } ; DeclConsts: DeclConsts CONST ListConst ';' -- cgit v1.2.3