summaryrefslogtreecommitdiff
path: root/src/stream.cc
Commit message (Collapse)AuthorAgeFilesLines
* Move headers to include/wabt/ (#1998)Alex Reinking2022-09-281-1/+1
| | | This makes things easier for users and packagers of libwabt.
* wat2wasm: support "-" for outputting to stdout (#1692) (#1902)Remko Tronçon2022-04-201-0/+12
|
* Use C++17 string_view (#1826)Sam Clegg2022-02-111-4/+4
| | | | | Now that we have C++17 we don't need our own string_view class anymore. Depends on #1825
* Clang-format codebase (#1684)Heejin Ahn2021-12-201-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Omit the DataCount section unless it is required (#1312)Ben Smith2020-01-211-1/+32
| | | | | | | | | | | | | 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).
* wasm-decompile: Output Tee as Set+Get instead if possible. (#1165)Wouter van Oortmerssen2019-09-251-0/+4
| | | | | | | | | 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.
* Run clang-format over all the files (#814)Ben Smith2018-03-161-1/+0
| | | | I also fixed some for/if to use braces if I noticed it. This is a non-functional change.
* Add wasm2c tool (#710)Ben Smith2018-01-081-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [cleanup] Always use braces with if (#691)Ben Smith2017-12-091-10/+20
|
* Remove Writer class, move functionality into Stream (#613)Ben Smith2017-09-061-14/+138
| | | | | | * Remove Writer class, move functionality into Stream * Fix emscripten build
* Always include quoted headers like "src/foo.h" (#601)Ben Smith2017-08-301-1/+1
| | | This way the names won't conflict with other headers with the same name.
* Refactor wasm-opcodecnt. (#580)Ben Smith2017-07-241-0/+8
| | | | | | | | | | | | | | 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`
* Always pass string_view by value (#563)Ben Smith2017-07-101-1/+1
| | | | | 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.
* Clean up BinaryWriterSpec::GetModuleFilename (#560)Ben Smith2017-07-071-1/+1
| | | | | | 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. (#540)KarlSchimpf2017-06-281-2/+2
| | | | | | | | * Remove WABT_ZERO_MEMORY WABT_FAILED and WABT_SUCCEEDED macros. * Add source generated files. * Add pod check.
* Improve display of data segments (#520)Sam Clegg2017-06-231-3/+3
| | | | | | | Use the virtual address (init offset) when display the data rather that the file offset. Show the segment size in the header.
* Use C++ style C headers (e.g. <cstdlib>) (#431)Ben Smith2017-05-111-2/+2
|
* Refactor Stream/Writer; write as C++ (#399)Ben Smith2017-04-161-97/+67
|
* Move loop variable into for loop header (#347)Ben Smith2017-03-091-4/+2
|
* Replace the Wabt/wabt prefix with a C++ namespace (#331)Ben Smith2017-03-021-65/+66
|
* Make most enumerations into enum classes (#329)Ben Smith2017-03-011-6/+6
|
* Require C++-style casts, disallow C-style casts (#320)Ben Smith2017-02-271-2/+4
|
* Change NULL -> nullptr (#315)Ben Smith2017-02-241-3/+3
| | | Also switch to using C++11.
* Switch C files to CC files (#309)Ben Smith2017-02-231-0/+162
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++.