From 2ebd7d03e6d9ff5d8badc637ca4c6ab3c6db4e81 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 4 May 2018 09:14:41 +0200 Subject: DIVSTAR working : 'It's working ! It's working' said Anakin --- src/tpc.y | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'src/tpc.y') diff --git a/src/tpc.y b/src/tpc.y index 387b3ef..41fa1d2 100644 --- a/src/tpc.y +++ b/src/tpc.y @@ -2,6 +2,19 @@ /* * UPEM / Compilation / Projet * Pacien TRAN-GIRARD, Adam NAILI + * + * + * + * + * + * + * TODO : + * - 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.) + * - Evaluation paresseuse + * - Gestion des tableaux + * + * + * */ #include @@ -160,7 +173,8 @@ Exp: | EB ; EB: - EB OR TB {check_expected_type($1,INT);check_expected_type($3,INT);} + EB {check_expected_type($1,INT); printf("pop rax\n");} + OR TB {check_expected_type($4,INT);} | TB ; TB: @@ -187,7 +201,20 @@ E: | T ; T: - T DIVSTAR F {check_expected_type($1,INT);check_expected_type($3,INT);} + T DIVSTAR F {check_expected_type($1,INT);check_expected_type($3,INT); + if($2 == '*'){ + printf(";E * T\npop rax\npop rcx\nimul rax,rcx\npush rax\n"); + } + else{ + printf(";E / T\npop rax\npop rcx\nxor rdx,rdx\nidiv rcx\n"); + if ($2 == '/'){ + printf("push rax\n"); + } + else{ + printf("push rdx\n"); + } + } + } | F ; F: @@ -196,15 +223,15 @@ F: printf(";+F\n"); } else{ - printf(";-F\npop rdx\nxor eax,eax\nsub eax,edx\npush rax\n"); + printf(";-F\npop rdx\nxor rax,rax\nsub rax,rdx\npush rax\n"); } } | '!' F {$$ = $2;printf(";!F\npop rax\nxor rax,1\npush rax\n");} | '(' Exp ')' {$$ = $2;} | LValue {if(status == GLOBAL) {$$ = glo_lookup($1);printf("push QWORD [rbp - %d] ;%s\n",glo_get_addr($1),$1);} else {$$ = loc_lookup($1); printf("push QWORD [rbp - %d] ;%s\n",loc_get_addr($1),$1);}} - | NUM {$$ = INT; printf("push %d\n",$1);} // on stocke les types pour l'analyse sémantique - | CARACTERE {$$ = CHAR; printf("push %d\n",$1);} + | NUM {$$ = INT; if(status == LOCAL) printf("push %d\n",$1);} // on stocke les types pour l'analyse sémantique + | CARACTERE {$$ = CHAR; if(status == LOCAL) printf("push %d\n",$1);} | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement ; LValue: -- cgit v1.2.3