intel/genxml/bits: Emit per-container _length helpers
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 30 Mar 2017 03:39:18 +0000 (20:39 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 8 Apr 2017 05:34:04 +0000 (22:34 -0700)
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
src/intel/genxml/gen_bits_header.py

index fc31baa1b88597086508f49e0c46216b919d7c96..ac8ec4c41f4a73e29e4a6d39662d62e5fb05788b 100644 (file)
@@ -107,6 +107,11 @@ ${item.token_name}_${prop}(const struct gen_device_info *devinfo)
 extern "C" {
 #endif
 % for _, container in sorted(containers.iteritems(), key=itemgetter(0)):
+
+/* ${container.name} */
+
+${emit_per_gen_prop_func(container, 'length')}
+
 % for _, field in sorted(container.fields.iteritems(), key=itemgetter(0)):
 
 /* ${container.name}::${field.name} */
@@ -191,8 +196,15 @@ class Container(object):
 
     def __init__(self, name):
         self.name = name
+        self.token_name = safe_name(name)
+        self.length_by_gen = {}
         self.fields = {}
 
+    def add_gen(self, gen, xml_attrs):
+        assert isinstance(gen, Gen)
+        if 'length' in xml_attrs:
+            self.length_by_gen[gen] = xml_attrs['length']
+
     def get_field(self, field_name, create=False):
         if field_name not in self.fields:
             if create:
@@ -201,6 +213,27 @@ class Container(object):
                 return None
         return self.fields[field_name]
 
+    def has_prop(self, prop):
+        if prop == 'length':
+            return bool(self.length_by_gen)
+        else:
+            raise ValueError('Invalid property: "{0}"'.format(prop))
+
+    def iter_prop(self, prop):
+        if prop == 'length':
+            return self.length_by_gen.iteritems()
+        else:
+            raise ValueError('Invalid property: "{0}"'.format(prop))
+
+    def get_prop(self, prop, gen):
+        if not isinstance(gen, Gen):
+            gen = Gen(gen)
+
+        if prop == 'length':
+            return self.length_by_gen.get(gen, 0)
+        else:
+            raise ValueError('Invalid property: "{0}"'.format(prop))
+
 class Field(object):
 
     def __init__(self, container, name):
@@ -277,6 +310,7 @@ class XmlParser(object):
         if name not in self.containers:
             self.containers[name] = Container(name)
         self.container = self.containers[name]
+        self.container.add_gen(self.gen, attrs)
 
     def start_field(self, attrs):
         if self.container is None: