-
Notifications
You must be signed in to change notification settings - Fork 130
TSCUtility: support additional spellings for ARM #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
compnerd
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
compnerd:spelling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,15 +36,23 @@ public struct Triple: Encodable, Equatable { | |
case unknownOS(os: String) | ||
} | ||
|
||
public enum Arch: String, Encodable { | ||
public enum ARMCore: String, Encodable, CaseIterable { | ||
case a = "a" | ||
case r = "r" | ||
case m = "m" | ||
case k = "k" | ||
case s = "s" | ||
} | ||
|
||
public enum Arch: Encodable { | ||
case x86_64 | ||
case x86_64h | ||
case i686 | ||
case powerpc64le | ||
case s390x | ||
case aarch64 | ||
case amd64 | ||
case armv7 | ||
case armv7(core: ARMCore?) | ||
case armv6 | ||
case armv5 | ||
case arm | ||
|
@@ -111,7 +119,7 @@ public struct Triple: Encodable, Equatable { | |
throw Error.badFormat(triple: string) | ||
} | ||
|
||
guard let arch = Arch(rawValue: components[0]) else { | ||
guard let arch = Triple.parseArch(components[0]) else { | ||
throw Error.unknownArch(arch: components[0]) | ||
} | ||
|
||
|
@@ -135,6 +143,43 @@ public struct Triple: Encodable, Equatable { | |
self.abiVersion = abiVersion | ||
} | ||
|
||
fileprivate static func parseArch(_ string: String) -> Arch? { | ||
let candidates: [String:Arch] = [ | ||
"x86_64h": .x86_64h, | ||
"x86_64": .x86_64, | ||
"i686": .i686, | ||
"powerpc64le": .powerpc64le, | ||
"s390x": .s390x, | ||
"aarch64": .aarch64, | ||
"amd64": .amd64, | ||
"armv7": .armv7(core: nil), | ||
"armv6": .armv6, | ||
"armv5": .armv5, | ||
"arm": .arm, | ||
"arm64": .arm64, | ||
"arm64e": .arm64e, | ||
"wasm32": .wasm32, | ||
] | ||
if let match = candidates.first(where: { string.hasPrefix($0.key) })?.value { | ||
if case let .armv7(core: _) = match { | ||
if string.hasPrefix("armv7a") { | ||
return .armv7(core: .a) | ||
} else if string.hasPrefix("armv7r") { | ||
return .armv7(core: .r) | ||
} else if string.hasPrefix("armv7m") { | ||
return .armv7(core: .m) | ||
} else if string.hasPrefix("armv7k") { | ||
return .armv7(core: .k) | ||
} else if string.hasPrefix("armv7s") { | ||
return .armv7(core: .s) | ||
} | ||
return .armv7(core: nil) | ||
} | ||
return match | ||
} | ||
return nil | ||
} | ||
|
||
fileprivate static func parseOS(_ string: String) -> OS? { | ||
var candidates = OS.allCases.map{ (name: $0.rawValue, value: $0) } | ||
// LLVM target triples support this alternate spelling as well. | ||
|
@@ -201,6 +246,7 @@ public struct Triple: Encodable, Equatable { | |
fatalError("Failed to get target info (\(error))") | ||
#endif | ||
} | ||
|
||
// Parse the compiler's JSON output. | ||
let parsedTargetInfo: JSON | ||
do { | ||
|
@@ -283,6 +329,78 @@ extension Triple { | |
} | ||
} | ||
|
||
extension Triple.Arch: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More of a nit, but could we utilize the candidate array from |
||
case .x86_64: | ||
return "x86_64" | ||
case .x86_64h: | ||
return "x86_64h" | ||
case .i686: | ||
return "i686" | ||
case .powerpc64le: | ||
return "powerpc64le" | ||
case .s390x: | ||
return "s390x" | ||
case .aarch64: | ||
return "aarch64" | ||
case .amd64: | ||
return "amd64" | ||
case .armv7(.none): | ||
return "armv7" | ||
case let .armv7(core: .some(core)): | ||
return "armv7\(core)" | ||
case .armv6: | ||
return "armv6" | ||
case .armv5: | ||
return "armv5" | ||
case .arm: | ||
return "arm" | ||
case .arm64: | ||
return "arm64" | ||
case .arm64e: | ||
return "arm64e" | ||
case .wasm32: | ||
return "wasm32" | ||
} | ||
} | ||
} | ||
|
||
extension Triple.Arch: Equatable { | ||
public static func == (_ lhs: Triple.Arch, _ rhs: Triple.Arch) -> Bool { | ||
switch (lhs, rhs) { | ||
case (.x86_64, .x86_64): | ||
return true | ||
case (.x86_64h, .x86_64h): | ||
return true | ||
case (.i686, .i686): | ||
return true | ||
case (.powerpc64le, .powerpc64le): | ||
return true | ||
case (.s390x, .s390x): | ||
return true | ||
case (.armv7(.none), .armv7(.none)): | ||
return true | ||
case let (.armv7(.some(lhs)), .armv7(.some(rhs))) where lhs == rhs: | ||
return true | ||
case (.armv6, .armv6): | ||
return true | ||
case (.armv5, .armv5): | ||
return true | ||
case (.arm, .arm): | ||
return true | ||
case (.arm64, .arm64): | ||
return true | ||
case (.arm64e, .arm64e): | ||
return true | ||
case (.wasm32, .wasm32): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
} | ||
|
||
extension Triple.Error: CustomNSError { | ||
public var errorUserInfo: [String : Any] { | ||
return [NSLocalizedDescriptionKey: "\(self)"] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift's
Dictionary
isn’t ordered, so we will run into random results here by usingfirst(where:)
.