WIP.
This commit is contained in:
parent
2a47a77cdc
commit
3ca0ca7f7a
21
src/passes/dom_pass.rs
Normal file
21
src/passes/dom_pass.rs
Normal 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);
|
||||||
|
}
|
Loading…
Reference in a new issue