toLLVM en cours

This commit is contained in:
trochas
2025-04-03 13:08:07 +02:00
parent 8b2f8a6b8f
commit bd7b74461e
4 changed files with 54 additions and 6 deletions

View File

@@ -10,11 +10,16 @@ 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 TP2.llvm.ProgramLLVM;
import TP2.llvm.ProgramLLVM.*;
import java.util.*;
/*
./gradlew build
java -jar build/libs/TP2.jar tests/fragment0/priority2.vsl
*/
public class Main {
public static void main(String[] args) {
try {
@@ -49,6 +54,11 @@ public class Main {
// Generate the intermediate representation
System.out.println("todo");
//ProgramLLVMImpl astLLVM = ast.toLLVM();
//System.out.println("\n\n PRETTYPRINTER : \n--------------\n" + astLLVM.prettyprinter() + "\n--------------\nFIN PRETTYPRINTER");
} catch (IOException | RecognitionException e) {
e.printStackTrace();

View File

@@ -3,20 +3,24 @@ package TP2.asd;
import java.util.ArrayList;
import java.util.Map;
import TP2.asd.Program.*;
import TP2.llvm.Interface.*;
import TP2.llvm.ProgramLLVM.*;
public interface Interface{
public interface ProgramI {
public <H,S> S accept(ProgramVisitor<H,S> v, H h);
public String prettyprinter();
public ProgramLLVMImpl toLLVM();
}
public interface Function {
public <H,S> S accept(FunctionVisitor<H,S> v, H h);
public String prettyprinter(String indent);
public String prettyprinter(String indent);
public DefineLLVM toLLVM();
}
public interface Instruction {
public <H,S> S accept(InstrVisitor<H,S> v, H h);
public String prettyprinter(String indent);
public InstructionLLVM toLLVM();
}
public interface Expression {

View File

@@ -6,6 +6,8 @@ import java.util.Map;
import org.antlr.grammar.v3.ANTLRParser.defaultNodeOption_return;
import TP2.asd.Interface.*;
import TP2.llvm.ProgramLLVM.*;
import TP2.llvm.Interface.*;
@@ -26,6 +28,17 @@ public class Program{
}
return str;
}
@Override
public ProgramLLVMImpl toLLVM() {
ArrayList<DefineLLVM> fonctionLLVM = new ArrayList<>();
for(int i = 0; i<fonctions.size(); i++){
fonctionLLVM.add(fonctions.get(i).toLLVM());
}
return new ProgramLLVMImpl(0,new ArrayList<>(),fonctionLLVM);
}
}
public static record FunctionImp(Type type, String nom, ArrayList<Instruction> instructions)implements Function {
@@ -45,6 +58,15 @@ public class Program{
str+= indent+"}";
return str;
}
@Override
public DefineLLVM toLLVM() {
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
for(int i = 0; i<instructions.size(); i++){
instrLLVM.add(instructions.get(i).toLLVM());
}
return new DefineLLVMImpl(nom, 32, instrLLVM);
}
}
public static record ConstImp(int c) implements Expression{
@@ -85,6 +107,12 @@ public class Program{
public String prettyprinter(String indent){
return indent+"RETURN " + e.prettyprinter();
}
@Override
public InstructionLLVM toLLVM() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'toLLVM'");
}
}
public static record AssignImp(String t, Expression e) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
@@ -96,6 +124,12 @@ public class Program{
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'prettyprinter'");
}
@Override
public InstructionLLVM toLLVM() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'toLLVM'");
}
}
public static record Type_voidImp() implements Type{

View File

@@ -7,12 +7,12 @@ import TP2.llvm.Interface.*;
public class ProgramLLVM {
static String INDENT = " ";
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