Skip to content

Commit c3a12b4

Browse files
committed
Disable and rewrite Metadata and Token type inits
These initializers do not have corresponding create calls in LLVM yet and so cannot possibly be used from user code. Disable them with a message.
1 parent 1f04fd4 commit c3a12b4

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Sources/LLVM/IRType.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ internal func convertType(_ type: LLVMTypeRef) -> IRType {
7878
let count = Int(LLVMGetVectorSize(type))
7979
return VectorType(elementType: elementType, count: count)
8080
case LLVMMetadataTypeKind:
81-
return MetadataType(llvm: type)
81+
return MetadataType(in: context)
8282
case LLVMX86_MMXTypeKind:
8383
return X86MMXType(in: context)
8484
case LLVMTokenTypeKind:
85-
return TokenType(llvm: type)
85+
return TokenType(in: context)
8686
default: fatalError("unknown type kind for type \(type)")
8787
}
8888
}

Sources/LLVM/MetadataType.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import cllvm
55
/// The `MetadataType` type represents embedded metadata. No derived types may
66
/// be created from metadata except for function arguments.
77
public struct MetadataType: IRType {
8-
internal let llvm: LLVMTypeRef
8+
/// Returns the context associated with this type.
9+
public let context: Context
910

1011
/// Creates an embedded metadata type for the given LLVM type object.
11-
public init(llvm: LLVMTypeRef) {
12-
self.llvm = llvm
12+
///
13+
/// - parameter context: The context to create this type in
14+
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
15+
public init(in context: Context = Context.global) {
16+
self.context = context
1317
}
1418

1519
/// Retrieves the underlying LLVM type object.
1620
public func asLLVM() -> LLVMTypeRef {
17-
return llvm
21+
fatalError("This version of LLVM does not support the creation of MetadataType objects")
1822
}
1923
}

Sources/LLVM/TokenType.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import cllvm
66
/// uses of the value must not attempt to introspect or obscure it. As such, it
77
/// is not appropriate to have a `PHI` or `select` of type `TokenType`.
88
public struct TokenType: IRType {
9-
internal let llvm: LLVMTypeRef
9+
/// Returns the context associated with this type.
10+
public let context: Context
1011

1112
/// Initializes a token type from the given LLVM type object.
12-
public init(llvm: LLVMTypeRef) { self.llvm = llvm }
13+
///
14+
/// - parameter context: The context to create this type in
15+
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext
16+
public init(in context: Context = Context.global) {
17+
self.context = context
18+
}
1319

1420
/// Retrieves the underlying LLVM type object.
1521
public func asLLVM() -> LLVMTypeRef {
16-
return llvm
22+
fatalError("This version of LLVM does not support the creation of TokenType objects")
1723
}
1824
}

0 commit comments

Comments
 (0)