IR: Fix -Werror noasserts build after r234255
[oota-llvm.git] / bindings / go / llvm / DIBuilderBindings.cpp
1 //===- DIBuilderBindings.cpp - Bindings for DIBuilder ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines C bindings for the DIBuilder class.
11 //
12 //===----------------------------------------------------------------------===//
13
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"
19
20 using namespace llvm;
21
22 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
23
24 namespace {
25 template <typename T> T unwrapDI(LLVMMetadataRef v) {
26   return v ? T(unwrap<MDNode>(v)) : T();
27 }
28 }
29
30 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
31   Module *m = unwrap(mref);
32   return wrap(new DIBuilder(*m));
33 }
34
35 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
36   DIBuilder *d = unwrap(dref);
37   delete d;
38 }
39
40 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); }
41
42 LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
43                                                unsigned Lang, const char *File,
44                                                const char *Dir,
45                                                const char *Producer,
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);
51   return wrap(CU);
52 }
53
54 LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File,
55                                         const char *Dir) {
56   DIBuilder *D = unwrap(Dref);
57   DIFile F = D->createFile(File, Dir);
58   return wrap(F);
59 }
60
61 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
62                                                 LLVMMetadataRef Scope,
63                                                 LLVMMetadataRef File,
64                                                 unsigned Line,
65                                                 unsigned Column) {
66   DIBuilder *D = unwrap(Dref);
67   DILexicalBlock LB = D->createLexicalBlock(
68       unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
69   return wrap(LB);
70 }
71
72 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
73                                                     LLVMMetadataRef Scope,
74                                                     LLVMMetadataRef File,
75                                                     unsigned Discriminator) {
76   DIBuilder *D = unwrap(Dref);
77   DILexicalBlockFile LBF = D->createLexicalBlockFile(
78       unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Discriminator);
79   return wrap(LBF);
80 }
81
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));
92   return wrap(SP);
93 }
94
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);
103   return wrap(V);
104 }
105
106 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
107                                              const char *Name,
108                                              uint64_t SizeInBits,
109                                              uint64_t AlignInBits,
110                                              unsigned Encoding) {
111   DIBuilder *D = unwrap(Dref);
112   DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
113   return wrap(T);
114 }
115
116 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
117                                                LLVMMetadataRef PointeeType,
118                                                uint64_t SizeInBits,
119                                                uint64_t AlignInBits,
120                                                const char *Name) {
121   DIBuilder *D = unwrap(Dref);
122   DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
123                                          SizeInBits, AlignInBits, Name);
124   return wrap(T);
125 }
126
127 LLVMMetadataRef
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));
133   return wrap(CT);
134 }
135
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));
146   return wrap(CT);
147 }
148
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,
153     unsigned Flags) {
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);
158   return wrap(CT);
159 }
160
161 LLVMMetadataRef
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));
171   return wrap(DT);
172 }
173
174 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
175                                              uint64_t SizeInBits,
176                                              uint64_t AlignInBits,
177                                              LLVMMetadataRef ElementType,
178                                              LLVMMetadataRef Subscripts) {
179   DIBuilder *D = unwrap(Dref);
180   DICompositeType CT =
181       D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
182                          unwrapDI<DIArray>(Subscripts));
183   return wrap(CT);
184 }
185
186 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
187                                            LLVMMetadataRef Ty, const char *Name,
188                                            LLVMMetadataRef File, unsigned Line,
189                                            LLVMMetadataRef Context) {
190   DIBuilder *D = unwrap(Dref);
191   DIDerivedType DT =
192       D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
193                        unwrapDI<DIDescriptor>(Context));
194   return wrap(DT);
195 }
196
197 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
198                                                  int64_t Lo, int64_t Count) {
199   DIBuilder *D = unwrap(Dref);
200   DISubrange S = D->getOrCreateSubrange(Lo, Count);
201   return wrap(S);
202 }
203
204 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
205                                               LLVMMetadataRef *Data,
206                                               size_t Length) {
207   DIBuilder *D = unwrap(Dref);
208   Metadata **DataValue = unwrap(Data);
209   ArrayRef<Metadata *> Elements(DataValue, Length);
210   DIArray A = D->getOrCreateArray(Elements);
211   return wrap(A);
212 }
213
214 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
215                                                   LLVMMetadataRef *Data,
216                                                   size_t Length) {
217   DIBuilder *D = unwrap(Dref);
218   Metadata **DataValue = unwrap(Data);
219   ArrayRef<Metadata *> Elements(DataValue, Length);
220   DITypeArray A = D->getOrCreateTypeArray(Elements);
221   return wrap(A);
222 }
223
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));
228   return wrap(Expr);
229 }
230
231 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
232                                              LLVMValueRef Storage,
233                                              LLVMMetadataRef VarInfo,
234                                              LLVMMetadataRef Expr,
235                                              LLVMBasicBlockRef Block) {
236   DIBuilder *D = unwrap(Dref);
237   Instruction *Instr =
238       D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
239                        unwrapDI<DIExpression>(Expr), unwrap(Block));
240   return wrap(Instr);
241 }
242
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));
252   return wrap(Instr);
253 }