Search code examples
vhdl

Multiple VHDL packages with constant having same name, how to select the correct constant?


I use a TCL script to generate a VHDL pkg for each submodule repository that stores the compilation date time and git hash of the submodule. The constant storing 32 bit git hash is called MAIN_GIT_HASH and is an std_logic_vector.

I now have multiple packages that all contain a constant called MAIN_GIT_HASH and I need to include them into the same source file using the VHDL "use" directive. Now the question is, what is the correct way to select the correct constant from each package since just writing "MAIN_GIT_HASH" will be ambigious?


Solution

  • Each of the packages either needs to have a unique name or needs to be analyzed into a separate library.

    If you use separate libraries, you simply reference it using a package path:

    library Submodule1 ; 
    use Submodule1.HashPkg.MAIN_GIT_HASH ;  -- just get the relevant constant
    

    Should a design need to reference more than one HashPkg (like your use case), then you can reference the constant with the same notation as above:

    HashReg <= Submodule1.HashPkg.MAIN_GIT_HASH ;
    

    If you use unique named packages, then they could all be put into the same library. Assuming that that library is the same as the one into which you are compiling the current design unit, then you can reference it as being in work:

    use work.Submodule1HashPkg.MAIN_GIT_HASH ;
    . . . 
    HashReg <= work.Submodule1HashPkg.MAIN_GIT_HASH ;