use crate::ir::{Block, Inst};
use core::fmt;
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum ProgramPoint {
Inst(Inst),
Block(Block),
}
impl ProgramPoint {
pub fn unwrap_inst(self) -> Inst {
match self {
Self::Inst(x) => x,
Self::Block(x) => panic!("expected inst: {}", x),
}
}
}
impl From<Inst> for ProgramPoint {
fn from(inst: Inst) -> Self {
Self::Inst(inst)
}
}
impl From<Block> for ProgramPoint {
fn from(block: Block) -> Self {
Self::Block(block)
}
}
impl fmt::Display for ProgramPoint {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Inst(x) => write!(f, "{}", x),
Self::Block(x) => write!(f, "{}", x),
}
}
}
impl fmt::Debug for ProgramPoint {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ProgramPoint({})", self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::entity::EntityRef;
use alloc::string::ToString;
#[test]
fn convert() {
let i5 = Inst::new(5);
let b3 = Block::new(3);
let pp1: ProgramPoint = i5.into();
let pp2: ProgramPoint = b3.into();
assert_eq!(pp1.to_string(), "inst5");
assert_eq!(pp2.to_string(), "block3");
}
}