wave_compiler/optimize/
pass.rs1use crate::mir::function::MirFunction;
10
11pub trait Pass {
13 fn name(&self) -> &'static str;
15
16 fn run(&self, func: &mut MirFunction) -> bool;
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23 use crate::mir::value::BlockId;
24
25 struct NoopPass;
26 impl Pass for NoopPass {
27 fn name(&self) -> &'static str {
28 "noop"
29 }
30 fn run(&self, func: &mut MirFunction) -> bool {
31 let _ = func.name.len();
32 false
33 }
34 }
35
36 #[test]
37 fn test_pass_trait() {
38 let pass = NoopPass;
39 assert_eq!(pass.name(), "noop");
40 }
41
42 #[test]
43 fn test_pass_returns_false_when_no_changes() {
44 let pass = NoopPass;
45 let mut func = MirFunction::new("test".into(), BlockId(0));
46 assert!(!pass.run(&mut func));
47 }
48}