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
295ac649
Commit
295ac649
authored
Sep 11, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
package item conversions preserve ordering (resolves #36)
parent
dd3a7e68
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
18 deletions
+17
-18
src/Convert/NestPI.hs
+6
-7
src/Convert/Package.hs
+11
-11
No files found.
src/Convert/NestPI.hs
View file @
295ac649
...
...
@@ -9,13 +9,12 @@ module Convert.NestPI (convert) where
import
Control.Monad.State
import
Control.Monad.Writer
import
Data.List
(
isPrefixOf
)
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Set
as
Set
import
Convert.Traverse
import
Language.SystemVerilog.AST
type
PIs
=
Map
.
Map
Identifier
PackageItem
type
PIs
=
[(
Identifier
,
PackageItem
)]
type
Idents
=
Set
.
Set
Identifier
convert
::
[
AST
]
->
[
AST
]
...
...
@@ -28,7 +27,7 @@ convert asts =
then
curr
else
nest
next
where
next
=
evalState
(
traverseM
curr
)
Map
.
empty
next
=
evalState
(
traverseM
curr
)
[]
traverseM
=
traverseDescriptionsM
traverseDescriptionM
isPI
::
Description
->
Bool
isPI
(
PackageItem
item
)
=
piName
item
/=
Nothing
...
...
@@ -39,16 +38,16 @@ traverseDescriptionM :: Description -> State PIs Description
traverseDescriptionM
(
PackageItem
item
)
=
do
()
<-
case
piName
item
of
Nothing
->
return
()
Just
ident
->
modify
$
Map
.
insert
ident
item
Just
ident
->
modify
$
flip
(
++
)
[(
ident
,
item
)]
return
$
PackageItem
item
traverseDescriptionM
(
orig
@
(
Part
extern
kw
lifetime
name
ports
items
))
=
do
tfs
<-
get
let
neededPIs
=
Set
.
difference
(
Set
.
union
usedPIs
$
Set
.
filter
(
isPrefixOf
"import "
)
$
Map
.
keysSe
t
tfs
)
Set
.
filter
(
isPrefixOf
"import "
)
$
Set
.
fromList
$
map
fs
t
tfs
)
existingPIs
let
newItems
=
map
MIPackageItem
$
Map
.
elems
$
Map
.
restrictKeys
tfs
neededPI
s
let
newItems
=
map
MIPackageItem
$
map
snd
$
filter
(
\
(
x
,
_
)
->
Set
.
member
x
neededPIs
)
tf
s
return
$
Part
extern
kw
lifetime
name
ports
(
newItems
++
items
)
where
existingPIs
=
execWriter
$
collectModuleItemsM
collectPIsM
orig
...
...
src/Convert/Package.hs
View file @
295ac649
...
...
@@ -33,7 +33,7 @@ import Convert.Traverse
import
Language.SystemVerilog.AST
type
Packages
=
Map
.
Map
Identifier
PackageItems
type
PackageItems
=
Map
.
Map
Identifier
PackageItem
type
PackageItems
=
[(
Identifier
,
PackageItem
)]
type
Idents
=
Set
.
Set
Identifier
convert
::
[
AST
]
->
[
AST
]
...
...
@@ -64,13 +64,13 @@ convertFile packages ast =
globalPackageItems
::
Identifier
->
PackageItems
->
[
PackageItem
]
globalPackageItems
name
items
=
map
(
prefixPackageItem
name
(
packageItemIdents
items
))
(
Map
.
elems
items
)
map
(
prefixPackageItem
name
(
packageItemIdents
items
))
(
map
snd
items
)
packageItemIdents
::
PackageItems
->
Idents
packageItemIdents
items
=
Set
.
union
(
Map
.
keysSe
t
items
)
(
Set
.
unions
$
map
packageItemSubIdents
$
Map
.
elems
items
)
(
Set
.
fromList
$
map
fs
t
items
)
(
Set
.
unions
$
map
(
packageItemSubIdents
.
snd
)
items
)
where
packageItemSubIdents
::
PackageItem
->
Idents
packageItemSubIdents
(
Typedef
(
Enum
_
enumItems
_
)
_
)
=
...
...
@@ -114,14 +114,14 @@ collectDescriptionM :: Description -> Writer Packages ()
collectDescriptionM
(
Package
_
name
items
)
=
if
any
isImport
items
then
return
()
else
tell
$
Map
.
singleton
name
item
Map
else
tell
$
Map
.
singleton
name
item
List
where
item
Map
=
Map
.
unions
$
map
toMap
items
to
Map
::
PackageItem
->
PackageItems
to
Map
item
=
item
List
=
concatMap
toPackageItems
items
to
PackageItems
::
PackageItem
->
PackageItems
to
PackageItems
item
=
case
piName
item
of
Nothing
->
Map
.
empty
Just
x
->
Map
.
singleton
x
item
Nothing
->
[]
Just
x
->
[(
x
,
item
)]
isImport
::
PackageItem
->
Bool
isImport
(
Import
_
_
)
=
True
isImport
_
=
False
...
...
@@ -151,7 +151,7 @@ traverseModuleItem existingItemNames packages (MIPackageItem (Import x y)) =
filterer
itemName
=
case
y
of
Nothing
->
Set
.
notMember
itemName
existingItemNames
Just
ident
->
ident
==
itemName
items
=
map
snd
$
filter
(
filterer
.
fst
)
$
Map
.
toList
packageItems
items
=
map
snd
$
filter
(
filterer
.
fst
)
$
packageItems
traverseModuleItem
_
_
item
=
(
traverseExprs
$
traverseNestedExprs
traverseExpr
)
$
(
traverseStmts
traverseStmt
)
$
...
...
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