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