|
@@ -30,13 +30,13 @@ int nbs_instructions_to_patch[10];
|
30
|
30
|
%token tMUL tDIV tADD tSUB tEQ
|
31
|
31
|
%token<nombre> tNB tNBEXP
|
32
|
32
|
%token<id> tID
|
33
|
|
-%token tPRINTF
|
|
33
|
+%token tPRINTF tGET
|
34
|
34
|
%token tERROR
|
35
|
35
|
%token<nombre> tIF tWHILE tELSE
|
36
|
36
|
%token tRETURN
|
37
|
37
|
%token tLT tGT tEQCOND
|
38
|
38
|
%token tAND tOR
|
39
|
|
-%token tADDR
|
|
39
|
+%token tADDR
|
40
|
40
|
|
41
|
41
|
%left tLT tGT
|
42
|
42
|
%left tEQCOND
|
|
@@ -45,7 +45,7 @@ int nbs_instructions_to_patch[10];
|
45
|
45
|
%left tADD tSUB
|
46
|
46
|
%left tMUL tDIV
|
47
|
47
|
|
48
|
|
-%type<nombre> E DebutAff SuiteAffPointeur DebutAffPointeur EBis Invocation Args ArgSuite Arg SuiteParams Params
|
|
48
|
+%type<nombre> E DebutAff SuiteAffPointeur DebutAffPointeur EBis Invocation Args ArgSuite Arg SuiteParams Params Get
|
49
|
49
|
|
50
|
50
|
|
51
|
51
|
|
|
@@ -57,51 +57,51 @@ int nbs_instructions_to_patch[10];
|
57
|
57
|
|
58
|
58
|
|
59
|
59
|
|
60
|
|
-C : Fonction Fonctions;
|
|
60
|
+C : Fonction Fonctions {add_operation(STOP,0,0,0); create_asm();};
|
61
|
61
|
|
62
|
62
|
Fonctions : Fonction Fonctions;
|
63
|
63
|
Fonctions : ;
|
64
|
64
|
|
65
|
|
-Main : tINT {printf("Déclaration du main\n");} tMAIN tOBRACE Args tCBRACE Body { print(); create_asm();} ;
|
|
65
|
+Main : tINT {printf("Déclaration du main\n"); create_jump_to_main(get_current_index());} tMAIN tOBRACE Args tCBRACE Body { print(); } ;
|
66
|
66
|
|
67
|
67
|
Fonction : Type tID {return_type_fonc = type_courant; printf("Déclaration de la fonction %s\n", $2);} tOBRACE {inc_prof();} Args {decrement_prof(); push_fonction($2,return_type_fonc,get_current_index(), $6);} tCBRACE Body { print_fonctions(); add_operation(RET,0,0,0);} ;
|
68
|
68
|
Fonction : Main {print_fonctions();};
|
69
|
69
|
|
70
|
|
-Return : tRETURN E tPV {if (return_type_fonc.pointeur_level > 0 || return_type_fonc.isTab){add_operation(COPR,$2, taille_types[INT],0);} else {add_operation(COPR,$2,taille_types[return_type_fonc.base],0);} pop(); };
|
|
70
|
+Get : tGET tOBRACE tCBRACE {int addr = push("0_TEMPORARY", 0, integer); add_operation(GET,addr,0,0); $$ = addr;};
|
|
71
|
+
|
|
72
|
+Return : tRETURN E tPV {add_operation(COP,0,$2,0); pop(); };
|
71
|
73
|
|
72
|
74
|
Args : Arg ArgSuite {$$ = $1 + $2; printf("Les arguments de la fonctions vont avoir une taille dans la pile de : %d\n",$$);};
|
73
|
75
|
Args : {$$ = 0;};
|
74
|
76
|
Arg : Type tID {int addr = push($2,1, type_courant); if (type_courant.pointeur_level > 0){$$ = taille_types[INT];} else{$$ = taille_types[type_courant.base];}};
|
75
|
|
-Arg : Type tID tOCROCH tCCROCH {int addr = push($2,1, type_courant); $$ = taille_types[INT];};
|
|
77
|
+Arg : Type tID tOCROCH tCCROCH {type_courant.isTab = 2; int addr = push($2,1, type_courant); $$ = taille_types[INT];};
|
76
|
78
|
ArgSuite : tCOMA Arg ArgSuite {$$ = $2 + $3;} ;
|
77
|
79
|
ArgSuite : {$$ = 0;};
|
78
|
80
|
|
79
|
81
|
|
80
|
|
-Body : tOBRACKET {inc_prof();} Instructions tCBRACKET {print(); reset_prof();} ;
|
|
82
|
+Body : tOBRACKET {inc_prof();} Instructions tCBRACKET {print(); reset_prof();};
|
81
|
83
|
|
82
|
84
|
|
83
|
85
|
Instructions : Instruction Instructions ;
|
84
|
86
|
Instructions : ;
|
85
|
87
|
Instruction : Aff {};
|
86
|
88
|
Instruction : Decl {};
|
87
|
|
-Instruction : Invocation tPV{};
|
|
89
|
+Instruction : Invocation tPV{pop();};
|
88
|
90
|
Instruction : If {};
|
89
|
91
|
Instruction : While {};
|
90
|
92
|
Instruction : Return {};
|
91
|
93
|
|
92
|
94
|
|
93
|
|
-Invocation : tID tOBRACE {struct fonction_t fonc = get_fonction($1); if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab){
|
94
|
|
- $2 = push("0_TEMPORARY_RETURN", 0, integer);
|
|
95
|
+Invocation : tID tOBRACE {struct fonction_t fonc = get_fonction($1);}
|
|
96
|
+Params tCBRACE {struct fonction_t fonc = get_fonction($1); multiple_pop($4);
|
|
97
|
+add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0); if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab){
|
|
98
|
+ $$ = push("0_TEMPORARY_RETURN", 0, integer);
|
95
|
99
|
}
|
96
|
100
|
else{
|
97
|
|
-$2 = push("0_TEMPORARY_RETURN", 0, fonc.return_type);
|
98
|
|
-}}
|
99
|
|
-
|
100
|
|
-Params tCBRACE {struct fonction_t fonc = get_fonction($1); multiple_pop($4);
|
101
|
|
-add_operation(CALL,fonc.first_instruction_line, fonc.taille_args,get_current_index() + 1); $$ = $2;};
|
|
101
|
+$$ = push("0_TEMPORARY_RETURN", 0, fonc.return_type);
|
|
102
|
+}};
|
102
|
103
|
|
103
|
|
-
|
104
|
|
-//Pour les tableaux quand on les passe en arguments, il faudra faire gaffe à bien les passer comme un pointeur vers un tableau et pas juste un tableau car sinon in ne pourra pas accéder au tableau de base depuis la fonction appellée. Il faut pour cela peut être rajouter un nouveau champ (isArg) dans la table des symboles (ou autre idée?)
|
|
104
|
+Invocation : tPRINTF tOBRACE E tCBRACE{add_operation(PRI,$3,0,0); pop();};
|
105
|
105
|
|
106
|
106
|
Params : {$$ = 0; printf("Sans Params\n"); } ;
|
107
|
107
|
Params : Param SuiteParams {$$ = $2 + 1;};
|
|
@@ -154,7 +154,7 @@ DebutAff : tID {struct symbole_t * symbole = get_variable($1); symbole->initial
|
154
|
154
|
DebutAffPointeur : tMUL SuiteAffPointeur {add_operation(READ, $2, $2, 0); $$=$2;};
|
155
|
155
|
DebutAffPointeur : SuiteAffPointeur {$$=$1;};
|
156
|
156
|
SuiteAffPointeur : tMUL tID {struct symbole_t * symbole = get_variable($2); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
157
|
|
-SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); if (symbole->type.pointeur_level > 0){add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, addr,symbole->adresse,0);} int addr2 = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3); add_operation(ADD,$3,addr,$3); $$=$3; pop(); pop();};
|
|
157
|
+SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); if (symbole->type.isTab == 2){add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, addr,symbole->adresse,0);} int addr2 = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3); add_operation(ADD,$3,addr,$3); $$=$3; pop(); pop();};
|
158
|
158
|
|
159
|
159
|
|
160
|
160
|
E : tNB { int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
|
|
@@ -173,15 +173,18 @@ E : tNOT E { printf("!\n"); };
|
173
|
173
|
E : E tAND E {add_operation(MUL,$1,$1,$3); $$ = $1; pop();};
|
174
|
174
|
E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; pop();} ;
|
175
|
175
|
E : tMUL E { add_operation(READ, $2, $2, 0); $$=$2;};
|
176
|
|
-E : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if (symbole->type.isTab){add_operation(AFCA, addr,symbole->adresse,0); } else{add_operation(COP, addr,symbole->adresse,0);} $$=addr;};
|
177
|
|
-E : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if(type.pointeur_level > 0) {add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, addr,symbole->adresse,0);} int addr2 = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3);
|
178
|
|
- add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; pop(); pop();};
|
|
176
|
+E : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if (symbole->type.isTab == 1){add_operation(AFCA, addr,symbole->adresse,0);} else{add_operation(COP, addr,symbole->adresse,0);} $$=addr;};
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+E : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if(type.isTab == 2) {add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, addr,symbole->adresse,0);} int addr2 = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3);
|
|
180
|
+add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; pop(); pop();};
|
179
|
181
|
E : tADDR EBis {$$=$2;};
|
|
182
|
+E : Get {$$ = $1;};
|
180
|
183
|
|
181
|
184
|
EBis : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1);
|
182
|
185
|
struct type_t type = symbole->type; type.nb_blocs = 1;
|
183
|
186
|
int addr = push("0_TEMPORARY", 1, type);
|
184
|
|
-if(type.pointeur_level > 0) {
|
|
187
|
+if(type.isTab == 2) {
|
185
|
188
|
add_operation(COP, addr,symbole->adresse,0);
|
186
|
189
|
}
|
187
|
190
|
else{
|