refactor(emit): 寄存器号 u8→u32 全链放宽,vreg 化去 checkpoint/reg_overflow(B005)

This commit is contained in:
爱特每羊队
2026-08-06 16:31:16 +08:00
parent c52bf6313e
commit 38d6c7a60e
54 changed files with 404 additions and 431 deletions
+8 -4
View File
@@ -14,9 +14,6 @@ use crate::IRFunction;
/// IRFunction → CompiledModule。错误消息与现状(退役前 compiler.rs)逐字一致。
pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
// 溢出检查 1:寄存器(仅 Operand::Reg 变体;This/NewTarget 是语义操作数,映射 254/255 合法)
if f.reg_overflow {
return Err("RangeError: function body uses too many registers (max 253)".into());
}
for inst in &f.insts {
for o in [&inst.rd, &inst.a, &inst.b] {
if let Operand::Reg(r) = o {
@@ -27,6 +24,13 @@ pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
}
}
// 溢出检查 1b:n_registers(u32 → CompiledModule u8 前的显式截断检查)。
// n_registers = max_regs = 最高分配号 + 1,合法上限 254(reg 0..253)。
// 纯参数/空体函数可能无指令引用最高号寄存器,逐指令检查漏掉,计数检查兜底防 u8 静默截断。
if f.n_registers > 254 {
return Err("RangeError: function body uses too many registers (max 253)".into());
}
// 溢出检查 2:常量池
if f.const_overflow || f.constants.len() > u16::MAX as usize {
return Err("RangeError: too many constants".into());
@@ -72,7 +76,7 @@ pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
Ok(CompiledModule {
bytecode: instrs,
constants: f.constants.clone(),
n_registers: f.n_registers,
n_registers: f.n_registers as u8,
n_args: f.param_layout.count as u8,
param_base: f.param_layout.base as u8,
builtin_reg_map: f.builtin_reg_map.clone(),