From b9d7164eff9974ca10693d87e7c980a3ebad48dd Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 13 Aug 2018 19:14:55 +0200 Subject: [PATCH] Fix and test checked binops --- build.sh | 2 +- examples/mini_core.rs | 15 +++++++++++++++ examples/mini_core_hello_world.rs | 2 +- src/base.rs | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 3d9bcbd1919..badfe3c9e7e 100755 --- a/build.sh +++ b/build.sh @@ -14,7 +14,7 @@ else exit 1 fi -RUSTC="rustc -Zcodegen-backend=$(pwd)/../target/debug/librustc_codegen_cranelift.$dylib_ext -L crate=. -Og" +RUSTC="rustc -Zcodegen-backend=$(pwd)/../target/debug/librustc_codegen_cranelift.$dylib_ext -L crate=." $RUSTC mini_core.rs --crate-name mini_core --crate-type lib && $RUSTC example.rs --crate-type lib && diff --git a/examples/mini_core.rs b/examples/mini_core.rs index d2a205856a9..7813f8a4c34 100644 --- a/examples/mini_core.rs +++ b/examples/mini_core.rs @@ -65,6 +65,21 @@ impl Mul for u8 { } } +#[lang = "add"] +pub trait Add { + type Output; + + fn add(self, rhs: RHS) -> Self::Output; +} + +impl Add for u8 { + type Output = Self; + + fn add(self, rhs: Self) -> Self { + self + rhs + } +} + #[lang = "sub"] pub trait Sub { type Output; diff --git a/examples/mini_core_hello_world.rs b/examples/mini_core_hello_world.rs index ffda837fac2..2519aacc578 100644 --- a/examples/mini_core_hello_world.rs +++ b/examples/mini_core_hello_world.rs @@ -27,7 +27,7 @@ fn start(_main: *const u8, i: isize, _: *const *const u8) -> isize { } unsafe { - NUM = 43; + NUM = 6 * 7 + 5; *NUM_REF as isize } } diff --git a/src/base.rs b/src/base.rs index 4a3de4fa52b..cb4ed7900dd 100644 --- a/src/base.rs +++ b/src/base.rs @@ -152,6 +152,8 @@ pub fn trans_fn<'a, 'tcx: 'a>( cleanup: _, } => { let cond = trans_operand(fx, cond).load_value(fx); + // TODO HACK brz/brnz for i8/i16 is not yet implemented + let cond = fx.bcx.ins().uextend(types::I32, cond); let target = fx.get_ebb(*target); if *expected { fx.bcx.ins().brnz(cond, target, &[]);