1 //===- DIBuilderBindings.cpp - Bindings for DIBuilder ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines C bindings for the DIBuilder class.
12 //===----------------------------------------------------------------------===//
14 #include "DIBuilderBindings.h"
16 #include "IRBindings.h"
17 #include "llvm/IR/IRBuilder.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/IR/DIBuilder.h"
23 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
26 template <typename T> T unwrapDI(LLVMMetadataRef v) {
27 return v ? T(unwrap<MDNode>(v)) : T();
31 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
32 Module *m = unwrap(mref);
33 return wrap(new DIBuilder(*m));
36 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
37 DIBuilder *d = unwrap(dref);
41 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); }
43 LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
44 unsigned Lang, const char *File,
47 int Optimized, const char *Flags,
48 unsigned RuntimeVersion) {
49 DIBuilder *D = unwrap(Dref);
50 DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
51 Flags, RuntimeVersion);
55 LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File,
57 DIBuilder *D = unwrap(Dref);
58 DIFile F = D->createFile(File, Dir);
62 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
63 LLVMMetadataRef Scope,
67 DIBuilder *D = unwrap(Dref);
68 DILexicalBlock LB = D->createLexicalBlock(
69 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
73 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
74 LLVMMetadataRef Scope,
76 unsigned Discriminator) {
77 DIBuilder *D = unwrap(Dref);
78 DILexicalBlockFile LBF = D->createLexicalBlockFile(
79 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Discriminator);
83 LLVMMetadataRef LLVMDIBuilderCreateFunction(
84 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
85 const char *LinkageName, LLVMMetadataRef File, unsigned Line,
86 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
87 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
88 DIBuilder *D = unwrap(Dref);
89 DISubprogram SP = D->createFunction(
90 unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
91 Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit,
92 IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func));
96 LLVMMetadataRef LLVMDIBuilderCreateLocalVariable(
97 LLVMDIBuilderRef Dref, unsigned Tag, LLVMMetadataRef Scope,
98 const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
99 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
100 DIBuilder *D = unwrap(Dref);
101 DIVariable V = D->createLocalVariable(
102 Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
103 unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo);
107 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
110 uint64_t AlignInBits,
112 DIBuilder *D = unwrap(Dref);
113 DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
117 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
118 LLVMMetadataRef PointeeType,
120 uint64_t AlignInBits,
122 DIBuilder *D = unwrap(Dref);
123 DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
124 SizeInBits, AlignInBits, Name);
129 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
130 LLVMMetadataRef ParameterTypes) {
131 DIBuilder *D = unwrap(Dref);
132 DICompositeType CT = D->createSubroutineType(
133 unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes));
137 LLVMMetadataRef LLVMDIBuilderCreateStructType(
138 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
139 LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
140 uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
141 LLVMMetadataRef ElementTypes) {
142 DIBuilder *D = unwrap(Dref);
143 DICompositeType CT = D->createStructType(
144 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
145 SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
146 unwrapDI<DIArray>(ElementTypes));
151 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
152 const char *Name, LLVMMetadataRef File,
153 unsigned Line, uint64_t SizeInBits,
154 uint64_t AlignInBits, uint64_t OffsetInBits,
155 unsigned Flags, LLVMMetadataRef Ty) {
156 DIBuilder *D = unwrap(Dref);
157 DIDerivedType DT = D->createMemberType(
158 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
159 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
163 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
165 uint64_t AlignInBits,
166 LLVMMetadataRef ElementType,
167 LLVMMetadataRef Subscripts) {
168 DIBuilder *D = unwrap(Dref);
170 D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
171 unwrapDI<DIArray>(Subscripts));
175 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
176 LLVMMetadataRef Ty, const char *Name,
177 LLVMMetadataRef File, unsigned Line,
178 LLVMMetadataRef Context) {
179 DIBuilder *D = unwrap(Dref);
181 D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
182 unwrapDI<DIDescriptor>(Context));
186 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
187 int64_t Lo, int64_t Count) {
188 DIBuilder *D = unwrap(Dref);
189 DISubrange S = D->getOrCreateSubrange(Lo, Count);
193 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
194 LLVMMetadataRef *Data,
196 DIBuilder *D = unwrap(Dref);
197 Metadata **DataValue = unwrap(Data);
198 ArrayRef<Metadata *> Elements(DataValue, Length);
199 DIArray A = D->getOrCreateArray(Elements);
203 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
204 LLVMMetadataRef *Data,
206 DIBuilder *D = unwrap(Dref);
207 Metadata **DataValue = unwrap(Data);
208 ArrayRef<Metadata *> Elements(DataValue, Length);
209 DITypeArray A = D->getOrCreateTypeArray(Elements);
213 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
214 int64_t *Addr, size_t Length) {
215 DIBuilder *D = unwrap(Dref);
216 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
220 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
221 LLVMValueRef Storage,
222 LLVMMetadataRef VarInfo,
223 LLVMMetadataRef Expr,
224 LLVMBasicBlockRef Block) {
225 DIBuilder *D = unwrap(Dref);
227 D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
228 unwrapDI<DIExpression>(Expr), unwrap(Block));
232 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
233 LLVMValueRef Val, uint64_t Offset,
234 LLVMMetadataRef VarInfo,
235 LLVMMetadataRef Expr,
236 LLVMBasicBlockRef Block) {
237 DIBuilder *D = unwrap(Dref);
238 Instruction *Instr = D->insertDbgValueIntrinsic(
239 unwrap(Val), Offset, unwrapDI<DIVariable>(VarInfo),
240 unwrapDI<DIExpression>(Expr), unwrap(Block));