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
9249c9fa
Commit
9249c9fa
authored
Jun 05, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
typdef conversion obeys generate scoping
parent
ae392d45
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
9 deletions
+91
-9
src/Convert/Traverse.hs
+4
-0
src/Convert/Typedef.hs
+33
-9
test/basic/typedef_scope.sv
+29
-0
test/basic/typedef_scope.v
+25
-0
No files found.
src/Convert/Traverse.hs
View file @
9249c9fa
...
...
@@ -67,6 +67,7 @@ module Convert.Traverse
,
traverseGenItems
,
collectGenItemsM
,
traverseNestedGenItemsM
,
traverseNestedGenItems
,
traverseAsgnsM
,
traverseAsgns
,
collectAsgnsM
...
...
@@ -974,6 +975,9 @@ traverseNestedGenItemsM mapper = fullMapper
fullMapper
stmt
=
mapper
stmt
>>=
traverseSinglyNestedGenItemsM
fullMapper
traverseNestedGenItems
::
Mapper
GenItem
->
Mapper
GenItem
traverseNestedGenItems
=
unmonad
traverseNestedGenItemsM
flattenGenBlocks
::
GenItem
->
[
GenItem
]
flattenGenBlocks
(
GenBlock
""
items
)
=
items
flattenGenBlocks
(
GenFor
_
_
_
GenNull
)
=
[]
...
...
src/Convert/Typedef.hs
View file @
9249c9fa
...
...
@@ -35,17 +35,20 @@ convert =
convertDescription
::
Types
->
Description
->
Description
convertDescription
globalTypes
description
=
traverseModuleItems
removeTypedef
$
traverseModuleItems
convertModuleItem
$
traverseModuleItems
(
traverseExprs
$
traverseNestedExprs
$
convertExpr
)
$
traverseModuleItems
(
traverseTypes
$
resolveType
types
)
$
description
traverseModuleItems
(
convertTypedef
types
)
description'
where
description'
=
traverseModuleItems
(
traverseGenItems
convertGenItem
)
description
types
=
Map
.
union
globalTypes
$
execWriter
$
collectModuleItemsM
getTypedef
description
getTypedef
::
ModuleItem
->
Writer
Types
()
getTypedef
(
MIPackageItem
(
Typedef
a
b
))
=
tell
$
Map
.
singleton
b
a
getTypedef
_
=
return
()
execWriter
$
collectModuleItemsM
collectTypedefM
description'
convertTypedef
::
Types
->
ModuleItem
->
ModuleItem
convertTypedef
types
=
removeTypedef
.
convertModuleItem
.
(
traverseExprs
$
traverseNestedExprs
$
convertExpr
)
.
(
traverseTypes
$
resolveType
types
)
where
removeTypedef
::
ModuleItem
->
ModuleItem
removeTypedef
(
MIPackageItem
(
Typedef
_
x
))
=
MIPackageItem
$
Decl
$
CommentDecl
$
"removed typedef: "
++
x
...
...
@@ -71,6 +74,27 @@ convertDescription globalTypes description =
where
mapParam
(
i
,
v
)
=
(
i
,
convertTypeOrExpr
v
)
convertModuleItem
other
=
other
convertGenItem
::
GenItem
->
GenItem
convertGenItem
(
GenIf
c
a
b
)
=
GenIf
c
a'
b'
where
a'
=
convertGenItem'
a
b'
=
convertGenItem'
b
convertGenItem
other
=
other
convertGenItem'
::
GenItem
->
GenItem
convertGenItem'
item
=
do
GenBlock
""
items
where
-- convert inner generate blocks first
item'
=
Generate
[
traverseNestedGenItems
convertGenItem
item
]
types
=
execWriter
$
collectNestedModuleItemsM
collectTypedefM
item'
Generate
items
=
traverseNestedModuleItems
(
convertTypedef
types
)
item'
collectTypedefM
::
ModuleItem
->
Writer
Types
()
collectTypedefM
(
MIPackageItem
(
Typedef
a
b
))
=
tell
$
Map
.
singleton
b
a
collectTypedefM
_
=
return
()
resolveItem
::
Types
->
(
Type
,
Identifier
)
->
(
Type
,
Identifier
)
resolveItem
types
(
t
,
x
)
=
(
resolveType
types
t
,
x
)
...
...
test/basic/typedef_scope.sv
0 → 100644
View file @
9249c9fa
module
Example
;
parameter
FLAG_1
=
0
;
parameter
FLAG_2
=
0
;
typedef
logic
[
2
:
0
]
T
;
if
(
FLAG_1
)
begin
typedef
logic
[
1
:
0
]
T
;
T
t
=
0
;
initial
$
display
(
"2 %b"
,
t
)
;
if
(
FLAG_2
)
begin
typedef
logic
[
3
:
0
]
T
;
T
t
=
0
;
initial
$
display
(
"4 %b"
,
t
)
;
end
end
else
begin
typedef
logic
T
;
T
t
=
0
;
initial
$
display
(
"1 %b"
,
t
)
;
end
T
t
=
0
;
initial
$
display
(
"3 %b"
,
t
)
;
endmodule
module
top
;
Example
#(
0
,
0
)
a
()
;
Example
#(
1
,
0
)
b
()
;
Example
#(
0
,
1
)
c
()
;
Example
#(
1
,
1
)
d
()
;
endmodule
test/basic/typedef_scope.v
0 → 100644
View file @
9249c9fa
module
Example
;
parameter
FLAG_1
=
0
;
parameter
FLAG_2
=
0
;
if
(
FLAG_1
)
begin
wire
[
1
:
0
]
t
=
0
;
initial
$
display
(
"2 %b"
,
t
)
;
if
(
FLAG_2
)
begin
wire
[
3
:
0
]
t
=
0
;
initial
$
display
(
"4 %b"
,
t
)
;
end
end
else
begin
wire
t
=
0
;
initial
$
display
(
"1 %b"
,
t
)
;
end
wire
[
2
:
0
]
t
=
0
;
initial
$
display
(
"3 %b"
,
t
)
;
endmodule
module
top
;
Example
#(
0
,
0
)
a
()
;
Example
#(
1
,
0
)
b
()
;
Example
#(
0
,
1
)
c
()
;
Example
#(
1
,
1
)
d
()
;
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