@@ -75,6 +75,61 @@ public class Target {
75
75
public init ( llvm: LLVMTargetRef ) {
76
76
self . llvm = llvm
77
77
}
78
+
79
+ /// Returns `true` if this target has a JIT.
80
+ var hasJIT : Bool {
81
+ return LLVMTargetHasJIT ( self . llvm) != 0
82
+ }
83
+
84
+ /// The name of this target.
85
+ public var name : String {
86
+ guard let str = LLVMGetTargetName ( self . llvm) else {
87
+ return " "
88
+ }
89
+ return String ( validatingUTF8: UnsafePointer < CChar > ( str) ) ?? " "
90
+ }
91
+
92
+ /// The description of this target.
93
+ public var targetDescription : String {
94
+ guard let str = LLVMGetTargetDescription ( self . llvm) else {
95
+ return " "
96
+ }
97
+ return String ( validatingUTF8: UnsafePointer < CChar > ( str) ) ?? " "
98
+ }
99
+
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
+
110
+ /// Returns a sequence of all targets in the global list of targets.
111
+ public static var allTargets : AnySequence < Target > {
112
+ var current = firstTarget
113
+ return AnySequence< Target> {
114
+ return AnyIterator< Target> {
115
+ defer { current = current? . next ( ) }
116
+ return current
117
+ }
118
+ }
119
+ }
120
+
121
+ /// Returns the first target in the global target list, if it exists.
122
+ public static var firstTarget : Target ? {
123
+ guard let targetRef = LLVMGetFirstTarget ( ) else { return nil }
124
+ return Target ( llvm: targetRef)
125
+ }
126
+
127
+ /// Returns the target following this target in the global target list,
128
+ /// if it exists.
129
+ public func next( ) -> Target ? {
130
+ guard let targetRef = LLVMGetNextTarget ( self . llvm) else { return nil }
131
+ return Target ( llvm: targetRef)
132
+ }
78
133
}
79
134
80
135
/// A `TargetMachine` object represents an object that encapsulates information
0 commit comments