about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorHaitao Li <lihaitao@gmail.com>2011-11-07 21:32:13 +0800
committerHaitao Li <lihaitao@gmail.com>2011-11-07 21:44:40 +0800
commitb12de9881418ff9fff8318d0142fa101efd9dc08 (patch)
treeaf2d2630f6c8f6d86559548599a74bdde1262253 /src/rustllvm/RustWrapper.cpp
parentf3468d03a23bda76af8e65956719487cb460f16a (diff)
downloadrust-b12de9881418ff9fff8318d0142fa101efd9dc08.tar.gz
rust-b12de9881418ff9fff8318d0142fa101efd9dc08.zip
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
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
-rw-r--r--src/rustllvm/RustWrapper.cpp12
1 files changed, 12 insertions, 0 deletions
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<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;