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
5ad8de9e
Commit
5ad8de9e
authored
Jul 21, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
standardize pattern conversion
parent
ed255344
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
52 deletions
+68
-52
src/Convert/Struct.hs
+45
-52
test/basic/package_pattern.sv
+16
-0
test/basic/package_pattern.v
+7
-0
No files found.
src/Convert/Struct.hs
View file @
5ad8de9e
...
...
@@ -191,46 +191,7 @@ convertExpr t (Mux c e1 e2) =
where
e1'
=
convertExpr
t
e1
e2'
=
convertExpr
t
e2
-- TODO: This is really a conversion for using default patterns to
-- populate arrays. Maybe this should be somewhere else?
convertExpr
(
IntegerVector
t
sg
(
r
:
rs
))
(
Pattern
[(
":default"
,
e
)])
=
Repeat
(
rangeSize
r
)
[
e'
]
where
e'
=
Cast
(
Left
$
IntegerVector
t
sg
rs
)
e
-- TODO: This is a conversion for concat array literals with elements
-- that are unsized numbers. This probably belongs somewhere else.
convertExpr
(
t
@
IntegerVector
{})
(
Pattern
items
)
=
if
all
null
names
then
convertExpr
t
$
Concat
exprs'
else
Pattern
items
where
(
names
,
exprs
)
=
unzip
items
t'
=
dropInnerTypeRange
t
exprs'
=
map
(
convertExpr
t'
)
exprs
convertExpr
(
t
@
IntegerVector
{})
(
Concat
exprs
)
=
if
all
isUnsizedNumber
exprs
then
Concat
$
map
(
Cast
$
Left
t'
)
exprs
else
Concat
$
map
(
convertExpr
t'
)
exprs
where
t'
=
dropInnerTypeRange
t
isUnsizedNumber
::
Expr
->
Bool
isUnsizedNumber
(
Number
n
)
=
not
$
numberIsSized
n
isUnsizedNumber
(
UniOp
UniSub
e
)
=
isUnsizedNumber
e
isUnsizedNumber
_
=
False
convertExpr
(
Implicit
sg
rs
)
expr
=
if
null
rs
then
expr
else
convertExpr
(
IntegerVector
TBit
sg
rs
)
expr
convertExpr
(
Struct
packing
fields
(
_
:
rs
))
(
Concat
exprs
)
=
Concat
$
map
(
convertExpr
(
Struct
packing
fields
rs
))
exprs
convertExpr
(
Struct
packing
fields
(
_
:
rs
))
(
Bit
e
_
)
=
convertExpr
(
Struct
packing
fields
rs
)
e
convertExpr
(
Struct
packing
fields
[]
)
(
Pattern
[(
""
,
Repeat
(
Number
n
)
exprs
)])
=
case
fmap
fromIntegral
(
numberToInteger
n
)
of
Just
val
->
convertExpr
(
Struct
packing
fields
[]
)
$
Pattern
$
zip
(
repeat
""
)
(
concat
$
replicate
val
exprs
)
Nothing
->
error
$
"unable to handle repeat in pattern: "
++
(
show
$
Repeat
(
Number
n
)
exprs
)
convertExpr
(
struct
@
(
Struct
_
fields
[]
))
(
Pattern
itemsOrig
)
=
if
extraNames
/=
Set
.
empty
then
error
$
"pattern "
++
show
(
Pattern
itemsOrig
)
++
...
...
@@ -295,20 +256,52 @@ convertExpr (struct @ (Struct _ fields [])) (Pattern itemsOrig) =
isStruct
(
Struct
{})
=
True
isStruct
_
=
False
convertExpr
(
Struct
packing
fields
(
r
:
rs
))
(
Pattern
items
)
=
if
all
null
keys
then
convertExpr
(
structTf
(
r
:
rs
))
(
Concat
vals
)
else
Repeat
(
rangeSize
r
)
[
subExpr'
]
convertExpr
(
Implicit
_
[]
)
expr
=
expr
convertExpr
(
Implicit
sg
rs
)
expr
=
convertExpr
(
IntegerVector
TBit
sg
rs
)
expr
-- TODO: This is a conversion for concat array literals with elements
-- that are unsized numbers. This probably belongs somewhere else.
convertExpr
(
t
@
IntegerVector
{})
(
Concat
exprs
)
=
if
all
isUnsizedNumber
exprs
then
Concat
$
map
(
Cast
$
Left
t'
)
exprs
else
Concat
$
map
(
convertExpr
t'
)
exprs
where
(
keys
,
vals
)
=
unzip
items
subExpr
=
Pattern
items
structTf
=
Struct
packing
fields
subExpr'
=
convertExpr
(
structTf
rs
)
subExpr
convertExpr
(
Struct
packing
fields
(
r
:
rs
))
subExpr
=
Repeat
(
rangeSize
r
)
[
subExpr'
]
t'
=
dropInnerTypeRange
t
isUnsizedNumber
::
Expr
->
Bool
isUnsizedNumber
(
Number
n
)
=
not
$
numberIsSized
n
isUnsizedNumber
(
UniOp
UniSub
e
)
=
isUnsizedNumber
e
isUnsizedNumber
_
=
False
-- TODO: This is really a conversion for using default patterns to
-- populate arrays. Maybe this should be somewhere else?
convertExpr
t
(
orig
@
(
Pattern
[(
":default"
,
expr
)]))
=
if
null
rs
then
orig
else
Repeat
count
[
expr'
]
where
structTf
=
Struct
packing
fields
subExpr'
=
convertExpr
(
structTf
rs
)
subExpr
count
=
rangeSize
$
head
rs
expr'
=
Cast
(
Left
t'
)
$
convertExpr
t'
expr
(
_
,
rs
)
=
typeRanges
t
t'
=
dropInnerTypeRange
t
-- pattern syntax used for simple array literals
convertExpr
t
(
Pattern
items
)
=
if
all
null
names
then
convertExpr
t
$
Concat
exprs'
else
Pattern
items
where
(
names
,
exprs
)
=
unzip
items
t'
=
dropInnerTypeRange
t
exprs'
=
map
(
convertExpr
t'
)
exprs
-- propagate types through concatenation expressions
convertExpr
t
(
Concat
exprs
)
=
Concat
exprs'
where
t'
=
dropInnerTypeRange
t
exprs'
=
map
(
convertExpr
t'
)
exprs
convertExpr
_
other
=
other
fallbackType
::
Scopes
Type
->
Expr
->
(
Type
,
Expr
)
...
...
test/basic/package_pattern.sv
0 → 100644
View file @
5ad8de9e
package
PKG
;
typedef
struct
packed
{
logic
f
;
}
foo_t
;
endpackage
module
top
;
typedef
struct
packed
{
PKG
::
foo_t
f
;
}
local_t
;
local_t
w
[
0
:
1
]
;
initial
begin
w
<=
'
{
default
:
0
};
$
display
(
"%b"
,
w
)
;
end
endmodule
test/basic/package_pattern.v
0 → 100644
View file @
5ad8de9e
module
top
;
reg
[
1
:
0
]
w
;
initial
begin
w
<=
2'b00
;
$
display
(
"%b"
,
w
)
;
end
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