toLLVM en cours
This commit is contained in:
@@ -10,11 +10,16 @@ import org.antlr.runtime.RecognitionException;
|
|||||||
import org.antlr.runtime.Token;
|
import org.antlr.runtime.Token;
|
||||||
|
|
||||||
import TP2.asd.Program.*;
|
import TP2.asd.Program.*;
|
||||||
import TP2.llvm.Interface.ProgramLLVM;
|
import TP2.llvm.ProgramLLVM;
|
||||||
import TP2.llvm.Program.ProgramLLVMImpl;
|
import TP2.llvm.ProgramLLVM.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
./gradlew build
|
||||||
|
java -jar build/libs/TP2.jar tests/fragment0/priority2.vsl
|
||||||
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
@@ -49,6 +54,11 @@ public class Main {
|
|||||||
// Generate the intermediate representation
|
// Generate the intermediate representation
|
||||||
System.out.println("todo");
|
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) {
|
} catch (IOException | RecognitionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -3,20 +3,24 @@ package TP2.asd;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import TP2.asd.Program.*;
|
import TP2.asd.Program.*;
|
||||||
|
import TP2.llvm.Interface.*;
|
||||||
|
import TP2.llvm.ProgramLLVM.*;
|
||||||
|
|
||||||
public interface Interface{
|
public interface Interface{
|
||||||
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();
|
||||||
|
public ProgramLLVMImpl toLLVM();
|
||||||
}
|
}
|
||||||
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);
|
||||||
public String prettyprinter(String indent);
|
public String prettyprinter(String indent);
|
||||||
|
public DefineLLVM toLLVM();
|
||||||
}
|
}
|
||||||
public interface Instruction {
|
public interface Instruction {
|
||||||
public <H,S> S accept(InstrVisitor<H,S> v, H h);
|
public <H,S> S accept(InstrVisitor<H,S> v, H h);
|
||||||
public String prettyprinter(String indent);
|
public String prettyprinter(String indent);
|
||||||
|
public InstructionLLVM toLLVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Expression {
|
public interface Expression {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import java.util.Map;
|
|||||||
import org.antlr.grammar.v3.ANTLRParser.defaultNodeOption_return;
|
import org.antlr.grammar.v3.ANTLRParser.defaultNodeOption_return;
|
||||||
|
|
||||||
import TP2.asd.Interface.*;
|
import TP2.asd.Interface.*;
|
||||||
|
import TP2.llvm.ProgramLLVM.*;
|
||||||
|
import TP2.llvm.Interface.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -26,6 +28,17 @@ public class Program{
|
|||||||
}
|
}
|
||||||
return str;
|
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 {
|
public static record FunctionImp(Type type, String nom, ArrayList<Instruction> instructions)implements Function {
|
||||||
@@ -45,6 +58,15 @@ public class Program{
|
|||||||
str+= indent+"}";
|
str+= indent+"}";
|
||||||
return str;
|
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{
|
public static record ConstImp(int c) implements Expression{
|
||||||
@@ -85,6 +107,12 @@ public class Program{
|
|||||||
public String prettyprinter(String indent){
|
public String prettyprinter(String indent){
|
||||||
return indent+"RETURN " + e.prettyprinter();
|
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 static record AssignImp(String t, Expression e) implements Instruction{
|
||||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||||
@@ -96,6 +124,12 @@ public class Program{
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'prettyprinter'");
|
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{
|
public static record Type_voidImp() implements Type{
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import TP2.llvm.Interface.*;
|
|||||||
|
|
||||||
|
|
||||||
public class ProgramLLVM {
|
public class ProgramLLVM {
|
||||||
static String INDENT = " ";
|
|
||||||
|
static String INDENT = " ";
|
||||||
|
|
||||||
//TODO //TODO
|
//TODO //TODO
|
||||||
public static record ProgramLLVMImpl(int target ,ArrayList<Integer> declration ,ArrayList<DefineLLVM> fonctions) implements ProgLLVM{
|
public static record ProgramLLVMImpl(int target ,ArrayList<Integer> declration ,ArrayList<DefineLLVM> fonctions) implements ProgLLVM{
|
||||||
|
|
||||||
|
|
||||||
public String prettyprinter(){
|
public String prettyprinter(){
|
||||||
String str = "";
|
String str = "";
|
||||||
str += target + "\n"; //TODO
|
str += target + "\n"; //TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user