Skip to content

Commit

Permalink
update vim syntax file
Browse files Browse the repository at this point in the history
- more highlighting: numbers, elemental types inside shaped types
- add some more keywords

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes #110

COPYBARA_INTEGRATE_REVIEW=tensorflow/mlir#110 from bondhugula:vim 029777db0ecb95bfc6453c0869af1c233d84d521
PiperOrigin-RevId: 266487768
  • Loading branch information
bondhugula authored and tensorflower-gardener committed Aug 31, 2019
1 parent 6a9d6a3 commit 25ac189
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions third_party/mlir/utils/vim/syntax/mlir.vim
Expand Up @@ -2,7 +2,7 @@
" Language: mlir
" Maintainer: The MLIR team, http://github.com/tensorflow/mlir/
" Version: $Revision$
" Adapted from the LLVM vim indent file
" Some parts adapted from the LLVM vim syntax file.

if version < 600
syntax clear
Expand All @@ -16,16 +16,22 @@ syn case match
syn keyword mlirType index f16 f32 f64
" Integer type.
syn match mlirType /\<i\d\+\>/
" Primitive types inside memref, tensor, or vector.
syn match mlirType /<.*x\s*\zs\(f16\|f32\|f64\|i\d\+\)/
syn match mlirType /\<memref\ze<.*>/
syn match mlirType /\<tensor\ze<.*>/
syn match mlirType /\<vector\ze<.*>/

" Elemental types inside memref, tensor, or vector types.
syn match mlirType /x\s*\zs\(f16\|f32\|f64\|i\d\+\)/

" Shaped types.
syn match mlirType /\<memref\ze\s*<.*>/
syn match mlirType /\<tensor\ze\s*<.*>/
syn match mlirType /\<vector\ze\s*<.*>/

" vector types inside memref or tensor.
syn match mlirType /x\s*\zsvector/

" Operations.
" Core ops (not exhaustive yet).
" TODO: the list is not exhaustive.
syn keyword mlirOps alloc addf addi call call_indirect cmpi constant dealloc dma_start dma_wait dim extract_element getTensor load memref_cast mulf muli store select subf subi tensor_cast
syn keyword mlirOps alloc addf addi call call_indirect cmpi constant dealloc dma_start dma_wait dim extract_element for getTensor if load memref_cast mulf muli store select subf subi tensor_cast

" Affine ops.
syn match mlirOps /\<affine\.apply\>/
Expand All @@ -36,6 +42,8 @@ syn match mlirOps /\<affine\.if\>/
syn match mlirOps /\<affine\.load\>/
syn match mlirOps /\<affine\.store\>/

" TODO: dialect name prefixed ops (llvm or std).

" Keywords.
syn keyword mlirKeyword
\ else
Expand All @@ -45,15 +53,20 @@ syn keyword mlirKeyword
\ to

" Misc syntax.
syn match mlirNoName /[%@!]\d\+\>/

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
syn match mlirComment /\/\/.*$/
syn region mlirString start=/"/ skip=/\\"/ end=/"/
syn match mlirLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/
syn match mlirIdentifier /[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*/
syn match mlirIdentifier /[%@][a-zA-Z$._-][a-zA-Z0-9$._-]*/
syn match mlirIdentifier /[%@!]\d\+\>/
syn match mlirMapSetOutline "#.*$"

" Syntax-highlight lit test commands and bug numbers.
Expand Down Expand Up @@ -84,7 +97,6 @@ if version >= 508 || !exists("did_c_syn_inits")
HiLink mlirKeyword Keyword
HiLink mlirBoolean Boolean
HiLink mlirFloat Float
HiLink mlirNoName Identifier
HiLink mlirConstant Constant
HiLink mlirSpecialComment SpecialComment
HiLink mlirIdentifier Identifier
Expand Down

0 comments on commit 25ac189

Please sign in to comment.