eva_asm/instruction/
flow.rs

1//! Flow Operations.
2
3use derive_more::Display;
4
5use crate::{
6    instruction::Instruction,
7    opcode::{Mnemonic, OpCode},
8};
9
10/// Alter the program counter.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
12#[display("{}", self.opcode())]
13pub struct Jump;
14
15impl Instruction for Jump {
16    fn opcode(&self) -> OpCode {
17        OpCode::Known(Mnemonic::JUMP)
18    }
19}
20
21/// Conditionally alter the program counter.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
23#[display("{}", self.opcode())]
24pub struct JumpI;
25
26impl Instruction for JumpI {
27    fn opcode(&self) -> OpCode {
28        OpCode::Known(Mnemonic::JUMPI)
29    }
30}
31
32/// Get the value of the program counter prior to the increment corresponding to this instruction.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
34#[display("{}", self.opcode())]
35pub struct Pc;
36
37impl Instruction for Pc {
38    fn opcode(&self) -> OpCode {
39        OpCode::Known(Mnemonic::PC)
40    }
41}
42
43/// Get the amount of available gas, including the corresponding reduction for the cost of this instruction.
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
45#[display("{}", self.opcode())]
46pub struct Gas;
47
48impl Instruction for Gas {
49    fn opcode(&self) -> OpCode {
50        OpCode::Known(Mnemonic::GAS)
51    }
52}
53
54/// Mark a valid destination for jumps.
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
56#[display("{}", self.opcode())]
57pub struct JumpDest;
58
59impl Instruction for JumpDest {
60    fn opcode(&self) -> OpCode {
61        OpCode::Known(Mnemonic::JUMPDEST)
62    }
63}