This commit is contained in:
Chris Fallin 2021-12-12 10:34:19 -08:00
parent 0473031ba4
commit 563092e4f3
2 changed files with 25 additions and 7 deletions

View file

@ -559,18 +559,26 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
wasmparser::Operator::LocalGet { local_index } => {
let ty = self.body.locals[*local_index as usize];
let value = self.locals.get(&mut self.body, *local_index);
self.op_stack.push((ty, value));
if self.cur_block.is_some() {
let value = self.locals.get(&mut self.body, *local_index);
self.op_stack.push((ty, value));
} else {
self.op_stack.push((ty, Value::undef()));
}
}
wasmparser::Operator::LocalSet { local_index } => {
let (_, value) = self.op_stack.pop().unwrap();
self.locals.set(*local_index, value);
if self.cur_block.is_some() {
self.locals.set(*local_index, value);
}
}
wasmparser::Operator::LocalTee { local_index } => {
let (_ty, value) = *self.op_stack.last().unwrap();
self.locals.set(*local_index, value);
if self.cur_block.is_some() {
self.locals.set(*local_index, value);
}
}
wasmparser::Operator::Call { .. }
@ -978,9 +986,11 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
.map(|(_ty, value)| *value)
.collect::<Vec<_>>();
self.emit_cond_branch(cond, frame.br_target(), &args[..], cont, &[]);
self.cur_block = Some(cont);
self.locals.seal_block_preds(cont, &mut self.body);
self.locals.start_block(cont);
if self.cur_block.is_some() {
self.cur_block = Some(cont);
self.locals.start_block(cont);
}
}
}
}

View file

@ -87,6 +87,7 @@ impl FunctionBody {
}
pub fn set_alias(&mut self, value: Value, to: Value) {
assert_ne!(to, Value::undef());
log::trace!("set_alias: value {:?} to {:?}", value, to);
// Resolve the `to` value through all existing aliases.
let to = self.resolve_alias(to);
@ -116,8 +117,15 @@ impl FunctionBody {
value
}
pub fn add_blockparam(&mut self, block: BlockId, ty: Type) {
pub fn add_blockparam(&mut self, block: BlockId, ty: Type) -> usize {
let index = self.blocks[block].params.len();
self.blocks[block].params.push(ty);
index
}
pub fn add_blockparam_value(&mut self, block: BlockId, ty: Type) -> Value {
let index = self.add_blockparam(block, ty);
self.add_value(ValueDef::BlockParam(block, index), Some(ty))
}
pub fn add_placeholder(&mut self, ty: Type) -> Value {