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)
25 template <typename T> T unwrapDI(LLVMMetadataRef v) {
26 return v ? T(unwrap<MDNode>(v)) : T();
30 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
31 Module *m = unwrap(mref);
32 return wrap(new DIBuilder(*m));
35 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
36 DIBuilder *d = unwrap(dref);
40 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); }
42 LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
43 unsigned Lang, const char *File,
46 int Optimized, const char *Flags,
47 unsigned RuntimeVersion) {
48 DIBuilder *D = unwrap(Dref);
49 DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
50 Flags, RuntimeVersion);
54 LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File,
56 DIBuilder *D = unwrap(Dref);
57 DIFile F = D->createFile(File, Dir);
61 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
62 LLVMMetadataRef Scope,
66 DIBuilder *D = unwrap(Dref);
67 DILexicalBlock LB = D->createLexicalBlock(
68 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
72 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
73 LLVMMetadataRef Scope,
75 unsigned Discriminator) {
76 DIBuilder *D = unwrap(Dref);
77 DILexicalBlockFile LBF = D->createLexicalBlockFile(
78 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Discriminator);
82 LLVMMetadataRef LLVMDIBuilderCreateFunction(
83 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
84 const char *LinkageName, LLVMMetadataRef File, unsigned Line,
85 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
86 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
87 DIBuilder *D = unwrap(Dref);
88 DISubprogram SP = D->createFunction(
89 unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
90 Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit,
91 IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func));
95 LLVMMetadataRef LLVMDIBuilderCreateLocalVariable(
96 LLVMDIBuilderRef Dref, unsigned Tag, LLVMMetadataRef Scope,
97 const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
98 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
99 DIBuilder *D = unwrap(Dref);
100 DIVariable V = D->createLocalVariable(
101 Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
102 unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo);
106 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
109 uint64_t AlignInBits,
111 DIBuilder *D = unwrap(Dref);
112 DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
116 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
117 LLVMMetadataRef PointeeType,
119 uint64_t AlignInBits,
121 DIBuilder *D = unwrap(Dref);
122 DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
123 SizeInBits, AlignInBits, Name);
128 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
129 LLVMMetadataRef ParameterTypes) {
130 DIBuilder *D = unwrap(Dref);
131 DICompositeType CT = D->createSubroutineType(
132 unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes));
136 LLVMMetadataRef LLVMDIBuilderCreateStructType(
137 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
138 LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
139 uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
140 LLVMMetadataRef ElementTypes) {
141 DIBuilder *D = unwrap(Dref);
142 DICompositeType CT = D->createStructType(
143 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
144 SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
145 unwrapDI<DIArray>(ElementTypes));
149 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
150 LLVMDIBuilderRef Dref, unsigned Tag, const char *Name,
151 LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
152 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
154 DIBuilder *D = unwrap(Dref);
155 DICompositeType CT = D->createReplaceableCompositeType(
156 Tag, Name, unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line,
157 RuntimeLang, SizeInBits, AlignInBits, Flags);
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 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
170 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
174 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
176 uint64_t AlignInBits,
177 LLVMMetadataRef ElementType,
178 LLVMMetadataRef Subscripts) {
179 DIBuilder *D = unwrap(Dref);
181 D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
182 unwrapDI<DIArray>(Subscripts));
186 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
187 LLVMMetadataRef Ty, const char *Name,
188 LLVMMetadataRef File, unsigned Line,
189 LLVMMetadataRef Context) {
190 DIBuilder *D = unwrap(Dref);
192 D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
193 unwrapDI<DIDescriptor>(Context));
197 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
198 int64_t Lo, int64_t Count) {
199 DIBuilder *D = unwrap(Dref);
200 DISubrange S = D->getOrCreateSubrange(Lo, Count);
204 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
205 LLVMMetadataRef *Data,
207 DIBuilder *D = unwrap(Dref);
208 Metadata **DataValue = unwrap(Data);
209 ArrayRef<Metadata *> Elements(DataValue, Length);
210 DIArray A = D->getOrCreateArray(Elements);
214 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
215 LLVMMetadataRef *Data,
217 DIBuilder *D = unwrap(Dref);
218 Metadata **DataValue = unwrap(Data);
219 ArrayRef<Metadata *> Elements(DataValue, Length);
220 DITypeArray A = D->getOrCreateTypeArray(Elements);
224 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
225 int64_t *Addr, size_t Length) {
226 DIBuilder *D = unwrap(Dref);
227 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
231 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
232 LLVMValueRef Storage,
233 LLVMMetadataRef VarInfo,
234 LLVMMetadataRef Expr,
235 LLVMBasicBlockRef Block) {
236 DIBuilder *D = unwrap(Dref);
238 D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
239 unwrapDI<DIExpression>(Expr), unwrap(Block));
243 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
244 LLVMValueRef Val, uint64_t Offset,
245 LLVMMetadataRef VarInfo,
246 LLVMMetadataRef Expr,
247 LLVMBasicBlockRef Block) {
248 DIBuilder *D = unwrap(Dref);
249 Instruction *Instr = D->insertDbgValueIntrinsic(
250 unwrap(Val), Offset, unwrapDI<DIVariable>(VarInfo),
251 unwrapDI<DIExpression>(Expr), unwrap(Block));