broadcom/genxml: Emit code for default headers for structs as well.
authorEric Anholt <eric@anholt.net>
Mon, 19 Dec 2016 19:11:44 +0000 (11:11 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 18 Aug 2017 18:56:58 +0000 (11:56 -0700)
In the vc5 NIR backend, I want to use the XML code-generation to set up
pack/unpack of structs for the texture uniforms, and setting up the
unpacked copy needs a default header.

src/broadcom/cle/gen_pack_header.py

index 1ebeec7a794bd3de83be503e153ae11e6e5d0298..3ec189895a323bb1f3f235d287d86c1dd5c390e4 100644 (file)
@@ -478,13 +478,7 @@ class Parser(object):
 
         print("}\n#endif\n")
 
-    def emit_packet(self):
-        name = self.packet
-
-        assert(self.group.fields[0].name == "opcode")
-        print('#define %-33s %6d' %
-              (name + "_opcode", self.group.fields[0].default))
-
+    def emit_header(self, name):
         default_fields = []
         for field in self.group.fields:
             if not type(field) is Field:
@@ -493,11 +487,18 @@ class Parser(object):
                 continue
             default_fields.append("   .%-35s = %6d" % (field.name, field.default))
 
-        if default_fields:
-            print('#define %-40s\\' % (name + '_header'))
-            print(",  \\\n".join(default_fields))
-            print('')
+        print('#define %-40s\\' % (name + '_header'))
+        print(",  \\\n".join(default_fields))
+        print('')
+
+    def emit_packet(self):
+        name = self.packet
+
+        assert(self.group.fields[0].name == "opcode")
+        print('#define %-33s %6d' %
+              (name + "_opcode", self.group.fields[0].default))
 
+        self.emit_header(name)
         self.emit_template_struct(self.packet, self.group)
         self.emit_pack_function(self.packet, self.group)
         self.emit_unpack_function(self.packet, self.group)
@@ -516,10 +517,8 @@ class Parser(object):
 
     def emit_struct(self):
         name = self.struct
-        # Emit an empty header define so that we can use the CL pack functions
-        # with structs.
-        print('#define ' + name + '_header')
 
+        self.emit_header(name)
         self.emit_template_struct(self.struct, self.group)
         self.emit_pack_function(self.struct, self.group)
         self.emit_unpack_function(self.struct, self.group)