diff options
Diffstat (limited to 'src/tpc.y')
-rw-r--r-- | src/tpc.y | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -2,6 +2,19 @@ | |||
2 | /* | 2 | /* |
3 | * UPEM / Compilation / Projet | 3 | * UPEM / Compilation / Projet |
4 | * Pacien TRAN-GIRARD, Adam NAILI | 4 | * Pacien TRAN-GIRARD, Adam NAILI |
5 | * | ||
6 | * | ||
7 | * | ||
8 | * | ||
9 | * | ||
10 | * | ||
11 | * TODO : | ||
12 | * - Gérer les globales avec .bss (Il faut donc décaler le début du programme après l'analyse des globales pour savoir combien de place réserver.) | ||
13 | * - Evaluation paresseuse | ||
14 | * - Gestion des tableaux | ||
15 | * | ||
16 | * | ||
17 | * | ||
5 | */ | 18 | */ |
6 | 19 | ||
7 | #include <stdio.h> | 20 | #include <stdio.h> |
@@ -160,7 +173,8 @@ Exp: | |||
160 | | EB | 173 | | EB |
161 | ; | 174 | ; |
162 | EB: | 175 | EB: |
163 | EB OR TB {check_expected_type($1,INT);check_expected_type($3,INT);} | 176 | EB {check_expected_type($1,INT); printf("pop rax\n");} |
177 | OR TB {check_expected_type($4,INT);} | ||
164 | | TB | 178 | | TB |
165 | ; | 179 | ; |
166 | TB: | 180 | TB: |
@@ -187,7 +201,20 @@ E: | |||
187 | | T | 201 | | T |
188 | ; | 202 | ; |
189 | T: | 203 | T: |
190 | T DIVSTAR F {check_expected_type($1,INT);check_expected_type($3,INT);} | 204 | T DIVSTAR F {check_expected_type($1,INT);check_expected_type($3,INT); |
205 | if($2 == '*'){ | ||
206 | printf(";E * T\npop rax\npop rcx\nimul rax,rcx\npush rax\n"); | ||
207 | } | ||
208 | else{ | ||
209 | printf(";E / T\npop rax\npop rcx\nxor rdx,rdx\nidiv rcx\n"); | ||
210 | if ($2 == '/'){ | ||
211 | printf("push rax\n"); | ||
212 | } | ||
213 | else{ | ||
214 | printf("push rdx\n"); | ||
215 | } | ||
216 | } | ||
217 | } | ||
191 | | F | 218 | | F |
192 | ; | 219 | ; |
193 | F: | 220 | F: |
@@ -196,15 +223,15 @@ F: | |||
196 | printf(";+F\n"); | 223 | printf(";+F\n"); |
197 | } | 224 | } |
198 | else{ | 225 | else{ |
199 | printf(";-F\npop rdx\nxor eax,eax\nsub eax,edx\npush rax\n"); | 226 | printf(";-F\npop rdx\nxor rax,rax\nsub rax,rdx\npush rax\n"); |
200 | } | 227 | } |
201 | } | 228 | } |
202 | | '!' F {$$ = $2;printf(";!F\npop rax\nxor rax,1\npush rax\n");} | 229 | | '!' F {$$ = $2;printf(";!F\npop rax\nxor rax,1\npush rax\n");} |
203 | | '(' Exp ')' {$$ = $2;} | 230 | | '(' Exp ')' {$$ = $2;} |
204 | | LValue {if(status == GLOBAL) {$$ = glo_lookup($<ident>1);printf("push QWORD [rbp - %d] ;%s\n",glo_get_addr($<ident>1),$<ident>1);} | 231 | | LValue {if(status == GLOBAL) {$$ = glo_lookup($<ident>1);printf("push QWORD [rbp - %d] ;%s\n",glo_get_addr($<ident>1),$<ident>1);} |
205 | else {$$ = loc_lookup($<ident>1); printf("push QWORD [rbp - %d] ;%s\n",loc_get_addr($<ident>1),$<ident>1);}} | 232 | else {$$ = loc_lookup($<ident>1); printf("push QWORD [rbp - %d] ;%s\n",loc_get_addr($<ident>1),$<ident>1);}} |
206 | | NUM {$$ = INT; printf("push %d\n",$1);} // on stocke les types pour l'analyse sémantique | 233 | | NUM {$$ = INT; if(status == LOCAL) printf("push %d\n",$1);} // on stocke les types pour l'analyse sémantique |
207 | | CARACTERE {$$ = CHAR; printf("push %d\n",$1);} | 234 | | CARACTERE {$$ = CHAR; if(status == LOCAL) printf("push %d\n",$1);} |
208 | | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement | 235 | | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement |
209 | ; | 236 | ; |
210 | LValue: | 237 | LValue: |