【问题标题】:Folding/Identifying current `ifdef block in verilog code using emacs使用emacs在verilog代码中折叠/识别当前的`ifdef块
【发布时间】:2012-01-03 10:04:55
【问题描述】:

我的工作涉及浏览包含 `ifdef 块的长 verilog 代码。我的主要编辑器是 emacs。下面是一个典型的例子:

module Foo(
...
...
);

// Inputs, Outputs
...

`ifdef CONDITION_1
...
...    
`else // CONDITION_1
...
...    
`ifdef CONDITION_2
...
...
`endif //CONDITION_2
...
...
     foo <= 1'b1;
...
...
`endif // CONDITION_1

如您所见,foo &lt;= 1'b1;ifdef CONDITION_1else 块中假设我的观点就在foo &lt;= 1'b1; 线上,有什么方法可以让我可以直接移动到 ifdef CONDITION_1 行或折叠代码以便我可以看到 CONDITION1?我尝试使用向后增量搜索,但在这种情况下,我最终得到 ifdef CONDITION_2 我尝试使用 hide-ifdef-mode 但它识别#ifdef 而不是`ifdef。这些块不使用括号。所以使用 C-M-u 也无济于事

【问题讨论】:

    标签: emacs elisp verilog emacs23


    【解决方案1】:

    这会做到,尽管对于你上面的例子,它会停在

    `else // CONDITION_1
    

    声明,因为这就是 foo 分配的内容:

    (defun my-verilog-up-ifdef ()
      "Go up `ifdef/`ifndef/`else/`endif macros until an enclosing one is found."
      (interactive)
      (let ((pos (point)) (depth 0) done)
        (while (and (not done)
               (re-search-backward "^\\s-*`\\(ifdef\\|ifndef\\|else\\|endif\\)" nil t))
          (if (looking-at "\\s-*`endif")
              (setq depth (1+ depth))
            (if (= depth 0)
                (setq done t)
              (when (looking-at "\\s-*`if")
                (setq depth (1- depth))))))
        (unless done
          (goto-char pos)
          (error "Not inside an `ifdef construct"))))
    

    【讨论】:

    • 谢谢一百万兄弟...所有'else'都已用相应的条件进行了评论,所以即使它停在'else'也可以。 :)
    • 我想你会想要那个,否则你怎么知道它是在'ifdef部分还是'else部分:)
    • 如果不明显:如果没有注释'else,只需从那里再次执行命令,它将跳转到'ifdef。
    【解决方案2】:

    elisp 常量hif-cpp-prefix 控制hide-ifdef-mode 使用的基本语法。我您可以将其定义为如下所示。 (警告,这是未经测试的,因为我自己不使用verilog。)

    (setq hif-cpp-prefix "\\(^\\|\r\\)[ \t]*\\(#\\|`\\)[ \t]*")
    

    请注意,这是使用defconst 而不是defvar 定义的,因此hide-ifdef-mode 的编译版本可能仍使用原始值。将未编译的文件加载到 Emacs 中可能会解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-11
      • 1970-01-01
      • 2010-11-15
      • 1970-01-01
      • 2015-02-21
      • 2012-03-10
      • 1970-01-01
      相关资源
      最近更新 更多