layout: page |
title: Module (llvm.core) |
Modules are top-level container objects. You need to create a module object first, before you can add global variables, aliases or functions. Modules are created using the static method Module.new:
#!/usr/bin/env python
from llvm import *
from llvm.core import *
# create a module
my_module = Module.new('my_module')
A Module instance stores all the information related to an LLVM module.
Modules are the top level container of all other LLVM Intermediate Representation (IR) objects. Each module directly contains a list of globals variables, a list of functions, a list of libraries (or other modules) this module depends on, a symbol table, and various data about the target’s characteristics.
Construct a Module only using the static methods defined below, NOT using the constructor. A correct usage is:
module_obj = Module.new(‘my_module’)
Add a function of given type with given name.
Add a global variable of given type with given name.
The data layout string for the module’s target platform.
The data layout strings is an encoded representation of the type sizes and alignments expected by this module.
Create a Module instance from the contents of an LLVM assembly (.ll) file.
fileobj_or_str – takes a file-like object or string that contains a module represented in llvm-ir assembly.
Create a Module instance from the contents of a bitcode file.
fileobj_or_str – takes a file-like object or string that contains a module represented in bitcode.
All functions in this module.
Return a Function object representing function with given name.
Return a GlobalVariable object for the given name.
Like get_function_named(), but does add_function() first, if function is not present.
Link the `other’ module into this one.
The `other’ module is linked into this one such that types, global variables, function, etc. are matched and resolved.
The `other’ module is no longer valid after this method is invoked, all refs to it should be dropped.
In the future, this API might be replaced with a full-fledged Linker class.
The target triple string describing the target host.
Write bitcode representation of module to given file-like object.
fileobj – A file-like object to where the bitcode is written. If it is None, the bitcode is returned.
Return value – Returns None if fileobj is not None. Otherwise, return the bitcode as a bytestring.
Outputs the byte string of the module as native assembly code
If a fileobj is given, the output is written to it; Otherwise, the output is returned
Outputs the byte string of the module as native object code
If a fileobj is given, the output is written to it; Otherwise, the output is returned