Expand description
Identifies a sequential block of instructions within the original
bytecode sequence. That is, a sequence does not contain a jump
destination (other than at the very start), and ends either with a
terminating instruction (e.g. RETURN
, REVERT
, etc) or an
unconditional branch (to another block).
Fields§
§start: usize
Starting offset (in bytes) of this block.
end: usize
End offset (in bytes) of this block. That is the first byte which is not part of this block.
Implementations§
source§impl Block
impl Block
sourcepub fn new(start: usize, end: usize) -> Self
pub fn new(start: usize, end: usize) -> Self
Examples found in repository?
src/disassembler.rs (line 253)
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
fn scan_blocks(bytes: &[u8]) -> Vec<Block> {
let mut blocks = Vec::new();
// Current position in bytecodes
let mut pc = 0;
// Identifies start of current block.
let mut start = 0;
// Parse the block
while pc < bytes.len() {
// Decode instruction at the current position
let insn = Instruction::decode(pc,&bytes);
// Increment PC for next instruction
pc = pc + insn.length(&[]);
// Check whether terminating instruction
match insn {
JUMPDEST(n) => {
// Determine whether start of this block, or next
// block.
if (pc - 1) != start {
// Start of next block
blocks.push(Block::new(start,pc-1));
start = pc - 1;
}
}
INVALID|JUMP|RETURN|REVERT|STOP => {
blocks.push(Block::new(start,pc));
start = pc;
}
_ => {}
}
}
// Append last block (if necessary)
if start != pc {
blocks.push(Block::new(start,pc));
}
// Done
blocks
}
Trait Implementations§
source§impl PartialEq<Block> for Block
impl PartialEq<Block> for Block
impl Copy for Block
impl Eq for Block
impl StructuralEq for Block
impl StructuralPartialEq for Block
Auto Trait Implementations§
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin for Block
impl UnwindSafe for Block
Blanket Implementations§
§impl<T> CloneAny for Twhere
T: Any + Clone,
impl<T> CloneAny for Twhere
T: Any + Clone,
fn clone_any(&self) -> Box<dyn CloneAny + 'static, Global>
fn clone_any_send(&self) -> Box<dyn CloneAny + Send + 'static, Global>where
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync + 'static, Global>where
T: Sync,
fn clone_any_send_sync(
&self
) -> Box<dyn CloneAny + Send + Sync + 'static, Global>where
T: Send + Sync,
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.