[llvm] 8cbf041 - [emacs] Add llvm-mir-mode

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 7 16:01:35 PST 2023


Author: Justin Bogner
Date: 2023-02-07T16:01:25-08:00
New Revision: 8cbf041ecb1c304148cd09987f4bd73a41cb51a9

URL: https://github.com/llvm/llvm-project/commit/8cbf041ecb1c304148cd09987f4bd73a41cb51a9
DIFF: https://github.com/llvm/llvm-project/commit/8cbf041ecb1c304148cd09987f4bd73a41cb51a9.diff

LOG: [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.

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

Modified: 
    llvm/utils/emacs/README

Removed: 
    


################################################################################
diff  --git a/llvm/utils/emacs/README b/llvm/utils/emacs/README
index d0f2bfbbb3e58..44b51430fadbe 100644
--- a/llvm/utils/emacs/README
+++ b/llvm/utils/emacs/README
@@ -12,6 +12,15 @@ are:
     (cons (expand-file-name "path-to-llvm/utils/emacs") load-path))
   (require 'llvm-mode)
   
+* llvm-mir-mode.el
+
+  Syntax highlighting mode for LLVM Machine IR files. To use, add this code to
+  your ~/.emacs :
+
+  (setq load-path
+    (cons (expand-file-name "path-to-llvm/utils/emacs") load-path))
+  (require 'llvm-mir-mode)
+
 * tablegen-mode.el
 
   Syntax highlighting mode for TableGen description files. To use, add this code

diff  --git a/llvm/utils/emacs/llvm-mir-mode.el b/llvm/utils/emacs/llvm-mir-mode.el
new file mode 100644
index 0000000000000..6f1de4252445f
--- /dev/null
+++ b/llvm/utils/emacs/llvm-mir-mode.el
@@ -0,0 +1,70 @@
+;;; llvm-mir-mode.el --- Major mode for LLVM Machine IR
+
+;; Maintainer:  The LLVM team, http://llvm.org/
+;; Version: 1.0
+
+;;; Commentary:
+
+;; Major mode for editing LLVM MIR files.
+
+;;; Code:
+
+(require 'llvm-mode)
+
+(defvar llvm-mir-mode-map
+  (let ((map (make-sparse-keymap)))
+    map)
+  "Keymap for `llvm-mir-mode'.")
+
+(defvar llvm-mir-mode-syntax-table
+  (let ((st (make-syntax-table)))
+    (modify-syntax-entry ?% "_" st)
+    (modify-syntax-entry ?$ "_" st)
+    (modify-syntax-entry ?. "_" st)
+    (modify-syntax-entry ?# "< " st)
+    (modify-syntax-entry ?\; "< " st)
+    (modify-syntax-entry ?\n "> " st)
+    st)
+  "Syntax table for `llvm-mir-mode'.")
+
+(defvar llvm-mir-font-lock-keywords
+  (append
+   (list
+    ; YAML Attributes
+    '("^name: +\\([a-zA-Z._][-a-zA-Z._0-9]*\\)"
+      1 font-lock-function-name-face)
+    '("^body: +|" . font-lock-keyword-face)
+    '("^[a-zA-Z_.][-a-zA-Z._0-9]*:" . font-lock-keyword-face)
+    `(,(regexp-opt '("true" "false")) . font-lock-constant-face)
+    ; YAML separators
+    '("^\\(---\\( |\\)?\\|\\.\\.\\.\\)$" . font-lock-comment-face)
+    ; Registers
+    '("%[a-zA-Z_.][-a-zA-Z._0-9]*" . font-lock-variable-name-face)
+    '("%[0-9]+\\(\\.[a-zA-Z._0-9]+\\)?" . font-lock-variable-name-face)
+    '("$[a-zA-Z_.][-a-zA-Z._0-9]*" . font-lock-constant-face)
+    ; Register classes
+    `(,(concat
+        "%\\([a-zA-Z_.][-a-zA-Z._0-9]*\\|[0-9]+\\(\\.[a-zA-Z._0-9]+\\)?\\)"
+        "\\(:[a-zA-Z_.][-a-zA-Z._0-9]*\\)")
+      3 font-lock-type-face)
+    '("class: \\([a-zA-Z_.][-a-zA-Z._0-9]*\\)" 1 font-lock-type-face)
+    ; MO Register flags
+    `(,(regexp-opt '("dead" "debug-use" "def" "early-clobber" "implicit"
+                     "implicit-def" "internal" "killed" "renamable" "undef")
+                   'symbols)
+      . font-lock-keyword-face))
+   llvm-font-lock-keywords)
+  "Keyword highlighting specification for `llvm-mir-mode'.")
+
+ ;;;###autoload
+(define-derived-mode llvm-mir-mode prog-mode "LLVM MIR"
+  "A major mode for editing LLVM MIR files."
+  (setq-local comment-start "; ")
+  (setq-local font-lock-defaults `(llvm-mir-font-lock-keywords)))
+
+;;;###autoload
+(add-to-list 'auto-mode-alist (cons "\\.mir\\'" 'llvm-mir-mode))
+
+(provide 'llvm-mir-mode)
+
+;;; llvm-mir-mode.el ends here


        


More information about the llvm-commits mailing list