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