Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification pass #73

Merged
merged 8 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions crates/verifier/src/ctx.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 13 additions & 4 deletions crates/verifier/src/error_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ use crate::error::{Error, ErrorData, ErrorRef};

#[derive(Debug, Default)]
pub struct ErrorStack {
pub errors: PrimaryMap<ErrorRef, ErrorData>,
pub fatal_error: Option<ErrorData>,
pub non_fatal_errors: PrimaryMap<ErrorRef, ErrorData>,
}

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(
self,
func: &Function,
func_ref: FuncRef,
) -> impl IntoIterator<Item = Error<'_>> {
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))
}
}
6 changes: 6 additions & 0 deletions crates/verifier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions crates/verifier/src/pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Verification pass

use crate::VerificationCtx;

pub trait VerificationPass {
fn run(&mut self, ctx: VerificationCtx);
}