3 ms·
This looks much nicer than the wasm2c output for that binary. I compiled it with `clang wasm.c -c -target wasm32 -O2` just like in the instructions (I'm on LLVM
by snazz 7y ago
This looks much nicer than the wasm2c output for that binary. I compiled it with `clang wasm.c -c -target wasm32 -O2` just like in the instructions (I'm on LLVM 10), and used the latest wasm2wat with `wasm2wat -f wasm.o` and got this instead:
(module
(type (;0;) (func (param i32 i32) (result f32)))
(import "env" "__linear_memory" (memory (;0;) 0))
(import "env" "__indirect_function_table" (table (;0;) 0 funcref))
(func (;0;) (type 0) (param i32 i32) (result f32)
(f32.add
(f32.add
(f32.mul
(f32.load
(local.get 0))
(f32.load
(local.get 1)))
(f32.mul
(f32.load offset=4
(local.get 0))
(f32.load offset=4
(local.get 1))))
(f32.mul
(f32.load offset=8
(local.get 0))
(f32.load offset=8
(local.get 1))))))
wasm2c (also from WABT) returns this thing: https://paste.linux.community/view/7877995f https://paste.linux.community/view/7877995f
- Aardappel 7y agowasm2c has a different objective though: to be recompile-able again while preserving semantics. wasm-decompile was designed for readability first.
- snazz 7y agoFair enough. I’m still surprised at just how unreadable (for me) the wasm2c output was, though. The compiler must have done quite a bit of optimizing that wasm2c was unable to undo.
- Aardappel 7y agoIt doesn't actually try to undo anything, it just translates Wasm instructions 1:1 (they're in your link at lines 205-221). wasm-decompile does try to "undo" some thing, but it is generally impossible given LLVM's optimized output and how low-level Wasm is (see also article).
- snazz 7y agoOkay, that makes sense.