From e3b86a1448654dc60efb7c59057ea0030ba54e54 Mon Sep 17 00:00:00 2001 From: Nathaniel Navarro Date: Mon, 11 Jul 2022 16:19:01 -0400 Subject: [PATCH 1/4] Add more order of operation comparisons Previously all BinOps were grouped under a single precedence enum "Op." Now, they are spread out and more fine grained. This should fix issues regarding parentheses and order of operations --- src/subset/pretty_print.rs | 127 ++++++++++++++++++++++++++----------- tests/v05.rs | 12 ++++ 2 files changed, 101 insertions(+), 38 deletions(-) diff --git a/src/subset/pretty_print.rs b/src/subset/pretty_print.rs index 920e1fd6..8f17379f 100644 --- a/src/subset/pretty_print.rs +++ b/src/subset/pretty_print.rs @@ -1,5 +1,7 @@ use crate::subset::ast::*; -use crate::util::pretty_print::{block, intersperse, PrettyHelper, PrettyPrint}; +use crate::util::pretty_print::{ + block, intersperse, PrettyHelper, PrettyPrint, +}; use core::cmp::Ordering; use itertools::Itertools; use pretty::RcDoc; @@ -8,32 +10,32 @@ use pretty::RcDoc; /// operator with stronger binding. #[derive(Debug, Clone, Copy, Eq, PartialEq)] enum ParenCtx { - Op, Not, - And, - Or, + Index, + Mul, + AddSub, + Shift, + Cmp, + Equal, BAnd, BOr, + And, + Or, } impl From<&Binop> for ParenCtx { fn from(s: &Binop) -> Self { match s { - Binop::BitOr => ParenCtx::BOr, + Binop::IndexBit => ParenCtx::Index, + Binop::Mul => ParenCtx::Mul, + Binop::Add | Binop::Sub => ParenCtx::AddSub, + Binop::ShiftLeft => ParenCtx::Shift, + Binop::Lt | Binop::Gt | Binop::Geq | Binop::Leq => ParenCtx::Cmp, + Binop::Equal | Binop::NotEqual => ParenCtx::Equal, Binop::BitAnd => ParenCtx::BAnd, - Binop::LogOr => ParenCtx::Or, + Binop::BitOr => ParenCtx::BOr, Binop::LogAnd => ParenCtx::And, - Binop::Add - | Binop::Sub - | Binop::Mul - | Binop::Lt - | Binop::Gt - | Binop::Geq - | Binop::Leq - | Binop::Equal - | Binop::NotEqual - | Binop::IndexBit - | Binop::ShiftLeft => ParenCtx::Op, + Binop::LogOr => ParenCtx::Or, } } } @@ -47,18 +49,63 @@ impl Ord for ParenCtx { match (self, other) { (P::Not, _) => Ordering::Greater, - (P::Op, P::Not) => Ordering::Less, - (P::Op, _) => Ordering::Greater, + (P::Index, P::Not) => Ordering::Less, + (P::Index, _) => Ordering::Greater, + + (P::Mul, P::Not) | (P::Mul, P::Index) => Ordering::Less, + (P::Mul, _) => Ordering::Greater, + + (P::AddSub, P::Not) + | (P::AddSub, P::Index) + | (P::AddSub, P::Mul) => Ordering::Less, + (P::AddSub, _) => Ordering::Greater, + + (P::Shift, P::Not) + | (P::Shift, P::Index) + | (P::Shift, P::Mul) + | (P::Shift, P::AddSub) => Ordering::Less, + (P::Shift, _) => Ordering::Greater, - (P::BAnd, P::Not) | (P::BAnd, P::Op) => Ordering::Less, + (P::Cmp, P::Not) + | (P::Cmp, P::Index) + | (P::Cmp, P::Mul) + | (P::Cmp, P::AddSub) + | (P::Cmp, P::Shift) => Ordering::Greater, + (P::Cmp, _) => Ordering::Less, + + (P::Equal, P::Not) + | (P::Equal, P::Index) + | (P::Equal, P::Mul) + | (P::Equal, P::AddSub) + | (P::Equal, P::Shift) + | (P::Equal, P::Cmp) => Ordering::Greater, + (P::Equal, _) => Ordering::Less, + + (P::BAnd, P::Not) + | (P::BAnd, P::Mul) + | (P::BAnd, P::AddSub) + | (P::BAnd, P::Shift) + | (P::BAnd, P::Cmp) + | (P::BAnd, P::Equal) => Ordering::Less, (P::BAnd, _) => Ordering::Greater, - (P::BOr, P::Not) | (P::BOr, P::Op) | (P::BOr, P::BAnd) => Ordering::Less, + (P::BOr, P::Not) + | (P::BOr, P::Mul) + | (P::BOr, P::AddSub) + | (P::BOr, P::Shift) + | (P::BOr, P::Cmp) + | (P::BOr, P::Equal) + | (P::BOr, P::BAnd) => Ordering::Less, (P::BOr, _) => Ordering::Greater, - (P::And, P::Not) | (P::And, P::Op) | (P::And, P::BAnd) | (P::And, P::BOr) => { - Ordering::Less - } + (P::And, P::Not) + | (P::And, P::Mul) + | (P::And, P::AddSub) + | (P::And, P::Shift) + | (P::And, P::Cmp) + | (P::And, P::Equal) + | (P::And, P::BOr) + | (P::And, P::BAnd) => Ordering::Less, (P::And, _) => Ordering::Greater, (P::Or, _) => Ordering::Less, @@ -174,7 +221,9 @@ impl PrettyPrint for Expr { path.to_doc() } } - Expr::Unop(op, input) => op.to_doc().append(print_expr(input, ParenCtx::Not)), + Expr::Unop(op, input) => { + op.to_doc().append(print_expr(input, ParenCtx::Not)) + } Expr::Binop(Binop::IndexBit, lhs, rhs) => { print_expr(lhs, ParenCtx::Not).append(rhs.to_doc().brackets()) } @@ -207,15 +256,17 @@ impl PrettyPrint for Expr { .append(lo.to_doc()) .brackets(), ), - Expr::Terop(Terop::IndexSlice, var, lo, width) => var.to_doc().append( - lo.to_doc() - .append(RcDoc::space()) - .append(RcDoc::text("+")) - .append(RcDoc::text(":")) - .append(RcDoc::space()) - .append(width.to_doc()) - .brackets(), - ), + Expr::Terop(Terop::IndexSlice, var, lo, width) => { + var.to_doc().append( + lo.to_doc() + .append(RcDoc::space()) + .append(RcDoc::text("+")) + .append(RcDoc::text(":")) + .append(RcDoc::space()) + .append(width.to_doc()) + .brackets(), + ) + } Expr::Concat(concat) => concat.to_doc(), Expr::Repeat(times, expr) => RcDoc::text(times.to_string()) .append(expr.to_doc().braces()) @@ -269,13 +320,13 @@ impl PrettyPrint for AssignTy { impl PrettyPrint for Map { fn to_doc(&self) -> RcDoc<()> { intersperse( - self.iter() - .sorted_by_key(|(id, _)| (*id).clone()) - .map(|(id, expr)| { + self.iter().sorted_by_key(|(id, _)| (*id).clone()).map( + |(id, expr)| { RcDoc::text(".") .append(RcDoc::as_string(id)) .append(expr.to_doc().parens()) - }), + }, + ), RcDoc::text(",").append(RcDoc::hardline()), ) } diff --git a/tests/v05.rs b/tests/v05.rs index 2b4e7eb4..9770192d 100644 --- a/tests/v05.rs +++ b/tests/v05.rs @@ -166,6 +166,18 @@ fn test_decl_array() { check!(decl, exp); } +#[test] +fn test_bit_shift_order_of_operations() { + let bin1 = Expr::new_ulit_bin(4, "1000"); + let bin2 = Expr::new_ulit_bin(4, "0100"); + let shift_by :i32 = 2; + let shift = Expr::new_shift_left(bin1, shift_by); + let add = Expr::new_add(bin2, shift); + let exp = "4'b0100 + (4'b1000 << 2)".to_string(); + let res = add.to_string(); + check!(res, exp); +} + #[test] fn test_event_ty_posedge() { let event = EventTy::Posedge; From 9649010b3371d904eccb32eefb8669495e3f4765 Mon Sep 17 00:00:00 2001 From: Nathaniel Navarro Date: Mon, 11 Jul 2022 17:40:17 -0400 Subject: [PATCH 2/4] Formatting --- src/subset/helpers.rs | 5 ++++- src/util/pretty_print.rs | 5 ++++- src/v05/helpers.rs | 11 +++++++++-- src/v05/pretty_print.rs | 8 ++++++-- src/v17/ast.rs | 3 ++- src/v17/pretty_print.rs | 13 ++++++++++--- tests/v05.rs | 8 +++++--- tests/v17.rs | 6 ++++-- 8 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/subset/helpers.rs b/src/subset/helpers.rs index e4072ae3..a2d67267 100644 --- a/src/subset/helpers.rs +++ b/src/subset/helpers.rs @@ -264,7 +264,10 @@ impl Expr { } pub fn new_ipath_with_index(path: &str, index: &str) -> Expr { - Expr::IPath(InstancePath::new(path), Some(Rc::new(Expr::new_ref(index)))) + Expr::IPath( + InstancePath::new(path), + Some(Rc::new(Expr::new_ref(index))), + ) } pub fn new_call(name: &str, params: Vec) -> Expr { diff --git a/src/util/pretty_print.rs b/src/util/pretty_print.rs index d78abf8a..d64e8154 100644 --- a/src/util/pretty_print.rs +++ b/src/util/pretty_print.rs @@ -63,7 +63,10 @@ impl<'a, A> PrettyHelper<'a> for RcDoc<'a, A> { } } -pub fn intersperse<'a>(iter: impl Iterator>, separator: RcDoc<'a>) -> RcDoc<'a> { +pub fn intersperse<'a>( + iter: impl Iterator>, + separator: RcDoc<'a>, +) -> RcDoc<'a> { RcDoc::intersperse(iter, separator) } diff --git a/src/v05/helpers.rs b/src/v05/helpers.rs index 9c249273..52f1421e 100644 --- a/src/v05/helpers.rs +++ b/src/v05/helpers.rs @@ -33,11 +33,18 @@ impl Decl { } pub fn new_array(name: &str, width: u64, depth: u64) -> Decl { - Decl::Array(name.to_string(), Ty::new_width(width), Ty::new_width(depth)) + Decl::Array( + name.to_string(), + Ty::new_width(width), + Ty::new_width(depth), + ) } pub fn new_param_uint(name: &str, value: u32) -> Decl { - Decl::Param(name.to_string(), Expr::new_ulit_dec(32, &value.to_string())) + Decl::Param( + name.to_string(), + Expr::new_ulit_dec(32, &value.to_string()), + ) } pub fn new_param_str(name: &str, value: &str) -> Decl { diff --git a/src/v05/pretty_print.rs b/src/v05/pretty_print.rs index 8a35b23c..52be2e0c 100644 --- a/src/v05/pretty_print.rs +++ b/src/v05/pretty_print.rs @@ -1,5 +1,7 @@ // use crate::util::pretty_print::{PrettyHelper, PrettyPrint, PRETTY_INDENT}; -use crate::util::pretty_print::{block, block_with_parens, intersperse, PrettyHelper, PrettyPrint}; +use crate::util::pretty_print::{ + block, block_with_parens, intersperse, PrettyHelper, PrettyPrint, +}; use crate::v05::ast::*; use pretty::RcDoc; @@ -114,7 +116,9 @@ impl PrettyPrint for Sequential { match self { // wildcard for sensitivity list Sequential::Wildcard => RcDoc::text("*"), - Sequential::Event(ty, expr) => ty.to_doc().append(RcDoc::space()).append(expr.to_doc()), + Sequential::Event(ty, expr) => { + ty.to_doc().append(RcDoc::space()).append(expr.to_doc()) + } Sequential::IfElse(ifelse) => ifelse.to_doc(), Sequential::Assign(lexpr, rexpr, ty) => lexpr .to_doc() diff --git a/src/v17/ast.rs b/src/v17/ast.rs index 340f63a3..cfa6ee2d 100644 --- a/src/v17/ast.rs +++ b/src/v17/ast.rs @@ -11,7 +11,8 @@ pub type Instance = subset::ast::Instance; pub type CaseBranch = subset::ast::GenericCaseBranch; pub type CaseDefault = subset::ast::GenericCaseDefault; pub type Case = subset::ast::GenericCase; -pub type Function = subset::ast::GenericFunction; +pub type Function = + subset::ast::GenericFunction; pub type Stmt = subset::ast::GenericStmt; pub type Port = subset::ast::GenericPort; pub type Module = subset::ast::GenericModule; diff --git a/src/v17/pretty_print.rs b/src/v17/pretty_print.rs index 23ba142f..94431d64 100644 --- a/src/v17/pretty_print.rs +++ b/src/v17/pretty_print.rs @@ -1,5 +1,7 @@ use crate::subset::ast::Terop; -use crate::util::pretty_print::{block, block_with_parens, intersperse, PrettyHelper, PrettyPrint}; +use crate::util::pretty_print::{ + block, block_with_parens, intersperse, PrettyHelper, PrettyPrint, +}; use crate::v17::ast::*; use pretty::RcDoc; @@ -106,7 +108,10 @@ impl PrettyPrint for Function { let body = if self.body().is_empty() { RcDoc::nil() } else { - intersperse(self.body().iter().map(|x| x.to_doc()), RcDoc::hardline()) + intersperse( + self.body().iter().map(|x| x.to_doc()), + RcDoc::hardline(), + ) }; let args = RcDoc::space() .append(self.ret.to_doc()) @@ -195,7 +200,9 @@ impl PrettyPrint for Sequential { .append(RcDoc::text(";")), Sequential::SeqCase(case) => case.to_doc(), Sequential::Call(call) => call.to_doc().append(RcDoc::text(";")), - Sequential::Event(ty, expr) => ty.to_doc().append(RcDoc::space()).append(expr.to_doc()), + Sequential::Event(ty, expr) => { + ty.to_doc().append(RcDoc::space()).append(expr.to_doc()) + } Sequential::Assert(expr, branch) => { let cond = RcDoc::text("assert").append(expr.to_doc().parens()); if let Some(block) = branch { diff --git a/tests/v05.rs b/tests/v05.rs index 9770192d..7a2defa5 100644 --- a/tests/v05.rs +++ b/tests/v05.rs @@ -170,7 +170,7 @@ fn test_decl_array() { fn test_bit_shift_order_of_operations() { let bin1 = Expr::new_ulit_bin(4, "1000"); let bin2 = Expr::new_ulit_bin(4, "0100"); - let shift_by :i32 = 2; + let shift_by: i32 = 2; let shift = Expr::new_shift_left(bin1, shift_by); let add = Expr::new_add(bin2, shift); let exp = "4'b0100 + (4'b1000 << 2)".to_string(); @@ -196,7 +196,8 @@ fn test_event_ty_negedge() { #[test] fn test_sequential_event_posedge_clock() { - let seq = Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); + let seq = + Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); let exp = "posedge clock".to_string(); let res = seq.to_string(); check!(res, exp); @@ -292,7 +293,8 @@ end"#; fn test_attribute_decl() { let mut attr = Attribute::default(); attr.add_stmt("ram_style", "block"); - let decl = Decl::new_attribute_decl(attr, Decl::new_reg("ram", 32)).to_string(); + let decl = + Decl::new_attribute_decl(attr, Decl::new_reg("ram", 32)).to_string(); let gold = r#"(*ram_style = "block"*) reg [31:0] ram"#; check!(decl, gold); } diff --git a/tests/v17.rs b/tests/v17.rs index 905079f9..3fd7fda6 100644 --- a/tests/v17.rs +++ b/tests/v17.rs @@ -324,7 +324,8 @@ end"#; #[test] fn test_seq_event_posedge_clock() { - let event = Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); + let event = + Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); let res = event.to_string(); let exp = "posedge clock".to_string(); check!(res, exp); @@ -623,7 +624,8 @@ fn test_module_with_always_comb() { #[test] fn test_module_with_always_ff() { let exp = read_to_string("regression/v17/module_with_always_ff.v"); - let event = Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); + let event = + Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); let mut always = ParallelProcess::new_always_ff(); always.add_seq(Sequential::new_display("hello sync world")); always.set_event(event); From 7e5be69b2d535ed099d683b89ac0b5b8a0f95135 Mon Sep 17 00:00:00 2001 From: Nathaniel Navarro Date: Mon, 11 Jul 2022 23:30:10 -0400 Subject: [PATCH 3/4] Revert "Formatting" This reverts commit 9649010b3371d904eccb32eefb8669495e3f4765. --- src/subset/helpers.rs | 5 +---- src/util/pretty_print.rs | 5 +---- src/v05/helpers.rs | 11 ++--------- src/v05/pretty_print.rs | 8 ++------ src/v17/ast.rs | 3 +-- src/v17/pretty_print.rs | 13 +++---------- tests/v05.rs | 8 +++----- tests/v17.rs | 6 ++---- 8 files changed, 15 insertions(+), 44 deletions(-) diff --git a/src/subset/helpers.rs b/src/subset/helpers.rs index a2d67267..e4072ae3 100644 --- a/src/subset/helpers.rs +++ b/src/subset/helpers.rs @@ -264,10 +264,7 @@ impl Expr { } pub fn new_ipath_with_index(path: &str, index: &str) -> Expr { - Expr::IPath( - InstancePath::new(path), - Some(Rc::new(Expr::new_ref(index))), - ) + Expr::IPath(InstancePath::new(path), Some(Rc::new(Expr::new_ref(index)))) } pub fn new_call(name: &str, params: Vec) -> Expr { diff --git a/src/util/pretty_print.rs b/src/util/pretty_print.rs index d64e8154..d78abf8a 100644 --- a/src/util/pretty_print.rs +++ b/src/util/pretty_print.rs @@ -63,10 +63,7 @@ impl<'a, A> PrettyHelper<'a> for RcDoc<'a, A> { } } -pub fn intersperse<'a>( - iter: impl Iterator>, - separator: RcDoc<'a>, -) -> RcDoc<'a> { +pub fn intersperse<'a>(iter: impl Iterator>, separator: RcDoc<'a>) -> RcDoc<'a> { RcDoc::intersperse(iter, separator) } diff --git a/src/v05/helpers.rs b/src/v05/helpers.rs index 52f1421e..9c249273 100644 --- a/src/v05/helpers.rs +++ b/src/v05/helpers.rs @@ -33,18 +33,11 @@ impl Decl { } pub fn new_array(name: &str, width: u64, depth: u64) -> Decl { - Decl::Array( - name.to_string(), - Ty::new_width(width), - Ty::new_width(depth), - ) + Decl::Array(name.to_string(), Ty::new_width(width), Ty::new_width(depth)) } pub fn new_param_uint(name: &str, value: u32) -> Decl { - Decl::Param( - name.to_string(), - Expr::new_ulit_dec(32, &value.to_string()), - ) + Decl::Param(name.to_string(), Expr::new_ulit_dec(32, &value.to_string())) } pub fn new_param_str(name: &str, value: &str) -> Decl { diff --git a/src/v05/pretty_print.rs b/src/v05/pretty_print.rs index 52be2e0c..8a35b23c 100644 --- a/src/v05/pretty_print.rs +++ b/src/v05/pretty_print.rs @@ -1,7 +1,5 @@ // use crate::util::pretty_print::{PrettyHelper, PrettyPrint, PRETTY_INDENT}; -use crate::util::pretty_print::{ - block, block_with_parens, intersperse, PrettyHelper, PrettyPrint, -}; +use crate::util::pretty_print::{block, block_with_parens, intersperse, PrettyHelper, PrettyPrint}; use crate::v05::ast::*; use pretty::RcDoc; @@ -116,9 +114,7 @@ impl PrettyPrint for Sequential { match self { // wildcard for sensitivity list Sequential::Wildcard => RcDoc::text("*"), - Sequential::Event(ty, expr) => { - ty.to_doc().append(RcDoc::space()).append(expr.to_doc()) - } + Sequential::Event(ty, expr) => ty.to_doc().append(RcDoc::space()).append(expr.to_doc()), Sequential::IfElse(ifelse) => ifelse.to_doc(), Sequential::Assign(lexpr, rexpr, ty) => lexpr .to_doc() diff --git a/src/v17/ast.rs b/src/v17/ast.rs index cfa6ee2d..340f63a3 100644 --- a/src/v17/ast.rs +++ b/src/v17/ast.rs @@ -11,8 +11,7 @@ pub type Instance = subset::ast::Instance; pub type CaseBranch = subset::ast::GenericCaseBranch; pub type CaseDefault = subset::ast::GenericCaseDefault; pub type Case = subset::ast::GenericCase; -pub type Function = - subset::ast::GenericFunction; +pub type Function = subset::ast::GenericFunction; pub type Stmt = subset::ast::GenericStmt; pub type Port = subset::ast::GenericPort; pub type Module = subset::ast::GenericModule; diff --git a/src/v17/pretty_print.rs b/src/v17/pretty_print.rs index 94431d64..23ba142f 100644 --- a/src/v17/pretty_print.rs +++ b/src/v17/pretty_print.rs @@ -1,7 +1,5 @@ use crate::subset::ast::Terop; -use crate::util::pretty_print::{ - block, block_with_parens, intersperse, PrettyHelper, PrettyPrint, -}; +use crate::util::pretty_print::{block, block_with_parens, intersperse, PrettyHelper, PrettyPrint}; use crate::v17::ast::*; use pretty::RcDoc; @@ -108,10 +106,7 @@ impl PrettyPrint for Function { let body = if self.body().is_empty() { RcDoc::nil() } else { - intersperse( - self.body().iter().map(|x| x.to_doc()), - RcDoc::hardline(), - ) + intersperse(self.body().iter().map(|x| x.to_doc()), RcDoc::hardline()) }; let args = RcDoc::space() .append(self.ret.to_doc()) @@ -200,9 +195,7 @@ impl PrettyPrint for Sequential { .append(RcDoc::text(";")), Sequential::SeqCase(case) => case.to_doc(), Sequential::Call(call) => call.to_doc().append(RcDoc::text(";")), - Sequential::Event(ty, expr) => { - ty.to_doc().append(RcDoc::space()).append(expr.to_doc()) - } + Sequential::Event(ty, expr) => ty.to_doc().append(RcDoc::space()).append(expr.to_doc()), Sequential::Assert(expr, branch) => { let cond = RcDoc::text("assert").append(expr.to_doc().parens()); if let Some(block) = branch { diff --git a/tests/v05.rs b/tests/v05.rs index 7a2defa5..9770192d 100644 --- a/tests/v05.rs +++ b/tests/v05.rs @@ -170,7 +170,7 @@ fn test_decl_array() { fn test_bit_shift_order_of_operations() { let bin1 = Expr::new_ulit_bin(4, "1000"); let bin2 = Expr::new_ulit_bin(4, "0100"); - let shift_by: i32 = 2; + let shift_by :i32 = 2; let shift = Expr::new_shift_left(bin1, shift_by); let add = Expr::new_add(bin2, shift); let exp = "4'b0100 + (4'b1000 << 2)".to_string(); @@ -196,8 +196,7 @@ fn test_event_ty_negedge() { #[test] fn test_sequential_event_posedge_clock() { - let seq = - Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); + let seq = Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); let exp = "posedge clock".to_string(); let res = seq.to_string(); check!(res, exp); @@ -293,8 +292,7 @@ end"#; fn test_attribute_decl() { let mut attr = Attribute::default(); attr.add_stmt("ram_style", "block"); - let decl = - Decl::new_attribute_decl(attr, Decl::new_reg("ram", 32)).to_string(); + let decl = Decl::new_attribute_decl(attr, Decl::new_reg("ram", 32)).to_string(); let gold = r#"(*ram_style = "block"*) reg [31:0] ram"#; check!(decl, gold); } diff --git a/tests/v17.rs b/tests/v17.rs index 3fd7fda6..905079f9 100644 --- a/tests/v17.rs +++ b/tests/v17.rs @@ -324,8 +324,7 @@ end"#; #[test] fn test_seq_event_posedge_clock() { - let event = - Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); + let event = Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); let res = event.to_string(); let exp = "posedge clock".to_string(); check!(res, exp); @@ -624,8 +623,7 @@ fn test_module_with_always_comb() { #[test] fn test_module_with_always_ff() { let exp = read_to_string("regression/v17/module_with_always_ff.v"); - let event = - Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); + let event = Sequential::Event(EventTy::Posedge, Expr::Ref("clock".to_string())); let mut always = ParallelProcess::new_always_ff(); always.add_seq(Sequential::new_display("hello sync world")); always.set_event(event); From 88e41b37073fa6ceee1e72b4365d51fc4c8c0af4 Mon Sep 17 00:00:00 2001 From: Nathaniel Navarro Date: Tue, 12 Jul 2022 11:15:39 -0400 Subject: [PATCH 4/4] Change operator precedence to nested pattern match --- src/subset/pretty_print.rs | 85 ++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/src/subset/pretty_print.rs b/src/subset/pretty_print.rs index 8f17379f..62004e78 100644 --- a/src/subset/pretty_print.rs +++ b/src/subset/pretty_print.rs @@ -52,60 +52,65 @@ impl Ord for ParenCtx { (P::Index, P::Not) => Ordering::Less, (P::Index, _) => Ordering::Greater, - (P::Mul, P::Not) | (P::Mul, P::Index) => Ordering::Less, + (P::Mul, P::Not | P::Index) => Ordering::Less, (P::Mul, _) => Ordering::Greater, - (P::AddSub, P::Not) - | (P::AddSub, P::Index) - | (P::AddSub, P::Mul) => Ordering::Less, + (P::AddSub, P::Not | P::Index | P::Mul) => Ordering::Less, (P::AddSub, _) => Ordering::Greater, - (P::Shift, P::Not) - | (P::Shift, P::Index) - | (P::Shift, P::Mul) - | (P::Shift, P::AddSub) => Ordering::Less, + (P::Shift, P::Not | P::Index | P::Mul | P::AddSub) => { + Ordering::Less + } (P::Shift, _) => Ordering::Greater, - (P::Cmp, P::Not) - | (P::Cmp, P::Index) - | (P::Cmp, P::Mul) - | (P::Cmp, P::AddSub) - | (P::Cmp, P::Shift) => Ordering::Greater, + (P::Cmp, P::Not | P::Index | P::Mul | P::AddSub | P::Shift) => { + Ordering::Greater + } (P::Cmp, _) => Ordering::Less, - (P::Equal, P::Not) - | (P::Equal, P::Index) - | (P::Equal, P::Mul) - | (P::Equal, P::AddSub) - | (P::Equal, P::Shift) - | (P::Equal, P::Cmp) => Ordering::Greater, + ( + P::Equal, + P::Not | P::Index | P::Mul | P::AddSub | P::Shift | P::Cmp, + ) => Ordering::Greater, (P::Equal, _) => Ordering::Less, - (P::BAnd, P::Not) - | (P::BAnd, P::Mul) - | (P::BAnd, P::AddSub) - | (P::BAnd, P::Shift) - | (P::BAnd, P::Cmp) - | (P::BAnd, P::Equal) => Ordering::Less, + ( + P::BAnd, + P::Not + | P::Index + | P::Mul + | P::AddSub + | P::Shift + | P::Cmp + | P::Equal, + ) => Ordering::Less, (P::BAnd, _) => Ordering::Greater, - (P::BOr, P::Not) - | (P::BOr, P::Mul) - | (P::BOr, P::AddSub) - | (P::BOr, P::Shift) - | (P::BOr, P::Cmp) - | (P::BOr, P::Equal) - | (P::BOr, P::BAnd) => Ordering::Less, + ( + P::BOr, + P::Not + | P::Index + | P::Mul + | P::AddSub + | P::Shift + | P::Cmp + | P::Equal + | P::BAnd, + ) => Ordering::Less, (P::BOr, _) => Ordering::Greater, - (P::And, P::Not) - | (P::And, P::Mul) - | (P::And, P::AddSub) - | (P::And, P::Shift) - | (P::And, P::Cmp) - | (P::And, P::Equal) - | (P::And, P::BOr) - | (P::And, P::BAnd) => Ordering::Less, + ( + P::And, + P::Not + | P::Index + | P::Mul + | P::AddSub + | P::Shift + | P::Cmp + | P::Equal + | P::BAnd + | P::BOr, + ) => Ordering::Less, (P::And, _) => Ordering::Greater, (P::Or, _) => Ordering::Less,