clean
This commit is contained in:
@@ -23,21 +23,21 @@ import java.util.*;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
./gradlew build
|
||||
|
||||
java -jar build/libs/TP2.jar tests/fragment0/priority2.vsl
|
||||
|
||||
java -jar build/libs/TP2.jar tests/aLaMain.vsl
|
||||
|
||||
(/!\ pas besoin, le main le fait tout seul /!\) java -jar build/libs/TP2.jar tests/fragment1/while2.vsl > tests/fragment1/while2.ll
|
||||
|
||||
clang tests/aLaMain.ll -o tests/aLaMain
|
||||
|
||||
*/
|
||||
|
||||
/* TODO : problème de "-" : un NUMVER seul avec un "-" devant doit être reconnu comme un NUMBER négatif
|
||||
frament 1 :
|
||||
java -jar build/libs/TP2.jar tests/fragment1/print4.vsl
|
||||
|
||||
java -jar build/libs/TP2.jar tests/fragment1/while2.vsl > tests/fragment1/while2.ll
|
||||
clang tests/fragment1/while2.ll -o tests/fragment1/while2
|
||||
|
||||
*/
|
||||
|
||||
public class Main {
|
||||
static Boolean TESTAUTOMOD = false;
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Set input
|
||||
@@ -62,18 +62,17 @@ public class Main {
|
||||
|
||||
// Pretty-print the program (to debug parsing)
|
||||
|
||||
System.out.println(ast.prettyprinter());
|
||||
if(!TESTAUTOMOD) System.out.println(ast.prettyprinter());
|
||||
|
||||
// Verify the program semantic
|
||||
|
||||
// Generate the intermediate representation
|
||||
System.out.println("\n\n");
|
||||
PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true);
|
||||
if(!TESTAUTOMOD) System.out.println("\n\n");
|
||||
|
||||
ProgramLLVMImp astLLVM = ast.toLLVM();
|
||||
|
||||
String llvmStr = astLLVM.prettyprinter();
|
||||
out2.println(llvmStr);
|
||||
System.out.println(llvmStr);
|
||||
|
||||
/*
|
||||
utiliser la commande :
|
||||
@@ -81,14 +80,17 @@ public class Main {
|
||||
provoque peut provoquer de mauvais encodage (UTF16(LE) au lieu d'UTF8)
|
||||
et empêche l'utilisation de print pour autre chose
|
||||
*/
|
||||
String sortieLLVM = args[0].replace(".vsl", ".ll");
|
||||
Files.write(
|
||||
Paths.get(sortieLLVM),
|
||||
llvmStr.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
|
||||
System.out.println("\n[VSL compile Succes] : " + args[0] + " -> " + sortieLLVM +"\n");
|
||||
|
||||
if(!TESTAUTOMOD){
|
||||
String sortieLLVM = args[0].replace(".vsl", ".ll");
|
||||
Files.write(
|
||||
Paths.get(sortieLLVM),
|
||||
llvmStr.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
|
||||
System.out.println("\n[VSL compile succes] : " + args[0] + " -> " + sortieLLVM);
|
||||
System.out.println("Pour compiler en bin utilisez :");
|
||||
System.out.println("clang " + sortieLLVM + " -o " + sortieLLVM.replace(".ll", "") + "\n");
|
||||
}
|
||||
|
||||
} catch (IOException | RecognitionException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -78,7 +78,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
||||
paramsLLVM.add(var);
|
||||
VarLLVMImp newVar =new VarLLVMImp(type, nameVar,false);
|
||||
setParam.add(new AssignLLVMImp(newVar,new allocaLLVMImp(type)));
|
||||
setParam.add(new StoreLLVMImp(type,var,type,newVar));
|
||||
setParam.add(new StoreLLVMImp(type,var,newVar));
|
||||
}
|
||||
instrLLVM.addAll(setParam);
|
||||
instrLLVM.addAll(fun.instruction().accept(this, h));
|
||||
@@ -184,7 +184,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
||||
ArrayList<InstructionLLVM> result = new ArrayList<>();
|
||||
result.addAll(res.instrs);
|
||||
//InstructionLLVM r = new AssignLLVMImp(new VarLLVMImpl(var.getType(),instr.t()),var);
|
||||
InstructionLLVM r = new StoreLLVMImp(var.getType(),var,var.getType(),new VarLLVMImp(var.getType(),h.getVar(instr.t()),false));
|
||||
InstructionLLVM r = new StoreLLVMImp(var.getType(),var,new VarLLVMImp(var.getType(),h.getVar(instr.t()),false));
|
||||
result.add(r);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ TypeLLVMVisitor<String,String>
|
||||
|
||||
@Override
|
||||
public String visitStoreLLVM(StoreLLVMImp instr, String h) {
|
||||
return INDENT+"store " + instr.valType().accept(this, "") + " " + instr.e().accept(this, "") + ", " + new PointerLLVMImp(instr.varType()).accept(this, "") + " " + instr.var().accept(this,"");
|
||||
return INDENT+"store " + instr.type().accept(this, "") + " " + instr.e().accept(this, "") + ", " + new PointerLLVMImp(instr.type()).accept(this, "") + " " + instr.var().accept(this,"");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ProgramLLVM {
|
||||
}
|
||||
}
|
||||
|
||||
public static record StoreLLVMImp(TypeLLVM valType, ExpressionLLVM e,TypeLLVM varType, ValLLVM var) implements InstructionLLVM{
|
||||
public static record StoreLLVMImp(TypeLLVM type, ExpressionLLVM e, ValLLVM var) implements InstructionLLVM{
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitStoreLLVM(this, h);
|
||||
|
||||
Reference in New Issue
Block a user