Modules
Although they conceptually represent the same thing, modules in the IR layer and modules in the 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 ModuleRef
as opposed to
llvmlite.ir.Module
.
To go from the IR layer to the binding layer, use
the parse_assembly()
function.
Factory functions
You can create a module from the following factory functions:
- llvmlite.binding.parse_assembly(llvmir, context=None)
Parse the given llvmir, a string containing some LLVM IR code. If parsing is successful, a new
ModuleRef
instance is returned.context: an instance of
LLVMContextRef
.Defaults to the global context.
EXAMPLE: You can obtain llvmir by calling
str()
on anllvmlite.ir.Module
object.
- llvmlite.binding.parse_bitcode(bitcode, context=None)
Parse the given bitcode, a bytestring containing the LLVM bitcode of a module. If parsing is successful, a new
ModuleRef
instance is returned.context: an instance of
LLVMContextRef
.Defaults to the global context.
EXAMPLE: You can obtain the bitcode by calling
ModuleRef.as_bitcode()
.
The ModuleRef class
- class llvmlite.binding.ModuleRef
A wrapper around an LLVM module object. The following methods and properties are available:
- as_bitcode()
Return the bitcode of this module as a bytes object.
- 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.
- verify()
Verify the module’s correctness. On error, raise
RuntimeError
.
- data_layout
The data layout string for this module. This attribute can be set.
- name
The module’s identifier, as a string. This attribute can be set.
- source_file
The module’s reported source file, as a string. This attribute can not be set.
- triple
The platform “triple” string for this module. This attribute can be set.