bytecodealliance / bytecodealliance/wasm-tools
Get end of module span
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 351
- Avg merge
- 16h 57m
- Merged PRs (30d)
- 38
Description
We're now going to use this crate to parse `.wast` scripts and convert them to specialized `.js` for testing in SpiderMonkey. [1]
One issue I ran into was how to output modules into JS. Ideally we'd output the module in text form, for easy debugging. The problem is how to get from a wast::Module to a text module.
I looked into two ways of doing this:
1. `wasmprinter::print(module.encode())` - this has the disadvantage that we lose info, such as $idNames. Additionally, some spec tests are changed semantically when round-tripped like this.
2. Use `module.span` and a handwritten scanner to mind the end of the S-expr for the module in the .wast file, then copying the string from the full-span.
(2) is the approach I went with and it works surprisingly well, once the scanner was written (look for `closed_module` in the phab diff. But I'm a little worried this is fragile, and it feels like getting the end of the span from the parser would be a better solution.
[1] https://phabricator.services.mozilla.com/D111306
Contributor guide
Assessment
This issue has not been assessed yet.