clean
This commit is contained in:
@@ -4,7 +4,9 @@ import TP2.asd.Program.*;
|
|||||||
import TP2.llvm.ProgramLLVM.*;
|
import TP2.llvm.ProgramLLVM.*;
|
||||||
|
|
||||||
public interface Interface{
|
public interface Interface{
|
||||||
|
|
||||||
//PROGRAM
|
//PROGRAM
|
||||||
|
|
||||||
public interface ProgramI {
|
public interface ProgramI {
|
||||||
public <H,S> S accept(ProgramVisitor<H,S> v, H h);
|
public <H,S> S accept(ProgramVisitor<H,S> v, H h);
|
||||||
public String prettyprinter();
|
public String prettyprinter();
|
||||||
@@ -15,8 +17,8 @@ public interface Interface{
|
|||||||
public S visitProgram(ProgramImp prog, H h);
|
public S visitProgram(ProgramImp prog, H h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//FUNCTION
|
//FUNCTION
|
||||||
|
|
||||||
public interface Function {
|
public interface Function {
|
||||||
public <H,S> S accept(FunctionVisitor<H,S> v, H h);
|
public <H,S> S accept(FunctionVisitor<H,S> v, H h);
|
||||||
}
|
}
|
||||||
@@ -43,7 +45,6 @@ public interface Interface{
|
|||||||
public <H,S> S accept(InstrVisitor<H,S> v, H h);
|
public <H,S> S accept(InstrVisitor<H,S> v, H h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface InstrVisitor<H,S>{
|
public interface InstrVisitor<H,S>{
|
||||||
public S visitReturn(Return_instrImp instr, H h);
|
public S visitReturn(Return_instrImp instr, H h);
|
||||||
public S visitBloc(BlocImp instr, H h);
|
public S visitBloc(BlocImp instr, H h);
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ public class Program{
|
|||||||
|
|
||||||
//Fonction
|
//Fonction
|
||||||
public static record FunctionImp(Type type, String nom, ArrayList<VarImp> params,Instruction instruction) implements Function {
|
public static record FunctionImp(Type type, String nom, ArrayList<VarImp> params,Instruction instruction) implements Function {
|
||||||
//public FunctionImp(Type type, String name, Instruction instruction) {
|
|
||||||
// this(type, name, new ArrayList<>() {{ add(instruction); }}); C KOI ?
|
|
||||||
//}
|
|
||||||
|
|
||||||
public <H, S> S accept(FunctionVisitor<H, S> v, H h) {
|
public <H, S> S accept(FunctionVisitor<H, S> v, H h) {
|
||||||
return v.visitFunction(this, h);
|
return v.visitFunction(this, h);
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ package TP2.asd;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.pcollections.*;
|
import org.pcollections.*;
|
||||||
import TP2.asd.Interface.Type;
|
|
||||||
import TP2.asd.Program.Type_intImp;
|
|
||||||
import TP2.llvm.Interface.TypeLLVM;
|
import TP2.llvm.Interface.TypeLLVM;
|
||||||
import TP2.llvm.ProgramLLVM.DeclarGlobalLLVMImp;
|
import TP2.llvm.ProgramLLVM.DeclarGlobalLLVMImp;
|
||||||
import TP2.llvm.ProgramLLVM.DefineLLVMImp;
|
import TP2.llvm.ProgramLLVM.DefineLLVMImp;
|
||||||
import TP2.llvm.ProgramLLVM.IntLLVMImp;
|
import TP2.llvm.ProgramLLVM.IntLLVMImp;
|
||||||
import TP2.llvm.ProgramLLVM.PointerLLVMImp;
|
|
||||||
|
|
||||||
|
|
||||||
public class SymTable {
|
public class SymTable {
|
||||||
@@ -35,6 +32,8 @@ public class SymTable {
|
|||||||
this.declarationsGlobal = declarationsGlobal;
|
this.declarationsGlobal = declarationsGlobal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static class ValueFunMap{
|
public static class ValueFunMap{
|
||||||
public DefineLLVMImp define;
|
public DefineLLVMImp define;
|
||||||
public Boolean isProto;
|
public Boolean isProto;
|
||||||
@@ -56,6 +55,18 @@ public class SymTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Result{
|
||||||
|
public SymTable symTable;
|
||||||
|
public String var;
|
||||||
|
public Result(SymTable symTable, String var){
|
||||||
|
this.symTable = symTable;
|
||||||
|
this.var = var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Fonction SymTable :
|
||||||
|
|
||||||
public SymTable newBlock() {
|
public SymTable newBlock() {
|
||||||
return new SymTable(varMap.plus(HashTreePMap.empty()), functionsMap, id,declarationsGlobal);
|
return new SymTable(varMap.plus(HashTreePMap.empty()), functionsMap, id,declarationsGlobal);
|
||||||
}
|
}
|
||||||
@@ -68,20 +79,11 @@ public class SymTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<DeclarGlobalLLVMImp> getDeclarationGlobal(){
|
public ArrayList<DeclarGlobalLLVMImp> getDeclarationGlobal(){
|
||||||
return this.declarationsGlobal;
|
return this.declarationsGlobal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Result{
|
|
||||||
public SymTable symTable;
|
|
||||||
public String var;
|
|
||||||
public Result(SymTable symTable, String var){
|
|
||||||
this.symTable = symTable;
|
|
||||||
this.var = var;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public SymTable addFunction(DefineLLVMImp function, Boolean isProto){
|
public SymTable addFunction(DefineLLVMImp function, Boolean isProto){
|
||||||
ValueFunMap value = this.functionsMap.get(function.name());
|
ValueFunMap value = this.functionsMap.get(function.name());
|
||||||
if(value == null || (value!=null && value.isProto && !isProto)){
|
if(value == null || (value!=null && value.isProto && !isProto)){
|
||||||
@@ -196,14 +198,6 @@ public class SymTable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeLLVM getvar_Type(String s){
|
|
||||||
for (PMap<String,ValueVarMap> scope : varMap) {
|
|
||||||
if (scope.containsKey(s)) {
|
|
||||||
return scope.get(s).type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//retourne le type de la var
|
//retourne le type de la var
|
||||||
public TypeLLVM getType(String nomVar){
|
public TypeLLVM getType(String nomVar){
|
||||||
@@ -216,11 +210,10 @@ public class SymTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public SymTable addVarInTab(String nomVar, TypeLLVM type, boolean isParam) {
|
public SymTable addVarInTab(String nomVar, TypeLLVM type, boolean isParam) {
|
||||||
PMap<String,ValueVarMap> top = varMap.get(0);
|
PMap<String,ValueVarMap> top = varMap.get(0);
|
||||||
if (top.containsKey(nomVar)) {
|
if (top.containsKey(nomVar)) {
|
||||||
System.err.println(nomVar+ " déjà déclaré.");
|
System.err.println("[VSL compile error] : " + nomVar+ " déjà déclaré.");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
top = top.plus(nomVar, new ValueVarMap(type, id[0], isParam));
|
top = top.plus(nomVar, new ValueVarMap(type, id[0], isParam));
|
||||||
@@ -228,6 +221,7 @@ public class SymTable {
|
|||||||
return new SymTable(varMap.minus(0).plus(0, top), functionsMap, id, this.declarationsGlobal);
|
return new SymTable(varMap.minus(0).plus(0, top), functionsMap, id, this.declarationsGlobal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String print_all(){
|
public String print_all(){
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
str.append("Id = ").append(id[0]).append("\n");
|
str.append("Id = ").append(id[0]).append("\n");
|
||||||
|
|||||||
@@ -432,10 +432,10 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
@Override
|
@Override
|
||||||
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
||||||
ArrayList<InstructionLLVM> l =new ArrayList<>();
|
ArrayList<InstructionLLVM> l =new ArrayList<>();
|
||||||
ValLLVM val = new VarLLVMImp(h.getvar_Type(e.name()),h.getVar(e.name()),false);
|
ValLLVM val = new VarLLVMImp(h.getType(e.name()),h.getVar(e.name()),false);
|
||||||
Result r = h.addNewTempVar();
|
Result r = h.addNewTempVar();
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
VarLLVMImp varTemp = new VarLLVMImp(h.getvar_Type(e.name()),r.var,false);
|
VarLLVMImp varTemp = new VarLLVMImp(h.getType(e.name()),r.var,false);
|
||||||
l.add(new AssignLLVMImp(varTemp,((ExpressionLLVM)(new LoadLLVMImp(val)))));
|
l.add(new AssignLLVMImp(varTemp,((ExpressionLLVM)(new LoadLLVMImp(val)))));
|
||||||
return new InstrAndVal(l, varTemp);
|
return new InstrAndVal(l, varTemp);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user