use crate::ir_inner::model::program::Program;
pub trait CpuOp {
fn cpu(input: &[u8], output: &mut Vec<u8>);
}
pub trait CategoryAOp {
fn program() -> Program;
}
pub type CpuFn = fn(input: &[u8], output: &mut Vec<u8>);
pub fn structured_intrinsic_cpu(input: &[u8], output: &mut Vec<u8>) {
output.clear();
tracing::error!(
target: "vyre::cpu_ref_fallback",
input_len = input.len(),
"structured intrinsic CPU adapter received flat bytes; no typed reference implementation is registered for this op. Fix: implement the op's typed reference in vyre-reference and dispatch via DialectRegistry::get_lowering(ReferenceBackend) instead of this fallback."
);
}
#[must_use]
pub fn is_fallback_cpu_ref(f: CpuFn) -> bool {
std::ptr::fn_addr_eq(f, structured_intrinsic_cpu as CpuFn)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_fallback_detects_structured_intrinsic() {
assert!(is_fallback_cpu_ref(structured_intrinsic_cpu));
}
#[test]
fn is_fallback_rejects_other_fn() {
#[allow(clippy::ptr_arg)] fn custom_cpu(_input: &[u8], _output: &mut Vec<u8>) {}
assert!(!is_fallback_cpu_ref(custom_cpu));
}
#[test]
fn structured_intrinsic_clears_output() {
let mut output = vec![1, 2, 3];
structured_intrinsic_cpu(b"input", &mut output);
assert!(output.is_empty());
}
}