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
2081f6a3
Commit
2081f6a3
authored
Dec 08, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support attributes on port declarations
parent
d137fd3d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
10 deletions
+45
-10
src/Language/SystemVerilog/Parser/Parse.y
+1
-0
src/Language/SystemVerilog/Parser/ParseDecl.hs
+26
-2
test/basic/attr.sv
+17
-1
test/basic/attr.v
+1
-7
No files found.
src/Language/SystemVerilog/Parser/Parse.y
View file @
2081f6a3
...
@@ -646,6 +646,7 @@ PortDeclTokens(delim) :: { [DeclToken] }
...
@@ -646,6 +646,7 @@ PortDeclTokens(delim) :: { [DeclToken] }
:
DeclTokensBase
(
PortDeclTokens
(
delim
),
delim
)
{
$
1
}
:
DeclTokensBase
(
PortDeclTokens
(
delim
),
delim
)
{
$
1
}
|
GenericInterfaceDecl
PortDeclTokens
(
delim
)
{
$
1
++
$
2
}
|
GenericInterfaceDecl
PortDeclTokens
(
delim
)
{
$
1
++
$
2
}
|
GenericInterfaceDecl
delim
{
$
1
}
|
GenericInterfaceDecl
delim
{
$
1
}
|
AttributeInstance
PortDeclTokens
(
delim
)
{
%
posInject
\
p
->
DTAttr
p
$
1
:
$
2
}
GenericInterfaceDecl
::
{
[
DeclToken
]
}
GenericInterfaceDecl
::
{
[
DeclToken
]
}
:
"interface"
Identifier
{
%
posInject
\
p
->
[
DTType
p
(
\
Unspecified
->
InterfaceT
""
Nothing
),
DTIdent
p
$
2
]
}
:
"interface"
Identifier
{
%
posInject
\
p
->
[
DTType
p
(
\
Unspecified
->
InterfaceT
""
Nothing
),
DTIdent
p
$
2
]
}
...
...
src/Language/SystemVerilog/Parser/ParseDecl.hs
View file @
2081f6a3
...
@@ -69,6 +69,7 @@ data DeclToken
...
@@ -69,6 +69,7 @@ data DeclToken
|
DTDot
Position
Identifier
|
DTDot
Position
Identifier
|
DTSigning
Position
Signing
|
DTSigning
Position
Signing
|
DTLifetime
Position
Lifetime
|
DTLifetime
Position
Lifetime
|
DTAttr
Position
Attr
deriving
(
Show
,
Eq
)
deriving
(
Show
,
Eq
)
-- entrypoints besides `parseDTsAsDeclOrStmt` use this to disallow `DTAsgn` with
-- entrypoints besides `parseDTsAsDeclOrStmt` use this to disallow `DTAsgn` with
...
@@ -93,7 +94,7 @@ parseDTsAsPortDecls pieces =
...
@@ -93,7 +94,7 @@ parseDTsAsPortDecls pieces =
forbidNonEqAsgn
pieces
$
forbidNonEqAsgn
pieces
$
if
isSimpleList
if
isSimpleList
then
(
simpleIdents
,
[]
)
then
(
simpleIdents
,
[]
)
else
(
portNames
declarations
,
map
(
MIPackageItem
.
Decl
)
declarations
)
else
(
portNames
declarations
,
applyAttrs
[]
pieces
declarations
)
where
where
commaIdxs
=
findIndices
isComma
pieces
commaIdxs
=
findIndices
isComma
pieces
identIdxs
=
findIndices
isIdent
pieces
identIdxs
=
findIndices
isIdent
pieces
...
@@ -104,10 +105,15 @@ parseDTsAsPortDecls pieces =
...
@@ -104,10 +105,15 @@ parseDTsAsPortDecls pieces =
length
pieces
==
length
commaIdxs
+
length
identIdxs
length
pieces
==
length
commaIdxs
+
length
identIdxs
simpleIdents
=
map
extractIdent
$
filter
isIdent
pieces
simpleIdents
=
map
extractIdent
$
filter
isIdent
pieces
declarations
=
propagateDirections
Input
$
parseDTsAsDecls
pieces
declarations
=
propagateDirections
Input
$
parseDTsAsDecls
pieces
'
extractIdent
=
\
(
DTIdent
_
x
)
->
x
extractIdent
=
\
(
DTIdent
_
x
)
->
x
pieces'
=
filter
(
not
.
isDTAttr
)
pieces
isDTAttr
::
DeclToken
->
Bool
isDTAttr
DTAttr
{}
=
True
isDTAttr
_
=
False
propagateDirections
::
Direction
->
[
Decl
]
->
[
Decl
]
propagateDirections
::
Direction
->
[
Decl
]
->
[
Decl
]
propagateDirections
dir
(
decl
@
(
Variable
_
InterfaceT
{}
_
_
_
)
:
decls
)
=
propagateDirections
dir
(
decl
@
(
Variable
_
InterfaceT
{}
_
_
_
)
:
decls
)
=
decl
:
propagateDirections
dir
decls
decl
:
propagateDirections
dir
decls
...
@@ -128,6 +134,23 @@ parseDTsAsPortDecls pieces =
...
@@ -128,6 +134,23 @@ parseDTsAsPortDecls pieces =
portName
decl
=
portName
decl
=
error
$
"unexpected non-variable port declaration: "
++
(
show
decl
)
error
$
"unexpected non-variable port declaration: "
++
(
show
decl
)
applyAttrs
::
[
Attr
]
->
[
DeclToken
]
->
[
Decl
]
->
[
ModuleItem
]
applyAttrs
_
[]
[]
=
[]
applyAttrs
_
tokens
(
CommentDecl
c
:
decls
)
=
MIPackageItem
(
Decl
$
CommentDecl
c
)
:
applyAttrs
[]
tokens
decls
applyAttrs
attrs
(
DTAttr
_
attr
:
tokens
)
decls
=
applyAttrs
(
attr
:
attrs
)
tokens
decls
applyAttrs
attrs
[]
[
decl
]
=
[
wrapDecl
attrs
decl
]
applyAttrs
attrs
(
DTComma
{}
:
tokens
)
(
decl
:
decls
)
=
wrapDecl
attrs
decl
:
applyAttrs
attrs
tokens
decls
applyAttrs
attrs
(
_
:
tokens
)
decls
=
applyAttrs
attrs
tokens
decls
applyAttrs
_
[]
_
=
error
"applyAttrs internal invariant failed"
wrapDecl
::
[
Attr
]
->
Decl
->
ModuleItem
wrapDecl
attrs
decl
=
foldr
MIAttr
(
MIPackageItem
$
Decl
decl
)
attrs
-- [PUBLIC]: parser for single (semicolon-terminated) declarations (including
-- [PUBLIC]: parser for single (semicolon-terminated) declarations (including
-- parameters) and module instantiations
-- parameters) and module instantiations
...
@@ -494,3 +517,4 @@ tokPos (DTStream p _ _ _) = p
...
@@ -494,3 +517,4 @@ tokPos (DTStream p _ _ _) = p
tokPos
(
DTDot
p
_
)
=
p
tokPos
(
DTDot
p
_
)
=
p
tokPos
(
DTSigning
p
_
)
=
p
tokPos
(
DTSigning
p
_
)
=
p
tokPos
(
DTLifetime
p
_
)
=
p
tokPos
(
DTLifetime
p
_
)
=
p
tokPos
(
DTAttr
p
_
)
=
p
test/basic/attr.sv
View file @
2081f6a3
module
Example
(
input
a
,
b
,
(
*
who
=
1
*
)
output
c
,
(
*
what
=
2
*
)
output
d
,
e
,
input
f
,
(
*
when
=
3
*
)
(
*
where
=
4
*
)
output
g
,
h
,
i
)
;
endmodule
(
*
a
=
1
*
)
module
top
;
(
*
a
=
1
*
)
module
top
;
(
*
foo
=
"bar"
*
)
logic
x
;
(
*
foo
=
"bar"
*
)
reg
x
;
initial
begin
initial
begin
x
=
1
;
x
=
1
;
$
display
(
x
)
;
$
display
(
x
)
;
end
end
reg
a
,
b
;
wire
c
;
wire
d
,
e
;
reg
f
;
wire
g
,
h
,
i
;
Example
m
(
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
)
;
endmodule
endmodule
test/basic/attr.v
View file @
2081f6a3
(
*
a
=
1
*
)
module
top
;
`include
"attr.sv"
(
*
foo
=
"bar"
*
)
reg
x
;
initial
begin
x
=
1
;
$
display
(
x
)
;
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