binaryninja/high_level_il/
block.rs

1use std::ops::Range;
2
3use crate::basic_block::{BasicBlock, BlockContext};
4use crate::rc::Ref;
5
6use super::{HighLevelILFunction, HighLevelILInstruction, HighLevelInstructionIndex};
7
8pub struct HighLevelILBlockIter {
9    function: Ref<HighLevelILFunction>,
10    range: Range<usize>,
11}
12
13impl Iterator for HighLevelILBlockIter {
14    type Item = HighLevelILInstruction;
15
16    fn next(&mut self) -> Option<Self::Item> {
17        self.range
18            .next()
19            .map(HighLevelInstructionIndex)
20            // TODO: Is this already MAPPED>!>?!? If so we map twice that is BAD!!!!
21            .and_then(|i| self.function.instruction_from_index(i))
22    }
23}
24
25pub struct HighLevelILBlock {
26    pub(crate) function: Ref<HighLevelILFunction>,
27}
28
29impl core::fmt::Debug for HighLevelILBlock {
30    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
31        // TODO: Actual basic block please
32        write!(f, "mlil_bb {:?}", self.function)
33    }
34}
35
36impl BlockContext for HighLevelILBlock {
37    type Instruction = HighLevelILInstruction;
38    type InstructionIndex = HighLevelInstructionIndex;
39    type Iter = HighLevelILBlockIter;
40
41    fn start(&self, block: &BasicBlock<Self>) -> HighLevelILInstruction {
42        // TODO: Is this start index already mappedd?????
43        self.function
44            .instruction_from_index(block.start_index())
45            .unwrap()
46    }
47
48    fn iter(&self, block: &BasicBlock<Self>) -> HighLevelILBlockIter {
49        HighLevelILBlockIter {
50            function: self.function.to_owned(),
51            range: block.start_index().0..block.end_index().0,
52        }
53    }
54}
55
56impl Clone for HighLevelILBlock {
57    fn clone(&self) -> Self {
58        HighLevelILBlock {
59            function: self.function.to_owned(),
60        }
61    }
62}