@@ -50,6 +50,9 @@ public struct IntType: IRType {
5050 /// - parameter value: A Swift integer value.
5151 /// - parameter signExtend: Whether to sign-extend this value to fit this
5252 /// 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.
5356 public func constant< IntTy: UnsignedInteger > ( _ value: IntTy , signExtend: Bool = false ) -> Constant < Unsigned > {
5457 return Constant ( llvm: LLVMConstInt ( asLLVM ( ) ,
5558 UInt64 ( value) ,
@@ -61,12 +64,28 @@ public struct IntType: IRType {
6164 /// - parameter value: A Swift integer value.
6265 /// - parameter signExtend: Whether to sign-extend this value to fit this
6366 /// 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.
6470 public func constant< IntTy: SignedInteger > ( _ value: IntTy , signExtend: Bool = false ) -> Constant < Signed > {
6571 return Constant ( llvm: LLVMConstInt ( asLLVM ( ) ,
6672 UInt64 ( bitPattern: Int64 ( value) ) ,
6773 signExtend. llvm) )
6874 }
6975
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+ }
7089
7190 /// Retrieves an integer value of this type's bit width consisting of all
7291 /// one-bits.
0 commit comments