From 3ca0ca7f7aad5cd273646371ffab14a29002aa25 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Thu, 3 Nov 2022 00:21:07 -0700 Subject: [PATCH] WIP. --- src/passes/dom_pass.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/passes/dom_pass.rs diff --git a/src/passes/dom_pass.rs b/src/passes/dom_pass.rs new file mode 100644 index 0000000..75fb03a --- /dev/null +++ b/src/passes/dom_pass.rs @@ -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(body: &mut FunctionBody, cfg: &CFGInfo, pass: &mut P) { + visit::

(body, cfg, pass, body.entry); +} + +fn visit(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); +}