Go to file
2018-07-20 13:51:34 +02:00
cranelift@1c3601789d Add cranelift submodule 2018-07-15 20:30:03 +02:00
src Better comment handling 2018-07-20 13:51:34 +02:00
.gitignore Initial commit 2018-06-17 18:05:11 +02:00
.gitmodules Add cranelift submodule 2018-07-15 20:30:03 +02:00
.travis.yml Add RUST_BACKTRACE=1 to .travis.yml 2018-07-19 18:58:30 +02:00
0001-Disable-stdsimd-in-libcore.patch Better libcore building instructions and rustup 2018-07-19 18:41:37 +02:00
0002-Disable-u128-and-i128-in-libcore.patch Better libcore building instructions and rustup 2018-07-19 18:41:37 +02:00
build.sh Better libcore building instructions and rustup 2018-07-19 18:41:37 +02:00
Cargo.lock Add cranelift submodule 2018-07-15 20:30:03 +02:00
Cargo.toml Add cranelift submodule 2018-07-15 20:30:03 +02:00
example.rs Implement char to uint cast 2018-07-19 19:37:34 +02:00
LICENSE-APACHE Create LICENSE-APACHE 2018-06-22 19:33:35 +02:00
LICENSE-MIT Add LICENSE-MIT 2018-06-22 19:34:27 +02:00
prepare_libcore.sh Better libcore building instructions and rustup 2018-07-19 18:41:37 +02:00
Readme.md Add a known panic case 2018-07-19 19:08:37 +02:00
rust-toolchain Initial commit 2018-06-17 18:05:11 +02:00

Work in progress cranelift codegen backend for rust

⚠⚠⚠ This doesn't do anything useful yet ⚠⚠⚠

Building

$ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
$ cd rustc_codegen_cranelift
$ rustup override set nightly
$ git submodule update --init
$ cargo build

Usage

$ rustc -Zcodegen-backend=$(pwd)/target/debug/librustc_codegen_cranelift.so my_crate.rs --crate-type lib -Og

You must compile with -Og, because checked binops are not yet supported.

Building libcore

$ rustup component add rust-src
$ ./prepare_libcore.sh
$ ./build.sh

⚠⚠⚠ You will get a panic because of unimplemented stuff ⚠⚠⚠

Not yet supported

  • Checked binops

  • Statics

  • Drop glue

  • Building libraries

  • Other call abi's

  • Unsized types

  • Slice indexing

  • Sub slice

  • Closures

  • Some rvalue's

  • Inline assembly

  • Custom sections

Known errors

  • cranelift-module api seems to be used wrong, thus causing panic for some consts
  • cranelift-codegen doesn't have encodings for some instructions for types smaller than I32
[...]
warning: DefId(0/0:128 ~ lib[8787]::f64[0]::{{impl}}[0]::classify[0]):
fn f64::<impl at ./target/libcore/src/libcore/num/f64.rs:156:1: 490:2>::classify(_1: f64) -> num::FpCategory{
[...]
}
warning: stmt _3 = _1
warning: stmt _5 = BitAnd(move _6, const Unevaluated(DefId(0/0:130 ~ lib[8787]::f64[0]::{{impl}}[0]::classify[0]::MAN_MASK[0]), []):u64)
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:345:21
stack backtrace:
[...]
  10: <core::option::Option<T>>::unwrap
             at /checkout/src/libcore/macros.rs:20
  11: rustc_codegen_cranelift::constant::trans_constant
             at src/constant.rs:26
[...]