Skip to content

Commit 56dd415

Browse files
committed
Merge branch 'main' of github.com:LucSAMAIN/4IF_PLD
2 parents d744803 + cf0543b commit 56dd415

File tree

4 files changed

+38
-55
lines changed

4 files changed

+38
-55
lines changed

compiler/TypeCheckVisitor.cpp

+6-23
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ antlrcpp::Any TypeCheckVisitor::visitDecl_stmt(ifccParser::Decl_stmtContext *ctx
5757
if (type_expr != stv.varTable[nomVar].type) {
5858
reportError("warning: type mismatch in declaration of variable " + nomVar + ", expected " + typeToString(stv.varTable[nomVar].type) + " found " + typeToString(type_expr), ctx->decl_element(i));
5959
}
60-
if (type_expr != stv.varTable[nomVar].type) {
61-
std::cerr << "warning: type mismatch in declaration of variable " << nomVar << ", expected " << typeToString(stv.varTable[nomVar].type) << " found " << typeToString(type_expr) << "\n";
62-
}
6360
}
6461
}
6562
return 0;
@@ -82,9 +79,6 @@ antlrcpp::Any TypeCheckVisitor::visitReturn_stmt(ifccParser::Return_stmtContext
8279
else if (type_expr != stv.funcTable[func_name].type) {
8380
reportError("warning: type mismatch in return statement of function " + func_name + ", expected " + typeToString(stv.funcTable[func_name].type) + " found " + typeToString(type_expr), ctx);
8481
}
85-
if (type_expr != stv.funcTable[func_name].type) {
86-
std::cerr << "warning: type mismatch in return statement of function " << func_name << ", expected " << typeToString(stv.funcTable[func_name].type) << " found " << typeToString(type_expr) << "\n";
87-
}
8882

8983
return 0;
9084
}
@@ -161,10 +155,9 @@ antlrcpp::Any TypeCheckVisitor::visitAssignExpr(ifccParser::AssignExprContext *c
161155
reportError("error: type mismatch in assignment of variable expected " + typeToString(type_var) + " found " + typeToString(type_expr), ctx);
162156
error++;
163157
}
164-
// if (type_expr != type_var) {
165-
// std::cerr << "error: type mismatch in assignment of variable " << nomVar << ", expected " << typeToString(type_var) << " found " << typeToString(type_expr) << "\n";
166-
// error++;
167-
// }
158+
else if (type_expr != type_var) {
159+
reportError("warning: type mismatch in assignment of variable expected " + typeToString(type_var) + " found " + typeToString(type_expr), ctx);
160+
}
168161

169162
return type_var;
170163
}
@@ -175,10 +168,9 @@ antlrcpp::Any TypeCheckVisitor::visitAssign_stmt(ifccParser::Assign_stmtContext
175168
reportError("error: type mismatch in assignment of variable expected " + typeToString(type_var) + " found " + typeToString(type_expr), ctx);
176169
error++;
177170
}
178-
// if (type_expr != type_var) {
179-
// std::cerr << "error: type mismatch in assignment of variable " << nomVar << ", expected " << typeToString(type_var) << " found " << typeToString(type_expr) << "\n";
180-
// error++;
181-
// }
171+
else if (type_expr != type_var) {
172+
reportError("warning: type mismatch in assignment of variable expected " + typeToString(type_var) + " found " + typeToString(type_expr), ctx);
173+
}
182174

