ExASIC
分享让工作更轻松

RTL顶层自动连线的秘武器:Emacs verilog-mode介绍

RTL顶层自动连线听说过吗?想学吗?我们今天就来介绍自动连线的神器——emacs verilog-mode。

emacs是什么?

江湖流传版:传说中神的编辑器。

维基百科版:Emacs(Editor MACroS,宏编辑器),最初由Richard Stallman于1975年在MIT协同Guy Lewis Steele Jr.共同完成。

verilog-mode是什么

官网的介绍(https://www.veripool.org/wiki/verilog-mode):

Verilog-mode.el is the extremely popular free Verilog mode for Emacs which provides context-sensitive highlighting, auto indenting, and provides macro expansion capabilities to greatly reduce Verilog coding time. It supports AUTOs and indentation in Emacs for traditional Verilog (1394-2005), the Open Verification Methodology (OVM) and SystemVerilog (1800-2005/1800-2009).
Recent versions allow you to insert AUTOS in non-AUTO designs, so IP interconnect can be easily modified. You can also expand SystemVerilog ".*" port instantiations, to see what ports will be connected by the simulators.

简单点说就是支持Verilog、SystemVerilog(包括UVM)的emacs语法高亮文件。其中提到Verilog-mode支持Autos——这就是今天的重点。

Verilog-mode是由Michael McNamara mac@verilog.com和Wilson Snyder wsnyder@wsnyder.org编写。难能可贵的是,这个verilog-mode保持着每月都有更新。

值得一提的是Wilson Snyder就是SystemVerilog开源仿真器Verilator的作者。

verilog-mode Autos有哪些功能

手动编写的verilog代码:

module example (/*AUTOARG*/);
  input i;
  output o;
  /*AUTOINPUT*/
  /*AUTOOUTPUT*/
  /*AUTOREG*/

  inst inst (/*AUTOINST*/);

  always @ (/*AUTOSENSE*/) begin
    o = i;
  end

endmodule

由Autos处理后的Verilog代码:

module example (/*AUTOARG*/
  // Outputs
  lower_out, o,
  // Inputs
  lower_inb, lower_ina, i
  );
  input i;
  output o;
  /*AUTOINPUT*/
  // Beginning of automatic inputs
  input  lower_ina; // To inst of inst.v
  input  lower_inb; // To inst of inst.v
  // End of automatics
  /*AUTOOUTPUT*/
  // Beginning of automatic output
  output lower_out; // From inst of inst.v
  // End of automactics
  /*AUTOREG*/
  // Beginning of automatic regs
  reg    o;
  // End of automatics

  inst inst (/*AUTOINST*
             // Outputs
             .lower_out (lower_out),
             // Inputs
             .lower_inb (lower_inb),
             .lower_ina (lower_ina));

  always @ (/*AUTOSENSE*/i) begin
    o = i;
  end

大家可以看到,verilog-mode自动分析出:

自动提取子模块的端口定义来连线是今天的重点中的重点。一般来讲,我们实例化模块时大部分的信号名与子模块定义的名字一致即可。如上面代码中的:

  inst inst (/*AUTOINST*
             // Outputs
             .lower_out (lower_out),
             // Inputs
             .lower_inb (lower_inb),
             .lower_ina (lower_ina));

特殊连接关系的处理

但常常我们顶层连接时会换一个名字。比如module A有一个输出端口dat_o,module B有一个输入端口dat_i,这两者怎么连?定义模版AUTO_TEMPLATE,如下:

手动编写的verilog:

/* A AUTO_TMEPLATE (
  .dat_o (dat_a2b),
)
*/
A u_A (/*AUTOINST*/);

/* B AUTO_TEMPLATE (
  .dat_i (dat_a2b),
)
*/
B u_B (/*AUTOINST*/);

由Autos处理后的verilog代码:

/* A AUTO_TMEPLATE (
  .dat_o (dat_a2b),
)
*/
A u_A (/*AUTOINST*/
       // Outputs
       .dat_o  (dat_a2b));  // Templated

/* B AUTO_TEMPLATE (
  .dat_i (dat_a2b),
)
*/
B u_B (/*AUTOINST*/
       // Inputs
       .dat_i  (dat_a2b));  // Templated

在哪里找子模块定义?

默认规则:

使用方法:在顶层endmodule后面指定verilog-library-directories,如下:

endmodule // top

// Local Variables:
// verilog-library-directories:("." "subdir" "subdirs")
// End:

除了写模版还需要做什么?

只需要Ctrl-C Ctrl-A,仅此而已。

如果修改了子模块或者模版,再按一次Ctrl-C Ctrl-A。

更多功能

    verilog-auto-arg          for AUTOARG module instantiations
    verilog-auto-ascii-enum   for AUTOASCIIENUM enumeration decoding
    verilog-auto-assign-modport for AUTOASSIGNMODPORT assignment to/from modport
    verilog-auto-inout        for AUTOINOUT making hierarchy inouts
    verilog-auto-inout-comp   for AUTOINOUTCOMP copy complemented i/o
    verilog-auto-inout-in     for AUTOINOUTIN inputs for all i/o
    verilog-auto-inout-modport  for AUTOINOUTMODPORT i/o from an interface modport
    verilog-auto-inout-module for AUTOINOUTMODULE copying i/o from elsewhere
    verilog-auto-inout-param  for AUTOINOUTPARAM copying params from elsewhere
    verilog-auto-input        for AUTOINPUT making hierarchy inputs
    verilog-auto-insert-lisp  for AUTOINSERTLISP insert code from lisp function
    verilog-auto-insert-last  for AUTOINSERTLAST insert code from lisp function
    verilog-auto-inst         for AUTOINST instantiation pins
    verilog-auto-star         for AUTOINST .* SystemVerilog pins
    verilog-auto-inst-param   for AUTOINSTPARAM instantiation params
    verilog-auto-logic        for AUTOLOGIC declaring logic signals
    verilog-auto-output       for AUTOOUTPUT making hierarchy outputs
    verilog-auto-output-every for AUTOOUTPUTEVERY making all outputs
    verilog-auto-reg          for AUTOREG registers
    verilog-auto-reg-input    for AUTOREGINPUT instantiation registers
    verilog-auto-reset        for AUTORESET flop resets
    verilog-auto-sense        for AUTOSENSE or AS always sensitivity lists
    verilog-auto-tieoff       for AUTOTIEOFF output tieoffs
    verilog-auto-undef        for AUTOUNDEF \=`undef of local \=`defines
    verilog-auto-unused       for AUTOUNUSED unused inputs/inouts
    verilog-auto-wire         for AUTOWIRE instantiation wires

    verilog-read-defines      for reading \=`define values
    verilog-read-includes     for reading \=`includes

详见官网帮助文档:
https://www.veripool.org/projects/verilog-mode/wiki/Verilog-mode-Help

verilog-mode下载、安装

新版的GNU Emacs自带verilog-mode,如果需要最新的verilog-mode可以在官网下载:
https://www.veripool.org/projects/verilog-mode/wiki/Installing

VIM用户咋办?

可以用VIM调动shell命令执行(emacs批处理模式),例如:

:!emacs --batch  <filenames.v>  -f verilog-batch-auto

是不是很简单!

阅读数:
更多文章:文章目录
欢迎使用ExASIC订阅服务
仅用于ExASIC最新文章通知,方便及时阅读。
成都奥卡思微电科技有限公司,主要产品有AVE自动化验证工具软件和MegaEC等价验证工具软件。硅知识,上海市集成电路高技能人才培养基地NanDigits中国,主要产品GOF。AD