diff options
-rw-r--r-- | res/test_add_ok.tpc (renamed from res/test_add.tpc) | 0 | ||||
-rw-r--r-- | res/test_array_ok.tpc (renamed from res/test_array.tpc) | 0 | ||||
-rw-r--r-- | res/test_global_ok.tpc (renamed from res/test_global.tpc) | 0 | ||||
-rw-r--r-- | res/test_if_ok.tpc (renamed from res/test_if.tpc) | 0 | ||||
-rw-r--r-- | res/test_mul_ok.tpc (renamed from res/test_mul.tpc) | 0 | ||||
-rw-r--r-- | res/test_nomain_ko.tpc | 6 | ||||
-rw-r--r-- | res/test_parameters_ok.tpc (renamed from res/test_parameters.tpc) | 0 | ||||
-rw-r--r-- | res/test_read_ok.tpc (renamed from res/test_read.tpc) | 0 | ||||
-rw-r--r-- | res/test_return_ok.tpc (renamed from res/test_return.tpc) | 0 | ||||
-rw-r--r-- | res/test_sample_ko.tpc (renamed from res/ko_sample.tpc) | 0 | ||||
-rw-r--r-- | res/test_sample_ok.tpc (renamed from res/ok_sample.tpc) | 0 | ||||
-rw-r--r-- | res/test_table_symbols_ok.tpc (renamed from res/test-table-symboles.tpc) | 0 | ||||
-rw-r--r-- | res/test_while_ok.tpc (renamed from res/test_while.tpc) | 0 | ||||
-rw-r--r-- | src/generator.c | 5 | ||||
-rw-r--r-- | src/generator.h | 2 | ||||
-rw-r--r-- | src/tpc.y | 2 |
16 files changed, 12 insertions, 3 deletions
diff --git a/res/test_add.tpc b/res/test_add_ok.tpc index 848130c..848130c 100644 --- a/res/test_add.tpc +++ b/res/test_add_ok.tpc | |||
diff --git a/res/test_array.tpc b/res/test_array_ok.tpc index a968c22..a968c22 100644 --- a/res/test_array.tpc +++ b/res/test_array_ok.tpc | |||
diff --git a/res/test_global.tpc b/res/test_global_ok.tpc index d8b7d45..d8b7d45 100644 --- a/res/test_global.tpc +++ b/res/test_global_ok.tpc | |||
diff --git a/res/test_if.tpc b/res/test_if_ok.tpc index 054811b..054811b 100644 --- a/res/test_if.tpc +++ b/res/test_if_ok.tpc | |||
diff --git a/res/test_mul.tpc b/res/test_mul_ok.tpc index 62a8080..62a8080 100644 --- a/res/test_mul.tpc +++ b/res/test_mul_ok.tpc | |||
diff --git a/res/test_nomain_ko.tpc b/res/test_nomain_ko.tpc new file mode 100644 index 0000000..570c5ca --- /dev/null +++ b/res/test_nomain_ko.tpc | |||
@@ -0,0 +1,6 @@ | |||
1 | const c = 0; | ||
2 | |||
3 | /* not a main */ | ||
4 | void f(void) { | ||
5 | print(c); | ||
6 | } | ||
diff --git a/res/test_parameters.tpc b/res/test_parameters_ok.tpc index 479fb60..479fb60 100644 --- a/res/test_parameters.tpc +++ b/res/test_parameters_ok.tpc | |||
diff --git a/res/test_read.tpc b/res/test_read_ok.tpc index 6ad3632..6ad3632 100644 --- a/res/test_read.tpc +++ b/res/test_read_ok.tpc | |||
diff --git a/res/test_return.tpc b/res/test_return_ok.tpc index f450203..f450203 100644 --- a/res/test_return.tpc +++ b/res/test_return_ok.tpc | |||
diff --git a/res/ko_sample.tpc b/res/test_sample_ko.tpc index 9dc344f..9dc344f 100644 --- a/res/ko_sample.tpc +++ b/res/test_sample_ko.tpc | |||
diff --git a/res/ok_sample.tpc b/res/test_sample_ok.tpc index c8d3d9d..c8d3d9d 100644 --- a/res/ok_sample.tpc +++ b/res/test_sample_ok.tpc | |||
diff --git a/res/test-table-symboles.tpc b/res/test_table_symbols_ok.tpc index b2cc31e..b2cc31e 100644 --- a/res/test-table-symboles.tpc +++ b/res/test_table_symbols_ok.tpc | |||
diff --git a/res/test_while.tpc b/res/test_while_ok.tpc index 25d04c6..25d04c6 100644 --- a/res/test_while.tpc +++ b/res/test_while_ok.tpc | |||
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 | ||
82 | void gen_const_declaration() { | 82 | void 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 | ||
97 | void gen_const(const char name[], int value, Scope scope) { | 100 | 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; | |||
16 | 16 | ||
17 | void gen_prologue(); | 17 | void gen_prologue(); |
18 | void gen_prologue_continue(int *bss_done); | 18 | void gen_prologue_continue(int *bss_done); |
19 | void gen_const_declaration(); | 19 | void gen_epilogue(); |
20 | void gen_const(const char name[], int value, Scope scope); | 20 | void gen_const(const char name[], int value, Scope scope); |
21 | 21 | ||
22 | Type gen_function_declaration(const char name[], int return_type); | 22 | Type gen_function_declaration(const char name[], int return_type); |
@@ -58,7 +58,7 @@ static char fname[64]; | |||
58 | 58 | ||
59 | %% | 59 | %% |
60 | Prog: { gen_prologue(); } | 60 | Prog: { gen_prologue(); } |
61 | DeclConsts DeclVars DeclFoncts { gen_const_declaration(); } | 61 | DeclConsts DeclVars DeclFoncts { gen_epilogue(); } |
62 | ; | 62 | ; |
63 | DeclConsts: | 63 | DeclConsts: |
64 | DeclConsts CONST ListConst ';' | 64 | DeclConsts CONST ListConst ';' |