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 { get set }
-
Returns a string describing the data layout associated with this module.
Declaration
Swift
public var dataLayoutString: String { get set }
-
The identifier of this module.
Declaration
Swift
public var name: String { get set }
-
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
-
Links the given module with this module. If the link succeeds, this module will the composite of the two input modules.
The result of this function is
true
if the link succeeds, orfalse
otherwise - unlikellvm::Linker::linkModules
.Declaration
Swift
public func link(_ other: Module) -> Bool
Parameters
other
The module to link with this module.
-
Retrieves the sequence of functions that make up this module.
Declaration
Swift
public var functions: AnySequence<Function> { get }
-
Retrieves the first function in this module, if there are any functions.
Declaration
Swift
public var firstFunction: Function? { get }
-
Retrieves the last function in this module, if there are any functions.
Declaration
Swift
public var lastFunction: Function? { get }
-
Retrieves the first global in this module, if there are any globals.
Declaration
Swift
public var firstGlobal: Global? { get }
-
Retrieves the last global in this module, if there are any globals.
Declaration
Swift
public var lastGlobal: Global? { get }
-
Retrieves the sequence of functions that make up this module.
Declaration
Swift
public var globals: AnySequence<Global> { get }
-
The current debug metadata version number.
Declaration
Swift
public static var debugMetadataVersion: UInt32 { get }
-
The version of debug metadata that’s present in this module.
Declaration
Swift
public var debugMetadataVersion: UInt32 { get }
-
Strip debug info in the module if it exists.
To do this, we remove all calls to the debugger intrinsics and any named metadata for debugging. We also remove debug locations for instructions. Return true if module is modified.
Declaration
Swift
public func stripDebugInfo() -> Bool
-
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 { get }
-
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.
-
Searches for and retrieves a comdat section with the given name in this module. If none is found, one with that name is created and returned.
Declaration
Swift
public func comdat(named name: String) -> Comdat
Parameters
name
The name of the comdat section to create.
Return Value
A representation of the newly created comdat section with the given name.
-
Searches for and retrieves module-level named metadata with the given name in this module. If none is found, one with that name is created and returned.
Declaration
Swift
public func metadata(named name: String) -> NamedMetadata
Parameters
name
The name of the comdat section to create.
Return Value
A representation of the newly created metadata with the given name.
-
Build a named global of the given type.
Declaration
Parameters
name
The name of the newly inserted global value.
type
The type of the newly inserted global value.
addressSpace
The optional address space where the global variable resides.
Return Value
A value representing the newly inserted global variable.
-
Build a named global of the given type.
Declaration
Parameters
name
The name of the newly inserted global value.
initializer
The initial value for the global variable.
addressSpace
The optional address space where the global variable resides.
Return Value
A value representing the newly inserted global variable.
-
Build a named global string consisting of an array of
i8
type filled in with the nul terminated string value.Declaration
Swift
public func addGlobalString(name: String, value: String) -> Global
Parameters
name
The name of the newly inserted global string value.
value
The character contents of the newly inserted global.
Return Value
A value representing the newly inserted global string variable.
-
Build a named alias to a global value or a constant expression.
Aliases, unlike function or variables, don’t create any new data. They are just a new symbol and metadata for an existing position.
Parameters
name
The name of the newly inserted alias.
aliasee
The value or constant to alias.
type
The type of the aliased value or expression.
Return Value
A value representing the newly created alias.