diff options
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index ac9b48cda8f..81b8cbc9e0c 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -12,10 +12,18 @@ // //===----------------------------------------------------------------------===// +#include "llvm/PassManager.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Support/FormattedStream.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetSelect.h" +#include "llvm/Target/TargetRegistry.h" #include "llvm-c/Core.h" #include "llvm-c/Object.h" #include <cstdlib> +using namespace llvm; + static char *LLVMRustError; extern "C" LLVMMemoryBufferRef @@ -33,3 +41,24 @@ extern "C" void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM); void (*RustHackToFetchPassesO)(LLVMPassManagerRef PM) = LLVMAddBasicAliasAnalysisPass; + +extern "C" void LLVMRustWriteAssembly(LLVMPassManagerRef PMR, LLVMModuleRef M, + const char *triple, const char *path) { + InitializeAllTargets(); + InitializeAllAsmPrinters(); + std::string Err; + const Target *TheTarget = TargetRegistry::lookupTarget(triple, Err); + std::string FeaturesStr; + TargetMachine &Target = *TheTarget->createTargetMachine(triple, FeaturesStr); + bool NoVerify = false; + CodeGenOpt::Level OLvl = CodeGenOpt::Default; + TargetMachine::CodeGenFileType FileType = TargetMachine::CGFT_AssemblyFile; + PassManager *PM = unwrap<PassManager>(PMR); + std::string ErrorInfo; + raw_fd_ostream OS(path, ErrorInfo, + raw_fd_ostream::F_Binary); + formatted_raw_ostream FOS(OS); + bool foo = Target.addPassesToEmitFile(*PM, FOS, FileType, OLvl, NoVerify); + assert(!foo); + PM->run(*unwrap(M)); +} |
