Skip to main content

datex_core/disassembler/
mod.rs

1//! This module contains the disassembler for DATEX, which converts DXB bytecode into a human-readable assembly-like string representation e.g.
2//! from `24, 73, 1, 73, 2`(1+2) to
3//! ```asm
4//! ADD
5//!   UINT_8 1
6//!   UINT_8 2
7//! ```
8
9#[cfg(feature = "disassembler")]
10pub mod assertions;
11#[cfg(feature = "disassembler")]
12mod disassembler;
13pub mod options;
14
15use crate::{disassembler::options::DisassemblerOptions, prelude::*};
16use cfg_if::cfg_if;
17#[cfg(feature = "disassembler")]
18pub use disassembler::*;
19use log::info;
20
21/// Converts a DXB block to a human-readable assembly string representation and prints it to stdout
22pub fn print_disassembled(dxb: &[u8]) {
23    print_disassembled_with_options(dxb, DisassemblerOptions::default());
24}
25
26/// Converts a DXB block to a human-readable assembly string representation and prints it to stdout
27pub fn print_disassembled_with_options(
28    dxb: &[u8],
29    options: DisassemblerOptions,
30) {
31    info!(
32        "\n\n=== Disassembled DXB Body ===\n{}==== END ===\n",
33        get_disassembled_with_options(dxb, options)
34    );
35}
36
37/// Converts a DXB block to a human-readable assembly string representation
38pub fn get_disassembled_with_options(
39    dxb: &[u8],
40    options: DisassemblerOptions,
41) -> String {
42    cfg_if! {
43        if #[cfg(feature = "disassembler")] {
44            disassemble_body_to_string(dxb, options)
45        }
46        else {
47            "[feature 'disassembler' is not enabled]".to_string()
48        }
49    }
50}