3
votes

I have a simulation helper protected type, which is declared in a package. An instance of that type is defined in the same package. The code is acepted by GHDL, but not by ModelSim.

Is it standard conform?
and
How can a write a workaround?

** Error (suppressible): D:\...\simulation.v08.vhdl(143): (vcom-1257) Shared variable "globalSimStatus" of protected type "T_SIM" cannot be declared before the protected type body.

My (reduced) package example:

package simulation is
  type T_SIM is protected 
    procedure stop;
  end protected;

  shared variable globalSimStatus : T_SIM;
  -- QuestaSim 10.4c complains that a shared variable can not be declared, before the type's body was parsed.
end package;

package body simulation is
  type T_SIM is protected body
    variable IsStopped : BOOLEAN := FALSE;

    procedure stop is
    begin
      IsStopped := TRUE;
    end procedure;
  end protected body;

  -- This is OK but not global
  shared variable localSimStatus : T_SIM;
end package body;

One solution could be to define 2 packages: one with the type in it and one with the shared variable.

The disadvantages would be to find a second package name and to import (use) 2 packages in the testbench...

Are there better solutions?


I assume QuestaSim wants to know the type's size, which is unknown until all members are parsed.

1
You're committing a cardinal sin, not supplying an mcve or actual (and full) error messages. For instance IEEE Std 1076-2008 4.7 Package declarations, para 8 "For a package declaration that appears in a subprogram body, a process statement, or a protected type body, it is an error if a variable declaration in the package declarative part of the package declaration declares a shared variable. Moreover, it is an error if a signal declaration, a disconnection specification, or a PSL declaration appears as a package declarative item of such a package declaration." Where is this package declared?user1155120
I use a protected type in a separate package for this. It is not worth fighting with. Perhaps a generic package that allows one to get and set an object would be convenient - however, I avoided generic packages in OSVVM as they were on the bleeding edge of tool support. Perhaps a separate one for scalars and vectors as vectors need to use pointers rather than a fixed sized object. In OSVVM, I still use regular packages. See NamePkg. Also see AlertLogPkg where the PT and the shared variable are in the package body.Jim Lewis
I should add that most of the shared variables I have used in packages are package local (declared in the package body).Jim Lewis
This package is declared in a single file. QuestaSim complains while execution vcom. I don't have the complete error message on my phone, but I'll insert it tomorrow. The package is used in my testbenches.Paebbels
I've gone part way through an analysis. Scope and visibility rules says it's legal, ditto for elaboration.user1155120

1 Answers

2
votes

Modelsim 6.3b or later no longer allows a shared variable of a protected type to be declared before the protected body.

Your workaround and the one Jim suggests is one option: to create another package just for your shared variable.

An alternative solution is to suppress the error to a warning using a modelsim switch:

-allowProtectedBeforeBody

This is the work-around that I use.