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"
23 T unwrapDI(LLVMValueRef v) {
24 return v ? T(unwrap<MDNode>(v)) : T();
28 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
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 LLVMValueRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
43 unsigned Lang, const char *File,
45 const char *Producer, int Optimized,
47 unsigned RuntimeVersion) {
48 DIBuilder *D = unwrap(Dref);
49 DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
50 Flags, RuntimeVersion);
54 LLVMValueRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File,
56 DIBuilder *D = unwrap(Dref);
57 DIFile F = D->createFile(File, Dir);
61 LLVMValueRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
63 LLVMValueRef File, unsigned Line,
65 DIBuilder *D = unwrap(Dref);
66 DILexicalBlock LB = D->createLexicalBlock(
67 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
71 LLVMValueRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
74 unsigned Discriminator) {
75 DIBuilder *D = unwrap(Dref);
76 DILexicalBlockFile LBF = D->createLexicalBlockFile(
77 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Discriminator);
81 LLVMValueRef LLVMDIBuilderCreateFunction(
82 LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name,
83 const char *LinkageName, LLVMValueRef File, unsigned Line,
84 LLVMValueRef CompositeType, int IsLocalToUnit, int IsDefinition,
85 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
86 DIBuilder *D = unwrap(Dref);
87 DISubprogram SP = D->createFunction(
88 unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
89 Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit,
90 IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func));
94 LLVMValueRef LLVMDIBuilderCreateLocalVariable(
95 LLVMDIBuilderRef Dref, unsigned Tag, LLVMValueRef Scope, const char *Name,
96 LLVMValueRef File, unsigned Line, LLVMValueRef Ty, int AlwaysPreserve,
97 unsigned Flags, unsigned ArgNo) {
98 DIBuilder *D = unwrap(Dref);
99 DIVariable V = D->createLocalVariable(
100 Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
101 unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo);
105 LLVMValueRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
106 const char *Name, uint64_t SizeInBits,
107 uint64_t AlignInBits,
109 DIBuilder *D = unwrap(Dref);
110 DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
114 LLVMValueRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
115 LLVMValueRef PointeeType,
117 uint64_t AlignInBits,
119 DIBuilder *D = unwrap(Dref);
120 DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
121 SizeInBits, AlignInBits, Name);
125 LLVMValueRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref,
127 LLVMValueRef ParameterTypes) {
128 DIBuilder *D = unwrap(Dref);
129 DICompositeType CT = D->createSubroutineType(
130 unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes));
134 LLVMValueRef LLVMDIBuilderCreateStructType(
135 LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name,
136 LLVMValueRef File, unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
137 unsigned Flags, LLVMValueRef DerivedFrom, LLVMValueRef ElementTypes) {
138 DIBuilder *D = unwrap(Dref);
139 DICompositeType CT = D->createStructType(
140 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
141 SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
142 unwrapDI<DIArray>(ElementTypes));
146 LLVMValueRef LLVMDIBuilderCreateMemberType(
147 LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name,
148 LLVMValueRef File, unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
149 uint64_t OffsetInBits, unsigned Flags, LLVMValueRef Ty) {
150 DIBuilder *D = unwrap(Dref);
151 DIDerivedType DT = D->createMemberType(
152 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
153 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
157 LLVMValueRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
159 uint64_t AlignInBits,
160 LLVMValueRef ElementType,
161 LLVMValueRef Subscripts) {
162 DIBuilder *D = unwrap(Dref);
164 D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
165 unwrapDI<DIArray>(Subscripts));
169 LLVMValueRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, LLVMValueRef Ty,
170 const char *Name, LLVMValueRef File,
171 unsigned Line, LLVMValueRef Context) {
172 DIBuilder *D = unwrap(Dref);
174 D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
175 unwrapDI<DIDescriptor>(Context));
179 LLVMValueRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, int64_t Lo,
181 DIBuilder *D = unwrap(Dref);
182 DISubrange S = D->getOrCreateSubrange(Lo, Count);
186 LLVMValueRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
187 LLVMValueRef *Data, size_t Length) {
188 DIBuilder *D = unwrap(Dref);
189 Value **DataValue = unwrap(Data);
190 ArrayRef<Value *> Elements(DataValue, Length);
191 DIArray A = D->getOrCreateArray(Elements);
195 LLVMValueRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
198 DIBuilder *D = unwrap(Dref);
199 Value **DataValue = unwrap(Data);
200 ArrayRef<Value *> Elements(DataValue, Length);
201 DITypeArray A = D->getOrCreateTypeArray(Elements);
205 LLVMValueRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, int64_t *Addr,
207 DIBuilder *D = unwrap(Dref);
208 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
212 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
213 LLVMValueRef Storage,
214 LLVMValueRef VarInfo,
216 LLVMBasicBlockRef Block) {
217 DIBuilder *D = unwrap(Dref);
219 D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
220 unwrapDI<DIExpression>(Expr), unwrap(Block));