diff --git a/Package.swift b/Package.swift index eaf0436d1..4c57c1ed6 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,12 +45,19 @@ let package = Package( targets: [ // The compiler's executable target. .executableTarget( - name: "CLI", + name: "hc", dependencies: [ "Driver" ], swiftSettings: allTargetsSwiftSettings), + .executableTarget( + name: "hylo-demangle", + dependencies: [ + "IR" + ], + swiftSettings: allTargetsSwiftSettings), + .target( name: "Driver", dependencies: [ 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 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) } 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 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()