misc API updates

This commit is contained in:
Chris Fallin 2023-02-07 15:54:24 -08:00
parent eaa1f76ba0
commit fd748dd493
3 changed files with 26 additions and 24 deletions

View file

@ -190,14 +190,10 @@ impl<'a> Display for ModuleDisplay<'a> {
for seg in &memory_data.segments { for seg in &memory_data.segments {
writeln!( writeln!(
f, f,
" {} offset {}: [{}]", " {} offset {}: # {} bytes",
memory, memory,
seg.offset, seg.offset,
seg.data seg.data.len()
.iter()
.map(|&byte| format!("0x{:02x}", byte))
.collect::<Vec<_>>()
.join(", ")
)?; )?;
} }
} }

View file

@ -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> { pub fn body(&self) -> Option<&FunctionBody> {
match self { match self {
FuncDecl::Body(_, body) => Some(body), FuncDecl::Body(_, body) => Some(body),

View file

@ -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] { if let FuncDecl::Lazy(..) = self.funcs[id] {
// End the borrow. This is cheap (a slice copy). // End the borrow. This is cheap (a slice copy).
let mut func = self.funcs[id].clone(); let mut func = self.funcs[id].clone();
func.parse(self)?; func.parse(self)?;
self.funcs[id] = func; self.funcs[id] = func;
} }
Ok(&self.funcs[id]) Ok(&mut self.funcs[id])
} }
pub fn expand_all_funcs(&mut self) -> Result<()> { pub fn expand_all_funcs(&mut self) -> Result<()> {
@ -254,22 +254,6 @@ impl<'a> Module<'a> {
Ok(()) 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> pub fn display<'b>(&'b self) -> ModuleDisplay<'b>
where where
'b: 'a, 'b: 'a,