include!(concat!(env!("OUT_DIR"), "/opcodes_yaml.rs"));
macro_rules! macro_opcodes_table {
(
$( ($code:literal, $variant:ident, $mnem:literal, $doc:literal, $_delta:expr, {$($f:tt)*}) ),*
$(,)?
) => {
const MACRO_OPCODES: &[(u8, &str)] = &[
$( ($code, $mnem), )*
];
};
}
crate::opcodes!(macro_opcodes_table);
#[expect(
clippy::indexing_slicing,
reason = "const fn cannot use slice::get; loop condition bounds the index"
)]
const fn str_eq(a: &str, b: &str) -> bool {
let ab = a.as_bytes();
let bb = b.as_bytes();
if ab.len() != bb.len() {
return false;
}
let mut i = 0;
while i < ab.len() {
if ab[i] != bb[i] {
return false;
}
i += 1;
}
true
}
#[expect(
clippy::indexing_slicing,
reason = "const fn cannot use slice::get; loop condition bounds the index"
)]
const fn tables_match() -> bool {
if MACRO_OPCODES.len() != YAML_OPCODES.len() {
return false;
}
let mut i = 0;
while i < MACRO_OPCODES.len() {
let (mc, mn) = MACRO_OPCODES[i];
let (yc, yn) = YAML_OPCODES[i];
if mc != yc || !str_eq(mn, yn) {
return false;
}
i += 1;
}
true
}
const _: () = assert!(
tables_match(),
"opcodes! x-macro disagrees with conformance/opcodes.yaml — \
update the YAML or the macro so they match, or run `make opcode-parity` \
for a detailed diff."
);
#[cfg(test)]
mod tests {
#[test]
fn tables_have_expected_size() {
assert_eq!(super::MACRO_OPCODES.len(), 93);
assert_eq!(super::YAML_OPCODES.len(), 93);
}
#[test]
fn tables_agree() {
assert_eq!(super::MACRO_OPCODES, super::YAML_OPCODES);
}
}