From 238c39c564839861f58450864c195a70e5874415 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Wed, 6 Sep 2023 15:55:33 +0200 Subject: [PATCH 1/4] Rename 'HyloCommand.swift' to 'Driver.swift' --- Sources/Driver/{HyloCommand.swift => Driver.swift} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Sources/Driver/{HyloCommand.swift => Driver.swift} (100%) diff --git a/Sources/Driver/HyloCommand.swift b/Sources/Driver/Driver.swift similarity index 100% rename from Sources/Driver/HyloCommand.swift rename to Sources/Driver/Driver.swift From 241df59dd8104cbc13c9a58b7b196ec9744f7074 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Wed, 6 Sep 2023 16:20:27 +0200 Subject: [PATCH 2/4] Rename 'Sources/CLI' to 'hc' --- Package.swift | 4 ++-- Sources/{CLI => hc}/FullPathInFatalErrors.swift | 0 Sources/{CLI => hc}/main.swift | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename Sources/{CLI => hc}/FullPathInFatalErrors.swift (100%) rename Sources/{CLI => hc}/main.swift (100%) diff --git a/Package.swift b/Package.swift index eaf0436d1..3f7f89fa4 100644 --- a/Package.swift +++ b/Package.swift @@ -14,7 +14,7 @@ let package = Package( ], products: [ - .executable(name: "hc", targets: ["CLI"]) + .executable(name: "hc", targets: ["hc"]) ], dependencies: [ @@ -45,7 +45,7 @@ let package = Package( targets: [ // The compiler's executable target. .executableTarget( - name: "CLI", + name: "hc", dependencies: [ "Driver" ], diff --git a/Sources/CLI/FullPathInFatalErrors.swift b/Sources/hc/FullPathInFatalErrors.swift similarity index 100% rename from Sources/CLI/FullPathInFatalErrors.swift rename to Sources/hc/FullPathInFatalErrors.swift diff --git a/Sources/CLI/main.swift b/Sources/hc/main.swift similarity index 100% rename from Sources/CLI/main.swift rename to Sources/hc/main.swift From 7ea2116bdd43b10a4a7b181d14897a953f93b2c3 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Wed, 6 Sep 2023 16:20:54 +0200 Subject: [PATCH 3/4] 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() From 6b144d688c2a9d97407f6405ef6f863a85da8515 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Wed, 6 Sep 2023 16:58:00 +0200 Subject: [PATCH 4/4] Fix typo --- Sources/IR/Mangling/Mangler.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/IR/Mangling/Mangler.swift b/Sources/IR/Mangling/Mangler.swift index fd469b93e..874cb0964 100644 --- a/Sources/IR/Mangling/Mangler.swift +++ b/Sources/IR/Mangling/Mangler.swift @@ -255,7 +255,7 @@ struct Mangler { /// Writes the mangled representation of `u` to `output`. private mutating func write(subscriptImpl d: SubscriptImpl.ID, to output: inout Output) { write(operator: .subscriptImpl, to: &output) - write(base64Didit: program.ast[d].introducer.value, to: &output) + write(base64Digit: program.ast[d].introducer.value, to: &output) } /// Writes the mangled representation of `u` to `output`. @@ -321,7 +321,7 @@ struct Mangler { synthesized symbol: SynthesizedFunctionDecl, to output: inout Output ) { write(operator: .synthesizedFunctionDecl, to: &output) - write(base64Didit: symbol.kind, to: &output) + write(base64Digit: symbol.kind, to: &output) write(scope: symbol.scope, to: &output) mangle(type: ^symbol.type, to: &output) } @@ -389,7 +389,7 @@ struct Mangler { case let t as ParameterType: write(operator: .parameterType, to: &output) - write(base64Didit: t.access, to: &output) + write(base64Digit: t.access, to: &output) mangle(type: t.bareType, to: &output) case let t as ProductType: @@ -401,7 +401,7 @@ struct Mangler { case let t as RemoteType: write(operator: .remoteType, to: &output) - write(base64Didit: t.access, to: &output) + write(base64Digit: t.access, to: &output) mangle(type: t.bareType, to: &output) case let t as SubscriptType: @@ -502,7 +502,7 @@ struct Mangler { /// Writes the mangled representation of `symbol` to `output`. private mutating func write(subscriptType t: SubscriptType, to output: inout Output) { write(operator: .subscriptType, to: &output) - write(base64Didit: t.capabilities, to: &output) + write(base64Digit: t.capabilities, to: &output) mangle(type: t.environment, to: &output) write(integer: t.inputs.count, to: &output) @@ -562,10 +562,10 @@ struct Mangler { write(base64Didit: tag, to: &output) if let n = name.notation { - write(base64Didit: n, to: &output) + write(base64Digit: n, to: &output) } if let i = name.introducer { - write(base64Didit: i, to: &output) + write(base64Digit: i, to: &output) } write(string: name.stem, to: &output) } @@ -583,7 +583,7 @@ struct Mangler { /// Writes the raw value of `v` encoded as a base 64 digit to `output`. private func write( - base64Didit v: T, to output: inout Output + base64Digit v: T, to output: inout Output ) where T.RawValue == UInt8 { write(base64Didit: v.rawValue, to: &output) }