Mercurial > hg > CbC > CbC_llvm
comparison bindings/go/llvm/DIBuilderBindings.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 7d135dc70f03 |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
18 #include "llvm/IR/Module.h" | 18 #include "llvm/IR/Module.h" |
19 | 19 |
20 using namespace llvm; | 20 using namespace llvm; |
21 | 21 |
22 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef) | 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 | 23 |
30 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) { | 24 LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) { |
31 Module *m = unwrap(mref); | 25 Module *m = unwrap(mref); |
32 return wrap(new DIBuilder(*m)); | 26 return wrap(new DIBuilder(*m)); |
33 } | 27 } |
44 const char *Dir, | 38 const char *Dir, |
45 const char *Producer, | 39 const char *Producer, |
46 int Optimized, const char *Flags, | 40 int Optimized, const char *Flags, |
47 unsigned RuntimeVersion) { | 41 unsigned RuntimeVersion) { |
48 DIBuilder *D = unwrap(Dref); | 42 DIBuilder *D = unwrap(Dref); |
49 DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized, | 43 return wrap(D->createCompileUnit(Lang, File, Dir, Producer, Optimized, Flags, |
50 Flags, RuntimeVersion); | 44 RuntimeVersion)); |
51 return wrap(CU); | |
52 } | 45 } |
53 | 46 |
54 LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File, | 47 LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File, |
55 const char *Dir) { | 48 const char *Dir) { |
56 DIBuilder *D = unwrap(Dref); | 49 DIBuilder *D = unwrap(Dref); |
57 DIFile F = D->createFile(File, Dir); | 50 return wrap(D->createFile(File, Dir)); |
58 return wrap(F); | |
59 } | 51 } |
60 | 52 |
61 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref, | 53 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref, |
62 LLVMMetadataRef Scope, | 54 LLVMMetadataRef Scope, |
63 LLVMMetadataRef File, | 55 LLVMMetadataRef File, |
64 unsigned Line, | 56 unsigned Line, |
65 unsigned Column) { | 57 unsigned Column) { |
66 DIBuilder *D = unwrap(Dref); | 58 DIBuilder *D = unwrap(Dref); |
67 DILexicalBlock LB = D->createLexicalBlock( | 59 auto *LB = D->createLexicalBlock(unwrap<DILocalScope>(Scope), |
68 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column); | 60 unwrap<DIFile>(File), Line, Column); |
69 return wrap(LB); | 61 return wrap(LB); |
70 } | 62 } |
71 | 63 |
72 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref, | 64 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref, |
73 LLVMMetadataRef Scope, | 65 LLVMMetadataRef Scope, |
74 LLVMMetadataRef File, | 66 LLVMMetadataRef File, |
75 unsigned Discriminator) { | 67 unsigned Discriminator) { |
76 DIBuilder *D = unwrap(Dref); | 68 DIBuilder *D = unwrap(Dref); |
77 DILexicalBlockFile LBF = D->createLexicalBlockFile( | 69 return wrap(D->createLexicalBlockFile(unwrap<DILocalScope>(Scope), |
78 unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Discriminator); | 70 unwrap<DIFile>(File), Discriminator)); |
79 return wrap(LBF); | |
80 } | 71 } |
81 | 72 |
82 LLVMMetadataRef LLVMDIBuilderCreateFunction( | 73 LLVMMetadataRef LLVMDIBuilderCreateFunction( |
83 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, | 74 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, |
84 const char *LinkageName, LLVMMetadataRef File, unsigned Line, | 75 const char *LinkageName, LLVMMetadataRef File, unsigned Line, |
85 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition, | 76 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition, |
86 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) { | 77 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) { |
87 DIBuilder *D = unwrap(Dref); | 78 DIBuilder *D = unwrap(Dref); |
88 DISubprogram SP = D->createFunction( | 79 return wrap(D->createFunction(unwrap<DIScope>(Scope), Name, LinkageName, |
89 unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File), | 80 File ? unwrap<DIFile>(File) : nullptr, Line, |
90 Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit, | 81 unwrap<DISubroutineType>(CompositeType), |
91 IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func)); | 82 IsLocalToUnit, IsDefinition, ScopeLine, Flags, |
92 return wrap(SP); | 83 IsOptimized, unwrap<Function>(Func))); |
93 } | 84 } |
94 | 85 |
95 LLVMMetadataRef LLVMDIBuilderCreateLocalVariable( | 86 LLVMMetadataRef |
96 LLVMDIBuilderRef Dref, unsigned Tag, LLVMMetadataRef Scope, | 87 LLVMDIBuilderCreateAutoVariable(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, |
97 const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, | 88 const char *Name, LLVMMetadataRef File, |
98 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) { | 89 unsigned Line, LLVMMetadataRef Ty, |
99 DIBuilder *D = unwrap(Dref); | 90 int AlwaysPreserve, unsigned Flags) { |
100 DIVariable V = D->createLocalVariable( | 91 DIBuilder *D = unwrap(Dref); |
101 Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line, | 92 return wrap(D->createAutoVariable(unwrap<DIScope>(Scope), Name, |
102 unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo); | 93 unwrap<DIFile>(File), Line, |
103 return wrap(V); | 94 unwrap<DIType>(Ty), AlwaysPreserve, Flags)); |
95 } | |
96 | |
97 LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( | |
98 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, | |
99 unsigned ArgNo, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, | |
100 int AlwaysPreserve, unsigned Flags) { | |
101 DIBuilder *D = unwrap(Dref); | |
102 return wrap(D->createParameterVariable( | |
103 unwrap<DIScope>(Scope), Name, ArgNo, unwrap<DIFile>(File), Line, | |
104 unwrap<DIType>(Ty), AlwaysPreserve, Flags)); | |
104 } | 105 } |
105 | 106 |
106 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref, | 107 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref, |
107 const char *Name, | 108 const char *Name, |
108 uint64_t SizeInBits, | 109 uint64_t SizeInBits, |
109 uint64_t AlignInBits, | 110 uint64_t AlignInBits, |
110 unsigned Encoding) { | 111 unsigned Encoding) { |
111 DIBuilder *D = unwrap(Dref); | 112 DIBuilder *D = unwrap(Dref); |
112 DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding); | 113 return wrap(D->createBasicType(Name, SizeInBits, AlignInBits, Encoding)); |
113 return wrap(T); | |
114 } | 114 } |
115 | 115 |
116 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref, | 116 LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref, |
117 LLVMMetadataRef PointeeType, | 117 LLVMMetadataRef PointeeType, |
118 uint64_t SizeInBits, | 118 uint64_t SizeInBits, |
119 uint64_t AlignInBits, | 119 uint64_t AlignInBits, |
120 const char *Name) { | 120 const char *Name) { |
121 DIBuilder *D = unwrap(Dref); | 121 DIBuilder *D = unwrap(Dref); |
122 DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType), | 122 return wrap(D->createPointerType(unwrap<DIType>(PointeeType), SizeInBits, |
123 SizeInBits, AlignInBits, Name); | 123 AlignInBits, Name)); |
124 return wrap(T); | |
125 } | 124 } |
126 | 125 |
127 LLVMMetadataRef | 126 LLVMMetadataRef |
128 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File, | 127 LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File, |
129 LLVMMetadataRef ParameterTypes) { | 128 LLVMMetadataRef ParameterTypes) { |
130 DIBuilder *D = unwrap(Dref); | 129 DIBuilder *D = unwrap(Dref); |
131 DICompositeType CT = D->createSubroutineType( | 130 return wrap( |
132 unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes)); | 131 D->createSubroutineType(File ? unwrap<DIFile>(File) : nullptr, |
133 return wrap(CT); | 132 DITypeRefArray(unwrap<MDTuple>(ParameterTypes)))); |
134 } | 133 } |
135 | 134 |
136 LLVMMetadataRef LLVMDIBuilderCreateStructType( | 135 LLVMMetadataRef LLVMDIBuilderCreateStructType( |
137 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, | 136 LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, |
138 LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits, | 137 LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits, |
139 uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom, | 138 uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom, |
140 LLVMMetadataRef ElementTypes) { | 139 LLVMMetadataRef ElementTypes) { |
141 DIBuilder *D = unwrap(Dref); | 140 DIBuilder *D = unwrap(Dref); |
142 DICompositeType CT = D->createStructType( | 141 return wrap(D->createStructType( |
143 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line, | 142 unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line, |
144 SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom), | 143 SizeInBits, AlignInBits, Flags, |
145 unwrapDI<DIArray>(ElementTypes)); | 144 DerivedFrom ? unwrap<DIType>(DerivedFrom) : nullptr, |
146 return wrap(CT); | 145 ElementTypes ? DINodeArray(unwrap<MDTuple>(ElementTypes)) : nullptr)); |
146 } | |
147 | |
148 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType( | |
149 LLVMDIBuilderRef Dref, unsigned Tag, const char *Name, | |
150 LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, | |
151 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, | |
152 unsigned Flags) { | |
153 DIBuilder *D = unwrap(Dref); | |
154 return wrap(D->createReplaceableCompositeType( | |
155 Tag, Name, unwrap<DIScope>(Scope), File ? unwrap<DIFile>(File) : nullptr, | |
156 Line, RuntimeLang, SizeInBits, AlignInBits, Flags)); | |
147 } | 157 } |
148 | 158 |
149 LLVMMetadataRef | 159 LLVMMetadataRef |
150 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, | 160 LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, |
151 const char *Name, LLVMMetadataRef File, | 161 const char *Name, LLVMMetadataRef File, |
152 unsigned Line, uint64_t SizeInBits, | 162 unsigned Line, uint64_t SizeInBits, |
153 uint64_t AlignInBits, uint64_t OffsetInBits, | 163 uint64_t AlignInBits, uint64_t OffsetInBits, |
154 unsigned Flags, LLVMMetadataRef Ty) { | 164 unsigned Flags, LLVMMetadataRef Ty) { |
155 DIBuilder *D = unwrap(Dref); | 165 DIBuilder *D = unwrap(Dref); |
156 DIDerivedType DT = D->createMemberType( | 166 return wrap(D->createMemberType( |
157 unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line, | 167 unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line, |
158 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty)); | 168 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrap<DIType>(Ty))); |
159 return wrap(DT); | |
160 } | 169 } |
161 | 170 |
162 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref, | 171 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref, |
163 uint64_t SizeInBits, | 172 uint64_t SizeInBits, |
164 uint64_t AlignInBits, | 173 uint64_t AlignInBits, |
165 LLVMMetadataRef ElementType, | 174 LLVMMetadataRef ElementType, |
166 LLVMMetadataRef Subscripts) { | 175 LLVMMetadataRef Subscripts) { |
167 DIBuilder *D = unwrap(Dref); | 176 DIBuilder *D = unwrap(Dref); |
168 DICompositeType CT = | 177 return wrap(D->createArrayType(SizeInBits, AlignInBits, |
169 D->createArrayType(SizeInBits, AlignInBits, unwrapDI<DIType>(ElementType), | 178 unwrap<DIType>(ElementType), |
170 unwrapDI<DIArray>(Subscripts)); | 179 DINodeArray(unwrap<MDTuple>(Subscripts)))); |
171 return wrap(CT); | |
172 } | 180 } |
173 | 181 |
174 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, | 182 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, |
175 LLVMMetadataRef Ty, const char *Name, | 183 LLVMMetadataRef Ty, const char *Name, |
176 LLVMMetadataRef File, unsigned Line, | 184 LLVMMetadataRef File, unsigned Line, |
177 LLVMMetadataRef Context) { | 185 LLVMMetadataRef Context) { |
178 DIBuilder *D = unwrap(Dref); | 186 DIBuilder *D = unwrap(Dref); |
179 DIDerivedType DT = | 187 return wrap(D->createTypedef(unwrap<DIType>(Ty), Name, |
180 D->createTypedef(unwrapDI<DIType>(Ty), Name, unwrapDI<DIFile>(File), Line, | 188 File ? unwrap<DIFile>(File) : nullptr, Line, |
181 unwrapDI<DIDescriptor>(Context)); | 189 Context ? unwrap<DIScope>(Context) : nullptr)); |
182 return wrap(DT); | |
183 } | 190 } |
184 | 191 |
185 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, | 192 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, |
186 int64_t Lo, int64_t Count) { | 193 int64_t Lo, int64_t Count) { |
187 DIBuilder *D = unwrap(Dref); | 194 DIBuilder *D = unwrap(Dref); |
188 DISubrange S = D->getOrCreateSubrange(Lo, Count); | 195 return wrap(D->getOrCreateSubrange(Lo, Count)); |
189 return wrap(S); | |
190 } | 196 } |
191 | 197 |
192 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref, | 198 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref, |
193 LLVMMetadataRef *Data, | 199 LLVMMetadataRef *Data, |
194 size_t Length) { | 200 size_t Length) { |
195 DIBuilder *D = unwrap(Dref); | 201 DIBuilder *D = unwrap(Dref); |
196 Metadata **DataValue = unwrap(Data); | 202 Metadata **DataValue = unwrap(Data); |
197 ArrayRef<Metadata *> Elements(DataValue, Length); | 203 ArrayRef<Metadata *> Elements(DataValue, Length); |
198 DIArray A = D->getOrCreateArray(Elements); | 204 DINodeArray A = D->getOrCreateArray(Elements); |
199 return wrap(A); | 205 return wrap(A.get()); |
200 } | 206 } |
201 | 207 |
202 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref, | 208 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref, |
203 LLVMMetadataRef *Data, | 209 LLVMMetadataRef *Data, |
204 size_t Length) { | 210 size_t Length) { |
205 DIBuilder *D = unwrap(Dref); | 211 DIBuilder *D = unwrap(Dref); |
206 Metadata **DataValue = unwrap(Data); | 212 Metadata **DataValue = unwrap(Data); |
207 ArrayRef<Metadata *> Elements(DataValue, Length); | 213 ArrayRef<Metadata *> Elements(DataValue, Length); |
208 DITypeArray A = D->getOrCreateTypeArray(Elements); | 214 DITypeRefArray A = D->getOrCreateTypeArray(Elements); |
209 return wrap(A); | 215 return wrap(A.get()); |
210 } | 216 } |
211 | 217 |
212 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, | 218 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, |
213 int64_t *Addr, size_t Length) { | 219 int64_t *Addr, size_t Length) { |
214 DIBuilder *D = unwrap(Dref); | 220 DIBuilder *D = unwrap(Dref); |
215 DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length)); | 221 return wrap(D->createExpression(ArrayRef<int64_t>(Addr, Length))); |
216 return wrap(Expr); | |
217 } | 222 } |
218 | 223 |
219 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref, | 224 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref, |
220 LLVMValueRef Storage, | 225 LLVMValueRef Storage, |
221 LLVMMetadataRef VarInfo, | 226 LLVMMetadataRef VarInfo, |
222 LLVMMetadataRef Expr, | 227 LLVMMetadataRef Expr, |
223 LLVMBasicBlockRef Block) { | 228 LLVMBasicBlockRef Block) { |
224 DIBuilder *D = unwrap(Dref); | 229 // Fail immediately here until the llgo folks update their bindings. The |
225 Instruction *Instr = | 230 // called function is going to assert out anyway. |
226 D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo), | 231 llvm_unreachable("DIBuilder API change requires a DebugLoc"); |
227 unwrapDI<DIExpression>(Expr), unwrap(Block)); | 232 |
233 DIBuilder *D = unwrap(Dref); | |
234 Instruction *Instr = D->insertDeclare( | |
235 unwrap(Storage), unwrap<DILocalVariable>(VarInfo), | |
236 unwrap<DIExpression>(Expr), /* DebugLoc */ nullptr, unwrap(Block)); | |
228 return wrap(Instr); | 237 return wrap(Instr); |
229 } | 238 } |
230 | 239 |
231 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref, | 240 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref, |
232 LLVMValueRef Val, uint64_t Offset, | 241 LLVMValueRef Val, uint64_t Offset, |
233 LLVMMetadataRef VarInfo, | 242 LLVMMetadataRef VarInfo, |
234 LLVMMetadataRef Expr, | 243 LLVMMetadataRef Expr, |
235 LLVMBasicBlockRef Block) { | 244 LLVMBasicBlockRef Block) { |
245 // Fail immediately here until the llgo folks update their bindings. The | |
246 // called function is going to assert out anyway. | |
247 llvm_unreachable("DIBuilder API change requires a DebugLoc"); | |
248 | |
236 DIBuilder *D = unwrap(Dref); | 249 DIBuilder *D = unwrap(Dref); |
237 Instruction *Instr = D->insertDbgValueIntrinsic( | 250 Instruction *Instr = D->insertDbgValueIntrinsic( |
238 unwrap(Val), Offset, unwrapDI<DIVariable>(VarInfo), | 251 unwrap(Val), Offset, unwrap<DILocalVariable>(VarInfo), |
239 unwrapDI<DIExpression>(Expr), unwrap(Block)); | 252 unwrap<DIExpression>(Expr), /* DebugLoc */ nullptr, unwrap(Block)); |
240 return wrap(Instr); | 253 return wrap(Instr); |
241 } | 254 } |