nim-lang / nif

NIF is a text based data format designed for compiler frontend/backend communication or communication between different programming languages.
MIT License
32 stars 2 forks source link

NIFC: Translate to Cranelift #41

Open Araq opened 2 weeks ago

Araq commented 2 weeks ago

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.

ASVIEST commented 2 weeks 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.

Araq commented 2 weeks ago

My plan is to generate a NIF based syntax instead of cranelift's adhoc syntax. We can call that NIF-BB, yes.

Araq commented 2 weeks ago

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".