Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inst as Type #59

Merged
merged 26 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dd3048f
Define trait
Y-Nak Sep 7, 2024
2a9da44
Implement a macro to provide an easy way to define `Inst` types
Y-Nak Sep 7, 2024
c40008e
Define basic instructions
Y-Nak Sep 7, 2024
38d61d9
`Define HasInst<I>` as a bulding block of IsaGroup
Y-Nak Sep 8, 2024
dac7644
Define `Inst` derive proc macro
Y-Nak Sep 9, 2024
2271f80
Define `ValueVisitable` trait
Y-Nak Sep 9, 2024
c7b6826
Improve `Inst` derive macro
Y-Nak Sep 9, 2024
327ac61
Use `Inst` derive macro
Y-Nak Sep 9, 2024
fe88bff
Cleanup related module structure
Y-Nak Sep 9, 2024
0fe0d38
Define macro to define `DynINstGroup`
Y-Nak Sep 9, 2024
3e57817
Register basic insts to `InstGroup`
Y-Nak Sep 9, 2024
152665c
Make the naming rule more clearer
Y-Nak Sep 10, 2024
0436c23
Define `inst_set` macro
Y-Nak Sep 10, 2024
d58f60f
Add `prelude` for inst related traits
Y-Nak Sep 10, 2024
41bd4b4
Let `inst_set` macro generate `InstKind` enum from a given inst set
Y-Nak Sep 10, 2024
5ecbe35
Extend `inst_set` macro so it can generate `InstSetExt` impl and cons…
Y-Nak Sep 10, 2024
1deeb4e
Add runtime tests for macro-generated instruction sets
Y-Nak Sep 10, 2024
23e2143
Simplify `has_side_effect` specifier
Y-Nak Sep 11, 2024
ae17d47
Simplify inst def
Y-Nak Sep 11, 2024
35f6052
Allow attributes in `InstSetBase` definition
Y-Nak Sep 11, 2024
1be6d6e
Docwork
Y-Nak Sep 11, 2024
84dfc54
Cleanup inst module structure
Y-Nak Sep 11, 2024
9d5d3e9
Define evm instructions
Y-Nak Sep 11, 2024
5e82248
suppress clippy warning from macro generated code
Y-Nak Sep 11, 2024
1b5a36f
Fix bug in `inst_set` macro
Y-Nak Sep 12, 2024
9b471b9
Define `EvmInstSet`
Y-Nak Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ members = [
"crates/parser",
"crates/filecheck",
"crates/triple",
"crates/macros",
"crates/interpreter",
]
1 change: 1 addition & 0 deletions crates/ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ smallvec = "1.7.0"
rustc-hash = "2.0.0"
dyn-clone = "1.0.4"
sonatina-triple = { path = "../triple", version = "0.0.3-alpha" }
macros = { package = "sonatina-macros", path = "../macros", version = "0.0.3-alpha" }
indexmap = "2.0.0"
dot2 = { git = "https://github.com/sanpii/dot2.rs.git" }
93 changes: 93 additions & 0 deletions crates/ir/src/inst/arith.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use macros::Inst;

use crate::Value;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Neg {
#[inst(value)]
arg: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Add {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Mul {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Sub {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Sdiv {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Udiv {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Umod {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Smod {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Shl {
#[inst(value)]
bits: Value,
#[inst(value)]
value: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Shr {
#[inst(value)]
bits: Value,
#[inst(value)]
value: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Sar {
#[inst(value)]
bits: Value,
#[inst(value)]
value: Value,
}
31 changes: 31 additions & 0 deletions crates/ir/src/inst/cast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use macros::Inst;

use crate::{Type, Value};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Sext {
#[inst(value)]
from: Value,
ty: Type,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Zext {
#[inst(value)]
from: Value,
ty: Type,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Trunc {
#[inst(value)]
from: Value,
ty: Type,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Bitcast {
#[inst(value)]
from: Value,
ty: Type,
}
89 changes: 89 additions & 0 deletions crates/ir/src/inst/cmp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use macros::Inst;

use crate::Value;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Lt {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Gt {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Slt {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Sgt {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Le {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Ge {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Sle {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Sge {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Eq {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Ne {
#[inst(value)]
lhs: Value,
#[inst(value)]
rhs: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct IsZero {
#[inst(value)]
lhs: Value,
}
51 changes: 51 additions & 0 deletions crates/ir/src/inst/control_flow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use macros::Inst;
use smallvec::SmallVec;

use crate::{module::FuncRef, Block, Type, Value};

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
pub struct Jump {
dest: Block,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
pub struct Br {
#[inst(value)]
cond: Value,

z_dest: Block,
nz_dest: Block,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
pub struct BrTable {
#[inst(value)]
scrutinee: Value,
#[inst(value)]
table: Vec<(Value, Block)>,

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 {
#[inst(value)]
args: SmallVec<[Value; 8]>,
callee: FuncRef,
ret_ty: Type,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Return {
#[inst(value)]
arg: Option<Value>,
}
25 changes: 25 additions & 0 deletions crates/ir/src/inst/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use macros::Inst;
use smallvec::SmallVec;

use crate::Value;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
pub struct Mload {
#[inst(value)]
addr: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
pub struct Mstore {
#[inst(value)]
value: Value,
#[inst(value)]
addr: Value,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
pub struct Gep {
#[inst(value)]
values: SmallVec<[Value; 8]>,
}
Loading