From 055193e926cc79d3f9dd7b78f8ef17b8d243b1b0 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Fri, 24 Feb 2023 14:40:37 -0800 Subject: [PATCH] Add tracing. --- src/interp.rs | 4 +--- src/passes.rs | 1 + src/passes/trace.rs | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/passes/trace.rs diff --git a/src/interp.rs b/src/interp.rs index 2133386..b04f056 100644 --- a/src/interp.rs +++ b/src/interp.rs @@ -14,7 +14,6 @@ pub struct InterpContext { memories: PerEntity, tables: PerEntity, globals: PerEntity, - trace_log: Vec<(usize, Vec)>, } type MultiVal = SmallVec<[ConstVal; 2]>; @@ -73,7 +72,6 @@ impl InterpContext { memories, tables, globals, - trace_log: vec![], } } @@ -191,7 +189,7 @@ impl InterpContext { multivalue[0] }) .collect::>(); - self.trace_log.push((id, args)); + eprintln!("TRACE: {}: {:?}", id, &args[..]); smallvec![] } &ValueDef::None | &ValueDef::Placeholder(..) | &ValueDef::BlockParam(..) => { diff --git a/src/passes.rs b/src/passes.rs index c001335..93de4ad 100644 --- a/src/passes.rs +++ b/src/passes.rs @@ -5,3 +5,4 @@ pub mod dom_pass; pub mod empty_blocks; pub mod maxssa; pub mod resolve_aliases; +pub mod trace; diff --git a/src/passes/trace.rs b/src/passes/trace.rs new file mode 100644 index 0000000..8c5f9d0 --- /dev/null +++ b/src/passes/trace.rs @@ -0,0 +1,18 @@ +//! Trace-insertion pass. + +use crate::entity::EntityRef; +use crate::ir::*; + +pub fn run(body: &mut FunctionBody) { + for (block, data) in body.blocks.entries_mut() { + let value = ValueDef::Trace( + block.index(), + data.params + .iter() + .map(|&(_, param)| param) + .collect::>(), + ); + let value = body.values.push(value); + data.insts.insert(0, value); + } +}