TargetMachine

public class TargetMachine

A TargetMachine object represents an object that encapsulates information about a particular machine (i.e. CPU type) associated with a target environment.

  • The target information associated with this target machine.

    Declaration

    Swift

    public let target: Target
  • The data layout semantics associated with this target machine.

    Declaration

    Swift

    public let dataLayout: TargetData
  • The target triple for this target machine.

    Declaration

    Swift

    public let triple: Triple
  • cpu

    The CPU associated with this target machine.

    Declaration

    Swift

    public var cpu: String { get }
  • The feature string associated with this target machine.

    Declaration

    Swift

    public var features: String { get }
  • Creates a Target Machine with information about its target environment.

    Declaration

    Swift

    public init(triple: Triple = .default, cpu: String = "", features: String = "",
                optLevel: CodeGenOptLevel = .default, relocations: RelocationModel = .default,
                codeModel: CodeModel = .default) throws

    Parameters

    triple

    An optional target triple to target. If this is not provided the target triple of the host machine will be assumed.

    cpu

    An optional CPU type to target. If this is not provided the host CPU will be inferred.

    features

    An optional string containing the features a particular target provides.

    optLevel

    The optimization level for generated code. If no value is provided, the default level of optimization is assumed.

    relocations

    The relocation model of the target environment. If no mode is provided, the default model for the target architecture is assumed.

    codeModel

    The kind of code to produce for this target. If no model is provided, the default model for the target architecture is assumed.

  • Emits an LLVM Bitcode, ASM, or object file for the given module to the provided filename.

    Failure during any part of the compilation process or the process of writing the results to disk will result in a TargetMachineError being thrown describing the error in detail.

    Declaration

    Swift

    public func emitToFile(module: Module, type: CodegenFileType, path: String) throws

    Parameters

    module

    The module whose contents will be codegened.

    type

    The type of codegen to perform on the given module.

    path

    The path to write the resulting file.

  • Emits an LLVM Bitcode, ASM, or object file for the given module to a new MemoryBuffer containing the contents.

    Failure during any part of the compilation process or the process of writing the results to disk will result in a TargetMachineError being thrown describing the error in detail.

    Declaration

    Swift

    public func emitToMemoryBuffer(module: Module, type: CodegenFileType) throws -> MemoryBuffer

    Parameters

    module

    The module whose contents will be codegened.

    type

    The type of codegen to perform on the given module.