File: modules.rst

package info (click to toggle)
llvmlite 0.44.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,736 kB
  • sloc: python: 12,771; cpp: 3,146; sh: 185; makefile: 183
file content (137 lines) | stat: -rw-r--r-- 3,903 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
=======
Modules
=======

.. currentmodule:: llvmlite.binding

Although they conceptually represent the same thing, modules in
the :ref:`IR layer <ir-layer>` and modules in the
:ref:`binding layer <binding-layer>` do not have the same roles
and do not expose the same API.

While modules in the IR layer allow you to build and group
functions together, modules in the binding layer give access to
compilation, linking and execution of code. To distinguish
between them, the module class in the binding layer is
called :class:`ModuleRef` as opposed to
:class:`llvmlite.ir.Module`.

To go from the IR layer to the binding layer, use
the :func:`parse_assembly` function.

Factory functions
=================

You can create a module from the following factory functions:

* .. function:: parse_assembly(llvmir, context=None)

     Parse the given *llvmir*, a string containing some LLVM IR
     code. If parsing is successful, a new :class:`ModuleRef`
     instance is returned.

     * context: an instance of :class:`LLVMContextRef`.

        Defaults to the global context.

     EXAMPLE: You can obtain *llvmir* by calling ``str()`` on an
     :class:`llvmlite.ir.Module` object.

* .. function:: parse_bitcode(bitcode, context=None)

     Parse the given *bitcode*, a bytestring containing the
     LLVM bitcode of a module. If parsing is successful, a new
     :class:`ModuleRef` instance is returned.

     * context: an instance of :class:`LLVMContextRef`.

        Defaults to the global context.

     EXAMPLE: You can obtain the *bitcode* by calling
     :meth:`ModuleRef.as_bitcode`.


The ModuleRef class
===================

.. class:: ModuleRef

   A wrapper around an LLVM module object. The following methods
   and properties are available:

   * .. method:: as_bitcode()

        Return the bitcode of this module as a bytes object.

   * .. method:: get_function(name)

        Get the function with the given *name* in this module.

        If found, a :class:`ValueRef` is returned. Otherwise,
        :exc:`NameError` is raised.

   * .. method:: get_global_variable(name)

        Get the global variable with the given *name* in this
        module.

        If found, a :class:`ValueRef` is returned. Otherwise,
        :exc:`NameError` is raised.

    * .. method:: get_struct_type(name)

        Get the struct type with the given *name* in this module.

        If found, a :class:`TypeRef` is returned. Otherwise,
        :exc:`NameError` is raised.

   * .. method:: link_in(other, preserve=False)

        Link the *other* module into this module, resolving
        references wherever possible.

        * If *preserve* is ``True``, the other module is first
          copied in order to preserve its contents.
        * If *preserve* is ``False``, the other module is not
          usable after this call.

   * .. method:: verify()

        Verify the module's correctness. On error, raise
        :exc:`RuntimeError`.

   * .. attribute:: data_layout

        The data layout string for this module. This attribute
        can be set.

   * .. attribute:: functions

        An iterator over the functions defined in this module.
        Each function is a :class:`ValueRef` instance.

   * .. attribute:: global_variables

        An iterator over the global variables defined in this
        module. Each global variable is a :class:`ValueRef`
        instance.

   * .. attribute:: struct_types

        An iterator over the struct types defined in this module.
        Each type is a :class:`TypeRef` instance.

   * .. attribute:: name

        The module's identifier, as a string. This attribute can
        be set.

   * .. attribute:: source_file

        The module's reported source file, as a string. This
        attribute can not be set.
	
   * .. attribute:: triple

        The platform "triple" string for this module. This
        attribute can be set.