Skip to main content

neo_decompiler/decompiler/
output_format.rs

1#[cfg(feature = "cli")]
2use clap::ValueEnum;
3
4/// Select which decompiler outputs should be generated.
5#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
6#[cfg_attr(feature = "cli", derive(ValueEnum))]
7pub enum OutputFormat {
8    /// Emit pseudocode output.
9    Pseudocode,
10    /// Emit a higher-level structured output.
11    HighLevel,
12    /// Emit C# source code output.
13    // Override clap's default kebab-case derivation (`c-sharp`) so the
14    // CLI accepts the same `csharp` token as `--format csharp`. The
15    // legacy `c-sharp` form is kept as an alias for back-compat with
16    // any scripts that pinned the old spelling.
17    #[cfg_attr(feature = "cli", value(name = "csharp", alias = "c-sharp"))]
18    CSharp,
19    /// Emit all supported outputs.
20    #[default]
21    All,
22}
23
24impl OutputFormat {
25    pub(super) fn wants_pseudocode(self) -> bool {
26        matches!(self, OutputFormat::Pseudocode | OutputFormat::All)
27    }
28
29    pub(super) fn wants_high_level(self) -> bool {
30        matches!(self, OutputFormat::HighLevel | OutputFormat::All)
31    }
32
33    pub(super) fn wants_csharp(self) -> bool {
34        matches!(self, OutputFormat::CSharp | OutputFormat::All)
35    }
36}
37
38/// Knobs shared by the high-level and C# renderers.
39///
40/// Bundling these keeps the renderer entry-point signatures under clippy's
41/// `too_many_arguments` threshold and ensures both front-ends stay in sync as
42/// new rendering options are added.
43#[derive(Debug, Clone, Copy, Default)]
44pub(crate) struct RenderOptions {
45    /// Inline single-use temps (`let tN = rhs;` used once) at their use site.
46    pub inline_single_use_temps: bool,
47    /// Emit per-instruction `// XXXX: OPCODE` trace comments in the output.
48    pub emit_trace_comments: bool,
49    /// Annotate inferred argument signatures and slot declarations with types
50    /// (high-level: `arg0: int`, `int loc0 = ...;`; C#: `BigInteger arg0`,
51    /// `BigInteger loc0 = ...;` instead of `object arg0` / `var loc0 = ...;`).
52    pub typed_declarations: bool,
53}