From b12de9881418ff9fff8318d0142fa101efd9dc08 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 7 Nov 2011 21:32:13 +0800 Subject: rustc: Add support of generating LLVM assembly rustc generates output files in LLVM bitcode format if "--emit-llvm" option is given. When used with the "-S" option, rustc generates LLVM intermediate language assembly files. Fixes Issue #476 --- src/rustllvm/RustWrapper.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/rustllvm/RustWrapper.cpp') diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index a9373b6c7e5..26d0764934e 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -15,6 +15,7 @@ #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" @@ -46,6 +47,17 @@ extern "C" const char *LLVMRustGetLastError(void) { extern "C" void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM); +extern "C" void LLVMRustAddPrintModulePass(LLVMPassManagerRef PMR, + LLVMModuleRef M, + const char* path) { + PassManager *PM = unwrap(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; -- cgit 1.4.1-3-g733a5