From 28d9af4a8c75ed15e0b0042d834ae197290dd086 Mon Sep 17 00:00:00 2001 From: ec798 Date: Sat, 5 Oct 2024 21:42:08 -0400 Subject: [PATCH 01/10] inital pathing for debugger --- interp/src/debugger/debugger_core.rs | 21 ++++++++++++- .../src/flatten/structures/environment/env.rs | 6 ++++ .../structures/environment/program_counter.rs | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/interp/src/debugger/debugger_core.rs b/interp/src/debugger/debugger_core.rs index 6b34dc8ef7..ebc5b12003 100644 --- a/interp/src/debugger/debugger_core.rs +++ b/interp/src/debugger/debugger_core.rs @@ -220,6 +220,22 @@ impl + Clone> Debugger { Ok(()) } + // Print executing points + pub fn print_executing(&self) { + let env = self.interpreter.env(); + let ctx = self.program_context.as_ref(); + + let mut pc_iterable = env.pc_iter(); + + // For now we do all control points: + let mut item = pc_iterable.next(); + while item.is_some() { + let control_point = item.unwrap(); + println!("{}", control_point.string_path(ctx)); + item = pc_iterable.next(); + } + } + // so on and so forth /// The main loop of the debugger. This function is the entry point for the @@ -281,7 +297,10 @@ impl + Clone> Debugger { }; match comm { - Command::Step(n) => self.do_step(n)?, + Command::Step(n) => { + self.print_executing(); + self.do_step(n)? + } Command::StepOver(target) => { self.do_step_over(target)?; } diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index 98e3c96bea..2fbfd58fbc 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -46,6 +46,7 @@ use owo_colors::OwoColorize; use slog::warn; use std::fmt::Debug; use std::fmt::Write; +use std::slice::Iter; pub type PortMap = IndexedMap; @@ -284,6 +285,11 @@ impl + Clone> Environment { pub fn ctx(&self) -> &Context { self.ctx.as_ref() } + + pub fn pc_iter(&self) -> Iter<'_, ControlPoint> { + self.pc.iter() + } + /// Returns the full name and port list of each cell in the context pub fn iter_cells( &self, diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index 7b1e52f95d..7ef947bb2a 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -56,6 +56,37 @@ impl ControlPoint { false } } + + /// Returns a string showing the path from the root node to input node. + /// How to get context? + pub fn string_path(&self, ctx: &Context) -> String { + // Does it matter if it takes ownership? + let path = SearchPath::find_path_from_root(self.control_node_idx, ctx); + let control_map = &ctx.primary.control; + let mut string_path = String::from("main::"); + let mut first = true; + for search_node in path.path { + // The control_idx should exist in the map, so we shouldn't worry about it + // exploding. + let seperator = if first { "" } else { "_" }; + first = false; + + let control_idx = search_node.node; + let control_node = control_map.get(control_idx).unwrap(); + let control_type = match control_node { + ControlNode::Empty(_) => "empty", + ControlNode::Enable(_) => "enable", + ControlNode::Seq(_) => "seq", + ControlNode::Par(_) => "par", + ControlNode::If(_) => "if", + ControlNode::While(_) => "while", + ControlNode::Repeat(_) => "repeat", + ControlNode::Invoke(_) => "invoke", + }; + string_path = string_path + seperator + control_type; + } + string_path + } } #[derive(Debug, Clone)] From 17fed18954d41c4369428cfb0daf9ae30e113751 Mon Sep 17 00:00:00 2001 From: ec798 Date: Mon, 4 Nov 2024 23:30:43 -0500 Subject: [PATCH 02/10] Finished implementing print node command for debugger --- .../src/debugger/commands/command_parser.rs | 17 +++-- interp/src/debugger/commands/commands.pest | 3 +- interp/src/debugger/commands/core.rs | 9 ++- interp/src/debugger/debugger_core.rs | 36 ++++------- .../src/flatten/structures/environment/env.rs | 16 +++++ .../structures/environment/program_counter.rs | 63 ++++++++++++++----- 6 files changed, 98 insertions(+), 46 deletions(-) diff --git a/interp/src/debugger/commands/command_parser.rs b/interp/src/debugger/commands/command_parser.rs index cd512c5a17..9cf336a3ad 100644 --- a/interp/src/debugger/commands/command_parser.rs +++ b/interp/src/debugger/commands/command_parser.rs @@ -1,5 +1,8 @@ -use super::core::{ - Command, ParsedBreakPointID, ParsedGroupName, PrintMode, WatchPosition, +use super::{ + core::{ + Command, ParsedBreakPointID, ParsedGroupName, PrintMode, WatchPosition, + }, + PrintCommand, }; use pest_consume::{match_nodes, Error, Parser}; @@ -20,10 +23,15 @@ impl CommandParser { fn EOI(_input: Node) -> ParseResult<()> { Ok(()) } + fn code_calyx(_input: Node) -> ParseResult<()> { Ok(()) } + fn code_nodes(_input: Node) -> ParseResult<()> { + Ok(()) + } + // ---------------------- fn help(_input: Node) -> ParseResult { @@ -59,8 +67,9 @@ impl CommandParser { fn comm_where(input: Node) -> ParseResult { Ok(match_nodes!(input.into_children(); - [code_calyx(_)] => Command::PrintPC(true), - [] => Command::PrintPC(false), + [code_calyx(_)] => Command::PrintPC(PrintCommand::PrintCalyx), + [code_nodes(_)] => Command::PrintPC(PrintCommand::PrintNodes), + [] => Command::PrintPC(PrintCommand::Normal), )) } diff --git a/interp/src/debugger/commands/commands.pest b/interp/src/debugger/commands/commands.pest index 799971648c..7a1920c680 100644 --- a/interp/src/debugger/commands/commands.pest +++ b/interp/src/debugger/commands/commands.pest @@ -14,6 +14,7 @@ pc_s = { ^"s" } pc_ufx = { ^"u." ~ num } pc_sfx = { ^"s." ~ num } code_calyx = { ^"calyx" } +code_nodes = {^"nodes"} print_code = { "\\" ~ (pc_ufx | pc_sfx | pc_s | pc_un) @@ -67,7 +68,7 @@ disable_watch = { (^"disable-watch " | ^"disw ") ~ brk_id+ } exit = { ^"exit" | ^"quit" } -comm_where = { (^"where" | "pc") ~ (code_calyx)? } +comm_where = { (^"where" | "pc") ~ (code_calyx | code_nodes)? } explain = { ^"explain" } diff --git a/interp/src/debugger/commands/core.rs b/interp/src/debugger/commands/core.rs index 46f86279bb..37148ef8a0 100644 --- a/interp/src/debugger/commands/core.rs +++ b/interp/src/debugger/commands/core.rs @@ -299,6 +299,13 @@ impl From<(Vec, Option, PrintMode)> for PrintTuple { } } +// Different types of printing commands +pub enum PrintCommand { + Normal, + PrintCalyx, + PrintNodes, +} + /// A command that can be sent to the debugger. pub enum Command { /// Advance the execution by a given number of steps (cycles). @@ -345,7 +352,7 @@ pub enum Command { PrintMode, ), /// Print the current program counter - PrintPC(bool), + PrintPC(PrintCommand), /// Show command examples Explain, /// Restart the debugger from the beginning of the execution. Command history, breakpoints, watchpoints, etc. are preserved. diff --git a/interp/src/debugger/debugger_core.rs b/interp/src/debugger/debugger_core.rs index ebc5b12003..9c38678f21 100644 --- a/interp/src/debugger/debugger_core.rs +++ b/interp/src/debugger/debugger_core.rs @@ -5,7 +5,9 @@ use super::{ source::structures::NewSourceMap, }; use crate::{ - debugger::{source::SourceMap, unwrap_error_message}, + debugger::{ + commands::PrintCommand, source::SourceMap, unwrap_error_message, + }, errors::{InterpreterError, InterpreterResult}, flatten::{ flat_ir::prelude::GroupIdx, @@ -220,22 +222,6 @@ impl + Clone> Debugger { Ok(()) } - // Print executing points - pub fn print_executing(&self) { - let env = self.interpreter.env(); - let ctx = self.program_context.as_ref(); - - let mut pc_iterable = env.pc_iter(); - - // For now we do all control points: - let mut item = pc_iterable.next(); - while item.is_some() { - let control_point = item.unwrap(); - println!("{}", control_point.string_path(ctx)); - item = pc_iterable.next(); - } - } - // so on and so forth /// The main loop of the debugger. This function is the entry point for the @@ -297,10 +283,7 @@ impl + Clone> Debugger { }; match comm { - Command::Step(n) => { - self.print_executing(); - self.do_step(n)? - } + Command::Step(n) => self.do_step(n)?, Command::StepOver(target) => { self.do_step_over(target)?; } @@ -379,10 +362,15 @@ impl + Clone> Debugger { Command::InfoWatch => self .debugging_context .print_watchpoints(self.interpreter.env()), - Command::PrintPC(_override_flag) => { - self.interpreter.print_pc(); - } + Command::PrintPC(print_mode) => match print_mode { + PrintCommand::Normal | PrintCommand::PrintCalyx => { + self.interpreter.print_pc(); + } + PrintCommand::PrintNodes => { + self.interpreter.print_pc_string(); + } + }, Command::Explain => { print!("{}", Command::get_explain_string()) } diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index 2fbfd58fbc..e116b8aae7 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -727,6 +727,18 @@ impl + Clone> Environment { } } + pub fn print_pc_string(&self) { + let current_nodes = self.pc.iter(); + let ctx = &self.ctx.as_ref(); + for node in current_nodes { + println!( + "{}: {}", + self.get_full_name(node.comp), + node.string_path(ctx) + ); + } + } + fn get_name_from_cell_and_parent( &self, parent: GlobalCellIdx, @@ -1274,6 +1286,10 @@ impl + Clone> Simulator { self.env.print_pc() } + pub fn print_pc_string(&self) { + self.env.print_pc_string() + } + /// Pins the port with the given name to the given value. This may only be /// used for input ports on the entrypoint component (excluding the go port) /// and will panic if used otherwise. Intended for external use. diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index 7ef947bb2a..587d9696e1 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -63,27 +63,58 @@ impl ControlPoint { // Does it matter if it takes ownership? let path = SearchPath::find_path_from_root(self.control_node_idx, ctx); let control_map = &ctx.primary.control; - let mut string_path = String::from("main::"); - let mut first = true; + let mut string_path = String::from(""); + let mut count = -1; + let mut body = false; + let mut if_branches: HashMap = HashMap::new(); for search_node in path.path { // The control_idx should exist in the map, so we shouldn't worry about it - // exploding. - let seperator = if first { "" } else { "_" }; - first = false; - + // exploding. First SearchNode is root, hence "." let control_idx = search_node.node; let control_node = control_map.get(control_idx).unwrap(); - let control_type = match control_node { - ControlNode::Empty(_) => "empty", - ControlNode::Enable(_) => "enable", - ControlNode::Seq(_) => "seq", - ControlNode::Par(_) => "par", - ControlNode::If(_) => "if", - ControlNode::While(_) => "while", - ControlNode::Repeat(_) => "repeat", - ControlNode::Invoke(_) => "invoke", + match control_node { + // These are terminal nodes + // ControlNode::Empty(_) => "empty", + // ControlNode::Invoke(_) => "invoke", + // ControlNode::Enable(_) => "enable", + + // These have unbounded children + // ControlNode::Seq(_) => "seq", + // ControlNode::Par(_) => "par", + + // Special cases + ControlNode::If(if_node) => { + if_branches.insert(if_node.tbranch(), String::from("t")); + if_branches.insert(if_node.tbranch(), String::from("f")); + } + ControlNode::While(_) => { + body = true; + } + ControlNode::Repeat(_) => { + body = true; + } + _ => {} + }; + // At root, at end to process logic above. + if string_path == String::from("") { + string_path = string_path + "."; + continue; + } + let control_type = if body { + body = false; + count = -1; + "b" + } else { + if if_branches.contains_key(&control_idx) { + let (_, branch) = + if_branches.get_key_value(&control_idx).unwrap(); + branch + } else { + count += 1; + &count.to_string() + } }; - string_path = string_path + seperator + control_type; + string_path = string_path + "-" + control_type; } string_path } From e75a7178f7d25b8fe9adc35daa53d0ae0583f8d8 Mon Sep 17 00:00:00 2001 From: ec798 Date: Sat, 9 Nov 2024 22:14:40 -0500 Subject: [PATCH 03/10] borrow fix --- .../src/flatten/structures/environment/program_counter.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index 587d9696e1..7f7288723f 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -103,18 +103,18 @@ impl ControlPoint { let control_type = if body { body = false; count = -1; - "b" + String::from("b") } else { if if_branches.contains_key(&control_idx) { let (_, branch) = if_branches.get_key_value(&control_idx).unwrap(); - branch + branch.clone() } else { count += 1; - &count.to_string() + count.to_string() } }; - string_path = string_path + "-" + control_type; + string_path = string_path + "-" + &control_type; } string_path } From a9791c4632adb90cfbec3ac12370cc96b2fa1e30 Mon Sep 17 00:00:00 2001 From: ec798 Date: Sat, 9 Nov 2024 22:32:46 -0500 Subject: [PATCH 04/10] clippy complaints --- .../structures/environment/program_counter.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index 7f7288723f..eb3c51e510 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -96,24 +96,23 @@ impl ControlPoint { _ => {} }; // At root, at end to process logic above. - if string_path == String::from("") { - string_path = string_path + "."; + if string_path == "" { + string_path += "."; continue; } let control_type = if body { body = false; count = -1; String::from("b") + } else if if_branches.contains_key(&control_idx) { + let (_, branch) = + if_branches.get_key_value(&control_idx).unwrap(); + branch.clone() } else { - if if_branches.contains_key(&control_idx) { - let (_, branch) = - if_branches.get_key_value(&control_idx).unwrap(); - branch.clone() - } else { - count += 1; - count.to_string() - } + count += 1; + count.to_string() }; + string_path = string_path + "-" + &control_type; } string_path From 537833067c76ea12e11138408c55101034301c46 Mon Sep 17 00:00:00 2001 From: ec798 Date: Sat, 9 Nov 2024 22:36:29 -0500 Subject: [PATCH 05/10] MORE clippy complaints --- interp/src/flatten/structures/environment/program_counter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index eb3c51e510..81b2edfe79 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -96,7 +96,7 @@ impl ControlPoint { _ => {} }; // At root, at end to process logic above. - if string_path == "" { + if string_path.is_empty() { string_path += "."; continue; } From 8aab63468732ec43051b1ac46b9ed6ebf6153a1e Mon Sep 17 00:00:00 2001 From: ec798 Date: Mon, 11 Nov 2024 20:57:24 -0500 Subject: [PATCH 06/10] minor fixes --- .../src/flatten/structures/environment/env.rs | 2 +- .../structures/environment/program_counter.rs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index e116b8aae7..238526f877 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -729,7 +729,7 @@ impl + Clone> Environment { pub fn print_pc_string(&self) { let current_nodes = self.pc.iter(); - let ctx = &self.ctx.as_ref(); + let ctx = self.ctx.as_ref(); for node in current_nodes { println!( "{}: {}", diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index 81b2edfe79..e6fd6d5a15 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -57,17 +57,21 @@ impl ControlPoint { } } - /// Returns a string showing the path from the root node to input node. - /// How to get context? + /// Returns a string showing the path from the root node to input node. This + /// path is displayed in the minimal metadata path syntax. pub fn string_path(&self, ctx: &Context) -> String { - // Does it matter if it takes ownership? let path = SearchPath::find_path_from_root(self.control_node_idx, ctx); + let mut path_vec = path.path; + + // Remove first element since we know it is a root + path_vec.remove(0); + let mut string_path = String::new(); + string_path.push_str("."); let control_map = &ctx.primary.control; - let mut string_path = String::from(""); let mut count = -1; let mut body = false; let mut if_branches: HashMap = HashMap::new(); - for search_node in path.path { + for search_node in path_vec { // The control_idx should exist in the map, so we shouldn't worry about it // exploding. First SearchNode is root, hence "." let control_idx = search_node.node; @@ -95,11 +99,7 @@ impl ControlPoint { } _ => {} }; - // At root, at end to process logic above. - if string_path.is_empty() { - string_path += "."; - continue; - } + let control_type = if body { body = false; count = -1; From 0616f94a9734eb40a6f1f41cd8a045cddb119834 Mon Sep 17 00:00:00 2001 From: ec798 Date: Mon, 11 Nov 2024 21:00:19 -0500 Subject: [PATCH 07/10] clippy complaints --- interp/src/flatten/structures/environment/program_counter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index e6fd6d5a15..d86b3ec53d 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -66,7 +66,7 @@ impl ControlPoint { // Remove first element since we know it is a root path_vec.remove(0); let mut string_path = String::new(); - string_path.push_str("."); + string_path.push('.'); let control_map = &ctx.primary.control; let mut count = -1; let mut body = false; From eb8e4f75c409c580510024e24e2a502b32080fdd Mon Sep 17 00:00:00 2001 From: ec798 Date: Tue, 12 Nov 2024 12:12:59 -0500 Subject: [PATCH 08/10] node type fix --- interp/src/flatten/structures/environment/env.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index e27a433688..7ca5dc363b 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -340,8 +340,8 @@ impl + Clone> Environment { self.ctx.as_ref() } - pub fn pc_iter(&self) -> Iter<'_, ControlPoint> { - self.pc.iter() + pub fn pc_iter(&self) -> impl Iterator { + self.pc.iter().map(|(_, x)| x) } /// Returns the full name and port list of each cell in the context @@ -845,9 +845,8 @@ impl + Clone> Environment { } pub fn print_pc_string(&self) { - let current_nodes = self.pc.iter(); let ctx = self.ctx.as_ref(); - for node in current_nodes { + for node in self.pc_iter() { println!( "{}: {}", self.get_full_name(node.comp), From 5f8200a6012a9107c83f9e7425c583298244fe3d Mon Sep 17 00:00:00 2001 From: ec798 Date: Tue, 12 Nov 2024 12:29:45 -0500 Subject: [PATCH 09/10] fix --- interp/src/flatten/structures/environment/env.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index bd9757bbec..60dc38f9bd 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -1475,6 +1475,10 @@ impl + Clone> Simulator { ) -> DataDump { self.base.dump_memories(dump_registers, all_mems) } + + pub fn print_pc_string(&self) { + self.base.print_pc_string() + } } impl + Clone> BaseSimulator { From f9bd15f9d051869c9012bb00de3d18959b4bbc47 Mon Sep 17 00:00:00 2001 From: ec798 Date: Tue, 12 Nov 2024 13:07:32 -0500 Subject: [PATCH 10/10] clippy stuff --- interp/src/flatten/structures/environment/env.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index 60dc38f9bd..7b7360a57b 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -51,7 +51,6 @@ use owo_colors::OwoColorize; use slog::{info, warn, Logger}; use std::fmt::Debug; use std::fmt::Write; -use std::slice::Iter; pub type PortMap = IndexedMap;