[OCaml] Expose Llvm_executionengine.ExecutionEngine.create_mcjit.
[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
16 #include "llvm/IR/Module.h"
17 #include "llvm/IR/DIBuilder.h"
18
19 using namespace llvm;
20
21 namespace {
22 template <typename T>
23 T unwrapDI(LLVMValueRef v) {
24   return v ? T(unwrap<MDNode>(v)) : T();
25 }
26 }
27
28 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
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 LLVMValueRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref,
43                                             unsigned Lang, const char *File,
44                                             const char *Dir,
45                                             const char *Producer, int Optimized,
46                                             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 LLVMValueRef 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 LLVMValueRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
62                                              LLVMValueRef Scope,
63                                              LLVMValueRef File, unsigned Line,
64                                              unsigned Column) {
65   DIBuilder *D = unwrap(Dref);
66   DILexicalBlock LB = D->createLexicalBlock(
67       unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
68   return wrap(LB);
69 }
70
71 LLVMValueRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
72                                                  LLVMValueRef Scope,
73                                                  LLVMValueRef File,
74                                                  unsigned Discriminator) {
75   DIBuilder *D = unwrap(Dref);
76   DILexicalBlockFile LBF = D->createLexicalBlockFile(
77       unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Discriminator);
78   return wrap(LBF);
79 }
80
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));
91   return wrap(SP);
92 }
93
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);
102   return wrap(V);
103 }
104
105 LLVMValueRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
106                                           const char *Name, uint64_t SizeInBits,
107                                           uint64_t AlignInBits,
108                                           unsigned Encoding) {
109   DIBuilder *D = unwrap(Dref);
110   DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
111   return wrap(T);
112 }
113
114 LLVMValueRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
115                                             LLVMValueRef PointeeType,
116                                             uint64_t SizeInBits,
117                                             uint64_t AlignInBits,
118                                             const char *Name) {
119   DIBuilder *D = unwrap(Dref);
120   DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
121                                          SizeInBits, AlignInBits, Name);
122   return wrap(T);
123 }
124
125 LLVMValueRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref,
126                                                LLVMValueRef File,
127                                                LLVMValueRef ParameterTypes) {
128   DIBuilder *D = unwrap(Dref);
129   DICompositeType CT = D->createSubroutineType(
130       unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes));
131   return wrap(CT);
132 }
133
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));
143   return wrap(CT);
144 }
145
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));
154   return wrap(DT);
155 }
156
157 LLVMValueRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
158                                           uint64_t SizeInBits,
159                                           uint64_t AlignInBits,
160                                           LLVMValueRef ElementType,
161                                           LLVMValueRef Subscripts) {
162   DIBuilder *D = unwrap(Dref);
163   DICompositeType CT =
164       D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
165                          unwrapDI<DIArray>(Subscripts));
166   return wrap(CT);
167 }
168
169 LLVMValueRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, LLVMValueRef Ty,
170                                         const char *Name, LLVMValueRef File,
171                                         unsigned Line, LLVMValueRef Context) {
172   DIBuilder *D = unwrap(Dref);
173   DIDerivedType DT =
174       D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
175                        unwrapDI<DIDescriptor>(Context));
176   return wrap(DT);
177 }
178
179 LLVMValueRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, int64_t Lo,
180                                               int64_t Count) {
181   DIBuilder *D = unwrap(Dref);
182   DISubrange S = D->getOrCreateSubrange(Lo, Count);
183   return wrap(S);
184 }
185
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);
192   return wrap(A);
193 }
194
195 LLVMValueRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
196                                                LLVMValueRef *Data,
197                                                size_t Length) {
198   DIBuilder *D = unwrap(Dref);
199   Value **DataValue = unwrap(Data);
200   ArrayRef<Value *> Elements(DataValue, Length);
201   DITypeArray A = D->getOrCreateTypeArray(Elements);
202   return wrap(A);
203 }
204
205 LLVMValueRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, int64_t *Addr,
206                                            size_t Length) {
207   DIBuilder *D = unwrap(Dref);
208   DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
209   return wrap(Expr);
210 }
211
212 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
213                                              LLVMValueRef Storage,
214                                              LLVMValueRef VarInfo,
215                                              LLVMValueRef Expr,
216                                              LLVMBasicBlockRef Block) {
217   DIBuilder *D = unwrap(Dref);
218   Instruction *Instr =
219       D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
220                        unwrapDI<DIExpression>(Expr), unwrap(Block));
221   return wrap(Instr);
222 }