2

I am having some trouble with Vivado where it is saying that there is a previously defined package and I believe it is causing failure in synthesis due to the order that these packages are being compiled. I have the file that is being reported as being defined twice added to the project as a verilog header that is labeled for global inclusion.

I have attempted to change the import statements to include statements and there is now a mix because I am unsure which is the correct way and what both of them are doing. Before I added the include statements the project was failing to synthesize because it couldn't find the package at all.

4 Answers 4

3

`include is a pre-processing directive that is just text in a file getting inserted at the point of inclusion. It is unaware of any SystemVerilog syntax. It is preprocessed and injected into the stream of characters the compiler parses as SystemVerilog syntax.

A package is a namespace containing declarations of variables, types and other SystemVerilog constructs. It is part of the SystemVerilog syntax. A package must be defined prior to referencing any of its content.

Both constructs have implications on certain "define before referencing" rules, we would have to see exactly the way you are trying to use it. It would help to get a better understanding of the operation of those two constructs.

I suggest looking at my post "SystemVerilog Coding Guidelines: Package import versus `include"

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the post @dave_59 , what do you think about includes when it comes to a purely RTL design aspect (not concerning verification). I have for years avoided the use of include precisely because of the reasons you mention above, feels like a hack to me outside of the language itself, which seems like a bad idea. I have seen many designs with interfaces included in every RTL sources. It seems wrong to me, but I wonder, is there an actual reason that it is a bad practice or is it just bad taste? I see little to no good reason to use includes in RTL design, do you agree?
@viterbi My answer applies equally to RTL or verification code. The two most common uses of including files are when they contain soley other compiler directives (mostly macro defines), or individual classes that make up a package.
hmmm I read your post in verificationhorizons but I am not sure I understand your comment. I rarely if ever have seen SV classes being used in RTL code. So, classes aside, could you perhaps give me some examples of what you would have in an include file?
`define TRUE 1'b1
lol, you made me laugh @dave_59
2

The issue seems to one of visibility.
The difference WRT visibility/access:

  • 'include causes the header file to be assessable by every other file which is compiled after the header file.
  • import provides access to some or all of the definitions in the package for only the module(s) where the package is imported.

Comments

1

`include is like copy-pasting the text of one file into another. import allows you to use the things defined in a package without having to prefix the package name in front of them.

In order to import the package must have first been defined, so depending on how your project is set up you may need `include to pull in the code that defines it.

Comments

1

`include is a pre-processing directive used to include text from other files in compilation. It is the same as #include in 'c/c++'. There are essentially two forms:

`include "file.name"
or 
`inclde <file.name>

The difference is in using of current directory for locating the file. Usually the +incdir+ or similar qualifiers tells the compiler where to look for the included files. A compiler will search for the 'file.name' in the list of provided directories. Then it will parse its code before the rest.

import is a SystemVerilog language construct and is provides an ability to import contents of a SystemVerilog package. In a sense it is similar to the c++ use statement for namespaces.

Importing means to provide an ability to use a package member without specifying the package name.

For the following package:

package pkg;
   function foo; ... endfunction
   function bar; ... endfunction
endpackage

Without import you have to use pkg::foo or pkg::bar to use its functions.

Import can have one of two forms:

import pkg::*; // import all contents of the package 'pkg' (foo and bar)
or 
import pkg::foo; // where it only imports 'foo' from the package.

In both cases you can use just foo to access the function of bar in the first case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.