]> git.proxmox.com Git - rustc.git/blob - src/librustc_trans/trans/mir/statement.rs
Imported Upstream version 1.8.0+dfsg1
[rustc.git] / src / librustc_trans / trans / mir / statement.rs
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.
4 //
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.
10
11 use rustc::mir::repr as mir;
12 use trans::common::BlockAndBuilder;
13
14 use super::MirContext;
15 use super::TempRef;
16
17 impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
18 pub fn trans_statement(&mut self,
19 bcx: BlockAndBuilder<'bcx, 'tcx>,
20 statement: &mir::Statement<'tcx>)
21 -> BlockAndBuilder<'bcx, 'tcx> {
22 debug!("trans_statement(statement={:?})", statement);
23
24 match statement.kind {
25 mir::StatementKind::Assign(ref lvalue, ref rvalue) => {
26 match *lvalue {
27 mir::Lvalue::Temp(index) => {
28 let index = index as usize;
29 match self.temps[index as usize] {
30 TempRef::Lvalue(tr_dest) => {
31 self.trans_rvalue(bcx, tr_dest, rvalue)
32 }
33 TempRef::Operand(None) => {
34 let (bcx, operand) = self.trans_rvalue_operand(bcx, rvalue);
35 self.temps[index] = TempRef::Operand(Some(operand));
36 bcx
37 }
38 TempRef::Operand(Some(_)) => {
39 bcx.tcx().sess.span_bug(
40 statement.span,
41 &format!("operand {:?} already assigned", rvalue));
42 }
43 }
44 }
45 _ => {
46 let tr_dest = self.trans_lvalue(&bcx, lvalue);
47 self.trans_rvalue(bcx, tr_dest, rvalue)
48 }
49 }
50 }
51 }
52 }
53 }