From 7ea2116bdd43b10a4a7b181d14897a953f93b2c3 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Wed, 6 Sep 2023 16:20:54 +0200 Subject: [PATCH] Implement a CLI to demangle symbols --- Package.swift | 7 +++++++ Sources/hylo-demangle/main.swift | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Sources/hylo-demangle/main.swift diff --git a/Package.swift b/Package.swift index 3f7f89fa4..4c57c1ed6 100644 --- a/Package.swift +++ b/Package.swift @@ -51,6 +51,13 @@ let package = Package( ], swiftSettings: allTargetsSwiftSettings), + .executableTarget( + name: "hylo-demangle", + dependencies: [ + "IR" + ], + swiftSettings: allTargetsSwiftSettings), + .target( name: "Driver", dependencies: [ diff --git a/Sources/hylo-demangle/main.swift b/Sources/hylo-demangle/main.swift new file mode 100644 index 000000000..98cefcf63 --- /dev/null +++ b/Sources/hylo-demangle/main.swift @@ -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()