binaryen
binaryen copied to clipboard
Can't have drop's and unreachable's?
Hey, I am trying to use Wasm-as to parse some .wat files to .wasm. Multiple of them include drop's, and wasm-as toss an error on the line of the drop every time. Is there any way around this issue?
An example:
(i32.load ;; load int from elem pos
(i32.load ;; load data pointer
(global.get $var_arr) ;; get local var: var_arr, have been hoisted
)
(i32.add ;; add offset to base address
(i32.mul ;; multiply index with byte offset
(i32.const 0) ;; push 0 on stack
(i32.const 4) ;; byte offset
)
)
)
(drop)
The error:
Loading 'test.wat'...
s-parsing...
w-parsing...
[parse exception: expected more elements in list (at 214:4)]Fatal: error in parsing input
It is the same problem with unreachable.
See the comment about the text format here:
Consequently Binaryen's text format allows only s-expressions.
So it can parse (drop (foo))
but not (foo) (drop)
, because the latter is not nested like s-expressions are.
Work on a new parser is underway, but for now you can use wabt
or another parser.
@kripken - I want to use WasmGC features and to my understanding, wasm-as is, at the moment the only wat-to-wasm parser that has implemented WasmGC?
Oh, yeah, if you need WasmGC atm then options are limited. In that case it might be simplest to use s-expressions, which are supported in Binaryen's text format. The add and the load etc. in your example code are all properly nested, so maybe you are close to that already?
(Btw, it might help to see the code samples in the test suite for what Binaryen supports. For example you can find examples of drop
being used in the .wat
files under test/
.)
@trolund wasm-tools parse
(from wasm-tools) also supports WasmGC.
This is a pretty old issue, but these days you can also use --new-wat-parser
to parse the standard text format. This will become the default soon (see #6208).
Closing this issue because the question is answered.