|
@@ -79,9 +79,9 @@ C : Fonctions {add_operation(STOP,0,0,0);
|
79
|
79
|
|
80
|
80
|
// Le main, renvoi un int, possède le mot clé main, des arguments et un body
|
81
|
81
|
// Dès que le main est reconnu (token main) on met en place le JMP
|
82
|
|
-Main : tINT tMAIN {create_jump_to_main(get_current_index()); printf("DANS LE MAIN \n");
|
|
82
|
+Main : tINT tMAIN {create_jump_to_main(get_current_index());
|
83
|
83
|
}
|
84
|
|
- tOBRACE Args tCBRACE Body {print();};
|
|
84
|
+ tOBRACE Args tCBRACE Body;
|
85
|
85
|
|
86
|
86
|
|
87
|
87
|
|
|
@@ -217,8 +217,11 @@ Instruction : Print tPV;
|
217
|
217
|
/*************************************/
|
218
|
218
|
/*************************************/
|
219
|
219
|
|
220
|
|
-Invocation : tID tOBRACE Params tCBRACE {struct fonction_t fonc = get_fonction($1); // On récupère la fonction
|
221
|
|
- multiple_pop($3); // On pop les paramètres de la table des symboles
|
|
220
|
+Invocation : tID tOBRACE {push("0_TEMPORARY_CTX", 0, integer); // On reserve la place du contexte
|
|
221
|
+ push("0_TEMPORARY_ADDR_RT", 0, pointer); // On reserve la place de l'adresse de retour
|
|
222
|
+ }
|
|
223
|
+ Params tCBRACE {struct fonction_t fonc = get_fonction($1); // On récupère la fonction
|
|
224
|
+ multiple_pop($4 + 2); // On pop les paramètres de la table des symboles
|
222
|
225
|
add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0); // On écrit le CALL
|
223
|
226
|
// On renvoi l'adresse de la valeur retour de la fonction
|
224
|
227
|
if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab) {
|
|
@@ -374,7 +377,7 @@ SymboleAffectation : SymboleAffectation tOCROCH E tCCROCH {if ($1.type.pointeur
|
374
|
377
|
add_operation(AFC, addr, taille_types[$1.type.base],0); // Sinon le type de base
|
375
|
378
|
}
|
376
|
379
|
add_operation(MUL,$3,addr,$3); // On multiple le nombre de décalage par la taille du type
|
377
|
|
- add_operation(ADD,$3,$1.adresse,$3); // On l'ajoute a l'adresse de base
|
|
380
|
+ add_operation(ADD,$1.adresse,$1.adresse,$3); // On l'ajoute a l'adresse de base
|
378
|
381
|
$1.type.isTab = 0;
|
379
|
382
|
$$=$1;
|
380
|
383
|
pop();
|
|
@@ -418,7 +421,6 @@ SymboleAffectation : tMUL SymboleAffectation {if ($2.type.pointeur
|
418
|
421
|
E : tNB {int addr = push("0_TEMPORARY", 1, integer); // On reserve la place de la variable temporaire
|
419
|
422
|
add_operation(AFC, addr,$1,0); // On Affecte la valeur a cette adresse
|
420
|
423
|
$$ = addr; // On renvoi l'adresse
|
421
|
|
- printf("Nombre %d@%d\n", $1, addr);
|
422
|
424
|
};
|
423
|
425
|
|
424
|
426
|
// Un nombre sous forme XeY, même traitement qu'un nombre classique
|
|
@@ -480,7 +482,7 @@ E : tSUB E {int addr = push("0_TEMPORARY", 1, inte
|
480
|
482
|
|
481
|
483
|
|
482
|
484
|
// Opérateur == (idem multiplication)
|
483
|
|
-E : E tEQCOND E {add_operation(EQU,$1,$1,$3);
|
|
485
|
+E : E tEQCOND E {add_operation(EQU,$1,$1,$3);
|
484
|
486
|
$$ = $1;
|
485
|
487
|
pop();
|
486
|
488
|
};
|
|
@@ -492,8 +494,6 @@ E : E tGT E {add_operation(SUP,$1,$1,$3);
|
492
|
494
|
|
493
|
495
|
// Opérateur < (idem multiplication)
|
494
|
496
|
E : E tLT E {add_operation(INF,$1,$1,$3);
|
495
|
|
- printf("INF %d %d %d\n", $1, $1, $3);
|
496
|
|
- print();
|
497
|
497
|
$$ = $1;
|
498
|
498
|
pop();
|
499
|
499
|
};
|
|
@@ -502,7 +502,7 @@ E : tNOT E {int addr = push("0_TEMPORARY", 1, inte
|
502
|
502
|
add_operation(AFC, addr,0,0); // On affecte le 0
|
503
|
503
|
add_operation(EQU, $2, addr, $2); // On applique le 0==E
|
504
|
504
|
$$ = $2; // On renvoi l'adresse
|
505
|
|
- pop();
|
|
505
|
+ pop();
|
506
|
506
|
};
|
507
|
507
|
|
508
|
508
|
// Opérateur E && E' <=> E*E' (idem multiplication)
|
|
@@ -539,7 +539,6 @@ E : tID {struct symbole_t * symbole = get_vari
|
539
|
539
|
add_operation(COP, addr,symbole->adresse,0); // Si c'est autre chose, on copie la valeur
|
540
|
540
|
}
|
541
|
541
|
$$ = addr;
|
542
|
|
- printf("variable stoquée a l'adresse %d \n", addr);
|
543
|
542
|
};
|
544
|
543
|
|
545
|
544
|
// Une variable sous forme de tableau
|
|
@@ -547,10 +546,10 @@ E : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_vari
|
547
|
546
|
struct type_t type = symbole->type; // On récupère le type
|
548
|
547
|
type.nb_blocs = 1;
|
549
|
548
|
int addr = push("0_TEMPORARY", 1, type); // On créé la variable temporaire
|
550
|
|
- if (type.isTab == 2) {
|
551
|
|
- add_operation(COP, addr,symbole->adresse,0);
|
552
|
|
- } else {
|
|
549
|
+ if (type.isTab) {
|
553
|
550
|
add_operation(AFCA, addr,symbole->adresse,0);
|
|
551
|
+ } else {
|
|
552
|
+ add_operation(COP, addr,symbole->adresse,0);
|
554
|
553
|
}
|
555
|
554
|
int addr2 = push("0_TEMPORARY", 1, integer);
|
556
|
555
|
add_operation(AFC, addr2, taille_types[symbole->type.base],0);
|
|
@@ -569,10 +568,10 @@ EBis : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_vari
|
569
|
568
|
struct type_t type = symbole->type;
|
570
|
569
|
type.nb_blocs = 1;
|
571
|
570
|
int addr = push("0_TEMPORARY", 1, type);
|
572
|
|
- if(type.isTab == 2) {
|
573
|
|
- add_operation(COP, addr,symbole->adresse,0);
|
574
|
|
- } else {
|
|
571
|
+ if(type.isTab) {
|
575
|
572
|
add_operation(AFCA, addr,symbole->adresse,0);
|
|
573
|
+ } else {
|
|
574
|
+ add_operation(COP, addr,symbole->adresse,0);
|
576
|
575
|
}
|
577
|
576
|
int addr2 = push("0_TEMPORARY", 1, integer);
|
578
|
577
|
add_operation(AFC, addr2, taille_types[symbole->type.base],0);
|