Error-[IUCD] Illegal use of compiler directive Illegal use of compiler directive: `include is illegal in this context. "macros_one.sv", 28 Source info: $display(`include(clock));
** Warning: macros2.sv(7): (vlog-2263) Redefinition of macro: 'debug' (previously defined near macros2.sv(3)) .
Parsing design file 'macros4.sv'
Warning-[TMR] Text macro redefined macros2.sv, 7 Text macro (debug) is redefined. The last definition will override previous ones. In macros2.sv, 3, it was defined as $display("%s, %0d: %s", `__FILE__, `__LINE__, msg)
/* Example 2 */ `define test1(A) $display(`"1 Color A`") `define test2(A=blue, B, C=green) $display(`"3 Colors A, B, C`") `define test3(A=str1, B, C=green) \ if (A == "orange")$display("Oooo .. I received an Orange!"); \ else$display(`"3 Colors %s, B, C`", A);
// No args provided even without default value `test1(); `test2(,,);
// Passing some args `test1(black); `test2(,pink,);
// Passing a var (str1, str2) as an arg `test3(str1,mistygreen,babypink); `test3(str2,mistygreen,babypink);
`debug1(program-block, "this is a debug message"); `debug2("program-block", "this is a debug message");
/* The following will result in an Error * `test2(); // no args provided * `test2(,); // insufficient args provided * * // arg1 is used as a var in an if statement, * // This will compile fail because the macro * // will expand to *if ( == "orange")* * `test(, blue, pink) */ end endprogram: test
运行结果
1 2 3 4 5 6 7 8
# 1 Color # 3 Colors blue, , green # 1 Color black # 3 Colors blue, pink, green # 3 Colors gray, mistygreen, babypink # Oooo .. I received an Orange! # program-block >> macros2.sv, 31: this is a debug message # program-block >> macros2.sv, 32: this is a debug message
//> src/macros/uvm_tlm_defines.svh // Check out the MacroStyleGuide in use here // [ 1.] If the Macro defines a function or a task, // use UPPERCASE for macro name and lower case for args `define UVM_BLOCKING_TRANSPORT_IMP_SFX(SFX, imp, REQ, RSP, req_arg, rsp_arg) \ task transport( input REQ req_arg, output RSP rsp_arg); \ imp.transport``SFX(req_arg, rsp_arg); \ endtask
// [ 2a.] For everything else (i.e., if Macro defines // a snippet of code, class or a convenience definition), // use lowercase with UPPERCASE args `define uvm_analysis_imp_decl(SFX) \ class uvm_analysis_imp``SFX #(type T=int, type IMP=int) \ extends uvm_port_base #(uvm_tlm_if_base #(T,T)); \ `UVM_IMP_COMMON(`UVM_TLM_ANALYSIS_MASK,`"uvm_analysis_imp``SFX`",IMP) \ functionvoid write( input T t); \ m_imp.write``SFX( t); \ endfunction \ \ endclass
// [ 2b.] Examples of lowercase+uppercase with snippets `define uvm_error(ID, MSG) \ begin \ if (uvm_report_enabled(UVM_NONE,UVM_ERROR,ID)) \ uvm_report_error (ID, MSG, UVM_NONE, `uvm_file, `uvm_line, "", 1); \ end // [ 3.] Separate words with underscores, don't use camelCase `define uvm_non_blocking_transport_imp_decl(SFX) \ `uvm_nonblocking_transport_imp_decl(SFX)