SwadicalRag / wasm2lua

wasm2lua: converting WASM into Lua
MIT License
194 stars 11 forks source link

Optimise br_if boolean casting #24

Closed SwadicalRag closed 5 years ago

SwadicalRag commented 5 years ago

(copied from discord)

if i were to do it i'll probably add an extra field inside a phantom register called lastBoolTransformation: string which is set (with the code snippet before it was converted into a bool) whenever a number is cast into a bool via an operation and then i'd add an extra parameter to getPop called shouldReturnBool and inside the function, if: 1) a phantom register is on the stack AND 2) lastBoolTransformation is set, return lastBoolTransformation 3) otherwrise, return (${phantomReg.value}) as normal

and in br_if, use that added parameter in getPop lastBoolTransformation is guaranteed to be only written once because phantom registers should only ever be assigned to once

SwadicalRag commented 5 years ago

Duplicate of #16