Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -59,6 +59,13 @@ } using legacy::PassManagerBase; +extern "C" { +// This function from the C API is deprecated. We still supports it using a +// private method on the TargetMachine for now. But it needs to be friended and +// so we forward declare it here. +LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T); +} + //===----------------------------------------------------------------------===// /// /// Primary interface to the complete machine description for the target @@ -103,6 +110,12 @@ unsigned RequireStructuredCFG : 1; + /// This API is here to support the C API, deprecated in 3.7 release. + /// This should never be used outside of legacy existing client. + const DataLayout &getDataLayout() const { return DL; } + friend struct LLVMOpaqueTargetData * ::LLVMGetTargetMachineData( + LLVMTargetMachineRef T); + public: mutable TargetOptions Options; Index: lib/Target/TargetMachineC.cpp =================================================================== --- lib/Target/TargetMachineC.cpp +++ lib/Target/TargetMachineC.cpp @@ -32,25 +32,14 @@ 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 P->Machine.get(); + return reinterpret_cast(P); } static Target *unwrap(LLVMTargetRef P) { return reinterpret_cast(P); } static LLVMTargetMachineRef wrap(const TargetMachine *P) { - return new LLVMOpaqueTargetMachine{ std::unique_ptr(const_cast(P)), P->createDataLayout() }; + return reinterpret_cast(const_cast(P)); } static LLVMTargetRef wrap(const Target * P) { return reinterpret_cast(const_cast(P)); @@ -79,16 +68,16 @@ 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 +144,7 @@ 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 +166,9 @@ 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(&unwrap(T)->getDataLayout()); } void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,