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
- 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
...
...
@@ -21,6 +21,7 @@ convertType (IntegerAtom TInt sg) = baseType sg Signed 32
convertType
(
IntegerAtom
TShortint
sg
)
=
baseType
sg
Signed
16
convertType
(
IntegerAtom
TLongint
sg
)
=
baseType
sg
Signed
64
convertType
(
IntegerAtom
TByte
sg
)
=
baseType
sg
Unspecified
8
convertType
(
IntegerVector
TBit
sg
rs
)
=
IntegerVector
TLogic
sg
rs
convertType
other
=
other
-- 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
-- write down unstructured versions of packed struct types
collectStructM
::
Type
->
Writer
Structs
()
collectStructM
(
Struct
(
Packed
sg
)
fields
_
)
=
do
-- TODO: How should we combine the structs Signing with that of the types it
-- contains?
if
canUnstructure
then
tell
$
Map
.
singleton
(
Struct
(
Packed
sg
)
fields
)
...
...
@@ -102,25 +100,19 @@ collectStructM (Struct (Packed sg) fields _) = do
vals
=
zip
unstructRanges
unstructOffsets
unstructFields
=
Map
.
fromList
$
zip
keys
vals
-- create the unstructured type
tf
=
fst
$
typeRanges
$
head
fieldTypes
-- create the unstructured type
; result type takes on the signing of the
-- struct itself to preserve behavior of operations on the whole struct
structSize
=
foldl1
(
BinOp
Add
)
fieldSizes
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
-- with all the same base type. We might be able to get away with
-- converting everything to a Logic type. This should work in cases of
-- mixed `wire`/`logic` or `reg`/`logic`.
fieldClasses
=
map
(
show
.
fst
.
typeRanges
)
fieldTypes
isComplex
::
Type
->
Bool
isComplex
(
Struct
_
_
_
)
=
True
isComplex
(
Enum
_
_
_
)
=
True
isComplex
(
Alias
_
_
_
)
=
True
isComplex
_
=
False
canUnstructure
=
all
(
head
fieldClasses
==
)
fieldClasses
&&
not
(
any
isComplex
fieldTypes
)
-- check if this struct can be packed into an integer vector; integer
-- atoms and non-integers do not have a definitive size, and so cannot
-- be packed; net types are not permitted as struct fields
isIntVec
::
Type
->
Bool
isIntVec
(
IntegerVector
_
_
_
)
=
True
isIntVec
_
=
False
canUnstructure
=
all
isIntVec
fieldTypes
collectStructM
_
=
return
()
...
...
test/basic/struct_shadow.sv
View file @
3bef2b9c
typedef
struct
packed
{
logic
w
,
x
,
y
;
}
StructA
;
typedef
struct
packed
{
logic
w
,
y
,
x
;
}
StructB
;
typedef
struct
packed
{
logic
x
,
w
,
y
;
}
StructC
;
typedef
struct
packed
{
logic
y
,
w
,
x
;
}
StructD
;
typedef
struct
packed
{
logic
x
,
y
,
w
;
}
StructE
;
typedef
struct
packed
{
logic
y
,
x
,
w
;
}
StructF
;
typedef
struct
packed
{
reg
w
;
bit
x
;
logic
y
;
}
StructA
;
typedef
struct
packed
{
reg
w
;
logic
y
;
bit
x
;
}
StructB
;
typedef
struct
packed
{
bit
x
;
reg
w
;
logic
y
;
}
StructC
;
typedef
struct
packed
{
logic
y
;
reg
w
;
bit
x
;
}
StructD
;
typedef
struct
packed
{
bit
x
;
logic
y
;
reg
w
;
}
StructE
;
typedef
struct
packed
{
logic
y
;
bit
x
;
reg
w
;
}
StructF
;
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