print et read fini !

This commit is contained in:
Rochas
2025-04-29 00:50:56 +02:00
parent 291bc96079
commit bd56995d63
8 changed files with 70 additions and 24 deletions

View File

@@ -30,7 +30,7 @@ public interface Interface {
public S visitAssignLLVM(AssignLLVMImp instr, H h);
public S visitStoreLLVM(StoreLLVMImp instr, H h);
public S visitPrintLLVM(PrintLLVMImp instr, H h);
public S visitReadLLVM(ReadLLVMImp instr, H h);
public S visitScanLLVM(ScanLLVMImp instr, H h);
public S visitLabelLLVM(LabelLLVMImp instr, H h);
public S visitBrLLVM(BrLLVMImp instr, H h);
public S visitBrCondLLVM(BrCondLLVMImp instr, H h);

View File

@@ -139,12 +139,12 @@ TypeLLVMVisitor<String,String>
@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, new ArrayList<>(),"(i8*,...) ");
CallLLVMImp callPrint = new CallLLVMImp(printLLVM, instr.l(),"(i8*,...) ");
return callPrint.accept(this, h);
}
@Override
public String visitReadLLVM(ReadLLVMImp instr, String h) { //TODO
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*,...) ");
return callRead.accept(this, h);
@@ -153,8 +153,8 @@ TypeLLVMVisitor<String,String>
@Override
public String visitDeclarGlobalLLVM(DeclarGlobalLLVMImp instr, String h) {
String str = "@."+instr.var().nom() + " = global";
str += " [" + instr.type().accept(this, h)+ "x"+ instr.size()+ "] ";
str+= "c\"\"\n";
str += " [" + instr.size() + " x "+ instr.type().accept(this, h) + "] ";
str+= "c\""+ instr.str()+"\"\n";
return str;
}

View File

@@ -88,15 +88,15 @@ public class ProgramLLVM {
}
}
public static record ReadLLVMImp(DeclarGlobalLLVMImp fmt,ArrayList<ValLLVM> l) implements InstructionLLVM{
public static record ScanLLVMImp(DeclarGlobalLLVMImp fmt,ArrayList<ValLLVM> l) implements InstructionLLVM{
@Override
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
return v.visitReadLLVM(this, h);
return v.visitScanLLVM(this, h);
}
}
public static record DeclarGlobalLLVMImp(VarLLVMImp var,TypeLLVM type, int size) implements InstructionLLVM{
public static record DeclarGlobalLLVMImp(VarLLVMImp var,TypeLLVM type,String str, int size) implements InstructionLLVM{
@Override
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {