Stream: cranelift

Topic: Using Cranelift from Java / Cranelift CLI


view this post on Zulip Michael Williamson (Mar 30 2024 at 13:50):

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?

view this post on Zulip Michael Williamson (Mar 30 2024 at 20:58):

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!

Compiles `.clir` IR files into object files. Contribute to mwilliamson/cranelift-compiler development by creating an account on GitHub.

view this post on Zulip Michael Williamson (Mar 30 2024 at 21:06):

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

Feature Define a textual representation of a cranelift module that is like the current clir ir text form, but with added support for defining data objects, importing extern functions and data objec...

Last updated: Nov 22 2024 at 16:03 UTC