Add ability to generate constants from dawn.json

The "constant" category has two keys:
 - `"type"`: a string, the name of the base data type
 - `"value"`: a string, the value is defined with preprocessor macro

Remove deprecated constant InputStepMode.

BUG=dawn:1201, dawn:1023

Change-Id: If4308bd5b25dddd9453514ce362bebe4fd771a57
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/70704
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Commit-Queue: Junwei Fu <junwei.fu@intel.com>
This commit is contained in:
fujunwei
2021-11-25 08:44:01 +00:00
committed by Dawn LUCI CQ
parent a329997e27
commit 4e8769087a
5 changed files with 72 additions and 29 deletions

View File

@@ -239,6 +239,14 @@ class StructureType(Record, Type):
return self.chained == "out" or self.extensible == "out"
class ConstantDefinition():
def __init__(self, is_enabled, name, json_data):
self.type = None
self.value = json_data['value']
self.json_data = json_data
self.name = Name(name)
class Command(Record):
def __init__(self, name, members=None):
Record.__init__(self, name)
@@ -310,6 +318,11 @@ def link_typedef(typedef, types):
typedef.type = types[typedef.json_data['type']]
def link_constant(constant, types):
constant.type = types[constant.json_data['type']]
assert constant.type.name.native
# Sort structures so that if struct A has struct B as a member, then B is
# listed before A.
#
@@ -362,6 +375,7 @@ def parse_json(json, enabled_tags):
'object': ObjectType,
'structure': StructureType,
'typedef': TypedefType,
'constant': ConstantDefinition,
}
types = {}
@@ -390,6 +404,9 @@ def parse_json(json, enabled_tags):
for typedef in by_category['typedef']:
link_typedef(typedef, types)
for constant in by_category['constant']:
link_constant(constant, types)
for category in by_category.keys():
by_category[category] = sorted(
by_category[category], key=lambda typ: typ.name.canonical_case())