toLLVM en visitor, todo : réparer la Declaration
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package TP2.asd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.plaf.synth.SynthLabelUI;
|
||||
|
||||
import TP2.asd.Interface.*;
|
||||
import TP2.llvm.ProgramLLVM.*;
|
||||
import TP2.llvm.Interface.*;
|
||||
@@ -24,11 +26,13 @@ public class Program{
|
||||
|
||||
@Override
|
||||
public ProgramLLVMImpl toLLVM() {
|
||||
ArrayList<DefineLLVM> fonctionLLVM = new ArrayList<>();
|
||||
/**ArrayList<DefineLLVM> fonctionLLVM = new ArrayList<>();
|
||||
for(int i = 0; i<fonctions.size(); i++){
|
||||
fonctionLLVM.add(fonctions.get(i).toLLVM());
|
||||
}
|
||||
return new ProgramLLVMImpl(new ArrayList<>(),fonctionLLVM);
|
||||
return new ProgramLLVMImpl(new ArrayList<>(),fonctionLLVM);*/
|
||||
toLLVM_Visitor llvmVisitor = new toLLVM_Visitor();
|
||||
return this.accept(llvmVisitor,new SymTable());
|
||||
}
|
||||
|
||||
|
||||
@@ -43,15 +47,6 @@ public class Program{
|
||||
public <H, S> S accept(FunctionVisitor<H, S> v, H h) {
|
||||
return v.visitFunction(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefineLLVM toLLVM() {
|
||||
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
||||
for(int i = 0; i<instructions.size(); i++){
|
||||
instrLLVM.addAll(instructions.get(i).toLLVM());
|
||||
}
|
||||
return new DefineLLVMImpl(nom, type.toLLVM(), instrLLVM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,14 +60,6 @@ public class Program{
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<AssignLVMImp> toLLVM() { //TODO
|
||||
// TODO Auto-generated method stub
|
||||
ArrayList<AssignLVMImp> list = new ArrayList<>();
|
||||
ValLLVM cLLVM = new ValLLVMImpl(new IntLLVMImpl(),c);
|
||||
list.add(new AssignLVMImp(new VarLLVMImpl(new IntLLVMImpl(),"todo"), cLLVM));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,32 +68,6 @@ public class Program{
|
||||
return v.visitBinOp(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<AssignLVMImp> toLLVM() { //TODO si e1 ou e2 est une constante, elle doit pouvoir être mise directement dans l'expression
|
||||
ArrayList<AssignLVMImp> list = new ArrayList<>();
|
||||
ValLLVM val1 = null;
|
||||
ValLLVM val2 = null;
|
||||
if(e1 instanceof Val){
|
||||
val1 = ((Val) e1).getValLLVM();
|
||||
}
|
||||
else {
|
||||
ArrayList<AssignLVMImp> eLLVM1 = e1.toLLVM();
|
||||
list.addAll(eLLVM1);
|
||||
val1 = eLLVM1.getLast().getVar();
|
||||
}
|
||||
if(e2 instanceof Val){
|
||||
val2 = ((Val) e2).getValLLVM();
|
||||
}
|
||||
else {
|
||||
ArrayList<AssignLVMImp> eLLVM2 = e2.toLLVM();
|
||||
list.addAll(eLLVM2);
|
||||
val2 = eLLVM2.getLast().getVar();
|
||||
}
|
||||
|
||||
list.add(new AssignLVMImp(new VarLLVMImpl(new IntLLVMImpl()/*TODO*/,"todo"), new BinOpLLVMImp(new IntLLVMImpl()/*TODO*/,op,val1,val2)));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -116,16 +77,6 @@ public class Program{
|
||||
return v.visitReturn(this,h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> toLLVM() {
|
||||
ArrayList<AssignLVMImp> list = e.toLLVM();
|
||||
InstructionLLVM r = new ReturnLLVMImp(new IntLLVMImpl()/*TODO*/,list.getLast().getVar());
|
||||
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
||||
result.addAll(list);
|
||||
result.add(r);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,30 +84,13 @@ public class Program{
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitAssign(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> toLLVM() {
|
||||
ArrayList<AssignLVMImp> list = e.toLLVM();
|
||||
InstructionLLVM r = new AssignLVMImp(new VarLLVMImpl(new IntLLVMImpl()/*TODO*/,t),list.getLast().getVar());
|
||||
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
||||
result.addAll(list);
|
||||
result.add(r);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static record DeclarationImp(Type t, ArrayList<String> s) implements Instruction{
|
||||
|
||||
@Override
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitDeclaration(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> toLLVM() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'toLLVM'");
|
||||
}
|
||||
}
|
||||
|
||||
//Type
|
||||
@@ -165,12 +99,6 @@ public class Program{
|
||||
public <H, S> S accept(TypeVisitor<H, S> v, H h) {
|
||||
return v.visitVoid(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeLLVM toLLVM() {
|
||||
return new IntLLVMImpl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -179,11 +107,6 @@ public class Program{
|
||||
public <H, S> S accept(TypeVisitor<H, S> v, H h) {
|
||||
return v.visitInt(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeLLVM toLLVM() {
|
||||
return new VoidLLVMImpl();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user