WIP.
This commit is contained in:
parent
9ce0d259b4
commit
5a6177b613
|
@ -145,7 +145,7 @@ impl<'a> WasmFuncBackend<'a> {
|
||||||
// If this value is "owned", do nothing: it will be lowered in
|
// If this value is "owned", do nothing: it will be lowered in
|
||||||
// the one place it's used.
|
// the one place it's used.
|
||||||
if self.trees.owner.contains_key(&inst) {
|
if self.trees.owner.contains_key(&inst) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
self.lower_inst(inst, /* root = */ true, func);
|
self.lower_inst(inst, /* root = */ true, func);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1032,6 +1032,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
wasmparser::Operator::Return => {
|
wasmparser::Operator::Return => {
|
||||||
let retvals = self.pop_n(self.module.signature(self.my_sig).returns.len());
|
let retvals = self.pop_n(self.module.signature(self.my_sig).returns.len());
|
||||||
self.emit_ret(&retvals[..]);
|
self.emit_ret(&retvals[..]);
|
||||||
|
self.reachable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => bail!(FrontendError::UnsupportedFeature(format!(
|
_ => bail!(FrontendError::UnsupportedFeature(format!(
|
||||||
|
@ -1056,6 +1057,13 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_ctrl_op(&mut self, op: wasmparser::Operator<'a>) -> Result<bool> {
|
fn handle_ctrl_op(&mut self, op: wasmparser::Operator<'a>) -> Result<bool> {
|
||||||
|
log::trace!(
|
||||||
|
"handle_ctrl_op: op {:?} reachable {} cur_block {}",
|
||||||
|
op,
|
||||||
|
self.reachable,
|
||||||
|
self.cur_block
|
||||||
|
);
|
||||||
|
log::trace!("ctrl stack: {:?}", self.ctrl_stack);
|
||||||
match &op {
|
match &op {
|
||||||
wasmparser::Operator::End => {
|
wasmparser::Operator::End => {
|
||||||
let frame = self.ctrl_stack.pop();
|
let frame = self.ctrl_stack.pop();
|
||||||
|
@ -1083,6 +1091,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
}) => {
|
}) => {
|
||||||
// Generate a branch to the out-block with
|
// Generate a branch to the out-block with
|
||||||
// blockparams for the results.
|
// blockparams for the results.
|
||||||
|
let was_reachable = self.reachable;
|
||||||
if self.reachable {
|
if self.reachable {
|
||||||
let result_values =
|
let result_values =
|
||||||
self.block_results(&results[..], *start_depth, self.cur_block);
|
self.block_results(&results[..], *start_depth, self.cur_block);
|
||||||
|
@ -1100,7 +1109,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
// Set `cur_block` only if currently set (otherwise, unreachable!)
|
// Set `cur_block` only if currently set (otherwise, unreachable!)
|
||||||
self.cur_block = *out;
|
self.cur_block = *out;
|
||||||
self.locals.start_block(*out, self.reachable);
|
self.locals.start_block(*out, self.reachable);
|
||||||
self.reachable = self.reachable
|
self.reachable = was_reachable
|
||||||
|| match &frame {
|
|| match &frame {
|
||||||
Some(Frame::Block { out_reachable, .. }) => *out_reachable,
|
Some(Frame::Block { out_reachable, .. }) => *out_reachable,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -1118,6 +1127,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
}) => {
|
}) => {
|
||||||
// Generate a branch to the out-block with
|
// Generate a branch to the out-block with
|
||||||
// blockparams for the results.
|
// blockparams for the results.
|
||||||
|
let was_reachable = self.reachable;
|
||||||
if self.reachable {
|
if self.reachable {
|
||||||
let result_values =
|
let result_values =
|
||||||
self.block_results(&results[..], *start_depth, self.cur_block);
|
self.block_results(&results[..], *start_depth, self.cur_block);
|
||||||
|
@ -1141,7 +1151,6 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
assert_eq!(self.op_stack.len(), *start_depth);
|
assert_eq!(self.op_stack.len(), *start_depth);
|
||||||
}
|
}
|
||||||
self.cur_block = *out;
|
self.cur_block = *out;
|
||||||
let was_reachable = self.reachable;
|
|
||||||
self.reachable = *head_reachable || self.reachable;
|
self.reachable = *head_reachable || self.reachable;
|
||||||
self.locals.seal_block_preds(*out, &mut self.body);
|
self.locals.seal_block_preds(*out, &mut self.body);
|
||||||
self.locals.start_block(*out, was_reachable);
|
self.locals.start_block(*out, was_reachable);
|
||||||
|
@ -1156,6 +1165,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
}) => {
|
}) => {
|
||||||
// Generate a branch to the out-block with
|
// Generate a branch to the out-block with
|
||||||
// blockparams for the results.
|
// blockparams for the results.
|
||||||
|
let was_reachable = self.reachable;
|
||||||
if self.reachable {
|
if self.reachable {
|
||||||
let result_values =
|
let result_values =
|
||||||
self.block_results(&results[..], *start_depth, self.cur_block);
|
self.block_results(&results[..], *start_depth, self.cur_block);
|
||||||
|
@ -1163,7 +1173,6 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
}
|
}
|
||||||
self.op_stack.truncate(*start_depth);
|
self.op_stack.truncate(*start_depth);
|
||||||
self.cur_block = *out;
|
self.cur_block = *out;
|
||||||
let was_reachable = self.reachable;
|
|
||||||
self.reachable = *merge_reachable || self.reachable;
|
self.reachable = *merge_reachable || self.reachable;
|
||||||
self.locals.seal_block_preds(*out, &mut self.body);
|
self.locals.seal_block_preds(*out, &mut self.body);
|
||||||
self.locals.start_block(*out, was_reachable);
|
self.locals.start_block(*out, was_reachable);
|
||||||
|
@ -1334,7 +1343,6 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
};
|
};
|
||||||
self.body
|
self.body
|
||||||
.end_block(self.cur_block, Terminator::Br { target });
|
.end_block(self.cur_block, Terminator::Br { target });
|
||||||
self.reachable = false;
|
|
||||||
self.locals.finish_block(true);
|
self.locals.finish_block(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1422,6 +1430,12 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_ret(&mut self, values: &[Value]) {
|
fn emit_ret(&mut self, values: &[Value]) {
|
||||||
|
log::trace!(
|
||||||
|
"emit_ret: cur_block {} reachable {} values {:?}",
|
||||||
|
self.cur_block,
|
||||||
|
self.reachable,
|
||||||
|
values
|
||||||
|
);
|
||||||
if self.reachable {
|
if self.reachable {
|
||||||
let values = values.to_vec();
|
let values = values.to_vec();
|
||||||
self.body
|
self.body
|
||||||
|
|
Loading…
Reference in a new issue