helix/dna/cmd/
serializer.rs

1use clap::Args;
2use std::path::PathBuf;
3use crate::mds::serializer::BinarySerializer;
4use crate::HelixIR;
5
6#[derive(Args)]
7pub struct SerializeArgs {
8    /// Input IR file to serialize
9    #[arg(short, long)]
10    input: PathBuf,
11
12    /// Output binary file path
13    #[arg(short, long)]
14    output: PathBuf,
15
16    /// Enable compression
17    #[arg(long, default_value_t = false)]
18    compress: bool,
19}
20
21pub fn run(args: SerializeArgs) -> anyhow::Result<()> {
22    // Read the IR from the input file
23    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    // Create serializer
29    let serializer = BinarySerializer::new(args.compress);
30
31    // Serialize IR to binary
32    let binary = serializer.serialize(ir, Some(&args.input))
33        .map_err(|e| anyhow::anyhow!("Serialization error: {}", e))?;
34
35    // Write binary to output file
36    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}