summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjavad <uidopsu@gmail.com>2023-02-09 05:19:24 +0330
committerGitHub <noreply@github.com>2023-02-09 10:49:24 +0900
commitf78e9d634f9c1177031d4bdeda93f98d63b6bc12 (patch)
tree6e3eaab73797ff565994d6ef6435454d31e02565
parentae2d47ba831043e34fcd9547c41a76a4800992b8 (diff)
downloadale-f78e9d634f9c1177031d4bdeda93f98d63b6bc12.zip
Add support for llvm-mc as an assembly linter (#4446)
-rw-r--r--ale_linters/asm/llvm_mc.vim37
-rw-r--r--doc/ale-asm.txt19
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/handler/test_llvm_mc_handler.vader28
-rw-r--r--test/linter/test_llvm_mc.vader19
7 files changed, 106 insertions, 0 deletions
diff --git a/ale_linters/asm/llvm_mc.vim b/ale_linters/asm/llvm_mc.vim
new file mode 100644
index 00000000..ebfd0064
--- /dev/null
+++ b/ale_linters/asm/llvm_mc.vim
@@ -0,0 +1,37 @@
+" Author: uidops <uidops@protonmail.com>
+" Description: llvm-mc linter for asm files
+
+call ale#Set('asm_llvm_mc_executable', 'llvm-mc')
+call ale#Set('asm_llvm_mc_options', '')
+
+function! ale_linters#asm#llvm_mc#GetCommand(buffer) abort
+ return '%e --assemble'
+ \ . ' --filetype=asm'
+ \ . ' -o ' . g:ale#util#nul_file
+ \ . ' ' . ale#Var(a:buffer, 'asm_llvm_mc_options')
+endfunction
+
+function! ale_linters#asm#llvm_mc#Handle(buffer, lines) abort
+ let l:pattern = '^.\+:\(\d\+\):\(\d\+\): \([^:]\+\): \(.\+\)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'lnum': l:match[1] + 0,
+ \ 'col': l:match[2] + 0,
+ \ 'type': l:match[3] =~? 'error' ? 'E' : 'W',
+ \ 'text': l:match[4],
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('asm', {
+\ 'name': 'llvm_mc',
+\ 'output_stream': 'stderr',
+\ 'executable': {b -> ale#Var(b, 'asm_llvm_mc_executable')},
+\ 'command': function('ale_linters#asm#llvm_mc#GetCommand'),
+\ 'callback': 'ale_linters#asm#llvm_mc#Handle',
+\})
+
diff --git a/doc/ale-asm.txt b/doc/ale-asm.txt
index a97c6d00..c5fec7d6 100644
--- a/doc/ale-asm.txt
+++ b/doc/ale-asm.txt
@@ -22,4 +22,23 @@ g:ale_asm_gcc_options *g:ale_asm_gcc_options*
===============================================================================
+llvm_mc *ale-asm-llvm_mc*
+
+g:ale_asm_clang_executable *g:ale_asm_llvm_mc_executable*
+ *b:ale_asm_llvm_mc_executable*
+ Type: |String|
+ Default: `'llvm-mc'`
+
+This variable can be changed to use a different executable for llvm-mc.
+
+
+g:ale_asm_clang_options *g:ale_asm_llvm_mc_options*
+ *b:ale_asm_llvm_mc_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass additional options to llvm-mc.
+
+
+===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index b84fbdae..60b2537e 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -36,6 +36,7 @@ Notes:
* `write-good`
* ASM
* `gcc`
+ * `llvm-mc`
* AVRA
* `avra`
* Awk
diff --git a/doc/ale.txt b/doc/ale.txt
index 1ed74ec5..986d8e25 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2809,6 +2809,7 @@ documented in additional help files.
textlint..............................|ale-asciidoc-textlint|
asm.....................................|ale-asm-options|
gcc...................................|ale-asm-gcc|
+ llvm_mc...............................|ale-asm-llvm_mc|
avra....................................|ale-avra-options|
avra..................................|ale-avra-avra|
awk.....................................|ale-awk-options|
diff --git a/supported-tools.md b/supported-tools.md
index 408bbce1..722bff88 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -45,6 +45,7 @@ formatting.
* [write-good](https://github.com/btford/write-good)
* ASM
* [gcc](https://gcc.gnu.org)
+ * [llvm-mc](https://llvm.org)
* AVRA
* [avra](https://github.com/Ro5bert/avra)
* Awk
diff --git a/test/handler/test_llvm_mc_handler.vader b/test/handler/test_llvm_mc_handler.vader
new file mode 100644
index 00000000..e38ca304
--- /dev/null
+++ b/test/handler/test_llvm_mc_handler.vader
@@ -0,0 +1,28 @@
+Before:
+ runtime ale_linters/asm/llvm_mc.vim
+
+After:
+ call ale#linter#Reset()
+
+Execute(The asm llvm-mc handler should parse lines correctly):
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 10,
+ \ 'col' : 15,
+ \ 'text': "invalid operand for instruction",
+ \ 'type': 'E',
+ \ },
+ \ {
+ \ 'lnum': 11,
+ \ 'col' : 2,
+ \ 'text': "invalid instruction mnemonic 'lpaq'",
+ \ 'type': 'E',
+ \ },
+ \ ],
+ \ ale_linters#asm#llvm_mc#Handle(357, [
+ \ "xorq %rbp, %rbp",
+ \ "{standard_input}:10:15: error: invalid operand for instruction",
+ \ "{standard input}:11:2: error: invalid instruction mnemonic 'lpaq'",
+ \ ])
diff --git a/test/linter/test_llvm_mc.vader b/test/linter/test_llvm_mc.vader
new file mode 100644
index 00000000..6d896b26
--- /dev/null
+++ b/test/linter/test_llvm_mc.vader
@@ -0,0 +1,19 @@
+Before:
+ call ale#assert#SetUpLinterTest('asm', 'llvm_mc')
+ call ale#test#SetFilename('test.cpp')
+ let b:command_tail = ' --assemble'
+ \ . ' --filetype=asm'
+ \ . ' -o ' . (has('win32') ? 'nul': '/dev/null')
+ \ . ' '
+
+After:
+ unlet! b:command_tail
+
+ call ale#assert#TearDownLinterTest()
+
+Execute(The executable should be configurable):
+ AssertLinter 'llvm-mc', ale#Escape('llvm-mc') . b:command_tail
+
+ let b:ale_asm_llvm_mc_executable = 'foobar'
+
+ AssertLinter 'foobar', ale#Escape('foobar') . b:command_tail