diff options
Diffstat (limited to 'contrib/llvm/utils/vim')
-rw-r--r-- | contrib/llvm/utils/vim/README | 43 | ||||
-rw-r--r-- | contrib/llvm/utils/vim/llvm.vim | 109 | ||||
-rw-r--r-- | contrib/llvm/utils/vim/tablegen.vim | 54 | ||||
-rw-r--r-- | contrib/llvm/utils/vim/vimrc | 220 |
4 files changed, 426 insertions, 0 deletions
diff --git a/contrib/llvm/utils/vim/README b/contrib/llvm/utils/vim/README new file mode 100644 index 0000000..bca25bf --- /dev/null +++ b/contrib/llvm/utils/vim/README @@ -0,0 +1,43 @@ +-*- llvm/utils/vim/README -*- + +These are syntax highlighting files for the VIM editor. Included are: + +* 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 . + +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 +functionality, it will be most appreciated. Thank you. + +If you find yourself working with LLVM Makefiles often, but you don't get syntax +highlighting (because the files have names such as Makefile.rules or +TEST.nightly.Makefile), add the following to your ~/.vimrc: + + " LLVM Makefile highlighting mode + augroup filetype + au! BufRead,BufNewFile *Makefile* set filetype=make + augroup END diff --git a/contrib/llvm/utils/vim/llvm.vim b/contrib/llvm/utils/vim/llvm.vim new file mode 100644 index 0000000..acebc20 --- /dev/null +++ b/contrib/llvm/utils/vim/llvm.vim @@ -0,0 +1,109 @@ +" Vim syntax file +" Language: llvm +" Maintainer: The LLVM team, http://llvm.org/ +" Version: $Revision: 112382 $ + +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 float double +syn keyword llvmType x86_fp80 fp128 ppc_fp128 +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 fadd sub fsub mul fmul +syn keyword llvmStatement sdiv udiv fdiv srem urem frem +syn keyword llvmStatement and or xor +syn keyword llvmStatement icmp fcmp +syn keyword llvmStatement eq ne ugt uge ult ule sgt sge slt sle +syn keyword llvmStatement oeq ogt oge olt ole one ord ueq ugt uge +syn keyword llvmStatement ult ule une uno +syn keyword llvmStatement nuw nsw exact inbounds +syn keyword llvmStatement phi call select shl lshr ashr va_arg +syn keyword llvmStatement trunc zext sext +syn keyword llvmStatement fptrunc fpext fptoui fptosi uitofp sitofp +syn keyword llvmStatement ptrtoint inttoptr bitcast +syn keyword llvmStatement ret br indirectbr switch invoke unwind unreachable +syn keyword llvmStatement malloc alloca free load store getelementptr +syn keyword llvmStatement extractelement insertelement shufflevector +syn keyword llvmStatement extractvalue insertvalue + +" Keywords. +syn keyword llvmKeyword define declare global constant +syn keyword llvmKeyword internal external private +syn keyword llvmKeyword linkonce linkonce_odr weak weak_odr appending +syn keyword llvmKeyword common extern_weak +syn keyword llvmKeyword thread_local dllimport dllexport +syn keyword llvmKeyword hidden protected default +syn keyword llvmKeyword except deplibs +syn keyword llvmKeyword volatile fastcc coldcc cc ccc +syn keyword llvmKeyword x86_stdcallcc x86_fastcallcc +syn keyword llvmKeyword signext zeroext inreg sret nounwind noreturn +syn keyword llvmKeyword nocapture byval nest readnone readonly noalias +syn keyword llvmKeyword inlinehint noinline alwaysinline optsize ssp sspreq +syn keyword llvmKeyword noredzone noimplicitfloat naked alignstack +syn keyword llvmKeyword module asm align tail to +syn keyword llvmKeyword addrspace section alias sideeffect c gc +syn keyword llvmKeyword target datalayout triple +syn keyword llvmKeyword blockaddress + +" 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]*/ + +" 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:.*$/ +syn match llvmSpecialComment /;\s*XTARGET:.*$/ + +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" diff --git a/contrib/llvm/utils/vim/tablegen.vim b/contrib/llvm/utils/vim/tablegen.vim new file mode 100644 index 0000000..11a4d80 --- /dev/null +++ b/contrib/llvm/utils/vim/tablegen.vim @@ -0,0 +1,54 @@ +" Vim syntax file +" Language: TableGen +" Maintainer: The LLVM team, http://llvm.org/ +" Version: $Revision: 97271 $ + +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 +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" diff --git a/contrib/llvm/utils/vim/vimrc b/contrib/llvm/utils/vim/vimrc new file mode 100644 index 0000000..1f314c2 --- /dev/null +++ b/contrib/llvm/utils/vim/vimrc @@ -0,0 +1,220 @@ +" LLVM coding guidelines conformance for VIM +" $Revision: 112982 $ +" +" Maintainer: The LLVM Team, http://llvm.org +" WARNING: Read before you source in all these commands and macros! Some +" of them may change VIM behavior that you depend on. +" +" You can run VIM with these settings without changing your current setup with: +" $ vim -u /path/to/llvm/utils/vim/vimrc + +" It's VIM, not VI +set nocompatible + +" A tab produces a 2-space indentation +set softtabstop=2 +set shiftwidth=2 +set expandtab + +" Highlight trailing whitespace and lines longer than 80 columns. +highlight LongLine ctermbg=DarkYellow guibg=DarkYellow +highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow +if v:version >= 702 + " Lines longer than 80 columns. + au BufWinEnter * let w:m0=matchadd('LongLine', '\%>80v.\+', -1) + + " Whitespace at the end of a line. This little dance suppresses + " whitespace that has just been typed. + au BufWinEnter * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1) + au InsertEnter * call matchdelete(w:m1) + au InsertEnter * let w:m2=matchadd('WhitespaceEOL', '\s\+\%#\@<!$', -1) + au InsertLeave * call matchdelete(w:m2) + au InsertLeave * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1) +else + au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/ + au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/ + au InsertLeave * syntax match WhitespaceEOL /\s\+$/ +endif + +" Enable filetype detection +filetype on + +" Optional +" C/C++ programming helpers +augroup csrc + au! + autocmd FileType * set nocindent smartindent + autocmd FileType c,cpp set cindent +augroup END +" Set a few indentation parameters. See the VIM help for cinoptions-values for +" details. These aren't absolute rules; they're just an approximation of +" common style in LLVM source. +set cinoptions=:0,g0,(0,Ws,l1 +" Add and delete spaces in increments of `shiftwidth' for tabs +set smarttab + +" Highlight syntax in programming languages +syntax on + +" LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile, +" so it's important to categorize them as such. +augroup filetype + au! BufRead,BufNewFile *Makefile* set filetype=make +augroup END + +" In Makefiles, don't expand tabs to spaces, since we need the actual tabs +autocmd FileType make set noexpandtab + +" Useful macros for cleaning up code to conform to LLVM coding guidelines + +" Delete trailing whitespace and tabs at the end of each line +command! DeleteTrailingWs :%s/\s\+$// + +" Convert all tab characters to two spaces +command! Untab :%s/\t/ /g + +" Enable syntax highlighting for LLVM files. To use, copy +" utils/vim/llvm.vim to ~/.vim/syntax . +augroup filetype + au! BufRead,BufNewFile *.ll set filetype=llvm +augroup END + +" Enable syntax highlighting for tablegen files. To use, copy +" utils/vim/tablegen.vim to ~/.vim/syntax . +augroup filetype + au! BufRead,BufNewFile *.td set filetype=tablegen +augroup END + +" Additional vim features to optionally uncomment. +"set showcmd +"set showmatch +"set showmode +"set incsearch +"set ruler + +" Clang code-completion support. This is highly experimental! + +" A path to a clang executable. +let g:clang_path = "clang++" + +" A list of options to add to the clang commandline, for example to add +" include paths, predefined macros, and language options. +let g:clang_opts = [ + \ "-x","c++", + \ "-D__STDC_LIMIT_MACROS=1","-D__STDC_CONSTANT_MACROS=1", + \ "-Iinclude" ] + +function! ClangComplete(findstart, base) + if a:findstart == 1 + " In findstart mode, look for the beginning of the current identifier. + let l:line = getline('.') + let l:start = col('.') - 1 + while l:start > 0 && l:line[l:start - 1] =~ '\i' + let l:start -= 1 + endwhile + return l:start + endif + + " Get the current line and column numbers. + let l:l = line('.') + let l:c = col('.') + + " Build a clang commandline to do code completion on stdin. + let l:the_command = shellescape(g:clang_path) . + \ " -cc1 -code-completion-at=-:" . l:l . ":" . l:c + for l:opt in g:clang_opts + let l:the_command .= " " . shellescape(l:opt) + endfor + + " Copy the contents of the current buffer into a string for stdin. + " TODO: The extra space at the end is for working around clang's + " apparent inability to do code completion at the very end of the + " input. + " TODO: Is it better to feed clang the entire file instead of truncating + " it at the current line? + let l:process_input = join(getline(1, l:l), "\n") . " " + + " Run it! + let l:input_lines = split(system(l:the_command, l:process_input), "\n") + + " Parse the output. + for l:input_line in l:input_lines + " Vim's substring operator is annoyingly inconsistent with python's. + if l:input_line[:11] == 'COMPLETION: ' + let l:value = l:input_line[12:] + + " Chop off anything after " : ", if present, and move it to the menu. + let l:menu = "" + let l:spacecolonspace = stridx(l:value, " : ") + if l:spacecolonspace != -1 + let l:menu = l:value[l:spacecolonspace+3:] + let l:value = l:value[:l:spacecolonspace-1] + endif + + " Chop off " (Hidden)", if present, and move it to the menu. + let l:hidden = stridx(l:value, " (Hidden)") + if l:hidden != -1 + let l:menu .= " (Hidden)" + let l:value = l:value[:l:hidden-1] + endif + + " Handle "Pattern". TODO: Make clang less weird. + if l:value == "Pattern" + let l:value = l:menu + let l:pound = stridx(l:value, "#") + " Truncate the at the first [#, <#, or {#. + if l:pound != -1 + let l:value = l:value[:l:pound-2] + endif + endif + + " Filter out results which don't match the base string. + if a:base != "" + if l:value[:strlen(a:base)-1] != a:base + continue + end + endif + + " TODO: Don't dump the raw input into info, though it's nice for now. + " TODO: The kind string? + let l:item = { + \ "word": l:value, + \ "menu": l:menu, + \ "info": l:input_line, + \ "dup": 1 } + + " Report a result. + if complete_add(l:item) == 0 + return [] + endif + if complete_check() + return [] + endif + + elseif l:input_line[:9] == "OVERLOAD: " + " An overload candidate. Use a crazy hack to get vim to + " display the results. TODO: Make this better. + let l:value = l:input_line[10:] + let l:item = { + \ "word": " ", + \ "menu": l:value, + \ "info": l:input_line, + \ "dup": 1} + + " Report a result. + if complete_add(l:item) == 0 + return [] + endif + if complete_check() + return [] + endif + + endif + endfor + + + return [] +endfunction ClangComplete + +" Uncomment this to enable the highly-broken autocompletion support. +"set omnifunc=ClangComplete |