diff options
author | Christian Gmeiner <cgmeiner@igalia.com> | 2023-09-04 15:18:15 +0200 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2023-10-03 12:07:04 +0000 |
commit | b2e4972339711a9576ec309ecdd4f42eb664c2f9 (patch) | |
tree | 1a5cf23ac83b6586c10923223c32fbd4cfab4d1b | |
parent | b67cac5eba480307786537c875c3c37e8c86be4c (diff) |
isaspec: Add BitSetEnumValue object
There might be cases where you describe an enum in isaspec and want it to use
for decoding but also for codegen with e.g. mako.
Lets have a look at the following exmaple:
<enum name="#cond">
<value val="0" display=""/> <!-- always: display nothing -->
<value val="1" display=".gt"/>
...
</enum>
In the decoding case we want that nothing gets displayed if #cond has the value of "0". For
codegen with mako this could result in the following C code:
enum PACKED cond {
COND_ = 0,
COND_GT = 1,
...
};
What you really want is this:
enum PACKED cond {
COND_ALWAYS = 0,
COND_GT = 1,
...
};
To make this possible introduce BitSetEnumValue class which represents
an isaspec xml enum. It holds the value, displayname and now a name.
With the __str__ method the old behaviour is still intact.
Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25451>
-rw-r--r-- | src/compiler/isaspec/isa.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/compiler/isaspec/isa.py b/src/compiler/isaspec/isa.py index 32defb87b0b..dda0b7c84b0 100644 --- a/src/compiler/isaspec/isa.py +++ b/src/compiler/isaspec/isa.py @@ -405,18 +405,36 @@ class BitSetTemplate(object): self.display = xml.text.strip() dbg("found template '{}: {}'".format(self.name, self.display)) +class BitSetEnumValue(object): + """Class that encapsulates an enum value + """ + def __init__(self, isa, xml): + self.isa = isa + self.displayname = xml.attrib['display'] + self.value = xml.attrib['val'] + self.name = xml.attrib.get('name') + + def __str__(self): + return self.displayname + + def get_name(self): + return self.name or self.displayname + + def get_value(self): + return self.value + class BitSetEnum(object): """Class that encapsulates an enum declaration """ def __init__(self, isa, xml): self.isa = isa self.name = xml.attrib['name'] + # Table mapping value to name - # TODO currently just mapping to 'display' name, but if we - # need more attributes then maybe need BitSetEnumValue? self.values = {} for value in xml.findall('value'): - self.values[value.attrib['val']] = value.attrib['display'] + v = BitSetEnumValue(self, value) + self.values[v.get_value()] = v def get_c_name(self): return 'enum_' + get_c_name(self.name) |