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 | a2241d4 | 2021-12-16 04:54:38 +0000 | [diff] [blame] | 32 | self.impl_dir = metadata.get('impl_dir', '') |
| 33 | self.native_namespace = metadata['native_namespace'] |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 34 | self.copyright_year = metadata.get('copyright_year', None) |
| 35 | |
| 36 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 37 | class Name: |
| 38 | def __init__(self, name, native=False): |
| 39 | self.native = native |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 40 | self.name = name |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 41 | if native: |
| 42 | self.chunks = [name] |
| 43 | else: |
| 44 | self.chunks = name.split(' ') |
| 45 | |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 46 | def get(self): |
| 47 | return self.name |
| 48 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 49 | def CamelChunk(self, chunk): |
| 50 | return chunk[0].upper() + chunk[1:] |
| 51 | |
| 52 | def canonical_case(self): |
| 53 | return (' '.join(self.chunks)).lower() |
| 54 | |
| 55 | def concatcase(self): |
| 56 | return ''.join(self.chunks) |
| 57 | |
| 58 | def camelCase(self): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 59 | return self.chunks[0] + ''.join( |
| 60 | [self.CamelChunk(chunk) for chunk in self.chunks[1:]]) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 61 | |
| 62 | def CamelCase(self): |
| 63 | return ''.join([self.CamelChunk(chunk) for chunk in self.chunks]) |
| 64 | |
| 65 | def SNAKE_CASE(self): |
| 66 | return '_'.join([chunk.upper() for chunk in self.chunks]) |
| 67 | |
| 68 | def snake_case(self): |
| 69 | return '_'.join(self.chunks) |
| 70 | |
Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame] | 71 | def namespace_case(self): |
| 72 | return '::'.join(self.chunks) |
| 73 | |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 74 | def Dirs(self): |
| 75 | return '/'.join(self.chunks) |
| 76 | |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 77 | def js_enum_case(self): |
| 78 | result = self.chunks[0].lower() |
| 79 | for chunk in self.chunks[1:]: |
| 80 | if not result[-1].isdigit(): |
| 81 | result += '-' |
| 82 | result += chunk.lower() |
| 83 | return result |
| 84 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 85 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 86 | def concat_names(*names): |
| 87 | return ' '.join([name.canonical_case() for name in names]) |
| 88 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 89 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 90 | class Type: |
| 91 | def __init__(self, name, json_data, native=False): |
| 92 | self.json_data = json_data |
| 93 | self.dict_name = name |
| 94 | self.name = Name(name, native=native) |
| 95 | self.category = json_data['category'] |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 96 | self.is_wire_transparent = False |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 97 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 98 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 99 | EnumValue = namedtuple('EnumValue', ['name', 'value', 'valid', 'json_data']) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 100 | |
| 101 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 102 | class EnumType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 103 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 104 | Type.__init__(self, name, json_data) |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 105 | |
| 106 | self.values = [] |
| 107 | self.contiguousFromZero = True |
| 108 | lastValue = -1 |
| 109 | for m in self.json_data['values']: |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 110 | if not is_enabled(m): |
| 111 | continue |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 112 | value = m['value'] |
| 113 | if value != lastValue + 1: |
| 114 | self.contiguousFromZero = False |
| 115 | lastValue = value |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 116 | self.values.append( |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 117 | EnumValue(Name(m['name']), value, m.get('valid', True), m)) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 118 | |
Corentin Wallez | 7ac0815 | 2019-06-26 19:54:43 +0000 | [diff] [blame] | 119 | # Assert that all values are unique in enums |
| 120 | all_values = set() |
| 121 | for value in self.values: |
| 122 | if value.value in all_values: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 123 | raise Exception("Duplicate value {} in enum {}".format( |
| 124 | value.value, name)) |
Corentin Wallez | 7ac0815 | 2019-06-26 19:54:43 +0000 | [diff] [blame] | 125 | all_values.add(value.value) |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 126 | self.is_wire_transparent = True |
Corentin Wallez | 7ac0815 | 2019-06-26 19:54:43 +0000 | [diff] [blame] | 127 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 128 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 129 | BitmaskValue = namedtuple('BitmaskValue', ['name', 'value', 'json_data']) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 130 | |
| 131 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 132 | class BitmaskType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 133 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 134 | Type.__init__(self, name, json_data) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 135 | self.values = [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 136 | BitmaskValue(Name(m['name']), m['value'], m) |
| 137 | for m in self.json_data['values'] if is_enabled(m) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 138 | ] |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 139 | self.full_mask = 0 |
| 140 | for value in self.values: |
| 141 | self.full_mask = self.full_mask | value.value |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 142 | self.is_wire_transparent = True |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 143 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 144 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 145 | class FunctionPointerType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 146 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 147 | Type.__init__(self, name, json_data) |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 148 | self.return_type = None |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 149 | self.arguments = [] |
| 150 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 151 | |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 152 | class TypedefType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 153 | def __init__(self, is_enabled, name, json_data): |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 154 | Type.__init__(self, name, json_data) |
| 155 | self.type = None |
| 156 | |
| 157 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 158 | class NativeType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 159 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 160 | Type.__init__(self, name, json_data, native=True) |
Jiawei Shao | 6d6b63c | 2021-12-02 07:29:41 +0000 | [diff] [blame] | 161 | self.is_wire_transparent = True |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 162 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 163 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 164 | # Methods and structures are both "records", so record members correspond to |
| 165 | # method arguments or structure members. |
| 166 | class RecordMember: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 167 | def __init__(self, |
| 168 | name, |
| 169 | typ, |
| 170 | annotation, |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 171 | json_data, |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 172 | optional=False, |
| 173 | is_return_value=False, |
| 174 | default_value=None, |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 175 | skip_serialize=False): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 176 | self.name = name |
| 177 | self.type = typ |
| 178 | self.annotation = annotation |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 179 | self.json_data = json_data |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 180 | self.length = None |
| 181 | self.optional = optional |
| 182 | self.is_return_value = is_return_value |
| 183 | self.handle_type = None |
Corentin Wallez | 8f93871 | 2019-07-08 19:20:22 +0000 | [diff] [blame] | 184 | self.default_value = default_value |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 185 | self.skip_serialize = skip_serialize |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 186 | |
| 187 | def set_handle_type(self, handle_type): |
| 188 | assert self.type.dict_name == "ObjectHandle" |
| 189 | self.handle_type = handle_type |
| 190 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 191 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 192 | Method = namedtuple('Method', |
| 193 | ['name', 'return_type', 'arguments', 'json_data']) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 194 | |
| 195 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 196 | class ObjectType(Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 197 | def __init__(self, is_enabled, name, json_data): |
| 198 | json_data_override = {'methods': []} |
| 199 | if 'methods' in json_data: |
| 200 | json_data_override['methods'] = [ |
| 201 | m for m in json_data['methods'] if is_enabled(m) |
| 202 | ] |
| 203 | Type.__init__(self, name, dict(json_data, **json_data_override)) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 204 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 205 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 206 | class Record: |
| 207 | def __init__(self, name): |
| 208 | self.name = Name(name) |
| 209 | self.members = [] |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 210 | self.may_have_dawn_object = False |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 211 | |
| 212 | def update_metadata(self): |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 213 | def may_have_dawn_object(member): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 214 | if isinstance(member.type, ObjectType): |
| 215 | return True |
| 216 | elif isinstance(member.type, StructureType): |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 217 | return member.type.may_have_dawn_object |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 218 | else: |
| 219 | return False |
| 220 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 221 | self.may_have_dawn_object = any( |
| 222 | may_have_dawn_object(member) for member in self.members) |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 223 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 224 | # Set may_have_dawn_object to true if the type is chained or |
| 225 | # extensible. Chained structs may contain a Dawn object. |
Austin Eng | 76a8d0b | 2020-04-03 17:37:48 +0000 | [diff] [blame] | 226 | if isinstance(self, StructureType): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 227 | self.may_have_dawn_object = (self.may_have_dawn_object |
| 228 | or self.chained or self.extensible) |
| 229 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 230 | |
| 231 | class StructureType(Record, Type): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 232 | def __init__(self, is_enabled, name, json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 233 | Record.__init__(self, name) |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 234 | json_data_override = {} |
| 235 | if 'members' in json_data: |
| 236 | json_data_override['members'] = [ |
| 237 | m for m in json_data['members'] if is_enabled(m) |
| 238 | ] |
| 239 | Type.__init__(self, name, dict(json_data, **json_data_override)) |
Corentin Wallez | a45561b | 2022-07-14 12:58:25 +0000 | [diff] [blame] | 240 | self.chained = json_data.get('chained', None) |
| 241 | self.extensible = json_data.get('extensible', None) |
Austin Eng | 0c82405 | 2021-09-20 16:07:25 +0000 | [diff] [blame] | 242 | if self.chained: |
Corentin Wallez | a45561b | 2022-07-14 12:58:25 +0000 | [diff] [blame] | 243 | assert self.chained == 'in' or self.chained == 'out' |
| 244 | assert 'chain roots' in json_data |
Austin Eng | 0c82405 | 2021-09-20 16:07:25 +0000 | [diff] [blame] | 245 | if self.extensible: |
Corentin Wallez | a45561b | 2022-07-14 12:58:25 +0000 | [diff] [blame] | 246 | assert self.extensible == 'in' or self.extensible == 'out' |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 247 | # Chained structs inherit from wgpu::ChainedStruct, which has |
| 248 | # nextInChain, so setting both extensible and chained would result in |
| 249 | # two nextInChain members. |
| 250 | assert not (self.extensible and self.chained) |
| 251 | |
Jiawei Shao | 1fa386c | 2021-12-21 04:04:51 +0000 | [diff] [blame] | 252 | def update_metadata(self): |
| 253 | Record.update_metadata(self) |
| 254 | |
| 255 | if self.may_have_dawn_object: |
| 256 | self.is_wire_transparent = False |
| 257 | return |
| 258 | |
| 259 | assert not (self.chained or self.extensible) |
| 260 | |
| 261 | def get_is_wire_transparent(member): |
| 262 | return member.type.is_wire_transparent and member.annotation == 'value' |
| 263 | |
| 264 | self.is_wire_transparent = all( |
| 265 | get_is_wire_transparent(m) for m in self.members) |
| 266 | |
Austin Eng | 0c82405 | 2021-09-20 16:07:25 +0000 | [diff] [blame] | 267 | @property |
| 268 | def output(self): |
| 269 | return self.chained == "out" or self.extensible == "out" |
| 270 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 271 | |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 272 | class ConstantDefinition(): |
| 273 | def __init__(self, is_enabled, name, json_data): |
| 274 | self.type = None |
| 275 | self.value = json_data['value'] |
| 276 | self.json_data = json_data |
| 277 | self.name = Name(name) |
| 278 | |
| 279 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 280 | class FunctionDeclaration(): |
| 281 | def __init__(self, is_enabled, name, json_data): |
| 282 | self.return_type = None |
| 283 | self.arguments = [] |
| 284 | self.json_data = json_data |
| 285 | self.name = Name(name) |
| 286 | |
| 287 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 288 | class Command(Record): |
| 289 | def __init__(self, name, members=None): |
| 290 | Record.__init__(self, name) |
| 291 | self.members = members or [] |
| 292 | self.derived_object = None |
| 293 | self.derived_method = None |
| 294 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 295 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 296 | def linked_record_members(json_data, types): |
| 297 | members = [] |
| 298 | members_by_name = {} |
| 299 | for m in json_data: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 300 | member = RecordMember(Name(m['name']), |
| 301 | types[m['type']], |
Corentin Wallez | 8f93871 | 2019-07-08 19:20:22 +0000 | [diff] [blame] | 302 | m.get('annotation', 'value'), |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 303 | m, |
Corentin Wallez | 8f93871 | 2019-07-08 19:20:22 +0000 | [diff] [blame] | 304 | optional=m.get('optional', False), |
| 305 | is_return_value=m.get('is_return_value', False), |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 306 | default_value=m.get('default', None), |
| 307 | skip_serialize=m.get('skip_serialize', False)) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 308 | handle_type = m.get('handle_type') |
| 309 | if handle_type: |
| 310 | member.set_handle_type(types[handle_type]) |
| 311 | members.append(member) |
| 312 | members_by_name[member.name.canonical_case()] = member |
| 313 | |
| 314 | for (member, m) in zip(members, json_data): |
| 315 | if member.annotation != 'value': |
| 316 | if not 'length' in m: |
| 317 | if member.type.category != 'object': |
| 318 | member.length = "constant" |
| 319 | member.constant_length = 1 |
| 320 | else: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 321 | assert False |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 322 | elif m['length'] == 'strlen': |
| 323 | member.length = 'strlen' |
Yan | 5204053 | 2021-12-15 04:08:56 +0000 | [diff] [blame] | 324 | elif isinstance(m['length'], int): |
| 325 | assert m['length'] > 0 |
| 326 | member.length = "constant" |
| 327 | member.constant_length = m['length'] |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 328 | else: |
| 329 | member.length = members_by_name[m['length']] |
| 330 | |
| 331 | return members |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 332 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 333 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 334 | ############################################################ |
| 335 | # PARSE |
| 336 | ############################################################ |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 337 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 338 | |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 339 | def link_object(obj, types): |
| 340 | def make_method(json_data): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 341 | arguments = linked_record_members(json_data.get('args', []), types) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 342 | return Method(Name(json_data['name']), |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 343 | types[json_data.get('returns', |
| 344 | 'void')], arguments, json_data) |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 345 | |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 346 | 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] | 347 | obj.methods.sort(key=lambda method: method.name.canonical_case()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 348 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 349 | |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 350 | def link_structure(struct, types): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 351 | struct.members = linked_record_members(struct.json_data['members'], types) |
Corentin Wallez | a45561b | 2022-07-14 12:58:25 +0000 | [diff] [blame] | 352 | struct.chain_roots = [types[root] for root in struct.json_data.get('chain roots', [])] |
| 353 | assert all((root.category == 'structure' for root in struct.chain_roots)) |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 354 | |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 355 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 356 | def link_function_pointer(function_pointer, types): |
| 357 | link_function(function_pointer, types) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 358 | |
| 359 | |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 360 | def link_typedef(typedef, types): |
| 361 | typedef.type = types[typedef.json_data['type']] |
| 362 | |
| 363 | |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 364 | def link_constant(constant, types): |
| 365 | constant.type = types[constant.json_data['type']] |
| 366 | assert constant.type.name.native |
| 367 | |
| 368 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 369 | def link_function(function, types): |
| 370 | function.return_type = types[function.json_data.get('returns', 'void')] |
| 371 | function.arguments = linked_record_members(function.json_data['args'], |
| 372 | types) |
| 373 | |
| 374 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 375 | # Sort structures so that if struct A has struct B as a member, then B is |
| 376 | # listed before A. |
| 377 | # |
| 378 | # This is a form of topological sort where we try to keep the order reasonably |
| 379 | # similar to the original order (though the sort isn't technically stable). |
| 380 | # |
| 381 | # 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] | 382 | # 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] | 383 | # This makes a toposort because if A depends on B then its depth will be bigger |
| 384 | # than B's. It is also nice because all nodes with the same depth are kept in |
| 385 | # the input order. |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 386 | def topo_sort_structure(structs): |
| 387 | for struct in structs: |
| 388 | struct.visited = False |
| 389 | struct.subdag_depth = 0 |
| 390 | |
| 391 | def compute_depth(struct): |
| 392 | if struct.visited: |
| 393 | return struct.subdag_depth |
| 394 | |
| 395 | max_dependent_depth = 0 |
| 396 | for member in struct.members: |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 397 | if member.type.category == 'structure': |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 398 | max_dependent_depth = max(max_dependent_depth, |
| 399 | compute_depth(member.type) + 1) |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 400 | |
| 401 | struct.subdag_depth = max_dependent_depth |
| 402 | struct.visited = True |
| 403 | return struct.subdag_depth |
| 404 | |
| 405 | for struct in structs: |
| 406 | compute_depth(struct) |
| 407 | |
| 408 | result = sorted(structs, key=lambda struct: struct.subdag_depth) |
| 409 | |
| 410 | for struct in structs: |
| 411 | del struct.visited |
| 412 | del struct.subdag_depth |
| 413 | |
| 414 | return result |
| 415 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 416 | |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 417 | def parse_json(json, enabled_tags, disabled_tags=None): |
| 418 | is_enabled = lambda json_data: item_is_enabled( |
| 419 | enabled_tags, json_data) and not item_is_disabled( |
| 420 | disabled_tags, json_data) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 421 | category_to_parser = { |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 422 | 'bitmask': BitmaskType, |
| 423 | 'enum': EnumType, |
| 424 | 'native': NativeType, |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 425 | 'function pointer': FunctionPointerType, |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 426 | 'object': ObjectType, |
| 427 | 'structure': StructureType, |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 428 | 'typedef': TypedefType, |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 429 | 'constant': ConstantDefinition, |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 430 | 'function': FunctionDeclaration |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | types = {} |
| 434 | |
| 435 | by_category = {} |
| 436 | for name in category_to_parser.keys(): |
| 437 | by_category[name] = [] |
| 438 | |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 439 | for (name, json_data) in json.items(): |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 440 | if name[0] == '_' or not is_enabled(json_data): |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 441 | continue |
Corentin Wallez | e2f9484 | 2018-12-05 17:49:04 +0000 | [diff] [blame] | 442 | category = json_data['category'] |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 443 | parsed = category_to_parser[category](is_enabled, name, json_data) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 444 | by_category[category].append(parsed) |
| 445 | types[name] = parsed |
| 446 | |
| 447 | for obj in by_category['object']: |
| 448 | link_object(obj, types) |
| 449 | |
Corentin Wallez | a641654 | 2018-05-17 16:55:53 -0400 | [diff] [blame] | 450 | for struct in by_category['structure']: |
| 451 | link_structure(struct, types) |
| 452 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 453 | for function_pointer in by_category['function pointer']: |
| 454 | link_function_pointer(function_pointer, types) |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 455 | |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 456 | for typedef in by_category['typedef']: |
| 457 | link_typedef(typedef, types) |
| 458 | |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 459 | for constant in by_category['constant']: |
| 460 | link_constant(constant, types) |
| 461 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 462 | for function in by_category['function']: |
| 463 | link_function(function, types) |
| 464 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 465 | for category in by_category.keys(): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 466 | by_category[category] = sorted( |
| 467 | by_category[category], key=lambda typ: typ.name.canonical_case()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 468 | |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 469 | by_category['structure'] = topo_sort_structure(by_category['structure']) |
| 470 | |
Austin Eng | c7f416c | 2019-01-15 20:49:53 +0000 | [diff] [blame] | 471 | for struct in by_category['structure']: |
| 472 | struct.update_metadata() |
| 473 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 474 | api_params = { |
| 475 | 'types': types, |
| 476 | 'by_category': by_category, |
| 477 | 'enabled_tags': enabled_tags, |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 478 | 'disabled_tags': disabled_tags, |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 479 | } |
| 480 | return { |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 481 | 'metadata': Metadata(json['_metadata']), |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 482 | 'types': types, |
| 483 | 'by_category': by_category, |
| 484 | 'enabled_tags': enabled_tags, |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 485 | 'disabled_tags': disabled_tags, |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 486 | 'c_methods': lambda typ: c_methods(api_params, typ), |
| 487 | 'c_methods_sorted_by_name': get_c_methods_sorted_by_name(api_params), |
| 488 | } |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 489 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 490 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 491 | ############################################################ |
| 492 | # WIRE STUFF |
| 493 | ############################################################ |
| 494 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 495 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 496 | # Create wire commands from api methods |
| 497 | def compute_wire_params(api_params, wire_json): |
| 498 | wire_params = api_params.copy() |
| 499 | types = wire_params['types'] |
| 500 | |
| 501 | commands = [] |
| 502 | return_commands = [] |
| 503 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 504 | wire_json['special items']['client_handwritten_commands'] += wire_json[ |
| 505 | 'special items']['client_side_commands'] |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 506 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 507 | # Generate commands from object methods |
| 508 | for api_object in wire_params['by_category']['object']: |
| 509 | for method in api_object.methods: |
| 510 | command_name = concat_names(api_object.name, method.name) |
| 511 | command_suffix = Name(command_name).CamelCase() |
| 512 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 513 | # Only object return values or void are supported. |
| 514 | # Other methods must be handwritten. |
| 515 | is_object = method.return_type.category == 'object' |
| 516 | is_void = method.return_type.name.canonical_case() == 'void' |
| 517 | if not (is_object or is_void): |
| 518 | assert command_suffix in ( |
| 519 | wire_json['special items']['client_handwritten_commands']) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 520 | continue |
| 521 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 522 | if command_suffix in ( |
| 523 | wire_json['special items']['client_side_commands']): |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 524 | continue |
| 525 | |
| 526 | # Create object method commands by prepending "self" |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 527 | members = [ |
| 528 | RecordMember(Name('self'), types[api_object.dict_name], |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 529 | 'value', {}) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 530 | ] |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 531 | members += method.arguments |
| 532 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 533 | # Client->Server commands that return an object return the |
| 534 | # result object handle |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 535 | if method.return_type.category == 'object': |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 536 | result = RecordMember(Name('result'), |
| 537 | types['ObjectHandle'], |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 538 | 'value', {}, |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 539 | is_return_value=True) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 540 | result.set_handle_type(method.return_type) |
| 541 | members.append(result) |
| 542 | |
| 543 | command = Command(command_name, members) |
| 544 | command.derived_object = api_object |
| 545 | command.derived_method = method |
| 546 | commands.append(command) |
| 547 | |
| 548 | for (name, json_data) in wire_json['commands'].items(): |
| 549 | commands.append(Command(name, linked_record_members(json_data, types))) |
| 550 | |
| 551 | for (name, json_data) in wire_json['return commands'].items(): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 552 | return_commands.append( |
| 553 | Command(name, linked_record_members(json_data, types))) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 554 | |
| 555 | wire_params['cmd_records'] = { |
| 556 | 'command': commands, |
| 557 | 'return command': return_commands |
| 558 | } |
| 559 | |
| 560 | for commands in wire_params['cmd_records'].values(): |
| 561 | for command in commands: |
| 562 | command.update_metadata() |
| 563 | commands.sort(key=lambda c: c.name.canonical_case()) |
| 564 | |
| 565 | wire_params.update(wire_json.get('special items', {})) |
| 566 | |
| 567 | return wire_params |
| 568 | |
Brendon Tiszka | a045643 | 2023-03-23 16:02:20 +0000 | [diff] [blame] | 569 | ############################################################ |
| 570 | # DAWN LPM FUZZ STUFF |
| 571 | ############################################################ |
| 572 | |
| 573 | |
| 574 | def compute_lpm_params(api_and_wire_params, lpm_json): |
| 575 | # Start with all commands in dawn.json and dawn_wire.json |
| 576 | lpm_params = api_and_wire_params.copy() |
| 577 | |
| 578 | # Commands that are built through generation |
| 579 | proto_generated_commands = [] |
| 580 | |
| 581 | # All commands, including hand written commands that we can't generate |
| 582 | # through codegen |
| 583 | proto_all_commands = [] |
| 584 | |
| 585 | # Remove blocklisted commands from protobuf generation params |
| 586 | blocklisted_cmds_proto = lpm_json.get('blocklisted_cmds') |
| 587 | custom_cmds_proto = lpm_json.get('custom_cmds') |
| 588 | for command in lpm_params['cmd_records']['command']: |
| 589 | blocklisted = command.name.get() in blocklisted_cmds_proto |
| 590 | custom = command.name.get() in custom_cmds_proto |
| 591 | |
| 592 | if not blocklisted and not custom: |
| 593 | proto_generated_commands.append(command) |
| 594 | proto_all_commands.append(command) |
| 595 | |
| 596 | lpm_params['cmd_records'] = { |
| 597 | 'proto_generated_commands': proto_generated_commands, |
| 598 | 'proto_all_commands': proto_all_commands, |
| 599 | } |
| 600 | |
| 601 | return lpm_params |
| 602 | |
| 603 | |
| 604 | def as_protobufTypeLPM(member): |
| 605 | assert 'type' in member.json_data |
| 606 | |
| 607 | if member.type.name.native: |
| 608 | typ = member.json_data['type'] |
| 609 | cpp_to_protobuf_type = { |
| 610 | "bool": "bool", |
| 611 | "float": "float", |
| 612 | "double": "double", |
| 613 | "int8_t": "int32", |
| 614 | "int16_t": "int32", |
| 615 | "int32_t": "int32", |
| 616 | "int64_t": "int64", |
| 617 | "uint8_t": "uint32", |
| 618 | "uint16_t": "uint32", |
| 619 | "uint32_t": "uint32", |
| 620 | "uint64_t": "uint64", |
| 621 | } |
| 622 | |
| 623 | assert typ in cpp_to_protobuf_type |
| 624 | |
| 625 | return cpp_to_protobuf_type[typ] |
| 626 | |
| 627 | return member.type.name.CamelCase() |
| 628 | |
| 629 | |
| 630 | def as_protobufNameLPM(*names): |
| 631 | # `descriptor` is a reserved keyword in lpm |
| 632 | if (names[0].concatcase() == "descriptor"): |
| 633 | return "desc" |
| 634 | return as_varName(*names) |
| 635 | |
| 636 | |
| 637 | def unreachable_code(): |
| 638 | assert False |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 639 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 640 | ############################################################# |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 641 | # Generator |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 642 | ############################################################# |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 643 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 644 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 645 | def as_varName(*names): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 646 | return names[0].camelCase() + ''.join( |
| 647 | [name.CamelCase() for name in names[1:]]) |
| 648 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 649 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 650 | def as_cType(c_prefix, name): |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 651 | if name.native: |
| 652 | return name.concatcase() |
| 653 | else: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 654 | return c_prefix + name.CamelCase() |
Corentin Wallez | 919812e | 2019-10-17 08:46:07 +0000 | [diff] [blame] | 655 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 656 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 657 | def as_cppType(name): |
| 658 | if name.native: |
| 659 | return name.concatcase() |
| 660 | else: |
| 661 | return name.CamelCase() |
| 662 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 663 | |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 664 | def as_jsEnumValue(value): |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 665 | if 'jsrepr' in value.json_data: return value.json_data['jsrepr'] |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 666 | return "'" + value.name.js_enum_case() + "'" |
| 667 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 668 | |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 669 | def convert_cType_to_cppType(typ, annotation, arg, indent=0): |
| 670 | if typ.category == 'native': |
| 671 | return arg |
| 672 | if annotation == 'value': |
| 673 | if typ.category == 'object': |
| 674 | return '{}::Acquire({})'.format(as_cppType(typ.name), arg) |
| 675 | elif typ.category == 'structure': |
| 676 | converted_members = [ |
| 677 | convert_cType_to_cppType( |
| 678 | member.type, member.annotation, |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 679 | '{}.{}'.format(arg, as_varName(member.name)), indent + 1) |
| 680 | for member in typ.members |
| 681 | ] |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 682 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 683 | converted_members = [(' ' * 4) + m for m in converted_members] |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 684 | converted_members = ',\n'.join(converted_members) |
| 685 | |
| 686 | return as_cppType(typ.name) + ' {\n' + converted_members + '\n}' |
fujunwei | d3cac11 | 2021-12-14 02:20:15 +0000 | [diff] [blame] | 687 | elif typ.category == 'function pointer': |
| 688 | return 'reinterpret_cast<{}>({})'.format(as_cppType(typ.name), arg) |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 689 | else: |
| 690 | return 'static_cast<{}>({})'.format(as_cppType(typ.name), arg) |
| 691 | else: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 692 | return 'reinterpret_cast<{} {}>({})'.format(as_cppType(typ.name), |
| 693 | annotation, arg) |
| 694 | |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 695 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 696 | def decorate(name, typ, arg): |
| 697 | if arg.annotation == 'value': |
| 698 | return typ + ' ' + name |
Austin Eng | 740995c | 2019-05-15 18:55:22 +0000 | [diff] [blame] | 699 | elif arg.annotation == '*': |
| 700 | return typ + ' * ' + name |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 701 | elif arg.annotation == 'const*': |
| 702 | return typ + ' const * ' + name |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 703 | elif arg.annotation == 'const*const*': |
| 704 | return 'const ' + typ + '* const * ' + name |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 705 | else: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 706 | assert False |
| 707 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 708 | |
| 709 | def annotated(typ, arg): |
| 710 | name = as_varName(arg.name) |
| 711 | return decorate(name, typ, arg) |
| 712 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 713 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 714 | def item_is_enabled(enabled_tags, json_data): |
| 715 | tags = json_data.get('tags') |
| 716 | if tags is None: return True |
| 717 | return any(tag in enabled_tags for tag in tags) |
| 718 | |
| 719 | |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 720 | def item_is_disabled(disabled_tags, json_data): |
| 721 | if disabled_tags is None: return False |
| 722 | tags = json_data.get('tags') |
| 723 | if tags is None: return False |
| 724 | |
| 725 | return any(tag in disabled_tags for tag in tags) |
| 726 | |
| 727 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 728 | def as_cppEnum(value_name): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 729 | assert not value_name.native |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 730 | if value_name.concatcase()[0].isdigit(): |
| 731 | return "e" + value_name.CamelCase() |
| 732 | return value_name.CamelCase() |
| 733 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 734 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 735 | def as_MethodSuffix(type_name, method_name): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 736 | assert not type_name.native and not method_name.native |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 737 | return type_name.CamelCase() + method_name.CamelCase() |
| 738 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 739 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 740 | def as_frontendType(metadata, typ): |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 741 | if typ.category == 'object': |
Corentin Wallez | 4f5fc2d | 2019-04-01 21:48:38 +0000 | [diff] [blame] | 742 | return typ.name.CamelCase() + 'Base*' |
Corentin Wallez | fe253f1 | 2018-08-01 15:12:10 +0200 | [diff] [blame] | 743 | elif typ.category in ['bitmask', 'enum']: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 744 | return metadata.namespace + '::' + typ.name.CamelCase() |
Corentin Wallez | fe253f1 | 2018-08-01 15:12:10 +0200 | [diff] [blame] | 745 | elif typ.category == 'structure': |
| 746 | return as_cppType(typ.name) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 747 | else: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 748 | return as_cType(metadata.c_prefix, typ.name) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 749 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 750 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 751 | def as_wireType(metadata, typ): |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 752 | if typ.category == 'object': |
| 753 | return typ.name.CamelCase() + '*' |
Brandon Jones | 6f2bbe9 | 2021-04-05 23:34:17 +0000 | [diff] [blame] | 754 | elif typ.category in ['bitmask', 'enum', 'structure']: |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 755 | return metadata.c_prefix + typ.name.CamelCase() |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 756 | else: |
| 757 | return as_cppType(typ.name) |
| 758 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 759 | |
Loko Kung | 4d83525 | 2022-03-19 00:21:48 +0000 | [diff] [blame] | 760 | def as_formatType(typ): |
| 761 | # Unsigned integral types |
| 762 | if typ.json_data['type'] in ['bool', 'uint32_t', 'uint64_t']: |
| 763 | return 'u' |
| 764 | |
| 765 | # Defaults everything else to strings. |
| 766 | return 's' |
| 767 | |
| 768 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 769 | def c_methods(params, typ): |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 770 | return typ.methods + [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 771 | x for x in [ |
| 772 | Method(Name('reference'), params['types']['void'], [], |
| 773 | {'tags': ['dawn', 'emscripten']}), |
| 774 | Method(Name('release'), params['types']['void'], [], |
| 775 | {'tags': ['dawn', 'emscripten']}), |
| 776 | ] if item_is_enabled(params['enabled_tags'], x.json_data) |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 777 | and not item_is_disabled(params['disabled_tags'], x.json_data) |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 778 | ] |
| 779 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 780 | |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 781 | def get_c_methods_sorted_by_name(api_params): |
Corentin Wallez | c57b180 | 2019-10-15 12:08:48 +0000 | [diff] [blame] | 782 | unsorted = [(as_MethodSuffix(typ.name, method.name), typ, method) \ |
| 783 | for typ in api_params['by_category']['object'] \ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 784 | for method in c_methods(api_params, typ) ] |
Corentin Wallez | c57b180 | 2019-10-15 12:08:48 +0000 | [diff] [blame] | 785 | return [(typ, method) for (_, typ, method) in sorted(unsorted)] |
| 786 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 787 | |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 788 | def has_callback_arguments(method): |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 789 | return any(arg.type.category == 'function pointer' for arg in method.arguments) |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 790 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 791 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 792 | def make_base_render_params(metadata): |
| 793 | c_prefix = metadata.c_prefix |
| 794 | |
| 795 | def as_cTypeEnumSpecialCase(typ): |
| 796 | if typ.category == 'bitmask': |
| 797 | return as_cType(c_prefix, typ.name) + 'Flags' |
| 798 | return as_cType(c_prefix, typ.name) |
| 799 | |
| 800 | def as_cEnum(type_name, value_name): |
| 801 | assert not type_name.native and not value_name.native |
| 802 | return c_prefix + type_name.CamelCase() + '_' + value_name.CamelCase() |
| 803 | |
| 804 | def as_cMethod(type_name, method_name): |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 805 | c_method = c_prefix.lower() |
| 806 | if type_name != None: |
| 807 | assert not type_name.native |
| 808 | c_method += type_name.CamelCase() |
| 809 | assert not method_name.native |
| 810 | c_method += method_name.CamelCase() |
| 811 | return c_method |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 812 | |
| 813 | def as_cProc(type_name, method_name): |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 814 | c_proc = c_prefix + 'Proc' |
| 815 | if type_name != None: |
| 816 | assert not type_name.native |
| 817 | c_proc += type_name.CamelCase() |
| 818 | assert not method_name.native |
| 819 | c_proc += method_name.CamelCase() |
| 820 | return c_proc |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 821 | |
| 822 | return { |
| 823 | 'Name': lambda name: Name(name), |
| 824 | 'as_annotated_cType': \ |
| 825 | lambda arg: annotated(as_cTypeEnumSpecialCase(arg.type), arg), |
| 826 | 'as_annotated_cppType': \ |
| 827 | lambda arg: annotated(as_cppType(arg.type.name), arg), |
| 828 | 'as_cEnum': as_cEnum, |
| 829 | 'as_cppEnum': as_cppEnum, |
| 830 | 'as_cMethod': as_cMethod, |
| 831 | 'as_MethodSuffix': as_MethodSuffix, |
| 832 | 'as_cProc': as_cProc, |
| 833 | 'as_cType': lambda name: as_cType(c_prefix, name), |
| 834 | 'as_cppType': as_cppType, |
| 835 | 'as_jsEnumValue': as_jsEnumValue, |
| 836 | 'convert_cType_to_cppType': convert_cType_to_cppType, |
| 837 | 'as_varName': as_varName, |
Loko Kung | 4d83525 | 2022-03-19 00:21:48 +0000 | [diff] [blame] | 838 | 'decorate': decorate, |
| 839 | 'as_formatType': as_formatType |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 843 | class MultiGeneratorFromDawnJSON(Generator): |
| 844 | def get_description(self): |
| 845 | return 'Generates code for various target from Dawn.json.' |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 846 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 847 | def add_commandline_arguments(self, parser): |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 848 | allowed_targets = [ |
Ben Clayton | 35940f9 | 2022-02-04 17:15:16 +0000 | [diff] [blame] | 849 | 'dawn_headers', 'cpp_headers', 'cpp', 'proc', 'mock_api', 'wire', |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 850 | 'native_utils', 'dawn_lpmfuzz_cpp', 'dawn_lpmfuzz_proto' |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 851 | ] |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 852 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 853 | parser.add_argument('--dawn-json', |
| 854 | required=True, |
| 855 | type=str, |
| 856 | help='The DAWN JSON definition to use.') |
| 857 | parser.add_argument('--wire-json', |
| 858 | default=None, |
| 859 | type=str, |
| 860 | help='The DAWN WIRE JSON definition to use.') |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 861 | parser.add_argument("--lpm-json", |
| 862 | default=None, |
| 863 | type=str, |
| 864 | help='The DAWN LPM FUZZER definitions to use.') |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 865 | parser.add_argument( |
| 866 | '--targets', |
| 867 | required=True, |
| 868 | type=str, |
| 869 | help= |
| 870 | 'Comma-separated subset of targets to output. Available targets: ' |
| 871 | + ', '.join(allowed_targets)) |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 872 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 873 | def get_file_renders(self, args): |
| 874 | with open(args.dawn_json) as f: |
| 875 | loaded_json = json.loads(f.read()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 876 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 877 | targets = args.targets.split(',') |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 878 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 879 | wire_json = None |
| 880 | if args.wire_json: |
| 881 | with open(args.wire_json) as f: |
| 882 | wire_json = json.loads(f.read()) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 883 | |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 884 | lpm_json = None |
| 885 | if args.lpm_json: |
| 886 | with open(args.lpm_json) as f: |
| 887 | lpm_json = json.loads(f.read()) |
| 888 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 889 | renders = [] |
| 890 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 891 | params_dawn = parse_json(loaded_json, |
| 892 | enabled_tags=['dawn', 'native', 'deprecated']) |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 893 | metadata = params_dawn['metadata'] |
| 894 | RENDER_PARAMS_BASE = make_base_render_params(metadata) |
Corentin Wallez | 79a62bf | 2017-05-24 16:04:55 +0200 | [diff] [blame] | 895 | |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 896 | api = metadata.api.lower() |
fujunwei | a840574 | 2021-12-10 01:35:19 +0000 | [diff] [blame] | 897 | prefix = metadata.proc_table_prefix.lower() |
Ben Clayton | 35940f9 | 2022-02-04 17:15:16 +0000 | [diff] [blame] | 898 | if 'headers' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 899 | renders.append( |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 900 | FileRender('api.h', 'include/dawn/' + api + '.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 901 | [RENDER_PARAMS_BASE, params_dawn])) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 902 | renders.append( |
| 903 | FileRender('dawn_proc_table.h', |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 904 | 'include/dawn/' + prefix + '_proc_table.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 905 | [RENDER_PARAMS_BASE, params_dawn])) |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 906 | |
Ben Clayton | 35940f9 | 2022-02-04 17:15:16 +0000 | [diff] [blame] | 907 | if 'cpp_headers' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 908 | renders.append( |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 909 | FileRender('api_cpp.h', 'include/dawn/' + api + '_cpp.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 910 | [RENDER_PARAMS_BASE, params_dawn])) |
Austin Eng | cc071e4 | 2019-10-16 10:26:01 +0000 | [diff] [blame] | 911 | |
Austin Eng | a9e39e1 | 2021-06-01 18:49:12 +0000 | [diff] [blame] | 912 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 913 | FileRender('api_cpp_print.h', |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 914 | 'include/dawn/' + api + '_cpp_print.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 915 | [RENDER_PARAMS_BASE, params_dawn])) |
Austin Eng | a9e39e1 | 2021-06-01 18:49:12 +0000 | [diff] [blame] | 916 | |
Ben Clayton | 35940f9 | 2022-02-04 17:15:16 +0000 | [diff] [blame] | 917 | if 'proc' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 918 | renders.append( |
fujunwei | a840574 | 2021-12-10 01:35:19 +0000 | [diff] [blame] | 919 | FileRender('dawn_proc.c', 'src/dawn/' + prefix + '_proc.c', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 920 | [RENDER_PARAMS_BASE, params_dawn])) |
Austin Eng | 16e01af | 2020-10-06 16:13:42 +0000 | [diff] [blame] | 921 | renders.append( |
| 922 | FileRender('dawn_thread_dispatch_proc.cpp', |
fujunwei | a840574 | 2021-12-10 01:35:19 +0000 | [diff] [blame] | 923 | 'src/dawn/' + prefix + '_thread_dispatch_proc.cpp', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 924 | [RENDER_PARAMS_BASE, params_dawn])) |
Corentin Wallez | 9649682 | 2019-10-15 11:44:38 +0000 | [diff] [blame] | 925 | |
Austin Eng | 63f6546 | 2021-12-09 20:03:48 +0000 | [diff] [blame] | 926 | if 'webgpu_dawn_native_proc' in targets: |
| 927 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 928 | FileRender('dawn/native/api_dawn_native_proc.cpp', |
| 929 | 'src/dawn/native/webgpu_dawn_native_proc.cpp', |
Austin Eng | 63f6546 | 2021-12-09 20:03:48 +0000 | [diff] [blame] | 930 | [RENDER_PARAMS_BASE, params_dawn])) |
| 931 | |
Ben Clayton | 35940f9 | 2022-02-04 17:15:16 +0000 | [diff] [blame] | 932 | if 'cpp' in targets: |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 933 | renders.append( |
fujunwei | d3cac11 | 2021-12-14 02:20:15 +0000 | [diff] [blame] | 934 | FileRender('api_cpp.cpp', 'src/dawn/' + api + '_cpp.cpp', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 935 | [RENDER_PARAMS_BASE, params_dawn])) |
| 936 | |
| 937 | if 'webgpu_headers' in targets: |
| 938 | params_upstream = parse_json(loaded_json, |
Shrek Shao | 1554a7d | 2022-03-08 20:56:10 +0000 | [diff] [blame] | 939 | enabled_tags=['upstream', 'native'], |
| 940 | disabled_tags=['dawn']) |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 941 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 942 | FileRender('api.h', 'webgpu-headers/' + api + '.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 943 | [RENDER_PARAMS_BASE, params_upstream])) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 944 | |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 945 | if 'emscripten_bits' in targets: |
Shrek Shao | ee50bc0 | 2022-02-08 20:21:40 +0000 | [diff] [blame] | 946 | params_emscripten = parse_json(loaded_json, |
| 947 | enabled_tags=['emscripten']) |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 948 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 949 | FileRender('api.h', 'emscripten-bits/' + api + '.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 950 | [RENDER_PARAMS_BASE, params_emscripten])) |
| 951 | renders.append( |
fujunwei | c7d4f2c | 2021-12-07 00:46:35 +0000 | [diff] [blame] | 952 | FileRender('api_cpp.h', 'emscripten-bits/' + api + '_cpp.h', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 953 | [RENDER_PARAMS_BASE, params_emscripten])) |
| 954 | renders.append( |
fujunwei | d3cac11 | 2021-12-14 02:20:15 +0000 | [diff] [blame] | 955 | FileRender('api_cpp.cpp', 'emscripten-bits/' + api + '_cpp.cpp', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 956 | [RENDER_PARAMS_BASE, params_emscripten])) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 957 | renders.append( |
fujunwei | 16ae3b8 | 2021-12-15 04:35:26 +0000 | [diff] [blame] | 958 | FileRender('api_struct_info.json', |
| 959 | 'emscripten-bits/' + api + '_struct_info.json', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 960 | [RENDER_PARAMS_BASE, params_emscripten])) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 961 | renders.append( |
fujunwei | 16ae3b8 | 2021-12-15 04:35:26 +0000 | [diff] [blame] | 962 | FileRender('library_api_enum_tables.js', |
| 963 | 'emscripten-bits/library_' + api + '_enum_tables.js', |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 964 | [RENDER_PARAMS_BASE, params_emscripten])) |
Kai Ninomiya | 7b6246a | 2020-01-28 23:54:38 +0000 | [diff] [blame] | 965 | |
fujunwei | 16ae3b8 | 2021-12-15 04:35:26 +0000 | [diff] [blame] | 966 | if 'mock_api' in targets: |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 967 | mock_params = [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 968 | RENDER_PARAMS_BASE, params_dawn, { |
Corentin Wallez | 540abab | 2019-11-22 13:18:22 +0000 | [diff] [blame] | 969 | 'has_callback_arguments': has_callback_arguments |
| 970 | } |
| 971 | ] |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 972 | renders.append( |
fujunwei | 16ae3b8 | 2021-12-15 04:35:26 +0000 | [diff] [blame] | 973 | FileRender('mock_api.h', 'src/dawn/mock_' + api + '.h', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 974 | mock_params)) |
| 975 | renders.append( |
fujunwei | 16ae3b8 | 2021-12-15 04:35:26 +0000 | [diff] [blame] | 976 | FileRender('mock_api.cpp', 'src/dawn/mock_' + api + '.cpp', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 977 | mock_params)) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 978 | |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 979 | if 'native_utils' in targets: |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 980 | frontend_params = [ |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 981 | RENDER_PARAMS_BASE, |
| 982 | params_dawn, |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 983 | { |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 984 | # TODO: as_frontendType and co. take a Type, not a Name :( |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 985 | 'as_frontendType': lambda typ: as_frontendType(metadata, typ), |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 986 | 'as_annotated_frontendType': \ |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 987 | lambda arg: annotated(as_frontendType(metadata, arg.type), arg), |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 988 | } |
| 989 | ] |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 990 | |
fujunwei | a2241d4 | 2021-12-16 04:54:38 +0000 | [diff] [blame] | 991 | impl_dir = metadata.impl_dir + '/' if metadata.impl_dir else '' |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 992 | native_dir = impl_dir + Name(metadata.native_namespace).Dirs() |
fujunwei | 7f3f8ac | 2021-12-21 03:27:34 +0000 | [diff] [blame] | 993 | namespace = metadata.namespace |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 994 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 995 | FileRender('dawn/native/ValidationUtils.h', |
fujunwei | a2241d4 | 2021-12-16 04:54:38 +0000 | [diff] [blame] | 996 | 'src/' + native_dir + '/ValidationUtils_autogen.h', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 997 | frontend_params)) |
| 998 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 999 | FileRender('dawn/native/ValidationUtils.cpp', |
fujunwei | a2241d4 | 2021-12-16 04:54:38 +0000 | [diff] [blame] | 1000 | 'src/' + native_dir + '/ValidationUtils_autogen.cpp', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1001 | frontend_params)) |
| 1002 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1003 | FileRender('dawn/native/dawn_platform.h', |
fujunwei | fc38f7d | 2021-12-17 00:46:08 +0000 | [diff] [blame] | 1004 | 'src/' + native_dir + '/' + prefix + '_platform_autogen.h', |
Austin Eng | 3faa478 | 2021-10-27 19:07:37 +0000 | [diff] [blame] | 1005 | frontend_params)) |
| 1006 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1007 | FileRender('dawn/native/api_structs.h', |
fujunwei | 7f3f8ac | 2021-12-21 03:27:34 +0000 | [diff] [blame] | 1008 | 'src/' + native_dir + '/' + namespace + '_structs_autogen.h', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1009 | frontend_params)) |
| 1010 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1011 | FileRender('dawn/native/api_structs.cpp', |
fujunwei | 7f3f8ac | 2021-12-21 03:27:34 +0000 | [diff] [blame] | 1012 | 'src/' + native_dir + '/' + namespace + '_structs_autogen.cpp', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1013 | frontend_params)) |
| 1014 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1015 | FileRender('dawn/native/ProcTable.cpp', |
Ningxin Hu | 7e5930b | 2021-12-22 06:12:13 +0000 | [diff] [blame] | 1016 | 'src/' + native_dir + '/ProcTable.cpp', frontend_params)) |
Brian Ho | 5346e77 | 2021-04-22 17:49:42 +0000 | [diff] [blame] | 1017 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1018 | FileRender('dawn/native/ChainUtils.h', |
fujunwei | 2b1dcd9 | 2021-12-22 01:05:03 +0000 | [diff] [blame] | 1019 | 'src/' + native_dir + '/ChainUtils_autogen.h', |
Brian Ho | 5346e77 | 2021-04-22 17:49:42 +0000 | [diff] [blame] | 1020 | frontend_params)) |
| 1021 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1022 | FileRender('dawn/native/ChainUtils.cpp', |
fujunwei | 2b1dcd9 | 2021-12-22 01:05:03 +0000 | [diff] [blame] | 1023 | 'src/' + native_dir + '/ChainUtils_autogen.cpp', |
Brian Ho | 5346e77 | 2021-04-22 17:49:42 +0000 | [diff] [blame] | 1024 | frontend_params)) |
Brandon Jones | ba66295 | 2021-09-23 21:26:33 +0000 | [diff] [blame] | 1025 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1026 | FileRender('dawn/native/api_absl_format.h', |
fujunwei | f001ef5 | 2021-12-23 05:16:04 +0000 | [diff] [blame] | 1027 | 'src/' + native_dir + '/' + api + '_absl_format_autogen.h', |
Brandon Jones | ba66295 | 2021-09-23 21:26:33 +0000 | [diff] [blame] | 1028 | frontend_params)) |
| 1029 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1030 | FileRender('dawn/native/api_absl_format.cpp', |
fujunwei | f001ef5 | 2021-12-23 05:16:04 +0000 | [diff] [blame] | 1031 | 'src/' + native_dir + '/' + api + '_absl_format_autogen.cpp', |
Brandon Jones | ba66295 | 2021-09-23 21:26:33 +0000 | [diff] [blame] | 1032 | frontend_params)) |
Loko Kung | 8d195d5 | 2021-09-28 15:40:01 +0000 | [diff] [blame] | 1033 | renders.append( |
Austin Eng | bc285fb | 2022-07-29 00:36:21 +0000 | [diff] [blame] | 1034 | FileRender( |
| 1035 | 'dawn/native/api_StreamImpl.cpp', 'src/' + native_dir + |
| 1036 | '/' + api + '_StreamImpl_autogen.cpp', frontend_params)) |
| 1037 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1038 | FileRender('dawn/native/ObjectType.h', |
fujunwei | 2b1dcd9 | 2021-12-22 01:05:03 +0000 | [diff] [blame] | 1039 | 'src/' + native_dir + '/ObjectType_autogen.h', |
Loko Kung | 8d195d5 | 2021-09-28 15:40:01 +0000 | [diff] [blame] | 1040 | frontend_params)) |
| 1041 | renders.append( |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 1042 | FileRender('dawn/native/ObjectType.cpp', |
fujunwei | 2b1dcd9 | 2021-12-22 01:05:03 +0000 | [diff] [blame] | 1043 | 'src/' + native_dir + '/ObjectType_autogen.cpp', |
Loko Kung | 8d195d5 | 2021-09-28 15:40:01 +0000 | [diff] [blame] | 1044 | frontend_params)) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 1045 | |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1046 | if 'wire' in targets: |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 1047 | params_dawn_wire = parse_json(loaded_json, |
| 1048 | enabled_tags=['dawn', 'deprecated'], |
| 1049 | disabled_tags=['native']) |
| 1050 | additional_params = compute_wire_params(params_dawn_wire, |
| 1051 | wire_json) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 1052 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 1053 | wire_params = [ |
Austin Eng | 2f218e2 | 2021-12-22 19:02:23 +0000 | [diff] [blame] | 1054 | RENDER_PARAMS_BASE, params_dawn_wire, { |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 1055 | 'as_wireType': lambda type : as_wireType(metadata, type), |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1056 | 'as_annotated_wireType': \ |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 1057 | lambda arg: annotated(as_wireType(metadata, arg.type), arg), |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1058 | }, additional_params |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 1059 | ] |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1060 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1061 | FileRender('dawn/wire/ObjectType.h', |
| 1062 | 'src/dawn/wire/ObjectType_autogen.h', wire_params)) |
Austin Eng | 3120d5e | 2020-11-11 19:46:18 +0000 | [diff] [blame] | 1063 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1064 | FileRender('dawn/wire/WireCmd.h', |
| 1065 | 'src/dawn/wire/WireCmd_autogen.h', wire_params)) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1066 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1067 | FileRender('dawn/wire/WireCmd.cpp', |
| 1068 | 'src/dawn/wire/WireCmd_autogen.cpp', wire_params)) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1069 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1070 | FileRender('dawn/wire/client/ApiObjects.h', |
| 1071 | 'src/dawn/wire/client/ApiObjects_autogen.h', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1072 | wire_params)) |
| 1073 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1074 | FileRender('dawn/wire/client/ApiProcs.cpp', |
| 1075 | 'src/dawn/wire/client/ApiProcs_autogen.cpp', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1076 | wire_params)) |
| 1077 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1078 | FileRender('dawn/wire/client/ClientBase.h', |
| 1079 | 'src/dawn/wire/client/ClientBase_autogen.h', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1080 | wire_params)) |
| 1081 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1082 | FileRender('dawn/wire/client/ClientHandlers.cpp', |
| 1083 | 'src/dawn/wire/client/ClientHandlers_autogen.cpp', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1084 | wire_params)) |
| 1085 | renders.append( |
| 1086 | FileRender( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1087 | 'dawn/wire/client/ClientPrototypes.inc', |
| 1088 | 'src/dawn/wire/client/ClientPrototypes_autogen.inc', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1089 | wire_params)) |
| 1090 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1091 | FileRender('dawn/wire/server/ServerBase.h', |
| 1092 | 'src/dawn/wire/server/ServerBase_autogen.h', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1093 | wire_params)) |
| 1094 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1095 | FileRender('dawn/wire/server/ServerDoers.cpp', |
| 1096 | 'src/dawn/wire/server/ServerDoers_autogen.cpp', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1097 | wire_params)) |
| 1098 | renders.append( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1099 | FileRender('dawn/wire/server/ServerHandlers.cpp', |
| 1100 | 'src/dawn/wire/server/ServerHandlers_autogen.cpp', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1101 | wire_params)) |
| 1102 | renders.append( |
| 1103 | FileRender( |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 1104 | 'dawn/wire/server/ServerPrototypes.inc', |
| 1105 | 'src/dawn/wire/server/ServerPrototypes_autogen.inc', |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1106 | wire_params)) |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 1107 | |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 1108 | if 'dawn_lpmfuzz_proto' in targets: |
| 1109 | params_dawn_wire = parse_json(loaded_json, |
| 1110 | enabled_tags=['dawn', 'deprecated'], |
| 1111 | disabled_tags=['native']) |
Brendon Tiszka | a045643 | 2023-03-23 16:02:20 +0000 | [diff] [blame] | 1112 | api_and_wire_params = compute_wire_params(params_dawn_wire, |
| 1113 | wire_json) |
| 1114 | |
| 1115 | fuzzer_params = compute_lpm_params(api_and_wire_params, lpm_json) |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 1116 | |
| 1117 | lpm_params = [ |
Brendon Tiszka | a045643 | 2023-03-23 16:02:20 +0000 | [diff] [blame] | 1118 | RENDER_PARAMS_BASE, params_dawn_wire, { |
| 1119 | 'as_protobufTypeLPM': as_protobufTypeLPM, |
| 1120 | 'as_protobufNameLPM': as_protobufNameLPM, |
| 1121 | 'unreachable': unreachable_code |
| 1122 | }, api_and_wire_params, fuzzer_params |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 1123 | ] |
| 1124 | |
| 1125 | renders.append( |
| 1126 | FileRender('dawn/fuzzers/lpmfuzz/dawn_lpm.proto', |
| 1127 | 'src/dawn/fuzzers/lpmfuzz/dawn_lpm_autogen.proto', |
| 1128 | lpm_params)) |
| 1129 | |
| 1130 | if 'dawn_lpmfuzz_cpp' in targets: |
| 1131 | params_dawn_wire = parse_json(loaded_json, |
| 1132 | enabled_tags=['dawn', 'deprecated'], |
| 1133 | disabled_tags=['native']) |
Brendon Tiszka | a045643 | 2023-03-23 16:02:20 +0000 | [diff] [blame] | 1134 | api_and_wire_params = compute_wire_params(params_dawn_wire, |
| 1135 | wire_json) |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 1136 | |
| 1137 | lpm_params = [ |
Brendon Tiszka | a045643 | 2023-03-23 16:02:20 +0000 | [diff] [blame] | 1138 | RENDER_PARAMS_BASE, params_dawn_wire, {}, api_and_wire_params |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 1139 | ] |
| 1140 | |
| 1141 | renders.append( |
| 1142 | FileRender( |
| 1143 | 'dawn/fuzzers/lpmfuzz/DawnLPMSerializer.cpp', |
| 1144 | 'src/dawn/fuzzers/lpmfuzz/DawnLPMSerializer_autogen.cpp', |
| 1145 | lpm_params)) |
| 1146 | |
| 1147 | renders.append( |
| 1148 | FileRender( |
| 1149 | 'dawn/fuzzers/lpmfuzz/DawnLPMSerializer.h', |
| 1150 | 'src/dawn/fuzzers/lpmfuzz/DawnLPMSerializer_autogen.h', |
| 1151 | lpm_params)) |
| 1152 | |
Brendon Tiszka | a045643 | 2023-03-23 16:02:20 +0000 | [diff] [blame] | 1153 | renders.append( |
| 1154 | FileRender( |
| 1155 | 'dawn/fuzzers/lpmfuzz/DawnLPMConstants.h', |
| 1156 | 'src/dawn/fuzzers/lpmfuzz/DawnLPMConstants_autogen.h', |
| 1157 | lpm_params)) |
| 1158 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 1159 | return renders |
Corentin Wallez | 59e7fad | 2018-08-16 15:32:35 +0200 | [diff] [blame] | 1160 | |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 1161 | def get_dependencies(self, args): |
| 1162 | deps = [os.path.abspath(args.dawn_json)] |
| 1163 | if args.wire_json != None: |
| 1164 | deps += [os.path.abspath(args.wire_json)] |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 1165 | if args.lpm_json != None: |
| 1166 | deps += [os.path.abspath(args.lpm_json)] |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 1167 | return deps |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 1168 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 1169 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 1170 | if __name__ == '__main__': |
Corentin Wallez | 0c38e92 | 2019-06-07 08:59:17 +0000 | [diff] [blame] | 1171 | sys.exit(run_generator(MultiGeneratorFromDawnJSON())) |