use crate::generate::archetypes::TestInput;
use crate::generate::emit::naming::sanitize;
use crate::generate::emit::TemplateKind;
use crate::spec::types::OracleKind;
use crate::spec::Property;
#[inline]
pub(crate) fn oracle_name(kind: OracleKind) -> &'static str {
match kind {
OracleKind::Law => "Law",
OracleKind::SpecTable => "SpecTable",
OracleKind::ReferenceInterpreter => "ReferenceInterpreter",
OracleKind::CpuReference => "CpuReference",
OracleKind::Composition => "Composition",
OracleKind::External => "External",
OracleKind::Property => "Property",
}
}
#[inline]
pub(crate) fn last_segment(id: &str) -> &str {
match id.rsplit('.').next() {
Some(segment) => segment,
None => id,
}
}
#[inline]
pub(crate) fn property_key(property: &Property) -> String {
match property {
Property::DeclaredLawHolds { law } => format!("declared_law_{}", sanitize(law.name())),
Property::SpecTableRowMatches { row_index } => format!("spec_row_{row_index}"),
Property::PointParity { input_index } => format!("point_parity_{input_index}"),
Property::CompositionPreservesLaw { law } => {
format!("composition_law_{}", sanitize(law.name()))
}
Property::PropertyCheck { description } => format!("property_{}", sanitize(description)),
}
}
#[inline]
pub(crate) fn template_src(kind: TemplateKind) -> &'static str {
match kind {
TemplateKind::OpCorrectness => include_str!("../../templates/op_correctness.tmpl"),
TemplateKind::Law => include_str!("../../templates/law.tmpl"),
TemplateKind::BackendEquiv => include_str!("../../templates/backend_equiv.tmpl"),
TemplateKind::Archetype => include_str!("../../templates/archetype.tmpl"),
TemplateKind::Validation => include_str!("../../templates/validation.tmpl"),
TemplateKind::MutationKill => include_str!("../../templates/mutation_kill.tmpl"),
}
}
#[inline]
pub(crate) fn input_bytes_for_arity(input: &TestInput, arity: usize) -> Vec<u8> {
(0..arity)
.map(|index| input.values.get(index).copied().unwrap_or(0))
.flat_map(|value| value.to_le_bytes())
.collect()
}