Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't have drop's and unreachable's? #6133

Closed
trolund opened this issue Nov 24, 2023 · 5 comments
Closed

Can't have drop's and unreachable's? #6133

trolund opened this issue Nov 24, 2023 · 5 comments

Comments

@trolund
Copy link

trolund commented Nov 24, 2023

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.

@trolund trolund changed the title Can't have drop's? Can't have drop's and unreachable's? Nov 24, 2023
@kripken
Copy link
Member

kripken commented Nov 24, 2023

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.

@trolund
Copy link
Author

trolund commented Nov 24, 2023

@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?

@kripken
Copy link
Member

kripken commented Nov 24, 2023

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/.)

@xortoast
Copy link

@trolund wasm-tools parse (from wasm-tools) also supports WasmGC.

@tlively
Copy link
Member

tlively commented Apr 15, 2024

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.

@tlively tlively closed this as completed Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants