简体   繁体   English

如何将调试消息传递给 SystemVerilog 中的宏

[英]How to pass debug messages to a macro in SystemVerilog

I'm attempting the following SystemVerilog:我正在尝试以下 SystemVerilog:

`define DEBUG (ARG) \
`ifdef DEBUG_ON \
  $display ARG;
`endif

module my_mod;
logic a;
logic [1:0] b;

assign a = 1'b0;
assign b = 2'b01;

`DEBUG(("a=%x, b=%b", a, b))
endmodule

VCS gives me the following compile error: VCS 给了我以下编译错误:

Error-[SE] Syntax error
  Following verilog source has syntax error :
  "/media/psf/Home/projects/dep2/hw/rtl/dep_dc/dep_dc_cs.sv", 254 (expanding 
  macro): token is '('
        `DEBUG(("a=%x, b=%b", a, b))
              ^

#0, DEBUG : "<my_file>":21
full expansion of macro (DEBUG), error at line 1
=>(ARG) 
  `ifdef DEP_DEBUG_ON
  ...

According to this answer: How to emulate $display using Verilog Macros?根据这个答案: How to emulate $display using Verilog Macros?

This seems like the correct syntax to me.这对我来说似乎是正确的语法。 Can someone spot anything wrong?有人能发现什么不对吗?

So I found it apparently, the compiler doesn't like spaces between the macro definition and arguments:所以我很明显地发现,编译器不喜欢宏定义和 arguments 之间的空格:

`define DEBUG(ARG) \
`ifdef DEBUG_ON \
  $display ARG;
`endif

Works.作品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM