Expand description
llama
is a friendly LLVM wrapper
§Getting started
use llama::*;
// Convenience type alias for the `sum` function.
//
// Calling this is innately `unsafe` because there's no guarantee it doesn't
// do `unsafe` operations internally.
type SumFunc = unsafe extern "C" fn(u64, u64, u64) -> u64;
fn compile_sum(jit: &mut Jit) -> Result<SumFunc, Error> {
let i64 = Type::i64(jit.context())?;
let sum_t = FuncType::new(i64, [i64, i64, i64])?;
jit.declare_function("sum", sum_t, |build, f| {
let params = f.params();
let x = params[0];
let y = params[1];
let z = params[2];
let sum = build.add(x, y, "sum")?;
let sum = build.add(sum, z, "sum")?;
build.ret(sum)
})?;
unsafe { jit.engine().function("sum") }
}
fn main() -> Result<(), Error> {
let mut jit = Jit::new("sum", None)?;
let sum = compile_sum(&mut jit)?;
let x = 1u64;
let y = 2u64;
let z = 3u64;
unsafe {
println!("{} + {} + {} = {}", x, y, z, sum(x, y, z));
assert_eq!(sum(x, y, z), x + y + z);
}
Ok(())
}
Re-exports§
pub use llvm_sys as llvm;
Modules§
Macros§
- symbol
- Add symbols to the global namespace
Structs§
- Attribute
- LLVM Attribute
- Basic
Block - BasicBlock wraps LLVMBasicBlock
- Binary
- Binary is used to store compiled binary objects
- Builder
- A
Builder
is used to createInstruction
s - Codegen
- Platform-specific machine code
- Const
- Constant values
- Context
- Context wraps LLVMContext
- Execution
Engine - An execution engine can be used to execute JIT compiled code
- Func
- Functions
- Func
Pass Manager - PassManager for function optimizations
- Func
Type - Function type
- Instr
- Instruction value
- Instr
Alloca - Alloca instruction
- Instr
Call - Call instruction
- Instr
Fcmp - Fcmp instruction
- Instr
Gep - GEP instruction
- Instr
Icmp - Icmp instruction
- Instr
Indirect Br - IndirectBr instruction
- Instr
Phi - Phi instruction
- Instr
Switch - Switch instruction
- Jit
- Jit bundles LLVMContext, LLVMBuilder and LLVMExecutionEngine
- Memory
Buffer - Memory buffer wraps LLVMMemoryBufferRef
- Message
- Wraps LLVM messages, these are strings that should be freed using LLVMDisposeMessage
- Metadata
- Metadata values
- Module
- Wraps LLVMModule
- Module
Pass Manager - PassManager for module optimizations
- Struct
Type - Struct type
- Target
- LLVMTarget wrapper
- Target
Data - LLVMTargetData wrapper
- Target
Machine - Information about the target machine
- Type
- LLVMType wrapper
- Value
- LLVM Value wrapper
Enums§
- Atomic
Ordering - AtomicRMW
BinOp - Attribute
Index - Attribute placement index
- Binary
Type - Byte
Order - Call
Conv - Code
GenOpt Level - Code
Model - Diagnostic
Severity - Error
- An enumeration of all possible errors
- Fcmp
- Icmp
- Inline
AsmDialect - Linkage
- Module
Flag Behavior - OpCode
- Reloc
Mode - Thread
Local Mode - Unnamed
Addr - Visibility
Traits§
- LLVM
- Allows for llama types to be converted into LLVM pointers
- Pass
Manager - PassManager trait is used to define common functionality between the two types of PassManagers
Functions§
- add_
symbol - Add a symbol
- default_
target_ triple - Get the default target triple
- load_
library - Load a shared library