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