Error while Compiling the UVM Testbench

Hi Team,
Here I am trying to compile and simulate the UVM testbench for multiplication operation using RISC-V instructions (R-TYPE, I-TYPE). I am getting error for all the testbench components, and all the errors are in the same line for all the files as follows.

** Error: (vlog-13069) D:/RISCV_UVM - Copy/log/agent.sv (2): near “uvm_agent”: syntax error, unexpected IDENTIFIER.
** Error: D:/RISCV_UVM - Copy/log/agent.sv (2): Error in class extension specification.

Here I am attaching the uvm_agent code


(2) class agent extends uvm_agent;
`uvm_component_utils(agent)

sequencer system_sqncr;
driver system_driv;
monitor system_mon;

function new(string name, uvm_component parent);
super.new(name,parent);
endfunction: new

  //////////////   BUILD PHASE   //////////////////////////////
function void build_phase(uvm_phase phase);
super.build_phase(phase);
      //ACTIVE 
  system_sqncr=sequencer::type_id::create("system_sqncr",this);
  system_driv=driver::type_id::create("system_driv",this);
  system_mon=monitor::type_id::create("system_mon",this);
endfunction:build_phase

//////////////   CONNECT PHASE   //////////////////////////////

function void connect_phase(uvm_phase phase);
system_driv.seq_item_port.connect(system_sqncr.seq_item_export);
endfunction: connect_phase

endclass: agent

when I try to load the project for compilation in questasim it displays the below errors

//

Loading project uvm_ALL

Compile of agent.sv failed with 2 errors.

Compile of driver.sv failed with 2 errors.

Compile of environment.sv failed with 2 errors.

Compile of interface.sv was successful.

Compile of monitor.sv failed with 2 errors.

Compile of picorv32.sv was successful.

Compile of scoreboard.sv failed with 2 errors.

Compile of sequence.sv failed with 2 errors.

Compile of sequence_items.sv failed with 2 errors.

Compile of sequencer.sv failed with 2 errors.

Compile of system_dut.sv was successful.

Compile of system_tb.v was successful.

Compile of test.sv failed with 2 errors.

Compile of testbench.sv failed with 2 errors.

Compile of top.svh was successful.

15 compiles, 10 failed with 20 errors.

In reply to Divya_LTTS:

This error messages typically arises when you do not import the nase class library.
Please add these 2 lines at the top of your code:

import uvm_pkg::*;
`include "uvm_macros.svh"

And you should review how you have packaged your code.
Put the agent cod and below in a seperate package.

In reply to chr_sue:

Hi chr_sue,
As you mentioned in the reply, I had added those packages in the agent code, but still errors for this agent code have been increased. here I have attached the error list kindly help me resolve these errors, and for the other files it is showing the same errors.


import uvm_pkg::*;
`include "uvm_macros.svh"

class agent extends uvm_agent;
  `uvm_component_utils(agent)
  
  sequencer system_sqncr;
  driver system_driv;
  monitor system_mon;
  
  function new(string name, uvm_component parent);
    super.new(name,parent);
  endfunction: new
  
      //////////////   BUILD PHASE   //////////////////////////////
    function void build_phase(uvm_phase phase);
    super.build_phase(phase);
          //ACTIVE 
      system_sqncr=sequencer::type_id::create("system_sqncr",this);
      system_driv=driver::type_id::create("system_driv",this);
      system_mon=monitor::type_id::create("system_mon",this);
    endfunction:build_phase
  
    //////////////   CONNECT PHASE   //////////////////////////////
  function void connect_phase(uvm_phase phase);
    system_driv.seq_item_port.connect(system_sqncr.seq_item_export);
  endfunction: connect_phase
  
endclass: agent

