From 6aba056348d2a8f9dfb452c276ca5e400d56ad57 Mon Sep 17 00:00:00 2001 From: h3lio5 Date: Sun, 7 Apr 2024 14:56:29 +0530 Subject: [PATCH 1/2] feat: add modifies_memory macro --- crates/interpreter/src/instructions/opcode.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/interpreter/src/instructions/opcode.rs b/crates/interpreter/src/instructions/opcode.rs index 8896c9da27..af38e48ca4 100644 --- a/crates/interpreter/src/instructions/opcode.rs +++ b/crates/interpreter/src/instructions/opcode.rs @@ -498,6 +498,28 @@ impl OpCode { } } +/// Returns true if the opcode modifies memory. +/// +/// +#[inline] +pub const fn modifies_memory(opcode: OpCode) -> bool { + matches!( + opcode, + OpCode::EXTCODECOPY + | OpCode::MLOAD + | OpCode::MSTORE + | OpCode::MSTORE8 + | OpCode::MCOPY + | OpCode::CODECOPY + | OpCode::CALLDATACOPY + | OpCode::RETURNDATACOPY + | OpCode::CALL + | OpCode::CALLCODE + | OpCode::DELEGATECALL + | OpCode::STATICCALL + ) +} + #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct OpInfo { /// Data contains few information packed inside u32: From d466979a5ac4672862166627d1b52035f8b3ac2c Mon Sep 17 00:00:00 2001 From: h3lio5 Date: Sun, 7 Apr 2024 17:47:00 +0530 Subject: [PATCH 2/2] refactor --- crates/interpreter/src/instructions/opcode.rs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/interpreter/src/instructions/opcode.rs b/crates/interpreter/src/instructions/opcode.rs index af38e48ca4..58aea3172e 100644 --- a/crates/interpreter/src/instructions/opcode.rs +++ b/crates/interpreter/src/instructions/opcode.rs @@ -496,28 +496,28 @@ impl OpCode { pub const fn get(self) -> u8 { self.0 } -} -/// Returns true if the opcode modifies memory. -/// -/// -#[inline] -pub const fn modifies_memory(opcode: OpCode) -> bool { - matches!( - opcode, - OpCode::EXTCODECOPY - | OpCode::MLOAD - | OpCode::MSTORE - | OpCode::MSTORE8 - | OpCode::MCOPY - | OpCode::CODECOPY - | OpCode::CALLDATACOPY - | OpCode::RETURNDATACOPY - | OpCode::CALL - | OpCode::CALLCODE - | OpCode::DELEGATECALL - | OpCode::STATICCALL - ) + /// Returns true if the opcode modifies memory. + /// + /// + #[inline] + pub const fn modifies_memory(&self) -> bool { + matches!( + *self, + OpCode::EXTCODECOPY + | OpCode::MLOAD + | OpCode::MSTORE + | OpCode::MSTORE8 + | OpCode::MCOPY + | OpCode::CODECOPY + | OpCode::CALLDATACOPY + | OpCode::RETURNDATACOPY + | OpCode::CALL + | OpCode::CALLCODE + | OpCode::DELEGATECALL + | OpCode::STATICCALL + ) + } } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]