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
378ede9e
Commit
378ede9e
authored
Jan 24, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
standardize internal representation of unknown types
parent
58e5bfa6
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
38 additions
and
35 deletions
+38
-35
src/Convert/Interface.hs
+4
-4
src/Convert/ParamNoDefault.hs
+4
-4
src/Convert/ParamType.hs
+8
-4
src/Convert/StringParam.hs
+0
-4
src/Convert/Traverse.hs
+5
-5
src/Convert/TypeOf.hs
+0
-4
src/Convert/Typedef.hs
+1
-1
src/Language/SystemVerilog/AST/Decl.hs
+5
-4
src/Language/SystemVerilog/AST/Type.hs
+6
-0
src/Language/SystemVerilog/Parser/Parse.y
+5
-5
No files found.
src/Convert/Interface.hs
View file @
378ede9e
...
...
@@ -490,7 +490,7 @@ inlineInstance ranges modportBindings items
parameterBinds
=
map
makeParameterBind
instanceParams
makeParameterBind
::
ParamBinding
->
Decl
makeParameterBind
(
x
,
Left
t
)
=
ParamType
Localparam
(
paramTmp
++
x
)
(
Just
t
)
ParamType
Localparam
(
paramTmp
++
x
)
t
makeParameterBind
(
x
,
Right
e
)
=
Param
Localparam
(
TypeOf
e
)
(
paramTmp
++
x
)
e
...
...
@@ -501,11 +501,11 @@ inlineInstance ranges modportBindings items
Just
(
Right
_
)
->
Param
Localparam
t
x
(
Ident
$
paramTmp
++
x
)
Just
(
Left
t'
)
->
error
$
inlineKind
++
" param "
++
x
++
" expected expr, found type: "
++
show
t'
overrideParam
(
ParamType
Parameter
x
m
t
)
=
overrideParam
(
ParamType
Parameter
x
t
)
=
case
lookup
x
instanceParams
of
Nothing
->
ParamType
Localparam
x
m
t
Nothing
->
ParamType
Localparam
x
t
Just
(
Left
_
)
->
ParamType
Localparam
x
(
Just
$
Alias
(
paramTmp
++
x
)
[]
)
ParamType
Localparam
x
$
Alias
(
paramTmp
++
x
)
[]
Just
(
Right
e'
)
->
error
$
inlineKind
++
" param "
++
x
++
" expected type, found expr: "
++
show
e'
overrideParam
other
=
other
...
...
src/Convert/ParamNoDefault.hs
View file @
378ede9e
...
...
@@ -55,12 +55,12 @@ traverseDeclM (Param Parameter t x e) = do
return
$
if
e
==
Nil
then
Param
Parameter
t
x
$
RawNum
0
else
Param
Parameter
t
x
e
traverseDeclM
(
ParamType
Localparam
x
Nothing
)
=
traverseDeclM
(
ParamType
Localparam
x
UnknownType
)
=
error
$
"localparam type "
++
show
x
++
" has no default value"
traverseDeclM
(
ParamType
Parameter
x
m
t
)
=
do
traverseDeclM
(
ParamType
Parameter
x
t
)
=
do
-- parameter types are rewritten separately, so no fake default here
tell
[(
x
,
mt
==
Nothing
)]
return
$
ParamType
Parameter
x
m
t
tell
[(
x
,
t
==
UnknownType
)]
return
$
ParamType
Parameter
x
t
traverseDeclM
other
=
return
other
-- check for instances missing values for parameters without defaults
...
...
src/Convert/ParamType.hs
View file @
378ede9e
...
...
@@ -116,7 +116,7 @@ convert files =
traverseModuleItems
(
traverseDecls
rewriteDecl
)
part
rewriteDecl
::
Decl
->
Decl
rewriteDecl
(
ParamType
Parameter
x
_
)
=
ParamType
Parameter
x
Nothing
ParamType
Parameter
x
UnknownType
rewriteDecl
other
=
other
removeDefaultTypeParams
_
=
error
"not possible"
...
...
@@ -152,7 +152,7 @@ convert files =
items'
=
map
(
traverseDecls
rewriteDecl
)
items
rewriteDecl
::
Decl
->
Decl
rewriteDecl
(
ParamType
Parameter
x
_
)
=
ParamType
Localparam
x
(
Just
$
fst
$
typeMap
Map
.!
x
)
ParamType
Localparam
x
(
fst
$
typeMap
Map
.!
x
)
rewriteDecl
other
=
other
additionalParamItems
=
concatMap
makeAddedParams
$
Map
.
toList
$
Map
.
map
snd
typeMap
...
...
@@ -170,7 +170,7 @@ convert files =
typ
=
Alias
(
addedParamTypeName
paramName
ident
)
[]
name
=
addedParamName
paramName
ident
toTypeParam
::
Identifier
->
Decl
toTypeParam
ident
=
ParamType
Parameter
name
Nothing
toTypeParam
ident
=
ParamType
Parameter
name
UnknownType
where
name
=
addedParamTypeName
paramName
ident
-- write down module parameter names and type parameters
...
...
@@ -184,9 +184,13 @@ collectDescriptionM (part @ (Part _ _ _ _ name _ _)) =
maybeTypeMap
=
Map
.
fromList
$
map
(
\
(
x
,
y
)
->
(
x
,
fromJust
y
))
$
filter
(
isJust
.
snd
)
params
--- TODO FIXME XXX
collectDeclM
::
Decl
->
Writer
[(
Identifier
,
Maybe
(
Maybe
Type
))]
()
collectDeclM
(
Param
Parameter
_
x
_
)
=
tell
[(
x
,
Nothing
)]
collectDeclM
(
ParamType
Parameter
x
v
)
=
tell
[(
x
,
Just
v
)]
collectDeclM
(
ParamType
Parameter
x
v
)
=
if
v
==
UnknownType
then
tell
[(
x
,
Just
Nothing
)]
else
tell
[(
x
,
Just
$
Just
v
)]
collectDeclM
_
=
return
()
collectDescriptionM
_
=
return
()
...
...
src/Convert/StringParam.hs
View file @
378ede9e
{-# LANGUAGE PatternSynonyms #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
...
...
@@ -52,9 +51,6 @@ parameterNames =
collectDeclM
(
ParamType
Parameter
x
_
)
=
tell
[
x
]
collectDeclM
_
=
return
()
pattern
UnknownType
::
Type
pattern
UnknownType
=
Implicit
Unspecified
[]
-- rewrite an existing string parameter
traverseModuleItemM
::
ModuleItem
->
Writer
[
Identifier
]
ModuleItem
traverseModuleItemM
(
orig
@
(
MIPackageItem
(
Decl
(
Param
Parameter
t
x
e
))))
=
...
...
src/Convert/Traverse.hs
View file @
378ede9e
...
...
@@ -913,9 +913,9 @@ traverseDeclExprsM exprMapper =
t'
<-
typeMapper
t
e'
<-
exprMapper
e
return
$
Param
s
t'
x
e'
declMapper
(
ParamType
s
x
m
t
)
=
do
mt'
<-
mapM
typeMapper
m
t
return
$
ParamType
s
x
m
t'
declMapper
(
ParamType
s
x
t
)
=
do
t'
<-
typeMapper
t
return
$
ParamType
s
x
t'
declMapper
(
Variable
d
t
x
a
e
)
=
do
t'
<-
typeMapper
t
a'
<-
mapM
(
mapBothM
exprMapper
)
a
...
...
@@ -932,8 +932,8 @@ collectDeclExprsM = collectify traverseDeclExprsM
traverseDeclTypesM
::
Monad
m
=>
MapperM
m
Type
->
MapperM
m
Decl
traverseDeclTypesM
mapper
(
Param
s
t
x
e
)
=
mapper
t
>>=
\
t'
->
return
$
Param
s
t'
x
e
traverseDeclTypesM
mapper
(
ParamType
s
x
m
t
)
=
map
M
mapper
mt
>>=
\
mt'
->
return
$
ParamType
s
x
m
t'
traverseDeclTypesM
mapper
(
ParamType
s
x
t
)
=
map
per
t
>>=
\
t'
->
return
$
ParamType
s
x
t'
traverseDeclTypesM
mapper
(
Variable
d
t
x
a
e
)
=
mapper
t
>>=
\
t'
->
return
$
Variable
d
t'
x
a
e
traverseDeclTypesM
_
(
CommentDecl
c
)
=
return
$
CommentDecl
c
...
...
src/Convert/TypeOf.hs
View file @
378ede9e
...
...
@@ -27,10 +27,6 @@ convert :: [AST] -> [AST]
convert
=
map
$
traverseDescriptions
$
partScoper
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
-- internal representation of a fully implicit type
pattern
UnknownType
::
Type
pattern
UnknownType
=
Implicit
Unspecified
[]
-- single bit 4-state `logic` type
pattern
UnitType
::
Type
pattern
UnitType
=
IntegerVector
TLogic
Unspecified
[]
...
...
src/Convert/Typedef.hs
View file @
378ede9e
...
...
@@ -70,7 +70,7 @@ traverseDeclM decl = do
case
decl'
of
Variable
{}
->
return
decl'
Param
{}
->
return
decl'
ParamType
Localparam
x
(
Just
t
)
->
do
ParamType
Localparam
x
t
->
do
t'
<-
traverseNestedTypesM
traverseTypeM
t
insertElem
x
t'
return
$
CommentDecl
$
"removed localparam type "
++
x
...
...
src/Language/SystemVerilog/AST/Decl.hs
View file @
378ede9e
{-# LANGUAGE PatternSynonyms #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
...
...
@@ -16,12 +17,12 @@ module Language.SystemVerilog.AST.Decl
import
Text.Printf
(
printf
)
import
Language.SystemVerilog.AST.ShowHelp
(
showPad
,
unlines'
)
import
Language.SystemVerilog.AST.Type
(
Type
,
Identifier
)
import
Language.SystemVerilog.AST.Type
(
Type
,
Identifier
,
pattern
UnknownType
)
import
Language.SystemVerilog.AST.Expr
(
Expr
,
Range
,
showRanges
,
showAssignment
)
data
Decl
=
Param
ParamScope
Type
Identifier
Expr
|
ParamType
ParamScope
Identifier
(
Maybe
Type
)
|
ParamType
ParamScope
Identifier
Type
|
Variable
Direction
Type
Identifier
[
Range
]
Expr
|
CommentDecl
String
deriving
(
Eq
,
Ord
)
...
...
@@ -29,8 +30,8 @@ data Decl
instance
Show
Decl
where
showList
l
_
=
unlines'
$
map
show
l
show
(
Param
s
t
x
e
)
=
printf
"%s %s%s%s;"
(
show
s
)
(
showPad
t
)
x
(
showAssignment
e
)
show
(
ParamType
s
x
m
t
)
=
printf
"%s type %s%s;"
(
show
s
)
x
tStr
where
tStr
=
maybe
""
((
" = "
++
)
.
show
)
m
t
show
(
ParamType
s
x
t
)
=
printf
"%s type %s%s;"
(
show
s
)
x
tStr
where
tStr
=
if
t
==
UnknownType
then
""
else
" = "
++
show
t
show
(
Variable
d
t
x
a
e
)
=
printf
"%s%s%s%s%s;"
(
showPad
d
)
(
showPad
t
)
x
(
showRanges
a
)
(
showAssignment
e
)
show
(
CommentDecl
c
)
=
if
elem
'
\n
'
c
...
...
src/Language/SystemVerilog/AST/Type.hs
View file @
378ede9e
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PatternSynonyms #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
...
...
@@ -21,6 +22,7 @@ module Language.SystemVerilog.AST.Type
,
Strength0
(
..
)
,
Strength1
(
..
)
,
ChargeStrength
(
..
)
,
pattern
UnknownType
,
typeRanges
,
nullRange
,
elaborateIntegerAtom
...
...
@@ -80,6 +82,10 @@ showFields items = itemsStr
itemsStr
=
indent
$
unlines'
$
map
showItem
items
showItem
(
t
,
x
)
=
printf
"%s %s;"
(
show
t
)
x
-- internal representation of a fully implicit or unknown type
pattern
UnknownType
::
Type
pattern
UnknownType
=
Implicit
Unspecified
[]
instance
Show
([
Range
]
->
Type
)
where
show
tf
=
show
(
tf
[]
)
instance
Eq
([
Range
]
->
Type
)
where
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
378ede9e
...
...
@@ -1077,12 +1077,12 @@ ParameterDeclKW :: { ParamScope }
:
"parameter"
{
Parameter
}
|
"localparam"
{
Localparam
}
TypeAsgns
::
{
[(
Identifier
,
Maybe
Type
)]
}
TypeAsgns
::
{
[(
Identifier
,
Type
)]
}
:
TypeAsgn
{
[
$
1
]
}
|
TypeAsgns
","
TypeAsgn
{
$
1
++
[
$
3
]
}
TypeAsgn
::
{
(
Identifier
,
Maybe
Type
)
}
:
Identifier
"="
Type
{
(
$
1
,
Just
$
3
)
}
|
Identifier
{
(
$
1
,
Nothing
)
}
TypeAsgn
::
{
(
Identifier
,
Type
)
}
:
Identifier
"="
Type
{
(
$
1
,
$
3
)
}
|
Identifier
{
(
$
1
,
UnknownType
)
}
-- TODO: This does not allow for @identifier
ClockingEvent
::
{
Sense
}
...
...
@@ -1476,7 +1476,7 @@ validateGenCases items =
makeLocalparam
::
Decl
->
Decl
makeLocalparam
(
Param
_
t
x
e
)
=
Param
Localparam
t
x
e
makeLocalparam
(
ParamType
_
x
mt
)
=
ParamType
Localparam
x
m
t
makeLocalparam
(
ParamType
_
x
t
)
=
ParamType
Localparam
x
t
makeLocalparam
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