use crate::ir_inner::model::expr::Expr;
use crate::ir_inner::model::types::{BinOp, UnOp};
impl Expr {
#[must_use]
#[inline(always)]
pub fn add(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::Add,
left: Box::new(left),
right: Box::new(right),
}
}
#[must_use]
#[inline(always)]
pub fn sub(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::Sub,
left: Box::new(left),
right: Box::new(right),
}
}
#[must_use]
#[inline]
pub fn saturating_sub(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::Sub,
left: Box::new(left.clone()),
right: Box::new(Expr::BinOp {
op: BinOp::Min,
left: Box::new(left),
right: Box::new(right),
}),
}
}
#[must_use]
#[inline(always)]
pub fn mul(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::Mul,
left: Box::new(left),
right: Box::new(right),
}
}
#[must_use]
#[inline(always)]
pub fn div(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::Div,
left: Box::new(left),
right: Box::new(right),
}
}
#[must_use]
#[inline(always)]
pub fn mulhi(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::MulHigh,
left: Box::new(left),
right: Box::new(right),
}
}
#[must_use]
#[inline(always)]
pub fn rem(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::Mod,
left: Box::new(left),
right: Box::new(right),
}
}
#[must_use]
#[inline(always)]
pub fn negate(operand: Expr) -> Expr {
Expr::UnOp {
op: UnOp::Negate,
operand: Box::new(operand),
}
}
#[must_use]
#[inline(always)]
pub fn abs_diff(left: Expr, right: Expr) -> Expr {
Expr::BinOp {
op: BinOp::AbsDiff,
left: Box::new(left),
right: Box::new(right),
}
}
#[must_use]
#[inline]
pub fn wrapping_add(self, other: impl Into<Expr>) -> Self {
Self::BinOp {
op: BinOp::WrappingAdd,
left: Box::new(self),
right: Box::new(other.into()),
}
}
#[must_use]
#[inline]
pub fn wrapping_sub(self, other: impl Into<Expr>) -> Self {
Self::BinOp {
op: BinOp::WrappingSub,
left: Box::new(self),
right: Box::new(other.into()),
}
}
}