diff --git a/src/main/java/TP2/Main.java b/src/main/java/TP2/Main.java index 7c1a7b7..5008630 100644 --- a/src/main/java/TP2/Main.java +++ b/src/main/java/TP2/Main.java @@ -10,6 +10,9 @@ import org.antlr.runtime.RecognitionException; import org.antlr.runtime.Token; import TP2.asd.Program.*; +import TP2.llvm.Interface.ProgramLLVM; +import TP2.llvm.Program.ProgramLLVMImpl; + import java.util.*; public class Main { @@ -46,6 +49,7 @@ public class Main { // Generate the intermediate representation System.out.println("todo"); + } catch (IOException | RecognitionException e) { e.printStackTrace(); throw new RuntimeException("Unable to proceed"); diff --git a/src/main/java/TP2/LLVM.java b/src/main/java/TP2/VSL.java similarity index 99% rename from src/main/java/TP2/LLVM.java rename to src/main/java/TP2/VSL.java index 7dfb510..db1835e 100644 --- a/src/main/java/TP2/LLVM.java +++ b/src/main/java/TP2/VSL.java @@ -6,7 +6,7 @@ import java.util.List; -public class LLVM { +public class VSL { static String INDENT = " "; diff --git a/src/main/java/TP2/asd/Program.java b/src/main/java/TP2/asd/Program.java index 189f02e..23cfb63 100644 --- a/src/main/java/TP2/asd/Program.java +++ b/src/main/java/TP2/asd/Program.java @@ -5,16 +5,7 @@ import java.util.Map; import org.antlr.grammar.v3.ANTLRParser.defaultNodeOption_return; -import TP2.asd.Interface.ExprVisitor; -import TP2.asd.Interface.Expression; -import TP2.asd.Interface.Function; -import TP2.asd.Interface.FunctionVisitor; -import TP2.asd.Interface.InstrVisitor; -import TP2.asd.Interface.Instruction; -import TP2.asd.Interface.Op; -import TP2.asd.Interface.ProgramI; -import TP2.asd.Interface.ProgramVisitor; -import TP2.asd.Interface.Type; +import TP2.asd.Interface.*; @@ -99,6 +90,12 @@ public class Program{ public S accept(InstrVisitor v, H h) { return v.visitAssign(this, h); } + + @Override + public String prettyprinter(String indent) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'prettyprinter'"); + } } public static record Type_voidImp() implements Type{ diff --git a/src/main/java/TP2/llvm/Interface.java b/src/main/java/TP2/llvm/Interface.java new file mode 100644 index 0000000..8282a23 --- /dev/null +++ b/src/main/java/TP2/llvm/Interface.java @@ -0,0 +1,30 @@ +package TP2.llvm; +import TP2.llvm.ProgramLLVM.*; + +public interface Interface { + public interface ProgLLVM{ + public String prettyprinter(); + } + + public interface DefineLLVM{ + public String prettyprinter(); + } + + public interface IdentifierLLVM{ //globaux @ et local % + public String prettyprinter(); + } + + public interface InstructionLLVM{ + public String prettyprinter(); + } + + public interface ExpressionLLVM{ + public String prettyprinter(); + } + + public interface Val{ + public String prettyprinter(); + } + + +} diff --git a/src/main/java/TP2/llvm/ProgramLLVM.java b/src/main/java/TP2/llvm/ProgramLLVM.java new file mode 100644 index 0000000..1e89ae5 --- /dev/null +++ b/src/main/java/TP2/llvm/ProgramLLVM.java @@ -0,0 +1,100 @@ +package TP2.llvm; + +import java.util.ArrayList; + +import TP2.asd.Program.ProgramImp; +import TP2.llvm.Interface.*; + + +public class ProgramLLVM { + static String INDENT = " "; + + //TODO //TODO + public static record ProgramLLVMImpl(int target ,ArrayList declration ,ArrayList fonctions) implements ProgLLVM{ + + + public String prettyprinter(){ + String str = ""; + str += target + "\n"; //TODO + for(int i = 0; i instrs) implements DefineLLVM{ + public String prettyprinter(){ + String str = "define i"+ nbBits + "@"+nom + "() {\n"; + for(int i = 0; i < instrs.size(); i++){ + str += instrs.get(i).prettyprinter() + "\n"; + } + str += "}"; + return str; + } + } + + //Instructon : + + public static record LabelLLVMImpl(String nom) implements InstructionLLVM{ + public String prettyprinter(){ + String str = "" + nom + ":"; + return str; + } + } + + public static record AffectLLVM(Var var, ExpressionLLVM e) implements InstructionLLVM{ + public String prettyprinter(){ + return "%" + var.prettyprinter() + " = " + e.prettyprinter(); + } + } + + //Expression : + + public static record AddLLVMImpl(int nbBits, Val val1,Val val2) implements ExpressionLLVM{ + public String prettyprinter(){ + return "add" + " i" + nbBits + " " + val1.prettyprinter() + ", " + val2.prettyprinter(); + } + } + + public static record SubLLVMImpl(int nbBits, Val val1,Val val2) implements ExpressionLLVM{ + public String prettyprinter(){ + return "sub" + " i" + nbBits + " " + val1.prettyprinter() + ", " + val2.prettyprinter(); + } + } + + public static record allocaLLVMImpl(int nbBits) implements ExpressionLLVM{ + public String prettyprinter(){ + return "aloca" + " i" + nbBits; + } + } + + public static record loadLLVMImpl(int nbBits,int nbBits2, Val val) implements ExpressionLLVM{ + public String prettyprinter(){ + return "load" + " i" + nbBits + ", i"+ nbBits2 + "* %" + val.prettyprinter(); + } + } + + //Val + + public static record ValImpl(int val) implements Val{ + public String prettyprinter(){ + return val + ""; + } + } + + public static record Var(String nom) implements Val{ + public String prettyprinter(){ + return "%"+nom; + } + } + + + + + + +}