@@ -50,6 +50,9 @@ public struct IntType: IRType {
50
50
/// - parameter value: A Swift integer value.
51
51
/// - parameter signExtend: Whether to sign-extend this value to fit this
52
52
/// type's bit width. Defaults to `false`.
53
+ ///
54
+ /// - returns: A value representing an unsigned integer constant initialized
55
+ /// with the given Swift integer value.
53
56
public func constant< IntTy: UnsignedInteger > ( _ value: IntTy , signExtend: Bool = false ) -> Constant < Unsigned > {
54
57
return Constant ( llvm: LLVMConstInt ( asLLVM ( ) ,
55
58
UInt64 ( value) ,
@@ -61,12 +64,28 @@ public struct IntType: IRType {
61
64
/// - parameter value: A Swift integer value.
62
65
/// - parameter signExtend: Whether to sign-extend this value to fit this
63
66
/// type's bit width. Defaults to `false`.
67
+ ///
68
+ /// - returns: A value representing a signed integer constant initialized with
69
+ /// the given Swift integer value.
64
70
public func constant< IntTy: SignedInteger > ( _ value: IntTy , signExtend: Bool = false ) -> Constant < Signed > {
65
71
return Constant ( llvm: LLVMConstInt ( asLLVM ( ) ,
66
72
UInt64 ( bitPattern: Int64 ( value) ) ,
67
73
signExtend. llvm) )
68
74
}
69
75
76
+ /// Creates a constant integer value of this type parsed from a string.
77
+ ///
78
+ /// - parameter value: A string value containing an integer.
79
+ /// - parameter radix: The radix, or base, to use for converting text to an
80
+ /// integer value. Defaults to 10.
81
+ ///
82
+ /// - returns: A value representing a constant initialized with the result of
83
+ /// parsing the string as a signed integer.
84
+ public func constant( _ value: String , radix: Int = 10 ) -> Constant < Signed > {
85
+ return value. withCString { cString in
86
+ return Constant ( llvm: LLVMConstIntOfStringAndSize ( asLLVM ( ) , cString, UInt32 ( value. count) , UInt8 ( radix) ) )
87
+ }
88
+ }
70
89
71
90
/// Retrieves an integer value of this type's bit width consisting of all
72
91
/// one-bits.
0 commit comments