Global parameters???

U

unfrostedpoptart

Guest
Related to my questions about parameters / include files for module port headers, I just ran into something that I don't think should work, but does - which is good if confusing:

I have a structure defined in an include file that I use as a type of port in my module. Therefore, I have to include the header file before the module keyword. However, this structure uses parameters. So, I have to include my parameter header file at the beginning of the structure header file. This means the parameters aren't defined inside a module. I didn't think that was legal.

What's going on here? Is this new in System Verilog? Is there some back-referencing going on? I have the 1800-2009 LRM, but don't know where to look for this. As an aside - you'd think for almost $300, the LRM PDF would have a PDF table of contents!!!

David
 
On Mon, 25 Jul 2011 19:06:28 -0700 (PDT), unfrostedpoptart
<david@therogoffs.com> wrote:

I have a structure defined in an include file that I use as a
type of port in my module. Therefore, I have to include the
header file before the module keyword. However, this structure
uses parameters. So, I have to include my parameter header file
at the beginning of the structure header file. This means the
parameters aren't defined inside a module.
Nor is your struct type, presumably???

I didn't think that was legal.
It is now, but not without some care.

Is this new in System Verilog?
Yes, but it's been around since the earliest days of SV.
It underwent some pretty serious rationalization at
(I think) SystemVerilog 3.1, but it's been well-defined
and usable for ages now.

Is there some back-referencing going on? I have the
1800-2009 LRM, but don't know where to look for this.
3.12.1 (Compilation units) tells all. However, there
are plenty of good methodology reasons for NOT putting
declarations in the $unit compilation-unit scope (i.e.
in the file but outside any module). Instead, consider
putting the declarations in a package and then taking
the rather small hit of explicitly referencing the
package in your port list:

package misc;
parameter N = 3;
typedef struct { int x; int y; } int_pair;
endpackage

And then much later, maybe even in another file:

module uses_pairs (input misc::int_pair inp[misc::N]);
import misc::*; // for later use in the module

This approach gives much better control over name
visibility and allows you to localize stuff better.
Putting the declaration into $unit, outside any module,
makes it visible to everything that appears later in
the compilation unit - not very well controlled.

It's kinda tedious that you need the explicit package
qualifier in your port list, because the import statement
must appear later in the module. 1800-2009 allows you to
put an import immediately after the module keyword:

module uses_pairs import misc::*;
(input int_pair inp);

see clause 26.4, Using package import in module headers.
This would be pretty useful if you have several ports
all of which use data types or parameters that are
declared in a package. However, I'm not sure what
level of tool support exists for that feature - I've
never gotten around to trying it.

As an aside - you'd think for almost $300, the LRM PDF
would have a PDF table of contents!!!
Are you sure about that? I get hyperlinks in the TOC text,
and the usual hierarchical section bookmarks - no index,
I grant you, but full-text search is quick. Where's
the problem?
--
Jonathan Bromley
 

Welcome to EDABoard.com

Sponsor

Back
Top