blob: 501f5f0872ab71f3881b40edd16cb239c0a7743c [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: GNU Assembler
Bram Moolenaar555cdc22010-01-12 21:31:21 +01003" Maintainer: Erik Wognsen <erik.wognsen@gmail.com>
4" Previous maintainer:
5" Kevin Dahlhausen <kdahlhaus@yahoo.com>
Bram Moolenaar92dff182014-02-11 19:15:50 +01006" Last Change: 2014 Feb 04
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007
8" Thanks to Ori Avtalion for feedback on the comment markers!
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020010" quit when a syntax file was already loaded
11if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000012 finish
13endif
14
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010015let s:cpo_save = &cpo
16set cpo&vim
17
Bram Moolenaar071d4272004-06-13 20:20:40 +000018syn case ignore
19
Bram Moolenaar071d4272004-06-13 20:20:40 +000020" storage types
21syn match asmType "\.long"
22syn match asmType "\.ascii"
23syn match asmType "\.asciz"
24syn match asmType "\.byte"
25syn match asmType "\.double"
26syn match asmType "\.float"
27syn match asmType "\.hword"
28syn match asmType "\.int"
29syn match asmType "\.octa"
30syn match asmType "\.quad"
31syn match asmType "\.short"
32syn match asmType "\.single"
33syn match asmType "\.space"
34syn match asmType "\.string"
35syn match asmType "\.word"
36
37syn match asmLabel "[a-z_][a-z0-9_]*:"he=e-1
38syn match asmIdentifier "[a-z_][a-z0-9_]*"
39
40" Various #'s as defined by GAS ref manual sec 3.6.2.1
41" Technically, the first decNumber def is actually octal,
42" since the value of 0-7 octal is the same as 0-7 decimal,
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010043" I (Kevin) prefer to map it as decimal:
Bram Moolenaar071d4272004-06-13 20:20:40 +000044syn match decNumber "0\+[1-7]\=[\t\n$,; ]"
45syn match decNumber "[1-9]\d*"
46syn match octNumber "0[0-7][0-7]\+"
47syn match hexNumber "0[xX][0-9a-fA-F]\+"
48syn match binNumber "0[bB][0-1]*"
49
Bram Moolenaar00a927d2010-05-14 23:24:24 +020050syn keyword asmTodo contained TODO
51
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010052
53" GAS supports one type of multi line comments:
Bram Moolenaar00a927d2010-05-14 23:24:24 +020054syn region asmComment start="/\*" end="\*/" contains=asmTodo
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010055
Bram Moolenaar53bfca22012-04-13 23:04:47 +020056" GAS (undocumentedly?) supports C++ style comments. Unlike in C/C++ however,
57" a backslash ending a C++ style comment does not extend the comment to the
58" next line (hence the syntax region does not define 'skip="\\$"')
59syn region asmComment start="//" end="$" keepend contains=asmTodo
60
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010061" Line comment characters depend on the target architecture and command line
62" options and some comments may double as logical line number directives or
63" preprocessor commands. This situation is described at
64" http://sourceware.org/binutils/docs-2.22/as/Comments.html
65" Some line comment characters have other meanings for other targets. For
66" example, .type directives may use the `@' character which is also an ARM
67" comment marker.
68" As a compromise to accommodate what I arbitrarily assume to be the most
69" frequently used features of the most popular architectures (and also the
70" non-GNU assembly languages that use this syntax file because their asm files
71" are also named *.asm), the following are used as line comment characters:
Bram Moolenaar00a927d2010-05-14 23:24:24 +020072syn match asmComment "[#;!|].*" contains=asmTodo
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010073
74" Side effects of this include:
75" - When `;' is used to separate statements on the same line (many targets
76" support this), all statements except the first get highlighted as
77" comments. As a remedy, remove `;' from the above.
78" - ARM comments are not highlighted correctly. For ARM, uncomment the
79" following two lines and comment the one above.
80"syn match asmComment "@.*" contains=asmTodo
81"syn match asmComment "^#.*" contains=asmTodo
82
83" Advanced users of specific architectures will probably want to change the
84" comment highlighting or use a specific, more comprehensive syntax file.
Bram Moolenaar071d4272004-06-13 20:20:40 +000085
86syn match asmInclude "\.include"
87syn match asmCond "\.if"
88syn match asmCond "\.else"
89syn match asmCond "\.endif"
90syn match asmMacro "\.macro"
91syn match asmMacro "\.endm"
92
Bram Moolenaar92dff182014-02-11 19:15:50 +010093" Assembler directives start with a '.' and may contain upper case (e.g.,
94" .ABORT), numbers (e.g., .p2align), dash (e.g., .app-file) and underscore in
95" CFI directives (e.g., .cfi_startproc). This will also match labels starting
96" with '.', including the GCC auto-generated '.L' labels.
97syn match asmDirective "\.[A-Za-z][0-9A-Za-z-_]*"
Bram Moolenaar071d4272004-06-13 20:20:40 +000098
99
100syn case match
101
102" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200103" Only when an item doesn't have highlighting yet
104command -nargs=+ HiLink hi def link <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200106" The default methods for highlighting. Can be overridden later
107HiLink asmSection Special
108HiLink asmLabel Label
109HiLink asmComment Comment
110HiLink asmTodo Todo
111HiLink asmDirective Statement
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200113HiLink asmInclude Include
114HiLink asmCond PreCondit
115HiLink asmMacro Macro
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200117HiLink hexNumber Number
118HiLink decNumber Number
119HiLink octNumber Number
120HiLink binNumber Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200122HiLink asmIdentifier Identifier
123HiLink asmType Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200125delcommand HiLink
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126
127let b:current_syntax = "asm"
128
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100129let &cpo = s:cpo_save
130unlet s:cpo_save
131
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132" vim: ts=8