pub fn find_anchor_branch(
bytecode: &[u8],
source_map: &SourceMap,
item_id: usize,
loc: &SourceLocation,
) -> Result<(ItemAnchor, ItemAnchor)>
Expand description
Finds the anchor corresponding to a branch item.
This finds the relevant anchors for a branch coverage item. These anchors are found using the bytecode of the contract in the range of the branching node.
For IfStatement
nodes, the template is generally:
<condition>
PUSH <ic if false>
JUMPI
<true branch>
<...>
<false branch>
For assert
and require
, the template is generally:
PUSH <ic if true>
JUMPI
<revert>
<...>
<true branch>
This function will look for the last JUMPI instruction, backtrack to find the program counter of the first branch, and return an item for that program counter, and the program counter immediately after the JUMPI instruction.