1 ;;; mlir-mode.el --- Major mode for the MLIR assembler language.
3 ;; Copyright (C) 2019 The MLIR Authors.
5 ;; Licensed under the Apache License, Version 2.0 (the "License");
6 ;; you may not use this file except in compliance with the License.
7 ;; You may obtain a copy of the License at
9 ;; http://www.apache.org/licenses/LICENSE-2.0
11 ;; Unless required by applicable law or agreed to in writing, software
12 ;; distributed under the License is distributed on an "AS IS" BASIS,
13 ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ;; See the License for the specific language governing permissions and
15 ;; limitations under the License.
19 ;; Major mode for editing MLIR files.
23 (defvar mlir-mode-syntax-table
24 (let ((table (make-syntax-table)))
25 (modify-syntax-entry ?%
"_" table
)
26 (modify-syntax-entry ?
@ "_" table
)
27 (modify-syntax-entry ?
# "_" table
)
28 (modify-syntax-entry ?.
"_" table
)
29 (modify-syntax-entry ?
/ ". 12" table
)
30 (modify-syntax-entry ?
\n "> " table
)
32 "Syntax table used while in MLIR mode.")
34 (defvar mlir-font-lock-keywords
37 '("%[-a-zA-Z$._0-9]*" . font-lock-variable-name-face
)
39 '("@[-a-zA-Z$._0-9]*" . font-lock-function-name-face
)
41 '("#[-a-zA-Z$._0-9]*" . font-lock-variable-name-face
)
43 '("\\b\\(f16\\|bf16\\|f32\\|f64\\|index\\|tf_control\\|i[1-9][0-9]*\\)\\b" . font-lock-type-face
)
44 '("\\b\\(tensor\\|vector\\|memref\\)\\b" . font-lock-type-face
)
46 '("\\b\\([0-9?]+x\\)*\\(f16\\|bf16\\|f32\\|f64\\|index\\|i[1-9][0-9]*\\)\\b" . font-lock-preprocessor-face
)
48 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face
)
49 ;; Floating point constants
50 '("\\b[-+]?[0-9]+.[0-9]*\\([eE][-+]?[0-9]+\\)?\\b" . font-lock-preprocessor-face
)
52 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face
)
55 '(;; Toplevel entities
56 "br" "ceildiv" "func" "cond_br" "else" "extfunc" "false" "floordiv" "for" "if" "mod" "return" "size" "step" "to" "true" "??" ) 'symbols
) . font-lock-keyword-face
))
57 "Syntax highlighting for MLIR.")
59 ;; Emacs 23 compatibility.
60 (defalias 'mlir-mode-prog-mode
61 (if (fboundp 'prog-mode
)
66 (define-derived-mode mlir-mode mlir-mode-prog-mode
"MLIR"
67 "Major mode for editing MLIR source files.
69 Runs `mlir-mode-hook' on startup."
70 (setq font-lock-defaults
`(mlir-font-lock-keywords))
71 (setq-local comment-start
"//"))
73 ;; Associate .mlir files with mlir-mode
75 (add-to-list 'auto-mode-alist
(cons "\\.mlir\\'" 'mlir-mode
))
78 "Major mode for editing MLIR source files."
82 ;; Set default value of opt-tool to use as mlir-opt.
83 (defcustom mlir-opt
"mlir-opt"
84 "Commandline MLIR opt tool to use."
87 ;; Enable reading/writing .mlirbc files.
89 (add-to-list 'jka-compr-compression-info-list
90 (vector "\\.mlirbc\\'"
91 "mlir-to-bytecode" mlir-opt
(vector "--mlir-print-debuginfo" "--emit-bytecode" "-o" "-" "-")
92 "mlir-bytecode-to-text" mlir-opt
(vector "--mlir-print-debuginfo")
95 (auto-compression-mode t
)
96 (add-to-list 'auto-mode-alist
(cons "\\.mlirbc\\'" 'mlir-mode
))
100 ;;; mlir-mode.el ends here