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

SwiftWASM REPL - allow import of WebAssembly.Memory #5431

Open
kerimcharfi opened this issue May 11, 2023 · 0 comments
Open

SwiftWASM REPL - allow import of WebAssembly.Memory #5431

kerimcharfi opened this issue May 11, 2023 · 0 comments

Comments

@kerimcharfi
Copy link

kerimcharfi commented May 11, 2023

Motivation
In order to make SwiftWasm more debuggable a SwiftWasm REPL is needed. This would also be very helpful for debug tools.
Solution
My Idea to make this happen with as little effort as possible for the swiftwasm maintainers while still having the maximum of flexibility for debugging tools is the following:

prerequisit: there is a paused (dummy or real) SwiftWasm main module inside of a wasm runtime xy

  1. A REPL prompt text is submitted
  2. analyse the current callframe of the main module and extract variable names and their pointers from DWARF
  3. swift codegen: wrap REPL prompt in a exported function with raw pointers to all reachable variables as function parameters
  4. compile the wrapped REPL prompt with SwiftWASM into a new wasm module. Lets call it "side module"
  5. load side module into runtime
  6. import WebAssembly.Memory from paused main module into the compiled side module
  7. call the exported generated repl wrapper function from side module and pass pointers of the reachable variables into the function
  8. add newly declared variables (found by dwarf in generated side module) to some kind of REPL session
  9. go back to step 0

Im currently blocked by step 5: importing a external WebAssembly.Memory into a Module compiled by SwiftWasm

I'm having problems with runtime initialization of the sidemodule crashing.

Whats needed

What I need to proceed is something similar to emscripten side modules.
Ideally theres also no swift runtime linked inside of a side module to improve performance by reducing parsing time and no call to the runtime initialization, which would f*** up the state of the runtime of the main module.

Questions

Are there already flags to avoid linking everything?
Can someone explain what happens inside __wasm_call_ctors?

Update

step 5 is not an issue anymore

▿ repl.astruct
  - myinti: 9
  - myfloat: 42.0
  ▿ mystruct: repl.aNestedStruct
    - a: 5

This is the first successful dump of a nested struct from a "sidemodule".
However, I need something like AssemblyScripts --memoryBase linker flag in order to proceed with my hacky prototype.

@kerimcharfi kerimcharfi changed the title SwiftWASM REPL / LLDB SwiftWASM REPL May 11, 2023
@kerimcharfi kerimcharfi changed the title SwiftWASM REPL SwiftWASM REPL / import WebAssembly.Memory May 11, 2023
@kerimcharfi kerimcharfi changed the title SwiftWASM REPL / import WebAssembly.Memory SwiftWASM REPL - allow import of WebAssembly.Memory May 11, 2023
@kateinoigakukun kateinoigakukun moved this to To triage in Yuta's project Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

No branches or pull requests

1 participant