2025-09-28 20:38:09 +09:00
|
|
|
//! ConstantEmissionBox — Const 命令の発行を集約(仕様不変)
|
2025-11-17 00:35:04 +09:00
|
|
|
//!
|
|
|
|
|
//! ✅ Phase 25.1b Fix: All constant emission now uses function-local ID generator
|
|
|
|
|
//! when inside a function context to ensure proper SSA verification.
|
2025-09-28 20:38:09 +09:00
|
|
|
|
|
|
|
|
use crate::mir::{ConstValue, MirInstruction, ValueId};
|
|
|
|
|
use crate::mir::builder::MirBuilder;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_integer(b: &mut MirBuilder, val: i64) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-09-28 20:38:09 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const { dst, value: ConstValue::Integer(val) });
|
|
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_bool(b: &mut MirBuilder, val: bool) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-09-28 20:38:09 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const { dst, value: ConstValue::Bool(val) });
|
|
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_float(b: &mut MirBuilder, val: f64) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-09-28 20:38:09 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const { dst, value: ConstValue::Float(val) });
|
|
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_string<S: Into<String>>(b: &mut MirBuilder, s: S) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-09-28 20:38:09 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const { dst, value: ConstValue::String(s.into()) });
|
|
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_null(b: &mut MirBuilder) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-09-28 20:38:09 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const { dst, value: ConstValue::Null });
|
|
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_void(b: &mut MirBuilder) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-09-28 20:38:09 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const { dst, value: ConstValue::Void });
|
|
|
|
|
dst
|
|
|
|
|
}
|