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" Math ops.
47syn match mlirOps /\<math\.erf\>/
48
49" Affine ops.
50syn match mlirOps /\<affine\.apply\>/
51syn match mlirOps /\<affine\.dma_start\>/
52syn match mlirOps /\<affine\.dma_wait\>/
53syn match mlirOps /\<affine\.for\>/
54syn match mlirOps /\<affine\.if\>/
55syn match mlirOps /\<affine\.load\>/
56syn match mlirOps /\<affine\.parallel\>/
57syn match mlirOps /\<affine\.prefetch\>/
58syn match mlirOps /\<affine\.store\>/
59syn match mlirOps /\<scf\.execute_region\>/
60syn match mlirOps /\<scf\.for\>/
61syn match mlirOps /\<scf\.if\>/
62syn match mlirOps /\<scf\.yield\>/
63
64" TODO: dialect name prefixed ops (llvm or std).
65
66" Keywords.
67syn keyword mlirKeyword
68      \ affine_map
69      \ affine_set
70      \ dense
71      \ else
72      \ func
73      \ module
74      \ return
75      \ step
76      \ to
77
78" Misc syntax.
79
80syn match   mlirNumber /-\?\<\d\+\>/
81" Match numbers even in shaped types.
82syn match   mlirNumber /-\?\<\d\+\ze\s*x/
83syn match   mlirNumber /x\s*\zs-\?\d\+\ze\s*x/
84
85syn match   mlirFloat  /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/
86syn match   mlirFloat  /\<0x\x\+\>/
87syn keyword mlirBoolean true false
88syn match   mlirComment /\/\/.*$/
89syn region  mlirString start=/"/ skip=/\\"/ end=/"/
90syn match   mlirLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/
91syn match   mlirIdentifier /[%@][a-zA-Z$._-][a-zA-Z0-9$._-]*/
92syn match   mlirIdentifier /[%@!]\d\+\>/
93syn match mlirMapSetOutline "#.*$"
94
95" Syntax-highlight lit test commands and bug numbers.
96syn match  mlirSpecialComment /\/\/\s*RUN:.*$/
97syn match  mlirSpecialComment /\/\/\s*CHECK:.*$/
98syn match  mlirSpecialComment "\v\/\/\s*CHECK-(NEXT|NOT|DAG|SAME|LABEL):.*$"
99syn match  mlirSpecialComment /\/\/\s*expected-error.*$/
100syn match  mlirSpecialComment /\/\/\s*expected-remark.*$/
101syn match  mlirSpecialComment /;\s*XFAIL:.*$/
102syn match  mlirSpecialComment /\/\/\s*PR\d*\s*$/
103syn match  mlirSpecialComment /\/\/\s*REQUIRES:.*$/
104
105if version >= 508 || !exists("did_c_syn_inits")
106  if version < 508
107    let did_c_syn_inits = 1
108    command -nargs=+ HiLink hi link <args>
109  else
110    command -nargs=+ HiLink hi def link <args>
111  endif
112
113  HiLink mlirType Type
114  HiLink mlirOps Statement
115  HiLink mlirMapSetOutline PreProc
116  HiLink mlirNumber Number
117  HiLink mlirComment Comment
118  HiLink mlirString String
119  HiLink mlirLabel Label
120  HiLink mlirKeyword Keyword
121  HiLink mlirBoolean Boolean
122  HiLink mlirFloat Float
123  HiLink mlirConstant Constant
124  HiLink mlirSpecialComment SpecialComment
125  HiLink mlirIdentifier Identifier
126
127  delcommand HiLink
128endif
129
130let b:current_syntax = "mlir"
131