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