vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
//! Comparison mutations.

use crate::adversarial::mutations::catalog::BinOpKind;

fn op_symbol(op: BinOpKind) -> &'static str {
    match op {
        BinOpKind::Lt => "<",
        BinOpKind::Le => "<=",
        BinOpKind::Gt => ">",
        BinOpKind::Ge => ">=",
        BinOpKind::Eq => "==",
        BinOpKind::Ne => "!=",
        BinOpKind::Add => "+",
        BinOpKind::Sub => "-",
        BinOpKind::Mul => "*",
        BinOpKind::Div => "/",
        BinOpKind::Shl => "<<",
        BinOpKind::Shr => ">>",
        BinOpKind::And => "&",
        BinOpKind::Or => "|",
        BinOpKind::Xor => "^",
    }
}

/// Swap a comparison operator.
#[inline]
pub fn apply_op_swap(source: &str, from: BinOpKind, to: BinOpKind) -> String {
    crate::adversarial::mutations::catalog::replace_operator(
        source,
        op_symbol(from),
        op_symbol(to),
        1,
    )
}

/// Invert boolean results by swapping `true`/`false` and the first `==`.
#[inline]
pub fn apply_invert(source: &str) -> String {
    let tmp = crate::adversarial::mutations::catalog::lexical::replace_code_word(
        source,
        "true",
        "__VYRE_TMP_TRUE__",
        usize::MAX,
    );
    let tmp = crate::adversarial::mutations::catalog::lexical::replace_code_word(
        &tmp,
        "false",
        "true",
        usize::MAX,
    );
    let tmp = crate::adversarial::mutations::catalog::lexical::replace_code_word(
        &tmp,
        "__VYRE_TMP_TRUE__",
        "false",
        usize::MAX,
    );
    crate::adversarial::mutations::catalog::replace_operator(&tmp, "==", "!=", 1)
}