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