diff --git a/src/main/java/TP2/Main.java b/src/main/java/TP2/Main.java index 75af21c..cf65198 100644 --- a/src/main/java/TP2/Main.java +++ b/src/main/java/TP2/Main.java @@ -5,6 +5,9 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + import org.antlr.runtime.ANTLRFileStream; import org.antlr.runtime.ANTLRInputStream; import org.antlr.runtime.CharStream; @@ -58,23 +61,30 @@ public class Main { ProgramImp ast = parser.program(); // Pretty-print the program (to debug parsing) - //System.err.println("todo " + ast); - //System.out.println("\n\n PRETTYPRINTER VSL : \n--------------\n"); - //System.out.println(ast.prettyprinter()); - //System.out.println("\n\n PRETTYPRINTER VSL : \n--------------\n"); + 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); + System.out.println("\n\n"); + PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true); ProgramLLVMImp astLLVM = ast.toLLVM(); - //System.out.println("\n\n PRETTYPRINTER LLVM : \n--------------\n"); - System.out.println(astLLVM.prettyprinter()); - //System.out.println("\n\n PRETTYPRINTER LLVM : \n--------------\n"); + + String llvmStr = astLLVM.prettyprinter(); + out2.println(llvmStr); + 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"); + + } catch (IOException | RecognitionException e) { e.printStackTrace(); throw new RuntimeException("Unable to proceed"); diff --git a/tests/fragment1/while2 b/tests/fragment1/while2 index e2fcb92..c903e04 100755 Binary files a/tests/fragment1/while2 and b/tests/fragment1/while2 differ