mirror of https://github.com/zachjs/sv2v.git
simplify $bits on simple part selects
This commit is contained in:
parent
eb93ba67fc
commit
2d7982f81e
|
|
@ -136,4 +136,11 @@ convertBits (Right e) =
|
|||
Nothing -> Number "32"
|
||||
Just 0 -> Number "32"
|
||||
Just idx -> Number $ take idx n
|
||||
Range expr mode range ->
|
||||
BinOp Mul size $ convertBits $ Right $ Bit expr (Number "0")
|
||||
where
|
||||
size = case mode of
|
||||
NonIndexed -> rangeSize range
|
||||
IndexedPlus -> snd range
|
||||
IndexedMinus -> snd range
|
||||
_ -> DimsFn FnBits $ Left $ TypeOf e
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
module top;
|
||||
parameter A = 3;
|
||||
parameter B = 4;
|
||||
logic [A*B-1:0] arr;
|
||||
initial begin
|
||||
arr = 0;
|
||||
for (integer i = 0; i < A; ++i) begin
|
||||
// yes this is silly but it captures an interesting edge case
|
||||
arr[i * B +: B] = $bits(arr[i * B +: B])'(i);
|
||||
end
|
||||
$display("%b", arr);
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
module top;
|
||||
parameter A = 3;
|
||||
parameter B = 4;
|
||||
reg [A*B-1:0] arr;
|
||||
initial begin : foo
|
||||
integer i;
|
||||
arr = 0;
|
||||
for (i = 0; i < A; ++i) begin
|
||||
arr[i * B +: B] = i;
|
||||
end
|
||||
$display("%b", arr);
|
||||
end
|
||||
endmodule
|
||||
|
||||
Loading…
Reference in New Issue