1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use rustc::middle::ty::Ty;
13 use rustc_mir::repr as mir;
16 use trans::common::Block;
19 use super::{MirContext, TempRef};
21 #[derive(Copy, Clone)]
22 pub struct OperandRef<'tcx> {
23 // This will be "indirect" if `appropriate_rvalue_mode` returns
24 // ByRef, and otherwise ByValue.
27 // The type of value being returned.
31 impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
32 pub fn trans_operand(&mut self,
33 bcx: Block<'bcx, 'tcx>,
34 operand: &mir::Operand<'tcx>)
37 debug!("trans_operand(operand={:?})", operand);
40 mir::Operand::Consume(ref lvalue) => {
41 // watch out for temporaries that do not have an
42 // alloca; they are handled somewhat differently
43 if let &mir::Lvalue::Temp(index) = lvalue {
44 match self.temps[index as usize] {
45 TempRef::Operand(Some(o)) => {
48 TempRef::Operand(None) => {
50 &format!("use of {:?} before def", lvalue));
52 TempRef::Lvalue(..) => {
58 // for most lvalues, to consume them we just load them
59 // out from their home
60 let tr_lvalue = self.trans_lvalue(bcx, lvalue);
61 let ty = tr_lvalue.ty.to_ty(bcx.tcx());
62 debug!("trans_operand: tr_lvalue={} @ {:?}",
63 bcx.val_to_string(tr_lvalue.llval),
65 let llval = match datum::appropriate_rvalue_mode(bcx.ccx(), ty) {
66 datum::ByValue => build::Load(bcx, tr_lvalue.llval),
67 datum::ByRef => tr_lvalue.llval,
75 mir::Operand::Constant(ref constant) => {
76 let llval = self.trans_constant(bcx, constant);
77 let ty = bcx.monomorphize(&constant.ty);
86 pub fn trans_operand_into(&mut self,
87 bcx: Block<'bcx, 'tcx>,
89 operand: &mir::Operand<'tcx>)
91 debug!("trans_operand_into(lldest={}, operand={:?})",
92 bcx.val_to_string(lldest),
96 mir::Operand::Consume(ref lvalue) => {
97 let tr_lvalue = self.trans_lvalue(bcx, lvalue);
98 let lvalue_ty = tr_lvalue.ty.to_ty(bcx.tcx());
99 debug!("trans_operand_into: tr_lvalue={} @ {:?}",
100 bcx.val_to_string(tr_lvalue.llval),
102 base::memcpy_ty(bcx, lldest, tr_lvalue.llval, lvalue_ty);
105 mir::Operand::Constant(..) => {