Skip to content

Commit

Permalink
Merge pull request #45 from sbillig/pest-parser
Browse files Browse the repository at this point in the history
New parser (pest)
  • Loading branch information
sbillig authored Jun 30, 2024
2 parents bc25040 + f5d4b7c commit f078e81
Show file tree
Hide file tree
Showing 127 changed files with 4,686 additions and 2,796 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,54 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- run: cargo doc --no-deps

fmt:
name: Rustfmt
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --workspace --all-features --all-targets -- -D clippy::all

unused_deps:
name: Unused dependencies
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
- name: Install cargo-udeps
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-udeps

- run: cargo +nightly udeps

test:
name: Test
defaults:
Expand All @@ -60,13 +79,15 @@ jobs:
- nightly

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}

- uses: Swatinem/rust-cache@v2

- name: Test
run: cargo test --workspace --all-targets
run: cargo test --workspace --all-targets --no-fail-fast

- name: Filecheck
run: cargo run -p sonatina-filecheck
Expand Down
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[workspace]
resolver = "2"
members = ["crates/ir", "crates/codegen", "crates/object", "crates/parser", "crates/filecheck", "crates/triple", "crates/interpreter"]
members = [
"crates/ir",
"crates/codegen",
"crates/object",
"crates/parser",
"crates/filecheck",
"crates/triple",
"crates/interpreter",
]
2 changes: 1 addition & 1 deletion crates/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ keywords = ["compiler", "evm", "wasm", "smart-contract"]
[dependencies]
cranelift-entity = "0.104"
smallvec = "1.7.0"
fxhash = "0.2.1"
rustc-hash = "2.0.0"
sonatina-ir = { path = "../ir", version = "0.0.3-alpha" }
sonatina-triple = { path = "../triple", version = "0.0.3-alpha" }
72 changes: 36 additions & 36 deletions crates/codegen/src/critical_edge.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use sonatina_ir::ControlFlowGraph;
use sonatina_ir::{func_cursor::FuncCursor, ControlFlowGraph};

