Skip to content

Call protected type method in declarative region

Capability

Currently the LRM disallows calling a method of a protected type in a declarative region.

However, in testing, many simulators already allow this.

Current Use Model

In the OSVVM AlertLogPkg, there is a singleton data structure. It is used control messaging and tabulate errors from particular message sources. Each message source is referenced by an ID. IDs are acquired when a model is created.

Currently we must do the following:

signal ModelID : AlertLogType ;
. . . 
initialize : process
begin
   ModelID <= GetAlertLogID("AxiStreamTx_1"); 

Updated Use Model

constant ModelID : AlertLogType := GetAlertLogID("AxiStreamTx_1"); 

GetAlertLogID is defined as follows and calls a method of a protected type.

package body AlertLogPkg is 
  type AlertLogStructPType is protected          
    . . .
  type AlertLogStructPType is protected body      
    . . .
  end  protected AlertLogStructPType ;

  shared variable AlertLogStruct : AlertLogStructPType ;

  impure function GetAlertLogID(Name : string ; ParentID : AlertLogIDType := ALERTLOG_ID_NOT_ASSIGNED ; CreateHierarchy : Boolean := TRUE) return AlertLogIDType is
    variable result : AlertLogIDType ;
  begin
    result := AlertLogStruct.GetAlertLogID(Name, ParentID, CreateHierarchy ) ;
    return result ;
  end function GetAlertLogID ;

The benefits are more than just code compactness. The benefit is that now the IDs can be used during initialization (time 0 ns, simulation cycle 0).

Currently there is a growing number of similar use cases that can benefit from this.

LRM Edits

In 14.4.1, in the last paragraph, delete the text marked below:

In certain cases, the elaboration of a declarative item involves the evaluation of expressions that appear within the declarative item. The value of any object denoted by a primary in such an expression shall be defined at the time the primary is read (see 6.5.2). In addition, if a primary in such an expression is a function call, then the value of any object denoted by or appearing as a part of an actual designator in the function call shall be defined at the time the expression is evaluated. Additionally, it is an error if a primary that denotes a shared variable, or a method of the protected type of a shared variable, is evaluated during the elaboration of a declarative item. During static elaboration, the function STD.STANDARD.NOW (see 16.3) returns the value 0 ns.

LCS

https://gitlab.com/IEEE-P1076/lrm-latex/-/merge_requests/52

Edited by JimLewis
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information