summaryrefslogtreecommitdiff
path: root/lib/Target/TargetMachineC.cpp
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2015-07-24 03:36:55 +0000
committerMehdi Amini <mehdi.amini@apple.com>2015-07-24 03:36:55 +0000
commit26be2142324893e254ec9ba91da3a54694936498 (patch)
tree512093eecbc7e8cc035495cb4a249b3ef2941d5b /lib/Target/TargetMachineC.cpp
parent90908cb34d73460d3aa83e2194a58d82c6d1f199 (diff)
Revert "Remove access to the DataLayout in the TargetMachine"
This reverts commit 0f720d984f419c747709462f7476dff962c0bc41. It breaks clang too badly, I need to prepare a proper patch for clang first. From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243089 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetMachineC.cpp')
-rw-r--r--lib/Target/TargetMachineC.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp
index eae23e6e67f..719923558de 100644
--- a/lib/Target/TargetMachineC.cpp
+++ b/lib/Target/TargetMachineC.cpp
@@ -32,25 +32,15 @@
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;
-};
-
-
inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
- return P->Machine.get();
+ return reinterpret_cast<TargetMachine*>(P);
}
inline Target *unwrap(LLVMTargetRef P) {
return reinterpret_cast<Target*>(P);
}
inline 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));
}
inline LLVMTargetRef wrap(const Target * P) {
return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
@@ -157,7 +147,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) {
- delete T;
+ delete unwrap(T);
}
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) {
@@ -180,9 +170,8 @@ char* LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T) {
return strdup(StringRep.c_str());
}
-/// @deprecated: see "struct LLVMOpaqueTargetMachine" description above
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
- return wrap(&T->DL);
+ return wrap(unwrap(T)->getDataLayout());
}
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
@@ -201,7 +190,14 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
std::string error;
- Mod->setDataLayout(TM->createDataLayout());
+ const DataLayout *td = TM->getDataLayout();
+
+ if (!td) {
+ error = "No DataLayout in TargetMachine";
+ *ErrorMessage = strdup(error.c_str());
+ return true;
+ }
+ Mod->setDataLayout(*td);
TargetMachine::CodeGenFileType ft;
switch (codegen) {