blob: 4d63bb7dc86af954c84309e586990bccda17d39d [file] [log] [blame]
James Molloy05632af2018-07-24 17:30:34 -07001;;; mlir-mode.el --- Major mode for the MLIR assembler language.
2
3;; Maintainer:
4;; Version: 0.0
5
6;;; Commentary:
7
8;; Major mode for editing MLIR files.
9
10;;; Code:
11
12(defvar mlir-mode-syntax-table
13 (let ((table (make-syntax-table)))
14 (modify-syntax-entry ?% "_" table)
15 (modify-syntax-entry ?@ "_" table)
16 (modify-syntax-entry ?# "_" table)
17 (modify-syntax-entry ?. "_" table)
18 (modify-syntax-entry ?/ ". 12" table)
19 (modify-syntax-entry ?\n "> " table)
20 table)
21 "Syntax table used while in MLIR mode.")
22
23(defvar mlir-font-lock-keywords
24 (list
25 ;; Variables
26 '("%[-a-zA-Z$._0-9]*" . font-lock-variable-name-face)
27 ;; Functions
28 '("@[-a-zA-Z$._0-9]*" . font-lock-function-name-face)
29 ;; Affinemaps
30 '("#[-a-zA-Z$._0-9]*" . font-lock-variable-name-face)
31 ;; Types
Jacques Pienaar5e544512018-07-30 08:43:22 -070032 '("\\b\\(f16\\|bf16\\|f32\\|f64\\|affineint\\|tf_control\\|i[1-9][0-9]*\\)\\b" . font-lock-type-face)
James Molloy05632af2018-07-24 17:30:34 -070033 '("\\b\\(tensor\\|vector\\|memref\\)\\b" . font-lock-type-face)
34 ;; Dimension lists
35 '("\\b\\([0-9?]+x\\)*\\(f16\\|bf16\\|f32\\|f64\\|affineint\\|i[1-9][0-9]*\\)\\b" . font-lock-preprocessor-face)
36 ;; Integer literals
37 '("\\b[-]?[0-9]+\\b" . font-lock-preprocessor-face)
38 ;; Floating point constants
39 '("\\b[-+]?[0-9]+.[0-9]*\\([eE][-+]?[0-9]+\\)?\\b" . font-lock-preprocessor-face)
40 ;; Hex constants
41 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)
42 ;; Keywords
43 `(,(regexp-opt
44 '(;; Toplevel entities
45 "br" "ceildiv" "cfgfunc" "cond_br" "else" "extfunc" "false" "floordiv" "for" "if" "mlfunc" "mod" "return" "size" "step" "to" "true" "??" ) 'symbols) . font-lock-keyword-face))
46 "Syntax highlighting for MLIR.")
47
48;; Emacs 23 compatibility.
49(defalias 'mlir-mode-prog-mode
50 (if (fboundp 'prog-mode)
51 'prog-mode
52 'fundamental-mode))
53
54;;;###autoload
55(define-derived-mode mlir-mode mlir-mode-prog-mode "MLIR"
56 "Major mode for editing MLIR source files.
57\\{mlir-mode-map}
58 Runs `mlir-mode-hook' on startup."
59 (setq font-lock-defaults `(mlir-font-lock-keywords))
60 (setq-local comment-start "//"))
61
62;; Associate .mlir files with mlir-mode
63;;;###autoload
64(add-to-list 'auto-mode-alist (cons "\\.mlir\\'" 'mlir-mode))
65
66(provide 'mlir-mode)
67
68;;; mlir-mode.el ends here