Change Call operands to be, well, Operands

This commit is contained in:
Niko Matsakis 2015-10-21 17:29:50 -04:00
parent 3ab29d3378
commit 044096b3e9
4 changed files with 25 additions and 28 deletions

View File

@ -211,10 +211,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
this.cfg.start_new_block().unit()
}
ExprKind::Call { fun, args } => {
let fun = unpack!(block = this.as_lvalue(block, fun));
let fun = unpack!(block = this.as_operand(block, fun));
let args: Vec<_> =
args.into_iter()
.map(|arg| unpack!(block = this.as_lvalue(block, arg)))
.map(|arg| unpack!(block = this.as_operand(block, arg)))
.collect();
let success = this.cfg.start_new_block();
let panic = this.diverge_cleanup();

View File

@ -100,27 +100,28 @@ impl<'a,'tcx> Builder<'a,'tcx> {
TestKind::Eq { value, ty } => {
// call PartialEq::eq(discrim, constant)
let constant = self.push_literal(block, test.span, ty.clone(), value);
let constant = self.literal_operand(test.span, ty.clone(), value);
let item_ref = self.hir.partial_eq(ty);
self.call_comparison_fn(block, test.span, item_ref, lvalue.clone(), constant)
self.call_comparison_fn(block, test.span, item_ref,
Operand::Consume(lvalue.clone()), constant)
}
TestKind::Range { lo, hi, ty } => {
// Test `v` by computing `PartialOrd::le(lo, v) && PartialOrd::le(v, hi)`.
let lo = self.push_literal(block, test.span, ty.clone(), lo);
let hi = self.push_literal(block, test.span, ty.clone(), hi);
let lo = self.literal_operand(test.span, ty.clone(), lo);
let hi = self.literal_operand(test.span, ty.clone(), hi);
let item_ref = self.hir.partial_le(ty);
let lo_blocks = self.call_comparison_fn(block,
test.span,
item_ref.clone(),
lo,
lvalue.clone());
Operand::Consume(lvalue.clone()));
let hi_blocks = self.call_comparison_fn(lo_blocks[0],
test.span,
item_ref,
lvalue.clone(),
Operand::Consume(lvalue.clone()),
hi);
let failure = self.cfg.start_new_block();
@ -165,14 +166,14 @@ impl<'a,'tcx> Builder<'a,'tcx> {
block: BasicBlock,
span: Span,
item_ref: ItemRef<'tcx>,
lvalue1: Lvalue<'tcx>,
lvalue2: Lvalue<'tcx>)
lvalue1: Operand<'tcx>,
lvalue2: Operand<'tcx>)
-> Vec<BasicBlock> {
let target_blocks = vec![self.cfg.start_new_block(), self.cfg.start_new_block()];
let bool_ty = self.hir.bool_ty();
let eq_result = self.temp(bool_ty);
let func = self.push_item_ref(block, span, item_ref);
let func = self.item_ref_operand(span, item_ref);
let call_blocks = [self.cfg.start_new_block(), self.diverge_cleanup()];
self.cfg.terminate(block,
Terminator::Call {

View File

@ -34,20 +34,17 @@ impl<'a,'tcx> Builder<'a,'tcx> {
lvalue
}
pub fn push_literal(&mut self,
block: BasicBlock,
span: Span,
ty: Ty<'tcx>,
literal: Literal<'tcx>)
-> Lvalue<'tcx> {
let temp = self.temp(ty.clone());
pub fn literal_operand(&mut self,
span: Span,
ty: Ty<'tcx>,
literal: Literal<'tcx>)
-> Operand<'tcx> {
let constant = Constant {
span: span,
ty: ty,
literal: literal,
};
self.cfg.push_assign_constant(block, span, &temp, constant);
temp
Operand::Constant(constant)
}
pub fn push_usize(&mut self, block: BasicBlock, span: Span, value: usize) -> Lvalue<'tcx> {
@ -63,15 +60,14 @@ impl<'a,'tcx> Builder<'a,'tcx> {
temp
}
pub fn push_item_ref(&mut self,
block: BasicBlock,
span: Span,
item_ref: ItemRef<'tcx>)
-> Lvalue<'tcx> {
pub fn item_ref_operand(&mut self,
span: Span,
item_ref: ItemRef<'tcx>)
-> Operand<'tcx> {
let literal = Literal::Item {
def_id: item_ref.def_id,
substs: item_ref.substs,
};
self.push_literal(block, span, item_ref.ty, literal)
self.literal_operand(span, item_ref.ty, literal)
}
}

View File

@ -294,10 +294,10 @@ pub struct CallData<'tcx> {
pub destination: Lvalue<'tcx>,
/// the fn being called
pub func: Lvalue<'tcx>,
pub func: Operand<'tcx>,
/// the arguments
pub args: Vec<Lvalue<'tcx>>,
pub args: Vec<Operand<'tcx>>,
}
impl<'tcx> BasicBlockData<'tcx> {