Commit 1472ea0c by Zachary Snow

convert unpacked parameter dimensions (closes #18)

parent 1d216a2e
...@@ -633,11 +633,12 @@ Dimension :: { Range } ...@@ -633,11 +633,12 @@ Dimension :: { Range }
: Range { $1 } : Range { $1 }
| "[" Expr "]" { (simplify $ BinOp Sub $2 (Number "1"), Number "0") } | "[" Expr "]" { (simplify $ BinOp Sub $2 (Number "1"), Number "0") }
DeclAsgns :: { [(Identifier, Expr)] } DeclAsgns :: { [(Identifier, Expr, [Range])] }
: DeclAsgn { [$1] } : DeclAsgn { [$1] }
| DeclAsgns "," DeclAsgn { $1 ++ [$3] } | DeclAsgns "," DeclAsgn { $1 ++ [$3] }
DeclAsgn :: { (Identifier, Expr) } DeclAsgn :: { (Identifier, Expr, [Range]) }
: Identifier "=" Expr { ($1, $3) } : Identifier "=" Expr { ($1, $3, []) }
| Identifier DimensionsNonEmpty "=" Expr { ($1, $4, $2) }
Range :: { Range } Range :: { Range }
: "[" Expr ":" Expr "]" { ($2, $4) } : "[" Expr ":" Expr "]" { ($2, $4) }
...@@ -730,10 +731,10 @@ DeclOrStmt :: { ([Decl], [Stmt]) } ...@@ -730,10 +731,10 @@ DeclOrStmt :: { ([Decl], [Stmt]) }
| ParameterDecl(";") { ($1, []) } | ParameterDecl(";") { ($1, []) }
ParameterDecl(delim) :: { [Decl] } ParameterDecl(delim) :: { [Decl] }
: ParameterDeclKW DeclAsgns delim { map (uncurry $ $1 (Implicit Unspecified [])) $2 } : ParameterDeclKW DeclAsgns delim { makeParamDecls $1 (Implicit Unspecified []) $2 }
| ParameterDeclKW ParamType DeclAsgns delim { map (uncurry $ $1 ($2 )) $3 } | ParameterDeclKW ParamType DeclAsgns delim { makeParamDecls $1 ($2 ) $3 }
| ParameterDeclKW Identifier Dimensions DeclAsgns delim { map (uncurry $ $1 (Alias (Nothing) $2 $3)) $4 } | ParameterDeclKW Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Nothing) $2 $3) $4 }
| ParameterDeclKW Identifier "::" Identifier Dimensions DeclAsgns delim { map (uncurry $ $1 (Alias (Just $2) $4 $5)) $6 } | ParameterDeclKW Identifier "::" Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Just $2) $4 $5) $6 }
ParameterDeclKW :: { Type -> Identifier -> Expr -> Decl } ParameterDeclKW :: { Type -> Identifier -> Expr -> Decl }
: "parameter" { Parameter } : "parameter" { Parameter }
| "localparam" { Localparam } | "localparam" { Localparam }
...@@ -995,4 +996,16 @@ toLHS expr = ...@@ -995,4 +996,16 @@ toLHS expr =
Just lhs -> lhs Just lhs -> lhs
Nothing -> error $ "Parse error: cannot convert expression to LHS: " Nothing -> error $ "Parse error: cannot convert expression to LHS: "
++ show expr ++ show expr
makeParamDecls
:: (Type -> Identifier -> Expr -> Decl)
-> Type
-> [(Identifier, Expr, [Range])]
-> [Decl]
makeParamDecls kw t items =
map mapper items
where
(tf, rs) = typeRanges t
mapper (x, e, a) = kw (tf $ a ++ rs) x e
} }
module top;
localparam logic [7:0] init_val [4] = {8'd0, 8'd8, 8'd10, 8'd200};
initial begin
integer i, j;
for (i = 0; i < 4; i += 1) begin
$display(init_val[i]);
for (j = 0; j < 8; j += 1) begin
$display(init_val[i][j]);
end
end
end
endmodule
module top;
localparam [31:0] init_val = {8'd0, 8'd8, 8'd10, 8'd200};
initial begin : foo
integer i, j;
for (i = 0; i < 4; i += 1) begin
$display(init_val[8*i+:8]);
for (j = 0; j < 8; j += 1) begin
$display(init_val[8*i+j]);
end
end
end
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