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
cf0e182e
Commit
cf0e182e
authored
Oct 14, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert unpacked structs as though packed
- also expands struct literals containing repeat expressions
parent
8e8d44f4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
src/Convert/Struct.hs
+19
-10
No files found.
src/Convert/Struct.hs
View file @
cf0e182e
...
@@ -76,6 +76,8 @@ convertDescription other = other
...
@@ -76,6 +76,8 @@ 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
Unpacked
fields
_
)
=
collectStructM'
(
Struct
Unpacked
)
True
Unspecified
fields
collectStructM
(
Struct
(
Packed
sg
)
fields
_
)
=
collectStructM
(
Struct
(
Packed
sg
)
fields
_
)
=
collectStructM'
(
Struct
$
Packed
sg
)
True
sg
fields
collectStructM'
(
Struct
$
Packed
sg
)
True
sg
fields
collectStructM
(
Union
(
Packed
sg
)
fields
_
)
=
collectStructM
(
Union
(
Packed
sg
)
fields
_
)
=
...
@@ -208,7 +210,7 @@ packerFn structTf =
...
@@ -208,7 +210,7 @@ packerFn structTf =
MIPackageItem
$
MIPackageItem
$
Function
Nothing
(
structTf
[]
)
fnName
decls
[
retStmt
]
Function
Nothing
(
structTf
[]
)
fnName
decls
[
retStmt
]
where
where
Struct
(
Packed
_
)
fields
[]
=
structTf
[]
Struct
_
fields
[]
=
structTf
[]
toInput
(
t
,
x
)
=
Variable
Input
t
x
[]
Nothing
toInput
(
t
,
x
)
=
Variable
Input
t
x
[]
Nothing
decls
=
map
toInput
fields
decls
=
map
toInput
fields
retStmt
=
Return
$
Concat
$
map
(
Ident
.
snd
)
fields
retStmt
=
Return
$
Concat
$
map
(
Ident
.
snd
)
fields
...
@@ -308,11 +310,18 @@ convertAsgn structs types (lhs, expr) =
...
@@ -308,11 +310,18 @@ convertAsgn structs types (lhs, expr) =
convertExpr
(
IntegerVector
t
sg
(
r
:
rs
))
(
Pattern
[(
":default"
,
e
)])
=
convertExpr
(
IntegerVector
t
sg
(
r
:
rs
))
(
Pattern
[(
":default"
,
e
)])
=
Repeat
(
rangeSize
r
)
[
e'
]
Repeat
(
rangeSize
r
)
[
e'
]
where
e'
=
convertExpr
(
IntegerVector
t
sg
rs
)
e
where
e'
=
convertExpr
(
IntegerVector
t
sg
rs
)
e
convertExpr
(
Struct
(
Packed
sg
)
fields
(
_
:
rs
))
(
Concat
exprs
)
=
convertExpr
(
Struct
packing
fields
(
_
:
rs
))
(
Concat
exprs
)
=
Concat
$
map
(
convertExpr
(
Struct
(
Packed
sg
)
fields
rs
))
exprs
Concat
$
map
(
convertExpr
(
Struct
packing
fields
rs
))
exprs
convertExpr
(
Struct
(
Packed
sg
)
fields
(
_
:
rs
))
(
Bit
e
_
)
=
convertExpr
(
Struct
packing
fields
(
_
:
rs
))
(
Bit
e
_
)
=
convertExpr
(
Struct
(
Packed
sg
)
fields
rs
)
e
convertExpr
(
Struct
packing
fields
rs
)
e
convertExpr
(
Struct
(
Packed
sg
)
fields
[]
)
(
Pattern
itemsOrig
)
=
convertExpr
(
Struct
packing
fields
[]
)
(
Pattern
[(
""
,
Repeat
(
Number
nStr
)
exprs
)])
=
case
readNumber
nStr
of
Just
n
->
convertExpr
(
Struct
packing
fields
[]
)
$
Pattern
$
zip
(
repeat
""
)
(
concat
$
take
n
$
repeat
exprs
)
Nothing
->
error
$
"unable to handle repeat in pattern: "
++
(
show
$
Repeat
(
Number
nStr
)
exprs
)
convertExpr
(
Struct
packing
fields
[]
)
(
Pattern
itemsOrig
)
=
if
extraNames
/=
Set
.
empty
then
if
extraNames
/=
Set
.
empty
then
error
$
"pattern "
++
show
(
Pattern
itemsOrig
)
++
error
$
"pattern "
++
show
(
Pattern
itemsOrig
)
++
" has extra named fields: "
++
" has extra named fields: "
++
...
@@ -325,7 +334,7 @@ convertAsgn structs types (lhs, expr) =
...
@@ -325,7 +334,7 @@ convertAsgn structs types (lhs, expr) =
else
else
Pattern
items
Pattern
items
where
where
structTf
=
Struct
(
Packed
sg
)
fields
structTf
=
Struct
packing
fields
fieldNames
=
map
snd
fields
fieldNames
=
map
snd
fields
fieldTypeMap
=
Map
.
fromList
$
map
swap
fields
fieldTypeMap
=
Map
.
fromList
$
map
swap
fields
...
@@ -335,7 +344,7 @@ convertAsgn structs types (lhs, expr) =
...
@@ -335,7 +344,7 @@ convertAsgn structs types (lhs, expr) =
itemsOrig
itemsOrig
-- position-based patterns should cover every field
-- position-based patterns should cover every field
else
if
length
itemsOrig
/=
length
fields
then
else
if
length
itemsOrig
/=
length
fields
then
error
$
"struct pattern "
++
show
items
++
error
$
"struct pattern "
++
show
(
Pattern
itemsOrig
)
++
" doesn't have the same # of items as "
++
" doesn't have the same # of items as "
++
show
structTf
show
structTf
-- if the pattern does not use identifiers, use the
-- if the pattern does not use identifiers, use the
...
@@ -379,10 +388,10 @@ convertAsgn structs types (lhs, expr) =
...
@@ -379,10 +388,10 @@ convertAsgn structs types (lhs, expr) =
isStruct
(
Struct
{})
=
True
isStruct
(
Struct
{})
=
True
isStruct
_
=
False
isStruct
_
=
False
convertExpr
(
Struct
(
Packed
sg
)
fields
(
r
:
rs
))
subExpr
=
convertExpr
(
Struct
packing
fields
(
r
:
rs
))
subExpr
=
Repeat
(
rangeSize
r
)
[
subExpr'
]
Repeat
(
rangeSize
r
)
[
subExpr'
]
where
where
structTf
=
Struct
(
Packed
sg
)
fields
structTf
=
Struct
packing
fields
subExpr'
=
convertExpr
(
structTf
rs
)
subExpr
subExpr'
=
convertExpr
(
structTf
rs
)
subExpr
convertExpr
_
other
=
other
convertExpr
_
other
=
other
...
...
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