This commit is contained in:
Nilton Constantino 2026-01-30 12:08:30 +00:00
parent 76660294d5
commit 4f442f3123
No known key found for this signature in database
3 changed files with 31 additions and 10 deletions

View File

@ -131,10 +131,10 @@ impl<'a> BytecodeEmitter<'a> {
InstrKind::BitXor => asm_instrs.push(Asm::Op(OpCode::BitXor, vec![])),
InstrKind::Shl => asm_instrs.push(Asm::Op(OpCode::Shl, vec![])),
InstrKind::Shr => asm_instrs.push(Asm::Op(OpCode::Shr, vec![])),
InstrKind::GetLocal(slot) => {
InstrKind::LocalLoad { slot } => {
asm_instrs.push(Asm::Op(OpCode::GetLocal, vec![Operand::U32(*slot)]));
}
InstrKind::SetLocal(slot) => {
InstrKind::LocalStore { slot } => {
asm_instrs.push(Asm::Op(OpCode::SetLocal, vec![Operand::U32(*slot)]));
}
InstrKind::GetGlobal(slot) => {

View File

@ -109,9 +109,9 @@ pub enum InstrKind {
// --- Variable Access ---
/// Retrieves a value from a local variable slot and pushes it onto the stack.
GetLocal(u32),
LocalLoad { slot: u32 },
/// Pops a value from the stack and stores it in a local variable slot.
SetLocal(u32),
LocalStore { slot: u32 },
/// Retrieves a value from a global variable slot and pushes it onto the stack.
GetGlobal(u32),
/// Pops a value from the stack and stores it in a global variable slot.
@ -207,8 +207,8 @@ mod tests {
InstrKind::BitXor,
InstrKind::Shl,
InstrKind::Shr,
InstrKind::GetLocal(0),
InstrKind::SetLocal(0),
InstrKind::LocalLoad { slot: 0 },
InstrKind::LocalStore { slot: 0 },
InstrKind::GetGlobal(0),
InstrKind::SetGlobal(0),
InstrKind::Jmp(Label("target".to_string())),
@ -266,10 +266,14 @@ mod tests {
"Shl",
"Shr",
{
"GetLocal": 0
"LocalLoad": {
"slot": 0
}
},
{
"SetLocal": 0
"LocalStore": {
"slot": 0
}
},
{
"GetGlobal": 0
@ -322,4 +326,21 @@ mod tests {
]"#;
assert_eq!(serialized, expected_json);
}
#[test]
fn test_no_ref_leakage_in_instr_names() {
// Enforce the rule that "Ref" must never refer to HIP memory in ir_vm.
// The snapshot test above already locks the names, but this test
// explicitly asserts the absence of the "Ref" substring in HIP-related instructions.
let instructions = [
"GateLoad", "GateStore", "Alloc",
"GateBeginPeek", "GateEndPeek",
"GateBeginBorrow", "GateEndBorrow",
"GateBeginMutate", "GateEndMutate"
];
for name in instructions {
assert!(!name.contains("Ref"), "Instruction {} contains forbidden 'Ref' terminology", name);
}
}
}

View File

@ -53,8 +53,8 @@ pub fn lower_function(core_func: &ir_core::Function) -> Result<ir_vm::Function>
arg_count: *arg_count
},
ir_core::Instr::HostCall(id) => ir_vm::InstrKind::Syscall(*id),
ir_core::Instr::GetLocal(slot) => ir_vm::InstrKind::GetLocal(*slot),
ir_core::Instr::SetLocal(slot) => ir_vm::InstrKind::SetLocal(*slot),
ir_core::Instr::GetLocal(slot) => ir_vm::InstrKind::LocalLoad { slot: *slot },
ir_core::Instr::SetLocal(slot) => ir_vm::InstrKind::LocalStore { slot: *slot },
ir_core::Instr::Pop => ir_vm::InstrKind::Pop,
ir_core::Instr::Dup => ir_vm::InstrKind::Dup,
ir_core::Instr::Add => ir_vm::InstrKind::Add,