Fix and test checked binops

This commit is contained in:
bjorn3 2018-08-13 19:14:55 +02:00
parent 4ee2a864b5
commit b9d7164eff
4 changed files with 19 additions and 2 deletions

View file

@ -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 &&

View file

@ -65,6 +65,21 @@ impl Mul for u8 {
}
}
#[lang = "add"]
pub trait Add<RHS = Self> {
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<RHS = Self> {
type Output;

View file

@ -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
}
}

View file

@ -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, &[]);