X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FTargetMachineC.cpp;h=20923c97ec8815c79a55b71d4becb84ec4def8c7;hb=998d8f50a777f3799c7c86d4a4262e7528237ae1;hp=e111380c628366c8aef4883157c827383bf17b15;hpb=fa74752298602e0b74fb60ce3f0e76d0c461d3d8;p=oota-llvm.git diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index e111380c628..20923c97ec8 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -18,10 +18,11 @@ #include "llvm/IR/Module.h" #include "llvm/PassManager.h" #include "llvm/Support/CodeGen.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Host.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/Host.h" #include "llvm/Target/TargetMachine.h" #include #include @@ -29,23 +30,6 @@ using namespace llvm; -inline DataLayout *unwrap(LLVMTargetDataRef P) { - return reinterpret_cast(P); -} - -inline LLVMTargetDataRef wrap(const DataLayout *P) { - return reinterpret_cast(const_cast(P)); -} - -inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) { - return reinterpret_cast(P); -} - -inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) { - TargetLibraryInfo *X = const_cast(P); - return reinterpret_cast(X); -} - inline TargetMachine *unwrap(LLVMTargetMachineRef P) { return reinterpret_cast(P); } @@ -62,7 +46,7 @@ inline LLVMTargetRef wrap(const Target * P) { LLVMTargetRef LLVMGetFirstTarget() { if(TargetRegistry::begin() == TargetRegistry::end()) { - return NULL; + return nullptr; } const Target* target = &*TargetRegistry::begin(); @@ -73,13 +57,14 @@ LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T) { } LLVMTargetRef LLVMGetTargetFromName(const char *Name) { + StringRef NameRef = Name; for (TargetRegistry::iterator IT = TargetRegistry::begin(), IE = TargetRegistry::end(); IT != IE; ++IT) { - if (IT->getName() == Name) + if (IT->getName() == NameRef) return wrap(&*IT); } - return NULL; + return nullptr; } LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T, @@ -211,7 +196,8 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, *ErrorMessage = strdup(error.c_str()); return true; } - pass.add(new DataLayout(*td)); + Mod->setDataLayout(td); + pass.add(new DataLayoutPass(Mod)); TargetMachine::CodeGenFileType ft; switch (codegen) { @@ -237,7 +223,7 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, char* Filename, LLVMCodeGenFileType codegen, char** ErrorMessage) { std::string error; - raw_fd_ostream dest(Filename, error, sys::fs::F_Binary); + raw_fd_ostream dest(Filename, error, sys::fs::F_None); if (!error.empty()) { *ErrorMessage = strdup(error.c_str()); return true; @@ -266,3 +252,7 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, char *LLVMGetDefaultTargetTriple(void) { return strdup(sys::getDefaultTargetTriple().c_str()); } + +void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM) { + unwrap(T)->addAnalysisPasses(*unwrap(PM)); +}