Add trace-level logging to interpreter

This commit is contained in:
Andrew Brown
2020-05-26 08:20:36 -07:00
committed by Benjamin Bouvier
parent ca0c24e346
commit 4e016afca3

View File

@@ -11,7 +11,7 @@ use cranelift_codegen::ir::{
Value as ValueRef, ValueList, Value as ValueRef, ValueList,
}; };
use cranelift_reader::{DataValue, DataValueCastFailure}; use cranelift_reader::{DataValue, DataValueCastFailure};
use log::debug; use log::trace;
use std::ops::{Add, Sub}; use std::ops::{Add, Sub};
use thiserror::Error; use thiserror::Error;
@@ -105,7 +105,7 @@ impl Interpreter {
/// Interpret a call to a [Function] given its [DataValue] arguments. /// Interpret a call to a [Function] given its [DataValue] arguments.
fn call(&self, function: &Function, arguments: &[DataValue]) -> Result<ControlFlow, Trap> { fn call(&self, function: &Function, arguments: &[DataValue]) -> Result<ControlFlow, Trap> {
debug!("Call: {}({:?})", function.name, arguments); trace!("Call: {}({:?})", function.name, arguments);
let first_block = function let first_block = function
.layout .layout
.blocks() .blocks()
@@ -120,14 +120,14 @@ impl Interpreter {
/// Interpret a [Block] in a [Function]. This drives the interpretation over sequences of /// Interpret a [Block] in a [Function]. This drives the interpretation over sequences of
/// instructions, which may continue in other blocks, until the function returns. /// instructions, which may continue in other blocks, until the function returns.
fn block(&self, frame: &mut Frame, block: Block) -> Result<ControlFlow, Trap> { fn block(&self, frame: &mut Frame, block: Block) -> Result<ControlFlow, Trap> {
debug!("Block: {}", block); trace!("Block: {}", block);
let layout = &frame.function.layout; let layout = &frame.function.layout;
let mut maybe_inst = layout.first_inst(block); let mut maybe_inst = layout.first_inst(block);
while let Some(inst) = maybe_inst { while let Some(inst) = maybe_inst {
match self.inst(frame, inst)? { match self.inst(frame, inst)? {
ControlFlow::Continue => maybe_inst = layout.next_inst(inst), ControlFlow::Continue => maybe_inst = layout.next_inst(inst),
ControlFlow::ContinueAt(block, old_names) => { ControlFlow::ContinueAt(block, old_names) => {
debug!("Block: {}", block); trace!("Block: {}", block);
let new_names = frame.function.dfg.block_params(block); let new_names = frame.function.dfg.block_params(block);
frame.rename(&old_names, new_names); frame.rename(&old_names, new_names);
maybe_inst = layout.first_inst(block) maybe_inst = layout.first_inst(block)
@@ -142,7 +142,7 @@ impl Interpreter {
/// implementations. /// implementations.
fn inst(&self, frame: &mut Frame, inst: Inst) -> Result<ControlFlow, Trap> { fn inst(&self, frame: &mut Frame, inst: Inst) -> Result<ControlFlow, Trap> {
use ControlFlow::{Continue, ContinueAt}; use ControlFlow::{Continue, ContinueAt};
debug!("Inst: {}", &frame.function.dfg.display_inst(inst, None)); trace!("Inst: {}", &frame.function.dfg.display_inst(inst, None));
let data = &frame.function.dfg[inst]; let data = &frame.function.dfg[inst];
match data { match data {