From 1acb2127bad420af19a5929df54a892957ba3c13 Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Wed, 6 Nov 2013 10:25:18 +0000 Subject: [llvm-c] Improve TargetMachine bindings Original patch by Chris Wailes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194143 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/TargetMachineC.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lib/Target/TargetMachineC.cpp') diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index 2bb0f4c3e9..36600d1c87 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -21,6 +21,7 @@ #include "llvm/Support/FormattedStream.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Host.h" #include "llvm/Target/TargetMachine.h" #include #include @@ -71,6 +72,35 @@ LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T) { return wrap(unwrap(T)->getNext()); } +LLVMBool LLVMGetTargetFromName(const char *Name, LLVMTargetRef *T) { + for (TargetRegistry::iterator IT = TargetRegistry::begin(), + IE = TargetRegistry::end(); IT != IE; ++IT) { + if (IT->getName() == Name) { + *T = wrap(&*IT); + + return 0; + } + } + + return 1; +} + +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(); } @@ -162,6 +192,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); @@ -229,3 +264,7 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, Data.length(), ""); return Result; } + +char *LLVMGetDefaultTargetTriple(void) { + return strdup(sys::getDefaultTargetTriple().c_str()); +} -- cgit v1.2.3