xref: /aosp_15_r20/external/llvm/utils/emacs/tablegen-mode.el (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker;;; tablegen-mode.el --- Major mode for TableGen description files (part of LLVM project)
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker;; Maintainer:  The LLVM team, http://llvm.org/
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker;;; Commentary:
6*9880d681SAndroid Build Coastguard Worker;; A major mode for TableGen description files in LLVM.
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker(require 'comint)
9*9880d681SAndroid Build Coastguard Worker(require 'custom)
10*9880d681SAndroid Build Coastguard Worker(require 'ansi-color)
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Worker;; Create mode-specific tables.
13*9880d681SAndroid Build Coastguard Worker;;; Code:
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Worker(defvar td-decorators-face 'td-decorators-face
16*9880d681SAndroid Build Coastguard Worker  "Face method decorators.")
17*9880d681SAndroid Build Coastguard Worker(make-face 'td-decorators-face)
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker(defvar tablegen-font-lock-keywords
20*9880d681SAndroid Build Coastguard Worker  (let ((kw (regexp-opt '("class" "defm" "def" "field" "include" "in"
21*9880d681SAndroid Build Coastguard Worker                         "let" "multiclass" "foreach")
22*9880d681SAndroid Build Coastguard Worker                        'words))
23*9880d681SAndroid Build Coastguard Worker        (type-kw (regexp-opt '("bit" "bits" "code" "dag" "int" "list" "string")
24*9880d681SAndroid Build Coastguard Worker                             'words))
25*9880d681SAndroid Build Coastguard Worker        )
26*9880d681SAndroid Build Coastguard Worker    (list
27*9880d681SAndroid Build Coastguard Worker     ;; Comments
28*9880d681SAndroid Build Coastguard Worker;;     '("\/\/" . font-lock-comment-face)
29*9880d681SAndroid Build Coastguard Worker     ;; Strings
30*9880d681SAndroid Build Coastguard Worker     '("\"[^\"]+\"" . font-lock-string-face)
31*9880d681SAndroid Build Coastguard Worker     ;; Hex constants
32*9880d681SAndroid Build Coastguard Worker     '("\\<0x[0-9A-Fa-f]+\\>" . font-lock-preprocessor-face)
33*9880d681SAndroid Build Coastguard Worker     ;; Binary constants
34*9880d681SAndroid Build Coastguard Worker     '("\\<0b[01]+\\>" . font-lock-preprocessor-face)
35*9880d681SAndroid Build Coastguard Worker     ;; Integer literals
36*9880d681SAndroid Build Coastguard Worker     '("\\<[-]?[0-9]+\\>" . font-lock-preprocessor-face)
37*9880d681SAndroid Build Coastguard Worker     ;; Floating point constants
38*9880d681SAndroid Build Coastguard Worker     '("\\<[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\>" . font-lock-preprocessor-face)
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker     '("^[ \t]*\\(@.+\\)" 1 'td-decorators-face)
41*9880d681SAndroid Build Coastguard Worker     ;; Keywords
42*9880d681SAndroid Build Coastguard Worker     (cons (concat kw "[ \n\t(]") 1)
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker     ;; Type keywords
45*9880d681SAndroid Build Coastguard Worker     (cons (concat type-kw "[ \n\t(]") 1)
46*9880d681SAndroid Build Coastguard Worker     ))
47*9880d681SAndroid Build Coastguard Worker  "Additional expressions to highlight in TableGen mode.")
48*9880d681SAndroid Build Coastguard Worker(put 'tablegen-mode 'font-lock-defaults '(tablegen-font-lock-keywords))
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Worker;; ---------------------- Syntax table ---------------------------
51*9880d681SAndroid Build Coastguard Worker;; Shamelessly ripped from jasmin.el
52*9880d681SAndroid Build Coastguard Worker;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker(defvar tablegen-mode-syntax-table nil
55*9880d681SAndroid Build Coastguard Worker  "Syntax table used in `tablegen-mode' buffers.")
56*9880d681SAndroid Build Coastguard Worker(when (not tablegen-mode-syntax-table)
57*9880d681SAndroid Build Coastguard Worker  (setq tablegen-mode-syntax-table (make-syntax-table))
58*9880d681SAndroid Build Coastguard Worker  ;; whitespace (` ')
59*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\   " "      tablegen-mode-syntax-table)
60*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\t  " "      tablegen-mode-syntax-table)
61*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\r  " "      tablegen-mode-syntax-table)
62*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\n  " "      tablegen-mode-syntax-table)
63*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\f  " "      tablegen-mode-syntax-table)
64*9880d681SAndroid Build Coastguard Worker  ;; word constituents (`w')
65*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\%  "w"      tablegen-mode-syntax-table)
66*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\_  "w"      tablegen-mode-syntax-table)
67*9880d681SAndroid Build Coastguard Worker  ;; comments
68*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?/   ". 124b" tablegen-mode-syntax-table)
69*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?*   ". 23"   tablegen-mode-syntax-table)
70*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\n  "> b"    tablegen-mode-syntax-table)
71*9880d681SAndroid Build Coastguard Worker  ;; open paren (`(')
72*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\(  "("      tablegen-mode-syntax-table)
73*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\[  "("      tablegen-mode-syntax-table)
74*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\{  "("      tablegen-mode-syntax-table)
75*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\<  "("      tablegen-mode-syntax-table)
76*9880d681SAndroid Build Coastguard Worker  ;; close paren (`)')
77*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\)  ")"      tablegen-mode-syntax-table)
78*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\]  ")"      tablegen-mode-syntax-table)
79*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\}  ")"      tablegen-mode-syntax-table)
80*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\>  ")"      tablegen-mode-syntax-table)
81*9880d681SAndroid Build Coastguard Worker  ;; string quote ('"')
82*9880d681SAndroid Build Coastguard Worker  (modify-syntax-entry ?\"  "\""     tablegen-mode-syntax-table)
83*9880d681SAndroid Build Coastguard Worker  )
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Worker;; --------------------- Abbrev table -----------------------------
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Worker(defvar tablegen-mode-abbrev-table nil
88*9880d681SAndroid Build Coastguard Worker  "Abbrev table used while in TableGen mode.")
89*9880d681SAndroid Build Coastguard Worker(define-abbrev-table 'tablegen-mode-abbrev-table ())
90*9880d681SAndroid Build Coastguard Worker
91*9880d681SAndroid Build Coastguard Worker(defvar tablegen-mode-hook nil)
92*9880d681SAndroid Build Coastguard Worker(defvar tablegen-mode-map nil)   ; Create a mode-specific keymap.
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Worker(if (not tablegen-mode-map)
95*9880d681SAndroid Build Coastguard Worker    ()  ; Do not change the keymap if it is already set up.
96*9880d681SAndroid Build Coastguard Worker  (setq tablegen-mode-map (make-sparse-keymap))
97*9880d681SAndroid Build Coastguard Worker  (define-key tablegen-mode-map "\t"  'tab-to-tab-stop)
98*9880d681SAndroid Build Coastguard Worker  (define-key tablegen-mode-map "\es" 'center-line)
99*9880d681SAndroid Build Coastguard Worker  (define-key tablegen-mode-map "\eS" 'center-paragraph))
100*9880d681SAndroid Build Coastguard Worker
101*9880d681SAndroid Build Coastguard Worker;;;###autoload
102*9880d681SAndroid Build Coastguard Worker(defun tablegen-mode ()
103*9880d681SAndroid Build Coastguard Worker  "Major mode for editing TableGen description files.
104*9880d681SAndroid Build Coastguard Worker\\{tablegen-mode-map}
105*9880d681SAndroid Build Coastguard Worker  Runs `tablegen-mode-hook' on startup."
106*9880d681SAndroid Build Coastguard Worker  (interactive)
107*9880d681SAndroid Build Coastguard Worker  (kill-all-local-variables)
108*9880d681SAndroid Build Coastguard Worker  (use-local-map tablegen-mode-map)      ; Provides the local keymap.
109*9880d681SAndroid Build Coastguard Worker  (make-local-variable 'font-lock-defaults)
110*9880d681SAndroid Build Coastguard Worker  (setq major-mode 'tablegen-mode        ; This is how describe-mode
111*9880d681SAndroid Build Coastguard Worker                                         ;   finds the doc string to print.
112*9880d681SAndroid Build Coastguard Worker	mode-name             "TableGen" ; This name goes into the modeline.
113*9880d681SAndroid Build Coastguard Worker        local-abbrev-table    tablegen-mode-abbrev-table
114*9880d681SAndroid Build Coastguard Worker	font-lock-defaults    `(tablegen-font-lock-keywords)
115*9880d681SAndroid Build Coastguard Worker	require-final-newline t
116*9880d681SAndroid Build Coastguard Worker        )
117*9880d681SAndroid Build Coastguard Worker
118*9880d681SAndroid Build Coastguard Worker  (set-syntax-table tablegen-mode-syntax-table)
119*9880d681SAndroid Build Coastguard Worker  (make-local-variable 'comment-start)
120*9880d681SAndroid Build Coastguard Worker  (setq comment-start "//")
121*9880d681SAndroid Build Coastguard Worker  (setq indent-tabs-mode nil)
122*9880d681SAndroid Build Coastguard Worker  (run-hooks 'tablegen-mode-hook))       ; Finally, this permits the user to
123*9880d681SAndroid Build Coastguard Worker                                         ;   customize the mode with a hook.
124*9880d681SAndroid Build Coastguard Worker
125*9880d681SAndroid Build Coastguard Worker;; Associate .td files with tablegen-mode
126*9880d681SAndroid Build Coastguard Worker;;;###autoload
127*9880d681SAndroid Build Coastguard Worker(add-to-list 'auto-mode-alist (cons (purecopy "\\.td\\'")  'tablegen-mode))
128*9880d681SAndroid Build Coastguard Worker
129*9880d681SAndroid Build Coastguard Worker(provide 'tablegen-mode)
130*9880d681SAndroid Build Coastguard Worker
131*9880d681SAndroid Build Coastguard Worker;;; tablegen-mode.el ends here
132