1" Vim syntax file
2" Language:   mlir
3" Maintainer: The MLIR team, http://github.com/tensorflow/mlir/
4" Version:      $Revision$
5" Some parts adapted from the LLVM vim syntax file.
6
7if version < 600
8  syntax clear
9elseif exists("b:current_syntax")
10  finish
11endif
12
13syn case match
14
15" Types.
16"
17syn keyword mlirType index f16 f32 f64
18" Signless integer types.
19syn match mlirType /\<i\d\+\>/
20" Unsigned integer types.
21syn match mlirType /\<ui\d\+\>/
22" Signed integer types.
23syn match mlirType /\<si\d\+\>/
24
25" Elemental types inside memref, tensor, or vector types.
26syn match mlirType /x\s*\zs\(f16\|f32\|f64\|i\d\+\|ui\d\+\|si\d\+\)/
27
28" Shaped types.
29syn match mlirType /\<memref\ze\s*<.*>/
30syn match mlirType /\<tensor\ze\s*<.*>/
31syn match mlirType /\<vector\ze\s*<.*>/
32
33" vector types inside memref or tensor.
34syn match mlirType /x\s*\zsvector/
35
36" Operations.
37" Standard dialect ops.
38" TODO: this list is not exhaustive.
39syn keyword mlirOps alloc alloca addf addi and call call_indirect cmpf cmpi
40syn keyword mlirOps constant dealloc divf dma_start dma_wait dim exp
41syn keyword mlirOps getTensor index_cast load log memref_cast
42syn keyword mlirOps memref_shape_cast mulf muli negf powf prefetch rsqrt sitofp
43syn keyword mlirOps splat store select sqrt subf subi subview tanh
44syn keyword mlirOps view
45
46" Affine ops.
47syn match mlirOps /\<affine\.apply\>/
48syn match mlirOps /\<affine\.dma_start\>/
49syn match mlirOps /\<affine\.dma_wait\>/
50syn match mlirOps /\<affine\.for\>/
51syn match mlirOps /\<affine\.if\>/
52syn match mlirOps /\<affine\.load\>/
53syn match mlirOps /\<affine\.parallel\>/
54syn match mlirOps /\<affine\.prefetch\>/
55syn match mlirOps /\<affine\.store\>/
56syn match mlirOps /\<scf\.execute_region\>/
57syn match mlirOps /\<scf\.for\>/
58syn match mlirOps /\<scf\.if\>/
59syn match mlirOps /\<scf\.yield\>/
60
61" TODO: dialect name prefixed ops (llvm or std).
62
63" Keywords.
64syn keyword mlirKeyword
65      \ affine_map
66      \ affine_set
67      \ dense
68      \ else
69      \ func
70      \ module
71      \ return
72      \ step
73      \ to
74
75" Misc syntax.
76
77syn match   mlirNumber /-\?\<\d\+\>/
78" Match numbers even in shaped types.
79syn match   mlirNumber /-\?\<\d\+\ze\s*x/
80syn match   mlirNumber /x\s*\zs-\?\d\+\ze\s*x/
81
82syn match   mlirFloat  /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/
83syn match   mlirFloat  /\<0x\x\+\>/
84syn keyword mlirBoolean true false
85syn match   mlirComment /\/\/.*$/
86syn region  mlirString start=/"/ skip=/\\"/ end=/"/
87syn match   mlirLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/
88syn match   mlirIdentifier /[%@][a-zA-Z$._-][a-zA-Z0-9$._-]*/
89syn match   mlirIdentifier /[%@!]\d\+\>/
90syn match mlirMapSetOutline "#.*$"
91
92" Syntax-highlight lit test commands and bug numbers.
93syn match  mlirSpecialComment /\/\/\s*RUN:.*$/
94syn match  mlirSpecialComment /\/\/\s*CHECK:.*$/
95syn match  mlirSpecialComment "\v\/\/\s*CHECK-(NEXT|NOT|DAG|SAME|LABEL):.*$"
96syn match  mlirSpecialComment /\/\/\s*expected-error.*$/
97syn match  mlirSpecialComment /\/\/\s*expected-remark.*$/
98syn match  mlirSpecialComment /;\s*XFAIL:.*$/
99syn match  mlirSpecialComment /\/\/\s*PR\d*\s*$/
100syn match  mlirSpecialComment /\/\/\s*REQUIRES:.*$/
101
102if version >= 508 || !exists("did_c_syn_inits")
103  if version < 508
104    let did_c_syn_inits = 1
105    command -nargs=+ HiLink hi link <args>
106  else
107    command -nargs=+ HiLink hi def link <args>
108  endif
109
110  HiLink mlirType Type
111  HiLink mlirOps Statement
112  HiLink mlirMapSetOutline PreProc
113  HiLink mlirNumber Number
114  HiLink mlirComment Comment
115  HiLink mlirString String
116  HiLink mlirLabel Label
117  HiLink mlirKeyword Keyword
118  HiLink mlirBoolean Boolean
119  HiLink mlirFloat Float
120  HiLink mlirConstant Constant
121  HiLink mlirSpecialComment SpecialComment
122  HiLink mlirIdentifier Identifier
123
124  delcommand HiLink
125endif
126
127let b:current_syntax = "mlir"
128