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
d11e898e
Commit
d11e898e
authored
Sep 06, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ParamType decl; combined parameter and localparam under Param
parent
9cc211d5
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
68 additions
and
48 deletions
+68
-48
src/Convert/Bits.hs
+2
-2
src/Convert/Enum.hs
+1
-1
src/Convert/Interface.hs
+2
-2
src/Convert/Logic.hs
+2
-4
src/Convert/Mux.hs
+1
-1
src/Convert/NestPI.hs
+2
-2
src/Convert/Package.hs
+4
-4
src/Convert/PackedArray.hs
+4
-5
src/Convert/Struct.hs
+4
-6
src/Convert/Traverse.hs
+15
-10
src/Language/SystemVerilog/AST/Decl.hs
+18
-6
src/Language/SystemVerilog/AST/Expr.hs
+1
-1
src/Language/SystemVerilog/Parser/Parse.y
+12
-4
No files found.
src/Convert/Bits.hs
View file @
d11e898e
...
@@ -36,8 +36,8 @@ traverseDeclM :: Decl -> State Info Decl
...
@@ -36,8 +36,8 @@ traverseDeclM :: Decl -> State Info Decl
traverseDeclM
decl
=
do
traverseDeclM
decl
=
do
case
decl
of
case
decl
of
Variable
_
t
ident
a
_
->
modify
$
Map
.
insert
ident
(
t
,
a
)
Variable
_
t
ident
a
_
->
modify
$
Map
.
insert
ident
(
t
,
a
)
Param
eter
t
ident
_
->
modify
$
Map
.
insert
ident
(
t
,
[]
)
Param
_
t
ident
_
->
modify
$
Map
.
insert
ident
(
t
,
[]
)
Localparam
t
ident
_
->
modify
$
Map
.
insert
ident
(
t
,
[]
)
ParamType
_
_
_
->
return
(
)
item
<-
traverseModuleItemM
(
MIPackageItem
$
Decl
decl
)
item
<-
traverseModuleItemM
(
MIPackageItem
$
Decl
decl
)
let
MIPackageItem
(
Decl
decl'
)
=
item
let
MIPackageItem
(
Decl
decl'
)
=
item
return
decl'
return
decl'
...
...
src/Convert/Enum.hs
View file @
d11e898e
...
@@ -91,7 +91,7 @@ convergeUsage items enums =
...
@@ -91,7 +91,7 @@ convergeUsage items enums =
toItem
::
EnumItem
->
PackageItem
toItem
::
EnumItem
->
PackageItem
toItem
((
mr
,
x
),
v
)
=
toItem
((
mr
,
x
),
v
)
=
Decl
$
Localparam
itemType
x
v'
Decl
$
Param
Localparam
itemType
x
v'
where
where
v'
=
if
mr
==
Nothing
v'
=
if
mr
==
Nothing
then
simplify
v
then
simplify
v
...
...
src/Convert/Interface.hs
View file @
d11e898e
...
@@ -192,8 +192,8 @@ prefixModuleItems prefix =
...
@@ -192,8 +192,8 @@ prefixModuleItems prefix =
where
where
prefixDecl
::
Decl
->
Decl
prefixDecl
::
Decl
->
Decl
prefixDecl
(
Variable
d
t
x
a
me
)
=
Variable
d
t
(
prefix
++
x
)
a
me
prefixDecl
(
Variable
d
t
x
a
me
)
=
Variable
d
t
(
prefix
++
x
)
a
me
prefixDecl
(
Param
eter
t
x
e
)
=
Parameter
t
(
prefix
++
x
)
e
prefixDecl
(
Param
s
t
x
e
)
=
Param
s
t
(
prefix
++
x
)
e
prefixDecl
(
Localparam
t
x
e
)
=
Localparam
t
(
prefix
++
x
)
e
prefixDecl
(
ParamType
s
x
mt
)
=
ParamType
s
(
prefix
++
x
)
mt
prefixExpr
::
Expr
->
Expr
prefixExpr
::
Expr
->
Expr
prefixExpr
(
Ident
x
)
=
Ident
(
prefix
++
x
)
prefixExpr
(
Ident
x
)
=
Ident
(
prefix
++
x
)
prefixExpr
other
=
other
prefixExpr
other
=
other
...
...
src/Convert/Logic.hs
View file @
d11e898e
...
@@ -122,10 +122,8 @@ convertDescription ports orig =
...
@@ -122,10 +122,8 @@ convertDescription ports orig =
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
convertDecl
(
Parameter
(
IntegerVector
_
sg
rs
)
x
e
)
=
convertDecl
(
Param
s
(
IntegerVector
_
sg
rs
)
x
e
)
=
Parameter
(
Implicit
sg
rs
)
x
e
Param
s
(
Implicit
sg
rs
)
x
e
convertDecl
(
Localparam
(
IntegerVector
_
sg
rs
)
x
e
)
=
Localparam
(
Implicit
sg
rs
)
x
e
convertDecl
(
Variable
d
(
IntegerVector
TLogic
sg
rs
)
x
a
me
)
=
convertDecl
(
Variable
d
(
IntegerVector
TLogic
sg
rs
)
x
a
me
)
=
Variable
d
(
IntegerVector
TReg
sg
rs
)
x
a
me
Variable
d
(
IntegerVector
TReg
sg
rs
)
x
a
me
convertDecl
other
=
other
convertDecl
other
=
other
...
...
src/Convert/Mux.hs
View file @
d11e898e
...
@@ -34,7 +34,7 @@ convertDescription =
...
@@ -34,7 +34,7 @@ convertDescription =
traverseDeclM
::
Decl
->
State
Info
Decl
traverseDeclM
::
Decl
->
State
Info
Decl
traverseDeclM
decl
=
do
traverseDeclM
decl
=
do
case
decl
of
case
decl
of
Localparam
_
x
e
->
modify
$
Map
.
insert
x
e
Param
Localparam
_
x
e
->
modify
$
Map
.
insert
x
e
_
->
return
()
_
->
return
()
return
decl
return
decl
...
...
src/Convert/NestPI.hs
View file @
d11e898e
...
@@ -90,8 +90,8 @@ piName (Function _ _ ident _ _) = Just ident
...
@@ -90,8 +90,8 @@ piName (Function _ _ ident _ _) = Just ident
piName
(
Task
_
ident
_
_
)
=
Just
ident
piName
(
Task
_
ident
_
_
)
=
Just
ident
piName
(
Typedef
_
ident
)
=
Just
ident
piName
(
Typedef
_
ident
)
=
Just
ident
piName
(
Decl
(
Variable
_
_
ident
_
_
))
=
Just
ident
piName
(
Decl
(
Variable
_
_
ident
_
_
))
=
Just
ident
piName
(
Decl
(
Param
eter
_
ident
_
))
=
Just
ident
piName
(
Decl
(
Param
_
_
ident
_
))
=
Just
ident
piName
(
Decl
(
Localparam
_
ident
_
))
=
Just
ident
piName
(
Decl
(
ParamType
_
ident
_
))
=
Just
ident
piName
(
Import
x
y
)
=
Just
$
show
$
Import
x
y
piName
(
Import
x
y
)
=
Just
$
show
$
Import
x
y
piName
(
Export
_
)
=
Nothing
piName
(
Export
_
)
=
Nothing
piName
(
Comment
_
)
=
Nothing
piName
(
Comment
_
)
=
Nothing
src/Convert/Package.hs
View file @
d11e898e
...
@@ -91,8 +91,8 @@ prefixPackageItem packageName idents item =
...
@@ -91,8 +91,8 @@ prefixPackageItem packageName idents item =
Task
a
x
c
d
->
Task
a
(
prefix
x
)
c
d
Task
a
x
c
d
->
Task
a
(
prefix
x
)
c
d
Typedef
a
x
->
Typedef
a
(
prefix
x
)
Typedef
a
x
->
Typedef
a
(
prefix
x
)
Decl
(
Variable
a
b
x
c
d
)
->
Decl
(
Variable
a
b
(
prefix
x
)
c
d
)
Decl
(
Variable
a
b
x
c
d
)
->
Decl
(
Variable
a
b
(
prefix
x
)
c
d
)
Decl
(
Param
eter
a
x
b
)
->
Decl
(
Parameter
a
(
prefix
x
)
b
)
Decl
(
Param
a
b
x
c
)
->
Decl
(
Param
a
b
(
prefix
x
)
c
)
Decl
(
Localparam
a
x
b
)
->
Decl
(
Localparam
a
(
prefix
x
)
b
)
Decl
(
ParamType
a
x
b
)
->
Decl
(
ParamType
a
(
prefix
x
)
b
)
other
->
other
other
->
other
convertType
(
Alias
Nothing
x
rs
)
=
Alias
Nothing
(
prefix
x
)
rs
convertType
(
Alias
Nothing
x
rs
)
=
Alias
Nothing
(
prefix
x
)
rs
convertType
(
Enum
mt
items
rs
)
=
Enum
mt
items'
rs
convertType
(
Enum
mt
items
rs
)
=
Enum
mt
items'
rs
...
@@ -181,8 +181,8 @@ piName (Function _ _ ident _ _) = Just ident
...
@@ -181,8 +181,8 @@ piName (Function _ _ ident _ _) = Just ident
piName
(
Task
_
ident
_
_
)
=
Just
ident
piName
(
Task
_
ident
_
_
)
=
Just
ident
piName
(
Typedef
_
ident
)
=
Just
ident
piName
(
Typedef
_
ident
)
=
Just
ident
piName
(
Decl
(
Variable
_
_
ident
_
_
))
=
Just
ident
piName
(
Decl
(
Variable
_
_
ident
_
_
))
=
Just
ident
piName
(
Decl
(
Param
eter
_
ident
_
))
=
Just
ident
piName
(
Decl
(
Param
_
_
ident
_
))
=
Just
ident
piName
(
Decl
(
Localparam
_
ident
_
))
=
Just
ident
piName
(
Decl
(
ParamType
_
ident
_
))
=
Just
ident
piName
(
Import
_
_
)
=
Nothing
piName
(
Import
_
_
)
=
Nothing
piName
(
Export
_
)
=
Nothing
piName
(
Export
_
)
=
Nothing
piName
(
Comment
_
)
=
Nothing
piName
(
Comment
_
)
=
Nothing
src/Convert/PackedArray.hs
View file @
d11e898e
...
@@ -51,12 +51,11 @@ traverseDeclM (Variable dir t ident a me) = do
...
@@ -51,12 +51,11 @@ traverseDeclM (Variable dir t ident a me) = do
else
do
else
do
t'
<-
traverseDeclM'
t
ident
t'
<-
traverseDeclM'
t
ident
return
$
Variable
dir
t'
ident
a
me
return
$
Variable
dir
t'
ident
a
me
traverseDeclM
(
Param
eter
t
ident
e
)
=
do
traverseDeclM
(
Param
s
t
ident
e
)
=
do
t'
<-
traverseDeclM'
t
ident
t'
<-
traverseDeclM'
t
ident
return
$
Parameter
t'
ident
e
return
$
Param
s
t'
ident
e
traverseDeclM
(
Localparam
t
ident
e
)
=
do
traverseDeclM
(
ParamType
s
ident
mt
)
=
t'
<-
traverseDeclM'
t
ident
return
$
ParamType
s
ident
mt
return
$
Localparam
t'
ident
e
traverseDeclM'
::
Type
->
Identifier
->
State
Info
Type
traverseDeclM'
::
Type
->
Identifier
->
State
Info
Type
traverseDeclM'
t
ident
=
do
traverseDeclM'
t
ident
=
do
...
...
src/Convert/Struct.hs
View file @
d11e898e
...
@@ -176,14 +176,12 @@ traverseDeclM structs origDecl = do
...
@@ -176,14 +176,12 @@ traverseDeclM structs origDecl = do
Just
e
->
do
Just
e
->
do
e'
<-
convertDeclExpr
x
e
e'
<-
convertDeclExpr
x
e
return
$
Variable
d
t
x
a
(
Just
e'
)
return
$
Variable
d
t
x
a
(
Just
e'
)
Param
eter
t
x
e
->
do
Param
s
t
x
e
->
do
modify
$
Map
.
insert
x
t
modify
$
Map
.
insert
x
t
e'
<-
convertDeclExpr
x
e
e'
<-
convertDeclExpr
x
e
return
$
Parameter
t
x
e'
return
$
Param
s
t
x
e'
Localparam
t
x
e
->
do
ParamType
s
x
mt
->
modify
$
Map
.
insert
x
t
return
$
ParamType
s
x
mt
e'
<-
convertDeclExpr
x
e
return
$
Localparam
t
x
e'
where
where
convertDeclExpr
::
Identifier
->
Expr
->
State
Types
Expr
convertDeclExpr
::
Identifier
->
Expr
->
State
Types
Expr
convertDeclExpr
x
e
=
do
convertDeclExpr
x
e
=
do
...
...
src/Convert/Traverse.hs
View file @
d11e898e
...
@@ -486,14 +486,17 @@ exprMapperHelpers exprMapper =
...
@@ -486,14 +486,17 @@ exprMapperHelpers exprMapper =
return
$
tf
rs'
return
$
tf
rs'
typeMapper
=
traverseNestedTypesM
typeMapper'
typeMapper
=
traverseNestedTypesM
typeMapper'
declMapper
(
Parameter
t
x
e
)
=
do
maybeTypeMapper
Nothing
=
return
Nothing
t'
<-
typeMapper
t
maybeTypeMapper
(
Just
t
)
=
e'
<-
exprMapper
e
typeMapper
t
>>=
return
.
Just
return
$
Parameter
t'
x
e'
declMapper
(
Localparam
t
x
e
)
=
do
declMapper
(
Param
s
t
x
e
)
=
do
t'
<-
typeMapper
t
t'
<-
typeMapper
t
e'
<-
exprMapper
e
e'
<-
exprMapper
e
return
$
Localparam
t'
x
e'
return
$
Param
s
t'
x
e'
declMapper
(
ParamType
s
x
mt
)
=
do
mt'
<-
maybeTypeMapper
mt
return
$
ParamType
s
x
mt'
declMapper
(
Variable
d
t
x
a
me
)
=
do
declMapper
(
Variable
d
t
x
a
me
)
=
do
t'
<-
typeMapper
t
t'
<-
typeMapper
t
a'
<-
mapM
rangeMapper
a
a'
<-
mapM
rangeMapper
a
...
@@ -820,15 +823,17 @@ traverseTypesM mapper item =
...
@@ -820,15 +823,17 @@ traverseTypesM mapper item =
traverseExprsM
(
traverseNestedExprsM
exprMapper
)
traverseExprsM
(
traverseNestedExprsM
exprMapper
)
where
where
fullMapper
=
traverseNestedTypesM
mapper
fullMapper
=
traverseNestedTypesM
mapper
maybeMapper
Nothing
=
return
Nothing
maybeMapper
(
Just
t
)
=
fullMapper
t
>>=
return
.
Just
exprMapper
(
Cast
(
Left
t
)
e
)
=
exprMapper
(
Cast
(
Left
t
)
e
)
=
fullMapper
t
>>=
\
t'
->
return
$
Cast
(
Left
t'
)
e
fullMapper
t
>>=
\
t'
->
return
$
Cast
(
Left
t'
)
e
exprMapper
(
Bits
(
Left
t
))
=
exprMapper
(
Bits
(
Left
t
))
=
fullMapper
t
>>=
return
.
Bits
.
Left
fullMapper
t
>>=
return
.
Bits
.
Left
exprMapper
other
=
return
other
exprMapper
other
=
return
other
declMapper
(
Param
eter
t
x
e
)
=
declMapper
(
Param
s
t
x
e
)
=
fullMapper
t
>>=
\
t'
->
return
$
Param
eter
t'
x
e
fullMapper
t
>>=
\
t'
->
return
$
Param
s
t'
x
e
declMapper
(
Localparam
t
x
e
)
=
declMapper
(
ParamType
s
x
mt
)
=
fullMapper
t
>>=
\
t'
->
return
$
Localparam
t'
x
e
maybeMapper
mt
>>=
\
mt'
->
return
$
ParamType
s
x
mt'
declMapper
(
Variable
d
t
x
a
me
)
=
declMapper
(
Variable
d
t
x
a
me
)
=
fullMapper
t
>>=
\
t'
->
return
$
Variable
d
t'
x
a
me
fullMapper
t
>>=
\
t'
->
return
$
Variable
d
t'
x
a
me
miMapper
(
MIPackageItem
(
Typedef
t
x
))
=
miMapper
(
MIPackageItem
(
Typedef
t
x
))
=
...
...
src/Language/SystemVerilog/AST/Decl.hs
View file @
d11e898e
...
@@ -3,11 +3,14 @@
...
@@ -3,11 +3,14 @@
- 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 left-hand sides (aka lvals)
-
- TODO: Normal parameters can be declared with no default valu.
-}
-}
module
Language.SystemVerilog.AST.Decl
module
Language.SystemVerilog.AST.Decl
(
Decl
(
..
)
(
Decl
(
..
)
,
Direction
(
..
)
,
Direction
(
..
)
,
ParamScope
(
..
)
)
where
)
where
import
Text.Printf
(
printf
)
import
Text.Printf
(
printf
)
...
@@ -17,15 +20,15 @@ import Language.SystemVerilog.AST.Type (Type, Identifier)
...
@@ -17,15 +20,15 @@ import Language.SystemVerilog.AST.Type (Type, Identifier)
import
Language.SystemVerilog.AST.Expr
(
Expr
,
Range
,
showRanges
,
showAssignment
)
import
Language.SystemVerilog.AST.Expr
(
Expr
,
Range
,
showRanges
,
showAssignment
)
data
Decl
data
Decl
=
Param
eter
Type
Identifier
Expr
=
Param
ParamScope
Type
Identifier
Expr
|
Localparam
Type
Identifier
Expr
|
ParamType
ParamScope
Identifier
(
Maybe
Type
)
|
Variable
Direction
Type
Identifier
[
Range
]
(
Maybe
Expr
)
|
Variable
Direction
Type
Identifier
[
Range
]
(
Maybe
Expr
)
deriving
Eq
deriving
Eq
instance
Show
Decl
where
instance
Show
Decl
where
showList
l
_
=
unlines'
$
map
show
l
showList
l
_
=
unlines'
$
map
show
l
show
(
Param
eter
t
x
e
)
=
printf
"parameter %s%s = %s;"
(
showPad
t
)
x
(
show
e
)
show
(
Param
s
t
x
e
)
=
printf
"%s %s%s = %s;"
(
show
s
)
(
showPad
t
)
x
(
show
e
)
show
(
Localparam
t
x
e
)
=
printf
"localparam %s%s = %s;"
(
showPad
t
)
x
(
show
e
)
show
(
ParamType
s
x
mt
)
=
printf
"%s type %s%s;"
(
show
s
)
x
(
showAssignment
mt
)
show
(
Variable
d
t
x
a
me
)
=
printf
"%s%s%s%s%s;"
(
showPad
d
)
(
showPad
t
)
x
(
showRanges
a
)
(
showAssignment
me
)
show
(
Variable
d
t
x
a
me
)
=
printf
"%s%s%s%s%s;"
(
showPad
d
)
(
showPad
t
)
x
(
showRanges
a
)
(
showAssignment
me
)
data
Direction
data
Direction
...
@@ -40,3 +43,12 @@ instance Show Direction where
...
@@ -40,3 +43,12 @@ instance Show Direction where
show
Output
=
"output"
show
Output
=
"output"
show
Inout
=
"inout"
show
Inout
=
"inout"
show
Local
=
""
show
Local
=
""
data
ParamScope
=
Parameter
|
Localparam
deriving
Eq
instance
Show
ParamScope
where
show
Parameter
=
"parameter"
show
Localparam
=
"localparam"
src/Language/SystemVerilog/AST/Expr.hs
View file @
d11e898e
...
@@ -96,7 +96,7 @@ instance Show PartSelectMode where
...
@@ -96,7 +96,7 @@ instance Show PartSelectMode where
show
IndexedPlus
=
"+:"
show
IndexedPlus
=
"+:"
show
IndexedMinus
=
"-:"
show
IndexedMinus
=
"-:"
showAssignment
::
Maybe
Expr
->
String
showAssignment
::
Show
a
=>
Maybe
a
->
String
showAssignment
Nothing
=
""
showAssignment
Nothing
=
""
showAssignment
(
Just
val
)
=
" = "
++
show
val
showAssignment
(
Just
val
)
=
" = "
++
show
val
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
d11e898e
...
@@ -896,10 +896,18 @@ ParameterDecl(delim) :: { [Decl] }
...
@@ -896,10 +896,18 @@ ParameterDecl(delim) :: { [Decl] }
| ParameterDeclKW ParamType DeclAsgns delim { makeParamDecls $1 ($2 ) $3 }
| ParameterDeclKW ParamType DeclAsgns delim { makeParamDecls $1 ($2 ) $3 }
| ParameterDeclKW Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Nothing) $2 $3) $4 }
| ParameterDeclKW Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Nothing) $2 $3) $4 }
| ParameterDeclKW Identifier "::" Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Just $2) $4 $5) $6 }
| ParameterDeclKW Identifier "::" Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Just $2) $4 $5) $6 }
ParameterDeclKW :: { Type -> Identifier -> Expr -> Decl }
| ParameterDeclKW "type" TypeAsgns delim { map (uncurry $ ParamType $1) $3 }
ParameterDeclKW :: { ParamScope }
: "parameter" { Parameter }
: "parameter" { Parameter }
| "localparam" { Localparam }
| "localparam" { Localparam }
TypeAsgns :: { [(Identifier, Maybe Type)] }
: TypeAsgn { [$1] }
| TypeAsgns "," TypeAsgn { $1 ++ [$3] }
TypeAsgn :: { (Identifier, Maybe Type) }
: Identifier "=" Type { ($1, Just $3) }
| Identifier { ($1, Nothing) }
-- TODO: This does not allow for @identifier
-- TODO: This does not allow for @identifier
ClockingEvent :: { Sense }
ClockingEvent :: { Sense }
: "@" "(" Senses ")" { $3 }
: "@" "(" Senses ")" { $3 }
...
@@ -1172,14 +1180,14 @@ toLHS expr =
...
@@ -1172,14 +1180,14 @@ toLHS expr =
++ show expr
++ show expr
makeParamDecls
makeParamDecls
::
(Type -> Identifier -> Expr -> Decl)
::
ParamScope
-> Type
-> Type
-> [(Identifier, Expr, [Range])]
-> [(Identifier, Expr, [Range])]
-> [Decl]
-> [Decl]
makeParamDecls
kw
t items =
makeParamDecls
s
t items =
map mapper items
map mapper items
where
where
(tf, rs) = typeRanges t
(tf, rs) = typeRanges t
mapper (x, e, a) =
kw
(tf $ a ++ rs) x e
mapper (x, e, a) =
Param s
(tf $ a ++ rs) x e
}
}
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