Skip to content

Commit

Permalink
Define Evm inst set
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Sep 12, 2024
1 parent 1b5a36f commit 81c2fa5
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 19 deletions.
17 changes: 7 additions & 10 deletions crates/ir/src/inst/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ pub struct BrTable {
default: Option<Block>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
pub struct Phi {
#[inst(value)]
values: Vec<(Value, Block)>,
ty: Type,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Call {
Expand All @@ -42,13 +49,3 @@ pub struct Return {
#[inst(value)]
arg: Option<Value>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
pub struct Phi {
#[inst(value)]
values: Vec<(Value, Block)>,
ty: Type,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Nop {}
8 changes: 1 addition & 7 deletions crates/ir/src/inst/data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use macros::Inst;
use smallvec::SmallVec;

use crate::{Type, Value};
use crate::Value;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Mload {
Expand All @@ -18,12 +18,6 @@ pub struct Mstore {
addr: Value,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Alloca {
ty: Type,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
pub struct Gep {
#[inst(value)]
Expand Down
93 changes: 93 additions & 0 deletions crates/ir/src/inst/evm/inst_set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use crate::inst::*;
use macros::inst_set;

#[inst_set(InstKind = "EvmInstSet")]
pub struct EvmInstSet(
arith::Add,
arith::Mul,
arith::Sub,
arith::Sdiv,
arith::Udiv,
arith::Umod,
arith::Smod,
arith::Shl,
arith::Shr,
arith::Sar,
cast::Sext,
cast::Zext,
cast::Trunc,
cast::Bitcast,
cmp::Lt,
cmp::Gt,
cmp::Slt,
cmp::Sgt,
cmp::Le,
cmp::Ge,
cmp::Sge,
cmp::Eq,
cmp::Ne,
cmp::IsZero,
control_flow::Jump,
control_flow::Br,
control_flow::Phi,
control_flow::BrTable,
control_flow::Call,
control_flow::Return,
data::Mload,
data::Mstore,
data::Gep,
logic::Not,
logic::And,
logic::Or,
logic::Xor,
evm::EvmStop,
evm::EvmAddMod,
evm::EvmMulMod,
evm::EvmExp,
evm::EvmByte,
evm::EvmKeccak256,
evm::EvmAddress,
evm::EvmBalance,
evm::EvmOrigin,
evm::EvmCaller,
evm::EvmCallValue,
evm::EvmCallDataLoad,
evm::EvmCallDataCopy,
evm::EvmCodeSize,
evm::EvmCodeCopy,
evm::EvmExtCodeCopy,
evm::EvmReturnDataSize,
evm::EvmReturnDataCopy,
evm::EvmExtCodeHash,
evm::EvmBlockHash,
evm::EvmCoinBase,
evm::EvmTimestamp,
evm::EvmNumber,
evm::EvmPrevRandao,
evm::EvmGasLimit,
evm::EvmChainId,
evm::EvmSelfBalance,
evm::EvmBaseFee,
evm::EvmBlobHash,
evm::EvmBlobBaseFee,
evm::EvmMstore8,
evm::EvmSload,
evm::EvmSstore,
evm::EvmMsize,
evm::EvmGas,
evm::EvmTload,
evm::EvmTstore,
evm::EvmLog0,
evm::EvmLog1,
evm::EvmLog2,
evm::EvmLog3,
evm::EvmLog4,
evm::EvmCreate,
evm::EvmCall,
evm::EvmReturn,
evm::EvmDelegateCall,
evm::EvmCreate2,
evm::EvmStaticCall,
evm::EvmRevert,
evm::EvmSelfDestruct,
);
1 change: 1 addition & 0 deletions crates/ir/src/inst/evm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use macros::Inst;
pub mod inst_set;

use crate::Value;

Expand Down
2 changes: 0 additions & 2 deletions crates/ir/src/inst/inst_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ define_inst_set_base! {
cast::Bitcast,
data::Mload,
data::Mstore,
data::Alloca,
data::Gep,
control_flow::Call,
control_flow::Jump,
control_flow::Br,
control_flow::BrTable,
control_flow::Return,
control_flow::Phi,
control_flow::Nop,
// Evm specific
evm::EvmStop,
evm::EvmAddMod,
Expand Down

0 comments on commit 81c2fa5

Please sign in to comment.