-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add zware-run to run wasm binaries from the command-line
An initial version of a command-line program that can take a WASM binary on the command line and a function name and execute it. It will find missing imports and populate them with "stubs". The stub will log the call and then populate the results with "zeroed" values. An enhancement could be to take multiple files on the command line and link them together before execution. A few examples of binaries I could use with this was: - binaries from the test suite - WASM4 binaries - the Zig wasm executable Of the ones I tested this seems like a viable strategy to quickly run the binaries from the test suite. The WASM4/Zig binaries would usually just call a function or two and then hit an assert because of the "zeroed" results that are produced by the stubs.
- Loading branch information
1 parent
9cd6f56
commit b0efcd0
Showing
10 changed files
with
344 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const std = @import("std"); | ||
|
||
const module = @import("module.zig"); | ||
|
||
/// A function can take a reference to this to pass extra error information to the caller. | ||
/// A function that does this guarantees the reference will be populated if it returns error.SeeContext. | ||
/// Error implements a format function. | ||
/// The same error instance can be re-used for multiple calls. | ||
/// | ||
/// Example usage: | ||
/// ---- | ||
/// var zware_error: Error = undefined; | ||
/// foo(&zware_error) catch |err| switch (err) { | ||
/// error.SeeContext => std.log.err("foo failed: {}", .{zware_error}), | ||
/// else => |err| return err, | ||
/// }; | ||
/// --- | ||
pub const Error = union(enum) { | ||
missing_import: module.Import, | ||
any: anyerror, | ||
|
||
/// Called by a function that wants to both populate this error instance and let the caller | ||
/// know it's been populated by returning error.SeeContext. | ||
pub fn set(self: *Error, e: Error) error{SeeContext} { | ||
self.* = e; | ||
return error.SeeContext; | ||
} | ||
pub fn format( | ||
self: Error, | ||
comptime fmt: []const u8, | ||
options: std.fmt.FormatOptions, | ||
writer: anytype, | ||
) !void { | ||
_ = fmt; | ||
_ = options; | ||
switch (self) { | ||
.missing_import => |import| try writer.print( | ||
"missing {s} import '{s}' from module '{s}'", | ||
.{ @tagName(import.desc_tag), import.name, import.module }, | ||
), | ||
.any => |e| try writer.print("{s}", .{@errorName(e)}), | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.