9

There's plenty of info on compiling to WebAssembly from languages like C++ or Rust, F.e. there's plenty of search resuilts on LLVM to Wasm, but what about WASM to LLVM.

But is there a way to compile from WebAssembly to regular assembly (or other "native" languages like C++ or ASM)?

Note, this is not a duplicate of How to convert javascript to LLVM IR?. This issue is not about converting JavaScript to native code, it is about converting WebAssembly to native code (f.e. native machine code). JavaScript and WebAssembly are different things.

trusktr
  • 44,284
  • 53
  • 191
  • 263
  • A possible duplicate from this https://stackoverflow.com/questions/34313561/how-to-convert-javascript-to-llvm-ir ? – Amadeus Jun 01 '19 at 04:36
  • @Amadeus As far as I understand the linked question and its answers correctly, it is only about tools that can convert JavaScript to native code. These tools seem not to be able to convert WebAssembly to native code. – Martin Rosenau Jun 01 '19 at 04:45
  • There are decompilers. Of course you can't create a regular assembly automatically. But possibly with (probably not insignificant) manual effort (I didn't try it myself): https://www.pnfsoftware.com/jeb/#wasm – Stephan Schlecht Jun 01 '19 at 16:45
  • Most browsers turn WebAssembly into regular machine language. – Lee Jun 04 '19 at 06:35
  • @Amadeus Maybe it isn't a duplicate, because JavaScript is not the same as WebAssembly. – trusktr Jun 05 '19 at 18:16

1 Answers1

5

There are few experimental facility exist. The Liftoff (google V8 embedded) compiler for WebAssembly must be doing this task internally; I am not aware of any exposed V8 API for application to use it for this task.

Lucetc says, it can compiles WebAssembly modules (.wasm or .wat files) into native code (.o or .so files). https://github.com/fastly/lucet

wasm2c: says, it can convert wasm files to C source and header https://github.com/WebAssembly/wabt/tree/master/wasm2c

Satyan
  • 1,346
  • 8
  • 15
  • 1
    Ah, interesting. Thanks for sharing those! Exactly what I asking about. I will expand on this answer if I find more. – trusktr Jun 05 '19 at 18:20