génération du fichier .ll sans passer par la sorti Print, pour controller le type d'encodage

This commit is contained in:
Rochas
2025-04-30 13:59:25 +02:00
parent ad30cd3c64
commit e27dcdb0a0
2 changed files with 19 additions and 9 deletions

View File

@@ -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");

Binary file not shown.