llvmlite 0.46.0b1__cp314-cp314-win_amd64.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 (47) hide show
  1. llvmlite/__init__.py +22 -0
  2. llvmlite/_version.py +11 -0
  3. llvmlite/binding/__init__.py +18 -0
  4. llvmlite/binding/analysis.py +69 -0
  5. llvmlite/binding/common.py +34 -0
  6. llvmlite/binding/config.py +143 -0
  7. llvmlite/binding/context.py +31 -0
  8. llvmlite/binding/dylib.py +45 -0
  9. llvmlite/binding/executionengine.py +330 -0
  10. llvmlite/binding/ffi.py +395 -0
  11. llvmlite/binding/initfini.py +85 -0
  12. llvmlite/binding/linker.py +20 -0
  13. llvmlite/binding/llvmlite.dll +0 -0
  14. llvmlite/binding/module.py +349 -0
  15. llvmlite/binding/newpassmanagers.py +1049 -0
  16. llvmlite/binding/object_file.py +82 -0
  17. llvmlite/binding/options.py +17 -0
  18. llvmlite/binding/orcjit.py +342 -0
  19. llvmlite/binding/targets.py +462 -0
  20. llvmlite/binding/typeref.py +267 -0
  21. llvmlite/binding/value.py +632 -0
  22. llvmlite/ir/__init__.py +11 -0
  23. llvmlite/ir/_utils.py +80 -0
  24. llvmlite/ir/builder.py +1120 -0
  25. llvmlite/ir/context.py +20 -0
  26. llvmlite/ir/instructions.py +920 -0
  27. llvmlite/ir/module.py +256 -0
  28. llvmlite/ir/transforms.py +64 -0
  29. llvmlite/ir/types.py +730 -0
  30. llvmlite/ir/values.py +1217 -0
  31. llvmlite/tests/__init__.py +57 -0
  32. llvmlite/tests/__main__.py +3 -0
  33. llvmlite/tests/customize.py +407 -0
  34. llvmlite/tests/refprune_proto.py +330 -0
  35. llvmlite/tests/test_binding.py +3155 -0
  36. llvmlite/tests/test_ir.py +3095 -0
  37. llvmlite/tests/test_refprune.py +574 -0
  38. llvmlite/tests/test_valuerepr.py +60 -0
  39. llvmlite/utils.py +29 -0
  40. llvmlite-0.46.0b1.dist-info/DELVEWHEEL +2 -0
  41. llvmlite-0.46.0b1.dist-info/METADATA +145 -0
  42. llvmlite-0.46.0b1.dist-info/RECORD +47 -0
  43. llvmlite-0.46.0b1.dist-info/WHEEL +5 -0
  44. llvmlite-0.46.0b1.dist-info/licenses/LICENSE +24 -0
  45. llvmlite-0.46.0b1.dist-info/licenses/LICENSE.thirdparty +225 -0
  46. llvmlite-0.46.0b1.dist-info/top_level.txt +1 -0
  47. llvmlite.libs/msvcp140-8f141b4454fa78db34bc1f28c571b4da.dll +0 -0
