| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
| |
This makes things easier for users and packagers of libwabt.
|
| |
|
|
|
|
|
| |
Now that we have C++17 we don't need our own string_view class anymore.
Depends on #1825
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
See #1189 and #1311. Even if bulk memory is enabled, it can be
convenient to omit the DataCount section for MVP compatibility.
This change only includes the DataCount section when an instruction
requires it; either `data.drop` or `memory.init`. It is also omitted if
there are no data segments.
Rather than doing a second pass on the instructions, this implementation
unconditionally writes the DataCount section, but removes it when it is
not needed. This required adding a function to truncate a stream
(Stream::Truncate).
|
|
|
|
|
|
|
|
|
| |
This really de-tangles the code, as in-line assignments are
hard to read.
To make this possible, I had to track the current stack depth, take
into account unreachable paths and a few other support features.
Also added debug output upon assert.
|
|
|
|
| |
I also fixed some for/if to use braces if I noticed it. This is a
non-functional change.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add `wasm2c`, a new tool that reads a `.wasm` file and generates a C
source file and its accompanying header file. The C output currently
only supports gcc/clang compilers, since it uses builtins for some
functionality.
The resulting C code is not standalone; there are runtime functions that
must be provided, as well as pointers to all imports.
The C runtime symbols that must be provided are as follows:
* `void wasm_rt_trap(wasm_rt_trap_t code)`:
Called when the WebAssembly code traps. This function must not return.
* `u32 wasm_rt_register_func_type(u32 param_count, u32 result_count, ...)`:
Register a function type with the given signature. This function must
check whether this signature has already been registered and return
the original index.
* `void wasm_rt_allocate_memory(wasm_rt_memory_t*, u32 initial, u32 max)`:
Allocate the memory buffer for the given memory object, given the
number of pages. The memory must be zeroed before returning.
* `u32 wasm_rt_grow_memory(wasm_rt_memory_t*, u32 delta)`:
Grow memory by the given number of pages. If allocation fails, or the
new pages size is larger than the maximum, return -1. Otherwise return
the previous number of pages. The newly allocated memory must be
zeroed.
* `void wasm_rt_allocate_table(wasm_rt_table_t*, u32 initial, u32 max)`:
Allocate the buffer for the given table object. The buffer must be
zeroed before returning.
* `u32 wasm_rt_call_stack_depth`:
A symbol that tracks the current call stack depth. If this value
exceeds `WASM_RT_MAX_CALL_STACK_DEPTH` then a trap occurs. This value
defaults to 500, but can redefined.
An example implementation can be found in `spec-wasm2c-prefix.c`.
All functionality from the WebAssembly MVP is supported, and the
generated code passes all of the core spec tests. There is a new test
tool called `run-spec-wasm2c.py` which runs the following:
* `wast2json` to convert the spec test to json and wasm files
* `wasm2c` to convert the wasm to C source and headers
* a C compiler (default `cc`) to compile and link all C source files,
including a C test runner (`spec-wasm2c-prefix.c`)
* Finally, the resulting executable to produce output
|
| |
|
|
|
|
|
|
| |
* Remove Writer class, move functionality into Stream
* Fix emscripten build
|
|
|
| |
This way the names won't conflict with other headers with the same name.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Simplify some of the code using map instead of vector. Also added the
ability to count immediates of any opcode.
* Add ubsan blacklist, because stl_tree is broken in older libstdc++
implementations. This also requires a clang upgrade, since clang 3.5 is
too old to support blacklists w/ ubsan.
* Fix FileStream move constructor; this was incorrect, but worked on gcc/clang
because the actual move was elided.
* Use MATRIX_EVAL to bypass CC being set by `compiler` in `.travis.yml`
|
|
|
|
|
| |
It's a value type, so it should be passed by value, just like int, etc.
For x64-clang linux ABI, it seems to be passed in two registers rather
than requiring indirection, so may be faster too.
|
|
|
|
|
|
| |
This previously had an upper limit to the extension length.
I've also taken this opportunity to modify the Writer and Stream APIs to
take `string_view` instead of `const char*` for filenames.
|
|
|
|
|
|
|
|
| |
* Remove WABT_ZERO_MEMORY WABT_FAILED and WABT_SUCCEEDED macros.
* Add source generated files.
* Add pod check.
|
|
|
|
|
|
|
| |
Use the virtual address (init offset) when display
the data rather that the file offset.
Show the segment size in the header.
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
| |
Also switch to using C++11.
|
|
Mostly this involves adding additional casts. Though there are a few
more substantial changes:
* The default method for relocating parser stacks no longer works
because Bison assumes that C++ values can't be memcpy'd. Ours can, but
there's no easy way to make the generated code do the right thing, so
we do it manually
* Removed all uses of WabtBool and replaced with bool
* Renamed all uses of export and mutable -> export_ and mutable_
* Casting an invalid value to an enum triggers ubsan, so we have to be a
little more careful about when we do it (see binary-reader.c:read_sections())
* It's illegal to forward-declare enums, so we just #include instead.
* Designated initializers are not allowed in g++, so we have to switch
them to lazily initialized structures instead. Pretty horrible, so it
will be nice to have a better solution for C++.
|