8d80602e116897122bbdd020db3bb4da3d6d1cbb
[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 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
25   Module *m = unwrap(mref);
26   return wrap(new DIBuilder(*m));
27 }
28
29 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
30   DIBuilder *d = unwrap(dref);
31   delete d;
32 }
33
34 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); }
35
36 LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
37                                                unsigned Lang, const char *File,
38                                                const char *Dir,
39                                                const char *Producer,
40                                                int Optimized, const char *Flags,
41                                                unsigned RuntimeVersion) {
42   DIBuilder *D = unwrap(Dref);
43   DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
44                                           Flags, RuntimeVersion);
45   return wrap(CU);
46 }
47
48 LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File,
49                                         const char *Dir) {
50   DIBuilder *D = unwrap(Dref);
51   DIFile F = D->createFile(File, Dir);
52   return wrap(F);
53 }
54
55 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
56                                                 LLVMMetadataRef Scope,
57                                                 LLVMMetadataRef File,
58                                                 unsigned Line,
59                                                 unsigned Column) {
60   DIBuilder *D = unwrap(Dref);
61   DILexicalBlock LB =
62       D->createLexicalBlock(DIDescriptor(unwrap<MDLocalScope>(Scope)),
63                             unwrap<MDFile>(File), Line, Column);
64   return wrap(LB);
65 }
66
67 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
68                                                     LLVMMetadataRef Scope,
69                                                     LLVMMetadataRef File,
70                                                     unsigned Discriminator) {
71   DIBuilder *D = unwrap(Dref);
72   DILexicalBlockFile LBF =
73       D->createLexicalBlockFile(DIDescriptor(unwrap<MDLocalScope>(Scope)),
74                                 unwrap<MDFile>(File), Discriminator);
75   return wrap(LBF);
76 }
77
78 LLVMMetadataRef LLVMDIBuilderCreateFunction(
79     LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
80     const char *LinkageName, LLVMMetadataRef File, unsigned Line,
81     LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
82     unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
83   DIBuilder *D = unwrap(Dref);
84   DISubprogram SP = D->createFunction(
85       DIDescriptor(unwrap<MDScope>(Scope)), Name, LinkageName,
86       unwrap<MDFile>(File), Line, unwrap<MDCompositeTypeBase>(CompositeType),
87       IsLocalToUnit, IsDefinition, ScopeLine, Flags, IsOptimized,
88       unwrap<Function>(Func));
89   return wrap(SP);
90 }
91
92 LLVMMetadataRef LLVMDIBuilderCreateLocalVariable(
93     LLVMDIBuilderRef Dref, unsigned Tag, LLVMMetadataRef Scope,
94     const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
95     int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
96   DIBuilder *D = unwrap(Dref);
97   DIVariable V = D->createLocalVariable(
98       Tag, DIDescriptor(unwrap<MDScope>(Scope)), Name, unwrap<MDFile>(File),
99       Line, unwrap<MDType>(Ty), AlwaysPreserve, Flags, ArgNo);
100   return wrap(V);
101 }
102
103 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
104                                              const char *Name,
105                                              uint64_t SizeInBits,
106                                              uint64_t AlignInBits,
107                                              unsigned Encoding) {
108   DIBuilder *D = unwrap(Dref);
109   DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
110   return wrap(T);
111 }
112
113 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
114                                                LLVMMetadataRef PointeeType,
115                                                uint64_t SizeInBits,
116                                                uint64_t AlignInBits,
117                                                const char *Name) {
118   DIBuilder *D = unwrap(Dref);
119   DIDerivedType T = D->createPointerType(unwrap<MDType>(PointeeType),
120                                          SizeInBits, AlignInBits, Name);
121   return wrap(T);
122 }
123
124 LLVMMetadataRef
125 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
126                                   LLVMMetadataRef ParameterTypes) {
127   DIBuilder *D = unwrap(Dref);
128   DICompositeType CT = D->createSubroutineType(
129       unwrap<MDFile>(File), DITypeArray(unwrap<MDTuple>(ParameterTypes)));
130   return wrap(CT);
131 }
132
133 LLVMMetadataRef LLVMDIBuilderCreateStructType(
134     LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
135     LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
136     uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
137     LLVMMetadataRef ElementTypes) {
138   DIBuilder *D = unwrap(Dref);
139   DICompositeType CT = D->createStructType(
140       DIDescriptor(unwrap<MDScope>(Scope)), Name, unwrap<MDFile>(File), Line,
141       SizeInBits, AlignInBits, Flags, unwrap<MDType>(DerivedFrom),
142       DIArray(unwrap<MDTuple>(ElementTypes)));
143   return wrap(CT);
144 }
145
146 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
147     LLVMDIBuilderRef Dref, unsigned Tag, const char *Name,
148     LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
149     unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
150     unsigned Flags) {
151   DIBuilder *D = unwrap(Dref);
152   DICompositeType CT = D->createReplaceableCompositeType(
153       Tag, Name, DIDescriptor(unwrap<MDScope>(Scope)), unwrap<MDFile>(File),
154       Line, RuntimeLang, SizeInBits, AlignInBits, Flags);
155   return wrap(CT);
156 }
157
158 LLVMMetadataRef
159 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
160                               const char *Name, LLVMMetadataRef File,
161                               unsigned Line, uint64_t SizeInBits,
162                               uint64_t AlignInBits, uint64_t OffsetInBits,
163                               unsigned Flags, LLVMMetadataRef Ty) {
164   DIBuilder *D = unwrap(Dref);
165   DIDerivedType DT = D->createMemberType(
166       DIDescriptor(unwrap<MDScope>(Scope)), Name, unwrap<MDFile>(File), Line,
167       SizeInBits, AlignInBits, OffsetInBits, Flags, unwrap<MDType>(Ty));
168   return wrap(DT);
169 }
170
171 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
172                                              uint64_t SizeInBits,
173                                              uint64_t AlignInBits,
174                                              LLVMMetadataRef ElementType,
175                                              LLVMMetadataRef Subscripts) {
176   DIBuilder *D = unwrap(Dref);
177   DICompositeType CT =
178       D->createArrayType(SizeInBits, AlignInBits, unwrap<MDType>(ElementType),
179                          DIArray(unwrap<MDTuple>(Subscripts)));
180   return wrap(CT);
181 }
182
183 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
184                                            LLVMMetadataRef Ty, const char *Name,
185                                            LLVMMetadataRef File, unsigned Line,
186                                            LLVMMetadataRef Context) {
187   DIBuilder *D = unwrap(Dref);
188   DIDerivedType DT =
189       D->createTypedef(unwrap<MDType>(Ty), Name, unwrap<MDFile>(File), Line,
190                        DIDescriptor(unwrap<MDScope>(Context)));
191   return wrap(DT);
192 }
193
194 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
195                                                  int64_t Lo, int64_t Count) {
196   DIBuilder *D = unwrap(Dref);
197   DISubrange S = D->getOrCreateSubrange(Lo, Count);
198   return wrap(S);
199 }
200
201 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
202                                               LLVMMetadataRef *Data,
203                                               size_t Length) {
204   DIBuilder *D = unwrap(Dref);
205   Metadata **DataValue = unwrap(Data);
206   ArrayRef<Metadata *> Elements(DataValue, Length);
207   DIArray A = D->getOrCreateArray(Elements);
208   return wrap(A);
209 }
210
211 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
212                                                   LLVMMetadataRef *Data,
213                                                   size_t Length) {
214   DIBuilder *D = unwrap(Dref);
215   Metadata **DataValue = unwrap(Data);
216   ArrayRef<Metadata *> Elements(DataValue, Length);
217   DITypeArray A = D->getOrCreateTypeArray(Elements);
218   return wrap(A);
219 }
220
221 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
222                                               int64_t *Addr, size_t Length) {
223   DIBuilder *D = unwrap(Dref);
224   DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
225   return wrap(Expr);
226 }
227
228 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
229                                              LLVMValueRef Storage,
230                                              LLVMMetadataRef VarInfo,
231                                              LLVMMetadataRef Expr,
232                                              LLVMBasicBlockRef Block) {
233   DIBuilder *D = unwrap(Dref);
234   Instruction *Instr =
235       D->insertDeclare(unwrap(Storage), unwrap<MDLocalVariable>(VarInfo),
236                        unwrap<MDExpression>(Expr), unwrap(Block));
237   return wrap(Instr);
238 }
239
240 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
241                                            LLVMValueRef Val, uint64_t Offset,
242                                            LLVMMetadataRef VarInfo,
243                                            LLVMMetadataRef Expr,
244                                            LLVMBasicBlockRef Block) {
245   DIBuilder *D = unwrap(Dref);
246   Instruction *Instr = D->insertDbgValueIntrinsic(
247       unwrap(Val), Offset, unwrap<MDLocalVariable>(VarInfo),
248       unwrap<MDExpression>(Expr), unwrap(Block));
249   return wrap(Instr);
250 }