2015-01-07 23:52:51 +08:00
|
|
|
;;; tablegen-mode.el --- Major mode for TableGen description files (part of LLVM project)
|
|
|
|
|
2006-03-14 13:54:52 +08:00
|
|
|
;; Maintainer: The LLVM team, http://llvm.org/
|
2015-01-07 23:52:51 +08:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; A major mode for TableGen description files in LLVM.
|
2007-03-28 04:23:56 +08:00
|
|
|
|
|
|
|
(require 'comint)
|
|
|
|
(require 'custom)
|
|
|
|
(require 'ansi-color)
|
2003-08-12 03:10:02 +08:00
|
|
|
|
|
|
|
;; Create mode-specific tables.
|
2015-01-07 23:52:51 +08:00
|
|
|
;;; Code:
|
|
|
|
|
2007-03-28 04:23:56 +08:00
|
|
|
(defvar td-decorators-face 'td-decorators-face
|
|
|
|
"Face method decorators.")
|
|
|
|
(make-face 'td-decorators-face)
|
|
|
|
|
2003-08-12 03:10:02 +08:00
|
|
|
(defvar tablegen-font-lock-keywords
|
2010-09-19 11:44:22 +08:00
|
|
|
(let ((kw (regexp-opt '("class" "defm" "def" "field" "include" "in"
|
2020-01-14 21:12:16 +08:00
|
|
|
"let" "multiclass" "foreach" "if" "then" "else"
|
|
|
|
"defvar" "defset")
|
2010-09-19 11:44:22 +08:00
|
|
|
'words))
|
|
|
|
(type-kw (regexp-opt '("bit" "bits" "code" "dag" "int" "list" "string")
|
|
|
|
'words))
|
2007-03-28 04:23:56 +08:00
|
|
|
)
|
|
|
|
(list
|
|
|
|
;; Comments
|
2007-12-19 14:20:05 +08:00
|
|
|
;; '("\/\/" . font-lock-comment-face)
|
2007-03-28 04:23:56 +08:00
|
|
|
;; Strings
|
|
|
|
'("\"[^\"]+\"" . font-lock-string-face)
|
|
|
|
;; Hex constants
|
2008-07-23 12:49:20 +08:00
|
|
|
'("\\<0x[0-9A-Fa-f]+\\>" . font-lock-preprocessor-face)
|
2007-03-28 04:23:56 +08:00
|
|
|
;; Binary constants
|
2008-07-23 12:49:20 +08:00
|
|
|
'("\\<0b[01]+\\>" . font-lock-preprocessor-face)
|
2007-03-28 04:23:56 +08:00
|
|
|
;; Integer literals
|
2008-07-23 12:49:20 +08:00
|
|
|
'("\\<[-]?[0-9]+\\>" . font-lock-preprocessor-face)
|
2007-03-28 04:23:56 +08:00
|
|
|
;; Floating point constants
|
2008-07-23 12:49:20 +08:00
|
|
|
'("\\<[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\>" . font-lock-preprocessor-face)
|
2007-03-28 04:23:56 +08:00
|
|
|
|
|
|
|
'("^[ \t]*\\(@.+\\)" 1 'td-decorators-face)
|
|
|
|
;; Keywords
|
2019-09-26 02:16:02 +08:00
|
|
|
kw
|
2007-03-28 04:23:56 +08:00
|
|
|
;; Type keywords
|
2019-09-26 02:16:02 +08:00
|
|
|
type-kw
|
2007-03-28 04:23:56 +08:00
|
|
|
))
|
|
|
|
"Additional expressions to highlight in TableGen mode.")
|
|
|
|
(put 'tablegen-mode 'font-lock-defaults '(tablegen-font-lock-keywords))
|
2003-08-12 03:10:02 +08:00
|
|
|
|
|
|
|
;; ---------------------- Syntax table ---------------------------
|
|
|
|
|
2007-12-19 14:20:05 +08:00
|
|
|
(defvar tablegen-mode-syntax-table nil
|
|
|
|
"Syntax table used in `tablegen-mode' buffers.")
|
|
|
|
(when (not tablegen-mode-syntax-table)
|
|
|
|
(setq tablegen-mode-syntax-table (make-syntax-table))
|
|
|
|
;; whitespace (` ')
|
|
|
|
(modify-syntax-entry ?\ " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\t " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\r " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\n " " tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\f " " tablegen-mode-syntax-table)
|
|
|
|
;; word constituents (`w')
|
|
|
|
(modify-syntax-entry ?\% "w" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\_ "w" tablegen-mode-syntax-table)
|
|
|
|
;; comments
|
|
|
|
(modify-syntax-entry ?/ ". 124b" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?* ". 23" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\n "> b" tablegen-mode-syntax-table)
|
|
|
|
;; open paren (`(')
|
|
|
|
(modify-syntax-entry ?\( "(" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\[ "(" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\{ "(" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\< "(" tablegen-mode-syntax-table)
|
|
|
|
;; close paren (`)')
|
|
|
|
(modify-syntax-entry ?\) ")" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\] ")" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\} ")" tablegen-mode-syntax-table)
|
|
|
|
(modify-syntax-entry ?\> ")" tablegen-mode-syntax-table)
|
|
|
|
;; string quote ('"')
|
|
|
|
(modify-syntax-entry ?\" "\"" tablegen-mode-syntax-table)
|
|
|
|
)
|
2003-08-12 03:10:02 +08:00
|
|
|
|
|
|
|
;; --------------------- Abbrev table -----------------------------
|
|
|
|
|
|
|
|
(defvar tablegen-mode-abbrev-table nil
|
|
|
|
"Abbrev table used while in TableGen mode.")
|
|
|
|
(define-abbrev-table 'tablegen-mode-abbrev-table ())
|
|
|
|
|
|
|
|
(defvar tablegen-mode-hook nil)
|
|
|
|
(defvar tablegen-mode-map nil) ; Create a mode-specific keymap.
|
|
|
|
|
|
|
|
(if (not tablegen-mode-map)
|
|
|
|
() ; Do not change the keymap if it is already set up.
|
|
|
|
(setq tablegen-mode-map (make-sparse-keymap))
|
2007-12-09 07:58:46 +08:00
|
|
|
(define-key tablegen-mode-map "\t" 'tab-to-tab-stop)
|
2003-08-12 03:10:02 +08:00
|
|
|
(define-key tablegen-mode-map "\es" 'center-line)
|
|
|
|
(define-key tablegen-mode-map "\eS" 'center-paragraph))
|
|
|
|
|
2015-01-07 23:52:51 +08:00
|
|
|
;;;###autoload
|
2003-08-12 03:10:02 +08:00
|
|
|
(defun tablegen-mode ()
|
|
|
|
"Major mode for editing TableGen description files.
|
2015-01-07 23:52:51 +08:00
|
|
|
\\{tablegen-mode-map}
|
|
|
|
Runs `tablegen-mode-hook' on startup."
|
2003-08-12 03:10:02 +08:00
|
|
|
(interactive)
|
|
|
|
(kill-all-local-variables)
|
2007-12-19 14:20:05 +08:00
|
|
|
(use-local-map tablegen-mode-map) ; Provides the local keymap.
|
2007-12-09 07:58:46 +08:00
|
|
|
(make-local-variable 'font-lock-defaults)
|
2007-12-19 14:20:05 +08:00
|
|
|
(setq major-mode 'tablegen-mode ; This is how describe-mode
|
|
|
|
; finds the doc string to print.
|
|
|
|
mode-name "TableGen" ; This name goes into the modeline.
|
|
|
|
local-abbrev-table tablegen-mode-abbrev-table
|
|
|
|
font-lock-defaults `(tablegen-font-lock-keywords)
|
|
|
|
require-final-newline t
|
|
|
|
)
|
2003-08-12 03:10:02 +08:00
|
|
|
|
|
|
|
(set-syntax-table tablegen-mode-syntax-table)
|
2009-10-21 13:07:57 +08:00
|
|
|
(make-local-variable 'comment-start)
|
|
|
|
(setq comment-start "//")
|
2014-06-24 09:42:29 +08:00
|
|
|
(setq indent-tabs-mode nil)
|
2007-12-19 14:20:05 +08:00
|
|
|
(run-hooks 'tablegen-mode-hook)) ; Finally, this permits the user to
|
|
|
|
; customize the mode with a hook.
|
2003-08-12 03:10:02 +08:00
|
|
|
|
|
|
|
;; Associate .td files with tablegen-mode
|
2015-01-07 23:52:51 +08:00
|
|
|
;;;###autoload
|
|
|
|
(add-to-list 'auto-mode-alist (cons (purecopy "\\.td\\'") 'tablegen-mode))
|
2003-08-12 03:10:02 +08:00
|
|
|
|
|
|
|
(provide 'tablegen-mode)
|
2015-01-07 23:52:51 +08:00
|
|
|
|
|
|
|
;;; tablegen-mode.el ends here
|