StructType

public struct StructType : IRType
extension StructType: Equatable

StructType is used to represent a collection of data members together in memory. The elements of a structure may be any type that has a size.

Structures in memory are accessed using load and store by getting a pointer to a field with the ‘getelementptr‘ instruction. Structures in registers are accessed using the extractvalue and insertvalue instructions.

Structures may optionally be “packed” structures, which indicate that the alignment of the struct is one byte, and that there is no padding between the elements. In non-packed structs, padding between field types is inserted as defined by the DataLayout of the module, which is required to match what the underlying code generator expects.

Structures can either be “literal” or “identified”. A literal structure is defined inline with other types (e.g. {i32, i32}*) whereas identified types are always defined at the top level with a name. Literal types are uniqued by their contents and can never be recursive or opaque since there is no way to write one. Identified types can be recursive, can be opaqued, and are never uniqued.

  • Initializes a structure type from the given LLVM type object.

    Declaration

    Swift

    public init(llvm: LLVMTypeRef)
  • Creates a structure type from an array of component element types.

    Declaration

    Swift

    public init(elementTypes: [IRType], isPacked: Bool = false, in context: Context = Context.global)

    Parameters

    elementTypes

    A list of types of members of this structure.

    isPacked

    Whether or not this structure is 1-byte aligned with no packing between fields. Defaults to false.

    context

    The context to create this type in

  • Invalidates and resets the member types of this structure.

    Declaration

    Swift

    public func setBody(_ types: [IRType], isPacked: Bool = false)

    Parameters

    types

    A list of types of members of this structure.

    isPacked

    Whether or not this structure is 1-byte aligned with no packing between fields. Defaults to false.

  • Creates a constant value of this structure type initialized with the given list of values.

    Precondition

    values.count == aggregate.elementCount

    Declaration

    Swift

    public func constant(values: [IRValue]) -> Constant<Struct>

    Parameters

    values

    A list of values of members of this structure.

    Return Value

    A value representing a constant value of this structure type.

  • Creates an constant struct value initialized with the given list of values.

    Declaration

    Swift

    public static func constant(values: [IRValue], isPacked: Bool = false) -> Constant<Struct>

    Parameters

    values

    A list of values of members of this structure.

    isPacked

    Whether or not this structure is 1-byte aligned with no packing between fields. Defaults to false.

    Return Value

    A value representing a constant struct value with given the values.

  • Retrieves the name associated with this structure type, or the empty string if this type is unnamed.

    Declaration

    Swift

    public var name: String { get }
  • Retrieves the element types associated with this structure type.

    Declaration

    Swift

    public var elementTypes: [IRType] { get }
  • Retrieves the underlying LLVM type object.

    Declaration

    Swift

    public func asLLVM() -> LLVMTypeRef
  • Return true if this is a struct type with an identity that has an unspecified body.

    Opaque struct types print as opaque in serialized .ll files.

    Declaration

    Swift

    public var isOpaque: Bool { get }
  • Returns true if this is a packed struct type.

    A packed struct type includes no padding between fields and is thus laid out in one contiguous region of memory with its elements laid out one after the other. A non-packed struct type includes padding according to the data layout of the target.

    Declaration

    Swift

    public var isPacked: Bool { get }
  • Returns true if this is a literal struct type.

    A literal struct type is uniqued by structural equivalence - that is, regardless of how it is named, two literal structures are equal if their fields are equal.

    Declaration

    Swift

    public var isLiteral: Bool { get }
  • Declaration

    Swift

    public static func == (lhs: StructType, rhs: StructType) -> Bool