6 releases (3 breaking)
0.5.0 | Sep 8, 2024 |
---|---|
0.4.0 | Aug 27, 2024 |
0.3.2 | Jul 8, 2024 |
0.2.0 | May 31, 2024 |
#1228 in Programming languages
370 downloads per month
465KB
11K
SLoC
LLVM Dialect for pliron
This crate provides the following functionality:
- Dialect definitions of LLVM ops, types and attributes.
- A wrapper around llvm-sys converting to and from our LLVM dialect. This necessitates that LLVM be installed locally.
We currently support LLVM-18, and hence LLVM-18 needs to be on your computer.
On Ubuntu, this means, you require the libllvm18
and libpolly-18-dev
packages.
llvm-opt tool
The llvm-opt
binary is provided to enable parsing LLVM bitcode binaries
into pliron
's LLVM dialect and to emit LLVM bitcode back from the dialect.
Example usage:
-
Compile fib.c into LLVM-IR:
$clang-18 -c -emit-llvm -o /tmp/fib.bc tests/resources/fib.c
-
Convert the LLVM bitcode to LLVM dialect in
pliron
and back to LLVM bitcode (the binaryllvm-opt
, produced in your cargo's target directory must be in $PATH):$llvm-opt -S -i /tmp/fib.bc -o /tmp/fib.opt.ll
-
Compile the output fibonacci LLVM-IR, along with a main function into a binary:
$clang-18 -o /tmp/fib /tmp/fib.out.ll tests/resources/fib-main.c
-
Run the fibonacci binary to see the first few fibonacci numbers printed.
$/tmp/fib
fib(0): 0 fib(1): 0 fib(2): 1 fib(3): 1 fib(4): 2
Note: Implementation of the LLVM dialect is not complete, and the above is just a proof-of-concept.
Dependencies
~5–7MB
~131K SLoC