were / trinity

Constructing LLVM IR in Rust w/o bindings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trinity: Building LLVM-IR in Rust without Binding

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:

  1. llvm-sys is a C-Rust bind for the C interfaces exposed by LLVM, which suffers from infinte unsafe annotations.
  2. inkwell wraps all those C-interfaces with Rust native data structures to get rid of unsafes, 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, and inkwell is a subset of llvm-sys. I need a full control to the struct fields.
  3. 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.

About

Constructing LLVM IR in Rust w/o bindings.


Languages

Language:Rust 100.0%