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