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
bd2efb42
Commit
bd2efb42
authored
Sep 11, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support struct patterns with partial defaults (resolves #35)
parent
46242aac
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
4 deletions
+31
-4
src/Convert/Struct.hs
+16
-4
test/basic/struct_default.sv
+11
-0
test/basic/struct_default.v
+4
-0
No files found.
src/Convert/Struct.hs
View file @
bd2efb42
...
...
@@ -285,6 +285,8 @@ convertAsgn structs types (lhs, expr) =
convertLHS
(
LHSStream
o
e
lhss
)
=
(
Implicit
Unspecified
[]
,
LHSStream
o
e
$
map
(
snd
.
convertLHS
)
lhss
)
defaultKey
=
Just
"default"
-- try expression conversion by looking at the *outermost* type first
convertExpr
::
Type
->
Expr
->
Expr
-- TODO: This is really a conversion for using default patterns to
...
...
@@ -298,7 +300,7 @@ convertAsgn structs types (lhs, expr) =
convertExpr
(
Struct
(
Packed
sg
)
fields
rs
)
e
convertExpr
(
Struct
(
Packed
sg
)
fields
rs
)
(
Pattern
[(
Just
"default"
,
e
)])
=
if
Map
.
notMember
structTf
structs
then
Pattern
[(
Just
"default"
,
e
)]
Pattern
[(
defaultKey
,
e
)]
else
if
null
rs
then
expanded
else
...
...
@@ -326,9 +328,19 @@ convertAsgn structs types (lhs, expr) =
itemsNamed
=
-- if the pattern does not use identifiers, use the
-- identifiers from the struct type definition in order
if
not
(
all
(
isJust
.
fst
)
itemsOrig
)
then
zip
(
map
(
Just
.
snd
)
fields
)
(
map
snd
itemsOrig
)
else
itemsOrig
if
not
(
all
(
isJust
.
fst
)
itemsOrig
)
then
zip
(
map
(
Just
.
snd
)
fields
)
(
map
snd
itemsOrig
)
-- if the pattern has a default value, use that for any
-- missing fields
else
if
any
((
==
defaultKey
)
.
fst
)
itemsOrig
then
let
origValueMap
=
Map
.
fromList
itemsOrig
origValues
=
Map
.
delete
defaultKey
origValueMap
defaultValue
=
origValueMap
Map
.!
defaultKey
defaultValues
=
Map
.
fromList
$
zip
(
map
Just
fieldNames
)
(
repeat
defaultValue
)
in
Map
.
toList
$
Map
.
union
origValues
defaultValues
else
itemsOrig
items
=
sortOn
itemPosition
$
map
subMap
itemsNamed
fieldNames
=
map
snd
fields
itemsFieldNames
=
map
(
fromJust
.
fst
)
items
...
...
test/basic/struct_default.sv
0 → 100644
View file @
bd2efb42
module
top
;
typedef
struct
packed
{
logic
a
;
logic
b
;
}
foo_t
;
foo_t
foo
;
initial
begin
foo
=
'
{
a
:
1'b1
,
default
:
'0
};
$
display
(
foo
,
foo
.
a
,
foo
.
b
)
;
end
endmodule
test/basic/struct_default.v
0 → 100644
View file @
bd2efb42
module
top
;
reg
[
1
:
0
]
foo
=
{
1'b1
,
1'b0
};
initial
$
display
(
foo
,
foo
[
1
]
,
foo
[
0
])
;
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