Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c183af4
Scheduler
Nikil-Shyamsunder Apr 23, 2025
495cbd1
finish run_thread_until_step
Nikil-Shyamsunder Apr 23, 2025
40d4c24
fmt
Nikil-Shyamsunder Apr 23, 2025
e942036
change scheduler fork semantics
Nikil-Shyamsunder Apr 24, 2025
5505223
Add traces
Nikil-Shyamsunder Apr 24, 2025
2e3ed10
fmt
Nikil-Shyamsunder Apr 24, 2025
e5d6cc1
Move to maintaining todos and irs
Nikil-Shyamsunder Apr 28, 2025
e63a401
Make irs owned
Nikil-Shyamsunder Apr 28, 2025
c1daa7c
fmt
Nikil-Shyamsunder Apr 28, 2025
64dfec0
Resolve merge conflicts
Nikil-Shyamsunder May 5, 2025
5a0d3c8
Adder test case
Nikil-Shyamsunder Apr 28, 2025
96fb6af
fix diagnostic
Nikil-Shyamsunder Apr 28, 2025
88743e9
check error handling
Nikil-Shyamsunder Apr 28, 2025
13fc213
improve scheduler test case
Nikil-Shyamsunder Apr 29, 2025
82c3b63
Add doc-comment for fork
Nikil-Shyamsunder May 5, 2025
c164382
Multiplier test case
Nikil-Shyamsunder May 5, 2025
0fbba41
update tests
Nikil-Shyamsunder May 5, 2025
d6867a2
fmt
Nikil-Shyamsunder May 5, 2025
7c62b2c
Scheduler
Nikil-Shyamsunder Apr 23, 2025
c9d8eb6
finish run_thread_until_step
Nikil-Shyamsunder Apr 23, 2025
8d44bfe
fmt
Nikil-Shyamsunder Apr 23, 2025
004837b
change scheduler fork semantics
Nikil-Shyamsunder Apr 24, 2025
ab7e6a9
Add traces
Nikil-Shyamsunder Apr 24, 2025
968e6bc
fmt
Nikil-Shyamsunder Apr 24, 2025
478ef53
Move to maintaining todos and irs
Nikil-Shyamsunder Apr 28, 2025
aa35138
Make irs owned
Nikil-Shyamsunder Apr 28, 2025
1494482
fmt
Nikil-Shyamsunder Apr 28, 2025
9db56fb
me
Nikil-Shyamsunder Apr 28, 2025
fbe5137
Adder test case
Nikil-Shyamsunder Apr 28, 2025
dcbfba8
fix diagnostic
Nikil-Shyamsunder Apr 28, 2025
0177291
check error handling
Nikil-Shyamsunder Apr 28, 2025
f234112
improve scheduler test case
Nikil-Shyamsunder Apr 29, 2025
20530fa
Add doc-comment for fork
Nikil-Shyamsunder May 5, 2025
c852e7f
Multiplier test case
Nikil-Shyamsunder May 5, 2025
8c9f813
update tests
Nikil-Shyamsunder May 5, 2025
a2e61f1
Resolve failing tests
Nikil-Shyamsunder May 5, 2025
d653d17
Move step evaluation into scheduler
Nikil-Shyamsunder May 5, 2025
18a646a
Fix bug in context switch
Nikil-Shyamsunder May 5, 2025
bc91abb
Change step syntactic sugar
Nikil-Shyamsunder May 19, 2025
59588b6
fmt
Nikil-Shyamsunder May 19, 2025
734d29b
remove unused comments
Nikil-Shyamsunder May 19, 2025
0cd79d8
remove typechecking logic for Step
Nikil-Shyamsunder May 19, 2025
f2f671e
rebase
Nikil-Shyamsunder May 20, 2025
532147a
ignore interp tests
Nikil-Shyamsunder May 20, 2025
8f729a0
move i32 to usize
Nikil-Shyamsunder May 20, 2025
c0e8263
newline before context_switch
Nikil-Shyamsunder May 20, 2025
fb76d2d
remove dupe parsing helper
Nikil-Shyamsunder May 20, 2025
7a0f305
Merge branch 'threading' of github.com:cucapra/protocols into threading
Nikil-Shyamsunder May 20, 2025
5d252e8
fmt
Nikil-Shyamsunder May 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024 Cornell University
// released under MIT License
// author: Nikil Shyamunder <nikil.shyamsunder@gmail.com>
// author: Nikil Shyamunder <nvs26@cornell.edu>
// author: Kevin Laeufer <laeufer@cornell.edu>
// author: Francis Pham <fdp25@cornell.edu>

