veryl icon indicating copy to clipboard operation
veryl copied to clipboard

[Feature] Iterate array

Open taichi-ishitani opened this issue 4 months ago • 0 comments

This feature is a syntax sugar for array iteration using for loop.

If one iterator is given then it shows iterated value.

var foo: logic<10>;
var bar: logic;

bar = 0;
for v in foo {
  bar ||= v;
}

This code is transrated to SV like below.

logic [10-1:0] foo;
logic          bar;

bar = 0;
foreach (foo[__i]) begin
  logic v;
  v = foo[__i];
  bar ||= v;
end

If two iterators are given then they show its index and value.

var foo: logic<10>;
var bar: logic<10>;

for i, v in foo {
  bar[i] = ~v;
}

This code is transrated to SV like below.

logic [10-1:0] foo;
logic [10-1:0] bar;

foreach (foo[i]) begin
  logic v;
  v = foo[i];
  bar[i] = ~v;
end

taichi-ishitani avatar Oct 03 '24 07:10 taichi-ishitani