use clap::Args;
use std::path::PathBuf;
use crate::mds::serializer::BinarySerializer;
use crate::HelixIR;
#[derive(Args)]
pub struct SerializeArgs {
#[arg(short, long)]
input: PathBuf,
#[arg(short, long)]
output: PathBuf,
#[arg(long, default_value_t = false)]
compress: bool,
}
pub fn run(args: SerializeArgs) -> anyhow::Result<()> {
let ir_data = std::fs::read(&args.input)
.map_err(|e| anyhow::anyhow!("Failed to read input IR file: {}", e))?;
let ir: HelixIR = bincode::deserialize(&ir_data)
.map_err(|e| anyhow::anyhow!("Failed to deserialize IR: {}", e))?;
let serializer = BinarySerializer::new(args.compress);
let binary = serializer.serialize(ir, Some(&args.input))
.map_err(|e| anyhow::anyhow!("Serialization error: {}", e))?;
serializer.write_to_file(&binary, &args.output)
.map_err(|e| anyhow::anyhow!("Failed to write binary: {}", e))?;
println!("Serialized binary written to {}", args.output.display());
Ok(())
}