blob: 61aec9894a1056deacc1a21b6c18778a1b6d0d04 [file] [log] [blame]
Misha Brukman4817a5e2003-06-03 00:59:24 +00001;; Maintainer: The LLVM team, http://llvm.cs.uiuc.edu/
Misha Brukmanf77ed7a2003-06-03 00:57:41 +00002;; Description: Major mode for the LLVM assembler language.
3;; Updated: 2003-06-02
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)
21 ;; Integer literals
22 '("[-]?[0-9]+" . font-lock-preprocessor-face)
23 ;; Floating point constants
24 '("[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?" . font-lock-preprocessor-face)
25 ;; Hex constants
26 '("0x[0-9A-Fa-f]+" . font-lock-preprocessor-face)
27 ;; Keywords
Chris Lattneraf26d3e2005-05-13 20:40:52 +000028 '("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)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000029 ;; Types
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
Chris Lattner653488d2005-05-06 06:07:34 +000034 '("phi\\|tail\\|call\\|cast\\|select\\|to\\|shl\\|shr\\|vaarg\\|vanext" . font-lock-keyword-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000035 ;; Control instructions
Chris Lattner4c554c52004-10-16 18:24:35 +000036 '("ret\\|br\\|switch\\|invoke\\|unwind\\|unreachable" . font-lock-keyword-face)
Misha Brukmand9b11cf2002-10-09 00:30:20 +000037 ;; Memory operators
38 '("malloc\\|alloca\\|free\\|load\\|store\\|getelementptr" . font-lock-keyword-face)
39 )
40 "Syntax highlighting for LLVM"
41 )
42
43;; ---------------------- Syntax table ---------------------------
44;; Shamelessly ripped from jasmin.el
45;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html
46
47(if (not llvm-mode-syntax-table)
48 (progn
49 (setq llvm-mode-syntax-table (make-syntax-table))
50 (mapcar (function (lambda (n)
51 (modify-syntax-entry (aref n 0)
52 (aref n 1)
53 llvm-mode-syntax-table)))
54 '(
55 ;; whitespace (` ')
56 [?\^m " "]
57 [?\f " "]
58 [?\n " "]
59 [?\t " "]
60 [?\ " "]
61 ;; word constituents (`w')
62 ;;[?< "w"]
63 ;;[?> "w"]
64 [?\% "w"]
65 ;;[?_ "w "]
66 ;; comments
67 [?\; "< "]
68 [?\n "> "]
69 ;;[?\r "> "]
70 ;;[?\^m "> "]
71 ;; symbol constituents (`_')
72 ;; punctuation (`.')
73 ;; open paren (`(')
74 [?\( "("]
75 [?\[ "("]
76 [?\{ "("]
77 ;; close paren (`)')
78 [?\) ")"]
79 [?\] ")"]
80 [?\} ")"]
81 ;; string quote ('"')
82 [?\" "\""]
83 ))))
84
85;; --------------------- Abbrev table -----------------------------
86
87(defvar llvm-mode-abbrev-table nil
88 "Abbrev table used while in LLVM mode.")
89(define-abbrev-table 'llvm-mode-abbrev-table ())
90
91(defvar llvm-mode-hook nil)
92(defvar llvm-mode-map nil) ; Create a mode-specific keymap.
93
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))
100
101
102(defun llvm-mode ()
103 "Major mode for editing LLVM source files.
104 \\{llvm-mode-map}
105 Runs llvm-mode-hook on startup."
106 (interactive)
107 (kill-all-local-variables)
108 (use-local-map llvm-mode-map) ; Provides the local keymap.
109 (setq major-mode 'llvm-mode)
110
Misha Brukman7f12bbb2004-09-28 21:46:18 +0000111 (make-local-variable 'font-lock-defaults)
Misha Brukmand9b11cf2002-10-09 00:30:20 +0000112 (setq major-mode 'llvm-mode ; This is how describe-mode
113 ; finds the doc string to print.
Misha Brukman7f12bbb2004-09-28 21:46:18 +0000114 mode-name "LLVM" ; This name goes into the modeline.
115 font-lock-defaults `(llvm-font-lock-keywords))
Misha Brukmand9b11cf2002-10-09 00:30:20 +0000116
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.
121
122;; Associate .ll files with llvm-mode
123(setq auto-mode-alist
Misha Brukmanbdb41192003-08-11 19:10:02 +0000124 (append '(("\\.ll$" . llvm-mode) ("\\.llx$" . llvm-mode)) auto-mode-alist))
Misha Brukmand9b11cf2002-10-09 00:30:20 +0000125
126(provide 'llvm-mode)
127;; end of llvm-mode.el