use crate::ir::{Op, Slot};
macro_rules! bail_unreachable {
($this:ident) => {{
if !$this.reachable {
return ::core::result::Result::Ok(());
}
}};
}
macro_rules! swap_ops {
($make_instr:path) => {{ |result: $crate::ir::Slot, lhs, rhs| -> $crate::ir::Op { $make_instr(result, rhs, lhs) } }};
}
pub trait Reset: Sized {
fn reset(&mut self);
#[must_use]
fn into_reset(self) -> Self {
let mut this = self;
this.reset();
this
}
}
pub trait ReusableAllocations {
type Allocations: Default + Reset;
fn into_allocations(self) -> Self::Allocations;
}
pub enum Input<T> {
Slot(Slot),
Immediate(T),
}
pub trait UpdateResultSlot: Sized {
fn update_result_slot(&self, new_result: Slot) -> Option<Self>;
}
impl UpdateResultSlot for Op {
fn update_result_slot(&self, new_result: Slot) -> Option<Self> {
let mut op = *self;
let result_mut = op.result_mut()?;
*result_mut = new_result;
Some(op)
}
}