mirror of https://github.com/zachjs/sv2v.git
full support for package and class subroutine invocations
This commit is contained in:
parent
c0282862ea
commit
0a65abd614
|
|
@ -1008,6 +1008,8 @@ StmtAsgn :: { Stmt }
|
|||
| LHS CallArgs ";" { Subroutine (lhsToExpr $1) $2 }
|
||||
| Identifier "::" Identifier ";" { Subroutine (PSIdent $1 $3) (Args [] []) }
|
||||
| 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 }
|
||||
: StmtBlock(BlockKWSeq, end ) { $1 }
|
||||
| StmtBlock(BlockKWPar, join) { $1 }
|
||||
|
|
|
|||
|
|
@ -265,10 +265,8 @@ parseDTsAsDeclOrStmt tokens =
|
|||
pos = tokPos $ last tokens
|
||||
stmt = case last tokens of
|
||||
DTAsgn _ op mt e -> Asgn op mt lhs e
|
||||
DTInstance _ args -> Subroutine (lhsToExpr lhs) (instanceToArgs args)
|
||||
_ -> case takeLHS tokens of
|
||||
Just fullLHS -> Subroutine (lhsToExpr fullLHS) (Args [] [])
|
||||
_ -> error $ "invalid block item decl or stmt: " ++ show tokens
|
||||
DTInstance _ args -> asSubroutine lhsToks (instanceToArgs args)
|
||||
_ -> asSubroutine tokens (Args [] [])
|
||||
lhsToks = init tokens
|
||||
lhs = case takeLHS lhsToks of
|
||||
Nothing -> error $ "could not parse as LHS: " ++ show lhsToks
|
||||
|
|
@ -282,6 +280,16 @@ parseDTsAsDeclOrStmt tokens =
|
|||
traceStmt :: Position -> Stmt
|
||||
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
|
||||
instanceToArgs :: [PortBinding] -> Args
|
||||
instanceToArgs bindings =
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
module top;
|
||||
`define TEST(subroutine) \
|
||||
initial repeat (4) $display(`"subroutine()`");
|
||||
`TEST(dump)
|
||||
`TEST(P::dump)
|
||||
`TEST(C#(1)::dump)
|
||||
endmodule
|
||||
Loading…
Reference in New Issue