Commit 581a7911 by Zachary Snow

support for deferred immediate assertion statements

parent 4ded2a59
...@@ -345,10 +345,10 @@ traverseAssertionExprsM mapper = assertionMapper ...@@ -345,10 +345,10 @@ traverseAssertionExprsM mapper = assertionMapper
e' <- mapper e e' <- mapper e
pe' <- propExprMapper pe pe' <- propExprMapper pe
return $ PropertySpec ms e' pe' return $ PropertySpec ms e' pe'
assertionExprMapper (Left e) = assertionExprMapper (Concurrent e) =
propSpecMapper e >>= return . Left propSpecMapper e >>= return . Concurrent
assertionExprMapper (Right e) = assertionExprMapper (Immediate d e) =
mapper e >>= return . Right mapper e >>= return . Immediate d
assertionMapper (Assert e ab) = do assertionMapper (Assert e ab) = do
e' <- assertionExprMapper e e' <- assertionExprMapper e
return $ Assert e' ab return $ Assert e' ab
...@@ -389,10 +389,10 @@ traverseStmtLHSsM mapper = stmtMapper ...@@ -389,10 +389,10 @@ traverseStmtLHSsM mapper = stmtMapper
s2' <- senseMapper s2 s2' <- senseMapper s2
return $ SenseOr s1' s2' return $ SenseOr s1' s2'
senseMapper (SenseStar ) = return SenseStar senseMapper (SenseStar ) = return SenseStar
assertionExprMapper (Left (PropertySpec (Just sense) me pe)) = do assertionExprMapper (Concurrent (PropertySpec (Just sense) me pe)) = do
sense' <- senseMapper sense sense' <- senseMapper sense
return $ Left $ PropertySpec (Just sense') me pe return $ Concurrent $ PropertySpec (Just sense') me pe
assertionExprMapper other = return $ other assertionExprMapper other = return other
assertionMapper (Assert e ab) = do assertionMapper (Assert e ab) = do
e' <- assertionExprMapper e e' <- assertionExprMapper e
return $ Assert e' ab return $ Assert e' ab
......
...@@ -16,8 +16,9 @@ module Language.SystemVerilog.AST.Stmt ...@@ -16,8 +16,9 @@ module Language.SystemVerilog.AST.Stmt
, SeqMatchItem (..) , SeqMatchItem (..)
, SeqExpr (..) , SeqExpr (..)
, AssertionItem , AssertionItem
, AssertionExpr
, Assertion (..) , Assertion (..)
, AssertionKind(..)
, Deferral (..)
, PropertySpec (..) , PropertySpec (..)
, ViolationCheck (..) , ViolationCheck (..)
, BlockKW (..) , BlockKW (..)
...@@ -235,20 +236,34 @@ instance Show SeqExpr where ...@@ -235,20 +236,34 @@ instance Show SeqExpr where
show (SeqExprFirstMatch e a) = printf "first_match(%s, %s)" (show e) (commas $ map show a) show (SeqExprFirstMatch e a) = printf "first_match(%s, %s)" (show e) (commas $ map show a)
type AssertionItem = (Identifier, Assertion) type AssertionItem = (Identifier, Assertion)
type AssertionExpr = Either PropertySpec Expr
data Assertion data Assertion
= Assert AssertionExpr ActionBlock = Assert AssertionKind ActionBlock
| Assume AssertionExpr ActionBlock | Assume AssertionKind ActionBlock
| Cover AssertionExpr Stmt | Cover AssertionKind Stmt
deriving Eq deriving Eq
instance Show Assertion where instance Show Assertion where
show (Assert e a) = printf "assert %s%s" (showAssertionExpr e) (show a) show (Assert k a) = printf "assert %s%s" (show k) (show a)
show (Assume e a) = printf "assume %s%s" (showAssertionExpr e) (show a) show (Assume k a) = printf "assume %s%s" (show k) (show a)
show (Cover e a) = printf "cover %s%s" (showAssertionExpr e) (show a) show (Cover k a) = printf "cover %s%s" (show k) (show a)
data AssertionKind
= Concurrent PropertySpec
| Immediate Deferral Expr
deriving Eq
instance Show AssertionKind where
show (Concurrent e) = printf "property (%s\n)" (show e)
show (Immediate d e) = printf "%s(%s)" (showPad d) (show e)
showAssertionExpr :: AssertionExpr -> String data Deferral
showAssertionExpr (Left e) = printf "property (%s\n)" (show e) = NotDeferred
showAssertionExpr (Right e) = printf "(%s)" (show e) | ObservedDeferred
| FinalDeferred
deriving Eq
instance Show Deferral where
show NotDeferred = ""
show ObservedDeferred = "#0"
show FinalDeferred = "final"
data PropertySpec data PropertySpec
= PropertySpec (Maybe Sense) Expr PropExpr = PropertySpec (Maybe Sense) Expr PropExpr
......
...@@ -733,16 +733,18 @@ ConcurrentAssertionItem :: { AssertionItem } ...@@ -733,16 +733,18 @@ ConcurrentAssertionItem :: { AssertionItem }
: Identifier ":" ConcurrentAssertionStatement { ($1, $3) } : Identifier ":" ConcurrentAssertionStatement { ($1, $3) }
| ConcurrentAssertionStatement { ("", $1) } | ConcurrentAssertionStatement { ("", $1) }
ConcurrentAssertionStatement :: { Assertion } ConcurrentAssertionStatement :: { Assertion }
: "assert" "property" "(" PropertySpec ")" ActionBlock { Assert (Left $4) $6 } : "assert" "property" "(" PropertySpec ")" ActionBlock { Assert (Concurrent $4) $6 }
| "assume" "property" "(" PropertySpec ")" ActionBlock { Assume (Left $4) $6 } | "assume" "property" "(" PropertySpec ")" ActionBlock { Assume (Concurrent $4) $6 }
| "cover" "property" "(" PropertySpec ")" Stmt { Cover (Left $4) $6 } | "cover" "property" "(" PropertySpec ")" Stmt { Cover (Concurrent $4) $6 }
ImmediateAssertionStatement :: { Assertion } ImmediateAssertionStatement :: { Assertion }
: SimpleImmediateAssertionStatement { $1 } : "assert" Deferral "(" Expr ")" ActionBlock { Assert (Immediate $2 $4) $6 }
SimpleImmediateAssertionStatement :: { Assertion } | "assume" Deferral "(" Expr ")" ActionBlock { Assume (Immediate $2 $4) $6 }
: "assert" "(" Expr ")" ActionBlock { Assert (Right $3) $5 } | "cover" Deferral "(" Expr ")" Stmt { Cover (Immediate $2 $4) $6 }
| "assume" "(" Expr ")" ActionBlock { Assume (Right $3) $5 } Deferral :: { Deferral }
| "cover" "(" Expr ")" Stmt { Cover (Right $3) $5 } : {- empty -} { NotDeferred }
| "#" number {% expectZeroDelay $2 ObservedDeferred }
| "final" { FinalDeferred }
PropertySpec :: { PropertySpec } PropertySpec :: { PropertySpec }
: opt(ClockingEvent) "disable" "iff" "(" Expr ")" PropExpr { PropertySpec $1 $5 $7 } : opt(ClockingEvent) "disable" "iff" "(" Expr ")" PropExpr { PropertySpec $1 $5 $7 }
...@@ -1682,4 +1684,12 @@ readNumber pos str = do ...@@ -1682,4 +1684,12 @@ readNumber pos str = do
hPutStrLn stderr $ show pos ++ ": Warning: " ++ msg hPutStrLn stderr $ show pos ++ ": Warning: " ++ msg
return num return num
expectZeroDelay :: Token -> a -> ParseState a
expectZeroDelay tok a = do
num <- readNumber pos str
case num of
Decimal (-32) True 0 -> return a
_ -> parseError pos $ "expected 0 after #, but found " ++ str
where Token { tokenString = str, tokenPosition = pos } = tok
} }
// pattern: assert_deferred_nonzero.sv:3:21: Parse error: expected 0 after #, but found 1
module top;
initial assert #1 (1);
endmodule
...@@ -12,7 +12,15 @@ module top; ...@@ -12,7 +12,15 @@ module top;
assert (1); assert (1);
assume (1); assume (1);
cover (1); cover (1);
assume (1); assert #0 (1);
assume #0 (1);
cover #0 (1);
assert #0_0 (1);
assume #0_0 (1);
cover #0_0 (1);
assert final (1);
assume final (1);
cover final (1);
end end
assert property (@(posedge clk) 1) assert property (@(posedge clk) 1)
else $display("FOO"); else $display("FOO");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment