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.
21 ;; Major mode for editing MLIR files.
25 (defvar mlir-mode-syntax-table
26 (let ((table (make-syntax-table)))
27 (modify-syntax-entry ?%
"_" table
)
28 (modify-syntax-entry ?
@ "_" table
)
29 (modify-syntax-entry ?
# "_" table
)
30 (modify-syntax-entry ?.
"_" table
)
31 (modify-syntax-entry ?
/ ". 12" table
)
32 (modify-syntax-entry ?
\n "> " table
)
34 "Syntax table used while in MLIR mode.")
36 (defvar mlir-font-lock-keywords
39 '("%[-a-zA-Z$._0-9]*" . font-lock-variable-name-face
)
41 '("@[-a-zA-Z$._0-9]*" . font-lock-function-name-face
)
43 '("#[-a-zA-Z$._0-9]*" . font-lock-variable-name-face
)
45 '("\\b\\(f16\\|bf16\\|f32\\|f64\\|index\\|tf_control\\|i[1-9][0-9]*\\)\\b" . font-lock-type-face
)
46 '("\\b\\(tensor\\|vector\\|memref\\)\\b" . font-lock-type-face
)
48 '("\\b\\([0-9?]+x\\)*\\(f16\\|bf16\\|f32\\|f64\\|index\\|i[1-9][0-9]*\\)\\b" . font-lock-preprocessor-face
)
50 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face
)
51 ;; Floating point constants
52 '("\\b[-+]?[0-9]+.[0-9]*\\([eE][-+]?[0-9]+\\)?\\b" . font-lock-preprocessor-face
)
54 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face
)
57 '(;; Toplevel entities
58 "br" "ceildiv" "func" "cond_br" "else" "extfunc" "false" "floordiv" "for" "if" "mod" "return" "size" "step" "to" "true" "??" ) 'symbols
) . font-lock-keyword-face
))
59 "Syntax highlighting for MLIR.")
61 ;; Emacs 23 compatibility.
62 (defalias 'mlir-mode-prog-mode
63 (if (fboundp 'prog-mode
)
68 (define-derived-mode mlir-mode mlir-mode-prog-mode
"MLIR"
69 "Major mode for editing MLIR source files.
71 Runs `mlir-mode-hook' on startup."
72 (setq font-lock-defaults
`(mlir-font-lock-keywords))
73 (setq-local comment-start
"//"))
75 ;; Associate .mlir files with mlir-mode
77 (add-to-list 'auto-mode-alist
(cons "\\.mlir\\'" 'mlir-mode
))
80 "Major mode for editing MLIR source files."
84 ;; Set default value of opt-tool to use as mlir-opt.
85 (defcustom mlir-opt
"mlir-opt"
86 "Commandline MLIR opt tool to use."
89 ;; Enable reading/writing .mlirbc files.
91 (add-to-list 'jka-compr-compression-info-list
92 (vector "\\.mlirbc\\'"
93 "mlir-to-bytecode" mlir-opt
(vector "--mlir-print-debuginfo" "--emit-bytecode" "-o" "-" "-")
94 "mlir-bytecode-to-text" mlir-opt
(vector "--mlir-print-debuginfo")
97 (auto-compression-mode t
)
98 (add-to-list 'auto-mode-alist
(cons "\\.mlirbc\\'" 'mlir-mode
))
101 ;;; mlir-mode.el ends here