Friday, July 15, 2011

Package export declaration

In the package, you can do more than import things from other packages; you can export something in the package declaration NOW. It might be useful, but somethings it might be dangerous or ambiguous.
The detail syntax of package import and export declarations, please refer to SystemVerilog IEEE 1800-2009 LRM. In the LRM, they already told you how to use export and how it is useful in your design.

It could be dangerous or ambiguous in the following ways

  1. If there is only export *::* or export pkg::* in your package declaration, you cannot always know what are really exported in current package. You have to trace back to the package which the current package imports, and read the statements in current package. Now you should make sure the data type, interface, task/function, blah blah blah are the correct one to be imported. It is always the simple example in the LRM that you can figure out what are really exported. But in fact, the real design contains a great deal of types, task/functions, properties... you cannot really really figure out everything by yourself only.
  2. Only the first used/referenced identifier is going to be exported. Others will not be exported without any information and warnings. That's really odd. Because that you have to figure what are exported by yourself. Tools won't give you any hints or information. It means every time you modified the package, you have to trace its reference to make sure what are going to be exported correctly.
  3. Package also provides another good practice usage such as namespace. Many identifiers can be categorized by their purpose or type. But you can break the rule by using package export declaration. It always true that you have to make sure what you really want to do when you write "export *::*"  
  4. You may do really know you have to export *::* in the current package. However, there are many people co-worked and maintained the design concurrently. They all have to know there is a small tiny statement export *::* somewhere in the package. All they wrote can be export outside the package, and even worse those identifiers could continue to be exported by following packages.
  5. The one side-effect of export *::* is not only all identifiers in current package will be exported, but something had been imported from other packages.
  6. Export things into other namespace will introduce name conflicts. It is OK for tools because they do know the rule of package import/export. However, human are always confused easily.
Summary:
  1. Specifically export things one by one
  2. Avoid using export *::* or export pkg::* unless you really know what you are doing
  3. Keep packages organized. Just using import pkg::* or pkg::item in your design.
  4. Make sure the package export declarations are maintained by architect, senior member, or owner.

No comments:

Post a Comment