Crates.io | silly-wat-linker |
lib.rs | silly-wat-linker |
version | 0.7.1 |
source | src |
created_at | 2022-07-25 12:48:38.257447 |
updated_at | 2023-02-25 01:23:56.80094 |
description | A tool that makes writing WebAssembly Text files easier. |
homepage | |
repository | https://github.com/surma/silly-wat-linker |
max_upload_size | |
id | 632533 |
size | 104,269 |
SWL is a tool that makes writing WebAssembly Text files easier.
It is future-proof and simple because it doesn’t actually understand WAT. Instead, it is a simplistic S-Expression parser and uses surface-level pattern matching to implement its features. This way, future iterations of WAT with new syntax are unlikely to break this tool.
WAT is the WebAssembly Text format and is defined in the WebAssembly spec.
SWL can be installed from Cargo:
$ cargo install silly-wat-linker
All work is done on the textual representation. SWL can invoke wabt’s wat2wasm
for you to produce a binary file instead:
$ silly-wat-linker ./main.wat # Emits .wat test file
$ silly-wat-linker -c ./main.wat # Emits .wasm binary
SWL has a handful of features to make your life easier when hand-writing WAT files. Most features are enabled by default, but you can explicitly select which features to enable using the --features
flag.
# This will only run the `size_adjust` and `sort` feature.
$ silly-wat-linker --features size_adjust,sort ./my-file.wat
import
)Adds support for importing another .wat file into the current one.
(module
(import "other_file.wat" (file))
;; ...
)
data_import
)Allows you to import other files as data segments.
(module
(data (i32.const 1024) (import "other_file.wat" (raw))
;; ...
)
constexpr
)Adds const expressions to WAT, allowing evaluation of complex expressions at compile time. Globals that aren’t themselves using const expressions are available.
(module
(global $DATA_PTR i32 (i32.const 0x4000))
(data
(i32.constexpr
(i32.add
(global.get $DATA_PTR)
(i32.const 0x100)))
"My data")
;; ...
)
Also supported specifically for the offset
attribute for store
and load
operations:
(module
(func
(i32.store
offset=(i32.constexp
(i32.add
(i32.const 0x123)
(i32.const 0x100)))
(i32.const 4)))
;; ...
)
size_adjust
)Automatically adjust the size of memory
directives to be big enough to hold all active data
segments. (This feature is also supposed to do the same for tables
and elem
segments, but this hasn’t been implemented yet.)
start_merge
)If there are multiple (start)
directives (which can easily happen in a multi-file project), SWL will create a new, singular start function that calls all the other start functions.
sort
)Sorts all top-level module segments so that imports come first. This feature mostly exists because wat2wasm
requires imports to come first.
License Apache-2.0