use vize_l0::{Allocator, Span, Vec};
use super::{EffectId, OpId, OpKind, Phase, Region, RegionId, StateEdge};
use crate::operand::Operand;
use crate::placement::PlacementRecord;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Op {
pub id: OpId,
pub kind: OpKind,
pub region: RegionId,
pub effect: Option<EffectId>,
pub span: Span,
}
impl Op {
#[must_use]
pub const fn new(id: OpId, kind: OpKind, region: RegionId, span: Span) -> Self {
Self {
id,
kind,
region,
effect: None,
span,
}
}
#[must_use]
pub const fn with_effect(mut self, effect: EffectId) -> Self {
self.effect = Some(effect);
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EffectScope {
pub id: EffectId,
pub owner: OpId,
pub region: RegionId,
pub span: Span,
}
#[derive(Debug)]
pub struct Program<'a> {
pub phase: Phase,
pub regions: Vec<'a, Region>,
pub ops: Vec<'a, Op>,
pub edges: Vec<'a, StateEdge>,
pub effects: Vec<'a, EffectScope>,
pub operands: Vec<'a, Operand<'a>>,
pub placements: Vec<'a, PlacementRecord>,
}
impl<'a> Program<'a> {
#[must_use]
pub fn new(allocator: &'a Allocator, phase: Phase) -> Self {
Self {
phase,
regions: Vec::new_in(&allocator),
ops: Vec::new_in(&allocator),
edges: Vec::new_in(&allocator),
effects: Vec::new_in(&allocator),
operands: Vec::new_in(&allocator),
placements: Vec::new_in(&allocator),
}
}
pub fn push_region(&mut self, region: Region) {
self.regions.push(region);
}
pub fn push_op(&mut self, op: Op) {
self.ops.push(op);
}
pub fn push_edge(&mut self, edge: StateEdge) {
self.edges.push(edge);
}
pub fn push_effect(&mut self, effect: EffectScope) {
self.effects.push(effect);
}
}