mod bindings;
mod exprs;
mod helpers;
mod lower;
mod short_circuit;
mod structure;
use self::lower::{ChildAnalyses, LowerArtifacts, lower_proto};
use super::simplify::{PassDumpConfig, simplify_hir};
use crate::decompile::{DecompileContext, DecompileError, DecompileState};
use crate::hir::common::HirModule;
use self::exprs::lower_branch_cond;
use self::helpers::{assign_stmt, branch_stmt, build_label_map_for_summary, goto_block};
use self::lower::{
ProtoBindings, ProtoLowering, is_control_terminator, lower_control_instr,
lower_phi_materialization_with_allowed_blocks_except, lower_regular_instr,
};
pub(crate) fn analyze_hir(
state: &mut DecompileState,
context: &DecompileContext<'_>,
) -> Result<(), DecompileError> {
let lowered = state.lowered.as_ref().unwrap();
let cfg = state.cfg.as_ref().unwrap();
let graph_facts = state.graph_facts.as_ref().unwrap();
let dataflow = state.dataflow.as_ref().unwrap();
let structure_facts = state.structure_facts.as_ref().unwrap();
let child_analyses = ChildAnalyses {
cfg_graphs: &cfg.children,
graph_facts: &graph_facts.children,
dataflow: &dataflow.children,
structure: &structure_facts.children,
};
let mut artifacts = LowerArtifacts::default();
let entry = context.timings.record("lower", || {
lower_proto(
&lowered.main,
&cfg.cfg,
graph_facts,
dataflow,
structure_facts,
child_analyses,
&mut artifacts,
)
});
let mut module = HirModule {
entry,
protos: artifacts.protos,
};
let dump_config = PassDumpConfig {
pass_names: context.options.debug.dump_passes.clone(),
filters: context.options.debug.filters,
};
context.timings.record("simplify", || {
simplify_hir(
&mut module,
context.options.readability,
context.timings,
&artifacts.promotion_facts,
context.options.generate.mode,
context.options.dialect,
&dump_config,
);
});
state.hir = Some(module);
Ok(())
}