1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;

use crate::bits::BitWriter;
use crate::environment::Environment;
use crate::result::CompilerResult;

mod sections;

/// Takes in a Binary Config representation and emits it to a file
pub fn emit(environment: &Environment, output_path: Option<PathBuf>) -> CompilerResult<u32> {
    let mut res = CompilerResult::new("Emitting Config Binary File");

    let default_cbf = "./a.cbf";
    let mut file = check!(res, File::create(output_path.unwrap_or(default_cbf.into())));
    let mut buffer = BitWriter::new();
    let crc_hash = environment.append_to_buffer(&mut buffer);

    res.require(file.write_all(buffer.as_bytes()));
    res.with_value(crc_hash)
}