]>
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 | ||
c30ab7b3 | 11 | use rustc::mir; |
3157f602 | 12 | |
8bb4bdeb | 13 | use asm; |
32a655c1 | 14 | use builder::Builder; |
92a42be0 | 15 | |
2c00a5a8 | 16 | use super::FunctionCx; |
3157f602 | 17 | use super::LocalRef; |
92a42be0 | 18 | |
2c00a5a8 | 19 | impl<'a, 'tcx> FunctionCx<'a, 'tcx> { |
92a42be0 | 20 | pub fn trans_statement(&mut self, |
2c00a5a8 | 21 | bx: Builder<'a, 'tcx>, |
92a42be0 | 22 | statement: &mir::Statement<'tcx>) |
32a655c1 | 23 | -> Builder<'a, 'tcx> { |
92a42be0 SL |
24 | debug!("trans_statement(statement={:?})", statement); |
25 | ||
2c00a5a8 | 26 | self.set_debug_loc(&bx, statement.source_info); |
92a42be0 | 27 | match statement.kind { |
ff7c6d11 XL |
28 | mir::StatementKind::Assign(ref place, ref rvalue) => { |
29 | if let mir::Place::Local(index) = *place { | |
3157f602 | 30 | match self.locals[index] { |
ff7c6d11 | 31 | LocalRef::Place(tr_dest) => { |
2c00a5a8 | 32 | self.trans_rvalue(bx, tr_dest, rvalue) |
3157f602 XL |
33 | } |
34 | LocalRef::Operand(None) => { | |
2c00a5a8 | 35 | let (bx, operand) = self.trans_rvalue_operand(bx, rvalue); |
3157f602 | 36 | self.locals[index] = LocalRef::Operand(Some(operand)); |
2c00a5a8 | 37 | bx |
3157f602 | 38 | } |
ff7c6d11 XL |
39 | LocalRef::Operand(Some(op)) => { |
40 | if !op.layout.is_zst() { | |
3157f602 XL |
41 | span_bug!(statement.source_info.span, |
42 | "operand {:?} already assigned", | |
43 | rvalue); | |
92a42be0 | 44 | } |
ff7c6d11 XL |
45 | |
46 | // If the type is zero-sized, it's already been set here, | |
47 | // but we still need to make sure we translate the operand | |
2c00a5a8 | 48 | self.trans_rvalue_operand(bx, rvalue).0 |
92a42be0 SL |
49 | } |
50 | } | |
3157f602 | 51 | } else { |
2c00a5a8 XL |
52 | let tr_dest = self.trans_place(&bx, place); |
53 | self.trans_rvalue(bx, tr_dest, rvalue) | |
92a42be0 SL |
54 | } |
55 | } | |
ff7c6d11 | 56 | mir::StatementKind::SetDiscriminant{ref place, variant_index} => { |
2c00a5a8 XL |
57 | self.trans_place(&bx, place) |
58 | .trans_set_discr(&bx, variant_index); | |
59 | bx | |
5bcae85e | 60 | } |
ea8adc8c | 61 | mir::StatementKind::StorageLive(local) => { |
ff7c6d11 | 62 | if let LocalRef::Place(tr_place) = self.locals[local] { |
2c00a5a8 | 63 | tr_place.storage_live(&bx); |
ff7c6d11 | 64 | } |
2c00a5a8 | 65 | bx |
5bcae85e | 66 | } |
ea8adc8c | 67 | mir::StatementKind::StorageDead(local) => { |
ff7c6d11 | 68 | if let LocalRef::Place(tr_place) = self.locals[local] { |
2c00a5a8 | 69 | tr_place.storage_dead(&bx); |
ff7c6d11 | 70 | } |
2c00a5a8 | 71 | bx |
5bcae85e | 72 | } |
8bb4bdeb XL |
73 | mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => { |
74 | let outputs = outputs.iter().map(|output| { | |
2c00a5a8 | 75 | self.trans_place(&bx, output) |
8bb4bdeb XL |
76 | }).collect(); |
77 | ||
78 | let input_vals = inputs.iter().map(|input| { | |
2c00a5a8 | 79 | self.trans_operand(&bx, input).immediate() |
8bb4bdeb XL |
80 | }).collect(); |
81 | ||
2c00a5a8 XL |
82 | asm::trans_inline_asm(&bx, asm, outputs, input_vals); |
83 | bx | |
8bb4bdeb | 84 | } |
041b39d2 | 85 | mir::StatementKind::EndRegion(_) | |
3b2f2976 | 86 | mir::StatementKind::Validate(..) | |
0531ce1d | 87 | mir::StatementKind::UserAssertTy(..) | |
2c00a5a8 | 88 | mir::StatementKind::Nop => bx, |
5bcae85e SL |
89 | } |
90 | } | |
92a42be0 | 91 | } |