Revert "Fix LLVM C API for DataLayout"
authorMehdi Amini <mehdi.amini@apple.com>
Wed, 26 Aug 2015 18:37:59 +0000 (18:37 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Wed, 26 Aug 2015 18:37:59 +0000 (18:37 +0000)
This reverts commit r246044.
Build broken, still. It builds for me...

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246049 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetMachine.h
lib/Target/TargetMachineC.cpp

index b2df9014bb7de99be1a5db642d348910d461f5c7..d707e7c029303166369a48dc84b7a8db16ddedba 100644 (file)
@@ -59,13 +59,6 @@ class PassManagerBase;
 }
 using legacy::PassManagerBase;
 
 }
 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
 //===----------------------------------------------------------------------===//
 ///
 /// Primary interface to the complete machine description for the target
@@ -110,12 +103,6 @@ protected: // Can only create subclasses.
 
   unsigned RequireStructuredCFG : 1;
 
 
   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;
 
 public:
   mutable TargetOptions Options;
 
index 6255448a7e3c5ba21076d359fbde0bff8e10aa42..b2bd8fae423edc5a1741a6336266aecb104079f6 100644 (file)
 
 using namespace llvm;
 
 
 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) {
 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) {
 }
 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));
 }
 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;
 LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T,
                                  char **ErrorMessage) {
   std::string Error;
-
+  
   *T = wrap(TargetRegistry::lookupTarget(TripleStr, Error));
   *T = wrap(TargetRegistry::lookupTarget(TripleStr, Error));
-
+  
   if (!*T) {
     if (ErrorMessage)
       *ErrorMessage = strdup(Error.c_str());
 
     return 1;
   }
   if (!*T) {
     if (ErrorMessage)
       *ErrorMessage = strdup(Error.c_str());
 
     return 1;
   }
-
+  
   return 0;
 }
 
   return 0;
 }
 
@@ -144,7 +155,10 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
     CM, OL));
 }
 
     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());
 
 LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) {
   const Target* target = &(unwrap(T)->getTarget());
@@ -166,9 +180,9 @@ char* LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T) {
   return strdup(StringRep.c_str());
 }
 
   return strdup(StringRep.c_str());
 }
 
-/** Deprecated: use LLVMGetDataLayout(LLVMModuleRef M) instead. */
+/// @deprecated: see "struct LLVMOpaqueTargetMachine" description above
 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
-  return wrap(&unwrap(T)->getDataLayout());
+  return wrap(&T->DL);
 }
 
 void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
 }
 
 void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,