asd LLVM
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.List;
|
||||
|
||||
|
||||
|
||||
public class LLVM {
|
||||
public class VSL {
|
||||
|
||||
static String INDENT = " ";
|
||||
|
||||
@@ -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 <H, S> S accept(InstrVisitor<H, S> 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{
|
||||
|
||||
30
src/main/java/TP2/llvm/Interface.java
Normal file
30
src/main/java/TP2/llvm/Interface.java
Normal file
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
100
src/main/java/TP2/llvm/ProgramLLVM.java
Normal file
100
src/main/java/TP2/llvm/ProgramLLVM.java
Normal file
@@ -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<Integer> declration ,ArrayList<DefineLLVM> fonctions) implements ProgLLVM{
|
||||
|
||||
|
||||
public String prettyprinter(){
|
||||
String str = "";
|
||||
str += target + "\n"; //TODO
|
||||
for(int i = 0; i<declration.size(); i++){
|
||||
str += declration.get(i) + "\n"; //TODO
|
||||
}
|
||||
for(int i = 0; i < fonctions.size(); i++){
|
||||
str += fonctions.get(i).prettyprinter() + "\n";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static record DefineLLVMImpl(String nom,int nbBits, ArrayList<InstructionLLVM> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user