llvm.org GIT mirror llvm / d9b11cf
Added a major mode for Emacs to edit LLVM assembler code with syntax highlighting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4092 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 17 years ago
1 changed file(s) with 130 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 ;; Author: Misha Brukman
1 ;; Description:
2 ;; Major mode for the LLVM assembler language.
3 ;; Updated:
4 ;; Oct 8, 2002
5 ;; Code:
6
7 ;; Create mode-specific tables.
8 (defvar llvm-mode-syntax-table nil
9 "Syntax table used while in LLVM mode.")
10
11 (defvar llvm-font-lock-keywords
12 (list
13 ;; Comments
14 '(";.*" . font-lock-comment-face)
15 ;; Variables
16 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face)
17 ;; Labels
18 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face)
19 ;; Strings
20 '("\"[^\"]+\"" . font-lock-string-face)
21 ;; Unnamed variable slots
22 '("%[-]?[0-9]+" . font-lock-variable-name-face)
23 ;; Integer literals
24 '("[-]?[0-9]+" . font-lock-preprocessor-face)
25 ;; Floating point constants
26 '("[-+]?[0-9]+\.[0-9]*\([eE][-+]?[0-9]+\)?" . font-lock-preprocessor-face)
27 ;; Hex constants
28 '("0x[0-9A-Fa-f]+" . font-lock-preprocessor-face)
29 ;; Keywords
30 '("begin\\|end\\|true\\|false\\|declare\\|global\\|constant\\|const\\|internal\\|implementation\\|\\.\\.\\.\\|null\\|to\\|except\\|not" . font-lock-keyword-face)
31 ;; Types
32 '("void\\|bool\\|sbyte\\|ubyte\\|u?short\\|u?int\\|u?long\\|float\\|double\\|type\\|label\\|opaque" . font-lock-type-face)
33 ;; Arithmetic and Logical Operators
34 '("add\\|sub\\|mul\\|div\\|rem\\|and\\|or\\|xor\\|set\\(ne\\|eq\\|lt\\|gt\\|le\\|ge\\)" . font-lock-keyword-face)
35 ;; Special instructions
36 '("phi\\|call\\|cast\\|shl\\|shr" . font-lock-keyword-face)
37 ;; Control instructions
38 '("ret\\|br\\|switch\\|invoke" . font-lock-keyword-face)
39 ;; Memory operators
40 '("malloc\\|alloca\\|free\\|load\\|store\\|getelementptr" . font-lock-keyword-face)
41 )
42 "Syntax highlighting for LLVM"
43 )
44
45 ;; ---------------------- Syntax table ---------------------------
46 ;; Shamelessly ripped from jasmin.el
47 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html
48
49 (if (not llvm-mode-syntax-table)
50 (progn
51 (setq llvm-mode-syntax-table (make-syntax-table))
52 (mapcar (function (lambda (n)
53 (modify-syntax-entry (aref n 0)
54 (aref n 1)
55 llvm-mode-syntax-table)))
56 '(
57 ;; whitespace (` ')
58 [?\^m " "]
59 [?\f " "]
60 [?\n " "]
61 [?\t " "]
62 [?\ " "]
63 ;; word constituents (`w')
64 ;;[?< "w"]
65 ;;[?> "w"]
66 [?\% "w"]
67 ;;[?_ "w "]
68 ;; comments
69 [?\; "< "]
70 [?\n "> "]
71 ;;[?\r "> "]
72 ;;[?\^m "> "]
73 ;; symbol constituents (`_')
74 ;; punctuation (`.')
75 ;; open paren (`(')
76 [?\( "("]
77 [?\[ "("]
78 [?\{ "("]
79 ;; close paren (`)')
80 [?\) ")"]
81 [?\] ")"]
82 [?\} ")"]
83 ;; string quote ('"')
84 [?\" "\""]
85 ))))
86
87 ;; --------------------- Abbrev table -----------------------------
88
89 (defvar llvm-mode-abbrev-table nil
90 "Abbrev table used while in LLVM mode.")
91 (define-abbrev-table 'llvm-mode-abbrev-table ())
92
93 (defvar llvm-mode-hook nil)
94 (defvar llvm-mode-map nil) ; Create a mode-specific keymap.
95
96 (if (not llvm-mode-map)
97 () ; Do not change the keymap if it is already set up.
98 (setq llvm-mode-map (make-sparse-keymap))
99 (define-key llvm-mode-map "\t" 'tab-to-tab-stop)
100 (define-key llvm-mode-map "\es" 'center-line)
101 (define-key llvm-mode-map "\eS" 'center-paragraph))
102
103
104 (defun llvm-mode ()
105 "Major mode for editing LLVM source files.
106 \\{llvm-mode-map}
107 Runs llvm-mode-hook on startup."
108 (interactive)
109 (kill-all-local-variables)
110 (use-local-map llvm-mode-map) ; Provides the local keymap.
111 (setq major-mode 'llvm-mode)
112
113 (make-local-variable 'font-lock-defaults)
114 (setq major-mode 'llvm-mode ; This is how describe-mode
115 ; finds the doc string to print.
116 mode-name "LLVM" ; This name goes into the modeline.
117 font-lock-defaults `(llvm-font-lock-keywords))
118
119 (setq local-abbrev-table llvm-mode-abbrev-table)
120 (set-syntax-table llvm-mode-syntax-table)
121 (run-hooks 'llvm-mode-hook)) ; Finally, this permits the user to
122 ; customize the mode with a hook.
123
124 ;; Associate .ll files with llvm-mode
125 (setq auto-mode-alist
126 (append '(("\\.ll$" . llvm-mode)) auto-mode-alist))
127
128 (provide 'llvm-mode)
129 ;; end of llvm-mode.el