Compile to Webassembly #674
Replies: 2 comments 5 replies
-
That is very cool! I was wondering about this but I always assumed libgmp would be a right pig to compile to wasm. Do you think you could provide a script or something (maybe a Dockerfile) to show all of your steps?
Yes! I have actually made a basic frontend for our internal use for this: It's not as fancy as rvcodec.js but it's useful for instructions that that doesn't have. It also decodes CHERI capabilities Currently I just execute a native binary but it would be nice to use WASM. I think it would also be very cool to make an interactive emulator where you can load some example ELFs and then step through the assembly, and it would show all the register values and memory accesses and so on. That's kind of a huge project though. |
Beta Was this translation helpful? Give feedback.
-
An entirely different approach is to compile the Sail into OCaml and then use Js_of_ocaml to run the OCaml bytecode as javascript. That's how the RISC-V support in RMEM was implemented e.g. this RISC-V concurrency test but it's quite a bit out-of-date now. |
Beta Was this translation helpful? Give feedback.
-
I did some interesting experiments and proved that it is possible to compile sail to WebAssembly. Maybe it can be of some help
Compile Steps
Prepare emscripten (which uses the llvm webassembly target)
Prepare zlib (compiled with emscripten), gmp, softfloat
Compile sail model
replace libs to wasm
replace gcc with emcc
Output
size 4.3M
Show
run it on web
But wasm can't access file system (I found some information saying you can package files together with wasm), the experiment ends here
Beta Was this translation helpful? Give feedback.
All reactions