]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a debug switch to the extension generator
authorMikko Rasa <tdb@tdb.fi>
Tue, 21 Nov 2017 20:18:18 +0000 (22:18 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 22 Nov 2017 06:01:17 +0000 (08:01 +0200)
scripts/extgen.py

index 4c3565e82cc0ac4ded23b39fbef6028d1978c27d..1d9cad3e853050a764ddc8fee308f1d4e87cc6ce 100755 (executable)
@@ -324,7 +324,7 @@ class GlXmlParser:
                self.sort_extensions()
 
 
-def detect_core_version(host_api, things):
+def detect_core_version(host_api, things, debug=None):
        max_version = Version(1, 0)
        max_count = 0
        lower_count = 0
@@ -347,11 +347,16 @@ def detect_core_version(host_api, things):
                print "Warning: Inconsistent core version %s"%max_version
 
        if missing:
+               if debug:
+                       print "---"
+                       print "%d things missing from core:"%len(missing)
+                       for t in missing:
+                               print "  "+t.name
                return None
 
        return max_version
 
-def detect_deprecated_version(host_api, things):
+def detect_deprecated_version(host_api, things, debug):
        min_version = None
        deprecated = []
        for t in things:
@@ -365,6 +370,11 @@ def detect_deprecated_version(host_api, things):
 
        if min_version and len(deprecated)*2<len(things):
                print "Warning: Inconsistent deprecation version %s"%min_version
+               if debug:
+                       print "---"
+                       print "%d things are deprecated:"%len(deprecated)
+                       for t in deprecated:
+                               print "  "+t.name
 
        return min_version
 
@@ -404,7 +414,7 @@ def collect_extensions(thing, api, exts):
        for s in supp.sources:
                collect_extensions(s, api, exts)
 
-def detect_source_extension(host_api, things):
+def detect_source_extension(host_api, things, debug=False):
        things_by_ext = {}
        for t in things:
                exts = []
@@ -412,6 +422,10 @@ def detect_source_extension(host_api, things):
                for e in exts:
                        things_by_ext.setdefault(e, []).append(t)
 
+       if debug:
+               print "---"
+               print "Looking for %d things in %d extensions"%(len(things), len(things_by_ext))
+
        extensions = []
        missing = set(things)
        while missing and things_by_ext:
@@ -425,6 +439,9 @@ def detect_source_extension(host_api, things):
                        elif count==largest_count and e.preference>largest_ext.preference:
                                largest_ext = e
 
+               if debug:
+                       print "Found %d things in %s"%(largest_count, largest_ext.name)
+
                extensions.append(largest_ext)
                for t in things_by_ext[largest_ext]:
                        missing.remove(t)
@@ -440,13 +457,17 @@ def detect_source_extension(host_api, things):
                                del things_by_ext[e]
 
        if missing:
+               if debug:
+                       print "%d things still missing:"%len(missing)
+                       for t in missing:
+                               print "  "+t.name
                return None
 
        return extensions
 
 
 class SourceGenerator:
-       def __init__(self, host_api, ext_name, things, optional_things):
+       def __init__(self, host_api, ext_name, things, optional_things, debug=False):
                self.host_api = host_api
                self.api_prefix = "GL"
                if self.host_api.name=="gles2":
@@ -458,14 +479,24 @@ class SourceGenerator:
                self.func_typedefs = dict((f.name, "FPtr_"+f.name) for f in self.funcs)
                self.enums = filter((lambda t: t.kind==Thing.ENUM), all_things)
                self.enums.sort(key=(lambda e: e.value))
-               self.core_version = detect_core_version(host_api, things)
-               self.deprecated_version = detect_deprecated_version(host_api, things)
+               self.core_version = detect_core_version(host_api, things, debug)
+               self.deprecated_version = detect_deprecated_version(host_api, things, debug)
                self.backport_ext = detect_backport_extension(host_api, things);
-               self.source_exts = detect_source_extension(host_api, things)
+               self.source_exts = detect_source_extension(host_api, things, debug)
 
                if not self.core_version and not self.backport_ext and not self.source_exts:
                        print "Warning: Not supportable on host API"
 
+       def dump_info(self):
+               print "--- Extension information ---"
+               print "Extension %s"%self.ext_name
+               print "Core %s"%self.core_version
+               print "Deprecated %s"%self.deprecated_version
+               if self.backport_ext:
+                       print "Backport %s"%self.backport_ext.name
+               if self.source_exts:
+                       print "Sources %s"%", ".join(e.name for e in self.source_exts)
+
        def write_header_intro(self, out):
                out.write("#ifndef MSP_GL_%s_\n"%self.ext_name.upper())
                out.write("#define MSP_GL_%s_\n"%self.ext_name.upper())
@@ -610,6 +641,29 @@ namespace GL {
                self.write_source_outro(out)
 
 
+def dump_api_support(supp, api, indent):
+       if supp.core_version:
+               print indent+"core in version "+str(supp.core_version)
+       if supp.deprecated_version:
+               print indent+"deprecated in version "+str(supp.deprecated_version)
+       for e in supp.extensions:
+               print indent+"extension %s (preference %d)"%(e.name, e.preference)
+       for r in supp.sources:
+               print indent+"source "+r.name
+               dump_thing_info(r, api, indent+"  ")
+
+def dump_thing_info(thing, api, indent):
+       for a in thing.aliases:
+               print indent+"alias "+a
+       if api:
+               supp = thing.api_support.get(api)
+               dump_api_support(supp, api, indent)
+       else:
+               for a, s in thing.api_support.iteritems():
+                       print indent+"api "+a
+                       dump_api_support(s, a, indent+"  ")
+
+
 class ExtensionParser:
        def __init__(self, host_api):
                self.host_api = host_api
@@ -697,9 +751,14 @@ name is used.  Anything after the last dot in <outfile> is removed and
 replaced with cpp and h."""
                sys.exit(1)
 
-       host_api_name = "gl"
-
        i = 1
+
+       debug = False
+       if sys.argv[i]=="-g":
+               debug = True
+               i += 1
+
+       host_api_name = "gl"
        if sys.argv[i].startswith("gl"):
                host_api_name = sys.argv[i]
                i += 1
@@ -725,7 +784,17 @@ replaced with cpp and h."""
        things = collect_extension_things(host_api, target_ext, ext_parser.ignore_things+ext_parser.optional_things)
        optional_things = collect_optional_things(target_ext, ext_parser.optional_things)
 
-       generator = SourceGenerator(host_api, target_ext.name, things, optional_things)
+       if debug:
+               print "--- Things included in this extension ---"
+               all_things = things+optional_things
+               all_things.sort(key=(lambda t: t.name))
+               for t in all_things:
+                       print t.name
+                       if t in optional_things:
+                               print "  optional"
+                       dump_thing_info(t, None, "  ")
+
+       generator = SourceGenerator(host_api, target_ext.name, things, optional_things, debug)
        if ext_parser.core_version:
                generator.core_version = ext_parser.core_version
        if ext_parser.deprecated_version:
@@ -735,6 +804,8 @@ replaced with cpp and h."""
                        generator.backport_ext = None
                else:
                        generator.backport_ext = get_extension(xml_parser.apis, ext_parser.backport_ext)
+       if debug:
+               generator.dump_info()
        generator.write_header(out_base+".h")
        generator.write_source(out_base+".cpp")