mod colorize;
mod focus;
pub(crate) use colorize::colorize_debug_text;
pub use focus::{
FocusPlan, FocusRequest, ProtoDepth, ProtoNode, ProtoSummaryRow, build_proto_nodes,
compute_focus_plan, format_breadcrumb, format_proto_summary_row,
};
macro_rules! define_stage_dump {
(
$(
$(#[doc = $doc:literal])*
pub fn $name:ident ( $state:ident, $options:ident ) => $stage:ident, $content:expr;
)+
) => {
$(
$(#[doc = $doc])*
#[cfg(feature = "decompile-debug")]
pub fn $name(
$state: &$crate::decompile::DecompileState,
$options: &$crate::decompile::DebugOptions,
) -> Result<$crate::decompile::StageDebugOutput, $crate::decompile::DecompileError> {
Ok($crate::decompile::StageDebugOutput {
stage: $crate::decompile::DecompileStage::$stage,
detail: $options.detail,
content: $content,
})
}
$(#[doc = $doc])*
#[cfg(not(feature = "decompile-debug"))]
pub fn $name(
_state: &$crate::decompile::DecompileState,
_options: &$crate::decompile::DebugOptions,
) -> Result<$crate::decompile::StageDebugOutput, $crate::decompile::DecompileError> {
Err($crate::decompile::DecompileError::DebugUnavailable)
}
)+
};
}
pub(crate) use define_stage_dump;
use std::{fmt, io::IsTerminal};
use strum_macros::{Display, EnumString, IntoStaticStr};
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Display, EnumString, IntoStaticStr)]
#[strum(serialize_all = "kebab-case")]
pub enum DebugDetail {
Summary,
#[default]
Normal,
Verbose,
}
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Display, EnumString, IntoStaticStr)]
#[strum(serialize_all = "kebab-case")]
pub enum DebugColorMode {
#[default]
Auto,
Always,
Never,
}
impl DebugColorMode {
pub(crate) fn enabled(self) -> bool {
match self {
Self::Auto => std::io::stdout().is_terminal(),
Self::Always => true,
Self::Never => false,
}
}
}
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
pub struct DebugFilters {
pub proto: Option<usize>,
pub proto_depth: ProtoDepth,
}
impl DebugFilters {
pub fn as_focus_request(&self) -> FocusRequest {
FocusRequest {
proto: self.proto,
depth: self.proto_depth,
}
}
pub fn unfiltered() -> Self {
Self {
proto: None,
proto_depth: ProtoDepth::All,
}
}
}
pub fn format_display_set(items: impl IntoIterator<Item = impl fmt::Display>) -> String {
let formatted: Vec<String> = items.into_iter().map(|item| item.to_string()).collect();
if formatted.is_empty() {
"[-]".to_string()
} else {
format!("[{}]", formatted.join(", "))
}
}