summaryrefslogtreecommitdiff
path: root/ale_linters/asm/gcc.vim
blob: c25d4aecfb292e365f747a02791bb919f78ed19d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
" Author: Lucas Kolstad <lkolstad@uw.edu>
" Description: gcc linter for asm files

let g:ale_asm_gcc_options = get(g:, 'ale_asm_gcc_options', '-Wall')

function! ale_linters#asm#gcc#GetCommand(buffer) abort
    return 'gcc -x assembler -fsyntax-only '
    \    . '-iquote ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
    \    . ' ' . ale#Var(a:buffer, 'asm_gcc_options') . ' -'
endfunction

function! ale_linters#asm#gcc#Handle(buffer, lines) abort
    let l:pattern = '^.\+:\(\d\+\): \([^:]\+\): \(.\+\)$'
    let l:output = []

    for l:line in a:lines
        let l:match = matchlist(l:line, l:pattern)

        if len(l:match) == 0
            continue
        endif

        call add(l:output, {
        \ 'bufnr': a:buffer,
        \ 'lnum': l:match[1] + 0,
        \ 'vcol': 0,
        \ 'col': 0,
        \ 'text': l:match[3],
        \ 'type': l:match[2] =~? 'error' ? 'E' : 'W',
        \ 'nr': -1,
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('asm', {
\    'name': 'gcc',
\    'output_stream': 'stderr',
\    'executable': 'gcc',
\    'command_callback': 'ale_linters#asm#gcc#GetCommand',
\    'callback': 'ale_linters#asm#gcc#Handle',
\})