1 ;; Maintainer: The LLVM team, http://llvm.org/
2 ;; Description: Major mode for the LLVM assembler language.
5 ;; Create mode-specific tables.
6 (defvar llvm-mode-syntax-table nil
7 "Syntax table used while in LLVM mode.")
9 (defvar llvm-font-lock-keywords
12 '(";.*" . font-lock-comment-face)
14 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face)
16 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face)
18 '("\"[^\"]+\"" . font-lock-string-face)
19 ;; Unnamed variable slots
20 '("%[-]?[0-9]+" . font-lock-variable-name-face)
22 '("[-]?[0-9]+" . font-lock-preprocessor-face)
23 ;; Floating point constants
24 '("[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?" . font-lock-preprocessor-face)
26 '("0x[0-9A-Fa-f]+" . font-lock-preprocessor-face)
28 '("begin\\|end\\|true\\|false\\|zeroinitializer\\|declare\\|global\\|constant\\|const\\|internal\\|linkonce\\|weak\\|appending\\|uninitialized\\|implementation\\|\\.\\.\\.\\|null\\|undef\\|to\\|except\\|not\\|target\\|endian\\|little\\|big\\|pointersize\\|deplibs\\|volatile\\|fastcc\\|coldcc\\|cc" . font-lock-keyword-face)
30 '("void\\|bool\\|sbyte\\|ubyte\\|u?short\\|u?int\\|u?long\\|float\\|double\\|type\\|label\\|opaque" . font-lock-type-face)
31 ;; Arithmetic and Logical Operators
32 '("add\\|sub\\|mul\\|div\\|rem\\|and\\|or\\|xor\\|set\\(ne\\|eq\\|lt\\|gt\\|le\\|ge\\)" . font-lock-keyword-face)
33 ;; Special instructions
34 '("phi\\|tail\\|call\\|cast\\|select\\|to\\|shl\\|shr\\|vaarg\\|vanext" . font-lock-keyword-face)
35 ;; Control instructions
36 '("ret\\|br\\|switch\\|invoke\\|unwind\\|unreachable" . font-lock-keyword-face)
38 '("malloc\\|alloca\\|free\\|load\\|store\\|getelementptr" . font-lock-keyword-face)
40 "Syntax highlighting for LLVM"
43 ;; ---------------------- Syntax table ---------------------------
44 ;; Shamelessly ripped from jasmin.el
45 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html
47 (if (not llvm-mode-syntax-table)
49 (setq llvm-mode-syntax-table (make-syntax-table))
50 (mapcar (function (lambda (n)
51 (modify-syntax-entry (aref n 0)
53 llvm-mode-syntax-table)))
61 ;; word constituents (`w')
71 ;; symbol constituents (`_')
85 ;; --------------------- Abbrev table -----------------------------
87 (defvar llvm-mode-abbrev-table nil
88 "Abbrev table used while in LLVM mode.")
89 (define-abbrev-table 'llvm-mode-abbrev-table ())
91 (defvar llvm-mode-hook nil)
92 (defvar llvm-mode-map nil) ; Create a mode-specific keymap.
94 (if (not llvm-mode-map)
95 () ; Do not change the keymap if it is already set up.
96 (setq llvm-mode-map (make-sparse-keymap))
97 (define-key llvm-mode-map "\t" 'tab-to-tab-stop)
98 (define-key llvm-mode-map "\es" 'center-line)
99 (define-key llvm-mode-map "\eS" 'center-paragraph))
103 "Major mode for editing LLVM source files.
105 Runs llvm-mode-hook on startup."
107 (kill-all-local-variables)
108 (use-local-map llvm-mode-map) ; Provides the local keymap.
109 (setq major-mode 'llvm-mode)
111 (make-local-variable 'font-lock-defaults)
112 (setq major-mode 'llvm-mode ; This is how describe-mode
113 ; finds the doc string to print.
114 mode-name "LLVM" ; This name goes into the modeline.
115 font-lock-defaults `(llvm-font-lock-keywords))
117 (setq local-abbrev-table llvm-mode-abbrev-table)
118 (set-syntax-table llvm-mode-syntax-table)
119 (run-hooks 'llvm-mode-hook)) ; Finally, this permits the user to
120 ; customize the mode with a hook.
122 ;; Associate .ll files with llvm-mode
123 (setq auto-mode-alist
124 (append '(("\\.ll$" . llvm-mode) ("\\.llx$" . llvm-mode)) auto-mode-alist))
127 ;; end of llvm-mode.el