Skip to content

Commit 8cbf041

Browse files
committed
[emacs] Add llvm-mir-mode
Adds an emacs mode for .mir files. For the most part this just consists of keyword rules for various MIR constructs and then appending the llvm-mode keywords to that. This doesn't currently attempt to do anything to be aware of the YAML structure or differentiate between machine IR and embedded LLVM IR.
1 parent 0096d17 commit 8cbf041

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

llvm/utils/emacs/README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ are:
1212
(cons (expand-file-name "path-to-llvm/utils/emacs") load-path))
1313
(require 'llvm-mode)
1414

15+
* llvm-mir-mode.el
16+
17+
Syntax highlighting mode for LLVM Machine IR files. To use, add this code to
18+
your ~/.emacs :
19+
20+
(setq load-path
21+
(cons (expand-file-name "path-to-llvm/utils/emacs") load-path))
22+
(require 'llvm-mir-mode)
23+
1524
* tablegen-mode.el
1625

1726
Syntax highlighting mode for TableGen description files. To use, add this code

llvm/utils/emacs/llvm-mir-mode.el

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
;;; llvm-mir-mode.el --- Major mode for LLVM Machine IR
2+
3+
;; Maintainer: The LLVM team, http://llvm.org/
4+
;; Version: 1.0
5+
6+
;;; Commentary:
7+
8+
;; Major mode for editing LLVM MIR files.
9+
10+
;;; Code:
11+
12+
(require 'llvm-mode)
13+
14+
(defvar llvm-mir-mode-map
15+
(let ((map (make-sparse-keymap)))
16+
map)
17+
"Keymap for `llvm-mir-mode'.")
18+
19+
(defvar llvm-mir-mode-syntax-table
20+
(let ((st (make-syntax-table)))
21+
(modify-syntax-entry ?% "_" st)
22+
(modify-syntax-entry ?$ "_" st)
23+
(modify-syntax-entry ?. "_" st)
24+
(modify-syntax-entry ?# "< " st)
25+
(modify-syntax-entry ?\; "< " st)
26+
(modify-syntax-entry ?\n "> " st)
27+
st)
28+
"Syntax table for `llvm-mir-mode'.")
29+
30+
(defvar llvm-mir-font-lock-keywords
31+
(append
32+
(list
33+
; YAML Attributes
34+
'("^name: +\\([a-zA-Z._][-a-zA-Z._0-9]*\\)"
35+
1 font-lock-function-name-face)
36+
'("^body: +|" . font-lock-keyword-face)
37+
'("^[a-zA-Z_.][-a-zA-Z._0-9]*:" . font-lock-keyword-face)
38+
`(,(regexp-opt '("true" "false")) . font-lock-constant-face)
39+
; YAML separators
40+
'("^\\(---\\( |\\)?\\|\\.\\.\\.\\)$" . font-lock-comment-face)
41+
; Registers
42+
'("%[a-zA-Z_.][-a-zA-Z._0-9]*" . font-lock-variable-name-face)
43+
'("%[0-9]+\\(\\.[a-zA-Z._0-9]+\\)?" . font-lock-variable-name-face)
44+
'("$[a-zA-Z_.][-a-zA-Z._0-9]*" . font-lock-constant-face)
45+
; Register classes
46+
`(,(concat
47+
"%\\([a-zA-Z_.][-a-zA-Z._0-9]*\\|[0-9]+\\(\\.[a-zA-Z._0-9]+\\)?\\)"
48+
"\\(:[a-zA-Z_.][-a-zA-Z._0-9]*\\)")
49+
3 font-lock-type-face)
50+
'("class: \\([a-zA-Z_.][-a-zA-Z._0-9]*\\)" 1 font-lock-type-face)
51+
; MO Register flags
52+
`(,(regexp-opt '("dead" "debug-use" "def" "early-clobber" "implicit"
53+
"implicit-def" "internal" "killed" "renamable" "undef")
54+
'symbols)
55+
. font-lock-keyword-face))
56+
llvm-font-lock-keywords)
57+
"Keyword highlighting specification for `llvm-mir-mode'.")
58+
59+
;;;###autoload
60+
(define-derived-mode llvm-mir-mode prog-mode "LLVM MIR"
61+
"A major mode for editing LLVM MIR files."
62+
(setq-local comment-start "; ")
63+
(setq-local font-lock-defaults `(llvm-mir-font-lock-keywords)))
64+
65+
;;;###autoload
66+
(add-to-list 'auto-mode-alist (cons "\\.mir\\'" 'llvm-mir-mode))
67+
68+
(provide 'llvm-mir-mode)
69+
70+
;;; llvm-mir-mode.el ends here

0 commit comments

Comments
 (0)