Add llvm-mir highlighting (#1398)
* Add injection regex for more languages To support embedding them in other languages like markdown. * Add llvm-mir highlighting LLVM Machine IR is dumped as yaml files that can embed LLVM IR and Machine IR. To support this, add a llvm-mir-yaml language that uses the yaml parser, but uses different injections to highlight IR and MIR. * Update submodule with fixed multiline comments Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
This commit is contained in:
parent
7c9d3682db
commit
641255ccc8
14 changed files with 203 additions and 3 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -174,6 +174,10 @@
|
||||||
path = helix-syntax/languages/tree-sitter-git-commit
|
path = helix-syntax/languages/tree-sitter-git-commit
|
||||||
url = https://github.com/the-mikedavis/tree-sitter-git-commit.git
|
url = https://github.com/the-mikedavis/tree-sitter-git-commit.git
|
||||||
shallow = true
|
shallow = true
|
||||||
|
[submodule "helix-syntax/languages/tree-sitter-llvm-mir"]
|
||||||
|
path = helix-syntax/languages/tree-sitter-llvm-mir
|
||||||
|
url = https://github.com/Flakebi/tree-sitter-llvm-mir.git
|
||||||
|
shallow = true
|
||||||
[submodule "helix-syntax/languages/tree-sitter-git-diff"]
|
[submodule "helix-syntax/languages/tree-sitter-git-diff"]
|
||||||
path = helix-syntax/languages/tree-sitter-git-diff
|
path = helix-syntax/languages/tree-sitter-git-diff
|
||||||
url = https://github.com/the-mikedavis/tree-sitter-git-diff.git
|
url = https://github.com/the-mikedavis/tree-sitter-git-diff.git
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
| latex | ✓ | | | |
|
| latex | ✓ | | | |
|
||||||
| ledger | ✓ | | | |
|
| ledger | ✓ | | | |
|
||||||
| llvm | ✓ | ✓ | ✓ | |
|
| llvm | ✓ | ✓ | ✓ | |
|
||||||
|
| llvm-mir | ✓ | ✓ | ✓ | |
|
||||||
|
| llvm-mir-yaml | ✓ | | ✓ | |
|
||||||
| lua | ✓ | | ✓ | |
|
| lua | ✓ | | ✓ | |
|
||||||
| markdown | ✓ | | | |
|
| markdown | ✓ | | | |
|
||||||
| mint | | | | `mint` |
|
| mint | | | | `mint` |
|
||||||
|
|
|
@ -436,6 +436,7 @@ where
|
||||||
comment_token: None,
|
comment_token: None,
|
||||||
auto_format: false,
|
auto_format: false,
|
||||||
diagnostic_severity: Severity::Warning,
|
diagnostic_severity: Severity::Warning,
|
||||||
|
tree_sitter_library: None,
|
||||||
language_server: None,
|
language_server: None,
|
||||||
indent: Some(IndentationConfiguration {
|
indent: Some(IndentationConfiguration {
|
||||||
tab_width: 4,
|
tab_width: 4,
|
||||||
|
|
|
@ -67,6 +67,8 @@ pub struct LanguageConfiguration {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub diagnostic_severity: Severity,
|
pub diagnostic_severity: Severity,
|
||||||
|
|
||||||
|
pub tree_sitter_library: Option<String>, // tree-sitter library name, defaults to language_id
|
||||||
|
|
||||||
// content_regex
|
// content_regex
|
||||||
#[serde(default, skip_serializing, deserialize_with = "deserialize_regex")]
|
#[serde(default, skip_serializing, deserialize_with = "deserialize_regex")]
|
||||||
pub injection_regex: Option<Regex>,
|
pub injection_regex: Option<Regex>,
|
||||||
|
@ -192,9 +194,14 @@ impl LanguageConfiguration {
|
||||||
if highlights_query.is_empty() {
|
if highlights_query.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let language = get_language(&crate::RUNTIME_DIR, &self.language_id)
|
let language = get_language(
|
||||||
.map_err(|e| log::info!("{}", e))
|
&crate::RUNTIME_DIR,
|
||||||
.ok()?;
|
self.tree_sitter_library
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or(&self.language_id),
|
||||||
|
)
|
||||||
|
.map_err(|e| log::info!("{}", e))
|
||||||
|
.ok()?;
|
||||||
let config = HighlightConfiguration::new(
|
let config = HighlightConfiguration::new(
|
||||||
language,
|
language,
|
||||||
&highlights_query,
|
&highlights_query,
|
||||||
|
|
1
helix-syntax/languages/tree-sitter-llvm-mir
Submodule
1
helix-syntax/languages/tree-sitter-llvm-mir
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 06fabca19454b2dc00c1b211a7cb7ad0bc2585f1
|
|
@ -334,6 +334,7 @@ file-types = ["yml", "yaml"]
|
||||||
roots = []
|
roots = []
|
||||||
comment-token = "#"
|
comment-token = "#"
|
||||||
indent = { tab-width = 2, unit = " " }
|
indent = { tab-width = 2, unit = " " }
|
||||||
|
injection-regex = "yml|yaml"
|
||||||
|
|
||||||
# [[language]]
|
# [[language]]
|
||||||
# name = "haskell"
|
# name = "haskell"
|
||||||
|
@ -386,6 +387,7 @@ roots = []
|
||||||
comment-token = "#"
|
comment-token = "#"
|
||||||
indent = { tab-width = 2, unit = " " }
|
indent = { tab-width = 2, unit = " " }
|
||||||
language-server = { command = "cmake-language-server" }
|
language-server = { command = "cmake-language-server" }
|
||||||
|
injection-regex = "cmake"
|
||||||
|
|
||||||
[[language]]
|
[[language]]
|
||||||
name = "glsl"
|
name = "glsl"
|
||||||
|
@ -394,6 +396,7 @@ file-types = ["glsl", "vert", "tesc", "tese", "geom", "frag", "comp" ]
|
||||||
roots = []
|
roots = []
|
||||||
comment-token = "//"
|
comment-token = "//"
|
||||||
indent = { tab-width = 4, unit = " " }
|
indent = { tab-width = 4, unit = " " }
|
||||||
|
injection-regex = "glsl"
|
||||||
|
|
||||||
[[language]]
|
[[language]]
|
||||||
name = "perl"
|
name = "perl"
|
||||||
|
@ -435,6 +438,25 @@ roots = []
|
||||||
file-types = ["ll"]
|
file-types = ["ll"]
|
||||||
comment-token = ";"
|
comment-token = ";"
|
||||||
indent = { tab-width = 2, unit = " " }
|
indent = { tab-width = 2, unit = " " }
|
||||||
|
injection-regex = "llvm"
|
||||||
|
|
||||||
|
[[language]]
|
||||||
|
name = "llvm-mir"
|
||||||
|
scope = "source.llvm_mir"
|
||||||
|
roots = []
|
||||||
|
file-types = []
|
||||||
|
comment-token = ";"
|
||||||
|
indent = { tab-width = 2, unit = " " }
|
||||||
|
injection-regex = "mir"
|
||||||
|
|
||||||
|
[[language]]
|
||||||
|
name = "llvm-mir-yaml"
|
||||||
|
tree-sitter-library = "yaml"
|
||||||
|
scope = "source.yaml"
|
||||||
|
roots = []
|
||||||
|
file-types = ["mir"]
|
||||||
|
comment-token = "#"
|
||||||
|
indent = { tab-width = 2, unit = " " }
|
||||||
|
|
||||||
[[language]]
|
[[language]]
|
||||||
name = "tablegen"
|
name = "tablegen"
|
||||||
|
|
1
runtime/queries/llvm-mir-yaml/highlights.scm
Normal file
1
runtime/queries/llvm-mir-yaml/highlights.scm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
; inherits: yaml
|
3
runtime/queries/llvm-mir-yaml/indents.toml
Normal file
3
runtime/queries/llvm-mir-yaml/indents.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
indent = [
|
||||||
|
"block_mapping_pair",
|
||||||
|
]
|
9
runtime/queries/llvm-mir-yaml/injections.scm
Normal file
9
runtime/queries/llvm-mir-yaml/injections.scm
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
; inherits: yaml
|
||||||
|
|
||||||
|
((document (block_node (block_scalar) @injection.content))
|
||||||
|
(#set! injection.language "llvm"))
|
||||||
|
|
||||||
|
((document (block_node (block_mapping (block_mapping_pair
|
||||||
|
key: (flow_node (plain_scalar (string_scalar))) ; "body"
|
||||||
|
value: (block_node (block_scalar) @injection.content)))))
|
||||||
|
(#set! injection.language "mir"))
|
136
runtime/queries/llvm-mir/highlights.scm
Normal file
136
runtime/queries/llvm-mir/highlights.scm
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
[
|
||||||
|
(label)
|
||||||
|
(bb_ref)
|
||||||
|
] @label
|
||||||
|
|
||||||
|
[
|
||||||
|
(comment)
|
||||||
|
(multiline_comment)
|
||||||
|
] @comment
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"<"
|
||||||
|
">"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
","
|
||||||
|
":"
|
||||||
|
"|"
|
||||||
|
"*"
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"="
|
||||||
|
"x"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"true"
|
||||||
|
"false"
|
||||||
|
] @constant.builtin.boolean
|
||||||
|
|
||||||
|
[
|
||||||
|
"null"
|
||||||
|
"_"
|
||||||
|
"unknown-address"
|
||||||
|
] @constant.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
(stack_object)
|
||||||
|
(constant_pool_index)
|
||||||
|
(jump_table_index)
|
||||||
|
(var)
|
||||||
|
(physical_register)
|
||||||
|
(ir_block)
|
||||||
|
(external_symbol)
|
||||||
|
(global_var)
|
||||||
|
(ir_local_var)
|
||||||
|
(metadata_ref)
|
||||||
|
(mnemonic)
|
||||||
|
] @variable
|
||||||
|
|
||||||
|
(low_level_type) @type
|
||||||
|
|
||||||
|
[
|
||||||
|
(immediate_type)
|
||||||
|
(primitive_type)
|
||||||
|
] @type.builtin
|
||||||
|
|
||||||
|
(number) @constant.numeric.integer
|
||||||
|
(float) @constant.numeric.float
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
(instruction name: _ @keyword.operator)
|
||||||
|
|
||||||
|
[
|
||||||
|
"successors"
|
||||||
|
"liveins"
|
||||||
|
"pre-instr-symbol"
|
||||||
|
"post-instr-symbol"
|
||||||
|
"heap-alloc-marker"
|
||||||
|
"debug-instr-number"
|
||||||
|
"debug-location"
|
||||||
|
"mcsymbol"
|
||||||
|
"tied-def"
|
||||||
|
"target-flags"
|
||||||
|
"CustomRegMask"
|
||||||
|
"same_value"
|
||||||
|
"def_cfa_register"
|
||||||
|
"restore"
|
||||||
|
"undefined"
|
||||||
|
"offset"
|
||||||
|
"rel_offset"
|
||||||
|
"def_cfa"
|
||||||
|
"llvm_def_aspace_cfa"
|
||||||
|
"register"
|
||||||
|
"escape"
|
||||||
|
"remember_state"
|
||||||
|
"restore_state"
|
||||||
|
"window_save"
|
||||||
|
"negate_ra_sign_state"
|
||||||
|
"intpred"
|
||||||
|
"floatpred"
|
||||||
|
"shufflemask"
|
||||||
|
"liveout"
|
||||||
|
"target-index"
|
||||||
|
"blockaddress"
|
||||||
|
"intrinsic"
|
||||||
|
"load"
|
||||||
|
"store"
|
||||||
|
"unknown-size"
|
||||||
|
"on"
|
||||||
|
"from"
|
||||||
|
"into"
|
||||||
|
"align"
|
||||||
|
"basealign"
|
||||||
|
"addrspace"
|
||||||
|
"call-entry"
|
||||||
|
"custom"
|
||||||
|
"constant-pool"
|
||||||
|
"stack"
|
||||||
|
"got"
|
||||||
|
"jump-table"
|
||||||
|
"syncscope"
|
||||||
|
"address-taken"
|
||||||
|
"landing-pad"
|
||||||
|
"inlineasm-br-indirect-target"
|
||||||
|
"ehfunclet-entry"
|
||||||
|
"bbsections"
|
||||||
|
|
||||||
|
(intpred)
|
||||||
|
(floatpred)
|
||||||
|
(memory_operand_flag)
|
||||||
|
(atomic_ordering)
|
||||||
|
(register_flag)
|
||||||
|
(instruction_flag)
|
||||||
|
(float_keyword)
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
(ERROR) @error
|
7
runtime/queries/llvm-mir/indents.toml
Normal file
7
runtime/queries/llvm-mir/indents.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
indent = [
|
||||||
|
"basic_block",
|
||||||
|
]
|
||||||
|
|
||||||
|
outdent = [
|
||||||
|
"label",
|
||||||
|
]
|
2
runtime/queries/llvm-mir/injections.scm
Normal file
2
runtime/queries/llvm-mir/injections.scm
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
([ (comment) (multiline_comment)] @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
3
runtime/queries/llvm-mir/textobjects.scm
Normal file
3
runtime/queries/llvm-mir/textobjects.scm
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
(basic_block) @function.around
|
||||||
|
|
||||||
|
(argument) @parameter.inside
|
2
runtime/queries/yaml/injections.scm
Normal file
2
runtime/queries/yaml/injections.scm
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
Loading…
Add table
Reference in a new issue