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
eeb2d809
Commit
eeb2d809
authored
Oct 20, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup interface conversion
parent
c936b39b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
43 deletions
+41
-43
src/Convert/Interface.hs
+41
-43
No files found.
src/Convert/Interface.hs
View file @
eeb2d809
...
@@ -32,12 +32,13 @@ convert =
...
@@ -32,12 +32,13 @@ convert =
collectDesc
(
orig
@
(
Part
_
False
kw
_
name
ports
items
))
=
do
collectDesc
(
orig
@
(
Part
_
False
kw
_
name
ports
items
))
=
do
if
kw
==
Interface
if
kw
==
Interface
then
tell
(
Map
.
singleton
name
(
ports
,
items
),
Map
.
empty
)
then
tell
(
Map
.
singleton
name
(
ports
,
items
),
Map
.
empty
)
else
collectModuleItemsM
(
collectDeclsM
$
collectDecl
name
)
orig
else
collectModuleItemsM
(
collectDeclsM
collectDecl
)
orig
where
collectDecl
::
Decl
->
Writer
(
Interfaces
,
Modules
)
()
collectDecl
(
Variable
_
t
ident
_
_
)
=
tell
(
Map
.
empty
,
Map
.
singleton
(
name
,
ident
)
t
)
collectDecl
_
=
return
()
collectDesc
_
=
return
()
collectDesc
_
=
return
()
collectDecl
::
Identifier
->
Decl
->
Writer
(
Interfaces
,
Modules
)
()
collectDecl
name
(
Variable
_
t
ident
_
_
)
=
do
tell
(
Map
.
empty
,
Map
.
singleton
(
name
,
ident
)
t
)
collectDecl
_
_
=
return
()
isInterface
::
Description
->
Bool
isInterface
::
Description
->
Bool
isInterface
(
Part
_
False
Interface
_
_
_
_
)
=
True
isInterface
(
Part
_
False
Interface
_
_
_
_
)
=
True
isInterface
_
=
False
isInterface
_
=
False
...
@@ -61,7 +62,7 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
...
@@ -61,7 +62,7 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
case
t
of
case
t
of
InterfaceT
interfaceName
(
Just
modportName
)
[]
->
InterfaceT
interfaceName
(
Just
modportName
)
[]
->
tell
(
Map
.
empty
,
Map
.
singleton
ident
modportDecls
)
tell
(
Map
.
empty
,
Map
.
singleton
ident
modportDecls
)
where
Just
modportDecls
=
lookupModport
Nothing
interfaceName
modportName
where
Just
modportDecls
=
lookupModport
interfaceName
modportName
_
->
return
()
_
->
return
()
collectInterface
(
Instance
part
_
ident
Nothing
_
)
=
collectInterface
(
Instance
part
_
ident
Nothing
_
)
=
if
Map
.
member
part
interfaces
if
Map
.
member
part
interfaces
...
@@ -71,6 +72,7 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
...
@@ -71,6 +72,7 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
mapInterface
::
ModuleItem
->
ModuleItem
mapInterface
::
ModuleItem
->
ModuleItem
mapInterface
(
orig
@
(
MIPackageItem
(
Decl
(
Variable
Local
t
ident
_
_
))))
=
mapInterface
(
orig
@
(
MIPackageItem
(
Decl
(
Variable
Local
t
ident
_
_
))))
=
-- expand instantiation of a modport
case
Map
.
lookup
ident
modports
of
case
Map
.
lookup
ident
modports
of
Just
modportDecls
->
Generate
$
Just
modportDecls
->
Generate
$
map
(
GenModuleItem
.
MIPackageItem
.
Decl
.
mapper
)
map
(
GenModuleItem
.
MIPackageItem
.
Decl
.
mapper
)
...
@@ -83,8 +85,10 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
...
@@ -83,8 +85,10 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
Variable
dir
mpt
(
ident
++
"_"
++
port
)
mprs
Nothing
Variable
dir
mpt
(
ident
++
"_"
++
port
)
mprs
Nothing
where
(
mpt
,
mprs
)
=
lookupType
interfaceItems
(
fromJust
expr
)
where
(
mpt
,
mprs
)
=
lookupType
interfaceItems
(
fromJust
expr
)
mapInterface
(
Instance
part
params
ident
Nothing
instancePorts
)
=
mapInterface
(
Instance
part
params
ident
Nothing
instancePorts
)
=
-- expand modport port bindings
case
Map
.
lookup
part
interfaces
of
case
Map
.
lookup
part
interfaces
of
Just
interface
->
Just
interface
->
-- inline instantiation of an interface
Generate
$
map
GenModuleItem
$
Generate
$
map
GenModuleItem
$
inlineInterface
interface
(
ident
,
params
,
expandedPorts
)
inlineInterface
interface
(
ident
,
params
,
expandedPorts
)
Nothing
->
Instance
part
params
ident
Nothing
expandedPorts
Nothing
->
Instance
part
params
ident
Nothing
expandedPorts
...
@@ -96,59 +100,57 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
...
@@ -96,59 +100,57 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
mapInterface
other
=
other
mapInterface
other
=
other
convertTF
::
[
Decl
]
->
ModuleItem
->
ModuleItem
convertTF
::
[
Decl
]
->
ModuleItem
->
ModuleItem
convertTF
decls
orig
=
convertTF
decls
=
traverseExprs
(
traverseNestedExprs
$
convertExpr
its
mps
)
$
traverseExprs
(
traverseNestedExprs
$
convertExpr
its
mps
)
.
traverseLHSs
(
traverseNestedLHSs
$
convertLHS
its
mps
)
$
traverseLHSs
(
traverseNestedLHSs
$
convertLHS
its
mps
)
orig
where
where
locals
=
Set
.
fromList
$
mapMaybe
declVarIdent
decls
locals
=
Set
.
fromList
$
mapMaybe
declVarIdent
decls
its
=
Map
.
withoutKeys
instances
locals
its
=
Map
.
withoutKeys
instances
locals
mps
=
Map
.
withoutKeys
modports
locals
mps
=
Map
.
withoutKeys
modports
locals
declVarIdent
::
Decl
->
Maybe
Identifier
declVarIdent
::
Decl
->
Maybe
Identifier
declVarIdent
(
Variable
_
_
x
_
_
)
=
Just
x
declVarIdent
(
Variable
_
_
x
_
_
)
=
Just
x
declVarIdent
_
=
Nothing
declVarIdent
_
=
Nothing
expandPortBinding
::
Identifier
->
PortBinding
->
[
PortBinding
]
expandPortBinding
::
Identifier
->
PortBinding
->
[
PortBinding
]
expandPortBinding
_
(
origBinding
@
(
portName
,
Just
(
Dot
(
Ident
instanceName
)
modportName
)))
=
expandPortBinding
_
(
origBinding
@
(
portName
,
Just
(
Dot
(
Ident
instanceName
)
modportName
)))
=
case
Map
.
lookup
instanceName
instances
of
-- expand instance modport bound to a modport
Nothing
->
if
Map
.
member
instanceName
instances
&&
modportDecls
/=
Nothing
case
Map
.
lookup
instanceName
modports
of
then
map
mapper
$
fromJust
modportDecls
Nothing
->
[
origBinding
]
else
[
origBinding
]
Just
_
->
[(
portName
,
Just
$
Ident
$
instanceName
++
"_"
++
modportName
)]
where
Just
interfaceName
->
interfaceName
=
instances
Map
.!
instanceName
case
modportDecls
of
modportDecls
=
lookupModport
interfaceName
modportName
Nothing
->
[(
portName
,
Just
$
Ident
$
instanceName
++
"_"
++
modportName
)]
mapper
(
_
,
x
,
me
)
=
(
portName
++
"_"
++
x
,
me'
)
Just
decls
->
map
mapper
decls
where
me'
=
fmap
(
traverseNestedExprs
prefixExpr
)
me
where
prefixExpr
::
Expr
->
Expr
modportDecls
=
lookupModport
(
Just
instanceName
)
interfaceName
modportName
prefixExpr
(
Ident
x
)
=
Ident
(
instanceName
++
"_"
++
x
)
mapper
(
_
,
x
,
me
)
=
(
portName
++
"_"
++
x
,
me
)
prefixExpr
other
=
other
expandPortBinding
moduleName
(
origBinding
@
(
portName
,
Just
(
Ident
i
nstanceName
)))
=
expandPortBinding
moduleName
(
origBinding
@
(
portName
,
Just
(
Ident
i
dent
)))
=
case
(
instances
Map
.!?
i
nstanceName
,
modports
Map
.!?
instanceName
)
of
case
(
instances
Map
.!?
i
dent
,
modports
Map
.!?
ident
)
of
(
Nothing
,
Nothing
)
->
[
origBinding
]
(
Nothing
,
Nothing
)
->
[
origBinding
]
(
Just
_
,
_
)
->
(
Just
_
,
_
)
->
map
mapper
modportDecls
-- given entire interface, but just bound to a modport
expandPortBinding
moduleName
(
portName
,
Just
newExpr
)
where
where
InterfaceT
interfaceName
(
Just
modportName
)
[]
=
InterfaceT
_
(
Just
modportName
)
[]
=
modules
Map
.!
(
moduleName
,
portName
)
modules
Map
.!
(
moduleName
,
portName
)
Just
modportDecls
=
lookupModport
(
Just
instanceName
)
interfaceName
modportName
newExpr
=
Dot
(
Ident
ident
)
modportName
mapper
(
_
,
x
,
me
)
=
(
portName
++
"_"
++
x
,
me
)
(
_
,
Just
decls
)
->
(
_
,
Just
decls
)
->
-- modport directly bound to a modport
map
mapper
decls
map
mapper
decls
where
mapper
(
_
,
x
,
_
)
=
where
mapper
(
_
,
x
,
_
)
=
(
portName
++
"_"
++
x
(
portName
++
"_"
++
x
,
Just
$
Ident
$
instanceName
++
"_"
++
x
)
,
Just
$
Dot
(
Ident
ident
)
x
)
expandPortBinding
_
other
=
[
other
]
expandPortBinding
_
other
=
[
other
]
lookupModport
::
Maybe
Identifier
->
Identifier
->
Identifier
->
Maybe
[
ModportDecl
]
lookupModport
::
Identifier
->
Identifier
->
Maybe
[
ModportDecl
]
lookupModport
in
stanceName
in
terfaceName
=
lookupModport
interfaceName
=
if
Map
.
member
interfaceName
interfaces
if
Map
.
member
interfaceName
interfaces
then
(
Map
.!?
)
modportMap
then
(
Map
.!?
)
modportMap
else
error
$
"could not find interface "
++
show
interfaceName
else
error
$
"could not find interface "
++
show
interfaceName
where
where
prefix
=
maybe
""
(
++
"_"
)
instanceName
interfaceItems
=
snd
$
interfaces
Map
.!
interfaceName
interfaceItems
=
map
(
prefixModuleItems
prefix
)
$
snd
$
interfaces
Map
.!
interfaceName
modportMap
=
execWriter
$
modportMap
=
execWriter
$
mapM
(
collectNestedModuleItemsM
collectModport
)
$
mapM
(
collectNestedModuleItemsM
collectModport
)
$
interfaceItems
interfaceItems
...
@@ -167,10 +169,6 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
...
@@ -167,10 +169,6 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
if
Map
.
member
x
mps
||
Map
.
member
x
its
if
Map
.
member
x
mps
||
Map
.
member
x
its
then
LHSIdent
(
x
++
"_"
++
y
)
then
LHSIdent
(
x
++
"_"
++
y
)
else
orig
else
orig
convertLHS
its
mps
(
LHSBit
l
e
)
=
LHSBit
l
(
traverseNestedExprs
(
convertExpr
its
mps
)
e
)
convertLHS
its
mps
(
LHSRange
l
m
(
e1
,
e2
))
=
LHSRange
l
m
(
traverseNestedExprs
(
convertExpr
its
mps
)
e1
,
traverseNestedExprs
(
convertExpr
its
mps
)
e2
)
convertLHS
_
_
other
=
other
convertLHS
_
_
other
=
other
convertPort
::
Identifier
->
[
Identifier
]
convertPort
::
Identifier
->
[
Identifier
]
convertPort
ident
=
convertPort
ident
=
...
...
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