Skip to content

Commit e86bff8

Browse files
committed
Publicize Target Predicates
1 parent bf2947c commit e86bff8

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

Sources/LLVM/TargetMachine.swift

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,33 @@ public class Target {
7676
self.llvm = llvm
7777
}
7878

79-
/// Returns `true` if this target has a JIT.
80-
var hasJIT: Bool {
79+
/// Returns `true` if this target supports just-in-time compilation.
80+
///
81+
/// Attempting to create a JIT for a `Target` where this predicate is false
82+
/// may lead to program instability or corruption.
83+
public var hasJIT: Bool {
8184
return LLVMTargetHasJIT(self.llvm) != 0
8285
}
8386

87+
88+
/// Returns `true` if this target has a `TargetMachine` associated with it.
89+
///
90+
/// Target machines are registered by the corresponding initializer functions
91+
/// for each target. LLVMSwift will ensure that these functions are invoked
92+
/// when a TargetMachine is created, but not before.
93+
public var hasTargetMachine: Bool {
94+
return LLVMTargetHasTargetMachine(self.llvm) != 0
95+
}
96+
97+
/// Returns `true` if this target has an ASM backend.
98+
///
99+
/// ASM backends are registered by the corresponding iniailizer functions for
100+
/// each target. LLVMSwift will ensure that these functions are invoked
101+
/// when a TargetMachine is created, but not before.
102+
public var hasASMBackend: Bool {
103+
return LLVMTargetHasAsmBackend(self.llvm) != 0
104+
}
105+
84106
/// The name of this target.
85107
public var name: String {
86108
guard let str = LLVMGetTargetName(self.llvm) else {
@@ -97,16 +119,6 @@ public class Target {
97119
return String(validatingUTF8: UnsafePointer<CChar>(str)) ?? ""
98120
}
99121

100-
/// Returns `true` if this target has a `TargetMachine` associated with it.
101-
var hasTargetMachine: Bool {
102-
return LLVMTargetHasTargetMachine(self.llvm) != 0
103-
}
104-
105-
/// Returns `true` if this target has an ASM backend
106-
var hasASMBackend: Bool {
107-
return LLVMTargetHasTargetMachine(self.llvm) != 0
108-
}
109-
110122
/// Returns a sequence of all targets in the global list of targets.
111123
public static var allTargets: AnySequence<Target> {
112124
var current = firstTarget

0 commit comments

Comments
 (0)