verilization_compiler/
model_loader.rs

1use crate::VError;
2use crate::model;
3use crate::type_check::type_check_verilization;
4
5#[cfg(not(target_arch = "wasm32"))]
6use std::path::Path;
7
8/// Loads a set of files into a model.
9/// 
10/// ```no_run
11/// use verilization_compiler::load_files;
12/// # fn main() -> Result<(), verilization_compiler::VError> {
13/// let model = load_files(vec!("hello.verilization", "world.verilization"))?;
14/// // ...
15/// # Ok(())
16/// # }
17/// ```
18#[cfg(not(target_arch = "wasm32"))]
19pub fn load_files<P : AsRef<Path>>(files: Vec<P>) -> Result<model::Verilization, VError> {
20	use crate::parser;
21	
22	let models = files
23		.into_iter()
24		.map(|file| {
25			let content = std::fs::read_to_string(file).expect("Could not read input file.");
26			let (_, model) = parser::parse_model(&content)?;
27			let model = model()?;
28			Ok(model)
29		});
30
31	load_all_models(models)
32}
33
34pub fn load_all_models<M : Iterator<Item = Result<model::Verilization, VError>>>(mut models: M) -> Result<model::Verilization, VError> {
35
36	let mut model = models.next().ok_or(VError::NoInputFiles)??;
37	while let Some(other) = models.next() {
38		model.merge(other?)?;
39	}
40
41	type_check_verilization(&model)?;
42
43	Ok(model)
44}
45