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"
15 #include "IRBindings.h"
16 #include "llvm/IR/DIBuilder.h"
17 #include "llvm/IR/IRBuilder.h"
18 #include "llvm/IR/Module.h"
22 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
24 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
25 Module *m = unwrap(mref);
26 return wrap(new DIBuilder(*m));
29 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
30 DIBuilder *d = unwrap(dref);
34 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); }
36 LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
37 unsigned Lang, const char *File,
40 int Optimized, const char *Flags,
41 unsigned RuntimeVersion) {
42 DIBuilder *D = unwrap(Dref);
43 DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
44 Flags, RuntimeVersion);
48 LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File,
50 DIBuilder *D = unwrap(Dref);
51 DIFile F = D->createFile(File, Dir);
55 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
56 LLVMMetadataRef Scope,
60 DIBuilder *D = unwrap(Dref);
62 D->createLexicalBlock(DIDescriptor(unwrap<MDLocalScope>(Scope)),
63 unwrap<MDFile>(File), Line, Column);
67 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
68 LLVMMetadataRef Scope,
70 unsigned Discriminator) {
71 DIBuilder *D = unwrap(Dref);
72 DILexicalBlockFile LBF =
73 D->createLexicalBlockFile(DIDescriptor(unwrap<MDLocalScope>(Scope)),
74 unwrap<MDFile>(File), Discriminator);
78 LLVMMetadataRef LLVMDIBuilderCreateFunction(
79 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
80 const char *LinkageName, LLVMMetadataRef File, unsigned Line,
81 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
82 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
83 DIBuilder *D = unwrap(Dref);
84 DISubprogram SP = D->createFunction(
85 DIDescriptor(unwrap<MDScope>(Scope)), Name, LinkageName,
86 File ? unwrap<MDFile>(File) : nullptr, Line,
87 unwrap<MDCompositeTypeBase>(CompositeType), IsLocalToUnit, IsDefinition,
88 ScopeLine, Flags, IsOptimized, unwrap<Function>(Func));
92 LLVMMetadataRef LLVMDIBuilderCreateLocalVariable(
93 LLVMDIBuilderRef Dref, unsigned Tag, LLVMMetadataRef Scope,
94 const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
95 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
96 DIBuilder *D = unwrap(Dref);
97 DIVariable V = D->createLocalVariable(
98 Tag, DIDescriptor(unwrap<MDScope>(Scope)), Name, unwrap<MDFile>(File),
99 Line, unwrap<MDType>(Ty), AlwaysPreserve, Flags, ArgNo);
103 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
106 uint64_t AlignInBits,
108 DIBuilder *D = unwrap(Dref);
109 DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
113 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
114 LLVMMetadataRef PointeeType,
116 uint64_t AlignInBits,
118 DIBuilder *D = unwrap(Dref);
119 DIDerivedType T = D->createPointerType(unwrap<MDType>(PointeeType),
120 SizeInBits, AlignInBits, Name);
125 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
126 LLVMMetadataRef ParameterTypes) {
127 DIBuilder *D = unwrap(Dref);
129 D->createSubroutineType(File ? unwrap<MDFile>(File) : nullptr,
130 DITypeArray(unwrap<MDTuple>(ParameterTypes)));
134 LLVMMetadataRef LLVMDIBuilderCreateStructType(
135 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
136 LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
137 uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
138 LLVMMetadataRef ElementTypes) {
139 DIBuilder *D = unwrap(Dref);
140 DICompositeType CT = D->createStructType(
141 DIDescriptor(unwrap<MDScope>(Scope)), Name,
142 File ? unwrap<MDFile>(File) : nullptr, Line, SizeInBits, AlignInBits,
143 Flags, DerivedFrom ? unwrap<MDType>(DerivedFrom) : nullptr,
144 ElementTypes ? DIArray(unwrap<MDTuple>(ElementTypes)) : nullptr);
148 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
149 LLVMDIBuilderRef Dref, unsigned Tag, const char *Name,
150 LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
151 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
153 DIBuilder *D = unwrap(Dref);
154 DICompositeType CT = D->createReplaceableCompositeType(
155 Tag, Name, DIDescriptor(unwrap<MDScope>(Scope)),
156 File ? unwrap<MDFile>(File) : nullptr, Line, RuntimeLang, SizeInBits,
162 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
163 const char *Name, LLVMMetadataRef File,
164 unsigned Line, uint64_t SizeInBits,
165 uint64_t AlignInBits, uint64_t OffsetInBits,
166 unsigned Flags, LLVMMetadataRef Ty) {
167 DIBuilder *D = unwrap(Dref);
168 DIDerivedType DT = D->createMemberType(
169 DIDescriptor(unwrap<MDScope>(Scope)), Name,
170 File ? unwrap<MDFile>(File) : nullptr, Line, SizeInBits, AlignInBits,
171 OffsetInBits, Flags, unwrap<MDType>(Ty));
175 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
177 uint64_t AlignInBits,
178 LLVMMetadataRef ElementType,
179 LLVMMetadataRef Subscripts) {
180 DIBuilder *D = unwrap(Dref);
182 D->createArrayType(SizeInBits, AlignInBits, unwrap<MDType>(ElementType),
183 DIArray(unwrap<MDTuple>(Subscripts)));
187 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
188 LLVMMetadataRef Ty, const char *Name,
189 LLVMMetadataRef File, unsigned Line,
190 LLVMMetadataRef Context) {
191 DIBuilder *D = unwrap(Dref);
192 DIDerivedType DT = D->createTypedef(
193 unwrap<MDType>(Ty), Name, File ? unwrap<MDFile>(File) : nullptr, Line,
194 Context ? DIDescriptor(unwrap<MDScope>(Context)) : DIDescriptor());
198 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
199 int64_t Lo, int64_t Count) {
200 DIBuilder *D = unwrap(Dref);
201 DISubrange S = D->getOrCreateSubrange(Lo, Count);
205 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
206 LLVMMetadataRef *Data,
208 DIBuilder *D = unwrap(Dref);
209 Metadata **DataValue = unwrap(Data);
210 ArrayRef<Metadata *> Elements(DataValue, Length);
211 DIArray A = D->getOrCreateArray(Elements);
212 return wrap(A.get());
215 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
216 LLVMMetadataRef *Data,
218 DIBuilder *D = unwrap(Dref);
219 Metadata **DataValue = unwrap(Data);
220 ArrayRef<Metadata *> Elements(DataValue, Length);
221 DITypeArray A = D->getOrCreateTypeArray(Elements);
222 return wrap(A.get());
225 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
226 int64_t *Addr, size_t Length) {
227 DIBuilder *D = unwrap(Dref);
228 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
232 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
233 LLVMValueRef Storage,
234 LLVMMetadataRef VarInfo,
235 LLVMMetadataRef Expr,
236 LLVMBasicBlockRef Block) {
237 DIBuilder *D = unwrap(Dref);
239 D->insertDeclare(unwrap(Storage), unwrap<MDLocalVariable>(VarInfo),
240 unwrap<MDExpression>(Expr), unwrap(Block));
244 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
245 LLVMValueRef Val, uint64_t Offset,
246 LLVMMetadataRef VarInfo,
247 LLVMMetadataRef Expr,
248 LLVMBasicBlockRef Block) {
249 DIBuilder *D = unwrap(Dref);
250 Instruction *Instr = D->insertDbgValueIntrinsic(
251 unwrap(Val), Offset, unwrap<MDLocalVariable>(VarInfo),
252 unwrap<MDExpression>(Expr), unwrap(Block));