#!/usr/bin/python3 -i # # Copyright (c) 2015-2016 The Khronos Group Inc. # Copyright (c) 2015-2016 Valve Corporation # Copyright (c) 2015-2016 LunarG, Inc. # Copyright (c) 2015-2016 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Author: Mark Lobodzinski import os,re,sys import xml.etree.ElementTree as etree from generator import * from collections import namedtuple # # HelperFileOutputGeneratorOptions - subclass of GeneratorOptions. class HelperFileOutputGeneratorOptions(GeneratorOptions): def __init__(self, filename = None, directory = '.', apiname = None, profile = None, versions = '.*', emitversions = '.*', defaultExtensions = None, addExtensions = None, removeExtensions = None, sortProcedure = regSortFeatures, prefixText = "", genFuncPointers = True, protectFile = True, protectFeature = True, protectProto = None, protectProtoStr = None, apicall = '', apientry = '', apientryp = '', alignFuncParam = 0, library_name = '', helper_file_type = ''): GeneratorOptions.__init__(self, filename, directory, apiname, profile, versions, emitversions, defaultExtensions, addExtensions, removeExtensions, sortProcedure) self.prefixText = prefixText self.genFuncPointers = genFuncPointers self.prefixText = None self.protectFile = protectFile self.protectFeature = protectFeature self.protectProto = protectProto self.protectProtoStr = protectProtoStr self.apicall = apicall self.apientry = apientry self.apientryp = apientryp self.alignFuncParam = alignFuncParam self.library_name = library_name self.helper_file_type = helper_file_type # # HelperFileOutputGenerator - subclass of OutputGenerator. # Outputs Vulkan helper files class HelperFileOutputGenerator(OutputGenerator): """Generate Windows def file based on XML element attributes""" def __init__(self, errFile = sys.stderr, warnFile = sys.stderr, 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 = () # # Called once at the beginning of each run def beginFile(self, genOpts): OutputGenerator.beginFile(self, genOpts) # User-supplied prefix text, if any (list of strings) if (genOpts.prefixText): for s in genOpts.prefixText: write(s, file=self.outFile) self.helper_file_type = genOpts.helper_file_type self.library_name = genOpts.library_name # File Comment file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n' file_comment += '// See helper_file_generator.py for modifications\n' write(file_comment, file=self.outFile) # Copyright Notice copyright = '' copyright += '\n' copyright += '/***************************************************************************\n' copyright += ' *\n' copyright += ' * Copyright (c) 2015-2016 The Khronos Group Inc.\n' copyright += ' * Copyright (c) 2015-2016 Valve Corporation\n' copyright += ' * Copyright (c) 2015-2016 LunarG, Inc.\n' copyright += ' * Copyright (c) 2015-2016 Google Inc.\n' copyright += ' *\n' copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n' copyright += ' * you may not use this file except in compliance with the License.\n' copyright += ' * You may obtain a copy of the License at\n' copyright += ' *\n' copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n' copyright += ' *\n' copyright += ' * Unless required by applicable law or agreed to in writing, software\n' copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n' copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' copyright += ' * See the License for the specific language governing permissions and\n' copyright += ' * limitations under the License.\n' copyright += ' *\n' copyright += ' * Author: Mark Lobodzinski \n' copyright += ' * Author: Courtney Goeltzenleuchter \n' copyright += ' * Author: Tobin Ehlis \n' copyright += ' *\n' copyright += ' ****************************************************************************/\n' write(copyright, file=self.outFile) # # Write generate and write def file content to output file def endFile(self): dest_file = '' dest_file += self.OutputDestFile() write(dest_file, file=self.outFile); # Finish processing in superclass OutputGenerator.endFile(self) # # Grab group (e.g. C "enum" type) info to output for enum-string conversion helper def genGroup(self, groupinfo, groupName): OutputGenerator.genGroup(self, groupinfo, groupName) groupElem = groupinfo.elem value_list = [] for elem in groupElem.findall('enum'): if elem.get('supported') != 'disabled': item_name = elem.get('name') value_list.append(item_name) if value_list is not None: self.enum_output += self.GenerateEnumStringConversion(groupName, value_list) # # Create a routine to convert an enumerated value into a string def GenerateEnumStringConversion(self, groupName, value_list): outstring = '\n' outstring += 'static inline const char* string_%s(%s input_value)\n' % (groupName, groupName) 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 outstring += ' default:\n' outstring += ' return "Unhandled %s";\n' % groupName outstring += ' }\n' outstring += '}\n' return outstring # # Create a helper file and return it as a string def OutputDestFile(self): out_file_entries = '\n' out_file_entries += '#pragma once\n' out_file_entries += '#ifdef _WIN32\n' out_file_entries += '#pragma warning( disable : 4065 )\n' out_file_entries += '#endif\n' out_file_entries += '\n' out_file_entries += '#include \n' out_file_entries += '\n' out_file_entries += self.enum_output return out_file_entries