Add a scheme for registering and obtaining errors even without access to an InterpCx

This commit is contained in:
Oliver Scherer 2019-12-24 00:22:32 +01:00
parent 4de031b3da
commit 4411903cca
2 changed files with 18 additions and 1 deletions

View File

@ -60,3 +60,20 @@ pub fn report_err<'tcx, 'mir>(
// Let the reported error determine the return code.
return None;
}
use std::cell::RefCell;
thread_local! {
static ECX: RefCell<Vec<InterpErrorInfo<'static>>> = RefCell::new(Vec::new());
}
pub fn register_err(e: InterpErrorInfo<'static>) {
ECX.with(|ecx| ecx.borrow_mut().push(e));
}
pub fn process_errors(mut f: impl FnMut(InterpErrorInfo<'static>)) {
ECX.with(|ecx| {
for e in ecx.borrow_mut().drain(..) {
f(e);
}
});
}

View File

@ -42,7 +42,7 @@ pub use crate::shims::time::EvalContextExt as TimeEvalContextExt;
pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
pub use crate::shims::EvalContextExt as ShimsEvalContextExt;
pub use crate::diagnostics::report_err;
pub use crate::diagnostics::{process_errors, register_err, report_err};
pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo};
pub use crate::helpers::EvalContextExt as HelpersEvalContextExt;
pub use crate::machine::{