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

From: Mark Hartoog <Mark.Hartoog_at_.....>
Date: Thu Aug 25 2005 - 10:51:03 PDT
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 
Received on Thu Aug 25 10:51:09 2005

This archive was generated by hypermail 2.1.8 : Thu Aug 25 2005 - 10:52:57 PDT