[X86] Cleanup ADCX/ADOX instruction definitions.
[lldb.git] / llvm / 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 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
23   Module *m = unwrap(mref);
24   return wrap(new DIBuilder(*m));
25 }
26
27 void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
28   DIBuilder *d = unwrap(dref);
29   delete d;
30 }
31
32 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
33                                                 LLVMMetadataRef Scope,
34                                                 LLVMMetadataRef File,
35                                                 unsigned Line,
36                                                 unsigned Column) {
37   DIBuilder *D = unwrap(Dref);
38   auto *LB = D->createLexicalBlock(unwrap<DILocalScope>(Scope),
39                                    unwrap<DIFile>(File), Line, Column);
40   return wrap(LB);
41 }
42
43 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
44                                                     LLVMMetadataRef Scope,
45                                                     LLVMMetadataRef File,
46                                                     unsigned Discriminator) {
47   DIBuilder *D = unwrap(Dref);
48   return wrap(D->createLexicalBlockFile(unwrap<DILocalScope>(Scope),
49                                         unwrap<DIFile>(File), Discriminator));
50 }
51
52 LLVMMetadataRef LLVMDIBuilderCreateFunction(
53     LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
54     const char *LinkageName, LLVMMetadataRef File, unsigned Line,
55     LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
56     unsigned ScopeLine, unsigned Flags, int IsOptimized) {
57   DIBuilder *D = unwrap(Dref);
58   return wrap(D->createFunction(
59       unwrap<DIScope>(Scope), Name, LinkageName,
60       File ? unwrap<DIFile>(File) : nullptr, Line,
61       unwrap<DISubroutineType>(CompositeType), IsLocalToUnit, IsDefinition,
62       ScopeLine, static_cast<DINode::DIFlags>(Flags), IsOptimized));
63 }
64
65 LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
66     LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
67     LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve,
68     unsigned Flags, uint32_t AlignInBits) {
69   DIBuilder *D = unwrap(Dref);
70   return wrap(
71       D->createAutoVariable(unwrap<DIScope>(Scope), Name, unwrap<DIFile>(File),
72                             Line, unwrap<DIType>(Ty), AlwaysPreserve,
73                             static_cast<DINode::DIFlags>(Flags), AlignInBits));
74 }
75
76 LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(
77     LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
78     unsigned ArgNo, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
79     int AlwaysPreserve, unsigned Flags) {
80   DIBuilder *D = unwrap(Dref);
81   return wrap(D->createParameterVariable(
82       unwrap<DIScope>(Scope), Name, ArgNo, unwrap<DIFile>(File), Line,
83       unwrap<DIType>(Ty), AlwaysPreserve, static_cast<DINode::DIFlags>(Flags)));
84 }
85
86 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
87                                              const char *Name,
88                                              uint64_t SizeInBits,
89                                              unsigned Encoding) {
90   DIBuilder *D = unwrap(Dref);
91   return wrap(D->createBasicType(Name, SizeInBits, Encoding));
92 }
93
94 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
95                                                LLVMMetadataRef PointeeType,
96                                                uint64_t SizeInBits,
97                                                uint32_t AlignInBits,
98                                                const char *Name) {
99   DIBuilder *D = unwrap(Dref);
100   return wrap(D->createPointerType(unwrap<DIType>(PointeeType), SizeInBits,
101                                    AlignInBits, /* DWARFAddressSpace */ None,
102                                    Name));
103 }
104
105 LLVMMetadataRef
106 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
107                                   LLVMMetadataRef ParameterTypes) {
108   DIBuilder *D = unwrap(Dref);
109   return wrap(
110       D->createSubroutineType(DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
111 }
112
113 LLVMMetadataRef LLVMDIBuilderCreateStructType(
114     LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
115     LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
116     uint32_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
117     LLVMMetadataRef ElementTypes) {
118   DIBuilder *D = unwrap(Dref);
119   return wrap(D->createStructType(
120       unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line,
121       SizeInBits, AlignInBits, static_cast<DINode::DIFlags>(Flags),
122       DerivedFrom ? unwrap<DIType>(DerivedFrom) : nullptr,
123       ElementTypes ? DINodeArray(unwrap<MDTuple>(ElementTypes)) : nullptr));
124 }
125
126 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
127     LLVMDIBuilderRef Dref, unsigned Tag, const char *Name,
128     LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
129     unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
130     unsigned Flags) {
131   DIBuilder *D = unwrap(Dref);
132   return wrap(D->createReplaceableCompositeType(
133       Tag, Name, unwrap<DIScope>(Scope), File ? unwrap<DIFile>(File) : nullptr,
134       Line, RuntimeLang, SizeInBits, AlignInBits,
135       static_cast<DINode::DIFlags>(Flags)));
136 }
137
138 LLVMMetadataRef
139 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
140                               const char *Name, LLVMMetadataRef File,
141                               unsigned Line, uint64_t SizeInBits,
142                               uint32_t AlignInBits, uint64_t OffsetInBits,
143                               unsigned Flags, LLVMMetadataRef Ty) {
144   DIBuilder *D = unwrap(Dref);
145   return wrap(D->createMemberType(
146       unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line,
147       SizeInBits, AlignInBits, OffsetInBits,
148       static_cast<DINode::DIFlags>(Flags), unwrap<DIType>(Ty)));
149 }
150
151 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
152                                              uint64_t SizeInBits,
153                                              uint32_t AlignInBits,
154                                              LLVMMetadataRef ElementType,
155                                              LLVMMetadataRef Subscripts) {
156   DIBuilder *D = unwrap(Dref);
157   return wrap(D->createArrayType(SizeInBits, AlignInBits,
158                                  unwrap<DIType>(ElementType),
159                                  DINodeArray(unwrap<MDTuple>(Subscripts))));
160 }
161
162 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
163                                            LLVMMetadataRef Ty, const char *Name,
164                                            LLVMMetadataRef File, unsigned Line,
165                                            LLVMMetadataRef Context) {
166   DIBuilder *D = unwrap(Dref);
167   return wrap(D->createTypedef(unwrap<DIType>(Ty), Name,
168                                File ? unwrap<DIFile>(File) : nullptr, Line,
169                                Context ? unwrap<DIScope>(Context) : nullptr));
170 }
171
172 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
173                                                  int64_t Lo, int64_t Count) {
174   DIBuilder *D = unwrap(Dref);
175   return wrap(D->getOrCreateSubrange(Lo, Count));
176 }
177
178 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
179                                               LLVMMetadataRef *Data,
180                                               size_t Length) {
181   DIBuilder *D = unwrap(Dref);
182   Metadata **DataValue = unwrap(Data);
183   ArrayRef<Metadata *> Elements(DataValue, Length);
184   DINodeArray A = D->getOrCreateArray(Elements);
185   return wrap(A.get());
186 }
187
188 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
189                                                   LLVMMetadataRef *Data,
190                                                   size_t Length) {
191   DIBuilder *D = unwrap(Dref);
192   Metadata **DataValue = unwrap(Data);
193   ArrayRef<Metadata *> Elements(DataValue, Length);
194   DITypeRefArray A = D->getOrCreateTypeArray(Elements);
195   return wrap(A.get());
196 }
197
198 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
199                                               int64_t *Addr, size_t Length) {
200   DIBuilder *D = unwrap(Dref);
201   return wrap(D->createExpression(ArrayRef<int64_t>(Addr, Length)));
202 }
203
204 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
205                                              LLVMValueRef Storage,
206                                              LLVMMetadataRef VarInfo,
207                                              LLVMMetadataRef Expr,
208                                              LLVMBasicBlockRef Block) {
209   // Fail immediately here until the llgo folks update their bindings.  The
210   // called function is going to assert out anyway.
211   llvm_unreachable("DIBuilder API change requires a DebugLoc");
212
213   DIBuilder *D = unwrap(Dref);
214   Instruction *Instr = D->insertDeclare(
215       unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
216       unwrap<DIExpression>(Expr), /* DebugLoc */ nullptr, unwrap(Block));
217   return wrap(Instr);
218 }
219
220 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
221                                            LLVMValueRef Val,
222                                            LLVMMetadataRef VarInfo,
223                                            LLVMMetadataRef Expr,
224                                            LLVMBasicBlockRef Block) {
225   // Fail immediately here until the llgo folks update their bindings.  The
226   // called function is going to assert out anyway.
227   llvm_unreachable("DIBuilder API change requires a DebugLoc");
228
229   DIBuilder *D = unwrap(Dref);
230   Instruction *Instr = D->insertDbgValueIntrinsic(
231       unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
232       /* DebugLoc */ nullptr, unwrap(Block));
233   return wrap(Instr);
234 }