Skip to content

Commit

Permalink
Add support for workspace compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlarumbe committed May 30, 2023
1 parent 7cd7f60 commit 2b689fd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
33 changes: 17 additions & 16 deletions verilog-ext-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
;; - (verilog-ext-compile-slang (concat "slang --color-diagnostics=false " buffer-file-name))
;; - (verilog-ext-compile-svlint (concat "svlint -1 " buffer-file-name))
;; - (verilog-ext-compile-surelog (concat "surelog -parseonly " buffer-file-name))
;;
;; It also includes a function to preprocess current buffer: `verilog-ext-preprocess'

;;; Code:

Expand Down Expand Up @@ -67,7 +69,8 @@ ARGS is a property list with :desc, :docstring, :compile-re and :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)
(when ,buf-name
(rename-buffer ,buf-name))
(setq truncate-lines t)
(goto-char (point-max)))))

Expand All @@ -83,7 +86,7 @@ ARGS is a property list."
(comp-mode (plist-get args :comp-mode)))
`(defun ,name (command)
,docstring
(when (get-buffer ,buf)
(when (and ,buf (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")))
Expand All @@ -97,7 +100,7 @@ ARGS is a property list."
(verilator-error2 ,(concat "^%\\(?1:Error\\): \\(?2:" verilog-ext-compile-filename-re "\\):\\(?3:[0-9]+\\):\\(?4:[0-9]+\\): ") 2 3 4 2 nil (1 compilation-error-face))
(verilator-error3 ,(concat "^%\\(?1:Error\\)-\\(?2:[^:]+\\): \\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\): ") 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face))
(verilator-error4 "^%\\(?1:Error\\): " nil nil nil 2 nil (1 compilation-error-face))
(verilator-warning ,(concat "^%\\(?1:Warning\\)-\\(?2:[^:]+\\): \\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\): ") 3 4 5 1 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face)))
(verilator-warning ,(concat "^%\\(?1:Warning\\)-\\(?2:[^:]+\\): \\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\): ") 3 4 5 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-msg-code-face)))
"Verilator regexps.")

(defconst verilog-ext-compile-iverilog-re
Expand Down Expand Up @@ -130,13 +133,17 @@ ARGS is a property list."
"Svlint regexps.")

