maj SymTable (id global) + DeclGlobal
This commit is contained in:
@@ -35,6 +35,7 @@ public interface Interface {
|
||||
public S visitBrLLVM(BrLLVMImp instr, H h);
|
||||
public S visitBrCondLLVM(BrCondLLVMImp instr, H h);
|
||||
public S visitCallVoidLLVM(CallVoidLLVMImp instr, H h);
|
||||
public S visitDeclarGlobalLLVM(DeclarGlobalLLVMImp instr, H h);
|
||||
}
|
||||
|
||||
//////////ExpressionLLVM (expression)
|
||||
|
||||
@@ -25,10 +25,11 @@ TypeLLVMVisitor<String,String>
|
||||
str.append("\n");
|
||||
str.append("; Actual code begins\n");
|
||||
|
||||
// Déclaration pour les string
|
||||
//for(int i = 0; i<declration.size(); i++){
|
||||
//str.append(declration.get(i) + "\n");
|
||||
//}
|
||||
for(int i = 0; i<prog.declarGlobal().size(); i++){
|
||||
str.append(prog.declarGlobal().get(i).accept(this, indent));
|
||||
}
|
||||
str.append("\n");
|
||||
|
||||
|
||||
//PROTO et FUNC
|
||||
|
||||
@@ -149,6 +150,15 @@ TypeLLVMVisitor<String,String>
|
||||
return callRead.accept(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitDeclarGlobalLLVM(DeclarGlobalLLVMImp instr, String h) {
|
||||
String str = "@."+instr.name() + " = global";
|
||||
str += "[" + "x"+ "]";
|
||||
str+= "c\"\"\n";
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//label
|
||||
@Override
|
||||
public String visitLabelLLVM(LabelLLVMImp instr, String h) {
|
||||
@@ -174,7 +184,9 @@ TypeLLVMVisitor<String,String>
|
||||
|
||||
@Override
|
||||
public String visitVarLLVM(VarLLVMImp e, String h) {
|
||||
return "%"+e.nom();
|
||||
String prefix = "%";
|
||||
if(e.isGlobal()) prefix = "@";
|
||||
return prefix+e.nom();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -198,4 +210,5 @@ TypeLLVMVisitor<String,String>
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import TP2.llvm.Interface.*;
|
||||
public class ProgramLLVM {
|
||||
|
||||
//Program
|
||||
public static record ProgramLLVMImp(ArrayList<Integer> declration ,ArrayList<DefineLLVM> fonctions) implements ProgLLVM{
|
||||
public static record ProgramLLVMImp(ArrayList<DeclarGlobalLLVMImp> declarGlobal ,ArrayList<DefineLLVM> fonctions) implements ProgLLVM{
|
||||
public <H, S> S accept(ProgramLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitProgramLLVM(this, h);
|
||||
}
|
||||
@@ -81,14 +81,14 @@ public class ProgramLLVM {
|
||||
}
|
||||
}
|
||||
|
||||
public static record PrintLLVMImp(ArrayList<ValLLVM> l) implements InstructionLLVM{ //TODO c'est un Call qui appel la fonction print
|
||||
public static record PrintLLVMImp(DeclarGlobalLLVMImp fmt,ArrayList<ValLLVM> l) implements InstructionLLVM{
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitPrintLLVM(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record ReadLLVMImp(ArrayList<ValLLVM> l) implements InstructionLLVM{ //TODO c'est un Call qui appel la fonction read
|
||||
public static record ReadLLVMImp(DeclarGlobalLLVMImp fmt,ArrayList<ValLLVM> l) implements InstructionLLVM{
|
||||
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
@@ -96,6 +96,14 @@ public class ProgramLLVM {
|
||||
}
|
||||
}
|
||||
|
||||
public static record DeclarGlobalLLVMImp(String name) implements InstructionLLVM{
|
||||
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitDeclarGlobalLLVM(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
//Expression :
|
||||
public static record BinOpLLVMImp(TypeLLVM type,Op op, ValLLVM val1,ValLLVM val2) implements ExpressionLLVM{
|
||||
@Override
|
||||
@@ -170,13 +178,12 @@ public class ProgramLLVM {
|
||||
|
||||
@Override
|
||||
public TypeLLVM getType() {
|
||||
System.out.println("getType");
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static record VarLLVMImp(TypeLLVM type, String nom) implements ValLLVM{
|
||||
public static record VarLLVMImp(TypeLLVM type, String nom, Boolean isGlobal) implements ValLLVM{
|
||||
@Override
|
||||
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitVarLLVM(this, h);
|
||||
@@ -184,7 +191,6 @@ public class ProgramLLVM {
|
||||
|
||||
@Override
|
||||
public TypeLLVM getType() {
|
||||
System.out.println("getType");
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user