aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/issue2270/fun.vhdl
blob: de7005fd09ea1ba54221eea906405537f826d659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
library ieee;
use ieee.std_logic_1164.all;

entity fun is
  port (
    d : in  std_logic_vector(3 downto 0);
    q : out std_logic_vector(4 downto 0)
    );
end entity;

architecture behaviour of fun is

  function fp (i : natural; v : std_logic_vector(3 downto 0)) return std_logic is
  begin
    if i > 3 or i < 0
    then
      return 'X';
    else
      return v(i);
    end if;
  end function;
  
begin

  process (d)

    impure function get_fp1 (i : natural) return std_logic is
    begin
      return fp(i, d);
    end function;

    impure function get_fp2 (i : natural) return std_logic is
    begin
      if i > 3 or i < 0
      then
        return 'X';
      else
        return d(i);
      end if;
    end function;

    variable fp3 : std_logic := '0';
    impure function get_fp3 return std_logic is
    begin
      fp3 := not fp3;
      return fp3;
    end function;

    impure function get_fp4 return std_logic is
    begin
      return '0';
    end function;
    
  begin
    q(0) <= fp(0, d);
    q(1) <= get_fp4;
    q(2) <= get_fp1(0);
    q(3) <= get_fp2(0);
    q(4) <= get_fp3;
  end process;
  
end architecture;