Commit 091520e4 by Zachary Snow

allow generate scoped basic subroutine invocations in statement blocks

parent 454f8dcb
...@@ -41,7 +41,6 @@ module Language.SystemVerilog.Parser.ParseDecl ...@@ -41,7 +41,6 @@ module Language.SystemVerilog.Parser.ParseDecl
, parseDTsAsPortDecls , parseDTsAsPortDecls
, parseDTsAsModuleItems , parseDTsAsModuleItems
, parseDTsAsDecls , parseDTsAsDecls
, parseDTsAsDecl
, parseDTsAsDeclOrStmt , parseDTsAsDeclOrStmt
, parseDTsAsDeclsOrAsgns , parseDTsAsDeclsOrAsgns
) where ) where
...@@ -225,16 +224,10 @@ parseDTsAsDecl tokens = ...@@ -225,16 +224,10 @@ parseDTsAsDecl tokens =
-- [PUBLIC]: parser for single block item declarations or assign or arg-less -- [PUBLIC]: parser for single block item declarations or assign or arg-less
-- subroutine call statements -- subroutine call statements
parseDTsAsDeclOrStmt :: [DeclToken] -> ([Decl], [Stmt]) parseDTsAsDeclOrStmt :: [DeclToken] -> ([Decl], [Stmt])
parseDTsAsDeclOrStmt [DTIdent pos f] =
([], [traceStmt pos, Subroutine (Ident f) (Args [] [])])
parseDTsAsDeclOrStmt [DTPSIdent pos ps f] =
([], [traceStmt pos, Subroutine (PSIdent ps f) (Args [] [])])
parseDTsAsDeclOrStmt [DTCSIdent pos ps pm f] =
([], [traceStmt pos, Subroutine (CSIdent ps pm f) (Args [] [])])
parseDTsAsDeclOrStmt (DTAsgn pos (AsgnOp op) mt e : tok : toks) = parseDTsAsDeclOrStmt (DTAsgn pos (AsgnOp op) mt e : tok : toks) =
parseDTsAsDeclOrStmt $ (tok : toks) ++ [DTAsgn pos (AsgnOp op) mt e] parseDTsAsDeclOrStmt $ (tok : toks) ++ [DTAsgn pos (AsgnOp op) mt e]
parseDTsAsDeclOrStmt tokens = parseDTsAsDeclOrStmt tokens =
if (isStmt (last tokens) || tripLookahead tokens) && maybeLhs /= Nothing if not hasLeadingDecl
then ([], [traceStmt pos, stmt]) then ([], [traceStmt pos, stmt])
else (parseDTsAsDecl tokens, []) else (parseDTsAsDecl tokens, [])
where where
...@@ -242,13 +235,15 @@ parseDTsAsDeclOrStmt tokens = ...@@ -242,13 +235,15 @@ parseDTsAsDeclOrStmt 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 -> Subroutine (lhsToExpr lhs) (instanceToArgs args)
_ -> error $ "invalid block item decl or stmt: " ++ (show tokens) _ -> case takeLHS tokens of
maybeLhs = takeLHS $ init tokens Just fullLHS -> Subroutine (lhsToExpr fullLHS) (Args [] [])
Just lhs = maybeLhs _ -> error $ "invalid block item decl or stmt: " ++ show tokens
isStmt :: DeclToken -> Bool Just lhs = takeLHS $ init tokens
isStmt (DTAsgn{}) = True hasLeadingDecl = tokens /= l4 && tripLookahead l4
isStmt (DTInstance{}) = True (_, l1) = takeDir tokens
isStmt _ = False (_, l2) = takeLifetime l1
(_, l3) = takeType l2
(_, l4) = takeRanges l3
traceStmt :: Position -> Stmt traceStmt :: Position -> Stmt
traceStmt pos = CommentStmt $ "Trace: " ++ show pos traceStmt pos = CommentStmt $ "Trace: " ++ show pos
......
module top;
task tick;
$display("tick() called");
endtask
generate
begin : foo
task tick;
$display("foo.tick() called");
endtask
end
genvar i;
for (i = 0; i < 2; i = i + 1) begin : bar
task tick;
$display("bar[%0d].tick() called", i);
endtask
end
endgenerate
initial begin
tick;
foo.tick;
bar[0].tick;
bar[1].tick;
tick();
foo.tick();
bar[0].tick();
bar[1].tick();
end
endmodule
`include "stmt_task.sv"
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