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
35e75c06
Commit
35e75c06
authored
Mar 20, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
language support for strengths
parent
bd68ab08
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
26 deletions
+137
-26
src/Convert/Interface.hs
+2
-2
src/Convert/Logic.hs
+5
-4
src/Convert/Traverse.hs
+7
-3
src/Language/SystemVerilog/AST/Decl.hs
+2
-2
src/Language/SystemVerilog/AST/ModuleItem.hs
+15
-5
src/Language/SystemVerilog/AST/Type.hs
+72
-8
src/Language/SystemVerilog/Parser/Parse.y
+34
-2
No files found.
src/Convert/Interface.hs
View file @
35e75c06
...
@@ -324,8 +324,8 @@ inlineInterface (ports, items) (instanceName, instanceParams, instancePorts) =
...
@@ -324,8 +324,8 @@ inlineInterface (ports, items) (instanceName, instanceParams, instancePorts) =
portBindingItem
::
PortBinding
->
Maybe
ModuleItem
portBindingItem
::
PortBinding
->
Maybe
ModuleItem
portBindingItem
(
ident
,
Just
expr
)
=
portBindingItem
(
ident
,
Just
expr
)
=
Just
$
if
declDirs
Map
.!
ident
==
Input
Just
$
if
declDirs
Map
.!
ident
==
Input
then
Assign
Nothing
(
LHSIdent
ident
)
expr
then
Assign
AssignOptionNone
(
LHSIdent
ident
)
expr
else
Assign
Nothing
(
toLHS
expr
)
(
Ident
ident
)
else
Assign
AssignOptionNone
(
toLHS
expr
)
(
Ident
ident
)
portBindingItem
(
_
,
Nothing
)
=
Nothing
portBindingItem
(
_
,
Nothing
)
=
Nothing
declDirs
=
execWriter
$
declDirs
=
execWriter
$
...
...
src/Convert/Logic.hs
View file @
35e75c06
...
@@ -77,9 +77,9 @@ convertDescription ports orig =
...
@@ -77,9 +77,9 @@ convertDescription ports orig =
fixModuleItem
::
ModuleItem
->
ModuleItem
fixModuleItem
::
ModuleItem
->
ModuleItem
-- rewrite bad continuous assignments to use procedural assignments
-- rewrite bad continuous assignments to use procedural assignments
fixModuleItem
(
Assign
Nothing
lhs
expr
)
=
fixModuleItem
(
Assign
AssignOptionNone
lhs
expr
)
=
if
Set
.
disjoint
usedIdents
origIdents
if
Set
.
disjoint
usedIdents
origIdents
then
Assign
Nothing
lhs
expr
then
Assign
AssignOptionNone
lhs
expr
else
AlwaysC
AlwaysComb
$
Asgn
AsgnOpEq
Nothing
lhs
expr
else
AlwaysC
AlwaysComb
$
Asgn
AsgnOpEq
Nothing
lhs
expr
where
where
usedIdents
=
execWriter
$
collectNestedLHSsM
lhsIdents
lhs
usedIdents
=
execWriter
$
collectNestedLHSsM
lhsIdents
lhs
...
@@ -106,7 +106,8 @@ convertDescription ports orig =
...
@@ -106,7 +106,8 @@ convertDescription ports orig =
collectNestedExprsM
exprIdents
expr
collectNestedExprsM
exprIdents
expr
tmp
=
"sv2v_tmp_"
++
instanceName
++
"_"
++
portName
tmp
=
"sv2v_tmp_"
++
instanceName
++
"_"
++
portName
tmpExpr
=
Ident
tmp
tmpExpr
=
Ident
tmp
t
=
Net
TWire
Unspecified
[(
DimsFn
FnBits
$
Right
expr
,
Number
"1"
)]
t
=
Net
(
NetType
TWire
)
Unspecified
[(
DimsFn
FnBits
$
Right
expr
,
Number
"1"
)]
items
=
items
=
[
MIPackageItem
$
Decl
$
Variable
Local
t
tmp
[]
Nothing
[
MIPackageItem
$
Decl
$
Variable
Local
t
tmp
[]
Nothing
,
AlwaysC
AlwaysComb
$
Asgn
AsgnOpEq
Nothing
lhs
tmpExpr
]
,
AlwaysC
AlwaysComb
$
Asgn
AsgnOpEq
Nothing
lhs
tmpExpr
]
...
@@ -125,7 +126,7 @@ convertDescription ports orig =
...
@@ -125,7 +126,7 @@ convertDescription ports orig =
where
where
t
=
if
Set
.
member
ident
fixedIdents
t
=
if
Set
.
member
ident
fixedIdents
then
IntegerVector
TReg
sg
then
IntegerVector
TReg
sg
else
Net
TWire
sg
else
Net
(
NetType
TWire
)
sg
convertModuleItem
other
=
other
convertModuleItem
other
=
other
-- all other logics (i.e. inside of functions) become regs
-- all other logics (i.e. inside of functions) become regs
convertDecl
::
Decl
->
Decl
convertDecl
::
Decl
->
Decl
...
...
src/Convert/Traverse.hs
View file @
35e75c06
...
@@ -576,11 +576,15 @@ traverseExprsM' strat exprMapper = moduleItemMapper
...
@@ -576,11 +576,15 @@ traverseExprsM' strat exprMapper = moduleItemMapper
stmtMapper
stmt
>>=
return
.
Initial
stmtMapper
stmt
>>=
return
.
Initial
moduleItemMapper
(
Final
stmt
)
=
moduleItemMapper
(
Final
stmt
)
=
stmtMapper
stmt
>>=
return
.
Final
stmtMapper
stmt
>>=
return
.
Final
moduleItemMapper
(
Assign
delay
lhs
expr
)
=
do
moduleItemMapper
(
Assign
opt
lhs
expr
)
=
do
delay'
<-
maybeExprMapper
delay
opt'
<-
case
opt
of
AssignOptionNone
->
return
$
AssignOptionNone
AssignOptionDrive
ds
->
return
$
AssignOptionDrive
ds
AssignOptionDelay
delay
->
exprMapper
delay
>>=
return
.
AssignOptionDelay
lhs'
<-
lhsMapper
lhs
lhs'
<-
lhsMapper
lhs
expr'
<-
exprMapper
expr
expr'
<-
exprMapper
expr
return
$
Assign
delay
'
lhs'
expr'
return
$
Assign
opt
'
lhs'
expr'
moduleItemMapper
(
MIPackageItem
(
Function
lifetime
ret
f
decls
stmts
))
=
do
moduleItemMapper
(
MIPackageItem
(
Function
lifetime
ret
f
decls
stmts
))
=
do
ret'
<-
typeMapper
ret
ret'
<-
typeMapper
ret
decls'
<-
decls'
<-
...
...
src/Language/SystemVerilog/AST/Decl.hs
View file @
35e75c06
...
@@ -2,9 +2,9 @@
...
@@ -2,9 +2,9 @@
- Author: Zachary Snow <zach@zachjs.com>
- Author: Zachary Snow <zach@zachjs.com>
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
-
-
- SystemVerilog
left-hand sides (aka lvals)
- SystemVerilog
data, net, and paramter declarations
-
-
- TODO: Normal parameters can be declared with no default valu.
- TODO: Normal parameters can be declared with no default valu
e
.
-}
-}
module
Language.SystemVerilog.AST.Decl
module
Language.SystemVerilog.AST.Decl
...
...
src/Language/SystemVerilog/AST/ModuleItem.hs
View file @
35e75c06
...
@@ -13,6 +13,7 @@ module Language.SystemVerilog.AST.ModuleItem
...
@@ -13,6 +13,7 @@ module Language.SystemVerilog.AST.ModuleItem
,
AlwaysKW
(
..
)
,
AlwaysKW
(
..
)
,
NInputGateKW
(
..
)
,
NInputGateKW
(
..
)
,
NOutputGateKW
(
..
)
,
NOutputGateKW
(
..
)
,
AssignOption
(
..
)
)
where
)
where
import
Data.List
(
intercalate
)
import
Data.List
(
intercalate
)
...
@@ -29,12 +30,12 @@ import Language.SystemVerilog.AST.Expr (Expr(Ident, Nil), Range, TypeOrExpr, sho
...
@@ -29,12 +30,12 @@ import Language.SystemVerilog.AST.Expr (Expr(Ident, Nil), Range, TypeOrExpr, sho
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
,
Timing
(
Delay
))
import
Language.SystemVerilog.AST.Stmt
(
Stmt
,
AssertionItem
,
Timing
(
Delay
))
import
Language.SystemVerilog.AST.Type
(
Identifier
)
import
Language.SystemVerilog.AST.Type
(
Identifier
,
DriveStrength
)
data
ModuleItem
data
ModuleItem
=
MIAttr
Attr
ModuleItem
=
MIAttr
Attr
ModuleItem
|
AlwaysC
AlwaysKW
Stmt
|
AlwaysC
AlwaysKW
Stmt
|
Assign
(
Maybe
Expr
)
LHS
Expr
|
Assign
AssignOption
LHS
Expr
|
Defparam
LHS
Expr
|
Defparam
LHS
Expr
|
Instance
Identifier
[
ParamBinding
]
Identifier
(
Maybe
Range
)
[
PortBinding
]
|
Instance
Identifier
[
ParamBinding
]
Identifier
(
Maybe
Range
)
[
PortBinding
]
|
Genvar
Identifier
|
Genvar
Identifier
...
@@ -52,6 +53,7 @@ instance Show ModuleItem where
...
@@ -52,6 +53,7 @@ instance Show ModuleItem where
show
(
MIPackageItem
i
)
=
show
i
show
(
MIPackageItem
i
)
=
show
i
show
(
MIAttr
attr
mi
)
=
printf
"%s %s"
(
show
attr
)
(
show
mi
)
show
(
MIAttr
attr
mi
)
=
printf
"%s %s"
(
show
attr
)
(
show
mi
)
show
(
AlwaysC
k
b
)
=
printf
"%s %s"
(
show
k
)
(
show
b
)
show
(
AlwaysC
k
b
)
=
printf
"%s %s"
(
show
k
)
(
show
b
)
show
(
Assign
o
a
b
)
=
printf
"assign %s%s = %s;"
(
showPad
o
)
(
show
a
)
(
show
b
)
show
(
Defparam
a
b
)
=
printf
"defparam %s = %s;"
(
show
a
)
(
show
b
)
show
(
Defparam
a
b
)
=
printf
"defparam %s = %s;"
(
show
a
)
(
show
b
)
show
(
Genvar
x
)
=
printf
"genvar %s;"
x
show
(
Genvar
x
)
=
printf
"genvar %s;"
x
show
(
Generate
b
)
=
printf
"generate
\n
%s
\n
endgenerate"
(
indent
$
unlines'
$
map
show
b
)
show
(
Generate
b
)
=
printf
"generate
\n
%s
\n
endgenerate"
(
indent
$
unlines'
$
map
show
b
)
...
@@ -62,9 +64,6 @@ instance Show ModuleItem where
...
@@ -62,9 +64,6 @@ instance Show ModuleItem where
showGate
kw
d
x
$
show
lhs
:
map
show
exprs
showGate
kw
d
x
$
show
lhs
:
map
show
exprs
show
(
NOutputGate
kw
d
x
lhss
expr
)
=
show
(
NOutputGate
kw
d
x
lhss
expr
)
=
showGate
kw
d
x
$
(
map
show
lhss
)
++
[
show
expr
]
showGate
kw
d
x
$
(
map
show
lhss
)
++
[
show
expr
]
show
(
Assign
d
a
b
)
=
printf
"assign %s%s = %s;"
delayStr
(
show
a
)
(
show
b
)
where
delayStr
=
maybe
""
(
\
e
->
"#("
++
show
e
++
") "
)
d
show
(
AssertionItem
(
mx
,
a
))
=
show
(
AssertionItem
(
mx
,
a
))
=
if
mx
==
Nothing
if
mx
==
Nothing
then
show
a
then
show
a
...
@@ -151,3 +150,14 @@ data NOutputGateKW
...
@@ -151,3 +150,14 @@ data NOutputGateKW
instance
Show
NOutputGateKW
where
instance
Show
NOutputGateKW
where
show
GateBuf
=
"buf"
show
GateBuf
=
"buf"
show
GateNot
=
"not"
show
GateNot
=
"not"
data
AssignOption
=
AssignOptionNone
|
AssignOptionDelay
Expr
|
AssignOptionDrive
DriveStrength
deriving
Eq
instance
Show
AssignOption
where
show
AssignOptionNone
=
""
show
(
AssignOptionDelay
de
)
=
printf
"#(%s)"
(
show
de
)
show
(
AssignOptionDrive
ds
)
=
show
ds
src/Language/SystemVerilog/AST/Type.hs
View file @
35e75c06
...
@@ -9,13 +9,18 @@
...
@@ -9,13 +9,18 @@
module
Language.SystemVerilog.AST.Type
module
Language.SystemVerilog.AST.Type
(
Identifier
(
Identifier
,
Field
,
Field
,
Type
(
..
)
,
Type
(
..
)
,
Signing
(
..
)
,
Signing
(
..
)
,
Packing
(
..
)
,
Packing
(
..
)
,
NetType
(
..
)
,
NetType
(
..
)
,
IntegerVectorType
(
..
)
,
IntegerVectorType
(
..
)
,
IntegerAtomType
(
..
)
,
IntegerAtomType
(
..
)
,
NonIntegerType
(
..
)
,
NonIntegerType
(
..
)
,
NetTypeAndStrength
(
..
)
,
DriveStrength
(
..
)
,
Strength0
(
..
)
,
Strength1
(
..
)
,
ChargeStrength
(
..
)
,
typeRanges
,
typeRanges
,
nullRange
,
nullRange
,
elaborateIntegerAtom
,
elaborateIntegerAtom
...
@@ -35,7 +40,7 @@ data Type
...
@@ -35,7 +40,7 @@ data Type
=
IntegerVector
IntegerVectorType
Signing
[
Range
]
=
IntegerVector
IntegerVectorType
Signing
[
Range
]
|
IntegerAtom
IntegerAtomType
Signing
|
IntegerAtom
IntegerAtomType
Signing
|
NonInteger
NonIntegerType
|
NonInteger
NonIntegerType
|
Net
NetType
Signing
[
Range
]
|
Net
NetType
AndStrength
Signing
[
Range
]
|
Implicit
Signing
[
Range
]
|
Implicit
Signing
[
Range
]
|
Alias
(
Maybe
Identifier
)
Identifier
[
Range
]
|
Alias
(
Maybe
Identifier
)
Identifier
[
Range
]
|
Enum
(
Maybe
Type
)
[
Item
]
[
Range
]
|
Enum
(
Maybe
Type
)
[
Item
]
[
Range
]
...
@@ -217,3 +222,62 @@ data Packing
...
@@ -217,3 +222,62 @@ data Packing
instance
Show
Packing
where
instance
Show
Packing
where
show
(
Unpacked
)
=
""
show
(
Unpacked
)
=
""
show
(
Packed
s
)
=
"packed"
++
(
showPadBefore
s
)
show
(
Packed
s
)
=
"packed"
++
(
showPadBefore
s
)
data
NetTypeAndStrength
=
NetType
NetType
|
NetTypeDrive
NetType
DriveStrength
|
NetTypeCharge
NetType
ChargeStrength
deriving
(
Eq
,
Ord
)
instance
Show
NetTypeAndStrength
where
show
(
NetType
nt
)
=
show
nt
show
(
NetTypeDrive
nt
ds
)
=
printf
"%s %s"
(
show
nt
)
(
show
ds
)
show
(
NetTypeCharge
nt
cs
)
=
printf
"%s %s"
(
show
nt
)
(
show
cs
)
data
DriveStrength
=
DriveStrength
Strength0
Strength1
deriving
(
Eq
,
Ord
)
instance
Show
DriveStrength
where
show
(
DriveStrength
s0
s1
)
=
printf
"(%s, %s)"
(
show
s0
)
(
show
s1
)
data
Strength0
=
Supply0
|
Strong0
|
Pull0
|
Weak0
|
Highz0
deriving
(
Eq
,
Ord
)
instance
Show
Strength0
where
show
Supply0
=
"supply0"
show
Strong0
=
"strong0"
show
Pull0
=
"pull0"
show
Weak0
=
"weak0"
show
Highz0
=
"highz0"
data
Strength1
=
Supply1
|
Strong1
|
Pull1
|
Weak1
|
Highz1
deriving
(
Eq
,
Ord
)
instance
Show
Strength1
where
show
Supply1
=
"supply1"
show
Strong1
=
"strong1"
show
Pull1
=
"pull1"
show
Weak1
=
"weak1"
show
Highz1
=
"highz1"
data
ChargeStrength
=
Small
|
Medium
|
Large
deriving
(
Eq
,
Ord
)
instance
Show
ChargeStrength
where
show
Small
=
"(small)"
show
Medium
=
"(medium)"
show
Large
=
"(large)"
src/Language/SystemVerilog/Parser/Parse.y
View file @
35e75c06
...
@@ -449,7 +449,7 @@ TypeNonIdent :: { Type }
...
@@ -449,7 +449,7 @@ TypeNonIdent :: { Type }
: PartialType OptSigning Dimensions { $1 $2 $3 }
: PartialType OptSigning Dimensions { $1 $2 $3 }
| "type" "(" Expr ")" { TypeOf $3 }
| "type" "(" Expr ")" { TypeOf $3 }
PartialType :: { Signing -> [Range] -> Type }
PartialType :: { Signing -> [Range] -> Type }
: NetType
{ Net $1 }
: NetType
AndStrength
{ Net $1 }
| IntegerVectorType { IntegerVector $1 }
| IntegerVectorType { IntegerVector $1 }
| IntegerAtomType { \sg -> \[] -> IntegerAtom $1 sg }
| IntegerAtomType { \sg -> \[] -> IntegerAtom $1 sg }
| NonIntegerType { \Unspecified -> \[] -> NonInteger $1 }
| NonIntegerType { \Unspecified -> \[] -> NonInteger $1 }
...
@@ -465,6 +465,11 @@ EnumBaseType :: { Maybe Type }
...
@@ -465,6 +465,11 @@ EnumBaseType :: { Maybe Type }
: opt(Type) { $1 }
: opt(Type) { $1 }
| DimensionsNonEmpty { Just $ Implicit Unspecified $1 }
| DimensionsNonEmpty { Just $ Implicit Unspecified $1 }
NetTypeAndStrength :: { NetTypeAndStrength }
: NetType %prec "+" { NetType $1 }
| NetType DriveStrength %prec "*" { NetTypeDrive $1 $2 }
| NetType ChargeStrength %prec "*" { NetTypeCharge $1 $2 }
Signing :: { Signing }
Signing :: { Signing }
: "signed" { Signed }
: "signed" { Signed }
| "unsigned" { Unsigned }
| "unsigned" { Unsigned }
...
@@ -656,7 +661,7 @@ NonGenerateModuleItem :: { [ModuleItem] }
...
@@ -656,7 +661,7 @@ NonGenerateModuleItem :: { [ModuleItem] }
: DeclTokens(";") { parseDTsAsModuleItems $1 }
: DeclTokens(";") { parseDTsAsModuleItems $1 }
| ParameterDecl(";") { map (MIPackageItem . Decl) $1 }
| ParameterDecl(";") { map (MIPackageItem . Decl) $1 }
| "defparam" LHSAsgns ";" { map (uncurry Defparam) $2 }
| "defparam" LHSAsgns ";" { map (uncurry Defparam) $2 }
| "assign"
opt(DelayControl) LHSAsgns ";"
{ map (uncurry $ Assign $2) $3 }
| "assign"
AssignOption LHSAsgns ";"
{ map (uncurry $ Assign $2) $3 }
| AlwaysKW Stmt { [AlwaysC $1 $2] }
| AlwaysKW Stmt { [AlwaysC $1 $2] }
| "initial" Stmt { [Initial $2] }
| "initial" Stmt { [Initial $2] }
| "final" Stmt { [Final $2] }
| "final" Stmt { [Final $2] }
...
@@ -668,6 +673,11 @@ NonGenerateModuleItem :: { [ModuleItem] }
...
@@ -668,6 +673,11 @@ NonGenerateModuleItem :: { [ModuleItem] }
| AttributeInstance ModuleItem { map (MIAttr $1) $2 }
| AttributeInstance ModuleItem { map (MIAttr $1) $2 }
| AssertionItem { [AssertionItem $1] }
| AssertionItem { [AssertionItem $1] }
AssignOption :: { AssignOption }
: {- empty -} { AssignOptionNone }
| DelayControl { AssignOptionDelay $1 }
| DriveStrength { AssignOptionDrive $1 }
-- for ModuleItem, for now
-- for ModuleItem, for now
AssertionItem :: { AssertionItem }
AssertionItem :: { AssertionItem }
: ConcurrentAssertionItem { $1 }
: ConcurrentAssertionItem { $1 }
...
@@ -769,6 +779,28 @@ NOutputGateKW :: { NOutputGateKW }
...
@@ -769,6 +779,28 @@ NOutputGateKW :: { NOutputGateKW }
: "buf" { GateBuf }
: "buf" { GateBuf }
| "not" { GateNot }
| "not" { GateNot }
DriveStrength :: { DriveStrength }
: "(" Strength0 "," Strength1 ")" { DriveStrength $2 $4 }
| "(" Strength1 "," Strength0 ")" { DriveStrength $4 $2 }
| "(" Strength0 "," "highz1" ")" { DriveStrength $2 Highz1 }
| "(" Strength1 "," "highz0" ")" { DriveStrength Highz0 $2 }
| "(" "highz0" "," Strength1 ")" { DriveStrength Highz0 $4 }
| "(" "highz1" "," Strength0 ")" { DriveStrength $4 Highz1 }
Strength0 :: { Strength0 }
: "supply0" { Supply0 }
| "strong0" { Strong0 }
| "pull0" { Pull0 }
| "weak0" { Weak0 }
Strength1 :: { Strength1 }
: "supply1" { Supply1 }
| "strong1" { Strong1 }
| "pull1" { Pull1 }
| "weak1" { Weak1 }
ChargeStrength :: { ChargeStrength }
: "(" "small" ")" { Small }
| "(" "medium" ")" { Medium }
| "(" "large" ")" { Large }
LHSAsgns :: { [(LHS, Expr)] }
LHSAsgns :: { [(LHS, Expr)] }
: LHSAsgn { [$1] }
: LHSAsgn { [$1] }
| LHSAsgns "," LHSAsgn { $1 ++ [$3] }
| LHSAsgns "," LHSAsgn { $1 ++ [$3] }
...
...
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