use std::collections::{BTreeMap, BTreeSet};
use crate::instruction::Instruction;
mod control_flow;
mod core;
mod dispatch;
mod helpers;
mod postprocess;
mod slots;
mod stack;
mod types;
mod util;
use helpers::{
convert_target_name, format_int_bytes_as_decimal, format_pushdata, format_type_operand,
literal_from_operand,
};
use types::{DoWhileLoop, LiteralValue, LoopContext, LoopJump, SlotKind};
pub(crate) const MAX_HIGH_LEVEL_METHOD_INSTRUCTIONS: usize = 16384;
#[derive(Debug, Default)]
pub(crate) struct HighLevelEmitter {
stack: Vec<String>,
statements: Vec<String>,
warnings: Vec<String>,
next_temp: usize,
inline_single_use_temps: bool,
emit_trace_comments: bool,
pending_closers: BTreeMap<usize, usize>,
else_targets: BTreeMap<usize, usize>,
pending_if_headers: BTreeMap<usize, Vec<String>>,
catch_targets: BTreeMap<usize, usize>,
finally_targets: BTreeMap<usize, usize>,
skip_jumps: BTreeSet<usize>,
transfer_labels: BTreeSet<usize>,
program: Vec<Instruction>,
index_by_offset: BTreeMap<usize, usize>,
do_while_headers: BTreeMap<usize, Vec<DoWhileLoop>>,
active_do_while_tails: BTreeSet<usize>,
loop_stack: Vec<LoopContext>,
initialized_locals: BTreeSet<usize>,
initialized_statics: BTreeSet<usize>,
local_pointer_values: BTreeMap<usize, usize>,
static_pointer_values: BTreeMap<usize, usize>,
argument_labels: BTreeMap<usize, String>,
literal_values: BTreeMap<String, LiteralValue>,
packed_values_by_name: BTreeMap<String, Vec<String>>,
callt_labels: Vec<String>,
callt_param_counts: Vec<usize>,
callt_returns_value: Vec<bool>,
branch_saved_stacks: BTreeMap<usize, Vec<String>>,
method_labels_by_offset: BTreeMap<usize, String>,
method_arg_counts_by_offset: BTreeMap<usize, usize>,
call_targets_by_offset: BTreeMap<usize, usize>,
calla_targets_by_offset: BTreeMap<usize, usize>,
noreturn_method_offsets: BTreeSet<usize>,
pre_branch_stack_depth: BTreeMap<usize, usize>,
returns_void: bool,
finally_body_ranges: Vec<(usize, usize)>,
try_catch_resume: BTreeMap<usize, usize>,
try_exit_stacks: BTreeMap<usize, Vec<String>>,
}
pub(crate) struct HighLevelOutput {
pub(crate) statements: Vec<String>,
pub(crate) warnings: Vec<String>,
}