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
5dcbce5f
Commit
5dcbce5f
authored
Jun 19, 2022
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix conversion of casts to structs containing multidimensional fields
parent
e7fc1e61
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
20 deletions
+39
-20
CHANGELOG.md
+1
-0
src/Convert/MultiplePacked.hs
+27
-20
test/core/multipack_struct_cast.sv
+7
-0
test/core/multipack_struct_cast.v
+4
-0
No files found.
CHANGELOG.md
View file @
5dcbce5f
...
...
@@ -35,6 +35,7 @@
necessary because of calls to functions which reference non-local data
*
Fixed signed
`struct`
fields being converted to unsigned expressions when
accessed directly
*
Fixed conversion of casts using structs containing multi-dimensional fields
## v0.0.9
...
...
src/Convert/MultiplePacked.hs
View file @
5dcbce5f
...
...
@@ -5,7 +5,7 @@
- Conversion for flattening variables with multiple packed dimensions
-
- This removes one packed dimension per identifier per pass. This works fine
- because
all conversions are
repeatedly applied.
- because
this conversion is
repeatedly applied.
-
- We previously had a very complex conversion which used `generate` to make
- flattened and unflattened versions of the array as necessary. This has now
...
...
@@ -28,6 +28,7 @@ module Convert.MultiplePacked (convert) where
import
Convert.ExprUtils
import
Control.Monad
((
>=>
))
import
Data.Bifunctor
(
first
)
import
Data.Tuple
(
swap
)
import
Data.Maybe
(
isJust
)
import
qualified
Data.Map.Strict
as
Map
...
...
@@ -59,30 +60,34 @@ traverseDeclM (Param s t ident e) = do
traverseDeclExprsM
traverseExprM
$
Param
s
t'
ident
e
traverseDeclM
other
=
traverseDeclExprsM
traverseExprM
other
-- write down the given declaration and then flatten it
traverseTypeM
::
Type
->
[
Range
]
->
Identifier
->
Scoper
TypeInfo
Type
traverseTypeM
t
a
ident
=
do
tScoped
<-
scopeType
t
insertElem
ident
(
tScoped
,
a
)
t'
<-
case
t
of
Struct
pk
fields
rs
->
do
fields'
<-
flattenFields
fields
return
$
Struct
pk
fields'
rs
Union
pk
fields
rs
->
do
fields'
<-
flattenFields
fields
return
$
Union
pk
fields'
rs
_
->
return
t
let
(
tf
,
rs
)
=
typeRanges
t'
if
length
rs
<=
1
then
return
t'
else
do
let
r1
:
r2
:
rest
=
rs
let
rs'
=
(
combineRanges
r1
r2
)
:
rest
return
$
tf
rs'
return
$
flattenType
t
-- flatten the innermost dimension of the given type, and any types it contains
flattenType
::
Type
->
Type
flattenType
t
=
tf
$
if
length
ranges
<=
1
then
ranges
else
rangesFlat
where
flattenFields
fields
=
do
let
(
fieldTypes
,
fieldNames
)
=
unzip
fields
fieldTypes'
<-
mapM
(
\
x
->
traverseTypeM
x
[]
""
)
fieldTypes
return
$
zip
fieldTypes'
fieldNames
(
tf
,
ranges
)
=
case
t
of
Struct
pk
fields
rs
->
(
Struct
pk
fields'
,
rs
)
where
fields'
=
flattenFields
fields
Union
pk
fields
rs
->
(
Union
pk
fields'
,
rs
)
where
fields'
=
flattenFields
fields
_
->
typeRanges
t
r1
:
r2
:
rest
=
ranges
rangesFlat
=
combineRanges
r1
r2
:
rest
-- flatten the types in a given list of struct/union fields
flattenFields
::
[
Field
]
->
[
Field
]
flattenFields
=
map
$
first
flattenType
traverseModuleItemM
::
ModuleItem
->
Scoper
TypeInfo
ModuleItem
traverseModuleItemM
(
Instance
m
p
x
rs
l
)
=
do
...
...
@@ -266,6 +271,8 @@ convertExpr scopes =
len
=
lenOuter
range'
=
(
base
,
len
)
one
=
RawNum
1
rewriteExpr
(
Cast
(
Left
t
)
expr
)
=
Cast
(
Left
$
flattenType
t
)
expr
rewriteExpr
other
=
rewriteExprLowPrec
other
...
...
test/core/multipack_struct_cast.sv
0 → 100644
View file @
5dcbce5f
module
top
;
typedef
struct
packed
{
logic
[
2
][
3
]
x
;
}
S
;
S
s
;
initial
s
=
S
'
(
'1
)
;
endmodule
test/core/multipack_struct_cast.v
0 → 100644
View file @
5dcbce5f
module
top
;
reg
[
5
:
0
]
s
;
initial
s
=
1
'
sb1
;
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