correction Call et CallVoid avec print et read + clean
This commit is contained in:
@@ -76,7 +76,7 @@ TypeLLVMVisitor<String,String>
|
||||
|
||||
@Override
|
||||
public String visitCallVoidLLVM(CallVoidLLVMImp instr, String h) {
|
||||
String str = INDENT+ "call " + instr.str() + instr.f().type().accept(this, h) + " @"+instr.f().name() + "(";
|
||||
String str = INDENT+ "call " + instr.f().type().accept(this, h) + " " + instr.str() + " @"+instr.f().name() + "(";
|
||||
for(int i = 0; i<instr.params().size(); i++){
|
||||
str += instr.params().get(i).getType().accept(this, h) + " " + instr.params().get(i).accept(this,h);
|
||||
if(i<instr.params().size()-1) str += ", ";
|
||||
@@ -84,6 +84,17 @@ TypeLLVMVisitor<String,String>
|
||||
return str + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitCallLLVM(CallLLVMImp instr, String h) {
|
||||
String str = "call " + instr.f().type().accept(this, h) + " " + instr.str() + " @" + instr.f().name() + "(";
|
||||
|
||||
for (int i = 0; i < instr.params().size(); i++) {
|
||||
str += instr.params().get(i).getType().accept(this, h) + " " + instr.params().get(i).accept(this, h);
|
||||
if (i < instr.params().size() - 1) str += ", ";
|
||||
}
|
||||
return str + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitBinOpLLVM(BinOpLLVMImp e, String h) {
|
||||
String str = "";
|
||||
@@ -130,28 +141,18 @@ TypeLLVMVisitor<String,String>
|
||||
return "load" + " " + e.getType().accept(this, h) + ", "+ e.getType().accept(this, h) + "* " + e.val().accept(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitCallLLVM(CallLLVMImp instr, String h) {
|
||||
String str = "call " + instr.f().type().accept(this, h) + " (" + instr.str() + ") @" + instr.f().name() + "(";
|
||||
|
||||
for (int i = 0; i < instr.params().size(); i++) {
|
||||
str += instr.params().get(i).getType().accept(this, h) + " " + instr.params().get(i).accept(this, h);
|
||||
if (i < instr.params().size() - 1) str += ", ";
|
||||
}
|
||||
return str + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPrintLLVM(PrintLLVMImp instr, String h) { //TODO
|
||||
DefineLLVMImp printLLVM = new DefineLLVMImp("printf", new IntLLVMImp(), new ArrayList<>(), new ArrayList<>());
|
||||
CallLLVMImp callPrint = new CallLLVMImp(printLLVM, instr.l(),"i8*, ...");
|
||||
CallVoidLLVMImp callPrint = new CallVoidLLVMImp(printLLVM, instr.l(),"(i8*, ...)");
|
||||
return callPrint.accept(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitScanLLVM(ScanLLVMImp instr, String h) { //TODO
|
||||
DefineLLVMImp readLLVM = new DefineLLVMImp("scanf", new IntLLVMImp(), new ArrayList<>(), new ArrayList<>());
|
||||
CallLLVMImp callRead = new CallLLVMImp(readLLVM, instr.l(),"i8*, ...");
|
||||
CallVoidLLVMImp callRead = new CallVoidLLVMImp(readLLVM, instr.l(),"(i8*, ...)");
|
||||
return callRead.accept(this, h);
|
||||
}
|
||||
|
||||
@@ -211,8 +212,7 @@ TypeLLVMVisitor<String,String>
|
||||
|
||||
@Override
|
||||
public String visitCharLLVM(CharLLVMImp e, String h) {
|
||||
if(e.isString()) return "i8*";
|
||||
else return "i8";
|
||||
return "i8";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -218,7 +218,7 @@ public class ProgramLLVM {
|
||||
}
|
||||
}
|
||||
|
||||
public static record CharLLVMImp(Boolean isString) implements TypeLLVM{
|
||||
public static record CharLLVMImp() implements TypeLLVM{
|
||||
@Override
|
||||
public <H, S> S accept(TypeLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitCharLLVM(this, h);
|
||||
|
||||
Reference in New Issue
Block a user