asd LLVM
This commit is contained in:
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