summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Symalla <5754458+tsymalla@users.noreply.github.com>2021-01-30 14:27:03 +0100
committerGitHub <noreply@github.com>2021-01-30 14:27:03 +0100
commitfc0d85490c8b64de8f60d70042ad7919470a0059 (patch)
treef8203d5e9a8b27ac693b2db3f1993606a609663e
parent8ef301a0251a575a776fd4550ff155b41af2def9 (diff)
downloadpygments-git-fc0d85490c8b64de8f60d70042ad7919470a0059.tar.gz
AMDGPU ISA Lexer (#1626)
* This commit implements a basic lexer for the AMDGPU ISA definition. * Updated comment. * Updated comment. * Tried to fix case-sensitive issue. * Updated AUTHORS file. * Added shader unit test for the AMD ISA Parser. * Renamed AMDGCN lexer to AMDGPU. * Renamed example file. * Renames. Co-authored-by: Thomas Symalla <root@SEUCHOMAT.localdomain>
-rw-r--r--AUTHORS2
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/amdgpu.py44
-rw-r--r--tests/examplefiles/amdgpu.isa10
4 files changed, 57 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index a5c9fb50..f28b47a4 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -234,6 +234,8 @@ Other contributors, listed alphabetically, are:
* Alex Zimin -- Nemerle lexer
* Rob Zimmerman -- Kal lexer
* Vincent Zurczak -- Roboconf lexer
+* Hubert Gruniaux -- C and C++ lexer improvements
+* Thomas Symalla -- AMDGPU Lexer
* 15b3 -- Image Formatter improvements
Many thanks for all contributions!
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index bb7df162..5f4473f6 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -14,6 +14,7 @@
LEXERS = {
'ABAPLexer': ('pygments.lexers.business', 'ABAP', ('abap',), ('*.abap', '*.ABAP'), ('text/x-abap',)),
+ 'AMDGPULexer': ('pygments.lexers.amdgpu', 'AMDGPU', ('amdgpu',), ('*.isa',), ()),
'APLLexer': ('pygments.lexers.apl', 'APL', ('apl',), ('*.apl',), ()),
'AbnfLexer': ('pygments.lexers.grammar_notation', 'ABNF', ('abnf',), ('*.abnf',), ('text/x-abnf',)),
'ActionScript3Lexer': ('pygments.lexers.actionscript', 'ActionScript 3', ('as3', 'actionscript3'), ('*.as',), ('application/x-actionscript3', 'text/x-actionscript3', 'text/actionscript3')),
diff --git a/pygments/lexers/amdgpu.py b/pygments/lexers/amdgpu.py
new file mode 100644
index 00000000..8fd5c921
--- /dev/null
+++ b/pygments/lexers/amdgpu.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.AMDGPULexer
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Lexers for the AMDGPU ISA assembly.
+
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from pygments.lexer import RegexLexer
+from pygments.token import *
+
+import re
+
+__all__ = ['AMDGPULexer']
+
+class AMDGPULexer(RegexLexer):
+ name = 'AMDGPU'
+ aliases = ['amdgpu']
+ filenames = ['*.isa']
+
+ flags = re.IGNORECASE
+
+ tokens = {
+ 'root': [
+ (r'\s+', Whitespace),
+ (r'[\r\n]+', Text),
+ (r'(([a-z_0-9])*:([a-z_0-9])*)', Name.Attribute),
+ (r'(\[|\]|\(|\)|,|\:|\&)', Text),
+ (r'([;#]|//).*?\n', Comment.Single),
+ (r'((s_)?(ds|buffer|flat|image)_[a-z0-9_]+)', Keyword.Reserved),
+ (r'(_lo|_hi)', Name.Variable),
+ (r'(vmcnt|lgkmcnt|expcnt|vmcnt|lit|unorm|glc)', Name.Attribute),
+ (r'(label_[a-z0-9]+)', Keyword),
+ (r'(_L[0-9]*)', Name.Variable),
+ (r'(s|v)_[a-z0-9_]+', Keyword),
+ (r'(v[0-9.]+|vcc|exec|v)', Name.Variable),
+ (r's[0-9.]+|s', Name.Variable),
+ (r'[0-9]+\.[^0-9]+', Number.Float),
+ (r'(0[xX][a-z0-9]+)|([0-9]+)', Number.Integer)
+ ]
+ } \ No newline at end of file
diff --git a/tests/examplefiles/amdgpu.isa b/tests/examplefiles/amdgpu.isa
new file mode 100644
index 00000000..fdab33cc
--- /dev/null
+++ b/tests/examplefiles/amdgpu.isa
@@ -0,0 +1,10 @@
+s_load_dwordx2 s[4:5], s[0:1], 0x10
+s_load_dwordx4 s[0:3], s[0:1], 0x00
+v_lshlrev_b32 v0, 2, v0
+s_waitcnt lgkmcnt(0)
+v_add_u32 v1, vcc, s2, v0
+v_mov_b32 v2, s3
+v_addc_u32 v2, vcc, v2, 0, vcc
+v_add_u32 v3, vcc, s0, v0
+v_mov_b32 v4, s1
+v_addc_u32 v4, vcc, v4, 0, vcc \ No newline at end of file