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 "llvm/IR/Module.h"
17 #include "llvm/IR/DIBuilder.h"
22 template <typename T> T unwrapDI(LLVMValueRef v) {
23 return v ? T(unwrap<MDNode>(v)) : T();
27 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
29 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
30 Module *m = unwrap(mref);
31 return wrap(new DIBuilder(*m));
34 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
35 DIBuilder *d = unwrap(dref);
39 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); }
41 LLVMValueRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
42 unsigned Lang, const char *File,
44 const char *Producer, int Optimized,
46 unsigned RuntimeVersion) {
47 DIBuilder *D = unwrap(Dref);
48 DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
49 Flags, RuntimeVersion);
53 LLVMValueRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File,
55 DIBuilder *D = unwrap(Dref);
56 DIFile F = D->createFile(File, Dir);
60 LLVMValueRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
62 LLVMValueRef File, unsigned Line,
64 DIBuilder *D = unwrap(Dref);
65 DILexicalBlock LB = D->createLexicalBlock(
66 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
70 LLVMValueRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
73 unsigned Discriminator) {
74 DIBuilder *D = unwrap(Dref);
75 DILexicalBlockFile LBF = D->createLexicalBlockFile(
76 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Discriminator);
80 LLVMValueRef LLVMDIBuilderCreateFunction(
81 LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name,
82 const char *LinkageName, LLVMValueRef File, unsigned Line,
83 LLVMValueRef CompositeType, int IsLocalToUnit, int IsDefinition,
84 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
85 DIBuilder *D = unwrap(Dref);
86 DISubprogram SP = D->createFunction(
87 unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
88 Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit,
89 IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func));
93 LLVMValueRef LLVMDIBuilderCreateLocalVariable(
94 LLVMDIBuilderRef Dref, unsigned Tag, LLVMValueRef Scope, const char *Name,
95 LLVMValueRef File, unsigned Line, LLVMValueRef Ty, int AlwaysPreserve,
96 unsigned Flags, unsigned ArgNo) {
97 DIBuilder *D = unwrap(Dref);
98 DIVariable V = D->createLocalVariable(
99 Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
100 unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo);
104 LLVMValueRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
105 const char *Name, uint64_t SizeInBits,
106 uint64_t AlignInBits,
108 DIBuilder *D = unwrap(Dref);
109 DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
113 LLVMValueRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
114 LLVMValueRef PointeeType,
116 uint64_t AlignInBits,
118 DIBuilder *D = unwrap(Dref);
119 DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
120 SizeInBits, AlignInBits, Name);
124 LLVMValueRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref,
126 LLVMValueRef ParameterTypes) {
127 DIBuilder *D = unwrap(Dref);
128 DICompositeType CT = D->createSubroutineType(
129 unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes));
133 LLVMValueRef LLVMDIBuilderCreateStructType(
134 LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name,
135 LLVMValueRef File, unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
136 unsigned Flags, LLVMValueRef DerivedFrom, LLVMValueRef ElementTypes) {
137 DIBuilder *D = unwrap(Dref);
138 DICompositeType CT = D->createStructType(
139 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
140 SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
141 unwrapDI<DIArray>(ElementTypes));
145 LLVMValueRef LLVMDIBuilderCreateMemberType(
146 LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name,
147 LLVMValueRef File, unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
148 uint64_t OffsetInBits, unsigned Flags, LLVMValueRef Ty) {
149 DIBuilder *D = unwrap(Dref);
150 DIDerivedType DT = D->createMemberType(
151 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
152 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
156 LLVMValueRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
158 uint64_t AlignInBits,
159 LLVMValueRef ElementType,
160 LLVMValueRef Subscripts) {
161 DIBuilder *D = unwrap(Dref);
163 D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
164 unwrapDI<DIArray>(Subscripts));
168 LLVMValueRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, LLVMValueRef Ty,
169 const char *Name, LLVMValueRef File,
170 unsigned Line, LLVMValueRef Context) {
171 DIBuilder *D = unwrap(Dref);
173 D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
174 unwrapDI<DIDescriptor>(Context));
178 LLVMValueRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, int64_t Lo,
180 DIBuilder *D = unwrap(Dref);
181 DISubrange S = D->getOrCreateSubrange(Lo, Count);
185 LLVMValueRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
186 LLVMValueRef *Data, size_t Length) {
187 DIBuilder *D = unwrap(Dref);
188 Value **DataValue = unwrap(Data);
189 ArrayRef<Value *> Elements(DataValue, Length);
190 DIArray A = D->getOrCreateArray(Elements);
194 LLVMValueRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
197 DIBuilder *D = unwrap(Dref);
198 Value **DataValue = unwrap(Data);
199 ArrayRef<Value *> Elements(DataValue, Length);
200 DITypeArray A = D->getOrCreateTypeArray(Elements);
204 LLVMValueRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, int64_t *Addr,
206 DIBuilder *D = unwrap(Dref);
207 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
211 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
212 LLVMValueRef Storage,
213 LLVMValueRef VarInfo,
215 LLVMBasicBlockRef Block) {
216 DIBuilder *D = unwrap(Dref);
218 D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
219 unwrapDI<DIExpression>(Expr), unwrap(Block));
223 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
224 LLVMValueRef Val, uint64_t Offset,
225 LLVMValueRef VarInfo,
227 LLVMBasicBlockRef Block) {
228 DIBuilder *D = unwrap(Dref);
229 Instruction *Instr = D->insertDbgValueIntrinsic(
230 unwrap(Val), Offset, unwrapDI<DIVariable>(VarInfo),
231 unwrapDI<DIExpression>(Expr), unwrap(Block));