Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sv2v
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
sv2v
Commits
610d9aba
Commit
610d9aba
authored
Jan 31, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for gates with delays
parent
6e4a19d0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
21 deletions
+74
-21
src/Convert/Traverse.hs
+10
-8
src/Language/SystemVerilog/AST/ModuleItem.hs
+14
-5
src/Language/SystemVerilog/Parser/Parse.y
+9
-8
test/basic/gate.sv
+39
-0
test/basic/gate.v
+2
-0
No files found.
src/Convert/Traverse.hs
View file @
610d9aba
...
@@ -630,14 +630,16 @@ traverseExprsM' strat exprMapper = moduleItemMapper
...
@@ -630,14 +630,16 @@ traverseExprsM' strat exprMapper = moduleItemMapper
return
$
Instance
m
p'
x
r'
l'
return
$
Instance
m
p'
x
r'
l'
moduleItemMapper
(
Modport
x
l
)
=
moduleItemMapper
(
Modport
x
l
)
=
mapM
modportDeclMapper
l
>>=
return
.
Modport
x
mapM
modportDeclMapper
l
>>=
return
.
Modport
x
moduleItemMapper
(
NInputGate
kw
x
lhs
exprs
)
=
do
moduleItemMapper
(
NInputGate
kw
d
x
lhs
exprs
)
=
do
d'
<-
maybeExprMapper
d
exprs'
<-
mapM
exprMapper
exprs
exprs'
<-
mapM
exprMapper
exprs
lhs'
<-
lhsMapper
lhs
lhs'
<-
lhsMapper
lhs
return
$
NInputGate
kw
x
lhs'
exprs'
return
$
NInputGate
kw
d'
x
lhs'
exprs'
moduleItemMapper
(
NOutputGate
kw
x
lhss
expr
)
=
do
moduleItemMapper
(
NOutputGate
kw
d
x
lhss
expr
)
=
do
d'
<-
maybeExprMapper
d
lhss'
<-
mapM
lhsMapper
lhss
lhss'
<-
mapM
lhsMapper
lhss
expr'
<-
exprMapper
expr
expr'
<-
exprMapper
expr
return
$
NOutputGate
kw
x
lhss'
expr'
return
$
NOutputGate
kw
d'
x
lhss'
expr'
moduleItemMapper
(
Genvar
x
)
=
return
$
Genvar
x
moduleItemMapper
(
Genvar
x
)
=
return
$
Genvar
x
moduleItemMapper
(
Generate
items
)
=
do
moduleItemMapper
(
Generate
items
)
=
do
items'
<-
mapM
(
traverseNestedGenItemsM
genItemMapper
)
items
items'
<-
mapM
(
traverseNestedGenItemsM
genItemMapper
)
items
...
@@ -769,12 +771,12 @@ traverseLHSsM' strat mapper item =
...
@@ -769,12 +771,12 @@ traverseLHSsM' strat mapper item =
traverseModuleItemLHSsM
(
Defparam
lhs
expr
)
=
do
traverseModuleItemLHSsM
(
Defparam
lhs
expr
)
=
do
lhs'
<-
mapper
lhs
lhs'
<-
mapper
lhs
return
$
Defparam
lhs'
expr
return
$
Defparam
lhs'
expr
traverseModuleItemLHSsM
(
NOutputGate
kw
x
lhss
expr
)
=
do
traverseModuleItemLHSsM
(
NOutputGate
kw
d
x
lhss
expr
)
=
do
lhss'
<-
mapM
mapper
lhss
lhss'
<-
mapM
mapper
lhss
return
$
NOutputGate
kw
x
lhss'
expr
return
$
NOutputGate
kw
d
x
lhss'
expr
traverseModuleItemLHSsM
(
NInputGate
kw
x
lhs
exprs
)
=
do
traverseModuleItemLHSsM
(
NInputGate
kw
d
x
lhs
exprs
)
=
do
lhs'
<-
mapper
lhs
lhs'
<-
mapper
lhs
return
$
NInputGate
kw
x
lhs'
exprs
return
$
NInputGate
kw
d
x
lhs'
exprs
traverseModuleItemLHSsM
(
AssertionItem
(
mx
,
a
))
=
do
traverseModuleItemLHSsM
(
AssertionItem
(
mx
,
a
))
=
do
converted
<-
converted
<-
traverseNestedStmtsM
(
traverseStmtLHSsM
mapper
)
(
Assertion
a
)
traverseNestedStmtsM
(
traverseStmtLHSsM
mapper
)
(
Assertion
a
)
...
...
src/Language/SystemVerilog/AST/ModuleItem.hs
View file @
610d9aba
...
@@ -28,7 +28,7 @@ import Language.SystemVerilog.AST.Description (PackageItem)
...
@@ -28,7 +28,7 @@ import Language.SystemVerilog.AST.Description (PackageItem)
import
Language.SystemVerilog.AST.Expr
(
Expr
(
Ident
,
Nil
),
Range
,
TypeOrExpr
,
showRanges
)
import
Language.SystemVerilog.AST.Expr
(
Expr
(
Ident
,
Nil
),
Range
,
TypeOrExpr
,
showRanges
)
import
Language.SystemVerilog.AST.GenItem
(
GenItem
)
import
Language.SystemVerilog.AST.GenItem
(
GenItem
)
import
Language.SystemVerilog.AST.LHS
(
LHS
)
import
Language.SystemVerilog.AST.LHS
(
LHS
)
import
Language.SystemVerilog.AST.Stmt
(
Stmt
,
AssertionItem
)
import
Language.SystemVerilog.AST.Stmt
(
Stmt
,
AssertionItem
,
Timing
(
Delay
)
)
import
Language.SystemVerilog.AST.Type
(
Identifier
)
import
Language.SystemVerilog.AST.Type
(
Identifier
)
data
ModuleItem
data
ModuleItem
...
@@ -43,8 +43,8 @@ data ModuleItem
...
@@ -43,8 +43,8 @@ data ModuleItem
|
Initial
Stmt
|
Initial
Stmt
|
Final
Stmt
|
Final
Stmt
|
MIPackageItem
PackageItem
|
MIPackageItem
PackageItem
|
NInputGate
NInputGateKW
(
Maybe
Identifier
)
LHS
[
Expr
]
|
NInputGate
NInputGateKW
(
Maybe
Expr
)
Identifier
LHS
[
Expr
]
|
NOutputGate
NOutputGateKW
(
Maybe
Identifier
)
[
LHS
]
Expr
|
NOutputGate
NOutputGateKW
(
Maybe
Expr
)
Identifier
[
LHS
]
Expr
|
AssertionItem
AssertionItem
|
AssertionItem
AssertionItem
deriving
Eq
deriving
Eq
...
@@ -58,8 +58,10 @@ instance Show ModuleItem where
...
@@ -58,8 +58,10 @@ instance Show ModuleItem where
show
(
Modport
x
l
)
=
printf
"modport %s(
\n
%s
\n
);"
x
(
indent
$
intercalate
",
\n
"
$
map
showModportDecl
l
)
show
(
Modport
x
l
)
=
printf
"modport %s(
\n
%s
\n
);"
x
(
indent
$
intercalate
",
\n
"
$
map
showModportDecl
l
)
show
(
Initial
s
)
=
printf
"initial %s"
(
show
s
)
show
(
Initial
s
)
=
printf
"initial %s"
(
show
s
)
show
(
Final
s
)
=
printf
"final %s"
(
show
s
)
show
(
Final
s
)
=
printf
"final %s"
(
show
s
)
show
(
NInputGate
kw
x
lhs
exprs
)
=
printf
"%s%s (%s, %s);"
(
show
kw
)
(
maybe
""
(
" "
++
)
x
)
(
show
lhs
)
(
commas
$
map
show
exprs
)
show
(
NInputGate
kw
d
x
lhs
exprs
)
=
show
(
NOutputGate
kw
x
lhss
expr
)
=
printf
"%s%s (%s, %s);"
(
show
kw
)
(
maybe
""
(
" "
++
)
x
)
(
commas
$
map
show
lhss
)
(
show
expr
)
showGate
kw
d
x
$
show
lhs
:
map
show
exprs
show
(
NOutputGate
kw
d
x
lhss
expr
)
=
showGate
kw
d
x
$
(
map
show
lhss
)
++
[
show
expr
]
show
(
Assign
d
a
b
)
=
show
(
Assign
d
a
b
)
=
printf
"assign %s%s = %s;"
delayStr
(
show
a
)
(
show
b
)
printf
"assign %s%s = %s;"
delayStr
(
show
a
)
(
show
b
)
where
delayStr
=
maybe
""
(
\
e
->
"#("
++
show
e
++
") "
)
d
where
delayStr
=
maybe
""
(
\
e
->
"#("
++
show
e
++
") "
)
d
...
@@ -83,6 +85,13 @@ showPort (i, arg) =
...
@@ -83,6 +85,13 @@ showPort (i, arg) =
then
show
(
fromJust
arg
)
then
show
(
fromJust
arg
)
else
printf
".%s(%s)"
i
(
if
isJust
arg
then
show
$
fromJust
arg
else
""
)
else
printf
".%s(%s)"
i
(
if
isJust
arg
then
show
$
fromJust
arg
else
""
)
showGate
::
Show
k
=>
k
->
Maybe
Expr
->
Identifier
->
[
String
]
->
String
showGate
kw
d
x
args
=
printf
"%s %s%s(%s);"
(
show
kw
)
delayStr
nameStr
(
commas
args
)
where
delayStr
=
maybe
""
(
showPad
.
Delay
)
d
nameStr
=
showPad
$
Ident
x
showParams
::
[
ParamBinding
]
->
String
showParams
::
[
ParamBinding
]
->
String
showParams
params
=
indentedParenList
$
map
showParam
params
showParams
params
=
indentedParenList
$
map
showParam
params
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
610d9aba
...
@@ -16,6 +16,7 @@ module Language.SystemVerilog.Parser.Parse (parse) where
...
@@ -16,6 +16,7 @@ module Language.SystemVerilog.Parser.Parse (parse) where
import Control.Monad.Except
import Control.Monad.Except
import Control.Monad.State
import Control.Monad.State
import Data.Maybe (fromMaybe)
import Language.SystemVerilog.AST
import Language.SystemVerilog.AST
import Language.SystemVerilog.Parser.ParseDecl
import Language.SystemVerilog.Parser.ParseDecl
import Language.SystemVerilog.Parser.Tokens
import Language.SystemVerilog.Parser.Tokens
...
@@ -649,8 +650,8 @@ NonGenerateModuleItem :: { [ModuleItem] }
...
@@ -649,8 +650,8 @@ NonGenerateModuleItem :: { [ModuleItem] }
| "genvar" Identifiers ";" { map Genvar $2 }
| "genvar" Identifiers ";" { map Genvar $2 }
| "modport" ModportItems ";" { map (uncurry Modport) $2 }
| "modport" ModportItems ";" { map (uncurry Modport) $2 }
| NonDeclPackageItem { map MIPackageItem $1 }
| NonDeclPackageItem { map MIPackageItem $1 }
| NInputGateKW NInputGates ";" { map (\(a, b, c
) -> NInputGate $1 a b c
) $2 }
| NInputGateKW NInputGates ";" { map (\(a, b, c
, d) -> NInputGate $1 a b c d
) $2 }
| NOutputGateKW NOutputGates ";" { map (\(a, b, c
) -> NOutputGate $1 a b c
) $2 }
| NOutputGateKW NOutputGates ";" { map (\(a, b, c
, d) -> NOutputGate $1 a b c d
) $2 }
| AttributeInstance ModuleItem { map (MIAttr $1) $2 }
| AttributeInstance ModuleItem { map (MIAttr $1) $2 }
| AssertionItem { [AssertionItem $1] }
| AssertionItem { [AssertionItem $1] }
...
@@ -729,17 +730,17 @@ AttrSpec :: { AttrSpec }
...
@@ -729,17 +730,17 @@ AttrSpec :: { AttrSpec }
: Identifier "=" Expr { ($1, Just $3) }
: Identifier "=" Expr { ($1, Just $3) }
| Identifier { ($1, Nothing) }
| Identifier { ($1, Nothing) }
NInputGates :: { [(Maybe Identifier, LHS, [Expr])] }
NInputGates :: { [(Maybe
Expr,
Identifier, LHS, [Expr])] }
: NInputGate { [$1] }
: NInputGate { [$1] }
| NInputGates "," NInputGate { $1 ++ [$3]}
| NInputGates "," NInputGate { $1 ++ [$3]}
NOutputGates :: { [(Maybe Identifier, [LHS], Expr)] }
NOutputGates :: { [(Maybe
Expr,
Identifier, [LHS], Expr)] }
: NOutputGate { [$1] }
: NOutputGate { [$1] }
| NOutputGates "," NOutputGate { $1 ++ [$3]}
| NOutputGates "," NOutputGate { $1 ++ [$3]}
NInputGate :: { (Maybe Identifier, LHS, [Expr]) }
NInputGate :: { (Maybe
Expr,
Identifier, LHS, [Expr]) }
: opt(
Identifier) "(" LHS "," Exprs ")" { ($1, $3, $5
) }
: opt(
DelayControl) opt(Identifier) "(" LHS "," Exprs ")" { ($1, fromMaybe "" $2, $4, $6
) }
NOutputGate :: { (Maybe Identifier, [LHS], Expr) }
NOutputGate :: { (Maybe
Expr,
Identifier, [LHS], Expr) }
: opt(
Identifier) "(" NOutputGateItems { ($1, fst $3, snd $3
) }
: opt(
DelayControl) opt(Identifier) "(" NOutputGateItems { ($1, fromMaybe "" $2, fst $4, snd $4
) }
NOutputGateItems :: { ([LHS], Expr) }
NOutputGateItems :: { ([LHS], Expr) }
: Expr ")" { ([], $1) }
: Expr ")" { ([], $1) }
| Expr "," NOutputGateItems { (fst $3 ++ [toLHS $1], snd $3) }
| Expr "," NOutputGateItems { (fst $3 ++ [toLHS $1], snd $3) }
...
...
test/basic/gate.sv
0 → 100644
View file @
610d9aba
module
top
;
reg
input_a
;
reg
input_b
;
wire
output_and
;
wire
output_and_delay
;
wire
output_not
;
wire
output_buf_delay
;
and
(
output_and
,
input_a
,
input_b
)
;
and
#
1
(
output_and_delay
,
input_a
,
input_b
)
;
not
(
output_not
,
input_a
)
;
buf
#
2
foo_name
(
output_buf_delay
,
input_a
)
;
initial
repeat
(
2
)
begin
$
monitor
(
"%3d "
,
$
time
,
input_a
,
input_b
,
output_and
,
output_and_delay
,
output_not
,
output_buf_delay
)
;
#
1
;
#
1
;
input_a
=
1
;
#
1
;
input_b
=
0
;
#
1
;
input_b
=
1
;
#
1
;
#
1
;
input_a
=
0
;
#
1
;
input_b
=
0
;
#
1
;
input_a
=
0
;
#
1
;
input_b
=
1
;
#
1
;
input_a
=
1
;
#
1
;
input_b
=
0
;
#
1
;
input_a
=
1
;
#
1
;
input_b
=
1
;
#
1
;
#
1
;
#
1
;
end
endmodule
test/basic/gate.v
0 → 100644
View file @
610d9aba
// This test is for parser coverge only.
`include
"gate.sv"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment