A safer wrapper for the LLVM C API bindings in Rust, based on llvm-sys
Notes on Safety
Although there are no unsafe
blocks needed to use this library, it does ignore some of Rust's
constraints on memory management. Mainly, immutable references can still be modified in order
to make certain programs more simple.
To make things simple, LLVMBuilder
and LLVMModule
are disposed automatically when they leave
scope. Values and types are always created in the default global context provided by LLVM.
If necessary, it is possible to use the inner
function to access the wrapped value, or
into_inner
to destroy the wrapper without disposing the contained value. Most types can also
dereference into their C equivalents. This crate is still in development and many features are
not fully supported, so use this if you need to use unsupported LLVM functions. Use into_c
and from_c
to make strings easier to work with when dealing directly with the C API.
Setup
This crate relies heavily on llvm-sys
and requires the same setup. Before using this crate,
be sure to install a version of LLVM 5 and add LLVM_SYS_50_PREFIX=/path/to/llvm
to your PATH
environment variable.
LLVM Documentation | LLVM Language Reference | Rust Bindings
Example
# extern crate llvm_wrap as llvm;
# use *;
# use *;
#
Output
; ModuleID = 'add'
source_filename = "add"
define i32 @add(i32 %a, i32 %b) {
entry:
%tmp = add i32 %a, %b
ret i32 %tmp
}