How to manage different class in different file

I am working on example project (edaplayground)

It is divided into two different files (DUT & testbench)

testbench has several classes in one file

When I compile two files, no problem exist

However, when I divided testbench into several files (based on class name), then I compile with “filelist.f” such as
############################

filelist.f

############################
reg_ctrl.sv #<-- DUT
reg_item.sv
driver.sv
monitor.sv
scoreboard.sv
environment.sv
interface.sv
test.sv
tb_top.sv
############################

However, I got compile error as below

#################################################################################################################

QuestaSim-64 vlog 10.5b Compiler 2016.05 May 21 2016

Start time: 12:52:10 on Aug 18,2020

vlog -reportprogress 300 -incr “+cover=bcestf” -f filelist.f

– Skipping module reg_ctrl

– Compiling package reg_item_sv_unit

** Error: (vlog-13069) driver.h(6): near “driver”: syntax error, unexpected IDENTIFIER.

** Error: driver.h(6): (vlog-13205) Syntax error found in the scope following ‘class’. Is there a missing ‘::’?

** Error: (vlog-13069) monitor.h(6): near “monitor”: syntax error, unexpected IDENTIFIER.

** Error: monitor.h(6): (vlog-13205) Syntax error found in the scope following ‘class’. Is there a missing ‘::’?

** Error: (vlog-13069) scoreboard.h(6): near “scoreboard”: syntax error, unexpected IDENTIFIER.

** Error: scoreboard.h(6): (vlog-13205) Syntax error found in the scope following ‘class’. Is there a missing ‘::’?

** Error: (vlog-13069) environment.h(17): near “env”: syntax error, unexpected IDENTIFIER.

** Error: environment.h(17): (vlog-13205) Syntax error found in the scope following ‘class’. Is there a missing ‘::’?

** Warning: environment.h(17): (vlog-2283) Extra semicolon in $unit (global) scope.

** Warning: scoreboard.h(6): (vlog-2283) Extra semicolon in $unit (global) scope.

** Warning: monitor.h(6): (vlog-2283) Extra semicolon in $unit (global) scope.

** Warning: driver.h(6): (vlog-2283) Extra semicolon in $unit (global) scope.

** Error: (vlog-13069) test.h(3): near “test”: syntax error, unexpected IDENTIFIER.

** Error: test.h(3): (vlog-13205) Syntax error found in the scope following ‘class’. Is there a missing ‘::’?

** Error: (vlog-13069) tb_top.sv(21): near “;”: syntax error, unexpected ‘;’, expecting ‘(’.

** Error: tb_top.sv(28): (vlog-2730) Undefined variable: ‘t0’.

** Warning: test.h(3): (vlog-2283) Extra semicolon in $unit (global) scope.

End time: 12:52:10 on Aug 18,2020, Elapsed time: 0:00:00

Errors: 12, Warnings: 5

** Error: C:/questasim64_10.5b/win64/vlog failed.

Error in macro ./Compile.do line 1

C:/questasim64_10.5b/win64/vlog failed.

while executing

“vlog -incr +cover=bcestf -f filelist.f”

#################################################################################################################

Did I miss something?

Can you tell me how to divide classes into different files?

Thank you

In reply to tw011:

It’s best to put your classes in a package and `include them instead of putting them on the command line
my_pkg.sv

package my_pkg;
`include "reg_item.sv"
`include "driver.sv"
`include "monitor.sv"
`include "scoreboard.sv"
`include "environment.SystemVerilog"
endpackage

And then replace these files with my_pkg.sv in your filelist. Also see http://go.mentor.com/package-import-versus-include

In reply to dave_59:

Dear Dave

I have added `include “xxxx.sv” into my_pkg.sv as you mentioned

First question is

Based on your information, Only Class definition should be in package. Am I on correct approach? (interface.sv should be in tb_top ?)

Second question is

I have modified my_pkg.sv as below
#########################
package my_pkg;
include "reg_item.sv" include “driver.sv”
include "monitor.sv" include “scoreboard.sv”
include "test.sv" include “environment.sv”
endpackage
#########################

However, I still got error as below
#####################################################################################

vlog -reportprogress 300 -incr “+cover=bcestf” -f filelist.f

– Skipping package my_pkg

– Skipping interface reg_if

** Error: (vlog-13069) tb_top.sv(25): near “;”: syntax error, unexpected ‘;’, expecting ‘(’.

** Error: tb_top.sv(32): (vlog-2730) Undefined variable: ‘t0’.

– Compiling module reg_ctrl

End time: 13:08:17 on Aug 19,2020, Elapsed time: 0:00:00

Errors: 2, Warnings: 0

** Error: C:/questasim64_10.5b/win64/vlog failed.

Error in macro ./Compile.do line 1

C:/questasim64_10.5b/win64/vlog failed.

while executing

“vlog -incr +cover=bcestf -f filelist.f”

#####################################################################################

Did I miss something? or Do I have to include or import “test class” on tb_top separately?

I hope you can comment on my mistake.

Thank you

In reply to tw011:

while including the files in the package we have too follow the order

  1. transaction class
  2. all the transactors in any order(driver, monitor, generator , SB etc)
  3. environment
  4. test

And the package has to be imported in the top module.

Regards,
Shanthi V A