use orzir_core::{verify_error, Context, Op, VerifyResult};
use thiserror::Error;
#[derive(Debug, Error)]
#[error("operation is not a terminator")]
struct NotTerminatorError;
pub trait IsTerminator: Op {
fn verify(&self, ctx: &Context) -> VerifyResult<()> {
let parent_region = self.parent_region(ctx);
if parent_region.is_none() {
panic!("terminator is not in a region");
}
if self
.parent_block()
.unwrap()
.deref(&ctx.blocks)
.layout()
.back()
!= Some(self.self_ptr())
{
return verify_error!(NotTerminatorError).into();
}
Ok(())
}
}
pub trait NoTerminator: Op {
fn verify(&self, _ctx: &Context) -> VerifyResult<()> { Ok(()) }
}