Single Responsibility Principle適用による完全分離: - Phase 1: テスト分離 → instruction/tests.rs (196行) - Phase 2: Display実装分離 → instruction/display.rs (130行) - Phase 3: メソッド実装分離 → instruction/methods.rs (247行) - Phase 4: 統合テスト成功(全コンパイルエラー解決) 技術的成果: - MirInstruction enumを単一責任に集中 - 各実装が独立して保守可能な構造 - EffectMask::read→READ修正も完了 - ビルド成功確認済み(警告のみ) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
137 lines
4.7 KiB
Rust
137 lines
4.7 KiB
Rust
//! Display implementation for MIR Instructions
|
|
//!
|
|
//! Provides human-readable string representation of MIR instructions for debugging and analysis.
|
|
|
|
use crate::mir::instruction::MirInstruction;
|
|
use std::fmt;
|
|
|
|
impl fmt::Display for MirInstruction {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
MirInstruction::Const { dst, value } => {
|
|
write!(f, "{} = const {}", dst, value)
|
|
}
|
|
MirInstruction::BinOp { dst, op, lhs, rhs } => {
|
|
write!(f, "{} = {} {:?} {}", dst, lhs, op, rhs)
|
|
}
|
|
MirInstruction::UnaryOp { dst, op, operand } => {
|
|
write!(f, "{} = {:?} {}", dst, op, operand)
|
|
}
|
|
MirInstruction::Compare { dst, op, lhs, rhs } => {
|
|
write!(f, "{} = {} {:?} {}", dst, lhs, op, rhs)
|
|
}
|
|
MirInstruction::Load { dst, ptr } => {
|
|
write!(f, "{} = load {}", dst, ptr)
|
|
}
|
|
MirInstruction::Store { value, ptr } => {
|
|
write!(f, "store {} -> {}", value, ptr)
|
|
}
|
|
MirInstruction::Call {
|
|
dst,
|
|
func,
|
|
callee: _, // TODO: Use callee for type-safe resolution display
|
|
args,
|
|
effects,
|
|
} => {
|
|
if let Some(dst) = dst {
|
|
write!(
|
|
f,
|
|
"{} = call {}({}); effects: {}",
|
|
dst,
|
|
func,
|
|
args.iter()
|
|
.map(|v| format!("{}", v))
|
|
.collect::<Vec<_>>()
|
|
.join(", "),
|
|
effects
|
|
)
|
|
} else {
|
|
write!(
|
|
f,
|
|
"call {}({}); effects: {}",
|
|
func,
|
|
args.iter()
|
|
.map(|v| format!("{}", v))
|
|
.collect::<Vec<_>>()
|
|
.join(", "),
|
|
effects
|
|
)
|
|
}
|
|
}
|
|
MirInstruction::PluginInvoke {
|
|
dst,
|
|
box_val,
|
|
method,
|
|
args,
|
|
effects: _,
|
|
} => {
|
|
if let Some(dst) = dst {
|
|
write!(
|
|
f,
|
|
"{} = plugin_invoke {}.{}({})",
|
|
dst,
|
|
box_val,
|
|
method,
|
|
args.iter()
|
|
.map(|v| format!("{}", v))
|
|
.collect::<Vec<_>>()
|
|
.join(", ")
|
|
)
|
|
} else {
|
|
write!(
|
|
f,
|
|
"plugin_invoke {}.{}({})",
|
|
box_val,
|
|
method,
|
|
args.iter()
|
|
.map(|v| format!("{}", v))
|
|
.collect::<Vec<_>>()
|
|
.join(", ")
|
|
)
|
|
}
|
|
}
|
|
MirInstruction::Return { value } => {
|
|
if let Some(value) = value {
|
|
write!(f, "ret {}", value)
|
|
} else {
|
|
write!(f, "ret void")
|
|
}
|
|
}
|
|
MirInstruction::ExternCall {
|
|
dst,
|
|
iface_name,
|
|
method_name,
|
|
args,
|
|
effects,
|
|
} => {
|
|
if let Some(dst) = dst {
|
|
write!(
|
|
f,
|
|
"{} = extern_call {}.{}({}); effects: {}",
|
|
dst,
|
|
iface_name,
|
|
method_name,
|
|
args.iter()
|
|
.map(|v| format!("{}", v))
|
|
.collect::<Vec<_>>()
|
|
.join(", "),
|
|
effects
|
|
)
|
|
} else {
|
|
write!(
|
|
f,
|
|
"extern_call {}.{}({}); effects: {}",
|
|
iface_name,
|
|
method_name,
|
|
args.iter()
|
|
.map(|v| format!("{}", v))
|
|
.collect::<Vec<_>>()
|
|
.join(", "),
|
|
effects
|
|
)
|
|
}
|
|
}
|
|
_ => write!(f, "{:?}", self), // Fallback for other instructions
|
|
}
|
|
}
|
|
} |