Skip to main content

chipi_core/backend/
binja.rs

1//! Binary Ninja Architecture plugin backend.
2//!
3//! Generates a Python Architecture plugin for Binary Ninja
4//! from a validated `.chipi` definition.
5
6use crate::codegen_binja;
7use crate::config::GenTarget;
8use crate::tree;
9use crate::types::ValidatedDef;
10
11use super::{CodegenBackend, CodegenError};
12
13/// The Binary Ninja code generation backend.
14pub struct BinjaBackend;
15
16impl CodegenBackend for BinjaBackend {
17    fn lang(&self) -> &str {
18        "binja"
19    }
20
21    fn generate(&self, ir: &ValidatedDef, config: &GenTarget) -> Result<String, CodegenError> {
22        let tree = tree::build_tree(ir);
23        let opts = config.lang_options.as_binja().ok_or_else(|| {
24            CodegenError::Internal("Binary Ninja backend requires Binja options".into())
25        })?;
26        Ok(codegen_binja::generate_binja_code(ir, &tree, opts))
27    }
28
29    fn formatter_command(&self) -> Option<&[&str]> {
30        Some(&["ruff", "format"])
31    }
32}