Skip to content

Commit 39a4eb0

Browse files
Freed-Wuchrisbra
authored andcommitted
patch 9.1.0982: TI linker files are not recognized
Problem: TI linker files are not recognized Solution: inspect '*.cmd' files and detect TI linker files as 'lnk' filetype, include a lnk ftplugin and syntax script (Wu, Zhenyu) closes: #16320 Signed-off-by: Wu, Zhenyu <wuzhenyu@ustc.edu> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent f27e80a commit 39a4eb0

6 files changed

Lines changed: 165 additions & 3 deletions

File tree

runtime/filetype.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim support file to detect file types
22
"
33
" Maintainer: The Vim Project <https://github.com/vim/vim>
4-
" Last Change: 2024 Dec 30
4+
" Last Change: 2024 Dec 31
55
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
66

77
" Listen very carefully, I will say this only once
@@ -240,9 +240,17 @@ au BufNewFile,BufRead *.fb setf freebasic
240240

241241
" Batch file for MSDOS. See dist#ft#FTsys for *.sys
242242
au BufNewFile,BufRead *.bat setf dosbatch
243-
" *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd.
243+
" *.cmd is close to a Batch file, but on OS/2 Rexx files and TI linker command files also use *.cmd.
244+
" lnk: `/* comment */`, `// comment`, and `--linker-option=value`
245+
" rexx: `/* comment */`, `-- comment`
244246
au BufNewFile,BufRead *.cmd
245-
\ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif
247+
\ if join(getline(1, 20), "\n") =~ 'MEMORY\|SECTIONS\|\%(^\|\n\)--\S\|\%(^\|\n\)//'
248+
\| setf lnk
249+
\| elseif getline(1) =~ '^/\*'
250+
\| setf rexx
251+
\| else
252+
\| setf dosbatch
253+
\| endif
246254
" ABB RAPID or Batch file for MSDOS.
247255
au BufNewFile,BufRead *.sys call dist#ft#FTsys()
248256
if has("fname_case")

runtime/ftplugin/lnk.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
" Vim filetype plugin file
2+
" Language: TI linker command file
3+
" Document: https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_Linker-Command-File-Primer.html
4+
" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
5+
" Last Change: 2024 Dec 31
6+
7+
if exists("b:did_ftplugin") | finish | endif
8+
let b:did_ftplugin = 1
9+
10+
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
11+
setlocal commentstring=/*\ %s\ */
12+
setlocal iskeyword+=.
13+
14+
let b:undo_ftplugin = "setl commentstring< comments< iskeyword<"