llvmlite/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ """""" # start delvewheel patch
2
+ def _delvewheel_patch_1_11_1():
3
+ import os
4
+ if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'llvmlite.libs'))):
5
+ os.add_dll_directory(libs_dir)
6
+
7
+
8
+ _delvewheel_patch_1_11_1()
9
+ del _delvewheel_patch_1_11_1
10
+ # end delvewheel patch
11
+
12
+ from ._version import get_versions
13
+ __version__ = get_versions()['version']
14
+ del get_versions
15
+
16
+ # We default to IR layer typed pointers being enabled, since they're needed in
17
+ # the most common usage scenarios with later LLVMs.
18
+ def _ir_layer_typed_pointers_enabled():
19
+ import os
20
+ return os.environ.get('LLVMLITE_ENABLE_IR_LAYER_TYPED_POINTERS', '1') == '1'
21
+ ir_layer_typed_pointers_enabled = _ir_layer_typed_pointers_enabled()
22
+ del _ir_layer_typed_pointers_enabled
llvmlite/_version.py ADDED
@@ -0,0 +1,11 @@
1
+
2
+ # This file was generated by 'versioneer.py' (0.14) from
3
+ # revision-control system data, or from the parent directory name of an
4
+ # unpacked source archive. Distribution tarballs contain a pre-generated copy
5
+ # of this file.
6
+
7
+ version_version = '0.46.0b1'
8
+ version_full = '5f77715902a7a311953fad682f41f25c81c21790'
9
+ def get_versions(default={}, verbose=False):
10
+ return {'version': version_version, 'full': version_full}
11
+
@@ -0,0 +1,18 @@
1
+ """
2
+ Things that rely on the LLVM library
3
+ """
4
+ from .dylib import *
5
+ from .executionengine import *
6
+ from .initfini import *
7
+ from .linker import *
8
+ from .module import *
9
+ from .options import *
10
+ from .newpassmanagers import *
11
+ from .targets import *
12
+ from .value import *
13
+ from .typeref import *
14
+ from .analysis import *
15
+ from .object_file import *
16
+ from .context import *
17
+ from .orcjit import *
18
+ from .config import *
@@ -0,0 +1,69 @@
1
+ """
2
+ A collection of analysis utilities
3
+ """
4
+
5
+ from ctypes import POINTER, c_char_p, c_int
6
+
7
+ from llvmlite.binding import ffi
8
+ from llvmlite.binding.module import parse_assembly
9
+
10
+
11
+ def get_function_cfg(func, show_inst=True):
12
+ """Return a string of the control-flow graph of the function in DOT
13
+ format. If the input `func` is not a materialized function, the module
14
+ containing the function is parsed to create an actual LLVM module.
15
+ The `show_inst` flag controls whether the instructions of each block
16
+ are printed.
17
+ """
18
+ assert func is not None
19
+ from llvmlite import ir
20
+ if isinstance(func, ir.Function):
21
+ mod = parse_assembly(str(func.module))
22
+ func = mod.get_function(func.name)
23
+
24
+ # Assume func is a materialized function
25
+ with ffi.OutputString() as dotstr:
26
+ ffi.lib.LLVMPY_WriteCFG(func, dotstr, show_inst)
27
+ return str(dotstr)
28
+
29
+
30
+ def view_dot_graph(graph, filename=None, view=False):
31
+ """
32
+ View the given DOT source. If view is True, the image is rendered
33
+ and viewed by the default application in the system. The file path of
34
+ the output is returned. If view is False, a graphviz.Source object is
35
+ returned. If view is False and the environment is in a IPython session,
36
+ an IPython image object is returned and can be displayed inline in the
37
+ notebook.
38
+
39
+ This function requires the graphviz package.
40
+
41
+ Args
42
+ ----
43
+ - graph [str]: a DOT source code
44
+ - filename [str]: optional. if given and view is True, this specifies
45
+ the file path for the rendered output to write to.
46
+ - view [bool]: if True, opens the rendered output file.
47
+
48
+ """
49
+ # Optionally depends on graphviz package
50
+ import graphviz as gv
51
+
52
+ src = gv.Source(graph)
53
+ if view:
54
+ # Returns the output file path
55
+ return src.render(filename, view=view)
56
+ else:
57
+ # Attempts to show the graph in IPython notebook
58
+ try:
59
+ __IPYTHON__
60
+ except NameError:
61
+ return src
62
+ else:
63
+ import IPython.display as display
64
+ format = 'svg'
65
+ return display.SVG(data=src.pipe(format))
66
+
67
+
68
+ # Ctypes binding
69
+ ffi.lib.LLVMPY_WriteCFG.argtypes = [ffi.LLVMValueRef, POINTER(c_char_p), c_int]
@@ -0,0 +1,34 @@
1
+ import atexit
2
+
3
+
4
+ def _encode_string(s):
5
+ encoded = s.encode('utf-8')
6
+ return encoded
7
+
8
+
9
+ def _decode_string(b):
10
+ return b.decode('utf-8')
11
+
12
+
13
+ _encode_string.__doc__ = """Encode a string for use by LLVM."""
14
+ _decode_string.__doc__ = """Decode a LLVM character (byte)string."""
15
+
16
+
17
+ _shutting_down = [False]
18
+
19
+
20
+ def _at_shutdown():
21
+ _shutting_down[0] = True
22
+
23
+
24
+ atexit.register(_at_shutdown)
25
+
26
+
27
+ def _is_shutting_down(_shutting_down=_shutting_down):
28
+ """
29
+ Whether the interpreter is currently shutting down.
30
+ For use in finalizers, __del__ methods, and similar; it is advised
31
+ to early bind this function rather than look it up when calling it,
32
+ since at shutdown module globals may be cleared.
33
+ """
34
+ return _shutting_down[0]
@@ -0,0 +1,143 @@
1
+ import os
2
+ import warnings
3
+ from functools import cache
4
+ from ctypes import c_int, c_char_p
5
+ from llvmlite.binding import ffi
6
+
7
+ # these are here as they cannot be lazy bound as the module globals make calls
8
+ # to the LLVMPY API functions
9
+ ffi.lib.LLVMPY_HasSVMLSupport.argtypes = ()
10
+ ffi.lib.LLVMPY_HasSVMLSupport.restype = c_int
11
+
12
+ ffi.lib.LLVMPY_IsStaticLibstdcxxLinkageBuild.argtypes = ()
13
+ ffi.lib.LLVMPY_IsStaticLibstdcxxLinkageBuild.restype = c_int
14
+
15
+ ffi.lib.LLVMPY_IsDynamicLLVMLinkageBuild.argtypes = ()
16
+ ffi.lib.LLVMPY_IsDynamicLLVMLinkageBuild.restype = c_int
17
+
18
+ ffi.lib.LLVMPY_PackageFormat.argtypes = ()
19
+ ffi.lib.LLVMPY_PackageFormat.restype = c_char_p
20
+
21
+ ffi.lib.LLVMPY_LlvmAssertionsState.argtypes = ()
22
+ ffi.lib.LLVMPY_LlvmAssertionsState.restype = c_char_p
23
+
24
+
25
+ def _has_svml():
26
+ """
27
+ Returns True if SVML was enabled at FFI support compile time.
28
+ """
29
+ if ffi.lib.LLVMPY_HasSVMLSupport() == 0:
30
+ return False
31
+ else:
32
+ return True
33
+
34
+
35
+ has_svml = _has_svml()
36
+
37
+
38
+ def _build_llvm_linkage_type():
39
+ """
40
+ Returns "static" if the FFI support is statically linked against LLVM,
41
+ returns "dynamic" otherwise.
42
+ """
43
+ if ffi.lib.LLVMPY_IsDynamicLLVMLinkageBuild() == 0:
44
+ return "static"
45
+ else:
46
+ return "dynamic"
47
+
48
+
49
+ build_llvm_linkage_type = _build_llvm_linkage_type()
50
+
51
+
52
+ def _build_libstdcxx_linkage_type():
53
+ """
54
+ Returns "static" if the FFI support is statically linked against libstdc++,
55
+ returns "dynamic" otherwise.
56
+ """
57
+ if ffi.lib.LLVMPY_IsStaticLibstdcxxLinkageBuild() == 1:
58
+ return "static"
59
+ else:
60
+ return "dynamic"
61
+
62
+
63
+ build_libstdcxx_linkage_type = _build_libstdcxx_linkage_type()
64
+
65
+
66
+ def _package_format():
67
+ """
68
+ Returns "wheel", "conda" or "unspecified"
69
+ """
70
+ return ffi.lib.LLVMPY_PackageFormat().decode()
71
+
72
+
73
+ package_format = _package_format()
74
+
75
+
76
+ def _llvm_assertions_state():
77
+ """
78
+ Returns one of "on", "off" or "unknown". Depending on whether it is
79
+ determined that LLVM was build with assertions on, off, or is not known.
80
+ "Is not known" is typically from a dynamic linkage against LLVM in which
81
+ case it's not easily identified whether LLVM was built with assertions.
82
+ """
83
+ return ffi.lib.LLVMPY_LlvmAssertionsState().decode()
84
+
85
+
86
+ llvm_assertions_state = _llvm_assertions_state()
87
+
88
+
89
+ @cache
90
+ def get_sysinfo():
91
+ d = dict()
92
+ d["ffi_lib_location"] = ffi.lib._name
93
+ d["package_format"] = package_format
94
+ d["llvm_linkage_type"] = build_llvm_linkage_type
95
+ d["libstdcxx_linkage_type"] = build_libstdcxx_linkage_type
96
+ d["llvm_assertions_state"] = llvm_assertions_state
97
+
98
+ # import lief
99
+ HAVE_LIEF = False
100
+ try:
101
+ import lief
102
+ HAVE_LIEF = True
103
+ except ImportError:
104
+ msg = "py-lief package not found, sysinfo is limited as a result"
105
+ warnings.warn(msg)
106
+
107
+ d["lief_probe_status"] = HAVE_LIEF
108
+ d["linked_libraries"] = None
109
+ d["canonicalised_linked_libraries"] = None
110
+
111
+ def canonicalise_library_type(dso):
112
+ """Canonicalises the representation of the binary::libraries as a
113
+ sequence of strings"""
114
+ # Note lief v16:
115
+ # Mach-O .libraries are DylibCommand instances.
116
+ # Windows PE and Linux ELF .libraries are strings.
117
+ return [getattr(x, "name", x) for x in dso.libraries]
118
+
119
+ def canonicalise_library_spelling(libs):
120
+ # This adjusts the library "spelling" so that it just contains the
121
+ # name given to the linker. e.g. `@rpath/somewhere/libfoo.so.1.3`
122
+ # would be canonicalised to "foo".
123
+ fixes = []
124
+ for lib in libs:
125
+ # some libraries, e.g. Mach-O have an @rpath or system path
126
+ # prefix in their name, remove it.
127
+ path_stripped = os.path.split(lib)[-1]
128
+ # Assume all library names contain at least one dot, even if they
129
+ # don't it's fine, the first part is the piece of interest.
130
+ prefix_libname = path_stripped.split(".")[0]
131
+ linker_name = prefix_libname.replace("lib", "").replace("LIB", "")
132
+ # further canonicalize by referring to all libraries in lower case.
133
+ fixes.append(linker_name.lower())
134
+ return fixes
135
+
136
+ if HAVE_LIEF:
137
+ dso = lief.parse(d["ffi_lib_location"])
138
+ link_libs = tuple(canonicalise_library_type(dso))
139
+ d["linked_libraries"] = link_libs
140
+ canonicalised_libs = canonicalise_library_spelling(link_libs)
141
+ d["canonicalised_linked_libraries"] = canonicalised_libs
142
+
143
+ return d
@@ -0,0 +1,31 @@
1
+ from llvmlite.binding import ffi
2
+
3
+
4
+ def create_context():
5
+ return ContextRef(
6
+ ffi.lib.LLVMPY_ContextCreate())
7
+
8
+
9
+ def get_global_context():
10
+ return GlobalContextRef(
11
+ ffi.lib.LLVMPY_GetGlobalContext())
12
+
13
+
14
+ class ContextRef(ffi.ObjectRef):
15
+ def __init__(self, context_ptr):
16
+ super(ContextRef, self).__init__(context_ptr)
17
+
18
+ def _dispose(self):
19
+ ffi.lib.LLVMPY_ContextDispose(self)
20
+
21
+
22
+ class GlobalContextRef(ContextRef):
23
+ def _dispose(self):
24
+ pass
25
+
26
+
27
+ ffi.lib.LLVMPY_GetGlobalContext.restype = ffi.LLVMContextRef
28
+
29
+ ffi.lib.LLVMPY_ContextCreate.restype = ffi.LLVMContextRef
30
+
31
+ ffi.lib.LLVMPY_ContextDispose.argtypes = [ffi.LLVMContextRef]
@@ -0,0 +1,45 @@
1
+ from ctypes import c_void_p, c_char_p, c_bool, POINTER
2
+
3
+ from llvmlite.binding import ffi
4
+ from llvmlite.binding.common import _encode_string
5
+
6
+
7
+ def address_of_symbol(name):
8
+ """
9
+ Get the in-process address of symbol named *name*.
10
+ An integer is returned, or None if the symbol isn't found.
11
+ """
12
+ return ffi.lib.LLVMPY_SearchAddressOfSymbol(_encode_string(name))
13
+
14
+
15
+ def add_symbol(name, address):
16
+ """
17
+ Register the *address* of global symbol *name*. This will make
18
+ it usable (e.g. callable) from LLVM-compiled functions.
19
+ """
20
+ ffi.lib.LLVMPY_AddSymbol(_encode_string(name), c_void_p(address))
21
+
22
+
23
+ def load_library_permanently(filename):
24
+ """
25
+ Load an external library
26
+ """
27
+ with ffi.OutputString() as outerr:
28
+ if ffi.lib.LLVMPY_LoadLibraryPermanently(
29
+ _encode_string(filename), outerr):
30
+ raise RuntimeError(str(outerr))
31
+
32
+ # ============================================================================
33
+ # FFI
34
+
35
+
36
+ ffi.lib.LLVMPY_AddSymbol.argtypes = [
37
+ c_char_p,
38
+ c_void_p,
39
+ ]
40
+
41
+ ffi.lib.LLVMPY_SearchAddressOfSymbol.argtypes = [c_char_p]
42
+ ffi.lib.LLVMPY_SearchAddressOfSymbol.restype = c_void_p
43
+
44
+ ffi.lib.LLVMPY_LoadLibraryPermanently.argtypes = [c_char_p, POINTER(c_char_p)]
45
+ ffi.lib.LLVMPY_LoadLibraryPermanently.restype = c_bool