github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/mlir/utils/emacs/mlir-mode.el (about)

     1  ;;; mlir-mode.el --- Major mode for the MLIR assembler language.
     2  
     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
    10  ;;
    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.
    16  
    17  ;;; Commentary:
    18  
    19  ;; Major mode for editing MLIR files.
    20  
    21  ;;; Code:
    22  
    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.")
    33  
    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.")
    58  
    59  ;; Emacs 23 compatibility.
    60  (defalias 'mlir-mode-prog-mode
    61    (if (fboundp 'prog-mode)
    62        'prog-mode
    63      'fundamental-mode))
    64  
    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 "//"))
    72  
    73  ;; Associate .mlir files with mlir-mode
    74  ;;;###autoload
    75  (add-to-list 'auto-mode-alist (cons "\\.mlir\\'" 'mlir-mode))
    76  
    77  (provide 'mlir-mode)
    78  
    79  ;;; mlir-mode.el ends here