Skip to content

Commit fd2f088

Browse files
committed
wip update old code for new insts
1 parent 4cc2876 commit fd2f088

File tree

31 files changed

+3113
-96
lines changed

31 files changed

+3113
-96
lines changed

crates/codegen/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ sonatina-ir = { path = "../ir", version = "0.0.3-alpha" }
2222
sonatina-triple = { path = "../triple", version = "0.0.3-alpha" }
2323
sonatina-macros = { path = "../macros", version = "0.0.3-alpha" }
2424
bit-set = "0.8.0"
25+
indexmap = "2.6.0"
26+
if_chain = "1.0.2"
2527

2628
[dev-dependencies]
29+
dir-test = "0.4.0"
30+
hex = "0.4.3"
31+
insta = "1.41.1"
2732
sonatina-parser = { path = "../parser", version = "0.0.3-alpha" }

crates/codegen/src/isa/evm/mod.rs

Lines changed: 510 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#[derive(Debug, Default, Clone, Copy)]
2+
#[repr(u8)]
3+
pub enum OpCode {
4+
STOP = 0x00,
5+
ADD = 0x01,
6+
MUL = 0x02,
7+
SUB = 0x03,
8+
DIV = 0x04,
9+
SDIV = 0x05,
10+
MOD = 0x06,
11+
SMOD = 0x07,
12+
ADDMOD = 0x08,
13+
MULMOD = 0x09,
14+
EXP = 0x0A,
15+
SIGNEXTEND = 0x0B,
16+
// 0C-0F unused
17+
LT = 0x10,
18+
GT = 0x11,
19+
SLT = 0x12,
20+
SGT = 0x13,
21+
EQ = 0x14,
22+
ISZERO = 0x15,
23+
AND = 0x16,
24+
OR = 0x17,
25+
XOR = 0x18,
26+
NOT = 0x19,
27+
BYTE = 0x1A,
28+
SHL = 0x1B,
29+
SHR = 0x1C,
30+
SAR = 0x1D,
31+
// 1E-1F unused
32+
KECCAK256 = 0x20,
33+
// 21-2F unused
34+
ADDRESS = 0x30,
35+
BALANCE = 0x31,
36+
ORIGIN = 0x32,
37+
CALLER = 0x33,
38+
CALLVALUE = 0x34,
39+
CALLDATALOAD = 0x35,
40+
CALLDATASIZE = 0x36,
41+
CALLDATACOPY = 0x37,
42+
CODESIZE = 0x38,
43+
CODECOPY = 0x39,
44+
GASPRICE = 0x3A,
45+
EXTCODESIZE = 0x3B,
46+
EXTCODECOPY = 0x3C,
47+
RETURNDATASIZE = 0x3D,
48+
RETURNDATACOPY = 0x3E,
49+
EXTCODEHASH = 0x3F,
50+
BLOCKHASH = 0x40,
51+
COINBASE = 0x41,
52+
TIMESTAMP = 0x42,
53+
NUMBER = 0x43,
54+
PREVRANDAO = 0x44,
55+
GASLIMIT = 0x45,
56+
CHAINID = 0x46,
57+
SELFBALANCE = 0x47,
58+
BASEFEE = 0x48,
59+
BLOBHASH = 0x49,
60+
BLOBBASEFEE = 0x4A,
61+
// 4B-4F unused
62+
POP = 0x50,
63+
MLOAD = 0x51,
64+
MSTORE = 0x52,
65+
MSTORE8 = 0x53,
66+
SLOAD = 0x54,
67+
SSTORE = 0x55,
68+
JUMP = 0x56,
69+
JUMPI = 0x57,
70+
PC = 0x58,
71+
MSIZE = 0x59,
72+
GAS = 0x5A,
73+
JUMPDEST = 0x5B,
74+
TLOAD = 0x5C,
75+
TSTORE = 0x5D,
76+
MCOPY = 0x5E,
77+
PUSH0 = 0x5F,
78+
PUSH1 = 0x60,
79+
PUSH2 = 0x61,
80+
PUSH3 = 0x62,
81+
PUSH4 = 0x63,
82+
PUSH5 = 0x64,
83+
PUSH6 = 0x65,
84+
PUSH7 = 0x66,
85+
PUSH8 = 0x67,
86+
PUSH9 = 0x68,
87+
PUSH10 = 0x69,
88+
PUSH11 = 0x6A,
89+
PUSH12 = 0x6B,
90+
PUSH13 = 0x6C,
91+
PUSH14 = 0x6D,
92+
PUSH15 = 0x6E,
93+
PUSH16 = 0x6F,
94+
PUSH17 = 0x70,
95+
PUSH18 = 0x71,
96+
PUSH19 = 0x72,
97+
PUSH20 = 0x73,
98+
PUSH21 = 0x74,
99+
PUSH22 = 0x75,
100+
PUSH23 = 0x76,
101+
PUSH24 = 0x77,
102+
PUSH25 = 0x78,
103+
PUSH26 = 0x79,
104+
PUSH27 = 0x7A,
105+
PUSH28 = 0x7B,
106+
PUSH29 = 0x7C,
107+
PUSH30 = 0x7D,
108+
PUSH31 = 0x7E,
109+
PUSH32 = 0x7F,
110+
DUP1 = 0x80,
111+
DUP2 = 0x81,
112+
DUP3 = 0x82,
113+
DUP4 = 0x83,
114+
DUP5 = 0x84,
115+
DUP6 = 0x85,
116+
DUP7 = 0x86,
117+
DUP8 = 0x87,
118+
DUP9 = 0x88,
119+
DUP10 = 0x89,
120+
DUP11 = 0x8A,
121+
DUP12 = 0x8B,
122+
DUP13 = 0x8C,
123+
DUP14 = 0x8D,
124+
DUP15 = 0x8E,
125+
DUP16 = 0x8F,
126+
SWAP1 = 0x90,
127+
SWAP2 = 0x91,
128+
SWAP3 = 0x92,
129+
SWAP4 = 0x93,
130+
SWAP5 = 0x94,
131+
SWAP6 = 0x95,
132+
SWAP7 = 0x96,
133+
SWAP8 = 0x97,
134+
SWAP9 = 0x98,
135+
SWAP10 = 0x99,
136+
SWAP11 = 0x9A,
137+
SWAP12 = 0x9B,
138+
SWAP13 = 0x9C,
139+
SWAP14 = 0x9D,
140+
SWAP15 = 0x9E,
141+
SWAP16 = 0x9F,
142+
LOG0 = 0xA0,
143+
LOG1 = 0xA1,
144+
LOG2 = 0xA2,
145+
LOG3 = 0xA3,
146+
LOG4 = 0xA4,
147+
// A5-EF unused
148+
CREATE = 0xF0,
149+
CALL = 0xF1,
150+
CALLCODE = 0xF2,
151+
RETURN = 0xF3,
152+
DELEGATECALL = 0xF4,
153+
CREATE2 = 0xF5,
154+
// F6-F9 unused
155+
STATICCALL = 0xFA,
156+
// FB-FC unused
157+
REVERT = 0xFD,
158+
#[default]
159+
INVALID = 0xFE,
160+
SELFDESTRUCT = 0xFF,
161+
}

crates/codegen/src/isa/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod evm;

crates/codegen/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
mod bitset;
66
pub mod critical_edge;
77
pub mod domtree;
8+
pub mod isa;
89
pub mod liveness;
910
pub mod loop_analysis;
11+
pub mod machinst;
1012
pub mod optim;
1113
pub mod post_domtree;
14+
pub mod stackalloc;

crates/codegen/src/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn value_uses_in_block_matching_predicate(
154154
fn for_each_use(func: &Function, block: BlockId, mut f: impl FnMut(ValueId, Option<BlockId>)) {
155155
for inst in func.layout.iter_inst(block) {
156156
if let Some(phi) = func.dfg.cast_phi(inst) {
157-
for (val, block) in phi.iter_args() {
157+
for (val, block) in phi.args().iter() {
158158
f(*val, Some(*block))
159159
}
160160
} else {

0 commit comments

Comments
 (0)