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
737c66a6
Commit
737c66a6
authored
Jul 10, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix default type parameters which depend on other parameters
parent
a83cc380
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
14 deletions
+44
-14
src/Convert/ParamType.hs
+12
-14
test/basic/paramtype_param_default.sv
+17
-0
test/basic/paramtype_param_default.v
+15
-0
No files found.
src/Convert/ParamType.hs
View file @
737c66a6
{-# LANGUAGE TupleSections #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
...
...
@@ -18,7 +19,7 @@ import Language.SystemVerilog.AST
type
MaybeTypeMap
=
Map
.
Map
Identifier
(
Maybe
Type
)
type
Info
=
Map
.
Map
Identifier
([
Identifier
],
MaybeTypeMap
)
type
Instance
=
Map
.
Map
Identifier
Type
type
Instance
=
Map
.
Map
Identifier
(
Type
,
IdentSet
)
type
Instances
=
Set
.
Set
(
Identifier
,
Instance
)
type
IdentSet
=
Set
.
Set
Identifier
...
...
@@ -150,12 +151,10 @@ convert files =
items'
=
map
(
traverseDecls
rewriteDecl
)
items
rewriteDecl
::
Decl
->
Decl
rewriteDecl
(
ParamType
Parameter
x
_
)
=
ParamType
Localparam
x
(
Just
$
typeMap'
Map
.!
x
)
ParamType
Localparam
x
(
Just
$
fst
$
typeMap
Map
.!
x
)
rewriteDecl
other
=
other
explodedTypeMap
=
Map
.
mapWithKey
prepareTypeIdents
typeMap
typeMap'
=
Map
.
map
fst
explodedTypeMap
additionalParamItems
=
concatMap
makeAddedParams
$
Map
.
toList
$
Map
.
map
snd
explodedT
ypeMap
Map
.
toList
$
Map
.
map
snd
t
ypeMap
makeAddedParams
::
(
Identifier
,
IdentSet
)
->
[
ModuleItem
]
makeAddedParams
(
paramName
,
identSet
)
=
...
...
@@ -195,7 +194,7 @@ defaultInstance :: MaybeTypeMap -> Maybe Instance
defaultInstance
maybeTypeMap
=
if
any
isNothing
maybeTypeMap
then
Nothing
else
Just
$
Map
.
map
fromJust
maybeTypeMap
else
Just
$
Map
.
map
((,
Set
.
empty
)
.
fromJust
)
maybeTypeMap
-- generate a "unique" name for a particular module type instance
moduleInstanceName
::
Identifier
->
Instance
->
Identifier
...
...
@@ -282,8 +281,8 @@ convertModuleItemM info (orig @ (Instance m bindings x r p)) =
else
if
any
(
isLeft
.
snd
)
bindings'
then
error
$
"param type resolution left type params: "
++
show
orig
++
" converted to: "
++
show
bindings'
else
if
any
(
not
.
isSimpleType
)
resolvedTypes
then
do
let
defaults
=
Map
.
map
Left
resolvedTypes
else
if
any
(
not
.
isSimpleType
.
fst
)
resolvedTypes
then
do
let
defaults
=
Map
.
map
(
Left
.
fst
)
resolvedTypes
let
bindingsDefaulted
=
Map
.
toList
$
Map
.
union
bindingsMap
defaults
if
isDefaultName
m
||
bindingsDefaulted
==
Map
.
toList
bindingsMap
then
return
$
Instance
m
bindingsNamed
x
r
p
...
...
@@ -305,19 +304,19 @@ convertModuleItemM info (orig @ (Instance m bindings x r p)) =
-- determine the types corresponding to each type parameter
bindingsMap
=
Map
.
fromList
bindingsNamed
resolvedTypes
=
Map
.
mapWithKey
resolveType
maybeTypeMap
resolveType
::
Identifier
->
Maybe
Type
->
Type
resolveType
::
Identifier
->
Maybe
Type
->
(
Type
,
IdentSet
)
resolveType
paramName
defaultType
=
case
(
Map
.
lookup
paramName
bindingsMap
,
defaultType
)
of
(
Nothing
,
Just
t
)
->
t
(
Nothing
,
Just
t
)
->
(
t
,
Set
.
empty
)
(
Nothing
,
Nothing
)
->
error
$
"instantiation "
++
show
orig
++
" is missing a type parameter: "
++
paramName
(
Just
(
Left
t
),
_
)
->
t
(
Just
(
Left
t
),
_
)
->
prepareTypeIdents
paramName
t
(
Just
(
Right
e
),
_
)
->
-- Some types are parsed as expressions because of the
-- ambiguities of defined type names.
case
exprToType
e
of
Just
t
->
t
Just
t
->
prepareTypeIdents
paramName
t
Nothing
->
error
$
"instantiation "
++
show
orig
++
" has expr "
++
show
e
...
...
@@ -328,9 +327,8 @@ convertModuleItemM info (orig @ (Instance m bindings x r p)) =
bindings'
=
filter
(
not
.
isParamType
.
fst
)
bindingsNamed
-- create additional parameters needed to specify existing type params
explodedTypes
=
Map
.
mapWithKey
prepareTypeIdents
resolvedTypes
additionalBindings
=
concatMap
makeAddedParams
$
Map
.
toList
$
Map
.
map
snd
explod
edTypes
Map
.
toList
$
Map
.
map
snd
resolv
edTypes
makeAddedParams
::
(
Identifier
,
IdentSet
)
->
[
ParamBinding
]
makeAddedParams
(
paramName
,
identSet
)
=
map
toTypeParam
idents
++
map
toParam
idents
...
...
test/basic/paramtype_param_default.sv
0 → 100644
View file @
737c66a6
module
M
#(
parameter
ID
=
"Z"
,
parameter
K
=
2
,
parameter
type
T
=
logic
[
K
-
1
:
0
]
)
;
initial
$
display
(
"%s %0d %0d"
,
ID
,
K
,
$
bits
(
T
))
;
endmodule
module
top
;
M
z
()
;
M
#(
.
ID
(
"A"
))
a
()
;
M
#(
.
ID
(
"B"
)
,
.
K
(
3
))
b
()
;
M
#(
.
ID
(
"C"
)
,
.
K
(
4
))
c
()
;
parameter
K
=
4
;
localparam
type
T
=
logic
[
2
*
K
-
1
:
0
]
;
M
#(
.
ID
(
"D"
)
,
.
K
(
4
)
,
.
T
(
T
))
d
()
;
endmodule
test/basic/paramtype_param_default.v
0 → 100644
View file @
737c66a6
module
M
#(
parameter
ID
=
"Z"
,
parameter
K
=
2
,
parameter
T
=
K
)
;
initial
$
display
(
"%s %0d %0d"
,
ID
,
K
,
T
)
;
endmodule
module
top
;
M
z
()
;
M
#(
.
ID
(
"A"
))
a
()
;
M
#(
.
ID
(
"B"
)
,
.
K
(
3
))
b
()
;
M
#(
.
ID
(
"C"
)
,
.
K
(
4
))
c
()
;
M
#(
.
ID
(
"D"
)
,
.
K
(
4
)
,
.
T
(
8
))
d
()
;
endmodule
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