mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
Introducing LLVMMetadataRef
Summary: This seems like an uncontroversial first step toward providing access to the metadata hierarchy that now exists in LLVM. This should allow for good debug info support from C. Future plans are to deprecate API that take mixed bags of values and metadata (mainly the LLVMMDNode family of functions) and migrate the rest toward the use of LLVMMetadataRef. Once this is in place, mapping of DIBuilder will be able to start. Reviewers: mehdi_amini, echristo, whitequark, jketema, Wallbraker Reviewed By: Wallbraker Subscribers: Eugene.Zelenko, axw, mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D19448 llvm-svn: 300447
This commit is contained in:
parent
d4bdf4737d
commit
5cbde7845f
@ -26,7 +26,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
|
||||
struct LLVMDebugLocMetadata{
|
||||
unsigned Line;
|
||||
unsigned Col;
|
||||
@ -59,16 +58,6 @@ void LLVMSetSubprogram(LLVMValueRef Fn, LLVMMetadataRef SP);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
|
||||
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
|
||||
|
||||
inline Metadata **unwrap(LLVMMetadataRef *Vals) {
|
||||
return reinterpret_cast<Metadata**>(Vals);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -2130,6 +2130,16 @@ LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
|
||||
*/
|
||||
LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
|
||||
|
||||
/**
|
||||
* Obtain a Metadata as a Value.
|
||||
*/
|
||||
LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
|
||||
|
||||
/**
|
||||
* Obtain a Value as a Metadata.
|
||||
*/
|
||||
LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
|
||||
|
||||
/**
|
||||
* Obtain the underlying string from a MDString value.
|
||||
*
|
||||
|
@ -82,6 +82,13 @@ typedef struct LLVMOpaqueValue *LLVMValueRef;
|
||||
*/
|
||||
typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
|
||||
|
||||
/**
|
||||
* Represents an LLVM Metadata.
|
||||
*
|
||||
* This models llvm::Metadata.
|
||||
*/
|
||||
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
|
||||
|
||||
/**
|
||||
* Represents an LLVM basic block builder.
|
||||
*
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
@ -133,6 +134,14 @@ public:
|
||||
/// @}
|
||||
};
|
||||
|
||||
// Create wrappers for C Binding types (see CBindingWrapping.h).
|
||||
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
|
||||
|
||||
// Specialized opaque metadata conversions.
|
||||
inline Metadata **unwrap(LLVMMetadataRef *MDs) {
|
||||
return reinterpret_cast<Metadata**>(MDs);
|
||||
}
|
||||
|
||||
#define HANDLE_METADATA(CLASS) class CLASS;
|
||||
#include "llvm/IR/Metadata.def"
|
||||
|
||||
|
@ -863,6 +863,19 @@ LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
|
||||
return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
|
||||
return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val) {
|
||||
auto *V = unwrap(Val);
|
||||
if (auto *C = dyn_cast<Constant>(V))
|
||||
return wrap(ConstantAsMetadata::get(C));
|
||||
if (auto *MAV = dyn_cast<MetadataAsValue>(V))
|
||||
return wrap(MAV->getMetadata());
|
||||
return wrap(ValueAsMetadata::get(V));
|
||||
}
|
||||
|
||||
const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length) {
|
||||
if (const auto *MD = dyn_cast<MetadataAsValue>(unwrap(V)))
|
||||
if (const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
|
||||
|
Loading…
Reference in New Issue
Block a user