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
3bef2b9c
Commit
3bef2b9c
authored
May 10, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
struct conversion handles alternate and mixed integer vector field types
parent
44ea16e3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
25 deletions
+18
-25
src/Convert/IntTypes.hs
+2
-1
src/Convert/Struct.hs
+10
-18
test/basic/struct_shadow.sv
+6
-6
No files found.
src/Convert/IntTypes.hs
View file @
3bef2b9c
{- sv2v
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
- Author: Zachary Snow <zach@zachjs.com>
-
-
- Conversion for `int`, `shortint`, `longint`, and `byte`
- Conversion for `
bit`, `
int`, `shortint`, `longint`, and `byte`
-}
-}
module
Convert.IntTypes
(
convert
)
where
module
Convert.IntTypes
(
convert
)
where
...
@@ -21,6 +21,7 @@ convertType (IntegerAtom TInt sg) = baseType sg Signed 32
...
@@ -21,6 +21,7 @@ convertType (IntegerAtom TInt sg) = baseType sg Signed 32
convertType
(
IntegerAtom
TShortint
sg
)
=
baseType
sg
Signed
16
convertType
(
IntegerAtom
TShortint
sg
)
=
baseType
sg
Signed
16
convertType
(
IntegerAtom
TLongint
sg
)
=
baseType
sg
Signed
64
convertType
(
IntegerAtom
TLongint
sg
)
=
baseType
sg
Signed
64
convertType
(
IntegerAtom
TByte
sg
)
=
baseType
sg
Unspecified
8
convertType
(
IntegerAtom
TByte
sg
)
=
baseType
sg
Unspecified
8
convertType
(
IntegerVector
TBit
sg
rs
)
=
IntegerVector
TLogic
sg
rs
convertType
other
=
other
convertType
other
=
other
-- makes a integer "compatible" type with the given signing, base signing and
-- makes a integer "compatible" type with the given signing, base signing and
...
...
src/Convert/Struct.hs
View file @
3bef2b9c
...
@@ -71,8 +71,6 @@ convertDescription other = other
...
@@ -71,8 +71,6 @@ convertDescription other = other
-- write down unstructured versions of packed struct types
-- write down unstructured versions of packed struct types
collectStructM
::
Type
->
Writer
Structs
()
collectStructM
::
Type
->
Writer
Structs
()
collectStructM
(
Struct
(
Packed
sg
)
fields
_
)
=
do
collectStructM
(
Struct
(
Packed
sg
)
fields
_
)
=
do
-- TODO: How should we combine the structs Signing with that of the types it
-- contains?
if
canUnstructure
if
canUnstructure
then
tell
$
Map
.
singleton
then
tell
$
Map
.
singleton
(
Struct
(
Packed
sg
)
fields
)
(
Struct
(
Packed
sg
)
fields
)
...
@@ -102,25 +100,19 @@ collectStructM (Struct (Packed sg) fields _) = do
...
@@ -102,25 +100,19 @@ collectStructM (Struct (Packed sg) fields _) = do
vals
=
zip
unstructRanges
unstructOffsets
vals
=
zip
unstructRanges
unstructOffsets
unstructFields
=
Map
.
fromList
$
zip
keys
vals
unstructFields
=
Map
.
fromList
$
zip
keys
vals
-- create the unstructured type
-- create the unstructured type
; result type takes on the signing of the
tf
=
fst
$
typeRanges
$
head
fieldTypes
-- struct itself to preserve behavior of operations on the whole struct
structSize
=
foldl1
(
BinOp
Add
)
fieldSizes
structSize
=
foldl1
(
BinOp
Add
)
fieldSizes
packedRange
=
(
simplify
$
BinOp
Sub
structSize
(
Number
"1"
),
zero
)
packedRange
=
(
simplify
$
BinOp
Sub
structSize
(
Number
"1"
),
zero
)
unstructType
=
tf
[
packedRange
]
unstructType
=
IntegerVector
TLogic
sg
[
packedRange
]
-- TODO: For now, we only convert packed structs which contain fields
-- check if this struct can be packed into an integer vector; integer
-- with all the same base type. We might be able to get away with
-- atoms and non-integers do not have a definitive size, and so cannot
-- converting everything to a Logic type. This should work in cases of
-- be packed; net types are not permitted as struct fields
-- mixed `wire`/`logic` or `reg`/`logic`.
isIntVec
::
Type
->
Bool
fieldClasses
=
map
(
show
.
fst
.
typeRanges
)
fieldTypes
isIntVec
(
IntegerVector
_
_
_
)
=
True
isComplex
::
Type
->
Bool
isIntVec
_
=
False
isComplex
(
Struct
_
_
_
)
=
True
canUnstructure
=
all
isIntVec
fieldTypes
isComplex
(
Enum
_
_
_
)
=
True
isComplex
(
Alias
_
_
_
)
=
True
isComplex
_
=
False
canUnstructure
=
all
(
head
fieldClasses
==
)
fieldClasses
&&
not
(
any
isComplex
fieldTypes
)
collectStructM
_
=
return
()
collectStructM
_
=
return
()
...
...
test/basic/struct_shadow.sv
View file @
3bef2b9c
typedef
struct
packed
{
logic
w
,
x
,
y
;
}
StructA
;
typedef
struct
packed
{
reg
w
;
bit
x
;
logic
y
;
}
StructA
;
typedef
struct
packed
{
logic
w
,
y
,
x
;
}
StructB
;
typedef
struct
packed
{
reg
w
;
logic
y
;
bit
x
;
}
StructB
;
typedef
struct
packed
{
logic
x
,
w
,
y
;
}
StructC
;
typedef
struct
packed
{
bit
x
;
reg
w
;
logic
y
;
}
StructC
;
typedef
struct
packed
{
logic
y
,
w
,
x
;
}
StructD
;
typedef
struct
packed
{
logic
y
;
reg
w
;
bit
x
;
}
StructD
;
typedef
struct
packed
{
logic
x
,
y
,
w
;
}
StructE
;
typedef
struct
packed
{
bit
x
;
logic
y
;
reg
w
;
}
StructE
;
typedef
struct
packed
{
logic
y
,
x
,
w
;
}
StructF
;
typedef
struct
packed
{
logic
y
;
bit
x
;
reg
w
;
}
StructF
;
module
top
;
module
top
;
...
...
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