test unimplant
This commit is contained in:
@@ -114,13 +114,13 @@ instruction returns [Instruction out]:
|
|||||||
})*
|
})*
|
||||||
{$out = new ReadImp(read);}
|
{$out = new ReadImp(read);}
|
||||||
| //IF THEN ELSE FIN
|
| //IF THEN ELSE FIN
|
||||||
IF ex1=expression THEN ins1=instruction
|
IF ex1=expression THEN ins1=list_instr
|
||||||
(FIN
|
(FIN
|
||||||
{$out= new IfThenImp($ex1.out, $ins1.out);}
|
{$out= new IfThenImp($ex1.out, $ins1.out);}
|
||||||
| ELSE ins2=instruction FIN
|
| ELSE ins2=list_instr FIN
|
||||||
{$out= new IfThenElseImp($ex1.out, $ins1.out,$ins2.out); }
|
{$out= new IfThenElseImp($ex1.out, $ins1.out,$ins2.out); }
|
||||||
)
|
)
|
||||||
| WHILE exp1=expression DO ins3=instruction DONE
|
| WHILE exp1=expression DO ins3=list_instr DONE
|
||||||
{$out = new WhileImp($exp1.out,$ins3.out);}
|
{$out = new WhileImp($exp1.out,$ins3.out);}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public interface Interface{
|
|||||||
public S visitProgram(ProgramImp prog, H h);
|
public S visitProgram(ProgramImp prog, H h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////Function
|
//////////Function
|
||||||
public interface Function {
|
public interface Function {
|
||||||
public <H,S> S accept(FunctionVisitor<H,S> v, H h);
|
public <H,S> S accept(FunctionVisitor<H,S> v, H h);
|
||||||
@@ -42,10 +41,7 @@ public interface Interface{
|
|||||||
public S visitWhile(WhileImp instr, H h);
|
public S visitWhile(WhileImp instr, H h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////Expression
|
//////////Expression
|
||||||
//We put prettyprinter here beause each expr will have to implement it like accept visitor
|
|
||||||
//but each implement will be different for prettyprinter
|
|
||||||
public interface Expression {
|
public interface Expression {
|
||||||
public <H,S> S accept(ExprVisitor<H,S> v, H h);
|
public <H,S> S accept(ExprVisitor<H,S> v, H h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,10 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
public String visitIfThen(IfThenImp instr, String indent) {
|
public String visitIfThen(IfThenImp instr, String indent) {
|
||||||
String str = indent + "IF ";
|
String str = indent + "IF ";
|
||||||
str +=(instr.e().accept(this, ""));
|
str +=(instr.e().accept(this, ""));
|
||||||
str +=" THEN " + (instr.i1().accept(this, ""));
|
str +=" THEN ";
|
||||||
|
for(int i=0; i<instr.i1().size();i++){
|
||||||
|
str+= instr.i1().get(i).accept(this, "");
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +89,14 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
public String visitIfThenElse(IfThenElseImp instr, String indent) {
|
public String visitIfThenElse(IfThenElseImp instr, String indent) {
|
||||||
String str = indent + "IF ";
|
String str = indent + "IF ";
|
||||||
str +=(instr.e().accept(this, ""));
|
str +=(instr.e().accept(this, ""));
|
||||||
str +=" THEN " + (instr.i1().accept(this, ""));
|
str +=" THEN ";
|
||||||
str +=" ELSE "+ (instr.i2().accept(this, ""));
|
for(int i=0; i<instr.i1().size();i++){
|
||||||
|
str+= instr.i1().get(i).accept(this, "");
|
||||||
|
}
|
||||||
|
str +=" ELSE ";
|
||||||
|
for(int i=0; i<instr.i2().size();i++){
|
||||||
|
str+= instr.i2().get(i).accept(this, "");
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +114,10 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
public String visitWhile(WhileImp instr, String indent) {
|
public String visitWhile(WhileImp instr, String indent) {
|
||||||
String str = indent+"WHILE ";
|
String str = indent+"WHILE ";
|
||||||
str += (instr.e().accept(this, ""));
|
str += (instr.e().accept(this, ""));
|
||||||
str+= " DO "+ (instr.i1().accept(this, ""));
|
str+= " DO ";
|
||||||
|
for(int i=0; i<instr.i1().size();i++){
|
||||||
|
str+= instr.i1().get(i).accept(this, "");
|
||||||
|
}
|
||||||
str+= " DONE";
|
str+= " DONE";
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,21 +88,21 @@ public class Program{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record IfThenImp(Expression e, Instruction i1) implements Instruction {
|
public static record IfThenImp(Expression e, ArrayList<Instruction> i1) implements Instruction {
|
||||||
@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.visitIfThen(this, h);
|
return v.visitIfThen(this, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record IfThenElseImp(Expression e, Instruction i1, Instruction i2) implements Instruction {
|
public static record IfThenElseImp(Expression e, ArrayList<Instruction> i1, ArrayList<Instruction> i2) implements Instruction {
|
||||||
@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.visitIfThenElse(this, h);
|
return v.visitIfThenElse(this, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record WhileImp(Expression e, Instruction i1) implements Instruction {
|
public static record WhileImp(Expression e, ArrayList<Instruction> i1) implements Instruction {
|
||||||
@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.visitWhile(this, h);
|
return v.visitWhile(this, h);
|
||||||
|
|||||||
@@ -85,10 +85,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
ArrayList<InstructionLLVM> list = new ArrayList<>();
|
ArrayList<InstructionLLVM> list = new ArrayList<>();
|
||||||
for(int i = 0; i<instr.s().size();i++){
|
for(int i = 0; i<instr.s().size();i++){
|
||||||
TypeLLVM t2 = instr.t().accept(this,h);
|
TypeLLVM t2 = instr.t().accept(this,h);
|
||||||
//String name = instr.s().get(i);//h.addVarLLVM(instr.s().get(i));
|
String name = instr.s().get(i);//h.addVarLLVM(instr.s().get(i));
|
||||||
Result r = h.addVar(instr.s().get(i));
|
|
||||||
String name = r.var;
|
|
||||||
h = r.symTable;
|
|
||||||
list.add(new AssignLVMImpl(new VarLLVMImpl(t2, name),new allocaLLVMImpl(t2)));
|
list.add(new AssignLVMImpl(new VarLLVMImpl(t2, name),new allocaLLVMImpl(t2)));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@@ -120,11 +117,10 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
throw new UnsupportedOperationException("Unimplemented method 'visitIfThenElse'");
|
throw new UnsupportedOperationException("Unimplemented method 'visitIfThenElse'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<InstructionLLVM> visitWhile(WhileImp instr, SymTable h) {
|
public ArrayList<InstructionLLVM> visitWhile(WhileImp instr, SymTable h) {
|
||||||
// TODO Auto-generated method stub
|
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'visitWhile'");
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
//EXPRESSION
|
//EXPRESSION
|
||||||
@@ -137,7 +133,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
||||||
ValLLVM val = new VarLLVMImpl(new IntLLVMImpl(), h.getVar(e.name()));
|
ValLLVM val = new VarLLVMImpl(new IntLLVMImpl(), e.name());
|
||||||
return new InstrAndVal(new ArrayList<>(), val);
|
return new InstrAndVal(new ArrayList<>(), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
package TP2.llvm;
|
package TP2.llvm;
|
||||||
|
import TP2.asd.Program.IfThenElseImp;
|
||||||
import TP2.llvm.ProgramLLVM.*;
|
import TP2.llvm.ProgramLLVM.*;
|
||||||
|
|
||||||
public interface Interface {
|
public interface Interface {
|
||||||
@@ -31,6 +32,9 @@ public interface Interface {
|
|||||||
public S visitStoreLLVM(StoreLLVMImpl instr, H h);
|
public S visitStoreLLVM(StoreLLVMImpl instr, H h);
|
||||||
public S visitPrintLLVM(PrintLLVMImpl instr, H h);
|
public S visitPrintLLVM(PrintLLVMImpl instr, H h);
|
||||||
public S visitReadLLVM(ReadLLVMImpl instr, H h);
|
public S visitReadLLVM(ReadLLVMImpl instr, H h);
|
||||||
|
public S visitIfThenElseLLVM(IfThenElseImp instr, H h);
|
||||||
|
public S visitIfThenLLVM(IfThenImp instr, H h);
|
||||||
|
public S visitWhileLLVM(WhileImp instr, H h);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////ExpressionLLVM (expression)
|
//////////ExpressionLLVM (expression)
|
||||||
|
|||||||
@@ -74,7 +74,33 @@ public class ProgramLLVM {
|
|||||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
return v.visitReadLLVM(this, h);
|
return v.visitReadLLVM(this, h);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static record IfThenLLVMImp() implements InstructionLLVM{
|
||||||
|
@Override
|
||||||
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'accept'");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static record IfThenElseLLVMImp() implements InstructionLLVM{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'accept'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static record WhileLLVMImp() implements InstructionLLVM{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'accept'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Expression :
|
//Expression :
|
||||||
|
|||||||
@@ -3,5 +3,9 @@ FUNC INT main() {
|
|||||||
b:=3
|
b:=3
|
||||||
c:=1
|
c:=1
|
||||||
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
|
||||||
READ a, b, n, t, m
|
IF 1 THEN a:=a+1 FI
|
||||||
|
IF 2 THEN b:=c+1 ELSE
|
||||||
|
b:=c+1
|
||||||
|
READ n, t,m
|
||||||
|
FI
|
||||||
RETURN 4 + 6 * 5 + 2 }
|
RETURN 4 + 6 * 5 + 2 }
|
||||||
Reference in New Issue
Block a user