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.
15 use traits::BuilderMethods;
17 use super::FunctionCx;
19 use super::OperandValue;
22 impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
23 pub fn codegen_statement(&mut self,
24 bx: Builder<'a, 'll, 'tcx>,
25 statement: &mir::Statement<'tcx>)
26 -> Builder<'a, 'll, 'tcx> {
27 debug!("codegen_statement(statement={:?})", statement);
29 self.set_debug_loc(&bx, statement.source_info);
30 match statement.kind {
31 mir::StatementKind::Assign(ref place, ref rvalue) => {
32 if let mir::Place::Local(index) = *place {
33 match self.locals[index] {
34 LocalRef::Place(cg_dest) => {
35 self.codegen_rvalue(bx, cg_dest, rvalue)
37 LocalRef::UnsizedPlace(cg_indirect_dest) => {
38 self.codegen_rvalue_unsized(bx, cg_indirect_dest, rvalue)
40 LocalRef::Operand(None) => {
41 let (bx, operand) = self.codegen_rvalue_operand(bx, rvalue);
42 self.locals[index] = LocalRef::Operand(Some(operand));
45 LocalRef::Operand(Some(op)) => {
46 if !op.layout.is_zst() {
47 span_bug!(statement.source_info.span,
48 "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 codegen the operand
54 self.codegen_rvalue_operand(bx, rvalue).0
58 let cg_dest = self.codegen_place(&bx, place);
59 self.codegen_rvalue(bx, cg_dest, rvalue)
62 mir::StatementKind::SetDiscriminant{ref place, variant_index} => {
63 self.codegen_place(&bx, place)
64 .codegen_set_discr(&bx, variant_index);
67 mir::StatementKind::StorageLive(local) => {
68 if let LocalRef::Place(cg_place) = self.locals[local] {
69 cg_place.storage_live(&bx);
70 } else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
71 cg_indirect_place.storage_live(&bx);
75 mir::StatementKind::StorageDead(local) => {
76 if let LocalRef::Place(cg_place) = self.locals[local] {
77 cg_place.storage_dead(&bx);
78 } else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
79 cg_indirect_place.storage_dead(&bx);
83 mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
84 let outputs = outputs.iter().map(|output| {
85 self.codegen_place(&bx, output)
88 let input_vals = inputs.iter()
89 .fold(Vec::with_capacity(inputs.len()), |mut acc, (span, input)| {
90 let op = self.codegen_operand(&bx, input);
91 if let OperandValue::Immediate(_) = op.val {
92 acc.push(op.immediate());
94 span_err!(bx.sess(), span.to_owned(), E0669,
95 "invalid value for constraint in inline assembly");
100 if input_vals.len() == inputs.len() {
101 let res = asm::codegen_inline_asm(&bx, asm, outputs, input_vals);
103 span_err!(bx.sess(), statement.source_info.span, E0668,
104 "malformed inline assembly");
109 mir::StatementKind::FakeRead(..) |
110 mir::StatementKind::EndRegion(..) |
111 mir::StatementKind::Retag { .. } |
112 mir::StatementKind::EscapeToRaw { .. } |
113 mir::StatementKind::AscribeUserType(..) |
114 mir::StatementKind::Nop => bx,