Variable declarations
variable_declaration
[ shared ] variable identifier_list : subtype_indication [ := expression ] ;
Parents
- entity_declarative_part
- architecture_declarative_part
- package
- package_body
- block_declarative_part
- function_declarative_part
- procedure_declarative_part
- process_declarative_part
Further definitions
identifier_list
identifier {, identifier }
subtype_indication
[ resolution_function_ name ] type_mark [ constraint ]
expression
- relation { and relation }
- relation { or relation }
- relation { xor relation }
- relation [ nand relation ]
- relation [ nor relation ]
- relation { xnor relation }
Comment
Shared variables declarations are allowed only in the declarative part of entities, architectures, packages, package bodies and blocks. Shared variables declarations must not be used in processes and subprograms.
More than one process can access shared variables. If several processes access a given shared variable in the same simulation cycle, the sequence of accesses is not prescribed. It is neither the actual value of the variable after the simulation cycle nor the different values of the variable read within the simulation cycle are deterministic. See example below.
Examples
The variable count of the type positive is declared.
VARIABLE count : positive ;
The variables index and memory are declared as subtypes of the types integer and bit_matrix .
VARIABLE index : integer RANGE 0 TO 99 := 0 ; VARIABLE memory : bit_matrix ( 0 TO 7, 0 TO 1023 ) ;
- address_bus is declared as a variable of the type bit8 and initialized with the value ā00110110ā.
- integer_address is declared as a variable of the type integer and initialized with (2**nb_bit-1).
- The variable bittab is declared as a subtype of the type bit_vector and initialized with ā000111Z1Zā.
- The variable tab is declared as a subtype of the type table_type and initialized with the values 2, 3, 4, -2 and 0.
VARIABLE address_bus : bit8 := "00110110" ; VARIABLE integer_address : integer := 2**nb_bit - 1 ; VARIABLE bittab : bit_vector (1 TO 9) := ( 1 TO 3 => '0', 7 | 9 => 'Z', OTHERS => '1' ) ; VARIABLE tab : table_type( 0 TO 4 ) := ( 2, 3, 4, -2, 0 ) ;
An example for the non-deterministic of using shared variables :
A shared variable which is manipulated by two processes is declared in the architecture.
It is not prescribed, whether
- first p1 increments counter by one (counter = 1) and then p2 decrements counter by one (counter = 0)
- first p2 tries to decrement counter by one, which would lead to an error because of the subtype violation
ARCHITECTURE beh OF sv_example IS SHARED VARIABLE counter : integer RANGE 0 TO 1 := 0 ; BEGIN p1: PROCESS BEGIN counter := counter + 1 ; wait ; END PROCESS p1; p2: PROCESS BEGIN counter := counter - 1; wait ; END PROCESS p2 ; END ARCHITECTURE beh;