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.
13 use traits::BuilderMethods;
14 use super::FunctionCx;
16 use super::OperandValue;
19 impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
20 pub fn codegen_statement(
23 statement: &mir::Statement<'tcx>
25 debug!("codegen_statement(statement={:?})", statement);
27 self.set_debug_loc(&mut bx, statement.source_info);
28 match statement.kind {
29 mir::StatementKind::Assign(ref place, ref rvalue) => {
30 if let mir::Place::Local(index) = *place {
31 match self.locals[index] {
32 LocalRef::Place(cg_dest) => {
33 self.codegen_rvalue(bx, cg_dest, rvalue)
35 LocalRef::UnsizedPlace(cg_indirect_dest) => {
36 self.codegen_rvalue_unsized(bx, cg_indirect_dest, rvalue)
38 LocalRef::Operand(None) => {
39 let (bx, operand) = self.codegen_rvalue_operand(bx, rvalue);
40 self.locals[index] = LocalRef::Operand(Some(operand));
43 LocalRef::Operand(Some(op)) => {
44 if !op.layout.is_zst() {
45 span_bug!(statement.source_info.span,
46 "operand {:?} already assigned",
50 // If the type is zero-sized, it's already been set here,
51 // but we still need to make sure we codegen the operand
52 self.codegen_rvalue_operand(bx, rvalue).0
56 let cg_dest = self.codegen_place(&mut bx, place);
57 self.codegen_rvalue(bx, cg_dest, rvalue)
60 mir::StatementKind::SetDiscriminant{ref place, variant_index} => {
61 self.codegen_place(&mut bx, place)
62 .codegen_set_discr(&mut bx, variant_index);
65 mir::StatementKind::StorageLive(local) => {
66 if let LocalRef::Place(cg_place) = self.locals[local] {
67 cg_place.storage_live(&mut bx);
68 } else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
69 cg_indirect_place.storage_live(&mut bx);
73 mir::StatementKind::StorageDead(local) => {
74 if let LocalRef::Place(cg_place) = self.locals[local] {
75 cg_place.storage_dead(&mut bx);
76 } else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
77 cg_indirect_place.storage_dead(&mut bx);
81 mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
82 let outputs = outputs.iter().map(|output| {
83 self.codegen_place(&mut bx, output)
86 let input_vals = inputs.iter()
87 .fold(Vec::with_capacity(inputs.len()), |mut acc, (span, input)| {
88 let op = self.codegen_operand(&mut bx, input);
89 if let OperandValue::Immediate(_) = op.val {
90 acc.push(op.immediate());
92 span_err!(bx.sess(), span.to_owned(), E0669,
93 "invalid value for constraint in inline assembly");
98 if input_vals.len() == inputs.len() {
99 let res = bx.codegen_inline_asm(asm, outputs, input_vals);
101 span_err!(bx.sess(), statement.source_info.span, E0668,
102 "malformed inline assembly");
107 mir::StatementKind::FakeRead(..) |
108 mir::StatementKind::Retag { .. } |
109 mir::StatementKind::EscapeToRaw { .. } |
110 mir::StatementKind::AscribeUserType(..) |
111 mir::StatementKind::Nop => bx,