Re: [sv-bc] Question about "let"

From: Surya Pratik Saha <spsaha_at_.....>
Date: Sat Jun 06 2009 - 21:08:06 PDT
Hi Shalom,
If I understand correctly, as you have explained by "rewriting algorithm", all the formal argument usage of "let" construct is substituted by a casted expression of provided actual argument, then any lvalue usage of formal argument or bit/part select of formal argument becomes also illegal. In other way, the usage which is legal on a casted expression only becomes legal, remaining all will become illegal. Is it the intention of LRM? Or casted expression is used here just to explain the concept?

For e.g.
let post_incr(v) = v [1:0];
let pre_incr(int v) = v[1:0];

int a = 0 , b = 0;
b = post_incr(a);
a = pre_incr( b );

All above usage are illegal, because int'(b)[1:0] is or type(a)'(a)[1:0] all are illegal. Please let me know if I am missing here anything, or this is the intention?
Regards
Surya


-------- Original Message  --------
Subject: Re:[sv-bc] Question about "let"
From: Bresticker, Shalom <shalom.bresticker@intel.com>
To: Brad Pierce <Brad.Pierce@synopsys.com>, sv-bc@eda.org <sv-bc@eda.org>
Date: Thursday, June 04, 2009 8:10:45 PM
As I understand the rewriting algorithm, the actual_argument is indeed an "expression", but the way it is rewritten depends on whether it is an lvalue or $ or not. It has the effect of determining whether it is rewritten with or without a cast.

Shalom

  
-----Original Message-----
From: owner-sv-bc@server.eda.org 
[mailto:owner-sv-bc@server.eda.org] On Behalf Of Brad Pierce
Sent: Thursday, June 04, 2009 5:28 PM
To: sv-bc@eda.org
Subject: RE: [sv-bc] Question about "let"

Thanks for correcting me, Shalom.  This is excellent information.

But I'm not sure about the distinction you're making between 
the actuals 'a' and 'b+1' here.  According to the BNF, the 
actual 'a' is not an lvalue, but an 'expression'.

Is the expression nature of 'a' laundered away by 'let'?  Or 
is 'expression' only being used very loosely, as in the 
'actual_argument' of Syntax 22-3?

-- Brad

________________________________________
From: owner-sv-bc@eda.org [owner-sv-bc@eda.org] On Behalf Of 
Bresticker, Shalom [shalom.bresticker@intel.com]
Sent: Thursday, June 04, 2009 7:07 AM
To: sv-bc@eda.org
Subject: RE: [sv-bc] Question about "let"

I discussed this with Dmitry.

First, the 'let' *is* a template. The LRM says, "A let 
declaration defines a template expression (a let body), 
customized by its ports."

The complete let expression is enclosed in parentheses where 
it is used. The LRM says, "The result of the substitution is 
enclosed in parentheses (...) so as to preserve the priority 
of evaluation of the let body."

However, this is not true of the substitution of the actual 
arguments for the formal arguments. This is done according to 
the rewriting algorithm in F.4.1.

A formal argument can be typed or untyped.

In Greg's example,

    
     let post_incr(v) = v++;
     let pre_incr(int v) = v++;
     int a = 0 , b = 0;
     b = post_incr(a);
     a = pre_incr( b+1 );
        
post_incr has an untyped formal argument.
pre_incr has a typed formal argument.

In the case of an untyped formal argument (e.g., v in 
post_incr), then if the actual argument is $ or a 
variable_lvalue, then it is substituted as is. "a" means this 
condition, "b+1" does not. If this condition is not met, the 
formal argument is replaced by the actual argument, with the 
addition of a cast: item(type(af)'(af)), where "af" is the 
actual argument. Note that the operand of the ++ operator is 
required to be an lvalue. b+1 is not an lvalue, so this will 
not be a legal value for this let construct.

If the formal argument is typed, as in pre_incr, even if the 
argument is an lvalue, the formal argument is replaced by a 
cast of the actual argument to the type of the formal 
argument. So for pre_incr, even if the argument were simply 
b, it would be replaced by int'(b), which again is not a 
legal lvalue, even though b itself is a valid lvalue.

A careful reading of the rewrite algorithm will show that the 
substitution of actual arguments for formal arguments is not 
necessarily a simple literal textual substitution, even with 
casts. It is more of a conceptual substitution. That is the 
purpose of "item", which is described in the 3rd paragraph of F.4.1.

Dmitry, please correct me if I got any of this wrong.

Regards,
Shalom

    
-----Original Message-----
From: owner-sv-bc@server.eda.org
[mailto:owner-sv-bc@server.eda.org] On Behalf Of Greg Jaxon
Sent: Tuesday, June 02, 2009 12:00 AM
To: Brad Pierce
Cc: SV_BC List
Subject: Re: [sv-bc] Question about "let"

In C++, that wouldn't do the trick, but in SV it appears to
make all the
difference, Thanks!


Brad Pierce wrote:
      
Greg,

When the actual for v gets substituted in, isn't it wrapped
        
in parens, yielding something illegal, such as
      
              (x)++

-- Brad


________________________________________
From: owner-sv-bc@eda.org [owner-sv-bc@eda.org] On Behalf
        
Of Greg Jaxon [Greg.Jaxon@synopsys.COM]
      
Sent: Monday, June 01, 2009 1:03 PM
To: SV_BC List
Subject: [sv-bc] Question about "let"

Are either of the following legal?

     let post_incr(v) = v++;

     let pre_incr(int v) = v++;

If they are, what is the value of the actual arguments after the
following uses?

     int a = 0 , b = 0;
     b = post_incr(a);
     a = pre_incr( b+1 );

My understanding is that at the very least this last usage
        
is illegal,
      
but perhaps not, if we regard let as having more of a
        
functional than a
      
template interpretation.

Greg Jaxon
        
---------------------------------------------------------------------
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.

-- 
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 Sat Jun 6 21:09:31 2009

This archive was generated by hypermail 2.1.8 : Sat Jun 06 2009 - 21:10:22 PDT