183175
return type_var;
184176
}
@@ -262,9 +254,6 @@ antlrcpp::Any TypeCheckVisitor::visitAddSubExpr(ifccParser::AddSubExprContext *c
262254
if (type_left != type_right) {
263255
reportError("warning: type mismatch in add/sub expression, found " + typeToString(type_left) + " and " + typeToString(type_right), ctx);
264256
}
265-
if (type_left != type_right) {
266-
std::cerr << "warning: type mismatch in add/sub expression, found " << typeToString(type_left) << " and " << typeToString(type_right) << "\n";
267-
}
268257

269258
return output_type;
270259
}
@@ -279,9 +268,6 @@ antlrcpp::Any TypeCheckVisitor::visitCompExpr(ifccParser::CompExprContext *ctx)
279268
if (type_left != type_right) {
280269
reportError("warning: type mismatch in comparison expression, found " + typeToString(type_left) + " and " + typeToString(type_right), ctx);
281270
}
282-
if (type_left != type_right) {
283-
std::cerr << "warning: type mismatch in comparison expression, found " << typeToString(type_left) << " and " << typeToString(type_right) << "\n";
284-
}
285271

286272
return Type::INT32_T;
287273
}
@@ -296,9 +282,6 @@ antlrcpp::Any TypeCheckVisitor::visitEqExpr(ifccParser::EqExprContext *ctx) {
296282
if (type_left != type_right) {
297283
reportError("warning: type mismatch in comparison expression, found " + typeToString(type_left) + " and " + typeToString(type_right), ctx);
298284
}
299-
if (type_left != type_right) {
300-
std::cerr << "warning: type mismatch in comparison expression, found " << typeToString(type_left) << " and " << typeToString(type_right) << "\n";
301-
}
302285

303286
return Type::INT32_T;
304287
}

compiler/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int main(int argc, char* argv[])
126126

