Exemple #1
0
 def parseJSON(self):
     """Parse JSON VUIDs into data struct"""
     # Format of JSON file is:
     # "API": { "core|EXT": [ {"vuid": "<id>", "text": "<VU txt>"}]},
     # "VK_KHX_external_memory" & "VK_KHX_device_group" - extension case (vs. "core")
     for top_level in sorted(self.json_data):
         if "validation" == top_level:
             for api in sorted(self.json_data[top_level]):
                 for ext in sorted(self.json_data[top_level][api]):
                     for vu_txt_dict in self.json_data[top_level][api][ext]:
                         print("Looking at dict for api:ext entry %s:%s" %
                               (api, ext))
                         vuid = vu_txt_dict['vuid']
                         vutxt = vu_txt_dict['text']
                         #print ("%s:%s:%s:%s" % (api, ext, vuid, vutxt))
                         #print ("VUTXT orig:%s" % (vutxt))
                         just_txt = BeautifulSoup(vutxt, 'html.parser')
                         #print ("VUTXT only:%s" % (just_txt.get_text()))
                         num_vuid = vuid_mapping.convertVUID(vuid)
                         self.json_db[vuid] = {}
                         self.json_db[vuid]['ext'] = ext
                         self.json_db[vuid]['number_vuid'] = num_vuid
                         self.json_db[vuid]['struct_func'] = api
                         just_txt = just_txt.get_text().strip()
                         unicode_map = {
                             u"\u2019": "'",
                             u"\u2192": "->",
                         }
                         for um in unicode_map:
                             just_txt = just_txt.replace(
                                 um, unicode_map[um])
                         self.json_db[vuid]['vu_txt'] = just_txt.replace(
                             "\\", "")
                         print("Spec vu txt:%s" %
                               (self.json_db[vuid]['vu_txt']))
 def genHeader(self, header_file):
     """Generate a header file based on the contents of a parsed spec"""
     print ("Generating header %s..." % (header_file))
     file_contents = []
     file_contents.append(self.copyright)
     file_contents.append('\n#pragma once')
     file_contents.append('\n// Disable auto-formatting for generated file')
     file_contents.append('// clang-format off')
     file_contents.append('\n#include <unordered_map>')
     file_contents.append('\n// enum values for unique validation error codes')
     file_contents.append('//  Corresponding validation error message for each enum is given in the mapping table below')
     file_contents.append('//  When a given error occurs, these enum values should be passed to the as the messageCode')
     file_contents.append('//  parameter to the PFN_vkDebugReportCallbackEXT function')
     enum_decl = ['enum UNIQUE_VALIDATION_ERROR_CODE {\n    VALIDATION_ERROR_UNDEFINED = -1,']
     error_string_map = ['static std::unordered_map<int, char const *const> validation_error_map{']
     enum_value = 0
     max_enum_val = 0
     for enum in sorted(self.error_db_dict):
         #print ("Header enum is %s" % (enum))
         # TMP: Use updated value
         vuid_str = self.error_db_dict[enum]['vuid_string']
         if vuid_str in self.json_db:
             enum_value = self.json_db[vuid_str]['number_vuid']
         else:
             enum_value = vuid_mapping.convertVUID(vuid_str)
         new_enum = "%s%s" % (validation_error_enum_name, get8digithex(enum_value))
         enum_decl.append('    %s = 0x%s,' % (new_enum, get8digithex(enum_value)))
         error_string_map.append('    {%s, "%s"},' % (new_enum, self.error_db_dict[enum]['error_msg']))
         max_enum_val = max(max_enum_val, enum_value)
     enum_decl.append('    %sMAX_ENUM = %d,' % (validation_error_enum_name, max_enum_val + 1))
     enum_decl.append('};')
     error_string_map.append('};\n')
     file_contents.extend(enum_decl)
     file_contents.append('\n// Mapping from unique validation error enum to the corresponding error message')
     file_contents.append('// The error message should be appended to the end of a custom error message that is passed')
     file_contents.append('// as the pMessage parameter to the PFN_vkDebugReportCallbackEXT function')
     file_contents.extend(error_string_map)
     #print ("File contents: %s" % (file_contents))
     with open(header_file, "w") as outfile:
         outfile.write("\n".join(file_contents))
