xref: /vim-8.2.3635/runtime/syntax/asm.vim (revision d0bce504)
1" Vim syntax file
2" Language:		GNU Assembler
3" Maintainer:		Doug Kearns [email protected]
4" Previous Maintainers: Erik Wognsen <[email protected]>
5"			Kevin Dahlhausen <[email protected]>
6" Contributors:		Ori Avtalion, Lakshay Garg
7" Last Change:		2020 Oct 31
8
9" quit when a syntax file was already loaded
10if exists("b:current_syntax")
11  finish
12endif
13
14let s:cpo_save = &cpo
15set cpo&vim
16
17syn case ignore
18
19" storage types
20syn match asmType "\.long"
21syn match asmType "\.ascii"
22syn match asmType "\.asciz"
23syn match asmType "\.byte"
24syn match asmType "\.double"
25syn match asmType "\.float"
26syn match asmType "\.hword"
27syn match asmType "\.int"
28syn match asmType "\.octa"
29syn match asmType "\.quad"
30syn match asmType "\.short"
31syn match asmType "\.single"
32syn match asmType "\.space"
33syn match asmType "\.string"
34syn match asmType "\.word"
35
36syn match asmIdentifier		"[a-z_][a-z0-9_]*"
37syn match asmLabel		"[a-z_][a-z0-9_]*:"he=e-1
38
39" Various #'s as defined by GAS ref manual sec 3.6.2.1
40" Technically, the first asmDecimal def is actually octal,
41" since the value of 0-7 octal is the same as 0-7 decimal,
42" I (Kevin) prefer to map it as decimal:
43syn match asmDecimal		"\<0\+[1-7]\=\>"	 display
44syn match asmDecimal		"\<[1-9]\d*\>"		 display
45syn match asmOctal		"\<0[0-7][0-7]\+\>"	 display
46syn match asmHexadecimal	"\<0[xX][0-9a-fA-F]\+\>" display
47syn match asmBinary		"\<0[bB][0-1]\+\>"	 display
48
49syn match asmFloat		"\<\d\+\.\d*\%(e[+-]\=\d\+\)\=\>" display
50syn match asmFloat		"\.\d\+\%(e[+-]\=\d\+\)\=\>"	  display
51syn match asmFloat		"\<\d\%(e[+-]\=\d\+\)\>"	  display
52syn match asmFloat		"[+-]\=Inf\>\|\<NaN\>"		  display
53
54syn match asmFloat		"\%(0[edfghprs]\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\="    display
55syn match asmFloat		"\%(0[edfghprs]\)[+-]\=\d\+\%(\.\d\+\)\=\%(e[+-]\=\d\+\)\=" display
56" Avoid fighting the hexadecimal match for unicorn-like '0x' prefixed floats
57syn match asmFloat		"\%(0x\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\="		    display
58
59" Allow all characters to be escaped (and in strings) as these vary across
60" architectures [See sec 3.6.1.1 Strings]
61syn match asmCharacterEscape	"\\."    contained
62syn match asmCharacter		"'\\\=." contains=asmCharacterEscape
63
64syn match asmStringEscape	"\\\_."			contained
65syn match asmStringEscape	"\\\%(\o\{3}\|00[89]\)"	contained display
66syn match asmStringEscape	"\\x\x\+"		contained display
67
68syn region asmString		start="\"" end="\"" skip="\\\\\|\\\"" contains=asmStringEscape
69
70syn keyword asmTodo		contained TODO FIXME XXX NOTE
71
72" GAS supports one type of multi line comments:
73syn region asmComment		start="/\*" end="\*/" contains=asmTodo,@Spell
74
75" GAS (undocumentedly?) supports C++ style comments. Unlike in C/C++ however,
76" a backslash ending a C++ style comment does not extend the comment to the
77" next line (hence the syntax region does not define 'skip="\\$"')
78syn region asmComment		start="//" end="$" keepend contains=asmTodo,@Spell
79
80" Line comment characters depend on the target architecture and command line
81" options and some comments may double as logical line number directives or
82" preprocessor commands. This situation is described at
83" http://sourceware.org/binutils/docs-2.22/as/Comments.html
84" Some line comment characters have other meanings for other targets. For
85" example, .type directives may use the `@' character which is also an ARM
86" comment marker.
87" As a compromise to accommodate what I arbitrarily assume to be the most
88" frequently used features of the most popular architectures (and also the
89" non-GNU assembly languages that use this syntax file because their asm files
90" are also named *.asm), the following are used as line comment characters:
91syn match asmComment		"[#;!|].*" contains=asmTodo,@Spell
92
93" Side effects of this include:
94" - When `;' is used to separate statements on the same line (many targets
95"   support this), all statements except the first get highlighted as
96"   comments. As a remedy, remove `;' from the above.
97" - ARM comments are not highlighted correctly. For ARM, uncomment the
98"   following two lines and comment the one above.
99"syn match asmComment		"@.*" contains=asmTodo
100"syn match asmComment		"^#.*" contains=asmTodo
101
102" Advanced users of specific architectures will probably want to change the
103" comment highlighting or use a specific, more comprehensive syntax file.
104
105syn match asmInclude		"\.include"
106syn match asmCond		"\.if"
107syn match asmCond		"\.else"
108syn match asmCond		"\.endif"
109syn match asmMacro		"\.macro"
110syn match asmMacro		"\.endm"
111
112" Assembler directives start with a '.' and may contain upper case (e.g.,
113" .ABORT), numbers (e.g., .p2align), dash (e.g., .app-file) and underscore in
114" CFI directives (e.g., .cfi_startproc). This will also match labels starting
115" with '.', including the GCC auto-generated '.L' labels.
116syn match asmDirective		"\.[A-Za-z][0-9A-Za-z-_]*"
117
118syn case match
119
120" Define the default highlighting.
121" Only when an item doesn't have highlighting yet
122
123" The default methods for highlighting.  Can be overridden later
124hi def link asmSection		Special
125hi def link asmLabel		Label
126hi def link asmComment		Comment
127hi def link asmTodo		Todo
128hi def link asmDirective	Statement
129
130hi def link asmInclude		Include
131hi def link asmCond		PreCondit
132hi def link asmMacro		Macro
133
134if exists('g:asm_legacy_syntax_groups')
135  hi def link hexNumber		Number
136  hi def link decNumber		Number
137  hi def link octNumber		Number
138  hi def link binNumber		Number
139  hi def link asmHexadecimal	hexNumber
140  hi def link asmDecimal	decNumber
141  hi def link asmOctal		octNumber
142  hi def link asmBinary		binNumber
143else
144  hi def link asmHexadecimal	Number
145  hi def link asmDecimal	Number
146  hi def link asmOctal		Number
147  hi def link asmBinary		Number
148endif
149hi def link asmFloat		Float
150
151hi def link asmString		String
152hi def link asmStringEscape	Special
153hi def link asmCharacter	Character
154hi def link asmCharacterEscape	Special
155
156hi def link asmIdentifier	Identifier
157hi def link asmType		Type
158
159let b:current_syntax = "asm"
160
161let &cpo = s:cpo_save
162unlet s:cpo_save
163
164" vim: nowrap sw=2 sts=2 ts=8 noet
165