-
Notifications
You must be signed in to change notification settings - Fork 170
[CIR] Provide syntax highlighting support of clang ir for vim/nvim users #1854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+129
−0
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
13decfd
Provide syntax highlighting support of clang ir for vim/nvim users
badumbatish 1db325c
Improve highlighting for comments, add constant keyword, remove redun…
badumbatish bfd7446
Remove redundant highlighting group
badumbatish 5dd4198
Update float coloring, added extra keywords
badumbatish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
au BufRead,BufNewFile *.cir set filetype=cir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
" Vim syntax file | ||
" Language: cir | ||
" Maintainer: The CIR team | ||
" Version: $Revision$ | ||
" Some parts adapted from the LLVM and MLIR vim syntax file. | ||
|
||
if version < 600 | ||
syntax clear | ||
elseif exists("b:current_syntax") | ||
finish | ||
endif | ||
|
||
syn case match | ||
|
||
" Types. | ||
" | ||
syn keyword mlirType index f16 f32 f64 bf16 | ||
" Signless integer types. | ||
syn match mlirType /\<i\d\+\>/ | ||
" Unsigned integer types. | ||
syn match mlirType /\<ui\d\+\>/ | ||
" Signed integer types. | ||
syn match mlirType /\<si\d\+\>/ | ||
|
||
" Elemental types inside memref, tensor, or vector types. | ||
syn match mlirType /x\s*\zs\(bf16|f16\|f32\|f64\|i\d\+\|ui\d\+\|si\d\+\)/ | ||
|
||
" Shaped types. | ||
syn match mlirType /\<memref\ze\s*<.*>/ | ||
syn match mlirType /\<tensor\ze\s*<.*>/ | ||
syn match mlirType /\<vector\ze\s*<.*>/ | ||
|
||
" vector types inside memref or tensor. | ||
syn match mlirType /x\s*\zsvector/ | ||
|
||
" Misc syntax. | ||
|
||
syn match mlirNumber /-\?\<\d\+\>/ | ||
" Match numbers even in shaped types. | ||
syn match mlirNumber /-\?\<\d\+\ze\s*x/ | ||
syn match mlirNumber /x\s*\zs-\?\d\+\ze\s*x/ | ||
|
||
syn match mlirFloat /-\?\<\d\+\.\d*\(e[+-]\d\+\)\?\>/ | ||
syn match mlirFloat /\<0x\x\+\>/ | ||
syn keyword mlirBoolean true false | ||
" Spell checking is enabled only in comments by default. | ||
syn match mlirComment /\/\/.*$/ contains=@Spell | ||
syn region mlirString start=/"/ skip=/\\"/ end=/"/ | ||
syn match mlirLabel /[-a-zA-Z$._][-a-zA-Z$._0-9]*:/ | ||
" Prefixed identifiers usually used for ssa values and symbols. | ||
syn match mlirIdentifier /[%@][a-zA-Z$._-][a-zA-Z0-9$._-]*/ | ||
syn match mlirIdentifier /[%@]\d\+\>/ | ||
" Prefixed identifiers usually used for blocks. | ||
syn match mlirBlockIdentifier /\^[a-zA-Z$._-][a-zA-Z0-9$._-]*/ | ||
syn match mlirBlockIdentifier /\^\d\+\>/ | ||
" Prefixed identifiers usually used for types. | ||
syn match mlirTypeIdentifier /![a-zA-Z$._-][a-zA-Z0-9$._-]*/ | ||
syn match mlirTypeIdentifier /!\d\+\>/ | ||
" Prefixed identifiers usually used for attribute aliases and result numbers. | ||
syn match mlirAttrIdentifier /#[a-zA-Z$._-][a-zA-Z0-9$._-]*/ | ||
syn match mlirAttrIdentifier /#\d\+\>/ | ||
|
||
" Syntax-highlight lit test commands and bug numbers. | ||
" Old highlighting version of MLIR is faulty, any misamount of whitespace before or after on a line | ||
" will not highlight the special comments anymore. | ||
syn match mlirSpecialComment /^\s*\/\/\s*RUN:.*$/ | ||
syn match mlirSpecialComment /^\s*\/\/\s*\(CHECK\|MLIR\|LLVM\|OGCG\):.*$/ | ||
syn match mlirSpecialComment /^\s*\/\/\s*\(CHECK\|MLIR\|LLVM\|OGCG\)-\(NEXT\|NOT\|DAG\|SAME\|LABEL\):.*$/ | ||
syn match mlirSpecialComment /^\s*\/\/\s*expected-error.*$/ | ||
syn match mlirSpecialComment /^\s*\/\/\s*expected-remark.*$/ | ||
syn match mlirSpecialComment /^\s*;\s*XFAIL:.*$/ | ||
syn match mlirSpecialComment /^\s*\/\/\s*PR\d*\s*$/ | ||
syn match mlirSpecialComment /^\s*\/\/\s*REQUIRES:.*$/ | ||
|
||
"""""""""""" CIR SECTION """""""""""" | ||
" CIR blanket operations | ||
syn match cirOps /\vcir(\.\w+)+/ | ||
badumbatish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
syn keyword cirKeyword | ||
badumbatish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
\ from to cond body step | ||
\ align alignment init | ||
\ cond exception | ||
\ null | ||
\ coroutine suspend resume cleanup | ||
\ class union struct | ||
\ do while | ||
\ if then else | ||
\ nsw nuw | ||
\ constant | ||
\ equal default anyof | ||
\ internal external private linkonce_odr | ||
|
||
|
||
syn keyword cirType bytes | ||
|
||
|
||
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 mlirNumber Number | ||
HiLink mlirComment Comment | ||
HiLink mlirString String | ||
HiLink mlirLabel Label | ||
HiLink mlirBoolean Boolean | ||
HiLink mlirFloat Float | ||
HiLink mlirSpecialComment SpecialComment | ||
HiLink mlirIdentifier Identifier | ||
HiLink mlirBlockIdentifier Label | ||
HiLink mlirTypeIdentifier Type | ||
HiLink mlirAttrIdentifier PreProc | ||
|
||
HiLink cirType Type | ||
HiLink cirOps Statement | ||
HiLink cirKeyword Keyword | ||
delcommand HiLink | ||
endif | ||
|
||
let b:current_syntax = "cir" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.