Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
UnsignedByte authored Nov 19, 2024
2 parents 6c8f6b4 + fa298e9 commit 471cf9a
Show file tree
Hide file tree
Showing 21 changed files with 590 additions and 116 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.

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


[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
15 changes: 15 additions & 0 deletions interp/src/flatten/primitives/combinational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use baa::{BitVecOps, BitVecValue};

use super::prim_trait::UpdateResult;

#[derive(Clone)]
pub struct StdConst {
value: BitVecValue,
out: GlobalPortIdx,
Expand Down Expand Up @@ -44,8 +45,13 @@ impl Primitive for StdConst {
fn has_stateful(&self) -> bool {
false
}

fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}
}

#[derive(Clone)]
pub struct StdMux {
base: GlobalPortIdx,
}
Expand Down Expand Up @@ -80,6 +86,10 @@ impl Primitive for StdMux {
fn has_stateful(&self) -> bool {
false
}

fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}
}

comb_primitive!(StdNot(input [0]) -> (out [1]) {
Expand Down Expand Up @@ -275,6 +285,7 @@ comb_primitive!(StdUnsynSmod[WIDTH](left [0], right [1]) -> (out [2]) {
Ok(Some(BitVecValue::from_big_int(&res, WIDTH)))
});

#[derive(Clone)]
pub struct StdUndef(GlobalPortIdx);

impl StdUndef {
Expand All @@ -288,4 +299,8 @@ impl Primitive for StdUndef {
port_map.write_undef(self.0)?;
Ok(UpdateStatus::Unchanged)
}

fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}
}
6 changes: 6 additions & 0 deletions interp/src/flatten/primitives/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ macro_rules! comb_primitive {
false
}

fn clone_boxed(&self) -> Box<dyn $crate::flatten::primitives::Primitive> {
Box::new(Self {
base_port: self.base_port,
$($($param: self.$param,)+)?
})
}
}
};

Expand Down
11 changes: 10 additions & 1 deletion interp/src/flatten/primitives/prim_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ pub trait Primitive {
fn dump_memory_state(&self) -> Option<Vec<u8>> {
None
}

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

pub trait RaceDetectionPrimitive: Primitive {
Expand All @@ -158,10 +160,13 @@ pub trait RaceDetectionPrimitive: Primitive {
/// Get a reference to the underlying primitive. Unfortunately cannot add an
/// optional default implementation due to size rules
fn as_primitive(&self) -> &dyn Primitive;

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

/// An empty primitive implementation used for testing. It does not do anything
/// and has no ports of any kind
#[derive(Clone, Copy)]
pub struct DummyPrimitive;

impl DummyPrimitive {
Expand All @@ -170,4 +175,8 @@ impl DummyPrimitive {
}
}

impl Primitive for DummyPrimitive {}
impl Primitive for DummyPrimitive {
fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(*self)
}
}
24 changes: 24 additions & 0 deletions interp/src/flatten/primitives/stateful/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::flatten::{
use baa::{BitVecOps, BitVecValue, WidthInt};
use num_traits::Euclid;

#[derive(Clone)]
pub struct StdMultPipe<const DEPTH: usize> {
base_port: GlobalPortIdx,
pipeline: ShiftBuffer<(PortValue, PortValue), DEPTH>,
Expand All @@ -32,6 +33,10 @@ impl<const DEPTH: usize> StdMultPipe<DEPTH> {
}

impl<const DEPTH: usize> Primitive for StdMultPipe<DEPTH> {
fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}

fn exec_comb(&self, port_map: &mut PortMap) -> UpdateResult {
ports![&self.base_port; out: Self::OUT, done: Self::DONE];

Expand Down Expand Up @@ -106,6 +111,7 @@ impl<const DEPTH: usize> Primitive for StdMultPipe<DEPTH> {
}
}

#[derive(Clone)]
pub struct StdDivPipe<const DEPTH: usize, const SIGNED: bool> {
base_port: GlobalPortIdx,
pipeline: ShiftBuffer<(PortValue, PortValue), DEPTH>,
Expand All @@ -132,6 +138,10 @@ impl<const DEPTH: usize, const SIGNED: bool> StdDivPipe<DEPTH, SIGNED> {
impl<const DEPTH: usize, const SIGNED: bool> Primitive
for StdDivPipe<DEPTH, SIGNED>
{
fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}

fn exec_comb(&self, port_map: &mut PortMap) -> UpdateResult {
ports![&self.base_port;
out_quot: Self::OUT_QUOTIENT,
Expand Down Expand Up @@ -253,6 +263,10 @@ impl<const IS_FIXED_POINT: bool> Sqrt<IS_FIXED_POINT> {
}

impl<const IS_FIXED_POINT: bool> Primitive for Sqrt<IS_FIXED_POINT> {
fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}

fn exec_comb(&self, port_map: &mut PortMap) -> UpdateResult {
ports![&self.base_port; out: Self::OUT, done: Self::DONE];

Expand Down Expand Up @@ -309,6 +323,7 @@ impl<const IS_FIXED_POINT: bool> Primitive for Sqrt<IS_FIXED_POINT> {
}
}

#[derive(Clone)]
pub struct FxpMultPipe<const DEPTH: usize> {
base_port: GlobalPortIdx,
pipeline: ShiftBuffer<(PortValue, PortValue), DEPTH>,
Expand Down Expand Up @@ -339,6 +354,10 @@ impl<const DEPTH: usize> FxpMultPipe<DEPTH> {
}

impl<const DEPTH: usize> Primitive for FxpMultPipe<DEPTH> {
fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}

fn exec_comb(&self, port_map: &mut PortMap) -> UpdateResult {
ports![&self.base_port; out: Self::OUT, done: Self::DONE];

Expand Down Expand Up @@ -422,6 +441,7 @@ impl<const DEPTH: usize> Primitive for FxpMultPipe<DEPTH> {
}
}

#[derive(Clone)]
pub struct FxpDivPipe<const DEPTH: usize, const SIGNED: bool> {
base_port: GlobalPortIdx,
pipeline: ShiftBuffer<(PortValue, PortValue), DEPTH>,
Expand Down Expand Up @@ -460,6 +480,10 @@ impl<const DEPTH: usize, const SIGNED: bool> FxpDivPipe<DEPTH, SIGNED> {
impl<const DEPTH: usize, const SIGNED: bool> Primitive
for FxpDivPipe<DEPTH, SIGNED>
{
fn clone_boxed(&self) -> Box<dyn Primitive> {
Box::new(self.clone())
}

fn exec_comb(&self, port_map: &mut PortMap) -> UpdateResult {
ports![&self.base_port;
out_quot: Self::OUT_QUOTIENT,
Expand Down
Loading

0 comments on commit 471cf9a

Please sign in to comment.