correction bug pour SemanticError
This commit is contained in:
6
NULL
6
NULL
@@ -1,4 +1,4 @@
|
|||||||
tests\testsAdvanced\portee3.ll:20:4: error: multiple definition of local value named 'null'
|
tests\testsAdvanced\hanoi.ll:62:1: error: expected instruction opcode
|
||||||
20 | %null = alloca i32
|
62 | fi3:
|
||||||
| ^
|
| ^
|
||||||
1 error generated.
|
1 error generated.
|
||||||
|
|||||||
@@ -62,12 +62,14 @@ public class Main {
|
|||||||
|
|
||||||
// Pretty-print the program (to debug parsing)
|
// Pretty-print the program (to debug parsing)
|
||||||
|
|
||||||
|
if(!TESTAUTOMOD) System.out.println("\nVSL:\n");
|
||||||
|
|
||||||
if(!TESTAUTOMOD) System.out.println(ast.prettyprinter());
|
if(!TESTAUTOMOD) System.out.println(ast.prettyprinter());
|
||||||
|
|
||||||
// Verify the program semantic
|
// Verify the program semantic
|
||||||
|
|
||||||
// Generate the intermediate representation
|
// Generate the intermediate representation
|
||||||
if(!TESTAUTOMOD) System.out.println("\n\n");
|
if(!TESTAUTOMOD) System.out.println("\nLLVM:\n");
|
||||||
|
|
||||||
ProgramLLVMImp astLLVM = ast.toLLVM();
|
ProgramLLVMImp astLLVM = ast.toLLVM();
|
||||||
|
|
||||||
|
|||||||
@@ -85,19 +85,27 @@ public class SymTable {
|
|||||||
public SymTable addFunction(DefineLLVMImp function, Boolean isProto){
|
public SymTable addFunction(DefineLLVMImp function, Boolean isProto){
|
||||||
ValueFunMap value = this.functionsMap.get(function.name());
|
ValueFunMap value = this.functionsMap.get(function.name());
|
||||||
if(value == null || (value!=null && value.isProto && !isProto)){
|
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);
|
return new SymTable(this.varMap, this.functionsMap.plus(function.name(),new ValueFunMap(function,isProto)), this.id,this.declarationsGlobal);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(value.isProto) System.err.println("[VSL compile error] : Le prototype '"+function.name()+"()' existe déjà");
|
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 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à");
|
else System.err.println("[VSL compile error] : La fonction '"+function.name()+"()' existe déjà");
|
||||||
|
System.exit(1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueFunMap getFunction(String name){
|
public ValueFunMap getFunction(String name){
|
||||||
ValueFunMap f = this.functionsMap.get(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;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +154,8 @@ public class SymTable {
|
|||||||
PMap<String, ValueVarMap> top = varMap.get(0);
|
PMap<String, ValueVarMap> top = varMap.get(0);
|
||||||
if (top.containsKey(nomVar)) {
|
if (top.containsKey(nomVar)) {
|
||||||
if(!top.get(nomVar).isParam){ //si non on écrase, on a plus besoin du param après
|
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);
|
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.err.println("[VSL compile error] : '" + nomVar + "' n'a pas été déclaré");
|
||||||
|
System.exit(1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +192,7 @@ public class SymTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.err.println("[VSL compile error] : '" + nomVar+"' n'est pas trouvé");
|
System.err.println("[VSL compile error] : '" + nomVar+"' n'est pas trouvé");
|
||||||
|
System.exit(1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefineLLVMImp visitPrototype(PrototypeImp fun, SymTable h) {
|
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
|
//DECLARATION
|
||||||
@@ -196,6 +200,10 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
||||||
result.addAll(res.instrs);
|
result.addAll(res.instrs);
|
||||||
//InstructionLLVM r = new AssignLLVMImp(new VarLLVMImpl(var.getType(),instr.t()),var);
|
//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));
|
InstructionLLVM r = new StoreLLVMImp(var.getType(),var,new VarLLVMImp(var.getType(),h.getVar(instr.t()),false));
|
||||||
result.add(r);
|
result.add(r);
|
||||||
return result;
|
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.
Reference in New Issue
Block a user