2015-10-21 16:42:25 -05:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-11-19 09:37:34 -06:00
|
|
|
use rustc::mir::repr as mir;
|
2016-03-22 12:23:36 -05:00
|
|
|
use common::BlockAndBuilder;
|
2015-10-21 16:42:25 -05:00
|
|
|
|
|
|
|
use super::MirContext;
|
2015-11-02 08:39:59 -06:00
|
|
|
use super::TempRef;
|
2015-10-21 16:42:25 -05:00
|
|
|
|
|
|
|
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
|
|
|
pub fn trans_statement(&mut self,
|
2016-02-01 04:04:46 -06:00
|
|
|
bcx: BlockAndBuilder<'bcx, 'tcx>,
|
2015-10-21 16:42:25 -05:00
|
|
|
statement: &mir::Statement<'tcx>)
|
2016-02-01 04:04:46 -06:00
|
|
|
-> BlockAndBuilder<'bcx, 'tcx> {
|
2015-10-21 16:42:25 -05:00
|
|
|
debug!("trans_statement(statement={:?})", statement);
|
|
|
|
|
|
|
|
match statement.kind {
|
|
|
|
mir::StatementKind::Assign(ref lvalue, ref rvalue) => {
|
2015-11-02 08:39:59 -06:00
|
|
|
match *lvalue {
|
|
|
|
mir::Lvalue::Temp(index) => {
|
|
|
|
let index = index as usize;
|
|
|
|
match self.temps[index as usize] {
|
|
|
|
TempRef::Lvalue(tr_dest) => {
|
2015-12-24 17:02:34 -06:00
|
|
|
self.trans_rvalue(bcx, tr_dest, rvalue)
|
2015-11-02 08:39:59 -06:00
|
|
|
}
|
|
|
|
TempRef::Operand(None) => {
|
|
|
|
let (bcx, operand) = self.trans_rvalue_operand(bcx, rvalue);
|
|
|
|
self.temps[index] = TempRef::Operand(Some(operand));
|
|
|
|
bcx
|
|
|
|
}
|
|
|
|
TempRef::Operand(Some(_)) => {
|
|
|
|
bcx.tcx().sess.span_bug(
|
|
|
|
statement.span,
|
|
|
|
&format!("operand {:?} already assigned", rvalue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
2016-02-01 04:04:46 -06:00
|
|
|
let tr_dest = self.trans_lvalue(&bcx, lvalue);
|
2015-12-24 17:02:34 -06:00
|
|
|
self.trans_rvalue(bcx, tr_dest, rvalue)
|
2015-11-02 08:39:59 -06:00
|
|
|
}
|
|
|
|
}
|
2015-10-21 16:42:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|