]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
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 | ||
92a42be0 | 11 | use rustc::mir::repr as mir; |
3157f602 | 12 | |
5bcae85e | 13 | use base; |
a7813a04 | 14 | use common::{self, BlockAndBuilder}; |
92a42be0 SL |
15 | |
16 | use super::MirContext; | |
3157f602 | 17 | use super::LocalRef; |
5bcae85e SL |
18 | use super::super::adt; |
19 | use super::super::disr::Disr; | |
92a42be0 SL |
20 | |
21 | impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { | |
22 | pub fn trans_statement(&mut self, | |
7453a54e | 23 | bcx: BlockAndBuilder<'bcx, 'tcx>, |
92a42be0 | 24 | statement: &mir::Statement<'tcx>) |
7453a54e | 25 | -> BlockAndBuilder<'bcx, 'tcx> { |
92a42be0 SL |
26 | debug!("trans_statement(statement={:?})", statement); |
27 | ||
3157f602 | 28 | let debug_loc = self.debug_loc(statement.source_info); |
a7813a04 XL |
29 | debug_loc.apply_to_bcx(&bcx); |
30 | debug_loc.apply(bcx.fcx()); | |
92a42be0 SL |
31 | match statement.kind { |
32 | mir::StatementKind::Assign(ref lvalue, ref rvalue) => { | |
3157f602 XL |
33 | if let Some(index) = self.mir.local_index(lvalue) { |
34 | match self.locals[index] { | |
35 | LocalRef::Lvalue(tr_dest) => { | |
36 | self.trans_rvalue(bcx, tr_dest, rvalue, debug_loc) | |
37 | } | |
38 | LocalRef::Operand(None) => { | |
39 | let (bcx, operand) = self.trans_rvalue_operand(bcx, rvalue, | |
40 | debug_loc); | |
41 | self.locals[index] = LocalRef::Operand(Some(operand)); | |
42 | bcx | |
43 | } | |
44 | LocalRef::Operand(Some(_)) => { | |
5bcae85e | 45 | let ty = self.monomorphized_lvalue_ty(lvalue); |
a7813a04 | 46 | |
3157f602 XL |
47 | if !common::type_is_zero_size(bcx.ccx(), ty) { |
48 | span_bug!(statement.source_info.span, | |
49 | "operand {:?} already assigned", | |
50 | rvalue); | |
51 | } else { | |
52 | // If the type is zero-sized, it's already been set here, | |
53 | // but we still need to make sure we translate the operand | |
54 | self.trans_rvalue_operand(bcx, rvalue, debug_loc).0 | |
92a42be0 SL |
55 | } |
56 | } | |
57 | } | |
3157f602 XL |
58 | } else { |
59 | let tr_dest = self.trans_lvalue(&bcx, lvalue); | |
60 | self.trans_rvalue(bcx, tr_dest, rvalue, debug_loc) | |
92a42be0 SL |
61 | } |
62 | } | |
5bcae85e SL |
63 | mir::StatementKind::SetDiscriminant{ref lvalue, variant_index} => { |
64 | let ty = self.monomorphized_lvalue_ty(lvalue); | |
5bcae85e SL |
65 | let lvalue_transed = self.trans_lvalue(&bcx, lvalue); |
66 | bcx.with_block(|bcx| | |
67 | adt::trans_set_discr(bcx, | |
9e0c209e | 68 | ty, |
5bcae85e SL |
69 | lvalue_transed.llval, |
70 | Disr::from(variant_index)) | |
71 | ); | |
72 | bcx | |
73 | } | |
74 | mir::StatementKind::StorageLive(ref lvalue) => { | |
75 | self.trans_storage_liveness(bcx, lvalue, base::Lifetime::Start) | |
76 | } | |
77 | mir::StatementKind::StorageDead(ref lvalue) => { | |
78 | self.trans_storage_liveness(bcx, lvalue, base::Lifetime::End) | |
79 | } | |
9e0c209e | 80 | mir::StatementKind::Nop => bcx, |
5bcae85e SL |
81 | } |
82 | } | |
83 | ||
84 | fn trans_storage_liveness(&self, | |
85 | bcx: BlockAndBuilder<'bcx, 'tcx>, | |
86 | lvalue: &mir::Lvalue<'tcx>, | |
87 | intrinsic: base::Lifetime) | |
88 | -> BlockAndBuilder<'bcx, 'tcx> { | |
89 | if let Some(index) = self.mir.local_index(lvalue) { | |
90 | if let LocalRef::Lvalue(tr_lval) = self.locals[index] { | |
91 | intrinsic.call(&bcx, tr_lval.llval); | |
92 | } | |
92a42be0 | 93 | } |
5bcae85e | 94 | bcx |
92a42be0 SL |
95 | } |
96 | } |