diff --git a/Sources/CLI/CLI.swift b/Sources/CLI/CLI.swift index 9b31eb33..1f65e300 100644 --- a/Sources/CLI/CLI.swift +++ b/Sources/CLI/CLI.swift @@ -4,7 +4,7 @@ import ArgumentParser struct CLI: ParsableCommand { static let configuration = CommandConfiguration( commandName: "wasmkit", - abstract: "WebAssembly Runtime written in Swift.", + abstract: "WasmKit WebAssembly Runtime", version: "0.0.8", subcommands: [Run.self, Explore.self] ) diff --git a/Sources/CLI/Commands/Explore.swift b/Sources/CLI/Commands/Explore.swift index f6d01c5c..813b621b 100644 --- a/Sources/CLI/Commands/Explore.swift +++ b/Sources/CLI/Commands/Explore.swift @@ -3,6 +3,16 @@ import SystemPackage @_spi(OnlyForCLI) import WasmKit struct Explore: ParsableCommand { + + static let configuration = CommandConfiguration( + abstract: "Explore the compiled functions of a WebAssembly module", + discussion: """ + This command will parse a WebAssembly module and dump the compiled functions. + """, + // This command is just for debugging purposes, so it should be hidden by default + shouldDisplay: false + ) + @Argument var path: String diff --git a/Sources/CLI/Commands/Run.swift b/Sources/CLI/Commands/Run.swift index 216b5348..cac7548f 100644 --- a/Sources/CLI/Commands/Run.swift +++ b/Sources/CLI/Commands/Run.swift @@ -7,7 +7,17 @@ import os.signpost #endif struct Run: ParsableCommand { - @Flag + static let configuration = CommandConfiguration( + abstract: "Run a WebAssembly module", + discussion: """ + This command will parse a WebAssembly module and run it. + """ + ) + + @Flag( + name: .shortAndLong, + help: "Enable verbose logging" + ) var verbose = false @Option( @@ -47,14 +57,41 @@ struct Run: ParsableCommand { @Option(name: .customLong("dir"), help: "Grant access to the given host directory") var directories: [String] = [] - enum ThreadingModel: String, ExpressibleByArgument { + enum ThreadingModel: String, ExpressibleByArgument, CaseIterable { case direct case token + + func resolve() -> EngineConfiguration.ThreadingModel { + switch self { + case .direct: return .direct + case .token: return .token + } + } } @Option(help: ArgumentHelp("The execution threading model to use", visibility: .hidden)) var threadingModel: ThreadingModel? + enum CompilationMode: String, ExpressibleByArgument, CaseIterable { + case eager + case lazy + + func resolve() -> EngineConfiguration.CompilationMode { + switch self { + case .eager: return .eager + case .lazy: return .lazy + } + } + } + + @Option( + help: ArgumentHelp( + "The compilation mode to use for WebAssembly modules", + valueName: "mode", visibility: .hidden + ) + ) + var compilationMode: CompilationMode? + @Option( help: ArgumentHelp( "The size of the interpreter stack in bytes", @@ -151,13 +188,11 @@ struct Run: ParsableCommand { } private func deriveRuntimeConfiguration() -> EngineConfiguration { - let threadingModel: EngineConfiguration.ThreadingModel? - switch self.threadingModel { - case .direct: threadingModel = .direct - case .token: threadingModel = .token - case nil: threadingModel = nil - } - return EngineConfiguration(threadingModel: threadingModel, stackSize: self.stackSize) + return EngineConfiguration( + threadingModel: threadingModel?.resolve(), + compilationMode: compilationMode?.resolve(), + stackSize: self.stackSize + ) } func instantiateWASI(module: Module, interceptor: EngineInterceptor?) throws -> () throws -> Void { diff --git a/Sources/WasmKit/Engine.swift b/Sources/WasmKit/Engine.swift index 8ed2fa28..b9399cf5 100644 --- a/Sources/WasmKit/Engine.swift +++ b/Sources/WasmKit/Engine.swift @@ -89,9 +89,9 @@ public struct EngineConfiguration { /// - Parameter threadingModel: The threading model to use for the virtual /// machine interpreter. If `nil`, the default threading model for the /// current platform will be used. - public init(threadingModel: ThreadingModel? = nil, compilationMode: CompilationMode = .lazy, stackSize: Int? = nil) { + public init(threadingModel: ThreadingModel? = nil, compilationMode: CompilationMode? = nil, stackSize: Int? = nil) { self.threadingModel = threadingModel ?? .defaultForCurrentPlatform - self.compilationMode = compilationMode + self.compilationMode = compilationMode ?? .lazy self.stackSize = stackSize ?? (1 << 19) } }