Tobin Ehlis | 33267fd | 2014-11-10 16:03:19 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 3 | # Copyright (c) 2015-2016 The Khronos Group Inc. |
| 4 | # Copyright (c) 2015-2016 Valve Corporation |
| 5 | # Copyright (c) 2015-2016 LunarG, Inc. |
| 6 | # Copyright (c) 2015-2016 Google Inc. |
Tobin Ehlis | 33267fd | 2014-11-10 16:03:19 -0700 | [diff] [blame] | 7 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | # of this software and/or associated documentation files (the "Materials"), to |
| 10 | # deal in the Materials without restriction, including without limitation the |
| 11 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | # sell copies of the Materials, and to permit persons to whom the Materials |
| 13 | # are furnished to do so, subject to the following conditions: |
Tobin Ehlis | 33267fd | 2014-11-10 16:03:19 -0700 | [diff] [blame] | 14 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 15 | # The above copyright notice(s) and this permission notice shall be included |
| 16 | # in all copies or substantial portions of the Materials. |
Tobin Ehlis | 33267fd | 2014-11-10 16:03:19 -0700 | [diff] [blame] | 17 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 18 | # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Tobin Ehlis | 33267fd | 2014-11-10 16:03:19 -0700 | [diff] [blame] | 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | # |
| 22 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 23 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 24 | # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 25 | # USE OR OTHER DEALINGS IN THE MATERIALS |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 26 | # |
| 27 | # Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 28 | # Author: Tobin Ehlis <tobin@lunarg.com> |
| 29 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 30 | import argparse |
| 31 | import os |
| 32 | import sys |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 33 | import re |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 34 | import vulkan |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 35 | from source_line_info import sourcelineinfo |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 36 | |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 37 | # vk_helper.py overview |
| 38 | # This script generates code based on vulkan input header |
| 39 | # It generate wrappers functions that can be used to display |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 40 | # structs in a human-readable txt format, as well as utility functions |
| 41 | # to print enum values as strings |
| 42 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 43 | def handle_args(): |
| 44 | parser = argparse.ArgumentParser(description='Perform analysis of vogl trace.') |
| 45 | parser.add_argument('input_file', help='The input header file from which code will be generated.') |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 46 | parser.add_argument('--rel_out_dir', required=False, default='vktrace_gen', help='Path relative to exec path to write output files. Will be created if needed.') |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 47 | parser.add_argument('--abs_out_dir', required=False, default=None, help='Absolute path to write output files. Will be created if needed.') |
| 48 | parser.add_argument('--gen_enum_string_helper', required=False, action='store_true', default=False, help='Enable generation of helper header file to print string versions of enums.') |
| 49 | parser.add_argument('--gen_struct_wrappers', required=False, action='store_true', default=False, help='Enable generation of struct wrapper classes.') |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 50 | parser.add_argument('--gen_struct_sizes', required=False, action='store_true', default=False, help='Enable generation of struct sizes.') |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 51 | parser.add_argument('--gen_cmake', required=False, action='store_true', default=False, help='Enable generation of cmake file for generated code.') |
| 52 | parser.add_argument('--gen_graphviz', required=False, action='store_true', default=False, help='Enable generation of graphviz dot file.') |
| 53 | #parser.add_argument('--test', action='store_true', default=False, help='Run simple test.') |
| 54 | return parser.parse_args() |
| 55 | |
| 56 | # TODO : Ideally these data structs would be opaque to user and could be wrapped |
| 57 | # in their own class(es) to make them friendly for data look-up |
| 58 | # Dicts for Data storage |
| 59 | # enum_val_dict[value_name] = dict keys are the string enum value names for all enums |
| 60 | # |-------->['type'] = the type of enum class into which the value falls |
| 61 | # |-------->['val'] = the value assigned to this particular value_name |
| 62 | # '-------->['unique'] = bool designating if this enum 'val' is unique within this enum 'type' |
| 63 | enum_val_dict = {} |
| 64 | # enum_type_dict['type'] = the type or class of of enum |
| 65 | # '----->['val_name1', 'val_name2'...] = each type references a list of val_names within this type |
| 66 | enum_type_dict = {} |
| 67 | # struct_dict['struct_basename'] = the base (non-typedef'd) name of the struct |
| 68 | # |->[<member_num>] = members are stored via their integer placement in the struct |
| 69 | # | |->['name'] = string name of this struct member |
| 70 | # ... |->['full_type'] = complete type qualifier for this member |
| 71 | # |->['type'] = base type for this member |
| 72 | # |->['ptr'] = bool indicating if this member is ptr |
| 73 | # |->['const'] = bool indicating if this member is const |
| 74 | # |->['struct'] = bool indicating if this member is a struct type |
| 75 | # |->['array'] = bool indicating if this member is an array |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 76 | # |->['dyn_array'] = bool indicating if member is a dynamically sized array |
| 77 | # '->['array_size'] = For dyn_array, member name used to size array, else int size for static array |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 78 | struct_dict = {} |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 79 | struct_order_list = [] # struct names in order they're declared |
| 80 | # Store struct names that require #ifdef guards |
| 81 | # dict stores struct and enum definitions that are guarded by ifdef as the key |
| 82 | # and the txt of the ifdef is the value |
| 83 | ifdef_dict = {} |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 84 | # typedef_fwd_dict stores mapping from orig_type_name -> new_type_name |
| 85 | typedef_fwd_dict = {} |
| 86 | # typedef_rev_dict stores mapping from new_type_name -> orig_type_name |
| 87 | typedef_rev_dict = {} # store new_name -> orig_name mapping |
| 88 | # types_dict['id_name'] = identifier name will map to it's type |
| 89 | # '---->'type' = currently either 'struct' or 'enum' |
| 90 | types_dict = {} # store orig_name -> type mapping |
| 91 | |
| 92 | |
| 93 | # Class that parses header file and generates data structures that can |
| 94 | # Then be used for other tasks |
| 95 | class HeaderFileParser: |
| 96 | def __init__(self, header_file=None): |
| 97 | self.header_file = header_file |
| 98 | # store header data in various formats, see above for more info |
| 99 | self.enum_val_dict = {} |
| 100 | self.enum_type_dict = {} |
| 101 | self.struct_dict = {} |
| 102 | self.typedef_fwd_dict = {} |
| 103 | self.typedef_rev_dict = {} |
| 104 | self.types_dict = {} |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 105 | self.last_struct_count_name = '' |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 106 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 107 | def setHeaderFile(self, header_file): |
| 108 | self.header_file = header_file |
| 109 | |
| 110 | def get_enum_val_dict(self): |
| 111 | return self.enum_val_dict |
| 112 | |
| 113 | def get_enum_type_dict(self): |
| 114 | return self.enum_type_dict |
| 115 | |
| 116 | def get_struct_dict(self): |
| 117 | return self.struct_dict |
| 118 | |
| 119 | def get_typedef_fwd_dict(self): |
| 120 | return self.typedef_fwd_dict |
| 121 | |
| 122 | def get_typedef_rev_dict(self): |
| 123 | return self.typedef_rev_dict |
| 124 | |
| 125 | def get_types_dict(self): |
| 126 | return self.types_dict |
| 127 | |
| 128 | # Parse header file into data structures |
| 129 | def parse(self): |
| 130 | # parse through the file, identifying different sections |
| 131 | parse_enum = False |
| 132 | parse_struct = False |
| 133 | member_num = 0 |
| 134 | # TODO : Comment parsing is very fragile but handles 2 known files |
| 135 | block_comment = False |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 136 | prev_count_name = '' |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 137 | ifdef_txt = '' |
| 138 | ifdef_active = 0 |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 139 | exclude_struct_list = ['VkPlatformHandleXcbKHR', 'VkPlatformHandleX11KHR'] |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 140 | with open(self.header_file) as f: |
| 141 | for line in f: |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 142 | if True in [ifd_txt in line for ifd_txt in ['#ifdef ', '#ifndef ']]: |
| 143 | ifdef_txt = line.split()[1] |
| 144 | ifdef_active = ifdef_active + 1 |
| 145 | continue |
| 146 | if ifdef_active != 0 and '#endif' in line: |
| 147 | ifdef_active = ifdef_active - 1 |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 148 | if block_comment: |
| 149 | if '*/' in line: |
| 150 | block_comment = False |
| 151 | continue |
| 152 | if '/*' in line: |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 153 | if '*/' in line: # single line block comment |
| 154 | continue |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 155 | block_comment = True |
| 156 | elif 0 == len(line.split()): |
| 157 | #print("Skipping empty line") |
| 158 | continue |
| 159 | elif line.split()[0].strip().startswith("//"): |
Jon Ashburn | fe6113c | 2015-01-09 09:11:44 -0700 | [diff] [blame] | 160 | #print("Skipping commented line %s" % line) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 161 | continue |
| 162 | elif 'typedef enum' in line: |
| 163 | (ty_txt, en_txt, base_type) = line.strip().split(None, 2) |
| 164 | #print("Found ENUM type %s" % base_type) |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 165 | if '{' == base_type: |
| 166 | base_type = 'tmp_enum' |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 167 | parse_enum = True |
Jon Ashburn | fe6113c | 2015-01-09 09:11:44 -0700 | [diff] [blame] | 168 | default_enum_val = 0 |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 169 | self.types_dict[base_type] = 'enum' |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 170 | elif 'typedef struct' in line or 'typedef union' in line: |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 171 | if True in [ex_type in line for ex_type in exclude_struct_list]: |
| 172 | continue |
Chia-I Wu | 44c99b6 | 2015-10-27 19:55:29 +0800 | [diff] [blame] | 173 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 174 | (ty_txt, st_txt, base_type) = line.strip().split(None, 2) |
Chia-I Wu | 44c99b6 | 2015-10-27 19:55:29 +0800 | [diff] [blame] | 175 | if ' ' in base_type: |
| 176 | (ignored, base_type) = base_type.strip().split(None, 1) |
| 177 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 178 | #print("Found STRUCT type: %s" % base_type) |
Cody Northrop | 22b7fae | 2015-08-11 11:21:48 -0600 | [diff] [blame] | 179 | # Note: This really needs to be updated to handle one line struct definition, like |
| 180 | # typedef struct obj##_T { uint64_t handle; } obj; |
| 181 | if ('{' == base_type or not (' ' in base_type)): |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 182 | base_type = 'tmp_struct' |
Cody Northrop | 22b7fae | 2015-08-11 11:21:48 -0600 | [diff] [blame] | 183 | parse_struct = True |
| 184 | self.types_dict[base_type] = 'struct' |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 185 | # elif 'typedef union' in line: |
| 186 | # (ty_txt, st_txt, base_type) = line.strip().split(None, 2) |
| 187 | # print("Found UNION type: %s" % base_type) |
| 188 | # parse_struct = True |
| 189 | # self.types_dict[base_type] = 'struct' |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 190 | elif '}' in line and (parse_enum or parse_struct): |
| 191 | if len(line.split()) > 1: # deals with embedded union in one struct |
| 192 | parse_enum = False |
| 193 | parse_struct = False |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 194 | self.last_struct_count_name = '' |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 195 | member_num = 0 |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 196 | (cur_char, targ_type) = line.strip().split(None, 1) |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 197 | if 'tmp_struct' == base_type: |
| 198 | base_type = targ_type.strip(';') |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 199 | if True in [ex_type in base_type for ex_type in exclude_struct_list]: |
| 200 | del self.struct_dict['tmp_struct'] |
| 201 | continue |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 202 | #print("Found Actual Struct type %s" % base_type) |
| 203 | self.struct_dict[base_type] = self.struct_dict['tmp_struct'] |
| 204 | self.struct_dict.pop('tmp_struct', 0) |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 205 | struct_order_list.append(base_type) |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 206 | self.types_dict[base_type] = 'struct' |
| 207 | self.types_dict.pop('tmp_struct', 0) |
| 208 | elif 'tmp_enum' == base_type: |
| 209 | base_type = targ_type.strip(';') |
| 210 | #print("Found Actual ENUM type %s" % base_type) |
| 211 | for n in self.enum_val_dict: |
| 212 | if 'tmp_enum' == self.enum_val_dict[n]['type']: |
| 213 | self.enum_val_dict[n]['type'] = base_type |
| 214 | # self.enum_val_dict[base_type] = self.enum_val_dict['tmp_enum'] |
| 215 | # self.enum_val_dict.pop('tmp_enum', 0) |
| 216 | self.enum_type_dict[base_type] = self.enum_type_dict['tmp_enum'] |
| 217 | self.enum_type_dict.pop('tmp_enum', 0) |
| 218 | self.types_dict[base_type] = 'enum' |
| 219 | self.types_dict.pop('tmp_enum', 0) |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 220 | if ifdef_active: |
| 221 | ifdef_dict[base_type] = ifdef_txt |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 222 | self.typedef_fwd_dict[base_type] = targ_type.strip(';') |
| 223 | self.typedef_rev_dict[targ_type.strip(';')] = base_type |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 224 | #print("fwd_dict: %s = %s" % (base_type, targ_type)) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 225 | elif parse_enum: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 226 | #if 'VK_MAX_ENUM' not in line and '{' not in line: |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 227 | if True not in [ens in line for ens in ['{', '_MAX_ENUM', '_BEGIN_RANGE', '_END_RANGE', '_NUM = ', '_ENUM_RANGE']]: |
Jon Ashburn | fe6113c | 2015-01-09 09:11:44 -0700 | [diff] [blame] | 228 | self._add_enum(line, base_type, default_enum_val) |
| 229 | default_enum_val += 1 |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 230 | elif parse_struct: |
| 231 | if ';' in line: |
| 232 | self._add_struct(line, base_type, member_num) |
| 233 | member_num = member_num + 1 |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 234 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 235 | # populate enum dicts based on enum lines |
Jon Ashburn | fe6113c | 2015-01-09 09:11:44 -0700 | [diff] [blame] | 236 | def _add_enum(self, line_txt, enum_type, def_enum_val): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 237 | #print("Parsing enum line %s" % line_txt) |
Jon Ashburn | fe6113c | 2015-01-09 09:11:44 -0700 | [diff] [blame] | 238 | if '=' in line_txt: |
| 239 | (enum_name, eq_char, enum_val) = line_txt.split(None, 2) |
| 240 | else: |
| 241 | enum_name = line_txt.split(',')[0] |
| 242 | enum_val = str(def_enum_val) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 243 | self.enum_val_dict[enum_name] = {} |
| 244 | self.enum_val_dict[enum_name]['type'] = enum_type |
| 245 | # strip comma and comment, then extra split in case of no comma w/ comments |
| 246 | enum_val = enum_val.strip().split(',', 1)[0] |
| 247 | self.enum_val_dict[enum_name]['val'] = enum_val.split()[0] |
Tobin Ehlis | d335065 | 2015-04-22 13:59:43 -0600 | [diff] [blame] | 248 | # Perform conversion of VK_BIT macro |
| 249 | if 'VK_BIT' in self.enum_val_dict[enum_name]['val']: |
| 250 | vk_bit_val = self.enum_val_dict[enum_name]['val'] |
| 251 | bit_shift = int(vk_bit_val[vk_bit_val.find('(')+1:vk_bit_val.find(')')], 0) |
| 252 | self.enum_val_dict[enum_name]['val'] = str(1 << bit_shift) |
| 253 | else: |
| 254 | # account for negative values surrounded by parens |
| 255 | self.enum_val_dict[enum_name]['val'] = self.enum_val_dict[enum_name]['val'].strip(')').replace('-(', '-') |
Tobin Ehlis | 43ebcac | 2014-12-05 12:13:07 -0700 | [diff] [blame] | 256 | # Try to cast to int to determine if enum value is unique |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 257 | try: |
| 258 | #print("ENUM val:", self.enum_val_dict[enum_name]['val']) |
| 259 | int(self.enum_val_dict[enum_name]['val'], 0) |
| 260 | self.enum_val_dict[enum_name]['unique'] = True |
| 261 | #print("ENUM has num value") |
| 262 | except ValueError: |
| 263 | self.enum_val_dict[enum_name]['unique'] = False |
| 264 | #print("ENUM is not a number value") |
| 265 | # Update enum_type_dict as well |
| 266 | if not enum_type in self.enum_type_dict: |
| 267 | self.enum_type_dict[enum_type] = [] |
| 268 | self.enum_type_dict[enum_type].append(enum_name) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 269 | |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 270 | # Return True if struct member is a dynamic array |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 271 | # RULES : This is a bit quirky based on the API |
| 272 | # NOTE : Changes in API spec may cause these rules to change |
| 273 | # 1. There must be a previous uint var w/ 'count' in the name in the struct |
| 274 | # 2. Dynam array must have 'const' and '*' qualifiers |
| 275 | # 3a. Name of dynam array must end in 's' char OR |
| 276 | # 3b. Name of count var minus 'count' must be contained in name of dynamic array |
| 277 | def _is_dynamic_array(self, full_type, name): |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 278 | exceptions = ['pEnabledFeatures', 'pWaitDstStageMask', 'pSampleMask'] |
| 279 | if name in exceptions: |
| 280 | return False |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 281 | if '' != self.last_struct_count_name: |
| 282 | if 'const' in full_type and '*' in full_type: |
| 283 | if name.endswith('s') or self.last_struct_count_name.lower().replace('count', '') in name.lower(): |
| 284 | return True |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 285 | |
| 286 | # VkWriteDescriptorSet |
| 287 | if self.last_struct_count_name == "descriptorCount": |
| 288 | return True |
| 289 | |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 290 | return False |
| 291 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 292 | # populate struct dicts based on struct lines |
| 293 | # TODO : Handle ":" bitfield, "**" ptr->ptr and "const type*const*" |
| 294 | def _add_struct(self, line_txt, struct_type, num): |
| 295 | #print("Parsing struct line %s" % line_txt) |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 296 | if '{' == struct_type: |
| 297 | print("Parsing struct '{' w/ line %s" % line_txt) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 298 | if not struct_type in self.struct_dict: |
| 299 | self.struct_dict[struct_type] = {} |
| 300 | members = line_txt.strip().split(';', 1)[0] # first strip semicolon & comments |
| 301 | # TODO : Handle bitfields more correctly |
| 302 | members = members.strip().split(':', 1)[0] # strip bitfield element |
| 303 | (member_type, member_name) = members.rsplit(None, 1) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 304 | # Store counts to help recognize and size dynamic arrays |
Tobin Ehlis | b493438 | 2015-04-15 16:01:16 -0600 | [diff] [blame] | 305 | if 'count' in member_name.lower() and 'samplecount' != member_name.lower() and 'uint' in member_type: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 306 | self.last_struct_count_name = member_name |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 307 | self.struct_dict[struct_type][num] = {} |
| 308 | self.struct_dict[struct_type][num]['full_type'] = member_type |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 309 | self.struct_dict[struct_type][num]['dyn_array'] = False |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 310 | if '*' in member_type: |
| 311 | self.struct_dict[struct_type][num]['ptr'] = True |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 312 | # TODO : Need more general purpose way here to reduce down to basic type |
| 313 | member_type = member_type.replace(' const*', '') |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 314 | member_type = member_type.strip('*') |
| 315 | else: |
| 316 | self.struct_dict[struct_type][num]['ptr'] = False |
| 317 | if 'const' in member_type: |
| 318 | self.struct_dict[struct_type][num]['const'] = True |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 319 | member_type = member_type.replace('const', '').strip() |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 320 | else: |
| 321 | self.struct_dict[struct_type][num]['const'] = False |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 322 | # TODO : There is a bug here where it seems that at the time we do this check, |
| 323 | # the data is not in the types or typedef_rev_dict, so we never pass this if check |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 324 | if is_type(member_type, 'struct'): |
| 325 | self.struct_dict[struct_type][num]['struct'] = True |
| 326 | else: |
| 327 | self.struct_dict[struct_type][num]['struct'] = False |
| 328 | self.struct_dict[struct_type][num]['type'] = member_type |
| 329 | if '[' in member_name: |
| 330 | (member_name, array_size) = member_name.split('[', 1) |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 331 | #if 'char' in member_type: |
| 332 | # self.struct_dict[struct_type][num]['array'] = False |
| 333 | # self.struct_dict[struct_type][num]['array_size'] = 0 |
| 334 | # self.struct_dict[struct_type][num]['ptr'] = True |
| 335 | #else: |
| 336 | self.struct_dict[struct_type][num]['array'] = True |
| 337 | self.struct_dict[struct_type][num]['array_size'] = array_size.strip(']') |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 338 | elif self._is_dynamic_array(self.struct_dict[struct_type][num]['full_type'], member_name): |
| 339 | #print("Found dynamic array %s of size %s" % (member_name, self.last_struct_count_name)) |
| 340 | self.struct_dict[struct_type][num]['array'] = True |
| 341 | self.struct_dict[struct_type][num]['dyn_array'] = True |
| 342 | self.struct_dict[struct_type][num]['array_size'] = self.last_struct_count_name |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 343 | elif not 'array' in self.struct_dict[struct_type][num]: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 344 | self.struct_dict[struct_type][num]['array'] = False |
| 345 | self.struct_dict[struct_type][num]['array_size'] = 0 |
| 346 | self.struct_dict[struct_type][num]['name'] = member_name |
| 347 | |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 348 | # check if given identifier is of specified type_to_check |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 349 | def is_type(identifier, type_to_check): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 350 | if identifier in types_dict and type_to_check == types_dict[identifier]: |
| 351 | return True |
| 352 | if identifier in typedef_rev_dict: |
| 353 | new_id = typedef_rev_dict[identifier] |
| 354 | if new_id in types_dict and type_to_check == types_dict[new_id]: |
| 355 | return True |
| 356 | return False |
| 357 | |
| 358 | # This is a validation function to verify that we can reproduce the original structs |
| 359 | def recreate_structs(): |
| 360 | for struct_name in struct_dict: |
| 361 | sys.stdout.write("typedef struct %s\n{\n" % struct_name) |
| 362 | for mem_num in sorted(struct_dict[struct_name]): |
| 363 | sys.stdout.write(" ") |
| 364 | if struct_dict[struct_name][mem_num]['const']: |
| 365 | sys.stdout.write("const ") |
| 366 | #if struct_dict[struct_name][mem_num]['struct']: |
| 367 | # sys.stdout.write("struct ") |
| 368 | sys.stdout.write (struct_dict[struct_name][mem_num]['type']) |
| 369 | if struct_dict[struct_name][mem_num]['ptr']: |
| 370 | sys.stdout.write("*") |
| 371 | sys.stdout.write(" ") |
| 372 | sys.stdout.write(struct_dict[struct_name][mem_num]['name']) |
| 373 | if struct_dict[struct_name][mem_num]['array']: |
| 374 | sys.stdout.write("[") |
| 375 | sys.stdout.write(struct_dict[struct_name][mem_num]['array_size']) |
| 376 | sys.stdout.write("]") |
| 377 | sys.stdout.write(";\n") |
| 378 | sys.stdout.write("} ") |
| 379 | sys.stdout.write(typedef_fwd_dict[struct_name]) |
| 380 | sys.stdout.write(";\n\n") |
| 381 | |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 382 | # |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 383 | # TODO: Fix construction of struct name |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 384 | def get_struct_name_from_struct_type(struct_type): |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 385 | # Note: All struct types are now camel-case |
Karl Schultz | 7b74e11 | 2016-02-12 13:50:13 -0700 | [diff] [blame] | 386 | # Debug Report has an inconsistency - so need special case. |
| 387 | if ("VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT" == struct_type): |
| 388 | return "VkDebugReportCallbackCreateInfoEXT" |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 389 | caps_struct_name = struct_type.replace("_STRUCTURE_TYPE", "") |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 390 | char_idx = 0 |
| 391 | struct_name = '' |
| 392 | for char in caps_struct_name: |
| 393 | if (0 == char_idx) or (caps_struct_name[char_idx-1] == '_'): |
| 394 | struct_name += caps_struct_name[char_idx] |
| 395 | elif (caps_struct_name[char_idx] == '_'): |
| 396 | pass |
| 397 | else: |
| 398 | struct_name += caps_struct_name[char_idx].lower() |
| 399 | char_idx += 1 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 400 | |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 401 | return struct_name |
| 402 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 403 | # class for writing common file elements |
| 404 | # Here's how this class lays out a file: |
| 405 | # COPYRIGHT |
| 406 | # HEADER |
| 407 | # BODY |
| 408 | # FOOTER |
| 409 | # |
| 410 | # For each of these sections, there's a "set*" function |
| 411 | # The class as a whole has a generate function which will write each section in order |
| 412 | class CommonFileGen: |
| 413 | def __init__(self, filename=None, copyright_txt="", header_txt="", body_txt="", footer_txt=""): |
| 414 | self.filename = filename |
| 415 | self.contents = {'copyright': copyright_txt, 'header': header_txt, 'body': body_txt, 'footer': footer_txt} |
| 416 | # TODO : Set a default copyright & footer at least |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 417 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 418 | def setFilename(self, filename): |
| 419 | self.filename = filename |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 420 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 421 | def setCopyright(self, c): |
| 422 | self.contents['copyright'] = c |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 423 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 424 | def setHeader(self, h): |
| 425 | self.contents['header'] = h |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 426 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 427 | def setBody(self, b): |
| 428 | self.contents['body'] = b |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 429 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 430 | def setFooter(self, f): |
| 431 | self.contents['footer'] = f |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 432 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 433 | def generate(self): |
| 434 | #print("Generate to file %s" % self.filename) |
| 435 | with open(self.filename, "w") as f: |
| 436 | f.write(self.contents['copyright']) |
| 437 | f.write(self.contents['header']) |
| 438 | f.write(self.contents['body']) |
| 439 | f.write(self.contents['footer']) |
| 440 | |
| 441 | # class for writing a wrapper class for structures |
| 442 | # The wrapper class wraps the structs and includes utility functions for |
| 443 | # setting/getting member values and displaying the struct data in various formats |
| 444 | class StructWrapperGen: |
| 445 | def __init__(self, in_struct_dict, prefix, out_dir): |
| 446 | self.struct_dict = in_struct_dict |
| 447 | self.include_headers = [] |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 448 | self.lineinfo = sourcelineinfo() |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 449 | self.api = prefix |
Courtney Goeltzenleuchter | dba7998 | 2015-04-14 16:30:53 -0600 | [diff] [blame] | 450 | if prefix.lower() == "vulkan": |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 451 | self.api_prefix = "vk" |
| 452 | else: |
| 453 | self.api_prefix = prefix |
| 454 | self.header_filename = os.path.join(out_dir, self.api_prefix+"_struct_wrappers.h") |
| 455 | self.class_filename = os.path.join(out_dir, self.api_prefix+"_struct_wrappers.cpp") |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 456 | self.safe_struct_header_filename = os.path.join(out_dir, self.api_prefix+"_safe_struct.h") |
| 457 | self.safe_struct_source_filename = os.path.join(out_dir, self.api_prefix+"_safe_struct.cpp") |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 458 | self.string_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper.h") |
| 459 | self.string_helper_no_addr_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper_no_addr.h") |
| 460 | self.string_helper_cpp_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper_cpp.h") |
| 461 | self.string_helper_no_addr_cpp_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper_no_addr_cpp.h") |
| 462 | self.validate_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_validate_helper.h") |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 463 | self.no_addr = False |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 464 | # Safe Struct (ss) header and source files |
| 465 | self.ssh = CommonFileGen(self.safe_struct_header_filename) |
| 466 | self.sss = CommonFileGen(self.safe_struct_source_filename) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 467 | self.hfg = CommonFileGen(self.header_filename) |
| 468 | self.cfg = CommonFileGen(self.class_filename) |
| 469 | self.shg = CommonFileGen(self.string_helper_filename) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 470 | self.shcppg = CommonFileGen(self.string_helper_cpp_filename) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 471 | self.vhg = CommonFileGen(self.validate_helper_filename) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 472 | self.size_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_size_helper.h") |
| 473 | self.size_helper_c_filename = os.path.join(out_dir, self.api_prefix+"_struct_size_helper.c") |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 474 | self.size_helper_gen = CommonFileGen(self.size_helper_filename) |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 475 | self.size_helper_c_gen = CommonFileGen(self.size_helper_c_filename) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 476 | #print(self.header_filename) |
| 477 | self.header_txt = "" |
| 478 | self.definition_txt = "" |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 479 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 480 | def set_include_headers(self, include_headers): |
| 481 | self.include_headers = include_headers |
| 482 | |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 483 | def set_no_addr(self, no_addr): |
| 484 | self.no_addr = no_addr |
| 485 | if self.no_addr: |
| 486 | self.shg = CommonFileGen(self.string_helper_no_addr_filename) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 487 | self.shcppg = CommonFileGen(self.string_helper_no_addr_cpp_filename) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 488 | else: |
| 489 | self.shg = CommonFileGen(self.string_helper_filename) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 490 | self.shcppg = CommonFileGen(self.string_helper_cpp_filename) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 491 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 492 | # Return class name for given struct name |
| 493 | def get_class_name(self, struct_name): |
| 494 | class_name = struct_name.strip('_').lower() + "_struct_wrapper" |
| 495 | return class_name |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 496 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 497 | def get_file_list(self): |
| 498 | return [os.path.basename(self.header_filename), os.path.basename(self.class_filename), os.path.basename(self.string_helper_filename)] |
| 499 | |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 500 | # Generate class header file |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 501 | def generateHeader(self): |
| 502 | self.hfg.setCopyright(self._generateCopyright()) |
| 503 | self.hfg.setHeader(self._generateHeader()) |
| 504 | self.hfg.setBody(self._generateClassDeclaration()) |
| 505 | self.hfg.setFooter(self._generateFooter()) |
| 506 | self.hfg.generate() |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 507 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 508 | # Generate class definition |
| 509 | def generateBody(self): |
| 510 | self.cfg.setCopyright(self._generateCopyright()) |
| 511 | self.cfg.setHeader(self._generateCppHeader()) |
| 512 | self.cfg.setBody(self._generateClassDefinition()) |
| 513 | self.cfg.setFooter(self._generateFooter()) |
| 514 | self.cfg.generate() |
| 515 | |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 516 | # Safe Structs are versions of vulkan structs with non-const safe ptrs |
| 517 | # that make shadowing structures and clean-up of shadowed structures very simple |
| 518 | def generateSafeStructHeader(self): |
| 519 | self.ssh.setCopyright(self._generateCopyright()) |
| 520 | self.ssh.setHeader(self._generateSafeStructHeader()) |
| 521 | self.ssh.setBody(self._generateSafeStructDecls()) |
| 522 | self.ssh.generate() |
| 523 | |
| 524 | def generateSafeStructs(self): |
| 525 | self.sss.setCopyright(self._generateCopyright()) |
| 526 | self.sss.setHeader(self._generateSafeStructSourceHeader()) |
| 527 | self.sss.setBody(self._generateSafeStructSource()) |
| 528 | self.sss.generate() |
| 529 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 530 | # Generate c-style .h file that contains functions for printing structs |
| 531 | def generateStringHelper(self): |
| 532 | print("Generating struct string helper") |
| 533 | self.shg.setCopyright(self._generateCopyright()) |
| 534 | self.shg.setHeader(self._generateStringHelperHeader()) |
| 535 | self.shg.setBody(self._generateStringHelperFunctions()) |
| 536 | self.shg.generate() |
| 537 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 538 | # Generate cpp-style .h file that contains functions for printing structs |
| 539 | def generateStringHelperCpp(self): |
| 540 | print("Generating struct string helper cpp") |
| 541 | self.shcppg.setCopyright(self._generateCopyright()) |
| 542 | self.shcppg.setHeader(self._generateStringHelperHeaderCpp()) |
| 543 | self.shcppg.setBody(self._generateStringHelperFunctionsCpp()) |
| 544 | self.shcppg.generate() |
| 545 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 546 | # Generate c-style .h file that contains functions for printing structs |
| 547 | def generateValidateHelper(self): |
| 548 | print("Generating struct validate helper") |
| 549 | self.vhg.setCopyright(self._generateCopyright()) |
| 550 | self.vhg.setHeader(self._generateValidateHelperHeader()) |
| 551 | self.vhg.setBody(self._generateValidateHelperFunctions()) |
| 552 | self.vhg.generate() |
| 553 | |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 554 | def generateSizeHelper(self): |
| 555 | print("Generating struct size helper") |
| 556 | self.size_helper_gen.setCopyright(self._generateCopyright()) |
| 557 | self.size_helper_gen.setHeader(self._generateSizeHelperHeader()) |
| 558 | self.size_helper_gen.setBody(self._generateSizeHelperFunctions()) |
| 559 | self.size_helper_gen.generate() |
| 560 | |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 561 | def generateSizeHelperC(self): |
| 562 | print("Generating struct size helper c") |
| 563 | self.size_helper_c_gen.setCopyright(self._generateCopyright()) |
| 564 | self.size_helper_c_gen.setHeader(self._generateSizeHelperHeaderC()) |
| 565 | self.size_helper_c_gen.setBody(self._generateSizeHelperFunctionsC()) |
| 566 | self.size_helper_c_gen.generate() |
| 567 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 568 | def _generateCopyright(self): |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 569 | copyright = [] |
| 570 | copyright.append('/* THIS FILE IS GENERATED. DO NOT EDIT. */'); |
| 571 | copyright.append(''); |
| 572 | copyright.append('/*'); |
Ian Elliott | 0977abc | 2015-04-15 11:15:13 -0600 | [diff] [blame] | 573 | copyright.append(' * Vulkan'); |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 574 | copyright.append(' *'); |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 575 | copyright.append(' * Copyright (c) 2015-2016 The Khronos Group Inc.'); |
| 576 | copyright.append(' * Copyright (c) 2015-2016 Valve Corporation.'); |
| 577 | copyright.append(' * Copyright (c) 2015-2016 LunarG, Inc.'); |
| 578 | copyright.append(' * Copyright (c) 2015-2016 Google Inc.'); |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 579 | copyright.append(' *'); |
| 580 | copyright.append(' * Permission is hereby granted, free of charge, to any person obtaining a'); |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 581 | copyright.append(' * copy of this software and associated documentation files (the "Materials"),'); |
| 582 | copyright.append(' * to deal in the Materials without restriction, including without limitation'); |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 583 | copyright.append(' * the rights to use, copy, modify, merge, publish, distribute, sublicense,'); |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 584 | copyright.append(' * and/or sell copies of the Materials, and to permit persons to whom the'); |
| 585 | copyright.append(' * Materials is furnished to do so, subject to the following conditions:'); |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 586 | copyright.append(' *'); |
| 587 | copyright.append(' * The above copyright notice and this permission notice shall be included'); |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 588 | copyright.append(' * in all copies or substantial portions of the Materials.'); |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 589 | copyright.append(' *'); |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 590 | copyright.append(' * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR'); |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 591 | copyright.append(' * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,'); |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 592 | copyright.append(' * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.'); |
| 593 | copyright.append(' *'); |
| 594 | copyright.append(' * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,'); |
| 595 | copyright.append(' * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR'); |
| 596 | copyright.append(' * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE'); |
| 597 | copyright.append(' * USE OR OTHER DEALINGS IN THE MATERIALS'); |
| 598 | copyright.append(' *'); |
| 599 | copyright.append(' * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>'); |
| 600 | copyright.append(' * Author: Tobin Ehlis <tobin@lunarg.com>'); |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 601 | copyright.append(' */'); |
| 602 | copyright.append(''); |
| 603 | return "\n".join(copyright) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 604 | |
| 605 | def _generateCppHeader(self): |
| 606 | header = [] |
| 607 | header.append("//#includes, #defines, globals and such...\n") |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 608 | header.append("#include <stdio.h>\n#include <%s>\n#include <%s_enum_string_helper.h>\n" % (os.path.basename(self.header_filename), self.api_prefix)) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 609 | return "".join(header) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 610 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 611 | def _generateClassDefinition(self): |
| 612 | class_def = [] |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 613 | if 'vk' == self.api: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 614 | class_def.append(self._generateDynamicPrintFunctions()) |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 615 | for s in sorted(self.struct_dict): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 616 | class_def.append("\n// %s class definition" % self.get_class_name(s)) |
| 617 | class_def.append(self._generateConstructorDefinitions(s)) |
| 618 | class_def.append(self._generateDestructorDefinitions(s)) |
| 619 | class_def.append(self._generateDisplayDefinitions(s)) |
| 620 | return "\n".join(class_def) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 621 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 622 | def _generateConstructorDefinitions(self, s): |
| 623 | con_defs = [] |
| 624 | con_defs.append("%s::%s() : m_struct(), m_indent(0), m_dummy_prefix('\\0'), m_origStructAddr(NULL) {}" % (self.get_class_name(s), self.get_class_name(s))) |
| 625 | # TODO : This is a shallow copy of ptrs |
| 626 | con_defs.append("%s::%s(%s* pInStruct) : m_indent(0), m_dummy_prefix('\\0')\n{\n m_struct = *pInStruct;\n m_origStructAddr = pInStruct;\n}" % (self.get_class_name(s), self.get_class_name(s), typedef_fwd_dict[s])) |
| 627 | con_defs.append("%s::%s(const %s* pInStruct) : m_indent(0), m_dummy_prefix('\\0')\n{\n m_struct = *pInStruct;\n m_origStructAddr = pInStruct;\n}" % (self.get_class_name(s), self.get_class_name(s), typedef_fwd_dict[s])) |
| 628 | return "\n".join(con_defs) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 629 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 630 | def _generateDestructorDefinitions(self, s): |
| 631 | return "%s::~%s() {}" % (self.get_class_name(s), self.get_class_name(s)) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 632 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 633 | def _generateDynamicPrintFunctions(self): |
| 634 | dp_funcs = [] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 635 | dp_funcs.append("\nvoid dynamic_display_full_txt(const void* pStruct, uint32_t indent)\n{\n // Cast to APP_INFO ptr initially just to pull sType off struct") |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 636 | dp_funcs.append(" VkStructureType sType = ((VkApplicationInfo*)pStruct)->sType;\n") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 637 | dp_funcs.append(" switch (sType)\n {") |
| 638 | for e in enum_type_dict: |
| 639 | class_num = 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 640 | if "StructureType" in e: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 641 | for v in sorted(enum_type_dict[e]): |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 642 | struct_name = get_struct_name_from_struct_type(v) |
Chia-I Wu | 736324e | 2015-10-26 20:42:12 +0800 | [diff] [blame] | 643 | if struct_name not in self.struct_dict: |
| 644 | continue |
| 645 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 646 | class_name = self.get_class_name(struct_name) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 647 | instance_name = "swc%i" % class_num |
| 648 | dp_funcs.append(" case %s:\n {" % (v)) |
| 649 | dp_funcs.append(" %s %s((%s*)pStruct);" % (class_name, instance_name, struct_name)) |
| 650 | dp_funcs.append(" %s.set_indent(indent);" % (instance_name)) |
| 651 | dp_funcs.append(" %s.display_full_txt();" % (instance_name)) |
| 652 | dp_funcs.append(" }") |
| 653 | dp_funcs.append(" break;") |
| 654 | class_num += 1 |
| 655 | dp_funcs.append(" }") |
| 656 | dp_funcs.append("}\n") |
| 657 | return "\n".join(dp_funcs) |
| 658 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 659 | def _get_func_name(self, struct, mid_str): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 660 | return "%s_%s_%s" % (self.api_prefix, mid_str, struct.lower().strip("_")) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 661 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 662 | def _get_sh_func_name(self, struct): |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 663 | return self._get_func_name(struct, 'print') |
| 664 | |
| 665 | def _get_vh_func_name(self, struct): |
| 666 | return self._get_func_name(struct, 'validate') |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 667 | |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 668 | def _get_size_helper_func_name(self, struct): |
| 669 | return self._get_func_name(struct, 'size') |
| 670 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 671 | # Return elements to create formatted string for given struct member |
| 672 | def _get_struct_print_formatted(self, struct_member, pre_var_name="prefix", postfix = "\\n", struct_var_name="pStruct", struct_ptr=True, print_array=False): |
| 673 | struct_op = "->" |
| 674 | if not struct_ptr: |
| 675 | struct_op = "." |
| 676 | member_name = struct_member['name'] |
| 677 | print_type = "p" |
| 678 | cast_type = "" |
| 679 | member_post = "" |
| 680 | array_index = "" |
| 681 | member_print_post = "" |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 682 | print_delimiter = "%" |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 683 | if struct_member['array'] and 'char' in struct_member['type'].lower(): # just print char array as string |
| 684 | if member_name.startswith('pp'): # TODO : Only printing first element of dynam array of char* for now |
| 685 | member_post = "[0]" |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 686 | print_type = "s" |
| 687 | print_array = False |
| 688 | elif struct_member['array'] and not print_array: |
| 689 | # Just print base address of array when not full print_array |
| 690 | cast_type = "(void*)" |
| 691 | elif is_type(struct_member['type'], 'enum'): |
| 692 | cast_type = "string_%s" % struct_member['type'] |
Jon Ashburn | fe6113c | 2015-01-09 09:11:44 -0700 | [diff] [blame] | 693 | if struct_member['ptr']: |
| 694 | struct_var_name = "*" + struct_var_name |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 695 | print_type = "s" |
| 696 | elif is_type(struct_member['type'], 'struct'): # print struct address for now |
| 697 | cast_type = "(void*)" |
| 698 | if not struct_member['ptr']: |
| 699 | cast_type = "(void*)&" |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 700 | elif 'bool' in struct_member['type'].lower(): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 701 | print_type = "s" |
| 702 | member_post = ' ? "TRUE" : "FALSE"' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 703 | elif 'float' in struct_member['type']: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 704 | print_type = "f" |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 705 | elif 'uint64' in struct_member['type'] or 'gpusize' in struct_member['type'].lower(): |
| 706 | print_type = '" PRId64 "' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 707 | elif 'uint8' in struct_member['type']: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 708 | print_type = "hu" |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 709 | elif 'size' in struct_member['type'].lower(): |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 710 | print_type = '" PRINTF_SIZE_T_SPECIFIER "' |
| 711 | print_delimiter = "" |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 712 | elif True in [ui_str.lower() in struct_member['type'].lower() for ui_str in ['uint', 'flags', 'samplemask']]: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 713 | print_type = "u" |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 714 | elif 'int' in struct_member['type']: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 715 | print_type = "i" |
| 716 | elif struct_member['ptr']: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 717 | pass |
| 718 | else: |
| 719 | #print("Unhandled struct type: %s" % struct_member['type']) |
| 720 | cast_type = "(void*)" |
| 721 | if print_array and struct_member['array']: |
| 722 | member_print_post = "[%u]" |
| 723 | array_index = " i," |
| 724 | member_post = "[i]" |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 725 | print_out = "%%s%s%s = %s%s%s" % (member_name, member_print_post, print_delimiter, print_type, postfix) # section of print that goes inside of quotes |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 726 | print_arg = ", %s,%s %s(%s%s%s)%s" % (pre_var_name, array_index, cast_type, struct_var_name, struct_op, member_name, member_post) # section of print passed to portion in quotes |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 727 | if self.no_addr and "p" == print_type: |
| 728 | print_out = "%%s%s%s = addr\\n" % (member_name, member_print_post) # section of print that goes inside of quotes |
| 729 | print_arg = ", %s" % (pre_var_name) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 730 | return (print_out, print_arg) |
| 731 | |
| 732 | def _generateStringHelperFunctions(self): |
| 733 | sh_funcs = [] |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 734 | # We do two passes, first pass just generates prototypes for all the functsions |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 735 | for s in sorted(self.struct_dict): |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 736 | sh_funcs.append('char* %s(const %s* pStruct, const char* prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s])) |
| 737 | sh_funcs.append('') |
| 738 | sh_funcs.append('#if defined(_WIN32)') |
| 739 | sh_funcs.append('// Microsoft did not implement C99 in Visual Studio; but started adding it with') |
| 740 | sh_funcs.append('// VS2013. However, VS2013 still did not have snprintf(). The following is a') |
| 741 | sh_funcs.append('// work-around.') |
| 742 | sh_funcs.append('#define snprintf _snprintf') |
| 743 | sh_funcs.append('#endif // _WIN32\n') |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 744 | for s in sorted(self.struct_dict): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 745 | p_out = "" |
| 746 | p_args = "" |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 747 | stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 748 | # This pre-pass flags embedded structs and pNext |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 749 | for m in sorted(self.struct_dict[s]): |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 750 | if 'pNext' == self.struct_dict[s][m]['name'] or is_type(self.struct_dict[s][m]['type'], 'struct'): |
| 751 | stp_list.append(self.struct_dict[s][m]) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 752 | sh_funcs.append('char* %s(const %s* pStruct, const char* prefix)\n{\n char* str;' % (self._get_sh_func_name(s), typedef_fwd_dict[s])) |
| 753 | sh_funcs.append(" size_t len;") |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 754 | num_stps = len(stp_list); |
| 755 | total_strlen_str = '' |
| 756 | if 0 != num_stps: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 757 | sh_funcs.append(" char* tmpStr;") |
| 758 | sh_funcs.append(' char* extra_indent = (char*)malloc(strlen(prefix) + 3);') |
| 759 | sh_funcs.append(' strcpy(extra_indent, " ");') |
| 760 | sh_funcs.append(' strncat(extra_indent, prefix, strlen(prefix));') |
| 761 | sh_funcs.append(' char* stp_strs[%i];' % num_stps) |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 762 | for index in range(num_stps): |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 763 | # If it's an array, print all of the elements |
| 764 | # If it's a ptr, print thing it's pointing to |
| 765 | # Non-ptr struct case. Print the struct using its address |
| 766 | struct_deref = '&' |
| 767 | if 1 < stp_list[index]['full_type'].count('*'): |
| 768 | struct_deref = '' |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 769 | if (stp_list[index]['ptr']): |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 770 | sh_funcs.append(' if (pStruct->%s) {' % stp_list[index]['name']) |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 771 | if 'pNext' == stp_list[index]['name']: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 772 | sh_funcs.append(' tmpStr = dynamic_display((void*)pStruct->pNext, prefix);') |
| 773 | sh_funcs.append(' len = 256+strlen(tmpStr);') |
| 774 | sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % index) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 775 | if self.no_addr: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 776 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%spNext (addr)\\n%%s", prefix, tmpStr);' % index) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 777 | else: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 778 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%spNext (%%p)\\n%%s", prefix, (void*)pStruct->pNext, tmpStr);' % index) |
| 779 | sh_funcs.append(' free(tmpStr);') |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 780 | else: |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 781 | if stp_list[index]['name'] in ['pImageViews', 'pBufferViews']: |
| 782 | # TODO : This is a quick hack to handle these arrays of ptrs |
Courtney Goeltzenleuchter | eeae16b | 2015-04-02 22:54:15 -0600 | [diff] [blame] | 783 | sh_funcs.append(' tmpStr = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 784 | else: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 785 | sh_funcs.append(' tmpStr = %s(pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
| 786 | sh_funcs.append(' len = 256+strlen(tmpStr)+strlen(prefix);') |
| 787 | sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index)) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 788 | if self.no_addr: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 789 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (addr)\\n%%s", prefix, tmpStr);' % (index, stp_list[index]['name'])) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 790 | else: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 791 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (%%p)\\n%%s", prefix, (void*)pStruct->%s, tmpStr);' % (index, stp_list[index]['name'], stp_list[index]['name'])) |
| 792 | sh_funcs.append(' }') |
| 793 | sh_funcs.append(" else\n stp_strs[%i] = \"\";" % (index)) |
| 794 | elif stp_list[index]['array']: |
| 795 | sh_funcs.append(' tmpStr = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
| 796 | sh_funcs.append(' len = 256+strlen(tmpStr);') |
| 797 | sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index)) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 798 | if self.no_addr: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 799 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s[0] (addr)\\n%%s", prefix, tmpStr);' % (index, stp_list[index]['name'])) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 800 | else: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 801 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s[0] (%%p)\\n%%s", prefix, (void*)&pStruct->%s[0], tmpStr);' % (index, stp_list[index]['name'], stp_list[index]['name'])) |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 802 | else: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 803 | sh_funcs.append(' tmpStr = %s(&pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
| 804 | sh_funcs.append(' len = 256+strlen(tmpStr);') |
| 805 | sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index)) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 806 | if self.no_addr: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 807 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (addr)\\n%%s", prefix, tmpStr);' % (index, stp_list[index]['name'])) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 808 | else: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 809 | sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (%%p)\\n%%s", prefix, (void*)&pStruct->%s, tmpStr);' % (index, stp_list[index]['name'], stp_list[index]['name'])) |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 810 | total_strlen_str += 'strlen(stp_strs[%i]) + ' % index |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 811 | sh_funcs.append(' len = %ssizeof(char)*1024;' % (total_strlen_str)) |
| 812 | sh_funcs.append(' str = (char*)malloc(len);') |
Courtney Goeltzenleuchter | bbd0a36 | 2014-12-01 09:31:17 -0700 | [diff] [blame] | 813 | sh_funcs.append(' snprintf(str, len, "') |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 814 | for m in sorted(self.struct_dict[s]): |
| 815 | (p_out1, p_args1) = self._get_struct_print_formatted(self.struct_dict[s][m]) |
| 816 | p_out += p_out1 |
| 817 | p_args += p_args1 |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 818 | p_out += '"' |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 819 | p_args += ");" |
| 820 | sh_funcs[-1] = '%s%s%s' % (sh_funcs[-1], p_out, p_args) |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 821 | if 0 != num_stps: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 822 | sh_funcs.append(' for (int32_t stp_index = %i; stp_index >= 0; stp_index--) {' % (num_stps-1)) |
| 823 | sh_funcs.append(' if (0 < strlen(stp_strs[stp_index])) {') |
| 824 | sh_funcs.append(' strncat(str, stp_strs[stp_index], strlen(stp_strs[stp_index]));') |
| 825 | sh_funcs.append(' free(stp_strs[stp_index]);') |
| 826 | sh_funcs.append(' }') |
| 827 | sh_funcs.append(' }') |
| 828 | sh_funcs.append(' free(extra_indent);') |
| 829 | sh_funcs.append(" return str;\n}") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 830 | # Add function to dynamically print out unknown struct |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 831 | sh_funcs.append("char* dynamic_display(const void* pStruct, const char* prefix)\n{") |
| 832 | sh_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct") |
| 833 | sh_funcs.append(" if (pStruct == NULL) {") |
| 834 | sh_funcs.append(" return NULL;") |
| 835 | sh_funcs.append(" }") |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 836 | sh_funcs.append(" VkStructureType sType = ((VkApplicationInfo*)pStruct)->sType;") |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 837 | sh_funcs.append(' char indent[100];\n strcpy(indent, " ");\n strcat(indent, prefix);') |
| 838 | sh_funcs.append(" switch (sType)\n {") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 839 | for e in enum_type_dict: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 840 | if "StructureType" in e: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 841 | for v in sorted(enum_type_dict[e]): |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 842 | struct_name = get_struct_name_from_struct_type(v) |
Chia-I Wu | 736324e | 2015-10-26 20:42:12 +0800 | [diff] [blame] | 843 | if struct_name not in self.struct_dict: |
| 844 | continue |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 845 | print_func_name = self._get_sh_func_name(struct_name) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 846 | sh_funcs.append(' case %s:\n {' % (v)) |
| 847 | sh_funcs.append(' return %s((%s*)pStruct, indent);' % (print_func_name, struct_name)) |
| 848 | sh_funcs.append(' }') |
| 849 | sh_funcs.append(' break;') |
| 850 | sh_funcs.append(" default:") |
| 851 | sh_funcs.append(" return NULL;") |
| 852 | sh_funcs.append(" }") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 853 | sh_funcs.append("}") |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 854 | return "\n".join(sh_funcs) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 855 | |
| 856 | def _generateStringHelperFunctionsCpp(self): |
| 857 | # declare str & tmp str |
| 858 | # declare array of stringstreams for every struct ptr in current struct |
| 859 | # declare array of stringstreams for every non-string element in current struct |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 860 | # For every struct ptr, if non-Null, then set its string, else set to NULL str |
| 861 | # For every non-string element, set its string stream |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 862 | # create and return final string |
| 863 | sh_funcs = [] |
| 864 | # First generate prototypes for every struct |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 865 | # XXX - REMOVE this comment |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 866 | lineinfo = sourcelineinfo() |
| 867 | sh_funcs.append('%s' % lineinfo.get()) |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 868 | exclude_struct_list = ['VkAndroidSurfaceCreateInfoKHR', |
| 869 | 'VkMirSurfaceCreateInfoKHR', |
| 870 | 'VkWaylandSurfaceCreateInfoKHR', |
| 871 | 'VkXlibSurfaceCreateInfoKHR'] |
| 872 | if sys.platform == 'win32': |
| 873 | exclude_struct_list.append('VkXcbSurfaceCreateInfoKHR') |
| 874 | else: |
| 875 | exclude_struct_list.append('VkWin32SurfaceCreateInfoKHR') |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 876 | for s in sorted(self.struct_dict): |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 877 | if (typedef_fwd_dict[s] not in exclude_struct_list): |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 878 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 879 | sh_funcs.append("#ifdef VK_USE_PLATFORM_XCB_KHR") |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 880 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 881 | sh_funcs.append("#ifdef VK_USE_PLATFORM_WIN32_KHR") |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 882 | sh_funcs.append('string %s(const %s* pStruct, const string prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s])) |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 883 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 884 | sh_funcs.append("#endif //VK_USE_PLATFORM_WIN32_KHR") |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 885 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 886 | sh_funcs.append("#endif //VK_USE_PLATFORM_XCB_KHR") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 887 | sh_funcs.append('\n') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 888 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 889 | for s in sorted(self.struct_dict): |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 890 | num_non_enum_elems = [(is_type(self.struct_dict[s][elem]['type'], 'enum') and not self.struct_dict[s][elem]['ptr']) for elem in self.struct_dict[s]].count(False) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 891 | stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 892 | # This pre-pass flags embedded structs and pNext |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 893 | for m in sorted(self.struct_dict[s]): |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 894 | if 'pNext' == self.struct_dict[s][m]['name'] or is_type(self.struct_dict[s][m]['type'], 'struct') or self.struct_dict[s][m]['array']: |
Courtney Goeltzenleuchter | 82e7239 | 2015-07-10 09:06:56 -0600 | [diff] [blame] | 895 | # TODO: This is a tmp workaround |
| 896 | if 'ppActiveLayerNames' not in self.struct_dict[s][m]['name']: |
| 897 | stp_list.append(self.struct_dict[s][m]) |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 898 | if (typedef_fwd_dict[s] in exclude_struct_list): |
| 899 | continue |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 900 | sh_funcs.append('%s' % lineinfo.get()) |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 901 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 902 | sh_funcs.append("#ifdef VK_USE_PLATFORM_XCB_KHR") |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 903 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 904 | sh_funcs.append("#ifdef VK_USE_PLATFORM_WIN32_KHR") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 905 | sh_funcs.append('string %s(const %s* pStruct, const string prefix)\n{' % (self._get_sh_func_name(s), typedef_fwd_dict[s])) |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 906 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 907 | indent = ' ' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 908 | sh_funcs.append('%susing namespace StreamControl;' % (indent)) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 909 | sh_funcs.append('%sstring final_str;' % (indent)) |
| 910 | sh_funcs.append('%sstring tmp_str;' % (indent)) |
| 911 | sh_funcs.append('%sstring extra_indent = " " + prefix;' % (indent)) |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 912 | if (0 != num_non_enum_elems): |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 913 | sh_funcs.append('%sstringstream ss[%u];' % (indent, num_non_enum_elems)) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 914 | num_stps = len(stp_list) |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 915 | # First generate code for any embedded structs or arrays |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 916 | if 0 < num_stps: |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 917 | sh_funcs.append('%sstring stp_strs[%u];' % (indent, num_stps)) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 918 | idx_ss_decl = False # Make sure to only decl this once |
| 919 | for index in range(num_stps): |
| 920 | addr_char = '&' |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 921 | if 1 < stp_list[index]['full_type'].count('*'): |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 922 | addr_char = '' |
Tobin Ehlis | f03e8cd | 2015-06-30 15:28:00 -0600 | [diff] [blame] | 923 | if stp_list[index]['array']: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 924 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 925 | if stp_list[index]['dyn_array']: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 926 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 927 | array_count = 'pStruct->%s' % (stp_list[index]['array_size']) |
| 928 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 929 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 930 | array_count = '%s' % (stp_list[index]['array_size']) |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 931 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 932 | sh_funcs.append('%sstp_strs[%u] = "";' % (indent, index)) |
| 933 | if not idx_ss_decl: |
| 934 | sh_funcs.append('%sstringstream index_ss;' % (indent)) |
| 935 | idx_ss_decl = True |
Mark Lobodzinski | 74dfa18 | 2015-08-11 09:35:02 -0600 | [diff] [blame] | 936 | if (stp_list[index]['name'] == 'pQueueFamilyIndices'): |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 937 | if (typedef_fwd_dict[s] == 'VkSwapchainCreateInfoKHR'): |
| 938 | sh_funcs.append('%sif (pStruct->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {' % (indent)) |
| 939 | else: |
| 940 | sh_funcs.append('%sif (pStruct->sharingMode == VK_SHARING_MODE_CONCURRENT) {' % (indent)) |
Mark Lobodzinski | 74dfa18 | 2015-08-11 09:35:02 -0600 | [diff] [blame] | 941 | indent += ' ' |
Mark Lobodzinski | 80971c6 | 2016-01-08 14:52:49 -0700 | [diff] [blame] | 942 | if (stp_list[index]['name'] == 'pImageInfo'): |
| 943 | sh_funcs.append('%sif ((pStruct->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||' % (indent)) |
| 944 | sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||' % (indent)) |
| 945 | sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||' % (indent)) |
| 946 | sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE)) {' % (indent)) |
| 947 | indent += ' ' |
| 948 | elif (stp_list[index]['name'] == 'pBufferInfo'): |
| 949 | sh_funcs.append('%sif ((pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||' % (indent)) |
| 950 | sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||' % (indent)) |
| 951 | sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||' % (indent)) |
| 952 | sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {' % (indent)) |
| 953 | indent += ' ' |
| 954 | elif (stp_list[index]['name'] == 'pTexelBufferView'): |
| 955 | sh_funcs.append('%sif ((pStruct->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||' % (indent)) |
| 956 | sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {' % (indent)) |
| 957 | indent += ' ' |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 958 | if stp_list[index]['dyn_array']: |
| 959 | sh_funcs.append('%sif (pStruct->%s) {' % (indent, stp_list[index]['name'])) |
| 960 | indent += ' ' |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 961 | sh_funcs.append('%sfor (uint32_t i = 0; i < %s; i++) {' % (indent, array_count)) |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 962 | indent += ' ' |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 963 | sh_funcs.append('%sindex_ss.str("");' % (indent)) |
| 964 | sh_funcs.append('%sindex_ss << i;' % (indent)) |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 965 | if is_type(stp_list[index]['type'], 'enum'): |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 966 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 967 | addr_char = '' |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 968 | #value_print = 'string_%s(%spStruct->%s)' % (self.struct_dict[s][m]['type'], deref, self.struct_dict[s][m]['name']) |
| 969 | sh_funcs.append('%sss[%u] << string_%s(pStruct->%s[i]);' % (indent, index, stp_list[index]['type'], stp_list[index]['name'])) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 970 | sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] = " + ss[%u].str() + "\\n";' % (indent, index, stp_list[index]['name'], index)) |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 971 | elif is_type(stp_list[index]['type'], 'struct'): |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 972 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 973 | sh_funcs.append('%sss[%u] << %spStruct->%s[i];' % (indent, index, addr_char, stp_list[index]['name'])) |
| 974 | sh_funcs.append('%stmp_str = %s(%spStruct->%s[i], extra_indent);' % (indent, self._get_sh_func_name(stp_list[index]['type']), addr_char, stp_list[index]['name'])) |
| 975 | if self.no_addr: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 976 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 977 | sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] (addr)\\n" + tmp_str;' % (indent, index, stp_list[index]['name'])) |
| 978 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 979 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 980 | sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] (" + ss[%u].str() + ")\\n" + tmp_str;' % (indent, index, stp_list[index]['name'], index)) |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 981 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 982 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 983 | addr_char = '' |
Karl Schultz | cb85519 | 2016-03-04 15:20:27 -0700 | [diff] [blame] | 984 | sh_funcs.append('%sss[%u] << %spStruct->%s[i];' % (indent, index, addr_char, stp_list[index]['name'])) |
Courtney Goeltzenleuchter | 4498155 | 2015-10-23 15:48:32 -0600 | [diff] [blame] | 985 | if stp_list[index]['type'] in vulkan.core.objects: |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 986 | sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "].handle = " + ss[%u].str() + "\\n";' % (indent, index, stp_list[index]['name'], index)) |
| 987 | else: |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 988 | sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] = " + ss[%u].str() + "\\n";' % (indent, index, stp_list[index]['name'], index)) |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 989 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 990 | sh_funcs.append('%sss[%u].str("");' % (indent, index)) |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 991 | indent = indent[4:] |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 992 | sh_funcs.append('%s}' % (indent)) |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 993 | if stp_list[index]['dyn_array']: |
| 994 | indent = indent[4:] |
| 995 | sh_funcs.append('%s}' % (indent)) |
Mark Lobodzinski | 74dfa18 | 2015-08-11 09:35:02 -0600 | [diff] [blame] | 996 | #endif |
Mark Lobodzinski | 80971c6 | 2016-01-08 14:52:49 -0700 | [diff] [blame] | 997 | if (stp_list[index]['name'] == 'pQueueFamilyIndices') or (stp_list[index]['name'] == 'pImageInfo') or (stp_list[index]['name'] == 'pBufferInfo') or (stp_list[index]['name'] == 'pTexelBufferView'): |
Mark Lobodzinski | 74dfa18 | 2015-08-11 09:35:02 -0600 | [diff] [blame] | 998 | indent = indent[4:] |
| 999 | sh_funcs.append('%s}' % (indent)) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 1000 | elif (stp_list[index]['ptr']): |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1001 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | f03e8cd | 2015-06-30 15:28:00 -0600 | [diff] [blame] | 1002 | sh_funcs.append('%sif (pStruct->%s) {' % (indent, stp_list[index]['name'])) |
| 1003 | indent += ' ' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1004 | if 'pNext' == stp_list[index]['name']: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1005 | sh_funcs.append('%s' % lineinfo.get()) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1006 | sh_funcs.append(' tmp_str = dynamic_display((void*)pStruct->pNext, prefix);') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1007 | else: |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 1008 | if stp_list[index]['name'] in ['pImageViews', 'pBufferViews']: |
| 1009 | # TODO : This is a quick hack to handle these arrays of ptrs |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1010 | sh_funcs.append('%s' % lineinfo.get()) |
Courtney Goeltzenleuchter | eeae16b | 2015-04-02 22:54:15 -0600 | [diff] [blame] | 1011 | sh_funcs.append(' tmp_str = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 1012 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1013 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 1014 | sh_funcs.append(' tmp_str = %s(pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1015 | sh_funcs.append(' ss[%u] << %spStruct->%s;' % (index, addr_char, stp_list[index]['name'])) |
| 1016 | if self.no_addr: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1017 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1018 | sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (addr)\\n" + tmp_str;' % (index, stp_list[index]['name'])) |
| 1019 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1020 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1021 | sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (" + ss[%u].str() + ")\\n" + tmp_str;' % (index, stp_list[index]['name'], index)) |
| 1022 | sh_funcs.append(' ss[%u].str("");' % (index)) |
| 1023 | sh_funcs.append(' }') |
| 1024 | sh_funcs.append(' else') |
| 1025 | sh_funcs.append(' stp_strs[%u] = "";' % index) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1026 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1027 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1028 | sh_funcs.append(' tmp_str = %s(&pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
| 1029 | sh_funcs.append(' ss[%u] << %spStruct->%s;' % (index, addr_char, stp_list[index]['name'])) |
| 1030 | if self.no_addr: |
| 1031 | sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (addr)\\n" + tmp_str;' % (index, stp_list[index]['name'])) |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1032 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1033 | else: |
| 1034 | sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (" + ss[%u].str() + ")\\n" + tmp_str;' % (index, stp_list[index]['name'], index)) |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1035 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1036 | sh_funcs.append(' ss[%u].str("");' % index) |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 1037 | # Now print one-line info for all data members |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1038 | index = 0 |
| 1039 | final_str = '' |
| 1040 | for m in sorted(self.struct_dict[s]): |
| 1041 | if not is_type(self.struct_dict[s][m]['type'], 'enum'): |
| 1042 | if is_type(self.struct_dict[s][m]['type'], 'struct') and not self.struct_dict[s][m]['ptr']: |
| 1043 | if self.no_addr: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1044 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1045 | sh_funcs.append(' ss[%u].str("addr");' % (index)) |
| 1046 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1047 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1048 | sh_funcs.append(' ss[%u] << &pStruct->%s;' % (index, self.struct_dict[s][m]['name'])) |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1049 | elif self.struct_dict[s][m]['array']: |
| 1050 | sh_funcs.append('%s' % lineinfo.get()) |
| 1051 | sh_funcs.append(' ss[%u] << (void*)pStruct->%s;' % (index, self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 1052 | elif 'bool' in self.struct_dict[s][m]['type'].lower(): |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1053 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1054 | sh_funcs.append(' ss[%u].str(pStruct->%s ? "TRUE" : "FALSE");' % (index, self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 1055 | elif 'uint8' in self.struct_dict[s][m]['type'].lower(): |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1056 | sh_funcs.append('%s' % lineinfo.get()) |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1057 | sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 17f45a6 | 2015-04-28 17:27:16 -0600 | [diff] [blame] | 1058 | elif 'void' in self.struct_dict[s][m]['type'].lower() and self.struct_dict[s][m]['ptr']: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1059 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 17f45a6 | 2015-04-28 17:27:16 -0600 | [diff] [blame] | 1060 | sh_funcs.append(' if (StreamControl::writeAddress)') |
| 1061 | sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name'])) |
| 1062 | sh_funcs.append(' else') |
| 1063 | sh_funcs.append(' ss[%u].str("address");' % (index)) |
Mark Young | d46f6e9 | 2016-01-27 17:46:16 -0700 | [diff] [blame] | 1064 | elif 'char' in self.struct_dict[s][m]['type'].lower() and self.struct_dict[s][m]['ptr']: |
| 1065 | sh_funcs.append('%s' % lineinfo.get()) |
Jon Ashburn | 34edc12 | 2016-03-10 14:21:09 -0700 | [diff] [blame] | 1066 | sh_funcs.append(' if (pStruct->%s != NULL) {' % self.struct_dict[s][m]['name']) |
| 1067 | sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name'])) |
| 1068 | sh_funcs.append(' } else {') |
| 1069 | sh_funcs.append(' ss[%u] << "";' % index) |
| 1070 | sh_funcs.append(' }') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1071 | else: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1072 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1073 | (po, pa) = self._get_struct_print_formatted(self.struct_dict[s][m]) |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 1074 | if "addr" in po: # or self.struct_dict[s][m]['ptr']: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1075 | sh_funcs.append(' ss[%u].str("addr");' % (index)) |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 1076 | elif not self.struct_dict[s][m]['ptr'] and self.struct_dict[s][m]['type'] in vulkan.core.objects: |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1077 | sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1078 | else: |
| 1079 | sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name'])) |
| 1080 | value_print = 'ss[%u].str()' % index |
| 1081 | index += 1 |
| 1082 | else: |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 1083 | # For an non-empty array of enums just print address w/ note that array will be displayed below |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1084 | if self.struct_dict[s][m]['ptr']: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1085 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | ce32094 | 2015-06-11 09:37:00 -0600 | [diff] [blame] | 1086 | sh_funcs.append(' if (pStruct->%s)' % (self.struct_dict[s][m]['name'])) |
| 1087 | sh_funcs.append(' ss[%u] << pStruct->%s << " (See individual array values below)";' % (index, self.struct_dict[s][m]['name'])) |
| 1088 | sh_funcs.append(' else') |
| 1089 | sh_funcs.append(' ss[%u].str("NULL");' % (index)) |
| 1090 | value_print = 'ss[%u].str()' % index |
| 1091 | index += 1 |
| 1092 | # For single enum just print the string representation |
| 1093 | else: |
| 1094 | value_print = 'string_%s(pStruct->%s)' % (self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name']) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1095 | final_str += ' + prefix + "%s = " + %s + "\\n"' % (self.struct_dict[s][m]['name'], value_print) |
| 1096 | final_str = final_str[3:] # strip off the initial ' + ' |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 1097 | if 0 != num_stps: # Append data for any embedded structs |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1098 | final_str += " + %s" % " + ".join(['stp_strs[%u]' % n for n in reversed(range(num_stps))]) |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1099 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1100 | sh_funcs.append(' final_str = %s;' % final_str) |
| 1101 | sh_funcs.append(' return final_str;\n}') |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1102 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 1103 | sh_funcs.append("#endif //VK_USE_PLATFORM_WIN32_KHR") |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 1104 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 1105 | sh_funcs.append("#endif //VK_USE_PLATFORM_XCB_KHR") |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 1106 | # Add function to return a string value for input void* |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1107 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 1108 | sh_funcs.append("string string_convert_helper(const void* toString, const string prefix)\n{") |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1109 | sh_funcs.append(" using namespace StreamControl;") |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 1110 | sh_funcs.append(" stringstream ss;") |
| 1111 | sh_funcs.append(' ss << toString;') |
| 1112 | sh_funcs.append(' string final_str = prefix + ss.str();') |
| 1113 | sh_funcs.append(" return final_str;") |
| 1114 | sh_funcs.append("}") |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1115 | sh_funcs.append('%s' % lineinfo.get()) |
Tony Barbour | b5d2c94 | 2015-07-14 13:34:05 -0600 | [diff] [blame] | 1116 | # Add function to return a string value for input uint64_t |
| 1117 | sh_funcs.append("string string_convert_helper(const uint64_t toString, const string prefix)\n{") |
Tobin Ehlis | 0854174 | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 1118 | sh_funcs.append(" using namespace StreamControl;") |
| 1119 | sh_funcs.append(" stringstream ss;") |
| 1120 | sh_funcs.append(' ss << toString;') |
| 1121 | sh_funcs.append(' string final_str = prefix + ss.str();') |
| 1122 | sh_funcs.append(" return final_str;") |
| 1123 | sh_funcs.append("}") |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1124 | sh_funcs.append('%s' % lineinfo.get()) |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1125 | # Add function to return a string value for input VkSurfaceFormatKHR* |
| 1126 | sh_funcs.append("string string_convert_helper(VkSurfaceFormatKHR toString, const string prefix)\n{") |
| 1127 | sh_funcs.append(' string final_str = prefix + "format = " + string_VkFormat(toString.format) + "format = " + string_VkColorSpaceKHR(toString.colorSpace);') |
Ian Elliott | 2b6b68a | 2015-08-07 14:11:14 -0600 | [diff] [blame] | 1128 | sh_funcs.append(" return final_str;") |
| 1129 | sh_funcs.append("}") |
| 1130 | sh_funcs.append('%s' % lineinfo.get()) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1131 | # Add function to dynamically print out unknown struct |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1132 | sh_funcs.append("string dynamic_display(const void* pStruct, const string prefix)\n{") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1133 | sh_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct") |
Ian Elliott | 8280002 | 2015-02-25 17:40:38 -0700 | [diff] [blame] | 1134 | sh_funcs.append(" if (pStruct == NULL) {\n") |
Michael Lentine | fb3b23b | 2015-10-23 12:40:50 -0700 | [diff] [blame] | 1135 | sh_funcs.append(" return string();") |
Ian Elliott | 8280002 | 2015-02-25 17:40:38 -0700 | [diff] [blame] | 1136 | sh_funcs.append(" }\n") |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1137 | sh_funcs.append(" VkStructureType sType = ((VkApplicationInfo*)pStruct)->sType;") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1138 | sh_funcs.append(' string indent = " ";') |
| 1139 | sh_funcs.append(' indent += prefix;') |
| 1140 | sh_funcs.append(" switch (sType)\n {") |
| 1141 | for e in enum_type_dict: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1142 | if "StructureType" in e: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1143 | for v in sorted(enum_type_dict[e]): |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 1144 | struct_name = get_struct_name_from_struct_type(v) |
Chia-I Wu | 736324e | 2015-10-26 20:42:12 +0800 | [diff] [blame] | 1145 | if struct_name not in self.struct_dict: |
| 1146 | continue |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1147 | print_func_name = self._get_sh_func_name(struct_name) |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1148 | #sh_funcs.append('string %s(const %s* pStruct, const string prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s])) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1149 | sh_funcs.append(' case %s:\n {' % (v)) |
| 1150 | sh_funcs.append(' return %s((%s*)pStruct, indent);' % (print_func_name, struct_name)) |
| 1151 | sh_funcs.append(' }') |
| 1152 | sh_funcs.append(' break;') |
| 1153 | sh_funcs.append(" default:") |
Michael Lentine | fb3b23b | 2015-10-23 12:40:50 -0700 | [diff] [blame] | 1154 | sh_funcs.append(" return string();") |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1155 | sh_funcs.append('%s' % lineinfo.get()) |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1156 | sh_funcs.append(" }") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1157 | sh_funcs.append("}") |
| 1158 | return "\n".join(sh_funcs) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1159 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1160 | def _genStructMemberPrint(self, member, s, array, struct_array): |
| 1161 | (p_out, p_arg) = self._get_struct_print_formatted(self.struct_dict[s][member], pre_var_name="&m_dummy_prefix", struct_var_name="m_struct", struct_ptr=False, print_array=True) |
| 1162 | extra_indent = "" |
| 1163 | if array: |
| 1164 | extra_indent = " " |
| 1165 | if is_type(self.struct_dict[s][member]['type'], 'struct'): # print struct address for now |
| 1166 | struct_array.insert(0, self.struct_dict[s][member]) |
| 1167 | elif self.struct_dict[s][member]['ptr']: |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1168 | # Special case for void* named "pNext" |
| 1169 | if "void" in self.struct_dict[s][member]['type'] and "pNext" == self.struct_dict[s][member]['name']: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1170 | struct_array.insert(0, self.struct_dict[s][member]) |
| 1171 | return (' %sprintf("%%*s %s", m_indent, ""%s);' % (extra_indent, p_out, p_arg), struct_array) |
| 1172 | |
| 1173 | def _generateDisplayDefinitions(self, s): |
| 1174 | disp_def = [] |
| 1175 | struct_array = [] |
| 1176 | # Single-line struct print function |
| 1177 | disp_def.append("// Output 'structname = struct_address' on a single line") |
| 1178 | disp_def.append("void %s::display_single_txt()\n{" % self.get_class_name(s)) |
| 1179 | disp_def.append(' printf(" %%*s%s = %%p", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s]) |
| 1180 | disp_def.append("}\n") |
| 1181 | # Private helper function to print struct members |
| 1182 | disp_def.append("// Private helper function that displays the members of the wrapped struct") |
| 1183 | disp_def.append("void %s::display_struct_members()\n{" % self.get_class_name(s)) |
| 1184 | i_declared = False |
| 1185 | for member in sorted(self.struct_dict[s]): |
| 1186 | # TODO : Need to display each member based on its type |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1187 | # TODO : Need to handle pNext which are structs, but of void* type |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1188 | # Can grab struct type off of header of struct pointed to |
| 1189 | # TODO : Handle Arrays |
| 1190 | if self.struct_dict[s][member]['array']: |
| 1191 | # Create for loop to print each element of array |
| 1192 | if not i_declared: |
| 1193 | disp_def.append(' uint32_t i;') |
| 1194 | i_declared = True |
| 1195 | disp_def.append(' for (i = 0; i<%s; i++) {' % self.struct_dict[s][member]['array_size']) |
| 1196 | (return_str, struct_array) = self._genStructMemberPrint(member, s, True, struct_array) |
| 1197 | disp_def.append(return_str) |
| 1198 | disp_def.append(' }') |
| 1199 | else: |
| 1200 | (return_str, struct_array) = self._genStructMemberPrint(member, s, False, struct_array) |
| 1201 | disp_def.append(return_str) |
| 1202 | disp_def.append("}\n") |
| 1203 | i_declared = False |
| 1204 | # Basic print function to display struct members |
| 1205 | disp_def.append("// Output all struct elements, each on their own line") |
| 1206 | disp_def.append("void %s::display_txt()\n{" % self.get_class_name(s)) |
| 1207 | disp_def.append(' printf("%%*s%s struct contents at %%p:\\n", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s]) |
| 1208 | disp_def.append(' this->display_struct_members();') |
| 1209 | disp_def.append("}\n") |
| 1210 | # Advanced print function to display current struct and contents of any pointed-to structs |
| 1211 | disp_def.append("// Output all struct elements, and for any structs pointed to, print complete contents") |
| 1212 | disp_def.append("void %s::display_full_txt()\n{" % self.get_class_name(s)) |
| 1213 | disp_def.append(' printf("%%*s%s struct contents at %%p:\\n", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s]) |
| 1214 | disp_def.append(' this->display_struct_members();') |
| 1215 | class_num = 0 |
| 1216 | # TODO : Need to handle arrays of structs here |
| 1217 | for ms in struct_array: |
| 1218 | swc_name = "class%s" % str(class_num) |
| 1219 | if ms['array']: |
| 1220 | if not i_declared: |
| 1221 | disp_def.append(' uint32_t i;') |
| 1222 | i_declared = True |
| 1223 | disp_def.append(' for (i = 0; i<%s; i++) {' % ms['array_size']) |
| 1224 | #disp_def.append(" if (m_struct.%s[i]) {" % (ms['name'])) |
| 1225 | disp_def.append(" %s %s(&(m_struct.%s[i]));" % (self.get_class_name(ms['type']), swc_name, ms['name'])) |
| 1226 | disp_def.append(" %s.set_indent(m_indent + 4);" % (swc_name)) |
| 1227 | disp_def.append(" %s.display_full_txt();" % (swc_name)) |
| 1228 | #disp_def.append(' }') |
| 1229 | disp_def.append(' }') |
| 1230 | elif 'pNext' == ms['name']: |
| 1231 | # Need some code trickery here |
| 1232 | # I'm thinking have a generated function that takes pNext ptr value |
| 1233 | # then it checks sType and in large switch statement creates appropriate |
| 1234 | # wrapper class type and then prints contents |
| 1235 | disp_def.append(" if (m_struct.%s) {" % (ms['name'])) |
| 1236 | #disp_def.append(' printf("%*s This is where we would call dynamic print function\\n", m_indent, "");') |
| 1237 | disp_def.append(' dynamic_display_full_txt(m_struct.%s, m_indent);' % (ms['name'])) |
| 1238 | disp_def.append(" }") |
| 1239 | else: |
| 1240 | if ms['ptr']: |
| 1241 | disp_def.append(" if (m_struct.%s) {" % (ms['name'])) |
| 1242 | disp_def.append(" %s %s(m_struct.%s);" % (self.get_class_name(ms['type']), swc_name, ms['name'])) |
| 1243 | else: |
| 1244 | disp_def.append(" if (&m_struct.%s) {" % (ms['name'])) |
| 1245 | disp_def.append(" %s %s(&m_struct.%s);" % (self.get_class_name(ms['type']), swc_name, ms['name'])) |
| 1246 | disp_def.append(" %s.set_indent(m_indent + 4);" % (swc_name)) |
| 1247 | disp_def.append(" %s.display_full_txt();\n }" % (swc_name)) |
| 1248 | class_num += 1 |
| 1249 | disp_def.append("}\n") |
| 1250 | return "\n".join(disp_def) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1251 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1252 | def _generateStringHelperHeader(self): |
| 1253 | header = [] |
| 1254 | header.append("//#includes, #defines, globals and such...\n") |
| 1255 | for f in self.include_headers: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1256 | if 'vk_enum_string_helper' not in f: |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1257 | header.append("#include <%s>\n" % f) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1258 | header.append('#include "vk_enum_string_helper.h"\n\n// Function Prototypes\n') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1259 | header.append("char* dynamic_display(const void* pStruct, const char* prefix);\n") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1260 | return "".join(header) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1261 | |
| 1262 | def _generateStringHelperHeaderCpp(self): |
| 1263 | header = [] |
| 1264 | header.append("//#includes, #defines, globals and such...\n") |
| 1265 | for f in self.include_headers: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1266 | if 'vk_enum_string_helper' not in f: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1267 | header.append("#include <%s>\n" % f) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1268 | header.append('#include "vk_enum_string_helper.h"\n') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1269 | header.append('using namespace std;\n\n// Function Prototypes\n') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1270 | header.append('\n') |
| 1271 | header.append('namespace StreamControl\n') |
| 1272 | header.append('{\n') |
| 1273 | header.append('bool writeAddress = true;\n') |
| 1274 | header.append('template <typename T>\n') |
| 1275 | header.append('std::ostream& operator<< (std::ostream &out, T const* pointer)\n') |
| 1276 | header.append('{\n') |
| 1277 | header.append(' if(writeAddress)\n') |
| 1278 | header.append(' {\n') |
| 1279 | header.append(' out.operator<<(pointer);\n') |
| 1280 | header.append(' }\n') |
| 1281 | header.append(' else\n') |
| 1282 | header.append(' {\n') |
| 1283 | header.append(' std::operator<<(out, "address");\n') |
| 1284 | header.append(' }\n') |
| 1285 | header.append(' return out;\n') |
| 1286 | header.append('}\n') |
| 1287 | header.append('std::ostream& operator<<(std::ostream &out, char const*const s)\n') |
| 1288 | header.append('{\n') |
| 1289 | header.append(' return std::operator<<(out, s);\n') |
| 1290 | header.append('}\n') |
| 1291 | header.append('}\n') |
| 1292 | header.append('\n') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1293 | header.append("string dynamic_display(const void* pStruct, const string prefix);\n") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1294 | return "".join(header) |
| 1295 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1296 | def _generateValidateHelperFunctions(self): |
| 1297 | sh_funcs = [] |
| 1298 | # We do two passes, first pass just generates prototypes for all the functsions |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 1299 | exclude_struct_list = ['VkAndroidSurfaceCreateInfoKHR', |
| 1300 | 'VkMirSurfaceCreateInfoKHR', |
| 1301 | 'VkWaylandSurfaceCreateInfoKHR', |
| 1302 | 'VkXlibSurfaceCreateInfoKHR'] |
| 1303 | if sys.platform == 'win32': |
| 1304 | exclude_struct_list.append('VkXcbSurfaceCreateInfoKHR') |
| 1305 | else: |
| 1306 | exclude_struct_list.append('VkWin32SurfaceCreateInfoKHR') |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1307 | for s in sorted(self.struct_dict): |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 1308 | if (typedef_fwd_dict[s] not in exclude_struct_list): |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 1309 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 1310 | sh_funcs.append("#ifdef VK_USE_PLATFORM_XCB_KHR") |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1311 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 1312 | sh_funcs.append("#ifdef VK_USE_PLATFORM_WIN32_KHR") |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 1313 | sh_funcs.append('uint32_t %s(const %s* pStruct);' % (self._get_vh_func_name(s), typedef_fwd_dict[s])) |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1314 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 1315 | sh_funcs.append("#endif //VK_USE_PLATFORM_WIN32_KHR") |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 1316 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 1317 | sh_funcs.append("#endif //VK_USE_PLATFORM_XCB_KHR") |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1318 | sh_funcs.append('\n') |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1319 | for s in sorted(self.struct_dict): |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 1320 | if (typedef_fwd_dict[s] in exclude_struct_list): |
| 1321 | continue |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 1322 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 1323 | sh_funcs.append("#ifdef VK_USE_PLATFORM_XCB_KHR") |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1324 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 1325 | sh_funcs.append("#ifdef VK_USE_PLATFORM_WIN32_KHR") |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1326 | sh_funcs.append('uint32_t %s(const %s* pStruct)\n{' % (self._get_vh_func_name(s), typedef_fwd_dict[s])) |
| 1327 | for m in sorted(self.struct_dict[s]): |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1328 | # TODO : Need to handle arrays of enums like in VkRenderPassCreateInfo struct |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1329 | if is_type(self.struct_dict[s][m]['type'], 'enum') and not self.struct_dict[s][m]['ptr']: |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1330 | sh_funcs.append(' if (!validate_%s(pStruct->%s))\n return 0;' % (self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name'])) |
Jon Ashburn | 27e02a6 | 2015-01-12 15:46:51 -0700 | [diff] [blame] | 1331 | # TODO : Need a little refinement to this code to make sure type of struct matches expected input (ptr, const...) |
Tobin Ehlis | ce12ad6 | 2014-12-18 09:29:58 -0700 | [diff] [blame] | 1332 | if is_type(self.struct_dict[s][m]['type'], 'struct'): |
| 1333 | if (self.struct_dict[s][m]['ptr']): |
Tobin Ehlis | f4a3ac5 | 2015-02-24 15:39:04 -0700 | [diff] [blame] | 1334 | sh_funcs.append(' if (pStruct->%s && !%s((const %s*)pStruct->%s))\n return 0;' % (self.struct_dict[s][m]['name'], self._get_vh_func_name(self.struct_dict[s][m]['type']), self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name'])) |
Tobin Ehlis | ce12ad6 | 2014-12-18 09:29:58 -0700 | [diff] [blame] | 1335 | else: |
| 1336 | sh_funcs.append(' if (!%s((const %s*)&pStruct->%s))\n return 0;' % (self._get_vh_func_name(self.struct_dict[s][m]['type']), self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1337 | sh_funcs.append(" return 1;\n}") |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1338 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 1339 | sh_funcs.append("#endif //VK_USE_PLATFORM_WIN32_KHR") |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 1340 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 1341 | sh_funcs.append("#endif //VK_USE_PLATFORM_XCB_KHR") |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1342 | |
| 1343 | return "\n".join(sh_funcs) |
| 1344 | |
| 1345 | def _generateValidateHelperHeader(self): |
| 1346 | header = [] |
| 1347 | header.append("//#includes, #defines, globals and such...\n") |
| 1348 | for f in self.include_headers: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1349 | if 'vk_enum_validate_helper' not in f: |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1350 | header.append("#include <%s>\n" % f) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1351 | header.append('#include "vk_enum_validate_helper.h"\n\n// Function Prototypes\n') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1352 | #header.append("char* dynamic_display(const void* pStruct, const char* prefix);\n") |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1353 | return "".join(header) |
| 1354 | |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1355 | def _generateSizeHelperFunctions(self): |
| 1356 | sh_funcs = [] |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 1357 | # just generates prototypes for all the functions |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 1358 | exclude_struct_list = ['VkAndroidSurfaceCreateInfoKHR', |
| 1359 | 'VkMirSurfaceCreateInfoKHR', |
| 1360 | 'VkWaylandSurfaceCreateInfoKHR', |
| 1361 | 'VkXlibSurfaceCreateInfoKHR'] |
| 1362 | if sys.platform == 'win32': |
| 1363 | exclude_struct_list.append('VkXcbSurfaceCreateInfoKHR') |
| 1364 | else: |
| 1365 | exclude_struct_list.append('VkWin32SurfaceCreateInfoKHR') |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1366 | for s in sorted(self.struct_dict): |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 1367 | if (typedef_fwd_dict[s] not in exclude_struct_list): |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 1368 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 1369 | sh_funcs.append("#ifdef VK_USE_PLATFORM_XCB_KHR") |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1370 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 1371 | sh_funcs.append("#ifdef VK_USE_PLATFORM_WIN32_KHR") |
Ian Elliott | f6b168c | 2015-12-11 15:03:05 -0700 | [diff] [blame] | 1372 | sh_funcs.append('size_t %s(const %s* pStruct);' % (self._get_size_helper_func_name(s), typedef_fwd_dict[s])) |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1373 | if (re.match(r'.*Win32.*', typedef_fwd_dict[s])): |
| 1374 | sh_funcs.append("#endif //VK_USE_PLATFORM_WIN32_KHR") |
Michael Lentine | 33d96a3 | 2016-01-05 11:10:15 -0600 | [diff] [blame] | 1375 | if (re.match(r'.*Xcb.*', typedef_fwd_dict[s])): |
| 1376 | sh_funcs.append("#endif //VK_USE_PLATFORM_XCB_KHR") |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 1377 | return "\n".join(sh_funcs) |
| 1378 | |
| 1379 | |
| 1380 | def _generateSizeHelperFunctionsC(self): |
| 1381 | sh_funcs = [] |
| 1382 | # generate function definitions |
Jon Ashburn | 81b1d9c | 2015-12-29 14:21:25 -0700 | [diff] [blame] | 1383 | exclude_struct_list = ['VkAndroidSurfaceCreateInfoKHR', |
| 1384 | 'VkMirSurfaceCreateInfoKHR', |
| 1385 | 'VkWaylandSurfaceCreateInfoKHR', |
| 1386 | 'VkXlibSurfaceCreateInfoKHR'] |
| 1387 | if sys.platform == 'win32': |
| 1388 | exclude_struct_list.append('VkXcbSurfaceCreateInfoKHR') |
| 1389 | else: |
| 1390 | exclude_struct_list.append('VkWin32SurfaceCreateInfoKHR') |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1391 | for s in sorted(self.struct_dict): |
Jon Ashburn | 81b1d9c | 2015-12-29 14:21:25 -0700 | [diff] [blame] | 1392 | if (typedef_fwd_dict[s] in exclude_struct_list): |
| 1393 | continue |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1394 | skip_list = [] # Used when struct elements need to be skipped because size already accounted for |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1395 | sh_funcs.append('size_t %s(const %s* pStruct)\n{' % (self._get_size_helper_func_name(s), typedef_fwd_dict[s])) |
| 1396 | indent = ' ' |
| 1397 | sh_funcs.append('%ssize_t structSize = 0;' % (indent)) |
| 1398 | sh_funcs.append('%sif (pStruct) {' % (indent)) |
| 1399 | indent = ' ' |
| 1400 | sh_funcs.append('%sstructSize = sizeof(%s);' % (indent, typedef_fwd_dict[s])) |
| 1401 | i_decl = False |
| 1402 | for m in sorted(self.struct_dict[s]): |
| 1403 | if m in skip_list: |
| 1404 | continue |
| 1405 | if self.struct_dict[s][m]['dyn_array']: |
| 1406 | if self.struct_dict[s][m]['full_type'].count('*') > 1: |
| 1407 | if not is_type(self.struct_dict[s][m]['type'], 'struct') and not 'char' in self.struct_dict[s][m]['type'].lower(): |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1408 | if 'ppMemoryBarriers' == self.struct_dict[s][m]['name']: |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1409 | # TODO : For now be conservative and consider all memBarrier ptrs as largest possible struct |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1410 | sh_funcs.append('%sstructSize += pStruct->%s*(sizeof(%s*) + sizeof(VkImageMemoryBarrier));' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type'])) |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1411 | else: |
| 1412 | sh_funcs.append('%sstructSize += pStruct->%s*(sizeof(%s*) + sizeof(%s));' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type'], self.struct_dict[s][m]['type'])) |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1413 | else: # This is an array of char* or array of struct ptrs |
| 1414 | if not i_decl: |
| 1415 | sh_funcs.append('%suint32_t i = 0;' % (indent)) |
| 1416 | i_decl = True |
| 1417 | sh_funcs.append('%sfor (i = 0; i < pStruct->%s; i++) {' % (indent, self.struct_dict[s][m]['array_size'])) |
| 1418 | indent = ' ' |
| 1419 | if is_type(self.struct_dict[s][m]['type'], 'struct'): |
| 1420 | sh_funcs.append('%sstructSize += (sizeof(%s*) + %s(pStruct->%s[i]));' % (indent, self.struct_dict[s][m]['type'], self._get_size_helper_func_name(self.struct_dict[s][m]['type']), self.struct_dict[s][m]['name'])) |
| 1421 | else: |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 1422 | sh_funcs.append('%sstructSize += (sizeof(char*) + (sizeof(char) * (1 + strlen(pStruct->%s[i]))));' % (indent, self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1423 | indent = ' ' |
| 1424 | sh_funcs.append('%s}' % (indent)) |
| 1425 | else: |
| 1426 | if is_type(self.struct_dict[s][m]['type'], 'struct'): |
| 1427 | if not i_decl: |
| 1428 | sh_funcs.append('%suint32_t i = 0;' % (indent)) |
| 1429 | i_decl = True |
| 1430 | sh_funcs.append('%sfor (i = 0; i < pStruct->%s; i++) {' % (indent, self.struct_dict[s][m]['array_size'])) |
| 1431 | indent = ' ' |
| 1432 | sh_funcs.append('%sstructSize += %s(&pStruct->%s[i]);' % (indent, self._get_size_helper_func_name(self.struct_dict[s][m]['type']), self.struct_dict[s][m]['name'])) |
| 1433 | indent = ' ' |
| 1434 | sh_funcs.append('%s}' % (indent)) |
| 1435 | else: |
| 1436 | sh_funcs.append('%sstructSize += pStruct->%s*sizeof(%s);' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type'])) |
| 1437 | elif self.struct_dict[s][m]['ptr'] and 'pNext' != self.struct_dict[s][m]['name']: |
| 1438 | if 'char' in self.struct_dict[s][m]['type'].lower(): |
Karl Schultz | c3f0963 | 2016-01-27 16:03:49 -0700 | [diff] [blame] | 1439 | sh_funcs.append('%sstructSize += (pStruct->%s != NULL) ? sizeof(%s)*(1+strlen(pStruct->%s)) : 0;' % (indent, self.struct_dict[s][m]['name'], self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1440 | elif is_type(self.struct_dict[s][m]['type'], 'struct'): |
| 1441 | sh_funcs.append('%sstructSize += %s(pStruct->%s);' % (indent, self._get_size_helper_func_name(self.struct_dict[s][m]['type']), self.struct_dict[s][m]['name'])) |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1442 | elif 'void' not in self.struct_dict[s][m]['type'].lower(): |
Jon Ashburn | 81b1d9c | 2015-12-29 14:21:25 -0700 | [diff] [blame] | 1443 | if (self.struct_dict[s][m]['type'] != 'xcb_connection_t'): |
| 1444 | sh_funcs.append('%sstructSize += sizeof(%s);' % (indent, self.struct_dict[s][m]['type'])) |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1445 | elif 'size_t' == self.struct_dict[s][m]['type'].lower(): |
| 1446 | sh_funcs.append('%sstructSize += pStruct->%s;' % (indent, self.struct_dict[s][m]['name'])) |
| 1447 | skip_list.append(m+1) |
| 1448 | indent = ' ' |
| 1449 | sh_funcs.append('%s}' % (indent)) |
| 1450 | sh_funcs.append("%sreturn structSize;\n}" % (indent)) |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1451 | # Now generate generic functions to loop over entire struct chain (or just handle single generic structs) |
Ian Elliott | ba04233 | 2015-11-18 14:57:08 -0700 | [diff] [blame] | 1452 | if '_debug_' not in self.header_filename: |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 1453 | for follow_chain in [True, False]: |
| 1454 | sh_funcs.append('%s' % self.lineinfo.get()) |
| 1455 | if follow_chain: |
| 1456 | sh_funcs.append('size_t get_struct_chain_size(const void* pStruct)\n{') |
| 1457 | else: |
| 1458 | sh_funcs.append('size_t get_dynamic_struct_size(const void* pStruct)\n{') |
| 1459 | indent = ' ' |
| 1460 | sh_funcs.append('%s// Just use VkApplicationInfo as struct until actual type is resolved' % (indent)) |
| 1461 | sh_funcs.append('%sVkApplicationInfo* pNext = (VkApplicationInfo*)pStruct;' % (indent)) |
| 1462 | sh_funcs.append('%ssize_t structSize = 0;' % (indent)) |
| 1463 | if follow_chain: |
| 1464 | sh_funcs.append('%swhile (pNext) {' % (indent)) |
| 1465 | indent = ' ' |
| 1466 | sh_funcs.append('%sswitch (pNext->sType) {' % (indent)) |
| 1467 | indent += ' ' |
| 1468 | for e in enum_type_dict: |
| 1469 | if 'StructureType' in e: |
| 1470 | for v in sorted(enum_type_dict[e]): |
| 1471 | struct_name = get_struct_name_from_struct_type(v) |
Chia-I Wu | 736324e | 2015-10-26 20:42:12 +0800 | [diff] [blame] | 1472 | if struct_name not in self.struct_dict: |
| 1473 | continue |
| 1474 | |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 1475 | sh_funcs.append('%scase %s:' % (indent, v)) |
| 1476 | sh_funcs.append('%s{' % (indent)) |
| 1477 | indent += ' ' |
| 1478 | sh_funcs.append('%sstructSize += %s((%s*)pNext);' % (indent, self._get_size_helper_func_name(struct_name), struct_name)) |
| 1479 | sh_funcs.append('%sbreak;' % (indent)) |
| 1480 | indent = indent[:-4] |
| 1481 | sh_funcs.append('%s}' % (indent)) |
| 1482 | sh_funcs.append('%sdefault:' % (indent)) |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1483 | indent += ' ' |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 1484 | sh_funcs.append('%sassert(0);' % (indent)) |
| 1485 | sh_funcs.append('%sstructSize += 0;' % (indent)) |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1486 | indent = indent[:-4] |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1487 | indent = indent[:-4] |
| 1488 | sh_funcs.append('%s}' % (indent)) |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 1489 | if follow_chain: |
| 1490 | sh_funcs.append('%spNext = (VkApplicationInfo*)pNext->pNext;' % (indent)) |
| 1491 | indent = indent[:-4] |
| 1492 | sh_funcs.append('%s}' % (indent)) |
| 1493 | sh_funcs.append('%sreturn structSize;\n}' % indent) |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1494 | return "\n".join(sh_funcs) |
| 1495 | |
| 1496 | def _generateSizeHelperHeader(self): |
| 1497 | header = [] |
| 1498 | header.append("//#includes, #defines, globals and such...\n") |
| 1499 | for f in self.include_headers: |
| 1500 | header.append("#include <%s>\n" % f) |
| 1501 | header.append('\n// Function Prototypes\n') |
| 1502 | header.append("size_t get_struct_chain_size(const void* pStruct);\n") |
Tobin Ehlis | 0411292 | 2015-03-16 10:44:40 -0600 | [diff] [blame] | 1503 | header.append("size_t get_dynamic_struct_size(const void* pStruct);\n") |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1504 | return "".join(header) |
| 1505 | |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 1506 | def _generateSizeHelperHeaderC(self): |
| 1507 | header = [] |
Courtney Goeltzenleuchter | dba7998 | 2015-04-14 16:30:53 -0600 | [diff] [blame] | 1508 | header.append('#include "vk_struct_size_helper.h"') |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 1509 | header.append('#include <string.h>') |
| 1510 | header.append('#include <assert.h>') |
| 1511 | header.append('\n// Function definitions\n') |
| 1512 | return "\n".join(header) |
| 1513 | |
| 1514 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1515 | def _generateHeader(self): |
| 1516 | header = [] |
| 1517 | header.append("//#includes, #defines, globals and such...\n") |
| 1518 | for f in self.include_headers: |
| 1519 | header.append("#include <%s>\n" % f) |
| 1520 | return "".join(header) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1521 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1522 | # Declarations |
| 1523 | def _generateConstructorDeclarations(self, s): |
| 1524 | constructors = [] |
| 1525 | constructors.append(" %s();\n" % self.get_class_name(s)) |
| 1526 | constructors.append(" %s(%s* pInStruct);\n" % (self.get_class_name(s), typedef_fwd_dict[s])) |
| 1527 | constructors.append(" %s(const %s* pInStruct);\n" % (self.get_class_name(s), typedef_fwd_dict[s])) |
| 1528 | return "".join(constructors) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1529 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1530 | def _generateDestructorDeclarations(self, s): |
| 1531 | return " virtual ~%s();\n" % self.get_class_name(s) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1532 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1533 | def _generateDisplayDeclarations(self, s): |
| 1534 | return " void display_txt();\n void display_single_txt();\n void display_full_txt();\n" |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1535 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1536 | def _generateGetSetDeclarations(self, s): |
| 1537 | get_set = [] |
| 1538 | get_set.append(" void set_indent(uint32_t indent) { m_indent = indent; }\n") |
| 1539 | for member in sorted(self.struct_dict[s]): |
| 1540 | # TODO : Skipping array set/get funcs for now |
| 1541 | if self.struct_dict[s][member]['array']: |
| 1542 | continue |
| 1543 | get_set.append(" %s get_%s() { return m_struct.%s; }\n" % (self.struct_dict[s][member]['full_type'], self.struct_dict[s][member]['name'], self.struct_dict[s][member]['name'])) |
| 1544 | if not self.struct_dict[s][member]['const']: |
| 1545 | get_set.append(" void set_%s(%s inValue) { m_struct.%s = inValue; }\n" % (self.struct_dict[s][member]['name'], self.struct_dict[s][member]['full_type'], self.struct_dict[s][member]['name'])) |
| 1546 | return "".join(get_set) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1547 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1548 | def _generatePrivateMembers(self, s): |
| 1549 | priv = [] |
| 1550 | priv.append("\nprivate:\n") |
| 1551 | priv.append(" %s m_struct;\n" % typedef_fwd_dict[s]) |
| 1552 | priv.append(" const %s* m_origStructAddr;\n" % typedef_fwd_dict[s]) |
| 1553 | priv.append(" uint32_t m_indent;\n") |
| 1554 | priv.append(" const char m_dummy_prefix;\n") |
| 1555 | priv.append(" void display_struct_members();\n") |
| 1556 | return "".join(priv) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1557 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1558 | def _generateClassDeclaration(self): |
| 1559 | class_decl = [] |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1560 | for s in sorted(self.struct_dict): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1561 | class_decl.append("\n//class declaration") |
| 1562 | class_decl.append("class %s\n{\npublic:" % self.get_class_name(s)) |
| 1563 | class_decl.append(self._generateConstructorDeclarations(s)) |
| 1564 | class_decl.append(self._generateDestructorDeclarations(s)) |
| 1565 | class_decl.append(self._generateDisplayDeclarations(s)) |
| 1566 | class_decl.append(self._generateGetSetDeclarations(s)) |
| 1567 | class_decl.append(self._generatePrivateMembers(s)) |
| 1568 | class_decl.append("};\n") |
| 1569 | return "\n".join(class_decl) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1570 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1571 | def _generateFooter(self): |
| 1572 | return "\n//any footer info for class\n" |
| 1573 | |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 1574 | def _getSafeStructName(self, struct): |
| 1575 | return "safe_%s" % (struct) |
| 1576 | |
| 1577 | # If struct has sType or ptr members, generate safe type |
| 1578 | def _hasSafeStruct(self, s): |
| 1579 | exceptions = ['VkPhysicalDeviceFeatures', 'VkPipelineColorBlendStateCreateInfo'] |
| 1580 | if s in exceptions: |
| 1581 | return False |
| 1582 | if 'sType' == self.struct_dict[s][0]['name']: |
| 1583 | return True |
| 1584 | for m in self.struct_dict[s]: |
| 1585 | if self.struct_dict[s][m]['ptr']: |
| 1586 | return True |
| 1587 | return False |
| 1588 | |
| 1589 | def _generateSafeStructHeader(self): |
| 1590 | header = [] |
| 1591 | header.append("//#includes, #defines, globals and such...\n") |
| 1592 | header.append('#include "vulkan/vulkan.h"') |
| 1593 | return "".join(header) |
| 1594 | |
| 1595 | # If given ty is in obj list, or is a struct that contains anything in obj list, return True |
| 1596 | def _typeHasObject(self, ty, obj): |
| 1597 | if ty in obj: |
| 1598 | return True |
| 1599 | if is_type(ty, 'struct'): |
| 1600 | for m in self.struct_dict[ty]: |
| 1601 | if self.struct_dict[ty][m]['type'] in obj: |
| 1602 | return True |
| 1603 | return False |
| 1604 | |
| 1605 | def _generateSafeStructDecls(self): |
| 1606 | ss_decls = [] |
| 1607 | for s in struct_order_list: |
| 1608 | if not self._hasSafeStruct(s): |
| 1609 | continue |
| 1610 | if s in ifdef_dict: |
| 1611 | ss_decls.append('#ifdef %s' % ifdef_dict[s]) |
| 1612 | ss_name = self._getSafeStructName(s) |
| 1613 | ss_decls.append("\nstruct %s {" % (ss_name)) |
| 1614 | for m in sorted(self.struct_dict[s]): |
| 1615 | m_type = self.struct_dict[s][m]['type'] |
| 1616 | if is_type(m_type, 'struct') and self._hasSafeStruct(m_type): |
| 1617 | m_type = self._getSafeStructName(m_type) |
| 1618 | if self.struct_dict[s][m]['array_size'] != 0 and not self.struct_dict[s][m]['dyn_array']: |
| 1619 | ss_decls.append(" %s %s[%s];" % (m_type, self.struct_dict[s][m]['name'], self.struct_dict[s][m]['array_size'])) |
| 1620 | elif self.struct_dict[s][m]['ptr'] and 'safe_' not in m_type and not self._typeHasObject(m_type, vulkan.object_non_dispatch_list):#m_type in ['char', 'float', 'uint32_t', 'void', 'VkPhysicalDeviceFeatures']: # We'll never overwrite char* so it can remain const |
| 1621 | ss_decls.append(" %s %s;" % (self.struct_dict[s][m]['full_type'], self.struct_dict[s][m]['name'])) |
| 1622 | elif self.struct_dict[s][m]['array']: |
| 1623 | ss_decls.append(" %s* %s;" % (m_type, self.struct_dict[s][m]['name'])) |
| 1624 | elif self.struct_dict[s][m]['ptr']: |
| 1625 | ss_decls.append(" %s* %s;" % (m_type, self.struct_dict[s][m]['name'])) |
| 1626 | else: |
| 1627 | ss_decls.append(" %s %s;" % (m_type, self.struct_dict[s][m]['name'])) |
| 1628 | ss_decls.append(" %s(const %s* pInStruct);" % (ss_name, s)) |
| 1629 | ss_decls.append(" %s();" % (ss_name)) |
| 1630 | ss_decls.append(" ~%s();" % (ss_name)) |
| 1631 | ss_decls.append(" void initialize(const %s* pInStruct);" % (s)) |
| 1632 | ss_decls.append("};") |
| 1633 | if s in ifdef_dict: |
| 1634 | ss_decls.append('#endif') |
| 1635 | return "\n".join(ss_decls) |
| 1636 | |
| 1637 | def _generateSafeStructSourceHeader(self): |
| 1638 | header = [] |
| 1639 | header.append("//#includes, #defines, globals and such...\n") |
| 1640 | header.append('#include "vk_safe_struct.h"') |
| 1641 | return "".join(header) |
| 1642 | |
| 1643 | def _generateSafeStructSource(self): |
| 1644 | ss_src = [] |
| 1645 | for s in struct_order_list: |
| 1646 | if not self._hasSafeStruct(s): |
| 1647 | continue |
| 1648 | if s in ifdef_dict: |
| 1649 | ss_src.append('#ifdef %s' % ifdef_dict[s]) |
| 1650 | ss_name = self._getSafeStructName(s) |
| 1651 | init_list = '' # list of members in struct constructor initializer |
| 1652 | init_func_txt = '' # Txt for initialize() function that takes struct ptr and inits members |
| 1653 | construct_txt = '' |
| 1654 | destruct_txt = '' |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1655 | # VkWriteDescriptorSet is special case because pointers may be non-null but ignored |
| 1656 | # TODO : This is ugly, figure out better way to do this |
| 1657 | custom_construct_txt = {'VkWriteDescriptorSet' : |
| 1658 | ' switch (descriptorType) {\n' |
| 1659 | ' case VK_DESCRIPTOR_TYPE_SAMPLER:\n' |
| 1660 | ' case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:\n' |
| 1661 | ' case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:\n' |
| 1662 | ' case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:\n' |
| 1663 | ' case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:\n' |
| 1664 | ' if (descriptorCount && pInStruct->pImageInfo) {\n' |
| 1665 | ' pImageInfo = new VkDescriptorImageInfo[descriptorCount];\n' |
| 1666 | ' for (uint32_t i=0; i<descriptorCount; ++i) {\n' |
| 1667 | ' pImageInfo[i] = pInStruct->pImageInfo[i];\n' |
| 1668 | ' }\n' |
| 1669 | ' }\n' |
| 1670 | ' break;\n' |
| 1671 | ' case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:\n' |
| 1672 | ' case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:\n' |
| 1673 | ' case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:\n' |
| 1674 | ' case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:\n' |
| 1675 | ' if (descriptorCount && pInStruct->pBufferInfo) {\n' |
| 1676 | ' pBufferInfo = new VkDescriptorBufferInfo[descriptorCount];\n' |
| 1677 | ' for (uint32_t i=0; i<descriptorCount; ++i) {\n' |
| 1678 | ' pBufferInfo[i] = pInStruct->pBufferInfo[i];\n' |
| 1679 | ' }\n' |
| 1680 | ' }\n' |
| 1681 | ' break;\n' |
| 1682 | ' case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:\n' |
| 1683 | ' case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:\n' |
| 1684 | ' if (descriptorCount && pInStruct->pTexelBufferView) {\n' |
| 1685 | ' pTexelBufferView = new VkBufferView[descriptorCount];\n' |
| 1686 | ' for (uint32_t i=0; i<descriptorCount; ++i) {\n' |
| 1687 | ' pTexelBufferView[i] = pInStruct->pTexelBufferView[i];\n' |
| 1688 | ' }\n' |
| 1689 | ' }\n' |
| 1690 | ' break;\n' |
Tobin Ehlis | d183b2d | 2016-02-16 12:08:54 -0700 | [diff] [blame] | 1691 | ' default:\n' |
| 1692 | ' break;\n' |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1693 | ' }\n'} |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 1694 | for m in self.struct_dict[s]: |
| 1695 | m_name = self.struct_dict[s][m]['name'] |
| 1696 | m_type = self.struct_dict[s][m]['type'] |
| 1697 | if is_type(m_type, 'struct') and self._hasSafeStruct(m_type): |
| 1698 | m_type = self._getSafeStructName(m_type) |
| 1699 | if self.struct_dict[s][m]['ptr'] and 'safe_' not in m_type and not self._typeHasObject(m_type, vulkan.object_non_dispatch_list):# in ['char', 'float', 'uint32_t', 'void', 'VkPhysicalDeviceFeatures']) or 'pp' == self.struct_dict[s][m]['name'][0:1]: |
| 1700 | init_list += '\n\t%s(pInStruct->%s),' % (m_name, m_name) |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1701 | init_func_txt += ' %s = pInStruct->%s;\n' % (m_name, m_name) |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 1702 | elif self.struct_dict[s][m]['array']: |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1703 | # Init array ptr to NULL |
| 1704 | init_list += '\n\t%s(NULL),' % (m_name) |
| 1705 | init_func_txt += ' %s = NULL;\n' % (m_name) |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 1706 | array_element = 'pInStruct->%s[i]' % (m_name) |
| 1707 | if is_type(self.struct_dict[s][m]['type'], 'struct') and self._hasSafeStruct(self.struct_dict[s][m]['type']): |
| 1708 | array_element = '%s(&pInStruct->%s[i])' % (self._getSafeStructName(self.struct_dict[s][m]['type']), m_name) |
| 1709 | construct_txt += ' if (%s && pInStruct->%s) {\n' % (self.struct_dict[s][m]['array_size'], m_name) |
| 1710 | construct_txt += ' %s = new %s[%s];\n' % (m_name, m_type, self.struct_dict[s][m]['array_size']) |
| 1711 | destruct_txt += ' if (%s)\n' % (m_name) |
| 1712 | destruct_txt += ' delete[] %s;\n' % (m_name) |
| 1713 | construct_txt += ' for (uint32_t i=0; i<%s; ++i) {\n' % (self.struct_dict[s][m]['array_size']) |
| 1714 | if 'safe_' in m_type: |
| 1715 | construct_txt += ' %s[i].initialize(&pInStruct->%s[i]);\n' % (m_name, m_name) |
| 1716 | else: |
| 1717 | construct_txt += ' %s[i] = %s;\n' % (m_name, array_element) |
| 1718 | construct_txt += ' }\n' |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 1719 | construct_txt += ' }\n' |
| 1720 | elif self.struct_dict[s][m]['ptr']: |
| 1721 | construct_txt += ' if (pInStruct->%s)\n' % (m_name) |
| 1722 | construct_txt += ' %s = new %s(pInStruct->%s);\n' % (m_name, m_type, m_name) |
| 1723 | construct_txt += ' else\n' |
| 1724 | construct_txt += ' %s = NULL;\n' % (m_name) |
| 1725 | destruct_txt += ' if (%s)\n' % (m_name) |
| 1726 | destruct_txt += ' delete %s;\n' % (m_name) |
| 1727 | elif 'safe_' in m_type: # inline struct, need to pass in reference for constructor |
| 1728 | init_list += '\n\t%s(&pInStruct->%s),' % (m_name, m_name) |
| 1729 | init_func_txt += ' %s.initialize(&pInStruct->%s);\n' % (m_name, m_name) |
| 1730 | else: |
| 1731 | init_list += '\n\t%s(pInStruct->%s),' % (m_name, m_name) |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1732 | init_func_txt += ' %s = pInStruct->%s;\n' % (m_name, m_name) |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 1733 | if '' != init_list: |
| 1734 | init_list = init_list[:-1] # hack off final comma |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1735 | if s in custom_construct_txt: |
| 1736 | construct_txt = custom_construct_txt[s] |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 1737 | ss_src.append("\n%s::%s(const %s* pInStruct) : %s\n{\n%s}" % (ss_name, ss_name, s, init_list, construct_txt)) |
| 1738 | ss_src.append("\n%s::%s() {}" % (ss_name, ss_name)) |
| 1739 | ss_src.append("\n%s::~%s()\n{\n%s}" % (ss_name, ss_name, destruct_txt)) |
| 1740 | ss_src.append("\nvoid %s::initialize(const %s* pInStruct)\n{\n%s%s}" % (ss_name, s, init_func_txt, construct_txt)) |
| 1741 | if s in ifdef_dict: |
| 1742 | ss_src.append('#endif') |
| 1743 | return "\n".join(ss_src) |
| 1744 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1745 | class EnumCodeGen: |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 1746 | def __init__(self, enum_type_dict=None, enum_val_dict=None, typedef_fwd_dict=None, in_file=None, out_sh_file=None, out_vh_file=None): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1747 | self.et_dict = enum_type_dict |
| 1748 | self.ev_dict = enum_val_dict |
| 1749 | self.tf_dict = typedef_fwd_dict |
| 1750 | self.in_file = in_file |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 1751 | self.out_sh_file = out_sh_file |
| 1752 | self.eshfg = CommonFileGen(self.out_sh_file) |
| 1753 | self.out_vh_file = out_vh_file |
| 1754 | self.evhfg = CommonFileGen(self.out_vh_file) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1755 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1756 | def generateStringHelper(self): |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 1757 | self.eshfg.setHeader(self._generateSHHeader()) |
| 1758 | self.eshfg.setBody(self._generateSHBody()) |
| 1759 | self.eshfg.generate() |
| 1760 | |
| 1761 | def generateEnumValidate(self): |
| 1762 | self.evhfg.setHeader(self._generateSHHeader()) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1763 | self.evhfg.setBody(self._generateVHBody()) |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 1764 | self.evhfg.generate() |
| 1765 | |
| 1766 | def _generateVHBody(self): |
| 1767 | body = [] |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1768 | for bet in sorted(self.et_dict): |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 1769 | fet = self.tf_dict[bet] |
Tobin Ehlis | 9d8ba36 | 2015-04-15 17:04:03 -0600 | [diff] [blame] | 1770 | body.append("static inline uint32_t validate_%s(%s input_value)\n{" % (fet, fet)) |
| 1771 | # TODO : This is not ideal, but allows for flag combinations. Need more rigorous validation of realistic flag combinations |
Tobin Ehlis | d335065 | 2015-04-22 13:59:43 -0600 | [diff] [blame] | 1772 | if 'flagbits' in bet.lower(): |
Tobin Ehlis | 9d8ba36 | 2015-04-15 17:04:03 -0600 | [diff] [blame] | 1773 | body.append(' if (input_value > (%s))' % (' | '.join(self.et_dict[bet]))) |
| 1774 | body.append(' return 0;') |
| 1775 | body.append(' return 1;') |
| 1776 | body.append('}\n\n') |
| 1777 | else: |
| 1778 | body.append(' switch ((%s)input_value)\n {' % (fet)) |
| 1779 | for e in sorted(self.et_dict[bet]): |
| 1780 | if (self.ev_dict[e]['unique']): |
| 1781 | body.append(' case %s:' % (e)) |
| 1782 | body.append(' return 1;\n default:\n return 0;\n }\n}\n\n') |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 1783 | return "\n".join(body) |
| 1784 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1785 | def _generateSHBody(self): |
| 1786 | body = [] |
| 1787 | # with open(self.out_file, "a") as hf: |
| 1788 | # bet == base_enum_type, fet == final_enum_type |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1789 | for bet in sorted(self.et_dict): |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1790 | fet = self.tf_dict[bet] |
Ian Elliott | feae405 | 2015-02-18 12:38:04 -0700 | [diff] [blame] | 1791 | body.append("static inline const char* string_%s(%s input_value)\n{\n switch ((%s)input_value)\n {" % (fet, fet, fet)) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1792 | for e in sorted(self.et_dict[bet]): |
| 1793 | if (self.ev_dict[e]['unique']): |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1794 | body.append(' case %s:\n return "%s";' % (e, e)) |
| 1795 | body.append(' default:\n return "Unhandled %s";\n }\n}\n\n' % (fet)) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1796 | return "\n".join(body) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1797 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1798 | def _generateSHHeader(self): |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1799 | header = [] |
| 1800 | header.append('#pragma once\n') |
Ian Elliott | c779c7e | 2015-04-28 16:11:24 -0600 | [diff] [blame] | 1801 | header.append('#ifdef _WIN32\n') |
| 1802 | header.append('#pragma warning( disable : 4065 )\n') |
| 1803 | header.append('#endif\n') |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 1804 | header.append('#include <vulkan/%s>\n\n\n' % self.in_file) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1805 | return "\n".join(header) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1806 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1807 | |
| 1808 | class CMakeGen: |
| 1809 | def __init__(self, struct_wrapper=None, out_dir=None): |
| 1810 | self.sw = struct_wrapper |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1811 | self.include_headers = [] |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1812 | self.add_lib_file_list = self.sw.get_file_list() |
| 1813 | self.out_dir = out_dir |
| 1814 | self.out_file = os.path.join(self.out_dir, "CMakeLists.txt") |
| 1815 | self.cmg = CommonFileGen(self.out_file) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1816 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1817 | def generate(self): |
| 1818 | self.cmg.setBody(self._generateBody()) |
| 1819 | self.cmg.generate() |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 1820 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1821 | def _generateBody(self): |
| 1822 | body = [] |
| 1823 | body.append("project(%s)" % os.path.basename(self.out_dir)) |
| 1824 | body.append("cmake_minimum_required(VERSION 2.8)\n") |
| 1825 | body.append("add_library(${PROJECT_NAME} %s)\n" % " ".join(self.add_lib_file_list)) |
| 1826 | body.append('set(COMPILE_FLAGS "-fpermissive")') |
| 1827 | body.append('set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}")\n') |
| 1828 | body.append("include_directories(${SRC_DIR}/thirdparty/${GEN_API}/inc/)\n") |
| 1829 | body.append("target_include_directories (%s PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" % os.path.basename(self.out_dir)) |
| 1830 | return "\n".join(body) |
| 1831 | |
| 1832 | class GraphVizGen: |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1833 | def __init__(self, struct_dict, prefix, out_dir): |
| 1834 | self.struct_dict = struct_dict |
| 1835 | self.api = prefix |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1836 | if prefix == "vulkan": |
| 1837 | self.api_prefix = "vk" |
| 1838 | else: |
| 1839 | self.api_prefix = prefix |
| 1840 | self.out_file = os.path.join(out_dir, self.api_prefix+"_struct_graphviz_helper.h") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1841 | self.gvg = CommonFileGen(self.out_file) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1842 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1843 | def generate(self): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1844 | self.gvg.setCopyright("//This is the copyright\n") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1845 | self.gvg.setHeader(self._generateHeader()) |
| 1846 | self.gvg.setBody(self._generateBody()) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1847 | #self.gvg.setFooter('}') |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1848 | self.gvg.generate() |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1849 | |
| 1850 | def set_include_headers(self, include_headers): |
| 1851 | self.include_headers = include_headers |
| 1852 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1853 | def _generateHeader(self): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1854 | header = [] |
| 1855 | header.append("//#includes, #defines, globals and such...\n") |
| 1856 | for f in self.include_headers: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1857 | if 'vk_enum_string_helper' not in f: |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1858 | header.append("#include <%s>\n" % f) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1859 | #header.append('#include "vk_enum_string_helper.h"\n\n// Function Prototypes\n') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1860 | header.append("\nchar* dynamic_gv_display(const void* pStruct, const char* prefix);\n") |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1861 | return "".join(header) |
| 1862 | |
| 1863 | def _get_gv_func_name(self, struct): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1864 | return "%s_gv_print_%s" % (self.api_prefix, struct.lower().strip("_")) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1865 | |
| 1866 | # Return elements to create formatted string for given struct member |
| 1867 | def _get_struct_gv_print_formatted(self, struct_member, pre_var_name="", postfix = "\\n", struct_var_name="pStruct", struct_ptr=True, print_array=False, port_label=""): |
| 1868 | struct_op = "->" |
| 1869 | pre_var_name = '"%s "' % struct_member['full_type'] |
| 1870 | if not struct_ptr: |
| 1871 | struct_op = "." |
| 1872 | member_name = struct_member['name'] |
| 1873 | print_type = "p" |
| 1874 | cast_type = "" |
| 1875 | member_post = "" |
| 1876 | array_index = "" |
| 1877 | member_print_post = "" |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 1878 | print_delimiter = "%" |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1879 | if struct_member['array'] and 'char' in struct_member['type'].lower(): # just print char array as string |
| 1880 | print_type = "p" |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1881 | print_array = False |
| 1882 | elif struct_member['array'] and not print_array: |
| 1883 | # Just print base address of array when not full print_array |
| 1884 | cast_type = "(void*)" |
| 1885 | elif is_type(struct_member['type'], 'enum'): |
Jon Ashburn | fe6113c | 2015-01-09 09:11:44 -0700 | [diff] [blame] | 1886 | if struct_member['ptr']: |
| 1887 | struct_var_name = "*" + struct_var_name |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1888 | cast_type = "string_%s" % struct_member['type'] |
| 1889 | print_type = "s" |
| 1890 | elif is_type(struct_member['type'], 'struct'): # print struct address for now |
| 1891 | cast_type = "(void*)" |
| 1892 | if not struct_member['ptr']: |
| 1893 | cast_type = "(void*)&" |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 1894 | elif 'bool' in struct_member['type'].lower(): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1895 | print_type = "s" |
| 1896 | member_post = ' ? "TRUE" : "FALSE"' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1897 | elif 'float' in struct_member['type']: |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1898 | print_type = "f" |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1899 | elif 'uint64' in struct_member['type'] or 'gpusize' in struct_member['type'].lower(): |
| 1900 | print_type = '" PRId64 "' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1901 | elif 'uint8' in struct_member['type']: |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1902 | print_type = "hu" |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1903 | elif 'size' in struct_member['type'].lower(): |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 1904 | print_type = '" PRINTF_SIZE_T_SPECIFIER "' |
| 1905 | print_delimiter = "" |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1906 | elif True in [ui_str.lower() in struct_member['type'].lower() for ui_str in ['uint', 'flags', 'samplemask']]: |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1907 | print_type = "u" |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1908 | elif 'int' in struct_member['type']: |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1909 | print_type = "i" |
| 1910 | elif struct_member['ptr']: |
| 1911 | pass |
| 1912 | else: |
| 1913 | #print("Unhandled struct type: %s" % struct_member['type']) |
| 1914 | cast_type = "(void*)" |
| 1915 | if print_array and struct_member['array']: |
| 1916 | member_print_post = "[%u]" |
| 1917 | array_index = " i," |
| 1918 | member_post = "[i]" |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 1919 | print_out = "<TR><TD>%%s%s%s</TD><TD%s>%s%s%s</TD></TR>" % (member_name, member_print_post, port_label, print_delimiter, print_type, postfix) # section of print that goes inside of quotes |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1920 | print_arg = ", %s,%s %s(%s%s%s)%s\n" % (pre_var_name, array_index, cast_type, struct_var_name, struct_op, member_name, member_post) # section of print passed to portion in quotes |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1921 | return (print_out, print_arg) |
| 1922 | |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 1923 | def _generateBody(self): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1924 | gv_funcs = [] |
| 1925 | array_func_list = [] # structs for which we'll generate an array version of their print function |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1926 | array_func_list.append('vkbufferviewattachinfo') |
| 1927 | array_func_list.append('vkimageviewattachinfo') |
| 1928 | array_func_list.append('vksamplerimageviewinfo') |
| 1929 | array_func_list.append('vkdescriptortypecount') |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1930 | # For first pass, generate prototype |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1931 | for s in sorted(self.struct_dict): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1932 | gv_funcs.append('char* %s(const %s* pStruct, const char* myNodeName);\n' % (self._get_gv_func_name(s), typedef_fwd_dict[s])) |
| 1933 | if s.lower().strip("_") in array_func_list: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1934 | if s.lower().strip("_") in ['vkbufferviewattachinfo', 'vkimageviewattachinfo']: |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 1935 | gv_funcs.append('char* %s_array(uint32_t count, const %s* const* pStruct, const char* myNodeName);\n' % (self._get_gv_func_name(s), typedef_fwd_dict[s])) |
| 1936 | else: |
| 1937 | gv_funcs.append('char* %s_array(uint32_t count, const %s* pStruct, const char* myNodeName);\n' % (self._get_gv_func_name(s), typedef_fwd_dict[s])) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1938 | gv_funcs.append('\n') |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 1939 | for s in sorted(self.struct_dict): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1940 | p_out = "" |
| 1941 | p_args = "" |
| 1942 | stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs |
| 1943 | # the fields below are a super-hacky way for now to get port labels into GV output, TODO : Clean this up! |
| 1944 | pl_dict = {} |
| 1945 | struct_num = 0 |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 1946 | # This isn't great but this pre-pass flags structs w/ pNext and other struct ptrs |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1947 | for m in sorted(self.struct_dict[s]): |
| 1948 | if 'pNext' == self.struct_dict[s][m]['name'] or is_type(self.struct_dict[s][m]['type'], 'struct'): |
| 1949 | stp_list.append(self.struct_dict[s][m]) |
| 1950 | if 'pNext' == self.struct_dict[s][m]['name']: |
| 1951 | pl_dict[m] = ' PORT=\\"pNext\\"' |
| 1952 | else: |
| 1953 | pl_dict[m] = ' PORT=\\"struct%i\\"' % struct_num |
| 1954 | struct_num += 1 |
| 1955 | gv_funcs.append('char* %s(const %s* pStruct, const char* myNodeName)\n{\n char* str;\n' % (self._get_gv_func_name(s), typedef_fwd_dict[s])) |
| 1956 | num_stps = len(stp_list); |
| 1957 | total_strlen_str = '' |
| 1958 | if 0 != num_stps: |
| 1959 | gv_funcs.append(" char* tmpStr;\n") |
| 1960 | gv_funcs.append(" char nodeName[100];\n") |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1961 | gv_funcs.append(' char* stp_strs[%i];\n' % num_stps) |
| 1962 | for index in range(num_stps): |
| 1963 | if (stp_list[index]['ptr']): |
| 1964 | if 'pDescriptorInfo' == stp_list[index]['name']: |
| 1965 | gv_funcs.append(' if (pStruct->pDescriptorInfo && (0 != pStruct->descriptorCount)) {\n') |
| 1966 | else: |
| 1967 | gv_funcs.append(' if (pStruct->%s) {\n' % stp_list[index]['name']) |
| 1968 | if 'pNext' == stp_list[index]['name']: |
| 1969 | gv_funcs.append(' sprintf(nodeName, "pNext_%p", (void*)pStruct->pNext);\n') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1970 | gv_funcs.append(' tmpStr = dynamic_gv_display((void*)pStruct->pNext, nodeName);\n') |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1971 | gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % index) |
| 1972 | gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":pNext -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % index) |
| 1973 | gv_funcs.append(' free(tmpStr);\n') |
| 1974 | else: |
| 1975 | gv_funcs.append(' sprintf(nodeName, "%s_%%p", (void*)pStruct->%s);\n' % (stp_list[index]['name'], stp_list[index]['name'])) |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 1976 | if stp_list[index]['name'] in ['pTypeCount', 'pSamplerImageViews']: |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 1977 | gv_funcs.append(' tmpStr = %s_array(pStruct->count, pStruct->%s, nodeName);\n' % (self._get_gv_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1978 | else: |
| 1979 | gv_funcs.append(' tmpStr = %s(pStruct->%s, nodeName);\n' % (self._get_gv_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
| 1980 | gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % (index)) |
| 1981 | gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":struct%i -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % (index, index)) |
| 1982 | gv_funcs.append(' }\n') |
Chia-I Wu | 3bf80a6 | 2014-12-16 00:36:58 +0800 | [diff] [blame] | 1983 | gv_funcs.append(" else\n stp_strs[%i] = \"\";\n" % (index)) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 1984 | elif stp_list[index]['array']: # TODO : For now just printing first element of array |
| 1985 | gv_funcs.append(' sprintf(nodeName, "%s_%%p", (void*)&pStruct->%s[0]);\n' % (stp_list[index]['name'], stp_list[index]['name'])) |
| 1986 | gv_funcs.append(' tmpStr = %s(&pStruct->%s[0], nodeName);\n' % (self._get_gv_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
| 1987 | gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % (index)) |
| 1988 | gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":struct%i -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % (index, index)) |
| 1989 | else: |
| 1990 | gv_funcs.append(' sprintf(nodeName, "%s_%%p", (void*)&pStruct->%s);\n' % (stp_list[index]['name'], stp_list[index]['name'])) |
| 1991 | gv_funcs.append(' tmpStr = %s(&pStruct->%s, nodeName);\n' % (self._get_gv_func_name(stp_list[index]['type']), stp_list[index]['name'])) |
| 1992 | gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % (index)) |
| 1993 | gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":struct%i -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % (index, index)) |
| 1994 | total_strlen_str += 'strlen(stp_strs[%i]) + ' % index |
| 1995 | gv_funcs.append(' str = (char*)malloc(%ssizeof(char)*2048);\n' % (total_strlen_str)) |
| 1996 | gv_funcs.append(' sprintf(str, "\\"%s\\" [\\nlabel = <<TABLE BORDER=\\"0\\" CELLBORDER=\\"1\\" CELLSPACING=\\"0\\"><TR><TD COLSPAN=\\"2\\">%s (%p)</TD></TR>') |
| 1997 | p_args = ", myNodeName, myNodeName, pStruct" |
| 1998 | for m in sorted(self.struct_dict[s]): |
| 1999 | plabel = "" |
| 2000 | if m in pl_dict: |
| 2001 | plabel = pl_dict[m] |
| 2002 | (p_out1, p_args1) = self._get_struct_gv_print_formatted(self.struct_dict[s][m], port_label=plabel) |
| 2003 | p_out += p_out1 |
| 2004 | p_args += p_args1 |
| 2005 | p_out += '</TABLE>>\\n];\\n\\n"' |
| 2006 | p_args += ");\n" |
| 2007 | gv_funcs.append(p_out) |
| 2008 | gv_funcs.append(p_args) |
| 2009 | if 0 != num_stps: |
| 2010 | gv_funcs.append(' for (int32_t stp_index = %i; stp_index >= 0; stp_index--) {\n' % (num_stps-1)) |
| 2011 | gv_funcs.append(' if (0 < strlen(stp_strs[stp_index])) {\n') |
| 2012 | gv_funcs.append(' strncat(str, stp_strs[stp_index], strlen(stp_strs[stp_index]));\n') |
| 2013 | gv_funcs.append(' free(stp_strs[stp_index]);\n') |
| 2014 | gv_funcs.append(' }\n') |
| 2015 | gv_funcs.append(' }\n') |
| 2016 | gv_funcs.append(" return str;\n}\n") |
| 2017 | if s.lower().strip("_") in array_func_list: |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 2018 | ptr_array = False |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2019 | if s.lower().strip("_") in ['vkbufferviewattachinfo', 'vkimageviewattachinfo']: |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 2020 | ptr_array = True |
| 2021 | gv_funcs.append('char* %s_array(uint32_t count, const %s* const* pStruct, const char* myNodeName)\n{\n char* str;\n char tmpStr[1024];\n' % (self._get_gv_func_name(s), typedef_fwd_dict[s])) |
| 2022 | else: |
| 2023 | gv_funcs.append('char* %s_array(uint32_t count, const %s* pStruct, const char* myNodeName)\n{\n char* str;\n char tmpStr[1024];\n' % (self._get_gv_func_name(s), typedef_fwd_dict[s])) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2024 | gv_funcs.append(' str = (char*)malloc(sizeof(char)*1024*count);\n') |
| 2025 | gv_funcs.append(' sprintf(str, "\\"%s\\" [\\nlabel = <<TABLE BORDER=\\"0\\" CELLBORDER=\\"1\\" CELLSPACING=\\"0\\"><TR><TD COLSPAN=\\"3\\">%s (%p)</TD></TR>", myNodeName, myNodeName, pStruct);\n') |
| 2026 | gv_funcs.append(' for (uint32_t i=0; i < count; i++) {\n') |
| 2027 | gv_funcs.append(' sprintf(tmpStr, "'); |
| 2028 | p_args = "" |
| 2029 | p_out = "" |
| 2030 | for m in sorted(self.struct_dict[s]): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2031 | plabel = "" |
| 2032 | (p_out1, p_args1) = self._get_struct_gv_print_formatted(self.struct_dict[s][m], port_label=plabel) |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 2033 | if 0 == m: # Add array index notation at end of first row |
| 2034 | p_out1 = '%s<TD ROWSPAN=\\"%i\\" PORT=\\"slot%%u\\">%%u</TD></TR>' % (p_out1[:-5], len(self.struct_dict[s])) |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2035 | p_args1 += ', i, i' |
| 2036 | p_out += p_out1 |
| 2037 | p_args += p_args1 |
| 2038 | p_out += '"' |
| 2039 | p_args += ");\n" |
Tobin Ehlis | b8013a2 | 2015-02-26 12:57:08 -0700 | [diff] [blame] | 2040 | if ptr_array: |
| 2041 | p_args = p_args.replace('->', '[i]->') |
| 2042 | else: |
| 2043 | p_args = p_args.replace('->', '[i].') |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2044 | gv_funcs.append(p_out); |
| 2045 | gv_funcs.append(p_args); |
| 2046 | gv_funcs.append(' strncat(str, tmpStr, strlen(tmpStr));\n') |
| 2047 | gv_funcs.append(' }\n') |
| 2048 | gv_funcs.append(' strncat(str, "</TABLE>>\\n];\\n\\n", 20);\n') |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2049 | gv_funcs.append(' return str;\n}\n') |
| 2050 | # Add function to dynamically print out unknown struct |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2051 | gv_funcs.append("char* dynamic_gv_display(const void* pStruct, const char* nodeName)\n{\n") |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2052 | gv_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct\n") |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2053 | gv_funcs.append(" VkStructureType sType = ((VkApplicationInfo*)pStruct)->sType;\n") |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2054 | gv_funcs.append(" switch (sType)\n {\n") |
| 2055 | for e in enum_type_dict: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2056 | if "StructureType" in e: |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2057 | for v in sorted(enum_type_dict[e]): |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 2058 | struct_name = get_struct_name_from_struct_type(v) |
Chia-I Wu | 736324e | 2015-10-26 20:42:12 +0800 | [diff] [blame] | 2059 | if struct_name not in self.struct_dict: |
| 2060 | continue |
| 2061 | |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2062 | print_func_name = self._get_gv_func_name(struct_name) |
| 2063 | # TODO : Hand-coded fixes for some exceptions |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2064 | #if 'VkPipelineCbStateCreateInfo' in struct_name: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2065 | # struct_name = 'VK_PIPELINE_CB_STATE' |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2066 | if 'VkSemaphoreCreateInfo' in struct_name: |
| 2067 | struct_name = 'VkSemaphoreCreateInfo' |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2068 | print_func_name = self._get_gv_func_name(struct_name) |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2069 | elif 'VkSemaphoreOpenInfo' in struct_name: |
| 2070 | struct_name = 'VkSemaphoreOpenInfo' |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2071 | print_func_name = self._get_gv_func_name(struct_name) |
| 2072 | gv_funcs.append(' case %s:\n' % (v)) |
| 2073 | gv_funcs.append(' return %s((%s*)pStruct, nodeName);\n' % (print_func_name, struct_name)) |
| 2074 | #gv_funcs.append(' }\n') |
| 2075 | #gv_funcs.append(' break;\n') |
Chia-I Wu | bfa3fea | 2014-12-16 00:43:20 +0800 | [diff] [blame] | 2076 | gv_funcs.append(" default:\n") |
| 2077 | gv_funcs.append(" return NULL;\n") |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2078 | gv_funcs.append(" }\n") |
| 2079 | gv_funcs.append("}") |
| 2080 | return "".join(gv_funcs) |
| 2081 | |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | |
| 2086 | # def _generateHeader(self): |
| 2087 | # hdr = [] |
| 2088 | # hdr.append('digraph g {\ngraph [\nrankdir = "LR"\n];') |
| 2089 | # hdr.append('node [\nfontsize = "16"\nshape = "plaintext"\n];') |
| 2090 | # hdr.append('edge [\n];\n') |
| 2091 | # return "\n".join(hdr) |
Mark Lobodzinski | 28b8f02 | 2015-08-27 15:30:29 -0600 | [diff] [blame] | 2092 | # |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2093 | # def _generateBody(self): |
| 2094 | # body = [] |
Peter Lohrmann | 49ea184 | 2015-03-30 16:29:56 -0700 | [diff] [blame] | 2095 | # for s in sorted(self.struc_dict): |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 2096 | # field_num = 1 |
| 2097 | # body.append('"%s" [\nlabel = <<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD COLSPAN="2" PORT="f0">%s</TD></TR>' % (s, typedef_fwd_dict[s])) |
| 2098 | # for m in sorted(self.struc_dict[s]): |
| 2099 | # body.append('<TR><TD PORT="f%i">%s</TD><TD PORT="f%i">%s</TD></TR>' % (field_num, self.struc_dict[s][m]['full_type'], field_num+1, self.struc_dict[s][m]['name'])) |
| 2100 | # field_num += 2 |
| 2101 | # body.append('</TABLE>>\n];\n') |
| 2102 | # return "".join(body) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2103 | |
| 2104 | def main(argv=None): |
| 2105 | opts = handle_args() |
| 2106 | # Parse input file and fill out global dicts |
| 2107 | hfp = HeaderFileParser(opts.input_file) |
| 2108 | hfp.parse() |
| 2109 | # TODO : Don't want these to be global, see note at top about wrapper classes |
| 2110 | global enum_val_dict |
| 2111 | global enum_type_dict |
| 2112 | global struct_dict |
| 2113 | global typedef_fwd_dict |
| 2114 | global typedef_rev_dict |
| 2115 | global types_dict |
| 2116 | enum_val_dict = hfp.get_enum_val_dict() |
| 2117 | enum_type_dict = hfp.get_enum_type_dict() |
| 2118 | struct_dict = hfp.get_struct_dict() |
Tobin Ehlis | 5a487e5 | 2014-11-11 12:28:12 -0700 | [diff] [blame] | 2119 | # TODO : Would like to validate struct data here to verify that all of the bools for struct members are correct at this point |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2120 | typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 2121 | typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 2122 | types_dict = hfp.get_types_dict() |
| 2123 | #print(enum_val_dict) |
| 2124 | #print(typedef_dict) |
| 2125 | #print(struct_dict) |
Jeremy Hayes | df3f205 | 2015-11-26 13:32:58 -0700 | [diff] [blame] | 2126 | input_header = os.path.basename(opts.input_file) |
| 2127 | if 'vulkan.h' == input_header: |
| 2128 | input_header = "vulkan/vulkan.h" |
Jon Ashburn | 54e2460 | 2016-02-01 17:02:38 -0700 | [diff] [blame] | 2129 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2130 | prefix = os.path.basename(opts.input_file).strip(".h") |
| 2131 | if prefix == "vulkan": |
| 2132 | prefix = "vk" |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2133 | if (opts.abs_out_dir is not None): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2134 | enum_sh_filename = os.path.join(opts.abs_out_dir, prefix+"_enum_string_helper.h") |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2135 | else: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2136 | enum_sh_filename = os.path.join(os.getcwd(), opts.rel_out_dir, prefix+"_enum_string_helper.h") |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 2137 | enum_sh_filename = os.path.abspath(enum_sh_filename) |
| 2138 | if not os.path.exists(os.path.dirname(enum_sh_filename)): |
| 2139 | print("Creating output dir %s" % os.path.dirname(enum_sh_filename)) |
| 2140 | os.mkdir(os.path.dirname(enum_sh_filename)) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2141 | if opts.gen_enum_string_helper: |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 2142 | print("Generating enum string helper to %s" % enum_sh_filename) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2143 | enum_vh_filename = os.path.join(os.path.dirname(enum_sh_filename), prefix+"_enum_validate_helper.h") |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 2144 | print("Generating enum validate helper to %s" % enum_vh_filename) |
| 2145 | eg = EnumCodeGen(enum_type_dict, enum_val_dict, typedef_fwd_dict, os.path.basename(opts.input_file), enum_sh_filename, enum_vh_filename) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2146 | eg.generateStringHelper() |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 2147 | eg.generateEnumValidate() |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2148 | #for struct in struct_dict: |
| 2149 | #print(struct) |
| 2150 | if opts.gen_struct_wrappers: |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 2151 | sw = StructWrapperGen(struct_dict, os.path.basename(opts.input_file).strip(".h"), os.path.dirname(enum_sh_filename)) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2152 | #print(sw.get_class_name(struct)) |
Jeremy Hayes | df3f205 | 2015-11-26 13:32:58 -0700 | [diff] [blame] | 2153 | sw.set_include_headers([input_header,os.path.basename(enum_sh_filename),"stdint.h","inttypes.h", "stdio.h","stdlib.h"]) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2154 | print("Generating struct wrapper header to %s" % sw.header_filename) |
| 2155 | sw.generateHeader() |
| 2156 | print("Generating struct wrapper class to %s" % sw.class_filename) |
| 2157 | sw.generateBody() |
| 2158 | sw.generateStringHelper() |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 2159 | sw.generateValidateHelper() |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 2160 | # Generate a 2nd helper file that excludes addrs |
| 2161 | sw.set_no_addr(True) |
| 2162 | sw.generateStringHelper() |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 2163 | sw.set_no_addr(False) |
Jeremy Hayes | df3f205 | 2015-11-26 13:32:58 -0700 | [diff] [blame] | 2164 | sw.set_include_headers([input_header,os.path.basename(enum_sh_filename),"stdint.h","stdio.h","stdlib.h","iostream","sstream","string"]) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 2165 | sw.set_no_addr(True) |
| 2166 | sw.generateStringHelperCpp() |
Tobin Ehlis | 5178bd7 | 2015-03-06 10:38:25 -0700 | [diff] [blame] | 2167 | sw.set_no_addr(False) |
| 2168 | sw.generateStringHelperCpp() |
Jeremy Hayes | df3f205 | 2015-11-26 13:32:58 -0700 | [diff] [blame] | 2169 | sw.set_include_headers(["stdio.h", "stdlib.h", input_header]) |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 2170 | sw.generateSizeHelper() |
Peter Lohrmann | 4a8d891 | 2015-04-03 11:43:06 -0700 | [diff] [blame] | 2171 | sw.generateSizeHelperC() |
Tobin Ehlis | 3764969 | 2016-02-10 15:32:46 -0700 | [diff] [blame] | 2172 | sw.generateSafeStructHeader() |
| 2173 | sw.generateSafeStructs() |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 2174 | if opts.gen_struct_sizes: |
| 2175 | st = StructWrapperGen(struct_dict, os.path.basename(opts.input_file).strip(".h"), os.path.dirname(enum_sh_filename)) |
Jeremy Hayes | df3f205 | 2015-11-26 13:32:58 -0700 | [diff] [blame] | 2176 | st.set_include_headers(["stdio.h", "stdlib.h", input_header]) |
Jon Ashburn | ea65e49 | 2015-08-06 17:27:49 -0600 | [diff] [blame] | 2177 | st.generateSizeHelper() |
| 2178 | st.generateSizeHelperC() |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2179 | if opts.gen_cmake: |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 2180 | cmg = CMakeGen(sw, os.path.dirname(enum_sh_filename)) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2181 | cmg.generate() |
| 2182 | if opts.gen_graphviz: |
Tobin Ehlis | 7c47fc4 | 2014-12-17 07:20:23 -0700 | [diff] [blame] | 2183 | gv = GraphVizGen(struct_dict, os.path.basename(opts.input_file).strip(".h"), os.path.dirname(enum_sh_filename)) |
Jeremy Hayes | df3f205 | 2015-11-26 13:32:58 -0700 | [diff] [blame] | 2184 | gv.set_include_headers([input_header,os.path.basename(enum_sh_filename),"stdint.h","stdio.h","stdlib.h", "inttypes.h"]) |
Tobin Ehlis | 6442dca | 2014-10-22 15:13:53 -0600 | [diff] [blame] | 2185 | gv.generate() |
| 2186 | print("DONE!") |
| 2187 | #print(typedef_rev_dict) |
| 2188 | #print(types_dict) |
| 2189 | #recreate_structs() |
| 2190 | |
| 2191 | if __name__ == "__main__": |
| 2192 | sys.exit(main()) |