@@ -65,7 +65,7 @@ antlrcpp::Any IRGenVisitor::visitDecl_stmt(ifccParser::Decl_stmtContext *ctx)
65
65
{
66
66
std::string nomVar = scope + " _" + ctx->decl_element (i)->ID ()->getText ();
67
67
// std::cout << "# nomVar " << i << " : " << nomVar << "\n";
68
- std::string address = " RBP" + std::to_string (stv.symbolTable [nomVar].offset );
68
+ std::string address = " RBP" + std::to_string (stv.varTable [nomVar].offset );
69
69
// std::cout << "# address " << address << "\n";
70
70
71
71
// Évaluation de l'expression qu'on place dans le registre universel !reg
@@ -85,7 +85,7 @@ antlrcpp::Any IRGenVisitor::visitAssign_stmt(ifccParser::Assign_stmtContext *ctx
85
85
{
86
86
// On récupère le nom et l'adresse stack de la variable en question
87
87
std::string tried_scope = scope;
88
- while (tried_scope != " " && stv.symbolTable .find (tried_scope + ' _' + ctx->ID ()->getText ()) == stv.symbolTable .end ()) {
88
+ while (tried_scope != " " && stv.varTable .find (tried_scope + ' _' + ctx->ID ()->getText ()) == stv.varTable .end ()) {
89
89
while (tried_scope.size () != 0 && tried_scope.back () != ' _' ) {
90
90
tried_scope.pop_back ();
91
91
}
@@ -96,28 +96,15 @@ antlrcpp::Any IRGenVisitor::visitAssign_stmt(ifccParser::Assign_stmtContext *ctx
96
96
std::string nomVar = tried_scope + " _" + ctx->ID ()->getText ();
97
97
std::pair<bool , int > res (visit (ctx->expr ()));
98
98
99
- // on regarde si c'est un argument de la fonction
100
- if (stv.symbolTable [nomVar].index_arg >= 0 ) {
101
- // Évaluation de l'expression qu'on place dans le registre universel !reg
102
- if (res.first ) {
103
- IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second ); // block, dst, src
104
- cfgs.back ()->current_bb ->add_IRInstr (instruction_const);
105
- }
106
-
107
- IRInstr *instruction_copy_arg = new Copy (cfgs.back ()->current_bb , " !arg" + std::to_string (stv.symbolTable [nomVar].index_arg ), " !reg" );
108
- cfgs.back ()->current_bb ->add_IRInstr (instruction_copy_arg);
109
- }
110
- else {
111
- std::string address = " RBP" + std::to_string (stv.symbolTable [nomVar].offset );
99
+ std::string address = " RBP" + std::to_string (stv.varTable [nomVar].offset );
112
100
113
- // Évaluation de l'expression qu'on place dans le registre universel !reg
114
- if (res.first ) {
115
- IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second ); // block, dst, src
116
- cfgs.back ()->current_bb ->add_IRInstr (instruction_const);
117
- }
118
- IRInstr *instruction = new Wmem (cfgs.back ()->current_bb , address, " !reg" ); // block, dst, src
119
- cfgs.back ()->current_bb ->add_IRInstr (instruction);
101
+ // Évaluation de l'expression qu'on place dans le registre universel !reg
102
+ if (res.first ) {
103
+ IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second ); // block, dst, src
104
+ cfgs.back ()->current_bb ->add_IRInstr (instruction_const);
120
105
}
106
+ IRInstr *instruction = new Wmem (cfgs.back ()->current_bb , address, " !reg" ); // block, dst, src
107
+ cfgs.back ()->current_bb ->add_IRInstr (instruction);
121
108
122
109
return 0 ;
123
110
}
@@ -267,7 +254,7 @@ antlrcpp::Any IRGenVisitor::visitIdUse(ifccParser::IdUseContext *ctx)
267
254
{
268
255
// On récupère le nom et l'adresse stack de la variable en question
269
256
std::string tried_scope = scope;
270
- while (tried_scope != " " && stv.symbolTable .find (tried_scope + ' _' + ctx->ID ()->getText ()) == stv.symbolTable .end ()) {
257
+ while (tried_scope != " " && stv.varTable .find (tried_scope + ' _' + ctx->ID ()->getText ()) == stv.varTable .end ()) {
271
258
while (tried_scope.size () != 0 && tried_scope.back () != ' _' ) {
272
259
tried_scope.pop_back ();
273
260
}
@@ -277,25 +264,18 @@ antlrcpp::Any IRGenVisitor::visitIdUse(ifccParser::IdUseContext *ctx)
277
264
}
278
265
std::string nomVar = tried_scope + " _" + ctx->ID ()->getText ();
279
266
280
- // on regarde si c'est un argument de la fonction
281
- if (stv.symbolTable [nomVar].index_arg >= 0 ) {
282
- IRInstr *instruction_copy_arg = new Copy (cfgs.back ()->current_bb , " !reg" , " !arg" + std::to_string (stv.symbolTable [nomVar].index_arg ));
283
- cfgs.back ()->current_bb ->add_IRInstr (instruction_copy_arg);
284
- }
285
- else {
286
- std::string address = " RBP" + std::to_string (stv.symbolTable [nomVar].offset );
267
+ std::string address = " RBP" + std::to_string (stv.varTable [nomVar].offset );
287
268
288
- IRInstr *instruction = new Rmem (cfgs.back ()->current_bb , " !reg" , address);
289
- cfgs.back ()->current_bb ->add_IRInstr (instruction);
290
- }
269
+ IRInstr *instruction = new Rmem (cfgs.back ()->current_bb , " !reg" , address);
270
+ cfgs.back ()->current_bb ->add_IRInstr (instruction);
291
271
292
272
return std::pair<bool , int >(false , 0 );
293
273
}
294
274
295
275
antlrcpp::Any IRGenVisitor::visitAssignExpr (ifccParser::AssignExprContext *ctx) {
296
276
// On récupère le nom et l'adresse stack de la variable en question
297
277
std::string tried_scope = scope;
298
- while (tried_scope != " " && stv.symbolTable .find (tried_scope + ' _' + ctx->ID ()->getText ()) == stv.symbolTable .end ()) {
278
+ while (tried_scope != " " && stv.varTable .find (tried_scope + ' _' + ctx->ID ()->getText ()) == stv.varTable .end ()) {
299
279
while (tried_scope.size () != 0 && tried_scope.back () != ' _' ) {
300
280
tried_scope.pop_back ();
301
281
}
@@ -307,28 +287,15 @@ antlrcpp::Any IRGenVisitor::visitAssignExpr(ifccParser::AssignExprContext *ctx)
307
287
std::string nomVar = tried_scope + " _" + ctx->ID ()->getText ();
308
288
std::pair<bool , int > res (visit (ctx->expr ()));
309
289
310
- // on regarde si c'est un argument de la fonction
311
- if (stv.symbolTable [nomVar].index_arg >= 0 ) {
312
- // Évaluation de l'expression qu'on place dans le registre universel !reg
313
- if (res.first ) {
314
- IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second ); // block, dst, src
315
- cfgs.back ()->current_bb ->add_IRInstr (instruction_const);
316
- }
317
-
318
- IRInstr *instruction_copy_arg = new Copy (cfgs.back ()->current_bb , " !arg" + std::to_string (stv.symbolTable [nomVar].index_arg ), " !reg" );
319
- cfgs.back ()->current_bb ->add_IRInstr (instruction_copy_arg);
320
- }
321
- else {
322
- std::string address = " RBP" + std::to_string (stv.symbolTable [nomVar].offset );
323
-
324
- // Évaluation de l'expression qu'on place dans le registre universel !reg
325
- if (res.first ) {
326
- IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second ); // block, dst, src
327
- cfgs.back ()->current_bb ->add_IRInstr (instruction_const);
328
- }
329
- IRInstr *instruction = new Wmem (cfgs.back ()->current_bb , address, " !reg" ); // block, dst, src
330
- cfgs.back ()->current_bb ->add_IRInstr (instruction);
290
+ std::string address = " RBP" + std::to_string (stv.varTable [nomVar].offset );
291
+
292
+ // Évaluation de l'expression qu'on place dans le registre universel !reg
293
+ if (res.first ) {
294
+ IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second ); // block, dst, src
295
+ cfgs.back ()->current_bb ->add_IRInstr (instruction_const);
331
296
}
297
+ IRInstr *instruction = new Wmem (cfgs.back ()->current_bb , address, " !reg" ); // block, dst, src
298
+ cfgs.back ()->current_bb ->add_IRInstr (instruction);
332
299
333
300
return res;
334
301
}
@@ -408,7 +375,7 @@ antlrcpp::Any IRGenVisitor::visitMulDivExpr(ifccParser::MulDivExprContext *ctx)
408
375
409
376
else {
410
377
std::string temp_left = cfgs.back ()->create_new_tempvar (Type::INT);
411
- std::string address_left = " RBP" + std::to_string (stv.symbolTable [temp_left].offset );
378
+ std::string address_left = " RBP" + std::to_string (stv.varTable [temp_left].offset );
412
379
// Copier le résultat de l'expression dans la variable temporaire
413
380
IRInstr *instruction_left = new Wmem (cfgs.back ()->current_bb , address_left, " !reg" );
414
381
cfgs.back ()->current_bb ->add_IRInstr (instruction_left);
@@ -487,7 +454,7 @@ antlrcpp::Any IRGenVisitor::visitAddSubExpr(ifccParser::AddSubExprContext *ctx)
487
454
488
455
else {
489
456
std::string temp_left = cfgs.back ()->create_new_tempvar (Type::INT);
490
- std::string address_left = " RBP" + std::to_string (stv.symbolTable [temp_left].offset );
457
+ std::string address_left = " RBP" + std::to_string (stv.varTable [temp_left].offset );
491
458
// Copier le résultat de l'expression dans la variable temporaire
492
459
IRInstr *instruction_left = new Wmem (cfgs.back ()->current_bb , address_left, " !reg" );
493
460
cfgs.back ()->current_bb ->add_IRInstr (instruction_left);
@@ -565,7 +532,7 @@ antlrcpp::Any IRGenVisitor::visitCompExpr(ifccParser::CompExprContext *ctx) {
565
532
566
533
else {
567
534
std::string temp_left = cfgs.back ()->create_new_tempvar (Type::INT);
568
- std::string address_left = " RBP" + std::to_string (stv.symbolTable [temp_left].offset );
535
+ std::string address_left = " RBP" + std::to_string (stv.varTable [temp_left].offset );
569
536
// Copier le résultat de l'expression dans la variable temporaire
570
537
IRInstr *instruction_left = new Wmem (cfgs.back ()->current_bb , address_left, " !reg" );
571
538
cfgs.back ()->current_bb ->add_IRInstr (instruction_left);
@@ -633,7 +600,7 @@ antlrcpp::Any IRGenVisitor::visitEqExpr(ifccParser::EqExprContext *ctx) {
633
600
634
601
else {
635
602
std::string temp_left = cfgs.back ()->create_new_tempvar (Type::INT);
636
- std::string address_left = " RBP" + std::to_string (stv.symbolTable [temp_left].offset );
603
+ std::string address_left = " RBP" + std::to_string (stv.varTable [temp_left].offset );
637
604
// Copier le résultat de l'expression dans la variable temporaire
638
605
IRInstr *instruction_left = new Wmem (cfgs.back ()->current_bb , address_left, " !reg" );
639
606
cfgs.back ()->current_bb ->add_IRInstr (instruction_left);
@@ -679,7 +646,7 @@ antlrcpp::Any IRGenVisitor::visitAndExpr(ifccParser::AndExprContext *ctx) {
679
646
680
647
else {
681
648
std::string temp_left = cfgs.back ()->create_new_tempvar (Type::INT);
682
- std::string address_left = " RBP" + std::to_string (stv.symbolTable [temp_left].offset );
649
+ std::string address_left = " RBP" + std::to_string (stv.varTable [temp_left].offset );
683
650
// Copier le résultat de l'expression dans la variable temporaire
684
651
IRInstr *instruction_left = new Wmem (cfgs.back ()->current_bb , address_left, " !reg" );
685
652
cfgs.back ()->current_bb ->add_IRInstr (instruction_left);
@@ -715,7 +682,7 @@ antlrcpp::Any IRGenVisitor::visitXorExpr(ifccParser::XorExprContext *ctx) {
715
682
716
683
else {
717
684
std::string temp_left = cfgs.back ()->create_new_tempvar (Type::INT);
718
- std::string address_left = " RBP" + std::to_string (stv.symbolTable [temp_left].offset );
685
+ std::string address_left = " RBP" + std::to_string (stv.varTable [temp_left].offset );
719
686
// Copier le résultat de l'expression dans la variable temporaire
720
687
IRInstr *instruction_left = new Wmem (cfgs.back ()->current_bb , address_left, " !reg" );
721
688
cfgs.back ()->current_bb ->add_IRInstr (instruction_left);
@@ -752,7 +719,7 @@ antlrcpp::Any IRGenVisitor::visitOrExpr(ifccParser::OrExprContext *ctx) {
752
719
753
720
else {
754
721
std::string temp_left = cfgs.back ()->create_new_tempvar (Type::INT);
755
- std::string address_left = " RBP" + std::to_string (stv.symbolTable [temp_left].offset );
722
+ std::string address_left = " RBP" + std::to_string (stv.varTable [temp_left].offset );
756
723
// Copier le résultat de l'expression dans la variable temporaire
757
724
IRInstr *instruction_left = new Wmem (cfgs.back ()->current_bb , address_left, " !reg" );
758
725
cfgs.back ()->current_bb ->add_IRInstr (instruction_left);
@@ -784,11 +751,11 @@ antlrcpp::Any IRGenVisitor::visitFuncCall(ifccParser::FuncCallContext *ctx) {
784
751
std::vector<std::string> args_temp_addr;
785
752
786
753
for (int i = 0 ; i < ctx->expr ().size (); i++) {
787
- std::string temp (cfgs.back ()->create_new_tempvar (Type::INT ));
788
- args_temp_addr.push_back (" RBP" + std::to_string (stv.symbolTable [temp].offset ));
754
+ std::string temp (cfgs.back ()->create_new_tempvar (stv. funcTable [nomFonction]. args [i]-> type ));
755
+ args_temp_addr.push_back (" RBP" + std::to_string (stv.varTable [temp].offset ));
789
756
std::pair<bool , int > res (visit (ctx->expr (i)));
790
757
if (res.first ) {
791
- IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second ); // block, dst, src
758
+ IRInstr *instruction_const = new LdConst (cfgs.back ()->current_bb , " !reg" , res.second );
792
759
cfgs.back ()->current_bb ->add_IRInstr (instruction_const);
793
760
}
794
761
IRInstr *instruction_temp = new Wmem (cfgs.back ()->current_bb , args_temp_addr.back (), " !reg" );
@@ -797,7 +764,7 @@ antlrcpp::Any IRGenVisitor::visitFuncCall(ifccParser::FuncCallContext *ctx) {
797
764
}
798
765
799
766
// On appelle la fonction
800
- IRInstr *instruction_call = new Call (cfgs.back ()->current_bb , nomFonction, args_temp_addr); // block, dst, src
767
+ IRInstr *instruction_call = new Call (cfgs.back ()->current_bb , nomFonction, args_temp_addr);
801
768
cfgs.back ()->current_bb ->add_IRInstr (instruction_call);
802
769
803
770
return std::pair<bool , int >(false , 0 );
0 commit comments