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
;
20 impl FunctionCx
<'a
, 'll
, 'tcx
> {
21 pub fn codegen_statement(&mut self,
22 bx
: Builder
<'a
, 'll
, 'tcx
>,
23 statement
: &mir
::Statement
<'tcx
>)
24 -> Builder
<'a
, 'll
, 'tcx
> {
25 debug
!("codegen_statement(statement={:?})", statement
);
27 self.set_debug_loc(&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(&bx
, place
);
57 self.codegen_rvalue(bx
, cg_dest
, rvalue
)
60 mir
::StatementKind
::SetDiscriminant{ref place, variant_index}
=> {
61 self.codegen_place(&bx
, place
)
62 .codegen_set_discr(&bx
, variant_index
);
65 mir
::StatementKind
::StorageLive(local
) => {
66 if let LocalRef
::Place(cg_place
) = self.locals
[local
] {
67 cg_place
.storage_live(&bx
);
68 } else if let LocalRef
::UnsizedPlace(cg_indirect_place
) = self.locals
[local
] {
69 cg_indirect_place
.storage_live(&bx
);
73 mir
::StatementKind
::StorageDead(local
) => {
74 if let LocalRef
::Place(cg_place
) = self.locals
[local
] {
75 cg_place
.storage_dead(&bx
);
76 } else if let LocalRef
::UnsizedPlace(cg_indirect_place
) = self.locals
[local
] {
77 cg_indirect_place
.storage_dead(&bx
);
81 mir
::StatementKind
::InlineAsm { ref asm, ref outputs, ref inputs }
=> {
82 let outputs
= outputs
.iter().map(|output
| {
83 self.codegen_place(&bx
, output
)
86 let input_vals
= inputs
.iter()
87 .try_fold(Vec
::with_capacity(inputs
.len()), |mut acc
, input
| {
88 let op
= self.codegen_operand(&bx
, input
);
89 if let OperandValue
::Immediate(_
) = op
.val
{
90 acc
.push(op
.immediate());
97 if input_vals
.is_err() {
98 span_err
!(bx
.sess(), statement
.source_info
.span
, E0669
,
99 "invalid value for constraint in inline assembly");
101 let input_vals
= input_vals
.unwrap();
102 let res
= asm
::codegen_inline_asm(&bx
, asm
, outputs
, input_vals
);
104 span_err
!(bx
.sess(), statement
.source_info
.span
, E0668
,
105 "malformed inline assembly");
110 mir
::StatementKind
::FakeRead(..) |
111 mir
::StatementKind
::EndRegion(_
) |
112 mir
::StatementKind
::Validate(..) |
113 mir
::StatementKind
::AscribeUserType(..) |
114 mir
::StatementKind
::Nop
=> bx
,