Skip to content

Commit d88b6ad

Browse files
committed
All types have a context therefore context should be non optional
1 parent eadb5be commit d88b6ad

File tree

6 files changed

+22
-44
lines changed

6 files changed

+22
-44
lines changed

Sources/LLVM/FloatType.swift

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public struct FloatType: IRType {
1010
public var kind: Kind
1111

1212
/// Returns the context associated with this module.
13-
public let context: Context?
13+
public let context: Context
1414

1515
/// Creates a float type of a particular kind
1616
///
1717
/// - parameter kind: The kind of floating point type to create
1818
/// - parameter context: The context to create this type in
1919
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
20-
public init(kind: Kind, in context: Context? = nil) {
20+
public init(kind: Kind, in context: Context = Context.global) {
2121
self.kind = kind
2222
self.context = context
2323
}
@@ -57,23 +57,13 @@ public struct FloatType: IRType {
5757

5858
/// Retrieves the underlying LLVM type object.
5959
public func asLLVM() -> LLVMTypeRef {
60-
if let context = context {
61-
switch kind {
62-
case .half: return LLVMHalfTypeInContext(context.llvm)
63-
case .float: return LLVMFloatTypeInContext(context.llvm)
64-
case .double: return LLVMDoubleTypeInContext(context.llvm)
65-
case .x86FP80: return LLVMX86FP80TypeInContext(context.llvm)
66-
case .fp128: return LLVMFP128TypeInContext(context.llvm)
67-
case .ppcFP128: return LLVMPPCFP128TypeInContext(context.llvm)
68-
}
69-
}
7060
switch kind {
71-
case .half: return LLVMHalfType()
72-
case .float: return LLVMFloatType()
73-
case .double: return LLVMDoubleType()
74-
case .x86FP80: return LLVMX86FP80Type()
75-
case .fp128: return LLVMFP128Type()
76-
case .ppcFP128: return LLVMPPCFP128Type()
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)
7767
}
7868
}
7969
}

Sources/LLVM/IRType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public extension IRType {
3131
}
3232

3333
/// Returns the context associated with this type
34-
public func context() -> Context {
34+
public var context: Context {
3535
return Context(llvm: LLVMGetTypeContext(asLLVM()))
3636
}
3737

Sources/LLVM/IntType.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public struct IntType: IRType {
1212
public let width: Int
1313

1414
/// Returns the context associated with this module.
15-
public let context: Context?
15+
public let context: Context
1616

1717
/// Creates an integer type with the specified bit width.
1818
///
1919
/// - parameter width: The width in bits of the integer type
2020
/// - parameter context: The context to create this type in
2121
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
22-
public init(width: Int, in context: Context? = nil) {
22+
public init(width: Int, in context: Context = Context.global) {
2323
self.width = width
2424
self.context = context
2525
}
@@ -78,9 +78,6 @@ public struct IntType: IRType {
7878

7979
/// Retrieves the underlying LLVM type object.
8080
public func asLLVM() -> LLVMTypeRef {
81-
if let context = context {
82-
return LLVMIntTypeInContext(context.llvm, UInt32(width))
83-
}
84-
return LLVMIntType(UInt32(width))
81+
return LLVMIntTypeInContext(context.llvm, UInt32(width))
8582
}
8683
}

Sources/LLVM/LabelType.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,18 @@ import cllvm
66
public struct LabelType: IRType {
77

88
/// Returns the context associated with this module.
9-
public let context: Context?
9+
public let context: Context
1010

1111
/// Creates a code label.
1212
///
1313
/// - parameter context: The context to create this type in
1414
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
15-
public init(in context: Context? = nil) {
15+
public init(in context: Context = Context.global) {
1616
self.context = context
1717
}
1818

1919
/// Retrieves the underlying LLVM type object.
2020
public func asLLVM() -> LLVMTypeRef {
21-
if let context = context {
22-
return LLVMLabelTypeInContext(context.llvm)
23-
}
24-
return LLVMLabelType()
21+
return LLVMLabelTypeInContext(context.llvm)
2522
}
2623
}

Sources/LLVM/VoidType.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,18 @@ import cllvm
66
public struct VoidType: IRType {
77

88
/// Returns the context associated with this module.
9-
public let context: Context?
9+
public let context: Context
1010

1111
/// Creates an instance of the `Void` type.
1212
///
1313
/// - parameter context: The context to create this type in
1414
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
15-
public init(in context: Context? = nil) {
15+
public init(in context: Context = Context.global) {
1616
self.context = context
1717
}
1818

1919
/// Retrieves the underlying LLVM type object.
2020
public func asLLVM() -> LLVMTypeRef {
21-
if let context = context {
22-
return LLVMVoidTypeInContext(context.llvm)
23-
}
24-
return LLVMVoidType()
21+
return LLVMVoidTypeInContext(context.llvm)
2522
}
2623
}

Sources/LLVM/X86MMXType.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@ import cllvm
1111
public struct X86MMXType: IRType {
1212

1313
/// Returns the context associated with this module.
14-
public let context: Context?
15-
14+
public let context: Context
15+
1616
/// Creates an `X86MMXType`.
1717
///
1818
/// - parameter context: The context to create this type in
1919
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
20-
public init(in context: Context? = nil) {
20+
public init(in context: Context = Context.global) {
2121
self.context = context
2222
}
2323

2424
/// Retrieves the underlying LLVM type object.
2525
public func asLLVM() -> LLVMTypeRef {
26-
if let context = context {
27-
return LLVMX86MMXTypeInContext(context.llvm)
28-
}
29-
return LLVMX86MMXType()
26+
return LLVMX86MMXTypeInContext(context.llvm)
3027
}
3128
}

0 commit comments

Comments
 (0)