mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 01:15:39 +00:00
Generators for Emscripten
api_struct_info.json: //* This generator is used to produce part of Emscripten's struct_info.json, //* which is a list of struct fields that it uses to generate field offset //* information for its own code generators. //* https://github.com/emscripten-core/emscripten/blob/master/src/struct_info.json library_webgpu_enum_tables.js: //* This generator is used to produce the number-to-string mappings for //* Emscripten's library_webgpu.js. //* https://github.com/emscripten-core/emscripten/blob/master/src/library_webgpu.js Change-Id: I4704509737cde4685a093eb484dd977e5a106d19 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15240 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
74f5054ec9
commit
7b6246a2ad
@@ -51,6 +51,14 @@ class Name:
|
||||
def snake_case(self):
|
||||
return '_'.join(self.chunks)
|
||||
|
||||
def js_enum_case(self):
|
||||
result = self.chunks[0].lower()
|
||||
for chunk in self.chunks[1:]:
|
||||
if not result[-1].isdigit():
|
||||
result += '-'
|
||||
result += chunk.lower()
|
||||
return result
|
||||
|
||||
def concat_names(*names):
|
||||
return ' '.join([name.canonical_case() for name in names])
|
||||
|
||||
@@ -60,12 +68,26 @@ class Type:
|
||||
self.dict_name = name
|
||||
self.name = Name(name, native=native)
|
||||
self.category = json_data['category']
|
||||
self.javascript = self.json_data.get('javascript', True)
|
||||
|
||||
EnumValue = namedtuple('EnumValue', ['name', 'value', 'valid'])
|
||||
EnumValue = namedtuple('EnumValue', ['name', 'value', 'valid', 'jsrepr'])
|
||||
class EnumType(Type):
|
||||
def __init__(self, name, json_data):
|
||||
Type.__init__(self, name, json_data)
|
||||
self.values = [EnumValue(Name(m['name']), m['value'], m.get('valid', True)) for m in self.json_data['values']]
|
||||
|
||||
self.values = []
|
||||
self.contiguousFromZero = True
|
||||
lastValue = -1
|
||||
for m in self.json_data['values']:
|
||||
value = m['value']
|
||||
if value != lastValue + 1:
|
||||
self.contiguousFromZero = False
|
||||
lastValue = value
|
||||
self.values.append(EnumValue(
|
||||
Name(m['name']),
|
||||
value,
|
||||
m.get('valid', True),
|
||||
m.get('jsrepr', None)))
|
||||
|
||||
# Assert that all values are unique in enums
|
||||
all_values = set()
|
||||
@@ -377,6 +399,10 @@ def as_cppType(name):
|
||||
else:
|
||||
return name.CamelCase()
|
||||
|
||||
def as_jsEnumValue(value):
|
||||
if value.jsrepr: return value.jsrepr
|
||||
return "'" + value.name.js_enum_case() + "'"
|
||||
|
||||
def convert_cType_to_cppType(typ, annotation, arg, indent=0):
|
||||
if typ.category == 'native':
|
||||
return arg
|
||||
@@ -522,6 +548,7 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||
'as_cType': as_cType,
|
||||
'as_cTypeDawn': as_cTypeDawn,
|
||||
'as_cppType': as_cppType,
|
||||
'as_jsEnumValue': as_jsEnumValue,
|
||||
'convert_cType_to_cppType': convert_cType_to_cppType,
|
||||
'as_varName': as_varName,
|
||||
'decorate': decorate,
|
||||
@@ -544,6 +571,10 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||
if 'dawncpp' in targets:
|
||||
renders.append(FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', [base_params, api_params]))
|
||||
|
||||
if 'emscripten_bits' in targets:
|
||||
renders.append(FileRender('webgpu_struct_info.json', 'src/dawn/webgpu_struct_info.json', [base_params, api_params]))
|
||||
renders.append(FileRender('library_webgpu_enum_tables.js', 'src/dawn/library_webgpu_enum_tables.js', [base_params, api_params]))
|
||||
|
||||
if 'mock_webgpu' in targets:
|
||||
mock_params = [
|
||||
base_params,
|
||||
|
||||
Reference in New Issue
Block a user