Hi folks,
I am trying to get better understanding on text macro(`ifdef) within and outside packages. Can someone share some insight on that?
Why compiling pkg_ac.sv, a.sv is not compiled? (The source codes append in the end)
According to LRM2012 P18, “The text macro name space is global within the compilation unit.”
Here my understanding are:
- pkg_ab.sv is a compilation unit which contains a.sv & b.sv & pkg_ab.sv(itself)
- pkg_ac.sv is another compilation unit which contains a.sv & c.sv & pkg_ac.sv(itself)
- `define A_SV is global within pkg_ab.sv but not outside pkg_ab.sv
Now the compilation log shows Error when compiling pkg_ac.sv due to class identifier - a is not visible, so why is a.sv not compiled in pkg_ac.sv? I wonder why does define A_SV inside pkg_ab.sv go out of the scope then make pkg_ac.sv see
define A_SV.
The source code are distributed in 6 files:
a.sv
`ifndef A_SV
`define A_SV
class a;
endclass // a
`endif
b.sv
`ifndef B_SV
`define B_SV
class b extends a;
endclass // b
`endif
c.sv
`ifndef C_SV
`define C_SV
class c extends a;
endclass // c
`endif
pkg_ab.sv
`ifndef PKG_AB_SV
`define PKG_AB_SV
package pkg_ab;
`include "a.sv"
`include "b.sv"
endpackage // pkg_ab
`endif
pkg_ac.sv
`ifndef PKG_AC_SV
`define PKG_AC_SV
package pkg_ac;
`include "a.sv"
`include "c.sv"
endpackage // pkg_ac
`endif
tb.sv
`include "pkg_ab.sv"
`include "pkg_ac.sv"
module tb;
a a0;
b b0;
c c0;
endmodule