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