Commit e6e96b62 by Zachary Snow

support for edge event

parent 53fa152f
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,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 the SystemVerilog `edge` event
* Added support for passing through DPI imports and exports * Added support for passing through DPI imports and exports
* Added support for passing through functions with output ports * Added support for passing through functions with output ports
......
...@@ -41,6 +41,7 @@ import qualified Convert.ParamType ...@@ -41,6 +41,7 @@ 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
...@@ -101,6 +102,7 @@ initialPhases selectExclude = ...@@ -101,6 +102,7 @@ initialPhases selectExclude =
, Convert.Jump.convert , Convert.Jump.convert
, Convert.KWArgs.convert , Convert.KWArgs.convert
, Convert.Unique.convert , Convert.Unique.convert
, Convert.SenseEdge.convert
, Convert.LogOp.convert , Convert.LogOp.convert
, Convert.EmptyArgs.convert , Convert.EmptyArgs.convert
, Convert.Foreach.convert , Convert.Foreach.convert
......
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
- Conversion for `edge` sensitivity
-
- IEEE 1800-2017 Section 9.4.2 defines `edge` as either `posedge` or `negedge`.
- This does not convert senses in assertions as they are likely either removed
- or fully supported downstream.
-}
module Convert.SenseEdge (convert) where
import Convert.Traverse
import Language.SystemVerilog.AST
convert :: [AST] -> [AST]
convert =
map $ traverseDescriptions $ traverseModuleItems $ traverseStmts $
traverseNestedStmts convertStmt
convertStmt :: Stmt -> Stmt
convertStmt (Asgn op (Just timing) lhs expr) =
Asgn op (Just $ convertTiming timing) lhs expr
convertStmt (Timing timing stmt) =
Timing (convertTiming timing) stmt
convertStmt other = other
convertTiming :: Timing -> Timing
convertTiming (Event sense) = Event $ convertSense sense
convertTiming other = other
convertSense :: Sense -> Sense
convertSense (SenseOr s1 s2) =
SenseOr (convertSense s1) (convertSense s2)
convertSense (SenseEdge lhs) =
SenseOr (SensePosedge lhs) (SenseNegedge lhs)
convertSense other = other
...@@ -386,6 +386,7 @@ traverseStmtLHSsM mapper = stmtMapper ...@@ -386,6 +386,7 @@ traverseStmtLHSsM mapper = stmtMapper
senseMapper (Sense lhs) = fullMapper lhs >>= return . Sense senseMapper (Sense lhs) = fullMapper lhs >>= return . Sense
senseMapper (SensePosedge lhs) = fullMapper lhs >>= return . SensePosedge senseMapper (SensePosedge lhs) = fullMapper lhs >>= return . SensePosedge
senseMapper (SenseNegedge lhs) = fullMapper lhs >>= return . SenseNegedge senseMapper (SenseNegedge lhs) = fullMapper lhs >>= return . SenseNegedge
senseMapper (SenseEdge lhs) = fullMapper lhs >>= return . SenseEdge
senseMapper (SenseOr s1 s2) = do senseMapper (SenseOr s1 s2) = do
s1' <- senseMapper s1 s1' <- senseMapper s1
s2' <- senseMapper s2 s2' <- senseMapper s2
......
...@@ -175,6 +175,7 @@ data Sense ...@@ -175,6 +175,7 @@ data Sense
| SenseOr Sense Sense | SenseOr Sense Sense
| SensePosedge LHS | SensePosedge LHS
| SenseNegedge LHS | SenseNegedge LHS
| SenseEdge LHS
| SenseStar | SenseStar
deriving Eq deriving Eq
...@@ -183,6 +184,7 @@ instance Show Sense where ...@@ -183,6 +184,7 @@ instance Show Sense where
show (SenseOr a b) = printf "%s or %s" (show a) (show b) show (SenseOr a b) = printf "%s or %s" (show a) (show b)
show (SensePosedge a ) = printf "posedge %s" (show a) show (SensePosedge a ) = printf "posedge %s" (show a)
show (SenseNegedge a ) = printf "negedge %s" (show a) show (SenseNegedge a ) = printf "negedge %s" (show a)
show (SenseEdge a ) = printf "edge %s" (show a)
show (SenseStar ) = "*" show (SenseStar ) = "*"
data ActionBlock data ActionBlock
......
...@@ -1234,10 +1234,12 @@ Senses :: { Sense } ...@@ -1234,10 +1234,12 @@ Senses :: { Sense }
Sense :: { Sense } Sense :: { Sense }
: "(" Sense ")" { $2 } : "(" Sense ")" { $2 }
| LHS { Sense $1 } | LHS { Sense $1 }
| "posedge" LHS { SensePosedge $2 } | "posedge" LHSOptParen { SensePosedge $2 }
| "negedge" LHS { SenseNegedge $2 } | "negedge" LHSOptParen { SenseNegedge $2 }
| "posedge" "(" LHS ")" { SensePosedge $3 } | "edge" LHSOptParen { SenseEdge $2 }
| "negedge" "(" LHS ")" { SenseNegedge $3 } LHSOptParen :: { LHS }
: LHS { $1 }
| "(" LHS ")" { $2 }
CaseKW :: { CaseKW } CaseKW :: { CaseKW }
: "case" { CaseN } : "case" { CaseN }
......
...@@ -94,6 +94,7 @@ executable sv2v ...@@ -94,6 +94,7 @@ 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 mod(input clk);
always @(posedge clk)
$display($time, "posedge");
always @(negedge clk)
$display($time, "negedge");
always @(edge clk)
$display($time, "edge");
endmodule
module mod(input clk);
always @(posedge clk)
$display($time, "posedge");
always @(negedge clk)
$display($time, "negedge");
always @(posedge clk or negedge clk)
$display($time, "edge");
endmodule
module top;
reg clk;
initial begin
clk = 0;
repeat (10)
#5 clk = ~clk;
end
mod m(clk);
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