diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2015-08-26 21:16:29 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2015-08-26 21:16:29 +0000 |
commit | 0ab4b5b52e5828a23c7d7d37b7c5cba6cf86895a (patch) | |
tree | d25592692deaae28c660295944471e859590684a /llvm/lib/Target/TargetMachineC.cpp | |
parent | 9d7593fb33c50d6960dbf89e7c12b1417617b187 (diff) | |
download | bcm5719-llvm-0ab4b5b52e5828a23c7d7d37b7c5cba6cf86895a.tar.gz bcm5719-llvm-0ab4b5b52e5828a23c7d7d37b7c5cba6cf86895a.zip |
Fix LLVM C API for DataLayout
We removed access to the DataLayout on the TargetMachine and
deprecated the C API function LLVMGetTargetMachineData() in r243114.
However the way I tried to be backward compatible was broken: I
changed the wrapper of the TargetMachine to be a structure that
includes the DataLayout as well. However the TargetMachine is also
wrapped by the ExecutionEngine, in the more classic way. A client
using the TargetMachine wrapped by the ExecutionEngine and trying
to get the DataLayout would break.
It seems tricky to solve the problem completely in the C API
implementation. This patch tries to address this backward
compatibility in a more lighter way in the C++ API. The C API is
restored in its original state and the removed C++ API is
reintroduced, but privately. The C API is friended to the
TargetMachine and should be the only consumer for this API.
Reviewers: ributzka
Differential Revision: http://reviews.llvm.org/D12263
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 246082
Diffstat (limited to 'llvm/lib/Target/TargetMachineC.cpp')
-rw-r--r-- | llvm/lib/Target/TargetMachineC.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp index b2bd8fae423..f82566c37ba 100644 --- a/llvm/lib/Target/TargetMachineC.cpp +++ b/llvm/lib/Target/TargetMachineC.cpp @@ -32,25 +32,23 @@ using namespace llvm; - -// The TargetMachine uses to offer access to a DataLayout member. This is reflected -// in the C API. For backward compatibility reason, this structure allows to keep -// a DataLayout member accessible to C client that have a handle to a -// LLVMTargetMachineRef. -struct LLVMOpaqueTargetMachine { - std::unique_ptr<TargetMachine> Machine; - DataLayout DL; +namespace llvm { +// Friend to the TargetMachine, access legacy API that are made private in C++ +struct C_API_PRIVATE_ACCESS { + static const DataLayout &getDataLayout(const TargetMachine &T) { + return T.getDataLayout(); + } }; - +} static TargetMachine *unwrap(LLVMTargetMachineRef P) { - return P->Machine.get(); + return reinterpret_cast<TargetMachine *>(P); } static Target *unwrap(LLVMTargetRef P) { return reinterpret_cast<Target*>(P); } static LLVMTargetMachineRef wrap(const TargetMachine *P) { - return new LLVMOpaqueTargetMachine{ std::unique_ptr<TargetMachine>(const_cast<TargetMachine*>(P)), P->createDataLayout() }; + return reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine *>(P)); } static LLVMTargetRef wrap(const Target * P) { return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P)); @@ -79,16 +77,16 @@ LLVMTargetRef LLVMGetTargetFromName(const char *Name) { 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; } @@ -155,10 +153,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, CM, OL)); } - -void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) { - delete T; -} +void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) { delete unwrap(T); } LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) { const Target* target = &(unwrap(T)->getTarget()); @@ -180,9 +175,9 @@ char* LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T) { return strdup(StringRep.c_str()); } -/// @deprecated: see "struct LLVMOpaqueTargetMachine" description above +/** Deprecated: use LLVMGetDataLayout(LLVMModuleRef M) instead. */ LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) { - return wrap(&T->DL); + return wrap(&C_API_PRIVATE_ACCESS::getDataLayout(*unwrap(T))); } void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, |