llvmlite 0.44.0rc2__cp310-cp310-macosx_10_14_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of llvmlite might be problematic. Click here for more details.

Files changed (46) hide show
  1. llvmlite/__init__.py +10 -0
  2. llvmlite/_version.py +11 -0
  3. llvmlite/binding/__init__.py +19 -0
  4. llvmlite/binding/analysis.py +69 -0
  5. llvmlite/binding/common.py +34 -0
  6. llvmlite/binding/context.py +39 -0
  7. llvmlite/binding/dylib.py +45 -0
  8. llvmlite/binding/executionengine.py +330 -0
  9. llvmlite/binding/ffi.py +395 -0
  10. llvmlite/binding/initfini.py +73 -0
  11. llvmlite/binding/libllvmlite.dylib +0 -0
  12. llvmlite/binding/linker.py +20 -0
  13. llvmlite/binding/module.py +349 -0
  14. llvmlite/binding/newpassmanagers.py +357 -0
  15. llvmlite/binding/object_file.py +82 -0
  16. llvmlite/binding/options.py +17 -0
  17. llvmlite/binding/orcjit.py +342 -0
  18. llvmlite/binding/passmanagers.py +946 -0
  19. llvmlite/binding/targets.py +520 -0
  20. llvmlite/binding/transforms.py +151 -0
  21. llvmlite/binding/typeref.py +285 -0
  22. llvmlite/binding/value.py +632 -0
  23. llvmlite/ir/__init__.py +11 -0
  24. llvmlite/ir/_utils.py +80 -0
  25. llvmlite/ir/builder.py +1120 -0
  26. llvmlite/ir/context.py +20 -0
  27. llvmlite/ir/instructions.py +920 -0
  28. llvmlite/ir/module.py +246 -0
  29. llvmlite/ir/transforms.py +64 -0
  30. llvmlite/ir/types.py +734 -0
  31. llvmlite/ir/values.py +1217 -0
  32. llvmlite/tests/__init__.py +57 -0
  33. llvmlite/tests/__main__.py +3 -0
  34. llvmlite/tests/customize.py +407 -0
  35. llvmlite/tests/refprune_proto.py +329 -0
  36. llvmlite/tests/test_binding.py +3208 -0
  37. llvmlite/tests/test_ir.py +2994 -0
  38. llvmlite/tests/test_refprune.py +730 -0
  39. llvmlite/tests/test_valuerepr.py +60 -0
  40. llvmlite/utils.py +29 -0
  41. llvmlite-0.44.0rc2.dist-info/LICENSE +24 -0
  42. llvmlite-0.44.0rc2.dist-info/LICENSE.thirdparty +225 -0
  43. llvmlite-0.44.0rc2.dist-info/METADATA +138 -0
  44. llvmlite-0.44.0rc2.dist-info/RECORD +46 -0
  45. llvmlite-0.44.0rc2.dist-info/WHEEL +5 -0
  46. llvmlite-0.44.0rc2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,285 @@