runtime/syntax/cmacro.vim

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
" Vim syntax file
2+
" Language: C macro for C preprocessor
3+
" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
4+
" Last Change: 2024 Dec 31
5+
" modified from syntax/c.vim
6+
7+
" C compiler has a preprocessor: `cpp -P test.txt`
8+
" test.txt doesn't need to be a C file
9+
if exists("b:current_syntax")
10+
finish
11+
endif
12+
13+
let s:cpo_save = &cpo
14+
set cpo&vim
15+
16+
" Accept %: for # (C99)
17+
syn region cmacroPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cmacroCppParen,cmacroNumbers
18+
syn match cmacroPreConditMatch display "^\s*\zs\%(%:\|#\)\s*\%(else\|endif\)\>"
19+
if !exists("c_no_if0")
20+
syn cluster cmacroCppOutInGroup contains=cmacroCppInIf,cmacroCppInElse,cmacroCppInElse2,cmacroCppOutIf,cmacroCppOutIf2,cmacroCppOutElse,cmacroCppInSkip,cmacroCppOutSkip
21+
syn region cmacroCppOutWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0\+\s*\%($\|//\|/\*\|&\)" end=".\@=\|$" contains=cmacroCppOutIf,cmacroCppOutElse,@NoSpell fold
22+
syn region cmacroCppOutIf contained start="0\+" matchgroup=cmacroCppOutWrapper end="^\s*\%(%:\|#\)\s*endif\>" contains=cmacroCppOutIf2,cmacroCppOutElse
23+
if !exists("c_no_if0_fold")
24+
syn region cmacroCppOutIf2 contained matchgroup=cmacroCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cmacroCppOutSkip,@Spell fold
25+
else
26+
syn region cmacroCppOutIf2 contained matchgroup=cmacroCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cmacroCppOutSkip,@Spell
27+
endif
28+
syn region cmacroCppOutElse contained matchgroup=cmacroCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cmacroPreCondit
29+
syn region cmacroCppInWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\%($\|//\|/\*\||\)" end=".\@=\|$" contains=cmacroCppInIf,cmacroCppInElse fold
30+
syn region cmacroCppInIf contained matchgroup=cmacroCppInWrapper start="\d\+" end="^\s*\%(%:\|#\)\s*endif\>" contains=TOP,cmacroPreCondit
31+
if !exists("c_no_if0_fold")
32+
syn region cmacroCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cmacroCppInIf contains=cmacroCppInElse2 fold
33+
else
34+
syn region cmacroCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cmacroCppInIf contains=cmacroCppInElse2
35+
endif
36+
syn region cmacroCppInElse2 contained matchgroup=cmacroCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cmacroCppOutSkip,@Spell
37+
syn region cmacroCppOutSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cmacroCppOutSkip
38+
syn region cmacroCppInSkip contained matchgroup=cmacroCppInWrapper start="^\s*\%(%:\|#\)\s*\%(if\s\+\%(\d\+\s*\%($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" containedin=cmacroCppOutElse,cmacroCppInIf,cmacroCppInSkip contains=TOP,cmacroPreProc
39+
endif
40+
syn region cmacroIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
41+
syn match cmacroIncluded display contained "<[^>]*>"
42+
syn match cmacroInclude display "^\s*\zs\%(%:\|#\)\s*include\>\s*["<]" contains=cmacroIncluded
43+
"syn match cmacroLineSkip "\\$"
44+
syn cluster cmacroPreProcmacroGroup contains=cmacroPreCondit,cmacroIncluded,cmacroInclude,cmacroDefine,cmacroCppOutWrapper,cmacroCppInWrapper,@cmacroCppOutInGroup,cmacroNumbersCom,@cmacroCommentGroup,cmacroParen,cmacroBracket,cmacroMulti,cmacroBadBlock
45+
syn region cmacroDefine start="^\s*\zs\%(%:\|#\)\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cmacroPreProcmacroGroup,@Spell
46+
syn region cmacroPreProc start="^\s*\zs\%(%:\|#\)\s*\%(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cmacroPreProcmacroGroup,@Spell
47+
48+
" be able to fold #pragma regions
49+
syn region cmacroPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold
50+
51+
syn keyword cmacroTodo contained TODO FIXME XXX NOTE
52+
syn region cmacroComment start='/\*' end='\*/' contains=cmacroTodo,@Spell
53+
syn match cmacroCommentError "\*/"
54+
syn region cmacroComment start='//' end='$' contains=cmacroTodo,@Spell
55+
56+
" Define the default highlighting.
57+
" Only used when an item doesn't have highlighting yet
58+
hi def link cmacroInclude Include
59+
hi def link cmacroPreProc PreProc
60+
hi def link cmacroDefine Macro
61+
hi def link cmacroIncluded cmacroString
62+
hi def link cmacroCppInWrapper cmacroCppOutWrapper
63+
hi def link cmacroCppOutWrapper cmacroPreCondit
64+
hi def link cmacroPreConditMatch cmacroPreCondit
65+
hi def link cmacroPreCondit PreCondit
66+
hi def link cmacroCppOutSkip cmacroCppOutIf2
67+
hi def link cmacroCppInElse2 cmacroCppOutIf2
68+
hi def link cmacroCppOutIf2 cmacroCppOut
69+
hi def link cmacroCppOut Comment
70+
hi def link cmacroTodo Todo
71+
hi def link cmacroComment Comment
72+
hi def link cmacroCommentError Error
73+
74+
let b:current_syntax = "cmacro"
75+
76+
let &cpo = s:cpo_save
77+
unlet s:cpo_save

runtime/syntax/lnk.vim

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
" Vim syntax file
2+
" Language: TI linker command file
3+
" Document: https://downloads.ti.com/docs/esd/SPRUI03A/Content/SPRUI03A_HTML/linker_description.html
4+
" Document: https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_Linker-Command-File-Primer.html
5+
" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
6+
" Last Change: 2024 Dec 31
7+
8+
if exists("b:current_syntax")
9+
finish
10+
endif
11+
12+
runtime! syntax/cmacro.vim
13+
14+
syn case ignore
15+
syn match lnkNumber "0x[0-9a-f]\+"
16+
" Linker command files are ASCII files that contain one or more of the following:
17+
" Input filenames, which specify object files, archive libraries, or other command files.
18+
" Linker options, which can be used in the command file in the same manner that they are used on the command line
19+
syn match lnkOption "^[-+][-_a-zA-Z#@]\+"
20+
syn match lnkOption "^--[^ \t$=`'"|);]\+"
21+
syn match lnkFile '[^ =]\+\%(\.\S\+\)\+\>'
22+
syn match lnkLibFile '[^ =]\+\.lib\>'
23+
" The MEMORY and SECTIONS linker directives. The MEMORY directive defines the target memory configuration (see Section 8.5.4). The SECTIONS directive controls how sections are built and allocated (see Section 8.5.5.)
24+
syn keyword lnkKeyword ADDRESS_MASK f LOAD ORIGIN START ALGORITHM FILL LOAD_END PAGE TABLE ALIGN GROUP LOAD_SIZE PALIGN TYPE ATTR HAMMING_MASK LOAD_START PARITY_MASK UNION BLOCK HIGH MEMORY RUN UNORDERED COMPRESSION INPUT_PAGE MIRRORING RUN_END VFILL COPY INPUT_RANGE NOINIT RUN_SIZE DSECT l NOLOAD RUN_START ECC LEN o SECTIONS END LENGTH ORG SIZE
25+
syn region lnkLibrary start=+<+ end=+>+
26+
syn match lnkAttrib '\<[RWXI]\+\>'
27+
syn match lnkSections '\<\.\k\+'
28+
" Assignment statements, which define and assign values to global symbols
29+
syn case match
30+
31+
hi def link lnkNumber Number
32+
hi def link lnkOption Special
33+
hi def link lnkKeyword Keyword
34+
hi def link lnkLibrary String
35+
hi def link lnkFile String
36+
hi def link lnkLibFile Special
37+
hi def link lnkAttrib Type
38+
hi def link lnkSections Macro
39+
40+
let b:current_syntax = "lnk"

src/testdir/test_filetype.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,27 @@ func Test_cls_file()
23092309
filetype off
23102310
endfunc
23112311

2312+
func Test_cmd_file()
2313+
filetype on
2314+
2315+
call writefile(['--rom_model'], 'Xfile.cmd')
2316+
split Xfile.cmd
2317+
call assert_equal('lnk', &filetype)
2318+
bwipe!
2319+
2320+
call writefile(['/* comment */'], 'Xfile.cmd')
2321+
split Xfile.cmd
2322+
call assert_equal('rexx', &filetype)
2323+
bwipe!
2324+
2325+
call writefile(['REM comment'], 'Xfile.cmd')
2326+
split Xfile.cmd
2327+
call assert_equal('dosbatch', &filetype)
2328+
bwipe!
2329+
2330+
filetype off
2331+
endfunc
2332+
23122333
func Test_sig_file()
23132334
filetype on
23142335

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
982,
707709
/**/
708710
981,
709711
/**/

0 commit comments

Comments
 (0)