221 lines
6.3 KiB
Java
221 lines
6.3 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 name, TypeLLVM type, ArrayList<VarLLVMImpl> params, ArrayList<InstructionLLVM> instrs) implements DefineLLVM{
|
|
public <H, S> S accept(DefineLLVMVisitor<H, S> v, H h) {
|
|
return v.visitDefineLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
|
|
//Instructon :
|
|
//Label
|
|
public static record LabelLLVMImp(String name) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitLabelLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record BrLLVMImp(String label) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitBrLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record BrCondLLVMImp(VarLLVMImpl var, String label, String labelElse) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitBrCondLLVM(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 CallLLVMImpl(DefineLLVMImpl f, ArrayList<ValLLVM> params, String str) implements InstructionLLVM{
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitCallLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record PrintLLVMImpl(ArrayList<ValLLVM> l) implements InstructionLLVM{ //TODO c'est un Call qui appel la fonction print
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitPrintLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record ReadLLVMImpl(ArrayList<ValLLVM> l) implements InstructionLLVM{ //TODO c'est un Call qui appel la fonction read
|
|
|
|
@Override
|
|
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitReadLLVM(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(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 val().getType();
|
|
}
|
|
}
|
|
|
|
public static record IcmpLLVMImp(ValLLVM val1, ValLLVM val2) implements ExpressionLLVM{
|
|
@Override
|
|
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
|
|
return v.visitIcmpLLVM(this, h);
|
|
}
|
|
|
|
@Override
|
|
public TypeLLVM getType() {
|
|
return new BooleanLLVMImp();
|
|
}
|
|
|
|
}
|
|
|
|
//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 static record VoidLLVMImpl() implements TypeLLVM{
|
|
@Override
|
|
public <H, S> S accept(TypeLLVMVisitor<H, S> v, H h) {
|
|
return v.visitVoidLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record BooleanLLVMImp() implements TypeLLVM{
|
|
@Override
|
|
public <H, S> S accept(TypeLLVMVisitor<H, S> v, H h) {
|
|
return v.visitBooleanLLVM(this, h);
|
|
}
|
|
}
|
|
|
|
public static record StringLLVMImp() implements TypeLLVM{
|
|
@Override
|
|
public <H, S> S accept(TypeLLVMVisitor<H, S> v, H h) {
|
|
return v.visitStringLLVM(this, h);
|
|
}
|
|
}
|
|
}
|