Skip to content

Commit

Permalink
rustc: Trim down and rename trans_compare. Now only eq shape glue rem…
Browse files Browse the repository at this point in the history
…ains.
  • Loading branch information
pcwalton committed Sep 10, 2012
1 parent 10aa849 commit bea6fe0
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/rustc/middle/trans/alt.rs
Expand Up @@ -428,32 +428,18 @@ impl branch_kind : cmp::Eq {
}

// Compiles a comparison between two things.
fn trans_compare(cx: block, op: ast::binop, lhs: ValueRef,
_lhs_t: ty::t, rhs: ValueRef, rhs_t: ty::t) -> Result {
let _icx = cx.insn_ctxt("trans_compare");
fn compare_values(cx: block, lhs: ValueRef, rhs: ValueRef, rhs_t: ty::t) ->
Result {
let _icx = cx.insn_ctxt("compare_values");
if ty::type_is_scalar(rhs_t) {
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, op);
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::eq);
return rslt(rs.bcx, rs.val);
}

// Determine the operation we need.
let llop = {
match op {
ast::eq | ast::ne => C_u8(abi::cmp_glue_op_eq),
ast::lt | ast::ge => C_u8(abi::cmp_glue_op_lt),
ast::le | ast::gt => C_u8(abi::cmp_glue_op_le),
_ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op")
}
};

let llop = C_u8(abi::cmp_glue_op_eq);
let cmpval = glue::call_cmp_glue(cx, lhs, rhs, rhs_t, llop);

// Invert the result if necessary.
match op {
ast::eq | ast::lt | ast::le => rslt(cx, cmpval),
ast::ne | ast::ge | ast::gt => rslt(cx, Not(cx, cmpval)),
_ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op")
}
rslt(cx, cmpval)
}

fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef],
Expand Down Expand Up @@ -663,15 +649,12 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef],
do with_scope_result(bcx, None, ~"compare_scope") |bcx| {
match trans_opt(bcx, opt) {
single_result(
Result {bcx, val}) =>
{
trans_compare(bcx, ast::eq, test_val,
t, val, t)
Result {bcx, val}) => {
compare_values(bcx, test_val, val, t)
}
range_result(
Result {val: vbegin, _},
Result {bcx, val: vend}) =>
{
Result {bcx, val: vend}) => {
let Result {bcx, val: llge} =
compare_scalar_types(bcx, test_val,
vbegin, t, ast::ge);
Expand Down

0 comments on commit bea6fe0

Please sign in to comment.