Skip to content

Commit

Permalink
WIP: More stuff to be added
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlarumbe committed May 30, 2023
1 parent c64887a commit 5ebe339
Showing 1 changed file with 106 additions and 125 deletions.
231 changes: 106 additions & 125 deletions verilog-ext-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,145 +28,97 @@

(require 'verilog-mode)


;;;; Additional faces
(defvar verilog-ext-compile-gray-face 'verilog-ext-compile-gray-face)
(defface verilog-ext-compile-gray-face
'((t (:foreground "gray55")))
"Gray face."
:group 'verilog-ext-compile)

(defvar verilog-ext-compile-binary-face 'verilog-ext-compile-binary-face)
(defface verilog-ext-compile-binary-face
'((t (:foreground "goldenrod")))
"Binary face."
:group 'verilog-ext-compile)


;;;; Variables
;;;;; Simulators
(defvar verilog-ext-compile-re-xrun
'((xrun-fatal "\\(?1:^[a-z]+\\): \\(?2:\\*F\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)|\\(?6:[0-9]+\\)\\)" 4 5 6 2 nil (1 verilog-ext-compile-binary-face) (2 compilation-error-face) (3 verilog-ext-compile-gray-face))
(xrun-fatal2 "\\(?1:^[a-z]+\\): \\(?2:\\*F\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)\\)" 4 5 nil 2 nil (1 verilog-ext-compile-binary-face) (2 compilation-error-face) (3 verilog-ext-compile-gray-face))
(xrun-fatal3 "\\(?1:^[a-z]+\\): \\(?2:\\*F\\),\\(?3:[0-9A-Z]+\\):" 1 nil nil 2 nil (1 verilog-ext-compile-binary-face) (2 compilation-error-face) (3 verilog-ext-compile-gray-face))
(xrun-error "\\(?1:^[a-z]+\\): \\(?2:\\*E\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)|\\(?6:[0-9]+\\)\\)" 4 5 6 2 nil (1 verilog-ext-compile-binary-face) (2 compilation-error-face) (3 verilog-ext-compile-gray-face))
(xrun-error2 "\\(?1:^[a-z]+\\): \\(?2:\\*E\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)\\)" 4 5 nil 2 nil (1 verilog-ext-compile-binary-face) (2 compilation-error-face) (3 verilog-ext-compile-gray-face))
(xrun-error3 "\\(?1:^[a-z]+\\): \\(?2:\\*E\\),\\(?3:[0-9A-Z]+\\):" 1 nil nil 2 nil (1 verilog-ext-compile-binary-face) (2 compilation-error-face) (3 verilog-ext-compile-gray-face))
(xrun-warning "\\(?1:^[a-z]+\\): \\(?2:\\*W\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)|\\(?6:[0-9]+\\)\\)" 4 5 6 1 nil (1 verilog-ext-compile-binary-face) (2 compilation-warning-face) (3 verilog-ext-compile-gray-face))
(xrun-warning2 "\\(?1:^[a-z]+\\): \\(?2:\\*W\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)\\)" 4 5 nil 1 nil (1 verilog-ext-compile-binary-face) (2 compilation-warning-face) (3 verilog-ext-compile-gray-face))
(xrun-warning3 "\\(?1:^[a-z]+\\): \\(?2:\\*W\\),\\(?3:[0-9A-Z]+\\):" 1 nil nil 1 nil (1 verilog-ext-compile-binary-face) (2 compilation-warning-face) (3 verilog-ext-compile-gray-face))
(xrun-note "\\(?1:^[a-z]+\\): \\(?2:\\*N\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)|\\(?6:[0-9]+\\)\\)" 4 5 6 0 nil (1 verilog-ext-compile-binary-face) (2 compilation-info-face) (3 verilog-ext-compile-gray-face))
(xrun-note2 "\\(?1:^[a-z]+\\): \\(?2:\\*N\\),\\(?3:[0-9A-Z]+\\)\\(?:\\(?:\\[[0-9A-Z_,]+\\]\\)? (\\(?4:[^ \t,]+\\),\\(?5:[0-9]+\\)\\)" 4 5 nil 0 nil (1 verilog-ext-compile-binary-face) (2 compilation-info-face) (3 verilog-ext-compile-gray-face))
(xrun-note3 "\\(?1:^[a-z]+\\): \\(?2:\\*N\\),\\(?3:[0-9A-Z]+\\):" 1 nil nil 0 nil (1 verilog-ext-compile-binary-face) (2 compilation-info-face) (3 verilog-ext-compile-gray-face)))
"Xcelium regexps:
- xrun-error: errors with line number and column number
- xrun-error2: errors with line number
- xrun-error3: errors without file/line number.")

;; TODO: Add Questa/Vsim

(defvar verilog-ext-compile-re-uvm
'((uvm-fatal "^\\(?1:UVM_FATAL\\) \\(?2:[a-zA-Z0-9\./_-]+\\)(\\(?3:[0-9]+\\))" 2 3 nil 2 nil (1 compilation-error-face))
(uvm-fatal2 "^\\(?1:UVM_FATAL\\) @" 1 nil nil 2 nil)
(uvm-error "^\\(?1:UVM_ERROR\\) \\(?2:[a-zA-Z0-9\./_-]+\\)(\\(?3:[0-9]+\\))" 2 3 nil 2 nil (1 compilation-error-face))
(uvm-error2 "^\\(?1:UVM_ERROR\\) @" 1 nil nil 2 nil)
(uvm-warning "^\\(?1:UVM_WARNING\\) \\(?2:[a-zA-Z0-9\./_-]+\\)(\\(?3:[0-9]+\\))" 2 3 nil 1 nil (1 compilation-warning-face))
(uvm-warning2 "^\\(?1:UVM_WARNING\\) @" 1 nil nil 1 nil)
(uvm-info "^\\(?1:UVM_INFO\\) \\(?2:[a-zA-Z0-9\./_-]+\\)(\\(?3:[0-9]+\\))" 2 3 nil 0 nil (1 compilation-info-face))
(uvm-info2 "^\\(?1:UVM_INFO\\) @" 1 nil nil 0 nil))
"UVM regexps:
- uvm-error: errors with line number and column number
- uvm-error2: errors without file/line number")

(defvar verilog-ext-compile-re-ovm
'((ovm-fatal "^\\(?1:OVM_FATAL\\) @ \\(?2:[0-9]+\\): " 1 nil nil 2 nil (2 compilation-line-face))
(ovm-error "^\\(?1:OVM_ERROR\\) @ \\(?2:[0-9]+\\): " 1 nil nil 2 nil (2 compilation-line-face))
(ovm-warning "^\\(?1:OVM_WARNING\\) @ \\(?2:[0-9]+\\): " 1 nil nil 1 nil (2 compilation-line-face))
(ovm-info "^\\(?1:OVM_INFO\\) @ \\(?2:[0-9]+\\): " 1 nil nil 0 nil (2 compilation-line-face)))
"OVM regexps:
- No line/column numbers.")

(defmacro verilog-ext-compile-define-mode (name &rest args)
"Macro to define a compilation derived mode for a Verilog error regexp.
NAME is the name of the created compilation mode.
ARGS is a property list with :desc, :docstring, :compile-re and :buf-name."
(declare (indent 1) (debug 1))
(let ((desc (plist-get args :desc))
(docstring (plist-get args :docstring))
(compile-re (plist-get args :compile-re))
(buf-name (plist-get args :buf-name)))
`(define-compilation-mode ,name ,desc ,docstring
(setq-local compilation-error-regexp-alist (mapcar #'car ,compile-re))
(setq-local compilation-error-regexp-alist-alist ,compile-re)
(rename-buffer ,buf-name)
(setq truncate-lines t)
(goto-char (point-max)))))

(defmacro verilog-ext-compile-define-fn (name &rest args)
"Macro to define a function to compile with error regexp highlighting.
Function will be callable by NAME.
ARGS is a property list."
(declare (indent 1) (debug 1))
(let ((docstring (plist-get args :docstring))
(buf (plist-get args :buf))
(comp-mode (plist-get args :comp-mode)))
`(defun ,name (command)
,docstring
(when (get-buffer ,buf)
(if (y-or-n-p (format "Buffer %s is in use, kill its process and start new compilation?" ,buf))
(kill-buffer ,buf)
(user-error "Aborted")))
(compile command)
(,comp-mode))))


;;;; Compilation-re
;; TODO: Update according to the ones at flycheck
;; TODO: Add notes?
(defvar verilog-ext-compile-re-verilator
'((verilator-error "%?\\(Error\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4 nil 2 nil (1 compilation-error-face) (2 compilation-line-face))
(verilator-warning "%?\\(Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4 nil 1 nil (1 compilation-warning-face) (2 compilation-line-face)))
(defvar verilog-ext-compile-verilator-re
'((verilator-error "%?\\(Error\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4 nil 2 nil (1 compilation-error-face) (2 compilation-line-face))
(verilator-warning "%?\\(Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4 nil 1 nil (1 compilation-warning-face) (2 compilation-line-face)))
"Verilator regexps.")

(defvar verilog-ext-compile-re-iverilog
'((iverilog-unsupported "\\(?1:.*\\):\\(?2:[0-9]+\\):.*sorry:" 1 2 nil 0 nil (1 compilation-info-face) (2 compilation-line-face))
(iverilog-warning "\\(?1:.*\\):\\(?2:[0-9]+\\):.*warning:" 1 2 nil 1 nil (1 compilation-warning-face) (2 compilation-line-face))
(iverilog-warning2 "^\\(?1:warning\\):" 1 nil nil 1 nil)
(iverilog-error "\\(?1:.*\\):\\(?2:[0-9]+\\):.*error:" 1 2 nil 2 nil (1 compilation-error-face) (2 compilation-line-face))
(vvp-warning "^\\(?1:WARNING\\): \\(?2:.*\\):\\(?3:[0-9]+\\):" 2 3 nil 1 nil (1 compilation-warning-face) (2 compilation-warning-face) (3 compilation-line-face))
(vvp-error "^\\(?1:ERROR\\): \\(?2:.*\\):\\(?3:[0-9]+\\):" 2 3 nil 2 nil (1 compilation-warning-face) (2 compilation-warning-face) (3 compilation-line-face))
(vvp-info "^\\(?1:LXT2 info\\):" 1 nil nil 0 nil))
(defvar verilog-ext-compile-iverilog-re
'((iverilog-unsupported "\\(?1:.*\\):\\(?2:[0-9]+\\):.*sorry:" 1 2 nil 0 nil (1 compilation-info-face) (2 compilation-line-face))
(iverilog-warning "\\(?1:.*\\):\\(?2:[0-9]+\\):.*warning:" 1 2 nil 1 nil (1 compilation-warning-face) (2 compilation-line-face))
(iverilog-warning2 "^\\(?1:warning\\):" 1 nil nil 1 nil )
(iverilog-error "\\(?1:.*\\):\\(?2:[0-9]+\\):.*error:" 1 2 nil 2 nil (1 compilation-error-face) (2 compilation-line-face))
(vvp-warning "^\\(?1:WARNING\\): \\(?2:.*\\):\\(?3:[0-9]+\\):" 2 3 nil 1 nil (1 compilation-warning-face) (2 compilation-warning-face) (3 compilation-line-face))
(vvp-error "^\\(?1:ERROR\\): \\(?2:.*\\):\\(?3:[0-9]+\\):" 2 3 nil 2 nil (1 compilation-warning-face) (2 compilation-warning-face) (3 compilation-line-face))
(vvp-info "^\\(?1:LXT2 info\\):" 1 nil nil 0 nil))
"Icarus Verilog regexps.")

;; TODO: Add slang/svlint and others...
;;;; Compilation-modes and functions
(verilog-ext-compile-define-mode verilog-ext-compile-verilator-mode
:desc "Verilator"
:docstring "Verilator Compilation mode."
:compile-re verilog-ext-verilator-compile-re
:buf-name verilog-ext-verilator-buf)

;;;; Synthesis
(defvar verilog-ext-compile-re-vivado
'((vivado-error "^\\(?1:^ERROR:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)\\(?3:.*\\[\\(?4:.*\\):\\(?5:[0-9]+\\)\\]\\)" 4 5 nil 2 nil (1 compilation-error-face) (2 verilog-ext-compile-gray-face))
(vivado-error2 "^\\(?1:^ERROR:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)" 1 nil nil 2 nil (1 compilation-error-face) (2 verilog-ext-compile-gray-face))
(vivado-critical "^\\(?1:^CRITICAL WARNING:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)\\(?3:.*\\[\\(?4:.*\\):\\(?5:[0-9]+\\)\\]\\)" 4 5 nil 1 nil (1 compilation-error-face) (2 verilog-ext-compile-gray-face))
(vivado-critical2 "^\\(?1:^CRITICAL WARNING:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)" 1 nil nil 1 nil (1 compilation-error-face) (2 verilog-ext-compile-gray-face))
(vivado-warning "^\\(?1:^WARNING:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)\\(?3:.*\\[\\(?4:.*\\):\\(?5:[0-9]+\\)\\]\\)" 4 5 nil 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-gray-face))
(vivado-warning2 "^\\(?1:^WARNING:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)" 1 nil nil 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-gray-face))
(vivado-info "^\\(?1:^INFO:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)\\(?3:.*\\[\\(?4:.*\\):\\(?5:[0-9]+\\)\\]\\)" 4 5 nil 0 nil (1 compilation-info-face) (2 verilog-ext-compile-gray-face))
(vivado-info2 "^\\(?1:^INFO:\\) \\(?2:\\[[ a-zA-Z0-9\./_-]+\\]\\)" 1 nil nil 0 nil (1 compilation-info-face) (2 verilog-ext-compile-gray-face)))
"Xilinx Vivado regexps:
- vivado-error: errors with line number and column number
- vivado-error2: errors without file/line number.")

;; TODO: Intel/Altera
;; (defvar verilog-ext-compile-re-quartus
;; '())

(defvar verilog-ext-compile-re-diamond
'((lattice-error "\\(?1:^ERROR\\) -" 1 nil nil 2 nil (1 compilation-error-face))
(lattice-warning "\\(?1:^WARNING\\) - \\(?2:[a-z0-9]+:\\) \\(?3:[a-zA-Z0-9\./_-]+\\)(\\(?4:[0-9]+\\)):" 3 4 nil 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-binary-face))
(lattice-warning2 "\\(?1:^WARNING\\) - \\(?2:[a-z0-9]+:\\)" 1 nil nil 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-binary-face))
(lattice-warning3 "\\(?1:^WARNING\\) -" 1 nil nil 1 nil (1 compilation-warning-face)))
"Lattice Diamond regexps.")

(defvar verilog-ext-compile-re-synplify
'((synp-error "^@\\(?1:E\\): \\(?2:[A-Z0-9]+\\) :\"\\(?3:[0-9a-zA-Z./_-]+\\)\":\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):" 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-gray-face))
(synp-error2 "^@\\(?1:E\\): \\(?2:[A-Z0-9]+\\) [:]?|" 1 nil nil 2 nil (2 verilog-ext-compile-gray-face))
(synp-error3 "^@\\(?1:E\\):" 1 nil nil 2 nil)
(synp-warning "^@\\(?1:W\\): \\(?2:[A-Z0-9]+\\) :\"\\(?3:[0-9a-zA-Z./_-]+\\)\":\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):" 3 4 5 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-gray-face))
(synp-warning2 "^@\\(?1:W\\): \\(?2:[A-Z0-9]+\\) [:]?|" 1 nil nil 1 nil (2 verilog-ext-compile-gray-face))
(synp-warning3 "^@\\(?1:W\\):" 1 nil nil 1 nil)
(synp-note "^@\\(?1:N\\): \\(?2:[A-Z0-9]+\\) :\"\\(?3:[0-9a-zA-Z./_-]+\\)\":\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):" 3 4 5 0 nil (1 compilation-info-face) (2 verilog-ext-compile-gray-face))
(synp-note2 "^@\\(?1:N\\): \\(?2:[A-Z0-9]+\\) [:]?|" 1 nil nil 0 nil (2 verilog-ext-compile-gray-face))
;; Did not find what those meant online, so set as warnings
(synp-alt-info "^@\\(?1:A\\): \\(?2:[A-Z0-9]+\\) :\"\\(?3:[0-9a-zA-Z./_-]+\\)\":\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):" 3 4 5 0 nil (1 compilation-info-face) (2 verilog-ext-compile-gray-face))
(synp-alt-info2 "^@\\(?1:A\\): \\(?2:[A-Z0-9]+\\) [:]?|" 1 nil nil 0 nil (2 verilog-ext-compile-gray-face))
(synp-alt-info3 "^@\\(?1:A\\):" 1 nil nil 0 nil)
(synp-note3 "^@\\(?1:N\\):" 1 nil nil 0 nil)
(synp-info "^@\\(?1:I\\):" nil nil nil 0 nil (1 compilation-line-face))
(synp-log "^@\\(?1:L\\):" nil nil nil 0 nil (1 compilation-line-face)))
"Synopsys Synplify regexps.")

(defvar verilog-ext-compile-re-design-compiler
'((dc-error "\\(?1:^Error\\): \\(?2:[0-9a-zA-Z./_-]+\\):\\(?3:[0-9]+\\): " 2 3 nil 2 nil (1 compilation-error-face))
(dc-error-2 "\\(?1:^Error\\): .*" 1 nil nil 2 nil)
(dc-warning "\\(?1:^Warning\\): \\(?2:[0-9a-zA-Z./_-]+\\):\\(?3:[0-9]+\\): " 2 3 nil 1 nil (1 compilation-warning-face))
(dc-warning-2 "\\(?1:^Warning\\): .*" 1 nil nil 1 nil)
(dc-info "\\(?1:^Information\\): \\(?2:[0-9a-zA-Z./_-]+\\):\\(?3:[0-9]+\\): " 2 3 nil 0 nil (1 compilation-info-face))
(dc-info-2 "\\(?1:^Information\\): .*" 1 nil nil 0 nil))
"Synopsys Design Compiler regexps.")
;;;###autoload (autoload 'verilog-ext-compile-verilator "verilog-ext-compile.el")
(verilog-ext-compile-define-fn verilog-ext-compile-verilator
:docstring "Compile Verilator COMMAND with error regexp highlighting."
:buf verilog-ext-verilator-buf
:comp-mode verilog-ext-compile-verilator-mode)


