blob: 33e1348761c890c103520c3d00d1274c01cf2f4d [file] [log] [blame]
Tobin Ehlis3ed06942014-11-10 16:03:19 -07001#!/usr/bin/env python3
2#
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003# VK
Tobin Ehlis3ed06942014-11-10 16:03:19 -07004#
5# Copyright (C) 2014 LunarG, Inc.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a
8# copy of this software and associated documentation files (the "Software"),
9# to deal in the Software without restriction, including without limitation
10# the rights to use, copy, modify, merge, publish, distribute, sublicense,
11# and/or sell copies of the Software, and to permit persons to whom the
12# Software is furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included
15# in all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23# DEALINGS IN THE SOFTWARE.
Tobin Ehlisee33fa52014-10-22 15:13:53 -060024import argparse
25import os
26import sys
27
28# code_gen.py overview
29# This script generates code based on input headers
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060030# Initially it's intended to support Mantle and VK headers and
Tobin Ehlisee33fa52014-10-22 15:13:53 -060031# generate wrappers functions that can be used to display
32# structs in a human-readable txt format, as well as utility functions
33# to print enum values as strings
34
35
36def handle_args():
37 parser = argparse.ArgumentParser(description='Perform analysis of vogl trace.')
38 parser.add_argument('input_file', help='The input header file from which code will be generated.')
39 parser.add_argument('--rel_out_dir', required=False, default='glave_gen', help='Path relative to exec path to write output files. Will be created if needed.')
40 parser.add_argument('--abs_out_dir', required=False, default=None, help='Absolute path to write output files. Will be created if needed.')
41 parser.add_argument('--gen_enum_string_helper', required=False, action='store_true', default=False, help='Enable generation of helper header file to print string versions of enums.')
42 parser.add_argument('--gen_struct_wrappers', required=False, action='store_true', default=False, help='Enable generation of struct wrapper classes.')
43 parser.add_argument('--gen_cmake', required=False, action='store_true', default=False, help='Enable generation of cmake file for generated code.')
44 parser.add_argument('--gen_graphviz', required=False, action='store_true', default=False, help='Enable generation of graphviz dot file.')
45 #parser.add_argument('--test', action='store_true', default=False, help='Run simple test.')
46 return parser.parse_args()
47
48# TODO : Ideally these data structs would be opaque to user and could be wrapped
49# in their own class(es) to make them friendly for data look-up
50# Dicts for Data storage
51# enum_val_dict[value_name] = dict keys are the string enum value names for all enums
52# |-------->['type'] = the type of enum class into which the value falls
53# |-------->['val'] = the value assigned to this particular value_name
54# '-------->['unique'] = bool designating if this enum 'val' is unique within this enum 'type'
55enum_val_dict = {}
56# enum_type_dict['type'] = the type or class of of enum
57# '----->['val_name1', 'val_name2'...] = each type references a list of val_names within this type
58enum_type_dict = {}
59# struct_dict['struct_basename'] = the base (non-typedef'd) name of the struct
60# |->[<member_num>] = members are stored via their integer placement in the struct
61# | |->['name'] = string name of this struct member
62# ... |->['full_type'] = complete type qualifier for this member
63# |->['type'] = base type for this member
64# |->['ptr'] = bool indicating if this member is ptr
65# |->['const'] = bool indicating if this member is const
66# |->['struct'] = bool indicating if this member is a struct type
67# |->['array'] = bool indicating if this member is an array
Tobin Ehlisf57562c2015-03-13 07:18:05 -060068# |->['dyn_array'] = bool indicating if member is a dynamically sized array
69# '->['array_size'] = For dyn_array, member name used to size array, else int size for static array
Tobin Ehlisee33fa52014-10-22 15:13:53 -060070struct_dict = {}
71# typedef_fwd_dict stores mapping from orig_type_name -> new_type_name
72typedef_fwd_dict = {}
73# typedef_rev_dict stores mapping from new_type_name -> orig_type_name
74typedef_rev_dict = {} # store new_name -> orig_name mapping
75# types_dict['id_name'] = identifier name will map to it's type
76# '---->'type' = currently either 'struct' or 'enum'
77types_dict = {} # store orig_name -> type mapping
78
79
80# Class that parses header file and generates data structures that can
81# Then be used for other tasks
82class HeaderFileParser:
83 def __init__(self, header_file=None):
84 self.header_file = header_file
85 # store header data in various formats, see above for more info
86 self.enum_val_dict = {}
87 self.enum_type_dict = {}
88 self.struct_dict = {}
89 self.typedef_fwd_dict = {}
90 self.typedef_rev_dict = {}
91 self.types_dict = {}
Tobin Ehlis91cc24a2015-03-06 10:38:25 -070092 self.last_struct_count_name = ''
Tobin Ehlisee33fa52014-10-22 15:13:53 -060093
94 def setHeaderFile(self, header_file):
95 self.header_file = header_file
96
97 def get_enum_val_dict(self):
98 return self.enum_val_dict
99
100 def get_enum_type_dict(self):
101 return self.enum_type_dict
102
103 def get_struct_dict(self):
104 return self.struct_dict
105
106 def get_typedef_fwd_dict(self):
107 return self.typedef_fwd_dict
108
109 def get_typedef_rev_dict(self):
110 return self.typedef_rev_dict
111
112 def get_types_dict(self):
113 return self.types_dict
114
115 # Parse header file into data structures
116 def parse(self):
117 # parse through the file, identifying different sections
118 parse_enum = False
119 parse_struct = False
120 member_num = 0
121 # TODO : Comment parsing is very fragile but handles 2 known files
122 block_comment = False
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700123 prev_count_name = ''
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600124 with open(self.header_file) as f:
125 for line in f:
126 if block_comment:
127 if '*/' in line:
128 block_comment = False
129 continue
130 if '/*' in line:
131 block_comment = True
132 elif 0 == len(line.split()):
133 #print("Skipping empty line")
134 continue
135 elif line.split()[0].strip().startswith("//"):
Jon Ashburna0ddc902015-01-09 09:11:44 -0700136 #print("Skipping commented line %s" % line)
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600137 continue
138 elif 'typedef enum' in line:
139 (ty_txt, en_txt, base_type) = line.strip().split(None, 2)
140 #print("Found ENUM type %s" % base_type)
141 parse_enum = True
Jon Ashburna0ddc902015-01-09 09:11:44 -0700142 default_enum_val = 0
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600143 self.types_dict[base_type] = 'enum'
144 elif 'typedef struct' in line:
145 (ty_txt, st_txt, base_type) = line.strip().split(None, 2)
146 #print("Found STRUCT type: %s" % base_type)
147 parse_struct = True
148 self.types_dict[base_type] = 'struct'
Jon Ashburna0ddc902015-01-09 09:11:44 -0700149 elif 'typedef union' in line:
150 (ty_txt, st_txt, base_type) = line.strip().split(None, 2)
151 #print("Found UNION type: %s" % base_type)
152 parse_struct = True
153 self.types_dict[base_type] = 'struct'
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600154 elif '}' in line and (parse_enum or parse_struct):
155 if len(line.split()) > 1: # deals with embedded union in one struct
156 parse_enum = False
157 parse_struct = False
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700158 self.last_struct_count_name = ''
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600159 member_num = 0
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600160 (cur_char, targ_type) = line.strip().split(None, 1)
161 self.typedef_fwd_dict[base_type] = targ_type.strip(';')
162 self.typedef_rev_dict[targ_type.strip(';')] = base_type
163 elif parse_enum:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600164 #if 'VK_MAX_ENUM' not in line and '{' not in line:
165 if True not in [ens in line for ens in ['{', 'VK_MAX_ENUM', '_RANGE']]:
Jon Ashburna0ddc902015-01-09 09:11:44 -0700166 self._add_enum(line, base_type, default_enum_val)
167 default_enum_val += 1
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600168 elif parse_struct:
169 if ';' in line:
170 self._add_struct(line, base_type, member_num)
171 member_num = member_num + 1
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600172
173 # populate enum dicts based on enum lines
Jon Ashburna0ddc902015-01-09 09:11:44 -0700174 def _add_enum(self, line_txt, enum_type, def_enum_val):
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600175 #print("Parsing enum line %s" % line_txt)
Jon Ashburna0ddc902015-01-09 09:11:44 -0700176 if '=' in line_txt:
177 (enum_name, eq_char, enum_val) = line_txt.split(None, 2)
178 else:
179 enum_name = line_txt.split(',')[0]
180 enum_val = str(def_enum_val)
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600181 self.enum_val_dict[enum_name] = {}
182 self.enum_val_dict[enum_name]['type'] = enum_type
183 # strip comma and comment, then extra split in case of no comma w/ comments
184 enum_val = enum_val.strip().split(',', 1)[0]
185 self.enum_val_dict[enum_name]['val'] = enum_val.split()[0]
Tobin Ehlis5e848502014-12-05 12:13:07 -0700186 # account for negative values surrounded by parens
187 self.enum_val_dict[enum_name]['val'] = self.enum_val_dict[enum_name]['val'].strip(')').replace('-(', '-')
188 # Try to cast to int to determine if enum value is unique
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600189 try:
190 #print("ENUM val:", self.enum_val_dict[enum_name]['val'])
191 int(self.enum_val_dict[enum_name]['val'], 0)
192 self.enum_val_dict[enum_name]['unique'] = True
193 #print("ENUM has num value")
194 except ValueError:
195 self.enum_val_dict[enum_name]['unique'] = False
196 #print("ENUM is not a number value")
197 # Update enum_type_dict as well
198 if not enum_type in self.enum_type_dict:
199 self.enum_type_dict[enum_type] = []
200 self.enum_type_dict[enum_type].append(enum_name)
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700201
202 # Return True of struct member is a dynamic array
203 # RULES : This is a bit quirky based on the API
204 # NOTE : Changes in API spec may cause these rules to change
205 # 1. There must be a previous uint var w/ 'count' in the name in the struct
206 # 2. Dynam array must have 'const' and '*' qualifiers
207 # 3a. Name of dynam array must end in 's' char OR
208 # 3b. Name of count var minus 'count' must be contained in name of dynamic array
209 def _is_dynamic_array(self, full_type, name):
210 if '' != self.last_struct_count_name:
211 if 'const' in full_type and '*' in full_type:
212 if name.endswith('s') or self.last_struct_count_name.lower().replace('count', '') in name.lower():
213 return True
214 return False
215
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600216 # populate struct dicts based on struct lines
217 # TODO : Handle ":" bitfield, "**" ptr->ptr and "const type*const*"
218 def _add_struct(self, line_txt, struct_type, num):
219 #print("Parsing struct line %s" % line_txt)
220 if not struct_type in self.struct_dict:
221 self.struct_dict[struct_type] = {}
222 members = line_txt.strip().split(';', 1)[0] # first strip semicolon & comments
223 # TODO : Handle bitfields more correctly
224 members = members.strip().split(':', 1)[0] # strip bitfield element
225 (member_type, member_name) = members.rsplit(None, 1)
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700226 # Store counts to help recognize and size dynamic arrays
227 if 'count' in member_name.lower() and 'uint' in member_type:
228 self.last_struct_count_name = member_name
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600229 self.struct_dict[struct_type][num] = {}
230 self.struct_dict[struct_type][num]['full_type'] = member_type
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700231 self.struct_dict[struct_type][num]['dyn_array'] = False
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600232 if '*' in member_type:
233 self.struct_dict[struct_type][num]['ptr'] = True
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700234 # TODO : Need more general purpose way here to reduce down to basic type
235 member_type = member_type.replace(' const*', '')
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600236 member_type = member_type.strip('*')
237 else:
238 self.struct_dict[struct_type][num]['ptr'] = False
239 if 'const' in member_type:
240 self.struct_dict[struct_type][num]['const'] = True
241 member_type = member_type.strip('const').strip()
242 else:
243 self.struct_dict[struct_type][num]['const'] = False
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700244 # TODO : There is a bug here where it seems that at the time we do this check,
245 # the data is not in the types or typedef_rev_dict, so we never pass this if check
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600246 if is_type(member_type, 'struct'):
247 self.struct_dict[struct_type][num]['struct'] = True
248 else:
249 self.struct_dict[struct_type][num]['struct'] = False
250 self.struct_dict[struct_type][num]['type'] = member_type
251 if '[' in member_name:
252 (member_name, array_size) = member_name.split('[', 1)
253 self.struct_dict[struct_type][num]['array'] = True
254 self.struct_dict[struct_type][num]['array_size'] = array_size.strip(']')
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700255 elif self._is_dynamic_array(self.struct_dict[struct_type][num]['full_type'], member_name):
256 #print("Found dynamic array %s of size %s" % (member_name, self.last_struct_count_name))
257 self.struct_dict[struct_type][num]['array'] = True
258 self.struct_dict[struct_type][num]['dyn_array'] = True
259 self.struct_dict[struct_type][num]['array_size'] = self.last_struct_count_name
Tobin Ehlisd1c0e662015-02-26 12:57:08 -0700260 elif not 'array' in self.struct_dict[struct_type][num]:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600261 self.struct_dict[struct_type][num]['array'] = False
262 self.struct_dict[struct_type][num]['array_size'] = 0
263 self.struct_dict[struct_type][num]['name'] = member_name
264
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700265# check if given identifier is of specified type_to_check
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600266def is_type(identifier, type_to_check):
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600267 if identifier in types_dict and type_to_check == types_dict[identifier]:
268 return True
269 if identifier in typedef_rev_dict:
270 new_id = typedef_rev_dict[identifier]
271 if new_id in types_dict and type_to_check == types_dict[new_id]:
272 return True
273 return False
274
275# This is a validation function to verify that we can reproduce the original structs
276def recreate_structs():
277 for struct_name in struct_dict:
278 sys.stdout.write("typedef struct %s\n{\n" % struct_name)
279 for mem_num in sorted(struct_dict[struct_name]):
280 sys.stdout.write(" ")
281 if struct_dict[struct_name][mem_num]['const']:
282 sys.stdout.write("const ")
283 #if struct_dict[struct_name][mem_num]['struct']:
284 # sys.stdout.write("struct ")
285 sys.stdout.write (struct_dict[struct_name][mem_num]['type'])
286 if struct_dict[struct_name][mem_num]['ptr']:
287 sys.stdout.write("*")
288 sys.stdout.write(" ")
289 sys.stdout.write(struct_dict[struct_name][mem_num]['name'])
290 if struct_dict[struct_name][mem_num]['array']:
291 sys.stdout.write("[")
292 sys.stdout.write(struct_dict[struct_name][mem_num]['array_size'])
293 sys.stdout.write("]")
294 sys.stdout.write(";\n")
295 sys.stdout.write("} ")
296 sys.stdout.write(typedef_fwd_dict[struct_name])
297 sys.stdout.write(";\n\n")
298
299# class for writing common file elements
300# Here's how this class lays out a file:
301# COPYRIGHT
302# HEADER
303# BODY
304# FOOTER
305#
306# For each of these sections, there's a "set*" function
307# The class as a whole has a generate function which will write each section in order
308class CommonFileGen:
309 def __init__(self, filename=None, copyright_txt="", header_txt="", body_txt="", footer_txt=""):
310 self.filename = filename
311 self.contents = {'copyright': copyright_txt, 'header': header_txt, 'body': body_txt, 'footer': footer_txt}
312 # TODO : Set a default copyright & footer at least
313
314 def setFilename(self, filename):
315 self.filename = filename
316
317 def setCopyright(self, c):
318 self.contents['copyright'] = c
319
320 def setHeader(self, h):
321 self.contents['header'] = h
322
323 def setBody(self, b):
324 self.contents['body'] = b
325
326 def setFooter(self, f):
327 self.contents['footer'] = f
328
329 def generate(self):
330 #print("Generate to file %s" % self.filename)
331 with open(self.filename, "w") as f:
332 f.write(self.contents['copyright'])
333 f.write(self.contents['header'])
334 f.write(self.contents['body'])
335 f.write(self.contents['footer'])
336
337# class for writing a wrapper class for structures
338# The wrapper class wraps the structs and includes utility functions for
339# setting/getting member values and displaying the struct data in various formats
340class StructWrapperGen:
341 def __init__(self, in_struct_dict, prefix, out_dir):
342 self.struct_dict = in_struct_dict
343 self.include_headers = []
344 self.api = prefix
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345 if prefix == "vulkan":
346 self.api_prefix = "vk"
347 else:
348 self.api_prefix = prefix
349 self.header_filename = os.path.join(out_dir, self.api_prefix+"_struct_wrappers.h")
350 self.class_filename = os.path.join(out_dir, self.api_prefix+"_struct_wrappers.cpp")
351 self.string_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper.h")
352 self.string_helper_no_addr_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper_no_addr.h")
353 self.string_helper_cpp_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper_cpp.h")
354 self.string_helper_no_addr_cpp_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper_no_addr_cpp.h")
355 self.validate_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_validate_helper.h")
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700356 self.no_addr = False
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600357 self.hfg = CommonFileGen(self.header_filename)
358 self.cfg = CommonFileGen(self.class_filename)
359 self.shg = CommonFileGen(self.string_helper_filename)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700360 self.shcppg = CommonFileGen(self.string_helper_cpp_filename)
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700361 self.vhg = CommonFileGen(self.validate_helper_filename)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600362 self.size_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_size_helper.h")
363 self.size_helper_c_filename = os.path.join(out_dir, self.api_prefix+"_struct_size_helper.c")
Tobin Ehlisff765b02015-03-12 14:50:40 -0600364 self.size_helper_gen = CommonFileGen(self.size_helper_filename)
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -0700365 self.size_helper_c_gen = CommonFileGen(self.size_helper_c_filename)
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600366 #print(self.header_filename)
367 self.header_txt = ""
368 self.definition_txt = ""
369
370 def set_include_headers(self, include_headers):
371 self.include_headers = include_headers
372
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700373 def set_no_addr(self, no_addr):
374 self.no_addr = no_addr
375 if self.no_addr:
376 self.shg = CommonFileGen(self.string_helper_no_addr_filename)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700377 self.shcppg = CommonFileGen(self.string_helper_no_addr_cpp_filename)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700378 else:
379 self.shg = CommonFileGen(self.string_helper_filename)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700380 self.shcppg = CommonFileGen(self.string_helper_cpp_filename)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700381
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600382 # Return class name for given struct name
383 def get_class_name(self, struct_name):
384 class_name = struct_name.strip('_').lower() + "_struct_wrapper"
385 return class_name
386
387 def get_file_list(self):
388 return [os.path.basename(self.header_filename), os.path.basename(self.class_filename), os.path.basename(self.string_helper_filename)]
389
390 # Generate class header file
391 def generateHeader(self):
392 self.hfg.setCopyright(self._generateCopyright())
393 self.hfg.setHeader(self._generateHeader())
394 self.hfg.setBody(self._generateClassDeclaration())
395 self.hfg.setFooter(self._generateFooter())
396 self.hfg.generate()
397
398 # Generate class definition
399 def generateBody(self):
400 self.cfg.setCopyright(self._generateCopyright())
401 self.cfg.setHeader(self._generateCppHeader())
402 self.cfg.setBody(self._generateClassDefinition())
403 self.cfg.setFooter(self._generateFooter())
404 self.cfg.generate()
405
406 # Generate c-style .h file that contains functions for printing structs
407 def generateStringHelper(self):
408 print("Generating struct string helper")
409 self.shg.setCopyright(self._generateCopyright())
410 self.shg.setHeader(self._generateStringHelperHeader())
411 self.shg.setBody(self._generateStringHelperFunctions())
412 self.shg.generate()
413
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700414 # Generate cpp-style .h file that contains functions for printing structs
415 def generateStringHelperCpp(self):
416 print("Generating struct string helper cpp")
417 self.shcppg.setCopyright(self._generateCopyright())
418 self.shcppg.setHeader(self._generateStringHelperHeaderCpp())
419 self.shcppg.setBody(self._generateStringHelperFunctionsCpp())
420 self.shcppg.generate()
421
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700422 # Generate c-style .h file that contains functions for printing structs
423 def generateValidateHelper(self):
424 print("Generating struct validate helper")
425 self.vhg.setCopyright(self._generateCopyright())
426 self.vhg.setHeader(self._generateValidateHelperHeader())
427 self.vhg.setBody(self._generateValidateHelperFunctions())
428 self.vhg.generate()
429
Tobin Ehlisff765b02015-03-12 14:50:40 -0600430 def generateSizeHelper(self):
431 print("Generating struct size helper")
432 self.size_helper_gen.setCopyright(self._generateCopyright())
433 self.size_helper_gen.setHeader(self._generateSizeHelperHeader())
434 self.size_helper_gen.setBody(self._generateSizeHelperFunctions())
435 self.size_helper_gen.generate()
436
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -0700437 def generateSizeHelperC(self):
438 print("Generating struct size helper c")
439 self.size_helper_c_gen.setCopyright(self._generateCopyright())
440 self.size_helper_c_gen.setHeader(self._generateSizeHelperHeaderC())
441 self.size_helper_c_gen.setBody(self._generateSizeHelperFunctionsC())
442 self.size_helper_c_gen.generate()
443
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600444 def _generateCopyright(self):
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -0700445 copyright = []
446 copyright.append('/* THIS FILE IS GENERATED. DO NOT EDIT. */');
447 copyright.append('');
448 copyright.append('/*');
449 copyright.append(' * XGL');
450 copyright.append(' *');
451 copyright.append(' * Copyright (C) 2014 LunarG, Inc.');
452 copyright.append(' *');
453 copyright.append(' * Permission is hereby granted, free of charge, to any person obtaining a');
454 copyright.append(' * copy of this software and associated documentation files (the "Software"),');
455 copyright.append(' * to deal in the Software without restriction, including without limitation');
456 copyright.append(' * the rights to use, copy, modify, merge, publish, distribute, sublicense,');
457 copyright.append(' * and/or sell copies of the Software, and to permit persons to whom the');
458 copyright.append(' * Software is furnished to do so, subject to the following conditions:');
459 copyright.append(' *');
460 copyright.append(' * The above copyright notice and this permission notice shall be included');
461 copyright.append(' * in all copies or substantial portions of the Software.');
462 copyright.append(' *');
463 copyright.append(' * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR');
464 copyright.append(' * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,');
465 copyright.append(' * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL');
466 copyright.append(' * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER');
467 copyright.append(' * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING');
468 copyright.append(' * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER');
469 copyright.append(' * DEALINGS IN THE SOFTWARE.');
470 copyright.append(' */');
471 copyright.append('');
472 return "\n".join(copyright)
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600473
474 def _generateCppHeader(self):
475 header = []
476 header.append("//#includes, #defines, globals and such...\n")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600477 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 Ehlisee33fa52014-10-22 15:13:53 -0600478 return "".join(header)
479
480 def _generateClassDefinition(self):
481 class_def = []
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600482 if 'vk' == self.api: # Mantle doesn't have pNext to worry about
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600483 class_def.append(self._generateDynamicPrintFunctions())
Peter Lohrmannc55cfa12015-03-30 16:29:56 -0700484 for s in sorted(self.struct_dict):
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600485 class_def.append("\n// %s class definition" % self.get_class_name(s))
486 class_def.append(self._generateConstructorDefinitions(s))
487 class_def.append(self._generateDestructorDefinitions(s))
488 class_def.append(self._generateDisplayDefinitions(s))
489 return "\n".join(class_def)
490
491 def _generateConstructorDefinitions(self, s):
492 con_defs = []
493 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)))
494 # TODO : This is a shallow copy of ptrs
495 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]))
496 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]))
497 return "\n".join(con_defs)
498
499 def _generateDestructorDefinitions(self, s):
500 return "%s::~%s() {}" % (self.get_class_name(s), self.get_class_name(s))
501
502 def _generateDynamicPrintFunctions(self):
503 dp_funcs = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600504 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505 dp_funcs.append(" VK_STRUCTURE_TYPE sType = ((VK_APPLICATION_INFO*)pStruct)->sType;\n")
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600506 dp_funcs.append(" switch (sType)\n {")
507 for e in enum_type_dict:
508 class_num = 0
509 if "_STRUCTURE_TYPE" in e:
510 for v in sorted(enum_type_dict[e]):
511 struct_name = v.replace("_STRUCTURE_TYPE", "")
512 class_name = self.get_class_name(struct_name)
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600513 instance_name = "swc%i" % class_num
514 dp_funcs.append(" case %s:\n {" % (v))
515 dp_funcs.append(" %s %s((%s*)pStruct);" % (class_name, instance_name, struct_name))
516 dp_funcs.append(" %s.set_indent(indent);" % (instance_name))
517 dp_funcs.append(" %s.display_full_txt();" % (instance_name))
518 dp_funcs.append(" }")
519 dp_funcs.append(" break;")
520 class_num += 1
521 dp_funcs.append(" }")
522 dp_funcs.append("}\n")
523 return "\n".join(dp_funcs)
524
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700525 def _get_func_name(self, struct, mid_str):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600526 return "%s_%s_%s" % (self.api_prefix, mid_str, struct.lower().strip("_"))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700527
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600528 def _get_sh_func_name(self, struct):
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700529 return self._get_func_name(struct, 'print')
530
531 def _get_vh_func_name(self, struct):
532 return self._get_func_name(struct, 'validate')
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600533
Tobin Ehlisff765b02015-03-12 14:50:40 -0600534 def _get_size_helper_func_name(self, struct):
535 return self._get_func_name(struct, 'size')
536
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600537 # Return elements to create formatted string for given struct member
538 def _get_struct_print_formatted(self, struct_member, pre_var_name="prefix", postfix = "\\n", struct_var_name="pStruct", struct_ptr=True, print_array=False):
539 struct_op = "->"
540 if not struct_ptr:
541 struct_op = "."
542 member_name = struct_member['name']
543 print_type = "p"
544 cast_type = ""
545 member_post = ""
546 array_index = ""
547 member_print_post = ""
Tobin Ehlisbf0146e2015-02-11 14:24:02 -0700548 print_delimiter = "%"
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700549 if struct_member['array'] and 'char' in struct_member['type'].lower(): # just print char array as string
550 if member_name.startswith('pp'): # TODO : Only printing first element of dynam array of char* for now
551 member_post = "[0]"
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600552 print_type = "s"
553 print_array = False
554 elif struct_member['array'] and not print_array:
555 # Just print base address of array when not full print_array
556 cast_type = "(void*)"
557 elif is_type(struct_member['type'], 'enum'):
558 cast_type = "string_%s" % struct_member['type']
Jon Ashburna0ddc902015-01-09 09:11:44 -0700559 if struct_member['ptr']:
560 struct_var_name = "*" + struct_var_name
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600561 print_type = "s"
562 elif is_type(struct_member['type'], 'struct'): # print struct address for now
563 cast_type = "(void*)"
564 if not struct_member['ptr']:
565 cast_type = "(void*)&"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700566 elif 'bool' in struct_member['type']:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600567 print_type = "s"
568 member_post = ' ? "TRUE" : "FALSE"'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700569 elif 'float' in struct_member['type']:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600570 print_type = "f"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700571 elif 'uint64' in struct_member['type']:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600572 print_type = "lu"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700573 elif 'uint8' in struct_member['type']:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600574 print_type = "hu"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700575 elif '_size' in struct_member['type']:
Tobin Ehlisbf0146e2015-02-11 14:24:02 -0700576 print_type = '" PRINTF_SIZE_T_SPECIFIER "'
577 print_delimiter = ""
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700578 elif True in [ui_str.lower() in struct_member['type'].lower() for ui_str in ['uint', '_FLAGS', '_SAMPLE_MASK']]:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600579 print_type = "u"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700580 elif 'int' in struct_member['type']:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600581 print_type = "i"
582 elif struct_member['ptr']:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600583 pass
584 else:
585 #print("Unhandled struct type: %s" % struct_member['type'])
586 cast_type = "(void*)"
587 if print_array and struct_member['array']:
588 member_print_post = "[%u]"
589 array_index = " i,"
590 member_post = "[i]"
Tobin Ehlisbf0146e2015-02-11 14:24:02 -0700591 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 Ehlisee33fa52014-10-22 15:13:53 -0600592 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 Ehlis07fe9ab2014-11-25 17:43:26 -0700593 if self.no_addr and "p" == print_type:
594 print_out = "%%s%s%s = addr\\n" % (member_name, member_print_post) # section of print that goes inside of quotes
595 print_arg = ", %s" % (pre_var_name)
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600596 return (print_out, print_arg)
597
598 def _generateStringHelperFunctions(self):
599 sh_funcs = []
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700600 # We do two passes, first pass just generates prototypes for all the functsions
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700601 for s in sorted(self.struct_dict):
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700602 sh_funcs.append('char* %s(const %s* pStruct, const char* prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s]))
603 sh_funcs.append('')
604 sh_funcs.append('#if defined(_WIN32)')
605 sh_funcs.append('// Microsoft did not implement C99 in Visual Studio; but started adding it with')
606 sh_funcs.append('// VS2013. However, VS2013 still did not have snprintf(). The following is a')
607 sh_funcs.append('// work-around.')
608 sh_funcs.append('#define snprintf _snprintf')
609 sh_funcs.append('#endif // _WIN32\n')
Peter Lohrmannc55cfa12015-03-30 16:29:56 -0700610 for s in sorted(self.struct_dict):
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600611 p_out = ""
612 p_args = ""
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700613 stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700614 # This pre-pass flags embedded structs and pNext
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700615 for m in sorted(self.struct_dict[s]):
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700616 if 'pNext' == self.struct_dict[s][m]['name'] or is_type(self.struct_dict[s][m]['type'], 'struct'):
617 stp_list.append(self.struct_dict[s][m])
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700618 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]))
619 sh_funcs.append(" size_t len;")
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700620 num_stps = len(stp_list);
621 total_strlen_str = ''
622 if 0 != num_stps:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700623 sh_funcs.append(" char* tmpStr;")
624 sh_funcs.append(' char* extra_indent = (char*)malloc(strlen(prefix) + 3);')
625 sh_funcs.append(' strcpy(extra_indent, " ");')
626 sh_funcs.append(' strncat(extra_indent, prefix, strlen(prefix));')
627 sh_funcs.append(' char* stp_strs[%i];' % num_stps)
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700628 for index in range(num_stps):
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700629 # If it's an array, print all of the elements
630 # If it's a ptr, print thing it's pointing to
631 # Non-ptr struct case. Print the struct using its address
632 struct_deref = '&'
633 if 1 < stp_list[index]['full_type'].count('*'):
634 struct_deref = ''
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700635 if (stp_list[index]['ptr']):
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700636 sh_funcs.append(' if (pStruct->%s) {' % stp_list[index]['name'])
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700637 if 'pNext' == stp_list[index]['name']:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700638 sh_funcs.append(' tmpStr = dynamic_display((void*)pStruct->pNext, prefix);')
639 sh_funcs.append(' len = 256+strlen(tmpStr);')
640 sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % index)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700641 if self.no_addr:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700642 sh_funcs.append(' snprintf(stp_strs[%i], len, " %%spNext (addr)\\n%%s", prefix, tmpStr);' % index)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700643 else:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700644 sh_funcs.append(' snprintf(stp_strs[%i], len, " %%spNext (%%p)\\n%%s", prefix, (void*)pStruct->pNext, tmpStr);' % index)
645 sh_funcs.append(' free(tmpStr);')
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700646 else:
Tobin Ehlisd1c0e662015-02-26 12:57:08 -0700647 if stp_list[index]['name'] in ['pImageViews', 'pBufferViews']:
648 # TODO : This is a quick hack to handle these arrays of ptrs
Courtney Goeltzenleuchter24591b62015-04-02 22:54:15 -0600649 sh_funcs.append(' tmpStr = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
Tobin Ehlisd1c0e662015-02-26 12:57:08 -0700650 else:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700651 sh_funcs.append(' tmpStr = %s(pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
652 sh_funcs.append(' len = 256+strlen(tmpStr)+strlen(prefix);')
653 sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index))
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700654 if self.no_addr:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700655 sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (addr)\\n%%s", prefix, tmpStr);' % (index, stp_list[index]['name']))
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700656 else:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700657 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']))
658 sh_funcs.append(' }')
659 sh_funcs.append(" else\n stp_strs[%i] = \"\";" % (index))
660 elif stp_list[index]['array']:
661 sh_funcs.append(' tmpStr = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
662 sh_funcs.append(' len = 256+strlen(tmpStr);')
663 sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index))
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700664 if self.no_addr:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700665 sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s[0] (addr)\\n%%s", prefix, tmpStr);' % (index, stp_list[index]['name']))
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700666 else:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700667 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 Ehlis6f7029b2014-11-11 12:28:12 -0700668 else:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700669 sh_funcs.append(' tmpStr = %s(&pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
670 sh_funcs.append(' len = 256+strlen(tmpStr);')
671 sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index))
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700672 if self.no_addr:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700673 sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (addr)\\n%%s", prefix, tmpStr);' % (index, stp_list[index]['name']))
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700674 else:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700675 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 Ehlis6f7029b2014-11-11 12:28:12 -0700676 total_strlen_str += 'strlen(stp_strs[%i]) + ' % index
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700677 sh_funcs.append(' len = %ssizeof(char)*1024;' % (total_strlen_str))
678 sh_funcs.append(' str = (char*)malloc(len);')
Courtney Goeltzenleuchtercde421c2014-12-01 09:31:17 -0700679 sh_funcs.append(' snprintf(str, len, "')
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600680 for m in sorted(self.struct_dict[s]):
681 (p_out1, p_args1) = self._get_struct_print_formatted(self.struct_dict[s][m])
682 p_out += p_out1
683 p_args += p_args1
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600684 p_out += '"'
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700685 p_args += ");"
686 sh_funcs[-1] = '%s%s%s' % (sh_funcs[-1], p_out, p_args)
Tobin Ehlis6f7029b2014-11-11 12:28:12 -0700687 if 0 != num_stps:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700688 sh_funcs.append(' for (int32_t stp_index = %i; stp_index >= 0; stp_index--) {' % (num_stps-1))
689 sh_funcs.append(' if (0 < strlen(stp_strs[stp_index])) {')
690 sh_funcs.append(' strncat(str, stp_strs[stp_index], strlen(stp_strs[stp_index]));')
691 sh_funcs.append(' free(stp_strs[stp_index]);')
692 sh_funcs.append(' }')
693 sh_funcs.append(' }')
694 sh_funcs.append(' free(extra_indent);')
695 sh_funcs.append(" return str;\n}")
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600696 # Add function to dynamically print out unknown struct
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700697 sh_funcs.append("char* dynamic_display(const void* pStruct, const char* prefix)\n{")
698 sh_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct")
699 sh_funcs.append(" if (pStruct == NULL) {")
700 sh_funcs.append(" return NULL;")
701 sh_funcs.append(" }")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600702 sh_funcs.append(" VK_STRUCTURE_TYPE sType = ((VK_APPLICATION_INFO*)pStruct)->sType;")
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700703 sh_funcs.append(' char indent[100];\n strcpy(indent, " ");\n strcat(indent, prefix);')
704 sh_funcs.append(" switch (sType)\n {")
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600705 for e in enum_type_dict:
706 if "_STRUCTURE_TYPE" in e:
707 for v in sorted(enum_type_dict[e]):
708 struct_name = v.replace("_STRUCTURE_TYPE", "")
709 print_func_name = self._get_sh_func_name(struct_name)
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700710 sh_funcs.append(' case %s:\n {' % (v))
711 sh_funcs.append(' return %s((%s*)pStruct, indent);' % (print_func_name, struct_name))
712 sh_funcs.append(' }')
713 sh_funcs.append(' break;')
714 sh_funcs.append(" default:")
715 sh_funcs.append(" return NULL;")
716 sh_funcs.append(" }")
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600717 sh_funcs.append("}")
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700718 return "\n".join(sh_funcs)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700719
720 def _generateStringHelperFunctionsCpp(self):
721 # declare str & tmp str
722 # declare array of stringstreams for every struct ptr in current struct
723 # declare array of stringstreams for every non-string element in current struct
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700724 # For every struct ptr, if non-Null, then set its string, else set to NULL str
725 # For every non-string element, set its string stream
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700726 # create and return final string
727 sh_funcs = []
728 # First generate prototypes for every struct
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700729 for s in sorted(self.struct_dict):
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700730 sh_funcs.append('string %s(const %s* pStruct, const string prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s]))
731 sh_funcs.append('\n')
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700732 for s in sorted(self.struct_dict):
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700733 num_non_enum_elems = [is_type(self.struct_dict[s][elem]['type'], 'enum') for elem in self.struct_dict[s]].count(False)
734 stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700735 # This pre-pass flags embedded structs and pNext
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700736 for m in sorted(self.struct_dict[s]):
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700737 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']:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700738 stp_list.append(self.struct_dict[s][m])
739 sh_funcs.append('string %s(const %s* pStruct, const string prefix)\n{' % (self._get_sh_func_name(s), typedef_fwd_dict[s]))
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700740 indent = ' '
741 sh_funcs.append('%sstring final_str;' % (indent))
742 sh_funcs.append('%sstring tmp_str;' % (indent))
743 sh_funcs.append('%sstring extra_indent = " " + prefix;' % (indent))
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700744 if (0 != num_non_enum_elems):
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700745 sh_funcs.append('%sstringstream ss[%u];' % (indent, num_non_enum_elems))
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700746 num_stps = len(stp_list)
747 # First generate code for any embedded structs
748 if 0 < num_stps:
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700749 sh_funcs.append('%sstring stp_strs[%u];' % (indent, num_stps))
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700750 idx_ss_decl = False # Make sure to only decl this once
751 for index in range(num_stps):
752 addr_char = '&'
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700753 if 1 < stp_list[index]['full_type'].count('*'):
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700754 addr_char = ''
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700755 if (stp_list[index]['array']):
756 if stp_list[index]['dyn_array']:
757 array_count = 'pStruct->%s' % (stp_list[index]['array_size'])
758 else:
759 array_count = '%s' % (stp_list[index]['array_size'])
760 sh_funcs.append('%sstp_strs[%u] = "";' % (indent, index))
761 if not idx_ss_decl:
762 sh_funcs.append('%sstringstream index_ss;' % (indent))
763 idx_ss_decl = True
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600764 sh_funcs.append('%sif (pStruct->%s) {' % (indent, stp_list[index]['name']))
765 indent += ' '
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700766 sh_funcs.append('%sfor (uint32_t i = 0; i < %s; i++) {' % (indent, array_count))
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600767 indent += ' '
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700768 sh_funcs.append('%sindex_ss.str("");' % (indent))
769 sh_funcs.append('%sindex_ss << i;' % (indent))
770 if not is_type(stp_list[index]['type'], 'struct'):
771 addr_char = ''
772 sh_funcs.append('%sss[%u] << %spStruct->%s[i];' % (indent, index, addr_char, stp_list[index]['name']))
773 sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] = " + ss[%u].str() + "\\n";' % (indent, index, stp_list[index]['name'], index))
774 else:
775 sh_funcs.append('%sss[%u] << %spStruct->%s[i];' % (indent, index, addr_char, stp_list[index]['name']))
776 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']))
777 if self.no_addr:
778 sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] (addr)\\n" + tmp_str;' % (indent, index, stp_list[index]['name']))
779 else:
780 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 Ehlisdd82f6b2015-04-03 12:01:11 -0600781 indent = indent[4:]
782 sh_funcs.append('%s}' % (indent))
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700783 sh_funcs.append('%sss[%u].str("");' % (indent, index))
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600784 indent = indent[4:]
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700785 sh_funcs.append('%s}' % (indent))
786 elif (stp_list[index]['ptr']):
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700787 sh_funcs.append(' if (pStruct->%s) {' % stp_list[index]['name'])
788 if 'pNext' == stp_list[index]['name']:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600789 sh_funcs.append(' tmp_str = dynamic_display((void*)pStruct->pNext, prefix);')
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700790 else:
Tobin Ehlisd1c0e662015-02-26 12:57:08 -0700791 if stp_list[index]['name'] in ['pImageViews', 'pBufferViews']:
792 # TODO : This is a quick hack to handle these arrays of ptrs
Courtney Goeltzenleuchter24591b62015-04-02 22:54:15 -0600793 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 Ehlisd1c0e662015-02-26 12:57:08 -0700794 else:
795 sh_funcs.append(' tmp_str = %s(pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700796 sh_funcs.append(' ss[%u] << %spStruct->%s;' % (index, addr_char, stp_list[index]['name']))
797 if self.no_addr:
798 sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (addr)\\n" + tmp_str;' % (index, stp_list[index]['name']))
799 else:
800 sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (" + ss[%u].str() + ")\\n" + tmp_str;' % (index, stp_list[index]['name'], index))
801 sh_funcs.append(' ss[%u].str("");' % (index))
802 sh_funcs.append(' }')
803 sh_funcs.append(' else')
804 sh_funcs.append(' stp_strs[%u] = "";' % index)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700805 else:
806 sh_funcs.append(' tmp_str = %s(&pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
807 sh_funcs.append(' ss[%u] << %spStruct->%s;' % (index, addr_char, stp_list[index]['name']))
808 if self.no_addr:
809 sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (addr)\\n" + tmp_str;' % (index, stp_list[index]['name']))
810 else:
811 sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (" + ss[%u].str() + ")\\n" + tmp_str;' % (index, stp_list[index]['name'], index))
812 sh_funcs.append(' ss[%u].str("");' % index)
813 # Now print non-enum data members
814 index = 0
815 final_str = ''
816 for m in sorted(self.struct_dict[s]):
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700817 deref = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700818 if not is_type(self.struct_dict[s][m]['type'], 'enum'):
819 if is_type(self.struct_dict[s][m]['type'], 'struct') and not self.struct_dict[s][m]['ptr']:
820 if self.no_addr:
821 sh_funcs.append(' ss[%u].str("addr");' % (index))
822 else:
823 sh_funcs.append(' ss[%u] << &pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700824 elif 'bool' in self.struct_dict[s][m]['type'].lower():
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700825 sh_funcs.append(' ss[%u].str(pStruct->%s ? "TRUE" : "FALSE");' % (index, self.struct_dict[s][m]['name']))
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700826 elif 'uint8' in self.struct_dict[s][m]['type'].lower():
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700827 sh_funcs.append(' ss[%u] << (uint32_t)pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
828 else:
829 (po, pa) = self._get_struct_print_formatted(self.struct_dict[s][m])
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700830 if "addr" in po: # or self.struct_dict[s][m]['ptr']:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700831 sh_funcs.append(' ss[%u].str("addr");' % (index))
832 else:
833 sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
834 value_print = 'ss[%u].str()' % index
835 index += 1
836 else:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700837 if self.struct_dict[s][m]['ptr']:
838 deref = '*'
839 value_print = 'string_%s(%spStruct->%s)' % (self.struct_dict[s][m]['type'], deref, self.struct_dict[s][m]['name'])
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700840 final_str += ' + prefix + "%s = " + %s + "\\n"' % (self.struct_dict[s][m]['name'], value_print)
841 final_str = final_str[3:] # strip off the initial ' + '
Tobin Ehlis91cc24a2015-03-06 10:38:25 -0700842 if 0 != num_stps: # Append data for any embedded structs
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700843 final_str += " + %s" % " + ".join(['stp_strs[%u]' % n for n in reversed(range(num_stps))])
844 sh_funcs.append(' final_str = %s;' % final_str)
845 sh_funcs.append(' return final_str;\n}')
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700846 # Add function to return a string value for input void*
847 sh_funcs.append("string string_convert_helper(const void* toString, const string prefix)\n{")
848 sh_funcs.append(" stringstream ss;")
849 sh_funcs.append(' ss << toString;')
850 sh_funcs.append(' string final_str = prefix + ss.str();')
851 sh_funcs.append(" return final_str;")
852 sh_funcs.append("}")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700853 # Add function to dynamically print out unknown struct
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600854 sh_funcs.append("string dynamic_display(const void* pStruct, const string prefix)\n{")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700855 sh_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct")
Ian Elliotta5a0a172015-02-25 17:40:38 -0700856 sh_funcs.append(" if (pStruct == NULL) {\n")
Jon Ashburn49398b32015-02-25 12:45:23 -0700857 sh_funcs.append(" return NULL;")
Ian Elliotta5a0a172015-02-25 17:40:38 -0700858 sh_funcs.append(" }\n")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600859 sh_funcs.append(" VK_STRUCTURE_TYPE sType = ((VK_APPLICATION_INFO*)pStruct)->sType;")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700860 sh_funcs.append(' string indent = " ";')
861 sh_funcs.append(' indent += prefix;')
862 sh_funcs.append(" switch (sType)\n {")
863 for e in enum_type_dict:
864 if "_STRUCTURE_TYPE" in e:
865 for v in sorted(enum_type_dict[e]):
866 struct_name = v.replace("_STRUCTURE_TYPE", "")
867 print_func_name = self._get_sh_func_name(struct_name)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700868 sh_funcs.append(' case %s:\n {' % (v))
869 sh_funcs.append(' return %s((%s*)pStruct, indent);' % (print_func_name, struct_name))
870 sh_funcs.append(' }')
871 sh_funcs.append(' break;')
872 sh_funcs.append(" default:")
873 sh_funcs.append(" return NULL;")
874 sh_funcs.append(" }")
875 sh_funcs.append("}")
876 return "\n".join(sh_funcs)
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600877
878 def _genStructMemberPrint(self, member, s, array, struct_array):
879 (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)
880 extra_indent = ""
881 if array:
882 extra_indent = " "
883 if is_type(self.struct_dict[s][member]['type'], 'struct'): # print struct address for now
884 struct_array.insert(0, self.struct_dict[s][member])
885 elif self.struct_dict[s][member]['ptr']:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700886 # Special case for void* named "pNext"
887 if "void" in self.struct_dict[s][member]['type'] and "pNext" == self.struct_dict[s][member]['name']:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600888 struct_array.insert(0, self.struct_dict[s][member])
889 return (' %sprintf("%%*s %s", m_indent, ""%s);' % (extra_indent, p_out, p_arg), struct_array)
890
891 def _generateDisplayDefinitions(self, s):
892 disp_def = []
893 struct_array = []
894 # Single-line struct print function
895 disp_def.append("// Output 'structname = struct_address' on a single line")
896 disp_def.append("void %s::display_single_txt()\n{" % self.get_class_name(s))
897 disp_def.append(' printf(" %%*s%s = %%p", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s])
898 disp_def.append("}\n")
899 # Private helper function to print struct members
900 disp_def.append("// Private helper function that displays the members of the wrapped struct")
901 disp_def.append("void %s::display_struct_members()\n{" % self.get_class_name(s))
902 i_declared = False
903 for member in sorted(self.struct_dict[s]):
904 # TODO : Need to display each member based on its type
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600905 # TODO : Need to handle pNext which are structs, but of void* type
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600906 # Can grab struct type off of header of struct pointed to
907 # TODO : Handle Arrays
908 if self.struct_dict[s][member]['array']:
909 # Create for loop to print each element of array
910 if not i_declared:
911 disp_def.append(' uint32_t i;')
912 i_declared = True
913 disp_def.append(' for (i = 0; i<%s; i++) {' % self.struct_dict[s][member]['array_size'])
914 (return_str, struct_array) = self._genStructMemberPrint(member, s, True, struct_array)
915 disp_def.append(return_str)
916 disp_def.append(' }')
917 else:
918 (return_str, struct_array) = self._genStructMemberPrint(member, s, False, struct_array)
919 disp_def.append(return_str)
920 disp_def.append("}\n")
921 i_declared = False
922 # Basic print function to display struct members
923 disp_def.append("// Output all struct elements, each on their own line")
924 disp_def.append("void %s::display_txt()\n{" % self.get_class_name(s))
925 disp_def.append(' printf("%%*s%s struct contents at %%p:\\n", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s])
926 disp_def.append(' this->display_struct_members();')
927 disp_def.append("}\n")
928 # Advanced print function to display current struct and contents of any pointed-to structs
929 disp_def.append("// Output all struct elements, and for any structs pointed to, print complete contents")
930 disp_def.append("void %s::display_full_txt()\n{" % self.get_class_name(s))
931 disp_def.append(' printf("%%*s%s struct contents at %%p:\\n", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s])
932 disp_def.append(' this->display_struct_members();')
933 class_num = 0
934 # TODO : Need to handle arrays of structs here
935 for ms in struct_array:
936 swc_name = "class%s" % str(class_num)
937 if ms['array']:
938 if not i_declared:
939 disp_def.append(' uint32_t i;')
940 i_declared = True
941 disp_def.append(' for (i = 0; i<%s; i++) {' % ms['array_size'])
942 #disp_def.append(" if (m_struct.%s[i]) {" % (ms['name']))
943 disp_def.append(" %s %s(&(m_struct.%s[i]));" % (self.get_class_name(ms['type']), swc_name, ms['name']))
944 disp_def.append(" %s.set_indent(m_indent + 4);" % (swc_name))
945 disp_def.append(" %s.display_full_txt();" % (swc_name))
946 #disp_def.append(' }')
947 disp_def.append(' }')
948 elif 'pNext' == ms['name']:
949 # Need some code trickery here
950 # I'm thinking have a generated function that takes pNext ptr value
951 # then it checks sType and in large switch statement creates appropriate
952 # wrapper class type and then prints contents
953 disp_def.append(" if (m_struct.%s) {" % (ms['name']))
954 #disp_def.append(' printf("%*s This is where we would call dynamic print function\\n", m_indent, "");')
955 disp_def.append(' dynamic_display_full_txt(m_struct.%s, m_indent);' % (ms['name']))
956 disp_def.append(" }")
957 else:
958 if ms['ptr']:
959 disp_def.append(" if (m_struct.%s) {" % (ms['name']))
960 disp_def.append(" %s %s(m_struct.%s);" % (self.get_class_name(ms['type']), swc_name, ms['name']))
961 else:
962 disp_def.append(" if (&m_struct.%s) {" % (ms['name']))
963 disp_def.append(" %s %s(&m_struct.%s);" % (self.get_class_name(ms['type']), swc_name, ms['name']))
964 disp_def.append(" %s.set_indent(m_indent + 4);" % (swc_name))
965 disp_def.append(" %s.display_full_txt();\n }" % (swc_name))
966 class_num += 1
967 disp_def.append("}\n")
968 return "\n".join(disp_def)
969
970 def _generateStringHelperHeader(self):
971 header = []
972 header.append("//#includes, #defines, globals and such...\n")
973 for f in self.include_headers:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600974 if 'vk_enum_string_helper' not in f:
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600975 header.append("#include <%s>\n" % f)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600976 header.append('#include "vk_enum_string_helper.h"\n\n// Function Prototypes\n')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600977 header.append("char* dynamic_display(const void* pStruct, const char* prefix);\n")
Tobin Ehlisee33fa52014-10-22 15:13:53 -0600978 return "".join(header)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700979
980 def _generateStringHelperHeaderCpp(self):
981 header = []
982 header.append("//#includes, #defines, globals and such...\n")
983 for f in self.include_headers:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600984 if 'vk_enum_string_helper' not in f:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700985 header.append("#include <%s>\n" % f)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600986 header.append('#include "vk_enum_string_helper.h"\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700987 header.append('using namespace std;\n\n// Function Prototypes\n')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600988 header.append("string dynamic_display(const void* pStruct, const string prefix);\n")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700989 return "".join(header)
990
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700991 def _generateValidateHelperFunctions(self):
992 sh_funcs = []
993 # We do two passes, first pass just generates prototypes for all the functsions
Peter Lohrmannc55cfa12015-03-30 16:29:56 -0700994 for s in sorted(self.struct_dict):
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700995 sh_funcs.append('uint32_t %s(const %s* pStruct);' % (self._get_vh_func_name(s), typedef_fwd_dict[s]))
996 sh_funcs.append('\n')
Peter Lohrmannc55cfa12015-03-30 16:29:56 -0700997 for s in sorted(self.struct_dict):
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700998 sh_funcs.append('uint32_t %s(const %s* pStruct)\n{' % (self._get_vh_func_name(s), typedef_fwd_dict[s]))
999 for m in sorted(self.struct_dict[s]):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001000 # TODO : Need to handle arrays of enums like in VK_RENDER_PASS_CREATE_INFO struct
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001001 if is_type(self.struct_dict[s][m]['type'], 'enum') and not self.struct_dict[s][m]['ptr']:
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001002 sh_funcs.append(' if (!validate_%s(pStruct->%s))\n return 0;' % (self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name']))
Jon Ashburnaad29362015-01-12 15:46:51 -07001003 # TODO : Need a little refinement to this code to make sure type of struct matches expected input (ptr, const...)
Tobin Ehlise719e022014-12-18 09:29:58 -07001004 if is_type(self.struct_dict[s][m]['type'], 'struct'):
1005 if (self.struct_dict[s][m]['ptr']):
Tobin Ehlis516aa842015-02-24 15:39:04 -07001006 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 Ehlise719e022014-12-18 09:29:58 -07001007 else:
1008 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 Ehlis6cd06372014-12-17 17:44:50 -07001009 sh_funcs.append(" return 1;\n}")
1010
1011 return "\n".join(sh_funcs)
1012
1013 def _generateValidateHelperHeader(self):
1014 header = []
1015 header.append("//#includes, #defines, globals and such...\n")
1016 for f in self.include_headers:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001017 if 'vk_enum_validate_helper' not in f:
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001018 header.append("#include <%s>\n" % f)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001019 header.append('#include "vk_enum_validate_helper.h"\n\n// Function Prototypes\n')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001020 #header.append("char* dynamic_display(const void* pStruct, const char* prefix);\n")
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001021 return "".join(header)
1022
Tobin Ehlisff765b02015-03-12 14:50:40 -06001023 def _generateSizeHelperFunctions(self):
1024 sh_funcs = []
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -07001025 # just generates prototypes for all the functions
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001026 for s in sorted(self.struct_dict):
Tobin Ehlisff765b02015-03-12 14:50:40 -06001027 sh_funcs.append('size_t %s(const %s* pStruct);' % (self._get_size_helper_func_name(s), typedef_fwd_dict[s]))
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -07001028 return "\n".join(sh_funcs)
1029
1030
1031 def _generateSizeHelperFunctionsC(self):
1032 sh_funcs = []
1033 # generate function definitions
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001034 for s in sorted(self.struct_dict):
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -07001035 skip_list = [] # Used when struct elements need to be skipped b/c size already accounted for
Tobin Ehlisff765b02015-03-12 14:50:40 -06001036 sh_funcs.append('size_t %s(const %s* pStruct)\n{' % (self._get_size_helper_func_name(s), typedef_fwd_dict[s]))
1037 indent = ' '
1038 sh_funcs.append('%ssize_t structSize = 0;' % (indent))
1039 sh_funcs.append('%sif (pStruct) {' % (indent))
1040 indent = ' '
1041 sh_funcs.append('%sstructSize = sizeof(%s);' % (indent, typedef_fwd_dict[s]))
1042 i_decl = False
1043 for m in sorted(self.struct_dict[s]):
1044 if m in skip_list:
1045 continue
1046 if self.struct_dict[s][m]['dyn_array']:
1047 if self.struct_dict[s][m]['full_type'].count('*') > 1:
1048 if not is_type(self.struct_dict[s][m]['type'], 'struct') and not 'char' in self.struct_dict[s][m]['type'].lower():
Tobin Ehlis91b2b642015-03-16 10:44:40 -06001049 if 'ppMemBarriers' == self.struct_dict[s][m]['name']:
1050 # TODO : For now be conservative and consider all memBarrier ptrs as largest possible struct
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001051 sh_funcs.append('%sstructSize += pStruct->%s*(sizeof(%s*) + sizeof(VK_IMAGE_MEMORY_BARRIER));' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type']))
Tobin Ehlis91b2b642015-03-16 10:44:40 -06001052 else:
1053 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 Ehlisff765b02015-03-12 14:50:40 -06001054 else: # This is an array of char* or array of struct ptrs
1055 if not i_decl:
1056 sh_funcs.append('%suint32_t i = 0;' % (indent))
1057 i_decl = True
1058 sh_funcs.append('%sfor (i = 0; i < pStruct->%s; i++) {' % (indent, self.struct_dict[s][m]['array_size']))
1059 indent = ' '
1060 if is_type(self.struct_dict[s][m]['type'], 'struct'):
1061 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']))
1062 else:
Tobin Ehlisf57562c2015-03-13 07:18:05 -06001063 sh_funcs.append('%sstructSize += (sizeof(char*) + (sizeof(char) * (1 + strlen(pStruct->%s[i]))));' % (indent, self.struct_dict[s][m]['name']))
Tobin Ehlisff765b02015-03-12 14:50:40 -06001064 indent = ' '
1065 sh_funcs.append('%s}' % (indent))
1066 else:
1067 if is_type(self.struct_dict[s][m]['type'], 'struct'):
1068 if not i_decl:
1069 sh_funcs.append('%suint32_t i = 0;' % (indent))
1070 i_decl = True
1071 sh_funcs.append('%sfor (i = 0; i < pStruct->%s; i++) {' % (indent, self.struct_dict[s][m]['array_size']))
1072 indent = ' '
1073 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']))
1074 indent = ' '
1075 sh_funcs.append('%s}' % (indent))
1076 else:
1077 sh_funcs.append('%sstructSize += pStruct->%s*sizeof(%s);' % (indent, self.struct_dict[s][m]['array_size'], self.struct_dict[s][m]['type']))
1078 elif self.struct_dict[s][m]['ptr'] and 'pNext' != self.struct_dict[s][m]['name']:
1079 if 'char' in self.struct_dict[s][m]['type'].lower():
Tobin Ehlisf57562c2015-03-13 07:18:05 -06001080 sh_funcs.append('%sstructSize += sizeof(%s)*(1+strlen(pStruct->%s));' % (indent, self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name']))
Tobin Ehlisff765b02015-03-12 14:50:40 -06001081 elif is_type(self.struct_dict[s][m]['type'], 'struct'):
1082 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 Ehlis91b2b642015-03-16 10:44:40 -06001083 elif 'void' not in self.struct_dict[s][m]['type'].lower():
Tobin Ehlisff765b02015-03-12 14:50:40 -06001084 sh_funcs.append('%sstructSize += sizeof(%s);' % (indent, self.struct_dict[s][m]['type']))
1085 elif 'size_t' == self.struct_dict[s][m]['type'].lower():
1086 sh_funcs.append('%sstructSize += pStruct->%s;' % (indent, self.struct_dict[s][m]['name']))
1087 skip_list.append(m+1)
1088 indent = ' '
1089 sh_funcs.append('%s}' % (indent))
1090 sh_funcs.append("%sreturn structSize;\n}" % (indent))
Tobin Ehlis91b2b642015-03-16 10:44:40 -06001091 # Now generate generic functions to loop over entire struct chain (or just handle single generic structs)
1092 for follow_chain in [True, False]:
1093 if follow_chain:
1094 sh_funcs.append('size_t get_struct_chain_size(const void* pStruct)\n{')
1095 else:
1096 sh_funcs.append('size_t get_dynamic_struct_size(const void* pStruct)\n{')
1097 indent = ' '
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001098 sh_funcs.append('%s// Just use VK_APPLICATION_INFO as struct until actual type is resolved' % (indent))
1099 sh_funcs.append('%sVK_APPLICATION_INFO* pNext = (VK_APPLICATION_INFO*)pStruct;' % (indent))
Tobin Ehlis91b2b642015-03-16 10:44:40 -06001100 sh_funcs.append('%ssize_t structSize = 0;' % (indent))
1101 if follow_chain:
1102 sh_funcs.append('%swhile (pNext) {' % (indent))
1103 indent = ' '
1104 sh_funcs.append('%sswitch (pNext->sType) {' % (indent))
1105 indent += ' '
1106 for e in enum_type_dict:
1107 if '_STRUCTURE_TYPE' in e:
1108 for v in sorted(enum_type_dict[e]):
1109 struct_name = v.replace("_STRUCTURE_TYPE", "")
1110 sh_funcs.append('%scase %s:' % (indent, v))
1111 sh_funcs.append('%s{' % (indent))
1112 indent += ' '
1113 sh_funcs.append('%sstructSize += %s((%s*)pNext);' % (indent, self._get_size_helper_func_name(struct_name), struct_name))
1114 sh_funcs.append('%sbreak;' % (indent))
1115 indent = indent[:-4]
1116 sh_funcs.append('%s}' % (indent))
1117 sh_funcs.append('%sdefault:' % (indent))
1118 indent += ' '
1119 sh_funcs.append('%sassert(0);' % (indent))
1120 sh_funcs.append('%sstructSize += 0;' % (indent))
1121 indent = indent[:-4]
1122 indent = indent[:-4]
1123 sh_funcs.append('%s}' % (indent))
1124 if follow_chain:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001125 sh_funcs.append('%spNext = (VK_APPLICATION_INFO*)pNext->pNext;' % (indent))
Tobin Ehlis91b2b642015-03-16 10:44:40 -06001126 indent = indent[:-4]
1127 sh_funcs.append('%s}' % (indent))
1128 sh_funcs.append('%sreturn structSize;\n}' % indent)
Tobin Ehlisff765b02015-03-12 14:50:40 -06001129 return "\n".join(sh_funcs)
1130
1131 def _generateSizeHelperHeader(self):
1132 header = []
1133 header.append("//#includes, #defines, globals and such...\n")
1134 for f in self.include_headers:
1135 header.append("#include <%s>\n" % f)
1136 header.append('\n// Function Prototypes\n')
1137 header.append("size_t get_struct_chain_size(const void* pStruct);\n")
Tobin Ehlis91b2b642015-03-16 10:44:40 -06001138 header.append("size_t get_dynamic_struct_size(const void* pStruct);\n")
Tobin Ehlisff765b02015-03-12 14:50:40 -06001139 return "".join(header)
1140
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -07001141 def _generateSizeHelperHeaderC(self):
1142 header = []
1143 header.append('#include "xgl_struct_size_helper.h"')
1144 header.append('#include <string.h>')
1145 header.append('#include <assert.h>')
1146 header.append('\n// Function definitions\n')
1147 return "\n".join(header)
1148
1149
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001150 def _generateHeader(self):
1151 header = []
1152 header.append("//#includes, #defines, globals and such...\n")
1153 for f in self.include_headers:
1154 header.append("#include <%s>\n" % f)
1155 return "".join(header)
1156
1157 # Declarations
1158 def _generateConstructorDeclarations(self, s):
1159 constructors = []
1160 constructors.append(" %s();\n" % self.get_class_name(s))
1161 constructors.append(" %s(%s* pInStruct);\n" % (self.get_class_name(s), typedef_fwd_dict[s]))
1162 constructors.append(" %s(const %s* pInStruct);\n" % (self.get_class_name(s), typedef_fwd_dict[s]))
1163 return "".join(constructors)
1164
1165 def _generateDestructorDeclarations(self, s):
1166 return " virtual ~%s();\n" % self.get_class_name(s)
1167
1168 def _generateDisplayDeclarations(self, s):
1169 return " void display_txt();\n void display_single_txt();\n void display_full_txt();\n"
1170
1171 def _generateGetSetDeclarations(self, s):
1172 get_set = []
1173 get_set.append(" void set_indent(uint32_t indent) { m_indent = indent; }\n")
1174 for member in sorted(self.struct_dict[s]):
1175 # TODO : Skipping array set/get funcs for now
1176 if self.struct_dict[s][member]['array']:
1177 continue
1178 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']))
1179 if not self.struct_dict[s][member]['const']:
1180 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']))
1181 return "".join(get_set)
1182
1183 def _generatePrivateMembers(self, s):
1184 priv = []
1185 priv.append("\nprivate:\n")
1186 priv.append(" %s m_struct;\n" % typedef_fwd_dict[s])
1187 priv.append(" const %s* m_origStructAddr;\n" % typedef_fwd_dict[s])
1188 priv.append(" uint32_t m_indent;\n")
1189 priv.append(" const char m_dummy_prefix;\n")
1190 priv.append(" void display_struct_members();\n")
1191 return "".join(priv)
1192
1193 def _generateClassDeclaration(self):
1194 class_decl = []
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001195 for s in sorted(self.struct_dict):
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001196 class_decl.append("\n//class declaration")
1197 class_decl.append("class %s\n{\npublic:" % self.get_class_name(s))
1198 class_decl.append(self._generateConstructorDeclarations(s))
1199 class_decl.append(self._generateDestructorDeclarations(s))
1200 class_decl.append(self._generateDisplayDeclarations(s))
1201 class_decl.append(self._generateGetSetDeclarations(s))
1202 class_decl.append(self._generatePrivateMembers(s))
1203 class_decl.append("};\n")
1204 return "\n".join(class_decl)
1205
1206 def _generateFooter(self):
1207 return "\n//any footer info for class\n"
1208
1209class EnumCodeGen:
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001210 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 Ehlisee33fa52014-10-22 15:13:53 -06001211 self.et_dict = enum_type_dict
1212 self.ev_dict = enum_val_dict
1213 self.tf_dict = typedef_fwd_dict
1214 self.in_file = in_file
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001215 self.out_sh_file = out_sh_file
1216 self.eshfg = CommonFileGen(self.out_sh_file)
1217 self.out_vh_file = out_vh_file
1218 self.evhfg = CommonFileGen(self.out_vh_file)
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001219
1220 def generateStringHelper(self):
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001221 self.eshfg.setHeader(self._generateSHHeader())
1222 self.eshfg.setBody(self._generateSHBody())
1223 self.eshfg.generate()
1224
1225 def generateEnumValidate(self):
1226 self.evhfg.setHeader(self._generateSHHeader())
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001227 self.evhfg.setBody(self._generateVHBody())
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001228 self.evhfg.generate()
1229
1230 def _generateVHBody(self):
1231 body = []
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001232 for bet in sorted(self.et_dict):
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001233 fet = self.tf_dict[bet]
Ian Elliotta742a622015-02-18 12:38:04 -07001234 body.append("static inline uint32_t validate_%s(%s input_value)\n{\n switch ((%s)input_value)\n {" % (fet, fet, fet))
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001235 for e in sorted(self.et_dict[bet]):
1236 if (self.ev_dict[e]['unique']):
Tobin Ehlis45bc7f82015-01-16 15:13:34 -07001237 body.append(' case %s:' % (e))
1238 body.append(' return 1;\n default:\n return 0;\n }\n}\n\n')
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001239 return "\n".join(body)
1240
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001241 def _generateSHBody(self):
1242 body = []
1243# with open(self.out_file, "a") as hf:
1244 # bet == base_enum_type, fet == final_enum_type
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001245 for bet in sorted(self.et_dict):
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001246 fet = self.tf_dict[bet]
Ian Elliotta742a622015-02-18 12:38:04 -07001247 body.append("static inline const char* string_%s(%s input_value)\n{\n switch ((%s)input_value)\n {" % (fet, fet, fet))
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001248 for e in sorted(self.et_dict[bet]):
1249 if (self.ev_dict[e]['unique']):
Tobin Ehlis45bc7f82015-01-16 15:13:34 -07001250 body.append(' case %s:\n return "%s";' % (e, e))
1251 body.append(' default:\n return "Unhandled %s";\n }\n}\n\n' % (fet))
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001252 return "\n".join(body)
1253
1254 def _generateSHHeader(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001255 header = []
1256 header.append('#pragma once\n')
Ian Elliotta742a622015-02-18 12:38:04 -07001257 header.append('#include <%s>\n\n\n' % self.in_file)
Ian Elliott81ac44c2015-01-13 17:52:38 -07001258 return "\n".join(header)
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001259
1260
1261class CMakeGen:
1262 def __init__(self, struct_wrapper=None, out_dir=None):
1263 self.sw = struct_wrapper
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001264 self.include_headers = []
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001265 self.add_lib_file_list = self.sw.get_file_list()
1266 self.out_dir = out_dir
1267 self.out_file = os.path.join(self.out_dir, "CMakeLists.txt")
1268 self.cmg = CommonFileGen(self.out_file)
1269
1270 def generate(self):
1271 self.cmg.setBody(self._generateBody())
1272 self.cmg.generate()
1273
1274 def _generateBody(self):
1275 body = []
1276 body.append("project(%s)" % os.path.basename(self.out_dir))
1277 body.append("cmake_minimum_required(VERSION 2.8)\n")
1278 body.append("add_library(${PROJECT_NAME} %s)\n" % " ".join(self.add_lib_file_list))
1279 body.append('set(COMPILE_FLAGS "-fpermissive")')
1280 body.append('set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}")\n')
1281 body.append("include_directories(${SRC_DIR}/thirdparty/${GEN_API}/inc/)\n")
1282 body.append("target_include_directories (%s PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" % os.path.basename(self.out_dir))
1283 return "\n".join(body)
1284
1285class GraphVizGen:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001286 def __init__(self, struct_dict, prefix, out_dir):
1287 self.struct_dict = struct_dict
1288 self.api = prefix
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001289 if prefix == "vulkan":
1290 self.api_prefix = "vk"
1291 else:
1292 self.api_prefix = prefix
1293 self.out_file = os.path.join(out_dir, self.api_prefix+"_struct_graphviz_helper.h")
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001294 self.gvg = CommonFileGen(self.out_file)
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001295
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001296 def generate(self):
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001297 self.gvg.setCopyright("//This is the copyright\n")
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001298 self.gvg.setHeader(self._generateHeader())
1299 self.gvg.setBody(self._generateBody())
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001300 #self.gvg.setFooter('}')
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001301 self.gvg.generate()
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001302
1303 def set_include_headers(self, include_headers):
1304 self.include_headers = include_headers
1305
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001306 def _generateHeader(self):
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001307 header = []
1308 header.append("//#includes, #defines, globals and such...\n")
1309 for f in self.include_headers:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001310 if 'vk_enum_string_helper' not in f:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001311 header.append("#include <%s>\n" % f)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001312 #header.append('#include "vk_enum_string_helper.h"\n\n// Function Prototypes\n')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001313 header.append("\nchar* dynamic_gv_display(const void* pStruct, const char* prefix);\n")
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001314 return "".join(header)
1315
1316 def _get_gv_func_name(self, struct):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001317 return "%s_gv_print_%s" % (self.api_prefix, struct.lower().strip("_"))
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001318
1319 # Return elements to create formatted string for given struct member
1320 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=""):
1321 struct_op = "->"
1322 pre_var_name = '"%s "' % struct_member['full_type']
1323 if not struct_ptr:
1324 struct_op = "."
1325 member_name = struct_member['name']
1326 print_type = "p"
1327 cast_type = ""
1328 member_post = ""
1329 array_index = ""
1330 member_print_post = ""
Tobin Ehlisbf0146e2015-02-11 14:24:02 -07001331 print_delimiter = "%"
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001332 if struct_member['array'] and 'CHAR' in struct_member['type']: # just print char array as string
1333 print_type = "s"
1334 print_array = False
1335 elif struct_member['array'] and not print_array:
1336 # Just print base address of array when not full print_array
1337 cast_type = "(void*)"
1338 elif is_type(struct_member['type'], 'enum'):
Jon Ashburna0ddc902015-01-09 09:11:44 -07001339 if struct_member['ptr']:
1340 struct_var_name = "*" + struct_var_name
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001341 cast_type = "string_%s" % struct_member['type']
1342 print_type = "s"
1343 elif is_type(struct_member['type'], 'struct'): # print struct address for now
1344 cast_type = "(void*)"
1345 if not struct_member['ptr']:
1346 cast_type = "(void*)&"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001347 elif 'bool' in struct_member['type']:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001348 print_type = "s"
1349 member_post = ' ? "TRUE" : "FALSE"'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001350 elif 'float' in struct_member['type']:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001351 print_type = "f"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001352 elif 'uint64' in struct_member['type']:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001353 print_type = "lu"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001354 elif 'uint8' in struct_member['type']:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001355 print_type = "hu"
Chia-I Wu54ed0792014-12-27 14:14:50 +08001356 elif '_SIZE' in struct_member['type']:
Tobin Ehlisbf0146e2015-02-11 14:24:02 -07001357 print_type = '" PRINTF_SIZE_T_SPECIFIER "'
1358 print_delimiter = ""
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001359 elif True in [ui_str in struct_member['type'] for ui_str in ['uint', '_FLAGS', '_SAMPLE_MASK']]:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001360 print_type = "u"
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001361 elif 'int' in struct_member['type']:
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001362 print_type = "i"
1363 elif struct_member['ptr']:
1364 pass
1365 else:
1366 #print("Unhandled struct type: %s" % struct_member['type'])
1367 cast_type = "(void*)"
1368 if print_array and struct_member['array']:
1369 member_print_post = "[%u]"
1370 array_index = " i,"
1371 member_post = "[i]"
Tobin Ehlisbf0146e2015-02-11 14:24:02 -07001372 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
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001373 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
1374 return (print_out, print_arg)
1375
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001376 def _generateBody(self):
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001377 gv_funcs = []
1378 array_func_list = [] # structs for which we'll generate an array version of their print function
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001379 array_func_list.append('vk_buffer_view_attach_info')
1380 array_func_list.append('vk_image_view_attach_info')
1381 array_func_list.append('vk_sampler_image_view_info')
1382 array_func_list.append('vk_descriptor_type_count')
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001383 # For first pass, generate prototype
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001384 for s in sorted(self.struct_dict):
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001385 gv_funcs.append('char* %s(const %s* pStruct, const char* myNodeName);\n' % (self._get_gv_func_name(s), typedef_fwd_dict[s]))
1386 if s.lower().strip("_") in array_func_list:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001387 if s.lower().strip("_") in ['vk_buffer_view_attach_info', 'vk_image_view_attach_info']:
Tobin Ehlisd1c0e662015-02-26 12:57:08 -07001388 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]))
1389 else:
1390 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 Ehlisa701ef02014-11-27 15:43:39 -07001391 gv_funcs.append('\n')
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001392 for s in sorted(self.struct_dict):
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001393 p_out = ""
1394 p_args = ""
1395 stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs
1396 # the fields below are a super-hacky way for now to get port labels into GV output, TODO : Clean this up!
1397 pl_dict = {}
1398 struct_num = 0
Tobin Ehlisd1c0e662015-02-26 12:57:08 -07001399 # This isn't great but this pre-pass flags structs w/ pNext and other struct ptrs
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001400 for m in sorted(self.struct_dict[s]):
1401 if 'pNext' == self.struct_dict[s][m]['name'] or is_type(self.struct_dict[s][m]['type'], 'struct'):
1402 stp_list.append(self.struct_dict[s][m])
1403 if 'pNext' == self.struct_dict[s][m]['name']:
1404 pl_dict[m] = ' PORT=\\"pNext\\"'
1405 else:
1406 pl_dict[m] = ' PORT=\\"struct%i\\"' % struct_num
1407 struct_num += 1
1408 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]))
1409 num_stps = len(stp_list);
1410 total_strlen_str = ''
1411 if 0 != num_stps:
1412 gv_funcs.append(" char* tmpStr;\n")
1413 gv_funcs.append(" char nodeName[100];\n")
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001414 gv_funcs.append(' char* stp_strs[%i];\n' % num_stps)
1415 for index in range(num_stps):
1416 if (stp_list[index]['ptr']):
1417 if 'pDescriptorInfo' == stp_list[index]['name']:
1418 gv_funcs.append(' if (pStruct->pDescriptorInfo && (0 != pStruct->descriptorCount)) {\n')
1419 else:
1420 gv_funcs.append(' if (pStruct->%s) {\n' % stp_list[index]['name'])
1421 if 'pNext' == stp_list[index]['name']:
1422 gv_funcs.append(' sprintf(nodeName, "pNext_%p", (void*)pStruct->pNext);\n')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001423 gv_funcs.append(' tmpStr = dynamic_gv_display((void*)pStruct->pNext, nodeName);\n')
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001424 gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % index)
1425 gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":pNext -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % index)
1426 gv_funcs.append(' free(tmpStr);\n')
1427 else:
1428 gv_funcs.append(' sprintf(nodeName, "%s_%%p", (void*)pStruct->%s);\n' % (stp_list[index]['name'], stp_list[index]['name']))
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001429 if stp_list[index]['name'] in ['pTypeCount', 'pSamplerImageViews']:
Tobin Ehlisd1c0e662015-02-26 12:57:08 -07001430 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 Ehlisa701ef02014-11-27 15:43:39 -07001431 else:
1432 gv_funcs.append(' tmpStr = %s(pStruct->%s, nodeName);\n' % (self._get_gv_func_name(stp_list[index]['type']), stp_list[index]['name']))
1433 gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % (index))
1434 gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":struct%i -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % (index, index))
1435 gv_funcs.append(' }\n')
Chia-I Wu81f46672014-12-16 00:36:58 +08001436 gv_funcs.append(" else\n stp_strs[%i] = \"\";\n" % (index))
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001437 elif stp_list[index]['array']: # TODO : For now just printing first element of array
1438 gv_funcs.append(' sprintf(nodeName, "%s_%%p", (void*)&pStruct->%s[0]);\n' % (stp_list[index]['name'], stp_list[index]['name']))
1439 gv_funcs.append(' tmpStr = %s(&pStruct->%s[0], nodeName);\n' % (self._get_gv_func_name(stp_list[index]['type']), stp_list[index]['name']))
1440 gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % (index))
1441 gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":struct%i -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % (index, index))
1442 else:
1443 gv_funcs.append(' sprintf(nodeName, "%s_%%p", (void*)&pStruct->%s);\n' % (stp_list[index]['name'], stp_list[index]['name']))
1444 gv_funcs.append(' tmpStr = %s(&pStruct->%s, nodeName);\n' % (self._get_gv_func_name(stp_list[index]['type']), stp_list[index]['name']))
1445 gv_funcs.append(' stp_strs[%i] = (char*)malloc(256+strlen(tmpStr)+strlen(nodeName)+strlen(myNodeName));\n' % (index))
1446 gv_funcs.append(' sprintf(stp_strs[%i], "%%s\\n\\"%%s\\":struct%i -> \\"%%s\\" [];\\n", tmpStr, myNodeName, nodeName);\n' % (index, index))
1447 total_strlen_str += 'strlen(stp_strs[%i]) + ' % index
1448 gv_funcs.append(' str = (char*)malloc(%ssizeof(char)*2048);\n' % (total_strlen_str))
1449 gv_funcs.append(' sprintf(str, "\\"%s\\" [\\nlabel = <<TABLE BORDER=\\"0\\" CELLBORDER=\\"1\\" CELLSPACING=\\"0\\"><TR><TD COLSPAN=\\"2\\">%s (%p)</TD></TR>')
1450 p_args = ", myNodeName, myNodeName, pStruct"
1451 for m in sorted(self.struct_dict[s]):
1452 plabel = ""
1453 if m in pl_dict:
1454 plabel = pl_dict[m]
1455 (p_out1, p_args1) = self._get_struct_gv_print_formatted(self.struct_dict[s][m], port_label=plabel)
1456 p_out += p_out1
1457 p_args += p_args1
1458 p_out += '</TABLE>>\\n];\\n\\n"'
1459 p_args += ");\n"
1460 gv_funcs.append(p_out)
1461 gv_funcs.append(p_args)
1462 if 0 != num_stps:
1463 gv_funcs.append(' for (int32_t stp_index = %i; stp_index >= 0; stp_index--) {\n' % (num_stps-1))
1464 gv_funcs.append(' if (0 < strlen(stp_strs[stp_index])) {\n')
1465 gv_funcs.append(' strncat(str, stp_strs[stp_index], strlen(stp_strs[stp_index]));\n')
1466 gv_funcs.append(' free(stp_strs[stp_index]);\n')
1467 gv_funcs.append(' }\n')
1468 gv_funcs.append(' }\n')
1469 gv_funcs.append(" return str;\n}\n")
1470 if s.lower().strip("_") in array_func_list:
Tobin Ehlisd1c0e662015-02-26 12:57:08 -07001471 ptr_array = False
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001472 if s.lower().strip("_") in ['vk_buffer_view_attach_info', 'vk_image_view_attach_info']:
Tobin Ehlisd1c0e662015-02-26 12:57:08 -07001473 ptr_array = True
1474 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]))
1475 else:
1476 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 Ehlisa701ef02014-11-27 15:43:39 -07001477 gv_funcs.append(' str = (char*)malloc(sizeof(char)*1024*count);\n')
1478 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')
1479 gv_funcs.append(' for (uint32_t i=0; i < count; i++) {\n')
1480 gv_funcs.append(' sprintf(tmpStr, "');
1481 p_args = ""
1482 p_out = ""
1483 for m in sorted(self.struct_dict[s]):
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001484 plabel = ""
1485 (p_out1, p_args1) = self._get_struct_gv_print_formatted(self.struct_dict[s][m], port_label=plabel)
Tobin Ehlisd1c0e662015-02-26 12:57:08 -07001486 if 0 == m: # Add array index notation at end of first row
1487 p_out1 = '%s<TD ROWSPAN=\\"%i\\" PORT=\\"slot%%u\\">%%u</TD></TR>' % (p_out1[:-5], len(self.struct_dict[s]))
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001488 p_args1 += ', i, i'
1489 p_out += p_out1
1490 p_args += p_args1
1491 p_out += '"'
1492 p_args += ");\n"
Tobin Ehlisd1c0e662015-02-26 12:57:08 -07001493 if ptr_array:
1494 p_args = p_args.replace('->', '[i]->')
1495 else:
1496 p_args = p_args.replace('->', '[i].')
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001497 gv_funcs.append(p_out);
1498 gv_funcs.append(p_args);
1499 gv_funcs.append(' strncat(str, tmpStr, strlen(tmpStr));\n')
1500 gv_funcs.append(' }\n')
1501 gv_funcs.append(' strncat(str, "</TABLE>>\\n];\\n\\n", 20);\n')
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001502 gv_funcs.append(' return str;\n}\n')
1503 # Add function to dynamically print out unknown struct
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001504 gv_funcs.append("char* dynamic_gv_display(const void* pStruct, const char* nodeName)\n{\n")
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001505 gv_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct\n")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001506 gv_funcs.append(" VK_STRUCTURE_TYPE sType = ((VK_APPLICATION_INFO*)pStruct)->sType;\n")
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001507 gv_funcs.append(" switch (sType)\n {\n")
1508 for e in enum_type_dict:
1509 if "_STRUCTURE_TYPE" in e:
1510 for v in sorted(enum_type_dict[e]):
1511 struct_name = v.replace("_STRUCTURE_TYPE", "")
1512 print_func_name = self._get_gv_func_name(struct_name)
1513 # TODO : Hand-coded fixes for some exceptions
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001514 #if 'VK_PIPELINE_CB_STATE_CREATE_INFO' in struct_name:
1515 # struct_name = 'VK_PIPELINE_CB_STATE'
1516 if 'VK_SEMAPHORE_CREATE_INFO' in struct_name:
1517 struct_name = 'VK_SEMAPHORE_CREATE_INFO'
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001518 print_func_name = self._get_gv_func_name(struct_name)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001519 elif 'VK_SEMAPHORE_OPEN_INFO' in struct_name:
1520 struct_name = 'VK_SEMAPHORE_OPEN_INFO'
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001521 print_func_name = self._get_gv_func_name(struct_name)
1522 gv_funcs.append(' case %s:\n' % (v))
1523 gv_funcs.append(' return %s((%s*)pStruct, nodeName);\n' % (print_func_name, struct_name))
1524 #gv_funcs.append(' }\n')
1525 #gv_funcs.append(' break;\n')
Chia-I Wu84d7f5c2014-12-16 00:43:20 +08001526 gv_funcs.append(" default:\n")
1527 gv_funcs.append(" return NULL;\n")
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001528 gv_funcs.append(" }\n")
1529 gv_funcs.append("}")
1530 return "".join(gv_funcs)
1531
1532
1533
1534
1535
1536# def _generateHeader(self):
1537# hdr = []
1538# hdr.append('digraph g {\ngraph [\nrankdir = "LR"\n];')
1539# hdr.append('node [\nfontsize = "16"\nshape = "plaintext"\n];')
1540# hdr.append('edge [\n];\n')
1541# return "\n".join(hdr)
1542#
1543# def _generateBody(self):
1544# body = []
Peter Lohrmannc55cfa12015-03-30 16:29:56 -07001545# for s in sorted(self.struc_dict):
Tobin Ehlisa701ef02014-11-27 15:43:39 -07001546# field_num = 1
1547# 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]))
1548# for m in sorted(self.struc_dict[s]):
1549# 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']))
1550# field_num += 2
1551# body.append('</TABLE>>\n];\n')
1552# return "".join(body)
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001553
1554def main(argv=None):
1555 opts = handle_args()
1556 # Parse input file and fill out global dicts
1557 hfp = HeaderFileParser(opts.input_file)
1558 hfp.parse()
1559 # TODO : Don't want these to be global, see note at top about wrapper classes
1560 global enum_val_dict
1561 global enum_type_dict
1562 global struct_dict
1563 global typedef_fwd_dict
1564 global typedef_rev_dict
1565 global types_dict
1566 enum_val_dict = hfp.get_enum_val_dict()
1567 enum_type_dict = hfp.get_enum_type_dict()
1568 struct_dict = hfp.get_struct_dict()
Tobin Ehlis6f7029b2014-11-11 12:28:12 -07001569 # TODO : Would like to validate struct data here to verify that all of the bools for struct members are correct at this point
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001570 typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1571 typedef_rev_dict = hfp.get_typedef_rev_dict()
1572 types_dict = hfp.get_types_dict()
1573 #print(enum_val_dict)
1574 #print(typedef_dict)
1575 #print(struct_dict)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001576 prefix = os.path.basename(opts.input_file).strip(".h")
1577 if prefix == "vulkan":
1578 prefix = "vk"
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001579 if (opts.abs_out_dir is not None):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001580 enum_sh_filename = os.path.join(opts.abs_out_dir, prefix+"_enum_string_helper.h")
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001581 else:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001582 enum_sh_filename = os.path.join(os.getcwd(), opts.rel_out_dir, prefix+"_enum_string_helper.h")
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001583 enum_sh_filename = os.path.abspath(enum_sh_filename)
1584 if not os.path.exists(os.path.dirname(enum_sh_filename)):
1585 print("Creating output dir %s" % os.path.dirname(enum_sh_filename))
1586 os.mkdir(os.path.dirname(enum_sh_filename))
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001587 if opts.gen_enum_string_helper:
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001588 print("Generating enum string helper to %s" % enum_sh_filename)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001589 enum_vh_filename = os.path.join(os.path.dirname(enum_sh_filename), prefix+"_enum_validate_helper.h")
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001590 print("Generating enum validate helper to %s" % enum_vh_filename)
1591 eg = EnumCodeGen(enum_type_dict, enum_val_dict, typedef_fwd_dict, os.path.basename(opts.input_file), enum_sh_filename, enum_vh_filename)
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001592 eg.generateStringHelper()
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001593 eg.generateEnumValidate()
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001594 #for struct in struct_dict:
1595 #print(struct)
1596 if opts.gen_struct_wrappers:
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001597 sw = StructWrapperGen(struct_dict, os.path.basename(opts.input_file).strip(".h"), os.path.dirname(enum_sh_filename))
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001598 #print(sw.get_class_name(struct))
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001599 sw.set_include_headers([os.path.basename(opts.input_file),os.path.basename(enum_sh_filename),"stdint.h","stdio.h","stdlib.h"])
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001600 print("Generating struct wrapper header to %s" % sw.header_filename)
1601 sw.generateHeader()
1602 print("Generating struct wrapper class to %s" % sw.class_filename)
1603 sw.generateBody()
1604 sw.generateStringHelper()
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001605 sw.generateValidateHelper()
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001606 # Generate a 2nd helper file that excludes addrs
1607 sw.set_no_addr(True)
1608 sw.generateStringHelper()
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001609 sw.set_no_addr(False)
1610 sw.set_include_headers([os.path.basename(opts.input_file),os.path.basename(enum_sh_filename),"stdint.h","stdio.h","stdlib.h","iostream","sstream","string"])
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001611 sw.set_no_addr(True)
1612 sw.generateStringHelperCpp()
Tobin Ehlis91cc24a2015-03-06 10:38:25 -07001613 sw.set_no_addr(False)
1614 sw.generateStringHelperCpp()
Courtney Goeltzenleuchtera8c06282015-04-14 14:55:44 -06001615 sw.set_include_headers(["stdio.h", "stdlib.h", "vulkan.h"])
Tobin Ehlisff765b02015-03-12 14:50:40 -06001616 sw.generateSizeHelper()
Peter Lohrmann3a9c63a2015-04-03 11:43:06 -07001617 sw.generateSizeHelperC()
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001618 if opts.gen_cmake:
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001619 cmg = CMakeGen(sw, os.path.dirname(enum_sh_filename))
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001620 cmg.generate()
1621 if opts.gen_graphviz:
Tobin Ehlisbe8dded2014-12-17 07:20:23 -07001622 gv = GraphVizGen(struct_dict, os.path.basename(opts.input_file).strip(".h"), os.path.dirname(enum_sh_filename))
1623 gv.set_include_headers([os.path.basename(opts.input_file),os.path.basename(enum_sh_filename),"stdint.h","stdio.h","stdlib.h"])
Tobin Ehlisee33fa52014-10-22 15:13:53 -06001624 gv.generate()
1625 print("DONE!")
1626 #print(typedef_rev_dict)
1627 #print(types_dict)
1628 #recreate_structs()
1629
1630if __name__ == "__main__":
1631 sys.exit(main())