pub struct TranslationContext {
pub code: Vec<u8>,
pub bitmask: Vec<u8>,
pub jump_table: Vec<u32>,
pub is_64bit: bool,
pub address_map: HashMap<u64, u32>,
pub code_ranges: Vec<(u64, u64)>,
/* private fields */
}Expand description
Translation context for converting RISC-V to PVM.
Fields§
§code: Vec<u8>Emitted PVM code bytes.
bitmask: Vec<u8>Bitmask: 1 for instruction start, 0 for continuation.
jump_table: Vec<u32>Jump table entries.
is_64bit: boolWhether translating 64-bit RISC-V.
address_map: HashMap<u64, u32>Map from RISC-V address to PVM code offset.
code_ranges: Vec<(u64, u64)>RISC-V code address ranges (lo, hi) — used to detect function pointers loaded via auipc+addi that need jump table entries.
Implementations§
Source§impl TranslationContext
impl TranslationContext
pub fn new(is_64bit: bool) -> Self
Sourcepub fn is_code_addr(&self, addr: u64) -> bool
pub fn is_code_addr(&self, addr: u64) -> bool
Build a mapping from RISC-V code addresses to PVM jump table addresses.
Only creates jump table entries for the given targets — the set of
RISC-V addresses actually referenced as function pointers (e.g. from
Check whether an address falls within any RISC-V code section.
Sourcepub fn build_function_pointer_map(
&mut self,
targets: &HashSet<u64>,
) -> HashMap<u64, u32>
pub fn build_function_pointer_map( &mut self, targets: &HashSet<u64>, ) -> HashMap<u64, u32>
absolute relocations in data sections like vtables). Returns a map of RISC-V address → jump table address (= (index+1)*2).
This is needed to fix indirect calls through function pointers stored in
data sections (vtables, callbacks, etc.). The PVM’s jump_ind instruction
expects jump table addresses, not raw code offsets.