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

Extend wast2wasm4cpp to also work with Rust sources #593

Closed
axic opened this issue Oct 9, 2020 · 0 comments · Fixed by #704
Closed

Extend wast2wasm4cpp to also work with Rust sources #593

axic opened this issue Oct 9, 2020 · 0 comments · Fixed by #704
Labels
hacktoberfest Selected for Hacktoberfest

Comments

@axic
Copy link
Member

axic commented Oct 9, 2020

wast2wasm4cpp is a tool proccessing .cpp files, which looks for a specific comment containing wasm source code and updates the binary code below it, e.g.

    /* wat2wasm
    (func (param i64) (result i64)
      (local i64)
      get_local 0
      set_local 1
      get_local 1
    )
    */
    const auto wasm =
        from_hex("0061736d0100000001060160017e017e030201000a0c010a01017e2000210120010b");

Here the source are the lines below /* wat2wasm and, the tool fills in the binary hex string within the from_hex() call.

Change this tool to emit Rust-compatible output if the filename is .rs:

    /* wat2wasm
    (func (param i64) (result i64)
      (local i64)
      get_local 0
      set_local 1
      get_local 1
    )
    */
    let input = hex::decode("0061736d0100000001060160017e017e030201000a0c010a01017e2000210120010b").unwrap();

Please note it must also run cargo fmt after the replacement, just like it runs clang-format for C/C++ sources.

@axic axic added the hacktoberfest Selected for Hacktoberfest label Oct 9, 2020
@gumb0 gumb0 closed this as completed in #704 Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Selected for Hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant