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
a7673c55
Commit
a7673c55
authored
Jul 08, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
automatically fix simple declaration order issues
parent
d2a0ba0d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
7 deletions
+40
-7
src/Convert.hs
+2
-1
src/Convert/NestPI.hs
+28
-6
test/basic/reorder.sv
+5
-0
test/basic/reorder.v
+5
-0
No files found.
src/Convert.hs
View file @
a7673c55
...
...
@@ -104,7 +104,8 @@ run :: [Job.Exclude] -> Phase
run
excludes
=
foldr
(
.
)
id
$
phases
excludes
convert
::
[
Job
.
Exclude
]
->
Phase
convert
excludes
=
convert'
convert
excludes
=
convert'
.
Convert
.
NestPI
.
reorder
where
convert'
::
Phase
convert'
descriptions
=
...
...
src/Convert/NestPI.hs
View file @
a7673c55
...
...
@@ -4,9 +4,10 @@
- Conversion for moving top-level package items into modules
-}
module
Convert.NestPI
(
convert
)
where
module
Convert.NestPI
(
convert
,
reorder
)
where
import
Control.Monad.Writer
import
Data.Maybe
(
mapMaybe
)
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Set
as
Set
...
...
@@ -29,6 +30,9 @@ convert =
isPI
(
PackageItem
item
)
=
piName
item
/=
""
isPI
_
=
False
reorder
::
[
AST
]
->
[
AST
]
reorder
=
map
$
traverseDescriptions
reorderDescription
-- collects packages items missing
collectDescriptionM
::
Description
->
Writer
PIs
()
collectDescriptionM
(
PackageItem
item
)
=
do
...
...
@@ -48,6 +52,18 @@ convertDescription pis (orig @ Part{}) =
items'
=
addItems
pis
Set
.
empty
items
convertDescription
_
other
=
other
-- attempt to fix simple declaration order issues
reorderDescription
::
Description
->
Description
reorderDescription
(
Part
attrs
extern
kw
lifetime
name
ports
items
)
=
Part
attrs
extern
kw
lifetime
name
ports
items'
where
items'
=
addItems
localPIs
Set
.
empty
items
localPIs
=
Map
.
fromList
$
mapMaybe
toPIElem
items
toPIElem
::
ModuleItem
->
Maybe
(
Identifier
,
PackageItem
)
toPIElem
(
MIPackageItem
item
)
=
Just
(
piName
item
,
item
)
toPIElem
_
=
Nothing
reorderDescription
other
=
other
-- iteratively inserts missing package items exactly where they are needed
addItems
::
PIs
->
Idents
->
[
ModuleItem
]
->
[
ModuleItem
]
addItems
pis
existingPIs
(
item
:
items
)
=
...
...
@@ -66,7 +82,8 @@ addItems pis existingPIs (item : items) =
usedPIs
=
Set
.
unions
$
map
runner
[
collectStmtsM
collectSubroutinesM
,
collectTypesM
$
collectNestedTypesM
collectTypenamesM
,
collectExprsM
$
collectNestedExprsM
collectIdentsM
,
collectExprsM
$
collectNestedExprsM
collectExprIdentsM
,
collectLHSsM
$
collectNestedLHSsM
collectLHSIdentsM
]
neededPIs
=
Set
.
difference
(
Set
.
difference
usedPIs
existingPIs
)
thisPI
itemsToAdd
=
map
MIPackageItem
$
Map
.
elems
$
...
...
@@ -87,10 +104,15 @@ collectSubroutinesM (Subroutine (Ident f) _) = tell $ Set.singleton f
collectSubroutinesM
_
=
return
()
-- writes down the names of function calls and identifiers
collectIdentsM
::
Expr
->
Writer
Idents
()
collectIdentsM
(
Call
(
Ident
x
)
_
)
=
tell
$
Set
.
singleton
x
collectIdentsM
(
Ident
x
)
=
tell
$
Set
.
singleton
x
collectIdentsM
_
=
return
()
collectExprIdentsM
::
Expr
->
Writer
Idents
()
collectExprIdentsM
(
Call
(
Ident
x
)
_
)
=
tell
$
Set
.
singleton
x
collectExprIdentsM
(
Ident
x
)
=
tell
$
Set
.
singleton
x
collectExprIdentsM
_
=
return
()
-- writes down the names of identifiers
collectLHSIdentsM
::
LHS
->
Writer
Idents
()
collectLHSIdentsM
(
LHSIdent
x
)
=
tell
$
Set
.
singleton
x
collectLHSIdentsM
_
=
return
()
-- writes down aliased typenames
collectTypenamesM
::
Type
->
Writer
Idents
()
...
...
test/basic/reorder.sv
0 → 100644
View file @
a7673c55
module
top
;
assign
arr
[
0
][
0
]
=
1
;
logic
[
1
:
0
][
2
:
0
]
arr
;
initial
$
display
(
"%b"
,
arr
)
;
endmodule
test/basic/reorder.v
0 → 100644
View file @
a7673c55
module
top
;
wire
[
5
:
0
]
arr
;
assign
arr
[
0
]
=
1
;
initial
$
display
(
"%b"
,
arr
)
;
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