[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / utils / emacs / mlir-mode.el
blob69056ba3620eb88be33f5de26f2066177a714a98
1 ;;; mlir-mode.el --- Major mode for the MLIR assembler language.
3 ;; Copyright (C) 2019 The MLIR Authors.
4 ;;
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
8 ;;
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.
17 ;;; Commentary:
19 ;; Major mode for editing MLIR files.
21 ;;; Code:
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)
31 table)
32 "Syntax table used while in MLIR mode.")
34 (defvar mlir-font-lock-keywords
35 (list
36 ;; Variables
37 '("%[-a-zA-Z$._0-9]*" . font-lock-variable-name-face)
38 ;; Functions
39 '("@[-a-zA-Z$._0-9]*" . font-lock-function-name-face)
40 ;; Affinemaps
41 '("#[-a-zA-Z$._0-9]*" . font-lock-variable-name-face)
42 ;; Types
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)
45 ;; Dimension lists
46 '("\\b\\([0-9?]+x\\)*\\(f16\\|bf16\\|f32\\|f64\\|index\\|i[1-9][0-9]*\\)\\b" . font-lock-preprocessor-face)
47 ;; Integer literals
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)
51 ;; Hex constants
52 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)
53 ;; Keywords
54 `(,(regexp-opt
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)
62 'prog-mode
63 'fundamental-mode))
65 ;;;###autoload
66 (define-derived-mode mlir-mode mlir-mode-prog-mode "MLIR"
67 "Major mode for editing MLIR source files.
68 \\{mlir-mode-map}
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
74 ;;;###autoload
75 (add-to-list 'auto-mode-alist (cons "\\.mlir\\'" 'mlir-mode))
77 (defgroup mlir nil
78 "Major mode for editing MLIR source files."
79 :group 'languages
80 :prefix "mlir-")
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."
85 :type 'string)
87 ;; Enable reading/writing .mlirbc files.
88 (require 'jka-compr)
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")
93 nil nil "ML\357R"))
94 (jka-compr-update)
95 (auto-compression-mode t)
96 (add-to-list 'auto-mode-alist (cons "\\.mlirbc\\'" 'mlir-mode))
98 (provide 'mlir-mode)
100 ;;; mlir-mode.el ends here