diff --git a/crates/verifier/src/ctx.rs b/crates/verifier/src/ctx.rs new file mode 100644 index 0000000..9547f86 --- /dev/null +++ b/crates/verifier/src/ctx.rs @@ -0,0 +1,34 @@ +//! Verification context + +use sonatina_ir::{ControlFlowGraph, Function}; + +use crate::{error::ErrorData, ErrorStack}; + +pub struct VerificationCtx<'a> { + pub func: &'a Function, + pub cfg: ControlFlowGraph, + pub error_stack: ErrorStack, +} + +impl<'a> VerificationCtx<'a> { + pub fn new(func: &'a Function) -> Self { + let mut cfg = ControlFlowGraph::new(); + cfg.compute(func); + + Self { + func, + cfg, + error_stack: ErrorStack::default(), + } + } + + pub fn report_nonfatal(&mut self, errs: &[ErrorData]) { + for e in errs { + let _err_ref = self.error_stack.push(*e); + } + } + + pub fn report_fatal(&mut self, e: ErrorData) { + self.error_stack.fatal_error = Some(e); + } +} diff --git a/crates/verifier/src/error_stack.rs b/crates/verifier/src/error_stack.rs index 6f6ec23..08b0e74 100644 --- a/crates/verifier/src/error_stack.rs +++ b/crates/verifier/src/error_stack.rs @@ -5,12 +5,13 @@ use crate::error::{Error, ErrorData, ErrorRef}; #[derive(Debug, Default)] pub struct ErrorStack { - pub errors: PrimaryMap, + pub fatal_error: Option, + pub non_fatal_errors: PrimaryMap, } impl ErrorStack { pub fn push(&mut self, err: ErrorData) -> ErrorRef { - self.errors.push(err) + self.non_fatal_errors.push(err) } pub fn into_errs_iter( @@ -18,8 +19,16 @@ impl ErrorStack { func: &Function, func_ref: FuncRef, ) -> impl IntoIterator> { - self.errors - .into_iter() + let Self { + fatal_error, + non_fatal_errors: mut errs, + } = self; + + if let Some(err) = fatal_error { + errs.push(err); + } + + errs.into_iter() .map(move |(_, err)| Error::new(err, func, func_ref)) } } diff --git a/crates/verifier/src/lib.rs b/crates/verifier/src/lib.rs index d32fd42..5cadc79 100644 --- a/crates/verifier/src/lib.rs +++ b/crates/verifier/src/lib.rs @@ -1,2 +1,8 @@ +pub mod ctx; pub mod error; pub mod error_stack; +pub mod pass; + +pub use ctx::VerificationCtx; +pub use error_stack::ErrorStack; +pub use pass::VerificationPass; diff --git a/crates/verifier/src/pass.rs b/crates/verifier/src/pass.rs new file mode 100644 index 0000000..9c4198e --- /dev/null +++ b/crates/verifier/src/pass.rs @@ -0,0 +1,7 @@ +//! Verification pass + +use crate::VerificationCtx; + +pub trait VerificationPass { + fn run(&mut self, ctx: VerificationCtx); +}