Module

public final class Module: CustomStringConvertible

A Module represents the top-level structure of an LLVM program. An LLVM module is effectively a translation unit or a collection of translation units merged together.

  • Creates a Module with the given name.

    Declaration

    Swift

    public init(name: String, context: Context? = nil)

    Parameters

    name

    The name of the module.

    context

    The context to associate this module with. If no context is provided, one will be inferred.

  • Returns the context associated with this module.

    Declaration

    Swift

    public let context: Context
  • Obtain the data layout for this module.

    Declaration

    Swift

    public var dataLayout: TargetData
  • The identifier of this module.

    Declaration

    Swift

    public var name: String
  • Print a representation of a module to a file at the given path.

    If the provided path is not suitable for writing, this function will throw ModuleError.couldNotPrint.

    Declaration

    Swift

    public func print(to path: String) throws

    Parameters

    path

    The path to write the module’s representation to.

  • Writes the bitcode of elements in this module to a file at the given path.

    If the provided path is not suitable for writing, this function will throw ModuleError.couldNotEmitBitCode.

    Declaration

    Swift

    public func emitBitCode(to path: String) throws

    Parameters

    path

    The path to write the module’s representation to.

  • Verifies that this module is valid, taking the specified action if not. If this module did not pass verification, a description of any invalid constructs is provided with the thrown ModuleError.didNotPassVerification error.

    Declaration

    Swift

    public func verify() throws
  • Retrieves the sequence of functions that make up this module.

    Declaration

    Swift

    public var functions: AnySequence<Function>
  • Retrieves the first function in this module, if there are any functions.

    Declaration

    Swift

    public var firstFunction: Function?
  • Retrieves the last function in this module, if there are any functions.

    Declaration

    Swift

    public var lastFunction: Function?
  • Retrieves the first global in this module, if there are any globals.

    Declaration

    Swift

    public var firstGlobal: Global?
  • Retrieves the last global in this module, if there are any globals.

    Declaration

    Swift

    public var lastGlobal: Global?
  • Retrieves the sequence of functions that make up this module.

    Declaration

    Swift

    public var globals: AnySequence<Global>
  • Dump a representation of this module to stderr.

    Declaration

    Swift

    public func dump()
  • The full text IR of this module

    Declaration

    Swift

    public var description: String
  • Searches for and retrieves a global variable with the given name in this module if that name references an existing global variable.

    Declaration

    Swift

    public func global(named name: String) -> Global?

    Parameters

    name

    The name of the global to reference.

    Return Value

    A value representing the referenced global if it exists.

  • Searches for and retrieves a type with the given name in this module if that name references an existing type.

    Declaration

    Swift

    public func type(named name: String) -> IRType?

    Parameters

    name

    The name of the type to create.

    Return Value

    A representation of the newly created type with the given name or nil if such a representation could not be created.

  • Searches for and retrieves a function with the given name in this module if that name references an existing function.

    Declaration

    Swift

    public func function(named name: String) -> Function?

    Parameters

    name

    The name of the function to create.

    Return Value

    A representation of the newly created function with the given name or nil if such a representation could not be created.