Exemple #3
0
 def genHeader(self, header_file):
     """Generate a header file based on the contents of a parsed spec"""
     print ("Generating header %s..." % (header_file))
     file_contents = []
     file_contents.append(self.copyright)
     file_contents.append('\n#pragma once')
     file_contents.append('\n// Disable auto-formatting for generated file')
     file_contents.append('// clang-format off')
     file_contents.append('\n#include <unordered_map>')
     file_contents.append('\n// enum values for unique validation error codes')
     file_contents.append('//  Corresponding validation error message for each enum is given in the mapping table below')
     file_contents.append('//  When a given error occurs, these enum values should be passed to the as the messageCode')
     file_contents.append('//  parameter to the PFN_vkDebugReportCallbackEXT function')
     enum_decl = ['enum UNIQUE_VALIDATION_ERROR_CODE {\n    VALIDATION_ERROR_UNDEFINED = -1,']
     error_string_map = ['static std::unordered_map<int, char const *const> validation_error_map{']
     enum_value = 0
     max_enum_val = 0
     for enum in sorted(self.error_db_dict):
         #print ("Header enum is %s" % (enum))
         # TMP: Use updated value
         vuid_str = self.error_db_dict[enum]['vuid_string']
         if vuid_str in self.json_db:
             enum_value = self.json_db[vuid_str]['number_vuid']
         else:
             enum_value = vuid_mapping.convertVUID(vuid_str)
         new_enum = "%s%s" % (validation_error_enum_name, get8digithex(enum_value))
         enum_decl.append('    %s = 0x%s,' % (new_enum, get8digithex(enum_value)))
         error_string_map.append('    {%s, "%s"},' % (new_enum, self.error_db_dict[enum]['error_msg'].replace('"', '\\"')))
         max_enum_val = max(max_enum_val, enum_value)
     enum_decl.append('    %sMAX_ENUM = %d,' % (validation_error_enum_name, max_enum_val + 1))
     enum_decl.append('};')
     error_string_map.append('};\n')
     file_contents.extend(enum_decl)
     file_contents.append('\n// Mapping from unique validation error enum to the corresponding error message')
     file_contents.append('// The error message should be appended to the end of a custom error message that is passed')
     file_contents.append('// as the pMessage parameter to the PFN_vkDebugReportCallbackEXT function')
     file_contents.extend(error_string_map)
     #print ("File contents: %s" % (file_contents))
     with open(header_file, "w") as outfile:
         outfile.write("\n".join(file_contents))
 def parseJSON(self):
     """Parse JSON VUIDs into data struct"""
     # Format of JSON file is:
     # "API": { "core|EXT": [ {"vuid": "<id>", "text": "<VU txt>"}]},
     # "VK_KHX_external_memory" & "VK_KHX_device_group" - extension case (vs. "core")
     for top_level in sorted(self.json_data):
         if "validation" == top_level:
             for api in sorted(self.json_data[top_level]):
                 for ext in sorted(self.json_data[top_level][api]):
                     for vu_txt_dict in self.json_data[top_level][api][ext]:
                         print ("Looking at dict for api:ext entry %s:%s" % (api, ext))
                         vuid = vu_txt_dict['vuid']
                         vutxt = vu_txt_dict['text']
                         # strip asciidoc xref from vu text
                         vutxt = re.sub('&amp;amp;lt;&amp;amp;lt;([^&]*,\\s*|)(.*?)&amp;amp;gt;&amp;amp;gt;', '\\2', vutxt)
                         #print ("%s:%s:%s:%s" % (api, ext, vuid, vutxt))
                         #print ("VUTXT orig:%s" % (vutxt))
                         just_txt = BeautifulSoup(vutxt, 'html.parser')
                         #print ("VUTXT only:%s" % (just_txt.get_text()))
                         num_vuid = vuid_mapping.convertVUID(vuid)
                         self.json_db[vuid] = {}
                         self.json_db[vuid]['ext'] = ext
                         self.json_db[vuid]['number_vuid'] = num_vuid
                         self.json_db[vuid]['struct_func'] = api
                         just_txt = just_txt.get_text().strip()
                         unicode_map = {
                         u"\u2019" : "'",
                         u"\u201c" : "\"",
                         u"\u201d" : "\"",
                         u"\u2192" : "->",
                         }
                         for um in unicode_map:
                             just_txt = just_txt.replace(um, unicode_map[um])
                         self.json_db[vuid]['vu_txt'] = just_txt.replace("\\", "")
                         print ("Spec vu txt:%s" % (self.json_db[vuid]['vu_txt']))