Skip to content

Commit b5edc57

Browse files
committed
feat(driver): add -emit-llvm-bc compiler option
1 parent 18292b5 commit b5edc57

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

tools/gluc/sources/CompilerDriver.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Parser/Parser.hpp"
77
#include "Sema/Sema.hpp"
88

9+
#include <llvm/Bitcode/BitcodeWriter.h>
910
#include <llvm/IR/LegacyPassManager.h>
1011
#include <llvm/IR/Module.h>
1112
#include <llvm/IR/Verifier.h>
@@ -91,6 +92,7 @@ bool CompilerDriver::parseCommandLine(int argc, char **argv)
9192
clEnumValN(PrintGILGen, "print-gilgen", "Print GIL before passes"),
9293
clEnumValN(PrintGIL, "print-gil", "Print GIL after passes"),
9394
clEnumValN(PrintLLVMIR, "print-llvm-ir", "Print resulting LLVM IR"),
95+
clEnumValN(EmitBitcode, "emit-llvm-bc", "Emit LLVM bitcode"),
9496
clEnumValN(EmitAssembly, "S", "Emit assembly code"),
9597
clEnumValN(EmitObject, "c", "Emit object file")
9698
)
@@ -339,6 +341,11 @@ int CompilerDriver::processPreCompilationOptions()
339341
return 0;
340342
}
341343

344+
if (_config.stage == EmitBitcode) {
345+
llvm::WriteBitcodeToFile(*_llvmModule, *_outputStream);
346+
return 0;
347+
}
348+
342349
return 0;
343350
}
344351

@@ -513,8 +520,8 @@ int CompilerDriver::executeCompilation(char const *argv0)
513520
// Process pre-compilation options
514521
auto compileResult = processPreCompilationOptions();
515522

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) {
518525
return compileResult;
519526
}
520527

tools/gluc/sources/CompilerDriver.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum Stage {
3434
PrintGILGen,
3535
PrintGIL,
3636
PrintLLVMIR,
37+
EmitBitcode,
3738
EmitAssembly,
3839
EmitObject,
3940
Linking

0 commit comments

Comments
 (0)