gbf_core/decompiler/
mod.rs

1#![deny(missing_docs)]
2
3use ast::{AstKind, array_kind::ArrayKind, expr::ExprKind, identifier::IdentifierNode, ptr::P};
4
5/// This provides the AST for the decompiler.
6pub mod ast;
7/// The state of execution for the decompiler
8pub mod execution_frame;
9/// This assists in decompiling one function
10pub mod function_decompiler;
11/// This provides the context for the decompiler
12pub mod function_decompiler_context;
13/// This provides the handlers for the decompiler
14pub mod handlers;
15/// This is responsible for control flow analysis
16pub mod structure_analysis;
17
18#[derive(Debug, Clone, Default)]
19/// Builder for constructing a `ProcessedInstruction`.
20pub struct ProcessedInstructionBuilder {
21    ssa_id: Option<P<IdentifierNode>>,
22    node_to_push: Option<AstKind>,
23    function_parameters: Option<ArrayKind>,
24    jump_condition: Option<ExprKind>,
25}
26
27impl ProcessedInstructionBuilder {
28    /// Creates a new builder instance.
29    pub fn new() -> Self {
30        Self {
31            ssa_id: None,
32            node_to_push: None,
33            function_parameters: None,
34            jump_condition: None,
35        }
36    }
37
38    /// Sets the SSA ID for the processed instruction.
39    ///
40    /// # Arguments
41    /// - `ssa_id`: The SSA ID to assign.
42    ///
43    /// # Returns
44    /// A mutable reference to the builder for chaining.
45    pub fn ssa_id(mut self, ssa_id: P<IdentifierNode>) -> Self {
46        self.ssa_id = Some(ssa_id);
47        self
48    }
49
50    /// Sets the node to push to a region for the processed instruction.
51    ///
52    /// # Arguments
53    /// - `node_to_push`: The AST node to assign.
54    ///
55    /// # Returns
56    /// A mutable reference to the builder for chaining.
57    pub fn push_to_region(mut self, node_to_push: AstKind) -> Self {
58        self.node_to_push = Some(node_to_push);
59        self
60    }
61
62    /// Sets the function parameters for the processed instruction.
63    ///
64    /// # Arguments
65    /// - `function_parameters`: The function parameters to assign.
66    ///
67    /// # Returns
68    /// A mutable reference to the builder for chaining.
69    pub fn function_parameters(mut self, function_parameters: ArrayKind) -> Self {
70        self.function_parameters = Some(function_parameters);
71        self
72    }
73
74    /// Sets the jump condition for the processed instruction.
75    ///
76    /// # Arguments
77    /// - `jump_condition`: The jump condition to assign.
78    ///
79    /// # Returns
80    /// A mutable reference to the builder for chaining.
81    pub fn jump_condition(mut self, jump_condition: ExprKind) -> Self {
82        self.jump_condition = Some(jump_condition);
83        self
84    }
85
86    /// Builds the `ProcessedInstruction` instance.
87    ///
88    /// # Returns
89    /// A `ProcessedInstruction` populated with the specified values.
90    pub fn build(self) -> ProcessedInstruction {
91        ProcessedInstruction {
92            ssa_id: self.ssa_id,
93            node_to_push: self.node_to_push,
94            function_parameters: self.function_parameters,
95            jump_condition: self.jump_condition,
96        }
97    }
98}
99
100#[derive(Debug, Clone, Default)]
101/// Represents a processed instruction
102pub struct ProcessedInstruction {
103    /// The SSA ID
104    pub ssa_id: Option<P<IdentifierNode>>,
105    /// The node to push to a region
106    pub node_to_push: Option<AstKind>,
107    /// The parameters of a function. Returned with Opcode::EndParams.
108    pub function_parameters: Option<ArrayKind>,
109    /// The jump condition
110    pub jump_condition: Option<ExprKind>,
111}