X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FTargetMachineC.cpp;h=f82566c37baa43c4d237fdffd8f720514ac526d1;hb=54fa7b1f76bfc2573cd0d4bebe1eff8c80a892d8;hp=eae23e6e67fead4788cfe5e26c0f90ced1368bda;hpb=15e1e7f179e9740321df5cd9af21db5777044d9f;p=oota-llvm.git diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index eae23e6e67f..f82566c37ba 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -32,27 +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; +namespace llvm { +// Friend to the TargetMachine, access legacy API that are made private in C++ +struct C_API_PRIVATE_ACCESS { + static const DataLayout &getDataLayout(const TargetMachine &T) { + return T.getDataLayout(); + } }; +} - -inline TargetMachine *unwrap(LLVMTargetMachineRef P) { - return P->Machine.get(); +static TargetMachine *unwrap(LLVMTargetMachineRef P) { + return reinterpret_cast(P); } -inline Target *unwrap(LLVMTargetRef P) { +static Target *unwrap(LLVMTargetRef P) { return reinterpret_cast(P); } -inline LLVMTargetMachineRef wrap(const TargetMachine *P) { - return new LLVMOpaqueTargetMachine{ std::unique_ptr(const_cast(P)), P->createDataLayout() }; +static LLVMTargetMachineRef wrap(const TargetMachine *P) { + return reinterpret_cast(const_cast(P)); } -inline LLVMTargetRef wrap(const Target * P) { +static LLVMTargetRef wrap(const Target * P) { return reinterpret_cast(const_cast(P)); } @@ -79,16 +77,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; } @@ -155,10 +153,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, 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 +175,9 @@ char* LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T) { 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(&C_API_PRIVATE_ACCESS::getDataLayout(*unwrap(T))); } void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, @@ -243,7 +238,6 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, SmallString<0> CodeString; raw_svector_ostream OStream(CodeString); bool Result = LLVMTargetMachineEmit(T, M, OStream, codegen, ErrorMessage); - OStream.flush(); StringRef Data = OStream.str(); *OutMemBuf =