/cranelift_examples

A collection of examples using the Cranelift code generator

Primary LanguageRustMIT LicenseMIT

Cranelift Examples

A collection of examples using the Cranelift code generator.

I will try to keep these examples updated as I learn how to use Cranelift myself. Right now, I'm just getting started.

Examples

hello_object

[src]

This example shows the usage of the cranelift_object module to generate a native object file for a hello world program.

$ cargo run --example hello_object

This will generate a hello.o file in the out directory and compile it with clang into a.exe. A hello.clir file will also be genrated in the out directory containing a readable representation of the Cranelift IR that was generated.

hello_jit

[src]

This example shows the usage of the cranelift_jit module to compile a hello world function that can be used at runtime.

$ cargo run --example hello_jit
Hello, Sailor!

A hello.clir file will also be genrated in the out directory containing a readable representation of the Cranelift IR that was generated.

is_even

[src]

This example shows the usage of the brif instruction to implement a function that returns 1 if the input is even and 0 if it is odd.

$ cargo run --example is_even 42
even
$ cargo run --example is_even 69
odd