comparison bindings/go/llvm/DIBuilderBindings.cpp @ 83:60c9769439b8 LLVM3.7

LLVM 3.7
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 18 Feb 2015 14:55:36 +0900
parents
children afa8332a0e37
comparison
equal deleted inserted replaced
78:af83660cff7b 83:60c9769439b8
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
150 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
151 const char *Name, LLVMMetadataRef File,
152 unsigned Line, uint64_t SizeInBits,
153 uint64_t AlignInBits, uint64_t OffsetInBits,
154 unsigned Flags, LLVMMetadataRef Ty) {
155 DIBuilder *D = unwrap(Dref);
156 DIDerivedType DT = D->createMemberType(
157 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
158 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
159 return wrap(DT);
160 }
161
162 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
163 uint64_t SizeInBits,
164 uint64_t AlignInBits,
165 LLVMMetadataRef ElementType,
166 LLVMMetadataRef Subscripts) {
167 DIBuilder *D = unwrap(Dref);
168 DICompositeType CT =
169 D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType),
170 unwrapDI<DIArray>(Subscripts));
171 return wrap(CT);
172 }
173
174 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
175 LLVMMetadataRef Ty, const char *Name,
176 LLVMMetadataRef File, unsigned Line,
177 LLVMMetadataRef Context) {
178 DIBuilder *D = unwrap(Dref);
179 DIDerivedType DT =
180 D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line,
181 unwrapDI<DIDescriptor>(Context));
182 return wrap(DT);
183 }
184
185 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
186 int64_t Lo, int64_t Count) {
187 DIBuilder *D = unwrap(Dref);
188 DISubrange S = D->getOrCreateSubrange(Lo, Count);
189 return wrap(S);
190 }
191
192 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
193 LLVMMetadataRef *Data,
194 size_t Length) {
195 DIBuilder *D = unwrap(Dref);
196 Metadata **DataValue = unwrap(Data);
197 ArrayRef<Metadata *> Elements(DataValue, Length);
198 DIArray A = D->getOrCreateArray(Elements);
199 return wrap(A);
200 }
201
202 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
203 LLVMMetadataRef *Data,
204 size_t Length) {
205 DIBuilder *D = unwrap(Dref);
206 Metadata **DataValue = unwrap(Data);
207 ArrayRef<Metadata *> Elements(DataValue, Length);
208 DITypeArray A = D->getOrCreateTypeArray(Elements);
209 return wrap(A);
210 }
211
212 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
213 int64_t *Addr, size_t Length) {
214 DIBuilder *D = unwrap(Dref);
215 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
216 return wrap(Expr);
217 }
218
219 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
220 LLVMValueRef Storage,
221 LLVMMetadataRef VarInfo,
222 LLVMMetadataRef Expr,
223 LLVMBasicBlockRef Block) {
224 DIBuilder *D = unwrap(Dref);
225 Instruction *Instr =
226 D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
227 unwrapDI<DIExpression>(Expr), unwrap(Block));
228 return wrap(Instr);
229 }
230
231 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
232 LLVMValueRef Val, uint64_t Offset,
233 LLVMMetadataRef VarInfo,
234 LLVMMetadataRef Expr,
235 LLVMBasicBlockRef Block) {
236 DIBuilder *D = unwrap(Dref);
237 Instruction *Instr = D->insertDbgValueIntrinsic(
238 unwrap(Val), Offset, unwrapDI<DIVariable>(VarInfo),
239 unwrapDI<DIExpression>(Expr), unwrap(Block));
240 return wrap(Instr);
241 }