use std::ops::Range;
use super::block_id::BlockId;
use super::terminator::Terminator;
#[derive(Debug, Clone)]
pub struct BasicBlock {
pub id: BlockId,
pub start_offset: usize,
pub end_offset: usize,
pub instruction_range: Range<usize>,
pub terminator: Terminator,
}
impl BasicBlock {
#[must_use]
pub fn new(
id: BlockId,
start_offset: usize,
end_offset: usize,
instruction_range: Range<usize>,
terminator: Terminator,
) -> Self {
Self {
id,
start_offset,
end_offset,
instruction_range,
terminator,
}
}
#[must_use]
pub fn contains_offset(&self, offset: usize) -> bool {
offset >= self.start_offset && offset < self.end_offset
}
#[must_use]
pub fn instruction_count(&self) -> usize {
self.instruction_range.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.instruction_range.is_empty()
}
}