Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 1907eb8

Browse files
committed
[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
1 parent f948d85 commit 1907eb8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/llvm-c/TargetMachine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleR
137137
disposed with LLVMDisposeMessage. */
138138
char* LLVMGetDefaultTargetTriple(void);
139139

140+
/** Normalize a target triple. The result needs to be disposed with
141+
LLVMDisposeMessage. */
142+
char* LLVMNormalizeTargetTriple(const char* triple);
143+
140144
/** Get the host CPU as a string. The result needs to be disposed with
141145
LLVMDisposeMessage. */
142146
char* LLVMGetHostCPUName(void);

lib/Target/TargetMachineC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ char *LLVMGetDefaultTargetTriple(void) {
238238
return strdup(sys::getDefaultTargetTriple().c_str());
239239
}
240240

241+
char *LLVMNormalizeTargetTriple(const char* triple) {
242+
return strdup(Triple::normalize(StringRef(triple)).c_str());
243+
}
244+
241245
char *LLVMGetHostCPUName(void) {
242246
return strdup(sys::getHostCPUName().data());
243247
}

0 commit comments

Comments
 (0)