25 lines
981 B
Rust
25 lines
981 B
Rust
//! BranchEmissionBox — 分岐/ジャンプ命令発行の薄いヘルパ(仕様不変)
|
|
|
|
use crate::mir::{BasicBlockId, MirInstruction};
|
|
use crate::mir::builder::MirBuilder;
|
|
|
|
#[inline]
|
|
pub fn emit_conditional(b: &mut MirBuilder, cond: crate::mir::ValueId, then_bb: BasicBlockId, else_bb: BasicBlockId) -> Result<(), String> {
|
|
if let (Some(func), Some(cur_bb)) = (b.current_function.as_mut(), b.current_block) {
|
|
crate::mir::ssot::cf_common::set_branch(func, cur_bb, cond, then_bb, else_bb);
|
|
Ok(())
|
|
} else {
|
|
b.emit_instruction(MirInstruction::Branch { condition: cond, then_bb, else_bb })
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
pub fn emit_jump(b: &mut MirBuilder, target: BasicBlockId) -> Result<(), String> {
|
|
if let (Some(func), Some(cur_bb)) = (b.current_function.as_mut(), b.current_block) {
|
|
crate::mir::ssot::cf_common::set_jump(func, cur_bb, target);
|
|
Ok(())
|
|
} else {
|
|
b.emit_instruction(MirInstruction::Jump { target })
|
|
}
|
|
}
|