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

@@ -161,10 +161,32 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
String name = h.getGlobalDeclName();
VarLLVMImp varGlobal = new VarLLVMImp(new CharLLVMImp(true),name,true);
DeclarGlobalLLVMImp globalDecl = new DeclarGlobalLLVMImp(varGlobal,new CharLLVMImp(false),0); //TODO
h.addGlobalDecl(globalDecl);
params.add(varGlobal);
String strGlobal = "";
int size = 1; //le \00 est focément à la fin et compte comme un seul char
for(int i = 0; i<instr.t().size(); i++){
Object obj = instr.t().get(i);
if(obj instanceof String){
String str = (String)obj;
size+=str.length(); //on compte avant car \0A compte pour 1 en LLVM, mais 3 pour java
str = str.replace("\n", "\\0A");
strGlobal+=str;
}
else if(obj instanceof Expression){
Expression exp = (Expression)obj;
InstrAndVal r = exp.accept(this, h);
l.addAll(r.instrs);
params.add(r.val);
strGlobal+="%d";
size+=2;
}
}
strGlobal+="\\00";
DeclarGlobalLLVMImp globalDecl = new DeclarGlobalLLVMImp(varGlobal,new CharLLVMImp(false),strGlobal,size); //TODO
h.addGlobalDecl(globalDecl);
l.add(new PrintLLVMImp(globalDecl,params));
return l;
@@ -173,22 +195,30 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
@Override
public ArrayList<InstructionLLVM> visitRead(ReadImp instr, SymTable h) {
ArrayList<InstructionLLVM> l = new ArrayList<>();
ArrayList<ValLLVM> params = new ArrayList<>();
String name = h.getGlobalDeclName();
VarLLVMImp varGlobal = new VarLLVMImp(new CharLLVMImp(true),name,true);
params.add(varGlobal);
String strGlobal = "";
int size = 1; //le \00 est focément à la fin et compte comme un seul char
for(int i = 0; i<instr.t().size(); i++){
String nomVar = h.getVar(instr.t().get(i).name());
Type typeVar = h.getType(instr.t().get(i).name());
VarLLVMImp newVar = new VarLLVMImp(typeVar.accept(this,h), nomVar,false);
ArrayList<ValLLVM> params = new ArrayList<>();
String name = h.getGlobalDeclName();
VarLLVMImp varGlobal = new VarLLVMImp(new CharLLVMImp(true),name,true);
DeclarGlobalLLVMImp globalDecl = new DeclarGlobalLLVMImp(varGlobal,new CharLLVMImp(false),0);//TODO
h.addGlobalDecl(globalDecl);
params.add(varGlobal);
strGlobal+="%d"; //2 char de long
size+=2;
params.add(newVar);
l.add(new ReadLLVMImp(globalDecl,params));
}
}
strGlobal+="\\00";
DeclarGlobalLLVMImp globalDecl = new DeclarGlobalLLVMImp(varGlobal,new CharLLVMImp(false),strGlobal,size);//TODO
h.addGlobalDecl(globalDecl);
l.add(new ScanLLVMImp(globalDecl,params));
return l;
}