layout: page
title: Module (llvm.core)

llvm.core.Module

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')

Automatically Generated Documentation

class llvm.core.Module(ptr)

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_function(ty, name)

Add a function of given type with given name.

add_global_variable(ty, name, addrspace=0)

Add a global variable of given type with given name.

clone()
data_layout

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.

static from_assembly(fileobj_or_str)

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.

static from_bitcode(fileobj_or_str)

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.

functions

All functions in this module.

get_function_named(name)

Return a Function object representing function with given name.

get_global_variable_named(name)

Return a GlobalVariable object for the given name.

get_named_metadata(name)
get_or_insert_function(ty, name)

Like get_function_named(), but does add_function() first, if function is not present.

get_or_insert_named_metadata(name)
get_type_named(name)
global_variables
id

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.

static new(id)

Create a new Module instance.

Creates an instance of Module, having the id `id’.

pointer_size
target

The target triple string describing the target host.

to_bitcode(fileobj=None)

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.

to_native_assembly(fileobj=None)

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

to_native_object(fileobj=None)

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

verify()

Verify module.

Checks module for errors. Raises `llvm.LLVMException’ on any error.

Table Of Contents

Previous topic

llvm.core.IntegerType

Next topic

llvm.core.PointerType