diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2015-08-26 18:37:59 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2015-08-26 18:37:59 +0000 |
commit | 8b3dda3f71293c3a6588b1b12dc61164654b5ed1 (patch) | |
tree | d6248e5beb83fe45d9815b5340def181d79217be /llvm/lib/Target/TargetMachineC.cpp | |
parent | 19c5488015f6ed349fceebb1e5138b04dce65ce8 (diff) | |
download | bcm5719-llvm-8b3dda3f71293c3a6588b1b12dc61164654b5ed1.tar.gz bcm5719-llvm-8b3dda3f71293c3a6588b1b12dc61164654b5ed1.zip |
Revert "Fix LLVM C API for DataLayout"
This reverts commit r246044.
Build broken, still. It builds for me...
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 246049
Diffstat (limited to 'llvm/lib/Target/TargetMachineC.cpp')
-rw-r--r-- | llvm/lib/Target/TargetMachineC.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp index 6255448a7e3..b2bd8fae423 100644 --- a/llvm/lib/Target/TargetMachineC.cpp +++ b/llvm/lib/Target/TargetMachineC.cpp @@ -32,14 +32,25 @@ 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; +}; + + static TargetMachine *unwrap(LLVMTargetMachineRef P) { - return reinterpret_cast<TargetMachine *>(P); + return P->Machine.get(); } static Target *unwrap(LLVMTargetRef P) { return reinterpret_cast<Target*>(P); } static LLVMTargetMachineRef wrap(const TargetMachine *P) { - return reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine *>(P)); + return new LLVMOpaqueTargetMachine{ std::unique_ptr<TargetMachine>(const_cast<TargetMachine*>(P)), P->createDataLayout() }; } static LLVMTargetRef wrap(const Target * P) { return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P)); @@ -68,16 +79,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; } @@ -144,7 +155,10 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, CM, OL)); } -void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) { delete unwrap(T); } + +void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) { + delete T; +} LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) { const Target* target = &(unwrap(T)->getTarget()); @@ -166,9 +180,9 @@ char* LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T) { return strdup(StringRep.c_str()); } -/** Deprecated: use LLVMGetDataLayout(LLVMModuleRef M) instead. */ +/// @deprecated: see "struct LLVMOpaqueTargetMachine" description above LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) { - return wrap(&unwrap(T)->getDataLayout()); + return wrap(&T->DL); } void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, |