From f83b86544849588e761ed883f58b48432128586f Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 25 Aug 2015 01:21:09 +0000 Subject: Revert "Fix LLVM C API for DataLayout" This reverts commit 433bfd94e4b7e3cc3f8b08f8513ce47817941b0c. Broke some bot, have to see why it passed locally. From: Mehdi Amini llvm-svn: 245917 --- llvm/lib/Target/TargetMachineC.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'llvm/lib/Target/TargetMachineC.cpp') 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 Machine; + DataLayout DL; +}; + + static TargetMachine *unwrap(LLVMTargetMachineRef P) { - return reinterpret_cast(P); + return P->Machine.get(); } static Target *unwrap(LLVMTargetRef P) { return reinterpret_cast(P); } static LLVMTargetMachineRef wrap(const TargetMachine *P) { - return reinterpret_cast(const_cast(P)); + return new LLVMOpaqueTargetMachine{ std::unique_ptr(const_cast(P)), P->createDataLayout() }; } static LLVMTargetRef wrap(const Target * P) { return reinterpret_cast(const_cast(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, -- cgit v1.2.3