Open Araq opened 3 months ago
I believe that directly converting NIFC to cranelift would be a mistake, you need to create an intermediate nif layer (NIF-BB) that expresses the control flow through the basic blocks before doing so. Then writing the backend would be much easier and not as error prone.
My plan is to generate a NIF based syntax instead of cranelift's adhoc syntax. We can call that NIF-BB, yes.
Cranelift's tooling simply isn't ready for any of this. There is not even an assembler-like tool and the one I've written produces terrible error messages. There is no documention to speak of beyond "read the Rust code".
NIFC cannot only be translated to C. It can also be translated to Cranelift giving us native code without undefined behavior nonsense. Cranelift also offers a JIT for our compile-time needs.
If the dependency to Cranelift turns out to be a problem in the longer run, port its implementation to Nim, its IR is incredibly well designed ("SSA without the obscure Phi nodes") and simple yet powerful.