1
+ from ctypes import c_int, c_bool, c_void_p, c_uint64, c_uint, POINTER
2
+ import enum
3
+
4
+ from llvmlite import ir
5
+ from llvmlite.binding import ffi
6
+
7
+ # FIXME: Remove `opaque_pointers_enabled' when TP's are removed.
8
+ from llvmlite import opaque_pointers_enabled
9
+
10
+
11
+ class TypeKind(enum.IntEnum):
12
+ # The LLVMTypeKind enum from llvm-c/Core.h
13
+
14
+ void = 0
15
+ half = 1
16
+ float = 2
17
+ double = 3
18
+ x86_fp80 = 4
19
+ fp128 = 5
20
+ ppc_fp128 = 6
21
+ label = 7
22
+ integer = 8
23
+ function = 9
24
+ struct = 10
25
+ array = 11
26
+ pointer = 12
27
+ vector = 13
28
+ metadata = 14
29
+ x86_mmx = 15
30
+ token = 16
31
+ scalable_vector = 17
32
+ bfloat = 18
33
+ x86_amx = 19
34
+
35
+
36
+ _TypeKindToIRType = {
37
+ # All TypeKind here must have a TypeRef.as_ir() implementation
38
+ TypeKind.void: ir.VoidType,
39
+ TypeKind.half: ir.HalfType,
40
+ TypeKind.float: ir.FloatType,
41
+ TypeKind.double: ir.DoubleType,
42
+ TypeKind.integer: ir.IntType,
43
+ TypeKind.function: ir.FunctionType,
44
+ TypeKind.pointer: ir.PointerType,
45
+ TypeKind.array: ir.ArrayType,
46
+ TypeKind.vector: ir.VectorType,
47
+ TypeKind.struct: ir.LiteralStructType,
48
+ }
49
+
50
+
51
+ class TypeRef(ffi.ObjectRef):
52
+ """A weak reference to a LLVM type
53
+ """
54
+ @property
55
+ def name(self):
56
+ """
57
+ Get type name
58
+ """
59
+ return ffi.ret_string(ffi.lib.LLVMPY_GetTypeName(self))
60
+
61
+ @property
62
+ def is_struct(self):
63
+ """
64
+ Returns true if the type is a struct type.
65
+ """
66
+ return ffi.lib.LLVMPY_TypeIsStruct(self)
67
+
68
+ @property
69
+ def is_pointer(self):
70
+ """
71
+ Returns true if the type is a pointer type.
72
+ """
73
+ return ffi.lib.LLVMPY_TypeIsPointer(self)
74
+
75
+ @property
76
+ def is_array(self):
77
+ """
78
+ Returns true if the type is an array type.
79
+ """
80
+ return ffi.lib.LLVMPY_TypeIsArray(self)
81
+
82
+ @property
83
+ def is_vector(self):
84
+ """
85
+ Returns true if the type is a vector type.
86
+ """
87
+ return ffi.lib.LLVMPY_TypeIsVector(self)
88
+
89
+ @property
90
+ def is_function(self):
91
+ """
92
+ Returns true if the type is a function type.
93
+ """
94
+ return ffi.lib.LLVMPY_TypeIsFunction(self)
95
+
96
+ @property
97
+ def is_function_vararg(self):
98
+ """
99
+ Returns true if a function type accepts a variable number of arguments.
100
+ When the type is not a function, raises exception.
101
+ """
102
+ if self.type_kind != TypeKind.function:
103
+ raise ValueError("Type {} is not a function".format(self))
104
+ return ffi.lib.LLVMPY_IsFunctionVararg(self)
105
+
106
+ @property
107
+ def elements(self):
108
+ """
109
+ Returns iterator over enclosing types
110
+ """
111
+ if self.is_pointer and opaque_pointers_enabled:
112
+ raise ValueError("Type {} doesn't contain elements.".format(self))
113
+ return _TypeListIterator(ffi.lib.LLVMPY_ElementIter(self))
114
+
115
+ # FIXME: Remove me once typed pointers support is removed.
116
+ @property
117
+ def element_type(self):
118
+ """
119
+ Returns the pointed-to type. When the type is not a pointer,
120
+ raises exception.
121
+ """
122
+ if not self.is_pointer:
123
+ raise ValueError("Type {} is not a pointer".format(self))
124
+ return TypeRef(ffi.lib.LLVMPY_GetElementType(self))
125
+
126
+ @property
127
+ def element_count(self):
128
+ """
129
+ Returns the number of elements in an array or a vector. For scalable
130
+ vectors, returns minimum number of elements. When the type is neither
131
+ an array nor a vector, raises exception.
132
+ """
133
+ if not self.is_array and not self.is_vector:
134
+ raise ValueError("Type {} is not an array nor vector".format(self))
135
+ return ffi.lib.LLVMPY_GetTypeElementCount(self)
136
+
137
+ @property
138
+ def type_width(self):
139
+ """
140
+ Return the basic size of this type if it is a primitive type. These are
141
+ fixed by LLVM and are not target-dependent.
142
+ This will return zero if the type does not have a size or is not a
143
+ primitive type.
144
+
145
+ If this is a scalable vector type, the scalable property will be set and
146
+ the runtime size will be a positive integer multiple of the base size.
147
+
148
+ Note that this may not reflect the size of memory allocated for an
149
+ instance of the type or the number of bytes that are written when an
150
+ instance of the type is stored to memory.
151
+ """
152
+ return ffi.lib.LLVMPY_GetTypeBitWidth(self)
153
+
154
+ @property
155
+ def type_kind(self):
156
+ """
157
+ Returns the LLVMTypeKind enumeration of this type.
158
+ """
159
+ return TypeKind(ffi.lib.LLVMPY_GetTypeKind(self))
160
+
161
+ @property
162
+ def is_packed_struct(self):
163
+ return ffi.lib.LLVMPY_IsPackedStruct(self)
164
+
165
+ @property
166
+ def is_literal_struct(self):
167
+ return ffi.lib.LLVMPY_IsLiteralStruct(self)
168
+
169
+ @property
170
+ def is_opaque_struct(self):
171
+ return ffi.lib.LLVMPY_IsOpaqueStruct(self)
172
+
173
+ def get_function_parameters(self) -> tuple["TypeRef"]:
174
+ nparams = ffi.lib.LLVMPY_CountParamTypes(self)
175
+ if nparams > 0:
176
+ out_buffer = (ffi.LLVMTypeRef * nparams)(None)
177
+ ffi.lib.LLVMPY_GetParamTypes(self, out_buffer)
178
+ return tuple(map(TypeRef, out_buffer))
179
+ else:
180
+ return ()
181
+
182
+ def get_function_return(self) -> "TypeRef":
183
+ return TypeRef(ffi.lib.LLVMPY_GetReturnType(self))
184
+
185
+ def as_ir(self, ir_ctx: ir.Context) -> ir.Type:
186
+ """Convert into a ``llvmlite.ir.Type``.
187
+ """
188
+ try:
189
+ cls = _TypeKindToIRType[self.type_kind]
190
+ except KeyError:
191
+ msg = f"as_ir() unsupported for TypeRef of {self.type_kind}"
192
+ raise TypeError(msg)
193
+ else:
194
+ return cls.from_llvm(self, ir_ctx)
195
+
196
+ def __str__(self):
197
+ return ffi.ret_string(ffi.lib.LLVMPY_PrintType(self))
198
+
199
+
200
+ class _TypeIterator(ffi.ObjectRef):
201
+
202
+ def __next__(self):
203
+ vp = self._next()
204
+ if vp:
205
+ return TypeRef(vp)
206
+ else:
207
+ raise StopIteration
208
+
209
+ next = __next__
210
+
211
+ def __iter__(self):
212
+ return self
213
+
214
+
215
+ class _TypeListIterator(_TypeIterator):
216
+
217
+ def _dispose(self):
218
+ self._capi.LLVMPY_DisposeElementIter(self)
219
+
220
+ def _next(self):
221
+ return ffi.lib.LLVMPY_ElementIterNext(self)
222
+
223
+
224
+ # FFI
225
+
226
+ ffi.lib.LLVMPY_PrintType.argtypes = [ffi.LLVMTypeRef]
227
+ ffi.lib.LLVMPY_PrintType.restype = c_void_p
228
+
229
+ # FIXME: Remove me once typed pointers support is removed.
230
+ ffi.lib.LLVMPY_GetElementType.argtypes = [ffi.LLVMTypeRef]
231
+ ffi.lib.LLVMPY_GetElementType.restype = ffi.LLVMTypeRef
232
+
233
+ ffi.lib.LLVMPY_TypeIsPointer.argtypes = [ffi.LLVMTypeRef]
234
+ ffi.lib.LLVMPY_TypeIsPointer.restype = c_bool
235
+
236
+ ffi.lib.LLVMPY_TypeIsArray.argtypes = [ffi.LLVMTypeRef]
237
+ ffi.lib.LLVMPY_TypeIsArray.restype = c_bool
238
+
239
+ ffi.lib.LLVMPY_TypeIsVector.argtypes = [ffi.LLVMTypeRef]
240
+ ffi.lib.LLVMPY_TypeIsVector.restype = c_bool
241
+
242
+ ffi.lib.LLVMPY_TypeIsStruct.argtypes = [ffi.LLVMTypeRef]
243
+ ffi.lib.LLVMPY_TypeIsStruct.restype = c_bool
244
+
245
+ ffi.lib.LLVMPY_TypeIsFunction.argtypes = [ffi.LLVMTypeRef]
246
+ ffi.lib.LLVMPY_TypeIsFunction.restype = c_bool
247
+
248
+ ffi.lib.LLVMPY_IsPackedStruct.argtypes = [ffi.LLVMTypeRef]
249
+ ffi.lib.LLVMPY_IsPackedStruct.restype = c_bool
250
+
251
+ ffi.lib.LLVMPY_IsOpaqueStruct.argtypes = [ffi.LLVMTypeRef]
252
+ ffi.lib.LLVMPY_IsOpaqueStruct.restype = c_bool
253
+
254
+ ffi.lib.LLVMPY_IsLiteralStruct.argtypes = [ffi.LLVMTypeRef]
255
+ ffi.lib.LLVMPY_IsLiteralStruct.restype = c_bool
256
+
257
+ ffi.lib.LLVMPY_GetReturnType.argtypes = [ffi.LLVMTypeRef]
258
+ ffi.lib.LLVMPY_GetReturnType.restype = ffi.LLVMTypeRef
259
+
260
+ ffi.lib.LLVMPY_CountParamTypes.argtypes = [ffi.LLVMTypeRef]
261
+ ffi.lib.LLVMPY_CountParamTypes.restype = c_uint
262
+
263
+ ffi.lib.LLVMPY_GetParamTypes.argtypes = [ffi.LLVMTypeRef,
264
+ POINTER(ffi.LLVMTypeRef)]
265
+ ffi.lib.LLVMPY_GetParamTypes.restype = None
266
+
267
+ ffi.lib.LLVMPY_IsFunctionVararg.argtypes = [ffi.LLVMTypeRef]
268
+ ffi.lib.LLVMPY_IsFunctionVararg.restype = c_bool
269
+
270
+ ffi.lib.LLVMPY_GetTypeKind.argtypes = [ffi.LLVMTypeRef]
271
+ ffi.lib.LLVMPY_GetTypeKind.restype = c_int
272
+
273
+ ffi.lib.LLVMPY_GetTypeElementCount.argtypes = [ffi.LLVMTypeRef]
274
+ ffi.lib.LLVMPY_GetTypeElementCount.restype = c_int
275
+
276
+ ffi.lib.LLVMPY_GetTypeBitWidth.argtypes = [ffi.LLVMTypeRef]
277
+ ffi.lib.LLVMPY_GetTypeBitWidth.restype = c_uint64
278
+
279
+ ffi.lib.LLVMPY_ElementIter.argtypes = [ffi.LLVMTypeRef]
280
+ ffi.lib.LLVMPY_ElementIter.restype = ffi.LLVMElementIterator
281
+
282
+ ffi.lib.LLVMPY_ElementIterNext.argtypes = [ffi.LLVMElementIterator]
283
+ ffi.lib.LLVMPY_ElementIterNext.restype = ffi.LLVMTypeRef
284
+
285
+ ffi.lib.LLVMPY_DisposeElementIter.argtypes = [ffi.LLVMElementIterator]