aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMark Lobodzinski <mark@lunarg.com>2016-12-21 15:50:01 -0700
committerMark Lobodzinski <mark@lunarg.com>2016-12-27 15:43:29 -0700
commit59e613dac9ab68480f3a59895450d826cea1c03d (patch)
tree8016692438ab971b7a30a180cb0664df8648eb4f /scripts
parentbce464986cb0adf001410f3a2ab77ef9383beac7 (diff)
downloadusermoji-59e613dac9ab68480f3a59895450d826cea1c03d.tar.xz
scripts: Remove unused code from vk_helper.py
Mostly the string_struct_helper related stuff, but also some additional orphaned remnants. Change-Id: Ibdd124d10351c694b02917c81e97c56dc9645e6b
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vk_helper.py678
1 files changed, 0 insertions, 678 deletions
diff --git a/scripts/vk_helper.py b/scripts/vk_helper.py
index e5685b21..b2fe062a 100755
--- a/scripts/vk_helper.py
+++ b/scripts/vk_helper.py
@@ -482,13 +482,9 @@ class StructWrapperGen:
self.api_prefix = prefix
self.safe_struct_header_filename = os.path.join(out_dir, self.api_prefix+"_safe_struct.h")
self.safe_struct_source_filename = os.path.join(out_dir, self.api_prefix+"_safe_struct.cpp")
- self.string_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper.h")
- self.string_helper_cpp_filename = os.path.join(out_dir, self.api_prefix+"_struct_string_helper_cpp.h")
# Safe Struct (ss) header and source files
self.ssh = CommonFileGen(self.safe_struct_header_filename)
self.sss = CommonFileGen(self.safe_struct_source_filename)
- self.shg = CommonFileGen(self.string_helper_filename)
- self.shcppg = CommonFileGen(self.string_helper_cpp_filename)
self.size_helper_filename = os.path.join(out_dir, self.api_prefix+"_struct_size_helper.h")
self.size_helper_c_filename = os.path.join(out_dir, self.api_prefix+"_struct_size_helper.c")
self.size_helper_gen = CommonFileGen(self.size_helper_filename)
@@ -522,24 +518,6 @@ class StructWrapperGen:
self.sss.setBody(self._generateSafeStructSource())
self.sss.generate()
- # Generate c-style .h file that contains functions for printing structs
- def generateStringHelper(self):
- if not self.quiet:
- print("Generating struct string helper")
- self.shg.setCopyright(self._generateCopyright())
- self.shg.setHeader(self._generateStringHelperHeader())
- self.shg.setBody(self._generateStringHelperFunctions())
- self.shg.generate()
-
- # Generate cpp-style .h file that contains functions for printing structs
- def generateStringHelperCpp(self):
- if not self.quiet:
- print("Generating struct string helper cpp")
- self.shcppg.setCopyright(self._generateCopyright())
- self.shcppg.setHeader(self._generateStringHelperHeaderCpp())
- self.shcppg.setBody(self._generateStringHelperFunctionsCpp())
- self.shcppg.generate()
-
def generateSizeHelper(self):
if not self.quiet:
print("Generating struct size helper")
@@ -593,664 +571,12 @@ class StructWrapperGen:
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))
return "".join(header)
- def _generateClassDefinition(self):
- class_def = []
- if 'vk' == self.api:
- class_def.append(self._generateDynamicPrintFunctions())
- for s in sorted(self.struct_dict):
- class_def.append("\n// %s class definition" % self.get_class_name(s))
- class_def.append(self._generateConstructorDefinitions(s))
- class_def.append(self._generateDestructorDefinitions(s))
- class_def.append(self._generateDisplayDefinitions(s))
- return "\n".join(class_def)
-
- def _generateConstructorDefinitions(self, s):
- con_defs = []
- 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)))
- # TODO : This is a shallow copy of ptrs
- 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]))
- 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]))
- return "\n".join(con_defs)
-
- def _generateDestructorDefinitions(self, s):
- return "%s::~%s() {}" % (self.get_class_name(s), self.get_class_name(s))
-
- def _generateDynamicPrintFunctions(self):
- dp_funcs = []
- 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")
- dp_funcs.append(" VkStructureType sType = ((VkApplicationInfo*)pStruct)->sType;\n")
- dp_funcs.append(" switch (sType)\n {")
- for e in enum_type_dict:
- class_num = 0
- if "StructureType" in e:
- for v in sorted(enum_type_dict[e]):
- struct_name = get_struct_name_from_struct_type(v)
- if struct_name not in self.struct_dict:
- continue
-
- class_name = self.get_class_name(struct_name)
- instance_name = "swc%i" % class_num
- dp_funcs.append(" case %s:\n {" % (v))
- dp_funcs.append(" %s %s((%s*)pStruct);" % (class_name, instance_name, struct_name))
- dp_funcs.append(" %s.set_indent(indent);" % (instance_name))
- dp_funcs.append(" %s.display_full_txt();" % (instance_name))
- dp_funcs.append(" }")
- dp_funcs.append(" break;")
- class_num += 1
- dp_funcs.append(" }")
- dp_funcs.append("}\n")
- return "\n".join(dp_funcs)
-
def _get_func_name(self, struct, mid_str):
return "%s_%s_%s" % (self.api_prefix, mid_str, struct.lower().strip("_"))
- def _get_sh_func_name(self, struct):
- return self._get_func_name(struct, 'print')
-
- def _get_vh_func_name(self, struct):
- return self._get_func_name(struct, 'validate')
-
def _get_size_helper_func_name(self, struct):
return self._get_func_name(struct, 'size')
- # Return elements to create formatted string for given struct member
- def _get_struct_print_formatted(self, struct_member, pre_var_name="prefix", postfix = "\\n", struct_var_name="pStruct", struct_ptr=True, print_array=False):
- struct_op = "->"
- if not struct_ptr:
- struct_op = "."
- member_name = struct_member['name']
- print_type = "p"
- cast_type = ""
- member_post = ""
- array_index = ""
- member_print_post = ""
- print_delimiter = "%"
- if struct_member['array'] and 'char' in struct_member['type'].lower(): # just print char array as string
- if member_name.startswith('pp'): # TODO : Only printing first element of dynam array of char* for now
- member_post = "[0]"
- print_type = "s"
- print_array = False
- elif struct_member['array'] and not print_array:
- # Just print base address of array when not full print_array
- print_delimiter = "0x%"
- cast_type = "(void*)"
- elif is_type(struct_member['type'], 'enum'):
- cast_type = "string_%s" % struct_member['type']
- if struct_member['ptr']:
- struct_var_name = "*" + struct_var_name
- print_delimiter = "0x%"
- print_type = "s"
- elif is_type(struct_member['type'], 'struct'): # print struct address for now
- print_delimiter = "0x%"
- cast_type = "(void*)"
- if not struct_member['ptr']:
- cast_type = "(void*)&"
- elif 'bool' in struct_member['type'].lower():
- print_type = "s"
- member_post = ' ? "TRUE" : "FALSE"'
- elif 'float' in struct_member['type']:
- print_type = "f"
- elif 'uint64' in struct_member['type'] or 'gpusize' in struct_member['type'].lower():
- print_type = '" PRId64 "'
- elif 'uint8' in struct_member['type']:
- print_type = "hu"
- elif 'size' in struct_member['type'].lower():
- print_type = '" PRINTF_SIZE_T_SPECIFIER "'
- print_delimiter = ""
- elif True in [ui_str.lower() in struct_member['type'].lower() for ui_str in ['uint', 'flags', 'samplemask']]:
- print_type = "u"
- elif 'int' in struct_member['type']:
- print_type = "i"
- elif struct_member['ptr']:
- print_delimiter = "0x%"
- pass
- else:
- #print("Unhandled struct type: %s" % struct_member['type'])
- print_delimiter = "0x%"
- cast_type = "(void*)"
- if print_array and struct_member['array']:
- member_print_post = "[%u]"
- array_index = " i,"
- member_post = "[i]"
- 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
- 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
- return (print_out, print_arg)
-
- def _generateStringHelperFunctions(self):
- sh_funcs = []
- # We do two passes, first pass just generates prototypes for all the functsions
- for s in sorted(self.struct_dict):
- sh_funcs.append('char* %s(const %s* pStruct, const char* prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s]))
- sh_funcs.append('')
- sh_funcs.append('#if defined(_WIN32)')
- sh_funcs.append('// Microsoft did not implement C99 in Visual Studio; but started adding it with')
- sh_funcs.append('// VS2013. However, VS2013 still did not have snprintf(). The following is a')
- sh_funcs.append('// work-around.')
- sh_funcs.append('#define snprintf _snprintf')
- sh_funcs.append('#endif // _WIN32\n')
- for s in sorted(self.struct_dict):
- p_out = ""
- p_args = ""
- stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs
- # This pre-pass flags embedded structs and pNext
- for m in sorted(self.struct_dict[s]):
- if 'pNext' == self.struct_dict[s][m]['name'] or is_type(self.struct_dict[s][m]['type'], 'struct'):
- stp_list.append(self.struct_dict[s][m])
- 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]))
- sh_funcs.append(" size_t len;")
- num_stps = len(stp_list);
- total_strlen_str = ''
- if 0 != num_stps:
- sh_funcs.append(" char* tmpStr;")
- sh_funcs.append(' char* extra_indent = (char*)malloc(strlen(prefix) + 3);')
- sh_funcs.append(' strcpy(extra_indent, " ");')
- sh_funcs.append(' strncat(extra_indent, prefix, strlen(prefix));')
- sh_funcs.append(' char* stp_strs[%i];' % num_stps)
- for index in range(num_stps):
- # If it's an array, print all of the elements
- # If it's a ptr, print thing it's pointing to
- # Non-ptr struct case. Print the struct using its address
- struct_deref = '&'
- if 1 < stp_list[index]['full_type'].count('*'):
- struct_deref = ''
- if (stp_list[index]['ptr']):
- sh_funcs.append(' if (pStruct->%s) {' % stp_list[index]['name'])
- if 'pNext' == stp_list[index]['name']:
- sh_funcs.append(' tmpStr = dynamic_display((void*)pStruct->pNext, prefix);')
- sh_funcs.append(' len = 256+strlen(tmpStr);')
- sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % index)
- sh_funcs.append(' snprintf(stp_strs[%i], len, " %%spNext (0x%%p)\\n%%s", prefix, (void*)pStruct->pNext, tmpStr);' % index)
- sh_funcs.append(' free(tmpStr);')
- else:
- if stp_list[index]['name'] in ['pImageViews', 'pBufferViews']:
- # TODO : This is a quick hack to handle these arrays of ptrs
- sh_funcs.append(' tmpStr = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
- else:
- sh_funcs.append(' tmpStr = %s(pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
- sh_funcs.append(' len = 256+strlen(tmpStr)+strlen(prefix);')
- sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index))
- sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (0x%%p)\\n%%s", prefix, (void*)pStruct->%s, tmpStr);' % (index, stp_list[index]['name'], stp_list[index]['name']))
- sh_funcs.append(' }')
- sh_funcs.append(" else\n stp_strs[%i] = \"\";" % (index))
- elif stp_list[index]['array']:
- sh_funcs.append(' tmpStr = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
- sh_funcs.append(' len = 256+strlen(tmpStr);')
- sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index))
- sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s[0] (0x%%p)\\n%%s", prefix, (void*)&pStruct->%s[0], tmpStr);' % (index, stp_list[index]['name'], stp_list[index]['name']))
- else:
- sh_funcs.append(' tmpStr = %s(&pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
- sh_funcs.append(' len = 256+strlen(tmpStr);')
- sh_funcs.append(' stp_strs[%i] = (char*)malloc(len);' % (index))
- sh_funcs.append(' snprintf(stp_strs[%i], len, " %%s%s (0x%%p)\\n%%s", prefix, (void*)&pStruct->%s, tmpStr);' % (index, stp_list[index]['name'], stp_list[index]['name']))
- total_strlen_str += 'strlen(stp_strs[%i]) + ' % index
- sh_funcs.append(' len = %ssizeof(char)*1024;' % (total_strlen_str))
- sh_funcs.append(' str = (char*)malloc(len);')
- sh_funcs.append(' snprintf(str, len, "')
- for m in sorted(self.struct_dict[s]):
- (p_out1, p_args1) = self._get_struct_print_formatted(self.struct_dict[s][m])
- p_out += p_out1
- p_args += p_args1
- p_out += '"'
- p_args += ");"
- sh_funcs[-1] = '%s%s%s' % (sh_funcs[-1], p_out, p_args)
- if 0 != num_stps:
- sh_funcs.append(' for (int32_t stp_index = %i; stp_index >= 0; stp_index--) {' % (num_stps-1))
- sh_funcs.append(' if (0 < strlen(stp_strs[stp_index])) {')
- sh_funcs.append(' strncat(str, stp_strs[stp_index], strlen(stp_strs[stp_index]));')
- sh_funcs.append(' free(stp_strs[stp_index]);')
- sh_funcs.append(' }')
- sh_funcs.append(' }')
- sh_funcs.append(' free(extra_indent);')
- sh_funcs.append(" return str;\n}")
- # Add function to dynamically print out unknown struct
- sh_funcs.append("char* dynamic_display(const void* pStruct, const char* prefix)\n{")
- sh_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct")
- sh_funcs.append(" if (pStruct == NULL) {")
- sh_funcs.append(" return NULL;")
- sh_funcs.append(" }")
- sh_funcs.append(" VkStructureType sType = ((VkApplicationInfo*)pStruct)->sType;")
- sh_funcs.append(' char indent[100];\n strcpy(indent, " ");\n strcat(indent, prefix);')
- sh_funcs.append(" switch (sType)\n {")
- for e in enum_type_dict:
- if "StructureType" in e:
- for v in sorted(enum_type_dict[e]):
- struct_name = get_struct_name_from_struct_type(v)
- if struct_name not in self.struct_dict:
- continue
- print_func_name = self._get_sh_func_name(struct_name)
- sh_funcs.append(' case %s:\n {' % (v))
- sh_funcs.append(' return %s((%s*)pStruct, indent);' % (print_func_name, struct_name))
- sh_funcs.append(' }')
- sh_funcs.append(' break;')
- sh_funcs.append(" default:")
- sh_funcs.append(" return NULL;")
- sh_funcs.append(" }")
- sh_funcs.append("}")
- return "\n".join(sh_funcs)
-
- def _generateStringHelperFunctionsCpp(self):
- # declare str & tmp str
- # declare array of stringstreams for every struct ptr in current struct
- # declare array of stringstreams for every non-string element in current struct
- # For every struct ptr, if non-Null, then set its string, else set to NULL str
- # For every non-string element, set its string stream
- # create and return final string
- sh_funcs = []
- # First generate prototypes for every struct
- # XXX - REMOVE this comment
- lineinfo = sourcelineinfo()
- sh_funcs.append('%s' % lineinfo.get())
- for s in sorted(self.struct_dict):
- # Wrap this in platform check since it may contain undefined structs or functions
- add_platform_wrapper_entry(sh_funcs, typedef_fwd_dict[s])
- sh_funcs.append('std::string %s(const %s* pStruct, const std::string prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s]))
- add_platform_wrapper_exit(sh_funcs, typedef_fwd_dict[s])
-
- sh_funcs.append('\n')
- sh_funcs.append('%s' % lineinfo.get())
- for s in sorted(self.struct_dict):
- num_non_enum_elems = [(is_type(self.struct_dict[s][elem]['type'], 'enum') and not self.struct_dict[s][elem]['ptr']) for elem in self.struct_dict[s]].count(False)
- stp_list = [] # stp == "struct to print" a list of structs for this API call that should be printed as structs
- # This pre-pass flags embedded structs and pNext
- for m in sorted(self.struct_dict[s]):
- 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']:
- # TODO: This is a tmp workaround
- if 'ppActiveLayerNames' not in self.struct_dict[s][m]['name']:
- stp_list.append(self.struct_dict[s][m])
- sh_funcs.append('%s' % lineinfo.get())
-
- # Wrap this in platform check since it may contain undefined structs or functions
- add_platform_wrapper_entry(sh_funcs, typedef_fwd_dict[s])
-
- sh_funcs.append('std::string %s(const %s* pStruct, const std::string prefix)\n{' % (self._get_sh_func_name(s), typedef_fwd_dict[s]))
- sh_funcs.append('%s' % lineinfo.get())
- indent = ' '
- sh_funcs.append('%susing namespace StreamControl;' % (indent))
- sh_funcs.append('%susing namespace std;' % (indent))
- sh_funcs.append('%sstring final_str;' % (indent))
- sh_funcs.append('%sstring tmp_str;' % (indent))
- sh_funcs.append('%sstring extra_indent = " " + prefix;' % (indent))
- if (0 != num_non_enum_elems):
- sh_funcs.append('%sstringstream ss[%u];' % (indent, num_non_enum_elems))
- num_stps = len(stp_list)
- # First generate code for any embedded structs or arrays
- if 0 < num_stps:
- sh_funcs.append('%sstring stp_strs[%u];' % (indent, num_stps))
- idx_ss_decl = False # Make sure to only decl this once
- for index in range(num_stps):
- addr_char = '&'
- if 1 < stp_list[index]['full_type'].count('*'):
- addr_char = ''
- if stp_list[index]['array']:
- sh_funcs.append('%s' % lineinfo.get())
- if stp_list[index]['dyn_array']:
- sh_funcs.append('%s' % lineinfo.get())
- array_count = 'pStruct->%s' % (stp_list[index]['array_size'])
- else:
- sh_funcs.append('%s' % lineinfo.get())
- array_count = '%s' % (stp_list[index]['array_size'])
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append('%sstp_strs[%u] = "";' % (indent, index))
- if not idx_ss_decl:
- sh_funcs.append('%sstringstream index_ss;' % (indent))
- idx_ss_decl = True
- if (stp_list[index]['name'] == 'pQueueFamilyIndices'):
- if (typedef_fwd_dict[s] == 'VkSwapchainCreateInfoKHR'):
- sh_funcs.append('%sif (pStruct->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {' % (indent))
- else:
- sh_funcs.append('%sif (pStruct->sharingMode == VK_SHARING_MODE_CONCURRENT) {' % (indent))
- indent += ' '
- if (stp_list[index]['name'] == 'pImageInfo'):
- sh_funcs.append('%sif ((pStruct->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||' % (indent))
- sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||' % (indent))
- sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||' % (indent))
- sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE)) {' % (indent))
- indent += ' '
- elif (stp_list[index]['name'] == 'pBufferInfo'):
- sh_funcs.append('%sif ((pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||' % (indent))
- sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||' % (indent))
- sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||' % (indent))
- sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {' % (indent))
- indent += ' '
- elif (stp_list[index]['name'] == 'pTexelBufferView'):
- sh_funcs.append('%sif ((pStruct->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||' % (indent))
- sh_funcs.append('%s (pStruct->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {' % (indent))
- indent += ' '
- if stp_list[index]['dyn_array']:
- sh_funcs.append('%sif (pStruct->%s) {' % (indent, stp_list[index]['name']))
- indent += ' '
- sh_funcs.append('%sfor (uint32_t i = 0; i < %s; i++) {' % (indent, array_count))
- indent += ' '
- sh_funcs.append('%sindex_ss.str("");' % (indent))
- sh_funcs.append('%sindex_ss << i;' % (indent))
- if is_type(stp_list[index]['type'], 'enum'):
- sh_funcs.append('%s' % lineinfo.get())
- addr_char = ''
- #value_print = 'string_%s(%spStruct->%s)' % (self.struct_dict[s][m]['type'], deref, self.struct_dict[s][m]['name'])
- sh_funcs.append('%sss[%u] << string_%s(pStruct->%s[i]);' % (indent, index, stp_list[index]['type'], stp_list[index]['name']))
- sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] = " + ss[%u].str() + "\\n";' % (indent, index, stp_list[index]['name'], index))
- elif is_type(stp_list[index]['type'], 'struct'):
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append('%sss[%u] << "0x" << %spStruct->%s[i];' % (indent, index, addr_char, stp_list[index]['name']))
- 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']))
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] (" + ss[%u].str() + ")\\n" + tmp_str;' % (indent, index, stp_list[index]['name'], index))
- else:
- sh_funcs.append('%s' % lineinfo.get())
- addr_char = ''
- if stp_list[index]['ptr'] or 'UUID' in stp_list[index]['name']:
- sh_funcs.append('%sss[%u] << "0x" << %spStruct->%s[i];' % (indent, index, addr_char, stp_list[index]['name']))
- else:
- sh_funcs.append('%sss[%u] << %spStruct->%s[i];' % (indent, index, addr_char, stp_list[index]['name']))
- if stp_list[index]['type'] in vulkan.VK_VERSION_1_0.objects:
- sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "].handle = " + ss[%u].str() + "\\n";' % (indent, index, stp_list[index]['name'], index))
- else:
- sh_funcs.append('%sstp_strs[%u] += " " + prefix + "%s[" + index_ss.str() + "] = " + ss[%u].str() + "\\n";' % (indent, index, stp_list[index]['name'], index))
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append('%sss[%u].str("");' % (indent, index))
- indent = indent[4:]
- sh_funcs.append('%s}' % (indent))
- if stp_list[index]['dyn_array']:
- indent = indent[4:]
- sh_funcs.append('%s}' % (indent))
- #endif
- if (stp_list[index]['name'] == 'pQueueFamilyIndices') or (stp_list[index]['name'] == 'pImageInfo') or (stp_list[index]['name'] == 'pBufferInfo') or (stp_list[index]['name'] == 'pTexelBufferView'):
- indent = indent[4:]
- sh_funcs.append('%s}' % (indent))
- elif (stp_list[index]['ptr']):
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append('%sif (pStruct->%s) {' % (indent, stp_list[index]['name']))
- indent += ' '
- if 'pNext' == stp_list[index]['name']:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' tmp_str = dynamic_display((void*)pStruct->pNext, prefix);')
- else:
- if stp_list[index]['name'] in ['pImageViews', 'pBufferViews']:
- # TODO : This is a quick hack to handle these arrays of ptrs
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' tmp_str = %s(&pStruct->%s[0], extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
- else:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' tmp_str = %s(pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
- sh_funcs.append(' ss[%u] << "0x" << %spStruct->%s;' % (index, addr_char, stp_list[index]['name']))
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (" + ss[%u].str() + ")\\n" + tmp_str;' % (index, stp_list[index]['name'], index))
- sh_funcs.append(' ss[%u].str("");' % (index))
- sh_funcs.append(' }')
- sh_funcs.append(' else')
- sh_funcs.append(' stp_strs[%u] = "";' % index)
- else:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' tmp_str = %s(&pStruct->%s, extra_indent);' % (self._get_sh_func_name(stp_list[index]['type']), stp_list[index]['name']))
- sh_funcs.append(' ss[%u] << "0x" << %spStruct->%s;' % (index, addr_char, stp_list[index]['name']))
- sh_funcs.append(' stp_strs[%u] = " " + prefix + "%s (" + ss[%u].str() + ")\\n" + tmp_str;' % (index, stp_list[index]['name'], index))
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' ss[%u].str("");' % index)
- # Now print one-line info for all data members
- index = 0
- final_str = []
- for m in sorted(self.struct_dict[s]):
- if not is_type(self.struct_dict[s][m]['type'], 'enum'):
- if is_type(self.struct_dict[s][m]['type'], 'struct') and not self.struct_dict[s][m]['ptr']:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' ss[%u] << "0x" << &pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- elif self.struct_dict[s][m]['array']:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' ss[%u] << "0x" << (void*)pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- elif 'bool' in self.struct_dict[s][m]['type'].lower():
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' ss[%u].str(pStruct->%s ? "TRUE" : "FALSE");' % (index, self.struct_dict[s][m]['name']))
- elif 'uint8' in self.struct_dict[s][m]['type'].lower():
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- elif 'void' in self.struct_dict[s][m]['type'].lower() and self.struct_dict[s][m]['ptr']:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' if (StreamControl::writeAddress)')
- sh_funcs.append(' ss[%u] << "0x" << pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- sh_funcs.append(' else')
- sh_funcs.append(' ss[%u].str("address");' % (index))
- elif 'char' in self.struct_dict[s][m]['type'].lower() and self.struct_dict[s][m]['ptr']:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' if (pStruct->%s != NULL) {' % self.struct_dict[s][m]['name'])
- sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- sh_funcs.append(' } else {')
- sh_funcs.append(' ss[%u] << "";' % index)
- sh_funcs.append(' }')
- else:
- if self.struct_dict[s][m]['ptr'] or \
- 'Vk' in self.struct_dict[s][m]['full_type'] or \
- 'PFN_vk' in self.struct_dict[s][m]['full_type']:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' ss[%u] << "0x" << pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- elif any (x in self.struct_dict[s][m]['name'].lower() for x in ("flag", "bit", "offset", "handle", "buffer", "object", "mask")) or \
- 'ID' in self.struct_dict[s][m]['name']:
- sh_funcs.append('%s: NB: Edit here to choose hex vs dec output by variable name' % lineinfo.get())
- sh_funcs.append(' ss[%u] << "0x" << pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- else:
- sh_funcs.append('%s: NB Edit this section to choose hex vs dec output by variable name' % lineinfo.get())
- sh_funcs.append(' ss[%u] << pStruct->%s;' % (index, self.struct_dict[s][m]['name']))
- value_print = 'ss[%u].str()' % index
- index += 1
- else:
- # For an non-empty array of enums just print address w/ note that array will be displayed below
- if self.struct_dict[s][m]['ptr']:
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(' if (pStruct->%s)' % (self.struct_dict[s][m]['name']))
- sh_funcs.append(' ss[%u] << "0x" << pStruct->%s << " (See individual array values below)";' % (index, self.struct_dict[s][m]['name']))
- sh_funcs.append(' else')
- sh_funcs.append(' ss[%u].str("NULL");' % (index))
- value_print = 'ss[%u].str()' % index
- index += 1
- # For single enum just print the string representation
- else:
- value_print = 'string_%s(pStruct->%s)' % (self.struct_dict[s][m]['type'], self.struct_dict[s][m]['name'])
- final_str.append('+ prefix + "%s = " + %s + "\\n"' % (self.struct_dict[s][m]['name'], value_print))
- if 0 != num_stps: # Append data for any embedded structs
- final_str.append("+ %s" % " + ".join(['stp_strs[%u]' % n for n in reversed(range(num_stps))]))
- sh_funcs.append('%s' % lineinfo.get())
- for final_str_part in final_str:
- sh_funcs.append(' final_str = final_str %s;' % final_str_part)
- sh_funcs.append(' return final_str;\n}')
-
- # End of platform wrapped section
- add_platform_wrapper_exit(sh_funcs, typedef_fwd_dict[s])
-
- # Add function to return a string value for input void*
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append("std::string string_convert_helper(const void* toString, const std::string prefix)\n{")
- sh_funcs.append(" using namespace StreamControl;")
- sh_funcs.append(" using namespace std;")
- sh_funcs.append(" stringstream ss;")
- sh_funcs.append(' ss << toString;')
- sh_funcs.append(' string final_str = prefix + ss.str();')
- sh_funcs.append(" return final_str;")
- sh_funcs.append("}")
- sh_funcs.append('%s' % lineinfo.get())
- # Add function to return a string value for input uint64_t
- sh_funcs.append("std::string string_convert_helper(const uint64_t toString, const std::string prefix)\n{")
- sh_funcs.append(" using namespace StreamControl;")
- sh_funcs.append(" using namespace std;")
- sh_funcs.append(" stringstream ss;")
- sh_funcs.append(' ss << toString;')
- sh_funcs.append(' string final_str = prefix + ss.str();')
- sh_funcs.append(" return final_str;")
- sh_funcs.append("}")
- sh_funcs.append('%s' % lineinfo.get())
- # Add function to return a string value for input VkSurfaceFormatKHR*
- sh_funcs.append("std::string string_convert_helper(VkSurfaceFormatKHR toString, const std::string prefix)\n{")
- sh_funcs.append(" using namespace std;")
- sh_funcs.append(' string final_str = prefix + "format = " + string_VkFormat(toString.format) + "format = " + string_VkColorSpaceKHR(toString.colorSpace);')
- sh_funcs.append(" return final_str;")
- sh_funcs.append("}")
- sh_funcs.append('%s' % lineinfo.get())
- # Add function to dynamically print out unknown struct
- sh_funcs.append("std::string dynamic_display(const void* pStruct, const std::string prefix)\n{")
- sh_funcs.append(" using namespace std;")
- sh_funcs.append(" // Cast to APP_INFO ptr initially just to pull sType off struct")
- sh_funcs.append(" if (pStruct == NULL) {\n")
- sh_funcs.append(" return string();")
- sh_funcs.append(" }\n")
- sh_funcs.append(" VkStructureType sType = ((VkApplicationInfo*)pStruct)->sType;")
- sh_funcs.append(' string indent = " ";')
- sh_funcs.append(' indent += prefix;')
- sh_funcs.append(" switch (sType)\n {")
- for e in enum_type_dict:
- if "StructureType" in e:
- for v in sorted(enum_type_dict[e]):
- struct_name = get_struct_name_from_struct_type(v)
- if struct_name not in self.struct_dict:
- continue
- if 'WIN32' in v:
- sh_funcs.append("#ifdef VK_USE_PLATFORM_WIN32_KHR")
- print_func_name = self._get_sh_func_name(struct_name)
- #sh_funcs.append('string %s(const %s* pStruct, const string prefix);' % (self._get_sh_func_name(s), typedef_fwd_dict[s]))
- sh_funcs.append(' case %s:\n {' % (v))
- sh_funcs.append(' return %s((%s*)pStruct, indent);' % (print_func_name, struct_name))
- sh_funcs.append(' }')
- sh_funcs.append(' break;')
- if 'WIN32' in v:
- sh_funcs.append("#endif // VK_USE_PLATFORM_WIN32_KHR")
- sh_funcs.append(" default:")
- sh_funcs.append(" return string();")
- sh_funcs.append('%s' % lineinfo.get())
- sh_funcs.append(" }")
- sh_funcs.append("}")
- return "\n".join(sh_funcs)
-
- def _genStructMemberPrint(self, member, s, array, struct_array):
- (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)
- extra_indent = ""
- if array:
- extra_indent = " "
- if is_type(self.struct_dict[s][member]['type'], 'struct'): # print struct address for now
- struct_array.insert(0, self.struct_dict[s][member])
- elif self.struct_dict[s][member]['ptr']:
- # Special case for void* named "pNext"
- if "void" in self.struct_dict[s][member]['type'] and "pNext" == self.struct_dict[s][member]['name']:
- struct_array.insert(0, self.struct_dict[s][member])
- return (' %sprintf("%%*s %s", m_indent, ""%s);' % (extra_indent, p_out, p_arg), struct_array)
-
- def _generateDisplayDefinitions(self, s):
- disp_def = []
- struct_array = []
- # Single-line struct print function
- disp_def.append("// Output 'structname = struct_address' on a single line")
- disp_def.append("void %s::display_single_txt()\n{" % self.get_class_name(s))
- disp_def.append(' printf(" %%*s%s = 0x%%p", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s])
- disp_def.append("}\n")
- # Private helper function to print struct members
- disp_def.append("// Private helper function that displays the members of the wrapped struct")
- disp_def.append("void %s::display_struct_members()\n{" % self.get_class_name(s))
- i_declared = False
- for member in sorted(self.struct_dict[s]):
- # TODO : Need to display each member based on its type
- # TODO : Need to handle pNext which are structs, but of void* type
- # Can grab struct type off of header of struct pointed to
- # TODO : Handle Arrays
- if self.struct_dict[s][member]['array']:
- # Create for loop to print each element of array
- if not i_declared:
- disp_def.append(' uint32_t i;')
- i_declared = True
- disp_def.append(' for (i = 0; i<%s; i++) {' % self.struct_dict[s][member]['array_size'])
- (return_str, struct_array) = self._genStructMemberPrint(member, s, True, struct_array)
- disp_def.append(return_str)
- disp_def.append(' }')
- else:
- (return_str, struct_array) = self._genStructMemberPrint(member, s, False, struct_array)
- disp_def.append(return_str)
- disp_def.append("}\n")
- i_declared = False
- # Basic print function to display struct members
- disp_def.append("// Output all struct elements, each on their own line")
- disp_def.append("void %s::display_txt()\n{" % self.get_class_name(s))
- disp_def.append(' printf("%%*s%s struct contents at 0x%%p:\\n", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s])
- disp_def.append(' this->display_struct_members();')
- disp_def.append("}\n")
- # Advanced print function to display current struct and contents of any pointed-to structs
- disp_def.append("// Output all struct elements, and for any structs pointed to, print complete contents")
- disp_def.append("void %s::display_full_txt()\n{" % self.get_class_name(s))
- disp_def.append(' printf("%%*s%s struct contents at 0x%%p:\\n", m_indent, "", (void*)m_origStructAddr);' % typedef_fwd_dict[s])
- disp_def.append(' this->display_struct_members();')
- class_num = 0
- # TODO : Need to handle arrays of structs here
- for ms in struct_array:
- swc_name = "class%s" % str(class_num)
- if ms['array']:
- if not i_declared:
- disp_def.append(' uint32_t i;')
- i_declared = True
- disp_def.append(' for (i = 0; i<%s; i++) {' % ms['array_size'])
- #disp_def.append(" if (m_struct.%s[i]) {" % (ms['name']))
- disp_def.append(" %s %s(&(m_struct.%s[i]));" % (self.get_class_name(ms['type']), swc_name, ms['name']))
- disp_def.append(" %s.set_indent(m_indent + 4);" % (swc_name))
- disp_def.append(" %s.display_full_txt();" % (swc_name))
- #disp_def.append(' }')
- disp_def.append(' }')
- elif 'pNext' == ms['name']:
- # Need some code trickery here
- # I'm thinking have a generated function that takes pNext ptr value
- # then it checks sType and in large switch statement creates appropriate
- # wrapper class type and then prints contents
- disp_def.append(" if (m_struct.%s) {" % (ms['name']))
- #disp_def.append(' printf("%*s This is where we would call dynamic print function\\n", m_indent, "");')
- disp_def.append(' dynamic_display_full_txt(m_struct.%s, m_indent);' % (ms['name']))
- disp_def.append(" }")
- else:
- if ms['ptr']:
- disp_def.append(" if (m_struct.%s) {" % (ms['name']))
- disp_def.append(" %s %s(m_struct.%s);" % (self.get_class_name(ms['type']), swc_name, ms['name']))
- else:
- disp_def.append(" if (&m_struct.%s) {" % (ms['name']))
- disp_def.append(" %s %s(&m_struct.%s);" % (self.get_class_name(ms['type']), swc_name, ms['name']))
- disp_def.append(" %s.set_indent(m_indent + 4);" % (swc_name))
- disp_def.append(" %s.display_full_txt();\n }" % (swc_name))
- class_num += 1
- disp_def.append("}\n")
- return "\n".join(disp_def)
-
- def _generateStringHelperHeader(self):
- header = []
- header.append("//#includes, #defines, globals and such...\n")
- for f in self.include_headers:
- if 'vk_enum_string_helper' not in f:
- header.append("#include <%s>\n" % f)
- header.append('#include "vk_enum_string_helper.h"\n\n// Function Prototypes\n')
- header.append("char* dynamic_display(const void* pStruct, const char* prefix);\n")
- return "".join(header)
-
- def _generateStringHelperHeaderCpp(self):
- header = []
- header.append("//#includes, #defines, globals and such...\n")
- for f in self.include_headers:
- if 'vk_enum_string_helper' not in f:
- header.append("#include <%s>\n" % f)
- header.append('#include "vk_enum_string_helper.h"\n')
- header.append('namespace StreamControl\n')
- header.append('{\n')
- header.append('bool writeAddress = true;\n')
- header.append('template <typename T>\n')
- header.append('std::ostream& operator<< (std::ostream &out, T const* pointer)\n')
- header.append('{\n')
- header.append(' if(writeAddress)\n')
- header.append(' {\n')
- header.append(' out.operator<<(pointer);\n')
- header.append(' }\n')
- header.append(' else\n')
- header.append(' {\n')
- header.append(' std::operator<<(out, "address");\n')
- header.append(' }\n')
- header.append(' return out;\n')
- header.append('}\n')
- header.append('std::ostream& operator<<(std::ostream &out, char const*const s)\n')
- header.append('{\n')
- header.append(' return std::operator<<(out, s);\n')
- header.append('}\n')
- header.append('}\n')
- header.append('\n')
- header.append("std::string dynamic_display(const void* pStruct, const std::string prefix);\n")
- return "".join(header)
-
def _generateSizeHelperFunctions(self):
sh_funcs = []
# just generates prototypes for all the functions
@@ -1263,7 +589,6 @@ class StructWrapperGen:
return "\n".join(sh_funcs)
-
def _generateSizeHelperFunctionsC(self):
sh_funcs = []
# generate function definitions
@@ -1776,9 +1101,6 @@ def main(argv=None):
sw = StructWrapperGen(struct_dict, os.path.basename(opts.input_file).strip(".h"), os.path.dirname(enum_sh_filename), opts.quiet)
#print(sw.get_class_name(struct))
sw.set_include_headers([input_header,os.path.basename(enum_sh_filename),"stdint.h","cinttypes", "stdio.h","stdlib.h"])
- sw.generateStringHelper()
- sw.set_include_headers([input_header,os.path.basename(enum_sh_filename),"stdint.h","stdio.h","stdlib.h","iostream","sstream","string"])
- sw.generateStringHelperCpp()
sw.set_include_headers(["stdio.h", "stdlib.h", input_header])
sw.generateSizeHelper()
sw.generateSizeHelperC()