llvm.org GIT mirror llvm / 7ad3ef0
Cleaning up LLVM IR mode for Emacs. I've made a range of improvements to the Emacs mode for LLVM IR. Most importantly, it changes llvm-mode to inherit from prog-mode. This means llvm-mode will be treated as a normal programming mode in Emacs, so many Emacs features will just work. prog-mode is new to Emacs 24, so I've added an alias to ensure compatibility with Emacs 23 too. I've changed the mode definition to use define-derived-mode. This saves us needing to set up local variables ourselves, and saves us needing to define llvm-mode-map, llvm-mode-abbrev-table, llvm-mode-map. I've removed the keybindings to tab-to-tab-stop, center-line and center-paragraph. This shouldn't be llvm-mode's responsibility, and the code didn't actually work anyway (since `(not llvm-mode-map)` always evaluated to `t`, the keybindings were never executed). I've simplified the syntax-table definition, it's equivalent (e.g. `"` is treated as string delimiter by default in Emacs). I've added `.` as a symbol constituent, so functions like `llvm.memset.p0i8.i32` are recognised as a single symbol. I've also changed `%` to be a symbol constituent, so users can move between words or symbols at their choice, rather than conflating the two. I've fixed regexp for types, which incorrect used `symbol` instead of `symbols` as an argument to `regexp-opt`. This was causing incorrect highlighting on lines like `call void @foovoid`. I've removed string and comment highlighting from `llvm-font-lock-keywords`. This is already handled by the syntax-table. Finally, I've removed the reference to jasmin. That project is long abandoned and the link 404s. For reference, I've found an old copy of the project here: https://github.com/stevej/emacs/blob/master/vendor/jasmin/jasmin.el Patch by Wilfred Hughes! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247281 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
1 changed file(s) with 19 addition(s) and 78 deletion(s). Raw diff Collapse all Expand all
77
88 ;;; Code:
99
10 (defvar llvm-mode-syntax-table nil
10 (defvar llvm-mode-syntax-table
11 (let ((table (make-syntax-table)))
12 (modify-syntax-entry ?% "_" table)
13 (modify-syntax-entry ?. "_" table)
14 (modify-syntax-entry ?\; "< " table)
15 (modify-syntax-entry ?\n "> " table)
16 table)
1117 "Syntax table used while in LLVM mode.")
18
1219 (defvar llvm-font-lock-keywords
1320 (list
14 ;; Comments
15 '(";.*" . font-lock-comment-face)
1621 ;; Variables
1722 '("%[-a-zA-Z$\._][-a-zA-Z$\._0-9]*" . font-lock-variable-name-face)
1823 ;; Labels
1924 '("[-a-zA-Z$\._0-9]+:" . font-lock-variable-name-face)
20 ;; Strings
21 '("\"[^\"]+\"" . font-lock-string-face)
2225 ;; Unnamed variable slots
2326 '("%[-]?[0-9]+" . font-lock-variable-name-face)
2427 ;; Types
25 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbol) . font-lock-type-face)
28 `(,(regexp-opt '("void" "i1" "i8" "i16" "i32" "i64" "i128" "float" "double" "type" "label" "opaque") 'symbols) . font-lock-type-face)
2629 ;; Integer literals
2730 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)
2831 ;; Floating point constants
5558 ;; Metadata types
5659 `(,(regexp-opt '("distinct") 'symbols) . font-lock-keyword-face)
5760 ;; Use-list order directives
58 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face)
61 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face))
62 "Syntax highlighting for LLVM.")
5963
60 )
61 "Syntax highlighting for LLVM."
62 )
63
64 ;; ---------------------- Syntax table ---------------------------
65 ;; Shamelessly ripped from jasmin.el
66 ;; URL: http://www.neilvandyke.org/jasmin-emacs/jasmin.el.html
67
68 (if (not llvm-mode-syntax-table)
69 (progn
70 (setq llvm-mode-syntax-table (make-syntax-table))
71 (mapc (function (lambda (n)
72 (modify-syntax-entry (aref n 0)
73 (aref n 1)
74 llvm-mode-syntax-table)))
75 '(
76 ;; whitespace (` ')
77 [?\^m " "]
78 [?\f " "]
79 [?\n " "]
80 [?\t " "]
81 [?\ " "]
82 ;; word constituents (`w')
83 ;;[?< "w"]
84 ;;[?> "w"]
85 [?% "w"]
86 ;;[?_ "w "]
87 ;; comments
88 [?\; "< "]
89 [?\n "> "]
90 ;;[?\r "> "]
91 ;;[?\^m "> "]
92 ;; symbol constituents (`_')
93 ;; punctuation (`.')
94 ;; open paren (`(')
95 ;; close paren (`)')
96 ;; string quote ('"')
97 [?\" "\""]))))
98
99 ;; --------------------- Abbrev table -----------------------------
100
101 (defvar llvm-mode-abbrev-table nil
102 "Abbrev table used while in LLVM mode.")
103 (define-abbrev-table 'llvm-mode-abbrev-table ())
104
105 (defvar llvm-mode-hook nil)
106 (defvar llvm-mode-map nil) ; Create a mode-specific keymap.
107
108 (if (not llvm-mode-map)
109 () ; Do not change the keymap if it is already set up.
110 (setq llvm-mode-map (make-sparse-keymap))
111 (define-key llvm-mode-map "\t" 'tab-to-tab-stop)
112 (define-key llvm-mode-map "\es" 'center-line)
113 (define-key llvm-mode-map "\eS" 'center-paragraph))
64 ;; Emacs 23 compatibility.
65 (defalias 'llvm-mode-prog-mode
66 (if (fboundp 'prog-mode)
67 'prog-mode
68 'fundamental-mode))
11469
11570 ;;;###autoload
116 (defun llvm-mode ()
71 (define-derived-mode llvm-mode llvm-mode-prog-mode "LLVM"
11772 "Major mode for editing LLVM source files.
11873 \\{llvm-mode-map}
11974 Runs `llvm-mode-hook' on startup."
120 (interactive)
121 (kill-all-local-variables)
122 (use-local-map llvm-mode-map) ; Provides the local keymap.
123 (setq major-mode 'llvm-mode)
124
125 (make-local-variable 'font-lock-defaults)
126 (setq major-mode 'llvm-mode ; This is how describe-mode
127 ; finds the doc string to print.
128 mode-name "LLVM" ; This name goes into the modeline.
129 font-lock-defaults `(llvm-font-lock-keywords))
130
131 (setq local-abbrev-table llvm-mode-abbrev-table)
132 (set-syntax-table llvm-mode-syntax-table)
133 (setq comment-start ";")
134 (run-hooks 'llvm-mode-hook)) ; Finally, this permits the user to
135 ; customize the mode with a hook.
75 (setq font-lock-defaults `(llvm-font-lock-keywords))
76 (setq comment-start ";"))
13677
13778 ;; Associate .ll files with llvm-mode
13879 ;;;###autoload