use super::Node;
use crate::ir::model::expr::Expr;
impl Node {
#[must_use]
#[inline]
pub fn let_bind(name: impl Into<String>, value: Expr) -> Self {
Self::Let {
name: name.into(),
value,
}
}
#[must_use]
#[inline]
pub fn assign(name: &str, value: Expr) -> Self {
Self::Assign {
name: name.to_string(),
value,
}
}
#[must_use]
#[inline]
pub fn store(buffer: &str, index: Expr, value: Expr) -> Self {
Self::Store {
buffer: buffer.to_string(),
index,
value,
}
}
#[must_use]
#[inline]
pub fn if_then_else(cond: Expr, then: Vec<Self>, otherwise: Vec<Self>) -> Self {
Self::If {
cond,
then,
otherwise,
}
}
#[must_use]
#[inline]
pub fn if_then(cond: Expr, then: Vec<Self>) -> Self {
Self::If {
cond,
then,
otherwise: Vec::new(),
}
}
#[must_use]
#[inline]
pub fn loop_for(var: &str, from: Expr, to: Expr, body: Vec<Self>) -> Self {
Self::Loop {
var: var.to_string(),
from,
to,
body,
}
}
#[must_use]
#[inline]
pub fn loop_(var: &str, from: Expr, to: Expr, body: Vec<Self>) -> Self {
Self::loop_for(var, from, to, body)
}
#[must_use]
#[inline]
pub fn block(nodes: Vec<Self>) -> Self {
Self::Block(nodes)
}
#[must_use]
pub const fn return_() -> Self {
Self::Return
}
#[must_use]
pub const fn barrier() -> Self {
Self::Barrier
}
}