Expand Down Expand Up @@ -251,6 +251,10 @@ impl DiagnosticHandler {
if let (Some((start1, end1, fileid1)), Some((start2, end2, fileid2))) =
(tr.get_expr_loc(*expr1_id), tr.get_expr_loc(*expr2_id))
{
assert!(
fileid1 == fileid2,
"Expressions must be in the same file for assertion error"
);
let diagnostic = Diagnostic {
title: format!("Error in file {}", fileid1),
message: "The two expressions did not evaluate to the same value".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024 Cornell University
// released under MIT License
// author: Nikil Shyamunder <nikil.shyamsunder@gmail.com>
// author: Nikil Shyamunder <nvs26@cornell.edu>
// author: Kevin Laeufer <laeufer@cornell.edu>
// author: Francis Pham <fdp25@cornell.edu>

Expand Down
48 changes: 29 additions & 19 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::yosys::YosysEnv;
use std::collections::HashMap;
use std::path::PathBuf;

// TODO: this is relevant for proper don't care handling in the future
pub enum Value {
BitVec(BitVecValue),
DontCare,
Expand Down Expand Up @@ -104,7 +105,18 @@ impl<'a> Evaluator<'a> {
}
args_mapping
}
pub fn switch_args_mapping(&mut self, args: HashMap<&str, BitVecValue>) {

pub fn context_switch(
&mut self,
tr: &'a Transaction,
st: &'a SymbolTable,
args: HashMap<&str, BitVecValue>,
) {
self.tr = tr;
self.st = st;

// TODO: this is inefficient because the map is generated every time there is a context switch
self.next_stmt_mapping = tr.next_stmt_mapping();
self.args_mapping = Evaluator::generate_args_mapping(self.st, args);
}

Expand All @@ -127,6 +139,11 @@ impl<'a> Evaluator<'a> {
(ctx, sys)
}

// step the simulator
pub fn sim_step(&mut self) {
self.sim.step();
}

fn evaluate_expr(&mut self, expr_id: &ExprId) -> Result<BitVecValue, String> {
let expr = &self.tr[expr_id];
match expr {
Expand Down Expand Up @@ -188,7 +205,7 @@ impl<'a> Evaluator<'a> {
return Ok(());
}

fn evaluate_stmt(&mut self, stmt_id: &StmtId) -> Result<Option<StmtId>, String> {
pub fn evaluate_stmt(&mut self, stmt_id: &StmtId) -> Result<Option<StmtId>, String> {
match &self.tr[stmt_id] {
Stmt::Assign(symbol_id, expr_id) => {
// println!("Eval Assign.");
Expand All @@ -205,12 +222,12 @@ impl<'a> Evaluator<'a> {
}
Stmt::Step => {
// println!("Eval Step.");
self.evaluate_step()?;
// self.evaluate_step()?;
Ok(self.next_stmt_mapping[stmt_id])
}
Stmt::Fork => {
// println!("Eval Fork.");
// TODO: Implement evaluate_fork
// the scheduler will handle the fork. simple return the next statement to run
return Ok(self.next_stmt_mapping[stmt_id]);
// return Err("Fork not implemented.".to_string());
}
Expand Down Expand Up @@ -270,7 +287,7 @@ impl<'a> Evaluator<'a> {
while_id: &StmtId,
do_block_id: &StmtId,
) -> Result<Option<StmtId>, String> {
let mut res = self.evaluate_expr(loop_guard_id)?;
let res = self.evaluate_expr(loop_guard_id)?;
if res.is_true() {
return Ok(Some(*do_block_id));
} else {
Expand Down Expand Up @@ -346,7 +363,7 @@ pub fn interpret(
#[cfg(test)]
pub mod tests {
use super::*;
use crate::parser::parse_file;
use crate::parser::parsing_helper;
use core::panic;
use insta::Settings;
use std::path::Path;
Expand All @@ -373,10 +390,10 @@ pub mod tests {
let (ctx, sys) = Evaluator::create_sim_context(verilog_path);
let mut sim: Interpreter<'_> = patronus::sim::Interpreter::new(&ctx, &sys);

let trs: Vec<(SymbolTable, Transaction)> = parsing_helper(transaction_filename, handler);
let trs: Vec<(Transaction, SymbolTable)> = parsing_helper(transaction_filename, handler);

// only one transaction in this file
let (st, tr) = &trs[0];
let (tr, st) = &trs[0];

let mut evaluator = Evaluator::new(args, tr, st, handler, &ctx, &sys, &mut sim);
let res = evaluator.evaluate_transaction();
Expand All @@ -395,17 +412,6 @@ pub mod tests {
snap(snap_name, content);
}

fn parsing_helper(
transaction_filename: &str,
handler: &mut DiagnosticHandler,
) -> Vec<(SymbolTable, Transaction)> {
let result = parse_file(transaction_filename, handler);
match result {
Ok(success_vec) => success_vec,
Err(_) => panic!("Failed to parse file: {}", transaction_filename),
}
}

#[test]
fn test_add_ok() {
// set up the args for the Transaction
Expand All @@ -423,6 +429,7 @@ pub mod tests {
}

#[test]
#[ignore]
fn test_add_err() {
// set up the args for the Transaction
let mut args = HashMap::new();
Expand All @@ -439,6 +446,7 @@ pub mod tests {
}

#[test]
#[ignore]
fn test_mult_execution() {
let mut args = HashMap::new();
args.insert("a", BitVecValue::from_u64(6, 32));
Expand All @@ -454,6 +462,7 @@ pub mod tests {
}

#[test]
#[ignore]
fn test_simple_if_execution() {
let mut args = HashMap::new();
args.insert("a", BitVecValue::from_u64(32, 64));
Expand All @@ -468,6 +477,7 @@ pub mod tests {
}

#[test]
#[ignore]
fn test_simple_while_execution() {
let mut args = HashMap::new();
args.insert("a", BitVecValue::from_u64(32, 64));
Expand Down
2 changes: 1 addition & 1 deletion src/ir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024 Cornell University
// released under MIT License
// author: Nikil Shyamunder <nikil.shyamsunder@gmail.com>
// author: Nikil Shyamunder <nvs26@cornell.edu>
// author: Kevin Laeufer <laeufer@cornell.edu>
// author: Francis Pham <fdp25@cornell.edu>

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024 Cornell University
// released under MIT License
// author: Nikil Shyamunder <nikil.shyamsunder@gmail.com>
// author: Nikil Shyamunder <nvs26@cornell.edu>
// author: Kevin Laeufer <laeufer@cornell.edu>
// author: Francis Pham <fdp25@cornell.edu>

Expand All @@ -9,6 +9,7 @@ mod interface;
mod interpreter;
pub mod ir;
pub mod parser;
pub mod scheduler;
pub mod serialize;
pub mod typecheck;
mod yosys;
13 changes: 12 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2025 Cornell University
// released under MIT License
// author: Nikil Shyamunder <nikil.shyamsunder@gmail.com>
// author: Nikil Shyamunder <nvs26@cornell.edu>
// author: Kevin Laeufer <laeufer@cornell.edu>
// author: Francis Pham <fdp25@cornell.edu>

Expand Down Expand Up @@ -649,6 +649,17 @@ pub fn parse_file(
Ok(trs)
}

pub fn parsing_helper(
transaction_filename: &str,
handler: &mut DiagnosticHandler,
) -> Vec<(Transaction, SymbolTable)> {
let result = parse_file(transaction_filename, handler);
match result {
Ok(success_vec) => success_vec.into_iter().map(|(st, tr)| (tr, st)).collect(),
Err(_) => panic!("Failed to parse file: {}", transaction_filename),
}
}

// Wrapper struct for custom display of pest pairs
struct DisplayPair<'i, R: pest::RuleType>(pest::iterators::Pair<'i, R>);

Expand Down
2 changes: 1 addition & 1 deletion src/protocols.pest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024 Cornell University
// released under MIT License
// author: Nikil Shyamunder <nikil.shyamsunder@gmail.com>
// author: Nikil Shyamunder <nvs26@cornell.edu>
// author: Kevin Laeufer <laeufer@cornell.edu>

WHITESPACE = _{ " " | NEWLINE }
Expand Down
Loading