Skip to content

Commit d6ceef9

Browse files
committed
rustc: Move trans_compare into alt.rs
1 parent a93de20 commit d6ceef9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/rustc/middle/trans/alt.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,35 @@ impl branch_kind : cmp::Eq {
427427
pure fn ne(&&other: branch_kind) -> bool { !self.eq(other) }
428428
}
429429

430+
// Compiles a comparison between two things.
431+
fn trans_compare(cx: block, op: ast::binop, lhs: ValueRef,
432+
_lhs_t: ty::t, rhs: ValueRef, rhs_t: ty::t) -> Result {
433+
let _icx = cx.insn_ctxt("trans_compare");
434+
if ty::type_is_scalar(rhs_t) {
435+
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, op);
436+
return rslt(rs.bcx, rs.val);
437+
}
438+
439+
// Determine the operation we need.
440+
let llop = {
441+
match op {
442+
ast::eq | ast::ne => C_u8(abi::cmp_glue_op_eq),
443+
ast::lt | ast::ge => C_u8(abi::cmp_glue_op_lt),
444+
ast::le | ast::gt => C_u8(abi::cmp_glue_op_le),
445+
_ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op")
446+
}
447+
};
448+
449+
let cmpval = glue::call_cmp_glue(cx, lhs, rhs, rhs_t, llop);
450+
451+
// Invert the result if necessary.
452+
match op {
453+
ast::eq | ast::lt | ast::le => rslt(cx, cmpval),
454+
ast::ne | ast::ge | ast::gt => rslt(cx, Not(cx, cmpval)),
455+
_ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op")
456+
}
457+
}
458+
430459
fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef],
431460
chk: Option<mk_fail>, &exits: ~[exit_node]) {
432461
/*

0 commit comments

Comments
 (0)