-*- llvm/utils/vim/README -*-
-These are syntax highlighting files for the VIM editor. Included are:
+This directory contains settings for the vim editor to work on llvm *.ll and
+tablegen *.td files. It comes with filetype detection rules in the (ftdetect),
+syntax highlighting (syntax), some minimal sensible default settings (ftplugin)
+and indentation plugins (indent).
-* llvm.vim
-
- Syntax highlighting mode for LLVM assembly files. To use, copy `llvm.vim' to
- ~/.vim/syntax and add this code to your ~/.vimrc :
-
- augroup filetype
- au! BufRead,BufNewFile *.ll set filetype=llvm
- augroup END
-
-* tablegen.vim
-
- Syntax highlighting mode for TableGen description files. To use, copy
- `tablegen.vim' to ~/.vim/syntax and add this code to your ~/.vimrc :
-
- augroup filetype
- au! BufRead,BufNewFile *.td set filetype=tablegen
- augroup END
-
-
-If you prefer, instead of making copies you can make symlinks from
-~/.vim/syntax/... to the syntax files in your LLVM source tree. Apparently
-this did not work with older versions of vim however, so if this doesn't
-work you may need to make actual copies of the files.
-
-Another option, if you do not already have a ~/.vim/syntax directory, is
-to symlink ~/.vim/syntax itself to llvm/utils/vim .
+To install copy all subdirectories to your $HOME/.vim or if you prefer create
+symlinks to the files here. Do not copy the vimrc file here it is only meant as an inspiration and starting point for those working on llvm c++ code.
Note: If you notice missing or incorrect syntax highlighting, please contact
<llvmbugs [at] cs.uiuc.edu>; if you wish to provide a patch to improve the
--- /dev/null
+au BufRead,BufNewFile *.ll set filetype=llvm
--- /dev/null
+au BufRead,BufNewFile *.td set filetype=tablegen
--- /dev/null
+" Vim filetype plugin file
+" Language: LLVM Assembly
+" Maintainer: The LLVM team, http://llvm.org/
+
+if exists("b:did_ftplugin")
+ finish
+endif
+let b:did_ftplugin = 1
+
+setlocal softtabstop=2 shiftwidth=2
+setlocal expandtab
--- /dev/null
+" Vim filetype plugin file
+" Language: LLVM TableGen
+" Maintainer: The LLVM team, http://llvm.org/
+
+if exists("b:did_ftplugin")
+ finish
+endif
+let b:did_ftplugin = 1
+
+setlocal matchpairs+=<:>
+setlocal softtabstop=2 shiftwidth=2
+setlocal expandtab
--- /dev/null
+" Vim indent file
+" Language: llvm
+" Maintainer: The LLVM team, http://llvm.org/
+" 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 ends with ':' increase indentation
+" - If the current line 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=GetLLVMIndent()
+
+if exists("*GetLLVMIndent")
+ finish
+endif
+
+function! FindOpenBracket(lnum)
+ call cursor(a:lnum, 1)
+ return searchpair('{', '', '}', 'bW')
+endfun
+
+function! GetLLVMIndent()
+ " 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 =~ ':\s*$'
+ let blockbegin = FindOpenBracket(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_num > 0 && synIDattr(synID(prev_lnum, indent(prev_lnum)+1, 0), "name") =? "string\|comment"
+ 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 block or labels
+ if prevline =~ '{\s*$' || prevline =~ ':\s*$'
+ let ind = ind + &shiftwidth
+ endif
+
+ return ind
+endfunction
+++ /dev/null
-" Vim syntax file
-" Language: llvm
-" Maintainer: The LLVM team, http://llvm.org/
-" Version: $Revision$
-
-if version < 600
- syntax clear
-elseif exists("b:current_syntax")
- finish
-endif
-
-syn case match
-
-" Types.
-" Types also include struct, array, vector, etc. but these don't
-" benefit as much from having dedicated highlighting rules.
-syn keyword llvmType void half float double x86_fp80 fp128 ppc_fp128
-syn keyword llvmType label metadata x86_mmx
-syn keyword llvmType type label opaque
-syn match llvmType /\<i\d\+\>/
-
-" Instructions.
-" The true and false tokens can be used for comparison opcodes, but it's
-" much more common for these tokens to be used for boolean constants.
-syn keyword llvmStatement add addrspacecast alloca and arcp ashr atomicrmw
-syn keyword llvmStatement bitcast br call cmpxchg eq exact extractelement
-syn keyword llvmStatement extractvalue fadd fast fcmp fdiv fence fmul fpext
-syn keyword llvmStatement fptosi fptoui fptrunc free frem fsub getelementptr
-syn keyword llvmStatement icmp inbounds indirectbr insertelement insertvalue
-syn keyword llvmStatement inttoptr invoke landingpad load lshr malloc max min
-syn keyword llvmStatement mul nand ne ninf nnan nsw nsz nuw oeq oge ogt ole
-syn keyword llvmStatement olt one or ord phi ptrtoint resume ret sdiv select
-syn keyword llvmStatement sext sge sgt shl shufflevector sitofp sle slt srem
-syn keyword llvmStatement store sub switch trunc udiv ueq uge ugt uitofp ule ult
-syn keyword llvmStatement umax umin une uno unreachable unwind urem va_arg
-syn keyword llvmStatement xchg xor zext
-
-" Keywords.
-syn keyword llvmKeyword acq_rel acquire sanitize_address addrspace alias align
-syn keyword llvmKeyword alignstack alwaysinline appending arm_aapcs_vfpcc
-syn keyword llvmKeyword arm_aapcscc arm_apcscc asm atomic available_externally
-syn keyword llvmKeyword blockaddress byval c catch cc ccc cleanup coldcc common
-syn keyword llvmKeyword constant datalayout declare default define deplibs
-syn keyword llvmKeyword distinct dllexport dllimport except extern_weak external
-syn keyword llvmKeyword externally_initialized fastcc filter gc global hidden
-syn keyword llvmKeyword initialexec inlinehint inreg intel_ocl_bicc inteldialect
-syn keyword llvmKeyword internal linkonce linkonce_odr localdynamic localexec
-syn keyword llvmKeyword minsize module monotonic msp430_intrcc naked nest
-syn keyword llvmKeyword noalias nocapture noimplicitfloat noinline nonlazybind
-syn keyword llvmKeyword noredzone noreturn nounwind optnone optsize personality
-syn keyword llvmKeyword private protected ptx_device ptx_kernel readnone
-syn keyword llvmKeyword readonly release returns_twice sanitize_thread
-syn keyword llvmKeyword sanitize_memory section seq_cst sideeffect signext
-syn keyword llvmKeyword singlethread spir_func spir_kernel sret ssp sspreq
-syn keyword llvmKeyword sspstrong tail target thread_local to triple
-syn keyword llvmKeyword unnamed_addr unordered uwtable volatile weak weak_odr
-syn keyword llvmKeyword x86_fastcallcc x86_stdcallcc x86_thiscallcc
-syn keyword llvmKeyword x86_64_sysvcc x86_64_win64cc zeroext uselistorder
-syn keyword llvmKeyword uselistorder_bb
-
-" Obsolete keywords.
-syn keyword llvmError getresult begin end
-
-" Misc syntax.
-syn match llvmNoName /[%@!]\d\+\>/
-syn match llvmNumber /-\?\<\d\+\>/
-syn match llvmFloat /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/
-syn match llvmFloat /\<0x\x\+\>/
-syn keyword llvmBoolean true false
-syn keyword llvmConstant zeroinitializer undef null
-syn match llvmComment /;.*$/
-syn region llvmString start=/"/ skip=/\\"/ end=/"/
-syn match llvmLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/
-syn match llvmIdentifier /[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*/
-
-" Named metadata and specialized metadata keywords.
-syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*$/
-syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*[=!]/
-syn match llvmType /!\zs\a\+\ze\s*(/
-syn match llvmConstant /\<DW_TAG_[a-z_]\+\>/
-syn match llvmConstant /\<DW_ATE_[a-zA-Z_]\+\>/
-syn match llvmConstant /\<DW_OP_[a-zA-Z0-9_]\+\>/
-syn match llvmConstant /\<DW_LANG_[a-zA-Z0-9_]\+\>/
-syn match llvmConstant /\<DW_VIRTUALITY_[a-z_]\+\>/
-syn match llvmConstant /\<DIFlag[A-Za-z]\+\>/
-
-" Syntax-highlight dejagnu test commands.
-syn match llvmSpecialComment /;\s*RUN:.*$/
-syn match llvmSpecialComment /;\s*PR\d*\s*$/
-syn match llvmSpecialComment /;\s*END\.\s*$/
-syn match llvmSpecialComment /;\s*XFAIL:.*$/
-
-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 llvmType Type
- HiLink llvmStatement Statement
- HiLink llvmNumber Number
- HiLink llvmComment Comment
- HiLink llvmString String
- HiLink llvmLabel Label
- HiLink llvmKeyword Keyword
- HiLink llvmBoolean Boolean
- HiLink llvmFloat Float
- HiLink llvmNoName Identifier
- HiLink llvmConstant Constant
- HiLink llvmSpecialComment SpecialComment
- HiLink llvmError Error
- HiLink llvmIdentifier Identifier
-
- delcommand HiLink
-endif
-
-let b:current_syntax = "llvm"
--- /dev/null
+" Vim syntax file
+" Language: llvm
+" Maintainer: The LLVM team, http://llvm.org/
+" Version: $Revision$
+
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+syn case match
+
+" Types.
+" Types also include struct, array, vector, etc. but these don't
+" benefit as much from having dedicated highlighting rules.
+syn keyword llvmType void half float double x86_fp80 fp128 ppc_fp128
+syn keyword llvmType label metadata x86_mmx
+syn keyword llvmType type label opaque
+syn match llvmType /\<i\d\+\>/
+
+" Instructions.
+" The true and false tokens can be used for comparison opcodes, but it's
+" much more common for these tokens to be used for boolean constants.
+syn keyword llvmStatement add addrspacecast alloca and arcp ashr atomicrmw
+syn keyword llvmStatement bitcast br call cmpxchg eq exact extractelement
+syn keyword llvmStatement extractvalue fadd fast fcmp fdiv fence fmul fpext
+syn keyword llvmStatement fptosi fptoui fptrunc free frem fsub getelementptr
+syn keyword llvmStatement icmp inbounds indirectbr insertelement insertvalue
+syn keyword llvmStatement inttoptr invoke landingpad load lshr malloc max min
+syn keyword llvmStatement mul nand ne ninf nnan nsw nsz nuw oeq oge ogt ole
+syn keyword llvmStatement olt one or ord phi ptrtoint resume ret sdiv select
+syn keyword llvmStatement sext sge sgt shl shufflevector sitofp sle slt srem
+syn keyword llvmStatement store sub switch trunc udiv ueq uge ugt uitofp ule ult
+syn keyword llvmStatement umax umin une uno unreachable unwind urem va_arg
+syn keyword llvmStatement xchg xor zext
+
+" Keywords.
+syn keyword llvmKeyword acq_rel acquire sanitize_address addrspace alias align
+syn keyword llvmKeyword alignstack alwaysinline appending arm_aapcs_vfpcc
+syn keyword llvmKeyword arm_aapcscc arm_apcscc asm atomic available_externally
+syn keyword llvmKeyword blockaddress byval c catch cc ccc cleanup coldcc common
+syn keyword llvmKeyword constant datalayout declare default define deplibs
+syn keyword llvmKeyword distinct dllexport dllimport except extern_weak external
+syn keyword llvmKeyword externally_initialized fastcc filter gc global hidden
+syn keyword llvmKeyword initialexec inlinehint inreg intel_ocl_bicc inteldialect
+syn keyword llvmKeyword internal linkonce linkonce_odr localdynamic localexec
+syn keyword llvmKeyword minsize module monotonic msp430_intrcc naked nest
+syn keyword llvmKeyword noalias nocapture noimplicitfloat noinline nonlazybind
+syn keyword llvmKeyword noredzone noreturn nounwind optnone optsize personality
+syn keyword llvmKeyword private protected ptx_device ptx_kernel readnone
+syn keyword llvmKeyword readonly release returns_twice sanitize_thread
+syn keyword llvmKeyword sanitize_memory section seq_cst sideeffect signext
+syn keyword llvmKeyword singlethread spir_func spir_kernel sret ssp sspreq
+syn keyword llvmKeyword sspstrong tail target thread_local to triple
+syn keyword llvmKeyword unnamed_addr unordered uwtable volatile weak weak_odr
+syn keyword llvmKeyword x86_fastcallcc x86_stdcallcc x86_thiscallcc
+syn keyword llvmKeyword x86_64_sysvcc x86_64_win64cc zeroext uselistorder
+syn keyword llvmKeyword uselistorder_bb
+
+" Obsolete keywords.
+syn keyword llvmError getresult begin end
+
+" Misc syntax.
+syn match llvmNoName /[%@!]\d\+\>/
+syn match llvmNumber /-\?\<\d\+\>/
+syn match llvmFloat /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/
+syn match llvmFloat /\<0x\x\+\>/
+syn keyword llvmBoolean true false
+syn keyword llvmConstant zeroinitializer undef null
+syn match llvmComment /;.*$/
+syn region llvmString start=/"/ skip=/\\"/ end=/"/
+syn match llvmLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/
+syn match llvmIdentifier /[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*/
+
+" Named metadata and specialized metadata keywords.
+syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*$/
+syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*[=!]/
+syn match llvmType /!\zs\a\+\ze\s*(/
+syn match llvmConstant /\<DW_TAG_[a-z_]\+\>/
+syn match llvmConstant /\<DW_ATE_[a-zA-Z_]\+\>/
+syn match llvmConstant /\<DW_OP_[a-zA-Z0-9_]\+\>/
+syn match llvmConstant /\<DW_LANG_[a-zA-Z0-9_]\+\>/
+syn match llvmConstant /\<DW_VIRTUALITY_[a-z_]\+\>/
+syn match llvmConstant /\<DIFlag[A-Za-z]\+\>/
+
+" Syntax-highlight dejagnu test commands.
+syn match llvmSpecialComment /;\s*RUN:.*$/
+syn match llvmSpecialComment /;\s*PR\d*\s*$/
+syn match llvmSpecialComment /;\s*END\.\s*$/
+syn match llvmSpecialComment /;\s*XFAIL:.*$/
+
+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 llvmType Type
+ HiLink llvmStatement Statement
+ HiLink llvmNumber Number
+ HiLink llvmComment Comment
+ HiLink llvmString String
+ HiLink llvmLabel Label
+ HiLink llvmKeyword Keyword
+ HiLink llvmBoolean Boolean
+ HiLink llvmFloat Float
+ HiLink llvmNoName Identifier
+ HiLink llvmConstant Constant
+ HiLink llvmSpecialComment SpecialComment
+ HiLink llvmError Error
+ HiLink llvmIdentifier Identifier
+
+ delcommand HiLink
+endif
+
+let b:current_syntax = "llvm"
--- /dev/null
+" Vim syntax file
+" Language: TableGen
+" Maintainer: The LLVM team, http://llvm.org/
+" Version: $Revision$
+
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+" May be changed if you have a really slow machine
+syntax sync minlines=100
+
+syn case match
+
+syn keyword tgKeyword def let in code dag field include defm foreach
+syn keyword tgType class int string list bit bits multiclass
+
+syn match tgNumber /\<\d\+\>/
+syn match tgNumber /\<\d\+\.\d*\>/
+syn match tgNumber /\<0b[01]\+\>/
+syn match tgNumber /\<0x[0-9a-fA-F]\+\>/
+syn region tgString start=/"/ skip=/\\"/ end=/"/ oneline
+
+syn region tgCode start=/\[{/ end=/}\]/
+
+syn keyword tgTodo contained TODO FIXME
+syn match tgComment /\/\/.*$/ contains=tgTodo
+" Handle correctly imbricated comment
+syn region tgComment2 matchgroup=tgComment2 start=+/\*+ end=+\*/+ contains=tgTodo,tgComment2
+
+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 tgKeyword Statement
+ HiLink tgType Type
+ HiLink tgNumber Number
+ HiLink tgComment Comment
+ HiLink tgComment2 Comment
+ HiLink tgString String
+ " May find a better Hilight group...
+ HiLink tgCode Special
+ HiLink tgTodo Todo
+
+ delcommand HiLink
+endif
+
+let b:current_syntax = "tablegen"
+++ /dev/null
-" Vim syntax file
-" Language: TableGen
-" Maintainer: The LLVM team, http://llvm.org/
-" Version: $Revision$
-
-if version < 600
- syntax clear
-elseif exists("b:current_syntax")
- finish
-endif
-
-" May be changed if you have a really slow machine
-syntax sync minlines=100
-
-syn case match
-
-syn keyword tgKeyword def let in code dag field include defm foreach
-syn keyword tgType class int string list bit bits multiclass
-
-syn match tgNumber /\<\d\+\>/
-syn match tgNumber /\<\d\+\.\d*\>/
-syn match tgNumber /\<0b[01]\+\>/
-syn match tgNumber /\<0x[0-9a-fA-F]\+\>/
-syn region tgString start=/"/ skip=/\\"/ end=/"/ oneline
-
-syn region tgCode start=/\[{/ end=/}\]/
-
-syn keyword tgTodo contained TODO FIXME
-syn match tgComment /\/\/.*$/ contains=tgTodo
-" Handle correctly imbricated comment
-syn region tgComment2 matchgroup=tgComment2 start=+/\*+ end=+\*/+ contains=tgTodo,tgComment2
-
-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 tgKeyword Statement
- HiLink tgType Type
- HiLink tgNumber Number
- HiLink tgComment Comment
- HiLink tgComment2 Comment
- HiLink tgString String
- " May find a better Hilight group...
- HiLink tgCode Special
- HiLink tgTodo Todo
-
- delcommand HiLink
-endif
-
-let b:current_syntax = "tablegen"