From 2ad1ecf074cc3973c978044fd3414631eb03f033 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Wed, 18 Oct 2023 17:12:36 -0600 Subject: [PATCH] Add mlir syntax for vim --- vim/.vim/ftdetect/mlir.vim | 1 + vim/.vim/syntax/mlir.vim | 141 +++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 vim/.vim/ftdetect/mlir.vim create mode 100644 vim/.vim/syntax/mlir.vim diff --git a/vim/.vim/ftdetect/mlir.vim b/vim/.vim/ftdetect/mlir.vim new file mode 100644 index 0000000..f8b1de4 --- /dev/null +++ b/vim/.vim/ftdetect/mlir.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.mlir set filetype=mlir diff --git a/vim/.vim/syntax/mlir.vim b/vim/.vim/syntax/mlir.vim new file mode 100644 index 0000000..7989032 --- /dev/null +++ b/vim/.vim/syntax/mlir.vim @@ -0,0 +1,141 @@ +" Vim syntax file +" Language: mlir +" Maintainer: The MLIR team, http://github.com/tensorflow/mlir/ +" Version: $Revision$ +" Some parts adapted from the LLVM vim syntax file. + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +syn case match + +" Types. +" +syn keyword mlirType index f16 f32 f64 bf16 +" Signless integer types. +syn match mlirType /\/ +" Unsigned integer types. +syn match mlirType /\/ +" Signed integer types. +syn match mlirType /\/ + +" Elemental types inside memref, tensor, or vector types. +syn match mlirType /x\s*\zs\(bf16|f16\|f32\|f64\|i\d\+\|ui\d\+\|si\d\+\)/ + +" Shaped types. +syn match mlirType /\/ +syn match mlirType /\/ +syn match mlirType /\/ + +" vector types inside memref or tensor. +syn match mlirType /x\s*\zsvector/ + +" Operations. +" TODO: this list is not exhaustive. +syn keyword mlirOps alloc alloca addf addi and call call_indirect cmpf cmpi +syn keyword mlirOps constant dealloc divf dma_start dma_wait dim exp +syn keyword mlirOps getTensor index_cast load log memref_cast +syn keyword mlirOps memref_shape_cast mulf muli negf powf prefetch rsqrt sitofp +syn keyword mlirOps splat store select sqrt subf subi subview tanh +syn keyword mlirOps view + +" Math ops. +syn match mlirOps /\/ + +" Affine ops. +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ + +" TODO: dialect name prefixed ops (llvm or std). + +" Keywords. +syn keyword mlirKeyword + \ affine_map + \ affine_set + \ dense + \ else + \ func + \ module + \ return + \ step + \ to + +" Misc syntax. + +syn match mlirNumber /-\?\<\d\+\>/ +" Match numbers even in shaped types. +syn match mlirNumber /-\?\<\d\+\ze\s*x/ +syn match mlirNumber /x\s*\zs-\?\d\+\ze\s*x/ + +syn match mlirFloat /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/ +syn match mlirFloat /\<0x\x\+\>/ +syn keyword mlirBoolean true false +" Spell checking is enabled only in comments by default. +syn match mlirComment /\/\/.*$/ contains=@Spell +syn region mlirString start=/"/ skip=/\\"/ end=/"/ +syn match mlirLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/ +" Prefixed identifiers usually used for ssa values and symbols. +syn match mlirIdentifier /[%@][a-zA-Z$._-][a-zA-Z0-9$._-]*/ +syn match mlirIdentifier /[%@]\d\+\>/ +" Prefixed identifiers usually used for blocks. +syn match mlirBlockIdentifier /\^[a-zA-Z$._-][a-zA-Z0-9$._-]*/ +syn match mlirBlockIdentifier /\^\d\+\>/ +" Prefixed identifiers usually used for types. +syn match mlirTypeIdentifier /![a-zA-Z$._-][a-zA-Z0-9$._-]*/ +syn match mlirTypeIdentifier /!\d\+\>/ +" Prefixed identifiers usually used for attribute aliases and result numbers. +syn match mlirAttrIdentifier /#[a-zA-Z$._-][a-zA-Z0-9$._-]*/ +syn match mlirAttrIdentifier /#\d\+\>/ + +" Syntax-highlight lit test commands and bug numbers. +syn match mlirSpecialComment /\/\/\s*RUN:.*$/ +syn match mlirSpecialComment /\/\/\s*CHECK:.*$/ +syn match mlirSpecialComment "\v\/\/\s*CHECK-(NEXT|NOT|DAG|SAME|LABEL):.*$" +syn match mlirSpecialComment /\/\/\s*expected-error.*$/ +syn match mlirSpecialComment /\/\/\s*expected-remark.*$/ +syn match mlirSpecialComment /;\s*XFAIL:.*$/ +syn match mlirSpecialComment /\/\/\s*PR\d*\s*$/ +syn match mlirSpecialComment /\/\/\s*REQUIRES:.*$/ + +if version >= 508 || !exists("did_c_syn_inits") + if version < 508 + let did_c_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink mlirType Type + HiLink mlirOps Statement + HiLink mlirNumber Number + HiLink mlirComment Comment + HiLink mlirString String + HiLink mlirLabel Label + HiLink mlirKeyword Keyword + HiLink mlirBoolean Boolean + HiLink mlirFloat Float + HiLink mlirConstant Constant + HiLink mlirSpecialComment SpecialComment + HiLink mlirIdentifier Identifier + HiLink mlirBlockIdentifier Label + HiLink mlirTypeIdentifier Type + HiLink mlirAttrIdentifier PreProc + + delcommand HiLink +endif + +let b:current_syntax = "mlir"