在verilog中保留chisel中的注释

How to decipher comments in generated Verilog from chisel?

These are source locators and will show up in generated FIRRTL or Verilog. These tell you what line in a source file (Chisel or FIRRTL) was used to generate a specific line in the downstream FIRRTL or Verilog.

The format is generally: @[<file> <line>:<column> ...]

More than one source locator may be present.

Example

Consider the following example pulled from the BoringUtilsSpec. The line numbers (which do not start at zero as this was extracted from a larger file) are shown along with the column numbers. You can see how things line up between them. For example, the declaration of notA happens on line 27 column 20 and the assignment notA := ~a happens on line 30, column 10. You see 27:20 and 30:10 show up in the FIRRTL. In the Verilog, these get merged somewhat and you wind up with source locators indicating both 27:20 and 30:10:

scala 复制代码
// -------------------------------------------+----+
// File: BoringUtilsSpec.scala                |    |
// -------------------------------------------+----+
// Column Number                              |    |
// -------------------------------------------+----+
//           1         2         3         4  |    |
// 01234567890123456789012345678901234567890  |    |
// -------------------------------------------+----|
     class BoringInverter extends Module { // | 24 | Line Number
       val io = IO(new Bundle{})           // |  5 |
       val a = Wire(UInt(1.W))             // |  6 |
       val notA = Wire(UInt(1.W))          // |  7 |
       val b = Wire(UInt(1.W))             // |  8 |
       a := 0.U                            // |  9 |
       notA := ~a                          // | 30 |
       b := a                              // |  1 |
       chisel3.assert(b === 1.U)           // |  2 |
       BoringUtils.addSource(notA, "x")    // |  3 |
       BoringUtils.addSink(b, "x")         // |  4 |
     }                                     // |  5 |
// -------------------------------------------+----+

This produces the following FIRRTL:

复制代码
module BoringUtilsSpecBoringInverter : 
  input clock : Clock
  input reset : UInt<1>
  output io : {}

  wire a : UInt<1> @[BoringUtilsSpec.scala 26:17]
  wire notA : UInt<1> @[BoringUtilsSpec.scala 27:20]
  wire b : UInt<1> @[BoringUtilsSpec.scala 28:17]
  a <= UInt<1>("h00") @[BoringUtilsSpec.scala 29:7]
  node _T = not(a) @[BoringUtilsSpec.scala 30:13]
  notA <= _T @[BoringUtilsSpec.scala 30:10]
  b <= a @[BoringUtilsSpec.scala 31:7]
  node _T_1 = eq(b, UInt<1>("h01")) @[BoringUtilsSpec.scala 32:22]
  node _T_2 = bits(reset, 0, 0) @[BoringUtilsSpec.scala 32:19]
  node _T_3 = or(_T_1, _T_2) @[BoringUtilsSpec.scala 32:19]
  node _T_4 = eq(_T_3, UInt<1>("h00")) @[BoringUtilsSpec.scala 32:19]
  // assert not shown

And the following Verilog:

复制代码
module BoringUtilsSpecBoringInverter(
  input   clock,
  input   reset
);
  wire  _T; // @[BoringUtilsSpec.scala 30:13]
  wire  notA; // @[BoringUtilsSpec.scala 27:20 BoringUtilsSpec.scala 30:10]
  wire  _T_3; // @[BoringUtilsSpec.scala 32:19]
  wire  _T_4; // @[BoringUtilsSpec.scala 32:19]
  assign _T = 1'h1; // @[BoringUtilsSpec.scala 30:13]
  assign notA = 1'h1; // @[BoringUtilsSpec.scala 27:20 BoringUtilsSpec.scala 30:10]
  assign _T_3 = _T | reset; // @[BoringUtilsSpec.scala 32:19]
  assign _T_4 = _T_3 == 1'h0; // @[BoringUtilsSpec.scala 32:19]
  // assert not shown
endmodule

These are source locators and will show up in generated FIRRTL or Verilog. These tell you what line in a source file (Chisel or FIRRTL) was used to generate a specific line in the downstream FIRRTL or Verilog.

The format is generally: @ : ...

More than one source locator may be present.

Example

Consider the following example pulled from the BoringUtilsSpec. The line numbers (which do not start at zero as this was extracted from a larger file) are shown along with the column numbers. You can see how things line up between them. For example, the declaration of notA happens on line 27 column 20 and the assignment notA := ~a happens on line 30, column 10. You see 27:20 and 30:10 show up in the FIRRTL. In the Verilog, these get merged somewhat and you wind up with source locators indicating both 27:20 and 30:10:

// -------------------------------------------±---+

// File: BoringUtilsSpec.scala | |

// -------------------------------------------±---+

// Column Number | |

// -------------------------------------------±---+

// 1 2 3 4 | |

// 01234567890123456789012345678901234567890 | |

// -------------------------------------------±---|

