2016-09-19 23:50:00 +03:00
|
|
|
use rustc::mir;
|
2016-06-07 17:28:36 +03:00
|
|
|
|
2018-11-16 13:45:28 +02:00
|
|
|
use traits::BuilderMethods;
|
2018-01-05 07:34:28 +02:00
|
|
|
use super::FunctionCx;
|
2016-06-20 23:55:14 +03:00
|
|
|
use super::LocalRef;
|
2018-10-01 15:13:42 +02:00
|
|
|
use super::OperandValue;
|
2018-11-16 13:45:28 +02:00
|
|
|
use traits::*;
|
2015-10-21 17:42:25 -04:00
|
|
|
|
2018-09-20 15:47:22 +02:00
|
|
|
impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|
|
|
|
pub fn codegen_statement(
|
|
|
|
|
&mut self,
|
2018-10-05 15:08:49 +02:00
|
|
|
mut bx: Bx,
|
2018-09-20 15:47:22 +02:00
|
|
|
statement: &mir::Statement<'tcx>
|
|
|
|
|
) -> Bx {
|
2018-05-08 16:10:16 +03:00
|
|
|
debug!("codegen_statement(statement={:?})", statement);
|
2015-10-21 17:42:25 -04:00
|
|
|
|
2018-10-05 15:08:49 +02:00
|
|
|
self.set_debug_loc(&mut bx, statement.source_info);
|
2015-10-21 17:42:25 -04:00
|
|
|
match statement.kind {
|
2017-12-01 14:39:51 +02:00
|
|
|
mir::StatementKind::Assign(ref place, ref rvalue) => {
|
|
|
|
|
if let mir::Place::Local(index) = *place {
|
2016-06-20 23:55:14 +03:00
|
|
|
match self.locals[index] {
|
2018-05-08 16:10:16 +03:00
|
|
|
LocalRef::Place(cg_dest) => {
|
|
|
|
|
self.codegen_rvalue(bx, cg_dest, rvalue)
|
2016-06-20 23:55:14 +03:00
|
|
|
}
|
2018-05-29 00:12:55 +09:00
|
|
|
LocalRef::UnsizedPlace(cg_indirect_dest) => {
|
|
|
|
|
self.codegen_rvalue_unsized(bx, cg_indirect_dest, rvalue)
|
|
|
|
|
}
|
2016-06-20 23:55:14 +03:00
|
|
|
LocalRef::Operand(None) => {
|
2018-05-08 16:10:16 +03:00
|
|
|
let (bx, operand) = self.codegen_rvalue_operand(bx, rvalue);
|
2016-06-20 23:55:14 +03:00
|
|
|
self.locals[index] = LocalRef::Operand(Some(operand));
|
2018-01-05 07:12:32 +02:00
|
|
|
bx
|
2016-06-20 23:55:14 +03:00
|
|
|
}
|
2017-09-20 18:17:23 +03:00
|
|
|
LocalRef::Operand(Some(op)) => {
|
|
|
|
|
if !op.layout.is_zst() {
|
2016-06-20 23:55:14 +03:00
|
|
|
span_bug!(statement.source_info.span,
|
|
|
|
|
"operand {:?} already assigned",
|
|
|
|
|
rvalue);
|
2015-11-02 09:39:59 -05:00
|
|
|
}
|
2017-09-20 18:17:23 +03:00
|
|
|
|
|
|
|
|
// If the type is zero-sized, it's already been set here,
|
2018-05-08 16:10:16 +03:00
|
|
|
// but we still need to make sure we codegen the operand
|
|
|
|
|
self.codegen_rvalue_operand(bx, rvalue).0
|
2015-11-02 09:39:59 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 23:55:14 +03:00
|
|
|
} else {
|
2018-10-05 15:08:49 +02:00
|
|
|
let cg_dest = self.codegen_place(&mut bx, place);
|
2018-05-08 16:10:16 +03:00
|
|
|
self.codegen_rvalue(bx, cg_dest, rvalue)
|
2015-11-02 09:39:59 -05:00
|
|
|
}
|
2015-10-21 17:42:25 -04:00
|
|
|
}
|
2017-12-01 14:39:51 +02:00
|
|
|
mir::StatementKind::SetDiscriminant{ref place, variant_index} => {
|
2018-10-05 15:08:49 +02:00
|
|
|
self.codegen_place(&mut bx, place)
|
|
|
|
|
.codegen_set_discr(&mut bx, variant_index);
|
2018-01-05 07:12:32 +02:00
|
|
|
bx
|
2016-08-04 16:14:33 -07:00
|
|
|
}
|
2017-09-04 08:01:46 +03:00
|
|
|
mir::StatementKind::StorageLive(local) => {
|
2018-05-08 16:10:16 +03:00
|
|
|
if let LocalRef::Place(cg_place) = self.locals[local] {
|
2018-10-05 15:08:49 +02:00
|
|
|
cg_place.storage_live(&mut bx);
|
2018-05-29 00:12:55 +09:00
|
|
|
} else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
|
2018-10-05 15:08:49 +02:00
|
|
|
cg_indirect_place.storage_live(&mut bx);
|
2017-06-01 21:50:53 +03:00
|
|
|
}
|
2018-01-05 07:12:32 +02:00
|
|
|
bx
|
2016-08-14 06:34:14 +03:00
|
|
|
}
|
2017-09-04 08:01:46 +03:00
|
|
|
mir::StatementKind::StorageDead(local) => {
|
2018-05-08 16:10:16 +03:00
|
|
|
if let LocalRef::Place(cg_place) = self.locals[local] {
|
2018-10-05 15:08:49 +02:00
|
|
|
cg_place.storage_dead(&mut bx);
|
2018-05-29 00:12:55 +09:00
|
|
|
} else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
|
2018-10-05 15:08:49 +02:00
|
|
|
cg_indirect_place.storage_dead(&mut bx);
|
2017-06-01 21:50:53 +03:00
|
|
|
}
|
2018-01-05 07:12:32 +02:00
|
|
|
bx
|
2016-08-14 06:34:14 +03:00
|
|
|
}
|
2017-02-15 21:21:36 +02:00
|
|
|
mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
|
|
|
|
|
let outputs = outputs.iter().map(|output| {
|
2018-10-05 15:08:49 +02:00
|
|
|
self.codegen_place(&mut bx, output)
|
2017-02-15 21:21:36 +02:00
|
|
|
}).collect();
|
|
|
|
|
|
2018-10-01 15:13:42 +02:00
|
|
|
let input_vals = inputs.iter()
|
2018-10-28 23:57:45 +01:00
|
|
|
.fold(Vec::with_capacity(inputs.len()), |mut acc, (span, input)| {
|
2018-10-05 15:08:49 +02:00
|
|
|
let op = self.codegen_operand(&mut bx, input);
|
2018-10-01 15:13:42 +02:00
|
|
|
if let OperandValue::Immediate(_) = op.val {
|
|
|
|
|
acc.push(op.immediate());
|
|
|
|
|
} else {
|
2018-11-27 19:00:25 +01:00
|
|
|
span_err!(bx.sess(), span.to_owned(), E0669,
|
2018-10-28 23:57:45 +01:00
|
|
|
"invalid value for constraint in inline assembly");
|
2018-10-01 15:13:42 +02:00
|
|
|
}
|
2018-10-28 23:57:45 +01:00
|
|
|
acc
|
2018-10-01 15:13:42 +02:00
|
|
|
});
|
2017-02-15 21:21:36 +02:00
|
|
|
|
2018-10-28 23:57:45 +01:00
|
|
|
if input_vals.len() == inputs.len() {
|
2018-09-20 15:47:22 +02:00
|
|
|
let res = bx.codegen_inline_asm(asm, outputs, input_vals);
|
2018-10-01 15:13:42 +02:00
|
|
|
if !res {
|
2018-11-27 19:00:25 +01:00
|
|
|
span_err!(bx.sess(), statement.source_info.span, E0668,
|
2018-10-01 15:13:42 +02:00
|
|
|
"malformed inline assembly");
|
|
|
|
|
}
|
2018-09-25 20:35:19 +02:00
|
|
|
}
|
2018-01-05 07:12:32 +02:00
|
|
|
bx
|
2017-02-15 21:21:36 +02:00
|
|
|
}
|
2018-09-14 21:05:31 +02:00
|
|
|
mir::StatementKind::FakeRead(..) |
|
2018-10-24 11:47:17 +02:00
|
|
|
mir::StatementKind::Retag { .. } |
|
2018-08-31 18:59:35 -04:00
|
|
|
mir::StatementKind::AscribeUserType(..) |
|
2018-01-05 07:12:32 +02:00
|
|
|
mir::StatementKind::Nop => bx,
|
2016-08-14 06:34:14 +03:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-21 17:42:25 -04:00
|
|
|
}
|