15db71995Sopenharmony_ci#!/usr/bin/python3
25db71995Sopenharmony_ci#
35db71995Sopenharmony_ci# Copyright (c) 2013-2019 The Khronos Group Inc.
45db71995Sopenharmony_ci# Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
55db71995Sopenharmony_ci# Copyright (c) 2023-2023 RasterGrid Kft.
65db71995Sopenharmony_ci#
75db71995Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
85db71995Sopenharmony_ci# you may not use this file except in compliance with the License.
95db71995Sopenharmony_ci# You may obtain a copy of the License at
105db71995Sopenharmony_ci#
115db71995Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
125db71995Sopenharmony_ci#
135db71995Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
145db71995Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
155db71995Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
165db71995Sopenharmony_ci# See the License for the specific language governing permissions and
175db71995Sopenharmony_ci# limitations under the License.
185db71995Sopenharmony_ci
195db71995Sopenharmony_ciimport argparse, cProfile, pdb, string, sys, time, os
205db71995Sopenharmony_ci
215db71995Sopenharmony_ci# Simple timer functions
225db71995Sopenharmony_cistartTime = None
235db71995Sopenharmony_ci
245db71995Sopenharmony_cidef startTimer(timeit):
255db71995Sopenharmony_ci    global startTime
265db71995Sopenharmony_ci    if timeit:
275db71995Sopenharmony_ci        startTime = time.process_time()
285db71995Sopenharmony_ci
295db71995Sopenharmony_cidef endTimer(timeit, msg):
305db71995Sopenharmony_ci    global startTime
315db71995Sopenharmony_ci    if timeit:
325db71995Sopenharmony_ci        endTime = time.process_time()
335db71995Sopenharmony_ci        write(msg, endTime - startTime, file=sys.stderr)
345db71995Sopenharmony_ci        startTime = None
355db71995Sopenharmony_ci
365db71995Sopenharmony_ci# Turn a list of strings into a regexp string matching exactly those strings
375db71995Sopenharmony_cidef makeREstring(list, default = None):
385db71995Sopenharmony_ci    if len(list) > 0 or default is None:
395db71995Sopenharmony_ci        return '^(' + '|'.join(list) + ')$'
405db71995Sopenharmony_ci    else:
415db71995Sopenharmony_ci        return default
425db71995Sopenharmony_ci
435db71995Sopenharmony_ci# Returns a directory of [ generator function, generator options ] indexed
445db71995Sopenharmony_ci# by specified short names. The generator options incorporate the following
455db71995Sopenharmony_ci# parameters:
465db71995Sopenharmony_ci#
475db71995Sopenharmony_ci# args is an parsed argument object; see below for the fields that are used.
485db71995Sopenharmony_cidef makeGenOpts(args):
495db71995Sopenharmony_ci    global genOpts
505db71995Sopenharmony_ci    genOpts = {}
515db71995Sopenharmony_ci
525db71995Sopenharmony_ci    # API to generate sources for
535db71995Sopenharmony_ci    apiname = args.api
545db71995Sopenharmony_ci
555db71995Sopenharmony_ci    # Default class of extensions to include, or None
565db71995Sopenharmony_ci    if args.defaultExtensions is not None:
575db71995Sopenharmony_ci        defaultExtensions = args.defaultExtensions
585db71995Sopenharmony_ci    else:
595db71995Sopenharmony_ci        defaultExtensions = apiname
605db71995Sopenharmony_ci
615db71995Sopenharmony_ci    # Additional extensions to include (list of extensions)
625db71995Sopenharmony_ci    extensions = args.extension
635db71995Sopenharmony_ci
645db71995Sopenharmony_ci    # Extensions to remove (list of extensions)
655db71995Sopenharmony_ci    removeExtensions = args.removeExtensions
665db71995Sopenharmony_ci
675db71995Sopenharmony_ci    # Extensions to emit (list of extensions)
685db71995Sopenharmony_ci    emitExtensions = args.emitExtensions
695db71995Sopenharmony_ci
705db71995Sopenharmony_ci    # Features to include (list of features)
715db71995Sopenharmony_ci    features = args.feature
725db71995Sopenharmony_ci
735db71995Sopenharmony_ci    # Whether to disable inclusion protect in headers
745db71995Sopenharmony_ci    protect = args.protect
755db71995Sopenharmony_ci
765db71995Sopenharmony_ci    # Output target directory
775db71995Sopenharmony_ci    directory = args.directory
785db71995Sopenharmony_ci
795db71995Sopenharmony_ci    # Path to generated files, particularly api.py
805db71995Sopenharmony_ci    genpath = args.genpath
815db71995Sopenharmony_ci
825db71995Sopenharmony_ci    # Descriptive names for various regexp patterns used to select
835db71995Sopenharmony_ci    # versions and extensions
845db71995Sopenharmony_ci    allFeatures     = allExtensions = '.*'
855db71995Sopenharmony_ci    noFeatures      = noExtensions = None
865db71995Sopenharmony_ci
875db71995Sopenharmony_ci    # Turn lists of names/patterns into matching regular expressions
885db71995Sopenharmony_ci    addExtensionsPat     = makeREstring(extensions, None)
895db71995Sopenharmony_ci    removeExtensionsPat  = makeREstring(removeExtensions, None)
905db71995Sopenharmony_ci    emitExtensionsPat    = makeREstring(emitExtensions, allExtensions)
915db71995Sopenharmony_ci    featuresPat          = makeREstring(features, allFeatures)
925db71995Sopenharmony_ci
935db71995Sopenharmony_ci    # Copyright text prefixing all headers (list of strings).
945db71995Sopenharmony_ci    prefixStrings = [
955db71995Sopenharmony_ci        '/*',
965db71995Sopenharmony_ci        '** Copyright (c) 2015-2019 The Khronos Group Inc.',
975db71995Sopenharmony_ci        '**',
985db71995Sopenharmony_ci        '** Licensed under the Apache License, Version 2.0 (the "License");',
995db71995Sopenharmony_ci        '** you may not use this file except in compliance with the License.',
1005db71995Sopenharmony_ci        '** You may obtain a copy of the License at',
1015db71995Sopenharmony_ci        '**',
1025db71995Sopenharmony_ci        '**     http://www.apache.org/licenses/LICENSE-2.0',
1035db71995Sopenharmony_ci        '**',
1045db71995Sopenharmony_ci        '** Unless required by applicable law or agreed to in writing, software',
1055db71995Sopenharmony_ci        '** distributed under the License is distributed on an "AS IS" BASIS,',
1065db71995Sopenharmony_ci        '** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
1075db71995Sopenharmony_ci        '** See the License for the specific language governing permissions and',
1085db71995Sopenharmony_ci        '** limitations under the License.',
1095db71995Sopenharmony_ci        '*/',
1105db71995Sopenharmony_ci        ''
1115db71995Sopenharmony_ci    ]
1125db71995Sopenharmony_ci
1135db71995Sopenharmony_ci    # Text specific to Vulkan headers
1145db71995Sopenharmony_ci    vkPrefixStrings = [
1155db71995Sopenharmony_ci        '/*',
1165db71995Sopenharmony_ci        '** This header is generated from the Khronos Vulkan XML API Registry.',
1175db71995Sopenharmony_ci        '**',
1185db71995Sopenharmony_ci        '*/',
1195db71995Sopenharmony_ci        ''
1205db71995Sopenharmony_ci    ]
1215db71995Sopenharmony_ci
1225db71995Sopenharmony_ci    # Defaults for generating re-inclusion protection wrappers (or not)
1235db71995Sopenharmony_ci    protectFeature = protect
1245db71995Sopenharmony_ci
1255db71995Sopenharmony_ci    # An API style conventions object
1265db71995Sopenharmony_ci    conventions = VulkanConventions()
1275db71995Sopenharmony_ci
1285db71995Sopenharmony_ci    # Loader Generators
1295db71995Sopenharmony_ci    # Options for dispatch table helper generator
1305db71995Sopenharmony_ci    genOpts['vk_dispatch_table_helper.h'] = [
1315db71995Sopenharmony_ci          DispatchTableHelperOutputGenerator,
1325db71995Sopenharmony_ci          DispatchTableHelperOutputGeneratorOptions(
1335db71995Sopenharmony_ci            conventions       = conventions,
1345db71995Sopenharmony_ci            filename          = 'vk_dispatch_table_helper.h',
1355db71995Sopenharmony_ci            directory         = directory,
1365db71995Sopenharmony_ci            genpath           = None,
1375db71995Sopenharmony_ci            apiname           = apiname,
1385db71995Sopenharmony_ci            profile           = None,
1395db71995Sopenharmony_ci            versions          = featuresPat,
1405db71995Sopenharmony_ci            emitversions      = featuresPat,
1415db71995Sopenharmony_ci            defaultExtensions = defaultExtensions,
1425db71995Sopenharmony_ci            addExtensions     = addExtensionsPat,
1435db71995Sopenharmony_ci            removeExtensions  = removeExtensionsPat,
1445db71995Sopenharmony_ci            emitExtensions    = emitExtensionsPat,
1455db71995Sopenharmony_ci            prefixText        = prefixStrings + vkPrefixStrings,
1465db71995Sopenharmony_ci            apicall           = 'VKAPI_ATTR ',
1475db71995Sopenharmony_ci            apientry          = 'VKAPI_CALL ',
1485db71995Sopenharmony_ci            apientryp         = 'VKAPI_PTR *',
1495db71995Sopenharmony_ci            alignFuncParam    = 48,
1505db71995Sopenharmony_ci            expandEnumerants = False)
1515db71995Sopenharmony_ci        ]
1525db71995Sopenharmony_ci
1535db71995Sopenharmony_ci    # Options for Layer dispatch table generator
1545db71995Sopenharmony_ci    genOpts['vk_layer_dispatch_table.h'] = [
1555db71995Sopenharmony_ci          LoaderExtensionOutputGenerator,
1565db71995Sopenharmony_ci          LoaderExtensionGeneratorOptions(
1575db71995Sopenharmony_ci            conventions       = conventions,
1585db71995Sopenharmony_ci            filename          = 'vk_layer_dispatch_table.h',
1595db71995Sopenharmony_ci            directory         = directory,
1605db71995Sopenharmony_ci            genpath           = None,
1615db71995Sopenharmony_ci            apiname           = apiname,
1625db71995Sopenharmony_ci            profile           = None,
1635db71995Sopenharmony_ci            versions          = featuresPat,
1645db71995Sopenharmony_ci            emitversions      = featuresPat,
1655db71995Sopenharmony_ci            defaultExtensions = defaultExtensions,
1665db71995Sopenharmony_ci            addExtensions     = addExtensionsPat,
1675db71995Sopenharmony_ci            removeExtensions  = removeExtensionsPat,
1685db71995Sopenharmony_ci            emitExtensions    = emitExtensionsPat,
1695db71995Sopenharmony_ci            prefixText        = prefixStrings + vkPrefixStrings,
1705db71995Sopenharmony_ci            apicall           = 'VKAPI_ATTR ',
1715db71995Sopenharmony_ci            apientry          = 'VKAPI_CALL ',
1725db71995Sopenharmony_ci            apientryp         = 'VKAPI_PTR *',
1735db71995Sopenharmony_ci            alignFuncParam    = 48,
1745db71995Sopenharmony_ci            expandEnumerants = False)
1755db71995Sopenharmony_ci        ]
1765db71995Sopenharmony_ci
1775db71995Sopenharmony_ci    # Options for loader extension source generator
1785db71995Sopenharmony_ci    genOpts['vk_loader_extensions.h'] = [
1795db71995Sopenharmony_ci          LoaderExtensionOutputGenerator,
1805db71995Sopenharmony_ci          LoaderExtensionGeneratorOptions(
1815db71995Sopenharmony_ci            conventions       = conventions,
1825db71995Sopenharmony_ci            filename          = 'vk_loader_extensions.h',
1835db71995Sopenharmony_ci            directory         = directory,
1845db71995Sopenharmony_ci            genpath           = None,
1855db71995Sopenharmony_ci            apiname           = apiname,
1865db71995Sopenharmony_ci            profile           = None,
1875db71995Sopenharmony_ci            versions          = featuresPat,
1885db71995Sopenharmony_ci            emitversions      = featuresPat,
1895db71995Sopenharmony_ci            defaultExtensions = defaultExtensions,
1905db71995Sopenharmony_ci            addExtensions     = addExtensionsPat,
1915db71995Sopenharmony_ci            removeExtensions  = removeExtensionsPat,
1925db71995Sopenharmony_ci            emitExtensions    = emitExtensionsPat,
1935db71995Sopenharmony_ci            prefixText        = prefixStrings + vkPrefixStrings,
1945db71995Sopenharmony_ci            apicall           = 'VKAPI_ATTR ',
1955db71995Sopenharmony_ci            apientry          = 'VKAPI_CALL ',
1965db71995Sopenharmony_ci            apientryp         = 'VKAPI_PTR *',
1975db71995Sopenharmony_ci            alignFuncParam    = 48,
1985db71995Sopenharmony_ci            expandEnumerants = False)
1995db71995Sopenharmony_ci        ]
2005db71995Sopenharmony_ci
2015db71995Sopenharmony_ci    # Options for loader extension source generator
2025db71995Sopenharmony_ci    genOpts['vk_loader_extensions.c'] = [
2035db71995Sopenharmony_ci          LoaderExtensionOutputGenerator,
2045db71995Sopenharmony_ci          LoaderExtensionGeneratorOptions(
2055db71995Sopenharmony_ci            conventions       = conventions,
2065db71995Sopenharmony_ci            filename          = 'vk_loader_extensions.c',
2075db71995Sopenharmony_ci            directory         = directory,
2085db71995Sopenharmony_ci            genpath           = None,
2095db71995Sopenharmony_ci            apiname           = apiname,
2105db71995Sopenharmony_ci            profile           = None,
2115db71995Sopenharmony_ci            versions          = featuresPat,
2125db71995Sopenharmony_ci            emitversions      = featuresPat,
2135db71995Sopenharmony_ci            defaultExtensions = defaultExtensions,
2145db71995Sopenharmony_ci            addExtensions     = addExtensionsPat,
2155db71995Sopenharmony_ci            removeExtensions  = removeExtensionsPat,
2165db71995Sopenharmony_ci            emitExtensions    = emitExtensionsPat,
2175db71995Sopenharmony_ci            prefixText        = prefixStrings + vkPrefixStrings,
2185db71995Sopenharmony_ci            apicall           = 'VKAPI_ATTR ',
2195db71995Sopenharmony_ci            apientry          = 'VKAPI_CALL ',
2205db71995Sopenharmony_ci            apientryp         = 'VKAPI_PTR *',
2215db71995Sopenharmony_ci            alignFuncParam    = 48,
2225db71995Sopenharmony_ci            expandEnumerants = False)
2235db71995Sopenharmony_ci        ]
2245db71995Sopenharmony_ci
2255db71995Sopenharmony_ci    # Helper file generator options for vk_object_types.h
2265db71995Sopenharmony_ci    genOpts['vk_object_types.h'] = [
2275db71995Sopenharmony_ci          HelperFileOutputGenerator,
2285db71995Sopenharmony_ci          HelperFileOutputGeneratorOptions(
2295db71995Sopenharmony_ci            conventions       = conventions,
2305db71995Sopenharmony_ci            filename          = 'vk_object_types.h',
2315db71995Sopenharmony_ci            directory         = directory,
2325db71995Sopenharmony_ci            genpath           = None,
2335db71995Sopenharmony_ci            apiname           = apiname,
2345db71995Sopenharmony_ci            profile           = None,
2355db71995Sopenharmony_ci            versions          = featuresPat,
2365db71995Sopenharmony_ci            emitversions      = featuresPat,
2375db71995Sopenharmony_ci            defaultExtensions = defaultExtensions,
2385db71995Sopenharmony_ci            addExtensions     = addExtensionsPat,
2395db71995Sopenharmony_ci            removeExtensions  = removeExtensionsPat,
2405db71995Sopenharmony_ci            emitExtensions    = emitExtensionsPat,
2415db71995Sopenharmony_ci            prefixText        = prefixStrings + vkPrefixStrings,
2425db71995Sopenharmony_ci            apicall           = 'VKAPI_ATTR ',
2435db71995Sopenharmony_ci            apientry          = 'VKAPI_CALL ',
2445db71995Sopenharmony_ci            apientryp         = 'VKAPI_PTR *',
2455db71995Sopenharmony_ci            alignFuncParam    = 48,
2465db71995Sopenharmony_ci            expandEnumerants  = False,
2475db71995Sopenharmony_ci            helper_file_type  = 'object_types_header')
2485db71995Sopenharmony_ci        ]
2495db71995Sopenharmony_ci
2505db71995Sopenharmony_ci# Create an API generator and corresponding generator options based on
2515db71995Sopenharmony_ci# the requested target and command line options.
2525db71995Sopenharmony_ci# This is encapsulated in a function so it can be profiled and/or timed.
2535db71995Sopenharmony_ci# The args parameter is an parsed argument object containing the following
2545db71995Sopenharmony_ci# fields that are used:
2555db71995Sopenharmony_ci#   target - target to generate
2565db71995Sopenharmony_ci#   directory - directory to generate it in
2575db71995Sopenharmony_ci#   protect - True if re-inclusion wrappers should be created
2585db71995Sopenharmony_ci#   extensions - list of additional extensions to include in generated
2595db71995Sopenharmony_ci#   interfaces
2605db71995Sopenharmony_cidef genTarget(args):
2615db71995Sopenharmony_ci    global genOpts
2625db71995Sopenharmony_ci
2635db71995Sopenharmony_ci    # Create generator options with parameters specified on command line
2645db71995Sopenharmony_ci    makeGenOpts(args)
2655db71995Sopenharmony_ci
2665db71995Sopenharmony_ci    # Select a generator matching the requested target
2675db71995Sopenharmony_ci    if (args.target in genOpts.keys()):
2685db71995Sopenharmony_ci        createGenerator = genOpts[args.target][0]
2695db71995Sopenharmony_ci        options = genOpts[args.target][1]
2705db71995Sopenharmony_ci
2715db71995Sopenharmony_ci        if not args.quiet:
2725db71995Sopenharmony_ci            write('* Building', options.filename, file=sys.stderr)
2735db71995Sopenharmony_ci            write('* options.apiname           =', options.apiname, file=sys.stderr)
2745db71995Sopenharmony_ci            write('* options.versions          =', options.versions, file=sys.stderr)
2755db71995Sopenharmony_ci            write('* options.emitversions      =', options.emitversions, file=sys.stderr)
2765db71995Sopenharmony_ci            write('* options.defaultExtensions =', options.defaultExtensions, file=sys.stderr)
2775db71995Sopenharmony_ci            write('* options.addExtensions     =', options.addExtensions, file=sys.stderr)
2785db71995Sopenharmony_ci            write('* options.removeExtensions  =', options.removeExtensions, file=sys.stderr)
2795db71995Sopenharmony_ci            write('* options.emitExtensions    =', options.emitExtensions, file=sys.stderr)
2805db71995Sopenharmony_ci
2815db71995Sopenharmony_ci        gen = createGenerator(errFile=errWarn,
2825db71995Sopenharmony_ci                              warnFile=errWarn,
2835db71995Sopenharmony_ci                              diagFile=diag)
2845db71995Sopenharmony_ci        if not args.quiet:
2855db71995Sopenharmony_ci            write('* Generated', options.filename, file=sys.stderr)
2865db71995Sopenharmony_ci        return (gen, options)
2875db71995Sopenharmony_ci    else:
2885db71995Sopenharmony_ci        write('No generator options for unknown target:', args.target, file=sys.stderr)
2895db71995Sopenharmony_ci        return none
2905db71995Sopenharmony_ci
2915db71995Sopenharmony_ci# -feature name
2925db71995Sopenharmony_ci# -extension name
2935db71995Sopenharmony_ci# For both, "name" may be a single name, or a space-separated list
2945db71995Sopenharmony_ci# of names, or a regular expression.
2955db71995Sopenharmony_ciif __name__ == '__main__':
2965db71995Sopenharmony_ci    parser = argparse.ArgumentParser()
2975db71995Sopenharmony_ci
2985db71995Sopenharmony_ci    parser.add_argument('-api', action='store',
2995db71995Sopenharmony_ci                        default='vulkan',
3005db71995Sopenharmony_ci                        choices=['vulkan'],
3015db71995Sopenharmony_ci                        help='Specify API name to generate')
3025db71995Sopenharmony_ci    parser.add_argument('-defaultExtensions', action='store',
3035db71995Sopenharmony_ci                        default=None,
3045db71995Sopenharmony_ci                        help='Specify a single class of extensions to add to targets')
3055db71995Sopenharmony_ci    parser.add_argument('-extension', action='append',
3065db71995Sopenharmony_ci                        default=[],
3075db71995Sopenharmony_ci                        help='Specify an extension or extensions to add to targets')
3085db71995Sopenharmony_ci    parser.add_argument('-removeExtensions', action='append',
3095db71995Sopenharmony_ci                        default=[],
3105db71995Sopenharmony_ci                        help='Specify an extension or extensions to remove from targets')
3115db71995Sopenharmony_ci    parser.add_argument('-emitExtensions', action='append',
3125db71995Sopenharmony_ci                        default=[],
3135db71995Sopenharmony_ci                        help='Specify an extension or extensions to emit in targets')
3145db71995Sopenharmony_ci    parser.add_argument('-feature', action='append',
3155db71995Sopenharmony_ci                        default=[],
3165db71995Sopenharmony_ci                        help='Specify a core API feature name or names to add to targets')
3175db71995Sopenharmony_ci    parser.add_argument('-debug', action='store_true',
3185db71995Sopenharmony_ci                        help='Enable debugging')
3195db71995Sopenharmony_ci    parser.add_argument('-dump', action='store_true',
3205db71995Sopenharmony_ci                        help='Enable dump to stderr')
3215db71995Sopenharmony_ci    parser.add_argument('-diagfile', action='store',
3225db71995Sopenharmony_ci                        default=None,
3235db71995Sopenharmony_ci                        help='Write diagnostics to specified file')
3245db71995Sopenharmony_ci    parser.add_argument('-errfile', action='store',
3255db71995Sopenharmony_ci                        default=None,
3265db71995Sopenharmony_ci                        help='Write errors and warnings to specified file instead of stderr')
3275db71995Sopenharmony_ci    parser.add_argument('-noprotect', dest='protect', action='store_false',
3285db71995Sopenharmony_ci                        help='Disable inclusion protection in output headers')
3295db71995Sopenharmony_ci    parser.add_argument('-profile', action='store_true',
3305db71995Sopenharmony_ci                        help='Enable profiling')
3315db71995Sopenharmony_ci    parser.add_argument('-registry', action='store',
3325db71995Sopenharmony_ci                        default='vk.xml',
3335db71995Sopenharmony_ci                        help='Use specified registry file instead of vk.xml')
3345db71995Sopenharmony_ci    parser.add_argument('-time', action='store_true',
3355db71995Sopenharmony_ci                        help='Enable timing')
3365db71995Sopenharmony_ci    parser.add_argument('-validate', action='store_true',
3375db71995Sopenharmony_ci                        help='Enable XML group validation')
3385db71995Sopenharmony_ci    parser.add_argument('-genpath', action='store', default='gen',
3395db71995Sopenharmony_ci                        help='Path to generated files')
3405db71995Sopenharmony_ci    parser.add_argument('-o', action='store', dest='directory',
3415db71995Sopenharmony_ci                        default='.',
3425db71995Sopenharmony_ci                        help='Create target and related files in specified directory')
3435db71995Sopenharmony_ci    parser.add_argument('target', metavar='target', nargs='?',
3445db71995Sopenharmony_ci                        help='Specify target')
3455db71995Sopenharmony_ci    parser.add_argument('-quiet', action='store_true', default=True,
3465db71995Sopenharmony_ci                        help='Suppress script output during normal execution.')
3475db71995Sopenharmony_ci    parser.add_argument('-verbose', action='store_false', dest='quiet', default=True,
3485db71995Sopenharmony_ci                        help='Enable script output during normal execution.')
3495db71995Sopenharmony_ci
3505db71995Sopenharmony_ci    # This argument tells us where to load the script from the Vulkan-Headers registry
3515db71995Sopenharmony_ci    parser.add_argument('-scripts', action='store',
3525db71995Sopenharmony_ci                        help='Find additional scripts in this directory')
3535db71995Sopenharmony_ci
3545db71995Sopenharmony_ci    args = parser.parse_args()
3555db71995Sopenharmony_ci
3565db71995Sopenharmony_ci    # default scripts path to be same as registry
3575db71995Sopenharmony_ci    if not args.scripts:
3585db71995Sopenharmony_ci        args.scripts = os.path.dirname(args.registry)
3595db71995Sopenharmony_ci        print(args.scripts)
3605db71995Sopenharmony_ci
3615db71995Sopenharmony_ci    scripts_dir = os.path.dirname(os.path.abspath(__file__))
3625db71995Sopenharmony_ci    registry_dir = os.path.join(scripts_dir, args.scripts)
3635db71995Sopenharmony_ci    sys.path.insert(0, registry_dir)
3645db71995Sopenharmony_ci
3655db71995Sopenharmony_ci    # The imports need to be done here so that they can be picked up from Vulkan-Headers
3665db71995Sopenharmony_ci    from reg import *
3675db71995Sopenharmony_ci    from generator import write
3685db71995Sopenharmony_ci    from cgenerator import CGeneratorOptions, COutputGenerator
3695db71995Sopenharmony_ci
3705db71995Sopenharmony_ci    from dispatch_table_helper_generator import DispatchTableHelperOutputGenerator, DispatchTableHelperOutputGeneratorOptions
3715db71995Sopenharmony_ci    from helper_file_generator import HelperFileOutputGenerator, HelperFileOutputGeneratorOptions
3725db71995Sopenharmony_ci    from loader_extension_generator import LoaderExtensionOutputGenerator, LoaderExtensionGeneratorOptions
3735db71995Sopenharmony_ci
3745db71995Sopenharmony_ci    # Temporary workaround for vkconventions python2 compatibility
3755db71995Sopenharmony_ci    import abc; abc.ABC = abc.ABCMeta('ABC', (object,), {})
3765db71995Sopenharmony_ci    from vkconventions import VulkanConventions
3775db71995Sopenharmony_ci
3785db71995Sopenharmony_ci    # This splits arguments which are space-separated lists
3795db71995Sopenharmony_ci    args.feature = [name for arg in args.feature for name in arg.split()]
3805db71995Sopenharmony_ci    args.extension = [name for arg in args.extension for name in arg.split()]
3815db71995Sopenharmony_ci
3825db71995Sopenharmony_ci    # create error/warning & diagnostic files
3835db71995Sopenharmony_ci    if args.errfile:
3845db71995Sopenharmony_ci        errWarn = open(args.errfile, 'w', encoding='utf-8')
3855db71995Sopenharmony_ci    else:
3865db71995Sopenharmony_ci        errWarn = sys.stderr
3875db71995Sopenharmony_ci
3885db71995Sopenharmony_ci    if args.diagfile:
3895db71995Sopenharmony_ci        diag = open(args.diagfile, 'w', encoding='utf-8')
3905db71995Sopenharmony_ci    else:
3915db71995Sopenharmony_ci        diag = None
3925db71995Sopenharmony_ci
3935db71995Sopenharmony_ci    # Create the API generator & generator options
3945db71995Sopenharmony_ci    (gen, options) = genTarget(args)
3955db71995Sopenharmony_ci
3965db71995Sopenharmony_ci    # Create the registry object with the specified generator and generator
3975db71995Sopenharmony_ci    # options. The options are set before XML loading as they may affect it.
3985db71995Sopenharmony_ci    reg = Registry(gen, options)
3995db71995Sopenharmony_ci
4005db71995Sopenharmony_ci    # Parse the specified registry XML into an ElementTree objec
4015db71995Sopenharmony_ci    startTimer(args.time)
4025db71995Sopenharmony_ci    tree = etree.parse(args.registry)
4035db71995Sopenharmony_ci    endTimer(args.time, '* Time to make ElementTree =')
4045db71995Sopenharmony_ci
4055db71995Sopenharmony_ci    # Load the XML tree into the registry object
4065db71995Sopenharmony_ci    startTimer(args.time)
4075db71995Sopenharmony_ci    reg.loadElementTree(tree)
4085db71995Sopenharmony_ci    endTimer(args.time, '* Time to parse ElementTree =')
4095db71995Sopenharmony_ci
4105db71995Sopenharmony_ci    if (args.validate):
4115db71995Sopenharmony_ci        reg.validateGroups()
4125db71995Sopenharmony_ci
4135db71995Sopenharmony_ci    if (args.dump):
4145db71995Sopenharmony_ci        write('* Dumping registry to regdump.txt', file=sys.stderr)
4155db71995Sopenharmony_ci        reg.dumpReg(filehandle = open('regdump.txt', 'w', encoding='utf-8'))
4165db71995Sopenharmony_ci
4175db71995Sopenharmony_ci    # Finally, use the output generator to create the requested targe
4185db71995Sopenharmony_ci    if (args.debug):
4195db71995Sopenharmony_ci        pdb.run('reg.apiGen()')
4205db71995Sopenharmony_ci    else:
4215db71995Sopenharmony_ci        startTimer(args.time)
4225db71995Sopenharmony_ci        reg.apiGen()
4235db71995Sopenharmony_ci        endTimer(args.time, '* Time to generate ' + options.filename + ' =')
4245db71995Sopenharmony_ci
4255db71995Sopenharmony_ci    if not args.quiet:
4265db71995Sopenharmony_ci        write('* Generated', options.filename, file=sys.stderr)
427