ERROR for Agent:
** Error: D:/uvm_ALL/log/agent.sv(7): Invalid type ‘sequencer’. Please check the type of the variable ‘system_sqncr’.
** Error: D:/uvm_ALL/log/agent.sv(8): Invalid type ‘driver’. Please check the type of the variable ‘system_driv’.
** Error: D:/uvm_ALL/log/agent.sv(9): Invalid type ‘monitor’. Please check the type of the variable ‘system_mon’.
** Error: D:/uvm_ALL/log/agent.sv(19): (vlog-2730) Undefined variable: ‘system_sqncr’.
** Error: D:/uvm_ALL/log/agent.sv(19): (vlog-2164) Class or package ‘sequencer’ not found.
** Error: D:/uvm_ALL/log/agent.sv(19): (vlog-2730) Undefined variable: ‘sequencer’.
** Error: (vlog-13069) D:/uvm_ALL/log/agent.sv(19): near “::”: syntax error, unexpected ::, expecting ‘;’.
** Error: D:/uvm_ALL/log/agent.sv(20): (vlog-2730) Undefined variable: ‘system_driv’.
** Error: D:/uvm_ALL/log/agent.sv(20): (vlog-2164) Class or package ‘driver’ not found.
** Error: D:/uvm_ALL/log/agent.sv(20): (vlog-2730) Undefined variable: ‘driver’.
** Error: (vlog-13069) D:/uvm_ALL/log/agent.sv(20): near “::”: syntax error, unexpected ::, expecting ‘;’.
** Error: D:/uvm_ALL/log/agent.sv(21): (vlog-2730) Undefined variable: ‘system_mon’.
** Error: D:/uvm_ALL/log/agent.sv(21): (vlog-2164) Class or package ‘monitor’ not found.
** Error: D:/uvm_ALL/log/agent.sv(21): (vlog-2730) Undefined variable: ‘monitor’.
** Error: (vlog-13069) D:/uvm_ALL/log/agent.sv(21): near “::”: syntax error, unexpected ::, expecting ‘;’.

when I try to do compilation in questasim it displays the below errors

Compile of agent.sv failed with 15 errors.

Compile of driver.sv failed with 2 errors.

Compile of environment.sv failed with 2 errors.

Compile of interface.sv was successful.

Compile of monitor.sv failed with 2 errors.

Compile of picorv32.sv was successful.

Compile of scoreboard.sv failed with 2 errors.

Compile of sequence.sv failed with 2 errors.

Compile of sequence_items.sv was successful.

Compile of sequencer.sv failed with 2 errors.

Compile of system_dut.sv was successful.

Compile of system_tb.v was successful.

Compile of test.sv failed with 2 errors.

Compile of testbench.sv was successful.

Compile of top.svh was successful.

15 compiles, 8 failed with 29 errors.

In reply to Divya_LTTS:

These compilation errors are caused by a wrong compilation order. You need to compilethe sequencer driver etc befor they are used in the agent.
Best is to pack all these files in the right order in a package and then compile this package afterwards.

In reply to chr_sue:
1.Can you guide us what is a correct compilation order?
2.when we compile in questasim it automatically displays the order of compilation.
3. can you suggest how to pack all these files in the right order in a package for compilation.
4.Do we need to compile only the package file?

In reply to Divya_LTTS:

To give you a package file:
apb_pkg.sv looks like this

package apg_pkg;
  // Imports
  import uvm_pkg::*;
  `include "uvm_macros.svh"

  // UVC includes
  `include "apb_seq_item.sv"
  `include "apb_config.sv"
  `include "apb_driver.sv"
  `include "apb_monitor.sv"
  `include "apb_sequencer.sv"
  `include "apb_coverage.sv"
  `include "apb_agent.sv"
  `include "apb_env.sv"
  `include "apb_seq_lib.sv"
endpackage
 `include "apb_if.sv"

The Questa compilation command is
vlog apb_pkg.sv

In reply to Divya_LTTS:

You need to define the class name before you use it. The class agent tries to declare a handle of type sequencer, so you need to compile the sequencer class before agent.

package divya_pkg;
import umv_pkg::*;
`include "uvm_macros.svh"

class sequencer ...;
endclass

class agent extends uvm_agent;
  ...
  sequencer system_sqncr;

The alternative is to use typedef, so you can define classes in any order. The typedef still needs to come before the first use of the name.

