|
6 | 6 | #include "Parser/Parser.hpp" |
7 | 7 | #include "Sema/Sema.hpp" |
8 | 8 |
|
| 9 | +#include <llvm/Bitcode/BitcodeWriter.h> |
9 | 10 | #include <llvm/IR/LegacyPassManager.h> |
10 | 11 | #include <llvm/IR/Module.h> |
11 | 12 | #include <llvm/IR/Verifier.h> |
@@ -91,6 +92,7 @@ bool CompilerDriver::parseCommandLine(int argc, char **argv) |
91 | 92 | clEnumValN(PrintGILGen, "print-gilgen", "Print GIL before passes"), |
92 | 93 | clEnumValN(PrintGIL, "print-gil", "Print GIL after passes"), |
93 | 94 | clEnumValN(PrintLLVMIR, "print-llvm-ir", "Print resulting LLVM IR"), |
| 95 | + clEnumValN(EmitBitcode, "emit-llvm-bc", "Emit LLVM bitcode"), |
94 | 96 | clEnumValN(EmitAssembly, "S", "Emit assembly code"), |
95 | 97 | clEnumValN(EmitObject, "c", "Emit object file") |
96 | 98 | ) |
@@ -339,6 +341,11 @@ int CompilerDriver::processPreCompilationOptions() |
339 | 341 | return 0; |
340 | 342 | } |
341 | 343 |
|
| 344 | + if (_config.stage == EmitBitcode) { |
| 345 | + llvm::WriteBitcodeToFile(*_llvmModule, *_outputStream); |
| 346 | + return 0; |
| 347 | + } |
| 348 | + |
342 | 349 | return 0; |
343 | 350 | } |
344 | 351 |
|
@@ -513,8 +520,8 @@ int CompilerDriver::executeCompilation(char const *argv0) |
513 | 520 | // Process pre-compilation options |
514 | 521 | auto compileResult = processPreCompilationOptions(); |
515 | 522 |
|
516 | | - // Handle early exit cases for print options |
517 | | - if (_config.stage <= PrintLLVMIR) { |
| 523 | + // Handle early exit cases for print options and bitcode emission |
| 524 | + if (_config.stage <= EmitBitcode) { |
518 | 525 | return compileResult; |
519 | 526 | } |
520 | 527 |
|
|
0 commit comments