This commit is contained in:
Chris Fallin 2022-11-03 00:21:07 -07:00
parent 2a47a77cdc
commit 3ca0ca7f7a

21
src/passes/dom_pass.rs Normal file
View file

@ -0,0 +1,21 @@
//! Domtree-based pass.
use crate::cfg::CFGInfo;
use crate::ir::{Block, FunctionBody};
pub trait DomtreePass {
fn enter(&mut self, _block: Block, _body: &mut FunctionBody) {}
fn leave(&mut self, _block: Block, _body: &mut FunctionBody) {}
}
pub fn dom_pass<P: DomtreePass>(body: &mut FunctionBody, cfg: &CFGInfo, pass: &mut P) {
visit::<P>(body, cfg, pass, body.entry);
}
fn visit<P: DomtreePass>(body: &mut FunctionBody, cfg: &CFGInfo, pass: &mut P, block: Block) {
pass.enter(block, body);
for child in cfg.dom_children(block) {
visit(body, cfg, pass, child);
}
pass.leave(block, body);
}