Skip to content

Commit 3ae7553

Browse files
committed
Wrap LLVMConstNamedStruct
Allows emission of things like: ``` %Direction = type <{ i2 }> @Direction.north = global %Direction zeroinitializer @Direction.east = global %Direction <{ i2 1 }> @Direction.south = global %Direction <{ i2 -2 }> @Direction.west = global %Direction <{ i2 -1 }> ```
1 parent 5705c30 commit 3ae7553

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/LLVM/StructType.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,22 @@ public struct StructType: IRType {
5858
/// list of values.
5959
///
6060
/// - parameter values: A list of values of members of this structure.
61+
///
62+
/// - returns: A value representing a constant value of this structure type.
63+
public func constant(values: [IRValue]) -> IRValue {
64+
var vals = values.map { $0.asLLVM() as Optional }
65+
return vals.withUnsafeMutableBufferPointer { buf in
66+
return LLVMConstNamedStruct(asLLVM(), buf.baseAddress, UInt32(buf.count))
67+
}
68+
}
69+
70+
/// Creates a complex constant value initialized with the given list of values.
71+
///
72+
/// - parameter values: A list of values of members of this structure.
6173
/// - parameter isPacked: Whether or not this structure is 1-byte aligned with
6274
/// no packing between fields. Defaults to `false`.
6375
///
64-
/// - returns: A value representing a constant value of this structure type.
76+
/// - returns: A value representing a complex constant value with given the values.
6577
public static func constant(values: [IRValue], isPacked: Bool = false) -> IRValue {
6678
var vals = values.map { $0.asLLVM() as Optional }
6779
return vals.withUnsafeMutableBufferPointer { buf in

0 commit comments

Comments
 (0)