revm_primitives/bytecode/
legacy.rs

1mod jump_map;
2
3pub use jump_map::JumpTable;
4
5use crate::Bytes;
6use bitvec::{bitvec, order::Lsb0};
7use std::sync::Arc;
8
9/// Legacy analyzed
10#[derive(Clone, Debug, PartialEq, Eq, Hash)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub struct LegacyAnalyzedBytecode {
13    /// Bytecode with 32 zero bytes padding.
14    bytecode: Bytes,
15    /// Original bytes length.
16    original_len: usize,
17    /// Jump table.
18    jump_table: JumpTable,
19}
20
21impl Default for LegacyAnalyzedBytecode {
22    #[inline]
23    fn default() -> Self {
24        Self {
25            bytecode: Bytes::from_static(&[0]),
26            original_len: 0,
27            jump_table: JumpTable(Arc::new(bitvec![u8, Lsb0; 0])),
28        }
29    }
30}
31
32impl LegacyAnalyzedBytecode {
33    /// Create new analyzed bytecode.
34    pub fn new(bytecode: Bytes, original_len: usize, jump_table: JumpTable) -> Self {
35        Self {
36            bytecode,
37            original_len,
38            jump_table,
39        }
40    }
41
42    /// Returns a reference to the bytecode.
43    ///
44    /// The bytecode is padded with 32 zero bytes.
45    pub fn bytecode(&self) -> &Bytes {
46        &self.bytecode
47    }
48
49    /// Original bytes length.
50    pub fn original_len(&self) -> usize {
51        self.original_len
52    }
53
54    /// Original bytes without padding.
55    pub fn original_bytes(&self) -> Bytes {
56        self.bytecode.slice(..self.original_len)
57    }
58
59    /// Original bytes without padding.
60    pub fn original_byte_slice(&self) -> &[u8] {
61        &self.bytecode[..self.original_len]
62    }
63
64    /// Jumptable of analyzed bytes.
65    pub fn jump_table(&self) -> &JumpTable {
66        &self.jump_table
67    }
68}