15 |
15 |
16 "{ NameSpace: Smalltalk }" |
16 "{ NameSpace: Smalltalk }" |
17 |
17 |
18 LLVMObject subclass:#LLVMType |
18 LLVMObject subclass:#LLVMType |
19 instanceVariableNames:'' |
19 instanceVariableNames:'' |
20 classVariableNames:'Int1 Int16 Int32 Int64 IntPtr' |
20 classVariableNames:'Int1 Int8 Int16 Int32 Int64 IntPtr Void Half Float Double X86FP80 |
|
21 FP128 PPCFP128 X86MMX KindToClassMapping' |
21 poolDictionaries:'LLVMTypeKind' |
22 poolDictionaries:'LLVMTypeKind' |
22 category:'LLVM-S-Core' |
23 category:'LLVM-S-Core-Types' |
23 ! |
24 ! |
24 |
25 |
25 !LLVMType class methodsFor:'documentation'! |
26 !LLVMType class methodsFor:'documentation'! |
26 |
27 |
27 copyright |
28 copyright |
38 This license is provisional and may (will) change in |
39 This license is provisional and may (will) change in |
39 a future. |
40 a future. |
40 " |
41 " |
41 ! ! |
42 ! ! |
42 |
43 |
|
44 !LLVMType class methodsFor:'initialization'! |
|
45 |
|
46 initialize |
|
47 "Invoked at system start or when the class is dynamically loaded." |
|
48 |
|
49 KindToClassMapping := Dictionary withKeysAndValues: { |
|
50 LLVMHalfTypeKind . LLVMTypeHalt . |
|
51 LLVMFloatTypeKind . LLVMTypeFloat . |
|
52 LLVMDoubleTypeKind . LLVMTypeDouble . |
|
53 LLVMX86_FP80TypeKind . LLVMTypeX86_FP80 . |
|
54 LLVMFP128TypeKind . LLVMTypeFP128. |
|
55 LLVMPPC_FP128TypeKind . LLVMTypePPC_FP128 . |
|
56 LLVMIntegerTypeKind . LLVMTypeInteger . |
|
57 LLVMVectorTypeKind . LLVMTypeVector . |
|
58 LLVMArrayTypeKind . LLVMTypeArray . |
|
59 LLVMStructTypeKind . LLVMTypeStruct . |
|
60 LLVMPointerTypeKind . LLVMTypePointer . |
|
61 LLVMFunctionTypeKind . LLVMTypeFunction . |
|
62 LLVMMetadataTypeKind . LLVMTypeMetadata . |
|
63 LLVMVoidTypeKind . LLVMTypeVoid . |
|
64 LLVMLabelTypeKind . LLVMTypeLabel . |
|
65 LLVMX86_MMXTypeKind . LLVMTypeX86_MMX . |
|
66 } |
|
67 |
|
68 "Modified: / 13-08-2015 / 17:00:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
69 ! ! |
|
70 |
|
71 !LLVMType class methodsFor:'instance creation'! |
|
72 |
|
73 newAddress:addr |
|
74 ^ (super newAddress: addr) |
|
75 initialize; |
|
76 yourself |
|
77 |
|
78 "Created: / 13-08-2015 / 17:14:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
79 ! ! |
|
80 |
|
81 !LLVMType class methodsFor:'queries'! |
|
82 |
|
83 isAbstract |
|
84 "Return if this class is an abstract class. |
|
85 True is returned here for myself only; false for subclasses. |
|
86 Abstract subclasses must redefine again." |
|
87 |
|
88 ^ self == LLVMType. |
|
89 ! ! |
|
90 |
43 !LLVMType class methodsFor:'types - C'! |
91 !LLVMType class methodsFor:'types - C'! |
44 |
92 |
45 char |
93 char |
46 ^ self int8 |
94 ^ self int8 |
47 |
95 |
48 "Created: / 04-08-2015 / 19:32:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
96 "Created: / 04-08-2015 / 19:32:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
49 ! |
97 ! |
50 |
98 |
|
99 void |
|
100 Void isNil ifTrue:[ Void := LLVM VoidType ]. |
|
101 ^ Void |
|
102 |
|
103 "Created: / 13-08-2015 / 17:20:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
104 ! |
|
105 |
51 wchar |
106 wchar |
52 ^ self int16 |
107 ^ self int16 |
53 |
108 |
54 "Created: / 04-08-2015 / 19:32:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
109 "Created: / 04-08-2015 / 19:32:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
55 ! ! |
110 ! ! |
56 |
111 |
|
112 !LLVMType class methodsFor:'types - floating points'! |
|
113 |
|
114 double |
|
115 Double isNil ifTrue:[ Double := LLVM DoubleType ]. |
|
116 ^ Double |
|
117 |
|
118 "Created: / 13-08-2015 / 17:24:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
119 ! |
|
120 |
|
121 float |
|
122 Float isNil ifTrue:[ Float := LLVM FloatType ]. |
|
123 ^ Float |
|
124 |
|
125 "Created: / 13-08-2015 / 17:24:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
126 ! |
|
127 |
|
128 fp128 |
|
129 FP128 isNil ifTrue:[ FP128 := LLVM FP128Type ]. |
|
130 ^ FP128 |
|
131 |
|
132 "Created: / 13-08-2015 / 17:26:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
133 ! |
|
134 |
|
135 half |
|
136 Half isNil ifTrue:[ Half := LLVM HalfType ]. |
|
137 ^ Half |
|
138 |
|
139 "Created: / 13-08-2015 / 17:24:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
140 ! |
|
141 |
|
142 ppcfp128 |
|
143 PPCFP128 isNil ifTrue:[ PPCFP128 := LLVM PPCFP128Type ]. |
|
144 ^ PPCFP128 |
|
145 |
|
146 "Created: / 13-08-2015 / 17:26:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
147 ! |
|
148 |
|
149 x86fp80 |
|
150 X86FP80 isNil ifTrue:[ X86FP80 := LLVM X86FP80Type ]. |
|
151 ^ X86FP80 |
|
152 |
|
153 "Created: / 13-08-2015 / 17:25:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
154 ! |
|
155 |
|
156 x86mmx |
|
157 X86MMX isNil ifTrue:[ X86MMX := LLVM X86MMXType ]. |
|
158 ^ X86MMX |
|
159 |
|
160 "Created: / 13-08-2015 / 17:26:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
161 ! ! |
|
162 |
57 !LLVMType class methodsFor:'types - functions'! |
163 !LLVMType class methodsFor:'types - functions'! |
58 |
164 |
59 function: argumentTypes returning: returnType |
165 function: argumentTypes returning: returnType |
60 ^ self function: argumentTypes varargs: false returning: returnType |
166 ^ self function: argumentTypes varargs: false returning: returnType |
61 |
167 |
70 ! ! |
176 ! ! |
71 |
177 |
72 !LLVMType class methodsFor:'types - integers'! |
178 !LLVMType class methodsFor:'types - integers'! |
73 |
179 |
74 int1 |
180 int1 |
75 Int1 isNil ifTrue:[ |
181 Int1 isNil ifTrue:[ Int1 := LLVM Int1Type ]. |
76 Int1 := LLVM Int1Type |
|
77 ]. |
|
78 ^ Int1 |
182 ^ Int1 |
79 |
183 |
80 "Created: / 07-07-2015 / 21:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
184 "Created: / 07-07-2015 / 21:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
81 "Modified: / 08-08-2015 / 04:23:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
185 "Modified: / 08-08-2015 / 04:23:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
186 "Modified (format): / 13-08-2015 / 17:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
82 ! |
187 ! |
83 |
188 |
84 int16 |
189 int16 |
85 ^ LLVM Int16Type |
190 Int16 isNil ifTrue:[ Int16 := LLVM Int16Type ]. |
|
191 ^ Int16 |
86 |
192 |
87 "Created: / 07-07-2015 / 21:21:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
193 "Created: / 07-07-2015 / 21:21:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
194 "Modified: / 13-08-2015 / 18:48:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
88 ! |
195 ! |
89 |
196 |
90 int32 |
197 int32 |
91 ^ LLVM Int32Type |
198 Int32 isNil ifTrue:[ Int32 := LLVM Int32Type ]. |
|
199 ^ Int32 |
92 |
200 |
93 "Created: / 07-07-2015 / 21:21:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
201 "Created: / 07-07-2015 / 21:21:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
202 "Modified: / 13-08-2015 / 17:22:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
94 ! |
203 ! |
95 |
204 |
96 int64 |
205 int64 |
97 ^ LLVM Int64Type |
206 Int64 isNil ifTrue:[ Int64 := LLVM Int64Type ]. |
|
207 ^ Int64 |
98 |
208 |
99 "Created: / 07-07-2015 / 21:21:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
209 "Created: / 07-07-2015 / 21:21:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
210 "Modified: / 13-08-2015 / 17:22:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
100 ! |
211 ! |
101 |
212 |
102 int8 |
213 int8 |
103 ^ LLVM Int8Type |
214 Int8 isNil ifTrue:[ Int8 := LLVM Int8Type ]. |
|
215 ^ Int8 |
104 |
216 |
105 "Created: / 07-07-2015 / 21:21:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
217 "Created: / 07-07-2015 / 21:21:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
218 "Modified: / 13-08-2015 / 18:47:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
106 ! |
219 ! |
107 |
220 |
108 intptr |
221 intptr |
109 IntPtr isNil ifTrue:[ |
222 IntPtr isNil ifTrue:[ IntPtr := LLVM IntPtrType: LLVMTargetData new ]. |
110 IntPtr := LLVM IntPtrType: LLVMTargetData new. |
|
111 ]. |
|
112 ^ IntPtr |
223 ^ IntPtr |
113 |
224 |
114 "Created: / 11-07-2015 / 07:05:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
225 "Created: / 11-07-2015 / 07:05:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
226 "Modified (format): / 13-08-2015 / 17:22:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
227 ! ! |
|
228 |
|
229 !LLVMType class methodsFor:'types - structures'! |
|
230 |
|
231 struct: memberTypes |
|
232 ^ self struct: memberTypes packed: false |
|
233 |
|
234 "Created: / 13-08-2015 / 19:15:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
235 ! |
|
236 |
|
237 struct: memberTypes packed: packed |
|
238 |
|
239 self assert: memberTypes isSequenceable message: '`memberTypes` parameter is not an array of types'. |
|
240 self assert: (memberTypes allSatisfy:[:e|e isLLVMType]) message: 'element of a `memberTypes` parameter is not an LLVM type'. |
|
241 self assert: packed isBoolean message: '`packed` parameter is not a boolean'. |
|
242 |
|
243 ^ LLVM StructType: memberTypes asLLVMObjectArray _: memberTypes size _: (packed ifTrue:[ 1 ] ifFalse:[ 0 ]) |
|
244 |
|
245 "Created: / 13-08-2015 / 19:15:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
246 "Modified: / 14-08-2015 / 05:49:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
115 ! ! |
247 ! ! |
116 |
248 |
117 !LLVMType methodsFor:'accessing'! |
249 !LLVMType methodsFor:'accessing'! |
118 |
250 |
119 kind |
251 kind |
120 ^ LLVM GetTypeKind: self |
252 ^ LLVM GetTypeKind: self |
121 |
253 |
122 "Created: / 07-07-2015 / 21:59:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
254 "Created: / 07-07-2015 / 21:59:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
255 ! |
|
256 |
|
257 sizeInBits |
|
258 "For integer, pointer, FP types, return the size in bits. For all |
|
259 other types, throw an LLVMTypeError. |
|
260 |
|
261 LLVMType int32 sizeInBits -> 32 |
|
262 LLVMType int1 sizeInBits -> 1 |
|
263 " |
|
264 LLVMTypeError new signal: 'type size not known' |
|
265 |
|
266 "Created: / 13-08-2015 / 16:25:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
123 ! ! |
267 ! ! |
124 |
268 |
125 !LLVMType methodsFor:'comparing'! |
269 !LLVMType methodsFor:'comparing'! |
126 |
270 |
127 = anotherType |
271 = anotherType |
135 |
279 |
136 "Created: / 08-08-2015 / 02:50:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
280 "Created: / 08-08-2015 / 02:50:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
137 ! ! |
281 ! ! |
138 |
282 |
139 !LLVMType methodsFor:'converting'! |
283 !LLVMType methodsFor:'converting'! |
|
284 |
|
285 array: numberOfElements |
|
286 "Create a fixed-size array whose elements are of type of receiver |
|
287 `LLVMType int8 array: 13` returns `[ 13 x i8 ]`" |
|
288 |
|
289 self assertIsIntegerUnsigned: numberOfElements. |
|
290 ^ LLVM ArrayType: self _: numberOfElements |
|
291 |
|
292 "Created: / 13-08-2015 / 18:57:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
293 ! |
140 |
294 |
141 pointer |
295 pointer |
142 "Return a pointer to the type represented by the receiver. |
296 "Return a pointer to the type represented by the receiver. |
143 `LLVMType int32 pointer` returns int32_t*" |
297 `LLVMType int32 pointer` returns int32_t*" |
144 |
298 |
145 ^ LLVM PointerType: self _: "AddressSpace"0 |
299 ^ LLVM PointerType: self _: "AddressSpace"0 |
146 |
300 |
147 "Created: / 04-08-2015 / 19:31:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
301 "Created: / 04-08-2015 / 19:31:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
302 ! |
|
303 |
|
304 vector: numberOfElements |
|
305 "Create a fixed-size vector whose elements are of type of receiver." |
|
306 |
|
307 self assertIsIntegerUnsigned: numberOfElements. |
|
308 ^ LLVM VectorType: self _: numberOfElements |
|
309 |
|
310 "Created: / 13-08-2015 / 18:59:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
148 ! ! |
311 ! ! |
149 |
312 |
150 !LLVMType methodsFor:'debugging-dumping'! |
313 !LLVMType methodsFor:'debugging-dumping'! |
151 |
314 |
152 dumpOn: aStream |
315 dumpOn: aStream |
214 |
377 |
215 "Created: / 11-07-2015 / 07:08:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
378 "Created: / 11-07-2015 / 07:08:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
216 "Modified: / 08-08-2015 / 04:21:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
379 "Modified: / 08-08-2015 / 04:21:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
217 ! ! |
380 ! ! |
218 |
381 |
|
382 !LLVMType methodsFor:'initialization'! |
|
383 |
|
384 initialize |
|
385 self class == LLVMType ifTrue:[ |
|
386 self changeClassTo: (KindToClassMapping at: self kind) |
|
387 ]. |
|
388 |
|
389 "Created: / 13-08-2015 / 16:53:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
390 "Modified: / 13-08-2015 / 18:43:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
391 ! ! |
|
392 |
219 !LLVMType methodsFor:'testing'! |
393 !LLVMType methodsFor:'testing'! |
220 |
394 |
|
395 isArrayType |
|
396 ^ false |
|
397 |
|
398 "Created: / 13-08-2015 / 16:19:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
399 ! |
|
400 |
|
401 isDoubleType |
|
402 ^ false |
|
403 |
|
404 "Created: / 13-08-2015 / 16:14:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
405 ! |
|
406 |
|
407 isFP128Type |
|
408 ^ false |
|
409 |
|
410 "Created: / 13-08-2015 / 16:15:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
411 ! |
|
412 |
|
413 isFloatType |
|
414 ^ false |
|
415 |
|
416 "Created: / 13-08-2015 / 16:14:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
417 ! |
|
418 |
|
419 isFunctionType |
|
420 ^ false |
|
421 |
|
422 "Created: / 13-08-2015 / 16:16:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
423 ! |
|
424 |
|
425 isHalfType |
|
426 ^ false |
|
427 |
|
428 "Created: / 13-08-2015 / 16:14:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
429 ! |
|
430 |
221 isIntegerType |
431 isIntegerType |
222 ^ self kind == LLVMIntegerTypeKind |
432 ^ false |
223 |
433 |
224 "Created: / 11-07-2015 / 14:56:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
434 "Created: / 11-07-2015 / 14:56:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
435 "Modified: / 13-08-2015 / 16:49:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
225 ! |
436 ! |
226 |
437 |
227 isLLVMType |
438 isLLVMType |
228 "Return true, if receiver represents an LLVM type" |
439 "Return true, if receiver represents an LLVM type" |
229 |
440 |
230 ^ true |
441 ^ true |
231 |
442 |
232 "Created: / 08-08-2015 / 02:46:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
443 "Created: / 08-08-2015 / 02:46:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
233 ! |
444 ! |
234 |
445 |
|
446 isLabelType |
|
447 ^ false |
|
448 |
|
449 "Created: / 13-08-2015 / 16:16:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
450 ! |
|
451 |
|
452 isMetadataType |
|
453 ^ false |
|
454 |
|
455 "Created: / 13-08-2015 / 16:20:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
456 ! |
|
457 |
|
458 isPPC_FP128Type |
|
459 ^ false |
|
460 |
|
461 "Created: / 13-08-2015 / 16:15:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
462 ! |
|
463 |
|
464 isPointerType |
|
465 ^ false |
|
466 |
|
467 "Created: / 13-08-2015 / 16:19:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
468 ! |
|
469 |
|
470 isStructType |
|
471 ^ false |
|
472 |
|
473 "Created: / 13-08-2015 / 16:19:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
474 ! |
|
475 |
235 isVectorType |
476 isVectorType |
236 ^ self kind == LLVMVectorTypeKind |
477 ^ false |
237 |
478 |
238 "Created: / 11-07-2015 / 14:56:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
479 "Created: / 11-07-2015 / 14:56:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
480 "Modified: / 13-08-2015 / 16:50:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
481 ! |
|
482 |
|
483 isVoidType |
|
484 ^false |
|
485 |
|
486 "Created: / 13-08-2015 / 16:13:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
487 ! |
|
488 |
|
489 isX86_FP80Type |
|
490 ^ false |
|
491 |
|
492 "Created: / 13-08-2015 / 16:14:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
493 ! |
|
494 |
|
495 isX86_MMXType |
|
496 ^ false |
|
497 |
|
498 "Created: / 13-08-2015 / 16:20:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
239 ! ! |
499 ! ! |
240 |
500 |
241 !LLVMType class methodsFor:'documentation'! |
501 !LLVMType class methodsFor:'documentation'! |
242 |
502 |
243 version_HG |
503 version_HG |
244 |
504 |
245 ^ '$Changeset: <not expanded> $' |
505 ^ '$Changeset: <not expanded> $' |
246 ! ! |
506 ! ! |
247 |
507 |
|
508 |
|
509 LLVMType initialize! |