3 ms·
A primer on code generation in Cranelift
- rajandatta 5y agoThanks for sharing. Very interesting. I wasn't aware of Cranelift. Will read. What are people's thoughts on the current state of the art in using Cofe generation for higher level and lower level development?
- 0x000000E2 5y agoThere's a lot of JIT's using LLVM for code generation. Including some shader compilers, Azul's JVM, and I believe Safari's JS. DynASM is another popular library, used by Lua and others. Crane lift was originally designed for WASM but Rust developers have taken a liking to it My favorite flavor of code-gen is within VM based languages though. I'm most familiar with Java, where there's a rich set of libraries for generating code at build and run time. Codegen within JIT'ed languages is really cool because the new code is patched into the existing code with profile guided optimizing compilers. A lot of popular libraries use it. And it's nice to know it's there if you need to build up say a deserializer or rules engine with maximum performance.
- zinclozenge 5y agoI'd love it if there was a guide/tutorial on how to use it as an alternative to LLVM.
- runevault 5y agoI dunno that it is meant to be a full on replacement. Rust intends to use it as an alternative backend for debug builds that focuses on really fast build times with little if any optimizations.
- zinclozenge 5y agoIt's not, but I'm also not intending to write a production grade language either.
- winter_blue 5y agoJust FYI, there's an LLVM tutorial (for C++), but it's quite succinct, and you have to figure a lot of things out on your own: https://llvm.org/docs/tutorial/ https://llvm.org/docs/tutorial/
- winter_blue 5y agoIt looks this is used for WASM development, and it's built by the Bytecode Alliance[1]. One thing I want to see in the future (for use by programming language designers), is some convenient relatively-stable way to target the Rust MIR or the Rust HIR[2], directly. [1] https://github.com/bytecodealliance/wasmtime/tree/main/cranelift#cranelift-code-generator https://github.com/bytecodealliance/wasmtime/tree/main/crane... [2] https://blog.rust-lang.org/2016/04/19/MIR.html https://blog.rust-lang.org/2016/04/19/MIR.html