From: whitequark Date: Tue, 17 Jul 2018 10:57:39 +0000 (+0000) Subject: [LLVM-C] Add target triple normalization to the C API. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1907eb80ac01e7ed169c99c42977d1f7833b60a8;p=llvm [LLVM-C] Add target triple normalization to the C API. rL333307 was introduced to remove automatic target triple normalization when calling sys::getDefaultTargetTriple(), arguing that users of the latter already called Triple::normalize() if necessary. However, users of the C API currently have no way of doing target triple normalization. This patch introduces an LLVMNormalizeTargetTriple function to the C API which wraps Triple::normalize() and can be used on the result of LLVMGetDefaultTargetTriple to achieve the same effect. Differential Revision: https://reviews.llvm.org/D49414 Reviewed By: whitequark git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337263 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm-c/TargetMachine.h b/include/llvm-c/TargetMachine.h index fb0862c226a..7f672b5d10d 100644 --- a/include/llvm-c/TargetMachine.h +++ b/include/llvm-c/TargetMachine.h @@ -137,6 +137,10 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleR disposed with LLVMDisposeMessage. */ char* LLVMGetDefaultTargetTriple(void); +/** Normalize a target triple. The result needs to be disposed with + LLVMDisposeMessage. */ +char* LLVMNormalizeTargetTriple(const char* triple); + /** Get the host CPU as a string. The result needs to be disposed with LLVMDisposeMessage. */ char* LLVMGetHostCPUName(void); diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index a6f4790b866..37d398d580f 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -238,6 +238,10 @@ char *LLVMGetDefaultTargetTriple(void) { return strdup(sys::getDefaultTargetTriple().c_str()); } +char *LLVMNormalizeTargetTriple(const char* triple) { + return strdup(Triple::normalize(StringRef(triple)).c_str()); +} + char *LLVMGetHostCPUName(void) { return strdup(sys::getHostCPUName().data()); }