pub mod backend;
pub mod bindings;
pub mod codegen;
pub mod codegen_binja;
pub mod codegen_cpp;
pub mod codegen_ida;
pub mod codegen_python;
pub mod config;
pub mod error;
pub mod format_parser;
pub mod instr_gen;
pub mod lut_gen;
pub mod parser;
pub mod tree;
pub mod types;
pub mod validate;
use std::collections::HashMap;
use error::Errors;
use types::DecoderDef;
pub use config::Dispatch;
pub fn parse(input: &str) -> Result<DecoderDef, Box<dyn std::error::Error>> {
let path = std::path::Path::new(input);
parser::parse_file(path).map_err(|errs| Box::new(Errors(errs)) as Box<dyn std::error::Error>)
}
pub fn parse_str(source: &str, filename: &str) -> Result<DecoderDef, Vec<error::Error>> {
parser::parse(source, filename)
}
pub fn generate_from_str(
source: &str,
filename: &str,
) -> Result<String, Box<dyn std::error::Error>> {
let def = parser::parse(source, filename)
.map_err(|errs| Box::new(Errors(errs)) as Box<dyn std::error::Error>)?;
let validated = validate::validate(&def)
.map_err(|errs| Box::new(Errors(errs)) as Box<dyn std::error::Error>)?;
let tree = tree::build_tree(&validated);
let code = codegen::generate_code(&validated, &tree, &HashMap::new(), &HashMap::new());
Ok(code)
}