gbf_core/decompiler/
mod.rs

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#![deny(missing_docs)]

use ast::{assignable::AssignableKind, ast_vec::AstVec, expr::ExprKind, AstKind};

/// This provides the AST for the decompiler.
pub mod ast;
/// The state of execution for the decompiler
pub mod execution_frame;
/// This assists in decompiling one function
pub mod function_decompiler;
/// This provides the context for the decompiler
pub mod function_decompiler_context;
/// This provides the handlers for the decompiler
pub mod handlers;
/// This provides the region for the decompiler
pub mod region;

#[derive(Debug, Clone, Default)]
/// Builder for constructing a `ProcessedInstruction`.
pub struct ProcessedInstructionBuilder {
    ssa_id: Option<AssignableKind>,
    node_to_push: Option<AstKind>,
    function_parameters: Option<AstVec<ExprKind>>,
    jump_condition: Option<ExprKind>,
}

impl ProcessedInstructionBuilder {
    /// Creates a new builder instance.
    pub fn new() -> Self {
        Self {
            ssa_id: None,
            node_to_push: None,
            function_parameters: None,
            jump_condition: None,
        }
    }

    /// Sets the SSA ID for the processed instruction.
    ///
    /// # Arguments
    /// - `ssa_id`: The SSA ID to assign.
    ///
    /// # Returns
    /// A mutable reference to the builder for chaining.
    pub fn ssa_id(mut self, ssa_id: AssignableKind) -> Self {
        self.ssa_id = Some(ssa_id);
        self
    }

    /// Sets the node to push to a region for the processed instruction.
    ///
    /// # Arguments
    /// - `node_to_push`: The AST node to assign.
    ///
    /// # Returns
    /// A mutable reference to the builder for chaining.
    pub fn push_to_region(mut self, node_to_push: AstKind) -> Self {
        self.node_to_push = Some(node_to_push);
        self
    }

    /// Sets the function parameters for the processed instruction.
    ///
    /// # Arguments
    /// - `function_parameters`: The function parameters to assign.
    ///
    /// # Returns
    /// A mutable reference to the builder for chaining.
    pub fn function_parameters(mut self, function_parameters: AstVec<ExprKind>) -> Self {
        self.function_parameters = Some(function_parameters);
        self
    }

    /// Sets the jump condition for the processed instruction.
    ///
    /// # Arguments
    /// - `jump_condition`: The jump condition to assign.
    ///
    /// # Returns
    /// A mutable reference to the builder for chaining.
    pub fn jump_condition(mut self, jump_condition: ExprKind) -> Self {
        self.jump_condition = Some(jump_condition);
        self
    }

    /// Builds the `ProcessedInstruction` instance.
    ///
    /// # Returns
    /// A `ProcessedInstruction` populated with the specified values.
    pub fn build(self) -> ProcessedInstruction {
        ProcessedInstruction {
            ssa_id: self.ssa_id,
            node_to_push: self.node_to_push,
            function_parameters: self.function_parameters,
            jump_condition: self.jump_condition,
        }
    }
}

#[derive(Debug, Clone, Default)]
/// Represents a processed instruction
pub struct ProcessedInstruction {
    /// The SSA ID
    pub ssa_id: Option<AssignableKind>,
    /// The node to push to a region
    pub node_to_push: Option<AstKind>,
    /// The parameters of a function. Returned with Opcode::EndParams.
    pub function_parameters: Option<AstVec<ExprKind>>,
    /// The jump condition
    pub jump_condition: Option<ExprKind>,
}