Units are similar to structs. It also contain all struct members, i.e. fields, methods, etc. Units are static. It is created during start of the simulation and stays until the end of simulation. Units are generated in Pre-run generation phase. We will task about the generation phases in more detailed later. Units are associated with an HDL hierarchy instance. Predefine method hdl_path() is used for setting the unit's associated HDL path. For accessing parent enclosing unit , predefined method get_enclosing_unit() is used.
Syntax: unit unit-type [like base-unit-type]{[unit-member;...]};
EXAMPLE: unit XYZ_router { channels:listof XYZ_channel is instance; keep channels.size()==3; keepforeachin channels {.hdl_path()== append("chan",index);}; };
Units Vs Structs
The decision of whether to model a DUT component with a unit or a struct often depends on your verification strategy. You intend to test the DUT component both standalone and integrated into a larger system. Modeling the DUT component with a unit instead of a struct allows you to use relative path names when referencing HDL objects. Your e program has methods that access many signals at runtime. The correctness of all signal references within units are determined and checked during pre-run generation. If your e program does not contain user units, the absolute HDL references within structs are also checked during pre-run generation. However, if your e program does contain user units, the relative HDL references within structs are checked at run time. In this case, using units rather than structs can enhance runtime performance