System Verilog 中 ' line compiler 指令的工作

working of `line compiler directive in system verilog

提问人:aryan tiwari 提问时间:4/12/2022 更新时间:4/12/2022 访问量:289

问:

有人可以解释一下系统中“行编译器指令”的工作原理吗 verilog 试图从 LRM 读取它的工作原理,但无法理解它

编译器构造 Verilog System-Verilog using 指令

评论


答:

1赞 dave_59 4/12/2022 #1

'line 指令的工作方式与 C 等其他语言相同(#line 是什么意思?

主要用途是从另一种语言生成 SystemVerilog 代码的工具,以便生成的 SystemVerilog 代码生成的任何消息都可以指向原始代码,而不是翻译后的代码。这甚至适用于扩展 SystemVerilog 宏的工具,这是一个很好的例子。假设我有这个 5 行文件 top.sv

module top;
`include "defines.h"
   `M(A)
   `M(B)
  initial x.x=0; // elaboration error
endmodule

而这个 5 行文件 defines.h

int i1;
`define M(arg) \
   int L1_``arg; \
   int L2_``arg;
int i2;

SystemVerilog 宏预处理器的输出是这个 26 行文件 out.sv

`begin_keywords "1800-2017"

`line 1 "top.sv" 0
module top;
  
`line 1 "defines.h" 1
int i1;
  


`line 4 "defines.h" 0

int i2;

`line 6 "defines.h" 0

`line 2 "top.sv" 2

        int L1_A;     int L2_A;
        int L1_B;     int L2_B;
  initial x.x=0;
endmodule
   

`end_keywords

如果我尝试编译并运行此 out.sv 文件,则会在 top.v 的第 5 行报告错误,而不是 out.sv 的第 22 行。