127127
// Récupération du CFG généré
128128
std::vector<CFG*> cfgs = cgv.getCFGs();
129-
if(wat) {
129+
if (wat) {
130130
out << "(module\n ;; Import de putchar depuis l'environnement hôte\n (import \"env\" \"putchar\" (func $putchar (param i32) (result i32)))\n";
131131
out << " ;; Déclaration de la mémoire\n";
132132
out << " (memory 1)\n";

tests/tests_false/21_01_fast_exp.c renamed to tests/tests_false/21_01_fast_pow.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void print_int(int x) {
99
putchar(x % 10 + '0');
1010
}
1111

12-
int fast_exp(int base, int exp) {
12+
int fast_pow(int base, int exp) {
1313
if (exp == 0) {
1414
return 1;
1515
}
@@ -18,10 +18,10 @@ int fast_exp(int base, int exp) {
1818
}
1919

2020
if (exp % 2 == 0) {
21-
return fast_exp(base*base, exp / 2);
21+
return fast_pow(base*base, exp / 2);
2222
}
2323
else {
24-
return base*fast_exp(base*base, exp / 2);
24+
return base*fast_pow(base*base, exp / 2);
2525
}
2626
}
2727

@@ -60,7 +60,7 @@ int main() {
6060
exp *= 10;
6161
exp += c-'0';
6262
}
63-
res = fast_exp(base, exp);
63+
res = fast_pow(base, exp);
6464

6565
print_int(base);
6666
putchar('^');

tests/tests_false/21_01_fast_exp.s renamed to tests/tests_false/21_01_fast_pow.s

+27-27
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ print_int_epilogue:
7777
popq %rbp
7878
ret
7979

80-
fast_exp:
80+
fast_pow:
8181
pushq %rbp # prologue
8282
movq %rsp, %rbp
8383
subq $64, %rsp
8484
movl %edi, -4(%rbp)
8585
movl %esi, -8(%rbp)
86-
fast_exp_0:
86+
fast_pow_0:
8787
movl -8(%rbp), %eax # rmem
8888
movl %eax, -12(%rbp) # wmem
8989
movl $0, %ecx # ldconstint
@@ -92,12 +92,12 @@ fast_exp_0:
9292
sete %al
9393
movzbl %al, %eax
9494
cmpl $0, %eax # jump false
95-
je fast_exp_1_endif
96-
jmp fast_exp_1_if_true
97-
fast_exp_1_if_true:
95+
je fast_pow_1_endif
96+
jmp fast_pow_1_if_true
97+
fast_pow_1_if_true:
9898
movl $1, %eax # ldconstint
99-
jmp fast_exp_epilogue # jump
100-
fast_exp_1_endif:
99+
jmp fast_pow_epilogue # jump
100+
fast_pow_1_endif:
101101
movl -8(%rbp), %eax # rmem
102102
movl %eax, -16(%rbp) # wmem
103103
movl $1, %ecx # ldconstint
@@ -106,12 +106,12 @@ fast_exp_1_endif:
106106
sete %al
107107
movzbl %al, %eax
108108
cmpl $0, %eax # jump false
109-
je fast_exp_3_endif
110-
jmp fast_exp_3_if_true
111-
fast_exp_3_if_true:
109+
je fast_pow_3_endif
110+
jmp fast_pow_3_if_true
111+
fast_pow_3_if_true:
112112
movl -4(%rbp), %eax # rmem
113-
jmp fast_exp_epilogue # jump
114-
fast_exp_3_endif:
113+
jmp fast_pow_epilogue # jump
114+
fast_pow_3_endif:
115115
movl -8(%rbp), %eax # rmem
116116
movl %eax, -20(%rbp) # wmem
117117
movl $2, %ecx # ldconstint
@@ -126,9 +126,9 @@ fast_exp_3_endif:
126126
sete %al
127127
movzbl %al, %eax
128128
cmpl $0, %eax # jump false
129-
je fast_exp_5_if_false
130-
jmp fast_exp_5_if_true
131-
fast_exp_5_if_true:
129+
je fast_pow_5_if_false
130+
jmp fast_pow_5_if_true
131+
fast_pow_5_if_true:
132132
movl -4(%rbp), %eax # rmem
133133
movl %eax, -32(%rbp) # wmem
134134
movl -4(%rbp), %eax # rmem
@@ -143,12 +143,12 @@ fast_exp_5_if_true:
143143
cqo # div
144144
idivl %ecx
145145
movl %eax, -36(%rbp) # wmem
146-
# call fast_exp
146+
# call fast_pow
147147
movl -28(%rbp), %edi
148148
movl -36(%rbp), %esi
149-
call fast_exp
150-
jmp fast_exp_epilogue # jump
151-
fast_exp_5_if_false:
149+
call fast_pow
150+
jmp fast_pow_epilogue # jump
151+
fast_pow_5_if_false:
152152
movl -4(%rbp), %eax # rmem
153153
movl %eax, -44(%rbp) # wmem
154154
movl -4(%rbp), %eax # rmem
@@ -165,17 +165,17 @@ fast_exp_5_if_false:
165165
cqo # div
166166
idivl %ecx
167167
movl %eax, -56(%rbp) # wmem
168-
# call fast_exp
168+
# call fast_pow
169169
movl -48(%rbp), %edi
170170
movl -56(%rbp), %esi
171-
call fast_exp
171+
call fast_pow
172172
movl %eax, %ecx # copy
173173
movl -44(%rbp), %eax # rmem
174174
imull %ecx, %eax # mul
175-
jmp fast_exp_epilogue # jump
176-
fast_exp_5_endif:
177-
jmp fast_exp_epilogue # jump
178-
fast_exp_epilogue:
175+
jmp fast_pow_epilogue # jump
176+
fast_pow_5_endif:
177+
jmp fast_pow_epilogue # jump
178+
fast_pow_epilogue:
179179
movq %rbp, %rsp # epilogue
180180
popq %rbp
181181
ret
@@ -369,10 +369,10 @@ main_5_endwhile:
369369
movl %eax, -36(%rbp) # wmem
370370
movl -12(%rbp), %eax # rmem
371371
movl %eax, -40(%rbp) # wmem
372-
# call fast_exp
372+
# call fast_pow
373373
movl -36(%rbp), %edi
374374
movl -40(%rbp), %esi
375-
call fast_exp
375+
call fast_pow
376376
movl %eax, -16(%rbp) # wmem
377377
movl -8(%rbp), %eax # rmem
378378
movl %eax, -44(%rbp) # wmem

0 commit comments

Comments
 (0)