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

From: Bresticker, Shalom <shalom.bresticker@intel.com>
Date: Sun Apr 04 2010 - 03:50:49 PDT

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><mailto:Dave_Rich@mentor.com>
To: Surya Pratik Saha <spsaha@cal.interrasystems.com><mailto:spsaha@cal.interrasystems.com>, sv-ec@eda.org<mailto:sv-ec@eda.org>, sv-bc@eda.org<mailto:sv-bc@eda.org>
Cc: "Bijoy Gopal Nandy" <bijoy@cal.interrasystems.com><mailto: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> [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<mailto:sv-ec@eda.org>; sv-bc@eda.org<mailto: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<http://www.mailscanner.info/>, and is
believed to be clean.
--
This message has been scanned for viruses and
dangerous content by MailScanner<http://www.mailscanner.info/>, 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 19:44:58 2010

This archive was generated by hypermail 2.1.8 : Sun Apr 04 2010 - 19:45:12 PDT