voce_validator/engine.rs
1//! Validation engine — orchestrates passes and collects diagnostics.
2
3use crate::errors::ValidationResult;
4use crate::index::NodeIndex;
5use crate::ir::VoceIr;
6use crate::passes;
7
8/// Run all validation passes on a JSON IR string.
9///
10/// Returns a `ValidationResult` containing all diagnostics from all passes.
11/// The JSON string must be the Voce IR canonical JSON format.
12pub fn validate(json: &str) -> Result<ValidationResult, String> {
13 // Deserialize
14 let ir: VoceIr =
15 serde_json::from_str(json).map_err(|e| format!("Failed to parse IR JSON: {e}"))?;
16
17 // Build index
18 let index = NodeIndex::build(&ir);
19
20 // Run passes
21 let mut result = ValidationResult::default();
22 for pass in passes::all_passes() {
23 pass.run(&ir, &index, &mut result);
24 }
25
26 Ok(result)
27}