[llvm] c6a96df - [vim] Add initial syntax definition for .mir files

Cassie Jones via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 23:41:09 PST 2021


Author: Cassie Jones
Date: 2021-02-17T02:38:16-05:00
New Revision: c6a96df3752065a9411e517942e2cd928e7af82e

URL: https://github.com/llvm/llvm-project/commit/c6a96df3752065a9411e517942e2cd928e7af82e
DIFF: https://github.com/llvm/llvm-project/commit/c6a96df3752065a9411e517942e2cd928e7af82e.diff

LOG: [vim] Add initial syntax definition for .mir files

This initial definition handles the yaml container and the embedding of
the inner IRs. As a stopgap, this reuses the LLVM IR syntax highlighting
for the MIR function bodies--even though it's not technically correct,
it produces decent highlighting for a first pass.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D95552

Added: 
    llvm/utils/vim/ftdetect/mir.vim
    llvm/utils/vim/ftplugin/mir.vim
    llvm/utils/vim/syntax/machine-ir.vim
    llvm/utils/vim/syntax/mir.vim

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/utils/vim/ftdetect/mir.vim b/llvm/utils/vim/ftdetect/mir.vim
new file mode 100644
index 000000000000..15d5a63176dc
--- /dev/null
+++ b/llvm/utils/vim/ftdetect/mir.vim
@@ -0,0 +1 @@
+au BufRead,BufNewFile *.mir set filetype=mir

diff  --git a/llvm/utils/vim/ftplugin/mir.vim b/llvm/utils/vim/ftplugin/mir.vim
new file mode 100644
index 000000000000..3779c860c0db
--- /dev/null
+++ b/llvm/utils/vim/ftplugin/mir.vim
@@ -0,0 +1,13 @@
+" Vim filetype plugin file
+" Language: LLVM Machine IR
+" 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
+setlocal comments+=:;
+

diff  --git a/llvm/utils/vim/syntax/machine-ir.vim b/llvm/utils/vim/syntax/machine-ir.vim
new file mode 100644
index 000000000000..7f5373985688
--- /dev/null
+++ b/llvm/utils/vim/syntax/machine-ir.vim
@@ -0,0 +1,11 @@
+" Vim syntax file
+" Language:   mir
+" Maintainer: The LLVM team, http://llvm.org/
+" Version:      $Revision$
+
+" FIXME: MIR doesn't actually match LLVM IR. Reimplement this.
+" See the MIR LangRef: https://llvm.org/docs/MIRLangRef.html
+unlet b:current_syntax  " Unlet so that the LLVM syntax will load
+runtime! syntax/llvm.vim
+unlet b:current_syntax
+let b:current_syntax = "mir"

diff  --git a/llvm/utils/vim/syntax/mir.vim b/llvm/utils/vim/syntax/mir.vim
new file mode 100644
index 000000000000..51ac4982b7c9
--- /dev/null
+++ b/llvm/utils/vim/syntax/mir.vim
@@ -0,0 +1,48 @@
+" Vim syntax file
+" Language:   mir
+" Maintainer: The LLVM team, http://llvm.org/
+" Version:      $Revision$
+
+if version < 600
+  syntax clear
+elseif exists("b:current_syntax")
+  finish
+endif
+
+syn case match
+
+" MIR is embedded in a yaml container, so we load all of the yaml syntax.
+runtime! syntax/yaml.vim
+unlet b:current_syntax
+
+" The first document of a file is allowed to contain an LLVM IR module inside
+" a top-level yaml block string.
+syntax include @LLVM syntax/llvm.vim
+" FIXME: This should only be allowed for the first document of the file
+syntax region llvm start=/\(^---\s*|\)\@<=/ end=/\(^\.\.\.\)\@=/ contains=@LLVM
+
+" The `body:` field of a document contains the MIR dump of the function
+syntax include @MIR syntax/machine-ir.vim
+syntax region mir start=/\(^body:\s*|\)\@<=/ end=/\(^[^[:space:]]\)\@=/ contains=@MIR
+
+" Syntax-highlight lit test commands and bug numbers.
+syn match  mirSpecialComment /#\s*PR\d*\s*$/
+syn match  mirSpecialComment /#\s*REQUIRES:.*$/
+syn match  mirSpecialComment /#\s*RUN:.*$/
+syn match  mirSpecialComment /#\s*ALLOW_RETRIES:.*$/
+syn match  mirSpecialComment /#\s*CHECK:.*$/
+syn match  mirSpecialComment "\v#\s*CHECK-(NEXT|NOT|DAG|SAME|LABEL):.*$"
+syn match  mirSpecialComment /#\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 mirSpecialComment SpecialComment
+endif
+
+let b:current_syntax = "mir"


        


More information about the llvm-commits mailing list