Add a -S option for producing assembly. I will move more of it to

rust once the necessary APIs are available in C.
This commit is contained in:
Rafael Ávila de Espíndola
2011-04-15 17:35:46 -04:00
parent 790084ced1
commit 2214b6835d
5 changed files with 68 additions and 20 deletions

View File

@@ -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));
}