[sv-bc] Re: [sv-ec] Is instance constant allowed outside class?

From: Surya Pratik Saha <spsaha@cal.interrasystems.com>
Date: Sun Apr 04 2010 - 22:47:55 PDT
Hi Dave,
I have two more confusions regarding const declaration.

In section 6.20.6 it is written:
An instance of a class (an object handle) can also be declared with the const keyword.
const class_name object = new(5,3);
In other words, the object acts like a variable that cannot be written. The arguments to the new method shall be constant expressions (see 11.2.1).


If RHS of normal const declaration is not required to be const_expression, then why there is restriction for arguments of new method. Most of the simulators do not check this violation.

Another confusion is - class_property rule has following definition:
class_property ::=
{ property_qualifier } data_declaration
| const { class_item_qualifier } data_type const_identifier [ = constant_expression ] ;


Now a const declaration can be written either by 'data_declaration' or the explicit declaration present here, but why RHS has to be 'constant_expression' here. As usual most of the simulators do not check the constant-ness here.

I am not sure what Mantis 2372, 2410 said about as the Mantis server seems to be down.
Regards
Surya


-------- Original Message  --------
Subject: Re:[sv-ec] Is instance constant allowed outside class?
From: Bresticker, Shalom <shalom.bresticker@intel.com>
To: Rich, Dave <Dave_Rich@mentor.com>, Daniel Mlynek <daniel.mlynek@aldec.com.pl>, Surya Pratik Saha <spsaha@cal.interrasystems.com>
Cc: "sv-ec@eda.org" <sv-ec@eda.org>, "sv-bc@eda.org" <sv-bc@eda.org>, Bijoy Gopal Nandy <bijoy@cal.interrasystems.com>
Date: Sunday, April 04, 2010 4:20:49 PM
See related Mantis issues 2372 and 2410.
 
Shalom


From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Rich, Dave
Sent: Thursday, April 01, 2010 6:27 PM
To: Daniel Mlynek; Surya Pratik Saha
Cc: sv-ec@eda.org; sv-bc@eda.org; Bijoy Gopal Nandy
Subject: [sv-bc] RE: [sv-ec] Is instance constant allowed outside class?

DANiel,

 

Although I agree that it is good programming practice to consistently use a const initialization, it would add another semantic rule to the language. In such case, I would look at the cost of the rule versus the cost to the user of not having it. I don’t see any difficult to detect or debug issues with not having the rule.

 

I do think the LRM could be more explicit about when the evaluation of the initialization of a const class member occurs.

 

Dave

 

 

From: Daniel Mlynek [mailto:daniel.mlynek@aldec.com.pl]
Sent: Thursday, April 01, 2010 1:32 AM
To: Rich, Dave; 'Surya Pratik Saha'
Cc: sv-ec@eda.org; sv-bc@eda.org; 'Bijoy Gopal Nandy'
Subject: RE: [sv-ec] Is instance constant allowed outside class?

 

In my opinion this is not good idea to allow user skip the initialization of const variable.

This only confuses the user and adds no value to the language.

 

I agree with Surya that if conts with initialization should really be alllowed then LRM should be rewritten both chapters - about const and about const in classes.

I would prefer to rewrite them and say that const must have an initaliation.

 

 

DANiel

 


From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of Rich, Dave
Sent: Thursday, April 01, 2010 6:45 AM
To: Surya Pratik Saha
Cc: sv-ec@eda.org; sv-bc@eda.org; Bijoy Gopal Nandy
Subject: RE: [sv-ec] Is instance constant allowed outside class?

A static constant declared with the const keyword can be set to an expression of literals, parameters, local

parameters, genvars, enumerated names, a constant function of these, or other constants. Hierarchical names

are allowed because constants declared with the const keyword are calculated after elaboration.

const logic option = a.b.c ;

An automatic constant declared with the const keyword can be set to any expression that would be legal

without the const keyword.

 

Note the use of the word can, not shall. There is no requirement that it has to have an assignment. I would expect the behavior to be the same as a non-const variable. The const keyword is a modifier that prevents further assignments to that variable. That is all that it does.

 

Dave

 

From: Surya Pratik Saha [mailto:spsaha@cal.interrasystems.com]
Sent: Wednesday, March 31, 2010 9:11 PM
To: Rich, Dave
Cc: sv-ec@eda.org; sv-bc@eda.org; Bijoy Gopal Nandy
Subject: Re: [sv-ec] Is instance constant allowed outside class?

 

Hi Dave,
I could not find anything in "6.20.6" where it allows const declaration without initialization. Please let me know if there is any LRM specification.

Also, it is not clear what is the value of using a const declared variable which does not have initialization, will it take default value (like for 4 state, it will be all 'x', and for 2 state it will be all '0')?

And if 'global constant' can be declared without initialization, then I think some rewriting is required in "8.18 Constant class properties", otherwise it is very confusing.

Regards
Surya



-------- Original Message  --------
Subject: [sv-bc] RE: [sv-ec] Is instance constant allowed outside class?
From: Rich, Dave <Dave_Rich@mentor.com>
To: Surya Pratik Saha <spsaha@cal.interrasystems.com>, sv-ec@eda.org, sv-bc@eda.org
Cc: "Bijoy Gopal Nandy" <bijoy@cal.interrasystems.com>
Date: Wednesday, March 31, 2010 8:21:05 PM

Yes, see section 6.20. There is no requirement to have an user specified
initialization.
 
The name global constant is a misnomer. It behaves like any other const,
which means it can take on different values each time the variable comes
into existence because the initialization expression may evaluate
differently.
 
The only thing special about a class instance constant is that it is
allowing a "write" to the const variable in the constructor instead of
the declaration initialization. 
 
  
-----Original Message-----
From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of
    
Surya
  
Pratik Saha
Sent: Wednesday, March 31, 2010 7:19 AM
To: sv-ec@eda.org; sv-bc@eda.org
Cc: Bijoy Gopal Nandy
Subject: [sv-ec] Is instance constant allowed outside class?
 
Hi,
"8.18 Constant class properties" of SV 2009 LRM defines two types of
constants - global constant (initialization is must) and instance
constant (initialization is missing). Is it allowed to use that
    
instance
  
constant syntax in non-class scope? For e.g.:
module top;
    const int x; // Is it allowed?
endmodule
 
OR
module top;
    class C;
       function f;
          const int x; // Is it allowed
       endfunction
    endclass
endmodule
 
Some standard tools pass both the cases. Also OVM 2.1.1 has 2nd type
    
of
  
syntax usage in its source. Please let me know.
 
--
Regards
Surya
 
 
 
 
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
    
 
 
  

 


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
  


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean. Received on Sun Apr 4 22:49:03 2010

This archive was generated by hypermail 2.1.8 : Sun Apr 04 2010 - 22:49:16 PDT