aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/generator.c5
-rw-r--r--src/generator.h2
-rw-r--r--src/tpc.y2
3 files changed, 6 insertions, 3 deletions
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) {
79 *bss_done = 1; 79 *bss_done = 1;
80} 80}
81 81
82void gen_const_declaration() { 82void gen_epilogue() {
83 fprintf(output, "\n_start:\n"); 83 fprintf(output, "\n_start:\n");
84 fprintf(output, "push rbp\nmov rbp, rsp\n\n"); 84 fprintf(output, "push rbp\nmov rbp, rsp\n\n");
85 fprintf(output, "call main\n"); 85 fprintf(output, "call main\n");
@@ -92,6 +92,9 @@ void gen_const_declaration() {
92 loc_display_table(); 92 loc_display_table();
93 fprintf(output, ";function table\n"); 93 fprintf(output, ";function table\n");
94 fun_display_table(); 94 fun_display_table();
95
96 // require a main function
97 fun_lookup("main", 0);
95} 98}
96 99
97void gen_const(const char name[], int value, Scope scope) { 100void 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;
16 16
17void gen_prologue(); 17void gen_prologue();
18void gen_prologue_continue(int *bss_done); 18void gen_prologue_continue(int *bss_done);
19void gen_const_declaration(); 19void gen_epilogue();
20void gen_const(const char name[], int value, Scope scope); 20void gen_const(const char name[], int value, Scope scope);
21 21
22Type gen_function_declaration(const char name[], int return_type); 22Type 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];
58 58
59%% 59%%
60Prog: { gen_prologue(); } 60Prog: { gen_prologue(); }
61 DeclConsts DeclVars DeclFoncts { gen_const_declaration(); } 61 DeclConsts DeclVars DeclFoncts { gen_epilogue(); }
62; 62;
63DeclConsts: 63DeclConsts:
64 DeclConsts CONST ListConst ';' 64 DeclConsts CONST ListConst ';'