1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::fmt::Display;

use enum_dispatch::enum_dispatch;

use crate::ir::FunctionDefinition;
mod insert_basic_block;
mod insert_statement;
mod remove_basic_block;
mod remove_statement;
mod rename_local;
pub use insert_basic_block::InsertBasicBlock;
pub use insert_statement::InsertStatement;
pub use remove_basic_block::RemoveBasicBlock;
pub use remove_statement::RemoveStatement;
pub use rename_local::RenameLocal;

#[enum_dispatch]
pub trait IsAction {
    fn perform_on_function(self, ir: &mut FunctionDefinition);
}

#[enum_dispatch(IsAction)]
#[derive(Debug, Clone)]
pub enum Action {
    InsertStatement,
    RemoveStatement,
    RenameLocal,
    InsertBasicBlock,
    RemoveBasicBlock,
}

impl Display for Action {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Action::InsertStatement(action) => write!(f, "{action}"),
            Action::RemoveStatement(action) => write!(f, "{action}"),
            Action::RenameLocal(action) => write!(f, "{action}"),
            Action::InsertBasicBlock(action) => write!(f, "{action}"),
            Action::RemoveBasicBlock(action) => write!(f, "{action}"),
        }
    }
}