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.io.PrintWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.antlr.runtime.ANTLRFileStream; import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.ANTLRInputStream; import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CharStream; import org.antlr.runtime.CharStream;
@@ -58,21 +61,28 @@ public class Main {
ProgramImp ast = parser.program(); ProgramImp ast = parser.program();
// Pretty-print the program (to debug parsing) // 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(ast.prettyprinter());
//System.out.println("\n\n PRETTYPRINTER VSL : \n--------------\n");
// Verify the program semantic // Verify the program semantic
// Generate the intermediate representation // Generate the intermediate representation
//System.out.println("\n\n"); System.out.println("\n\n");
//PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true); PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true);
ProgramLLVMImp astLLVM = ast.toLLVM(); ProgramLLVMImp astLLVM = ast.toLLVM();
//System.out.println("\n\n PRETTYPRINTER LLVM : \n--------------\n");
System.out.println(astLLVM.prettyprinter()); String llvmStr = astLLVM.prettyprinter();
//System.out.println("\n\n PRETTYPRINTER LLVM : \n--------------\n"); 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) { } catch (IOException | RecognitionException e) {

Binary file not shown.