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
06411d70
Commit
06411d70
authored
Oct 20, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support converting interfaces with parameters
parent
5843ef38
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
20 deletions
+49
-20
README.md
+2
-3
src/Convert/Interface.hs
+26
-10
test/basic/interface_func.sv
+9
-4
test/basic/interface_func.v
+12
-3
No files found.
README.md
View file @
06411d70
...
...
@@ -86,9 +86,8 @@ Other:
## Supported Features
sv2v supports most synthesizable SystemVerilog features. Current notable
exceptions include
`export`
, interfaces _with parameter bindings_, and complex
(non-identifier)
`modport`
expressions. Assertions are also supported, but are
simply dropped during conversion.
exceptions include
`export`
and complex (non-identifier)
`modport`
expressions.
Assertions are also supported, but are simply dropped during conversion.
If you find a bug or have a feature request, please create an issue. Preference
will be given to issues which include examples or test cases.
...
...
src/Convert/Interface.hs
View file @
06411d70
...
...
@@ -85,13 +85,8 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
mapInterface
(
Instance
part
params
ident
Nothing
instancePorts
)
=
case
Map
.
lookup
part
interfaces
of
Just
interface
->
-- TODO: Add support for interfaces with parameter bindings.
if
not
$
null
params
then
error
$
"interface instantiations with parameter "
++
"bindings are not yet supported: "
++
show
(
part
,
params
,
ident
)
else
Generate
$
map
GenModuleItem
$
inlineInterface
interface
(
ident
,
expandedPorts
)
Generate
$
map
GenModuleItem
$
inlineInterface
interface
(
ident
,
params
,
expandedPorts
)
Nothing
->
Instance
part
params
ident
Nothing
expandedPorts
where
expandedPorts
=
concatMap
(
expandPortBinding
part
)
instancePorts
mapInterface
(
orig
@
(
MIPackageItem
(
Function
_
_
_
decls
_
)))
=
...
...
@@ -234,8 +229,8 @@ lookupType _ expr =
++
" are not identifiers: "
++
show
expr
-- convert an interface instantiation into a series of equivalent module items
inlineInterface
::
Interface
->
(
Identifier
,
[
PortBinding
])
->
[
ModuleItem
]
inlineInterface
(
ports
,
items
)
(
instanceName
,
instancePorts
)
=
inlineInterface
::
Interface
->
(
Identifier
,
[
P
aramBinding
],
[
P
ortBinding
])
->
[
ModuleItem
]
inlineInterface
(
ports
,
items
)
(
instanceName
,
instanceP
arams
,
instanceP
orts
)
=
(
:
)
(
MIPackageItem
$
Comment
$
"expanded instance: "
++
instanceName
)
$
flip
(
++
)
portBindings
$
map
(
traverseNestedModuleItems
removeModport
)
$
...
...
@@ -243,7 +238,10 @@ inlineInterface (ports, items) (instanceName, instancePorts) =
itemsPrefixed
where
prefix
=
instanceName
++
"_"
itemsPrefixed
=
map
(
prefixModuleItems
prefix
)
$
items
itemsPrefixed
=
map
(
prefixModuleItems
prefix
)
$
map
(
traverseDecls
overrideParam
)
$
items
origInstancePortNames
=
map
fst
instancePorts
instancePortExprs
=
map
snd
instancePorts
instancePortNames
=
...
...
@@ -264,6 +262,24 @@ inlineInterface (ports, items) (instanceName, instancePorts) =
MIPackageItem
$
Comment
$
"removed modport "
++
x
removeModport
other
=
other
instanceParamMap
=
Map
.
fromList
instanceParams
overrideParam
::
Decl
->
Decl
overrideParam
(
Param
Parameter
t
x
e
)
=
case
Map
.
lookup
x
instanceParamMap
of
Nothing
->
Param
Parameter
t
x
e
Just
(
Right
e'
)
->
Param
Parameter
t
x
e'
Just
(
Left
t'
)
->
error
$
"interface param expected expression, found type: "
++
show
t'
overrideParam
(
ParamType
Parameter
x
mt
)
=
case
Map
.
lookup
x
instanceParamMap
of
Nothing
->
ParamType
Parameter
x
mt
Just
(
Left
t'
)
->
ParamType
Parameter
x
(
Just
t'
)
Just
(
Right
e'
)
->
error
$
"interface param expected type, found expression: "
++
show
e'
overrideParam
other
=
other
portBindingItem
::
PortBinding
->
Maybe
ModuleItem
portBindingItem
(
ident
,
Just
expr
)
=
Just
$
if
declDirs
Map
.!
ident
==
Input
...
...
test/basic/interface_func.sv
View file @
06411d70
interface
Foo
;
function
bar
;
parameter
MULTIPLIER
=
7
;
function
integer
bar
;
input
integer
x
;
return
x
*
x
;
return
x
*
x
*
MULTIPLIER
;
endfunction
endinterface
module
top
;
Foo
foo
()
;
initial
$
display
(
foo
.
bar
(
3
))
;
Foo
foo_1
()
;
Foo
#(
.
MULTIPLIER
(
8
))
foo_2
()
;
initial
begin
$
display
(
foo_1
.
bar
(
3
))
;
$
display
(
foo_2
.
bar
(
3
))
;
end
endmodule
test/basic/interface_func.v
View file @
06411d70
module
top
;
function
bar
;
localparam
MULTIPLIER_1
=
7
;
localparam
MULTIPLIER_2
=
8
;
function
integer
bar_1
;
input
integer
x
;
bar
=
x
*
x
;
bar
_1
=
x
*
x
*
MULTIPLIER_1
;
endfunction
initial
$
display
(
bar
(
3
))
;
function
integer
bar_2
;
input
integer
x
;
bar_2
=
x
*
x
*
MULTIPLIER_2
;
endfunction
initial
begin
$
display
(
bar_1
(
3
))
;
$
display
(
bar_2
(
3
))
;
end
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