llvm-mode.el revision 0512d02af7f6ad6f293aabf2b0421472c55d9fdd
1;; Maintainer:  The LLVM team, http://llvm.cs.uiuc.edu/
2;; Description: Major mode for the LLVM assembler language.
3;; Updated:     2003-06-02
4
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
28   '("begin\\|end\\|true\\|false\\|declare\\|global\\|constant\\|const\\|internal\\|linkonce\\|weak\\|appending\\|uninitialized\\|implementation\\|\\.\\.\\.\\|null\\|to\\|except\\|not\\|target\\|endian\\|little\\|big\\|pointersize\\|volatile" . font-lock-keyword-face)
29   ;; 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
34   '("phi\\|call\\|cast\\|to\\|shl\\|shr\\|vaarg\\|vanext" . font-lock-keyword-face)
35   ;; Control instructions
36   '("ret\\|br\\|switch\\|invoke\\|unwind" . font-lock-keyword-face)
37   ;; 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
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))
116
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
124   (append '(("\\.ll$" . llvm-mode) ("\\.llx$" . llvm-mode)) auto-mode-alist))
125
126(provide 'llvm-mode)
127;; end of llvm-mode.el
128