Commit f68bf187 by Zachary Snow

refactor event control internals

- event expressions use Expr over LHS
- stricter AST representation of event controls
- property specs use event expressions directly
parent abbcaae0
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
* Added support for excluding the conversion of unbased unsized literals (e.g., * Added support for excluding the conversion of unbased unsized literals (e.g.,
`'1`, `'x`) via `--exclude UnbasedUniszed` `'1`, `'x`) via `--exclude UnbasedUniszed`
* Added support for enumerated type ranges (e.g., `enum { X[3:5] }`) * Added support for enumerated type ranges (e.g., `enum { X[3:5] }`)
* Added support for complex event expressions (e.g., `@(x ^ y)`)
* Added support for the SystemVerilog `edge` event * Added support for the SystemVerilog `edge` event
* Added support for cycle delay ranges in assertion sequence expressions * Added support for cycle delay ranges in assertion sequence expressions
* Added conversion for `do` `while` loops * Added conversion for `do` `while` loops
......
...@@ -21,6 +21,7 @@ import qualified Convert.DoWhile ...@@ -21,6 +21,7 @@ import qualified Convert.DoWhile
import qualified Convert.DuplicateGenvar import qualified Convert.DuplicateGenvar
import qualified Convert.EmptyArgs import qualified Convert.EmptyArgs
import qualified Convert.Enum import qualified Convert.Enum
import qualified Convert.EventEdge
import qualified Convert.ExprAsgn import qualified Convert.ExprAsgn
import qualified Convert.ForAsgn import qualified Convert.ForAsgn
import qualified Convert.Foreach import qualified Convert.Foreach
...@@ -43,7 +44,6 @@ import qualified Convert.ParamType ...@@ -43,7 +44,6 @@ import qualified Convert.ParamType
import qualified Convert.PortDecl import qualified Convert.PortDecl
import qualified Convert.RemoveComments import qualified Convert.RemoveComments
import qualified Convert.ResolveBindings import qualified Convert.ResolveBindings
import qualified Convert.SenseEdge
import qualified Convert.Simplify import qualified Convert.Simplify
import qualified Convert.Stream import qualified Convert.Stream
import qualified Convert.StringParam import qualified Convert.StringParam
...@@ -105,7 +105,7 @@ initialPhases selectExclude = ...@@ -105,7 +105,7 @@ initialPhases selectExclude =
, Convert.ExprAsgn.convert , Convert.ExprAsgn.convert
, Convert.KWArgs.convert , Convert.KWArgs.convert
, Convert.Unique.convert , Convert.Unique.convert
, Convert.SenseEdge.convert , Convert.EventEdge.convert
, Convert.LogOp.convert , Convert.LogOp.convert
, Convert.EmptyArgs.convert , Convert.EmptyArgs.convert
, Convert.DoWhile.convert , Convert.DoWhile.convert
......
...@@ -18,9 +18,9 @@ convert = map $ traverseDescriptions $ traverseModuleItems replaceAlwaysKW ...@@ -18,9 +18,9 @@ convert = map $ traverseDescriptions $ traverseModuleItems replaceAlwaysKW
replaceAlwaysKW :: ModuleItem -> ModuleItem replaceAlwaysKW :: ModuleItem -> ModuleItem
replaceAlwaysKW (AlwaysC AlwaysLatch stmt) = replaceAlwaysKW (AlwaysC AlwaysLatch stmt) =
AlwaysC Always $ Timing (Event SenseStar) stmt AlwaysC Always $ Timing (Event EventStar) stmt
replaceAlwaysKW (AlwaysC AlwaysComb stmt) = replaceAlwaysKW (AlwaysC AlwaysComb stmt) =
AlwaysC Always $ Timing (Event SenseStar) stmt AlwaysC Always $ Timing (Event EventStar) stmt
replaceAlwaysKW (AlwaysC AlwaysFF stmt) = replaceAlwaysKW (AlwaysC AlwaysFF stmt) =
AlwaysC Always stmt AlwaysC Always stmt
replaceAlwaysKW other = other replaceAlwaysKW other = other
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
- or fully supported downstream. - or fully supported downstream.
-} -}
module Convert.SenseEdge (convert) where module Convert.EventEdge (convert) where
import Convert.Traverse import Convert.Traverse
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
...@@ -26,12 +26,16 @@ convertStmt (Timing timing stmt) = ...@@ -26,12 +26,16 @@ convertStmt (Timing timing stmt) =
convertStmt other = other convertStmt other = other
convertTiming :: Timing -> Timing convertTiming :: Timing -> Timing
convertTiming (Event sense) = Event $ convertSense sense convertTiming (Event event) = Event $ convertEvent event
convertTiming other = other convertTiming other = other
convertSense :: Sense -> Sense convertEvent :: Event -> Event
convertSense (SenseOr s1 s2) = convertEvent EventStar = EventStar
SenseOr (convertSense s1) (convertSense s2) convertEvent (EventExpr e) = EventExpr $ convertEventExpr e
convertSense (SenseEdge lhs) =
SenseOr (SensePosedge lhs) (SenseNegedge lhs) convertEventExpr :: EventExpr -> EventExpr
convertSense other = other convertEventExpr (EventExprOr v1 v2) =
EventExprOr (convertEventExpr v1) (convertEventExpr v2)
convertEventExpr (EventExprEdge Edge lhs) =
EventExprOr (EventExprEdge Posedge lhs) (EventExprEdge Negedge lhs)
convertEventExpr other@EventExprEdge{} = other
...@@ -94,7 +94,7 @@ traverseModuleItem ports scopes = ...@@ -94,7 +94,7 @@ traverseModuleItem ports scopes =
Just (_, _, t) -> tell [isRegType t] Just (_, _, t) -> tell [isRegType t]
_ -> tell [False] _ -> tell [False]
always_comb = AlwaysC Always . Timing (Event SenseStar) always_comb = AlwaysC Always . Timing (Event EventStar)
fixModuleItem :: ModuleItem -> ModuleItem fixModuleItem :: ModuleItem -> ModuleItem
-- rewrite bad continuous assignments to use procedural assignments -- rewrite bad continuous assignments to use procedural assignments
...@@ -183,9 +183,6 @@ rewriteDeclM _ (Param s (IntegerVector _ sg rs) x e) = ...@@ -183,9 +183,6 @@ rewriteDeclM _ (Param s (IntegerVector _ sg rs) x e) =
rewriteDeclM _ decl = return decl rewriteDeclM _ decl = return decl
traverseStmtM :: Stmt -> ST Stmt traverseStmtM :: Stmt -> ST Stmt
traverseStmtM stmt@Timing{} =
-- ignore the timing LHSs
return stmt
traverseStmtM (Asgn op Just{} lhs expr) = traverseStmtM (Asgn op Just{} lhs expr) =
-- ignore the timing LHSs -- ignore the timing LHSs
traverseStmtM $ Asgn op Nothing lhs expr traverseStmtM $ Asgn op Nothing lhs expr
......
...@@ -343,10 +343,11 @@ traverseAssertionExprsM mapper = assertionMapper ...@@ -343,10 +343,11 @@ traverseAssertionExprsM mapper = assertionMapper
spMapper PropExprFollowsNO se pe spMapper PropExprFollowsNO se pe
propExprMapper (PropExprIff p1 p2) = propExprMapper (PropExprIff p1 p2) =
ppMapper PropExprIff p1 p2 ppMapper PropExprIff p1 p2
propSpecMapper (PropertySpec ms e pe) = do propSpecMapper (PropertySpec mv e pe) = do
mv' <- mapM (traverseEventExprsM mapper) mv
e' <- mapper e e' <- mapper e
pe' <- propExprMapper pe pe' <- propExprMapper pe
return $ PropertySpec ms e' pe' return $ PropertySpec mv' e' pe'
assertionExprMapper (Concurrent e) = assertionExprMapper (Concurrent e) =
propSpecMapper e >>= return . Concurrent propSpecMapper e >>= return . Concurrent
assertionExprMapper (Immediate d e) = assertionExprMapper (Immediate d e) =
...@@ -365,13 +366,6 @@ traverseStmtLHSsM :: Monad m => MapperM m LHS -> MapperM m Stmt ...@@ -365,13 +366,6 @@ traverseStmtLHSsM :: Monad m => MapperM m LHS -> MapperM m Stmt
traverseStmtLHSsM mapper = stmtMapper traverseStmtLHSsM mapper = stmtMapper
where where
fullMapper = mapper fullMapper = mapper
stmtMapper (Timing (Event sense) stmt) = do
sense' <- senseMapper sense
return $ Timing (Event sense') stmt
stmtMapper (Asgn op (Just (Event sense)) lhs expr) = do
lhs' <- fullMapper lhs
sense' <- senseMapper sense
return $ Asgn op (Just $ Event sense') lhs' expr
stmtMapper (Asgn op mt lhs expr) = stmtMapper (Asgn op mt lhs expr) =
fullMapper lhs >>= \lhs' -> return $ Asgn op mt lhs' expr fullMapper lhs >>= \lhs' -> return $ Asgn op mt lhs' expr
stmtMapper (For inits me incrs stmt) = do stmtMapper (For inits me incrs stmt) = do
...@@ -380,31 +374,7 @@ traverseStmtLHSsM mapper = stmtMapper ...@@ -380,31 +374,7 @@ traverseStmtLHSsM mapper = stmtMapper
lhss' <- mapM fullMapper lhss lhss' <- mapM fullMapper lhss
let incrs' = zip3 lhss' asgnOps exprs let incrs' = zip3 lhss' asgnOps exprs
return $ For inits' me incrs' stmt return $ For inits' me incrs' stmt
stmtMapper (Assertion a) =
assertionMapper a >>= return . Assertion
stmtMapper other = return other stmtMapper other = return other
senseMapper (Sense lhs) = fullMapper lhs >>= return . Sense
senseMapper (SensePosedge lhs) = fullMapper lhs >>= return . SensePosedge
senseMapper (SenseNegedge lhs) = fullMapper lhs >>= return . SenseNegedge
senseMapper (SenseEdge lhs) = fullMapper lhs >>= return . SenseEdge
senseMapper (SenseOr s1 s2) = do
s1' <- senseMapper s1
s2' <- senseMapper s2
return $ SenseOr s1' s2'
senseMapper (SenseStar ) = return SenseStar
assertionExprMapper (Concurrent (PropertySpec (Just sense) me pe)) = do
sense' <- senseMapper sense
return $ Concurrent $ PropertySpec (Just sense') me pe
assertionExprMapper other = return other
assertionMapper (Assert e ab) = do
e' <- assertionExprMapper e
return $ Assert e' ab
assertionMapper (Assume e ab) = do
e' <- assertionExprMapper e
return $ Assume e' ab
assertionMapper (Cover e stmt) = do
e' <- assertionExprMapper e
return $ Cover e' stmt
traverseStmtLHSs :: Mapper LHS -> Mapper Stmt traverseStmtLHSs :: Mapper LHS -> Mapper Stmt
traverseStmtLHSs = unmonad traverseStmtLHSsM traverseStmtLHSs = unmonad traverseStmtLHSsM
...@@ -672,7 +642,6 @@ traverseStmtExprsM exprMapper = flatStmtMapper ...@@ -672,7 +642,6 @@ traverseStmtExprsM exprMapper = flatStmtMapper
caseMapper (exprs, stmt) = do caseMapper (exprs, stmt) = do
exprs' <- mapM exprMapper exprs exprs' <- mapM exprMapper exprs
return (exprs', stmt) return (exprs', stmt)
stmtMapper = traverseNestedStmtsM flatStmtMapper
flatStmtMapper (StmtAttr attr stmt) = flatStmtMapper (StmtAttr attr stmt) =
-- note: we exclude expressions in attributes from conversion -- note: we exclude expressions in attributes from conversion
return $ StmtAttr attr stmt return $ StmtAttr attr stmt
...@@ -702,7 +671,8 @@ traverseStmtExprsM exprMapper = flatStmtMapper ...@@ -702,7 +671,8 @@ traverseStmtExprsM exprMapper = flatStmtMapper
flatStmtMapper (Foreach x vars stmt) = return $ Foreach x vars stmt flatStmtMapper (Foreach x vars stmt) = return $ Foreach x vars stmt
flatStmtMapper (If u cc s1 s2) = flatStmtMapper (If u cc s1 s2) =
exprMapper cc >>= \cc' -> return $ If u cc' s1 s2 exprMapper cc >>= \cc' -> return $ If u cc' s1 s2
flatStmtMapper (Timing event stmt) = return $ Timing event stmt flatStmtMapper (Timing timing stmt) =
timingMapper timing >>= \timing' -> return $ Timing timing' stmt
flatStmtMapper (Subroutine e (Args l p)) = do flatStmtMapper (Subroutine e (Args l p)) = do
e' <- exprMapper e e' <- exprMapper e
l' <- mapM exprMapper l l' <- mapM exprMapper l
...@@ -712,10 +682,8 @@ traverseStmtExprsM exprMapper = flatStmtMapper ...@@ -712,10 +682,8 @@ traverseStmtExprsM exprMapper = flatStmtMapper
flatStmtMapper (Return expr) = flatStmtMapper (Return expr) =
exprMapper expr >>= return . Return exprMapper expr >>= return . Return
flatStmtMapper (Trigger blocks x) = return $ Trigger blocks x flatStmtMapper (Trigger blocks x) = return $ Trigger blocks x
flatStmtMapper (Assertion a) = do flatStmtMapper (Assertion a) =
a' <- traverseAssertionStmtsM stmtMapper a traverseAssertionExprsM exprMapper a >>= return . Assertion
a'' <- traverseAssertionExprsM exprMapper a'
return $ Assertion a''
flatStmtMapper (Continue) = return Continue flatStmtMapper (Continue) = return Continue
flatStmtMapper (Break) = return Break flatStmtMapper (Break) = return Break
flatStmtMapper (Null) = return Null flatStmtMapper (Null) = return Null
...@@ -723,6 +691,22 @@ traverseStmtExprsM exprMapper = flatStmtMapper ...@@ -723,6 +691,22 @@ traverseStmtExprsM exprMapper = flatStmtMapper
asgnMapper (l, op, e) = exprMapper e >>= \e' -> return $ (l, op, e') asgnMapper (l, op, e) = exprMapper e >>= \e' -> return $ (l, op, e')
timingMapper (Event e) = eventMapper e >>= return . Event
timingMapper (Delay e) = exprMapper e >>= return . Delay
timingMapper (Cycle e) = exprMapper e >>= return . Cycle
eventMapper EventStar = return EventStar
eventMapper (EventExpr e) =
traverseEventExprsM exprMapper e >>= return . EventExpr
traverseEventExprsM :: Monad m => MapperM m Expr -> MapperM m EventExpr
traverseEventExprsM mapper (EventExprEdge edge expr) =
mapper expr >>= return . EventExprEdge edge
traverseEventExprsM mapper (EventExprOr e1 e2) = do
e1' <- traverseEventExprsM mapper e1
e2' <- traverseEventExprsM mapper e2
return $ EventExprOr e1' e2'
traverseStmtExprs :: Mapper Expr -> Mapper Stmt traverseStmtExprs :: Mapper Expr -> Mapper Stmt
traverseStmtExprs = unmonad traverseStmtExprsM traverseStmtExprs = unmonad traverseStmtExprsM
collectStmtExprsM :: Monad m => CollectorM m Expr -> CollectorM m Stmt collectStmtExprsM :: Monad m => CollectorM m Expr -> CollectorM m Stmt
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
module Language.SystemVerilog.AST.Stmt module Language.SystemVerilog.AST.Stmt
( Stmt (..) ( Stmt (..)
, Timing (..) , Timing (..)
, Sense (..) , Event (..)
, EventExpr (..)
, Edge (..)
, CaseKW (..) , CaseKW (..)
, Case , Case
, ActionBlock (..) , ActionBlock (..)
...@@ -160,32 +162,46 @@ instance Show CaseKW where ...@@ -160,32 +162,46 @@ instance Show CaseKW where
type Case = ([Expr], Stmt) type Case = ([Expr], Stmt)
data Timing data Timing
= Event Sense = Event Event
| Delay Expr | Delay Expr
| Cycle Expr | Cycle Expr
deriving Eq deriving Eq
instance Show Timing where instance Show Timing where
show (Event s) = printf "@(%s)" (show s) show (Event e) = printf "@(%s)" (show e)
show (Delay e) = printf "#(%s)" (show e) show (Delay e) = printf "#(%s)" (show e)
show (Cycle e) = printf "##(%s)" (show e) show (Cycle e) = printf "##(%s)" (show e)
data Sense data Event
= Sense LHS = EventStar
| SenseOr Sense Sense | EventExpr EventExpr
| SensePosedge LHS
| SenseNegedge LHS
| SenseEdge LHS
| SenseStar
deriving Eq deriving Eq
instance Show Sense where instance Show Event where
show (Sense a ) = show a show EventStar = "*"
show (SenseOr a b) = printf "%s or %s" (show a) (show b) show (EventExpr e) = show e
show (SensePosedge a ) = printf "posedge %s" (show a)
show (SenseNegedge a ) = printf "negedge %s" (show a) data EventExpr
show (SenseEdge a ) = printf "edge %s" (show a) = EventExprEdge Edge Expr
show (SenseStar ) = "*" | EventExprOr EventExpr EventExpr
deriving Eq
instance Show EventExpr where
show (EventExprEdge g e) = printf "%s%s" (showPad g) (show e)
show (EventExprOr a b) = printf "%s or %s" (show a) (show b)
data Edge
= Posedge
| Negedge
| Edge
| NoEdge
deriving Eq
instance Show Edge where
show Posedge = "posedge"
show Negedge = "negedge"
show Edge = "edge"
show NoEdge = ""
data ActionBlock data ActionBlock
= ActionBlock Stmt Stmt = ActionBlock Stmt Stmt
...@@ -273,15 +289,15 @@ instance Show Deferral where ...@@ -273,15 +289,15 @@ instance Show Deferral where
show FinalDeferred = "final" show FinalDeferred = "final"
data PropertySpec data PropertySpec
= PropertySpec (Maybe Sense) Expr PropExpr = PropertySpec (Maybe EventExpr) Expr PropExpr
deriving Eq deriving Eq
instance Show PropertySpec where instance Show PropertySpec where
show (PropertySpec ms e pe) = show (PropertySpec mv e pe) =
printf "%s%s\n\t%s" msStr eStr (show pe) printf "%s%s\n\t%s" mvStr eStr (show pe)
where where
msStr = case ms of mvStr = case mv of
Nothing -> "" Nothing -> ""
Just s -> printf "@(%s) " (show s) Just v -> printf "@(%s) " (show v)
eStr = case e of eStr = case e of
Nil -> "" Nil -> ""
_ -> printf "disable iff (%s)" (show e) _ -> printf "disable iff (%s)" (show e)
......
...@@ -406,7 +406,7 @@ time { Token Lit_time _ _ } ...@@ -406,7 +406,7 @@ time { Token Lit_time _ _ }
%nonassoc "else" %nonassoc "else"
%right "|->" "|=>" "#-#" "#=#" %right "|->" "|=>" "#-#" "#=#"
%right "iff" %right "iff"
%left "or" %left "or" ","
%left "and" %left "and"
%left "intersect" %left "intersect"
%left "within" %left "within"
...@@ -766,7 +766,7 @@ Deferral :: { Deferral } ...@@ -766,7 +766,7 @@ Deferral :: { Deferral }
PropertySpec :: { PropertySpec } PropertySpec :: { PropertySpec }
: OptClockingEvent "disable" "iff" "(" Expr ")" PropExpr { PropertySpec $1 $5 $7 } : OptClockingEvent "disable" "iff" "(" Expr ")" PropExpr { PropertySpec $1 $5 $7 }
| OptClockingEvent PropExpr { PropertySpec $1 Nil $2 } | OptClockingEvent PropExpr { PropertySpec $1 Nil $2 }
OptClockingEvent :: { Maybe Sense } OptClockingEvent :: { Maybe EventExpr }
: ClockingEvent { Just $1 } : ClockingEvent { Just $1 }
| {- empty -} { Nothing } | {- empty -} { Nothing }
...@@ -1208,8 +1208,8 @@ TypeAsgn :: { (Identifier, Type) } ...@@ -1208,8 +1208,8 @@ TypeAsgn :: { (Identifier, Type) }
| Identifier { ($1, UnknownType) } | Identifier { ($1, UnknownType) }
-- TODO: This does not allow for @identifier -- TODO: This does not allow for @identifier
ClockingEvent :: { Sense } ClockingEvent :: { EventExpr }
: "@" "(" Senses ")" { $3 } : "@" "(" EventExpr ")" { $3 }
TimingControl :: { Timing } TimingControl :: { Timing }
: DelayOrEvent { $1 } : DelayOrEvent { $1 }
...@@ -1228,28 +1228,27 @@ DelayControl :: { Expr } ...@@ -1228,28 +1228,27 @@ DelayControl :: { Expr }
| "#" Identifier ParamBindings "::" Identifier { CSIdent $2 $3 $5 } | "#" Identifier ParamBindings "::" Identifier { CSIdent $2 $3 $5 }
CycleDelay :: { Expr } CycleDelay :: { Expr }
: "##" Expr { $2 } : "##" Expr { $2 }
EventControl :: { Sense } EventControl :: { Event }
: "@" "(" Senses ")" { $3 } : "@*" { EventStar }
| "@" "(*)" { SenseStar } | "@" "(*)" { EventStar }
| "@" "(" "*" ")" { SenseStar } | "@" "(" "*" ")" { EventStar }
| "@" "(*" ")" { SenseStar } | "@" "(*" ")" { EventStar }
| "@" "(" "*)" { SenseStar } | "@" "(" "*)" { EventStar }
| "@" "*" { SenseStar } | "@" "*" { EventStar }
| "@*" { SenseStar } | "@" "(" EventExpr ")" { EventExpr $3 }
| "@" Identifier { Sense $ LHSIdent $2 } | "@" Identifier { EventExpr $ EventExprEdge NoEdge $ Ident $2 }
Senses :: { Sense } EventExpr :: { EventExpr }
: Sense { $1 } : Expr { EventExprEdge NoEdge $1 }
| Senses "or" Sense { SenseOr $1 $3 } | EventExprComplex { $1 }
| Senses "," Sense { SenseOr $1 $3 } EventExprComplex :: { EventExpr }
Sense :: { Sense } : "(" EventExprComplex ")" { $2 }
: "(" Sense ")" { $2 } | Edge Expr { EventExprEdge $1 $2 }
| LHS { Sense $1 } | EventExpr "or" EventExpr { EventExprOr $1 $3 }
| "posedge" LHSOptParen { SensePosedge $2 } | EventExpr "," EventExpr { EventExprOr $1 $3 }
| "negedge" LHSOptParen { SenseNegedge $2 } Edge :: { Edge }
| "edge" LHSOptParen { SenseEdge $2 } : "posedge" { Posedge }
LHSOptParen :: { LHS } | "negedge" { Negedge }
: LHS { $1 } | "edge" { Edge }
| "(" LHS ")" { $2 }
CaseKW :: { CaseKW } CaseKW :: { CaseKW }
: "case" { CaseN } : "case" { CaseN }
......
...@@ -72,6 +72,7 @@ executable sv2v ...@@ -72,6 +72,7 @@ executable sv2v
Convert.DuplicateGenvar Convert.DuplicateGenvar
Convert.EmptyArgs Convert.EmptyArgs
Convert.Enum Convert.Enum
Convert.EventEdge
Convert.ExprAsgn Convert.ExprAsgn
Convert.ExprUtils Convert.ExprUtils
Convert.ForAsgn Convert.ForAsgn
...@@ -96,7 +97,6 @@ executable sv2v ...@@ -96,7 +97,6 @@ executable sv2v
Convert.RemoveComments Convert.RemoveComments
Convert.ResolveBindings Convert.ResolveBindings
Convert.Scoper Convert.Scoper
Convert.SenseEdge
Convert.Simplify Convert.Simplify
Convert.Stream Convert.Stream
Convert.StringParam Convert.StringParam
......
module top;
reg x, y;
always @(x ^ y)
$display("%d %b %b", $time, x, y);
initial begin
#1 {x, y} = 2'b00;
#1 {x, y} = 2'b01;
#1 {x, y} = 2'b10;
#1 {x, y} = 2'b11;
#1 {x, y} = 2'b00;
#1 {x, y} = 2'b10;
end
endmodule
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