File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,21 @@ where
159159 Array :: new ( blocks, count, context)
160160 }
161161 }
162+
163+ /// Returns the [`BasicBlock`] at the given instruction `index`.
164+ ///
165+ /// You can also retrieve this using [`LowLevelILInstruction::basic_block`].
166+ pub fn basic_block_containing_index (
167+ & self ,
168+ index : LowLevelInstructionIndex ,
169+ ) -> Option < Ref < BasicBlock < LowLevelILBlock < M , F > > > > {
170+ let block = unsafe { BNGetLowLevelILBasicBlockForInstruction ( self . handle , index. 0 ) } ;
171+ if block. is_null ( ) {
172+ None
173+ } else {
174+ Some ( unsafe { BasicBlock :: ref_from_raw ( block, LowLevelILBlock { function : self } ) } )
175+ }
176+ }
162177}
163178
164179impl < M : FunctionMutability > LowLevelILFunction < M , NonSSA > {
Original file line number Diff line number Diff line change 1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ use crate :: basic_block:: BasicBlock ;
16+ use crate :: rc:: Ref ;
17+
18+ use super :: block:: LowLevelILBlock ;
1519use super :: operation;
1620use super :: operation:: Operation ;
1721use super :: VisitorAction ;
@@ -98,6 +102,12 @@ where
98102 pub fn into_raw ( & self ) -> BNLowLevelILInstruction {
99103 unsafe { BNGetLowLevelILByIndex ( self . function . handle , self . expr_idx ( ) . 0 ) }
100104 }
105+
106+ /// Returns the [`BasicBlock`] containing the given [`LowLevelILInstruction`].
107+ pub fn basic_block ( & self ) -> Option < Ref < BasicBlock < LowLevelILBlock < M , F > > > > {
108+ // TODO: We might be able to .expect this if we guarantee that self.index is valid.
109+ self . function . basic_block_containing_index ( self . index )
110+ }
101111}
102112
103113impl < M , F > Debug for LowLevelILInstruction < ' _ , M , F >
You can’t perform that action at this time.
0 commit comments