class BoringInverter extends Module { // | 24 | Line Number

val io = IO(new Bundle{}) // | 5 |

val a = Wire(UInt(1.W)) // | 6 |

val notA = Wire(UInt(1.W)) // | 7 |

val b = Wire(UInt(1.W)) // | 8 |

a := 0.U // | 9 |

notA := ~a // | 30 |

b := a // | 1 |

chisel3.assert(b === 1.U) // | 2 |

BoringUtils.addSource(notA, "x") // | 3 |

BoringUtils.addSink(b, "x") // | 4 |

} // | 5 |

// -------------------------------------------±---+

This produces the following FIRRTL:

module BoringUtilsSpecBoringInverter :

input clock : Clock

input reset : UInt<1>

output io : {}

wire a : UInt<1> @BoringUtilsSpec.scala 26:17

wire notA : UInt<1> @BoringUtilsSpec.scala 27:20

wire b : UInt<1> @BoringUtilsSpec.scala 28:17

a <= UInt<1>("h00") @BoringUtilsSpec.scala 29:7

node _T = not(a) @BoringUtilsSpec.scala 30:13

notA <= _T @BoringUtilsSpec.scala 30:10

b <= a @BoringUtilsSpec.scala 31:7

node _T_1 = eq(b, UInt<1>("h01")) @BoringUtilsSpec.scala 32:22

node _T_2 = bits(reset, 0, 0) @BoringUtilsSpec.scala 32:19

node _T_3 = or(_T_1, _T_2) @BoringUtilsSpec.scala 32:19

node _T_4 = eq(_T_3, UInt<1>("h00")) @BoringUtilsSpec.scala 32:19

// assert not shown

And the following Verilog:

module BoringUtilsSpecBoringInverter(

input clock,

input reset

);

wire _T; // @BoringUtilsSpec.scala 30:13

wire notA; // @BoringUtilsSpec.scala 27:20 BoringUtilsSpec.scala 30:10

wire _T_3; // @BoringUtilsSpec.scala 32:19

wire _T_4; // @BoringUtilsSpec.scala 32:19

assign _T = 1'h1; // @BoringUtilsSpec.scala 30:13

assign notA = 1'h1; // @BoringUtilsSpec.scala 27:20 BoringUtilsSpec.scala 30:10

assign _T_3 = _T | reset; // @BoringUtilsSpec.scala 32:19

assign _T_4 = _T_3 == 1'h0; // @BoringUtilsSpec.scala 32:19

// assert not shown

endmodule

Caveats

Generator Bootcamp

If you are running this in the Chisel Bootcamp Jupyter Notebook or through an sbt console/REPL, the source locators may not make as much sense as there really isn't a file here with lines.

Difference with Annotation

These source locators are not Annotations, in case anyone has come across that name.

Annotations are metadata associated with circuit components. Source locators (which map to Info in the FIRRTL IR) are associated with specific statements in some source file. Under the hood they're just strings that get generated and then copied around. There is no guarantee that source locators will be preserved---they may be changed or deleted arbitrarily. Conversely, Annotations are preserved and renamed across transformations and have strong guarantees on how they behave.

Consequently, do not rely on source locators for anything other than an aid if you need to debug the Chisel or FIRRTL compiler stages.

相关推荐
szxinmai主板定制专家6 小时前
Zynq MPSoC半导体高精度运动控制方案|FPGA硬件插补实现亚微米级伺服实时控制
人工智能·嵌入式硬件·fpga开发·zynq·运动控制·ethercat
星夜离尘561 天前
ILA 在线调试:Vivado 抓取片内信号与定位下板问题(附完整实操)
fpga开发
jz_ddk1 天前
[学习] 深入理解 USB 通信与 FPGA 实现:从协议到逻辑设计
学习·fpga开发·xilinx·usb2.0
星夜离尘562 天前
PWM 信号生成与呼吸灯:占空比控制、按键调光与舵机扩展(附完整 Verilog 实操)
fpga开发
zlinear数据采集卡2 天前
ZLinear DABM-D223 通信协议与软件开发全解析:从 USB CDC 到 DDS 波形输出
arm开发·嵌入式硬件·fpga开发·开源
LCMICRO-133108477462 天前
国产长芯微LD3092完全pin-pin替代LT3092,是一款可编程两端电流源
arm开发·单片机·嵌入式硬件·fpga开发·硬件工程·恒流源·lt3092
nuoxin1142 天前
BL-M8812CU3 无线 WiFi 模块-富利威
人工智能·嵌入式硬件·fpga开发·硬件工程·dsp开发
xiaojiaohuazi2 天前
基于Zynq UltraScale+ MPSoC的PL DDR4直写多NVMe条带阵列(RAID 0)与exFAT高速采集存储系统
fpga开发
ALINX技术博客2 天前
【黑金云课堂】FPGA技术教程Vitis开发:AXI总线
fpga开发·vitis