2025-09-28 20:38:09 +09:00
|
|
|
//! BranchEmissionBox — 分岐/ジャンプ命令発行の薄いヘルパ(仕様不変)
|
|
|
|
|
|
|
|
|
|
use crate::mir::builder::MirBuilder;
|
2025-11-21 06:25:17 +09:00
|
|
|
use crate::mir::{BasicBlockId, MirInstruction};
|
2025-09-28 20:38:09 +09:00
|
|
|
|
|
|
|
|
#[inline]
|
2025-11-21 06:25:17 +09:00
|
|
|
pub fn emit_conditional(
|
|
|
|
|
b: &mut MirBuilder,
|
|
|
|
|
cond: crate::mir::ValueId,
|
|
|
|
|
then_bb: BasicBlockId,
|
|
|
|
|
else_bb: BasicBlockId,
|
|
|
|
|
) -> Result<(), String> {
|
2025-12-15 23:41:30 +09:00
|
|
|
if let (Some(func), Some(cur_bb)) = (b.scope_ctx.current_function.as_mut(), b.current_block) {
|
2025-11-04 21:33:09 +09:00
|
|
|
crate::mir::ssot::cf_common::set_branch(func, cur_bb, cond, then_bb, else_bb);
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
2025-11-21 06:25:17 +09:00
|
|
|
b.emit_instruction(MirInstruction::Branch {
|
|
|
|
|
condition: cond,
|
|
|
|
|
then_bb,
|
|
|
|
|
else_bb,
|
|
|
|
|
})
|
2025-11-04 21:33:09 +09:00
|
|
|
}
|
2025-09-28 20:38:09 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_jump(b: &mut MirBuilder, target: BasicBlockId) -> Result<(), String> {
|
2025-12-15 23:41:30 +09:00
|
|
|
if let (Some(func), Some(cur_bb)) = (b.scope_ctx.current_function.as_mut(), b.current_block) {
|
2025-11-04 21:33:09 +09:00
|
|
|
crate::mir::ssot::cf_common::set_jump(func, cur_bb, target);
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
b.emit_instruction(MirInstruction::Jump { target })
|
|
|
|
|
}
|
2025-09-28 20:38:09 +09:00
|
|
|
}
|