output_type_none;
output_type_bitcode;
output_type_assembly;
+ output_type_llvm_assembly;
output_type_object;
output_type_exe;
}
if opts.time_llvm_passes { llvm::LLVMRustPrintPassTimings(); }
ret;
}
- // If only a bitcode file is asked for by using the '--emit-llvm'
- // flag, then output it here
- llvm::LLVMRunPassManager(pm.llpm, llmod);
- str::as_buf(output,
- {|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) });
+ if opts.output_type == output_type_llvm_assembly {
+ // Given options "-S --emit-llvm": output LLVM assembly
+ str::as_buf(output, {|buf_o|
+ llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o)});
+ } else {
+ // If only a bitcode file is asked for by using the '--emit-llvm'
+ // flag, then output it here
+ llvm::LLVMRunPassManager(pm.llpm, llmod);
+ str::as_buf(output,
+ {|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) });
+ }
+
llvm::LLVMDisposeModule(llmod);
if opts.time_llvm_passes { llvm::LLVMRustPrintPassTimings(); }
}
let output_type =
if parse_only || no_trans {
link::output_type_none
+ } else if opt_present(match, "S") && opt_present(match, "emit-llvm") {
+ link::output_type_llvm_assembly
} else if opt_present(match, "S") {
link::output_type_assembly
} else if opt_present(match, "c") {
link::output_type_none. { "none" }
link::output_type_bitcode. { "bc" }
link::output_type_assembly. { "s" }
+ link::output_type_llvm_assembly. { "s" }
// Object and exe output both use the '.o' extension here
link::output_type_object. | link::output_type_exe. {
"o"
fn LLVMRustConstSmallInt(IntTy: TypeRef, N: uint, SignExtend: Bool) ->
ValueRef;
+ fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
+ Output: sbuf);
+
/** Turn on LLVM pass-timing. */
fn LLVMRustEnableTimePasses();
/** Turn on LLVM segmented stacks. */
#include "llvm/Linker.h"
#include "llvm/PassManager.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
extern "C" void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM);
+extern "C" void LLVMRustAddPrintModulePass(LLVMPassManagerRef PMR,
+ LLVMModuleRef M,
+ const char* path) {
+ PassManager *PM = unwrap<PassManager>(PMR);
+ std::string ErrorInfo;
+ raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
+ formatted_raw_ostream FOS(OS);
+ PM->add(createPrintModulePass(&FOS));
+ PM->run(*unwrap(M));
+}
+
extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
static std::string err;
LLVMAddArgumentPromotionPass
LLVMAddAttribute
LLVMAddBasicAliasAnalysisPass
+LLVMRustAddPrintModulePass
LLVMAddCFGSimplificationPass
LLVMAddCase
LLVMAddClause