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
bd1c0723
Commit
bd1c0723
authored
Jun 20, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
experimenting with monad helpers
parent
4026ae8f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
47 deletions
+42
-47
src/Convert/Interface.hs
+11
-16
src/Convert/MultiplePacked.hs
+4
-4
src/Convert/Package.hs
+7
-7
src/Convert/Struct.hs
+9
-9
src/Convert/Traverse.hs
+3
-3
src/Convert/UnpackedArray.hs
+8
-8
No files found.
src/Convert/Interface.hs
View file @
bd1c0723
...
@@ -41,10 +41,9 @@ convert =
...
@@ -41,10 +41,9 @@ convert =
-- we can only collect/map non-extern interfaces
-- we can only collect/map non-extern interfaces
collectDesc
::
Description
->
Writer
(
Interfaces
,
Modules
)
()
collectDesc
::
Description
->
Writer
(
Interfaces
,
Modules
)
()
collectDesc
(
orig
@
(
Part
_
False
kw
_
name
ports
items
))
=
do
collectDesc
(
orig
@
(
Part
_
False
kw
_
name
ports
items
))
=
do
if
kw
==
Interface
then
if
kw
==
Interface
if
all
fullyResolved
items
then
when
(
all
fullyResolved
items
)
$
then
tell
(
Map
.
singleton
name
(
ports
,
items
),
Map
.
empty
)
tell
(
Map
.
singleton
name
(
ports
,
items
),
Map
.
empty
)
else
return
()
else
tell
(
Map
.
empty
,
Map
.
singleton
name
(
params
,
decls
))
else
tell
(
Map
.
empty
,
Map
.
singleton
name
(
params
,
decls
))
where
where
params
=
map
fst
$
parameters
items
params
=
map
fst
$
parameters
items
...
@@ -85,13 +84,11 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
...
@@ -85,13 +84,11 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
collectInstanceM
(
MIPackageItem
(
Decl
(
Variable
_
t
ident
_
_
)))
=
collectInstanceM
(
MIPackageItem
(
Decl
(
Variable
_
t
ident
_
_
)))
=
case
t
of
case
t
of
InterfaceT
interfaceName
(
Just
modportName
)
[]
->
InterfaceT
interfaceName
(
Just
modportName
)
[]
->
if
Map
.
member
interfaceName
interfaces
when
(
Map
.
member
interfaceName
interfaces
)
$
then
writeModport
interfaceName
modportName
writeModport
interfaceName
modportName
else
return
()
Alias
Nothing
interfaceName
[]
->
Alias
Nothing
interfaceName
[]
->
if
Map
.
member
interfaceName
interfaces
when
(
Map
.
member
interfaceName
interfaces
)
$
then
writeModport
interfaceName
""
writeModport
interfaceName
""
else
return
()
_
->
return
()
_
->
return
()
where
where
writeModport
::
Identifier
->
Identifier
->
writeModport
::
Identifier
->
Identifier
->
...
@@ -100,9 +97,8 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
...
@@ -100,9 +97,8 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
tell
(
Map
.
empty
,
Map
.
singleton
ident
modport
)
tell
(
Map
.
empty
,
Map
.
singleton
ident
modport
)
where
modport
=
(
interfaceName
,
modportName
)
where
modport
=
(
interfaceName
,
modportName
)
collectInstanceM
(
Instance
part
_
ident
[]
_
)
=
collectInstanceM
(
Instance
part
_
ident
[]
_
)
=
if
Map
.
member
part
interfaces
when
(
Map
.
member
part
interfaces
)
$
then
tell
(
Map
.
singleton
ident
part
,
Map
.
empty
)
tell
(
Map
.
singleton
ident
part
,
Map
.
empty
)
else
return
()
collectInstanceM
_
=
return
()
collectInstanceM
_
=
return
()
expandInterface
::
ModuleItem
->
ModuleItem
expandInterface
::
ModuleItem
->
ModuleItem
...
@@ -440,9 +436,8 @@ inlineInterface (ports, items) (instanceName, instanceParams, instancePorts) =
...
@@ -440,9 +436,8 @@ inlineInterface (ports, items) (instanceName, instanceParams, instancePorts) =
mapM
(
collectDeclsM
collectDeclDir
)
itemsPrefixed
mapM
(
collectDeclsM
collectDeclDir
)
itemsPrefixed
collectDeclDir
::
Decl
->
Writer
(
Map
.
Map
Identifier
Direction
)
()
collectDeclDir
::
Decl
->
Writer
(
Map
.
Map
Identifier
Direction
)
()
collectDeclDir
(
Variable
dir
_
ident
_
_
)
=
collectDeclDir
(
Variable
dir
_
ident
_
_
)
=
if
dir
/=
Local
when
(
dir
/=
Local
)
$
then
tell
$
Map
.
singleton
ident
dir
tell
$
Map
.
singleton
ident
dir
else
return
()
collectDeclDir
_
=
return
()
collectDeclDir
_
=
return
()
toLHS
::
Expr
->
LHS
toLHS
::
Expr
->
LHS
...
...
src/Convert/MultiplePacked.hs
View file @
bd1c0723
...
@@ -118,13 +118,13 @@ combineRanges r1 r2 = r
...
@@ -118,13 +118,13 @@ combineRanges r1 r2 = r
(
BinOp
Sub
lower
(
Number
"1"
))
(
BinOp
Sub
lower
(
Number
"1"
))
traverseModuleItemM
::
ModuleItem
->
State
Info
ModuleItem
traverseModuleItemM
::
ModuleItem
->
State
Info
ModuleItem
traverseModuleItemM
item
=
traverseModuleItemM
=
traverseLHSsM
traverseLHSM
item
>>=
traverseLHSsM
traverseLHSM
>=>
traverseExprsM
traverseExprM
traverseExprsM
traverseExprM
traverseStmtM
::
Stmt
->
State
Info
Stmt
traverseStmtM
::
Stmt
->
State
Info
Stmt
traverseStmtM
stmt
=
traverseStmtM
=
traverseStmtLHSsM
traverseLHSM
stmt
>>=
traverseStmtLHSsM
traverseLHSM
>=>
traverseStmtExprsM
traverseExprM
traverseStmtExprsM
traverseExprM
traverseExprM
::
Expr
->
State
Info
Expr
traverseExprM
::
Expr
->
State
Info
Expr
...
...
src/Convert/Package.hs
View file @
bd1c0723
...
@@ -123,13 +123,13 @@ prefixPackageItem packageName idents item =
...
@@ -123,13 +123,13 @@ prefixPackageItem packageName idents item =
convertLHSM
(
LHSIdent
x
)
=
prefixM
x
>>=
return
.
LHSIdent
convertLHSM
(
LHSIdent
x
)
=
prefixM
x
>>=
return
.
LHSIdent
convertLHSM
other
=
return
other
convertLHSM
other
=
return
other
convertModuleItemM
x
=
return
x
>>
=
convertModuleItemM
=
(
traverseTypesM
convertTypeM
)
>>=
traverseTypesM
convertTypeM
>=>
(
traverseExprsM
$
traverseNestedExprsM
convertExprM
)
>>=
traverseExprsM
(
traverseNestedExprsM
convertExprM
)
>=>
(
traverseLHSsM
$
traverseNestedLHSsM
convertLHSM
)
traverseLHSsM
(
traverseNestedLHSsM
convertLHSM
)
convertStmtM
stmt
=
return
stmt
>>
=
convertStmtM
=
(
traverseStmtExprsM
$
traverseNestedExprsM
convertExprM
)
>>=
traverseStmtExprsM
(
traverseNestedExprsM
convertExprM
)
>=>
(
traverseStmtLHSsM
$
traverseNestedLHSsM
convertLHSM
)
traverseStmtLHSsM
(
traverseNestedLHSsM
convertLHSM
)
MIPackageItem
item''
=
MIPackageItem
item''
=
evalState
evalState
...
...
src/Convert/Struct.hs
View file @
bd1c0723
...
@@ -52,21 +52,21 @@ convertDescription (description @ Part{}) =
...
@@ -52,21 +52,21 @@ convertDescription (description @ Part{}) =
let
MIPackageItem
(
Decl
decl''
)
=
res
let
MIPackageItem
(
Decl
decl''
)
=
res
return
decl''
return
decl''
traverseModuleItemM
::
ModuleItem
->
State
Types
ModuleItem
traverseModuleItemM
::
ModuleItem
->
State
Types
ModuleItem
traverseModuleItemM
item
=
traverseModuleItemM
=
traverseLHSsM
traverseLHSM
item
>>=
traverseLHSsM
traverseLHSM
>=>
traverseExprsM
traverseExprM
>>=
traverseExprsM
traverseExprM
>=>
traverseAsgnsM
traverseAsgnM
traverseAsgnsM
traverseAsgnM
traverseStmtM
::
Stmt
->
State
Types
Stmt
traverseStmtM
::
Stmt
->
State
Types
Stmt
traverseStmtM
(
Subroutine
expr
args
)
=
do
traverseStmtM
(
Subroutine
expr
args
)
=
do
stateTypes
<-
get
stateTypes
<-
get
let
stmt'
=
Subroutine
expr
$
convertCall
let
stmt'
=
Subroutine
expr
$
convertCall
structs
stateTypes
expr
args
structs
stateTypes
expr
args
traverseStmt
LHSsM
traverseLHSM
stmt'
>>=
traverseStmt
M'
stmt'
traverseStmtExprsM
traverseExprM
>>=
traverseStmtM
stmt
=
traverseStmtM'
stmt
traverseStmtAsgnsM
traverseAsgnM
traverseStmtM'
::
Stmt
->
State
Types
Stmt
traverseStmtM
stmt
=
traverseStmtM
'
=
traverseStmtLHSsM
traverseLHSM
stmt
>>=
traverseStmtLHSsM
traverseLHSM
>=>
traverseStmtExprsM
traverseExprM
>>=
traverseStmtExprsM
traverseExprM
>=>
traverseStmtAsgnsM
traverseAsgnM
traverseStmtAsgnsM
traverseAsgnM
traverseExprM
=
traverseExprM
=
traverseNestedExprsM
$
stately
converter
traverseNestedExprsM
$
stately
converter
...
...
src/Convert/Traverse.hs
View file @
bd1c0723
...
@@ -122,9 +122,9 @@ unmonad :: (MapperM Identity a -> MapperM Identity b) -> Mapper a -> Mapper b
...
@@ -122,9 +122,9 @@ unmonad :: (MapperM Identity a -> MapperM Identity b) -> Mapper a -> Mapper b
unmonad
traverser
mapper
=
runIdentity
.
traverser
(
return
.
mapper
)
unmonad
traverser
mapper
=
runIdentity
.
traverser
(
return
.
mapper
)
collectify
::
Monad
m
=>
(
MapperM
m
a
->
MapperM
m
b
)
->
CollectorM
m
a
->
CollectorM
m
b
collectify
::
Monad
m
=>
(
MapperM
m
a
->
MapperM
m
b
)
->
CollectorM
m
a
->
CollectorM
m
b
collectify
traverser
collector
thing
=
collectify
traverser
collector
=
traverser
mapper
thing
>>=
\
_
->
return
()
traverser
mapper
>=>
\
_
->
return
()
where
mapper
x
=
collector
x
>>
=
\
()
->
return
x
where
mapper
x
=
collector
x
>>
return
x
traverseDescriptionsM
::
Monad
m
=>
MapperM
m
Description
->
MapperM
m
AST
traverseDescriptionsM
::
Monad
m
=>
MapperM
m
Description
->
MapperM
m
AST
traverseDescriptionsM
=
mapM
traverseDescriptionsM
=
mapM
...
...
src/Convert/UnpackedArray.hs
View file @
bd1c0723
...
@@ -61,11 +61,11 @@ packDecl _ other = other
...
@@ -61,11 +61,11 @@ packDecl _ other = other
traverseModuleItemM
::
ModuleItem
->
ST
ModuleItem
traverseModuleItemM
::
ModuleItem
->
ST
ModuleItem
traverseModuleItemM
item
=
traverseModuleItemM
=
traverseModuleItemM'
item
traverseModuleItemM'
>
>=
traverseLHSsM
traverseLHSM
>
=>
traverseLHSsM
traverseLHSM
>
>=
traverseExprsM
traverseExprM
>
=>
traverseExprsM
traverseExprM
>
>=
traverseAsgnsM
traverseAsgnM
>
=>
traverseAsgnsM
traverseAsgnM
traverseModuleItemM'
::
ModuleItem
->
ST
ModuleItem
traverseModuleItemM'
::
ModuleItem
->
ST
ModuleItem
traverseModuleItemM'
(
Instance
a
b
c
d
bindings
)
=
do
traverseModuleItemM'
(
Instance
a
b
c
d
bindings
)
=
do
...
@@ -80,9 +80,9 @@ traverseModuleItemM' (Instance a b c d bindings) = do
...
@@ -80,9 +80,9 @@ traverseModuleItemM' (Instance a b c d bindings) = do
traverseModuleItemM'
other
=
return
other
traverseModuleItemM'
other
=
return
other
traverseStmtM
::
Stmt
->
ST
Stmt
traverseStmtM
::
Stmt
->
ST
Stmt
traverseStmtM
stmt
=
traverseStmtM
=
traverseStmtLHSsM
traverseLHSM
stmt
>>=
traverseStmtLHSsM
traverseLHSM
>=>
traverseStmtExprsM
traverseExprM
>
>=
traverseStmtExprsM
traverseExprM
>
=>
traverseStmtAsgnsM
traverseAsgnM
traverseStmtAsgnsM
traverseAsgnM
traverseExprM
::
Expr
->
ST
Expr
traverseExprM
::
Expr
->
ST
Expr
...
...
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