| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
| |
|
|
|
| |
This makes things easier for users and packagers of libwabt.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This applies clang-format to the whole codebase.
I noticed we have .clang-format in wabt but the codebase is not very
well formatted. This kind of mass-formatting PR has fans and skeptics
because it can mess with `git blame`, but we did a similar thing in
Binaryen a few years ago (WebAssembly/binaryen#2048, which was merged in
WebAssembly/binaryen#2059) and it was not very confusing after all.
If we are ever going to format the codebase, I think it is easier to do
it in a single big PR than dozens of smaller PRs.
This is using the existing .clang-format file in this repo, which
follows the style of Chromium. If we think this does not suit the
current formatting style, we can potentially tweak .clang-format too.
For example, I noticed the current codebase puts many `case` statements
within a single line when they are short, but the current .clang-format
does not allow that.
This does not include files in src/prebuilt, because they are generated.
This also manually fixes some comment lines, because mechanically
applying clang-format to long inline comments can look weird.
I also added a clang-format check hook in the Github CI in #1683, which
I think can be less controversial, given that it only checks the diff.
---
After discussions, we ended up reverting many changes, especially
one-liner functions and switch-cases, which are too many to wrap in
`// clang-format off` and `// clang-format on`. I also considered fixing
`.clang-format` to allow those one-liners but it caused a larger churn
in other parts. So currently the codebase does not conform to
`.clang-format` 100%, but we decided it's fine.
|
| |
|
|
|
|
| |
I think it was always intended to work this way but was
left as a TODO.
|
|
|
|
|
|
|
|
|
|
|
| |
Without this change wasm-interp always runs with default
features.
These features seem to be used in just a single location:
src/interp/interp.cc: int pass = store.features().bulk_memory_enabled() ? Init : Check;
I noticed this when trying to enable bulk memory but run
the interpreter with `--disable-bulk-memory` and it was
not effecting this line of code.
|
|
|
|
| |
I'm not sure why we were using stdout but the convention is normally to
write all logging and error message to stderr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
I've been used the tests from wasi-sdk to get started:
https://github.com/WebAssembly/wasi-sdk/tree/master/tests
All these tests now pass. Still this isn't saying much, there are still
some big missing pieces. Started using the new serdes
(serialize/deserialze) API in uvwasi. I think we are almost at the
point were we can look at auto-generating some of this stuff from witx
to avoid having the hand code all this marshelling stuff.
Add support for ArgumentCount::ZeroOrMore to OptionParser and also the
ability to force the end of option processing using `--`. This allows
is to pass options through the underlying wasi program when running
wasm-interp.
|
|
|
|
| |
This is almost enough to pass all the tiny tests in the wasi-sdk
repo.
|
|
|
|
| |
We should probably send traving to stderr too but thats a bigger
change.
|
|
|
|
|
|
|
|
|
|
| |
This is proof of concept that only implements the `proc_exit` and
`fd_write` APIs.
Extending this to the full WASI API will to follow assuming this
approach seems reasonable.
Fixes #1409
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The for experimental WASI implementation I'm working on the WASI
callbacks (implemented as HostFuncs) need to know which module a call is
coming from. This is because the implicitly operate on the memory of
the calling instance.
This approach seems the match the current convention of passing in the
Thread in `Func::DoCall`.
The purpose here is to allow the HostCall callback to determine from
which instance it is being called. An alternative approach that I
considered was created different set of WASI HostCall object for
each instance so that instance and its memory we bound to the WASI
functions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It's modeled closely on the wasm-c-api. All runtime objects are
garbage-collected. The GC'd objects are subclasses of `Object` and all
stored in the `Store`. GC roots can be created using a RefPtr<T> struct.
The `Module` stores no runtime objects, only description structs (named
`*Desc`, e.g. `FuncDesc`). Instantiation takes these descriptors and
turns them into runtime objects (e.g. `FuncDesc` is used to create a
`Func`). Only import-matching occurs during instantiation; all other
validation is assumed to have occurred during Module compilation.
As with the previous interpreter, the wasm instructions are not executed
directly, and instead compiled to an instruction stream that is easier
to interpret (e.g. all branches become gotos). It's still a stack
machine, though.
The previous interpreter would always compile and instantiate in one
step, which means that it was always known whether an imported function
is a host function or wasm function. As a result, calls between modules
that stayed in wasm could be very cheap (just update PC). Now that the
module is compiled before instantiation, an imported function call
always has to check first, which may be a slight performance hit.
One major difference to the structure of the interpreter is that
floating-point values are passed directly, instead of using their
equivalent bit pattern. This is more convenient in general, but requires
annotating all functions with WABT_VECTORCALL so Visual Studio x86 works
properly (otherwise floats are passed in the x87 FP stack).
Instruction stream decoding/tracing/disassembling is now all handled in
the `Istream` class. This reduces a lot of duplication between the
three, which makes the logging-all-opcodes and tracing-all-opcodes less
valuable, so I've removed them.
Here are the changes to files:
binary-reader-metadata.{h,cc} -> [removed]
interp-{disassemble.trace}.cc -> istream.{h,cc}
There are new helper files:
interp-util.{h,cc}: Primarily print debugging functions
interp-math.h: Templates used for handling wasm math
|
|
|
|
|
|
|
| |
The only major change to the interpreter is to move segment
initialization out `ReadBinaryInterp` (in the binary reader) and into
interp.cc. This is because the test suite now expects out of bound
semgments to be reported during initialization rather than reported
as validation errors.
|
|
|
|
|
|
|
|
|
|
|
| |
This means we can give more precise/useful errors for runtime failures.
Change interp::Result from an enum to struct so it can hold the
result enum plus an optional detailed error message.
Add TRAP_MSG and TRAP_IF_MSG macros that work just like TRAP and
TRAP_IF but contain a format string and printf-like arguments which
are formatted to produce the error message.
|
|
|
| |
We were printing the error message but returning success.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Closes: #1106
Ported versioning system from [Binaryen CMakeLists.txt](https://github.com/WebAssembly/binaryen/blob/dc31b460fef47dfb3415b4ae6276fff4919a03e2/CMakeLists.txt#L10-L23)
```
bin/wasm2c --version
1.0.11-44-g71f883ad
```
Applied to (all) tools in `src/tools/`.
|
|
|
|
| |
You can now pass `--dummy-import-func` to `wasm-interp`, which will
provide a function that logs the call and returns zero.
|
|
|
|
|
|
| |
* Create src/interp/ directory
* Move Thread::Trace into src/interp/interp-trace.cc
* Move Environment::Disassemble into src/interp/interp-disassemble.cc
* Move shared code into src/interp/interp-internal.h
|
|
|
| |
The `--run-all-exports` flag assumed that all exports are functions.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
`ErrorHandler` complicated all error handling in wabt, since it was
callback-based. Callbacks would be useful if we ever wanted to change
behavior when an error occurred, but instead all that the handler ever
did was write the errors to stdout/stderr or to a buffer.
This change adds a new class `Error`, which contains an `ErrorLevel`, a
`Location` and an error message. It also replaces ErrorHandler with
`Errors` (a typedef for `std::vector<Error>`), and adds a couple of
functions that can format a list of `Errors` for output:
`FormatErrorsTo{String,File}`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Importing from host modules used to be handled by a delegate, which is a
powerful enough solution to allow for all host import behaviors, but
makes the common case difficult and clunky.
It also assumed that every imported function/global/etc. needed to be
newly created and added to the environment, which is OK (though
wasteful) for functions, but is incorrect for mutable values like
memories and globals.
This change simplifies the common case by providing a set of functions
on `HostModule` that can be used to add exports, e.g.
AppendFuncExport("add", {{Type::I32, Type::I32}, {Type::I32}},
AddFunc);
A generic interface for functions is provided as well, to allow for
automatically generating functions as needed. This is currently used for
functions like "host.print" in `wasm-interp`.
|
| |
|
|
|
| |
Closes #857
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If a wasm engine fails to parse a custom section, it must not be an
error. In wabt we often won't want to continue if a custom section can't
be parsed, but it still may be useful to be able to continue.
This change adds a new flag `--ignore-custom-section-errors` to
`wasm2wat` and `wasm-validate`, which will partially parse a custom
section with errors. This could lead to some strange behavior (partially
completed data structures), but generally should be safe to do.
See issue #378 and the discussion on pull #830 for more info.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Move `Thread::Run*` functions into `Executor`. The executor abstracts
over any execution, which will allow us to simulated multi-threaded
execution (which would be awkward to implement with an API on the
Thread object).
* Add `ExecResult` type which wraps an `interp::Result` and the results
from the function. There are too many things called `Result` now, so
perhaps some should be renamed. Not sure what to call them though.
* Expose some of the low-level functionality of `Thread` as public
member functions. This means that it is possible to get `Thread` into
an invalid state, but IMO that's OK since the assumption is that you
know what you're doing if you use the `Thread` API.
* Simplify value_stack and call_stack to use array indexes instead of
pointers.
* Remove the `call_stack_return_top`. This was used to handle calling
back and forth between the interpreter and the host, but this is not
currently done anywhere anymore. It's probably better to remove this
functionality until it is used (if ever).
|
|
|
| |
We already used `interp` in a few places, may as well be consistent.
|
|
|
|
|
|
|
| |
Also:
* Add `TypedValues` typedef (for `std::vector<TypedValue>`)
* Fix bug when displaying very large numbers in the interpreter; length
was capped at 100 characters
|
|
|
|
|
|
| |
* `wasm-interp` tool now only runs `.wasm` file, not spec tests
* `wasm-interp` has a new flag `--host-print` for importing a print
function named "host.print"
* `spectest-interp` tool runs only `.json` files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
wasm-objdump wants to always try to read as much of the binary as
possible. This change adds a new BinaryReader option called
stop_on_first_error which can be set to false to enable this behavior.
Currently this will bail on any error in a section, but will try to read
the next section. We may expand the error-handling behavior to try and
recover inside of a section as well, but it's probably best to keep it
simple for now.
Because wasm-objdump does multiple passes over the binary, the errors
would normally be displayed multiple times. We also add a OnError
override which will suppress the error message for all passes other than
the first.
|
|
|
|
|
| |
`.wat` files can only contain one module, and no assertions.
This fixes issue #621.
|
|
|
|
| |
* wat2wasm only parses wat files (individual modules)
* wast2json parses spec test files and generates json + wasm
|
| |
|
|
|
|
|
|
| |
* Mostly just updating test expectations
* Function signatures need to be checked as part of parsing (see
assert_malformed test in `testsuite/func.wast`; added
`ValidateFuncSignatures` for this.
|
|
|
|
|
| |
This removes a few more places we were using `delete`. I also checked
the emscripten build and found that the previous change to
`wabt::Result` broke this, so I fixed those too.
|
|
|
| |
This way the names won't conflict with other headers with the same name.
|
|
|
|
|
|
|
| |
* Unify all uses of `CHECK_RESULT`
* Use `CHECK_RESULT` in a few more places
* Add `operator|` and `operator|=` to `Result`, use it instead of
`COMBINE_RESULT`
* Change a few occurrences of `!Succeeded` to `Failed`
|
|
|
|
|
|
| |
* Create Import derived classes instead of using union
* Use cast/dyn_cast for interpreter Func and Module (Defined vs. Host)
* Remove OnImport callback in BinaryReaderInterpreter; do all the work
in the kind-specific callbacks (e.g. OnImportFunc)
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add saturating truncation operators as described here:
https://github.com/webassembly/nontrapping-float-to-int-conversions.
This change also codifies the mechanism for enabling new WebAssembly features
by passing the `Features` object. Opcode now has a `IsEnabled(const Features&)`
member function to query if the opcode is enabled. This means that the
`--future-exceptions` flag has been renamed to `--enable-exceptions` for
consistency. Checking whether the feature is enabled always happens at input;
either WastParser or BinaryReader.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Remove Bison dependency
* Remove pre-generated parser files
* Rename build config from no-re2c-bison to no-re2c
* Add a simple make_unique implementation
* Move handling of module bindings into ir.cc
* Simplify lexer
- Remove lookahead, the parser handles this now
- Unify Token/LexerToken, it only contains terminal values now
- Refactor setting token type and value into one function (e.g.
LITERAL, RETURN => RETURN_LITERAL)
* New Parser
- Uses two tokens of lookahead (use Peek(0) or Peek(1))
- Consume() consumes one token of any kind
- Match(t) consumes the current token if it matches
- PeekMatch(t) returns true iff the token matches, but doesn't consume
- Basic error synchronization; plenty of room for improvement here
|
| |
|
|
|
|
| |
There are no functional changes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This adds the `DataOrNull` function, which is used to get a std::vector
or std::string data(), but return `nullptr` if the container is empty. This
is needed because it is undefined behavior (at least according to ubsan)
if you call `data()` on an empty container.
It would be nicer to have the various read_* functions not take a void*,
size_t pair either, but that's work for another PR (perhaps introducing
a span-like API?)
I've also been considering having ReadFile return a wrapper object
instead, so this could just mmap the file.
Fixes #570.
|
|
|
| |
Use std::string or string_view instead.
|
|
|
|
|
|
|
|
|
|
| |
There's still more to be done, but this is a decent cleanup.
There is now a template type called `ValueTypeRep` which is the integer
representation of a given type. So for example, `ValueTypeRep<float>` =>
`uint32_t`.
Nearly all of the unary and binary operators are defined via template
functions that operate on these values.
|
|
|
|
|
|
|
| |
Since SourceErrorHandler can support binary locations, it doesn't make
much sense to have two different error handlers. There is now only an
ErrorHandler base class, and the first argument specifies whether the
error handler is expecting text or binary locations.
|