Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of Subtypes of Records Fail #615

Closed
bpadalino opened this issue Feb 10, 2023 · 1 comment
Closed

Array of Subtypes of Records Fail #615

bpadalino opened this issue Feb 10, 2023 · 1 comment

Comments

@bpadalino
Copy link
Contributor

The following works in GHDL and Questa, but fails in nvc:

library ieee ;
    use ieee.std_logic_1164.all ;
    use ieee.numeric_std.all ;
    use ieee.math_real.all ;

    use std.textio.all ;

entity test is
end entity ;

architecture arch of test is

    constant LUT_DEPTH : positive := 2048 ;

    type cx_t is record
        re  :   signed ;
        im  :   signed ;
    end record ;

    function to_string(x : cx_t) return string is
    begin
        return "(" &
               to_string(to_integer(x.re)) &
               "," &
               to_string(to_integer(x.im)) &
               ")" ;
    end function ;

    subtype c18_t is cx_t( re(17 downto 0), im(17 downto 0) );

    type c18s_t is array(natural range <>) of c18_t ;

    function sincos(n : positive) return c18s_t is
        variable rv : c18s_t(0 to n-1) ;
    begin
        for idx in 0 to n-1 loop
            rv(idx).re := to_signed(integer(round(32768.0*cos(2.0*MATH_PI*real(idx)/real(n)))), 18) ;
            rv(idX).im := to_signed(integer(round(32768.0*sin(2.0*MATH_PI*real(idx)/real(n)))), 18) ;
        end loop ;
        return rv ;
    end function ;

    constant sincos_lut : c18s_t(0 to LUT_DEPTH-1) := sincos(LUT_DEPTH) ;

begin

    tb : process
        variable l : line ;
    begin
        for idx in sincos_lut'range loop
            write(l, to_string(sincos_lut(idx))) ;
            writeline(output, l) ;
        end loop ;
        std.env.stop ;
    end process ;

end architecture ;

The offending line is ...

   > test.vhd:34
    |
 34 |         variable rv : c18s_t(0 to n-1) ;
    |                  ^^
** Fatal: invalid type kind T_ARRAY in range_of
[0x558303fac54d] ../src/diag.c:890 diag_femit.part.0
[0x558303f0ac25] ../src/util.c:548 fatal_trace
[0x558303f632f2] ../src/common.c:836 range_of
[0x558303f703e6] ../src/lower.c:482 lower_array_len
[0x558303f703e6] ../src/lower.c:470 lower_array_len.lto_priv.0
[0x558303f707a0] ../src/lower.c:539 lower_array_total_len.lto_priv.0
[0x558303f7bf74] ../src/lower.c:4685 lower_default_value.lto_priv.0
[0x558303f7c23c] ../src/lower.c:4764 lower_default_value.lto_priv.0
[0x558303f7bfac] ../src/lower.c:4692 lower_default_value.lto_priv.0
[0x558303f89380] ../src/lower.c:6843 lower_decls.lto_priv.0
[0x558303f883ab] ../src/lower.c:9360 lower_decls.lto_priv.0
[0x558303f911f8] ../src/lower.c:10288 lower_concurrent_block
[0x558303f91bac] ../src/lower.c:10326 lower_elab
[0x558303f91bac] ../src/lower.c:10380 lower_unit
[0x558303f120b7] ../src/nvc.c:368 elaborate
[0x558303f120b7] ../src/nvc.c:1387 process_command
[0x558303f11d0b] ../src/nvc.c:394 elaborate
[0x558303f11d0b] ../src/nvc.c:1387 process_command
[0x558303f0878a] ../src/nvc.c:1512 main
@nickg
Copy link
Owner

nickg commented Feb 14, 2023

Fixed now, thanks for the test case.

@nickg nickg closed this as completed Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants