test call void
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package TP2.Error;
|
||||
/*package TP2.Error;
|
||||
|
||||
import TP2.asd.SymTable;
|
||||
import TP2.asd.Program.*;
|
||||
@@ -164,3 +164,4 @@ public class TypeChecking {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -53,6 +53,7 @@ public interface Interface{
|
||||
public S visitIfThen(IfThenImp instr, H h);
|
||||
public S visitIfThenElse(IfThenElseImp instr, H h);
|
||||
public S visitWhile(WhileImp instr, H h);
|
||||
public S visitVoidFunction(VoidFunctionImp instr, H h);
|
||||
}
|
||||
|
||||
//EXPRESSION
|
||||
|
||||
@@ -156,17 +156,19 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitAppeal(AppealImp instr,String indent){
|
||||
String str = indent + instr.fName() + "(";
|
||||
for(int i=0; i<instr.params().size();i++){
|
||||
str += instr.params().get(i).accept(this, "");
|
||||
if(i<instr.params().size()-1) str += ",";
|
||||
public String visitVoidFunction(VoidFunctionImp instr, String h) {
|
||||
String str = instr.nom()+ "( ";
|
||||
for(int i=0;i<instr.expr().size();i++){
|
||||
str+= instr.expr().get(i).accept(this,h);
|
||||
if(i<instr.expr().size()-1){
|
||||
str+=", ";
|
||||
}
|
||||
}
|
||||
return str+")";
|
||||
str+=")";
|
||||
return str;
|
||||
}
|
||||
|
||||
//EXPRESSION
|
||||
|
||||
@Override
|
||||
public String visitConst(ConstImp e, String indent) {
|
||||
return e.c()+"";
|
||||
@@ -186,6 +188,17 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
return "(" + e.e1().accept(this,"") +" "+ opStr +" " + e.e2().accept(this,"") + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitAppeal(AppealImp instr,String indent){
|
||||
String str = indent + instr.fName() + "(";
|
||||
for(int i=0; i<instr.params().size();i++){
|
||||
str += instr.params().get(i).accept(this, "");
|
||||
if(i<instr.params().size()-1) str += ",";
|
||||
}
|
||||
return str+")";
|
||||
}
|
||||
|
||||
|
||||
//TYPE
|
||||
|
||||
@Override
|
||||
|
||||
@@ -137,6 +137,13 @@ public class Program{
|
||||
}
|
||||
}
|
||||
|
||||
public static record VoidFunctionImp(String nom, ArrayList<Expression> expr) implements Instruction{
|
||||
@Override
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitVoidFunction(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
//Type
|
||||
public static record Type_voidImp() implements Type{
|
||||
@Override
|
||||
|
||||
@@ -185,6 +185,30 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitVoidFunction(VoidFunctionImp instr, SymTable h) {
|
||||
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||
ArrayList<ValLLVM> paramsLLVM = new ArrayList<>();
|
||||
|
||||
for(Expression param: instr.expr()){
|
||||
InstrAndVal result = param.accept(this, h);
|
||||
l.addAll(result.instrs);
|
||||
paramsLLVM.add(result.val);
|
||||
}
|
||||
ValueFunMap fun= h.getFunction(instr.nom());
|
||||
if(fun == null){
|
||||
System.err.println("Function n'est pas trouvé");
|
||||
return l;
|
||||
}
|
||||
|
||||
if (!(fun.define.type() instanceof VoidLLVMImp)){
|
||||
System.err.println("Fonction n'est pas un void");
|
||||
}
|
||||
|
||||
l.add(new CallLLVMImp(fun.define,paramsLLVM,""));
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitIfThen(IfThenImp instr, SymTable h) {
|
||||
SymTable prevSymTable = h;
|
||||
|
||||
@@ -6,11 +6,16 @@ FUNC INT add(a,b) {
|
||||
RETURN z
|
||||
}
|
||||
|
||||
FUNC VOID affiche(x){
|
||||
PRINT x
|
||||
}
|
||||
|
||||
FUNC INT main(x,y) {
|
||||
INT a,b,c,minh
|
||||
x := 5
|
||||
minh := x * y
|
||||
b:=3
|
||||
affiche(b)
|
||||
c:=add(x,b)
|
||||
PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp","il manque virgule au milieu", c*5+b
|
||||
WHILE b - 1
|
||||
|
||||
Reference in New Issue
Block a user