2

私はLLVM-IRコードで作業しており、によって生成されclang -emit-llvm、コードの折りたたみを機能させたいと考えています。

これまでのところ、私は と を使用foldmethod=exprしてfoldexpr=LLVMFold()います。foldmethod=syntaxllvm リポジトリの構文ファイルを使用して、構文ベースの折りたたみ (つまり) を使用したいと考えています。こちらから入手できます

最初の正規表現は、ラベルの構文ファイルからのものであることに注意してください。

function! LLVMFolds()
    let thisline = getline(v:lnum)
    if match(thisline, '^[-a-zA-Z$._][-a-zA-Z$._0-9]*:') >= 0
        return ">2"
    elseif match(thisline, '^\}$') >= 0
        return "<1"
    elseif match(thisline, '{$') >= 0
        return ">1"
    else
        return "="
    endif
endfunction

Which gobbles the closing braces into the level 2 folds.

Also tried have been foldmethod=indent which didn't fold enough and foldmethod=marker with foldmark="{,}" Ideally for this sample incomplete LLVM-IR code:

define i32 @main() nounwind {
entry:
  %retval = alloca i32, align 4

for.cond:                                         ; preds = %entry
  %4 = load i32* %i, align 4
  %cmp1 = icmp slt i32 %4, 10
  br i1 %cmp1, label %for.body, label %for.end
}

I would like folds to be from the { of the define to the } and in each labelled section, i.e. from the entry: to the clear line.

4

2 に答える 2

0

私は今、この機能を使用しています

function! LLVMFolds()
    let thisline = getline(v:lnum)
    let nextline = getline(v:lnum + 1)
    " match start of global var block
    if match(thisline, '^@') == 0 && foldlevel(v:lnum - 1) <= 0
        return ">1"
    " match start of global struct block
    elseif match(thisline, '^%') == 0 && foldlevel(v:lnum - 1) <= 0
        return ">1"
    " matches lables
    elseif match(thisline, '^[-a-zA-Z$._][-a-zA-Z$._0-9]*:') >= 0
        return ">2"
    " keep closing brace outside  l2 fold
    elseif match(nextline, '^\}$') >= 0
        return "<2"
    " keep closing brace in l1 fold
    elseif match(thisline, '^\}$') >= 0
        return "<1"
    " open new l1 fold for open brace
    elseif match(thisline, '{$') >= 0
        return ">1"
    " for the next line being empty, close the fold for the var and struct blocks
    elseif match(nextline, '^$') >= 0
        if match(thisline, '^@') == 0 && foldlevel(v:lnum - 1) == 1
            return "<1"
        elseif match(thisline, '^%') >= 0 && foldlevel(v:lnum - 1) == 1
            return "<1"
        else
            return "="
        endif
    else
        return "="
    endif
endfunction

これにより、レベル 2 の折り畳みから右中括弧が除外され、グローバル構造体と変数の初期リストが折り畳まれます。

于 2014-01-09T00:35:52.343 に答える