zksync_vm2/
instruction.rs1use std::fmt;
2
3use zksync_vm2_interface::ShouldStop;
4
5use crate::{addressing_modes::Arguments, vm::VirtualMachine};
6
7pub struct Instruction<T, W> {
12 pub(crate) handler: Handler<T, W>,
13 pub(crate) arguments: Arguments,
14}
15
16impl<T, W> fmt::Debug for Instruction<T, W> {
17 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
18 formatter
19 .debug_struct("Instruction")
20 .field("arguments", &self.arguments)
21 .finish_non_exhaustive()
22 }
23}
24
25pub(crate) type Handler<T, W> = fn(&mut VirtualMachine<T, W>, &mut W, &mut T) -> ExecutionStatus;
26
27#[derive(Debug)]
28pub(crate) enum ExecutionStatus {
29 Running,
30 Stopped(ExecutionEnd),
31}
32
33impl ExecutionStatus {
34 #[must_use]
35 #[inline(always)]
36 pub(crate) fn merge_tracer(self, should_stop: ShouldStop) -> Self {
37 match (&self, should_stop) {
38 (Self::Running, ShouldStop::Stop) => Self::Stopped(ExecutionEnd::StoppedByTracer),
39 _ => self,
40 }
41 }
42}
43
44impl From<ShouldStop> for ExecutionStatus {
45 fn from(should_stop: ShouldStop) -> Self {
46 match should_stop {
47 ShouldStop::Stop => Self::Stopped(ExecutionEnd::StoppedByTracer),
48 ShouldStop::Continue => Self::Running,
49 }
50 }
51}
52
53#[derive(Debug, PartialEq)]
55pub enum ExecutionEnd {
56 ProgramFinished(Vec<u8>),
58 Reverted(Vec<u8>),
60 Panicked,
62 SuspendedOnHook(u32),
64 StoppedByTracer,
66}