Skip to content

Commit

Permalink
Fix "expression cannot be folded" error when dumping arrays
Browse files Browse the repository at this point in the history
Fixes #979
  • Loading branch information
nickg committed Sep 19, 2024
1 parent be826a9 commit d0f7b34
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
instantiation (#969).
- Physical subtype ranges and 64-bit integer types are now handled
correctly by VHPI (#978).
- Several other minor bugs were resolved (#961, #962, #971, #975).
- Several other minor bugs were resolved (#961, #962, #971, #975, #979).

## Version 1.13.3 - 2024-08-24
- Type checking was not performed correctly for conversion function
Expand Down
16 changes: 7 additions & 9 deletions src/rt/wave.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,27 +600,25 @@ static void fst_create_array_var(wave_dumper_t *wd, tree_t d, rt_signal_t *s,

const bool is_memory = type_is_array(elem);

int64_t e_low = 1, e_high = 1;
int e_msb = 0, e_lsb = 0;
int64_t e_length = 1, e_msb = 0, e_lsb = 0;
if (is_memory) {
tree_t elem_r = range_of(elem, 0);
range_bounds(elem_r, &e_low, &e_high);

e_msb = assume_int(tree_left(elem_r));
e_lsb = assume_int(tree_right(elem_r));
range_kind_t dir;
assert(dimension_of(type) == 1);
fst_get_array_range(wd, elem, s->parent, s->where, 1, &e_msb, &e_lsb,
&dir, &e_length);
}

data = xcalloc_flex(sizeof(fst_data_t), length, sizeof(fstHandle));
data->count = length;
data->size = (e_high - e_low + 1) * ft->size;
data->size = e_length * ft->size;
data->type = ft;

for (int i = 0; i < length; i++) {
tb_rewind(tb);
tb_istr(tb, tree_ident(d));
tb_printf(tb, "[%"PRIi64"]", dir == RANGE_TO ? left + i : left - i);
if (is_memory)
tb_printf(tb, "[%d:%d]", e_msb, e_lsb);
tb_printf(tb, "[%"PRIi64":%"PRIi64"]", e_msb, e_lsb);
tb_downcase(tb);

data->handle[i] =
Expand Down
4 changes: 4 additions & 0 deletions test/regress/gold/issue979.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#0 issue979.mem[0][3:0] 1111
#0 issue979.mem[1][3:0] 0000
#1000000 issue979.mem[1][3:0] 0001
#1000000 issue979.mem[0][3:0] 0000
29 changes: 29 additions & 0 deletions test/regress/issue979.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
entity issue979 is
generic (
DATA_WIDTH: integer := 4;
FIFO_SIZE: integer := 36
);
end entity;

architecture sim of issue979 is
function GetWidth (
rdwr_width : in integer
) return integer is
variable func_width : integer;
begin
return rdwr_width;
end;
constant mem_width : integer := GetWidth(DATA_WIDTH);
type Two_D_array_type is array (1 downto 0) of bit_vector((mem_width - 1) downto 0);
signal mem : Two_D_array_type;
begin
process
begin
mem(0) <= (others => '1');
wait for 1 ns;
mem(0) <= (others => '0');
mem(1) <= (0 => '1', others => '0');
wait for 1 ns;
std.env.finish;
end process;
end architecture;
1 change: 1 addition & 0 deletions test/regress/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1045,3 +1045,4 @@ issue968 normal
issue971 normal,2008
ieee17 normal
issue978 normal,vhpi
issue979 wave,2008,dump-arrays

0 comments on commit d0f7b34

Please sign in to comment.