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
5d80c830
Commit
5d80c830
authored
Sep 15, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for module attributes (resolves #39)
parent
bb2a8feb
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
59 additions
and
49 deletions
+59
-49
src/Convert/EmptyArgs.hs
+1
-1
src/Convert/Enum.hs
+3
-3
src/Convert/Interface.hs
+4
-4
src/Convert/Logic.hs
+3
-3
src/Convert/NestPI.hs
+3
-2
src/Convert/ParamType.hs
+10
-10
src/Convert/StarPort.hs
+1
-1
src/Convert/Stream.hs
+3
-3
src/Convert/Struct.hs
+3
-3
src/Convert/Traverse.hs
+8
-8
src/Convert/Typedef.hs
+1
-1
src/Language/SystemVerilog/AST/Description.hs
+9
-6
src/Language/SystemVerilog/Parser/Parse.y
+8
-2
test/basic/attr.sv
+1
-1
test/basic/attr.v
+1
-1
No files found.
src/Convert/EmptyArgs.hs
View file @
5d80c830
...
@@ -20,7 +20,7 @@ convert :: [AST] -> [AST]
...
@@ -20,7 +20,7 @@ convert :: [AST] -> [AST]
convert
=
map
$
traverseDescriptions
convertDescription
convert
=
map
$
traverseDescriptions
convertDescription
convertDescription
::
Description
->
Description
convertDescription
::
Description
->
Description
convertDescription
(
description
@
(
Part
_
_
_
_
_
_
)
)
=
convertDescription
(
description
@
Part
{}
)
=
traverseModuleItems
traverseModuleItems
(
traverseExprs
$
traverseNestedExprs
$
convertExpr
functions
)
(
traverseExprs
$
traverseNestedExprs
$
convertExpr
functions
)
description'
description'
...
...
src/Convert/Enum.hs
View file @
5d80c830
...
@@ -40,11 +40,11 @@ defaultType :: Type
...
@@ -40,11 +40,11 @@ defaultType :: Type
defaultType
=
IntegerVector
TLogic
Unspecified
[(
Number
"31"
,
Number
"0"
)]
defaultType
=
IntegerVector
TLogic
Unspecified
[(
Number
"31"
,
Number
"0"
)]
convertDescription
::
Description
->
Description
convertDescription
::
Description
->
Description
convertDescription
(
description
@
(
Part
_
_
_
_
_
_
)
)
=
convertDescription
(
description
@
Part
{}
)
=
Part
extern
kw
lifetime
name
ports
(
enumItems
++
items
)
Part
attrs
extern
kw
lifetime
name
ports
(
enumItems
++
items
)
where
where
-- replace and collect the enum types in this description
-- replace and collect the enum types in this description
(
Part
extern
kw
lifetime
name
ports
items
,
enumPairs
)
=
(
Part
attrs
extern
kw
lifetime
name
ports
items
,
enumPairs
)
=
convertDescription'
description
convertDescription'
description
-- convert the collected enums into their corresponding localparams
-- convert the collected enums into their corresponding localparams
enumItems
=
map
MIPackageItem
$
map
toItem
$
sortOn
snd
$
convergeUsage
items
enumPairs
enumItems
=
map
MIPackageItem
$
map
toItem
$
sortOn
snd
$
convergeUsage
items
enumPairs
...
...
src/Convert/Interface.hs
View file @
5d80c830
...
@@ -29,7 +29,7 @@ convert =
...
@@ -29,7 +29,7 @@ convert =
map
(
convertDescription
interfaces
modules
)
map
(
convertDescription
interfaces
modules
)
-- we can only collect/map non-extern interfaces
-- we can only collect/map non-extern interfaces
collectDesc
::
Description
->
Writer
(
Interfaces
,
Modules
)
()
collectDesc
::
Description
->
Writer
(
Interfaces
,
Modules
)
()
collectDesc
(
orig
@
(
Part
False
kw
_
name
ports
items
))
=
do
collectDesc
(
orig
@
(
Part
_
False
kw
_
name
ports
items
))
=
do
if
kw
==
Interface
if
kw
==
Interface
then
tell
(
Map
.
singleton
name
(
ports
,
items
),
Map
.
empty
)
then
tell
(
Map
.
singleton
name
(
ports
,
items
),
Map
.
empty
)
else
collectModuleItemsM
(
collectDeclsM
$
collectDecl
name
)
orig
else
collectModuleItemsM
(
collectDeclsM
$
collectDecl
name
)
orig
...
@@ -39,12 +39,12 @@ convert =
...
@@ -39,12 +39,12 @@ convert =
tell
(
Map
.
empty
,
Map
.
singleton
(
name
,
ident
)
t
)
tell
(
Map
.
empty
,
Map
.
singleton
(
name
,
ident
)
t
)
collectDecl
_
_
=
return
()
collectDecl
_
_
=
return
()
isInterface
::
Description
->
Bool
isInterface
::
Description
->
Bool
isInterface
(
Part
False
Interface
_
_
_
_
)
=
True
isInterface
(
Part
_
False
Interface
_
_
_
_
)
=
True
isInterface
_
=
False
isInterface
_
=
False
convertDescription
::
Interfaces
->
Modules
->
Description
->
Description
convertDescription
::
Interfaces
->
Modules
->
Description
->
Description
convertDescription
interfaces
modules
(
Part
extern
Module
lifetime
name
ports
items
)
=
convertDescription
interfaces
modules
(
Part
attrs
extern
Module
lifetime
name
ports
items
)
=
Part
extern
Module
lifetime
name
ports'
items'
Part
attrs
extern
Module
lifetime
name
ports'
items'
where
where
items'
=
items'
=
map
(
traverseNestedModuleItems
$
traverseExprs'
ExcludeTFs
(
traverseNestedExprs
$
convertExpr
instances
modports
))
$
map
(
traverseNestedModuleItems
$
traverseExprs'
ExcludeTFs
(
traverseNestedExprs
$
convertExpr
instances
modports
))
$
...
...
src/Convert/Logic.hs
View file @
5d80c830
...
@@ -42,7 +42,7 @@ convert =
...
@@ -42,7 +42,7 @@ convert =
(
traverseDescriptions
.
convertDescription
)
(
traverseDescriptions
.
convertDescription
)
where
where
collectPortsM
::
Description
->
Writer
Ports
()
collectPortsM
::
Description
->
Writer
Ports
()
collectPortsM
(
orig
@
(
Part
_
_
_
name
portNames
_
))
=
collectPortsM
(
orig
@
(
Part
_
_
_
_
name
portNames
_
))
=
collectModuleItemsM
collectPortDirsM
orig
collectModuleItemsM
collectPortDirsM
orig
where
where
collectPortDirsM
::
ModuleItem
->
Writer
Ports
()
collectPortDirsM
::
ModuleItem
->
Writer
Ports
()
...
@@ -64,8 +64,8 @@ convertDescription ports orig =
...
@@ -64,8 +64,8 @@ convertDescription ports orig =
else
orig
else
orig
where
where
shouldConvert
=
case
orig
of
shouldConvert
=
case
orig
of
Part
_
Interface
_
_
_
_
->
False
Part
_
_
Interface
_
_
_
_
->
False
Part
_
Module
_
_
_
_
->
True
Part
_
_
Module
_
_
_
_
->
True
PackageItem
_
->
True
PackageItem
_
->
True
Package
_
_
_
->
False
Package
_
_
_
->
False
Directive
_
->
False
Directive
_
->
False
...
...
src/Convert/NestPI.hs
View file @
5d80c830
...
@@ -45,9 +45,10 @@ collectDescriptionM _ = return ()
...
@@ -45,9 +45,10 @@ collectDescriptionM _ = return ()
-- nests packages items missing from modules
-- nests packages items missing from modules
convertDescription
::
PIs
->
Description
->
Description
convertDescription
::
PIs
->
Description
->
Description
convertDescription
pis
(
orig
@
(
Part
extern
kw
lifetime
name
ports
items
)
)
=
convertDescription
pis
(
orig
@
Part
{}
)
=
Part
extern
kw
lifetime
name
ports
(
newItems
++
items
)
Part
attrs
extern
kw
lifetime
name
ports
(
newItems
++
items
)
where
where
Part
attrs
extern
kw
lifetime
name
ports
items
=
orig
existingPIs
=
execWriter
$
collectModuleItemsM
collectPIsM
orig
existingPIs
=
execWriter
$
collectModuleItemsM
collectPIsM
orig
runner
f
=
execWriter
$
collectModuleItemsM
f
orig
runner
f
=
execWriter
$
collectModuleItemsM
f
orig
usedPIs
=
Set
.
unions
$
map
runner
$
usedPIs
=
Set
.
unions
$
map
runner
$
...
...
src/Convert/ParamType.hs
View file @
5d80c830
...
@@ -39,7 +39,7 @@ convert files =
...
@@ -39,7 +39,7 @@ convert files =
-- add type parameter instantiations
-- add type parameter instantiations
files''
=
map
(
concatMap
explodeDescription
)
files'
files''
=
map
(
concatMap
explodeDescription
)
files'
explodeDescription
::
Description
->
[
Description
]
explodeDescription
::
Description
->
[
Description
]
explodeDescription
(
part
@
(
Part
_
_
_
name
_
_
))
=
explodeDescription
(
part
@
(
Part
_
_
_
_
name
_
_
))
=
if
null
theseInstances
then
if
null
theseInstances
then
[
part
]
[
part
]
else
else
...
@@ -52,7 +52,7 @@ convert files =
...
@@ -52,7 +52,7 @@ convert files =
isNonDefault
=
(
name
/=
)
.
moduleName
isNonDefault
=
(
name
/=
)
.
moduleName
alreadyExists
=
(
flip
Map
.
member
info
)
.
moduleName
alreadyExists
=
(
flip
Map
.
member
info
)
.
moduleName
moduleName
::
Description
->
Identifier
moduleName
::
Description
->
Identifier
moduleName
(
Part
_
_
_
x
_
_
)
=
x
moduleName
(
Part
_
_
_
_
x
_
_
)
=
x
moduleName
_
=
error
"not possible"
moduleName
_
=
error
"not possible"
explodeDescription
other
=
[
other
]
explodeDescription
other
=
[
other
]
...
@@ -65,7 +65,7 @@ convert files =
...
@@ -65,7 +65,7 @@ convert files =
usedTypedModules
=
Map
.
unionsWith
Set
.
union
$
map
(
uncurry
usedTypedModules
=
Map
.
unionsWith
Set
.
union
$
map
(
uncurry
Map
.
singleton
)
usedTypedModulesRaw
Map
.
singleton
)
usedTypedModulesRaw
collectUsageInfoM
::
Description
->
Writer
(
UsageMap
,
UsageMap
)
()
collectUsageInfoM
::
Description
->
Writer
(
UsageMap
,
UsageMap
)
()
collectUsageInfoM
(
part
@
(
Part
_
_
_
name
_
_
))
=
collectUsageInfoM
(
part
@
(
Part
_
_
_
_
name
_
_
))
=
tell
(
makeList
used
,
makeList
usedTyped
)
tell
(
makeList
used
,
makeList
usedTyped
)
where
where
makeList
s
=
zip
(
Set
.
toList
s
)
(
repeat
$
Set
.
singleton
name
)
makeList
s
=
zip
(
Set
.
toList
s
)
(
repeat
$
Set
.
singleton
name
)
...
@@ -83,7 +83,7 @@ convert files =
...
@@ -83,7 +83,7 @@ convert files =
else
tell
(
Set
.
singleton
m
,
Set
.
empty
)
else
tell
(
Set
.
singleton
m
,
Set
.
empty
)
collectModuleItemM
_
=
return
()
collectModuleItemM
_
=
return
()
replaceDefault
::
Description
->
[
Description
]
replaceDefault
::
Description
->
[
Description
]
replaceDefault
(
part
@
(
Part
_
_
_
name
_
_
))
=
replaceDefault
(
part
@
(
Part
_
_
_
_
name
_
_
))
=
if
Map
.
notMember
name
info
then
if
Map
.
notMember
name
info
then
[
part
]
[
part
]
else
if
Map
.
null
maybeTypeMap
then
else
if
Map
.
null
maybeTypeMap
then
...
@@ -103,10 +103,10 @@ convert files =
...
@@ -103,10 +103,10 @@ convert files =
replaceDefault
other
=
[
other
]
replaceDefault
other
=
[
other
]
removeDefaultTypeParams
::
Description
->
Description
removeDefaultTypeParams
::
Description
->
Description
removeDefaultTypeParams
(
part
@
(
Part
_
_
_
_
_
_
)
)
=
removeDefaultTypeParams
(
part
@
Part
{}
)
=
Part
extern
kw
ml
(
moduleDefaultName
name
)
p
items
Part
attrs
extern
kw
ml
(
moduleDefaultName
name
)
p
items
where
where
Part
extern
kw
ml
name
p
items
=
Part
attrs
extern
kw
ml
name
p
items
=
traverseModuleItems
(
traverseDecls
rewriteDecl
)
part
traverseModuleItems
(
traverseDecls
rewriteDecl
)
part
rewriteDecl
::
Decl
->
Decl
rewriteDecl
::
Decl
->
Decl
rewriteDecl
(
ParamType
Parameter
x
_
)
=
rewriteDecl
(
ParamType
Parameter
x
_
)
=
...
@@ -139,9 +139,9 @@ convert files =
...
@@ -139,9 +139,9 @@ convert files =
-- substitute in a particular instance's parameter types
-- substitute in a particular instance's parameter types
rewriteModule
::
Description
->
Instance
->
Description
rewriteModule
::
Description
->
Instance
->
Description
rewriteModule
part
typeMap
=
rewriteModule
part
typeMap
=
Part
extern
kw
ml
m'
p
items'
Part
attrs
extern
kw
ml
m'
p
items'
where
where
Part
extern
kw
ml
m
p
items
=
part
Part
attrs
extern
kw
ml
m
p
items
=
part
m'
=
moduleInstanceName
m
typeMap
m'
=
moduleInstanceName
m
typeMap
items'
=
map
rewriteDecl
items
items'
=
map
rewriteDecl
items
rewriteDecl
::
ModuleItem
->
ModuleItem
rewriteDecl
::
ModuleItem
->
ModuleItem
...
@@ -158,7 +158,7 @@ convert files =
...
@@ -158,7 +158,7 @@ convert files =
-- write down module parameter names and type parameters
-- write down module parameter names and type parameters
collectDescriptionM
::
Description
->
Writer
Info
()
collectDescriptionM
::
Description
->
Writer
Info
()
collectDescriptionM
(
part
@
(
Part
_
_
_
name
_
_
))
=
collectDescriptionM
(
part
@
(
Part
_
_
_
_
name
_
_
))
=
tell
$
Map
.
singleton
name
(
paramNames
,
maybeTypeMap
)
tell
$
Map
.
singleton
name
(
paramNames
,
maybeTypeMap
)
where
where
params
=
execWriter
$
params
=
execWriter
$
...
...
src/Convert/StarPort.hs
View file @
5d80c830
...
@@ -21,7 +21,7 @@ convert =
...
@@ -21,7 +21,7 @@ convert =
(
traverseDescriptions
.
traverseModuleItems
.
mapInstance
)
(
traverseDescriptions
.
traverseModuleItems
.
mapInstance
)
collectPortsM
::
Description
->
Writer
Ports
()
collectPortsM
::
Description
->
Writer
Ports
()
collectPortsM
(
Part
_
_
_
name
ports
_
)
=
tell
$
Map
.
singleton
name
ports
collectPortsM
(
Part
_
_
_
_
name
ports
_
)
=
tell
$
Map
.
singleton
name
ports
collectPortsM
_
=
return
()
collectPortsM
_
=
return
()
mapInstance
::
Ports
->
ModuleItem
->
ModuleItem
mapInstance
::
Ports
->
ModuleItem
->
ModuleItem
...
...
src/Convert/Stream.hs
View file @
5d80c830
...
@@ -18,12 +18,12 @@ convert :: [AST] -> [AST]
...
@@ -18,12 +18,12 @@ convert :: [AST] -> [AST]
convert
=
map
$
traverseDescriptions
convertDescription
convert
=
map
$
traverseDescriptions
convertDescription
convertDescription
::
Description
->
Description
convertDescription
::
Description
->
Description
convertDescription
(
description
@
(
Part
_
_
_
_
_
_
)
)
=
convertDescription
(
description
@
Part
{}
)
=
Part
extern
kw
lifetime
name
ports
(
items
++
funcs
)
Part
attrs
extern
kw
lifetime
name
ports
(
items
++
funcs
)
where
where
(
description'
,
funcSet
)
=
(
description'
,
funcSet
)
=
runWriter
$
traverseModuleItemsM
(
traverseStmtsM
traverseStmtM
)
description
runWriter
$
traverseModuleItemsM
(
traverseStmtsM
traverseStmtM
)
description
Part
extern
kw
lifetime
name
ports
items
=
description'
Part
attrs
extern
kw
lifetime
name
ports
items
=
description'
(
funcs
,
_
,
_
)
=
complex
funcSet
(
funcs
,
_
,
_
)
=
complex
funcSet
convertDescription
other
=
other
convertDescription
other
=
other
...
...
src/Convert/Struct.hs
View file @
5d80c830
...
@@ -27,11 +27,11 @@ convert :: [AST] -> [AST]
...
@@ -27,11 +27,11 @@ convert :: [AST] -> [AST]
convert
=
map
$
traverseDescriptions
convertDescription
convert
=
map
$
traverseDescriptions
convertDescription
convertDescription
::
Description
->
Description
convertDescription
::
Description
->
Description
convertDescription
(
description
@
(
Part
_
_
_
_
_
_
)
)
=
convertDescription
(
description
@
Part
{}
)
=
traverseModuleItems
(
traverseTypes
$
convertType
structs
)
$
traverseModuleItems
(
traverseTypes
$
convertType
structs
)
$
Part
extern
kw
lifetime
name
ports
(
items
++
funcs
)
Part
attrs
extern
kw
lifetime
name
ports
(
items
++
funcs
)
where
where
description'
@
(
Part
extern
kw
lifetime
name
ports
items
)
=
description'
@
(
Part
attrs
extern
kw
lifetime
name
ports
items
)
=
scopedConversion
(
traverseDeclM
structs
)
traverseModuleItemM
scopedConversion
(
traverseDeclM
structs
)
traverseModuleItemM
traverseStmtM
tfArgTypes
description
traverseStmtM
tfArgTypes
description
-- collect information about this description
-- collect information about this description
...
...
src/Convert/Traverse.hs
View file @
5d80c830
...
@@ -119,10 +119,10 @@ maybeDo _ Nothing = return Nothing
...
@@ -119,10 +119,10 @@ maybeDo _ Nothing = return Nothing
maybeDo
fun
(
Just
val
)
=
fun
val
>>=
return
.
Just
maybeDo
fun
(
Just
val
)
=
fun
val
>>=
return
.
Just
traverseModuleItemsM
::
Monad
m
=>
MapperM
m
ModuleItem
->
MapperM
m
Description
traverseModuleItemsM
::
Monad
m
=>
MapperM
m
ModuleItem
->
MapperM
m
Description
traverseModuleItemsM
mapper
(
Part
extern
kw
lifetime
name
ports
items
)
=
do
traverseModuleItemsM
mapper
(
Part
attrs
extern
kw
lifetime
name
ports
items
)
=
do
items'
<-
mapM
fullMapper
items
items'
<-
mapM
fullMapper
items
let
items''
=
concatMap
breakGenerate
items'
let
items''
=
concatMap
breakGenerate
items'
return
$
Part
extern
kw
lifetime
name
ports
items''
return
$
Part
attrs
extern
kw
lifetime
name
ports
items''
where
where
fullMapper
(
Generate
[
GenBlock
Nothing
genItems
])
=
fullMapper
(
Generate
[
GenBlock
Nothing
genItems
])
=
mapM
fullGenItemMapper
genItems
>>=
mapper
.
Generate
mapM
fullGenItemMapper
genItems
>>=
mapper
.
Generate
...
@@ -151,9 +151,9 @@ traverseModuleItemsM mapper (Part extern kw lifetime name ports items) = do
...
@@ -151,9 +151,9 @@ traverseModuleItemsM mapper (Part extern kw lifetime name ports items) = do
traverseModuleItemsM
mapper
(
PackageItem
packageItem
)
=
do
traverseModuleItemsM
mapper
(
PackageItem
packageItem
)
=
do
let
item
=
MIPackageItem
packageItem
let
item
=
MIPackageItem
packageItem
converted
<-
converted
<-
traverseModuleItemsM
mapper
(
Part
False
Module
Nothing
"DNE"
[]
[
item
])
traverseModuleItemsM
mapper
(
Part
[]
False
Module
Nothing
"DNE"
[]
[
item
])
let
item'
=
case
converted
of
let
item'
=
case
converted
of
Part
False
Module
Nothing
"DNE"
[]
[
newItem
]
->
newItem
Part
[]
False
Module
Nothing
"DNE"
[]
[
newItem
]
->
newItem
_
->
error
$
"redirected PackageItem traverse failed: "
_
->
error
$
"redirected PackageItem traverse failed: "
++
show
converted
++
show
converted
return
$
case
item'
of
return
$
case
item'
of
...
@@ -162,9 +162,9 @@ traverseModuleItemsM mapper (PackageItem packageItem) = do
...
@@ -162,9 +162,9 @@ traverseModuleItemsM mapper (PackageItem packageItem) = do
traverseModuleItemsM
mapper
(
Package
lifetime
name
packageItems
)
=
do
traverseModuleItemsM
mapper
(
Package
lifetime
name
packageItems
)
=
do
let
items
=
map
MIPackageItem
packageItems
let
items
=
map
MIPackageItem
packageItems
converted
<-
converted
<-
traverseModuleItemsM
mapper
(
Part
False
Module
Nothing
"DNE"
[]
items
)
traverseModuleItemsM
mapper
(
Part
[]
False
Module
Nothing
"DNE"
[]
items
)
let
items'
=
case
converted
of
let
items'
=
case
converted
of
Part
False
Module
Nothing
"DNE"
[]
newItems
->
newItems
Part
[]
False
Module
Nothing
"DNE"
[]
newItems
->
newItems
_
->
error
$
"redirected Package traverse failed: "
_
->
error
$
"redirected Package traverse failed: "
++
show
converted
++
show
converted
return
$
Package
lifetime
name
$
map
(
\
(
MIPackageItem
item
)
->
item
)
items'
return
$
Package
lifetime
name
$
map
(
\
(
MIPackageItem
item
)
->
item
)
items'
...
@@ -972,9 +972,9 @@ collectStmtAsgnsM = collectify traverseStmtAsgnsM
...
@@ -972,9 +972,9 @@ collectStmtAsgnsM = collectify traverseStmtAsgnsM
traverseNestedModuleItemsM
::
Monad
m
=>
MapperM
m
ModuleItem
->
MapperM
m
ModuleItem
traverseNestedModuleItemsM
::
Monad
m
=>
MapperM
m
ModuleItem
->
MapperM
m
ModuleItem
traverseNestedModuleItemsM
mapper
item
=
do
traverseNestedModuleItemsM
mapper
item
=
do
converted
<-
converted
<-
traverseModuleItemsM
mapper
(
Part
False
Module
Nothing
"DNE"
[]
[
item
])
traverseModuleItemsM
mapper
(
Part
[]
False
Module
Nothing
"DNE"
[]
[
item
])
let
items'
=
case
converted
of
let
items'
=
case
converted
of
Part
False
Module
Nothing
"DNE"
[]
newItems
->
newItems
Part
[]
False
Module
Nothing
"DNE"
[]
newItems
->
newItems
_
->
error
$
"redirected NestedModuleItems traverse failed: "
_
->
error
$
"redirected NestedModuleItems traverse failed: "
++
show
converted
++
show
converted
return
$
case
items'
of
return
$
case
items'
of
...
...
src/Convert/Typedef.hs
View file @
5d80c830
...
@@ -25,7 +25,7 @@ convert =
...
@@ -25,7 +25,7 @@ convert =
where
where
getTypedef
::
Description
->
Writer
Types
()
getTypedef
::
Description
->
Writer
Types
()
getTypedef
(
PackageItem
(
Typedef
a
b
))
=
tell
$
Map
.
singleton
b
a
getTypedef
(
PackageItem
(
Typedef
a
b
))
=
tell
$
Map
.
singleton
b
a
getTypedef
(
Part
_
Interface
_
x
_
_
)
=
getTypedef
(
Part
_
_
Interface
_
x
_
_
)
=
tell
$
Map
.
singleton
x
(
InterfaceT
x
Nothing
[]
)
tell
$
Map
.
singleton
x
(
InterfaceT
x
Nothing
[]
)
getTypedef
_
=
return
()
getTypedef
_
=
return
()
removeTypedef
::
Description
->
Description
removeTypedef
::
Description
->
Description
...
...
src/Language/SystemVerilog/AST/Description.hs
View file @
5d80c830
...
@@ -18,13 +18,14 @@ import Text.Printf (printf)
...
@@ -18,13 +18,14 @@ import Text.Printf (printf)
import
Language.SystemVerilog.AST.ShowHelp
import
Language.SystemVerilog.AST.ShowHelp
import
Language.SystemVerilog.AST.Attr
(
Attr
)
import
Language.SystemVerilog.AST.Decl
(
Decl
)
import
Language.SystemVerilog.AST.Decl
(
Decl
)
import
Language.SystemVerilog.AST.Stmt
(
Stmt
)
import
Language.SystemVerilog.AST.Stmt
(
Stmt
)
import
Language.SystemVerilog.AST.Type
(
Type
,
Identifier
)
import
Language.SystemVerilog.AST.Type
(
Type
,
Identifier
)
import
{-#
SOURCE
#-
}
Language
.
SystemVerilog
.
AST
.
ModuleItem
(
ModuleItem
)
import
{-#
SOURCE
#-
}
Language
.
SystemVerilog
.
AST
.
ModuleItem
(
ModuleItem
)
data
Description
data
Description
=
Part
Bool
PartKW
(
Maybe
Lifetime
)
Identifier
[
Identifier
]
[
ModuleItem
]
=
Part
[
Attr
]
Bool
PartKW
(
Maybe
Lifetime
)
Identifier
[
Identifier
]
[
ModuleItem
]
|
PackageItem
PackageItem
|
PackageItem
PackageItem
|
Package
(
Maybe
Lifetime
)
Identifier
[
PackageItem
]
|
Package
(
Maybe
Lifetime
)
Identifier
[
PackageItem
]
|
Directive
String
-- currently unused
|
Directive
String
-- currently unused
...
@@ -32,12 +33,14 @@ data Description
...
@@ -32,12 +33,14 @@ data Description
instance
Show
Description
where
instance
Show
Description
where
showList
descriptions
_
=
intercalate
"
\n
"
$
map
show
descriptions
showList
descriptions
_
=
intercalate
"
\n
"
$
map
show
descriptions
show
(
Part
True
kw
lifetime
name
_
items
)
=
show
(
Part
attrs
True
kw
lifetime
name
_
items
)
=
printf
"extern %s %s%s %s;"
printf
"%sextern %s %s%s %s;"
(
show
kw
)
(
showLifetime
lifetime
)
name
(
indentedParenList
itemStrs
)
(
concatMap
showPad
attrs
)
(
show
kw
)
(
showLifetime
lifetime
)
name
(
indentedParenList
itemStrs
)
where
itemStrs
=
map
(
init
.
show
)
items
where
itemStrs
=
map
(
init
.
show
)
items
show
(
Part
False
kw
lifetime
name
ports
items
)
=
show
(
Part
attrs
False
kw
lifetime
name
ports
items
)
=
printf
"%s %s%s%s;
\n
%s
\n
end%s"
printf
"%s%s %s%s%s;
\n
%s
\n
end%s"
(
concatMap
showPad
attrs
)
(
show
kw
)
(
showLifetime
lifetime
)
name
portsStr
bodyStr
(
show
kw
)
(
show
kw
)
(
showLifetime
lifetime
)
name
portsStr
bodyStr
(
show
kw
)
where
where
portsStr
=
if
null
ports
portsStr
=
if
null
ports
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
5d80c830
...
@@ -498,8 +498,11 @@ Packing :: { Packing }
...
@@ -498,8 +498,11 @@ Packing :: { Packing }
| {- empty -} { Unpacked }
| {- empty -} { Unpacked }
Part(begin, end) :: { Description }
Part(begin, end) :: { Description }
: begin opt(Lifetime) Identifier PackageImportDeclarations Params PortDecls ";" ModuleItems end opt(Tag) { Part False $1 $2 $3 (fst $6) ($4 ++ $5 ++ (snd $6) ++ $8) }
: AttributeInstances begin PartHeader ModuleItems end opt(Tag) { $3 $1 False $2 $4 }
| "extern" begin opt(Lifetime) Identifier PackageImportDeclarations Params PortDecls ";" { Part True $2 $3 $4 (fst $7) ($5 ++ $6 ++ (snd $7) ) }
| AttributeInstances "extern" begin PartHeader { $4 $1 True $3 [] }
PartHeader :: { [Attr] -> Bool -> PartKW -> [ModuleItem] -> Description }
: opt(Lifetime) Identifier PackageImportDeclarations Params PortDecls ";" { \attrs extern kw items -> Part attrs extern kw $1 $2 (fst $5) ($3 ++ $4 ++ (snd $5) ++ items) }
ModuleKW :: { PartKW }
ModuleKW :: { PartKW }
: "module" { Module }
: "module" { Module }
...
@@ -693,6 +696,9 @@ ActionBlock :: { ActionBlock }
...
@@ -693,6 +696,9 @@ ActionBlock :: { ActionBlock }
| "else" Stmt { ActionBlockElse (Nothing) $2 }
| "else" Stmt { ActionBlockElse (Nothing) $2 }
| Stmt "else" Stmt { ActionBlockElse (Just $1) $3 }
| Stmt "else" Stmt { ActionBlockElse (Just $1) $3 }
AttributeInstances :: { [Attr] }
: {- empty -} { [] }
| AttributeInstance AttributeInstances { $1 : $2 }
AttributeInstance :: { Attr }
AttributeInstance :: { Attr }
: "(*" AttrSpecs "*)" { Attr $2 }
: "(*" AttrSpecs "*)" { Attr $2 }
AttrSpecs :: { [AttrSpec] }
AttrSpecs :: { [AttrSpec] }
...
...
test/basic/attr.sv
View file @
5d80c830
module
top
;
(
*
a
=
1
*
)
module
top
;
(
*
foo
=
"bar"
*
)
logic
x
;
(
*
foo
=
"bar"
*
)
logic
x
;
initial
begin
initial
begin
x
=
1
;
x
=
1
;
...
...
test/basic/attr.v
View file @
5d80c830
module
top
;
(
*
a
=
1
*
)
module
top
;
(
*
foo
=
"bar"
*
)
reg
x
;
(
*
foo
=
"bar"
*
)
reg
x
;
initial
begin
initial
begin
x
=
1
;
x
=
1
;
...
...
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