@@ -4,19 +4,51 @@ import cllvm
44
55/// `FloatType` enumerates representations of a floating value of a particular
66/// bit width and semantics.
7- public enum FloatType : IRType {
8- /// 16-bit floating point value
9- case half
10- /// 32-bit floating point value
11- case float
12- /// 64-bit floating point value
13- case double
14- /// 80-bit floating point value (X87)
15- case x86FP80
16- /// 128-bit floating point value (112-bit mantissa)
17- case fp128
18- /// 128-bit floating point value (two 64-bits)
19- case ppcFP128
7+ public struct FloatType : IRType {
8+
9+ /// The kind of floating point type this is
10+ public var kind : Kind
11+
12+ /// Returns the context associated with this type.
13+ public let context : Context
14+
15+ /// Creates a float type of a particular kind
16+ ///
17+ /// - parameter kind: The kind of floating point type to create
18+ /// - parameter context: The context to create this type in
19+ /// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
20+ public init ( kind: Kind , in context: Context = Context . global) {
21+ self . kind = kind
22+ self . context = context
23+ }
24+
25+ public enum Kind {
26+ /// 16-bit floating point value
27+ case half
28+ /// 32-bit floating point value
29+ case float
30+ /// 64-bit floating point value
31+ case double
32+ /// 80-bit floating point value (X87)
33+ case x86FP80
34+ /// 128-bit floating point value (112-bit mantissa)
35+ case fp128
36+ /// 128-bit floating point value (two 64-bits)
37+ case ppcFP128
38+ }
39+
40+ /// 16-bit floating point value in the global context
41+ public static let half = FloatType ( kind: . half)
42+ /// 32-bit floating point value in the global context
43+ public static let float = FloatType ( kind: . float)
44+ /// 64-bit floating point value in the global context
45+ public static let double = FloatType ( kind: . double)
46+ /// 80-bit floating point value (X87) in the global context
47+ public static let x86FP80 = FloatType ( kind: . x86FP80)
48+ /// 128-bit floating point value (112-bit mantissa) in the global context
49+ public static let fp128 = FloatType ( kind: . fp128)
50+ /// 128-bit floating point value (two 64-bits) in the global context
51+ public static let ppcFP128 = FloatType ( kind: . ppcFP128)
2052
2153 /// Creates a constant floating value of this type from a Swift `Double` value.
2254 public func constant( _ value: Double ) -> Constant < Floating > {
@@ -25,13 +57,13 @@ public enum FloatType: IRType {
2557
2658 /// Retrieves the underlying LLVM type object.
2759 public func asLLVM( ) -> LLVMTypeRef {
28- switch self {
29- case . half: return LLVMHalfType ( )
30- case . float: return LLVMFloatType ( )
31- case . double: return LLVMDoubleType ( )
32- case . x86FP80: return LLVMX86FP80Type ( )
33- case . fp128: return LLVMFP128Type ( )
34- case . ppcFP128: return LLVMPPCFP128Type ( )
60+ switch kind {
61+ case . half: return LLVMHalfTypeInContext ( context . llvm )
62+ case . float: return LLVMFloatTypeInContext ( context . llvm )
63+ case . double: return LLVMDoubleTypeInContext ( context . llvm )
64+ case . x86FP80: return LLVMX86FP80TypeInContext ( context . llvm )
65+ case . fp128: return LLVMFP128TypeInContext ( context . llvm )
66+ case . ppcFP128: return LLVMPPCFP128TypeInContext ( context . llvm )
3567 }
3668 }
3769}
0 commit comments