This commit is contained in:
Chris Fallin 2021-12-19 14:47:40 -08:00
parent 7c15340372
commit b9c59fb5c0
2 changed files with 25 additions and 11 deletions

View file

@ -24,11 +24,11 @@ pub enum SerializedBlockTarget {
pub enum SerializedOperator {
StartBlock {
header: BlockId,
params: Vec<(Value, wasmparser::Type)>,
params: Vec<(wasmparser::Type, Value)>,
},
StartLoop {
header: BlockId,
param: Vec<(Value, wasmparser::Type)>,
param: Vec<(wasmparser::Type, Value)>,
},
Br(SerializedBlockTarget),
BrIf {
@ -61,10 +61,22 @@ impl SerializedBody {
operators: &mut Vec<SerializedOperator>,
) {
match entry {
&BlockOrderEntry::StartBlock(header, ref param_tys) => {
todo!()
&BlockOrderEntry::StartBlock(header, ref params) => {
operators.push(SerializedOperator::StartBlock {
header,
params: params.clone(),
});
}
_ => {
&BlockOrderEntry::StartLoop(header, ref params) => {
operators.push(SerializedOperator::StartBlock {
header,
params: params.clone(),
});
}
&BlockOrderEntry::End => {
operators.push(SerializedOperator::End);
}
&BlockOrderEntry::BasicBlock(block, ref targets) => {
todo!()
}
}

View file

@ -295,6 +295,7 @@ pub struct BlockOrderTarget {
pub target: BlockId,
/// `None` means fallthrough.
pub relative_branch: Option<usize>,
pub args: Vec<Value>,
}
impl BlockOrder {
@ -360,27 +361,28 @@ impl BlockOrder {
&WasmRegion::Leaf(block) => {
let mut targets = vec![];
for &succ in &cfg.block_succs[block] {
f.blocks[block].terminator.visit_targets(|target| {
log::trace!(
"BlockOrder::generate_region: looking for succ {} in stack {:?} fallthrough {:?}",
succ,
target.block,
target_stack,
fallthrough,
);
let relative_branch = if Some(succ) == fallthrough {
let relative_branch = if Some(target.block) == fallthrough {
None
} else {
let pos = target_stack
.iter()
.position(|entry| *entry == succ)
.position(|entry| *entry == target.block)
.expect("Malformed Wasm structured control flow");
Some(target_stack.len() - 1 - pos)
};
targets.push(BlockOrderTarget {
target: succ,
target: target.block,
relative_branch,
args: target.args.clone(),
});
});
}
entries.push(BlockOrderEntry::BasicBlock(block, targets));
}
}