System Verilog supports both single file and multiple file compilation through use of Compilation units.
A compilation unit is a collection of one or more SV source files compiled together. Every compilation unit is associated with single library. The compilation unit scope is a local to global compilation unit. The scope has all the declarations that lie outside of any other design scope. Generally functions, tasks, parameter, nets, variables, and user defined types declared outside the module, interface, package or program come under the compilation unit scope.
For example, consider the following design.
In Tcl mode
read_verilog -lib lib1 {test1.sv }
read_verilog -lib lib2 {test2.sv }
read_verilog test3.sv
Or IDE
In the previous case, if test1.sv has declarations in the compilation unit scope such as params, typedefs, and so on. Following is an example.
Parameter P1 =2; // parameter declared out of module scope
module test1 (<port list>)
...
...
endmodule
and read the files as mentioned previously. The compilation unit's scope starts when the tool reads file test1.sv under lib1. Reading test2.sv under lib2 is illegal because the compilation unit must be associated with a single library. You can address this in the following ways:
In Tcl mode, putting all the files in a single library.
read_verilog -lib lib1 {test1.sv}
read_verilog -lib lib1 {test2.sv}
read_verilog test3.sv
or not declaring libraries at all
read_verilog {test1.sv }
read_verilog {test2.sv}
read_verilog test3.sv
or (single file compilation unit mode)
read_verilog -lib lib1 {test1.sv}
read_verilog -lib lib2 {test2.sv}
read_verilog test3.sv
synth_design -top <top_name> -sfcu