From fd748dd4936d9ef7cdcbe4f2a268c4161f6152f6 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Tue, 7 Feb 2023 15:54:24 -0800 Subject: [PATCH] misc API updates --- src/ir/display.rs | 8 ++------ src/ir/func.rs | 22 ++++++++++++++++++++++ src/ir/module.rs | 20 ++------------------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/ir/display.rs b/src/ir/display.rs index 1f6a35d..2b1154e 100644 --- a/src/ir/display.rs +++ b/src/ir/display.rs @@ -190,14 +190,10 @@ impl<'a> Display for ModuleDisplay<'a> { for seg in &memory_data.segments { writeln!( f, - " {} offset {}: [{}]", + " {} offset {}: # {} bytes", memory, seg.offset, - seg.data - .iter() - .map(|&byte| format!("0x{:02x}", byte)) - .collect::>() - .join(", ") + seg.data.len() )?; } } diff --git a/src/ir/func.rs b/src/ir/func.rs index 050454c..50458fe 100644 --- a/src/ir/func.rs +++ b/src/ir/func.rs @@ -31,6 +31,28 @@ impl<'a> FuncDecl<'a> { } } + pub fn optimize(&mut self) { + match self { + FuncDecl::Body(_, body) => { + let cfg = crate::cfg::CFGInfo::new(body); + crate::passes::basic_opt::gvn(body, &cfg); + crate::passes::resolve_aliases::run(body); + crate::passes::empty_blocks::run(body); + } + _ => {} + } + } + + pub fn convert_to_max_ssa(&mut self) { + match self { + FuncDecl::Body(_, body) => { + let cfg = crate::cfg::CFGInfo::new(body); + crate::passes::maxssa::run(body, &cfg); + } + _ => {} + } + } + pub fn body(&self) -> Option<&FunctionBody> { match self { FuncDecl::Body(_, body) => Some(body), diff --git a/src/ir/module.rs b/src/ir/module.rs index c4cfe69..d2c1a07 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -236,14 +236,14 @@ impl<'a> Module<'a> { } } - pub fn expand_func<'b>(&'b mut self, id: Func) -> Result<&'b FuncDecl<'a>> { + pub fn expand_func<'b>(&'b mut self, id: Func) -> Result<&'b mut FuncDecl<'a>> { if let FuncDecl::Lazy(..) = self.funcs[id] { // End the borrow. This is cheap (a slice copy). let mut func = self.funcs[id].clone(); func.parse(self)?; self.funcs[id] = func; } - Ok(&self.funcs[id]) + Ok(&mut self.funcs[id]) } pub fn expand_all_funcs(&mut self) -> Result<()> { @@ -254,22 +254,6 @@ impl<'a> Module<'a> { Ok(()) } - pub fn optimize(&mut self) { - self.per_func_body(|body| { - let cfg = crate::cfg::CFGInfo::new(body); - crate::passes::basic_opt::gvn(body, &cfg); - crate::passes::resolve_aliases::run(body); - crate::passes::empty_blocks::run(body); - }); - } - - pub fn convert_to_max_ssa(&mut self) { - self.per_func_body(|body| { - let cfg = crate::cfg::CFGInfo::new(body); - crate::passes::maxssa::run(body, &cfg); - }); - } - pub fn display<'b>(&'b self) -> ModuleDisplay<'b> where 'b: 'a,