Hacker News new | past | comments | ask | show | jobs | submit login
A primer on code generation in Cranelift (benj.me)
63 points by bzbarsky on May 8, 2021 | hide | past | favorite | 7 comments



It 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/crane...

[2] https://blog.rust-lang.org/2016/04/19/MIR.html


Thanks 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?


There'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.


I'd love it if there was a guide/tutorial on how to use it as an alternative to LLVM.


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


It's not, but I'm also not intending to write a production grade language either.


Just 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/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: