1 ;; Author: Misha Brukman <brukman@cs.uiuc.edu>
3 ;; Major mode for the LLVM assembler language.
8 ;; Create mode-specific tables.
9 (defvar llvm-mode-syntax-table nil
10 "Syntax table used while in LLVM mode.")
12 (defvar llvm-font-lock-keywords
15 '(";.*" . font-lock-comment-face)
17 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face)
19 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face)
21 '("\"[^\"]+\"" . font-lock-string-face)
22 ;; Unnamed variable slots
23 '("%[-]?[0-9]+" . font-lock-variable-name-face)
25 '("[-]?[0-9]+" . font-lock-preprocessor-face)
26 ;; Floating point constants
27 '("[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?" . font-lock-preprocessor-face)
29 '("0x[0-9A-Fa-f]+" . font-lock-preprocessor-face)
31 '("begin\\|end\\|true\\|false\\|declare\\|global\\|constant\\|const\\|internal\\|linkonce\\|appending\\|uninitialized\\|implementation\\|\\.\\.\\.\\|null\\|to\\|except\\|not" . font-lock-keyword-face)
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" . font-lock-keyword-face)
38 ;; Control instructions
39 '("ret\\|br\\|switch\\|invoke" . font-lock-keyword-face)
41 '("malloc\\|alloca\\|free\\|load\\|store\\|getelementptr" . font-lock-keyword-face)
43 "Syntax highlighting for LLVM"
46 ;; ---------------------- Syntax table ---------------------------
47 ;; Shamelessly ripped from jasmin.el
48 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html
50 (if (not llvm-mode-syntax-table)
52 (setq llvm-mode-syntax-table (make-syntax-table))
53 (mapcar (function (lambda (n)
54 (modify-syntax-entry (aref n 0)
56 llvm-mode-syntax-table)))
64 ;; word constituents (`w')
74 ;; symbol constituents (`_')
88 ;; --------------------- Abbrev table -----------------------------
90 (defvar llvm-mode-abbrev-table nil
91 "Abbrev table used while in LLVM mode.")
92 (define-abbrev-table 'llvm-mode-abbrev-table ())
94 (defvar llvm-mode-hook nil)
95 (defvar llvm-mode-map nil) ; Create a mode-specific keymap.
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))
106 "Major mode for editing LLVM source files.
108 Runs llvm-mode-hook on startup."
110 (kill-all-local-variables)
111 (use-local-map llvm-mode-map) ; Provides the local keymap.
112 (setq major-mode 'llvm-mode)
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))
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.
125 ;; Associate .ll files with llvm-mode
126 (setq auto-mode-alist
127 (append '(("\\.ll$" . llvm-mode)) auto-mode-alist))
130 ;; end of llvm-mode.el