spirv: Handle instruction aliases in spirv_info_c.py
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 3 Apr 2019 19:45:22 +0000 (12:45 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Tue, 21 May 2019 18:50:47 +0000 (11:50 -0700)
Choose the first we see in the grammar file as the main one.  This is
needed to parse SPIR-V 1.4 because it introduced opcode aliases.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
src/compiler/spirv/spirv_info_c.py

index 22fd675720c72eb4225fa4722d8eadc9c2876e07..b9938aedb85e61c45724249cf7e201f3617a4337 100644 (file)
@@ -46,11 +46,18 @@ def collect_data(spirv, kind):
     return (kind, values)
 
 def collect_opcodes(spirv):
+    seen = set()
     values = []
     for x in spirv["instructions"]:
+        # Handle aliases by choosing the first one in the grammar.
+        # E.g. OpDecorateString and OpDecorateStringGOOGLE share same opcode.
+        if x["opcode"] in seen:
+            continue
+        opcode = x["opcode"]
         name = x["opname"]
         assert name.startswith("Op")
         values.append(name[2:])
+        seen.add(opcode)
 
     return ("Op", values)