1
\$\begingroup\$

I have a very simple interface definition in a package in SystemVerilog:

1 package general_pack;
2 interface diff_i_t ( input p,
3 input n );
4 endinterface
5 endpackage

I added the file into a Vivado project, and then the editor shows an error at line 2:

Error: Syntax error near diff_i_t.

What's wrong with it? Is this the right way to define interfaces in a package?

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked Mar 5, 2024 at 16:43
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

It is illegal to declare an interface inside a package. You need to declare it outside the package:

interface diff_i_t ( input p,
 input n );
endinterface
package general_pack;
endpackage

Refer to IEEE Std 1800-2017, section 26.2 Package declarations:

SystemVerilog packages provide an additional mechanism for sharing parameters, data, type, task, function, sequence, property, and checker declarations ...

Other simulators provide a more helpful error message:

Error-[USVSNM] Unsupported SystemVerilog construct
 Found 'interface' inside package before 'endpackage'. 'interface' inside 
 'package' is not allowed.

The above message is from Synopsys VCS, which is available (along with other simulators) on EDA Playground.

answered Mar 5, 2024 at 16:51
\$\endgroup\$
4
  • \$\begingroup\$ Good to know that. I thought in VHDL way that put such shared definitions inside packages. But if it's outside a package, how do I refer to it in a different file? \$\endgroup\$ Commented Mar 5, 2024 at 18:00
  • \$\begingroup\$ OK, I saw someone mentioned an interface should be treated like a module and no need to include the definition like a package, just "instantiate" it. \$\endgroup\$ Commented Mar 5, 2024 at 18:12
  • \$\begingroup\$ @fiedel: Yes, in that respect, think of an interface more like a module. \$\endgroup\$ Commented Mar 5, 2024 at 18:13
  • \$\begingroup\$ Got it. Thank you. @toolic \$\endgroup\$ Commented Mar 5, 2024 at 18:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.