;; TODO: Define macro that sets the proper variables

;; (defmacro verilog-ext-compile-setup (mode)
;; "Setup compilation functions."
;; (declare (indent 1) (debug 1))
;; `(let ((modes (mapcar #'car verilog-ext-compile-modes-alist)))
;; ;; (dolist (mode modes)
;; (define-compilation-mode (intern (concat "compilation-" (symbol-name ,mode) "-mode")) (capitalize ,mode)
;; (concat "Compilation Mode with " (capitalize ,mode) " regexps.")
;; (setq-local compilation-skip-threshold 2) ; Default to check errors
;; (setq-local compilation-error-regexp-alist (mapcar 'car verilog-ext-compile-re-synplify))
;; (setq-local compilation-error-regexp-alist-alist verilog-ext-compile-re-synplify))))

;;;; Compilation-derived modes
(define-compilation-mode synplify-log-mode "Synplify Log"
"Synplify log compilation mode"
;; TODO: Still need to do something more generic
;; TODO: Add the appended regexps
(define-compilation-mode compilation-xcelium-mode "Xcelium"
"Xcelium compilation mode."
(setq-local compilation-skip-threshold 2) ; Default to check errors
(setq-local compilation-error-regexp-alist (mapcar 'car verilog-ext-compile-re-synplify))
(setq-local compilation-error-regexp-alist-alist verilog-ext-compile-re-synplify))
(setq-local compilation-error-regexp-alist (mapcar 'car verilog-ext-compile-xrun-re))
(setq-local compilation-error-regexp-alist-alist verilog-ext-compile-xrun-re))



Expand Down Expand Up @@ -196,6 +148,35 @@ variable."
(pop-to-buffer "*Verilog-Preprocessed*")))


;;;; Verilator
;; INFO: Verilator does not support SystemVerilog verification constructs.
;; Therefore, any source with constructs such as a clocking blocks or classes must be
;; deleted from `verilator.files' (copied previously from gtags.file for example)
;; If that is not possible because it is used as a source (e.g. a SystemVerilog interface
;; with a clocking block), then tweak/comment temporarily files by hand.
;;
;; INFO: This is useful while developing small IPs
(defvar larumbe/verilator-project-list nil)

(defun larumbe/verilator-lint-command ()
"Return current verilator int command based on selected project from `larumbe/verilator-project-list'."
(let* ((project (completing-read "Select project: " (mapcar #'car larumbe/verilator-project-list)))
(lint-files (nth 0 (cdr (assoc project larumbe/verilator-project-list))))
(lint-top (nth 1 (cdr (assoc project larumbe/verilator-project-list)))))
(concat "verilator --lint-only +1800-2012ext+sv "
"-f " lint-files " "
"--top-module " lint-top)))

;;;###autoload
(defun larumbe/verilator-lint ()
"Files created with ggtags and renamed (useful for small projects).
It's faster than Vivado elaboration since it does not elaborate design"
(interactive)
(larumbe/compile (larumbe/verilator-lint-command) nil "verilator"))




(provide 'verilog-ext-compile)

;;; verilog-ext-compile.el ends here

0 comments on commit 5ebe339

Please sign in to comment.