@@ -36,15 +36,23 @@ public struct Triple: Encodable, Equatable {
36
36
case unknownOS( os: String )
37
37
}
38
38
39
- public enum Arch : String , Encodable {
39
+ public enum ARMCore : String , Encodable , CaseIterable {
40
+ case a = " a "
41
+ case r = " r "
42
+ case m = " m "
43
+ case k = " k "
44
+ case s = " s "
45
+ }
46
+
47
+ public enum Arch : Encodable {
40
48
case x86_64
41
49
case x86_64h
42
50
case i686
43
51
case powerpc64le
44
52
case s390x
45
53
case aarch64
46
54
case amd64
47
- case armv7
55
+ case armv7( core : ARMCore ? )
48
56
case armv6
49
57
case armv5
50
58
case arm
@@ -111,7 +119,7 @@ public struct Triple: Encodable, Equatable {
111
119
throw Error . badFormat ( triple: string)
112
120
}
113
121
114
- guard let arch = Arch ( rawValue : components [ 0 ] ) else {
122
+ guard let arch = Triple . parseArch ( components [ 0 ] ) else {
115
123
throw Error . unknownArch ( arch: components [ 0 ] )
116
124
}
117
125
@@ -135,6 +143,43 @@ public struct Triple: Encodable, Equatable {
135
143
self . abiVersion = abiVersion
136
144
}
137
145
146
+ fileprivate static func parseArch( _ string: String ) -> Arch ? {
147
+ let candidates : [ String : Arch ] = [
148
+ " x86_64h " : . x86_64h,
149
+ " x86_64 " : . x86_64,
150
+ " i686 " : . i686,
151
+ " powerpc64le " : . powerpc64le,
152
+ " s390x " : . s390x,
153
+ " aarch64 " : . aarch64,
154
+ " amd64 " : . amd64,
155
+ " armv7 " : . armv7( core: nil ) ,
156
+ " armv6 " : . armv6,
157
+ " armv5 " : . armv5,
158
+ " arm " : . arm,
159
+ " arm64 " : . arm64,
160
+ " arm64e " : . arm64e,
161
+ " wasm32 " : . wasm32,
162
+ ]
163
+ if let match = candidates. first ( where: { string. hasPrefix ( $0. key) } ) ? . value {
164
+ if case let . armv7( core: _) = match {
165
+ if string. hasPrefix ( " armv7a " ) {
166
+ return . armv7( core: . a)
167
+ } else if string. hasPrefix ( " armv7r " ) {
168
+ return . armv7( core: . r)
169
+ } else if string. hasPrefix ( " armv7m " ) {
170
+ return . armv7( core: . m)
171
+ } else if string. hasPrefix ( " armv7k " ) {
172
+ return . armv7( core: . k)
173
+ } else if string. hasPrefix ( " armv7s " ) {
174
+ return . armv7( core: . s)
175
+ }
176
+ return . armv7( core: nil )
177
+ }
178
+ return match
179
+ }
180
+ return nil
181
+ }
182
+
138
183
fileprivate static func parseOS( _ string: String ) -> OS ? {
139
184
var candidates = OS . allCases. map { ( name: $0. rawValue, value: $0) }
140
185
// LLVM target triples support this alternate spelling as well.
@@ -201,6 +246,7 @@ public struct Triple: Encodable, Equatable {
201
246
fatalError ( " Failed to get target info ( \( error) ) " )
202
247
#endif
203
248
}
249
+
204
250
// Parse the compiler's JSON output.
205
251
let parsedTargetInfo : JSON
206
252
do {
@@ -283,6 +329,78 @@ extension Triple {
283
329
}
284
330
}
285
331
332
+ extension Triple . Arch : CustomStringConvertible {
333
+ public var description : String {
334
+ switch self {
335
+ case . x86_64:
336
+ return " x86_64 "
337
+ case . x86_64h:
338
+ return " x86_64h "
339
+ case . i686:
340
+ return " i686 "
341
+ case . powerpc64le:
342
+ return " powerpc64le "
343
+ case . s390x:
344
+ return " s390x "
345
+ case . aarch64:
346
+ return " aarch64 "
347
+ case . amd64:
348
+ return " amd64 "
349
+ case . armv7( . none) :
350
+ return " armv7 "
351
+ case let . armv7( core: . some( core) ) :
352
+ return " armv7 \( core) "
353
+ case . armv6:
354
+ return " armv6 "
355
+ case . armv5:
356
+ return " armv5 "
357
+ case . arm:
358
+ return " arm "
359
+ case . arm64:
360
+ return " arm64 "
361
+ case . arm64e:
362
+ return " arm64e "
363
+ case . wasm32:
364
+ return " wasm32 "
365
+ }
366
+ }
367
+ }
368
+
369
+ extension Triple . Arch : Equatable {
370
+ public static func == ( _ lhs: Triple . Arch , _ rhs: Triple . Arch ) -> Bool {
371
+ switch ( lhs, rhs) {
372
+ case ( . x86_64, . x86_64) :
373
+ return true
374
+ case ( . x86_64h, . x86_64h) :
375
+ return true
376
+ case ( . i686, . i686) :
377
+ return true
378
+ case ( . powerpc64le, . powerpc64le) :
379
+ return true
380
+ case ( . s390x, . s390x) :
381
+ return true
382
+ case ( . armv7( . none) , . armv7( . none) ) :
383
+ return true
384
+ case let ( . armv7( . some( lhs) ) , . armv7( . some( rhs) ) ) where lhs == rhs:
385
+ return true
386
+ case ( . armv6, . armv6) :
387
+ return true
388
+ case ( . armv5, . armv5) :
389
+ return true
390
+ case ( . arm, . arm) :
391
+ return true
392
+ case ( . arm64, . arm64) :
393
+ return true
394
+ case ( . arm64e, . arm64e) :
395
+ return true
396
+ case ( . wasm32, . wasm32) :
397
+ return true
398
+ default :
399
+ return false
400
+ }
401
+ }
402
+ }
403
+
286
404
extension Triple . Error : CustomNSError {
287
405
public var errorUserInfo : [ String : Any ] {
288
406
return [ NSLocalizedDescriptionKey: " \( self ) " ]
0 commit comments