pr 04
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -23,5 +23,6 @@ pub mod layout;
|
||||
pub mod decoder;
|
||||
|
||||
mod model;
|
||||
pub mod io;
|
||||
|
||||
pub use model::*;
|
||||
|
||||
Reference in New Issue
Block a user