Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/CLI/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand Down
10 changes: 10 additions & 0 deletions Sources/CLI/Commands/Explore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 44 additions & 9 deletions Sources/CLI/Commands/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/WasmKit/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down