forked from OSchip/llvm-project
Add vim scripts for indent/syntax
- some of it has been adapted from LLVM's vim utils Signed-off-by: Uday Bondhugula <uday@polymagelabs.com> Closes tensorflow/mlir#90 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/90 from bondhugula:vim 22b1c958818c4b09de0ec8e1d7a4893171a03dbf PiperOrigin-RevId: 266071752
This commit is contained in:
parent
7dd5efdf2c
commit
e8d43cafe6
|
@ -0,0 +1,9 @@
|
|||
-*- mlir/utils/vim/README -*-
|
||||
|
||||
This directory contains settings for the vim editor to work on MLIR *.mlir
|
||||
files. It comes with filetype detection rules in the (ftdetect),
|
||||
syntax highlighting (syntax), some minimal sensible default settings (ftplugin)
|
||||
and indentation plugins (indent).
|
||||
|
||||
To install, copy all subdirectories to your $HOME/.vim/, or if you
|
||||
prefer, create symlinks to the files here.
|
|
@ -0,0 +1 @@
|
|||
au BufRead,BufNewFile *.mlir set filetype=mlir
|
|
@ -0,0 +1,12 @@
|
|||
" Vim filetype plugin file
|
||||
" Language: MLIR Assembly
|
||||
" Maintainer: The MLIR team
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal softtabstop=2 shiftwidth=2
|
||||
setlocal expandtab
|
||||
setlocal comments+=://
|
|
@ -0,0 +1,75 @@
|
|||
" Vim indent file
|
||||
" Language: mlir
|
||||
" Maintainer: The MLIR team
|
||||
" Adapted from the LLVM vim indent file
|
||||
" What this indent plugin currently does:
|
||||
" - If no other rule matches copy indent from previous non-empty,
|
||||
" non-commented line.
|
||||
" - On '}' align the same as the line containing the matching '{'.
|
||||
" - If previous line starts with a block label, increase indentation.
|
||||
" - If the current line is a block label and ends with ':' indent at the same
|
||||
" level as the enclosing '{'/'}' block.
|
||||
" Stuff that would be nice to add:
|
||||
" - Continue comments on next line.
|
||||
" - If there is an opening+unclosed parenthesis on previous line indent to
|
||||
" that.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal shiftwidth=2 expandtab
|
||||
|
||||
setlocal indentkeys=0{,0},<:>,!^F,o,O,e
|
||||
setlocal indentexpr=GetMLIRIndent()
|
||||
|
||||
if exists("*GetMLIRIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! FindOpenBrace(lnum)
|
||||
call cursor(a:lnum, 1)
|
||||
return searchpair('{', '', '}', 'bW')
|
||||
endfun
|
||||
|
||||
function! GetMLIRIndent()
|
||||
" On '}' align the same as the line containing the matching '{'
|
||||
let thisline = getline(v:lnum)
|
||||
if thisline =~ '^\s*}'
|
||||
call cursor(v:lnum, 1)
|
||||
silent normal %
|
||||
let opening_lnum = line('.')
|
||||
if opening_lnum != v:lnum
|
||||
return indent(opening_lnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Indent labels the same as the current opening block
|
||||
if thisline =~ '\^\h\+.*:\s*$'
|
||||
let blockbegin = FindOpenBrace(v:lnum)
|
||||
if blockbegin > 0
|
||||
return indent(blockbegin)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Find a non-blank not-completely commented line above the current line.
|
||||
let prev_lnum = prevnonblank(v:lnum - 1)
|
||||
while prev_lnum > 0 && synIDattr(synID(prev_lnum, 1 + indent(prev_lnum), 0), "name") == "mlirComment"
|
||||
let prev_lnum = prevnonblank(prev_lnum-1)
|
||||
endwhile
|
||||
" Hit the start of the file, use zero indent.
|
||||
if prev_lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let ind = indent(prev_lnum)
|
||||
let prevline = getline(prev_lnum)
|
||||
|
||||
" Add a 'shiftwidth' after lines that start a function, block/labels, or a
|
||||
" region.
|
||||
if prevline =~ '{\s*$' || prevline =~ '\^\h\+.*:\s*$'
|
||||
let ind = ind + &shiftwidth
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
|
@ -1,51 +0,0 @@
|
|||
" Copyright 2019 The MLIR Authors.
|
||||
"
|
||||
" Licensed under the Apache License, Version 2.0 (the "License");
|
||||
" you may not use this file except in compliance with the License.
|
||||
" You may obtain a copy of the License at
|
||||
"
|
||||
" http://www.apache.org/licenses/LICENSE-2.0
|
||||
"
|
||||
" Unless required by applicable law or agreed to in writing, software
|
||||
" distributed under the License is distributed on an "AS IS" BASIS,
|
||||
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
" See the License for the specific language governing permissions and
|
||||
" limitations under the License.
|
||||
|
||||
" Vim syntax file
|
||||
" Language: MLIR
|
||||
|
||||
" quit when a syntax file was already loaded
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn keyword mlirType index i1 i2 i4 i8 i13 i16 i32 i64
|
||||
\ f16 f32 tf_control
|
||||
syn keyword mlirType memref tensor vector
|
||||
|
||||
syntax keyword mlirKeywords extfunc cfgfunc mlfunc for to step return
|
||||
syntax keyword mlirConditional if else
|
||||
syntax keyword mlirCoreOps dim addf addi subf subi mulf muli cmpi select constant affine.apply call call_indirect extract_element getTensor memref_cast tensor_cast load store alloc dealloc dma_start dma_wait
|
||||
|
||||
syn match mlirInt "-\=\<\d\+\>"
|
||||
syn match mlirFloat "-\=\<\d\+\.\d\+\>"
|
||||
syn match mlirMapOutline "#.*$"
|
||||
syn match mlirOperator "[+\-*=]"
|
||||
|
||||
syn region mlirComment start="//" skip="\\$" end="$"
|
||||
syn region mlirString matchgroup=mlirString start=+"+ end=+"+
|
||||
|
||||
hi def link mlirComment Comment
|
||||
hi def link mlirKeywords Instruction
|
||||
hi def link mlirCoreOps Instruction
|
||||
hi def link mlirInt Constant
|
||||
hi def link mlirType Type
|
||||
hi def link mlirMapOutline PreProc
|
||||
hi def link mlirConditional Conditional
|
||||
hi def link mlirString String
|
||||
hi def link mlirOperator Operator
|
||||
hi def link mlirInstruction Operator
|
||||
hi def link mlirAffineOp Operator
|
||||
|
||||
let b:current_syntax = "mlir"
|
|
@ -0,0 +1,95 @@
|
|||
" Vim syntax file
|
||||
" Language: mlir
|
||||
" Maintainer: The MLIR team, http://github.com/tensorflow/mlir/
|
||||
" Version: $Revision$
|
||||
" Adapted from the LLVM vim indent file
|
||||
|
||||
if version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn case match
|
||||
|
||||
" Types.
|
||||
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<.*>/
|
||||
|
||||
" 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
|
||||
|
||||
" Affine ops.
|
||||
syn match mlirOps /\<affine\.apply\>/
|
||||
syn match mlirOps /\<affine\.dma_start\>/
|
||||
syn match mlirOps /\<affine\.dma_wait\>/
|
||||
syn match mlirOps /\<affine\.for\>/
|
||||
syn match mlirOps /\<affine\.if\>/
|
||||
syn match mlirOps /\<affine\.load\>/
|
||||
syn match mlirOps /\<affine\.store\>/
|
||||
|
||||
" Keywords.
|
||||
syn keyword mlirKeyword
|
||||
\ else
|
||||
\ func
|
||||
\ return
|
||||
\ step
|
||||
\ to
|
||||
|
||||
" Misc syntax.
|
||||
syn match mlirNoName /[%@!]\d\+\>/
|
||||
syn match mlirNumber /-\?\<\d\+\>/
|
||||
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 mlirMapSetOutline "#.*$"
|
||||
|
||||
" 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 <args>
|
||||
else
|
||||
command -nargs=+ HiLink hi def link <args>
|
||||
endif
|
||||
|
||||
HiLink mlirType Type
|
||||
HiLink mlirOps Statement
|
||||
HiLink mlirMapSetOutline PreProc
|
||||
HiLink mlirNumber Number
|
||||
HiLink mlirComment Comment
|
||||
HiLink mlirString String
|
||||
HiLink mlirLabel Label
|
||||
HiLink mlirKeyword Keyword
|
||||
HiLink mlirBoolean Boolean
|
||||
HiLink mlirFloat Float
|
||||
HiLink mlirNoName Identifier
|
||||
HiLink mlirConstant Constant
|
||||
HiLink mlirSpecialComment SpecialComment
|
||||
HiLink mlirIdentifier Identifier
|
||||
|
||||
delcommand HiLink
|
||||
endif
|
||||
|
||||
let b:current_syntax = "mlir"
|
Loading…
Reference in New Issue