use sonatina_ir::{
func_cursor::{CursorLocation, FuncCursor, InsnInserter},
func_cursor::{CursorLocation, InsnInserter},
insn::InsnData,
Block, Function, Insn,
};
Expand Down Expand Up @@ -65,10 +65,10 @@ impl CriticalEdgeSplitter {
// critical edge.
let inserted_dest = func.dfg.make_block();
let jump = func.dfg.make_insn(InsnData::jump(original_dest));
let mut cursor = InsnInserter::new(func, CursorLocation::BlockTop(original_dest));
cursor.append_block(inserted_dest);
cursor.set_loc(CursorLocation::BlockTop(inserted_dest));
cursor.append_insn(jump);
let mut cursor = InsnInserter::at_location(CursorLocation::BlockTop(original_dest));
cursor.append_block(func, inserted_dest);
cursor.set_location(CursorLocation::BlockTop(inserted_dest));
cursor.append_insn(func, jump);

// Rewrite branch destination to the new block.
func.dfg
Expand Down Expand Up @@ -123,8 +123,7 @@ mod tests {

#[test]
fn critical_edge_basic() {
let mut test_module_builder = TestModuleBuilder::new();
let mut builder = test_module_builder.func_builder(&[], Type::Void);
let mut builder = test_func_builder(&[], Type::Void);

let a = builder.append_block();
let b = builder.append_block();
Expand All @@ -141,17 +140,16 @@ mod tests {
builder.ret(None);

builder.seal_all();
let func_ref = builder.finish();

let mut module = test_module_builder.build();
let mut module = builder.finish().build();
let func_ref = module.iter_functions().next().unwrap();
let func = &mut module.funcs[func_ref];
let mut cfg = ControlFlowGraph::default();
cfg.compute(func);
CriticalEdgeSplitter::new().run(func, &mut cfg);

assert_eq!(
dump_func(func),
"func public %test_func() -> void:
dump_func(&module, func_ref),
"func public %test_func() -> void {
block0:
br 1.i32 block3 block1;
Expand All @@ -164,9 +162,11 @@ mod tests {
block3:
jump block2;
}
"
);

let func = &mut module.funcs[func_ref];
let mut cfg_split = ControlFlowGraph::default();
cfg_split.compute(func);
assert_eq!(cfg, cfg_split);
Expand All @@ -175,8 +175,7 @@ mod tests {
#[test]
#[allow(clippy::many_single_char_names)]
fn critical_edge_to_same_block() {
let mut test_module_builder = TestModuleBuilder::new();
let mut builder = test_module_builder.func_builder(&[], Type::Void);
let mut builder = test_func_builder(&[], Type::Void);

let a = builder.append_block();
let b = builder.append_block();
Expand All @@ -201,17 +200,16 @@ mod tests {
builder.ret(None);

builder.seal_all();
let func_ref = builder.finish();

let mut module = test_module_builder.build();
let mut module = builder.finish().build();
let func_ref = module.iter_functions().next().unwrap();
let func = &mut module.funcs[func_ref];
let mut cfg = ControlFlowGraph::default();
cfg.compute(func);
CriticalEdgeSplitter::new().run(func, &mut cfg);

assert_eq!(
dump_func(func),
"func public %test_func() -> void:
dump_func(&module, func_ref),
"func public %test_func() -> void {
block0:
br 1.i8 block5 block1;
Expand All @@ -233,18 +231,19 @@ mod tests {
block6:
jump block3;
}
"
);

let func = &mut module.funcs[func_ref];
let mut cfg_split = ControlFlowGraph::default();
cfg_split.compute(func);
assert_eq!(cfg, cfg_split);
}

#[test]
fn critical_edge_phi() {
let mut test_module_builder = TestModuleBuilder::new();
let mut builder = test_module_builder.func_builder(&[], Type::Void);
let mut builder = test_func_builder(&[], Type::Void);

let a = builder.append_block();
let b = builder.append_block();
Expand All @@ -255,7 +254,7 @@ mod tests {
builder.jump(b);

builder.switch_to_block(b);
let phi_value = builder.phi(&[(v1, a)]);
let phi_value = builder.phi(Type::I8, &[(v1, a)]);
let v2 = builder.add(phi_value, v1);
builder.append_phi_arg(phi_value, v2, b);
builder.br(phi_value, c, b);
Expand All @@ -264,17 +263,16 @@ mod tests {
builder.ret(None);

builder.seal_all();
let func_ref = builder.finish();

let mut module = test_module_builder.build();
let mut module = builder.finish().build();
let func_ref = module.iter_functions().next().unwrap();
let func = &mut module.funcs[func_ref];
let mut cfg = ControlFlowGraph::default();
cfg.compute(func);
CriticalEdgeSplitter::new().run(func, &mut cfg);

assert_eq!(
dump_func(func),
"func public %test_func() -> void:
dump_func(&module, func_ref),
"func public %test_func() -> void {
block0:
jump block1;
Expand All @@ -289,18 +287,19 @@ mod tests {
block3:
jump block1;
}
"
);

let func = &mut module.funcs[func_ref];
let mut cfg_split = ControlFlowGraph::default();
cfg_split.compute(func);
assert_eq!(cfg, cfg_split);
}

#[test]
fn critical_edge_br_table() {
let mut test_module_builder = TestModuleBuilder::new();
let mut builder = test_module_builder.func_builder(&[], Type::Void);
let mut builder = test_func_builder(&[], Type::Void);

let a = builder.append_block();
let b = builder.append_block();
Expand Down Expand Up @@ -328,19 +327,18 @@ mod tests {
builder.ret(None);

builder.seal_all();
let func_ref = builder.finish();

let mut module = test_module_builder.build();
let mut module = builder.finish().build();
let func_ref = module.iter_functions().next().unwrap();
let func = &mut module.funcs[func_ref];
let mut cfg = ControlFlowGraph::default();
cfg.compute(func);
CriticalEdgeSplitter::new().run(func, &mut cfg);

assert_eq!(
dump_func(func),
"func public %test_func() -> void:
dump_func(&module, func_ref),
"func public %test_func() -> void {
block0:
br -1.i1 block5 block6;
br 1.i1 block5 block6;
block1:
br_table 0.i32 block2 (1.i32 block3) (2.i32 block7);
Expand All @@ -363,9 +361,11 @@ mod tests {
block7:
jump block4;
}
"
);

let func = &mut module.funcs[func_ref];
let mut cfg_split = ControlFlowGraph::default();
cfg_split.compute(func);
assert_eq!(cfg, cfg_split);
Expand Down
Loading

0 comments on commit f078e81

Please sign in to comment.