SystemVerilog stringify (`") 运算符和换行符

SystemVerilog stringify (`") operator and line breaks

我在宏中使用 SystemVerilog 字符串化运算符 `",如下所示。该案例是故意设计的以显示错误:

module my_test();
    `define print(x) $fwrite(log_file, `"x`")
    `define println(x) $fwrite(log_file, `"x\n`")
    integer log_file;

    initial begin
        log_file = $fopen("result.txt", "w");
        `print(A);
        `print(B);
        `println(C);
        `println(D);
        `print(E);
        `print(F);
    end
endmodule

这给出了输出(没有尾随换行符):

ABC
`D
`EF

为什么输出中有 `,但仅来自 println
这是规范中记录的行为,还是我的模拟器 (Aldec Active-HDL) 中的错误?

这是您工具中的错误。但是,第二个 `" 不是必需的,它会为您提供所需的结果。