diff options
author | Mark Lobodzinski <mark@lunarg.com> | 2016-12-28 14:45:34 -0700 |
---|---|---|
committer | Mark Lobodzinski <mark@lunarg.com> | 2017-01-10 10:21:32 -0700 |
commit | cb3549ee298fee77c36e274823b09ad23cdf6bc1 (patch) | |
tree | 81234de4c9f86bf76d5ddf32f78f8373154c3798 /scripts | |
parent | 953dceee232a62c4b99df5a732c9d8c7067b3941 (diff) |
scripts: Add generation of struct_size_helper header
Added generator-side plumbing to create the vk_struct_size_helper.h
file.
Change-Id: I5ff226131b8db2d773e4422877bdb2993ed76cf4
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/helper_file_generator.py | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/scripts/helper_file_generator.py b/scripts/helper_file_generator.py index 4e18bf39..59c96e08 100644 --- a/scripts/helper_file_generator.py +++ b/scripts/helper_file_generator.py @@ -75,10 +75,10 @@ class HelperFileOutputGenerator(OutputGenerator): diagFile = sys.stdout): OutputGenerator.__init__(self, errFile, warnFile, diagFile) # Internal state - accumulators for different inner block text - self.enum_output = '' # string built up of enum string routines - self.enum_list = () + self.enum_output = '' # string built up of enum string routines + self.struct_size_h_output = '' # string built up of struct size header output + self.struct_size_c_output = '' # string built up of struct size source output # Internal state - accumulators for different inner block text - ########## self.sections = dict([(section, []) for section in self.ALL_SECTIONS]) self.structNames = [] # List of Vulkan struct typenames self.structTypes = dict() # Map of Vulkan struct typename to required VkStructureType self.handleTypes = set() # Set of handle type names @@ -89,7 +89,7 @@ class HelperFileOutputGenerator(OutputGenerator): self.StructType = namedtuple('StructType', ['name', 'value']) self.CommandParam = namedtuple('CommandParam', ['type', 'name', 'ispointer', 'isconst', 'iscount', 'len', 'extstructs', 'cdecl', 'islocal', 'iscreate', 'isdestroy']) self.CommandData = namedtuple('CommandData', ['name', 'return_type', 'params', 'cdecl']) - self.StructMemberData = namedtuple('StructMemberData', ['name', 'members']) + self.StructMemberData = namedtuple('StructMemberData', ['name', 'members', 'ifdef_protect']) # # Called once at the beginning of each run def beginFile(self, genOpts): @@ -249,7 +249,7 @@ class HelperFileOutputGenerator(OutputGenerator): islocal=False, iscreate=False, isdestroy=False)) - self.structMembers.append(self.StructMemberData(name=typeName, members=membersInfo)) + self.structMembers.append(self.StructMemberData(name=typeName, members=membersInfo, ifdef_protect=self.featureExtraProtect)) # # Enum_string_header: Create a routine to convert an enumerated value into a string def GenerateEnumStringConversion(self, groupName, value_list): @@ -258,7 +258,6 @@ class HelperFileOutputGenerator(OutputGenerator): outstring += '{\n' outstring += ' switch ((%s)input_value)\n' % groupName outstring += ' {\n' - for item in value_list: outstring += ' case %s:\n' % item outstring += ' return "%s";\n' % item @@ -268,6 +267,22 @@ class HelperFileOutputGenerator(OutputGenerator): outstring += '}\n' return outstring # + # struct_size_header: build function prototypes for header file + def GenerateStructSizeHeader(self): + outstring = '' + outstring += 'size_t get_struct_chain_size(const void* struct_ptr);\n' + for item in self.structMembers: + lower_case_name = item.name.lower() + if item.ifdef_protect != None: + outstring += '#ifdef %s\n' % item.ifdef_protect + outstring += 'size_t vk_size_%s(const %s* struct_ptr);\n' % (item.name.lower(), item.name) + if item.ifdef_protect != None: + outstring += '#endif // %s\n' % item.ifdef_protect + outstring += '#ifdef __cplusplus\n' + outstring += '}\n' + outstring += '#endif' + return outstring + # # Create a helper file and return it as a string def OutputDestFile(self): out_file_entries = '' @@ -283,10 +298,16 @@ class HelperFileOutputGenerator(OutputGenerator): out_file_entries += self.enum_output elif self.helper_file_type == 'struct_size_header': out_file_entries = '\n' - out_file_entries += 'Helper File header code\n' + out_file_entries += '#ifdef __cplusplus\n' + out_file_entries += 'extern "C" {\n' + out_file_entries += '#endif\n' out_file_entries += '\n' - out_file_entries += 'helper file.h \n' + out_file_entries += '#include <stdio.h>\n' + out_file_entries += '#include <stdlib.h>\n' + out_file_entries += '#include <vulkan/vulkan.h>\n' out_file_entries += '\n' + out_file_entries += '// Function Prototypes\n' + out_file_entries += self.GenerateStructSizeHeader() elif self.helper_file_type == 'struct_size_source': out_file_entries = '\n' out_file_entries += 'Helper File source code\n' |