213 lines
5.8 KiB
Java
213 lines
5.8 KiB
Java
package TP2.llvm;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import TP2.asd.Interface.*;
|
|
import TP2.llvm.Interface.*;
|
|
|
|
|
|
public class ProgramLLVM {
|
|
|
|
//Program
|
|
public static record ProgramLLVMImpl(ArrayList<Integer> declration ,ArrayList<DefineLLVM> fonctions) implements ProgLLVM{
|
|
public <H, S> S accept(ProgramLLVMVisitor<H, S> v, H h) {
|
|
return v.visitProgramLLVM(this, h);
|
|
}
|
|
|
|
public String prettyprinter(){
|
|
PrettyprinterLLVM_Visitor ppVisitor = new PrettyprinterLLVM_Visitor();
|
|
return this.accept(ppVisitor, "");
|
|
}
|
|
}
|
|
|
|
|
|
//Define
|
|
public static record DefineLLVMImpl(String nom, TypeLLVM type, ArrayList<InstructionLLVM> instrs) implements DefineLLVM{
|
|
public <H, S> S accept(DefineLLVMVisitor<H, S> v, H h) {
|
|
return v.visitDefineLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
|
|
//Instructon :
|
|
|
|
public static record LabelLLVMImp(String nom) implements InstructionLLVM{
|
|
public String prettyprinter(){
|
|
StringBuilder str = new StringBuilder();
|
|
return str.toString();
|
|
}
|
|
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitLabelLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
|
|
public static record AssignLVMImpl(VarLLVMImpl var, ExpressionLLVM e) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitAssignLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record ReturnLLVMImpl(TypeLLVM type, ExpressionLLVM e) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitReturnLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record StoreLLVMImpl(TypeLLVM valType, ExpressionLLVM e,TypeLLVM varType, ValLLVM var) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitStoreLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record PrintLLVMImpl(ArrayList<Object> l) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitPrintLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record ReadLLVMImpl(ArrayList<VarLLVMImpl> l) implements InstructionLLVM{
|
|
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitReadLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record IfThenLLVMImp(ExpressionLLVM cond, InstructionLLVM instr) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitIfThenLLVM(this, h);
|
|
}
|
|
|
|
}
|
|
|
|
public static record IfThenElseLLVMImp(ExpressionLLVM cond, InstructionLLVM intr1, InstructionLLVM instr2) implements InstructionLLVM{
|
|
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitIfThenElseLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record WhileLLVMImp(ExpressionLLVM cond, InstructionLLVM instr) implements InstructionLLVM{
|
|
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitWhileLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
//Expression :
|
|
public static record BinOpLLVMImpl(TypeLLVM type,Op op, ValLLVM val1,ValLLVM val2) implements ExpressionLLVM{
|
|
@Override
|
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitBinOpLLVM(this, h);
|
|
}
|
|
|
|
@Override
|
|
public TypeLLVM getType() {
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
/*public static record ConstLLVMImp(TypeLLVM type, int val) implements ExpressionLLVM{
|
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitConstLLVM(this, h);
|
|
}
|
|
|
|
@Override
|
|
public String prettyprinter() {
|
|
return val+"";
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
public static record allocaLLVMImpl(TypeLLVM type) implements ExpressionLLVM{
|
|
@Override
|
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitAllocaLLVM(this, h);
|
|
}
|
|
|
|
@Override
|
|
public TypeLLVM getType() {
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
public static record loadLLVMImpl(TypeLLVM type, int nbBits,int nbBits2, ValLLVM val) implements ExpressionLLVM{
|
|
@Override
|
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitLoadLLVM(this, h);
|
|
}
|
|
|
|
@Override
|
|
public TypeLLVM getType() {
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
//Val
|
|
|
|
public static record ValLLVMImpl(TypeLLVM type, int val) implements ValLLVM{
|
|
@Override
|
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitValLLVM(this, h);
|
|
}
|
|
|
|
@Override
|
|
public TypeLLVM getType() {
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
public static record VarLLVMImpl(TypeLLVM type, String nom) implements ValLLVM{
|
|
@Override
|
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitVarLLVM(this, h);
|
|
}
|
|
|
|
@Override
|
|
public TypeLLVM getType() {
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
public static record IntLLVMImpl() implements TypeLLVM{
|
|
|
|
@Override
|
|
public <H, S> S accept(TypeLLVMVisitor<H, S> v, H h) {
|
|
return v.visitIntLLVM(this, h);
|
|
}
|
|
|
|
public int getNbBit(){
|
|
return 32;
|
|
}
|
|
}
|
|
|
|
|
|
public static record VoidLLVMImpl() implements TypeLLVM{
|
|
|
|
@Override
|
|
public <H, S> S accept(TypeLLVMVisitor<H, S> v, H h) {
|
|
return v.visitVoidLLVM(this, h);
|
|
}
|
|
|
|
public int getNbBit(){
|
|
return 0;
|
|
}
|
|
}
|
|
}
|