Appeal, todo : corriger callLLVM
This commit is contained in:
@@ -96,7 +96,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
Result r = h.addVar(instr.s().get(i));
|
Result r = h.addVar(instr.s().get(i));
|
||||||
String name = r.var;
|
String name = r.var;
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
list.add(new AssignLVMImp(new VarLLVMImp(t2, name),new allocaLLVMImp(t2)));
|
list.add(new AssignLLVMImp(new VarLLVMImp(t2, name),new allocaLLVMImp(t2)));
|
||||||
}
|
}
|
||||||
prevSymTable.updateId(h);
|
prevSymTable.updateId(h);
|
||||||
return new InstrAndSymTable(list,h);
|
return new InstrAndSymTable(list,h);
|
||||||
@@ -145,9 +145,9 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<InstructionLLVM> visitAssign(AssignImp instr, SymTable h) {
|
public ArrayList<InstructionLLVM> visitAssign(AssignImp instr, SymTable h) {
|
||||||
|
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
||||||
InstrAndVal res = instr.e().accept(this,h);
|
InstrAndVal res = instr.e().accept(this,h);
|
||||||
ValLLVM var = res.val;
|
ValLLVM var = res.val;
|
||||||
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
|
||||||
result.addAll(res.instrs);
|
result.addAll(res.instrs);
|
||||||
//InstructionLLVM r = new AssignLVMImp(new VarLLVMImpl(var.getType(),instr.t()),var);
|
//InstructionLLVM r = new AssignLVMImp(new VarLLVMImpl(var.getType(),instr.t()),var);
|
||||||
InstructionLLVM r = new StoreLLVMImp(var.getType(),var,var.getType(),new VarLLVMImp(var.getType(),h.getVar(instr.t())));
|
InstructionLLVM r = new StoreLLVMImp(var.getType(),var,var.getType(),new VarLLVMImp(var.getType(),h.getVar(instr.t())));
|
||||||
@@ -194,7 +194,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
Result r = h.addNewTempVar();
|
Result r = h.addNewTempVar();
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
VarLLVMImp varCond = new VarLLVMImp(exTemp.getType(), r.var);
|
VarLLVMImp varCond = new VarLLVMImp(exTemp.getType(), r.var);
|
||||||
l.add(new AssignLVMImp(varCond,exTemp));
|
l.add(new AssignLLVMImp(varCond,exTemp));
|
||||||
l.add(new BrCondLLVMImp(varCond,labelThen,labelFin));
|
l.add(new BrCondLLVMImp(varCond,labelThen,labelFin));
|
||||||
|
|
||||||
l.add(new LabelLLVMImp(labelThen));
|
l.add(new LabelLLVMImp(labelThen));
|
||||||
@@ -222,7 +222,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
Result r = h.addNewTempVar();
|
Result r = h.addNewTempVar();
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
VarLLVMImp varCond = new VarLLVMImp(exTemp.getType(), r.var);
|
VarLLVMImp varCond = new VarLLVMImp(exTemp.getType(), r.var);
|
||||||
l.add(new AssignLVMImp(varCond,exTemp));
|
l.add(new AssignLLVMImp(varCond,exTemp));
|
||||||
l.add(new BrCondLLVMImp(varCond,labelThen,labelElse));
|
l.add(new BrCondLLVMImp(varCond,labelThen,labelElse));
|
||||||
|
|
||||||
l.add(new LabelLLVMImp(labelThen));
|
l.add(new LabelLLVMImp(labelThen));
|
||||||
@@ -256,7 +256,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
Result r = h.addNewTempVar();
|
Result r = h.addNewTempVar();
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
VarLLVMImp varCond = new VarLLVMImp(exTemp.getType(), r.var);
|
VarLLVMImp varCond = new VarLLVMImp(exTemp.getType(), r.var);
|
||||||
l.add(new AssignLVMImp(varCond,exTemp));
|
l.add(new AssignLLVMImp(varCond,exTemp));
|
||||||
l.add(new BrCondLLVMImp(varCond,labelDo,labelDone));
|
l.add(new BrCondLLVMImp(varCond,labelDo,labelDone));
|
||||||
|
|
||||||
l.add(new LabelLLVMImp(labelDo));
|
l.add(new LabelLLVMImp(labelDo));
|
||||||
@@ -286,7 +286,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
Result r = h.addNewTempVar();
|
Result r = h.addNewTempVar();
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
VarLLVMImp varTemp = new VarLLVMImp(h.getvar_Type(e.name()).accept(this,h),r.var);
|
VarLLVMImp varTemp = new VarLLVMImp(h.getvar_Type(e.name()).accept(this,h),r.var);
|
||||||
l.add(new AssignLVMImp(varTemp,((ExpressionLLVM)(new LoadLLVMImp(val)))));
|
l.add(new AssignLLVMImp(varTemp,((ExpressionLLVM)(new LoadLLVMImp(val)))));
|
||||||
prevSymTable.updateId(h);
|
prevSymTable.updateId(h);
|
||||||
return new InstrAndVal(l, varTemp);
|
return new InstrAndVal(l, varTemp);
|
||||||
}
|
}
|
||||||
@@ -313,17 +313,18 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
String temp = r.var;
|
String temp = r.var;
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
VarLLVMImp var = new VarLLVMImp(type,temp);
|
VarLLVMImp var = new VarLLVMImp(type,temp);
|
||||||
list.add(new AssignLVMImp(var, new BinOpLLVMImp(type,e.op(),val1,val2)));
|
list.add(new AssignLLVMImp(var, new BinOpLLVMImp(type,e.op(),val1,val2)));
|
||||||
prevSymTable.updateId(h);
|
prevSymTable.updateId(h);
|
||||||
return new InstrAndVal(list, var);
|
return new InstrAndVal(list, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InstrAndVal visitAppeal(AppealImp instr,SymTable h){
|
public InstrAndVal visitAppeal(AppealImp instr,SymTable h){
|
||||||
|
SymTable prevSymTable = h;
|
||||||
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||||
ArrayList<ValLLVM> paramsLLVM = new ArrayList<>();
|
ArrayList<ValLLVM> paramsLLVM = new ArrayList<>();
|
||||||
for(Expression param : instr.params()){
|
for(Expression param : instr.params()){
|
||||||
InstrAndVal result = param.accept(this,h);
|
InstrAndVal result = param.accept(this,h);
|
||||||
l.add((InstructionLLVM) result.instrs);
|
l.addAll(result.instrs);
|
||||||
paramsLLVM.add(result.val);
|
paramsLLVM.add(result.val);
|
||||||
}
|
}
|
||||||
ValueFunMap fLLVM = h.getFunction(instr.fName()); //on récupère la fonction LLVM dans la table des Symboles
|
ValueFunMap fLLVM = h.getFunction(instr.fName()); //on récupère la fonction LLVM dans la table des Symboles
|
||||||
@@ -331,7 +332,13 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
System.err.println("[VSL compile error] : la fonction n'existe pas, veuillez vous assurer de l'avoir déclarée avant l'appel");
|
System.err.println("[VSL compile error] : la fonction n'existe pas, veuillez vous assurer de l'avoir déclarée avant l'appel");
|
||||||
}
|
}
|
||||||
l.add(new CallLLVMImp(fLLVM.define,paramsLLVM,""));
|
l.add(new CallLLVMImp(fLLVM.define,paramsLLVM,""));
|
||||||
return new InstrAndVal(l, null);
|
|
||||||
|
//TODO Call est une expression
|
||||||
|
Result r = h.addNewTempVar();
|
||||||
|
ValLLVM val = new VarLLVMImp(new IntLLVMImp(),r.var);
|
||||||
|
h = r.symTable;
|
||||||
|
prevSymTable.updateId(h);
|
||||||
|
return new InstrAndVal(l, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public interface Interface {
|
|||||||
|
|
||||||
public interface InstructionLLVMVisitor<H,S> {
|
public interface InstructionLLVMVisitor<H,S> {
|
||||||
public S visitReturnLLVM(ReturnLLVMImp instr, H h);
|
public S visitReturnLLVM(ReturnLLVMImp instr, H h);
|
||||||
public S visitAssignLLVM(AssignLVMImp instr, H h);
|
public S visitAssignLLVM(AssignLLVMImp instr, H h);
|
||||||
public S visitStoreLLVM(StoreLLVMImp instr, H h);
|
public S visitStoreLLVM(StoreLLVMImp instr, H h);
|
||||||
public S visitPrintLLVM(PrintLLVMImp instr, H h);
|
public S visitPrintLLVM(PrintLLVMImp instr, H h);
|
||||||
public S visitReadLLVM(ReadLLVMImp instr, H h);
|
public S visitReadLLVM(ReadLLVMImp instr, H h);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ TypeLLVMVisitor<String,String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visitAssignLLVM(AssignLVMImp instr, String h) {
|
public String visitAssignLLVM(AssignLLVMImp instr, String h) {
|
||||||
return INDENT+instr.var().accept(this, h) + " = " + instr.e().accept(this, h);
|
return INDENT+instr.var().accept(this, h) + " = " + instr.e().accept(this, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ProgramLLVM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static record AssignLVMImp(VarLLVMImp var, ExpressionLLVM e) implements InstructionLLVM{
|
public static record AssignLLVMImp(VarLLVMImp var, ExpressionLLVM e) implements InstructionLLVM{
|
||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
return v.visitAssignLLVM(this, h);
|
return v.visitAssignLLVM(this, h);
|
||||||
@@ -74,7 +74,7 @@ public class ProgramLLVM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record CallLLVMImp(DefineLLVMImp f, ArrayList<ValLLVM> params, String str) implements InstructionLLVM{
|
public static record CallLLVMImp(DefineLLVMImp f, ArrayList<ValLLVM> params, String str) implements InstructionLLVM{ //une expression ?
|
||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
return v.visitCallLLVM(this, h);
|
return v.visitCallLLVM(this, h);
|
||||||
@@ -110,19 +110,6 @@ public class ProgramLLVM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*public static record ConstLLVMImp(TypeLLVM type, int val) implements ExpressionLLVM{
|
|
||||||
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
||||||
return v.visitConstLLVM(this, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String prettyprinter() {
|
|
||||||
return val+"";
|
|
||||||
}
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
public static record allocaLLVMImp(TypeLLVM type) implements ExpressionLLVM{
|
public static record allocaLLVMImp(TypeLLVM type) implements ExpressionLLVM{
|
||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
||||||
@@ -171,6 +158,7 @@ public class ProgramLLVM {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeLLVM getType() {
|
public TypeLLVM getType() {
|
||||||
|
System.out.println("getType");
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,6 +172,7 @@ public class ProgramLLVM {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeLLVM getType() {
|
public TypeLLVM getType() {
|
||||||
|
System.out.println("getType");
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ FUNC INT main(x,y) {
|
|||||||
x := 5
|
x := 5
|
||||||
minh := x * y
|
minh := x * y
|
||||||
b:=3
|
b:=3
|
||||||
|
c:=3
|
||||||
c:=add(x,b)
|
c:=add(x,b)
|
||||||
PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp","il manque virgule au milieu", c*5+b
|
PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp","il manque virgule au milieu", c*5+b
|
||||||
WHILE b - 1
|
WHILE b - 1
|
||||||
|
|||||||
Reference in New Issue
Block a user