package divya_pkg;
import umv_pkg::*;
`include "uvm_macros.svh"

typedef class sequencer;

class agent extends uvm_agent;
  ...
  sequencer system_sqncr;
endclass

class sequencer ...;
endclass

Here is a complete example.

Better yet, put each class in a separate file and include them in the package.

Hi chr_sue,

As per your suggestion we have done but still we are getting errors, for other files there are same errors but for the interface and package the error is different. Here we have attached agent, package and interface code along with the Errors.

Let us know what we are doing is right or wrong and this should be done in questasim if anyone has done any UVM example using questasim kindly share the example and procedure to do it in the questasim.

Agent Code:


package apb_pkg;
import uvm_pkg::*; //import umv_pkg::*;
`include "uvm_macros.svh"
 
typedef class agent;
typedef class sequencer;
typedef class driver;
typedef class monitor;

class agent extends uvm_agent;
  `uvm_component_utils(agent)
  
  sequencer system_sqncr;
  driver system_driv;
  monitor system_mon;
  
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction: new
  
      //////////////   BUILD PHASE   //////////////////////////////
    function void build_phase(uvm_phase phase);
    super.build_phase(phase);
          //ACTIVE 
      system_sqncr=sequencer::type_id::create("system_sqncr",this);
      system_driv=driver::type_id::create("system_driv",this);
      system_mon=monitor::type_id::create("system_mon",this);
    endfunction: build_phase
  
    //////////////   CONNECT PHASE   //////////////////////////////
  function void connect_phase(uvm_phase phase);
    system_driv.seq_item_port.connect(system_sqncr.seq_item_export);
  endfunction: connect_phase
  
endclass: agent

Package File:


package apb_pkg;

  // Imports
  
  import uvm_pkg::*;

  `include "uvm_macros.svh"
 
  // UVC includes
  
  `include "apb_seq_item.sv"
  `include "apb_sequence.sv"
  `include "apb_sequencer.sv"
  `include "apb_driver.sv"
  `include "apb_monitor.sv"
  `include "apb_agent.sv"
  `include "apb_scoreboard.sv"
  `include "apb_environment.sv"
  `include "apb_test.sv"
  `include "apb_Testbench_Top.sv"


 `include "apb_interface.sv"
 
 endpackage

Interface File:


package apb_pkg;
import uvm_pkg::*;   //import umv_pkg::*; 
`include "uvm_macros.svh"

typedef class interface;

interface system_inf( input logic clk, resetn);

  //logic clk;
  //logic resetn; 
  logic pcpi_valid;
	logic [31:0]pcpi_insn;
	logic [31:0]pcpi_rs1;
	logic [31:0]pcpi_rs2;
	logic pcpi_wr;
	logic [31:0]pcpi_rd;
	logic pcpi_wait;
	logic pcpi_ready;
        logic trap;
  
  clocking driver_cb @(posedge clk);
    default input #1 output #1;
  //output  clk; 
  //output  resetn; 
  output pcpi_valid;
  output pcpi_insn;
  output pcpi_rs1;
  output pcpi_rs2;
  output pcpi_wr;
  output pcpi_rd;
  output pcpi_wait;
  output pcpi_ready;
  input trap;
  endclocking
  
  clocking monitor_cb @(posedge clk);
    default input #1 output #1;
  input clk;
  input resetn; 
  input pcpi_valid;
  input pcpi_insn;
  input pcpi_rs1;
  input pcpi_rs2;
  input pcpi_wr;
  input pcpi_rd;
  input pcpi_wait;
  input pcpi_ready;
  
  input trap;
  endclocking 
  
  modport DRIVER (clocking driver_cb, input clk,resetn);
    modport MONITOR (clocking monitor_cb, input clk,resetn);
      
      endinterface
      

Error for Agent file:
vlog -work work -vopt -sv -stats=none {D:\UVM_Package\apb_agent.sv}
QuestaSim-64 vlog 2021.4 Compiler 2021.10 Oct 13 2021
– Compiling package apb_pkg
– Importing package mtiUvm.uvm_pkg (uvm-1.1d Built-in)
** Note: (vlog-2286) D:\UVM_Package\apb_agent.sv(3): Using implicit +incdir+C:/Program Files (x86)/questa_sim-win64-2021.4/uvm-1.1d/…/verilog_src/uvm-1.1d/src from import uvm_pkg
** Error: (vlog-13069) D:\UVM_Package\apb_agent.sv(36): near “EOF”: syntax error, unexpected end of source code, expecting class.

