correction bug pour SemanticError

This commit is contained in:
Rochas
2025-04-30 18:07:59 +02:00
parent 5a86f474bc
commit d6301bad2d
41 changed files with 28 additions and 7 deletions

6
NULL
View File

@@ -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.

View File

@@ -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();

View File

@@ -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<String, ValueVarMap> 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;
}

View File

@@ -96,7 +96,11 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
@Override
public DefineLLVMImp visitPrototype(PrototypeImp fun, SymTable h) {
return new DefineLLVMImp(fun.nom(), fun.type().accept(this, h), null,null);
ArrayList<VarLLVMImp> 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<SymTable,ProgramLLVMImp>,
ArrayList<InstructionLLVM> 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;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.