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

14 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:16 +0000

1""" 

2 pygments.lexers.ptx 

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

4 

5 Lexer for other PTX language. 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, include, words 

12from pygments.token import Comment, Keyword, Name, String, Number, Punctuation, \ 

13Whitespace, Operator 

14 

15__all__ = ["PtxLexer"] 

16 

17 

18class PtxLexer(RegexLexer): 

19 """ 

20 For NVIDIA `PTX <https://docs.nvidia.com/cuda/parallel-thread-execution/>`_ 

21 source. 

22 

23 .. versionadded:: 2.15 

24 """ 

25 name = 'PTX' 

26 url = "https://docs.nvidia.com/cuda/parallel-thread-execution/" 

27 filenames = ['*.ptx'] 

28 aliases = ['ptx'] 

29 mimetypes = ['text/x-ptx'] 

30 

31 #: optional Comment or Whitespace 

32 string = r'"[^"]*?"' 

33 followsym = r'[a-zA-Z0-9_$]' 

34 identifier = r'([-a-zA-Z$._][\w\-$.]*|' + string + ')' 

35 block_label = r'(' + identifier + r'|(\d+))' 

36 

37 tokens = { 

38 'root': [ 

39 include('whitespace'), 

40 

41 (block_label + r'\s*:', Name.Label), 

42 

43 include('keyword'), 

44 

45 (r'%' + identifier, Name.Variable), 

46 (r'%\d+', Name.Variable.Anonymous), 

47 (r'c?' + string, String), 

48 (identifier, Name.Variable), 

49 (r';', Punctuation), 

50 (r'[*+-/]', Operator), 

51 

52 (r'0[xX][a-fA-F0-9]+', Number), 

53 (r'-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?', Number), 

54 

55 (r'[=<>{}\[\]()*.,!]|x\b', Punctuation) 

56 

57 ], 

58 'whitespace': [ 

59 (r'(\n|\s+)+', Whitespace), 

60 (r'//.*?\n', Comment) 

61 ], 

62 

63 'keyword': [ 

64 # Instruction keywords 

65 (words(( 

66 'abs', 'discard', 'min', 'shf', 'vadd', 

67 'activemask', 'div', 'mma', 'shfl', 'vadd2', 

68 'add','dp2a','mov','shl','vadd4', 

69 'addc','dp4a','movmatrix','shr','vavrg2', 

70 'alloca','elect','mul','sin','vavrg4', 

71 'and','ex2','mul24','slct','vmad', 

72 'applypriority','exit','multimem','sqrt','vmax', 

73 'atom','fence','nanosleep','st','vmax2', 

74 'bar','fma','neg','stackrestore','vmax4', 

75 'barrier','fns','not','stacksave','vmin', 

76 'bfe','getctarank','or','stmatrix','vmin2', 

77 'bfi','griddepcontrol','pmevent','sub','vmin4', 

78 'bfind','isspacep','popc','subc','vote', 

79 'bmsk','istypep','prefetch','suld','vset', 

80 'bra','ld', 'prefetchu','suq','vset2', 

81 'brev','ldmatrix','prmt','sured','vset4', 

82 'brkpt','ldu','rcp','sust','vshl', 

83 'brx','lg2','red','szext','vshr', 

84 'call','lop3','redux','tanh','vsub', 

85 'clz','mad', 'rem','testp','vsub2', 

86 'cnot','mad24','ret','tex','vsub4', 

87 'copysign','madc','rsqrt','tld4','wgmma', 

88 'cos','mapa','sad','trap','wmma', 

89 'cp','match','selp','txq','xor', 

90 'createpolicy','max','set','vabsdiff','cvt', 

91 'mbarrier','setmaxnreg','vabsdiff2','cvta', 

92 'membar','setp','vabsdiff4')), Keyword), 

93 # State Spaces and Suffixes 

94 (words(( 

95 'reg', '.sreg', '.const', '.global', 

96 '.local', '.param', '.shared', '.tex', 

97 '.wide', '.loc' 

98 )), Keyword.Pseudo), 

99 # PTX Directives 

100 (words(( 

101 '.address_size','.explicitcluster','.maxnreg','.section', 

102 '.alias', '.extern','.maxntid','.shared', 

103 '.align','.file','.minnctapersm','.sreg', 

104 '.branchtargets','.func','.noreturn','.target', 

105 '.callprototype','.global','.param','.tex', 

106 '.calltargets','.loc','.pragma','.version', 

107 '.common','.local','.reg','.visible', 

108 '.const','.maxclusterrank','.reqnctapercluster','.weak', 

109 '.entry','.maxnctapersm','.reqntid')), Keyword.Reserved), 

110 # Fundamental Types 

111 (words(( 

112 '.s8', '.s16', '.s32', '.s64', 

113 '.u8', '.u16', '.u32', '.u64', 

114 '.f16', '.f16x2', '.f32', '.f64', 

115 '.b8', '.b16', '.b32', '.b64', 

116 '.pred' 

117 )), Keyword.Type) 

118 ], 

119 

120 }