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));
150 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
151 const char *Name, LLVMMetadataRef File,
152 unsigned Line, uint64_t SizeInBits,
153 uint64_t AlignInBits, uint64_t OffsetInBits,
154 unsigned Flags, LLVMMetadataRef Ty) {
155 DIBuilder *D = unwrap(Dref);
156 DIDerivedType DT = D->createMemberType(
157 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
158 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
162 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
164 uint64_t AlignInBits,
165 LLVMMetadataRef ElementType,
166 LLVMMetadataRef Subscripts) {
167 DIBuilder *D = unwrap(Dref);
169 D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
170 unwrapDI<DIArray>(Subscripts));
174 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
175 LLVMMetadataRef Ty, const char *Name,
176 LLVMMetadataRef File, unsigned Line,
177 LLVMMetadataRef Context) {
178 DIBuilder *D = unwrap(Dref);
180 D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
181 unwrapDI<DIDescriptor>(Context));
185 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
186 int64_t Lo, int64_t Count) {
187 DIBuilder *D = unwrap(Dref);
188 DISubrange S = D->getOrCreateSubrange(Lo, Count);
192 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
193 LLVMMetadataRef *Data,
195 DIBuilder *D = unwrap(Dref);
196 Metadata **DataValue = unwrap(Data);
197 ArrayRef<Metadata *> Elements(DataValue, Length);
198 DIArray A = D->getOrCreateArray(Elements);
202 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
203 LLVMMetadataRef *Data,
205 DIBuilder *D = unwrap(Dref);
206 Metadata **DataValue = unwrap(Data);
207 ArrayRef<Metadata *> Elements(DataValue, Length);
208 DITypeArray A = D->getOrCreateTypeArray(Elements);
212 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
213 int64_t *Addr, size_t Length) {
214 DIBuilder *D = unwrap(Dref);
215 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
219 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
220 LLVMValueRef Storage,
221 LLVMMetadataRef VarInfo,
222 LLVMMetadataRef Expr,
223 LLVMBasicBlockRef Block) {
224 DIBuilder *D = unwrap(Dref);
226 D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
227 unwrapDI<DIExpression>(Expr), unwrap(Block));
231 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
232 LLVMValueRef Val, uint64_t Offset,
233 LLVMMetadataRef VarInfo,
234 LLVMMetadataRef Expr,
235 LLVMBasicBlockRef Block) {
236 DIBuilder *D = unwrap(Dref);
237 Instruction *Instr = D->insertDbgValueIntrinsic(
238 unwrap(Val), Offset, unwrapDI<DIVariable>(VarInfo),
239 unwrapDI<DIExpression>(Expr), unwrap(Block));