1

I am creating a simple UVM tb these days, and I meet an issue with interface usage. Here is my code in the /my_proj/tb_uvm/intf/my_if.svh file: (interface definition)

interface my_if (
    input iCLK,
    input iRSTb,
    inout data
);
clocking monitor_cb @(posedge iCLK);
    input iRSTb;
    input data;
endclocking
modport monitor_mp(
    clocking monitor_cb
); 
endinterface : my_if

and I need to instance this interface in the /my_proj/tb_uvm/agent/my_driver.svh file :

class my_driver extends uvm_driver;
    `uvm_component_utils(my_driver)
    virtual my_if m_vif;
    ...
endclass

I tried to define a package file (named my_agt_pkg.sv) under /my_proj/tb_uvm/agent/ because there are several driver/monitor files in this directory including the my_driver.svh I mentioned above.

package my_agt_pkg;
    import uvm_pkg::*;

    `include "my_driver.svh"
    `include "../intf/my_if.svh"
     ....
endpackage

but I failed to compile because of below error. Could anyone give me help on this issue?

Found 'interface' inside package before 'endpackage'. 'interface' inside 'package' is not allowed.

1 Answer 1

3

The error message means what is says: you are not allowed to declare an interface inside a package.

A virtual interface is a peculiar concept. It behaves like a class variable, but an interface gets defined and instantiated like a module.

Just move your interface declaration outside the package

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

3 Comments

Hi Dave, If I want to instance this interface in the current sv file and this sv file is included in the package, how can I handle it ? ( I mean how can I declare the interface outside the package ?)
I tried to exclude this my_if.svh in my_agt_pkg.sv file. and retry to compile but failed with below error: Error-[SV-UIOT] Undefined interface or type ../agent/my_driver.svh, 10 my_if, "m_vif" The definition for the forward-referenced interface 'my_if' is missing or 'my_if' is the name of an undefined user type.
oh, It works if I move the include statement before the package definition. now this error is disappeared although next error is popped up. I will take a further look on my side.. anyway, thank you very much !

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.