diff options
author | Adam NAILI | 2018-06-05 14:09:01 +0200 |
---|---|---|
committer | Adam NAILI | 2018-06-05 14:09:01 +0200 |
commit | 53e859913d6eb7141dbd1ed48f28c336f1322534 (patch) | |
tree | b550a39273c38141a678dd0bd49d31902a0252dd | |
parent | 8f6dd273479bdc7789d40a235b0afb6598fd0435 (diff) | |
download | tpc-compiler-53e859913d6eb7141dbd1ed48f28c336f1322534.tar.gz |
Replacing VOID by VOID_T
-rw-r--r-- | res/test_read.tpc | 9 | ||||
-rw-r--r-- | src/generator.c | 5 | ||||
-rw-r--r-- | src/generator.h | 2 | ||||
-rw-r--r-- | src/symbol_table.c | 2 | ||||
-rw-r--r-- | src/symbol_table.h | 2 | ||||
-rw-r--r-- | src/tpc.lex | 1 | ||||
-rw-r--r-- | src/tpc.y | 12 |
7 files changed, 15 insertions, 18 deletions
diff --git a/res/test_read.tpc b/res/test_read.tpc index a201223..0109e4d 100644 --- a/res/test_read.tpc +++ b/res/test_read.tpc | |||
@@ -4,12 +4,9 @@ | |||
4 | entier r1,b,s,c,r2 ; | 4 | entier r1,b,s,c,r2 ; |
5 | caractere letter, digit, punct; | 5 | caractere letter, digit, punct; |
6 | 6 | ||
7 | void calcul(void) { | ||
8 | caractere r1; | ||
9 | readc(r1); | ||
10 | print(r1); | ||
11 | } | ||
12 | 7 | ||
13 | entier main(void) { | 8 | entier main(void) { |
14 | calcul(); | 9 | caractere r1; |
10 | readc(r1); | ||
11 | print(r1); | ||
15 | } | 12 | } |
diff --git a/src/generator.c b/src/generator.c index 3f9cc3b..d5df545 100644 --- a/src/generator.c +++ b/src/generator.c | |||
@@ -4,7 +4,6 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "generator.h" | 6 | #include "generator.h" |
7 | #include "symbol_table.h" | ||
8 | 7 | ||
9 | // ----- GLOBAL FUNCTIONS ----- | 8 | // ----- GLOBAL FUNCTIONS ----- |
10 | 9 | ||
@@ -107,14 +106,14 @@ void gen_function_return(Type expect, Type actual) { | |||
107 | exit(1); | 106 | exit(1); |
108 | } | 107 | } |
109 | 108 | ||
110 | if (actual != VOID) fprintf(output, "pop rax\n"); | 109 | if (actual != VOID_T) fprintf(output, "pop rax\n"); |
111 | gen_function_end_declaration(); | 110 | gen_function_end_declaration(); |
112 | } | 111 | } |
113 | 112 | ||
114 | int gen_function_call(const char name[], int nb_param) { | 113 | int gen_function_call(const char name[], int nb_param) { |
115 | Type return_type = fun_lookup(name, nb_param); | 114 | Type return_type = fun_lookup(name, nb_param); |
116 | fprintf(output, "call %s\n", name); | 115 | fprintf(output, "call %s\n", name); |
117 | if (return_type != VOID) fprintf(output, "push rax\n"); | 116 | if (return_type != VOID_T) fprintf(output, "push rax\n"); |
118 | return return_type; | 117 | return return_type; |
119 | } | 118 | } |
120 | 119 | ||
diff --git a/src/generator.h b/src/generator.h index 205fc01..1f586c1 100644 --- a/src/generator.h +++ b/src/generator.h | |||
@@ -7,6 +7,7 @@ | |||
7 | #define __GENERATOR_H__ | 7 | #define __GENERATOR_H__ |
8 | 8 | ||
9 | #include <stdio.h> | 9 | #include <stdio.h> |
10 | #include "symbol_table.h" | ||
10 | 11 | ||
11 | typedef enum scope { | 12 | typedef enum scope { |
12 | GLOBAL, | 13 | GLOBAL, |
@@ -14,6 +15,7 @@ typedef enum scope { | |||
14 | } Scope; | 15 | } Scope; |
15 | 16 | ||
16 | extern int nb_globals; | 17 | extern int nb_globals; |
18 | extern int lineno; | ||
17 | FILE *output; | 19 | FILE *output; |
18 | 20 | ||
19 | void gen_prologue(); | 21 | void gen_prologue(); |
diff --git a/src/symbol_table.c b/src/symbol_table.c index 3ac34fb..9d9617c 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c | |||
@@ -203,7 +203,7 @@ static char *string_of_type(int type) { | |||
203 | return "INT"; | 203 | return "INT"; |
204 | case CHAR: | 204 | case CHAR: |
205 | return "CHAR"; | 205 | return "CHAR"; |
206 | case VOID: | 206 | case VOID_T: |
207 | return "VOID"; | 207 | return "VOID"; |
208 | default: | 208 | default: |
209 | return "UNEXPECTED"; | 209 | return "UNEXPECTED"; |
diff --git a/src/symbol_table.h b/src/symbol_table.h index cd14ae2..a5dba69 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h | |||
@@ -17,7 +17,7 @@ | |||
17 | typedef enum type { | 17 | typedef enum type { |
18 | INT, | 18 | INT, |
19 | CHAR, | 19 | CHAR, |
20 | VOID | 20 | VOID_T |
21 | } Type; | 21 | } Type; |
22 | 22 | ||
23 | typedef struct { | 23 | typedef struct { |
diff --git a/src/tpc.lex b/src/tpc.lex index 7d907b4..bdf6bb5 100644 --- a/src/tpc.lex +++ b/src/tpc.lex | |||
@@ -7,7 +7,6 @@ | |||
7 | #include "tpc.tab.h" | 7 | #include "tpc.tab.h" |
8 | #define INT 0 | 8 | #define INT 0 |
9 | #define CHAR 1 | 9 | #define CHAR 1 |
10 | #define VOID 2 | ||
11 | int lineno = 1; | 10 | int lineno = 1; |
12 | %} | 11 | %} |
13 | 12 | ||
@@ -20,7 +20,7 @@ extern int lineno; | |||
20 | int yylex(); | 20 | int yylex(); |
21 | void yyerror(char *); | 21 | void yyerror(char *); |
22 | static Scope scope = GLOBAL; | 22 | static Scope scope = GLOBAL; |
23 | static Type return_type = VOID; | 23 | static Type return_type = VOID_T; |
24 | static int bss_done = 0; | 24 | static int bss_done = 0; |
25 | static int num_label = 0; | 25 | static int num_label = 0; |
26 | static int num_if = 0; | 26 | static int num_if = 0; |
@@ -89,11 +89,11 @@ DeclFoncts: | |||
89 | ; | 89 | ; |
90 | DeclFonct: | 90 | DeclFonct: |
91 | EnTeteFonct { scope = LOCAL; } | 91 | EnTeteFonct { scope = LOCAL; } |
92 | Corps { gen_function_end_declaration(); scope = GLOBAL; return_type = VOID; } | 92 | Corps { gen_function_end_declaration(); scope = GLOBAL; return_type = VOID_T; } |
93 | ; | 93 | ; |
94 | EnTeteFonct: | 94 | EnTeteFonct: |
95 | TYPE IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, $<type>1, $5); } | 95 | TYPE IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, $<type>1, $5); } |
96 | | VOID IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, VOID, $5); } | 96 | | VOID IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($<ident>2, VOID_T, $5); } |
97 | ; | 97 | ; |
98 | 98 | ||
99 | PrologueCont: {gen_prologue_continue(&bss_done);}; | 99 | PrologueCont: {gen_prologue_continue(&bss_done);}; |
@@ -116,8 +116,8 @@ SuiteInstr: | |||
116 | Instr: | 116 | Instr: |
117 | Exp ';' | 117 | Exp ';' |
118 | | ';' | 118 | | ';' |
119 | | RETURN Exp ';' { gen_function_return(return_type, $<type>2); scope = GLOBAL; return_type = VOID; } | 119 | | RETURN Exp ';' { gen_function_return(return_type, $<type>2); scope = GLOBAL; return_type = VOID_T; } |
120 | | RETURN ';' { gen_function_return(return_type, VOID); scope = GLOBAL; return_type = VOID; } | 120 | | RETURN ';' { gen_function_return(return_type, VOID_T); scope = GLOBAL; return_type = VOID_T; } |
121 | | READE '(' IDENT ')' ';' { gen_reade($<ident>3); } | 121 | | READE '(' IDENT ')' ';' { gen_reade($<ident>3); } |
122 | | READC '(' IDENT ')' ';' { gen_readc($<ident>3); } | 122 | | READC '(' IDENT ')' ';' { gen_readc($<ident>3); } |
123 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} | 123 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} |
@@ -164,7 +164,7 @@ F: | |||
164 | | LValue { $$ = gen_value($<ident>1, scope); } | 164 | | LValue { $$ = gen_value($<ident>1, scope); } |
165 | | NUM { $$ = gen_num($1, scope); } | 165 | | NUM { $$ = gen_num($1, scope); } |
166 | | CARACTERE { $$ = gen_char($1, scope); } | 166 | | CARACTERE { $$ = gen_char($1, scope); } |
167 | | IDENT '(' Arguments ')' { $$ = gen_function_call($<ident>1,$<num>3);} | 167 | | IDENT '(' Arguments ')' { return_type = fun_lookup($<ident>1,$<num>3);$$ = gen_function_call($<ident>1,$<num>3); } |
168 | ; | 168 | ; |
169 | LValue: | 169 | LValue: |
170 | IDENT { gen_check($<ident>1, scope); } | 170 | IDENT { gen_check($<ident>1, scope); } |