aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam NAILI2018-06-06 14:31:40 +0200
committerAdam NAILI2018-06-06 14:31:40 +0200
commit901e95ebf54575d24e533383fabfc5e9d916bf39 (patch)
tree45498bf25c66fe97c81ff720458250cc363e136b /src
parentcc1b72c1093dfd3bb0f41802a6a012402fa9717e (diff)
parent8a5ccc3b6e5e7a3ad064cc5cce1c4a1a9ac74aa8 (diff)
downloadtpc-compiler-901e95ebf54575d24e533383fabfc5e9d916bf39.tar.gz
Merge branch 'master' of https://github.com/pacien/upem-compil-tpc
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 601f482..bbb2af5 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -78,7 +78,7 @@ void gen_prologue_continue(int *bss_done) {
78 *bss_done = 1; 78 *bss_done = 1;
79} 79}
80 80
81void gen_const_declaration() { 81void gen_epilogue() {
82 fprintf(output, "\n_start:\n"); 82 fprintf(output, "\n_start:\n");
83 fprintf(output, "push rbp\nmov rbp, rsp\n\n"); 83 fprintf(output, "push rbp\nmov rbp, rsp\n\n");
84 fprintf(output, "call main\n"); 84 fprintf(output, "call main\n");
@@ -91,6 +91,9 @@ void gen_const_declaration() {
91 loc_display_table(); 91 loc_display_table();
92 fprintf(output, ";function table\n"); 92 fprintf(output, ";function table\n");
93 fun_display_table(); 93 fun_display_table();
94
95 // require a main function
96 fun_lookup("main", 0);
94} 97}
95 98
96void gen_const(const char name[], int value, Scope scope) { 99void 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 ';'