Hello! I'd like to try using Cranelift for a compiler for a toy language I've been working on. The compiler is written in Java, and I was wondering whether there were any recommended ways of using Cranelift in non-Rust projects?
Rather than trying to write bindings to the Cranelift API, I thought the better approach might be to generate .clif
IR files, and then to compile those to object files. In other words, the equivalent of llc -filetype obj
for LLVM. I had a quick search around, but couldn't find such a CLI: does it exist already and I just missed it, or is that something I'd need to write myself?
I cobbled something together quickly that seems to do the right thing (although I haven't tested it properly yet): https://github.com/mwilliamson/cranelift-compiler
Happy to have any foolishness in the approach or implementation pointed out!
Ah, evidently my prior searching was subpar: it looks like .clir
files can only represent functions, not entire modules: https://github.com/bytecodealliance/wasmtime/issues/2285
Which arose from a previous discussion of using Cranelift from a non-Rust project: https://bytecodealliance.zulipchat.com/#narrow/stream/217117-cranelift/topic/using.20cranelift.20as.20a.20backend.20for.20a.20non-rust.20compiler/near/212909451
Last updated: Dec 23 2024 at 12:05 UTC