Commit 0a65abd6 by Zachary Snow

full support for package and class subroutine invocations

parent c0282862
...@@ -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 }
......
...@@ -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 =
......
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
module top;
`define TEST(subroutine) \
initial repeat (4) $display(`"subroutine()`");
`TEST(dump)
`TEST(P::dump)
`TEST(C#(1)::dump)
endmodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment