WIP.
This commit is contained in:
parent
7c15340372
commit
b9c59fb5c0
|
@ -24,11 +24,11 @@ pub enum SerializedBlockTarget {
|
||||||
pub enum SerializedOperator {
|
pub enum SerializedOperator {
|
||||||
StartBlock {
|
StartBlock {
|
||||||
header: BlockId,
|
header: BlockId,
|
||||||
params: Vec<(Value, wasmparser::Type)>,
|
params: Vec<(wasmparser::Type, Value)>,
|
||||||
},
|
},
|
||||||
StartLoop {
|
StartLoop {
|
||||||
header: BlockId,
|
header: BlockId,
|
||||||
param: Vec<(Value, wasmparser::Type)>,
|
param: Vec<(wasmparser::Type, Value)>,
|
||||||
},
|
},
|
||||||
Br(SerializedBlockTarget),
|
Br(SerializedBlockTarget),
|
||||||
BrIf {
|
BrIf {
|
||||||
|
@ -61,10 +61,22 @@ impl SerializedBody {
|
||||||
operators: &mut Vec<SerializedOperator>,
|
operators: &mut Vec<SerializedOperator>,
|
||||||
) {
|
) {
|
||||||
match entry {
|
match entry {
|
||||||
&BlockOrderEntry::StartBlock(header, ref param_tys) => {
|
&BlockOrderEntry::StartBlock(header, ref params) => {
|
||||||
todo!()
|
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!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,6 +295,7 @@ pub struct BlockOrderTarget {
|
||||||
pub target: BlockId,
|
pub target: BlockId,
|
||||||
/// `None` means fallthrough.
|
/// `None` means fallthrough.
|
||||||
pub relative_branch: Option<usize>,
|
pub relative_branch: Option<usize>,
|
||||||
|
pub args: Vec<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockOrder {
|
impl BlockOrder {
|
||||||
|
@ -360,27 +361,28 @@ impl BlockOrder {
|
||||||
|
|
||||||
&WasmRegion::Leaf(block) => {
|
&WasmRegion::Leaf(block) => {
|
||||||
let mut targets = vec![];
|
let mut targets = vec![];
|
||||||
for &succ in &cfg.block_succs[block] {
|
f.blocks[block].terminator.visit_targets(|target| {
|
||||||
log::trace!(
|
log::trace!(
|
||||||
"BlockOrder::generate_region: looking for succ {} in stack {:?} fallthrough {:?}",
|
"BlockOrder::generate_region: looking for succ {} in stack {:?} fallthrough {:?}",
|
||||||
succ,
|
target.block,
|
||||||
target_stack,
|
target_stack,
|
||||||
fallthrough,
|
fallthrough,
|
||||||
);
|
);
|
||||||
let relative_branch = if Some(succ) == fallthrough {
|
let relative_branch = if Some(target.block) == fallthrough {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let pos = target_stack
|
let pos = target_stack
|
||||||
.iter()
|
.iter()
|
||||||
.position(|entry| *entry == succ)
|
.position(|entry| *entry == target.block)
|
||||||
.expect("Malformed Wasm structured control flow");
|
.expect("Malformed Wasm structured control flow");
|
||||||
Some(target_stack.len() - 1 - pos)
|
Some(target_stack.len() - 1 - pos)
|
||||||
};
|
};
|
||||||
targets.push(BlockOrderTarget {
|
targets.push(BlockOrderTarget {
|
||||||
target: succ,
|
target: target.block,
|
||||||
relative_branch,
|
relative_branch,
|
||||||
|
args: target.args.clone(),
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
entries.push(BlockOrderEntry::BasicBlock(block, targets));
|
entries.push(BlockOrderEntry::BasicBlock(block, targets));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue