pub struct ProgramBlob { /* private fields */ }
Expand description
A partially deserialized PolkaVM program.
Implementations§
Source§impl ProgramBlob
impl ProgramBlob
Sourcepub fn blob_length(raw_blob: &[u8]) -> Option<u64>
pub fn blob_length(raw_blob: &[u8]) -> Option<u64>
Parses the blob length information from the given raw_blob
bytes.
Returns None
if raw_blob
doesn’t contain enough bytes to read the length.
Sourcepub fn parse(bytes: ArcBytes) -> Result<ProgramBlob, ProgramParseError>
pub fn parse(bytes: ArcBytes) -> Result<ProgramBlob, ProgramParseError>
Parses the given bytes into a program blob.
Sourcepub fn from_parts(parts: ProgramParts) -> Result<ProgramBlob, ProgramParseError>
pub fn from_parts(parts: ProgramParts) -> Result<ProgramBlob, ProgramParseError>
Creates a program blob from parts.
Sourcepub fn unique_hash(&self, include_debug: bool) -> Hash
pub fn unique_hash(&self, include_debug: bool) -> Hash
Calculates an unique hash of the program blob.
Sourcepub fn ro_data(&self) -> &[u8] ⓘ
pub fn ro_data(&self) -> &[u8] ⓘ
Returns the contents of the read-only data section.
This only covers the initial non-zero portion of the section; use ro_data_size
to get the full size.
Sourcepub fn ro_data_size(&self) -> u32
pub fn ro_data_size(&self) -> u32
Returns the size of the read-only data section.
This can be larger than the length of ro_data
, in which case the rest of the space is assumed to be filled with zeros.
Sourcepub fn rw_data(&self) -> &[u8] ⓘ
pub fn rw_data(&self) -> &[u8] ⓘ
Returns the contents of the read-write data section.
This only covers the initial non-zero portion of the section; use rw_data_size
to get the full size.
Sourcepub fn rw_data_size(&self) -> u32
pub fn rw_data_size(&self) -> u32
Returns the size of the read-write data section.
This can be larger than the length of rw_data
, in which case the rest of the space is assumed to be filled with zeros.
Sourcepub fn stack_size(&self) -> u32
pub fn stack_size(&self) -> u32
Returns the initial size of the stack.
pub fn imports(&self) -> Imports<'_>
Sourcepub fn exports(&self) -> impl Iterator<Item = ProgramExport<&[u8]>> + Clone
pub fn exports(&self) -> impl Iterator<Item = ProgramExport<&[u8]>> + Clone
Returns an iterator over program exports.
Sourcepub fn visit<T>(
&self,
dispatch_table: T,
visitor: &mut <T as OpcodeVisitor>::State,
)where
T: OpcodeVisitor<ReturnTy = ()>,
pub fn visit<T>(
&self,
dispatch_table: T,
visitor: &mut <T as OpcodeVisitor>::State,
)where
T: OpcodeVisitor<ReturnTy = ()>,
Visits every instrution in the program.
Sourcepub fn instructions<I>(&self, instruction_set: I) -> Instructions<'_, I>where
I: InstructionSet,
pub fn instructions<I>(&self, instruction_set: I) -> Instructions<'_, I>where
I: InstructionSet,
Returns an iterator over all of the instructions in the program.
WARNING: this is unbounded and has O(n) complexity; just creating this iterator can iterate over the whole program, even if next
is never called!
Sourcepub fn instructions_bounded_at<I>(
&self,
instruction_set: I,
offset: ProgramCounter,
) -> Instructions<'_, I>where
I: InstructionSet,
pub fn instructions_bounded_at<I>(
&self,
instruction_set: I,
offset: ProgramCounter,
) -> Instructions<'_, I>where
I: InstructionSet,
Returns an interator over instructions starting at a given offset.
This iterator is bounded and has O(1) complexity.
Sourcepub fn is_jump_target_valid<I>(
&self,
instruction_set: I,
target: ProgramCounter,
) -> boolwhere
I: InstructionSet,
pub fn is_jump_target_valid<I>(
&self,
instruction_set: I,
target: ProgramCounter,
) -> boolwhere
I: InstructionSet,
Returns whether the given program counter is a valid target for a jump.
Sourcepub fn jump_table(&self) -> JumpTable<'_>
pub fn jump_table(&self) -> JumpTable<'_>
Returns a jump table.
Sourcepub fn get_debug_string(&self, offset: u32) -> Result<&str, ProgramParseError>
pub fn get_debug_string(&self, offset: u32) -> Result<&str, ProgramParseError>
Returns the debug string for the given relative offset.
Sourcepub fn get_debug_line_program_at(
&self,
program_counter: ProgramCounter,
) -> Result<Option<LineProgram<'_>>, ProgramParseError>
pub fn get_debug_line_program_at( &self, program_counter: ProgramCounter, ) -> Result<Option<LineProgram<'_>>, ProgramParseError>
Returns the line program for the given instruction.
Trait Implementations§
Source§impl Clone for ProgramBlob
impl Clone for ProgramBlob
Source§fn clone(&self) -> ProgramBlob
fn clone(&self) -> ProgramBlob
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more