Remove unused #include.
[oota-llvm.git] / utils / emacs / llvm-mode.el
1 ;; Maintainer:  The LLVM team, http://llvm.org/
2 ;; Description: Major mode for the LLVM assembler language.
3 ;; Updated:     2007-09-19
4
5 ;; Create mode-specific tables.
6 (defvar llvm-mode-syntax-table nil
7   "Syntax table used while in LLVM mode.")
8 (defvar llvm-font-lock-keywords
9   (list
10    ;; Comments
11    '(";.*" . font-lock-comment-face)
12    ;; Variables
13    '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face)
14    ;; Labels
15    '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face)
16    ;; Strings
17    '("\"[^\"]+\"" . font-lock-string-face)
18    ;; Unnamed variable slots
19    '("%[-]?[0-9]+" . font-lock-variable-name-face)
20    ;; Types
21    `(,(regexp-opt '("void" "i[0-9]+" "float" "double" "type" "label" "opaque") 'words) . font-lock-type-face)
22    ;; Integer literals
23    '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)
24    ;; Floating point constants
25    '("\\b[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?\\b" . font-lock-preprocessor-face)
26    ;; Hex constants
27    '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)
28    ;; Keywords
29    `(,(regexp-opt '("begin" "end" "true" "false" "zeroinitializer" "declare"
30                     "define" "global" "constant" "const" "internal" "linkonce" "linkonce_odr"
31                     "weak" "weak_odr" "appending" "uninitialized" "implementation" "..."
32                     "null" "undef" "to" "except" "not" "target" "endian" "little" "big"
33                     "pointersize" "volatile" "fastcc" "coldcc" "cc") 'words) . font-lock-keyword-face)
34    ;; Arithmetic and Logical Operators
35    `(,(regexp-opt '("add" "sub" "mul" "div" "rem" "and" "or" "xor"
36                     "setne" "seteq" "setlt" "setgt" "setle" "setge") 'words) . font-lock-keyword-face)
37    ;; Floating-point operators
38    `(,(regexp-opt '("fadd" "fsub" "fmul" "fdiv" "frem") 'words) . font-lock-keyword-face)
39    ;; Special instructions
40    `(,(regexp-opt '("phi" "tail" "call" "cast" "select" "to" "shl" "shr" "fcmp" "icmp" "vaarg" "vanext") 'words) . font-lock-keyword-face)
41    ;; Control instructions
42    `(,(regexp-opt '("ret" "br" "switch" "invoke" "unwind" "unreachable") 'words) . font-lock-keyword-face)
43    ;; Memory operators
44    `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr") 'words) . font-lock-keyword-face)
45    )
46   "Syntax highlighting for LLVM"
47   )
48
49 ;; ---------------------- Syntax table ---------------------------
50 ;; Shamelessly ripped from jasmin.el
51 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html
52
53 (if (not llvm-mode-syntax-table)
54     (progn
55       (setq llvm-mode-syntax-table (make-syntax-table))
56       (mapcar (function (lambda (n)
57                           (modify-syntax-entry (aref n 0)
58                                                (aref n 1)
59                                                llvm-mode-syntax-table)))
60               '(
61                 ;; whitespace (` ')
62                 [?\^m " "]
63                 [?\f  " "]
64                 [?\n  " "]
65                 [?\t  " "]
66                 [?\   " "]
67                 ;; word constituents (`w')
68                 ;;[?<  "w"]
69                 ;;[?>  "w"]
70                 [?\%  "w"]
71                 ;;[?_  "w  "]
72                 ;; comments
73                 [?\;  "< "]
74                 [?\n  "> "]
75                 ;;[?\r  "> "]
76                 ;;[?\^m "> "]
77                 ;; symbol constituents (`_')
78                 ;; punctuation (`.')
79                 ;; open paren (`(')
80                 [?\( "("]
81                 [?\[ "("]
82                 [?\{ "("]
83                 ;; close paren (`)')
84                 [?\) ")"]
85                 [?\] ")"]
86                 [?\} ")"]
87                 ;; string quote ('"')
88                 [?\" "\""]
89                 ))))
90
91 ;; --------------------- Abbrev table -----------------------------
92
93 (defvar llvm-mode-abbrev-table nil
94   "Abbrev table used while in LLVM mode.")
95 (define-abbrev-table 'llvm-mode-abbrev-table ())
96
97 (defvar llvm-mode-hook nil)
98 (defvar llvm-mode-map nil)   ; Create a mode-specific keymap.
99
100 (if (not llvm-mode-map)
101     ()  ; Do not change the keymap if it is already set up.
102   (setq llvm-mode-map (make-sparse-keymap))
103   (define-key llvm-mode-map "\t" 'tab-to-tab-stop)
104   (define-key llvm-mode-map "\es" 'center-line)
105   (define-key llvm-mode-map "\eS" 'center-paragraph))
106
107
108 (defun llvm-mode ()
109   "Major mode for editing LLVM source files.
110   \\{llvm-mode-map}
111   Runs llvm-mode-hook on startup."
112   (interactive)
113   (kill-all-local-variables)
114   (use-local-map llvm-mode-map)         ; Provides the local keymap.
115   (setq major-mode 'llvm-mode)
116
117   (make-local-variable 'font-lock-defaults)
118   (setq major-mode 'llvm-mode           ; This is how describe-mode
119                                         ;   finds the doc string to print.
120   mode-name "LLVM"                      ; This name goes into the modeline.
121   font-lock-defaults `(llvm-font-lock-keywords))
122
123   (setq local-abbrev-table llvm-mode-abbrev-table)
124   (set-syntax-table llvm-mode-syntax-table)
125   (setq comment-start ";")
126   (run-hooks 'llvm-mode-hook))          ; Finally, this permits the user to
127                                         ;   customize the mode with a hook.
128
129 ;; Associate .ll files with llvm-mode
130 (setq auto-mode-alist
131    (append '(("\\.ll$" . llvm-mode)) auto-mode-alist))
132
133 (provide 'llvm-mode)
134 ;; end of llvm-mode.el