2025-08-26 05:49:23 +09:00
|
|
|
//! Introspection helpers for MIR instruction set
|
2025-08-31 06:22:48 +09:00
|
|
|
//!
|
|
|
|
|
//! Migration note:
|
|
|
|
|
//! - Historically we synced to a canonical 26-instruction doc list.
|
|
|
|
|
//! - We are migrating to Core-15 for enforcement and tests. During migration,
|
|
|
|
|
//! docs may still list 26; tests should use `core15_instruction_names()`.
|
2025-08-26 05:49:23 +09:00
|
|
|
|
2025-08-31 06:22:48 +09:00
|
|
|
/// Returns the legacy canonical list of core MIR instruction names (26 items).
|
|
|
|
|
/// This list matched docs/reference/mir/INSTRUCTION_SET.md under "Core Instructions".
|
2025-08-26 05:49:23 +09:00
|
|
|
pub fn core_instruction_names() -> &'static [&'static str] {
|
|
|
|
|
&[
|
|
|
|
|
"Const",
|
|
|
|
|
"Copy",
|
|
|
|
|
"Load",
|
|
|
|
|
"Store",
|
|
|
|
|
"UnaryOp",
|
|
|
|
|
"BinOp",
|
|
|
|
|
"Compare",
|
|
|
|
|
"Jump",
|
|
|
|
|
"Branch",
|
|
|
|
|
"Phi",
|
|
|
|
|
"Return",
|
|
|
|
|
"Call",
|
|
|
|
|
"ExternCall",
|
|
|
|
|
"BoxCall",
|
|
|
|
|
"NewBox",
|
|
|
|
|
"ArrayGet",
|
|
|
|
|
"ArraySet",
|
|
|
|
|
"RefNew",
|
|
|
|
|
"RefGet",
|
|
|
|
|
"RefSet",
|
|
|
|
|
"Await",
|
|
|
|
|
"Print",
|
|
|
|
|
"TypeOp",
|
|
|
|
|
"WeakRef",
|
|
|
|
|
"Barrier",
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-31 06:22:48 +09:00
|
|
|
/// Returns the Core-15 instruction names used for the minimal kernel enforcement.
|
|
|
|
|
/// This list is implementation-driven for migration stage; docs may differ temporarily.
|
|
|
|
|
pub fn core15_instruction_names() -> &'static [&'static str] {
|
|
|
|
|
&[
|
|
|
|
|
// 値/計算
|
|
|
|
|
"Const",
|
|
|
|
|
"UnaryOp",
|
|
|
|
|
"BinOp",
|
|
|
|
|
"Compare",
|
|
|
|
|
"TypeOp",
|
|
|
|
|
// メモリ
|
|
|
|
|
"Load",
|
|
|
|
|
"Store",
|
|
|
|
|
// 制御
|
|
|
|
|
"Jump",
|
|
|
|
|
"Branch",
|
|
|
|
|
"Return",
|
|
|
|
|
"Phi",
|
|
|
|
|
// 呼び出し/Box
|
|
|
|
|
"Call",
|
|
|
|
|
"NewBox",
|
|
|
|
|
"BoxCall",
|
|
|
|
|
"ExternCall",
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 06:30:01 +09:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
use std::fs;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::collections::BTreeSet;
|
|
|
|
|
|
2025-08-31 06:22:48 +09:00
|
|
|
// Core-15 enforcement: only count check; names are implementation-defined during migration.
|
2025-08-26 06:30:01 +09:00
|
|
|
#[test]
|
2025-08-31 06:22:48 +09:00
|
|
|
fn core15_instruction_count_is_15() {
|
|
|
|
|
let impl_names = core15_instruction_names();
|
|
|
|
|
assert_eq!(impl_names.len(), 15, "Core-15 must contain exactly 15 instructions");
|
|
|
|
|
// basic sanity: includes a few key ops
|
|
|
|
|
let set: BTreeSet<_> = impl_names.iter().copied().collect();
|
|
|
|
|
for must in ["Const", "BinOp", "Return", "ExternCall"] { assert!(set.contains(must), "missing '{}'", must); }
|
2025-08-26 06:30:01 +09:00
|
|
|
}
|
|
|
|
|
}
|