Skip to content

Commit

Permalink
parser support for not, strong, weak, nexttime, and s_nexttime
Browse files Browse the repository at this point in the history
  • Loading branch information
zachjs committed Jun 18, 2024
1 parent 636130f commit 1c90277
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased

### New Features

* Added parsing support for `not`, `strong`, `weak`, `nexttime`, and
`s_nexttime` in assertion property expressions

### Bug Fixes

* Fixed `--write path/to/dir/` with directives like `` `default_nettype ``
Expand Down
11 changes: 11 additions & 0 deletions src/Convert/Traverse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ module Convert.Traverse
) where

import Data.Bitraversable (bimapM)
import Data.Functor ((<&>))
import Data.Functor.Identity (Identity, runIdentity)
import Control.Monad ((>=>))
import Control.Monad.Writer.Strict
Expand Down Expand Up @@ -344,6 +345,16 @@ traversePropExprExprsM mapper (PropExprIff p1 p2) = do
p1' <- traversePropExprExprsM mapper p1
p2' <- traversePropExprExprsM mapper p2
return $ PropExprIff p1' p2'
traversePropExprExprsM mapper (PropExprNeg pe) =
traversePropExprExprsM mapper pe <&> PropExprNeg
traversePropExprExprsM mapper (PropExprStrong se) =
traverseSeqExprExprsM mapper se <&> PropExprStrong
traversePropExprExprsM mapper (PropExprWeak se) =
traverseSeqExprExprsM mapper se <&> PropExprWeak
traversePropExprExprsM mapper (PropExprNextTime strong index prop) = do
index' <- mapper index
prop' <- traversePropExprExprsM mapper prop
return $ PropExprNextTime strong index' prop'

seqExprHelper :: Monad m => MapperM m Expr
-> (SeqExpr -> SeqExpr -> SeqExpr)
Expand Down
12 changes: 12 additions & 0 deletions src/Language/SystemVerilog/AST/Stmt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ data PropExpr
| PropExprFollowsO SeqExpr PropExpr
| PropExprFollowsNO SeqExpr PropExpr
| PropExprIff PropExpr PropExpr
| PropExprNeg PropExpr
| PropExprStrong SeqExpr
| PropExprWeak SeqExpr
| PropExprNextTime Bool Expr PropExpr
deriving Eq
instance Show PropExpr where
show (PropExpr se) = show se
Expand All @@ -243,6 +247,14 @@ instance Show PropExpr where
show (PropExprFollowsO a b) = printf "(%s #-# %s)" (show a) (show b)
show (PropExprFollowsNO a b) = printf "(%s #=# %s)" (show a) (show b)
show (PropExprIff a b) = printf "(%s iff %s)" (show a) (show b)
show (PropExprNeg pe) = printf "not (%s)" (show pe)
show (PropExprStrong se) = printf "strong (%s)" (show se)
show (PropExprWeak se) = printf "weak (%s)" (show se)
show (PropExprNextTime strong index prop) =
printf "%s%s (%s)" kwStr indexStr (show prop)
where
kwStr = (if strong then "s_" else "") ++ "nexttime"
indexStr = if index == Nil then "" else printf " [%s]" (show index)
data SeqMatchItem
= SeqMatchAsgn (LHS, AsgnOp, Expr)
| SeqMatchCall Identifier Args
Expand Down
8 changes: 8 additions & 0 deletions src/Language/SystemVerilog/Parser/Parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ time { Token Lit_time _ _ }
%right "iff"
%left "or" ","
%left "and"
%nonassoc "not" "nexttime" "s_nexttime"
%left "intersect"
%left "within"
%right "throughout"
Expand Down Expand Up @@ -794,6 +795,13 @@ PropExprParens :: { PropExpr }
| SeqExpr "#-#" PropExpr { PropExprFollowsO $1 $3 }
| SeqExpr "#=#" PropExpr { PropExprFollowsNO $1 $3 }
| PropExpr "iff" PropExpr { PropExprIff $1 $3 }
| "not" PropExpr { PropExprNeg $2 }
| "strong" "(" SeqExpr ")" { PropExprStrong $3 }
| "weak" "(" SeqExpr ")" { PropExprWeak $3 }
| "nexttime" PropExpr { PropExprNextTime False Nil $2 }
| "nexttime" "[" Expr "]" PropExpr { PropExprNextTime False $3 $5 }
| "s_nexttime" PropExpr { PropExprNextTime True Nil $2 }
| "s_nexttime" "[" Expr "]" PropExpr { PropExprNextTime True $3 $5 }
SeqExpr :: { SeqExpr }
: Expr { SeqExpr $1 }
| SeqExprParens { $1 }
Expand Down
5 changes: 5 additions & 0 deletions test/nosim/assert.sv
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ module top;
(1 |-> (1 |=> (1 #-# (1 #=# (1 iff 1))))));
assert property (@(posedge clk)
1 and 1 or 1 intersect 1 throughout 1 within 1);
assert property (@(posedge clk) not (strong(1) iff weak(1)));
assert property (@(posedge clk) nexttime (1 iff 1));
assert property (@(posedge clk) nexttime [0] (1 iff 1));
assert property (@(posedge clk) s_nexttime (1 iff 1));
assert property (@(posedge clk) s_nexttime [0] (1 iff 1));
assert property (@(posedge clk) 1 ##1 1);
assert property (@(posedge clk) ##1 1);
localparam C = 1;
Expand Down

0 comments on commit 1c90277

Please sign in to comment.