llvm.org GIT mirror llvm / 603e72e
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300447 91177308-0d34-0410-b5e6-96231b3b80d8 Amaury Sechet 2 years ago
5 changed file(s) with 39 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2525 extern "C" {
2626 #endif
2727
28 typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
2928 struct LLVMDebugLocMetadata{
3029 unsigned Line;
3130 unsigned Col;
5857 #ifdef __cplusplus
5958 }
6059
61 namespace llvm {
62
63 DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
64
65 inline Metadata **unwrap(LLVMMetadataRef *Vals) {
66 return reinterpret_cast(Vals);
67 }
68
69 }
70
7160 #endif
7261
7362 #endif
2929 #include "llvm/IR/LLVMContext.h"
3030 #include "llvm/IR/Value.h"
3131 #include "llvm/Support/Casting.h"
32 #include "llvm/Support/CBindingWrapping.h"
3233 #include "llvm/Support/ErrorHandling.h"
3334 #include
3435 #include
131132 const Module *M = nullptr) const;
132133 /// @}
133134 };
135
136 // Create wrappers for C Binding types (see CBindingWrapping.h).
137 DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
138
139 // Specialized opaque metadata conversions.
140 inline Metadata **unwrap(LLVMMetadataRef *MDs) {
141 return reinterpret_cast(MDs);
142 }
134143
135144 #define HANDLE_METADATA(CLASS) class CLASS;
136145 #include "llvm/IR/Metadata.def"
21302130 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
21312131
21322132 /**
2133 * Obtain a Metadata as a Value.
2134 */
2135 LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2136
2137 /**
2138 * Obtain a Value as a Metadata.
2139 */
2140 LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2141
2142 /**
21332143 * Obtain the underlying string from a MDString value.
21342144 *
21352145 * @param V Instance to obtain string from.
8282 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
8383
8484 /**
85 * Represents an LLVM Metadata.
86 *
87 * This models llvm::Metadata.
88 */
89 typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
90
91 /**
8592 * Represents an LLVM basic block builder.
8693 *
8794 * This models llvm::IRBuilder.
860860
861861 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
862862 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
863 }
864
865 LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
866 return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
867 }
868
869 LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val) {
870 auto *V = unwrap(Val);
871 if (auto *C = dyn_cast(V))
872 return wrap(ConstantAsMetadata::get(C));
873 if (auto *MAV = dyn_cast(V))
874 return wrap(MAV->getMetadata());
875 return wrap(ValueAsMetadata::get(V));
863876 }
864877
865878 const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length) {