wasm-as should allow top-level `module` wrapper to be omitted
As per https://webassembly.github.io/spec/core/text/modules.html#id10, this is a valid wat file:
(func $f)
However wasm-as is more strict:
[parse exception: toplevel does not start with module]Fatal: error in parsing input
(Feel free to close if I misunderstood what input language wasm-as should accept :)
My goodness. I didn't realize that wasm-as only takes a subset of wat as input. Notably it's impossible to branch with a value and then do something to it:
$ cat /tmp/test.wat
(module
(func $f (result i32)
(block (result i32) (i32.const 1) (br 0))
(i32.add (i32.const 41))))
$ wasm-as -o /tmp/test.wasm /tmp/test.wat
[parse exception: expected more elements in list (at 4:7)]Fatal: error in parsing input
I don't see a way to use br_if_cast from wat, if we can't use implicit stack values.
I have a side project under way to write a new text parser that is more spec compliant. You can try it out with --new-wat-parser, although it's not yet complete.
The problem with your branching example is that the (i32.const 1) should be nested under the (br 0) like this: (br 0 (i32.const 1)). Binaryen's legacy text parser requires the wat to be fully nested like that.
FWIW in my example even if you nest the passed value inside the br, that the use of the value in the i32.add doesn't work. However Jakob Kummerow kindly pointed out that you could use the block as a value:
(module
(func $f (result i32)
(i32.add (block (result i32) (br 0 (i32.const 1)))
(i32.const 41))))
Good to know there is a workaround.