3

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.

Paebbels
  • 15,573
  • 13
  • 70
  • 139
  • 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? –  Jan 20 '16 at 23:19
  • 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 Jan 20 '16 at 23:30
  • I should add that most of the shared variables I have used in packages are package local (declared in the package body). – Jim Lewis Jan 20 '16 at 23:32
  • This package is declared in a [single file](https://github.com/VLSI-EDA/PoC/blob/master/tb/common/simulation.v08.vhdl). 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 Jan 20 '16 at 23:33
  • I've gone part way through an analysis. Scope and visibility rules says it's legal, ditto for elaboration. –  Jan 20 '16 at 23:35

1 Answers1

2

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.

Russell
  • 3,384
  • 4
  • 31
  • 45