Commit e82537fa by Zachary Snow

add support for localparams in module parameter list (resolves #7)

parent 90bc30d4
...@@ -358,15 +358,11 @@ PackageImportDeclaration :: { [ModuleItem] } ...@@ -358,15 +358,11 @@ PackageImportDeclaration :: { [ModuleItem] }
: "import" PackageImportItems ";" { map (MIPackageItem . uncurry Import) $2 } : "import" PackageImportItems ";" { map (MIPackageItem . uncurry Import) $2 }
Params :: { [ModuleItem] } Params :: { [ModuleItem] }
: {- empty -} { [] } : {- empty -} { [] }
| "#" "(" ParamDecls { $3 } | "#" "(" ParamsFollow { map (MIPackageItem . Decl) $3 }
ParamDecls :: { [ModuleItem] } ParamsFollow :: { [Decl] }
: ParamDecl(")") { $1 } : ParameterDecl(")") { $1 }
| ParamDecl(",") ParamDecls { $1 ++ $2 } | ParameterDecl(",") ParamsFollow { $1 ++ $2 }
ParamDecl(delim) :: { [ModuleItem] }
: ParameterDecl(OnlyParamKW, delim) { map (MIPackageItem . Decl) $1 }
OnlyParamKW :: { Type -> Identifier -> Expr -> Decl }
: "parameter" { Parameter }
PortDecls :: { ([Identifier], [ModuleItem]) } PortDecls :: { ([Identifier], [ModuleItem]) }
: "(" DeclTokens(")") { parseDTsAsPortDecls $2 } : "(" DeclTokens(")") { parseDTsAsPortDecls $2 }
...@@ -455,8 +451,8 @@ ModuleItem :: { [ModuleItem] } ...@@ -455,8 +451,8 @@ ModuleItem :: { [ModuleItem] }
| "generate" GenItems "endgenerate" { [Generate $2] } | "generate" GenItems "endgenerate" { [Generate $2] }
NonGenerateModuleItem :: { [ModuleItem] } NonGenerateModuleItem :: { [ModuleItem] }
-- This item covers module instantiations and all declarations -- This item covers module instantiations and all declarations
: DeclTokens(";") { parseDTsAsModuleItems $1 } : DeclTokens(";") { parseDTsAsModuleItems $1 }
| ParameterDecl(ParameterDeclKW, ";") { map (MIPackageItem . Decl) $1 } | ParameterDecl(";") { map (MIPackageItem . Decl) $1 }
| "defparam" DefparamAsgns ";" { map (uncurry Defparam) $2 } | "defparam" DefparamAsgns ";" { map (uncurry Defparam) $2 }
| "assign" opt(DelayControl) LHS "=" Expr ";" { [Assign $2 $3 $5] } | "assign" opt(DelayControl) LHS "=" Expr ";" { [Assign $2 $3 $5] }
| AlwaysKW Stmt { [AlwaysC $1 $2] } | AlwaysKW Stmt { [AlwaysC $1 $2] }
...@@ -577,9 +573,9 @@ PackageItems :: { [PackageItem] } ...@@ -577,9 +573,9 @@ PackageItems :: { [PackageItem] }
: PackageItem { $1 } : PackageItem { $1 }
| PackageItems PackageItem { $1 ++ $2 } | PackageItems PackageItem { $1 ++ $2 }
PackageItem :: { [PackageItem] } PackageItem :: { [PackageItem] }
: DeclTokens(";") { map Decl $ parseDTsAsDecls $1 } : DeclTokens(";") { map Decl $ parseDTsAsDecls $1 }
| ParameterDecl(ParameterDeclKW, ";") { map Decl $1 } | ParameterDecl(";") { map Decl $1 }
| NonDeclPackageItem { $1 } | NonDeclPackageItem { $1 }
NonDeclPackageItem :: { [PackageItem] } NonDeclPackageItem :: { [PackageItem] }
: "typedef" Type Identifier ";" { [Typedef $2 $3] } : "typedef" Type Identifier ";" { [Typedef $2 $3] }
| "function" opt(Lifetime) FuncRetAndName TFItems DeclsAndStmts "endfunction" opt(Tag) { [Function $2 (fst $3) (snd $3) (map defaultFuncInput $ (map makeInput $4) ++ fst $5) (snd $5)] } | "function" opt(Lifetime) FuncRetAndName TFItems DeclsAndStmts "endfunction" opt(Tag) { [Function $2 (fst $3) (snd $3) (map defaultFuncInput $ (map makeInput $4) ++ fst $5) (snd $5)] }
...@@ -728,13 +724,13 @@ DeclsAndStmts :: { ([Decl], [Stmt]) } ...@@ -728,13 +724,13 @@ DeclsAndStmts :: { ([Decl], [Stmt]) }
| {- empty -} { ([], []) } | {- empty -} { ([], []) }
DeclOrStmt :: { ([Decl], [Stmt]) } DeclOrStmt :: { ([Decl], [Stmt]) }
: DeclOrStmtTokens(";") { parseDTsAsDeclOrAsgn $1 } : DeclOrStmtTokens(";") { parseDTsAsDeclOrAsgn $1 }
| ParameterDecl(ParameterDeclKW, ";") { ($1, []) } | ParameterDecl(";") { ($1, []) }
ParameterDecl(kw, delim) :: { [Decl] } ParameterDecl(delim) :: { [Decl] }
: kw DeclAsgns delim { map (uncurry $ $1 (Implicit Unspecified [])) $2 } : ParameterDeclKW DeclAsgns delim { map (uncurry $ $1 (Implicit Unspecified [])) $2 }
| kw ParamType DeclAsgns delim { map (uncurry $ $1 ($2 )) $3 } | ParameterDeclKW ParamType DeclAsgns delim { map (uncurry $ $1 ($2 )) $3 }
| kw Identifier DeclAsgns delim { map (uncurry $ $1 (Alias (Nothing) $2 [])) $3 } | ParameterDeclKW Identifier DeclAsgns delim { map (uncurry $ $1 (Alias (Nothing) $2 [])) $3 }
| kw Identifier "::" Identifier DeclAsgns delim { map (uncurry $ $1 (Alias (Just $2) $4 [])) $5 } | ParameterDeclKW Identifier "::" Identifier DeclAsgns delim { map (uncurry $ $1 (Alias (Just $2) $4 [])) $5 }
ParameterDeclKW :: { Type -> Identifier -> Expr -> Decl } ParameterDeclKW :: { Type -> Identifier -> Expr -> Decl }
: "parameter" { Parameter } : "parameter" { Parameter }
| "localparam" { Localparam } | "localparam" { Localparam }
......
module top module top
import pkg::*; import pkg::*;
#(parameter width = width_calc(2)) #(localparam width = width_calc(2))
(input [width-1:0] i, output [width-1:0] o); (input [width-1:0] i, output [width-1:0] o);
assign o = i + 1'b1; assign o = i + 1'b1;
initial begin initial begin
......
`define FANCY_SEEING_YOU 1337 `define FANCY_SEEING_YOU 1337
module top; module top;
parameter width = 5; localparam width = 5;
input [width-1:0] i; input [width-1:0] i;
output [width-1:0] o; output [width-1:0] o;
assign o = i + 1'b1; assign o = i + 1'b1;
......
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