From d6301bad2d91858e9a0cec6aa8d4d11661797842 Mon Sep 17 00:00:00 2001 From: Rochas Date: Wed, 30 Apr 2025 18:07:59 +0200 Subject: [PATCH] correction bug pour SemanticError --- NULL | 6 +++--- src/main/java/TP2/Main.java | 4 +++- src/main/java/TP2/asd/SymTable.java | 15 +++++++++++++-- src/main/java/TP2/asd/toLLVM_Visitor.java | 10 +++++++++- tests/fragment0/add0 | Bin 109568 -> 109568 bytes tests/fragment0/add1 | Bin 109568 -> 109568 bytes tests/fragment0/const0 | Bin 109568 -> 109568 bytes tests/fragment0/const1 | Bin 109568 -> 109568 bytes tests/fragment0/div0 | Bin 109568 -> 109568 bytes tests/fragment0/div1 | Bin 109568 -> 109568 bytes tests/fragment0/mod | Bin 109568 -> 109568 bytes tests/fragment0/mult1 | Bin 109568 -> 109568 bytes tests/fragment0/mult2 | Bin 109568 -> 109568 bytes tests/fragment0/paren | Bin 109568 -> 109568 bytes tests/fragment0/priority1 | Bin 109568 -> 109568 bytes tests/fragment0/priority2 | Bin 109568 -> 109568 bytes tests/fragment0/sub0 | Bin 109568 -> 109568 bytes tests/fragment0/sub1 | Bin 109568 -> 109568 bytes tests/fragment1/assign1 | Bin 109568 -> 109568 bytes tests/fragment1/assign2 | Bin 109568 -> 109568 bytes tests/fragment1/block | Bin 109568 -> 109568 bytes tests/fragment1/decl | Bin 109568 -> 109568 bytes tests/fragment1/hello_world | Bin 137216 -> 137216 bytes tests/fragment1/if1 | Bin 109568 -> 109568 bytes tests/fragment1/if2 | Bin 109568 -> 109568 bytes tests/fragment1/print1 | Bin 137216 -> 137216 bytes tests/fragment1/print2 | Bin 137216 -> 137216 bytes tests/fragment1/print3 | Bin 137216 -> 137216 bytes tests/fragment1/print4 | Bin 137728 -> 137728 bytes tests/fragment1/sequence | Bin 137728 -> 137728 bytes tests/fragment1/while1 | Bin 109568 -> 109568 bytes tests/fragment1/while2 | Bin 109568 -> 109568 bytes tests/fragment2/call | Bin 137728 -> 137728 bytes tests/fragment2/call2 | Bin 137728 -> 137728 bytes tests/fragment2/call3expr | Bin 137728 -> 137728 bytes tests/fragment2/call4if | Bin 137728 -> 137728 bytes tests/fragment2/proto1 | Bin 109568 -> 109568 bytes tests/fragment2/proto2 | Bin 137728 -> 137728 bytes tests/testsAdvanced/carre | Bin 137728 -> 137728 bytes tests/testsAdvanced/diverge | Bin 137728 -> 137728 bytes tests/testsAdvanced/divergeDifficile | Bin 137728 -> 137728 bytes 41 files changed, 28 insertions(+), 7 deletions(-) diff --git a/NULL b/NULL index a2721b4..b6fa581 100644 --- a/NULL +++ b/NULL @@ -1,4 +1,4 @@ -tests\testsAdvanced\portee3.ll:20:4: error: multiple definition of local value named 'null' - 20 | %null = alloca i32 - | ^ +tests\testsAdvanced\hanoi.ll:62:1: error: expected instruction opcode + 62 | fi3: + | ^ 1 error generated. diff --git a/src/main/java/TP2/Main.java b/src/main/java/TP2/Main.java index 604cdc9..701f93b 100644 --- a/src/main/java/TP2/Main.java +++ b/src/main/java/TP2/Main.java @@ -62,12 +62,14 @@ public class Main { // Pretty-print the program (to debug parsing) + if(!TESTAUTOMOD) System.out.println("\nVSL:\n"); + if(!TESTAUTOMOD) System.out.println(ast.prettyprinter()); // Verify the program semantic // Generate the intermediate representation - if(!TESTAUTOMOD) System.out.println("\n\n"); + if(!TESTAUTOMOD) System.out.println("\nLLVM:\n"); ProgramLLVMImp astLLVM = ast.toLLVM(); diff --git a/src/main/java/TP2/asd/SymTable.java b/src/main/java/TP2/asd/SymTable.java index f4d30e6..53620e8 100644 --- a/src/main/java/TP2/asd/SymTable.java +++ b/src/main/java/TP2/asd/SymTable.java @@ -85,19 +85,27 @@ public class SymTable { public SymTable addFunction(DefineLLVMImp function, Boolean isProto){ ValueFunMap value = this.functionsMap.get(function.name()); if(value == null || (value!=null && value.isProto && !isProto)){ + if(value!=null && value.isProto && (value.define.type().getClass() != function.type().getClass() || value.define.params().size() != function.params().size())){ + System.err.println("[VSL compile error] : La fonction '"+function.name()+"()' est incompatible avec le Proto déjà déclaré"); + System.exit(1); + } return new SymTable(this.varMap, this.functionsMap.plus(function.name(),new ValueFunMap(function,isProto)), this.id,this.declarationsGlobal); } else{ if(value.isProto) System.err.println("[VSL compile error] : Le prototype '"+function.name()+"()' existe déjà"); else if(isProto) System.err.println("[VSL compile error] : Le prototype '"+function.name()+"()' doit être déclaré avant son implémentation"); else System.err.println("[VSL compile error] : La fonction '"+function.name()+"()' existe déjà"); + System.exit(1); return null; } } public ValueFunMap getFunction(String name){ ValueFunMap f = this.functionsMap.get(name); - if (f==null) System.err.println("[VSL compile error] : la fonction '" + name + "()' n'existe pas, veuillez vous assurer de l'avoir déclarée avant l'appel"); + if (f==null){ + System.err.println("[VSL compile error] : la fonction '" + name + "()' n'existe pas, veuillez vous assurer de l'avoir déclarée avant l'appel"); + System.exit(1); + } return f; } @@ -146,7 +154,8 @@ public class SymTable { PMap top = varMap.get(0); if (top.containsKey(nomVar)) { if(!top.get(nomVar).isParam){ //si non on écrase, on a plus besoin du param après - System.err.println("[VSL compile error] : '" + nomVar+ "' Erreur"); + System.err.println("[VSL compile error] : '" + nomVar+ "' a déjà été déclaré"); + System.exit(1); return new Result(this, null); } } @@ -172,6 +181,7 @@ public class SymTable { } } System.err.println("[VSL compile error] : '" + nomVar + "' n'a pas été déclaré"); + System.exit(1); return null; } @@ -182,6 +192,7 @@ public class SymTable { } } System.err.println("[VSL compile error] : '" + nomVar+"' n'est pas trouvé"); + System.exit(1); return false; } diff --git a/src/main/java/TP2/asd/toLLVM_Visitor.java b/src/main/java/TP2/asd/toLLVM_Visitor.java index 1b2bec2..16a1887 100644 --- a/src/main/java/TP2/asd/toLLVM_Visitor.java +++ b/src/main/java/TP2/asd/toLLVM_Visitor.java @@ -96,7 +96,11 @@ public class toLLVM_Visitor implements ProgramVisitor, @Override public DefineLLVMImp visitPrototype(PrototypeImp fun, SymTable h) { - return new DefineLLVMImp(fun.nom(), fun.type().accept(this, h), null,null); + ArrayList params = new ArrayList<>(); + for(VarImp param: fun.params()){ + params.add(new VarLLVMImp(new IntLLVMImp(),param.name(),false)); + } + return new DefineLLVMImp(fun.nom(), fun.type().accept(this, h), params,null); } //DECLARATION @@ -196,6 +200,10 @@ public class toLLVM_Visitor implements ProgramVisitor, ArrayList result = new ArrayList<>(); result.addAll(res.instrs); //InstructionLLVM r = new AssignLLVMImp(new VarLLVMImpl(var.getType(),instr.t()),var); + if(var.getType().getClass() != h.getType(instr.t()).getClass()){ + System.err.println("[VSL compile error] : Erreur de typage"); + System.exit(1); + } InstructionLLVM r = new StoreLLVMImp(var.getType(),var,new VarLLVMImp(var.getType(),h.getVar(instr.t()),false)); result.add(r); return result; diff --git a/tests/fragment0/add0 b/tests/fragment0/add0 index 517b2b78bf391dc2abf419b1382694cddd95b5d8..1fe91491c382b70918608594cef30c1553a17daa 100755 GIT binary patch delta 30 kcmZp;!PantZ371*Q>Irl7vpv=MnIrl7vpv=MnIrl7vpv=Mn%ITYoWXoddGAtDR@Ow*F$&ItOHJS3A#m%L4$lq72Od diff --git a/tests/fragment1/if1 b/tests/fragment1/if1 index 5f24bf09b210fe211cacd3e306ce58a0d436e309..8b0242b84542b5d878c73b7f0359a4f5eab25463 100755 GIT binary patch delta 30 kcmZp;!PantZ371*Q=V5d7vpv=Mn!GSt6gNg diff --git a/tests/fragment1/sequence b/tests/fragment1/sequence index 8d21d2f27ff44f93adb65f42ed83bf1e3b3d35a3..5c8c446c8e1881af4bd866bd1af0ff9bb05227a8 100755 GIT binary patch delta 27 icmZqJ!qKpWW5N%nLa)YOTYoWXT>!GSt6gNg!GSt6gNgI~rk diff --git a/tests/fragment2/call2 b/tests/fragment2/call2 index 61f7b7d95cd87371e9b2027524604337bbd9b686..38e42ae268d19ad5cfb903928544eae0ac1817f1 100755 GIT binary patch delta 27 icmZqJ!qKpWW5N%nBCp0@TYoWXT>!GSt6gNgI~rk diff --git a/tests/fragment2/call3expr b/tests/fragment2/call3expr index 0e863ae26a0b6b540883213ecf25ebb1780b879e..55ae6e53666e2c97264c08baaa62dca3af458172 100755 GIT binary patch delta 27 icmZqJ!qKpWW5N%nBCp0@TYoWXT>!GSt6gNg!GSt6gNg!GSt6gNg!GSt6gNg!GSt6gNg!GSt6gNg