(defconst verilog-ext-compile-surelog-re
`((surelog-fatal ,(concat "^\\[\\(?1:FAT:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face))
(surelog-error ,(concat "^\\[\\(?1:ERR:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face))
(surelog-syntax ,(concat "^\\[\\(?1:SNT:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face))
(surelog-warning ,(concat "^\\[\\(?1:WRN:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-msg-code-face))
(surelog-note ,(concat "^\\[\\(?1:NTE:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))
(surelog-info ,(concat "^\\[\\(?1:INF:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))
(surelog-info2 ,(concat "^\\[\\(?1:INF:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+") nil nil nil 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face)))
`((surelog-fatal ,(concat "^\\[\\(?1:FAT:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face))
(surelog-fatal2 ,(concat "^\\[\\(?1:FAT:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+") nil nil nil 2 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))
(surelog-error ,(concat "^\\[\\(?1:ERR:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face))
(surelog-error2 ,(concat "^\\[\\(?1:ERR:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+") nil nil nil 2 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))
(surelog-syntax ,(concat "^\\[\\(?1:SNT:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 2 nil (1 compilation-error-face) (2 verilog-ext-compile-msg-code-face))
(surelog-warning ,(concat "^\\[\\(?1:WRN:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-msg-code-face))
(surelog-warning2 ,(concat "^\\[\\(?1:WRN:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+") nil nil nil 1 nil (1 compilation-warning-face) (2 verilog-ext-compile-msg-code-face))
(surelog-note ,(concat "^\\[\\(?1:NTE:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))
(surelog-note2 ,(concat "^\\[\\(?1:NTE:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+") nil nil nil 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))
(surelog-info ,(concat "^\\[\\(?1:INF:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+\\(?3:" verilog-ext-compile-filename-re "\\):\\(?4:[0-9]+\\):\\(?5:[0-9]+\\):\\s-+") 3 4 5 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))
(surelog-info2 ,(concat "^\\[\\(?1:INF:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+") nil nil nil 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face)))
"Surelog regexps.")

(defvar verilog-ext-compile-verilator-buf "*verilator*")
Expand All @@ -147,7 +154,6 @@ ARGS is a property list."
(defvar verilog-ext-compile-surelog-buf "*surelog*")

;;;; Compilation-modes and functions
;;;###autoload (autoload 'verilog-ext-compile-verilator-mode "verilog-ext-compile.el")
(verilog-ext-compile-define-mode verilog-ext-compile-verilator-mode
:desc "Verilator"
:docstring "Verilator Compilation mode."
Expand All @@ -160,7 +166,6 @@ ARGS is a property list."
:buf verilog-ext-compile-verilator-buf
:comp-mode verilog-ext-compile-verilator-mode)

;;;###autoload (autoload 'verilog-ext-compile-iverilog-mode "verilog-ext-compile.el")
(verilog-ext-compile-define-mode verilog-ext-compile-iverilog-mode
:desc "Iverilog"
:docstring "Iverilog Compilation mode."
Expand All @@ -173,7 +178,6 @@ ARGS is a property list."
:buf verilog-ext-compile-iverilog-buf
:comp-mode verilog-ext-compile-iverilog-mode)

;;;###autoload (autoload 'verilog-ext-compile-verible-mode "verilog-ext-compile.el")
(verilog-ext-compile-define-mode verilog-ext-compile-verible-mode
:desc "Verible"
:docstring "Verible Compilation mode."
Expand All @@ -186,7 +190,6 @@ ARGS is a property list."
:buf verilog-ext-compile-verible-buf
:comp-mode verilog-ext-compile-verible-mode)

;;;###autoload (autoload 'verilog-ext-compile-slang-mode "verilog-ext-compile.el")
(verilog-ext-compile-define-mode verilog-ext-compile-slang-mode
:desc "Slang"
:docstring "Slang Compilation mode."
Expand All @@ -199,7 +202,6 @@ ARGS is a property list."
:buf verilog-ext-compile-slang-buf
:comp-mode verilog-ext-compile-slang-mode)

;;;###autoload (autoload 'verilog-ext-compile-svlint-mode "verilog-ext-compile.el")
(verilog-ext-compile-define-mode verilog-ext-compile-svlint-mode
:desc "Svlint"
:docstring "Svlint Compilation mode."
Expand All @@ -212,7 +214,6 @@ ARGS is a property list."
:buf verilog-ext-compile-svlint-buf
:comp-mode verilog-ext-compile-svlint-mode)

;;;###autoload (autoload 'verilog-ext-compile-surelog-mode "verilog-ext-compile.el")
(verilog-ext-compile-define-mode verilog-ext-compile-surelog-mode
:desc "Surelog"
:docstring "Surelog Compilation mode."
Expand Down
42 changes: 42 additions & 0 deletions verilog-ext-workspace.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
(require 'verilog-ext-tags)
(require 'verilog-ext-hierarchy)
(require 'verilog-ext-template)
(require 'verilog-ext-compile)

(defgroup verilog-ext-workspace nil
"Verilog-ext workspace."
Expand Down Expand Up @@ -69,6 +70,11 @@ If set to nil default to search for current project files."
:group 'verilog-ext-workspace
:type 'file)

(defcustom verilog-ext-workspace-compile-cmd nil
"The command used to perform compilation on the workspace."
:group 'verilog-ext-workspace
:type 'string)


(defun verilog-ext-workspace-root ()
"Return directory of current workspace root."
Expand Down Expand Up @@ -578,6 +584,42 @@ Compiles them with various verilog regexps."
(compile cmd)))


;;;; Compilation
;;;###autoload
(defun verilog-ext-workspace-compile ()
"Compile using command of `verilog-ext-workspace-compile-cmd'.
Depending on the command, different syntax highlight will be applied.
The function will detect any of the supported compilation error parsers
and will set the appropriate mode."
(interactive)
(unless verilog-ext-workspace-compile-cmd
(error "You first need to set `verilog-ext-workspace-compile-cmd'."))
(let* ((cmd-list (split-string verilog-ext-workspace-compile-cmd))
(cmd-args (cdr cmd-list))
(cmd-bin (car cmd-list))
(fn (pcase cmd-bin
("verilator" #'verilog-ext-compile-verilator)
("iverilog" #'verilog-ext-compile-iverilog)
("slang" #'verilog-ext-compile-slang)
("svlint" #'verilog-ext-compile-svlint)
("surelog" #'verilog-ext-compile-surelog)
(_ #'compile)))
(cmd-processed (cond (;; For svlint, make sure the -1 arg is present
(string= cmd-bin "svlint")
(if (member "-1" cmd-args)
verilog-ext-workspace-compile-cmd
(mapconcat #'identity (append `(,cmd-bin) '("-1") cmd-args) " ")))
;; For slang make sure that there is no colored output
((string= cmd-bin "slang")
(if (member "--color-diagnostics=false" cmd-args)
verilog-ext-workspace-compile-cmd
(mapconcat #'identity (append `(,cmd-bin) '("--color-diagnostics=false") cmd-args) " ")))
;; For the rest use the provided command
(t
verilog-ext-workspace-compile-cmd)))
(cmd (concat "cd " (verilog-ext-workspace-root) " && " cmd-processed)))
(funcall fn cmd)))

;;;; Jump-to-parent module
(defun verilog-ext-workspace-jump-to-parent-module ()
"Find current module/interface instantiations via `ag'/`rg' in current workspace."
Expand Down

0 comments on commit 2b689fd

Please sign in to comment.