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
0a65abd6
Commit
0a65abd6
authored
May 29, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
full support for package and class subroutine invocations
parent
c0282862
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
4 deletions
+52
-4
src/Language/SystemVerilog/Parser/Parse.y
+2
-0
src/Language/SystemVerilog/Parser/ParseDecl.hs
+12
-4
test/basic/subroutine.sv
+31
-0
test/basic/subroutine.v
+7
-0
No files found.
src/Language/SystemVerilog/Parser/Parse.y
View file @
0a65abd6
...
@@ -1008,6 +1008,8 @@ StmtAsgn :: { Stmt }
...
@@ -1008,6 +1008,8 @@ StmtAsgn :: { Stmt }
|
LHS
CallArgs
";"
{
Subroutine
(
lhsToExpr
$
1
)
$
2
}
|
LHS
CallArgs
";"
{
Subroutine
(
lhsToExpr
$
1
)
$
2
}
|
Identifier
"::"
Identifier
";"
{
Subroutine
(
PSIdent
$
1
$
3
)
(
Args
[]
[]
)
}
|
Identifier
"::"
Identifier
";"
{
Subroutine
(
PSIdent
$
1
$
3
)
(
Args
[]
[]
)
}
|
Identifier
"::"
Identifier
CallArgs
";"
{
Subroutine
(
PSIdent
$
1
$
3
)
$
4
}
|
Identifier
"::"
Identifier
CallArgs
";"
{
Subroutine
(
PSIdent
$
1
$
3
)
$
4
}
|
Identifier
ParamBindings
"::"
Identifier
";"
{
Subroutine
(
CSIdent
$
1
$
2
$
4
)
(
Args
[]
[]
)
}
|
Identifier
ParamBindings
"::"
Identifier
CallArgs
";"
{
Subroutine
(
CSIdent
$
1
$
2
$
4
)
$
5
}
StmtNonAsgn
::
{
Stmt
}
StmtNonAsgn
::
{
Stmt
}
:
StmtBlock
(
BlockKWSeq
,
end
)
{
$
1
}
:
StmtBlock
(
BlockKWSeq
,
end
)
{
$
1
}
|
StmtBlock
(
BlockKWPar
,
join
)
{
$
1
}
|
StmtBlock
(
BlockKWPar
,
join
)
{
$
1
}
...
...
src/Language/SystemVerilog/Parser/ParseDecl.hs
View file @
0a65abd6
...
@@ -265,10 +265,8 @@ parseDTsAsDeclOrStmt tokens =
...
@@ -265,10 +265,8 @@ parseDTsAsDeclOrStmt tokens =
pos
=
tokPos
$
last
tokens
pos
=
tokPos
$
last
tokens
stmt
=
case
last
tokens
of
stmt
=
case
last
tokens
of
DTAsgn
_
op
mt
e
->
Asgn
op
mt
lhs
e
DTAsgn
_
op
mt
e
->
Asgn
op
mt
lhs
e
DTInstance
_
args
->
Subroutine
(
lhsToExpr
lhs
)
(
instanceToArgs
args
)
DTInstance
_
args
->
asSubroutine
lhsToks
(
instanceToArgs
args
)
_
->
case
takeLHS
tokens
of
_
->
asSubroutine
tokens
(
Args
[]
[]
)
Just
fullLHS
->
Subroutine
(
lhsToExpr
fullLHS
)
(
Args
[]
[]
)
_
->
error
$
"invalid block item decl or stmt: "
++
show
tokens
lhsToks
=
init
tokens
lhsToks
=
init
tokens
lhs
=
case
takeLHS
lhsToks
of
lhs
=
case
takeLHS
lhsToks
of
Nothing
->
error
$
"could not parse as LHS: "
++
show
lhsToks
Nothing
->
error
$
"could not parse as LHS: "
++
show
lhsToks
...
@@ -282,6 +280,16 @@ parseDTsAsDeclOrStmt tokens =
...
@@ -282,6 +280,16 @@ parseDTsAsDeclOrStmt tokens =
traceStmt
::
Position
->
Stmt
traceStmt
::
Position
->
Stmt
traceStmt
pos
=
CommentStmt
$
"Trace: "
++
show
pos
traceStmt
pos
=
CommentStmt
$
"Trace: "
++
show
pos
-- read the given tokens as the root of a subroutine invocation
asSubroutine
::
[
DeclToken
]
->
Args
->
Stmt
asSubroutine
[
DTIdent
_
x
]
=
Subroutine
$
Ident
x
asSubroutine
[
DTPSIdent
_
p
x
]
=
Subroutine
$
PSIdent
p
x
asSubroutine
[
DTCSIdent
_
c
p
x
]
=
Subroutine
$
CSIdent
c
p
x
asSubroutine
tokens
=
case
takeLHS
tokens
of
Just
lhs
->
Subroutine
$
lhsToExpr
lhs
Nothing
->
error
$
"invalid block item decl or stmt: "
++
show
tokens
-- converts port bindings to call args
-- converts port bindings to call args
instanceToArgs
::
[
PortBinding
]
->
Args
instanceToArgs
::
[
PortBinding
]
->
Args
instanceToArgs
bindings
=
instanceToArgs
bindings
=
...
...
test/basic/subroutine.sv
0 → 100644
View file @
0a65abd6
class
C
#(
parameter
X
=
1
)
;
// TODO: this should be static
task
dump
;
$
display
(
"C#(%0d)::dump()"
,
X
)
;
endtask
endclass
package
P
;
task
dump
;
$
display
(
"P::dump()"
)
;
endtask
endpackage
module
top
;
task
dump
;
$
display
(
"dump()"
)
;
endtask
`define
TEST
(
subroutine
)
\
initial begin subroutine
;
end \
initial begin subroutine
()
;
end \
initial begin
;
subroutine
;
end \
initial begin
;
subroutine
()
;
end
`TEST
(
dump
)
`TEST
(
P
::
dump
)
`TEST
(
C
#(
1
)
::
dump
)
endmodule
test/basic/subroutine.v
0 → 100644
View file @
0a65abd6
module
top
;
`define
TEST
(
subroutine
)
\
initial repeat
(
4
)
$
display
(`"
subroutine
()`")
;
`TEST
(
dump
)
`TEST
(
P
::
dump
)
`TEST
(
C
#(
1
)
::
dump
)
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