This commit is contained in:
2026-03-24 13:40:31 +00:00
parent cf94ecda84
commit 6eda2d21ac
13 changed files with 93 additions and 97 deletions
+1 -4
View File
@@ -62,10 +62,7 @@ pub struct TrapInfo {
/// Checks if an instruction is a jump (branch) instruction.
pub fn is_jump(opcode: OpCode) -> bool {
match opcode {
OpCode::Jmp | OpCode::JmpIfFalse | OpCode::JmpIfTrue => true,
_ => false,
}
opcode.spec().is_branch
}
/// Checks if an instruction has any immediate operands in the instruction stream.
+11
View File
@@ -0,0 +1,11 @@
pub fn read_u32_le(buf: &[u8], pos: usize) -> Option<u32> {
let b = buf.get(pos..pos + 4)?;
Some(u32::from_le_bytes([b[0], b[1], b[2], b[3]]))
}
pub fn write_u32_le(buf: &mut [u8], pos: usize, v: u32) -> Option<()> {
let b = buf.get_mut(pos..pos + 4)?;
let le = v.to_le_bytes();
b.copy_from_slice(&le);
Some(())
}
-9
View File
@@ -53,12 +53,3 @@ pub fn function_index_by_pc(functions: &[FunctionMeta], code_len_total: usize, p
}
None
}
/// Clamps an absolute jump target to the end (exclusive) of the enclosing
/// function identified by `func_idx`.
#[inline]
pub fn clamp_jump_target(functions: &[FunctionMeta], code_len_total: usize, func_idx: usize, target_abs: u32) -> u32 {
let start = functions.get(func_idx).map(|f| f.code_offset as usize).unwrap_or(0);
let end = function_end_from_next(functions, func_idx, code_len_total);
if (target_abs as usize) > end { end as u32 } else { target_abs }
}
+1
View File
@@ -23,5 +23,6 @@ pub mod layout;
pub mod decoder;
mod model;
pub mod io;
pub use model::*;