ThirdParty/Pygments/pygments/lexers/asm.py

changeset 684
2f29a0b6e1c7
parent 0
de9c2efb9d02
child 1112
8a7d1b9d18db
equal deleted inserted replaced
682:91114a975eda 684:2f29a0b6e1c7
3 pygments.lexers.asm 3 pygments.lexers.asm
4 ~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for assembly languages. 6 Lexers for assembly languages.
7 7
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 try:
14 set
15 except NameError:
16 from sets import Set as set
17 13
18 from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer 14 from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer
19 from pygments.lexers.compiled import DLexer, CppLexer, CLexer 15 from pygments.lexers.compiled import DLexer, CppLexer, CLexer
20 from pygments.token import * 16 from pygments.token import *
21 17
197 filenames = ['*.ll'] 193 filenames = ['*.ll']
198 mimetypes = ['text/x-llvm'] 194 mimetypes = ['text/x-llvm']
199 195
200 #: optional Comment or Whitespace 196 #: optional Comment or Whitespace
201 string = r'"[^"]*?"' 197 string = r'"[^"]*?"'
202 identifier = r'([a-zA-Z$._][a-zA-Z$._0-9]*|' + string + ')' 198 identifier = r'([-a-zA-Z$._][-a-zA-Z$._0-9]*|' + string + ')'
203 199
204 tokens = { 200 tokens = {
205 'root': [ 201 'root': [
206 include('whitespace'), 202 include('whitespace'),
207 203
209 (r'^\s*' + identifier + '\s*:', Name.Label), 205 (r'^\s*' + identifier + '\s*:', Name.Label),
210 206
211 include('keyword'), 207 include('keyword'),
212 208
213 (r'%' + identifier, Name.Variable),#Name.Identifier.Local), 209 (r'%' + identifier, Name.Variable),#Name.Identifier.Local),
214 (r'@' + identifier, Name.Constant),#Name.Identifier.Global), 210 (r'@' + identifier, Name.Variable.Global),#Name.Identifier.Global),
215 (r'%\d+', Name.Variable.Anonymous),#Name.Identifier.Anonymous), 211 (r'%\d+', Name.Variable.Anonymous),#Name.Identifier.Anonymous),
212 (r'@\d+', Name.Variable.Global),#Name.Identifier.Anonymous),
213 (r'!' + identifier, Name.Variable),
214 (r'!\d+', Name.Variable.Anonymous),
216 (r'c?' + string, String), 215 (r'c?' + string, String),
217 216
218 (r'0[xX][a-fA-F0-9]+', Number), 217 (r'0[xX][a-fA-F0-9]+', Number),
219 (r'-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?', Number), 218 (r'-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?', Number),
220 219
221 (r'[=<>{}\[\]()*.,]|x\b', Punctuation) 220 (r'[=<>{}\[\]()*.,!]|x\b', Punctuation)
222 ], 221 ],
223 'whitespace': [ 222 'whitespace': [
224 (r'(\n|\s)+', Text), 223 (r'(\n|\s)+', Text),
225 (r';.*?\n', Comment) 224 (r';.*?\n', Comment)
226 ], 225 ],
227 'keyword': [ 226 'keyword': [
228 # Regular keywords 227 # Regular keywords
229 (r'(void|label|float|double|opaque' 228 (r'(begin|end'
230 r'|to' 229 r'|true|false'
231 r'|alias|type' 230 r'|declare|define'
232 r'|zeroext|signext|inreg|sret|noalias|noreturn|nounwind|nest' 231 r'|global|constant'
233 r'|module|asm|target|datalayout|triple' 232
234 r'|true|false|null|zeroinitializer|undef' 233 r'|private|linker_private|internal|available_externally|linkonce'
235 r'|global|internal|external|linkonce|weak|appending|extern_weak' 234 r'|linkonce_odr|weak|weak_odr|appending|dllimport|dllexport'
236 r'|dllimport|dllexport' 235 r'|common|default|hidden|protected|extern_weak|external'
237 r'|ccc|fastcc|coldcc|cc|tail' 236 r'|thread_local|zeroinitializer|undef|null|to|tail|target|triple'
238 r'|default|hidden|protected' 237 r'|deplibs|datalayout|volatile|nuw|nsw|exact|inbounds|align'
239 r'|thread_local|constant|align|section' 238 r'|addrspace|section|alias|module|asm|sideeffect|gc|dbg'
240 r'|define|declare' 239
241 240 r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc'
242 # Statements & expressions 241 r'|arm_aapcscc|arm_aapcs_vfpcc'
243 r'|trunc|zext|sext|fptrunc|fpext|fptoui|fptosi|uitofp|sitofp' 242
244 r'|ptrtoint|inttoptr|bitcast|getelementptr|select|icmp|fcmp' 243 r'|cc|c'
245 r'|extractelement|insertelement|shufflevector' 244
246 r'|sideeffect|volatile' 245 r'|signext|zeroext|inreg|sret|nounwind|noreturn|noalias|nocapture'
247 r'|ret|br|switch|invoke|unwind|unreachable' 246 r'|byval|nest|readnone|readonly'
248 r'|add|sub|mul|udiv|sdiv|fdiv|urem|srem|frem' 247
249 r'|shl|lshr|ashr|and|or|xor' 248 r'|inlinehint|noinline|alwaysinline|optsize|ssp|sspreq|noredzone'
250 r'|malloc|free|alloca|load|store' 249 r'|noimplicitfloat|naked'
251 r'|phi|call|va_arg|va_list' 250
252 251 r'|type|opaque'
253 # Comparison condition codes for icmp 252
254 r'|eq|ne|ugt|uge|ult|ule|sgt|sge|slt|sle' 253 r'|eq|ne|slt|sgt|sle'
255 # Ditto for fcmp: (minus keywords mentioned in other contexts) 254 r'|sge|ult|ugt|ule|uge'
256 r'|oeq|ogt|oge|olt|ole|one|ord|ueq|ugt|uge|une|uno' 255 r'|oeq|one|olt|ogt|ole'
256 r'|oge|ord|uno|ueq|une'
257 r'|x'
258
259 # instructions
260 r'|add|fadd|sub|fsub|mul|fmul|udiv|sdiv|fdiv|urem|srem|frem|shl'
261 r'|lshr|ashr|and|or|xor|icmp|fcmp'
262
263 r'|phi|call|trunc|zext|sext|fptrunc|fpext|uitofp|sitofp|fptoui'
264 r'fptosi|inttoptr|ptrtoint|bitcast|select|va_arg|ret|br|switch'
265 r'|invoke|unwind|unreachable'
266
267 r'|malloc|alloca|free|load|store|getelementptr'
268
269 r'|extractelement|insertelement|shufflevector|getresult'
270 r'|extractvalue|insertvalue'
257 271
258 r')\b', Keyword), 272 r')\b', Keyword),
273
274 # Types
275 (r'void|float|double|x86_fp80|fp128|ppc_fp128|label|metadata',
276 Keyword.Type),
277
259 # Integer types 278 # Integer types
260 (r'i[1-9]\d*', Keyword) 279 (r'i[1-9]\d*', Keyword)
261 ] 280 ]
262 } 281 }
263 282
270 aliases = ['nasm'] 289 aliases = ['nasm']
271 filenames = ['*.asm', '*.ASM'] 290 filenames = ['*.asm', '*.ASM']
272 mimetypes = ['text/x-nasm'] 291 mimetypes = ['text/x-nasm']
273 292
274 identifier = r'[a-zA-Z$._?][a-zA-Z0-9$._?#@~]*' 293 identifier = r'[a-zA-Z$._?][a-zA-Z0-9$._?#@~]*'
275 hexn = r'(?:0[xX][0-9a-fA-F]+|$0[0-9a-fA-F]*|[0-9a-fA-F]+h)' 294 hexn = r'(?:0[xX][0-9a-fA-F]+|$0[0-9a-fA-F]*|[0-9]+[0-9a-fA-F]*h)'
276 octn = r'[0-7]+q' 295 octn = r'[0-7]+q'
277 binn = r'[01]+b' 296 binn = r'[01]+b'
278 decn = r'[0-9]+' 297 decn = r'[0-9]+'
279 floatn = decn + r'\.e?' + decn 298 floatn = decn + r'\.e?' + decn
280 string = r'"(\\"|[^"])*"|' + r"'(\\'|[^'])*'" 299 string = r'"(\\"|[^"])*"|' + r"'(\\'|[^'])*'"
282 register = (r'[a-d][lh]|e?[a-d]x|e?[sb]p|e?[sd]i|[c-gs]s|st[0-7]|' 301 register = (r'[a-d][lh]|e?[a-d]x|e?[sb]p|e?[sd]i|[c-gs]s|st[0-7]|'
283 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]') 302 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
284 wordop = r'seg|wrt|strict' 303 wordop = r'seg|wrt|strict'
285 type = r'byte|[dq]?word' 304 type = r'byte|[dq]?word'
286 directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|' 305 directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|'
287 r'COMMON|CPU|GROUP|UPPERCASE|IMPORT|EXPORT|LIBRARY|MODULE') 306 r'ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|'
307 r'EXPORT|LIBRARY|MODULE')
288 308
289 flags = re.IGNORECASE | re.MULTILINE 309 flags = re.IGNORECASE | re.MULTILINE
290 tokens = { 310 tokens = {
291 'root': [ 311 'root': [
292 include('whitespace'), 312 include('whitespace'),
293 (r'^\s*%', Comment.Preproc, 'preproc'), 313 (r'^\s*%', Comment.Preproc, 'preproc'),
294 (identifier + ':', Name.Label), 314 (identifier + ':', Name.Label),
315 (r'(%s)(\s+)(equ)' % identifier,
316 bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
317 'instruction-args'),
295 (directives, Keyword, 'instruction-args'), 318 (directives, Keyword, 'instruction-args'),
296 (r'(%s)\s+(equ)' % identifier,
297 bygroups(Name.Constant, Keyword.Declaration),
298 'instruction-args'),
299 (declkw, Keyword.Declaration, 'instruction-args'), 319 (declkw, Keyword.Declaration, 'instruction-args'),
300 (identifier, Name.Function, 'instruction-args'), 320 (identifier, Name.Function, 'instruction-args'),
301 (r'[\r\n]+', Text) 321 (r'[\r\n]+', Text)
302 ], 322 ],
303 'instruction-args': [ 323 'instruction-args': [

eric ide

mercurial