helix/dna/cmd/
serializer.rs1use clap::Args;
2use std::path::PathBuf;
3use crate::mds::serializer::BinarySerializer;
4use crate::HelixIR;
5
6#[derive(Args)]
7pub struct SerializeArgs {
8 #[arg(short, long)]
10 input: PathBuf,
11
12 #[arg(short, long)]
14 output: PathBuf,
15
16 #[arg(long, default_value_t = false)]
18 compress: bool,
19}
20
21pub fn run(args: SerializeArgs) -> anyhow::Result<()> {
22 let ir_data = std::fs::read(&args.input)
24 .map_err(|e| anyhow::anyhow!("Failed to read input IR file: {}", e))?;
25 let ir: HelixIR = bincode::deserialize(&ir_data)
26 .map_err(|e| anyhow::anyhow!("Failed to deserialize IR: {}", e))?;
27
28 let serializer = BinarySerializer::new(args.compress);
30
31 let binary = serializer.serialize(ir, Some(&args.input))
33 .map_err(|e| anyhow::anyhow!("Serialization error: {}", e))?;
34
35 serializer.write_to_file(&binary, &args.output)
37 .map_err(|e| anyhow::anyhow!("Failed to write binary: {}", e))?;
38
39 println!("Serialized binary written to {}", args.output.display());
40 Ok(())
41}