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
e42fbfa2
Commit
e42fbfa2
authored
Sep 16, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restructure scoper run and eval interface
parent
e169c907
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
113 deletions
+81
-113
src/Convert/Cast.hs
+3
-4
src/Convert/HierConst.hs
+3
-2
src/Convert/Interface.hs
+7
-9
src/Convert/Logic.hs
+7
-7
src/Convert/Package.hs
+7
-5
src/Convert/Scoper.hs
+48
-83
src/Convert/UnpackedArray.hs
+6
-3
No files found.
src/Convert/Cast.hs
View file @
e42fbfa2
...
@@ -41,11 +41,10 @@ convert :: [AST] -> [AST]
...
@@ -41,11 +41,10 @@ convert :: [AST] -> [AST]
convert
=
map
$
traverseDescriptions
convertDescription
convert
=
map
$
traverseDescriptions
convertDescription
convertDescription
::
Description
->
Description
convertDescription
::
Description
->
Description
convertDescription
description
=
convertDescription
=
traverseModuleItems
dropDuplicateCaster
$
traverseModuleItems
dropDuplicateCaster
.
evalScoper
.
scopePart
scoper
partScoper
where
scoper
=
scopeModuleItem
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
description
type
SC
=
Scoper
()
type
SC
=
Scoper
()
...
...
src/Convert/HierConst.hs
View file @
e42fbfa2
...
@@ -37,11 +37,12 @@ convertDescription (Part attrs extern kw lifetime name ports items) =
...
@@ -37,11 +37,12 @@ convertDescription (Part attrs extern kw lifetime name ports items) =
then
items'
then
items'
else
map
expand
items'
else
map
expand
items'
where
where
(
items'
,
mapping
)
=
runScoper
traverseDeclM
(
items'
,
mapping
)
=
runScoper
$
scopeModuleItems
scoper
name
items
scoper
=
scopeModuleItem
traverseDeclM
(
traverseExprsM
traverseExprM
)
(
traverseExprsM
traverseExprM
)
(
traverseGenItemExprsM
traverseExprM
)
(
traverseGenItemExprsM
traverseExprM
)
(
traverseStmtExprsM
traverseExprM
)
(
traverseStmtExprsM
traverseExprM
)
name
items
shadowedParams
=
Map
.
keys
$
Map
.
filter
(
fromLeft
False
)
$
shadowedParams
=
Map
.
keys
$
Map
.
filter
(
fromLeft
False
)
$
extractMapping
mapping
extractMapping
mapping
expand
=
traverseNestedModuleItems
$
expandParam
shadowedParams
expand
=
traverseNestedModuleItems
$
expandParam
shadowedParams
...
...
src/Convert/Interface.hs
View file @
e42fbfa2
...
@@ -63,11 +63,8 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
...
@@ -63,11 +63,8 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
PackageItem
$
Decl
$
CommentDecl
$
PackageItem
$
Decl
$
CommentDecl
$
"removed module with interface ports: "
++
name
"removed module with interface ports: "
++
name
where
where
items'
=
evalScoper
items'
=
evalScoper
$
scopeModuleItems
scoper
name
items
traverseDeclM
traverseModuleItemM
return
return
name
items
scoper
=
scopeModuleItem
traverseDeclM
traverseModuleItemM
return
return
convertNested
=
scopeModuleItemT
traverseDeclM
traverseModuleItemM
return
return
traverseDeclM
::
Decl
->
Scoper
[
ModportDecl
]
Decl
traverseDeclM
::
Decl
->
Scoper
[
ModportDecl
]
Decl
traverseDeclM
decl
=
do
traverseDeclM
decl
=
do
...
@@ -94,7 +91,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
...
@@ -94,7 +91,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
return
instanceItem
return
instanceItem
else
if
partKind
==
Interface
then
else
if
partKind
==
Interface
then
-- inline instantiation of an interface
-- inline instantiation of an interface
convertNested
$
Generate
$
map
GenModuleItem
$
scoper
$
Generate
$
map
GenModuleItem
$
inlineInstance
modports
rs
[]
inlineInstance
modports
rs
[]
partItems
part
instanceName
paramBindings
portBindings
partItems
part
instanceName
paramBindings
portBindings
else
if
null
modportInstances
then
else
if
null
modportInstances
then
...
@@ -108,7 +105,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
...
@@ -108,7 +105,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
++
" has interface ports "
++
" has interface ports "
++
showKeys
modportInstances
++
", but only "
++
showKeys
modportInstances
++
", but only "
++
showKeys
modportBindings
++
" are connected"
++
showKeys
modportBindings
++
" are connected"
else
convertNested
$
Generate
$
map
GenModuleItem
$
else
scoper
$
Generate
$
map
GenModuleItem
$
inlineInstance
modports
rs
modportBindings
partItems
inlineInstance
modports
rs
modportBindings
partItems
part
instanceName
paramBindings
portBindings
part
instanceName
paramBindings
portBindings
where
where
...
@@ -338,12 +335,13 @@ inlineInstance global ranges modportBindings items partName
...
@@ -338,12 +335,13 @@ inlineInstance global ranges modportBindings items partName
wrapInstance
instanceName
items'
wrapInstance
instanceName
items'
:
portBindings
:
portBindings
where
where
items'
=
evalScoper
traverseDeclM
traverseModuleItemM
traverseGenItemM
items'
=
evalScoper
$
scopeModuleItems
scoper
partName
$
traverseStmtM
partName
$
map
(
traverseNestedModuleItems
rewriteItem
)
$
map
(
traverseNestedModuleItems
rewriteItem
)
$
if
null
modportBindings
if
null
modportBindings
then
items
++
[
typeModport
,
dimensionModport
,
bundleModport
]
then
items
++
[
typeModport
,
dimensionModport
,
bundleModport
]
else
items
else
items
scoper
=
scopeModuleItem
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
key
=
shortHash
(
partName
,
instanceName
)
key
=
shortHash
(
partName
,
instanceName
)
...
...
src/Convert/Logic.hs
View file @
e42fbfa2
...
@@ -64,15 +64,15 @@ convert =
...
@@ -64,15 +64,15 @@ convert =
collectDeclDirsM
_
=
return
()
collectDeclDirsM
_
=
return
()
convertDescription
::
Ports
->
Description
->
Description
convertDescription
::
Ports
->
Description
->
Description
convertDescription
ports
description
@
(
Part
_
_
Module
_
_
_
_
)
=
convertDescription
ports
description
=
-- rewrite reg continuous assignments and output port connections
evalScoper
$
scopeModule
conScoper
description
partScoper
(
rewriteDeclM
locations
)
(
traverseModuleItemM
ports
)
return
return
description
where
where
locations
=
execWriter
$
evalScoperT
$
scopePart
locScoper
description
-- write down which vars are procedurally assigned
-- write down which vars are procedurally assigned
locations
=
execWriter
$
partScoperT
locScoper
=
scopeModuleItem
traverseDeclM
return
return
traverseStmtM
traverseDeclM
return
return
traverseStmtM
description
-- rewrite reg continuous assignments and output port connections
convertDescription
_
other
=
other
conScoper
=
scopeModuleItem
(
rewriteDeclM
locations
)
(
traverseModuleItemM
ports
)
return
return
traverseModuleItemM
::
Ports
->
ModuleItem
->
Scoper
Type
ModuleItem
traverseModuleItemM
::
Ports
->
ModuleItem
->
Scoper
Type
ModuleItem
traverseModuleItemM
ports
=
embedScopes
$
traverseModuleItem
ports
traverseModuleItemM
ports
=
embedScopes
$
traverseModuleItem
ports
...
...
src/Convert/Package.hs
View file @
e42fbfa2
...
@@ -226,8 +226,7 @@ explicitImport pkg ident = do
...
@@ -226,8 +226,7 @@ explicitImport pkg ident = do
processItems
::
Identifier
->
Identifier
->
[
ModuleItem
]
processItems
::
Identifier
->
Identifier
->
[
ModuleItem
]
->
PackagesState
(
IdentStateMap
,
[
ModuleItem
])
->
PackagesState
(
IdentStateMap
,
[
ModuleItem
])
processItems
topName
packageName
moduleItems
=
do
processItems
topName
packageName
moduleItems
=
do
(
moduleItems'
,
scopes
)
<-
runScoperT
(
moduleItems'
,
scopes
)
<-
runScoperT
$
scopeModuleItems
scoper
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
topName
(
reorderItems
moduleItems
)
topName
(
reorderItems
moduleItems
)
let
rawIdents
=
extractMapping
scopes
let
rawIdents
=
extractMapping
scopes
externalIdentMaps
<-
mapM
(
resolveExportMI
rawIdents
)
moduleItems
externalIdentMaps
<-
mapM
(
resolveExportMI
rawIdents
)
moduleItems
...
@@ -239,6 +238,9 @@ processItems topName packageName moduleItems = do
...
@@ -239,6 +238,9 @@ processItems topName packageName moduleItems = do
else
exports
else
exports
seq
exports
return
(
exports'
,
moduleItems'
)
seq
exports
return
(
exports'
,
moduleItems'
)
where
where
scoper
=
scopeModuleItem
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
-- produces partial mappings of exported identifiers, while also
-- produces partial mappings of exported identifiers, while also
-- checking the validity of the exports
-- checking the validity of the exports
resolveExportMI
::
IdentStateMap
->
ModuleItem
->
PackagesState
IdentStateMap
resolveExportMI
::
IdentStateMap
->
ModuleItem
->
PackagesState
IdentStateMap
...
@@ -677,9 +679,9 @@ addUsedPIs :: ModuleItem -> (ModuleItem, Idents)
...
@@ -677,9 +679,9 @@ addUsedPIs :: ModuleItem -> (ModuleItem, Idents)
addUsedPIs
item
=
addUsedPIs
item
=
(
item
,
usedPIs
)
(
item
,
usedPIs
)
where
where
usedPIs
=
execWriter
$
evalScoperT
usedPIs
=
execWriter
$
evalScoperT
$
scoper
item
writeDeclIdents
writeModuleItemIdents
writeGenItemIdents
writeStmt
Idents
scoper
=
scopeModuleItem
writeDeclIdents
writeModuleItem
Idents
""
[
item
]
writeGenItemIdents
writeStmtIdents
type
IdentWriter
=
ScoperT
()
(
Writer
Idents
)
type
IdentWriter
=
ScoperT
()
(
Writer
Idents
)
...
...
src/Convert/Scoper.hs
View file @
e42fbfa2
...
@@ -30,7 +30,10 @@ module Convert.Scoper
...
@@ -30,7 +30,10 @@ module Convert.Scoper
,
runScoper
,
runScoper
,
runScoperT
,
runScoperT
,
partScoper
,
partScoper
,
partScoperT
,
scopeModuleItem
,
scopeModuleItems
,
scopePart
,
scopeModule
,
accessesToExpr
,
accessesToExpr
,
replaceInType
,
replaceInType
,
replaceInExpr
,
replaceInExpr
...
@@ -60,13 +63,11 @@ module Convert.Scoper
...
@@ -60,13 +63,11 @@ module Convert.Scoper
,
loopVarDepthM
,
loopVarDepthM
,
lookupLocalIdent
,
lookupLocalIdent
,
lookupLocalIdentM
,
lookupLocalIdentM
,
scopeModuleItemT
,
Replacements
,
Replacements
,
LookupResult
,
LookupResult
)
where
)
where
import
Control.Monad.State.Strict
import
Control.Monad.State.Strict
import
Data.Functor.Identity
(
runIdentity
)
import
Data.List
(
findIndices
,
partition
)
import
Data.List
(
findIndices
,
partition
)
import
Data.Maybe
(
isNothing
)
import
Data.Maybe
(
isNothing
)
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Map.Strict
as
Map
...
@@ -369,75 +370,57 @@ loopVarDepth scopes x =
...
@@ -369,75 +370,57 @@ loopVarDepth scopes x =
loopVarDepthM
::
Monad
m
=>
Identifier
->
ScoperT
a
m
(
Maybe
Int
)
loopVarDepthM
::
Monad
m
=>
Identifier
->
ScoperT
a
m
(
Maybe
Int
)
loopVarDepthM
=
embedScopes
loopVarDepth
loopVarDepthM
=
embedScopes
loopVarDepth
evalScoper
scopeModuleItems
::
MapperM
(
Scoper
a
)
Decl
::
Monad
m
->
MapperM
(
Scoper
a
)
ModuleItem
=>
MapperM
(
ScoperT
a
m
)
ModuleItem
->
MapperM
(
Scoper
a
)
GenItem
->
MapperM
(
Scoper
a
)
Stmt
->
Identifier
->
[
ModuleItem
]
->
[
ModuleItem
]
evalScoper
declMapper
moduleItemMapper
genItemMapper
stmtMapper
topName
items
=
runIdentity
$
evalScoperT
declMapper
moduleItemMapper
genItemMapper
stmtMapper
topName
items
evalScoperT
::
forall
a
m
.
Monad
m
=>
MapperM
(
ScoperT
a
m
)
Decl
->
MapperM
(
ScoperT
a
m
)
ModuleItem
->
MapperM
(
ScoperT
a
m
)
GenItem
->
MapperM
(
ScoperT
a
m
)
Stmt
->
Identifier
->
Identifier
->
[
ModuleItem
]
->
MapperM
(
ScoperT
a
m
)
[
ModuleItem
]
->
m
[
ModuleItem
]
scopeModuleItems
moduleItemMapper
topName
items
=
do
evalScoperT
declMapper
moduleItemMapper
genItemMapper
stmtMapper
topName
items
=
do
enterScope
topName
""
(
items'
,
_
)
<-
runScoperT
items'
<-
mapM
moduleItemMapper
items
declMapper
moduleItemMapper
genItemMapper
stmtMapper
exitScope
topName
items
return
items'
return
items'
runScoper
scopeModule
::
Monad
m
::
MapperM
(
Scoper
a
)
Decl
=>
MapperM
(
ScoperT
a
m
)
ModuleItem
->
MapperM
(
Scoper
a
)
ModuleItem
->
MapperM
(
ScoperT
a
m
)
Description
->
MapperM
(
Scoper
a
)
GenItem
scopeModule
moduleItemMapper
description
->
MapperM
(
Scoper
a
)
Stmt
|
Part
_
_
Module
_
_
_
_
<-
description
=
->
Identifier
scopePart
moduleItemMapper
description
->
[
ModuleItem
]
|
otherwise
=
return
description
->
([
ModuleItem
],
Scopes
a
)
runScoper
declMapper
moduleItemMapper
genItemMapper
stmtMapper
topName
items
=
runIdentity
$
runScoperT
declMapper
moduleItemMapper
genItemMapper
stmtMapper
topName
items
runScoperT
scopePart
::
Monad
m
::
forall
a
m
.
Monad
m
=>
MapperM
(
ScoperT
a
m
)
ModuleItem
=>
MapperM
(
ScoperT
a
m
)
Decl
->
MapperM
(
ScoperT
a
m
)
Description
->
MapperM
(
ScoperT
a
m
)
ModuleItem
scopePart
moduleItemMapper
description
->
MapperM
(
ScoperT
a
m
)
GenItem
|
Part
attrs
extern
kw
liftetime
name
ports
items
<-
description
=
->
MapperM
(
ScoperT
a
m
)
Stmt
scopeModuleItems
moduleItemMapper
name
items
>>=
->
Identifier
return
.
Part
attrs
extern
kw
liftetime
name
ports
->
[
ModuleItem
]
|
otherwise
=
return
description
->
m
([
ModuleItem
],
Scopes
a
)
runScoperT
declMapper
moduleItemMapper
genItemMapper
stmtMapper
topName
items
=
runStateT
operation
initialState
where
operation
::
ScoperT
a
m
[
ModuleItem
]
operation
=
do
enterScope
topName
""
mapM
wrappedModuleItemMapper
items
initialState
=
Scopes
[]
Map
.
empty
[]
[]
[]
wrappedModuleItemMapper
=
scopeModuleItemT
evalScoper
::
Scoper
a
x
->
x
declMapper
moduleItemMapper
genItemMapper
stmtMapper
evalScoper
=
flip
evalState
initialState
evalScoperT
::
Monad
m
=>
ScoperT
a
m
x
->
m
x
evalScoperT
=
flip
evalStateT
initialState
runScoper
::
Scoper
a
x
->
(
x
,
Scopes
a
)
runScoper
=
flip
runState
initialState
scopeModuleItemT
runScoperT
::
Monad
m
=>
ScoperT
a
m
x
->
m
(
x
,
Scopes
a
)
runScoperT
=
flip
runStateT
initialState
initialState
::
Scopes
a
initialState
=
Scopes
[]
Map
.
empty
[]
[]
[]
scopeModuleItem
::
forall
a
m
.
Monad
m
::
forall
a
m
.
Monad
m
=>
MapperM
(
ScoperT
a
m
)
Decl
=>
MapperM
(
ScoperT
a
m
)
Decl
->
MapperM
(
ScoperT
a
m
)
ModuleItem
->
MapperM
(
ScoperT
a
m
)
ModuleItem
->
MapperM
(
ScoperT
a
m
)
GenItem
->
MapperM
(
ScoperT
a
m
)
GenItem
->
MapperM
(
ScoperT
a
m
)
Stmt
->
MapperM
(
ScoperT
a
m
)
Stmt
->
ModuleItem
->
MapperM
(
ScoperT
a
m
)
ModuleItem
->
ScoperT
a
m
ModuleItem
scopeModuleItem
declMapper
moduleItemMapper
genItemMapper
stmtMapper
=
scopeModuleItemT
declMapper
moduleItemMapper
genItemMapper
stmtMapper
=
wrappedModuleItemMapper
wrappedModuleItemMapper
where
where
fullStmtMapper
::
Stmt
->
ScoperT
a
m
Stmt
fullStmtMapper
::
Stmt
->
ScoperT
a
m
Stmt
...
@@ -606,26 +589,8 @@ partScoper
...
@@ -606,26 +589,8 @@ partScoper
->
MapperM
(
Scoper
a
)
ModuleItem
->
MapperM
(
Scoper
a
)
ModuleItem
->
MapperM
(
Scoper
a
)
GenItem
->
MapperM
(
Scoper
a
)
GenItem
->
MapperM
(
Scoper
a
)
Stmt
->
MapperM
(
Scoper
a
)
Stmt
->
Description
->
Mapper
Description
->
Description
partScoper
declMapper
moduleItemMapper
genItemMapper
stmtMapper
=
partScoper
declMapper
moduleItemMapper
genItemMapper
stmtMapper
part
=
evalScoper
.
scopePart
scoper
runIdentity
$
partScoperT
where
scoper
=
scopeModuleItem
declMapper
moduleItemMapper
genItemMapper
stmtMapper
part
partScoperT
::
Monad
m
=>
MapperM
(
ScoperT
a
m
)
Decl
->
MapperM
(
ScoperT
a
m
)
ModuleItem
->
MapperM
(
ScoperT
a
m
)
GenItem
->
MapperM
(
ScoperT
a
m
)
Stmt
->
Description
->
m
Description
partScoperT
declMapper
moduleItemMapper
genItemMapper
stmtMapper
=
mapper
where
operation
=
evalScoperT
declMapper
moduleItemMapper
genItemMapper
stmtMapper
declMapper
moduleItemMapper
genItemMapper
stmtMapper
mapper
(
Part
attrs
extern
kw
liftetime
name
ports
items
)
=
do
items'
<-
operation
name
items
return
$
Part
attrs
extern
kw
liftetime
name
ports
items'
mapper
description
=
return
description
src/Convert/UnpackedArray.hs
View file @
e42fbfa2
...
@@ -27,11 +27,14 @@ convert = map $ traverseDescriptions convertDescription
...
@@ -27,11 +27,14 @@ convert = map $ traverseDescriptions convertDescription
convertDescription
::
Description
->
Description
convertDescription
::
Description
->
Description
convertDescription
description
@
(
Part
_
_
Module
_
_
ports
_
)
=
convertDescription
description
@
(
Part
_
_
Module
_
_
ports
_
)
=
partScoper
(
rewriteDeclM
locations
)
return
return
return
description
evalScoper
$
scopePart
conScoper
description
where
where
locations
=
execState
(
operation
description
)
Map
.
empty
locations
=
execState
operation
=
partScoperT
(
evalScoperT
$
scopePart
locScoper
description
)
Map
.
empty
locScoper
=
scopeModuleItem
(
traverseDeclM
ports
)
traverseModuleItemM
return
traverseStmtM
(
traverseDeclM
ports
)
traverseModuleItemM
return
traverseStmtM
conScoper
=
scopeModuleItem
(
rewriteDeclM
locations
)
return
return
return
convertDescription
other
=
other
convertDescription
other
=
other
-- tracks multi-dimensional unpacked array declarations
-- tracks multi-dimensional unpacked array declarations
...
...
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