Skip to content

Commit

Permalink
Implement a CLI to demangle symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
kyouko-taiga committed Sep 6, 2023
1 parent 241df59 commit 7ea2116
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ let package = Package(
],
swiftSettings: allTargetsSwiftSettings),

.executableTarget(
name: "hylo-demangle",
dependencies: [
"IR"
],
swiftSettings: allTargetsSwiftSettings),

.target(
name: "Driver",
dependencies: [
Expand Down
24 changes: 24 additions & 0 deletions Sources/hylo-demangle/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation
import IR

/// Reports the given `diagnostic` on the standard error and exit with status -1.
func error(_ diagnostic: String) -> Never {
let d = Data("\(diagnostic)\n".utf8)
FileHandle.standardError.write(d)
exit(-1)
}

func main() {
guard CommandLine.arguments.count > 1 else {
error("missing input")
}

let n = CommandLine.arguments[1]
guard let s = DemangledSymbol(n) else {
error("could not demangle '\(n)'")
}

print(s)
}

main()

0 comments on commit 7ea2116

Please sign in to comment.