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
2bd24b60
Commit
2bd24b60
authored
Jan 11, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expand type operator support
parent
b58248fc
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
231 additions
and
137 deletions
+231
-137
src/Convert.hs
+1
-1
src/Convert/DimensionQuery.hs
+50
-100
src/Convert/Traverse.hs
+30
-12
src/Convert/TypeOf.hs
+35
-23
src/Convert/Typedef.hs
+6
-0
src/Language/SystemVerilog/AST/Type.hs
+4
-1
test/basic/dimensions.sv
+3
-0
test/basic/dimensions.v
+20
-0
test/basic/shadow_recurse.sv
+55
-0
test/basic/shadow_recurse.v
+27
-0
No files found.
src/Convert.hs
View file @
2bd24b60
...
@@ -64,6 +64,7 @@ phases excludes =
...
@@ -64,6 +64,7 @@ phases excludes =
,
Convert
.
KWArgs
.
convert
,
Convert
.
KWArgs
.
convert
,
Convert
.
LogOp
.
convert
,
Convert
.
LogOp
.
convert
,
Convert
.
MultiplePacked
.
convert
,
Convert
.
MultiplePacked
.
convert
,
Convert
.
TypeOf
.
convert
,
Convert
.
DimensionQuery
.
convert
,
Convert
.
DimensionQuery
.
convert
,
Convert
.
ParamType
.
convert
,
Convert
.
ParamType
.
convert
,
Convert
.
SizeCast
.
convert
,
Convert
.
SizeCast
.
convert
...
@@ -73,7 +74,6 @@ phases excludes =
...
@@ -73,7 +74,6 @@ phases excludes =
,
Convert
.
Stream
.
convert
,
Convert
.
Stream
.
convert
,
Convert
.
Struct
.
convert
,
Convert
.
Struct
.
convert
,
Convert
.
Typedef
.
convert
,
Convert
.
Typedef
.
convert
,
Convert
.
TypeOf
.
convert
,
Convert
.
UnbasedUnsized
.
convert
,
Convert
.
UnbasedUnsized
.
convert
,
Convert
.
Unique
.
convert
,
Convert
.
Unique
.
convert
,
Convert
.
UnpackedArray
.
convert
,
Convert
.
UnpackedArray
.
convert
...
...
src/Convert/DimensionQuery.hs
View file @
2bd24b60
...
@@ -11,22 +11,19 @@
...
@@ -11,22 +11,19 @@
- Functions on types are trivially elaborated based on the dimensions of that
- Functions on types are trivially elaborated based on the dimensions of that
- type, so long as it has been resolved to a primitive type.
- type, so long as it has been resolved to a primitive type.
-
-
- Functions on expressions requires a scoped traversal to determine the
- Functions on expressions relies on the `type` operator and the `TypeOf`
- underlying type of expression. The conversion of `$bits` on expressions
- conversion to determine the underlying type of expression. The conversion of
- recursively breaks the expression into its subtypes and finds their sizes.
- `$bits` on expressions recursively breaks the expression into its subtypes
- and finds their sizes.
-}
-}
module
Convert.DimensionQuery
(
convert
)
where
module
Convert.DimensionQuery
(
convert
)
where
import
Control.Monad.State
import
Data.List
(
elemIndex
)
import
Data.List
(
elemIndex
)
import
qualified
Data.Map.Strict
as
Map
import
Convert.Traverse
import
Convert.Traverse
import
Language.SystemVerilog.AST
import
Language.SystemVerilog.AST
type
Info
=
Map
.
Map
Identifier
(
Type
,
[
Range
])
convert
::
[
AST
]
->
[
AST
]
convert
::
[
AST
]
->
[
AST
]
convert
files
=
convert
files
=
if
files
==
files'
if
files
==
files'
...
@@ -36,26 +33,7 @@ convert files =
...
@@ -36,26 +33,7 @@ convert files =
convertDescription
::
Description
->
Description
convertDescription
::
Description
->
Description
convertDescription
=
convertDescription
=
scopedConversion
traverseDeclM
traverseModuleItemM
traverseStmtM
Map
.
empty
traverseModuleItems
$
traverseExprs
$
traverseNestedExprs
convertExpr
traverseDeclM
::
Decl
->
State
Info
Decl
traverseDeclM
decl
=
do
case
decl
of
Variable
_
t
ident
a
_
->
modify
$
Map
.
insert
ident
(
elaborateType
t
,
a
)
Param
_
t
ident
_
->
modify
$
Map
.
insert
ident
(
elaborateType
t
,
[]
)
ParamType
_
_
_
->
return
()
item
<-
traverseModuleItemM
(
MIPackageItem
$
Decl
decl
)
let
MIPackageItem
(
Decl
decl'
)
=
item
return
decl'
traverseModuleItemM
::
ModuleItem
->
State
Info
ModuleItem
traverseModuleItemM
item
=
traverseExprsM
traverseExprM
item
traverseStmtM
::
Stmt
->
State
Info
Stmt
traverseStmtM
stmt
=
traverseStmtExprsM
traverseExprM
stmt
traverseExprM
::
Expr
->
State
Info
Expr
traverseExprM
=
traverseNestedExprsM
$
stately
convertExpr
-- elaborate integer atom types to have explicit dimensions
-- elaborate integer atom types to have explicit dimensions
elaborateType
::
Type
->
Type
elaborateType
::
Type
->
Type
...
@@ -74,33 +52,34 @@ elaborateType (IntegerAtom t sg) =
...
@@ -74,33 +52,34 @@ elaborateType (IntegerAtom t sg) =
atomSize
TTime
=
64
atomSize
TTime
=
64
elaborateType
other
=
other
elaborateType
other
=
other
convertExpr
::
Info
->
Expr
->
Expr
convertExpr
::
Expr
->
Expr
-- conversion for array dimensions functions
-- conversion for array dimensions functions
convertExpr
info
(
DimsFn
FnBits
v
)
=
convertExpr
(
DimsFn
FnBits
v
)
=
convertBits
info
v
convertBits
v
convertExpr
_
(
DimsFn
FnUnpackedDimensions
(
Left
_
))
=
convertExpr
(
DimsFn
fn
(
Right
e
))
=
Number
"0"
DimsFn
fn
$
Left
$
TypeOf
e
convertExpr
_
(
DimsFn
FnDimensions
(
Left
t
))
=
convertExpr
(
DimFn
fn
(
Right
e
)
d
)
=
Number
$
show
$
DimFn
fn
(
Left
$
TypeOf
e
)
d
convertExpr
(
orig
@
(
DimsFn
FnUnpackedDimensions
(
Left
t
)))
=
case
t
of
case
t
of
IntegerAtom
_
_
->
1
UnpackedType
_
rs
->
Number
$
show
$
length
rs
_
->
length
$
snd
$
typeRanges
t
TypeOf
{}
->
orig
convertExpr
info
(
DimsFn
FnUnpackedDimensions
(
Right
(
Ident
x
)))
=
_
->
Number
"0"
case
Map
.
lookup
x
info
of
convertExpr
(
orig
@
(
DimsFn
FnDimensions
(
Left
t
)))
=
Nothing
->
DimsFn
FnUnpackedDimensions
$
Right
$
Ident
x
case
t
of
Just
(
_
,
rs
)
->
Number
$
show
$
length
rs
IntegerAtom
{}
->
Number
"1"
convertExpr
info
(
DimsFn
FnDimensions
(
Right
(
Ident
x
)))
=
Alias
{}
->
orig
case
Map
.
lookup
x
info
of
TypeOf
{}
->
orig
Nothing
->
DimsFn
FnDimensions
$
Right
$
Ident
x
UnpackedType
t'
rs
->
Just
(
t
,
rs
)
->
DimsFn
FnDimensions
$
Left
$
tf
rsCombine
d
BinOp
Ad
d
where
(
Number
$
show
$
length
rs
)
(
tf
,
trs
)
=
typeRanges
t
(
DimsFn
FnDimensions
$
Left
t'
)
rsCombined
=
rs
++
trs
_
->
Number
$
show
$
length
$
snd
$
typeRanges
t
-- conversion for array dimension functions on types
-- conversion for array dimension functions on types
convertExpr
_
(
DimFn
f
(
Left
t
)
(
Number
str
))
=
convertExpr
(
DimFn
f
(
Left
t
)
(
Number
str
))
=
if
dm
==
Nothing
||
is
Alias
t
then
if
dm
==
Nothing
||
is
Unresolved
t
then
DimFn
f
(
Left
t
)
(
Number
str
)
DimFn
f
(
Left
t
)
(
Number
str
)
else
if
d
<=
0
||
d
>
length
rs
then
else
if
d
<=
0
||
d
>
length
rs
then
Number
"'x"
Number
"'x"
...
@@ -112,80 +91,51 @@ convertExpr _ (DimFn f (Left t) (Number str)) =
...
@@ -112,80 +91,51 @@ convertExpr _ (DimFn f (Left t) (Number str)) =
FnHigh
->
endianCondExpr
r
(
fst
r
)
(
snd
r
)
FnHigh
->
endianCondExpr
r
(
fst
r
)
(
snd
r
)
FnSize
->
rangeSize
r
FnSize
->
rangeSize
r
where
where
(
_
,
rs
)
=
typeRanges
$
elaborateType
t
rs
=
case
elaborateType
t
of
UnpackedType
tInner
rsOuter
->
rsOuter
++
(
snd
$
typeRanges
$
elaborateType
tInner
)
_
->
snd
$
typeRanges
$
elaborateType
t
dm
=
readNumber
str
dm
=
readNumber
str
Just
d
=
dm
Just
d
=
dm
r
=
rs
!!
(
d
-
1
)
r
=
rs
!!
(
d
-
1
)
isAlias
::
Type
->
Bool
isUnresolved
::
Type
->
Bool
isAlias
(
Alias
_
_
_
)
=
True
isUnresolved
(
Alias
{})
=
True
isAlias
_
=
False
isUnresolved
(
TypeOf
{})
=
True
convertExpr
_
(
DimFn
f
(
Left
t
)
d
)
=
isUnresolved
_
=
False
convertExpr
(
DimFn
f
(
Left
t
)
d
)
=
DimFn
f
(
Left
t
)
d
DimFn
f
(
Left
t
)
d
-- conversion for array dimension functions on expression
convertExpr
other
=
other
convertExpr
info
(
DimFn
f
(
Right
(
Ident
x
))
d
)
=
case
Map
.
lookup
x
info
of
Nothing
->
DimFn
f
(
Right
(
Ident
x
))
d
Just
(
t
,
rs
)
->
DimFn
f
(
Left
$
tf
rsCombined
)
d
where
(
tf
,
trs
)
=
typeRanges
t
rsCombined
=
rs
++
trs
convertExpr
info
(
DimFn
f
(
Right
(
Bit
(
Ident
x
)
idx
))
d
)
=
case
Map
.
lookup
x
info
of
Nothing
->
DimFn
f
(
Right
$
Bit
(
Ident
x
)
idx
)
d
Just
(
t
,
rs
)
->
DimFn
f
(
Left
t'
)
d
where
t'
=
popRange
t
rs
convertExpr
_
(
DimFn
f
(
Right
e
)
d
)
=
DimFn
f
(
Right
e
)
d
convertExpr
_
other
=
other
-- simplify a bits expression
given scoped type information
-- simplify a bits expression
convertBits
::
Info
->
TypeOrExpr
->
Expr
convertBits
::
TypeOrExpr
->
Expr
convertBits
_
(
Left
t
)
=
convertBits
(
Left
t
)
=
case
elaborateType
t
of
case
elaborateType
t
of
IntegerVector
_
_
rs
->
dimensionsSize
rs
IntegerVector
_
_
rs
->
dimensionsSize
rs
Implicit
_
rs
->
dimensionsSize
rs
Implicit
_
rs
->
dimensionsSize
rs
Net
_
_
rs
->
dimensionsSize
rs
Net
_
_
rs
->
dimensionsSize
rs
UnpackedType
t'
rs
->
BinOp
Mul
(
dimensionsSize
rs
)
(
DimsFn
FnBits
$
Left
t'
)
_
->
DimsFn
FnBits
$
Left
t
_
->
DimsFn
FnBits
$
Left
t
convertBits
info
(
Right
e
)
=
convertBits
(
Right
e
)
=
case
e
of
case
e
of
Ident
x
->
case
Map
.
lookup
x
info
of
Nothing
->
DimsFn
FnBits
$
Right
e
Just
(
t
,
rs
)
->
simplify
$
BinOp
Mul
(
dimensionsSize
rs
)
(
convertBits
info
$
Left
t
)
Concat
exprs
->
Concat
exprs
->
foldl
(
BinOp
Add
)
(
Number
"0"
)
$
foldl
(
BinOp
Add
)
(
Number
"0"
)
$
map
(
convertBits
info
.
Right
)
$
map
(
convertBits
.
Right
)
$
exprs
exprs
Range
expr
mode
range
->
Range
expr
mode
range
->
simplify
$
BinOp
Mul
size
simplify
$
BinOp
Mul
size
(
convertBits
info
$
Right
$
Bit
expr
(
Number
"0"
))
(
convertBits
$
Right
$
Bit
expr
(
Number
"0"
))
where
where
size
=
case
mode
of
size
=
case
mode
of
NonIndexed
->
rangeSize
range
NonIndexed
->
rangeSize
range
IndexedPlus
->
snd
range
IndexedPlus
->
snd
range
IndexedMinus
->
snd
range
IndexedMinus
->
snd
range
Bit
(
Ident
x
)
idx
->
Stream
_
_
exprs
->
convertBits
$
Right
$
Concat
exprs
case
Map
.
lookup
x
info
of
Nothing
->
DimsFn
FnBits
$
Right
$
Bit
(
Ident
x
)
idx
Just
(
t
,
rs
)
->
convertBits
info
$
Left
t'
where
t'
=
popRange
t
rs
Stream
_
_
exprs
->
convertBits
info
$
Right
$
Concat
exprs
Number
n
->
Number
n
->
case
elemIndex
'
\'
'
n
of
case
elemIndex
'
\'
'
n
of
Nothing
->
Number
"32"
Nothing
->
Number
"32"
Just
idx
->
Number
$
take
idx
n
Just
idx
->
Number
$
take
idx
n
_
->
DimsFn
FnBits
$
Right
e
_
->
DimsFn
FnBits
$
Left
$
TypeOf
e
-- combines the given type and dimensions and returns a new type with the
-- innermost range removed
popRange
::
Type
->
[
Range
]
->
Type
popRange
t
rs
=
tf
$
tail
rsCombined
where
(
tf
,
trs
)
=
typeRanges
t
rsCombined
=
rs
++
trs
src/Convert/Traverse.hs
View file @
2bd24b60
...
@@ -50,6 +50,9 @@ module Convert.Traverse
...
@@ -50,6 +50,9 @@ module Convert.Traverse
,
traverseNestedTypesM
,
traverseNestedTypesM
,
traverseNestedTypes
,
traverseNestedTypes
,
collectNestedTypesM
,
collectNestedTypesM
,
traverseExprTypesM
,
traverseExprTypes
,
collectExprTypesM
,
traverseTypesM
,
traverseTypesM
,
traverseTypes
,
traverseTypes
,
collectTypesM
,
collectTypesM
...
@@ -422,10 +425,12 @@ traverseNestedExprsM :: Monad m => MapperM m Expr -> MapperM m Expr
...
@@ -422,10 +425,12 @@ traverseNestedExprsM :: Monad m => MapperM m Expr -> MapperM m Expr
traverseNestedExprsM
mapper
=
exprMapper
traverseNestedExprsM
mapper
=
exprMapper
where
where
exprMapper
e
=
mapper
e
>>=
em
exprMapper
e
=
mapper
e
>>=
em
(
_
,
_
,
_
,
_
,
typeMapper
)
=
exprMapperHelpers
exprMapper
maybeExprMapper
Nothing
=
return
Nothing
maybeExprMapper
Nothing
=
return
Nothing
maybeExprMapper
(
Just
e
)
=
maybeExprMapper
(
Just
e
)
=
exprMapper
e
>>=
return
.
Just
exprMapper
e
>>=
return
.
Just
typeOrExprMapper
(
Left
t
)
=
return
$
Left
t
typeOrExprMapper
(
Left
t
)
=
typeMapper
t
>>=
return
.
Left
typeOrExprMapper
(
Right
e
)
=
typeOrExprMapper
(
Right
e
)
=
exprMapper
e
>>=
return
.
Right
exprMapper
e
>>=
return
.
Right
exprOrRangeMapper
(
Left
e
)
=
exprOrRangeMapper
(
Left
e
)
=
...
@@ -861,6 +866,7 @@ traverseNestedTypesM mapper = fullMapper
...
@@ -861,6 +866,7 @@ traverseNestedTypesM mapper = fullMapper
tm
(
IntegerVector
kw
sg
rs
)
=
return
$
IntegerVector
kw
sg
rs
tm
(
IntegerVector
kw
sg
rs
)
=
return
$
IntegerVector
kw
sg
rs
tm
(
IntegerAtom
kw
sg
)
=
return
$
IntegerAtom
kw
sg
tm
(
IntegerAtom
kw
sg
)
=
return
$
IntegerAtom
kw
sg
tm
(
NonInteger
kw
)
=
return
$
NonInteger
kw
tm
(
NonInteger
kw
)
=
return
$
NonInteger
kw
tm
(
TypeOf
expr
)
=
return
$
TypeOf
expr
tm
(
InterfaceT
x
my
r
)
=
return
$
InterfaceT
x
my
r
tm
(
InterfaceT
x
my
r
)
=
return
$
InterfaceT
x
my
r
tm
(
Enum
Nothing
vals
r
)
=
tm
(
Enum
Nothing
vals
r
)
=
return
$
Enum
Nothing
vals
r
return
$
Enum
Nothing
vals
r
...
@@ -875,33 +881,45 @@ traverseNestedTypesM mapper = fullMapper
...
@@ -875,33 +881,45 @@ traverseNestedTypesM mapper = fullMapper
types
<-
mapM
fullMapper
$
map
fst
fields
types
<-
mapM
fullMapper
$
map
fst
fields
let
idents
=
map
snd
fields
let
idents
=
map
snd
fields
return
$
Union
p
(
zip
types
idents
)
r
return
$
Union
p
(
zip
types
idents
)
r
tm
(
TypeOf
expr
)
=
return
$
TypeOf
expr
tm
(
UnpackedType
t
r
)
=
do
t'
<-
fullMapper
t
return
$
UnpackedType
t'
r
traverseNestedTypes
::
Mapper
Type
->
Mapper
Type
traverseNestedTypes
::
Mapper
Type
->
Mapper
Type
traverseNestedTypes
=
unmonad
traverseNestedTypesM
traverseNestedTypes
=
unmonad
traverseNestedTypesM
collectNestedTypesM
::
Monad
m
=>
CollectorM
m
Type
->
CollectorM
m
Type
collectNestedTypesM
::
Monad
m
=>
CollectorM
m
Type
->
CollectorM
m
Type
collectNestedTypesM
=
collectify
traverseNestedTypesM
collectNestedTypesM
=
collectify
traverseNestedTypesM
traverseTypesM
::
Monad
m
=>
MapperM
m
Type
->
MapperM
m
ModuleItem
traverseExprTypesM
::
Monad
m
=>
MapperM
m
Type
->
MapperM
m
Expr
traverseTypesM
mapper
item
=
traverseExprTypesM
mapper
=
exprMapper
miMapper
item
>>=
traverseDeclsM
declMapper
>>=
traverseExprsM
(
traverseNestedExprsM
exprMapper
)
where
where
fullMapper
=
traverseNestedTypesM
mapper
maybeMapper
Nothing
=
return
Nothing
maybeMapper
(
Just
t
)
=
fullMapper
t
>>=
return
.
Just
typeOrExprMapper
(
Right
e
)
=
return
$
Right
e
typeOrExprMapper
(
Right
e
)
=
return
$
Right
e
typeOrExprMapper
(
Left
t
)
=
typeOrExprMapper
(
Left
t
)
=
fullM
apper
t
>>=
return
.
Left
m
apper
t
>>=
return
.
Left
exprMapper
(
Cast
(
Left
t
)
e
)
=
exprMapper
(
Cast
(
Left
t
)
e
)
=
fullM
apper
t
>>=
\
t'
->
return
$
Cast
(
Left
t'
)
e
m
apper
t
>>=
\
t'
->
return
$
Cast
(
Left
t'
)
e
exprMapper
(
DimsFn
f
tore
)
=
exprMapper
(
DimsFn
f
tore
)
=
typeOrExprMapper
tore
>>=
return
.
DimsFn
f
typeOrExprMapper
tore
>>=
return
.
DimsFn
f
exprMapper
(
DimFn
f
tore
e
)
=
do
exprMapper
(
DimFn
f
tore
e
)
=
do
tore'
<-
typeOrExprMapper
tore
tore'
<-
typeOrExprMapper
tore
return
$
DimFn
f
tore'
e
return
$
DimFn
f
tore'
e
exprMapper
other
=
return
other
exprMapper
other
=
return
other
traverseExprTypes
::
Mapper
Type
->
Mapper
Expr
traverseExprTypes
=
unmonad
traverseExprTypesM
collectExprTypesM
::
Monad
m
=>
CollectorM
m
Type
->
CollectorM
m
Expr
collectExprTypesM
=
collectify
traverseExprTypesM
traverseTypesM
::
Monad
m
=>
MapperM
m
Type
->
MapperM
m
ModuleItem
traverseTypesM
mapper
item
=
miMapper
item
>>=
traverseDeclsM
declMapper
>>=
traverseExprsM
(
traverseNestedExprsM
exprMapper
)
where
fullMapper
=
traverseNestedTypesM
mapper
maybeMapper
Nothing
=
return
Nothing
maybeMapper
(
Just
t
)
=
fullMapper
t
>>=
return
.
Just
exprMapper
=
traverseExprTypesM
fullMapper
declMapper
(
Param
s
t
x
e
)
=
declMapper
(
Param
s
t
x
e
)
=
fullMapper
t
>>=
\
t'
->
return
$
Param
s
t'
x
e
fullMapper
t
>>=
\
t'
->
return
$
Param
s
t'
x
e
declMapper
(
ParamType
s
x
mt
)
=
declMapper
(
ParamType
s
x
mt
)
=
...
...
src/Convert/TypeOf.hs
View file @
2bd24b60
...
@@ -12,13 +12,13 @@
...
@@ -12,13 +12,13 @@
module
Convert.TypeOf
(
convert
)
where
module
Convert.TypeOf
(
convert
)
where
import
Control.Monad.State
import
Control.Monad.State
import
Data.Maybe
(
mapMaybe
)
import
Data.Maybe
(
fromMaybe
,
mapMaybe
)
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Map.Strict
as
Map
import
Convert.Traverse
import
Convert.Traverse
import
Language.SystemVerilog.AST
import
Language.SystemVerilog.AST
type
Info
=
Map
.
Map
Identifier
(
Type
,
[
Range
])
type
Info
=
Map
.
Map
Identifier
Type
convert
::
[
AST
]
->
[
AST
]
convert
::
[
AST
]
->
[
AST
]
convert
=
map
$
traverseDescriptions
convertDescription
convert
=
map
$
traverseDescriptions
convertDescription
...
@@ -30,34 +30,37 @@ convertDescription (description @ Part{}) =
...
@@ -30,34 +30,37 @@ convertDescription (description @ Part{}) =
where
where
Part
_
_
_
_
_
_
items
=
description
Part
_
_
_
_
_
_
items
=
description
initialState
=
Map
.
fromList
$
mapMaybe
returnType
items
initialState
=
Map
.
fromList
$
mapMaybe
returnType
items
returnType
::
ModuleItem
->
Maybe
(
Identifier
,
(
Type
,
[
Range
])
)
returnType
::
ModuleItem
->
Maybe
(
Identifier
,
Type
)
returnType
(
MIPackageItem
(
Function
_
t
f
_
_
))
=
returnType
(
MIPackageItem
(
Function
_
t
f
_
_
))
=
Just
(
f
,
(
t'
,
[]
))
if
t
==
Implicit
Unspecified
[]
where
t'
=
if
t
==
Implicit
Unspecified
[]
-- functions with no return type implicitly return a single bit
then
IntegerVector
TLogic
Unspecified
[]
then
Just
(
f
,
IntegerVector
TLogic
Unspecified
[]
)
else
t
else
Just
(
f
,
t
)
returnType
_
=
Nothing
returnType
_
=
Nothing
convertDescription
other
=
other
convertDescription
other
=
other
traverseDeclM
::
Decl
->
State
Info
Decl
traverseDeclM
::
Decl
->
State
Info
Decl
traverseDeclM
decl
=
do
traverseDeclM
decl
=
do
case
decl
of
Variable
_
t
ident
a
_
->
modify
$
Map
.
insert
ident
(
t
,
a
)
Param
_
t
ident
_
->
modify
$
Map
.
insert
ident
(
t
,
[]
)
ParamType
_
_
_
->
return
()
item
<-
traverseModuleItemM
(
MIPackageItem
$
Decl
decl
)
item
<-
traverseModuleItemM
(
MIPackageItem
$
Decl
decl
)
let
MIPackageItem
(
Decl
decl'
)
=
item
let
MIPackageItem
(
Decl
decl'
)
=
item
return
decl'
case
decl'
of
Variable
d
t
ident
a
me
->
do
let
t'
=
injectRanges
t
a
modify
$
Map
.
insert
ident
t'
return
$
case
t'
of
UnpackedType
t''
a'
->
Variable
d
t''
ident
a'
me
_
->
Variable
d
t'
ident
[]
me
Param
_
t
ident
_
->
do
modify
$
Map
.
insert
ident
t
return
decl'
ParamType
_
_
_
->
return
decl'
traverseModuleItemM
::
ModuleItem
->
State
Info
ModuleItem
traverseModuleItemM
::
ModuleItem
->
State
Info
ModuleItem
traverseModuleItemM
item
=
traverseTypesM
traverseTypeM
item
traverseModuleItemM
item
=
traverseTypesM
traverseTypeM
item
traverseStmtM
::
Stmt
->
State
Info
Stmt
traverseStmtM
::
Stmt
->
State
Info
Stmt
traverseStmtM
stmt
=
do
traverseStmtM
=
let
item
=
Initial
stmt
traverseStmtExprsM
$
traverseNestedExprsM
$
traverseExprTypesM
traverseTypeM
item'
<-
traverseModuleItemM
item
let
Initial
stmt'
=
item'
return
stmt'
traverseTypeM
::
Type
->
State
Info
Type
traverseTypeM
::
Type
->
State
Info
Type
traverseTypeM
(
TypeOf
expr
)
=
typeof
expr
traverseTypeM
(
TypeOf
expr
)
=
typeof
expr
...
@@ -66,14 +69,23 @@ traverseTypeM other = return other
...
@@ -66,14 +69,23 @@ traverseTypeM other = return other
typeof
::
Expr
->
State
Info
Type
typeof
::
Expr
->
State
Info
Type
typeof
(
orig
@
(
Ident
x
))
=
do
typeof
(
orig
@
(
Ident
x
))
=
do
res
<-
gets
$
Map
.
lookup
x
res
<-
gets
$
Map
.
lookup
x
return
$
maybe
(
TypeOf
orig
)
injectRanges
res
return
$
fromMaybe
(
TypeOf
orig
)
res
typeof
(
orig
@
(
Call
(
Ident
x
)
_
))
=
do
typeof
(
orig
@
(
Call
(
Ident
x
)
_
))
=
do
res
<-
gets
$
Map
.
lookup
x
res
<-
gets
$
Map
.
lookup
x
return
$
maybe
(
TypeOf
orig
)
injectRanges
res
return
$
fromMaybe
(
TypeOf
orig
)
res
typeof
(
orig
@
(
Bit
(
Ident
x
)
_
))
=
do
res
<-
gets
$
Map
.
lookup
x
return
$
maybe
(
TypeOf
orig
)
popRange
res
typeof
other
=
return
$
TypeOf
other
typeof
other
=
return
$
TypeOf
other
-- combines a type with unpacked ranges
-- combines a type with unpacked ranges
injectRanges
::
(
Type
,
[
Range
])
->
Type
injectRanges
::
Type
->
[
Range
]
->
Type
injectRanges
(
t
,
unpacked
)
=
injectRanges
t
[]
=
t
tf
$
packed
++
unpacked
injectRanges
(
UnpackedType
t
rs
)
unpacked
=
UnpackedType
t
$
unpacked
++
rs
where
(
tf
,
packed
)
=
typeRanges
t
injectRanges
t
unpacked
=
UnpackedType
t
unpacked
-- removes the outermost range of the given type
popRange
::
Type
->
Type
popRange
t
=
tf
$
tail
rs
where
(
tf
,
rs
)
=
typeRanges
t
src/Convert/Typedef.hs
View file @
2bd24b60
...
@@ -51,6 +51,10 @@ convertDescription globalTypes description =
...
@@ -51,6 +51,10 @@ convertDescription globalTypes description =
MIPackageItem
$
Comment
$
"removed typedef: "
++
x
MIPackageItem
$
Comment
$
"removed typedef: "
++
x
removeTypedef
other
=
other
removeTypedef
other
=
other
convertTypeOrExpr
::
TypeOrExpr
->
TypeOrExpr
convertTypeOrExpr
::
TypeOrExpr
->
TypeOrExpr
convertTypeOrExpr
(
Left
(
TypeOf
(
Ident
x
)))
=
if
Map
.
member
x
types
then
Left
$
resolveType
types
(
Alias
Nothing
x
[]
)
else
Left
$
TypeOf
(
Ident
x
)
convertTypeOrExpr
(
Right
(
Ident
x
))
=
convertTypeOrExpr
(
Right
(
Ident
x
))
=
if
Map
.
member
x
types
if
Map
.
member
x
types
then
Left
$
resolveType
types
(
Alias
Nothing
x
[]
)
then
Left
$
resolveType
types
(
Alias
Nothing
x
[]
)
...
@@ -80,6 +84,7 @@ resolveType _ (InterfaceT x my rs) = InterfaceT x my rs
...
@@ -80,6 +84,7 @@ resolveType _ (InterfaceT x my rs) = InterfaceT x my rs
resolveType
_
(
Enum
Nothing
vals
rs
)
=
Enum
Nothing
vals
rs
resolveType
_
(
Enum
Nothing
vals
rs
)
=
Enum
Nothing
vals
rs
resolveType
_
(
Alias
(
Just
ps
)
st
rs
)
=
Alias
(
Just
ps
)
st
rs
resolveType
_
(
Alias
(
Just
ps
)
st
rs
)
=
Alias
(
Just
ps
)
st
rs
resolveType
_
(
TypeOf
expr
)
=
TypeOf
expr
resolveType
_
(
TypeOf
expr
)
=
TypeOf
expr
resolveType
_
(
UnpackedType
t
rs
)
=
UnpackedType
t
rs
resolveType
types
(
Enum
(
Just
t
)
vals
rs
)
=
Enum
(
Just
$
resolveType
types
t
)
vals
rs
resolveType
types
(
Enum
(
Just
t
)
vals
rs
)
=
Enum
(
Just
$
resolveType
types
t
)
vals
rs
resolveType
types
(
Struct
p
items
rs
)
=
Struct
p
(
map
(
resolveItem
types
)
items
)
rs
resolveType
types
(
Struct
p
items
rs
)
=
Struct
p
(
map
(
resolveItem
types
)
items
)
rs
resolveType
types
(
Union
p
items
rs
)
=
Union
p
(
map
(
resolveItem
types
)
items
)
rs
resolveType
types
(
Union
p
items
rs
)
=
Union
p
(
map
(
resolveItem
types
)
items
)
rs
...
@@ -95,6 +100,7 @@ resolveType types (Alias Nothing st rs1) =
...
@@ -95,6 +100,7 @@ resolveType types (Alias Nothing st rs1) =
(
Union
p
l
rs2
)
->
Union
p
l
$
rs1
++
rs2
(
Union
p
l
rs2
)
->
Union
p
l
$
rs1
++
rs2
(
InterfaceT
x
my
rs2
)
->
InterfaceT
x
my
$
rs1
++
rs2
(
InterfaceT
x
my
rs2
)
->
InterfaceT
x
my
$
rs1
++
rs2
(
Alias
ps
x
rs2
)
->
Alias
ps
x
$
rs1
++
rs2
(
Alias
ps
x
rs2
)
->
Alias
ps
x
$
rs1
++
rs2
(
UnpackedType
t
rs2
)
->
UnpackedType
t
$
rs1
++
rs2
(
IntegerAtom
kw
sg
)
->
nullRange
(
IntegerAtom
kw
sg
)
rs1
(
IntegerAtom
kw
sg
)
->
nullRange
(
IntegerAtom
kw
sg
)
rs1
(
NonInteger
kw
)
->
nullRange
(
NonInteger
kw
)
rs1
(
NonInteger
kw
)
->
nullRange
(
NonInteger
kw
)
rs1
(
TypeOf
expr
)
->
nullRange
(
TypeOf
expr
)
rs1
(
TypeOf
expr
)
->
nullRange
(
TypeOf
expr
)
rs1
src/Language/SystemVerilog/AST/Type.hs
View file @
2bd24b60
...
@@ -43,6 +43,7 @@ data Type
...
@@ -43,6 +43,7 @@ data Type
|
Union
Packing
[
Field
]
[
Range
]
|
Union
Packing
[
Field
]
[
Range
]
|
InterfaceT
Identifier
(
Maybe
Identifier
)
[
Range
]
|
InterfaceT
Identifier
(
Maybe
Identifier
)
[
Range
]
|
TypeOf
Expr
|
TypeOf
Expr
|
UnpackedType
Type
[
Range
]
-- used internally
deriving
(
Eq
,
Ord
)
deriving
(
Eq
,
Ord
)
instance
Show
Type
where
instance
Show
Type
where
...
@@ -62,6 +63,7 @@ instance Show Type where
...
@@ -62,6 +63,7 @@ instance Show Type where
show
(
Struct
p
items
r
)
=
printf
"struct %s{
\n
%s
\n
}%s"
(
showPad
p
)
(
showFields
items
)
(
showRanges
r
)
show
(
Struct
p
items
r
)
=
printf
"struct %s{
\n
%s
\n
}%s"
(
showPad
p
)
(
showFields
items
)
(
showRanges
r
)
show
(
Union
p
items
r
)
=
printf
"union %s{
\n
%s
\n
}%s"
(
showPad
p
)
(
showFields
items
)
(
showRanges
r
)
show
(
Union
p
items
r
)
=
printf
"union %s{
\n
%s
\n
}%s"
(
showPad
p
)
(
showFields
items
)
(
showRanges
r
)
show
(
TypeOf
expr
)
=
printf
"type(%s)"
(
show
expr
)
show
(
TypeOf
expr
)
=
printf
"type(%s)"
(
show
expr
)
show
(
UnpackedType
t
rs
)
=
printf
"UnpackedType(%s, %s)"
(
show
t
)
(
showRanges
rs
)
showFields
::
[
Field
]
->
String
showFields
::
[
Field
]
->
String
showFields
items
=
itemsStr
showFields
items
=
itemsStr
...
@@ -94,7 +96,8 @@ typeRanges (Enum t v r) = (Enum t v, r)
...
@@ -94,7 +96,8 @@ typeRanges (Enum t v r) = (Enum t v, r)
typeRanges
(
Struct
p
l
r
)
=
(
Struct
p
l
,
r
)
typeRanges
(
Struct
p
l
r
)
=
(
Struct
p
l
,
r
)
typeRanges
(
Union
p
l
r
)
=
(
Union
p
l
,
r
)
typeRanges
(
Union
p
l
r
)
=
(
Union
p
l
,
r
)
typeRanges
(
InterfaceT
x
my
r
)
=
(
InterfaceT
x
my
,
r
)
typeRanges
(
InterfaceT
x
my
r
)
=
(
InterfaceT
x
my
,
r
)
typeRanges
(
TypeOf
expr
)
=
(
nullRange
$
TypeOf
expr
,
[]
)
typeRanges
(
TypeOf
expr
)
=
(
UnpackedType
$
TypeOf
expr
,
[]
)
typeRanges
(
UnpackedType
t
rs
)
=
(
UnpackedType
t
,
rs
)
nullRange
::
Type
->
([
Range
]
->
Type
)
nullRange
::
Type
->
([
Range
]
->
Type
)
nullRange
t
[]
=
t
nullRange
t
[]
=
t
...
...
test/basic/dimensions.sv
View file @
2bd24b60
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
module
top
;
module
top
;
typedef
logic
[
16
:
1
]
Word
;
typedef
logic
[
16
:
1
]
Word
;
Word
Ram
[
0
:
9
]
;
Word
Ram
[
0
:
9
]
;
type
(
Ram
)
RamPair
[
2
]
;
integer
ints
[
3
:
0
]
;
integer
ints
[
3
:
0
]
;
typedef
struct
packed
{
logic
x
,
y
,
z
;
}
T
;
typedef
struct
packed
{
logic
x
,
y
,
z
;
}
T
;
logic
[$
size
(
T
)
-
1
:
0
]
foo
;
logic
[$
size
(
T
)
-
1
:
0
]
foo
;
...
@@ -22,6 +23,8 @@ module top;
...
@@ -22,6 +23,8 @@ module top;
$
display
($
bits
(
foo
))
;
$
display
($
bits
(
foo
))
;
`EXHAUST
(
Ram
)
;
`EXHAUST
(
Ram
)
;
`EXHAUST
(
RamPair
)
;
`EXHAUST
(
RamPair
[
0
])
;
`EXHAUST
(
Word
)
;
`EXHAUST
(
Word
)
;
`EXHAUST
(
integer
)
;
`EXHAUST
(
integer
)
;
`EXHAUST
(
bit
)
;
`EXHAUST
(
bit
)
;
...
...
test/basic/dimensions.v
View file @
2bd24b60
...
@@ -15,6 +15,26 @@ module top;
...
@@ -15,6 +15,26 @@ module top;
$
display
(
1
)
;
$
display
(
1
)
;
$
display
(
160
)
;
$
display
(
160
)
;
$
display
(
2
,
2
,
10
)
;
$
display
(
0
,
0
,
0
)
;
$
display
(
1
,
1
,
9
)
;
$
display
(
1
,
1
,
9
)
;
$
display
(
0
,
0
,
0
)
;
$
display
(
-
1
,
-
1
,
-
1
)
;
$
display
(
3
)
;
$
display
(
2
)
;
$
display
(
320
)
;
$
display
(
10
,
10
,
16
)
;
$
display
(
0
,
0
,
16
)
;
$
display
(
9
,
9
,
1
)
;
$
display
(
9
,
9
,
16
)
;
$
display
(
0
,
0
,
1
)
;
$
display
(
-
1
,
-
1
,
1
)
;
$
display
(
2
)
;
$
display
(
1
)
;
$
display
(
160
)
;
$
display
(
16
,
16
,
1'bx
)
;
$
display
(
16
,
16
,
1'bx
)
;
$
display
(
16
,
16
,
1'bx
)
;
$
display
(
16
,
16
,
1'bx
)
;
$
display
(
1
,
1
,
1'bx
)
;
$
display
(
1
,
1
,
1'bx
)
;
...
...
test/basic/shadow_recurse.sv
0 → 100644
View file @
2bd24b60
module
top
;
initial
begin
logic
x
;
$
display
($
bits
(
x
))
;
begin
logic
[
0
:
$
bits
(
x
)]
x
;
$
display
($
bits
(
x
))
;
begin
logic
[
0
:
$
bits
(
x
)]
x
;
$
display
($
bits
(
x
))
;
end
end
end
initial
begin
logic
x
;
$
display
($
bits
(
type
(
x
)))
;
begin
logic
[
0
:
$
bits
(
type
(
x
))]
x
;
$
display
($
bits
(
type
(
x
)))
;
begin
logic
[
0
:
$
bits
(
type
(
x
))]
x
;
$
display
($
bits
(
type
(
x
)))
;
end
end
end
initial
begin
logic
x
;
$
display
($
bits
(
x
))
;
begin
logic
[
0
:
$
bits
(
type
(
x
))]
x
;
$
display
($
bits
(
x
))
;
begin
logic
[
0
:
$
bits
(
type
(
x
))]
x
;
$
display
($
bits
(
x
))
;
end
end
end
initial
begin
logic
x
;
$
display
($
bits
(
type
(
x
)))
;
begin
logic
[
0
:
$
bits
(
x
)]
x
;
$
display
($
bits
(
type
(
x
)))
;
begin
logic
[
0
:
$
bits
(
x
)]
x
;
$
display
($
bits
(
type
(
x
)))
;
end
end
end
endmodule
test/basic/shadow_recurse.v
0 → 100644
View file @
2bd24b60
module
top
;
initial
begin
$
display
(
1
)
;
$
display
(
2
)
;
$
display
(
3
)
;
end
initial
begin
$
display
(
1
)
;
$
display
(
2
)
;
$
display
(
3
)
;
end
initial
begin
$
display
(
1
)
;
$
display
(
2
)
;
$
display
(
3
)
;
end
initial
begin
$
display
(
1
)
;
$
display
(
2
)
;
$
display
(
3
)
;
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