verilization_compiler/
memory_output_handler.rs

1use std::collections::HashMap;
2use std::path::Path;
3use crate::lang::{OutputHandler, GeneratorError};
4
5
6/// An output handler that operates on an in-memory file system.
7pub struct MemoryOutputHandler {
8    pub files: HashMap<String, Vec<u8>>,
9}
10
11impl <'output> OutputHandler<'output> for MemoryOutputHandler {
12    type FileHandle = &'output mut Vec<u8>;
13    fn create_file<P: AsRef<Path>>(&'output mut self, path: P) -> Result<Self::FileHandle, GeneratorError> {
14        let filename = path.as_ref().to_str().expect("Invalid filename").to_string();
15        Ok(self.files.entry(filename).or_insert_with(Vec::new))
16    }
17}