broadcom/genxml: Add support for enum-typed fields.
authorEric Anholt <eric@anholt.net>
Fri, 8 Sep 2017 22:31:37 +0000 (15:31 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 19 Sep 2017 17:40:55 +0000 (10:40 -0700)
This basically comes from the intel genxml script.  This will help improve
gdb and CLIF output once we convert fields over.

src/broadcom/cle/gen_pack_header.py

index 3ec189895a323bb1f3f235d287d86c1dd5c390e4..badcc2c587c078ad39f871dc1ecc16e5e8c41d06 100644 (file)
@@ -152,6 +152,8 @@ class Field(object):
             type = 'uint32_t'
         elif self.type in self.parser.structs:
             type = 'struct ' + self.parser.gen_prefix(safe_name(self.type))
+        elif self.type in self.parser.enums:
+            type = 'enum ' + self.parser.gen_prefix(safe_name(self.type))
         elif self.type == 'mbo':
             return
         else:
@@ -283,6 +285,9 @@ class Group(object):
                 elif field.type == "uint":
                     s = "__gen_uint(values->%s, %d, %d)" % \
                         (name, start, end)
+                elif field.type in self.parser.enums:
+                    s = "__gen_uint(values->%s, %d, %d)" % \
+                        (name, start, end)
                 elif field.type == "int":
                     s = "__gen_sint(values->%s, %d, %d)" % \
                         (name, start, end)
@@ -335,6 +340,8 @@ class Group(object):
                     convert = "__gen_unpack_address"
                 elif field.type == "uint":
                     convert = "__gen_unpack_uint"
+                elif field.type in self.parser.enums:
+                    convert = "__gen_unpack_uint"
                 elif field.type == "int":
                     convert = "__gen_unpack_sint"
                 elif field.type == "bool":
@@ -370,6 +377,8 @@ class Parser(object):
         self.packet = None
         self.struct = None
         self.structs = {}
+        # Set of enum names we've seen.
+        self.enums = set()
         self.registers = {}
 
     def gen_prefix(self, name):
@@ -423,6 +432,7 @@ class Parser(object):
         elif name == "enum":
             self.values = []
             self.enum = safe_name(attrs["name"])
+            self.enums.add(attrs["name"])
             if "prefix" in attrs:
                 self.prefix = safe_name(attrs["prefix"])
             else:
@@ -526,14 +536,14 @@ class Parser(object):
         print('')
 
     def emit_enum(self):
-        print('/* enum %s */' % self.gen_prefix(self.enum))
+        print('enum %s {' % self.gen_prefix(self.enum))
         for value in self.values:
             if self.prefix:
                 name = self.prefix + "_" + value.name
             else:
                 name = value.name
-                print('#define %-36s %6d' % (name.upper(), value.value))
-        print('')
+            print('        % -36s = %6d,' % (name.upper(), value.value))
+        print('};\n')
 
     def parse(self, filename):
         file = open(filename, "rb")