wasm2lua
wasm2lua copied to clipboard
Graph IR
Began work on an IR today. It is locked behind a compiler flag (--useGraphIR
) to facilitate easy testing + continued development alongside the main branch. It currently does not work at all.
- [x] Convert WASM control flow to graph IR.
- [x] Add all instructions to IR (No good dataflow yet, just for testing control flow).
- [ ] Test basic control flow. (Just link blocks together with gotos for now)
- [ ] Local dataflow: Each control block tracks which locals it uses, and the values locals are bound to when they terminate.
- [ ] Better control flow code generation.
- [ ] Proper bounding of variable lifetimes.
- [ ] Handling for very large jumps.
- [ ] Proper handling of setjmp/longjmp (setjmp should split control blocks).
Other thoughts:
- Planning to deal with block results by creating an extra pseudo-local and throwing it in block outputs.
- Track nesting to avoid the parser throwing a fit. Might be able to decompose expressions that are too large by creating a small scope with temp vars.
- Track estimate of LJ opcodes to avoid large jumps.
- Might be able to convert some loops into lua for loops.
- Maybe convert some blocks to functions? I'm not sure how the JIT feels about lambdas, will need to test.
Progress is being made on adding instructions to IR. Yet to do:
- ~~Indirect calls.~~
- ~~All memory reads/writes.~~
- ~~Global reads.~~
- ~~All conversions.~~
- ~~Select.~~
- ~~grow_memory / current_memory~~
- ~~"bitwise" float ops (neg, abs, copysign)~~
- ~~(Temp) local init~~
Some minor TODOS:
- Write barriers are broken trash.
- I started on a function for stripping parens from statements that don't need them (function args and the like) but never finished it.
Todo: Bools should be preserved for select opcode.