llvm.org GIT mirror llvm / b1675e5
Enhanced vim support. This brings the utils/vim folder into a more vim-like format by moving the syntax hightlighting files into a syntax subdirectory. It adds some minimal settings that everyone should agree on to ftdetect/ftplugin and features a new indentation plugin for .ll files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235369 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 4 years ago
10 changed file(s) with 276 addition(s) and 200 deletion(s). Raw diff Collapse all Expand all
0 -*- llvm/utils/vim/README -*-
11
2 These are syntax highlighting files for the VIM editor. Included are:
2 This directory contains settings for the vim editor to work on llvm *.ll and
3 tablegen *.td files. It comes with filetype detection rules in the (ftdetect),
4 syntax highlighting (syntax), some minimal sensible default settings (ftplugin)
5 and indentation plugins (indent).
36
4 * llvm.vim
5
6 Syntax highlighting mode for LLVM assembly files. To use, copy `llvm.vim' to
7 ~/.vim/syntax and add this code to your ~/.vimrc :
8
9 augroup filetype
10 au! BufRead,BufNewFile *.ll set filetype=llvm
11 augroup END
12
13 * tablegen.vim
14
15 Syntax highlighting mode for TableGen description files. To use, copy
16 `tablegen.vim' to ~/.vim/syntax and add this code to your ~/.vimrc :
17
18 augroup filetype
19 au! BufRead,BufNewFile *.td set filetype=tablegen
20 augroup END
21
22
23 If you prefer, instead of making copies you can make symlinks from
24 ~/.vim/syntax/... to the syntax files in your LLVM source tree. Apparently
25 this did not work with older versions of vim however, so if this doesn't
26 work you may need to make actual copies of the files.
27
28 Another option, if you do not already have a ~/.vim/syntax directory, is
29 to symlink ~/.vim/syntax itself to llvm/utils/vim .
7 To install copy all subdirectories to your $HOME/.vim or if you prefer create
8 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.
309
3110 Note: If you notice missing or incorrect syntax highlighting, please contact
3211 ; if you wish to provide a patch to improve the
0 au BufRead,BufNewFile *.ll set filetype=llvm
0 au BufRead,BufNewFile *.td set filetype=tablegen
0 " Vim filetype plugin file
1 " Language: LLVM Assembly
2 " Maintainer: The LLVM team, http://llvm.org/
3
4 if exists("b:did_ftplugin")
5 finish
6 endif
7 let b:did_ftplugin = 1
8
9 setlocal softtabstop=2 shiftwidth=2
10 setlocal expandtab
0 " Vim filetype plugin file
1 " Language: LLVM TableGen
2 " Maintainer: The LLVM team, http://llvm.org/
3
4 if exists("b:did_ftplugin")
5 finish
6 endif
7 let b:did_ftplugin = 1
8
9 setlocal matchpairs+=<:>
10 setlocal softtabstop=2 shiftwidth=2
11 setlocal expandtab
0 " Vim indent file
1 " Language: llvm
2 " Maintainer: The LLVM team, http://llvm.org/
3 " What this indent plugin currently does:
4 " - If no other rule matches copy indent from previous non-empty,
5 " non-commented line
6 " - On '}' align the same as the line containing the matching '{'
7 " - If previous line ends with ':' increase indentation
8 " - If the current line ends with ':' indent at the same level as the
9 " enclosing '{'/'}' block
10 " Stuff that would be nice to add:
11 " - Continue comments on next line
12 " - If there is an opening+unclosed parenthesis on previous line indent to that
13 if exists("b:did_indent")
14 finish
15 endif
16 let b:did_indent = 1
17
18 setlocal shiftwidth=2 expandtab
19
20 setlocal indentkeys=0{,0},<:>,!^F,o,O,e
21 setlocal indentexpr=GetLLVMIndent()
22
23 if exists("*GetLLVMIndent")
24 finish
25 endif
26
27 function! FindOpenBracket(lnum)
28 call cursor(a:lnum, 1)
29 return searchpair('{', '', '}', 'bW')
30 endfun
31
32 function! GetLLVMIndent()
33 " On '}' align the same as the line containing the matching '{'
34 let thisline = getline(v:lnum)
35 if thisline =~ '^\s*}'
36 call cursor(v:lnum, 1)
37 silent normal %
38 let opening_lnum = line('.')
39 if opening_lnum != v:lnum
40 return indent(opening_lnum)
41 endif
42 endif
43
44 " Indent labels the same as the current opening block
45 if thisline =~ ':\s*$'
46 let blockbegin = FindOpenBracket(v:lnum)
47 if blockbegin > 0
48 return indent(blockbegin)
49 endif
50 endif
51
52 " Find a non-blank not-completely commented line above the current line.
53 let prev_lnum = prevnonblank(v:lnum - 1)
54 while prev_num > 0 && synIDattr(synID(prev_lnum, indent(prev_lnum)+1, 0), "name") =? "string\|comment"
55 let prev_lnum = prevnonblank(prev_lnum-1)
56 endwhile
57 " Hit the start of the file, use zero indent.
58 if prev_lnum == 0
59 return 0
60 endif
61
62 let ind = indent(prev_lnum)
63 let prevline = getline(prev_lnum)
64
65 " Add a 'shiftwidth' after lines that start a block or labels
66 if prevline =~ '{\s*$' || prevline =~ ':\s*$'
67 let ind = ind + &shiftwidth
68 endif
69
70 return ind
71 endfunction
+0
-119
utils/vim/llvm.vim less more
None " Vim syntax file
1 " Language: llvm
2 " Maintainer: The LLVM team, http://llvm.org/
3 " Version: $Revision$
4
5 if version < 600
6 syntax clear
7 elseif exists("b:current_syntax")
8 finish
9 endif
10
11 syn case match
12
13 " Types.
14 " Types also include struct, array, vector, etc. but these don't
15 " benefit as much from having dedicated highlighting rules.
16 syn keyword llvmType void half float double x86_fp80 fp128 ppc_fp128
17 syn keyword llvmType label metadata x86_mmx
18 syn keyword llvmType type label opaque
19 syn match llvmType /\/
20
21 " Instructions.
22 " The true and false tokens can be used for comparison opcodes, but it's
23 " much more common for these tokens to be used for boolean constants.
24 syn keyword llvmStatement add addrspacecast alloca and arcp ashr atomicrmw
25 syn keyword llvmStatement bitcast br call cmpxchg eq exact extractelement
26 syn keyword llvmStatement extractvalue fadd fast fcmp fdiv fence fmul fpext
27 syn keyword llvmStatement fptosi fptoui fptrunc free frem fsub getelementptr
28 syn keyword llvmStatement icmp inbounds indirectbr insertelement insertvalue
29 syn keyword llvmStatement inttoptr invoke landingpad load lshr malloc max min
30 syn keyword llvmStatement mul nand ne ninf nnan nsw nsz nuw oeq oge ogt ole
31 syn keyword llvmStatement olt one or ord phi ptrtoint resume ret sdiv select
32 syn keyword llvmStatement sext sge sgt shl shufflevector sitofp sle slt srem
33 syn keyword llvmStatement store sub switch trunc udiv ueq uge ugt uitofp ule ult
34 syn keyword llvmStatement umax umin une uno unreachable unwind urem va_arg
35 syn keyword llvmStatement xchg xor zext
36
37 " Keywords.
38 syn keyword llvmKeyword acq_rel acquire sanitize_address addrspace alias align
39 syn keyword llvmKeyword alignstack alwaysinline appending arm_aapcs_vfpcc
40 syn keyword llvmKeyword arm_aapcscc arm_apcscc asm atomic available_externally
41 syn keyword llvmKeyword blockaddress byval c catch cc ccc cleanup coldcc common
42 syn keyword llvmKeyword constant datalayout declare default define deplibs
43 syn keyword llvmKeyword distinct dllexport dllimport except extern_weak external
44 syn keyword llvmKeyword externally_initialized fastcc filter gc global hidden
45 syn keyword llvmKeyword initialexec inlinehint inreg intel_ocl_bicc inteldialect
46 syn keyword llvmKeyword internal linkonce linkonce_odr localdynamic localexec
47 syn keyword llvmKeyword minsize module monotonic msp430_intrcc naked nest
48 syn keyword llvmKeyword noalias nocapture noimplicitfloat noinline nonlazybind
49 syn keyword llvmKeyword noredzone noreturn nounwind optnone optsize personality
50 syn keyword llvmKeyword private protected ptx_device ptx_kernel readnone
51 syn keyword llvmKeyword readonly release returns_twice sanitize_thread
52 syn keyword llvmKeyword sanitize_memory section seq_cst sideeffect signext
53 syn keyword llvmKeyword singlethread spir_func spir_kernel sret ssp sspreq
54 syn keyword llvmKeyword sspstrong tail target thread_local to triple
55 syn keyword llvmKeyword unnamed_addr unordered uwtable volatile weak weak_odr
56 syn keyword llvmKeyword x86_fastcallcc x86_stdcallcc x86_thiscallcc
57 syn keyword llvmKeyword x86_64_sysvcc x86_64_win64cc zeroext uselistorder
58 syn keyword llvmKeyword uselistorder_bb
59
60 " Obsolete keywords.
61 syn keyword llvmError getresult begin end
62
63 " Misc syntax.
64 syn match llvmNoName /[%@!]\d\+\>/
65 syn match llvmNumber /-\?\<\d\+\>/
66 syn match llvmFloat /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/
67 syn match llvmFloat /\<0x\x\+\>/
68 syn keyword llvmBoolean true false
69 syn keyword llvmConstant zeroinitializer undef null
70 syn match llvmComment /;.*$/
71 syn region llvmString start=/"/ skip=/\\"/ end=/"/
72 syn match llvmLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/
73 syn match llvmIdentifier /[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*/
74
75 " Named metadata and specialized metadata keywords.
76 syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*$/
77 syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*[=!]/
78 syn match llvmType /!\zs\a\+\ze\s*(/
79 syn match llvmConstant /\/
80 syn match llvmConstant /\/
81 syn match llvmConstant /\/
82 syn match llvmConstant /\/
83 syn match llvmConstant /\/
84 syn match llvmConstant /\/
85
86 " Syntax-highlight dejagnu test commands.
87 syn match llvmSpecialComment /;\s*RUN:.*$/
88 syn match llvmSpecialComment /;\s*PR\d*\s*$/
89 syn match llvmSpecialComment /;\s*END\.\s*$/
90 syn match llvmSpecialComment /;\s*XFAIL:.*$/
91
92 if version >= 508 || !exists("did_c_syn_inits")
93 if version < 508
94 let did_c_syn_inits = 1
95 command -nargs=+ HiLink hi link
96 else
97 command -nargs=+ HiLink hi def link
98 endif
99
100 HiLink llvmType Type
101 HiLink llvmStatement Statement
102 HiLink llvmNumber Number
103 HiLink llvmComment Comment
104 HiLink llvmString String
105 HiLink llvmLabel Label
106 HiLink llvmKeyword Keyword
107 HiLink llvmBoolean Boolean
108 HiLink llvmFloat Float
109 HiLink llvmNoName Identifier
110 HiLink llvmConstant Constant
111 HiLink llvmSpecialComment SpecialComment
112 HiLink llvmError Error
113 HiLink llvmIdentifier Identifier
114
115 delcommand HiLink
116 endif
117
118 let b:current_syntax = "llvm"
0 " Vim syntax file
1 " Language: llvm
2 " Maintainer: The LLVM team, http://llvm.org/
3 " Version: $Revision$
4
5 if version < 600
6 syntax clear
7 elseif exists("b:current_syntax")
8 finish
9 endif
10
11 syn case match
12
13 " Types.
14 " Types also include struct, array, vector, etc. but these don't
15 " benefit as much from having dedicated highlighting rules.
16 syn keyword llvmType void half float double x86_fp80 fp128 ppc_fp128
17 syn keyword llvmType label metadata x86_mmx
18 syn keyword llvmType type label opaque
19 syn match llvmType /\/
20
21 " Instructions.
22 " The true and false tokens can be used for comparison opcodes, but it's
23 " much more common for these tokens to be used for boolean constants.
24 syn keyword llvmStatement add addrspacecast alloca and arcp ashr atomicrmw
25 syn keyword llvmStatement bitcast br call cmpxchg eq exact extractelement
26 syn keyword llvmStatement extractvalue fadd fast fcmp fdiv fence fmul fpext
27 syn keyword llvmStatement fptosi fptoui fptrunc free frem fsub getelementptr
28 syn keyword llvmStatement icmp inbounds indirectbr insertelement insertvalue
29 syn keyword llvmStatement inttoptr invoke landingpad load lshr malloc max min
30 syn keyword llvmStatement mul nand ne ninf nnan nsw nsz nuw oeq oge ogt ole
31 syn keyword llvmStatement olt one or ord phi ptrtoint resume ret sdiv select
32 syn keyword llvmStatement sext sge sgt shl shufflevector sitofp sle slt srem
33 syn keyword llvmStatement store sub switch trunc udiv ueq uge ugt uitofp ule ult
34 syn keyword llvmStatement umax umin une uno unreachable unwind urem va_arg
35 syn keyword llvmStatement xchg xor zext
36
37 " Keywords.
38 syn keyword llvmKeyword acq_rel acquire sanitize_address addrspace alias align
39 syn keyword llvmKeyword alignstack alwaysinline appending arm_aapcs_vfpcc
40 syn keyword llvmKeyword arm_aapcscc arm_apcscc asm atomic available_externally
41 syn keyword llvmKeyword blockaddress byval c catch cc ccc cleanup coldcc common
42 syn keyword llvmKeyword constant datalayout declare default define deplibs
43 syn keyword llvmKeyword distinct dllexport dllimport except extern_weak external
44 syn keyword llvmKeyword externally_initialized fastcc filter gc global hidden
45 syn keyword llvmKeyword initialexec inlinehint inreg intel_ocl_bicc inteldialect
46 syn keyword llvmKeyword internal linkonce linkonce_odr localdynamic localexec
47 syn keyword llvmKeyword minsize module monotonic msp430_intrcc naked nest
48 syn keyword llvmKeyword noalias nocapture noimplicitfloat noinline nonlazybind
49 syn keyword llvmKeyword noredzone noreturn nounwind optnone optsize personality
50 syn keyword llvmKeyword private protected ptx_device ptx_kernel readnone
51 syn keyword llvmKeyword readonly release returns_twice sanitize_thread
52 syn keyword llvmKeyword sanitize_memory section seq_cst sideeffect signext
53 syn keyword llvmKeyword singlethread spir_func spir_kernel sret ssp sspreq
54 syn keyword llvmKeyword sspstrong tail target thread_local to triple
55 syn keyword llvmKeyword unnamed_addr unordered uwtable volatile weak weak_odr
56 syn keyword llvmKeyword x86_fastcallcc x86_stdcallcc x86_thiscallcc
57 syn keyword llvmKeyword x86_64_sysvcc x86_64_win64cc zeroext uselistorder
58 syn keyword llvmKeyword uselistorder_bb
59
60 " Obsolete keywords.
61 syn keyword llvmError getresult begin end
62
63 " Misc syntax.
64 syn match llvmNoName /[%@!]\d\+\>/
65 syn match llvmNumber /-\?\<\d\+\>/
66 syn match llvmFloat /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/
67 syn match llvmFloat /\<0x\x\+\>/
68 syn keyword llvmBoolean true false
69 syn keyword llvmConstant zeroinitializer undef null
70 syn match llvmComment /;.*$/
71 syn region llvmString start=/"/ skip=/\\"/ end=/"/
72 syn match llvmLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/
73 syn match llvmIdentifier /[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*/
74
75 " Named metadata and specialized metadata keywords.
76 syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*$/
77 syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*[=!]/
78 syn match llvmType /!\zs\a\+\ze\s*(/
79 syn match llvmConstant /\/
80 syn match llvmConstant /\/
81 syn match llvmConstant /\/
82 syn match llvmConstant /\/
83 syn match llvmConstant /\/
84 syn match llvmConstant /\/
85
86 " Syntax-highlight dejagnu test commands.
87 syn match llvmSpecialComment /;\s*RUN:.*$/
88 syn match llvmSpecialComment /;\s*PR\d*\s*$/
89 syn match llvmSpecialComment /;\s*END\.\s*$/
90 syn match llvmSpecialComment /;\s*XFAIL:.*$/
91
92 if version >= 508 || !exists("did_c_syn_inits")
93 if version < 508
94 let did_c_syn_inits = 1
95 command -nargs=+ HiLink hi link
96 else
97 command -nargs=+ HiLink hi def link
98 endif
99
100 HiLink llvmType Type
101 HiLink llvmStatement Statement
102 HiLink llvmNumber Number
103 HiLink llvmComment Comment
104 HiLink llvmString String
105 HiLink llvmLabel Label
106 HiLink llvmKeyword Keyword
107 HiLink llvmBoolean Boolean
108 HiLink llvmFloat Float
109 HiLink llvmNoName Identifier
110 HiLink llvmConstant Constant
111 HiLink llvmSpecialComment SpecialComment
112 HiLink llvmError Error
113 HiLink llvmIdentifier Identifier
114
115 delcommand HiLink
116 endif
117
118 let b:current_syntax = "llvm"
0 " Vim syntax file
1 " Language: TableGen
2 " Maintainer: The LLVM team, http://llvm.org/
3 " Version: $Revision$
4
5 if version < 600
6 syntax clear
7 elseif exists("b:current_syntax")
8 finish
9 endif
10
11 " May be changed if you have a really slow machine
12 syntax sync minlines=100
13
14 syn case match
15
16 syn keyword tgKeyword def let in code dag field include defm foreach
17 syn keyword tgType class int string list bit bits multiclass
18
19 syn match tgNumber /\<\d\+\>/
20 syn match tgNumber /\<\d\+\.\d*\>/
21 syn match tgNumber /\<0b[01]\+\>/
22 syn match tgNumber /\<0x[0-9a-fA-F]\+\>/
23 syn region tgString start=/"/ skip=/\\"/ end=/"/ oneline
24
25 syn region tgCode start=/\[{/ end=/}\]/
26
27 syn keyword tgTodo contained TODO FIXME
28 syn match tgComment /\/\/.*$/ contains=tgTodo
29 " Handle correctly imbricated comment
30 syn region tgComment2 matchgroup=tgComment2 start=+/\*+ end=+\*/+ contains=tgTodo,tgComment2
31
32 if version >= 508 || !exists("did_c_syn_inits")
33 if version < 508
34 let did_c_syn_inits = 1
35 command -nargs=+ HiLink hi link
36 else
37 command -nargs=+ HiLink hi def link
38 endif
39
40 HiLink tgKeyword Statement
41 HiLink tgType Type
42 HiLink tgNumber Number
43 HiLink tgComment Comment
44 HiLink tgComment2 Comment
45 HiLink tgString String
46 " May find a better Hilight group...
47 HiLink tgCode Special
48 HiLink tgTodo Todo
49
50 delcommand HiLink
51 endif
52
53 let b:current_syntax = "tablegen"
+0
-54
utils/vim/tablegen.vim less more
None " Vim syntax file
1 " Language: TableGen
2 " Maintainer: The LLVM team, http://llvm.org/
3 " Version: $Revision$
4
5 if version < 600
6 syntax clear
7 elseif exists("b:current_syntax")
8 finish
9 endif
10
11 " May be changed if you have a really slow machine
12 syntax sync minlines=100
13
14 syn case match
15
16 syn keyword tgKeyword def let in code dag field include defm foreach
17 syn keyword tgType class int string list bit bits multiclass
18
19 syn match tgNumber /\<\d\+\>/
20 syn match tgNumber /\<\d\+\.\d*\>/
21 syn match tgNumber /\<0b[01]\+\>/
22 syn match tgNumber /\<0x[0-9a-fA-F]\+\>/
23 syn region tgString start=/"/ skip=/\\"/ end=/"/ oneline
24
25 syn region tgCode start=/\[{/ end=/}\]/
26
27 syn keyword tgTodo contained TODO FIXME
28 syn match tgComment /\/\/.*$/ contains=tgTodo
29 " Handle correctly imbricated comment
30 syn region tgComment2 matchgroup=tgComment2 start=+/\*+ end=+\*/+ contains=tgTodo,tgComment2
31
32 if version >= 508 || !exists("did_c_syn_inits")
33 if version < 508
34 let did_c_syn_inits = 1
35 command -nargs=+ HiLink hi link
36 else
37 command -nargs=+ HiLink hi def link
38 endif
39
40 HiLink tgKeyword Statement
41 HiLink tgType Type
42 HiLink tgNumber Number
43 HiLink tgComment Comment
44 HiLink tgComment2 Comment
45 HiLink tgString String
46 " May find a better Hilight group...
47 HiLink tgCode Special
48 HiLink tgTodo Todo
49
50 delcommand HiLink
51 endif
52
53 let b:current_syntax = "tablegen"