title: Can I use a variable inside a generate statement?
body: <p>I am wondering if it is possible to use a variable inside a <strong>generate statement</strong>.</p>
  
  <pre><code>signal bitmap_nodes : std_logic_vector(0 to NB_NODES-1) := (others =&gt; '0');
  
  CIRCULAR: if (CLOCKWISE = 0) generate
      variable index : integer := 0;
      begin
      GENERATE_NODE : for i in NB_NODES-1 to 0 generate
      begin        
          node_inst: node
          port map (                    
              rx_bitmap =&gt; bitmap_nodes(index)
          );
  
          -- Increment index
          index := index + 1;
  
      end generate GENERATE_NODE;
  
  end generate CIRCULAR;
  </code></pre>
  
  <p>Here, the variable is only used for the vector slicing.  What it will do is assign the following (assume NB_NODES equals 4):</p>
  
  <pre><code>NODE0 -&gt; bitmap_nodes(3)
  NODE1 -&gt; bitmap_nodes(2)
  NODE2 -&gt; bitmap_nodes(1)
  NODE3 -&gt; bitmap_nodes(0)
  </code></pre>