eric6/ThirdParty/Pygments/pygments/lexers/asm.py

changeset 7701
25f42e208e08
parent 7547
21b0534faebc
child 7983
54c5cfbb1e29
equal deleted inserted replaced
7700:a3cf077a8db3 7701:25f42e208e08
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-2019 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2020 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 13
35 35
36 #: optional Comment or Whitespace 36 #: optional Comment or Whitespace
37 string = r'"(\\"|[^"])*"' 37 string = r'"(\\"|[^"])*"'
38 char = r'[\w$.@-]' 38 char = r'[\w$.@-]'
39 identifier = r'(?:[a-zA-Z$_]' + char + r'*|\.' + char + '+)' 39 identifier = r'(?:[a-zA-Z$_]' + char + r'*|\.' + char + '+)'
40 number = r'(?:0[xX][a-zA-Z0-9]+|\d+)' 40 number = r'(?:0[xX][a-fA-F0-9]+|#?-?\d+)'
41 register = '%' + identifier 41 register = '%' + identifier
42 42
43 tokens = { 43 tokens = {
44 'root': [ 44 'root': [
45 include('whitespace'), 45 include('whitespace'),
156 } 156 }
157 157
158 158
159 class ObjdumpLexer(RegexLexer): 159 class ObjdumpLexer(RegexLexer):
160 """ 160 """
161 For the output of 'objdump -dr' 161 For the output of ``objdump -dr``.
162 """ 162 """
163 name = 'objdump' 163 name = 'objdump'
164 aliases = ['objdump'] 164 aliases = ['objdump']
165 filenames = ['*.objdump'] 165 filenames = ['*.objdump']
166 mimetypes = ['text/x-objdump'] 166 mimetypes = ['text/x-objdump']
168 tokens = _objdump_lexer_tokens(GasLexer) 168 tokens = _objdump_lexer_tokens(GasLexer)
169 169
170 170
171 class DObjdumpLexer(DelegatingLexer): 171 class DObjdumpLexer(DelegatingLexer):
172 """ 172 """
173 For the output of 'objdump -Sr on compiled D files' 173 For the output of ``objdump -Sr`` on compiled D files.
174 """ 174 """
175 name = 'd-objdump' 175 name = 'd-objdump'
176 aliases = ['d-objdump'] 176 aliases = ['d-objdump']
177 filenames = ['*.d-objdump'] 177 filenames = ['*.d-objdump']
178 mimetypes = ['text/x-d-objdump'] 178 mimetypes = ['text/x-d-objdump']
179 179
180 def __init__(self, **options): 180 def __init__(self, **options):
181 super(DObjdumpLexer, self).__init__(DLexer, ObjdumpLexer, **options) 181 super().__init__(DLexer, ObjdumpLexer, **options)
182 182
183 183
184 class CppObjdumpLexer(DelegatingLexer): 184 class CppObjdumpLexer(DelegatingLexer):
185 """ 185 """
186 For the output of 'objdump -Sr on compiled C++ files' 186 For the output of ``objdump -Sr`` on compiled C++ files.
187 """ 187 """
188 name = 'cpp-objdump' 188 name = 'cpp-objdump'
189 aliases = ['cpp-objdump', 'c++-objdumb', 'cxx-objdump'] 189 aliases = ['cpp-objdump', 'c++-objdumb', 'cxx-objdump']
190 filenames = ['*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump'] 190 filenames = ['*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump']
191 mimetypes = ['text/x-cpp-objdump'] 191 mimetypes = ['text/x-cpp-objdump']
192 192
193 def __init__(self, **options): 193 def __init__(self, **options):
194 super(CppObjdumpLexer, self).__init__(CppLexer, ObjdumpLexer, **options) 194 super().__init__(CppLexer, ObjdumpLexer, **options)
195 195
196 196
197 class CObjdumpLexer(DelegatingLexer): 197 class CObjdumpLexer(DelegatingLexer):
198 """ 198 """
199 For the output of 'objdump -Sr on compiled C files' 199 For the output of ``objdump -Sr`` on compiled C files.
200 """ 200 """
201 name = 'c-objdump' 201 name = 'c-objdump'
202 aliases = ['c-objdump'] 202 aliases = ['c-objdump']
203 filenames = ['*.c-objdump'] 203 filenames = ['*.c-objdump']
204 mimetypes = ['text/x-c-objdump'] 204 mimetypes = ['text/x-c-objdump']
205 205
206 def __init__(self, **options): 206 def __init__(self, **options):
207 super(CObjdumpLexer, self).__init__(CLexer, ObjdumpLexer, **options) 207 super().__init__(CLexer, ObjdumpLexer, **options)
208 208
209 209
210 class HsailLexer(RegexLexer): 210 class HsailLexer(RegexLexer):
211 """ 211 """
212 For HSAIL assembly code. 212 For HSAIL assembly code.
451 # Integer types 451 # Integer types
452 (r'i[1-9]\d*', Keyword) 452 (r'i[1-9]\d*', Keyword)
453 ] 453 ]
454 } 454 }
455 455
456
456 class LlvmMirBodyLexer(RegexLexer): 457 class LlvmMirBodyLexer(RegexLexer):
457 """ 458 """
458 For LLVM MIR examples without the YAML wrapper 459 For LLVM MIR examples without the YAML wrapper.
459 460
460 For more information on LLVM MIR see https://llvm.org/docs/MIRLangRef.html. 461 For more information on LLVM MIR see https://llvm.org/docs/MIRLangRef.html.
461 462
462 .. versionadded:: 2.6 463 .. versionadded:: 2.6
463 """ 464 """
469 tokens = { 470 tokens = {
470 'root': [ 471 'root': [
471 # Attributes on basic blocks 472 # Attributes on basic blocks
472 (words(('liveins', 'successors'), suffix=':'), Keyword), 473 (words(('liveins', 'successors'), suffix=':'), Keyword),
473 # Basic Block Labels 474 # Basic Block Labels
474 (r'bb\.[0-9]+(\.[0-9a-zA-Z_.-]+)?( \(address-taken\))?:', Name.Label), 475 (r'bb\.[0-9]+(\.[a-zA-Z0-9_.-]+)?( \(address-taken\))?:', Name.Label),
475 (r'bb\.[0-9]+ \(%[0-9a-zA-Z_.-]+\)( \(address-taken\))?:', Name.Label), 476 (r'bb\.[0-9]+ \(%[a-zA-Z0-9_.-]+\)( \(address-taken\))?:', Name.Label),
476 (r'%bb\.[0-9]+(\.\w+)?', Name.Label), 477 (r'%bb\.[0-9]+(\.\w+)?', Name.Label),
477 # Stack references 478 # Stack references
478 (r'%stack\.[0-9]+(\.\w+\.addr)?', Name), 479 (r'%stack\.[0-9]+(\.\w+\.addr)?', Name),
479 # Subreg indices 480 # Subreg indices
480 (r'%subreg\.\w+', Name), 481 (r'%subreg\.\w+', Name),
481 # Virtual registers 482 # Virtual registers
482 (r'%[0-9a-zA-Z_]+ *', Name.Variable, 'vreg'), 483 (r'%[a-zA-Z0-9_]+ *', Name.Variable, 'vreg'),
483 # Reference to LLVM-IR global 484 # Reference to LLVM-IR global
484 include('global'), 485 include('global'),
485 # Reference to Intrinsic 486 # Reference to Intrinsic
486 (r'intrinsic\(\@[0-9a-zA-Z_.]+\)', Name.Variable.Global), 487 (r'intrinsic\(\@[a-zA-Z0-9_.]+\)', Name.Variable.Global),
487 # Comparison predicates 488 # Comparison predicates
488 (words(('eq', 'ne', 'sgt', 'sge', 'slt', 'sle', 'ugt', 'uge', 'ult', 489 (words(('eq', 'ne', 'sgt', 'sge', 'slt', 'sle', 'ugt', 'uge', 'ult',
489 'ule'), prefix=r'intpred\(', suffix=r'\)'), Name.Builtin), 490 'ule'), prefix=r'intpred\(', suffix=r'\)'), Name.Builtin),
490 (words(('oeq', 'one', 'ogt', 'oge', 'olt', 'ole', 'ugt', 'uge', 491 (words(('oeq', 'one', 'ogt', 'oge', 'olt', 'ole', 'ugt', 'uge',
491 'ult', 'ule'), prefix=r'floatpred\(', suffix=r'\)'), 492 'ult', 'ule'), prefix=r'floatpred\(', suffix=r'\)'),
492 Name.Builtin), 493 Name.Builtin),
493 # Physical registers 494 # Physical registers
494 (r'\$\w+', String.Single), 495 (r'\$\w+', String.Single),
495 # Assignment operator 496 # Assignment operator
496 (r'[=]', Operator), 497 (r'=', Operator),
497 # gMIR Opcodes 498 # gMIR Opcodes
498 (r'(G_ANYEXT|G_[SZ]EXT|G_SEXT_INREG|G_TRUNC|G_IMPLICIT_DEF|G_PHI|' 499 (r'(G_ANYEXT|G_[SZ]EXT|G_SEXT_INREG|G_TRUNC|G_IMPLICIT_DEF|G_PHI|'
499 r'G_FRAME_INDEX|G_GLOBAL_VALUE|G_INTTOPTR|G_PTRTOINT|G_BITCAST|' 500 r'G_FRAME_INDEX|G_GLOBAL_VALUE|G_INTTOPTR|G_PTRTOINT|G_BITCAST|'
500 r'G_CONSTANT|G_FCONSTANT|G_VASTART|G_VAARG|G_CTLZ|G_CTLZ_ZERO_UNDEF|' 501 r'G_CONSTANT|G_FCONSTANT|G_VASTART|G_VAARG|G_CTLZ|G_CTLZ_ZERO_UNDEF|'
501 r'G_CTTZ|G_CTTZ_ZERO_UNDEF|G_CTPOP|G_BSWAP|G_BITREVERSE|' 502 r'G_CTTZ|G_CTTZ_ZERO_UNDEF|G_CTPOP|G_BSWAP|G_BITREVERSE|'
524 (r'(COPY|PHI|INSERT_SUBREG|EXTRACT_SUBREG|REG_SEQUENCE)\b', 525 (r'(COPY|PHI|INSERT_SUBREG|EXTRACT_SUBREG|REG_SEQUENCE)\b',
525 Name.Builtin), 526 Name.Builtin),
526 # Flags 527 # Flags
527 (words(('killed', 'implicit')), Keyword), 528 (words(('killed', 'implicit')), Keyword),
528 # ConstantInt values 529 # ConstantInt values
529 (r'[i][0-9]+ +', Keyword.Type, 'constantint'), 530 (r'i[0-9]+ +', Keyword.Type, 'constantint'),
530 # ConstantFloat values 531 # ConstantFloat values
531 (r'(half|float|double) +', Keyword.Type, 'constantfloat'), 532 (r'(half|float|double) +', Keyword.Type, 'constantfloat'),
532 # Bare immediates 533 # Bare immediates
533 include('integer'), 534 include('integer'),
534 # MMO's 535 # MMO's
535 (r':: *', Operator, 'mmo'), 536 (r':: *', Operator, 'mmo'),
536 # MIR Comments 537 # MIR Comments
537 (r';.*', Comment), 538 (r';.*', Comment),
538 # If we get here, assume it's a target instruction 539 # If we get here, assume it's a target instruction
539 (r'[0-9a-zA-Z_]+', Name), 540 (r'[a-zA-Z0-9_]+', Name),
540 # Everything else that isn't highlighted 541 # Everything else that isn't highlighted
541 (r'[(), \n]+', Text), 542 (r'[(), \n]+', Text),
542 ], 543 ],
543 # The integer constant from a ConstantInt value 544 # The integer constant from a ConstantInt value
544 'constantint': [ 545 'constantint': [
558 (r'(?=.)', Text, '#pop'), 559 (r'(?=.)', Text, '#pop'),
559 ], 560 ],
560 'vreg_bank_or_class': [ 561 'vreg_bank_or_class': [
561 # The unassigned bank/class 562 # The unassigned bank/class
562 (r' *_', Name.Variable.Magic), 563 (r' *_', Name.Variable.Magic),
563 (r' *[0-9a-zA-Z_]+', Name.Variable), 564 (r' *[a-zA-Z0-9_]+', Name.Variable),
564 # The LLT if there is one 565 # The LLT if there is one
565 (r' *\(', Text, 'vreg_type'), 566 (r' *\(', Text, 'vreg_type'),
566 (r'(?=.)', Text, '#pop'), 567 (r'(?=.)', Text, '#pop'),
567 ], 568 ],
568 'vreg_type': [ 569 'vreg_type': [
577 (r' +', Text), 578 (r' +', Text),
578 (words(('load', 'store', 'on', 'into', 'from', 'align', 'monotonic', 579 (words(('load', 'store', 'on', 'into', 'from', 'align', 'monotonic',
579 'acquire', 'release', 'acq_rel', 'seq_cst')), 580 'acquire', 'release', 'acq_rel', 'seq_cst')),
580 Keyword), 581 Keyword),
581 # IR references 582 # IR references
582 (r'%ir\.[0-9a-zA-Z_.-]+', Name), 583 (r'%ir\.[a-zA-Z0-9_.-]+', Name),
583 (r'%ir-block\.[0-9a-zA-Z_.-]+', Name), 584 (r'%ir-block\.[a-zA-Z0-9_.-]+', Name),
584 (r'[-+]', Operator), 585 (r'[-+]', Operator),
585 include('integer'), 586 include('integer'),
586 include('global'), 587 include('global'),
587 (r',', Punctuation), 588 (r',', Punctuation),
588 (r'\), \(', Text), 589 (r'\), \(', Text),
589 (r'\)', Text, '#pop'), 590 (r'\)', Text, '#pop'),
590 ], 591 ],
591 'integer': [(r'-?[0-9]+', Number.Integer),], 592 'integer': [(r'-?[0-9]+', Number.Integer),],
592 'float': [(r'-?[0-9]+\.[0-9]+(e[+-][0-9]+)?', Number.Float)], 593 'float': [(r'-?[0-9]+\.[0-9]+(e[+-][0-9]+)?', Number.Float)],
593 'global': [(r'\@[0-9a-zA-Z_.]+', Name.Variable.Global)], 594 'global': [(r'\@[a-zA-Z0-9_.]+', Name.Variable.Global)],
594 } 595 }
595 596
597
596 class LlvmMirLexer(RegexLexer): 598 class LlvmMirLexer(RegexLexer):
597 """ 599 """
598 Lexer for the overall LLVM MIR document format 600 Lexer for the overall LLVM MIR document format.
599 601
600 MIR is a human readable serialization format that's used to represent LLVM's 602 MIR is a human readable serialization format that's used to represent LLVM's
601 machine specific intermediate representation. It allows LLVM's developers to 603 machine specific intermediate representation. It allows LLVM's developers to
602 see the state of the compilation process at various points, as well as test 604 see the state of the compilation process at various points, as well as test
603 individual pieces of the compiler. 605 individual pieces of the compiler.
647 (r'body: *\|', Keyword, 'llvm_mir_body'), 649 (r'body: *\|', Keyword, 'llvm_mir_body'),
648 # Consume everything else 650 # Consume everything else
649 (r'.+', Text), 651 (r'.+', Text),
650 (r'\n', Text), 652 (r'\n', Text),
651 ], 653 ],
652 'name': [ (r'[^\n]+', Name), default('#pop') ], 654 'name': [
653 'boolean': [ (r' *(true|false)', Name.Builtin), default('#pop') ], 655 (r'[^\n]+', Name),
654 'number': [ (r' *[0-9]+', Number), default('#pop') ], 656 default('#pop'),
657 ],
658 'boolean': [
659 (r' *(true|false)', Name.Builtin),
660 default('#pop'),
661 ],
662 'number': [
663 (r' *[0-9]+', Number),
664 default('#pop'),
665 ],
655 'llvm_mir_body': [ 666 'llvm_mir_body': [
656 # Documents end with '...' or '---'. 667 # Documents end with '...' or '---'.
657 # We have to pop llvm_mir_body and llvm_mir 668 # We have to pop llvm_mir_body and llvm_mir
658 (r'(\.\.\.|(?=---))', Keyword, '#pop:2'), 669 (r'(\.\.\.|(?=---))', Keyword, '#pop:2'),
659 # Delegate the body block to the LlvmMirBodyLexer 670 # Delegate the body block to the LlvmMirBodyLexer
660 (r'((?:.|\n)+?)(?=\.\.\.|---)', bygroups(using(LlvmMirBodyLexer))), 671 (r'((?:.|\n)+?)(?=\.\.\.|---)', bygroups(using(LlvmMirBodyLexer))),
661 # The '...' is optional. If we didn't already find it then it isn't 672 # The '...' is optional. If we didn't already find it then it isn't
662 # there. There might be a '---' instead though. 673 # there. There might be a '---' instead though.
663 (r'(?!\.\.\.|---)((.|\n)+)', bygroups(using(LlvmMirBodyLexer), Keyword)), 674 (r'(?!\.\.\.|---)((?:.|\n)+)', bygroups(using(LlvmMirBodyLexer))),
664 ], 675 ],
665 } 676 }
666 677
667 678
668 class NasmLexer(RegexLexer): 679 class NasmLexer(RegexLexer):
684 binn = r'[01]+b' 695 binn = r'[01]+b'
685 decn = r'[0-9]+' 696 decn = r'[0-9]+'
686 floatn = decn + r'\.e?' + decn 697 floatn = decn + r'\.e?' + decn
687 string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`" 698 string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
688 declkw = r'(?:res|d)[bwdqt]|times' 699 declkw = r'(?:res|d)[bwdqt]|times'
689 register = (r'r[0-9][0-5]?[bwd]|' 700 register = (r'r[0-9][0-5]?[bwd]?|'
690 r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|' 701 r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
691 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]') 702 r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
692 wordop = r'seg|wrt|strict' 703 wordop = r'seg|wrt|strict'
693 type = r'byte|[dq]?word' 704 type = r'byte|[dq]?word'
694 # Directives must be followed by whitespace, otherwise CPU will match 705 # Directives must be followed by whitespace, otherwise CPU will match
749 return False 760 return False
750 761
751 762
752 class NasmObjdumpLexer(ObjdumpLexer): 763 class NasmObjdumpLexer(ObjdumpLexer):
753 """ 764 """
754 For the output of 'objdump -d -M intel'. 765 For the output of ``objdump -d -M intel``.
755 766
756 .. versionadded:: 2.0 767 .. versionadded:: 2.0
757 """ 768 """
758 name = 'objdump-nasm' 769 name = 'objdump-nasm'
759 aliases = ['objdump-nasm'] 770 aliases = ['objdump-nasm']
887 return 0.9 898 return 0.9
888 899
889 900
890 class Dasm16Lexer(RegexLexer): 901 class Dasm16Lexer(RegexLexer):
891 """ 902 """
892 Simple lexer for DCPU-16 Assembly 903 For DCPU-16 Assembly.
893 904
894 Check http://0x10c.com/doc/dcpu-16.txt 905 Check http://0x10c.com/doc/dcpu-16.txt
895 906
896 .. versionadded:: 2.4 907 .. versionadded:: 2.4
897 """ 908 """
922 'SP', 'PC', 'EX', 933 'SP', 'PC', 'EX',
923 'POP', 'PEEK', 'PUSH' 934 'POP', 'PEEK', 'PUSH'
924 ] 935 ]
925 936
926 # Regexes yo 937 # Regexes yo
927 char = r'[a-zA-Z$._0-9@]' 938 char = r'[a-zA-Z0-9_$@.]'
928 identifier = r'(?:[a-zA-Z$_]' + char + r'*|\.' + char + '+)' 939 identifier = r'(?:[a-zA-Z$_]' + char + r'*|\.' + char + '+)'
929 number = r'[+-]?(?:0[xX][a-zA-Z0-9]+|\d+)' 940 number = r'[+-]?(?:0[xX][a-zA-Z0-9]+|\d+)'
930 binary_number = r'0b[01_]+' 941 binary_number = r'0b[01_]+'
931 instruction = r'(?i)(' + '|'.join(INSTRUCTIONS) + ')' 942 instruction = r'(?i)(' + '|'.join(INSTRUCTIONS) + ')'
932 single_char = r"'\\?" + char + "'" 943 single_char = r"'\\?" + char + "'"

eric ide

mercurial