Skip to content

Commit

Permalink
Merge branch 'main' into tb
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanuppal authored Nov 20, 2024
2 parents 447b6f7 + fa298e9 commit ee8eed6
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 74 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions interp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ baa = { version = "0.14.0", features = ["bigint", "serde1", "fraction1"] }
fst-writer = "0.2.1"
bon = "2.3"

# derivative = "2.2.0"

[dev-dependencies]
proptest = "1.0.0"

Expand Down
17 changes: 13 additions & 4 deletions interp/src/debugger/commands/command_parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::core::{
Command, ParsedBreakPointID, ParsedGroupName, PrintMode, WatchPosition,
use super::{
core::{
Command, ParsedBreakPointID, ParsedGroupName, PrintMode, WatchPosition,
},
PrintCommand,
};
use baa::WidthInt;
use pest_consume::{match_nodes, Error, Parser};
Expand All @@ -21,10 +24,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<Command> {
Expand Down Expand Up @@ -60,8 +68,9 @@ impl CommandParser {

fn comm_where(input: Node) -> ParseResult<Command> {
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),
))
}

Expand Down
3 changes: 2 additions & 1 deletion interp/src/debugger/commands/commands.pest
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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" }

Expand Down
9 changes: 8 additions & 1 deletion interp/src/debugger/commands/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ impl From<(Vec<Path>, Option<PrintCode>, 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).
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 11 additions & 4 deletions interp/src/debugger/debugger_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use super::{
};
use crate::{
configuration::RuntimeConfig,
debugger::{source::SourceMap, unwrap_error_message},
debugger::{
commands::PrintCommand, source::SourceMap, unwrap_error_message,
},
errors::{CiderError, CiderResult},
flatten::{
flat_ir::prelude::GroupIdx,
Expand Down Expand Up @@ -368,10 +370,15 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {
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())
}
Expand Down
2 changes: 1 addition & 1 deletion interp/src/flatten/primitives/prim_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub trait RaceDetectionPrimitive: Primitive {
/// optional default implementation due to size rules
fn as_primitive(&self) -> &dyn Primitive;

fn clone_boxed(&self) -> Box<dyn RaceDetectionPrimitive>;
fn clone_boxed_rd(&self) -> Box<dyn RaceDetectionPrimitive>;
}

/// An empty primitive implementation used for testing. It does not do anything
Expand Down
6 changes: 3 additions & 3 deletions interp/src/flatten/primitives/stateful/memories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Primitive for StdReg {
}

impl RaceDetectionPrimitive for StdReg {
fn clone_boxed(&self) -> Box<dyn RaceDetectionPrimitive> {
fn clone_boxed_rd(&self) -> Box<dyn RaceDetectionPrimitive> {
Box::new(self.clone())
}

Expand Down Expand Up @@ -624,7 +624,7 @@ impl Primitive for CombMem {
}

impl RaceDetectionPrimitive for CombMem {
fn clone_boxed(&self) -> Box<dyn RaceDetectionPrimitive> {
fn clone_boxed_rd(&self) -> Box<dyn RaceDetectionPrimitive> {
Box::new(self.clone())
}

Expand Down Expand Up @@ -939,7 +939,7 @@ impl Primitive for SeqMem {
}

impl RaceDetectionPrimitive for SeqMem {
fn clone_boxed(&self) -> Box<dyn RaceDetectionPrimitive> {
fn clone_boxed_rd(&self) -> Box<dyn RaceDetectionPrimitive> {
Box::new(self.clone())
}

Expand Down
28 changes: 25 additions & 3 deletions interp/src/flatten/structures/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ impl Clone for CellLedger {
},
Self::RaceDetectionPrimitive { cell_dyn } => {
Self::RaceDetectionPrimitive {
cell_dyn: RaceDetectionPrimitive::clone_boxed(
cell_dyn.deref(),
),
cell_dyn: cell_dyn.clone_boxed_rd(),
}
}
Self::Component(component_ledger) => {
Expand Down Expand Up @@ -359,6 +357,11 @@ impl<C: AsRef<Context> + Clone> Environment<C> {
pub fn ctx(&self) -> &Context {
self.ctx.as_ref()
}

pub fn pc_iter(&self) -> impl Iterator<Item = &ControlPoint> {
self.pc.iter().map(|(_, x)| x)
}

/// Returns the full name and port list of each cell in the context
pub fn iter_cells(
&self,
Expand Down Expand Up @@ -859,6 +862,17 @@ impl<C: AsRef<Context> + Clone> Environment<C> {
}
}

pub fn print_pc_string(&self) {
let ctx = self.ctx.as_ref();
for node in self.pc_iter() {
println!(
"{}: {}",
self.get_full_name(node.comp),
node.string_path(ctx)
);
}
}

fn get_name_from_cell_and_parent(
&self,
parent: GlobalCellIdx,
Expand Down Expand Up @@ -1460,6 +1474,10 @@ impl<C: AsRef<Context> + Clone> Simulator<C> {
) -> DataDump {
self.base.dump_memories(dump_registers, all_mems)
}

pub fn print_pc_string(&self) {
self.base.print_pc_string()
}
}

impl<C: AsRef<Context> + Clone> BaseSimulator<C> {
Expand Down Expand Up @@ -1518,6 +1536,10 @@ impl<C: AsRef<Context> + Clone> BaseSimulator<C> {
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.
Expand Down
61 changes: 61 additions & 0 deletions interp/src/flatten/structures/environment/program_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,67 @@ impl ControlPoint {
false
}
}

/// 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 {
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('.');
let control_map = &ctx.primary.control;
let mut count = -1;
let mut body = false;
let mut if_branches: HashMap<ControlIdx, String> = HashMap::new();
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;
let control_node = control_map.get(control_idx).unwrap();
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;
}
_ => {}
};

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 {
count += 1;
count.to_string()
};

string_path = string_path + "-" + &control_type;
}
string_path
}
}

#[derive(Debug, Clone)]
Expand Down
15 changes: 1 addition & 14 deletions interp/src/flatten/structures/indexed_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
ops::{self, Index},
};

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct IndexedMap<K, D>
where
K: IndexRef,
Expand Down Expand Up @@ -144,19 +144,6 @@ where
}
}

impl<T, K> Clone for IndexedMap<K, T>
where
K: IndexRef,
T: Clone,
{
fn clone(&self) -> Self {
Self {
data: self.data.clone(),
phantom: PhantomData,
}
}
}

#[allow(dead_code)]
pub struct IndexedMapRangeIterator<'range, 'data, K, D>
where
Expand Down
Loading

0 comments on commit ee8eed6

Please sign in to comment.