Why yet another LLVM-IR infrastructure in Rust?
Correct me if I am wrong. I had a hard time to find a crate that exactly fits my requirement. I want to write a LLVM and Rust based compiler tutorial, but:
- llvm-sys is a C-Rust
bind for the C interfaces exposed by LLVM,
which suffers from infinte
unsafe
annotations. - inkwell wraps all those C-interfaces
with Rust native data structures to get rid of
unsafe
s, but- I had a hard time to convert back-and-forth across their
{Any/Basic}{Value/Type}
s. - It makes me realize that both
llvm-sys
just exposes a subset of LLVM data structures, andinkwell
is a subset ofllvm-sys
. I need a full control to the struct fields.
- I had a hard time to convert back-and-forth across their
- llvm-ir can only do read and analysis, which is not a LLVM emitter.
Admittedly, I learned many from inkwell
's API design, and I hope this will be easier to use.
I will prove the usability of this set of APIs, through my compiler tutorial.
Another two major issues of using a bind library is the dependences and backward compatibility. Bind-free gets rid of the dependences of downloading a specific LLVM version. Moreover, as far as I observed, LLVM has very good backward compatibiilty on the IR side, but very poor compatibility on the developer side. Therefore, I believe the generated LLVM IR will be useful across as many versions as possible.
Where does the name Trinity come from?
I just merge the Context
, Module
, and IRBuilder
together
to both fit Rust's convention, and deal with the redundancy of LLVM IR data structures.