diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bootstrap/codegen.pry | 9 | ||||
| -rw-r--r-- | src/bootstrap/llvm.pry | 1 | ||||
| -rw-r--r-- | src/bootstrap/main.pry | 23 |
3 files changed, 29 insertions, 4 deletions
diff --git a/src/bootstrap/codegen.pry b/src/bootstrap/codegen.pry index 5b415c6..cb054ec 100644 --- a/src/bootstrap/codegen.pry +++ b/src/bootstrap/codegen.pry @@ -1393,14 +1393,19 @@ let codegen_generate = (c: *codegen, ast: *Node) => i64 { return 0; }; -let codegen_compile = (c: *codegen) => i64 { +let codegen_compile = (c: *codegen, dump_ir: bool) => i64 { /* Dump module */ LLVMDumpModule((*c).llvm_module); + let message = cast(**i8, null); + + if dump_ir { + LLVMPrintModuleToFile((*c).llvm_module, "output.ll", message); + return 0; + }; /* Generate code */ let triple = LLVMGetDefaultTargetTriple(); let target_ref = cast(*LLVMTargetRef, arena_alloc((*c).arena, sizeof(*LLVMTargetRef))); - let message = cast(**i8, null); let result = LLVMGetTargetFromTriple(triple, target_ref, message); if result != 0 { printf("Target output: %s\n", *message); diff --git a/src/bootstrap/llvm.pry b/src/bootstrap/llvm.pry index 6ae7182..2feb815 100644 --- a/src/bootstrap/llvm.pry +++ b/src/bootstrap/llvm.pry @@ -282,6 +282,7 @@ extern LLVMDisposeBuilder = (LLVMBuilderRef) => void; extern LLVMGetInsertBlock = (LLVMBuilderRef) => LLVMBasicBlockRef; extern LLVMDumpModule = (LLVMModuleRef) => void; +extern LLVMPrintModuleToFile = (LLVMModuleRef, *i8, **i8) => i64; extern LLVMGetDefaultTargetTriple = () => *i8; extern LLVMGetTargetFromTriple = (*i8, *LLVMTargetRef, **i8) => i64; extern LLVMDisposeMessage = (*i8) => void; diff --git a/src/bootstrap/main.pry b/src/bootstrap/main.pry index 835f4c4..a564965 100644 --- a/src/bootstrap/main.pry +++ b/src/bootstrap/main.pry @@ -36,7 +36,26 @@ let main = (argc: i64, argv: **i8) => i64 { return 1; }; - let filename = *(argv + cast(**i8, 1)); + let generate_ir = false; + let filename = cast(*i8, null); + + let i = 0; + while i < (argc - 1) { + i = i + 1; + let arg = *(argv + cast(**i8, i)); + + if strcmp(arg, "--generate-ir") { + generate_ir = true; + continue; + }; + + if filename == cast(*i8, null) { + filename = arg; + continue; + }; + + assert(false); + }; printf("%s\n", filename); @@ -52,7 +71,7 @@ let main = (argc: i64, argv: **i8) => i64 { let c = codegen_init(alloc); let res = codegen_generate(c, ast); - let res = codegen_compile(c); + let res = codegen_compile(c, generate_ir); codegen_deinit(c); arena_free(alloc); |