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
f40c71dc
Commit
f40c71dc
authored
Mar 08, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ParseDecl forbids non-EQ assignment operators in declarations
parent
d7f641b8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
src/Language/SystemVerilog/Parser/ParseDecl.hs
+23
-4
No files found.
src/Language/SystemVerilog/Parser/ParseDecl.hs
View file @
f40c71dc
...
...
@@ -59,10 +59,26 @@ data DeclToken
deriving
(
Show
,
Eq
)
-- entrypoints besides `parseDTsAsDeclOrAsgn` use this to disallow `DTAsgnNBlk`
-- and `DTAsgn` with a binary assignment operator because we don't expect to see
-- those assignment oeprators in declarations
forbidNonEqAsgn
::
[
DeclToken
]
->
a
->
a
forbidNonEqAsgn
tokens
=
if
any
isNonEqAsgn
tokens
then
error
$
"decl tokens contain bad assignment operator: "
++
show
tokens
else
id
where
isNonEqAsgn
::
DeclToken
->
Bool
isNonEqAsgn
(
DTAsgnNBlk
_
)
=
True
isNonEqAsgn
(
DTAsgn
(
AsgnOp
_
)
_
)
=
True
isNonEqAsgn
_
=
False
-- [PUBLIC]: parser for module port declarations, including interface ports
-- Example: `input foo, bar, One inst`
parseDTsAsPortDecls
::
[
DeclToken
]
->
([
Identifier
],
[
ModuleItem
])
parseDTsAsPortDecls
pieces
=
forbidNonEqAsgn
pieces
$
if
isSimpleList
then
(
simpleIdents
,
[]
)
else
(
portNames
declarations
,
map
MIDecl
declarations
)
...
...
@@ -94,6 +110,7 @@ parseDTsAsPortDecls pieces =
-- parameters) and module instantiations
parseDTsAsModuleItems
::
[
DeclToken
]
->
[
ModuleItem
]
parseDTsAsModuleItems
tokens
=
forbidNonEqAsgn
tokens
$
if
any
isInstance
tokens
then
parseDTsAsIntantiations
tokens
else
map
MIDecl
$
parseDTsAsDecl
tokens
...
...
@@ -127,6 +144,7 @@ parseDTsAsIntantiations tokens =
-- [PUBLIC]: parser for generic, comma-separated declarations
parseDTsAsDecls
::
[
DeclToken
]
->
[
Decl
]
parseDTsAsDecls
tokens
=
forbidNonEqAsgn
tokens
$
concat
$
map
finalize
$
parseDTsAsComponents
tokens
...
...
@@ -134,6 +152,7 @@ parseDTsAsDecls tokens =
-- outside of a port list
parseDTsAsDecl
::
[
DeclToken
]
->
[
Decl
]
parseDTsAsDecl
tokens
=
forbidNonEqAsgn
tokens
$
if
length
components
/=
1
then
error
$
"too many declarations: "
++
(
show
tokens
)
else
finalize
$
head
components
...
...
@@ -253,10 +272,10 @@ takeRanges (token : tokens) =
(
rs
,
rest
)
=
takeRanges
tokens
asRange
s
=
(
simplify
$
BinOp
Sub
s
(
Number
"1"
),
Number
"0"
)
--
TODO: entrypoints besides `parseDTsAsDeclOrAsgn` should disallow `DTAsgnNBlk`
--
Note: matching DTAsgnNBlk too is a bit of a hack to allow for tripLookahead
--
to work both for standard declarations and in `parseDTsAsDeclOrAsgn`, where
--
we're checking for an assignment
--
Matching DTAsgnNBlk here allows tripLookahead to work both for standard
--
declarations and in `parseDTsAsDeclOrAsgn`, where we're checking for an
--
assignment assignment statement. The other entry points disallow
--
`DTAsgnNBlk`, so this doesn't liberalize the parser.
takeAsgn
::
[
DeclToken
]
->
(
Maybe
Expr
,
[
DeclToken
])
takeAsgn
(
DTAsgn
AsgnOpEq
e
:
rest
)
=
(
Just
e
,
rest
)
takeAsgn
(
DTAsgnNBlk
e
:
rest
)
=
(
Just
e
,
rest
)
...
...
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