Error for Package file:
vlog -work work -vopt -sv -stats=none D:/UVM_Package/apb_pkg.sv
QuestaSim-64 vlog 2021.4 Compiler 2021.10 Oct 13 2021
– Compiling package apb_pkg
– Importing package mtiUvm.uvm_pkg (uvm-1.1d Built-in)
** Note: (vlog-2286) D:/UVM_Package/apb_pkg.sv(7): Using implicit +incdir+C:/Program Files (x86)/questa_sim-win64-2021.4/uvm-1.1d/…/verilog_src/uvm-1.1d/src from import uvm_pkg
** Error: (vlog-13069) ** while parsing file included at D:/UVM_Package/apb_pkg.sv(11)
** at apb_seq_item.sv(1): near “package”: syntax error, unexpected “SystemVerilog keyword ‘package’”, expecting class.

Error for Interface file:

vlog -work work -vopt -sv -stats=none {D:\UVM_Package\apb_interface.sv}
QuestaSim-64 vlog 2021.4 Compiler 2021.10 Oct 13 2021
– Compiling package apb_pkg
– Importing package mtiUvm.uvm_pkg (uvm-1.1d Built-in)
** Note: (vlog-2286) D:\UVM_Package\apb_interface.sv(4): Using implicit +incdir+C:/Program Files (x86)/questa_sim-win64-2021.4/uvm-1.1d/…/verilog_src/uvm-1.1d/src from import uvm_pkg
** Error: (vlog-13069) D:\UVM_Package\apb_interface.sv(6): near “interface”: syntax error, unexpected “SystemVerilog keyword ‘interface’”, expecting IDENTIFIER or TYPE_IDENTIFIER or NETTYPE_IDENTIFIER.

In reply to Divya_LTTS:

Now you have 3 different apb_pkg files. But you can use only 1. I recommend to use this code of your apb_pkg.sv:

package apb_pkg; 
  // Imports 
  import uvm_pkg::*; 
  `include "uvm_macros.svh"
  // UVC includes
  `include "apb_seq_item.sv"
  `include "apb_sequence.sv"
  `include "apb_sequencer.sv"
  `include "apb_driver.sv"
  `include "apb_monitor.sv"
  `include "apb_agent.sv"
  `include "apb_scoreboard.sv"
  `include "apb_environment.sv"
  `include "apb_test.sv"
  `include "apb_Testbench_Top.sv"
  endpackage
 `include "apb_interface.sv"

Please note the interface is a static construct and not a class. Therefore it cannot be part of the package. But we can compile it with the package code as shown above.

In reply to chr_sue:

There are three top-level “containers” here, interfaces, packages, and modules.

Make 1 apb_pkg that includes the classes. Compile this with:
% vlog apb_pkg.sv
Keep compiling until there are no errors or warnings.

An interface is like a module. It is not a class, no typedef needed, don’t put it in a package. Put each interface in a separate file, such as apb_inf.sv Compile it stand alone until there are no errors or warnings.


interface apb_inf( input logic clk, resetn);

  //logic clk;
  //logic resetn;
  logic pcpi_valid;
  logic [31:0]pcpi_insn;
  logic [31:0]pcpi_rs1;
  logic [31:0]pcpi_rs2;
  logic pcpi_wr;
  logic [31:0]pcpi_rd;
  logic pcpi_wait;
  logic pcpi_ready;
  logic trap;

  clocking driver_cb @(posedge clk);
    default input #1 output #1;
    output pcpi_valid, pcpi_insn, pcpi_rs1, pcpi_rs2, pcpi_wr;
    output pcpi_rd, pcpi_wait, pcpi_ready;
    input trap;
  endclocking

  clocking monitor_cb @(posedge clk);
    default input #1 output #1;
    input clk, resetn,  pcpi_valid, pcpi_insn, pcpi_rs1;
    input pcpi_rs2, pcpi_wr, pcpi_rd, pcpi_wait, pcpi_ready, trap;
  endclocking

  modport DRIVER (clocking driver_cb, input clk,resetn);
  modport MONITOR (clocking monitor_cb, input clk,resetn);

endinterface

By the way, what is the purpose of this class, which has no protocol?

class agent extends uvm_agent;