Commit 5a8801a4 by Zachary Snow

allow trailing commas in parameter and port lists and bindings

parent bdc7b5ad
......@@ -579,14 +579,17 @@ PIParams :: { [Decl] }
| "#" "(" ")" { [] }
| "#" "(" ParamsFollow { $3 }
ParamsFollow :: { [Decl] }
: ParamAsgn ")" { [$1] }
: ParamAsgn ParamsEnd { [$1] }
| ParamAsgn "," ParamsFollow { $1 : $3 }
| ParamsDecl { $1 }
ParamsDecl :: { [Decl] }
: ModuleParameterDecl(")") { $1 }
: ModuleParameterDecl(ParamsEnd) { $1 }
| ModuleParameterDecl(",") ParamsDecl { $1 ++ $2 }
ParamAsgn :: { Decl }
: Identifier "=" Expr { Param Parameter (Implicit Unspecified []) $1 $3 }
ParamsEnd
: ")" {}
| "," ")" {}
PortDecls :: { ([Identifier], [ModuleItem]) }
: "(" PortDeclTokens(")") { parseDTsAsPortDecls $2 }
......@@ -965,7 +968,7 @@ PortBindings :: { [PortBinding] }
: "(" ")" { [] }
| "(" PortBindingsInside ")" { $2 }
PortBindingsInside :: { [PortBinding] }
: PortBinding { [$1] }
: PortBinding opt(",") { [$1] }
| PortBinding "," PortBindingsInside { $1 : $3}
PortBinding :: { PortBinding }
: "." Identifier "(" ExprOrNil ")" { ($2, $4) }
......@@ -977,7 +980,7 @@ ParamBindings :: { [ParamBinding] }
: "#" "(" ")" { [] }
| "#" "(" ParamBindingsInside ")" { $3 }
ParamBindingsInside :: { [ParamBinding] }
: ParamBinding { [$1] }
: ParamBinding opt(",") { [$1] }
| ParamBinding "," ParamBindingsInside { $1 : $3}
ParamBinding :: { ParamBinding }
: "." Identifier "(" TypeOrExpr ")" { ($2, $4) }
......
......@@ -91,6 +91,14 @@ forbidNonEqAsgn tokens =
-- Example: `input foo, bar, One inst`
parseDTsAsPortDecls :: [DeclToken] -> ([Identifier], [ModuleItem])
parseDTsAsPortDecls pieces =
parseDTsAsPortDecls' $
case last pieces of
DTComma{} -> init pieces
_ -> pieces
-- internal parseDTsAsPortDecls after the removal of an optional trailing comma
parseDTsAsPortDecls' :: [DeclToken] -> ([Identifier], [ModuleItem])
parseDTsAsPortDecls' pieces =
forbidNonEqAsgn pieces $
if isSimpleList
then (simpleIdents, [])
......
module ModuleA #(P=1,) (inp,);
input inp;
initial $display("ModuleA P=%0d inp=%b", P, inp);
endmodule
module ModuleB #(parameter P,) (input inp,);
initial $display("ModuleB P=%0d inp=%b", P, inp);
endmodule
module top;
ModuleA #(1,) a(1'b1,);
ModuleB #(.P(1),) b(.inp(1'b1),);
endmodule
module ModuleA #(parameter P = 1) (input inp);
initial $display("ModuleA P=%0d inp=%b", P, inp);
endmodule
module ModuleB #(parameter P = 0) (input inp);
initial $display("ModuleB P=%0d inp=%b", P, inp);
endmodule
module top;
ModuleA #(1) a(1'b1);
ModuleB #(.P(1)) b(.inp(1'b1));
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