asahi: Allow GenXML to be used in C++
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 6 Feb 2022 20:02:26 +0000 (15:02 -0500)
committerMarge Bot <emma+marge@anholt.net>
Fri, 18 Feb 2022 23:48:32 +0000 (23:48 +0000)
C++ requires explicit casts from integers to enums. Fixes errors like
the following when trying to use Asahi GenXML from a GTest unit test.

src/asahi/lib/agx_pack.h:554:23: error: assigning to 'enum agx_channels' from incompatible type 'uint64_t' (aka 'unsigned long long')
   values->channels = __gen_unpack_uint(cl, 0, 6);

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14903>

src/asahi/lib/gen_pack.py

index a803147..1491994 100644 (file)
@@ -511,6 +511,9 @@ class Group(object):
                 if field.modifier[0] == "log2":
                     prefix = "1 << "
 
+            if field.type in self.parser.enums:
+                prefix = f"(enum {enum_name(field.type)}) {prefix}"
+
             decoded = '{}{}({}){}'.format(prefix, convert, ', '.join(args), suffix)
 
             print('   values->{} = {};'.format(fieldref.path, decoded))