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.
11 use rustc
::mir
::repr
as mir
;
14 use common
::{self, BlockAndBuilder}
;
16 use super::MirContext
;
18 use super::super::adt
;
19 use super::super::disr
::Disr
;
21 impl<'bcx
, 'tcx
> MirContext
<'bcx
, 'tcx
> {
22 pub fn trans_statement(&mut self,
23 bcx
: BlockAndBuilder
<'bcx
, 'tcx
>,
24 statement
: &mir
::Statement
<'tcx
>)
25 -> BlockAndBuilder
<'bcx
, 'tcx
> {
26 debug
!("trans_statement(statement={:?})", statement
);
28 let debug_loc
= self.debug_loc(statement
.source_info
);
29 debug_loc
.apply_to_bcx(&bcx
);
30 debug_loc
.apply(bcx
.fcx());
31 match statement
.kind
{
32 mir
::StatementKind
::Assign(ref lvalue
, ref rvalue
) => {
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
)
38 LocalRef
::Operand(None
) => {
39 let (bcx
, operand
) = self.trans_rvalue_operand(bcx
, rvalue
,
41 self.locals
[index
] = LocalRef
::Operand(Some(operand
));
44 LocalRef
::Operand(Some(_
)) => {
45 let ty
= self.monomorphized_lvalue_ty(lvalue
);
47 if !common
::type_is_zero_size(bcx
.ccx(), ty
) {
48 span_bug
!(statement
.source_info
.span
,
49 "operand {:?} already assigned",
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
59 let tr_dest
= self.trans_lvalue(&bcx
, lvalue
);
60 self.trans_rvalue(bcx
, tr_dest
, rvalue
, debug_loc
)
63 mir
::StatementKind
::SetDiscriminant{ref lvalue, variant_index}
=> {
64 let ty
= self.monomorphized_lvalue_ty(lvalue
);
65 let repr
= adt
::represent_type(bcx
.ccx(), ty
);
66 let lvalue_transed
= self.trans_lvalue(&bcx
, lvalue
);
68 adt
::trans_set_discr(bcx
,
71 Disr
::from(variant_index
))
75 mir
::StatementKind
::StorageLive(ref lvalue
) => {
76 self.trans_storage_liveness(bcx
, lvalue
, base
::Lifetime
::Start
)
78 mir
::StatementKind
::StorageDead(ref lvalue
) => {
79 self.trans_storage_liveness(bcx
, lvalue
, base
::Lifetime
::End
)
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
);