Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mchprs_blocks = { path = "./crates/blocks" }
mchprs_redpiler = { path = "./crates/redpiler" }
mchprs_redstone = { path = "./crates/redstone" }
paste = { workspace = true }
expect-test = { workspace = true }

[workspace.dependencies]
toml = "0.8"
Expand Down Expand Up @@ -86,3 +87,4 @@ tracing-appender = "0.2"
paste = "1.0"
chrono = "0.4"
clap = { version = "4.5", features = ["derive"] }
expect-test = "1.5"
9 changes: 7 additions & 2 deletions crates/redpiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ mod ril;
mod task_monitor;

use backend::{BackendDispatcher, JITBackend};

use mchprs_blocks::blocks::Block;
use mchprs_blocks::BlockPos;
use mchprs_world::{for_each_block_mut_optimized, TickEntry, World};
use passes::make_default_pass_manager;

use std::sync::Arc;
use std::time::Instant;
use tracing::{debug, error, trace, warn};

pub use task_monitor::TaskMonitor;

pub use compile_graph::*;
pub use passes::PassManager;
pub use ril::DumpGraph;

fn block_powered_mut(block: &mut Block) -> Option<&mut bool> {
Some(match block {
Block::RedstoneComparator { comparator } => &mut comparator.powered,
Expand Down Expand Up @@ -136,7 +141,7 @@ impl Compiler {
let start = Instant::now();

let input = CompilerInput { world, bounds };
let pass_manager = make_default_pass_manager::<W>();
let pass_manager = PassManager::default();
let graph = pass_manager.run_passes(&options, &input, monitor.clone());

if monitor.cancelled() {
Expand Down
38 changes: 20 additions & 18 deletions crates/redpiler/src/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ use std::sync::Arc;
use std::time::Instant;
use tracing::{debug, trace};

pub const fn make_default_pass_manager<'w, W: World>() -> PassManager<'w, W> {
PassManager::new(&[
&identify_nodes::IdentifyNodes,
&input_search::InputSearch,
&clamp_weights::ClampWeights,
&dedup_links::DedupLinks,
&constant_fold::ConstantFold,
&analysis::ss_range_analysis::SSRangeAnalysis,
&unreachable_output::UnreachableOutput,
&constant_coalesce::ConstantCoalesce,
&coalesce::Coalesce,
&prune_orphans::PruneOrphans,
&export_graph::ExportGraph,
])
}

pub trait AnalysisInfo: Any {}

#[derive(Default)]
Expand All @@ -64,6 +48,24 @@ pub struct PassManager<'p, W: World> {
passes: &'p [&'p dyn Pass<W>],
}

impl<'p, W: World> Default for PassManager<'p, W> {
fn default() -> Self {
Self::new(&[
&identify_nodes::IdentifyNodes,
&input_search::InputSearch,
&clamp_weights::ClampWeights,
&dedup_links::DedupLinks,
&constant_fold::ConstantFold,
&analysis::ss_range_analysis::SSRangeAnalysis,
&unreachable_output::UnreachableOutput,
&constant_coalesce::ConstantCoalesce,
&coalesce::Coalesce,
&prune_orphans::PruneOrphans,
&export_graph::ExportGraph,
])
}
}

impl<'p, W: World> PassManager<'p, W> {
pub const fn new(passes: &'p [&dyn Pass<W>]) -> Self {
Self { passes }
Expand Down Expand Up @@ -106,13 +108,13 @@ impl<'p, W: World> PassManager<'p, W> {

if options.print_after_all {
debug!("Printing circuit after pass: {}", pass.name());
graph.dump();
graph.dump_to_stderr();
}
}

if options.print_before_backend {
debug!("Printing circuit before backend compile:");
graph.dump();
graph.dump_to_stderr();
}

graph
Expand Down
9 changes: 7 additions & 2 deletions crates/redpiler/src/ril.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,18 @@ impl<'a> fmt::Display for GraphDumper<'a> {
}

pub trait DumpGraph {
fn dump(&self);
fn dump_to_stderr(&self);
fn dump_to_string(&self) -> String;
}

impl DumpGraph for CompileGraph {
fn dump(&self) {
fn dump_to_stderr(&self) {
eprintln!("{}", GraphDumper { graph: self });
}

fn dump_to_string(&self) -> String {
format!("{}", GraphDumper { graph: self })
}
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
Expand Down
5 changes: 5 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ impl TestWorld {
}
}

pub fn bounds(&self) -> (BlockPos, BlockPos) {
let max_coord = self.size * 16 - 1;
(pos(0, 0, 0), pos(max_coord, max_coord, max_coord))
}

fn get_chunk_index_for_chunk(&self, chunk_x: i32, chunk_z: i32) -> usize {
(chunk_x * self.size + chunk_z).unsigned_abs() as usize
}
Expand Down
Loading