Skip to content

Commit

Permalink
docs: Add documentation to visitor, clean up mir passes mod.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Besancon committed Feb 5, 2025
1 parent 7711db5 commit 0bd41a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
25 changes: 8 additions & 17 deletions ir/src/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,25 @@ mod inlining;
mod translate;
mod unrolling;
mod visitor;

pub use self::inlining::Inlining;
pub use self::translate::AstToMir;
pub use self::unrolling::Unrolling;
pub use inlining::Inlining;
pub use translate::AstToMir;
pub use unrolling::Unrolling;
// Note: ConstantPropagation and ValueNumbering are not implemented yet in the MIR
//mod constant_propagation;
//mod value_numbering;
//pub use constant_propagation::ConstantPropagation;
//pub use value_numbering::ValueNumbering;

use std::collections::HashMap;
use std::ops::Deref;

use air_pass::Pass;
use miden_diagnostics::Spanned;

use crate::ir::{
Accessor, Add, Boundary, Call, Enf, Exp, Fold, For, If, Link, Matrix, Mul, Node, Op, Owner,
Parameter, Parent, Sub, Value, Vector,
};

pub struct DumpAst;
impl Pass for DumpAst {
type Input<'a> = air_parser::ast::Program;
type Output<'a> = air_parser::ast::Program;
type Error = air_parser::SemanticAnalysisError;

fn run<'a>(&mut self, input: Self::Input<'a>) -> Result<Self::Output<'a>, Self::Error> {
println!("{}", &input);
Ok(input)
}
}

/// Helper to duplicate a MIR node and its children recursively
/// It should be used when we want to reference the same node multiple times in the MIR graph (e.g. referencing let bound variables)
///
Expand Down
8 changes: 7 additions & 1 deletion ir/src/passes/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ use crate::{
ir::{Graph, Link, Node, Op, Parent, Root},
CompileError,
};

use std::ops::Deref;

/// A trait for visiting nodes in a MIR graph, from the leafs to the root.
///
/// The process is as follows:
/// - Starting from the root_nodes_to_visit, we scan a node
/// - We recursively scan all the children of the node
/// - Once we have scanned all the children, we visit the node
/// - The visit will be dispatched based on the variant of the node
pub trait Visitor {
fn work_stack(&mut self) -> &mut Vec<Link<Node>>;
fn root_nodes_to_visit(&self, graph: &Graph) -> Vec<Link<Node>>;
Expand Down

0 comments on commit 0bd41a1

Please sign in to comment.