Module llvm

Source
Expand description

§LLVM IR lowering

Lower irvm IR to LLVM IR.

The main functions to use are lower_module_to_llvmir which gives you a CompileResult.

With this result you can either write it to a file (.ll), compile it to an object file or create a JIT Engine to execute methods (a bit limited currently, useful for testing).


// Lower the module.
let result = lower_module_to_llvmir(&mymodule, &my_type_storage)?;

// Output to a file as a .ll
output_to_file(&result, Path::new("out.ll"))?;

// Compile to an object file.
compile_object(&result, &mymodule.target_triple, CompileOptions::default(), Path::new("out.o"), false)?;

// Or create a JIT engine.
let engine = create_jit_engine(result, 3)?;
let res = unsafe { engine.execute("main", &[JitValue::U32(4)], JitValue::U32(0))? };

Structs§

CompileOptions
Compile options to generate the object file.
CompileResult
A compile result from lowering a given Module.
JitEngine
A prepared JIT engine.

Enums§

CodeModel
The code model supported by LLVM.
Error
A possible Error.
JitValue
Possible value/types to pass to the JIT engine execute method.
OptLevel
The optimization level to use.
OutputCompilation
RelocModel
The relocation model types supported by LLVM
TargetCpu
The target LLVM cpu.
TargetCpuFeatures
The target LLVM cpu features.

Functions§

compile_object
Compiles the given llvm compile result to an object or assembly file.
create_jit_engine
Creates a jit engine for the given compile result.
lower_module_to_llvmir
Lowers the given module to llvm ir.
output_to_file
Outputs the given compile result to a llvm ir file.