oxilean_codegen/opt_passes/
constantfoldingpass_traits.rs1use crate::lcnf::{LcnfArg, LcnfExpr, LcnfFunDecl, LcnfLetValue, LcnfLit, LcnfVarId};
14
15use super::functions::OptPass;
16use super::types::ConstantFoldingPass;
17use std::fmt;
18
19impl Default for ConstantFoldingPass {
20 fn default() -> Self {
21 Self::new()
22 }
23}
24
25impl fmt::Debug for ConstantFoldingPass {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 write!(f, "ConstantFoldingPass(folds={})", self.folds_performed)
28 }
29}
30
31impl OptPass for ConstantFoldingPass {
32 fn name(&self) -> &str {
33 "constant_folding"
34 }
35 fn run_pass(&mut self, decls: &mut [LcnfFunDecl]) -> usize {
36 let before = self.folds_performed;
37 self.run(decls);
38 (self.folds_performed - before) as usize
39 }
40}