aboutsummaryrefslogtreecommitdiff
path: root/src/generator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/generator.c')
-rw-r--r--src/generator.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/generator.c b/src/generator.c
index 1b11b67..553161a 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -12,9 +12,8 @@ void gen_prologue() {
12 fprintf(output, "section .data\n"); 12 fprintf(output, "section .data\n");
13} 13}
14 14
15void gen_prologue_continue(int *bss_done) { 15void gen_prologue_continue(bool *bss_done) {
16 if (*bss_done != 0) 16 if (!*bss_done) return;
17 return;
18 17
19 fprintf(output, "format_int db \"%%d\",10,0\n"); 18 fprintf(output, "format_int db \"%%d\",10,0\n");
20 fprintf(output, "format_char db \"%%c\",10,0\n"); 19 fprintf(output, "format_char db \"%%c\",10,0\n");
@@ -115,8 +114,7 @@ Type gen_function_declaration(const char name[], int return_type) {
115 return return_type; 114 return return_type;
116} 115}
117 116
118void gen_function_end_declaration(const char name[], int return_type, 117void gen_function_end_declaration(const char name[], Type return_type, int nb_param) {
119 int nb_param) {
120 fun_add(name, return_type, nb_param); 118 fun_add(name, return_type, nb_param);
121 fprintf(output, "mov rax,-1\nmov rsp, rbp\npop rbp\nret\n"); 119 fprintf(output, "mov rax,-1\nmov rsp, rbp\npop rbp\nret\n");
122} 120}
@@ -139,7 +137,7 @@ Type gen_function_call(const char name[], int nb_param) {
139 return return_type; 137 return return_type;
140} 138}
141 139
142void gen_declaration(const char name[], int type, Scope scope) { 140void gen_declaration(const char name[], Type type, Scope scope) {
143 switch (scope) { 141 switch (scope) {
144 case GLOBAL: 142 case GLOBAL:
145 glo_addVar(name, type); 143 glo_addVar(name, type);
@@ -220,7 +218,7 @@ void gen_readc(const char name[], Scope scope) {
220 fprintf(output, "mov rax,globals\nadd rax,%d\ncall readc\n", g_addr); 218 fprintf(output, "mov rax,globals\nadd rax,%d\ncall readc\n", g_addr);
221} 219}
222 220
223void gen_print(int type) { 221void gen_print(Type type) {
224 // check if the name exists in both tables 222 // check if the name exists in both tables
225 fprintf(output, "pop rax\n"); 223 fprintf(output, "pop rax\n");
226 switch (type) { 224 switch (type) {
@@ -437,7 +435,7 @@ void gen_divstar(char op, int left, int right) {
437 } 435 }
438} 436}
439 437
440int gen_signed_expr(char op, int type) { 438int gen_signed_expr(char op, Type type) {
441 check_expected_types(type, INT, TAB); 439 check_expected_types(type, INT, TAB);
442 switch (op) { 440 switch (op) {
443 case '+': 441 case '+':
@@ -453,7 +451,7 @@ int gen_signed_expr(char op, int type) {
453 return type; 451 return type;
454} 452}
455 453
456int gen_negate_expr(int type) { 454int gen_negate_expr(Type type) {
457 check_expected_types(type, INT, TAB); 455 check_expected_types(type, INT, TAB);
458 fprintf(output, ";!F\npop rax\nxor rax,1\npush rax\n"); 456 fprintf(output, ";!F\npop rax\nxor rax,1\npush rax\n");
459 return type; 457 return type;