Re: [sv-bc] Search order for functions/tasks in modules, $unit and packages

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Thu Aug 25 2005 - 17:08:18 PDT
I'm not sure that I want to suggest answers at this point, but
here are some additional similar scenarios:

1)
      module m;
      parameter p = 1;
      function int fn();
         return 0;
      endfunction
      if (p) begin:b   // generate
          reg x = fn();
          function int fn();
              return 1;
          endfunction
      end
      endmodule

2)
      // file mode compilation unit
      module m;
         int x = fn();
      endmodule
      function int fn();
          return 1;
      endfunction

2)
      // file mode compilation unit
      module m;
         int x = a;   // error?
      endmodule
      localparam a = 1;


The basic question relates to whether that Mark raises and that
is in (1) and (2) above is whether the function name goes
through a "resolve" step in the complete context or whether
lexical scoping dominates.  In the case of (3), the issue
is whethere the compilation unit is really an implicit package
that bundles all the declarations up as though they exist before
any of the scoped items in the compilation unit or whether they
follow lexical visibility rules.

I'll follow up again tomorrow.

Gord.




Mark Hartoog wrote:
> I tried to send this yesterday, but I never saw it appear on the list.
> 
> I am not completely clear on the search order rules for finding
> functions and tasks. Consider this case:
> 
> function int fn();
>   return 0;
> endfunction
> 
> module m();
> int x;
> initial x = fn(); // which fn() does this bind to?
> 
> function int fn()
>   return 1;
> endfunction
> 
> endmodule
> 
> I think in this case the fn() call in the initial block binds to the
> local definition in the module 'm', not to the function in $unit, but I
> do not think this is clearly spelled out in the LRM. Do other people
> agree with this?
> 
> What about this case:
> 
> package p;
> function int fn();
>   return 0;
> endfunction
> endpackage
> 
> module m();
> import p::*;
> int x;
> initial x = fn(); // which fn() does this bind to?
> 
> function int fn()
>   return 1;
> endfunction
> endmodule
> 
> A literal reading of section 19.2.2 would lead me to believe that this
> is an error, since the fn() call in the initial block cause the fn() to
> be imported from the package, making the subsequent local definition
> illegal. Is this what was intended?
> 
> package p;
> function int fn();
>   return 0;
> endfunction
> endpackage
> 
> import p::*;
> 
> module m();
> int x;
> initial x = fn(); // which fn() does this bind to?
> 
> function int fn()
>   return 1;
> endfunction
> endmodule
> 
> What about this case? Is this legal? Does the call to fn() in the
> initial block cause fn() to be imported into the $unit scope? 
> Does that make the subsequent definition of fn() in module 'm' illegal?
> In this case it seems to me that the fn() call in the initial block
> should go to the local fn() in the module 'm' and should not cause 'fn'
> to be imported into $unit.
> 
> What is the search order for looking for functions/tasks? I was thinking
> 
> module -> module imports -> $unit -> $unit imports
> 
> But for backwards compatibility you can not do this while parsing, but
> only after the module is complete, and I guess after $unit is complete.
> 
> package p;
> function int fn();
>   return 0;
> endfunction
> endpackage
> 
> import p::*;
> 
> module m();
> int x;
> initial x = fn(); // which fn() does this bind to?
> endmodule
> 
> function int fn()
>   return 1;
> endfunction
> 
> Is this an error? or does the fn() call bind to the fn() in $unit?
> 
> Mark Hartoog
> 700 E. Middlefield Road
> Mountain View, CA 94043
> 650 584-5404
> markh@synopsys.com 
> 
> 

-- 
--------------------------------------------------------------------
Gordon Vreugdenhil                                503-685-0808
Model Technology (Mentor Graphics)                gordonv@model.com
Received on Thu Aug 25 17:08:32 2005

This archive was generated by hypermail 2.1.8 : Thu Aug 25 2005 - 17:11:32 PDT