blob: 08f7f252c681ecd8e3c04f0c6a75ca66fadd79b4 [file] [log] [blame]
Reid Spencer9dce2b32006-03-14 05:54:52 +00001;; Maintainer: The LLVM team, http://llvm.org/
Misha Brukmanbdb41192003-08-11 19:10:02 +00002;; Description: Major mode for TableGen description files (part of LLVM project)
Bill Wendling83870762007-12-19 06:20:05 +00003;; Updated: 2007-12-18
Bill Wendlingd4eeb802007-03-27 20:23:56 +00004
5(require 'comint)
6(require 'custom)
7(require 'ansi-color)
Misha Brukmanbdb41192003-08-11 19:10:02 +00008
9;; Create mode-specific tables.
Bill Wendlingd4eeb802007-03-27 20:23:56 +000010(defvar td-decorators-face 'td-decorators-face
11 "Face method decorators.")
12(make-face 'td-decorators-face)
13
Misha Brukmanbdb41192003-08-11 19:10:02 +000014(defvar tablegen-font-lock-keywords
Bill Wendlingd4eeb802007-03-27 20:23:56 +000015 (let ((kw (mapconcat 'identity
Bill Wendling041b3f82007-12-08 23:58:46 +000016 '("class" "defm" "def" "field" "include" "in"
Bill Wendlingd4eeb802007-03-27 20:23:56 +000017 "let" "multiclass")
18 "\\|"))
19 (type-kw (mapconcat 'identity
20 '("bit" "bits" "code" "dag" "int" "list" "string")
21 "\\|"))
22 )
23 (list
24 ;; Comments
Bill Wendling83870762007-12-19 06:20:05 +000025;; '("\/\/" . font-lock-comment-face)
Bill Wendlingd4eeb802007-03-27 20:23:56 +000026 ;; Strings
27 '("\"[^\"]+\"" . font-lock-string-face)
28 ;; Hex constants
Chris Lattnera9173802008-07-23 04:49:20 +000029 '("\\<0x[0-9A-Fa-f]+\\>" . font-lock-preprocessor-face)
Bill Wendlingd4eeb802007-03-27 20:23:56 +000030 ;; Binary constants
Chris Lattnera9173802008-07-23 04:49:20 +000031 '("\\<0b[01]+\\>" . font-lock-preprocessor-face)
Bill Wendlingd4eeb802007-03-27 20:23:56 +000032 ;; Integer literals
Chris Lattnera9173802008-07-23 04:49:20 +000033 '("\\<[-]?[0-9]+\\>" . font-lock-preprocessor-face)
Bill Wendlingd4eeb802007-03-27 20:23:56 +000034 ;; Floating point constants
Chris Lattnera9173802008-07-23 04:49:20 +000035 '("\\<[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\>" . font-lock-preprocessor-face)
Bill Wendlingd4eeb802007-03-27 20:23:56 +000036
37 '("^[ \t]*\\(@.+\\)" 1 'td-decorators-face)
38 ;; Keywords
39 (cons (concat "\\<\\(" kw "\\)\\>[ \n\t(]") 1)
40
41 ;; Type keywords
42 (cons (concat "\\<\\(" type-kw "\\)[ \n\t(]") 1)
43 ))
44 "Additional expressions to highlight in TableGen mode.")
45(put 'tablegen-mode 'font-lock-defaults '(tablegen-font-lock-keywords))
Misha Brukmanbdb41192003-08-11 19:10:02 +000046
47;; ---------------------- Syntax table ---------------------------
48;; Shamelessly ripped from jasmin.el
Bill Wendling041b3f82007-12-08 23:58:46 +000049;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el
Misha Brukmanbdb41192003-08-11 19:10:02 +000050
Bill Wendling83870762007-12-19 06:20:05 +000051(defvar tablegen-mode-syntax-table nil
52 "Syntax table used in `tablegen-mode' buffers.")
53(when (not tablegen-mode-syntax-table)
54 (setq tablegen-mode-syntax-table (make-syntax-table))
55 ;; whitespace (` ')
56 (modify-syntax-entry ?\ " " tablegen-mode-syntax-table)
57 (modify-syntax-entry ?\t " " tablegen-mode-syntax-table)
58 (modify-syntax-entry ?\r " " tablegen-mode-syntax-table)
59 (modify-syntax-entry ?\n " " tablegen-mode-syntax-table)
60 (modify-syntax-entry ?\f " " tablegen-mode-syntax-table)
61 ;; word constituents (`w')
62 (modify-syntax-entry ?\% "w" tablegen-mode-syntax-table)
63 (modify-syntax-entry ?\_ "w" tablegen-mode-syntax-table)
64 ;; comments
65 (modify-syntax-entry ?/ ". 124b" tablegen-mode-syntax-table)
66 (modify-syntax-entry ?* ". 23" tablegen-mode-syntax-table)
67 (modify-syntax-entry ?\n "> b" tablegen-mode-syntax-table)
68 ;; open paren (`(')
69 (modify-syntax-entry ?\( "(" tablegen-mode-syntax-table)
70 (modify-syntax-entry ?\[ "(" tablegen-mode-syntax-table)
71 (modify-syntax-entry ?\{ "(" tablegen-mode-syntax-table)
72 (modify-syntax-entry ?\< "(" tablegen-mode-syntax-table)
73 ;; close paren (`)')
74 (modify-syntax-entry ?\) ")" tablegen-mode-syntax-table)
75 (modify-syntax-entry ?\] ")" tablegen-mode-syntax-table)
76 (modify-syntax-entry ?\} ")" tablegen-mode-syntax-table)
77 (modify-syntax-entry ?\> ")" tablegen-mode-syntax-table)
78 ;; string quote ('"')
79 (modify-syntax-entry ?\" "\"" tablegen-mode-syntax-table)
80 )
Misha Brukmanbdb41192003-08-11 19:10:02 +000081
82;; --------------------- Abbrev table -----------------------------
83
84(defvar tablegen-mode-abbrev-table nil
85 "Abbrev table used while in TableGen mode.")
86(define-abbrev-table 'tablegen-mode-abbrev-table ())
87
88(defvar tablegen-mode-hook nil)
89(defvar tablegen-mode-map nil) ; Create a mode-specific keymap.
90
91(if (not tablegen-mode-map)
92 () ; Do not change the keymap if it is already set up.
93 (setq tablegen-mode-map (make-sparse-keymap))
Bill Wendling041b3f82007-12-08 23:58:46 +000094 (define-key tablegen-mode-map "\t" 'tab-to-tab-stop)
Misha Brukmanbdb41192003-08-11 19:10:02 +000095 (define-key tablegen-mode-map "\es" 'center-line)
96 (define-key tablegen-mode-map "\eS" 'center-paragraph))
97
Misha Brukmanbdb41192003-08-11 19:10:02 +000098(defun tablegen-mode ()
99 "Major mode for editing TableGen description files.
100 \\{tablegen-mode-map}
101 Runs tablegen-mode-hook on startup."
102 (interactive)
103 (kill-all-local-variables)
Bill Wendling83870762007-12-19 06:20:05 +0000104 (use-local-map tablegen-mode-map) ; Provides the local keymap.
Bill Wendling041b3f82007-12-08 23:58:46 +0000105 (make-local-variable 'font-lock-defaults)
Bill Wendling83870762007-12-19 06:20:05 +0000106 (setq major-mode 'tablegen-mode ; This is how describe-mode
107 ; finds the doc string to print.
108 mode-name "TableGen" ; This name goes into the modeline.
109 local-abbrev-table tablegen-mode-abbrev-table
110 font-lock-defaults `(tablegen-font-lock-keywords)
111 require-final-newline t
112 )
Misha Brukmanbdb41192003-08-11 19:10:02 +0000113
Misha Brukmanbdb41192003-08-11 19:10:02 +0000114 (set-syntax-table tablegen-mode-syntax-table)
Bill Wendling83870762007-12-19 06:20:05 +0000115 (run-hooks 'tablegen-mode-hook)) ; Finally, this permits the user to
116 ; customize the mode with a hook.
Misha Brukmanbdb41192003-08-11 19:10:02 +0000117
118;; Associate .td files with tablegen-mode
119(setq auto-mode-alist (append '(("\\.td$" . tablegen-mode)) auto-mode-alist))
120
121(provide 'tablegen-mode)
122;; end of tablegen-mode.el