mirror of https://github.com/zachjs/sv2v.git
allow trailing commas in parameter and port lists and bindings
This commit is contained in:
parent
bdc7b5ad69
commit
5a8801a45f
|
|
@ -579,14 +579,17 @@ PIParams :: { [Decl] }
|
||||||
| "#" "(" ")" { [] }
|
| "#" "(" ")" { [] }
|
||||||
| "#" "(" ParamsFollow { $3 }
|
| "#" "(" ParamsFollow { $3 }
|
||||||
ParamsFollow :: { [Decl] }
|
ParamsFollow :: { [Decl] }
|
||||||
: ParamAsgn ")" { [$1] }
|
: ParamAsgn ParamsEnd { [$1] }
|
||||||
| ParamAsgn "," ParamsFollow { $1 : $3 }
|
| ParamAsgn "," ParamsFollow { $1 : $3 }
|
||||||
| ParamsDecl { $1 }
|
| ParamsDecl { $1 }
|
||||||
ParamsDecl :: { [Decl] }
|
ParamsDecl :: { [Decl] }
|
||||||
: ModuleParameterDecl(")") { $1 }
|
: ModuleParameterDecl(ParamsEnd) { $1 }
|
||||||
| ModuleParameterDecl(",") ParamsDecl { $1 ++ $2 }
|
| ModuleParameterDecl(",") ParamsDecl { $1 ++ $2 }
|
||||||
ParamAsgn :: { Decl }
|
ParamAsgn :: { Decl }
|
||||||
: Identifier "=" Expr { Param Parameter (Implicit Unspecified []) $1 $3 }
|
: Identifier "=" Expr { Param Parameter (Implicit Unspecified []) $1 $3 }
|
||||||
|
ParamsEnd
|
||||||
|
: ")" {}
|
||||||
|
| "," ")" {}
|
||||||
|
|
||||||
PortDecls :: { ([Identifier], [ModuleItem]) }
|
PortDecls :: { ([Identifier], [ModuleItem]) }
|
||||||
: "(" PortDeclTokens(")") { parseDTsAsPortDecls $2 }
|
: "(" PortDeclTokens(")") { parseDTsAsPortDecls $2 }
|
||||||
|
|
@ -965,7 +968,7 @@ PortBindings :: { [PortBinding] }
|
||||||
: "(" ")" { [] }
|
: "(" ")" { [] }
|
||||||
| "(" PortBindingsInside ")" { $2 }
|
| "(" PortBindingsInside ")" { $2 }
|
||||||
PortBindingsInside :: { [PortBinding] }
|
PortBindingsInside :: { [PortBinding] }
|
||||||
: PortBinding { [$1] }
|
: PortBinding opt(",") { [$1] }
|
||||||
| PortBinding "," PortBindingsInside { $1 : $3}
|
| PortBinding "," PortBindingsInside { $1 : $3}
|
||||||
PortBinding :: { PortBinding }
|
PortBinding :: { PortBinding }
|
||||||
: "." Identifier "(" ExprOrNil ")" { ($2, $4) }
|
: "." Identifier "(" ExprOrNil ")" { ($2, $4) }
|
||||||
|
|
@ -977,7 +980,7 @@ ParamBindings :: { [ParamBinding] }
|
||||||
: "#" "(" ")" { [] }
|
: "#" "(" ")" { [] }
|
||||||
| "#" "(" ParamBindingsInside ")" { $3 }
|
| "#" "(" ParamBindingsInside ")" { $3 }
|
||||||
ParamBindingsInside :: { [ParamBinding] }
|
ParamBindingsInside :: { [ParamBinding] }
|
||||||
: ParamBinding { [$1] }
|
: ParamBinding opt(",") { [$1] }
|
||||||
| ParamBinding "," ParamBindingsInside { $1 : $3}
|
| ParamBinding "," ParamBindingsInside { $1 : $3}
|
||||||
ParamBinding :: { ParamBinding }
|
ParamBinding :: { ParamBinding }
|
||||||
: "." Identifier "(" TypeOrExpr ")" { ($2, $4) }
|
: "." Identifier "(" TypeOrExpr ")" { ($2, $4) }
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,14 @@ forbidNonEqAsgn tokens =
|
||||||
-- Example: `input foo, bar, One inst`
|
-- Example: `input foo, bar, One inst`
|
||||||
parseDTsAsPortDecls :: [DeclToken] -> ([Identifier], [ModuleItem])
|
parseDTsAsPortDecls :: [DeclToken] -> ([Identifier], [ModuleItem])
|
||||||
parseDTsAsPortDecls pieces =
|
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 $
|
forbidNonEqAsgn pieces $
|
||||||
if isSimpleList
|
if isSimpleList
|
||||||
then (simpleIdents, [])
|
then (simpleIdents, [])
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
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
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
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
|
||||||
Loading…
Reference in New Issue