cargo-asm icon indicating copy to clipboard operation
cargo-asm copied to clipboard

Feature request: `cargo wat`

Open drewsilcock opened this issue 5 years ago • 5 comments

Being able to see and compare generated asm and LLVM IR is super useful. It would great to be able to have another command to show the generated .wat or .wast (i.e. WebAssembly in text format) output so that it could be directly compared against the assembly and LLVM IR.

Thanks for a great package!

drewsilcock avatar Sep 08 '19 21:09 drewsilcock

I'd kind of expected cargo asm --target=wasm32-unknown-unknown or similar to just work. Doesn't it ?

gnzlbg avatar Sep 09 '19 07:09 gnzlbg

If I just do cargo asm --target=wasm32-unknown-unknown or cargo asm --target=wasm32-wasi then I get a list of symbols as expected, but if I try to drill down into my particular function I get this:

$ RUST_BACKTRACE=1 cargo asm --target=wasm32-wasi nemolite2d_rs_lib::run_simulation
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }', src/libcore/result.rs:1165:5
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::default_hook
   2: std::panicking::rust_panic_with_hook
   3: std::panicking::continue_panic_fmt
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::result::unwrap_failed
   7: cargo_asm::asm::ast::Directive::new
   8: cargo_asm::asm::parse::function
   9: cargo_asm::asm::run
  10: cargo_asm::main
  11: std::rt::lang_start::{{closure}}
  12: std::panicking::try::do_call
  13: __rust_maybe_catch_panic
  14: std::rt::lang_start_internal
  15: main

$ RUST_BACKTRACE=1 cargo asm --target=wasm32-unknown-unknown nemolite2d_rs_lib::run_simulation
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::default_hook
   2: std::panicking::rust_panic_with_hook
   3: std::panicking::continue_panic_fmt
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::panicking::panic
   7: cargo_asm::asm::ast::Directive::new
   8: cargo_asm::asm::parse::function
   9: cargo_asm::asm::run
  10: cargo_asm::main
  11: std::rt::lang_start::{{closure}}
  12: std::panicking::try::do_call
  13: __rust_maybe_catch_panic
  14: std::rt::lang_start_internal
  15: main

drewsilcock avatar Sep 09 '19 08:09 drewsilcock

I should probably include additional information:

$ cargo asm --version
cargo-asm 0.1.16
$ rustc --version
rustc 1.39.0-nightly (c6e9c76c5 2019-09-04)
$ cargo --version
cargo 1.39.0-nightly (22f7dd049 2019-08-27)

drewsilcock avatar Sep 09 '19 08:09 drewsilcock

Ah yes, that makes sense.

cargo asm is trying to parse the assembly output from rustc like as if it was the assembly output from another target, which they all follow very similar formats.

For WASM, rustc assembly output probably outputs WASM textual format right ?

I think this wouldn't be hard to implement. We just need to detect whether the target is a WASM target, and then use a different parser / AST for the WASM textual-format, of which I suppose there are many Rust crates available for that.

gnzlbg avatar Sep 09 '19 08:09 gnzlbg

:+1: supporting cargo asm --target=wasm32... would be great.

osa1 avatar Aug 24 '21 09:08 osa1