Function: verilog-signals-combine-bus
verilog-signals-combine-bus is a byte-compiled function defined in
verilog-mode.el.gz.
Signature
(verilog-signals-combine-bus IN-LIST)
Documentation
Return a list of signals in IN-LIST, with buses combined.
Duplicate signals are also removed. For example A[2] and A[1] become A[2:1].
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/verilog-mode.el.gz
(defun verilog-signals-combine-bus (in-list)
"Return a list of signals in IN-LIST, with buses combined.
Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
(let (combo
buswarn
out-list
sig highbit lowbit ; Temp information about current signal
sv-name sv-highbit sv-lowbit ; Details about signal we are forming
sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
sv-modport
bus)
;; Shove signals so duplicated signals will be adjacent
(setq in-list (sort in-list #'verilog-signals-sort-compare))
(while in-list
(setq sig (car in-list))
;; No current signal; form from existing details
(unless sv-name
(setq sv-name (verilog-sig-name sig)
sv-highbit nil
sv-busstring nil
sv-comment (verilog-sig-comment sig)
sv-memory (verilog-sig-memory sig)
sv-enum (verilog-sig-enum sig)
sv-signed (verilog-sig-signed sig)
sv-type (verilog-sig-type sig)
sv-multidim (verilog-sig-multidim sig)
sv-modport (verilog-sig-modport sig)
combo ""
buswarn ""))
;; Extract bus details
(setq bus (verilog-sig-bits sig))
(setq bus (and bus (verilog-simplify-range-expression bus)))
(cond ((and bus
(or (and (string-match "^\\[\\([0-9]+\\):\\([0-9]+\\)\\]$" bus)
(setq highbit (string-to-number (match-string 1 bus))
lowbit (string-to-number
(match-string 2 bus))))
(and (string-match "^\\[\\([0-9]+\\)\\]$" bus)
(setq highbit (string-to-number (match-string 1 bus))
lowbit highbit))))
;; Combine bits in bus
(if sv-highbit
(setq sv-highbit (max highbit sv-highbit)
sv-lowbit (min lowbit sv-lowbit))
(setq sv-highbit highbit
sv-lowbit lowbit)))
(bus
;; String, probably something like `preproc:0
(setq sv-busstring bus)))
;; Peek ahead to next signal
(setq in-list (cdr in-list))
(setq sig (car in-list))
(cond ((and sig (equal sv-name (verilog-sig-name sig)))
;; Combine with this signal
(when (and sv-busstring
(not (equal sv-busstring (verilog-sig-bits sig))))
(when nil ; Debugging
(message (concat "Warning, can't merge into single bus `%s%s'"
", the AUTOs may be wrong")
sv-name bus))
(setq buswarn ", Couldn't Merge"))
(if (verilog-sig-comment sig) (setq combo ", ..."))
(setq sv-memory (or sv-memory (verilog-sig-memory sig))
sv-enum (or sv-enum (verilog-sig-enum sig))
sv-signed (or sv-signed (verilog-sig-signed sig))
sv-type (or sv-type (verilog-sig-type sig))
sv-multidim (or sv-multidim (verilog-sig-multidim sig))
sv-modport (or sv-modport (verilog-sig-modport sig))))
;; Doesn't match next signal, add to queue, zero in prep for next
;; Note sig may also be nil for the last signal in the list
(t
(setq out-list
(cons (verilog-sig-new
sv-name
(or sv-busstring
(if sv-highbit
(concat "[" (int-to-string sv-highbit) ":"
(int-to-string sv-lowbit) "]")))
(concat sv-comment combo buswarn)
sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
out-list)
sv-name nil))))
;;
out-list))