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