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