aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2018-06-05 14:09:01 +0200
committerAdam NAILI2018-06-05 14:09:01 +0200
commit53e859913d6eb7141dbd1ed48f28c336f1322534 (patch)
treeb550a39273c38141a678dd0bd49d31902a0252dd
parent8f6dd273479bdc7789d40a235b0afb6598fd0435 (diff)
downloadtpc-compiler-53e859913d6eb7141dbd1ed48f28c336f1322534.tar.gz
Replacing VOID by VOID_T
-rw-r--r--res/test_read.tpc9
-rw-r--r--src/generator.c5
-rw-r--r--src/generator.h2
-rw-r--r--src/symbol_table.c2
-rw-r--r--src/symbol_table.h2
-rw-r--r--src/tpc.lex1
-rw-r--r--src/tpc.y12
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 @@
4entier r1,b,s,c,r2 ; 4entier r1,b,s,c,r2 ;
5caractere letter, digit, punct; 5caractere letter, digit, punct;
6 6
7void calcul(void) {
8 caractere r1;
9 readc(r1);
10 print(r1);
11}
12 7
13entier main(void) { 8entier 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
114int gen_function_call(const char name[], int nb_param) { 113int 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
11typedef enum scope { 12typedef enum scope {
12 GLOBAL, 13 GLOBAL,
@@ -14,6 +15,7 @@ typedef enum scope {
14} Scope; 15} Scope;
15 16
16extern int nb_globals; 17extern int nb_globals;
18extern int lineno;
17FILE *output; 19FILE *output;
18 20
19void gen_prologue(); 21void 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 @@
17typedef enum type { 17typedef enum type {
18 INT, 18 INT,
19 CHAR, 19 CHAR,
20 VOID 20 VOID_T
21} Type; 21} Type;
22 22
23typedef struct { 23typedef 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
11int lineno = 1; 10int lineno = 1;
12%} 11%}
13 12
diff --git a/src/tpc.y b/src/tpc.y
index 3bd3df4..dc6bc4f 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -20,7 +20,7 @@ extern int lineno;
20int yylex(); 20int yylex();
21void yyerror(char *); 21void yyerror(char *);
22static Scope scope = GLOBAL; 22static Scope scope = GLOBAL;
23static Type return_type = VOID; 23static Type return_type = VOID_T;
24static int bss_done = 0; 24static int bss_done = 0;
25static int num_label = 0; 25static int num_label = 0;
26static int num_if = 0; 26static int num_if = 0;
@@ -89,11 +89,11 @@ DeclFoncts:
89; 89;
90DeclFonct: 90DeclFonct:
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;
94EnTeteFonct: 94EnTeteFonct:
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
99PrologueCont: {gen_prologue_continue(&bss_done);}; 99PrologueCont: {gen_prologue_continue(&bss_done);};
@@ -116,8 +116,8 @@ SuiteInstr:
116Instr: 116Instr:
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;
169LValue: 169LValue:
170 IDENT { gen_check($<ident>1, scope); } 170 IDENT { gen_check($<ident>1, scope); }