Merge remote-tracking branch 'origin/main'
# Conflicts: # src/main/java/TP2/asd/Program.java
This commit is contained in:
@@ -61,8 +61,15 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
@Override
|
@Override
|
||||||
public String visitPrint(PrintImp instr, String indent) {
|
public String visitPrint(PrintImp instr, String indent) {
|
||||||
String str = indent + "PRINT ";
|
String str = indent + "PRINT ";
|
||||||
for (String elem: instr.t()){
|
for(int i = 0; i<instr.t().size(); i++){
|
||||||
str += "\"" +elem +"\"";
|
String g = "";
|
||||||
|
Object o = instr.t().get(i);
|
||||||
|
if(o instanceof String){
|
||||||
|
str += "\"" + instr.t().get(i) +"\"";
|
||||||
|
}
|
||||||
|
else if(o instanceof Expression){
|
||||||
|
str += g + ((Expression)instr.t().get(i)).accept(this,"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import TP2.asd.Interface.*;
|
|||||||
import TP2.llvm.ProgramLLVM.*;
|
import TP2.llvm.ProgramLLVM.*;
|
||||||
|
|
||||||
public class Program{
|
public class Program{
|
||||||
|
|
||||||
//Prog
|
//Prog
|
||||||
public static record ProgramImp(ArrayList<Function> fonctions) implements ProgramI{
|
public static record ProgramImp(ArrayList<Function> fonctions) implements ProgramI{
|
||||||
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
||||||
@@ -84,7 +85,7 @@ public class Program{
|
|||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||||
return v.visitRead(this, h);
|
return v.visitRead(this, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Type
|
//Type
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import TP2.llvm.ProgramLLVM.*;
|
|||||||
public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>,
|
public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>,
|
||||||
FunctionVisitor<SymTable,DefineLLVM>,
|
FunctionVisitor<SymTable,DefineLLVM>,
|
||||||
InstrVisitor<SymTable,ArrayList<InstructionLLVM>>,
|
InstrVisitor<SymTable,ArrayList<InstructionLLVM>>,
|
||||||
ExprVisitor<SymTable,TP2.asd.toLLVM_Visitor.InstrOrVal>,
|
ExprVisitor<SymTable,TP2.asd.toLLVM_Visitor.InstrAndVal>,
|
||||||
TypeVisitor<SymTable,TypeLLVM>
|
TypeVisitor<SymTable,TypeLLVM>
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -21,13 +21,13 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
toLLVM ne renvoit pas la même chose si l'expression est
|
toLLVM ne renvoit pas la même chose si l'expression est
|
||||||
une simplement un val (var ou const) ou un binop
|
une simplement un val (var ou const) ou un binop
|
||||||
*/
|
*/
|
||||||
public static class InstrOrVal{
|
public static class InstrAndVal{
|
||||||
public ArrayList<AssignLVMImp> instr = null;
|
public ArrayList<AssignLVMImp> instr = null;
|
||||||
public ValLLVM val = null;
|
public ValLLVM val = null;
|
||||||
|
|
||||||
public InstrOrVal(ArrayList<AssignLVMImp> instr, ValLLVM val){
|
public InstrAndVal(ArrayList<AssignLVMImp> instr, ValLLVM val){
|
||||||
this.instr = instr;
|
this.instr = instr;
|
||||||
this.val = instr.getLast().var();
|
this.val = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<InstructionLLVM> visitReturn(Return_instrImp instr, SymTable h) {
|
public ArrayList<InstructionLLVM> visitReturn(Return_instrImp instr, SymTable h) {
|
||||||
InstrOrVal res = instr.e().accept(this,h);
|
InstrAndVal res = instr.e().accept(this,h);
|
||||||
ValLLVM var = res.val;
|
ValLLVM var = res.val;
|
||||||
|
|
||||||
InstructionLLVM r = new ReturnLLVMImp(var.getType(),var);
|
InstructionLLVM r = new ReturnLLVMImp(var.getType(),var);
|
||||||
@@ -70,7 +70,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<InstructionLLVM> visitAssign(AssignImp instr, SymTable h) {
|
public ArrayList<InstructionLLVM> visitAssign(AssignImp instr, SymTable h) {
|
||||||
InstrOrVal 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<>();
|
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
||||||
result.addAll(res.instr);
|
result.addAll(res.instr);
|
||||||
@@ -93,8 +93,9 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<InstructionLLVM> visitPrint(PrintImp instr, SymTable h) {
|
public ArrayList<InstructionLLVM> visitPrint(PrintImp instr, SymTable h) {
|
||||||
// TODO Auto-generated method stub
|
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'visitPrint'");
|
l.add(new PrintLLVMImp(new ArrayList())); //TODO
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,23 +107,23 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
//EXPRESSION
|
//EXPRESSION
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InstrOrVal visitConst(ConstImp e, SymTable h) {
|
public InstrAndVal visitConst(ConstImp e, SymTable h) {
|
||||||
ValLLVM val = new ValLLVMImpl(new IntLLVMImpl(),e.c());
|
ValLLVM val = new ValLLVMImpl(new IntLLVMImpl(),e.c());
|
||||||
return new InstrOrVal(new ArrayList<>(), val);
|
return new InstrAndVal(new ArrayList<>(), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InstrOrVal visitVar(VarImp e, SymTable h) {
|
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
||||||
ValLLVM val = new VarLLVMImpl(new IntLLVMImpl(), e.name());
|
ValLLVM val = new VarLLVMImpl(new IntLLVMImpl(), e.name());
|
||||||
return new InstrOrVal(new ArrayList<>(), val);
|
return new InstrAndVal(new ArrayList<>(), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InstrOrVal visitBinOp(BinopExpressionImp e, SymTable h) {
|
public InstrAndVal visitBinOp(BinopExpressionImp e, SymTable h) {
|
||||||
ArrayList<AssignLVMImp> list = new ArrayList<>();
|
ArrayList<AssignLVMImp> list = new ArrayList<>();
|
||||||
|
|
||||||
InstrOrVal res1 = e.e1().accept(this, h);
|
InstrAndVal res1 = e.e1().accept(this, h);
|
||||||
InstrOrVal res2 = e.e2().accept(this, h);
|
InstrAndVal res2 = e.e2().accept(this, h);
|
||||||
|
|
||||||
ValLLVM val1 = res1.val;
|
ValLLVM val1 = res1.val;
|
||||||
ValLLVM val2 = res2.val;
|
ValLLVM val2 = res2.val;
|
||||||
@@ -139,7 +140,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
VarLLVMImpl var = new VarLLVMImpl(type,temp);
|
VarLLVMImpl var = new VarLLVMImpl(type,temp);
|
||||||
list.add(new AssignLVMImp(var, new BinOpLLVMImp(type,e.op(),val1,val2)));
|
list.add(new AssignLVMImp(var, new BinOpLLVMImp(type,e.op(),val1,val2)));
|
||||||
|
|
||||||
return new InstrOrVal(list, var);
|
return new InstrAndVal(list, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public interface Interface {
|
|||||||
public S visitReturnLLVM(ReturnLLVMImp instr, H h);
|
public S visitReturnLLVM(ReturnLLVMImp instr, H h);
|
||||||
public S visitAssignLLVM(AssignLVMImp instr, H h);
|
public S visitAssignLLVM(AssignLVMImp 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 visitReadLLVM(ReadLLVMImp instr, H h);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////ExpressionLLVM (expression)
|
//////////ExpressionLLVM (expression)
|
||||||
|
|||||||
@@ -100,6 +100,17 @@ TypeLLVMVisitor<String,String>
|
|||||||
return "load" + " i" + e.nbBits() + ", i"+ e.nbBits2() + "* %" + e.val().accept(this, h);
|
return "load" + " i" + e.nbBits() + ", i"+ e.nbBits2() + "* %" + e.val().accept(this, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String visitPrintLLVM(PrintLLVMImp instr, String h) {
|
||||||
|
return INDENT+"print";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String visitReadLLVM(ReadLLVMImp instr, String h) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'visitReadLLVM'");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visitValLLVM(ValLLVMImpl e, String h) {
|
public String visitValLLVM(ValLLVMImpl e, String h) {
|
||||||
return e.val() + "";
|
return e.val() + "";
|
||||||
@@ -121,4 +132,5 @@ TypeLLVMVisitor<String,String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,21 @@ public class ProgramLLVM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static record PrintLLVMImp(ArrayList<String> l) implements InstructionLLVM{
|
||||||
|
@Override
|
||||||
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
|
return v.visitPrintLLVM(this, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static record ReadLLVMImp(ArrayList<String> l) implements InstructionLLVM{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
|
return v.visitReadLLVM(this, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//Expression :
|
//Expression :
|
||||||
public static record BinOpLLVMImp(TypeLLVM type,Op op, ValLLVM val1,ValLLVM val2) implements ExpressionLLVM{
|
public static record BinOpLLVMImp(TypeLLVM type,Op op, ValLLVM val1,ValLLVM val2) implements ExpressionLLVM{
|
||||||
|
|||||||
Reference in New Issue
Block a user