• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2#
3# Copyright (c) 2013-2019 The Khronos Group Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import argparse, cProfile, pdb, string, sys, time, os
18
19# Simple timer functions
20startTime = None
21
22def startTimer(timeit):
23    global startTime
24    if timeit:
25        startTime = time.process_time()
26
27def endTimer(timeit, msg):
28    global startTime
29    if timeit:
30        endTime = time.process_time()
31        write(msg, endTime - startTime, file=sys.stderr)
32        startTime = None
33
34# Turn a list of strings into a regexp string matching exactly those strings
35def makeREstring(list, default = None):
36    if len(list) > 0 or default is None:
37        return '^(' + '|'.join(list) + ')$'
38    else:
39        return default
40
41# Returns a directory of [ generator function, generator options ] indexed
42# by specified short names. The generator options incorporate the following
43# parameters:
44#
45# args is an parsed argument object; see below for the fields that are used.
46def makeGenOpts(args):
47    global genOpts
48    genOpts = {}
49
50    # Default class of extensions to include, or None
51    defaultExtensions = args.defaultExtensions
52
53    # Additional extensions to include (list of extensions)
54    extensions = args.extension
55
56    # Extensions to remove (list of extensions)
57    removeExtensions = args.removeExtensions
58
59    # Extensions to emit (list of extensions)
60    emitExtensions = args.emitExtensions
61
62    # Features to include (list of features)
63    features = args.feature
64
65    # Whether to disable inclusion protect in headers
66    protect = args.protect
67
68    # Output target directory
69    directory = args.directory
70
71    # Descriptive names for various regexp patterns used to select
72    # versions and extensions
73    allFeatures     = allExtensions = '.*'
74    noFeatures      = noExtensions = None
75
76    # Turn lists of names/patterns into matching regular expressions
77    addExtensionsPat     = makeREstring(extensions, None)
78    removeExtensionsPat  = makeREstring(removeExtensions, None)
79    emitExtensionsPat    = makeREstring(emitExtensions, allExtensions)
80    featuresPat          = makeREstring(features, allFeatures)
81
82    # Copyright text prefixing all headers (list of strings).
83    prefixStrings = [
84        '/*',
85        '** Copyright (c) 2015-2019 The Khronos Group Inc.',
86        '**',
87        '** Licensed under the Apache License, Version 2.0 (the "License");',
88        '** you may not use this file except in compliance with the License.',
89        '** You may obtain a copy of the License at',
90        '**',
91        '**     http://www.apache.org/licenses/LICENSE-2.0',
92        '**',
93        '** Unless required by applicable law or agreed to in writing, software',
94        '** distributed under the License is distributed on an "AS IS" BASIS,',
95        '** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
96        '** See the License for the specific language governing permissions and',
97        '** limitations under the License.',
98        '*/',
99        ''
100    ]
101
102    # Text specific to Vulkan headers
103    vkPrefixStrings = [
104        '/*',
105        '** This header is generated from the Khronos Vulkan XML API Registry.',
106        '**',
107        '*/',
108        ''
109    ]
110
111    # Defaults for generating re-inclusion protection wrappers (or not)
112    protectFeature = protect
113
114    # ValidationLayer Generators
115    # Options for thread safety header code-generation
116    genOpts['thread_safety.h'] = [
117          ThreadOutputGenerator,
118          ThreadGeneratorOptions(
119            filename          = 'thread_safety.h',
120            directory         = directory,
121            apiname           = 'vulkan',
122            profile           = None,
123            versions          = featuresPat,
124            emitversions      = featuresPat,
125            defaultExtensions = 'vulkan',
126            addExtensions     = addExtensionsPat,
127            removeExtensions  = removeExtensionsPat,
128            emitExtensions    = emitExtensionsPat,
129            prefixText        = prefixStrings + vkPrefixStrings,
130            protectFeature    = False,
131            apicall           = 'VKAPI_ATTR ',
132            apientry          = 'VKAPI_CALL ',
133            apientryp         = 'VKAPI_PTR *',
134            alignFuncParam    = 48,
135            expandEnumerants = False)
136        ]
137
138    # Options for thread safety source code-generation
139    genOpts['thread_safety.cpp'] = [
140          ThreadOutputGenerator,
141          ThreadGeneratorOptions(
142            filename          = 'thread_safety.cpp',
143            directory         = directory,
144            apiname           = 'vulkan',
145            profile           = None,
146            versions          = featuresPat,
147            emitversions      = featuresPat,
148            defaultExtensions = 'vulkan',
149            addExtensions     = addExtensionsPat,
150            removeExtensions  = removeExtensionsPat,
151            emitExtensions    = emitExtensionsPat,
152            prefixText        = prefixStrings + vkPrefixStrings,
153            protectFeature    = False,
154            apicall           = 'VKAPI_ATTR ',
155            apientry          = 'VKAPI_CALL ',
156            apientryp         = 'VKAPI_PTR *',
157            alignFuncParam    = 48,
158            expandEnumerants = False)
159        ]
160
161    # Options for stateless validation source file
162    genOpts['parameter_validation.cpp'] = [
163          ParameterValidationOutputGenerator,
164          ParameterValidationGeneratorOptions(
165            filename          = 'parameter_validation.cpp',
166            directory         = directory,
167            apiname           = 'vulkan',
168            profile           = None,
169            versions          = featuresPat,
170            emitversions      = featuresPat,
171            defaultExtensions = 'vulkan',
172            addExtensions     = addExtensionsPat,
173            removeExtensions  = removeExtensionsPat,
174            emitExtensions    = emitExtensionsPat,
175            prefixText        = prefixStrings + vkPrefixStrings,
176            apicall           = 'VKAPI_ATTR ',
177            apientry          = 'VKAPI_CALL ',
178            apientryp         = 'VKAPI_PTR *',
179            alignFuncParam    = 48,
180            expandEnumerants  = False,
181            valid_usage_path  = args.scripts)
182          ]
183
184    # Options for stateless validation source file
185    genOpts['parameter_validation.h'] = [
186          ParameterValidationOutputGenerator,
187          ParameterValidationGeneratorOptions(
188            filename          = 'parameter_validation.h',
189            directory         = directory,
190            apiname           = 'vulkan',
191            profile           = None,
192            versions          = featuresPat,
193            emitversions      = featuresPat,
194            defaultExtensions = 'vulkan',
195            addExtensions     = addExtensionsPat,
196            removeExtensions  = removeExtensionsPat,
197            emitExtensions    = emitExtensionsPat,
198            prefixText        = prefixStrings + vkPrefixStrings,
199            apicall           = 'VKAPI_ATTR ',
200            apientry          = 'VKAPI_CALL ',
201            apientryp         = 'VKAPI_PTR *',
202            alignFuncParam    = 48,
203            expandEnumerants  = False,
204            valid_usage_path  = args.scripts)
205          ]
206
207    # Options for object_tracker code-generated validation routines
208    genOpts['object_tracker.cpp'] = [
209          ObjectTrackerOutputGenerator,
210          ObjectTrackerGeneratorOptions(
211            filename          = 'object_tracker.cpp',
212            directory         = directory,
213            apiname           = 'vulkan',
214            profile           = None,
215            versions          = featuresPat,
216            emitversions      = featuresPat,
217            defaultExtensions = 'vulkan',
218            addExtensions     = addExtensionsPat,
219            removeExtensions  = removeExtensionsPat,
220            emitExtensions    = emitExtensionsPat,
221            prefixText        = prefixStrings + vkPrefixStrings,
222            protectFeature    = False,
223            apicall           = 'VKAPI_ATTR ',
224            apientry          = 'VKAPI_CALL ',
225            apientryp         = 'VKAPI_PTR *',
226            alignFuncParam    = 48,
227            expandEnumerants  = False,
228            valid_usage_path  = args.scripts)
229        ]
230
231    # Options for object_tracker code-generated prototypes
232    genOpts['object_tracker.h'] = [
233          ObjectTrackerOutputGenerator,
234          ObjectTrackerGeneratorOptions(
235            filename          = 'object_tracker.h',
236            directory         = directory,
237            apiname           = 'vulkan',
238            profile           = None,
239            versions          = featuresPat,
240            emitversions      = featuresPat,
241            defaultExtensions = 'vulkan',
242            addExtensions     = addExtensionsPat,
243            removeExtensions  = removeExtensionsPat,
244            emitExtensions    = emitExtensionsPat,
245            prefixText        = prefixStrings + vkPrefixStrings,
246            protectFeature    = False,
247            apicall           = 'VKAPI_ATTR ',
248            apientry          = 'VKAPI_CALL ',
249            apientryp         = 'VKAPI_PTR *',
250            alignFuncParam    = 48,
251            expandEnumerants  = False,
252            valid_usage_path  = args.scripts)
253        ]
254
255    # Options for dispatch table helper generator
256    genOpts['vk_dispatch_table_helper.h'] = [
257          DispatchTableHelperOutputGenerator,
258          DispatchTableHelperOutputGeneratorOptions(
259            filename          = 'vk_dispatch_table_helper.h',
260            directory         = directory,
261            apiname           = 'vulkan',
262            profile           = None,
263            versions          = featuresPat,
264            emitversions      = featuresPat,
265            defaultExtensions = 'vulkan',
266            addExtensions     = addExtensionsPat,
267            removeExtensions  = removeExtensionsPat,
268            emitExtensions    = emitExtensionsPat,
269            prefixText        = prefixStrings + vkPrefixStrings,
270            apicall           = 'VKAPI_ATTR ',
271            apientry          = 'VKAPI_CALL ',
272            apientryp         = 'VKAPI_PTR *',
273            alignFuncParam    = 48,
274            expandEnumerants = False)
275        ]
276
277    # Options for Layer dispatch table generator
278    genOpts['vk_layer_dispatch_table.h'] = [
279          LayerDispatchTableOutputGenerator,
280          LayerDispatchTableGeneratorOptions(
281            filename          = 'vk_layer_dispatch_table.h',
282            directory         = directory,
283            apiname           = 'vulkan',
284            profile           = None,
285            versions          = featuresPat,
286            emitversions      = featuresPat,
287            defaultExtensions = 'vulkan',
288            addExtensions     = addExtensionsPat,
289            removeExtensions  = removeExtensionsPat,
290            emitExtensions    = emitExtensionsPat,
291            prefixText        = prefixStrings + vkPrefixStrings,
292            apicall           = 'VKAPI_ATTR ',
293            apientry          = 'VKAPI_CALL ',
294            apientryp         = 'VKAPI_PTR *',
295            alignFuncParam    = 48,
296            expandEnumerants = False)
297        ]
298
299    # Helper file generator options for vk_enum_string_helper.h
300    genOpts['vk_enum_string_helper.h'] = [
301          HelperFileOutputGenerator,
302          HelperFileOutputGeneratorOptions(
303            filename          = 'vk_enum_string_helper.h',
304            directory         = directory,
305            apiname           = 'vulkan',
306            profile           = None,
307            versions          = featuresPat,
308            emitversions      = featuresPat,
309            defaultExtensions = 'vulkan',
310            addExtensions     = addExtensionsPat,
311            removeExtensions  = removeExtensionsPat,
312            emitExtensions    = emitExtensionsPat,
313            prefixText        = prefixStrings + vkPrefixStrings,
314            apicall           = 'VKAPI_ATTR ',
315            apientry          = 'VKAPI_CALL ',
316            apientryp         = 'VKAPI_PTR *',
317            alignFuncParam    = 48,
318            expandEnumerants  = False,
319            helper_file_type  = 'enum_string_header')
320        ]
321
322    # Helper file generator options for vk_safe_struct.h
323    genOpts['vk_safe_struct.h'] = [
324          HelperFileOutputGenerator,
325          HelperFileOutputGeneratorOptions(
326            filename          = 'vk_safe_struct.h',
327            directory         = directory,
328            apiname           = 'vulkan',
329            profile           = None,
330            versions          = featuresPat,
331            emitversions      = featuresPat,
332            defaultExtensions = 'vulkan',
333            addExtensions     = addExtensionsPat,
334            removeExtensions  = removeExtensionsPat,
335            emitExtensions    = emitExtensionsPat,
336            prefixText        = prefixStrings + vkPrefixStrings,
337            apicall           = 'VKAPI_ATTR ',
338            apientry          = 'VKAPI_CALL ',
339            apientryp         = 'VKAPI_PTR *',
340            alignFuncParam    = 48,
341            expandEnumerants  = False,
342            helper_file_type  = 'safe_struct_header')
343        ]
344
345    # Helper file generator options for vk_safe_struct.cpp
346    genOpts['vk_safe_struct.cpp'] = [
347          HelperFileOutputGenerator,
348          HelperFileOutputGeneratorOptions(
349            filename          = 'vk_safe_struct.cpp',
350            directory         = directory,
351            apiname           = 'vulkan',
352            profile           = None,
353            versions          = featuresPat,
354            emitversions      = featuresPat,
355            defaultExtensions = 'vulkan',
356            addExtensions     = addExtensionsPat,
357            removeExtensions  = removeExtensionsPat,
358            emitExtensions    = emitExtensionsPat,
359            prefixText        = prefixStrings + vkPrefixStrings,
360            apicall           = 'VKAPI_ATTR ',
361            apientry          = 'VKAPI_CALL ',
362            apientryp         = 'VKAPI_PTR *',
363            alignFuncParam    = 48,
364            expandEnumerants  = False,
365            helper_file_type  = 'safe_struct_source')
366        ]
367
368    # Helper file generator options for vk_object_types.h
369    genOpts['vk_object_types.h'] = [
370          HelperFileOutputGenerator,
371          HelperFileOutputGeneratorOptions(
372            filename          = 'vk_object_types.h',
373            directory         = directory,
374            apiname           = 'vulkan',
375            profile           = None,
376            versions          = featuresPat,
377            emitversions      = featuresPat,
378            defaultExtensions = 'vulkan',
379            addExtensions     = addExtensionsPat,
380            removeExtensions  = removeExtensionsPat,
381            emitExtensions    = emitExtensionsPat,
382            prefixText        = prefixStrings + vkPrefixStrings,
383            apicall           = 'VKAPI_ATTR ',
384            apientry          = 'VKAPI_CALL ',
385            apientryp         = 'VKAPI_PTR *',
386            alignFuncParam    = 48,
387            expandEnumerants  = False,
388            helper_file_type  = 'object_types_header')
389        ]
390
391    # Helper file generator options for extension_helper.h
392    genOpts['vk_extension_helper.h'] = [
393          HelperFileOutputGenerator,
394          HelperFileOutputGeneratorOptions(
395            filename          = 'vk_extension_helper.h',
396            directory         = directory,
397            apiname           = 'vulkan',
398            profile           = None,
399            versions          = featuresPat,
400            emitversions      = featuresPat,
401            defaultExtensions = 'vulkan',
402            addExtensions     = addExtensionsPat,
403            removeExtensions  = removeExtensionsPat,
404            emitExtensions    = emitExtensionsPat,
405            prefixText        = prefixStrings + vkPrefixStrings,
406            apicall           = 'VKAPI_ATTR ',
407            apientry          = 'VKAPI_CALL ',
408            apientryp         = 'VKAPI_PTR *',
409            alignFuncParam    = 48,
410            expandEnumerants  = False,
411            helper_file_type  = 'extension_helper_header')
412        ]
413
414    # Helper file generator options for typemap_helper.h
415    genOpts['vk_typemap_helper.h'] = [
416          HelperFileOutputGenerator,
417          HelperFileOutputGeneratorOptions(
418            filename          = 'vk_typemap_helper.h',
419            directory         = directory,
420            apiname           = 'vulkan',
421            profile           = None,
422            versions          = featuresPat,
423            emitversions      = featuresPat,
424            defaultExtensions = 'vulkan',
425            addExtensions     = addExtensionsPat,
426            removeExtensions  = removeExtensionsPat,
427            emitExtensions    = emitExtensionsPat,
428            prefixText        = prefixStrings + vkPrefixStrings,
429            protectFeature    = False,
430            apicall           = 'VKAPI_ATTR ',
431            apientry          = 'VKAPI_CALL ',
432            apientryp         = 'VKAPI_PTR *',
433            alignFuncParam    = 48,
434            expandEnumerants  = False,
435            helper_file_type  = 'typemap_helper_header')
436        ]
437
438    # Layer chassis related generation structs
439    # Options for layer chassis header
440    genOpts['chassis.h'] = [
441          LayerChassisOutputGenerator,
442          LayerChassisGeneratorOptions(
443            filename          = 'chassis.h',
444            directory         = directory,
445            apiname           = 'vulkan',
446            profile           = None,
447            versions          = featuresPat,
448            emitversions      = featuresPat,
449            defaultExtensions = 'vulkan',
450            addExtensions     = addExtensionsPat,
451            removeExtensions  = removeExtensionsPat,
452            emitExtensions    = emitExtensionsPat,
453            prefixText        = prefixStrings + vkPrefixStrings,
454            apicall           = 'VKAPI_ATTR ',
455            apientry          = 'VKAPI_CALL ',
456            apientryp         = 'VKAPI_PTR *',
457            alignFuncParam    = 48,
458            helper_file_type  = 'layer_chassis_header',
459            expandEnumerants = False)
460        ]
461
462    # Options for layer chassis source file
463    genOpts['chassis.cpp'] = [
464          LayerChassisOutputGenerator,
465          LayerChassisGeneratorOptions(
466            filename          = 'chassis.cpp',
467            directory         = directory,
468            apiname           = 'vulkan',
469            profile           = None,
470            versions          = featuresPat,
471            emitversions      = featuresPat,
472            defaultExtensions = 'vulkan',
473            addExtensions     = addExtensionsPat,
474            removeExtensions  = removeExtensionsPat,
475            emitExtensions    = emitExtensionsPat,
476            prefixText        = prefixStrings + vkPrefixStrings,
477            apicall           = 'VKAPI_ATTR ',
478            apientry          = 'VKAPI_CALL ',
479            apientryp         = 'VKAPI_PTR *',
480            alignFuncParam    = 48,
481            helper_file_type  = 'layer_chassis_source',
482            expandEnumerants = False)
483        ]
484
485    # Options for layer chassis dispatch source file
486    genOpts['layer_chassis_dispatch.cpp'] = [
487          LayerChassisDispatchOutputGenerator,
488          LayerChassisDispatchGeneratorOptions(
489            filename          = 'layer_chassis_dispatch.cpp',
490            directory         = directory,
491            apiname           = 'vulkan',
492            profile           = None,
493            versions          = featuresPat,
494            emitversions      = featuresPat,
495            defaultExtensions = 'vulkan',
496            addExtensions     = addExtensionsPat,
497            removeExtensions  = removeExtensionsPat,
498            emitExtensions    = emitExtensionsPat,
499            prefixText        = prefixStrings + vkPrefixStrings,
500            protectFeature    = False,
501            apicall           = 'VKAPI_ATTR ',
502            apientry          = 'VKAPI_CALL ',
503            apientryp         = 'VKAPI_PTR *',
504            alignFuncParam    = 48,
505            expandEnumerants = False)
506        ]
507
508    # Options for layer chassis dispatch header file
509    genOpts['layer_chassis_dispatch.h'] = [
510          LayerChassisDispatchOutputGenerator,
511          LayerChassisDispatchGeneratorOptions(
512            filename          = 'layer_chassis_dispatch.h',
513            directory         = directory,
514            apiname           = 'vulkan',
515            profile           = None,
516            versions          = featuresPat,
517            emitversions      = featuresPat,
518            defaultExtensions = 'vulkan',
519            addExtensions     = addExtensionsPat,
520            removeExtensions  = removeExtensionsPat,
521            emitExtensions    = emitExtensionsPat,
522            prefixText        = prefixStrings + vkPrefixStrings,
523            protectFeature    = False,
524            apicall           = 'VKAPI_ATTR ',
525            apientry          = 'VKAPI_CALL ',
526            apientryp         = 'VKAPI_PTR *',
527            alignFuncParam    = 48,
528            expandEnumerants = False)
529        ]
530
531
532# Generate a target based on the options in the matching genOpts{} object.
533# This is encapsulated in a function so it can be profiled and/or timed.
534# The args parameter is an parsed argument object containing the following
535# fields that are used:
536#   target - target to generate
537#   directory - directory to generate it in
538#   protect - True if re-inclusion wrappers should be created
539#   extensions - list of additional extensions to include in generated
540#   interfaces
541def genTarget(args):
542    global genOpts
543
544    # Create generator options with specified parameters
545    makeGenOpts(args)
546
547    if (args.target in genOpts.keys()):
548        createGenerator = genOpts[args.target][0]
549        options = genOpts[args.target][1]
550
551        if not args.quiet:
552            write('* Building', options.filename, file=sys.stderr)
553            write('* options.versions          =', options.versions, file=sys.stderr)
554            write('* options.emitversions      =', options.emitversions, file=sys.stderr)
555            write('* options.defaultExtensions =', options.defaultExtensions, file=sys.stderr)
556            write('* options.addExtensions     =', options.addExtensions, file=sys.stderr)
557            write('* options.removeExtensions  =', options.removeExtensions, file=sys.stderr)
558            write('* options.emitExtensions    =', options.emitExtensions, file=sys.stderr)
559
560        startTimer(args.time)
561        gen = createGenerator(errFile=errWarn,
562                              warnFile=errWarn,
563                              diagFile=diag)
564        reg.setGenerator(gen)
565        reg.apiGen(options)
566
567        if not args.quiet:
568            write('* Generated', options.filename, file=sys.stderr)
569        endTimer(args.time, '* Time to generate ' + options.filename + ' =')
570    else:
571        write('No generator options for unknown target:',
572              args.target, file=sys.stderr)
573
574# -feature name
575# -extension name
576# For both, "name" may be a single name, or a space-separated list
577# of names, or a regular expression.
578if __name__ == '__main__':
579    parser = argparse.ArgumentParser()
580
581    parser.add_argument('-defaultExtensions', action='store',
582                        default='vulkan',
583                        help='Specify a single class of extensions to add to targets')
584    parser.add_argument('-extension', action='append',
585                        default=[],
586                        help='Specify an extension or extensions to add to targets')
587    parser.add_argument('-removeExtensions', action='append',
588                        default=[],
589                        help='Specify an extension or extensions to remove from targets')
590    parser.add_argument('-emitExtensions', action='append',
591                        default=[],
592                        help='Specify an extension or extensions to emit in targets')
593    parser.add_argument('-feature', action='append',
594                        default=[],
595                        help='Specify a core API feature name or names to add to targets')
596    parser.add_argument('-debug', action='store_true',
597                        help='Enable debugging')
598    parser.add_argument('-dump', action='store_true',
599                        help='Enable dump to stderr')
600    parser.add_argument('-diagfile', action='store',
601                        default=None,
602                        help='Write diagnostics to specified file')
603    parser.add_argument('-errfile', action='store',
604                        default=None,
605                        help='Write errors and warnings to specified file instead of stderr')
606    parser.add_argument('-noprotect', dest='protect', action='store_false',
607                        help='Disable inclusion protection in output headers')
608    parser.add_argument('-profile', action='store_true',
609                        help='Enable profiling')
610    parser.add_argument('-registry', action='store',
611                        default='vk.xml',
612                        help='Use specified registry file instead of vk.xml')
613    parser.add_argument('-time', action='store_true',
614                        help='Enable timing')
615    parser.add_argument('-validate', action='store_true',
616                        help='Enable group validation')
617    parser.add_argument('-o', action='store', dest='directory',
618                        default='.',
619                        help='Create target and related files in specified directory')
620    parser.add_argument('target', metavar='target', nargs='?',
621                        help='Specify target')
622    parser.add_argument('-quiet', action='store_true', default=True,
623                        help='Suppress script output during normal execution.')
624    parser.add_argument('-verbose', action='store_false', dest='quiet', default=True,
625                        help='Enable script output during normal execution.')
626
627    # This argument tells us where to load the script from the Vulkan-Headers registry
628    parser.add_argument('-scripts', action='store',
629                        help='Find additional scripts in this directory')
630
631    args = parser.parse_args()
632
633    scripts_directory_path = os.path.dirname(os.path.abspath(__file__))
634    registry_headers_path = os.path.join(scripts_directory_path, args.scripts)
635    sys.path.insert(0, registry_headers_path)
636
637    from reg import *
638    from generator import write
639    from cgenerator import CGeneratorOptions, COutputGenerator
640
641    # ValidationLayer Generator Modifications
642    from thread_safety_generator import  ThreadGeneratorOptions, ThreadOutputGenerator
643    from parameter_validation_generator import ParameterValidationGeneratorOptions, ParameterValidationOutputGenerator
644    from object_tracker_generator import ObjectTrackerGeneratorOptions, ObjectTrackerOutputGenerator
645    from dispatch_table_helper_generator import DispatchTableHelperOutputGenerator, DispatchTableHelperOutputGeneratorOptions
646    from helper_file_generator import HelperFileOutputGenerator, HelperFileOutputGeneratorOptions
647    from layer_dispatch_table_generator import LayerDispatchTableOutputGenerator, LayerDispatchTableGeneratorOptions
648    from layer_chassis_generator import LayerChassisOutputGenerator, LayerChassisGeneratorOptions
649    from layer_chassis_dispatch_generator import LayerChassisDispatchOutputGenerator, LayerChassisDispatchGeneratorOptions
650
651    # This splits arguments which are space-separated lists
652    args.feature = [name for arg in args.feature for name in arg.split()]
653    args.extension = [name for arg in args.extension for name in arg.split()]
654
655    # Load & parse registry
656    reg = Registry()
657
658    startTimer(args.time)
659    tree = etree.parse(args.registry)
660    endTimer(args.time, '* Time to make ElementTree =')
661
662    if args.debug:
663        pdb.run('reg.loadElementTree(tree)')
664    else:
665        startTimer(args.time)
666        reg.loadElementTree(tree)
667        endTimer(args.time, '* Time to parse ElementTree =')
668
669    if (args.validate):
670        reg.validateGroups()
671
672    if (args.dump):
673        write('* Dumping registry to regdump.txt', file=sys.stderr)
674        reg.dumpReg(filehandle = open('regdump.txt', 'w', encoding='utf-8'))
675
676    # create error/warning & diagnostic files
677    if (args.errfile):
678        errWarn = open(args.errfile, 'w', encoding='utf-8')
679    else:
680        errWarn = sys.stderr
681
682    if (args.diagfile):
683        diag = open(args.diagfile, 'w', encoding='utf-8')
684    else:
685        diag = None
686
687    if (args.debug):
688        pdb.run('genTarget(args)')
689    elif (args.profile):
690        import cProfile, pstats
691        cProfile.run('genTarget(args)', 'profile.txt')
692        p = pstats.Stats('profile.txt')
693        p.strip_dirs().sort_stats('time').print_stats(50)
694    else:
695        genTarget(args)
696