mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 22:49:13 +02:00
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>
This commit is contained in:
parent
b67cac5eba
commit
b2e4972339
1 changed files with 21 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue