Skip to content

Commit 7fc4caf

Browse files
authored
Add ConstString initializer to ArrayType (#105)
Add ConstString initializer to ArrayType
1 parent c1d5ca6 commit 7fc4caf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sources/LLVM/ArrayType.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ public struct ArrayType: IRType {
3131
}
3232
}
3333

34+
/// Creates a constant, null terminated array value of UTF-8 bytes from
35+
/// string's `utf8` member.
36+
///
37+
/// - parameter string: A string to create a null terminated array from.
38+
/// - parameter context: The context to create the string in.
39+
///
40+
/// - returns: A null terminated constant array value containing
41+
/// `string.utf8.count + 1` i8's.
42+
public static func constant(string: String, in context: Context = .global) -> IRValue {
43+
let length = string.utf8.count
44+
return LLVMConstStringInContext(context.llvm, string, UInt32(length), 0)
45+
}
46+
3447
/// Retrieves the underlying LLVM type object.
3548
public func asLLVM() -> LLVMTypeRef {
3649
return LLVMArrayType(elementType.asLLVM(), UInt32(count))

0 commit comments

Comments
 (0)