X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FTargetMachineC.cpp;h=9e1c8997518ec0740fa87f90a999e8764acdc812;hb=974a445bd90795248274493eda5cdbf6721910f7;hp=19e78b83a74c4b003f0e03f763dea7e822b8d046;hpb=40be1e85665d10f5444186f0e7106e368dd735b8;p=oota-llvm.git diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index 19e78b83a74..9e1c8997518 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -19,6 +19,7 @@ #include "llvm/PassManager.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Host.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" @@ -60,13 +61,44 @@ inline LLVMTargetRef wrap(const Target * P) { } LLVMTargetRef LLVMGetFirstTarget() { - const Target* target = &*TargetRegistry::begin(); - return wrap(target); + if(TargetRegistry::begin() == TargetRegistry::end()) { + return NULL; + } + + const Target* target = &*TargetRegistry::begin(); + return wrap(target); } LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T) { return wrap(unwrap(T)->getNext()); } +LLVMTargetRef LLVMGetTargetFromName(const char *Name) { + StringRef NameRef = Name; + for (TargetRegistry::iterator IT = TargetRegistry::begin(), + IE = TargetRegistry::end(); IT != IE; ++IT) { + if (IT->getName() == NameRef) + return wrap(&*IT); + } + + return NULL; +} + +LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T, + char **ErrorMessage) { + std::string Error; + + *T = wrap(TargetRegistry::lookupTarget(TripleStr, Error)); + + if (!*T) { + if (ErrorMessage) + *ErrorMessage = strdup(Error.c_str()); + + return 1; + } + + return 0; +} + const char * LLVMGetTargetName(LLVMTargetRef T) { return unwrap(T)->getName(); } @@ -87,9 +119,10 @@ LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T) { return unwrap(T)->hasMCAsmBackend(); } -LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char* Triple, - char* CPU, char* Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, - LLVMCodeModel CodeModel) { +LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, + const char* Triple, const char* CPU, const char* Features, + LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, + LLVMCodeModel CodeModel) { Reloc::Model RM; switch (Reloc){ case LLVMRelocStatic: @@ -106,29 +139,9 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char* Triple, break; } - CodeModel::Model CM; - switch (CodeModel) { - case LLVMCodeModelJITDefault: - CM = CodeModel::JITDefault; - break; - case LLVMCodeModelSmall: - CM = CodeModel::Small; - break; - case LLVMCodeModelKernel: - CM = CodeModel::Kernel; - break; - case LLVMCodeModelMedium: - CM = CodeModel::Medium; - break; - case LLVMCodeModelLarge: - CM = CodeModel::Large; - break; - default: - CM = CodeModel::Default; - break; - } - CodeGenOpt::Level OL; + CodeModel::Model CM = unwrap(CodeModel); + CodeGenOpt::Level OL; switch (Level) { case LLVMCodeGenLevelNone: OL = CodeGenOpt::None; @@ -178,6 +191,11 @@ LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) { return wrap(unwrap(T)->getDataLayout()); } +void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, + LLVMBool VerboseAsm) { + unwrap(T)->setAsmVerbosityDefault(VerboseAsm); +} + static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, formatted_raw_ostream &OS, LLVMCodeGenFileType codegen, char **ErrorMessage) { TargetMachine* TM = unwrap(T); @@ -220,12 +238,12 @@ 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, raw_fd_ostream::F_Binary); - formatted_raw_ostream destf(dest); + raw_fd_ostream dest(Filename, error, sys::fs::F_Binary); if (!error.empty()) { *ErrorMessage = strdup(error.c_str()); return true; } + formatted_raw_ostream destf(dest); bool Result = LLVMTargetMachineEmit(T, M, destf, codegen, ErrorMessage); dest.flush(); return Result; @@ -245,3 +263,7 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, Data.length(), ""); return Result; } + +char *LLVMGetDefaultTargetTriple(void) { + return strdup(sys::getDefaultTargetTriple().c_str()); +}