Corentin Wallez | 59382b7 | 2020-04-17 20:43:07 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 2 | # Copyright 2017 The Dawn Authors |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 16 | import json, os, sys |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 17 | from collections import namedtuple |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 18 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 19 | from generator_lib import Generator, run_generator, FileRender |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 20 | |
| 21 | ############################################################ |
| 22 | # OBJECT MODEL |
| 23 | ############################################################ |
| 24 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 25 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 26 | class Metadata: |
| 27 | def __init__(self, metadata): |
| 28 | self.api = metadata['api'] |
| 29 | self.namespace = metadata['namespace'] |
| 30 | self.c_prefix = metadata.get('c_prefix', self.namespace.upper()) |
fujunwei | 3a46476 | 2021-12-05 05:29:44 +0000 | [diff] [blame] | 31 | self.proc_table_prefix = metadata['proc_table_prefix'] |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 32 | self.copyright_year = metadata.get('copyright_year', None) |
| 33 | |
| 34 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 35 | class Name: |
| 36 | def __init__(self, name, native=False): |
| 37 | self.native = native |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 38 | self.name = name |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 39 | if native: |
| 40 | self.chunks = [name] |
| 41 | else: |
| 42 | self.chunks = name.split(' ') |
| 43 | |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 44 | def get(self): |
| 45 | return self.name |
| 46 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 47 | def CamelChunk(self, chunk): |
| 48 | return chunk[0].upper() + chunk[1:] |
| 49 | |
| 50 | def canonical_case(self): |
| 51 | return (' '.join(self.chunks)).lower() |
| 52 | |
| 53 | def concatcase(self): |
| 54 | return ''.join(self.chunks) |
| 55 | |
| 56 | def camelCase(self): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 57 | return self.chunks[0] + ''.join( |
| 58 | [self.CamelChunk(chunk) for chunk in self.chunks[1:]]) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 59 | |
| 60 | def CamelCase(self): |
| 61 | return ''.join([self.CamelChunk(chunk) for chunk in self.chunks]) |
| 62 | |
| 63 | def SNAKE_CASE(self): |
| 64 | return '_'.join([chunk.upper() for chunk in self.chunks]) |
| 65 | |
| 66 | def snake_case(self): |
| 67 | return '_'.join(self.chunks) |
| 68 | |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 69 | def js_enum_case(self): |
| 70 | result = self.chunks[0].lower() |
| 71 | for chunk in self.chunks[1:]: |
| 72 | if not result[-1].isdigit(): |
| 73 | result += '-' |
| 74 | result += chunk.lower() |
| 75 | return result |
| 76 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 77 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 78 | def concat_names(*names): |
| 79 | return ' '.join([name.canonical_case() for name in names]) |
| 80 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 81 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 82 | class Type: |
| 83 | def __init__(self, name, json_data, native=False): |
| 84 | self.json_data = json_data |
| 85 | self.dict_name = name |
| 86 | self.name = Name(name, native=native) |
| 87 | self.category = json_data['category'] |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 88 | self.is_wire_transparent = False |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 89 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 90 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 91 | EnumValue = namedtuple('EnumValue', ['name', 'value', 'valid', 'json_data']) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 92 | |
| 93 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 94 | class EnumType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 95 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 96 | Type.__init__(self, name, json_data) |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 97 | |
| 98 | self.values = [] |
| 99 | self.contiguousFromZero = True |
| 100 | lastValue = -1 |
| 101 | for m in self.json_data['values']: |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 102 | if not is_enabled(m): |
| 103 | continue |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 104 | value = m['value'] |
| 105 | if value != lastValue + 1: |
| 106 | self.contiguousFromZero = False |
| 107 | lastValue = value |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 108 | self.values.append( |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 109 | EnumValue(Name(m['name']), value, m.get('valid', True), m)) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 110 | |
Corentin Wallez | 7ac0815 | 2019-06-26 19:54:43 +0000 | [diff] [blame] | 111 | # Assert that all values are unique in enums |
| 112 | all_values = set() |
| 113 | for value in self.values: |
| 114 | if value.value in all_values: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 115 | raise Exception("Duplicate value {} in enum {}".format( |
| 116 | value.value, name)) |
Corentin Wallez | 7ac0815 | 2019-06-26 19:54:43 +0000 | [diff] [blame] | 117 | all_values.add(value.value) |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 118 | self.is_wire_transparent = True |
Corentin Wallez | 7ac0815 | 2019-06-26 19:54:43 +0000 | [diff] [blame] | 119 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 120 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 121 | BitmaskValue = namedtuple('BitmaskValue', ['name', 'value', 'json_data']) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 122 | |
| 123 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 124 | class BitmaskType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 125 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 126 | Type.__init__(self, name, json_data) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 127 | self.values = [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 128 | BitmaskValue(Name(m['name']), m['value'], m) |
| 129 | for m in self.json_data['values'] if is_enabled(m) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 130 | ] |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 131 | self.full_mask = 0 |
| 132 | for value in self.values: |
| 133 | self.full_mask = self.full_mask | value.value |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 134 | self.is_wire_transparent = True |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 135 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 136 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 137 | class FunctionPointerType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 138 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 139 | Type.__init__(self, name, json_data) |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 140 | self.return_type = None |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 141 | self.arguments = [] |
| 142 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 143 | |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 144 | class TypedefType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 145 | def __init__(self, is_enabled, name, json_data): |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 146 | Type.__init__(self, name, json_data) |
| 147 | self.type = None |
| 148 | |
| 149 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 150 | class NativeType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 151 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 152 | Type.__init__(self, name, json_data, native=True) |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 153 | self.is_wire_transparent = True |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 154 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 155 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 156 | # Methods and structures are both "records", so record members correspond to |
| 157 | # method arguments or structure members. |
| 158 | class RecordMember: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 159 | def __init__(self, |
| 160 | name, |
| 161 | typ, |
| 162 | annotation, |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 163 | json_data, |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 164 | optional=False, |
| 165 | is_return_value=False, |
| 166 | default_value=None, |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 167 | skip_serialize=False): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 168 | self.name = name |
| 169 | self.type = typ |
| 170 | self.annotation = annotation |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 171 | self.json_data = json_data |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 172 | self.length = None |
| 173 | self.optional = optional |
| 174 | self.is_return_value = is_return_value |
| 175 | self.handle_type = None |
Corentin Wallez | 8f93871 | 2019-07-08 19:20:22 +0000 | [diff] [blame] | 176 | self.default_value = default_value |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 177 | self.skip_serialize = skip_serialize |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 178 | |
| 179 | def set_handle_type(self, handle_type): |
| 180 | assert self.type.dict_name == "ObjectHandle" |
| 181 | self.handle_type = handle_type |
| 182 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 183 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 184 | Method = namedtuple('Method', |
| 185 | ['name', 'return_type', 'arguments', 'json_data']) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 186 | |
| 187 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 188 | class ObjectType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 189 | def __init__(self, is_enabled, name, json_data): |
| 190 | json_data_override = {'methods': []} |
| 191 | if 'methods' in json_data: |
| 192 | json_data_override['methods'] = [ |
| 193 | m for m in json_data['methods'] if is_enabled(m) |
| 194 | ] |
| 195 | Type.__init__(self, name, dict(json_data, **json_data_override)) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 196 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 197 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 198 | class Record: |
| 199 | def __init__(self, name): |
| 200 | self.name = Name(name) |
| 201 | self.members = [] |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 202 | self.may_have_dawn_object = False |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 203 | |
| 204 | def update_metadata(self): |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 205 | def may_have_dawn_object(member): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 206 | if isinstance(member.type, ObjectType): |
| 207 | return True |
| 208 | elif isinstance(member.type, StructureType): |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 209 | return member.type.may_have_dawn_object |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 210 | else: |
| 211 | return False |
| 212 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 213 | self.may_have_dawn_object = any( |
| 214 | may_have_dawn_object(member) for member in self.members) |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 215 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 216 | # Set may_have_dawn_object to true if the type is chained or |
| 217 | # extensible. Chained structs may contain a Dawn object. |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 218 | if isinstance(self, StructureType): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 219 | self.may_have_dawn_object = (self.may_have_dawn_object |
| 220 | or self.chained or self.extensible) |
| 221 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 222 | |
| 223 | class StructureType(Record, Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 224 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 225 | Record.__init__(self, name) |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 226 | json_data_override = {} |
| 227 | if 'members' in json_data: |
| 228 | json_data_override['members'] = [ |
| 229 | m for m in json_data['members'] if is_enabled(m) |
| 230 | ] |
| 231 | Type.__init__(self, name, dict(json_data, **json_data_override)) |
Austin Eng | 0c82405 | 2021-09-20 16:07:25 +0000 | [diff] [blame] | 232 | self.chained = json_data.get("chained", None) |
| 233 | self.extensible = json_data.get("extensible", None) |
| 234 | if self.chained: |
| 235 | assert (self.chained == "in" or self.chained == "out") |
| 236 | if self.extensible: |
| 237 | assert (self.extensible == "in" or self.extensible == "out") |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 238 | # Chained structs inherit from wgpu::ChainedStruct, which has |
| 239 | # nextInChain, so setting both extensible and chained would result in |
| 240 | # two nextInChain members. |
| 241 | assert not (self.extensible and self.chained) |
| 242 | |
Austin Eng | 0c82405 | 2021-09-20 16:07:25 +0000 | [diff] [blame] | 243 | @property |
| 244 | def output(self): |
| 245 | return self.chained == "out" or self.extensible == "out" |
| 246 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 247 | |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 248 | class ConstantDefinition(): |
| 249 | def __init__(self, is_enabled, name, json_data): |
| 250 | self.type = None |
| 251 | self.value = json_data['value'] |
| 252 | self.json_data = json_data |
| 253 | self.name = Name(name) |
| 254 | |
| 255 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 256 | class FunctionDeclaration(): |
| 257 | def __init__(self, is_enabled, name, json_data): |
| 258 | self.return_type = None |
| 259 | self.arguments = [] |
| 260 | self.json_data = json_data |
| 261 | self.name = Name(name) |
| 262 | |
| 263 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 264 | class Command(Record): |
| 265 | def __init__(self, name, members=None): |
| 266 | Record.__init__(self, name) |
| 267 | self.members = members or [] |
| 268 | self.derived_object = None |
| 269 | self.derived_method = None |
| 270 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 271 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 272 | def linked_record_members(json_data, types): |
| 273 | members = [] |
| 274 | members_by_name = {} |
| 275 | for m in json_data: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 276 | member = RecordMember(Name(m['name']), |
| 277 | types[m['type']], |
Corentin Wallez | 8f93871 | 2019-07-08 19:20:22 +0000 | [diff] [blame] | 278 | m.get('annotation', 'value'), |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 279 | m, |
Corentin Wallez | 8f93871 | 2019-07-08 19:20:22 +0000 | [diff] [blame] | 280 | optional=m.get('optional', False), |
| 281 | is_return_value=m.get('is_return_value', False), |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 282 | default_value=m.get('default', None), |
| 283 | skip_serialize=m.get('skip_serialize', False)) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 284 | handle_type = m.get('handle_type') |
| 285 | if handle_type: |
| 286 | member.set_handle_type(types[handle_type]) |
| 287 | members.append(member) |
| 288 | members_by_name[member.name.canonical_case()] = member |
| 289 | |
| 290 | for (member, m) in zip(members, json_data): |
| 291 | if member.annotation != 'value': |
| 292 | if not 'length' in m: |
| 293 | if member.type.category != 'object': |
| 294 | member.length = "constant" |
| 295 | member.constant_length = 1 |
| 296 | else: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 297 | assert False |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 298 | elif m['length'] == 'strlen': |
| 299 | member.length = 'strlen' |
| 300 | else: |
| 301 | member.length = members_by_name[m['length']] |
| 302 | |
| 303 | return members |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 304 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 305 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 306 | ############################################################ |
| 307 | # PARSE |
| 308 | ############################################################ |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 309 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 310 | |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 311 | def link_object(obj, types): |
| 312 | def make_method(json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 313 | arguments = linked_record_members(json_data.get('args', []), types) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 314 | return Method(Name(json_data['name']), |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 315 | types[json_data.get('returns', |
| 316 | 'void')], arguments, json_data) |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 317 | |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 318 | obj.methods = [make_method(m) for m in obj.json_data.get('methods', [])] |
Corentin Wallez | 9723168 | 2019-10-08 07:38:01 +0000 | [diff] [blame] | 319 | obj.methods.sort(key=lambda method: method.name.canonical_case()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 320 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 321 | |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 322 | def link_structure(struct, types): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 323 | struct.members = linked_record_members(struct.json_data['members'], types) |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 324 | |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 325 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 326 | def link_function_pointer(function_pointer, types): |
| 327 | link_function(function_pointer, types) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 328 | |
| 329 | |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 330 | def link_typedef(typedef, types): |
| 331 | typedef.type = types[typedef.json_data['type']] |
| 332 | |
| 333 | |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 334 | def link_constant(constant, types): |
| 335 | constant.type = types[constant.json_data['type']] |
| 336 | assert constant.type.name.native |
| 337 | |
| 338 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 339 | def link_function(function, types): |
| 340 | function.return_type = types[function.json_data.get('returns', 'void')] |
| 341 | function.arguments = linked_record_members(function.json_data['args'], |
| 342 | types) |
| 343 | |
| 344 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 345 | # Sort structures so that if struct A has struct B as a member, then B is |
| 346 | # listed before A. |
| 347 | # |
| 348 | # This is a form of topological sort where we try to keep the order reasonably |
| 349 | # similar to the original order (though the sort isn't technically stable). |
| 350 | # |
| 351 | # It works by computing for each struct type what is the depth of its DAG of |
Kai Ninomiya | 7d174a1 | 2021-09-21 17:36:27 +0000 | [diff] [blame] | 352 | # dependents, then re-sorting based on that depth using Python's stable sort. |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 353 | # This makes a toposort because if A depends on B then its depth will be bigger |
| 354 | # than B's. It is also nice because all nodes with the same depth are kept in |
| 355 | # the input order. |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 356 | def topo_sort_structure(structs): |
| 357 | for struct in structs: |
| 358 | struct.visited = False |
| 359 | struct.subdag_depth = 0 |
| 360 | |
| 361 | def compute_depth(struct): |
| 362 | if struct.visited: |
| 363 | return struct.subdag_depth |
| 364 | |
| 365 | max_dependent_depth = 0 |
| 366 | for member in struct.members: |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 367 | if member.type.category == 'structure': |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 368 | max_dependent_depth = max(max_dependent_depth, |
| 369 | compute_depth(member.type) + 1) |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 370 | |
| 371 | struct.subdag_depth = max_dependent_depth |
| 372 | struct.visited = True |
| 373 | return struct.subdag_depth |
| 374 | |
| 375 | for struct in structs: |
| 376 | compute_depth(struct) |
| 377 | |
| 378 | result = sorted(structs, key=lambda struct: struct.subdag_depth) |
| 379 | |
| 380 | for struct in structs: |
| 381 | del struct.visited |
| 382 | del struct.subdag_depth |
| 383 | |
| 384 | return result |
| 385 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 386 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 387 | def parse_json(json, enabled_tags): |
| 388 | is_enabled = lambda json_data: item_is_enabled(enabled_tags, json_data) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 389 | category_to_parser = { |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 390 | 'bitmask': BitmaskType, |
| 391 | 'enum': EnumType, |
| 392 | 'native': NativeType, |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 393 | 'function pointer': FunctionPointerType, |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 394 | 'object': ObjectType, |
| 395 | 'structure': StructureType, |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 396 | 'typedef': TypedefType, |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 397 | 'constant': ConstantDefinition, |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 398 | 'function': FunctionDeclaration |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | types = {} |
| 402 | |
| 403 | by_category = {} |
| 404 | for name in category_to_parser.keys(): |
| 405 | by_category[name] = [] |
| 406 | |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 407 | for (name, json_data) in json.items(): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 408 | if name[0] == '_' or not item_is_enabled(enabled_tags, json_data): |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 409 | continue |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 410 | category = json_data['category'] |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 411 | parsed = category_to_parser[category](is_enabled, name, json_data) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 412 | by_category[category].append(parsed) |
| 413 | types[name] = parsed |
| 414 | |
| 415 | for obj in by_category['object']: |
| 416 | link_object(obj, types) |
| 417 | |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 418 | for struct in by_category['structure']: |
| 419 | link_structure(struct, types) |
| 420 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 421 | for function_pointer in by_category['function pointer']: |
| 422 | link_function_pointer(function_pointer, types) |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 423 | |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 424 | for typedef in by_category['typedef']: |
| 425 | link_typedef(typedef, types) |
| 426 | |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 427 | for constant in by_category['constant']: |
| 428 | link_constant(constant, types) |
| 429 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 430 | for function in by_category['function']: |
| 431 | link_function(function, types) |
| 432 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 433 | for category in by_category.keys(): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 434 | by_category[category] = sorted( |
| 435 | by_category[category], key=lambda typ: typ.name.canonical_case()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 436 | |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 437 | by_category['structure'] = topo_sort_structure(by_category['structure']) |
| 438 | |
Austin Eng | c7f416c | 2019-01-15 20:49:53 +0000 | [diff] [blame] | 439 | for struct in by_category['structure']: |
| 440 | struct.update_metadata() |
| 441 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 442 | api_params = { |
| 443 | 'types': types, |
| 444 | 'by_category': by_category, |
| 445 | 'enabled_tags': enabled_tags, |
| 446 | } |
| 447 | return { |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 448 | 'metadata': Metadata(json['_metadata']), |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 449 | 'types': types, |
| 450 | 'by_category': by_category, |
| 451 | 'enabled_tags': enabled_tags, |
| 452 | 'c_methods': lambda typ: c_methods(api_params, typ), |
| 453 | 'c_methods_sorted_by_name': get_c_methods_sorted_by_name(api_params), |
| 454 | } |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 455 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 456 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 457 | ############################################################ |
| 458 | # WIRE STUFF |
| 459 | ############################################################ |
| 460 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 461 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 462 | # Create wire commands from api methods |
| 463 | def compute_wire_params(api_params, wire_json): |
| 464 | wire_params = api_params.copy() |
| 465 | types = wire_params['types'] |
| 466 | |
| 467 | commands = [] |
| 468 | return_commands = [] |
| 469 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 470 | wire_json['special items']['client_handwritten_commands'] += wire_json[ |
| 471 | 'special items']['client_side_commands'] |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 472 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 473 | # Generate commands from object methods |
| 474 | for api_object in wire_params['by_category']['object']: |
| 475 | for method in api_object.methods: |
| 476 | command_name = concat_names(api_object.name, method.name) |
| 477 | command_suffix = Name(command_name).CamelCase() |
| 478 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 479 | # Only object return values or void are supported. |
| 480 | # Other methods must be handwritten. |
| 481 | is_object = method.return_type.category == 'object' |
| 482 | is_void = method.return_type.name.canonical_case() == 'void' |
| 483 | if not (is_object or is_void): |
| 484 | assert command_suffix in ( |
| 485 | wire_json['special items']['client_handwritten_commands']) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 486 | continue |
| 487 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 488 | if command_suffix in ( |
| 489 | wire_json['special items']['client_side_commands']): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 490 | continue |
| 491 | |
| 492 | # Create object method commands by prepending "self" |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 493 | members = [ |
| 494 | RecordMember(Name('self'), types[api_object.dict_name], |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 495 | 'value', {}) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 496 | ] |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 497 | members += method.arguments |
| 498 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 499 | # Client->Server commands that return an object return the |
| 500 | # result object handle |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 501 | if method.return_type.category == 'object': |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 502 | result = RecordMember(Name('result'), |
| 503 | types['ObjectHandle'], |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 504 | 'value', {}, |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 505 | is_return_value=True) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 506 | result.set_handle_type(method.return_type) |
| 507 | members.append(result) |
| 508 | |
| 509 | command = Command(command_name, members) |
| 510 | command.derived_object = api_object |
| 511 | command.derived_method = method |
| 512 | commands.append(command) |
| 513 | |
| 514 | for (name, json_data) in wire_json['commands'].items(): |
| 515 | commands.append(Command(name, linked_record_members(json_data, types))) |
| 516 | |
| 517 | for (name, json_data) in wire_json['return commands'].items(): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 518 | return_commands.append( |
| 519 | Command(name, linked_record_members(json_data, types))) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 520 | |
| 521 | wire_params['cmd_records'] = { |
| 522 | 'command': commands, |
| 523 | 'return command': return_commands |
| 524 | } |
| 525 | |
| 526 | for commands in wire_params['cmd_records'].values(): |
| 527 | for command in commands: |
| 528 | command.update_metadata() |
| 529 | commands.sort(key=lambda c: c.name.canonical_case()) |
| 530 | |
| 531 | wire_params.update(wire_json.get('special items', {})) |
| 532 | |
| 533 | return wire_params |
| 534 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 535 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 536 | ############################################################# |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 537 | # Generator |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 538 | ############################################################# |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 539 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 540 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 541 | def as_varName(*names): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 542 | return names[0].camelCase() + ''.join( |
| 543 | [name.CamelCase() for name in names[1:]]) |
| 544 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 545 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 546 | def as_cType(c_prefix, name): |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 547 | if name.native: |
| 548 | return name.concatcase() |
| 549 | else: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 550 | return c_prefix + name.CamelCase() |
Corentin Wallez | 919812e | 2019-10-17 08:46:07 +0000 | [diff] [blame] | 551 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 552 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 553 | def as_cppType(name): |
| 554 | if name.native: |
| 555 | return name.concatcase() |
| 556 | else: |
| 557 | return name.CamelCase() |
| 558 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 559 | |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 560 | def as_jsEnumValue(value): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 561 | if 'jsrepr' in value.json_data: return value.json_data['jsrepr'] |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 562 | return "'" + value.name.js_enum_case() + "'" |
| 563 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 564 | |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 565 | def convert_cType_to_cppType(typ, annotation, arg, indent=0): |
| 566 | if typ.category == 'native': |
| 567 | return arg |
| 568 | if annotation == 'value': |
| 569 | if typ.category == 'object': |
| 570 | return '{}::Acquire({})'.format(as_cppType(typ.name), arg) |
| 571 | elif typ.category == 'structure': |
| 572 | converted_members = [ |
| 573 | convert_cType_to_cppType( |
| 574 | member.type, member.annotation, |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 575 | '{}.{}'.format(arg, as_varName(member.name)), indent + 1) |
| 576 | for member in typ.members |
| 577 | ] |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 578 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 579 | converted_members = [(' ' * 4) + m for m in converted_members] |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 580 | converted_members = ',\n'.join(converted_members) |
| 581 | |
| 582 | return as_cppType(typ.name) + ' {\n' + converted_members + '\n}' |
| 583 | else: |
| 584 | return 'static_cast<{}>({})'.format(as_cppType(typ.name), arg) |
| 585 | else: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 586 | return 'reinterpret_cast<{} {}>({})'.format(as_cppType(typ.name), |
| 587 | annotation, arg) |
| 588 | |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 589 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 590 | def decorate(name, typ, arg): |
| 591 | if arg.annotation == 'value': |
| 592 | return typ + ' ' + name |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 593 | elif arg.annotation == '*': |
| 594 | return typ + ' * ' + name |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 595 | elif arg.annotation == 'const*': |
| 596 | return typ + ' const * ' + name |
| 597 | else: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 598 | assert False |
| 599 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 600 | |
| 601 | def annotated(typ, arg): |
| 602 | name = as_varName(arg.name) |
| 603 | return decorate(name, typ, arg) |
| 604 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 605 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 606 | def item_is_enabled(enabled_tags, json_data): |
| 607 | tags = json_data.get('tags') |
| 608 | if tags is None: return True |
| 609 | return any(tag in enabled_tags for tag in tags) |
| 610 | |
| 611 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 612 | def as_cppEnum(value_name): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 613 | assert not value_name.native |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 614 | if value_name.concatcase()[0].isdigit(): |
| 615 | return "e" + value_name.CamelCase() |
| 616 | return value_name.CamelCase() |
| 617 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 618 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 619 | def as_MethodSuffix(type_name, method_name): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 620 | assert not type_name.native and not method_name.native |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 621 | return type_name.CamelCase() + method_name.CamelCase() |
| 622 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 623 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 624 | def as_frontendType(metadata, typ): |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 625 | if typ.category == 'object': |
Corentin Wallez | 4f5fc2d | 2019-04-01 21:48:38 +0000 | [diff] [blame] | 626 | return typ.name.CamelCase() + 'Base*' |
Corentin Wallez | fe253f1 | 2018-08-01 15:12:10 +0200 | [diff] [blame] | 627 | elif typ.category in ['bitmask', 'enum']: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 628 | return metadata.namespace + '::' + typ.name.CamelCase() |
Corentin Wallez | fe253f1 | 2018-08-01 15:12:10 +0200 | [diff] [blame] | 629 | elif typ.category == 'structure': |
| 630 | return as_cppType(typ.name) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 631 | else: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 632 | return as_cType(metadata.c_prefix, typ.name) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 633 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 634 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 635 | def as_wireType(metadata, typ): |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 636 | if typ.category == 'object': |
| 637 | return typ.name.CamelCase() + '*' |
Brandon Jones | 6f2bbe9 | 2021-04-05 23:34:17 +0000 | [diff] [blame] | 638 | elif typ.category in ['bitmask', 'enum', 'structure']: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 639 | return metadata.c_prefix + typ.name.CamelCase() |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 640 | else: |
| 641 | return as_cppType(typ.name) |
| 642 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 643 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 644 | def c_methods(params, typ): |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 645 | return typ.methods + [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 646 | x for x in [ |
| 647 | Method(Name('reference'), params['types']['void'], [], |
| 648 | {'tags': ['dawn', 'emscripten']}), |
| 649 | Method(Name('release'), params['types']['void'], [], |
| 650 | {'tags': ['dawn', 'emscripten']}), |
| 651 | ] if item_is_enabled(params['enabled_tags'], x.json_data) |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 652 | ] |
| 653 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 654 | |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 655 | def get_c_methods_sorted_by_name(api_params): |
Corentin Wallez | c57b180 | 2019-10-15 12:08:48 +0000 | [diff] [blame] | 656 | unsorted = [(as_MethodSuffix(typ.name, method.name), typ, method) \ |
| 657 | for typ in api_params['by_category']['object'] \ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 658 | for method in c_methods(api_params, typ) ] |
Corentin Wallez | c57b180 | 2019-10-15 12:08:48 +0000 | [diff] [blame] | 659 | return [(typ, method) for (_, typ, method) in sorted(unsorted)] |
| 660 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 661 | |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 662 | def has_callback_arguments(method): |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 663 | return any(arg.type.category == 'function pointer' for arg in method.arguments) |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 664 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 665 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 666 | def make_base_render_params(metadata): |
| 667 | c_prefix = metadata.c_prefix |
| 668 | |
| 669 | def as_cTypeEnumSpecialCase(typ): |
| 670 | if typ.category == 'bitmask': |
| 671 | return as_cType(c_prefix, typ.name) + 'Flags' |
| 672 | return as_cType(c_prefix, typ.name) |
| 673 | |
| 674 | def as_cEnum(type_name, value_name): |
| 675 | assert not type_name.native and not value_name.native |
| 676 | return c_prefix + type_name.CamelCase() + '_' + value_name.CamelCase() |
| 677 | |
| 678 | def as_cMethod(type_name, method_name): |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 679 | c_method = c_prefix.lower() |
| 680 | if type_name != None: |
| 681 | assert not type_name.native |
| 682 | c_method += type_name.CamelCase() |
| 683 | assert not method_name.native |
| 684 | c_method += method_name.CamelCase() |
| 685 | return c_method |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 686 | |
| 687 | def as_cProc(type_name, method_name): |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 688 | c_proc = c_prefix + 'Proc' |
| 689 | if type_name != None: |
| 690 | assert not type_name.native |
| 691 | c_proc += type_name.CamelCase() |
| 692 | assert not method_name.native |
| 693 | c_proc += method_name.CamelCase() |
| 694 | return c_proc |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 695 | |
| 696 | return { |
| 697 | 'Name': lambda name: Name(name), |
| 698 | 'as_annotated_cType': \ |
| 699 | lambda arg: annotated(as_cTypeEnumSpecialCase(arg.type), arg), |
| 700 | 'as_annotated_cppType': \ |
| 701 | lambda arg: annotated(as_cppType(arg.type.name), arg), |
| 702 | 'as_cEnum': as_cEnum, |
| 703 | 'as_cppEnum': as_cppEnum, |
| 704 | 'as_cMethod': as_cMethod, |
| 705 | 'as_MethodSuffix': as_MethodSuffix, |
| 706 | 'as_cProc': as_cProc, |
| 707 | 'as_cType': lambda name: as_cType(c_prefix, name), |
| 708 | 'as_cppType': as_cppType, |
| 709 | 'as_jsEnumValue': as_jsEnumValue, |
| 710 | 'convert_cType_to_cppType': convert_cType_to_cppType, |
| 711 | 'as_varName': as_varName, |
| 712 | 'decorate': decorate |
| 713 | } |
| 714 | |
| 715 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 716 | class MultiGeneratorFromDawnJSON(Generator): |
| 717 | def get_description(self): |
| 718 | return 'Generates code for various target from Dawn.json.' |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 719 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 720 | def add_commandline_arguments(self, parser): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 721 | allowed_targets = [ |
| 722 | 'dawn_headers', 'dawncpp_headers', 'dawncpp', 'dawn_proc', |
| 723 | 'mock_webgpu', 'dawn_wire', "dawn_native_utils" |
| 724 | ] |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 725 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 726 | parser.add_argument('--dawn-json', |
| 727 | required=True, |
| 728 | type=str, |
| 729 | help='The DAWN JSON definition to use.') |
| 730 | parser.add_argument('--wire-json', |
| 731 | default=None, |
| 732 | type=str, |
| 733 | help='The DAWN WIRE JSON definition to use.') |
| 734 | parser.add_argument( |
| 735 | '--targets', |
| 736 | required=True, |
| 737 | type=str, |
| 738 | help= |
| 739 | 'Comma-separated subset of targets to output. Available targets: ' |
| 740 | + ', '.join(allowed_targets)) |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 741 | def get_file_renders(self, args): |
| 742 | with open(args.dawn_json) as f: |
| 743 | loaded_json = json.loads(f.read()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 744 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 745 | targets = args.targets.split(',') |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 746 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 747 | wire_json = None |
| 748 | if args.wire_json: |
| 749 | with open(args.wire_json) as f: |
| 750 | wire_json = json.loads(f.read()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 751 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 752 | renders = [] |
| 753 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 754 | params_dawn = parse_json(loaded_json, |
| 755 | enabled_tags=['dawn', 'native', 'deprecated']) |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 756 | metadata = params_dawn['metadata'] |
| 757 | RENDER_PARAMS_BASE = make_base_render_params(metadata) |
Corentin Wallez | 79a62bf | 2017-05-24 16:04:55 +0200 | [diff] [blame] | 758 | |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 759 | api = metadata.api.lower() |
fujunwei | a840574 | 2021-12-10 01:35:19 +0000 | [diff] [blame] | 760 | prefix = metadata.proc_table_prefix.lower() |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 761 | if 'dawn_headers' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 762 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 763 | FileRender('api.h', 'src/include/dawn/' + api + '.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 764 | [RENDER_PARAMS_BASE, params_dawn])) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 765 | renders.append( |
| 766 | FileRender('dawn_proc_table.h', |
fujunwei | 3a46476 | 2021-12-05 05:29:44 +0000 | [diff] [blame] | 767 | 'src/include/dawn/' + prefix + '_proc_table.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 768 | [RENDER_PARAMS_BASE, params_dawn])) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 769 | |
Austin Eng | cc071e4 | 2019-10-16 10:26:01 +0000 | [diff] [blame] | 770 | if 'dawncpp_headers' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 771 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 772 | FileRender('api_cpp.h', 'src/include/dawn/' + api + '_cpp.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 773 | [RENDER_PARAMS_BASE, params_dawn])) |
Austin Eng | cc071e4 | 2019-10-16 10:26:01 +0000 | [diff] [blame] | 774 | |
Austin Eng | a9e39e1 | 2021-06-01 18:49:12 +0000 | [diff] [blame] | 775 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 776 | FileRender('api_cpp_print.h', |
| 777 | 'src/include/dawn/' + api + '_cpp_print.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 778 | [RENDER_PARAMS_BASE, params_dawn])) |
Austin Eng | a9e39e1 | 2021-06-01 18:49:12 +0000 | [diff] [blame] | 779 | |
Corentin Wallez | 9649682 | 2019-10-15 11:44:38 +0000 | [diff] [blame] | 780 | if 'dawn_proc' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 781 | renders.append( |
fujunwei | a840574 | 2021-12-10 01:35:19 +0000 | [diff] [blame] | 782 | FileRender('dawn_proc.c', 'src/dawn/' + prefix + '_proc.c', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 783 | [RENDER_PARAMS_BASE, params_dawn])) |
Austin Eng | 16e01af | 2020-10-06 16:13:42 +0000 | [diff] [blame] | 784 | renders.append( |
| 785 | FileRender('dawn_thread_dispatch_proc.cpp', |
fujunwei | a840574 | 2021-12-10 01:35:19 +0000 | [diff] [blame] | 786 | 'src/dawn/' + prefix + '_thread_dispatch_proc.cpp', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 787 | [RENDER_PARAMS_BASE, params_dawn])) |
Corentin Wallez | 9649682 | 2019-10-15 11:44:38 +0000 | [diff] [blame] | 788 | |
Austin Eng | 63f6546 | 2021-12-09 20:03:48 +0000 | [diff] [blame] | 789 | if 'webgpu_dawn_native_proc' in targets: |
| 790 | renders.append( |
| 791 | FileRender('dawn_native/api_dawn_native_proc.cpp', |
| 792 | 'src/dawn_native/webgpu_dawn_native_proc.cpp', |
| 793 | [RENDER_PARAMS_BASE, params_dawn])) |
| 794 | |
Corentin Wallez | 9649682 | 2019-10-15 11:44:38 +0000 | [diff] [blame] | 795 | if 'dawncpp' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 796 | renders.append( |
| 797 | FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 798 | [RENDER_PARAMS_BASE, params_dawn])) |
| 799 | |
| 800 | if 'webgpu_headers' in targets: |
| 801 | params_upstream = parse_json(loaded_json, |
| 802 | enabled_tags=['upstream', 'native']) |
| 803 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 804 | FileRender('api.h', 'webgpu-headers/' + api + '.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 805 | [RENDER_PARAMS_BASE, params_upstream])) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 806 | |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 807 | if 'emscripten_bits' in targets: |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 808 | params_emscripten = parse_json( |
| 809 | loaded_json, enabled_tags=['upstream', 'emscripten']) |
| 810 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 811 | FileRender('api.h', 'emscripten-bits/' + api + '.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 812 | [RENDER_PARAMS_BASE, params_emscripten])) |
| 813 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 814 | FileRender('api_cpp.h', 'emscripten-bits/' + api + '_cpp.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 815 | [RENDER_PARAMS_BASE, params_emscripten])) |
| 816 | renders.append( |
| 817 | FileRender('webgpu_cpp.cpp', 'emscripten-bits/webgpu_cpp.cpp', |
| 818 | [RENDER_PARAMS_BASE, params_emscripten])) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 819 | renders.append( |
| 820 | FileRender('webgpu_struct_info.json', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 821 | 'emscripten-bits/webgpu_struct_info.json', |
| 822 | [RENDER_PARAMS_BASE, params_emscripten])) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 823 | renders.append( |
| 824 | FileRender('library_webgpu_enum_tables.js', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 825 | 'emscripten-bits/library_webgpu_enum_tables.js', |
| 826 | [RENDER_PARAMS_BASE, params_emscripten])) |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 827 | |
Corentin Wallez | 45b51f5 | 2019-10-28 22:15:47 +0000 | [diff] [blame] | 828 | if 'mock_webgpu' in targets: |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 829 | mock_params = [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 830 | RENDER_PARAMS_BASE, params_dawn, { |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 831 | 'has_callback_arguments': has_callback_arguments |
| 832 | } |
| 833 | ] |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 834 | renders.append( |
| 835 | FileRender('mock_webgpu.h', 'src/dawn/mock_webgpu.h', |
| 836 | mock_params)) |
| 837 | renders.append( |
| 838 | FileRender('mock_webgpu.cpp', 'src/dawn/mock_webgpu.cpp', |
| 839 | mock_params)) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 840 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 841 | if 'dawn_native_utils' in targets: |
| 842 | frontend_params = [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 843 | RENDER_PARAMS_BASE, |
| 844 | params_dawn, |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 845 | { |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 846 | # TODO: as_frontendType and co. take a Type, not a Name :( |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 847 | 'as_frontendType': lambda typ: as_frontendType(metadata, typ), |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 848 | 'as_annotated_frontendType': \ |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 849 | lambda arg: annotated(as_frontendType(metadata, arg.type), arg), |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 850 | } |
| 851 | ] |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 852 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 853 | renders.append( |
| 854 | FileRender('dawn_native/ValidationUtils.h', |
| 855 | 'src/dawn_native/ValidationUtils_autogen.h', |
| 856 | frontend_params)) |
| 857 | renders.append( |
| 858 | FileRender('dawn_native/ValidationUtils.cpp', |
| 859 | 'src/dawn_native/ValidationUtils_autogen.cpp', |
| 860 | frontend_params)) |
| 861 | renders.append( |
Austin Eng | 3faa478 | 2021-10-27 19:07:37 +0000 | [diff] [blame] | 862 | FileRender('dawn_native/dawn_platform.h', |
| 863 | 'src/dawn_native/dawn_platform_autogen.h', |
| 864 | frontend_params)) |
| 865 | renders.append( |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 866 | FileRender('dawn_native/wgpu_structs.h', |
| 867 | 'src/dawn_native/wgpu_structs_autogen.h', |
| 868 | frontend_params)) |
| 869 | renders.append( |
| 870 | FileRender('dawn_native/wgpu_structs.cpp', |
| 871 | 'src/dawn_native/wgpu_structs_autogen.cpp', |
| 872 | frontend_params)) |
| 873 | renders.append( |
| 874 | FileRender('dawn_native/ProcTable.cpp', |
| 875 | 'src/dawn_native/ProcTable.cpp', frontend_params)) |
Brian Ho | 5346e77 | 2021-04-22 17:49:42 +0000 | [diff] [blame] | 876 | renders.append( |
| 877 | FileRender('dawn_native/ChainUtils.h', |
| 878 | 'src/dawn_native/ChainUtils_autogen.h', |
| 879 | frontend_params)) |
| 880 | renders.append( |
| 881 | FileRender('dawn_native/ChainUtils.cpp', |
| 882 | 'src/dawn_native/ChainUtils_autogen.cpp', |
| 883 | frontend_params)) |
Brandon Jones | ba66295 | 2021-09-23 21:26:33 +0000 | [diff] [blame] | 884 | renders.append( |
| 885 | FileRender('dawn_native/webgpu_absl_format.h', |
| 886 | 'src/dawn_native/webgpu_absl_format_autogen.h', |
| 887 | frontend_params)) |
| 888 | renders.append( |
| 889 | FileRender('dawn_native/webgpu_absl_format.cpp', |
| 890 | 'src/dawn_native/webgpu_absl_format_autogen.cpp', |
| 891 | frontend_params)) |
Loko Kung | 8d195d5 | 2021-09-28 15:40:01 +0000 | [diff] [blame] | 892 | renders.append( |
| 893 | FileRender('dawn_native/ObjectType.h', |
| 894 | 'src/dawn_native/ObjectType_autogen.h', |
| 895 | frontend_params)) |
| 896 | renders.append( |
| 897 | FileRender('dawn_native/ObjectType.cpp', |
| 898 | 'src/dawn_native/ObjectType_autogen.cpp', |
| 899 | frontend_params)) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 900 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 901 | if 'dawn_wire' in targets: |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 902 | additional_params = compute_wire_params(params_dawn, wire_json) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 903 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 904 | wire_params = [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 905 | RENDER_PARAMS_BASE, params_dawn, { |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 906 | 'as_wireType': lambda type : as_wireType(metadata, type), |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 907 | 'as_annotated_wireType': \ |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 908 | lambda arg: annotated(as_wireType(metadata, arg.type), arg), |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 909 | }, additional_params |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 910 | ] |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 911 | renders.append( |
Austin Eng | 3120d5e | 2020-11-11 19:46:18 +0000 | [diff] [blame] | 912 | FileRender('dawn_wire/ObjectType.h', |
| 913 | 'src/dawn_wire/ObjectType_autogen.h', wire_params)) |
| 914 | renders.append( |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 915 | FileRender('dawn_wire/WireCmd.h', |
| 916 | 'src/dawn_wire/WireCmd_autogen.h', wire_params)) |
| 917 | renders.append( |
| 918 | FileRender('dawn_wire/WireCmd.cpp', |
| 919 | 'src/dawn_wire/WireCmd_autogen.cpp', wire_params)) |
| 920 | renders.append( |
| 921 | FileRender('dawn_wire/client/ApiObjects.h', |
| 922 | 'src/dawn_wire/client/ApiObjects_autogen.h', |
| 923 | wire_params)) |
| 924 | renders.append( |
| 925 | FileRender('dawn_wire/client/ApiProcs.cpp', |
| 926 | 'src/dawn_wire/client/ApiProcs_autogen.cpp', |
| 927 | wire_params)) |
| 928 | renders.append( |
| 929 | FileRender('dawn_wire/client/ClientBase.h', |
| 930 | 'src/dawn_wire/client/ClientBase_autogen.h', |
| 931 | wire_params)) |
| 932 | renders.append( |
| 933 | FileRender('dawn_wire/client/ClientHandlers.cpp', |
| 934 | 'src/dawn_wire/client/ClientHandlers_autogen.cpp', |
| 935 | wire_params)) |
| 936 | renders.append( |
| 937 | FileRender( |
| 938 | 'dawn_wire/client/ClientPrototypes.inc', |
| 939 | 'src/dawn_wire/client/ClientPrototypes_autogen.inc', |
| 940 | wire_params)) |
| 941 | renders.append( |
| 942 | FileRender('dawn_wire/server/ServerBase.h', |
| 943 | 'src/dawn_wire/server/ServerBase_autogen.h', |
| 944 | wire_params)) |
| 945 | renders.append( |
| 946 | FileRender('dawn_wire/server/ServerDoers.cpp', |
| 947 | 'src/dawn_wire/server/ServerDoers_autogen.cpp', |
| 948 | wire_params)) |
| 949 | renders.append( |
| 950 | FileRender('dawn_wire/server/ServerHandlers.cpp', |
| 951 | 'src/dawn_wire/server/ServerHandlers_autogen.cpp', |
| 952 | wire_params)) |
| 953 | renders.append( |
| 954 | FileRender( |
| 955 | 'dawn_wire/server/ServerPrototypes.inc', |
| 956 | 'src/dawn_wire/server/ServerPrototypes_autogen.inc', |
| 957 | wire_params)) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 958 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 959 | return renders |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 960 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 961 | def get_dependencies(self, args): |
| 962 | deps = [os.path.abspath(args.dawn_json)] |
| 963 | if args.wire_json != None: |
| 964 | deps += [os.path.abspath(args.wire_json)] |
| 965 | return deps |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 966 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 967 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 968 | if __name__ == '__main__': |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 969 | sys.exit(run_generator(MultiGeneratorFromDawnJSON())) |