Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/mips.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 07:45 +0000

1""" 

2 pygments.lexers.mips 

3 ~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for MIPS assembly. 

6 

7 :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, words 

12from pygments.token import Whitespace, Comment, String, Keyword, Name, Text 

13 

14__all__ = ["MIPSLexer"] 

15 

16 

17class MIPSLexer(RegexLexer): 

18 """ 

19 A MIPS Assembly Lexer. 

20 

21 Based on the Emacs major mode by hlissner: 

22 https://github.com/hlissner/emacs-mips-mode 

23 """ 

24 

25 name = 'MIPS' 

26 aliases = ['mips'] 

27 # TODO: add '*.s' and '*.asm', which will require designing an analyse_text 

28 # method for this lexer and refactoring those from Gas and Nasm in order to 

29 # have relatively reliable detection 

30 filenames = ['*.mips', '*.MIPS'] 

31 

32 keywords = [ 

33 # Arithmetic insturctions 

34 "add", "sub", "subu", "addi", "subi", "addu", "addiu", 

35 # Multiplication/division 

36 "mul", "mult", "multu", "mulu", "madd", "maddu", "msub", "msubu", "div", "divu", 

37 # Bitwise operations 

38 "and", "or", "nor", "xor", "andi", "ori", "xori", "clo", "clz", 

39 # Shifts 

40 "sll", "srl", "sllv", "srlv", "sra", "srav", 

41 # Comparisons 

42 "slt", "sltu", "slti", "sltiu", 

43 # Move data 

44 "mfhi", "mthi", "mflo", "mtlo", "movn", "movz", "movf", "movt", 

45 # Jump 

46 "j", "jal", "jalr", "jr", 

47 # branch 

48 "bc1f", "bc1t", "beq", "bgez", "bgezal", "bgtz", "blez", "bltzal", "bltz", "bne", 

49 # Load 

50 "lui", "lb", "lbu", "lh", "lhu", "lw", "lwcl", "lwl", "lwr", 

51 # Store 

52 "sb", "sh", "sw", "swl", "swr", # coproc: swc1 sdc1 

53 # Concurrent load/store 

54 "ll", "sc", 

55 # Trap handling 

56 "teq", "teqi", "tne", "tneqi", "tge", "tgeu", "tgei", "tgeiu", "tlt", "tltu", "tlti", 

57 "tltiu", 

58 # Exception / Interrupt 

59 "eret", "break", "bop", "syscall", 

60 # --- Floats ----------------------------------------------------- 

61 # Arithmetic 

62 "add.s", "add.d", "sub.s", "sub.d", "mul.s", "mul.d", "div.s", "div.d", "neg.d", 

63 "neg.s", 

64 # Comparison 

65 "c.e.d", "c.e.s", "c.le.d", "c.le.s", "c.lt.s", "c.lt.d", # "c.gt.s", "c.gt.d", 

66 "madd.s", "madd.d", "msub.s", "msub.d", 

67 # Move Floats 

68 "mov.d", "move.s", "movf.d", "movf.s", "movt.d", "movt.s", "movn.d", "movn.s", 

69 "movnzd", "movz.s", "movz.d", 

70 # Conversion 

71 "cvt.d.s", "cvt.d.w", "cvt.s.d", "cvt.s.w", "cvt.w.d", "cvt.w.s", "trunc.w.d", 

72 "trunc.w.s", 

73 # Math 

74 "abs.s", "abs.d", "sqrt.s", "sqrt.d", "ceil.w.d", "ceil.w.s", "floor.w.d", 

75 "floor.w.s", "round.w.d", "round.w.s", 

76 ] 

77 

78 pseudoinstructions = [ 

79 # Arithmetic & logical 

80 "rem", "remu", "mulo", "mulou", "abs", "neg", "negu", "not", "rol", "ror", 

81 # branches 

82 "b", "beqz", "bge", "bgeu", "bgt", "bgtu", "ble", "bleu", "blt", "bltu", "bnez", 

83 # loads 

84 "la", "li", "ld", "ulh", "ulhu", "ulw", 

85 # Store 

86 "sd", "ush", "usw", 

87 # move 

88 "move", # coproc: "mfc1.d", 

89 # comparisons 

90 "sgt", "sgtu", "sge", "sgeu", "sle", "sleu", "sne", "seq", 

91 # --- Floats ----------------------------------------------------- 

92 # load-store 

93 "l.d", "l.s", "s.d", "s.s", 

94 ] 

95 

96 directives = [ 

97 ".align", ".ascii", ".asciiz", ".byte", ".data", ".double", ".extern", ".float", 

98 ".globl", ".half", ".kdata", ".ktext", ".space", ".text", ".word", 

99 ] 

100 

101 deprecated = [ 

102 "beql", "bnel", "bgtzl", "bgezl", "bltzl", "blezl", "bltzall", "bgezall", 

103 ] 

104 

105 tokens = { 

106 'root': [ 

107 (r'\s+', Whitespace), 

108 (r'#.*', Comment), 

109 (r'"', String, 'string'), 

110 (r'-?[0-9]+?', Keyword.Constant), 

111 (r'\w*:', Name.Function), 

112 (words(deprecated, suffix=r'\b'), Keyword.Pseudo), # need warning face 

113 (words(pseudoinstructions, suffix=r'\b'), Name.Variable), 

114 (words(keywords, suffix=r'\b'), Keyword), 

115 (r'[slm][ftwd]c[0-9]([.]d)?', Keyword), 

116 (r'\$(f?[0-2][0-9]|f?3[01]|[ft]?[0-9]|[vk][01]|a[0-3]|s[0-7]|[gsf]p|ra|at|zero)', 

117 Keyword.Type), 

118 (words(directives, suffix=r'\b'), Name.Entity), # Preprocessor? 

119 (r':|,|;|\{|\}|=>|@|\$|=', Name.Builtin), 

120 (r'\w+', Text), 

121 (r'.', Text), 

122 ], 

123 'string': [ 

124 (r'\\.', String.Escape), 

125 (r'"', String, '#pop'), 

126 (r'[^\\"]+', String), 

127 ], 

128 }