Function: verilog-read-defines

verilog-read-defines is a byte-compiled function defined in verilog-mode.el.gz.

Signature

(verilog-read-defines &optional FILENAME RECURSE SUBCALL)

Documentation

Read `defines and parameters for the current file, or optional FILENAME.

If the filename is provided, verilog-library-flags will be used to resolve it. If optional RECURSE is non-nil, recurse through `includes.

Localparams must be simple assignments to constants, or have their own
"localparam" label rather than a list of localparams. Thus:

    localparam X = 5, Y = 10; // Ok
    localparam X = {1'b1, 2'h2}; // Ok
    localparam X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 localparam lines

Defines must be simple text substitutions, one on a line, starting at the beginning of the line. Any ifdefs or multiline comments around the define are ignored.

Defines are stored inside Emacs variables using the name vh-{definename}.

Localparams define what symbols are constants so that AUTOSENSE will not include them in sensitivity lists. However any parameters in the include file are not considered ports in the including file, thus will not appear in AUTOINSTPARAM lists for a parent module..

The file variables feature can be used to set defines that verilog-mode can see; put at the *END* of your file something like:

    // Local Variables:
    // vh-macro:"macro_definition"
    // End:

If macros are defined earlier in the same file and you want their values, you can read them automatically with:

    // Local Variables:
    // verilog-auto-read-includes:t
    // End:

Or a more specific alternative example, which requires having enable-local-eval non-nil:

    // Local Variables:
    // eval:(verilog-read-defines)
    // eval:(verilog-read-defines "group_standard_includes.v")
    // End:

Note these are only read when the file is first visited, you must use
C-x C-v (find-alternate-file) RET to have these take effect after editing them!

If you want to disable the "Process `eval' or hook local variables" warning message, you need to add to your init file:

    (setq enable-local-eval t)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/verilog-mode.el.gz
(defun verilog-read-defines (&optional filename recurse subcall)
  "Read \\=`defines and parameters for the current file, or optional FILENAME.
If the filename is provided, `verilog-library-flags' will be used to
resolve it.  If optional RECURSE is non-nil, recurse through \\=`includes.

Localparams must be simple assignments to constants, or have their own
\"localparam\" label rather than a list of localparams.  Thus:

    localparam X = 5, Y = 10;   // Ok
    localparam X = {1\\='b1, 2\\='h2};  // Ok
    localparam X = {1\\='b1, 2\\='h2}, Y = 10;  // Bad, make into 2 localparam lines

Defines must be simple text substitutions, one on a line, starting
at the beginning of the line.  Any ifdefs or multiline comments around the
define are ignored.

Defines are stored inside Emacs variables using the name
vh-{definename}.

Localparams define what symbols are constants so that AUTOSENSE
will not include them in sensitivity lists.  However any
parameters in the include file are not considered ports in the
including file, thus will not appear in AUTOINSTPARAM lists for a
parent module..

The file variables feature can be used to set defines that
`verilog-mode' can see; put at the *END* of your file something
like:

    // Local Variables:
    // vh-macro:\"macro_definition\"
    // End:

If macros are defined earlier in the same file and you want their values,
you can read them automatically with:

    // Local Variables:
    // verilog-auto-read-includes:t
    // End:

Or a more specific alternative example, which requires having
`enable-local-eval' non-nil:

    // Local Variables:
    // eval:(verilog-read-defines)
    // eval:(verilog-read-defines \"group_standard_includes.v\")
    // End:

Note these are only read when the file is first visited, you must use
\\[find-alternate-file] RET  to have these take effect after editing them!

If you want to disable the \"Process `eval' or hook local variables\"
warning message, you need to add to your init file:

    (setq enable-local-eval t)"
  (let ((origbuf (current-buffer)))
    (save-excursion
      (unless subcall (verilog-getopt-flags))
      (when filename
	(let ((fns (verilog-library-filenames filename (buffer-file-name))))
	  (if fns
	      (set-buffer (find-file-noselect (car fns)))
	    (error "%s: Can't find verilog-read-defines file: %s"
		   (verilog-point-text) filename))))
      (when recurse
	(goto-char (point-min))
	(while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
	  (let ((inc (verilog-substitute-include-name
                      (match-string-no-properties 1))))
	    (unless (verilog-inside-comment-or-string-p)
	      (verilog-read-defines inc recurse t)))))
      ;; Read `defines
      ;; note we don't use verilog-re... it's faster this way, and that
      ;; function has problems when comments are at the end of the define
      (goto-char (point-min))
      (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
	(let ((defname (match-string-no-properties 1))
	      (defvalue (match-string-no-properties 2)))
	  (unless (verilog-inside-comment-or-string-p (match-beginning 0))
	    (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
	    (verilog-set-define defname defvalue origbuf))))
      ;; Hack: Read parameters
      (goto-char (point-min))
      (while (re-search-forward
	      "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
	(let (enumname)
          ;; Advance over parameter's type if present
          (if (looking-at "\\([a-zA-Z0-9_]+\\s-+\\)[a-zA-Z0-9_]+")
              (goto-char (match-end 1)))
	  ;; The primary way of getting defines is verilog-read-decls
	  ;; However, that isn't called yet for included files, so we'll add another scheme
	  (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
	      (setq enumname (match-string-no-properties 2)))
	  (forward-comment 99999)
	  (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
				     "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
	    (unless (verilog-inside-comment-or-string-p (match-beginning 0))
	      (verilog-set-define (match-string-no-properties 1)
				  (match-string-no-properties 2) origbuf enumname))
	    (goto-char (match-end 0))
	    (forward-comment 99999)))))))