Пример #1
0
    def endFile(self):
        file_data = ''

        if self.genOpts.filename == 'xr_generated_loader.hpp':
            file_data += '#ifdef __cplusplus\n'
            file_data += 'extern "C" { \n'
            file_data += '#endif\n'
            file_data += self.outputLoaderManualFuncs()
            file_data += self.outputLoaderGeneratedPrototypes()
            file_data += '#ifdef __cplusplus\n'
            file_data += '} // extern "C"\n'
            file_data += '#endif\n'
            file_data += self.outputLoaderMapExterns()

        elif self.genOpts.filename == 'xr_generated_loader.cpp':
            file_data += self.outputLoaderMapDefines()
            file_data += '#ifdef __cplusplus\n'
            file_data += 'extern "C" { \n'
            file_data += '#endif\n'
            file_data += self.outputLoaderGeneratedFuncs()
            file_data += self.outputLoaderExportFuncs()
            file_data += '#ifdef __cplusplus\n'
            file_data += '} // extern "C"\n'
            file_data += '#endif\n'

        write(file_data, file=self.outFile)

        # Finish processing in superclass
        AutomaticSourceOutputGenerator.endFile(self)
Пример #2
0
 def beginFile(self, genOpts):
     AutomaticSourceOutputGenerator.beginFile(self, genOpts)
     self.conventions = self.genOpts.conventions
     self.env.globals['filename'] = genOpts.filename
     self.env.tests['cpp_hidden_member'] = self._cpp_hidden_member
     self.env.tests['struct_output'] = self._is_struct_output
     self.env.tests['struct_input'] = self._is_struct_input
     self.template = JinjaTemplate(self.env,
                                   "template_{}".format(genOpts.filename))
Пример #3
0
    def endFile(self):
        sorted_cmds = self.core_commands + self.ext_commands
        file_data = self.template.render(
            gen=self,
            registry=self.registry,
            null_instance_ok=VALID_FOR_NULL_INSTANCE,
            sorted_cmds=sorted_cmds)
        write(file_data, file=self.outFile)

        # Finish processing in superclass
        AutomaticSourceOutputGenerator.endFile(self)
    def beginFile(self, genOpts):
        AutomaticSourceOutputGenerator.beginFile(self, genOpts)
        preamble = ''
        if self.genOpts.filename == 'xr_generated_dispatch_table.h':
            preamble += '#pragma once\n'
        elif self.genOpts.filename == 'xr_generated_dispatch_table.c':
            preamble += '#include "xr_generated_dispatch_table.h"\n'

        preamble += '#include "xr_dependencies.h"\n'
        preamble += '#include <openxr/openxr.h>\n'
        preamble += '#include <openxr/openxr_platform.h>\n\n'
        write(preamble, file=self.outFile)
Пример #5
0
    def endFile(self):
        sorted_cmds = self.core_commands + self.ext_commands
        skip_hooks = set(self.no_trampoline_or_terminator).union(
            set(MANUALLY_DEFINED_IN_LAYER))
        file_data = self.template.render(gen=self,
                                         registry=self.registry,
                                         sorted_cmds=sorted_cmds,
                                         skip_hooks=skip_hooks)
        write(file_data, file=self.outFile)

        # Finish processing in superclass
        AutomaticSourceOutputGenerator.endFile(self)
Пример #6
0
    def beginFile(self, genOpts):
        AutomaticSourceOutputGenerator.beginFile(self, genOpts)
        preamble = ''

        if self.genOpts.filename == 'xr_generated_loader.hpp':
            preamble += '#pragma once\n'
            preamble += '#include <unordered_map>\n'
            preamble += '#include <thread>\n'
            preamble += '#include <mutex>\n\n'
            preamble += '#include "xr_dependencies.h"\n'
            preamble += '#include "openxr/openxr.h"\n'
            preamble += '#include "openxr/openxr_platform.h"\n\n'
            preamble += '#include "loader_interfaces.h"\n\n'
            preamble += '#include "loader_instance.hpp"\n\n'
            preamble += '#include "loader_platform.hpp"\n\n'

        elif self.genOpts.filename == 'xr_generated_loader.cpp':
            preamble += '#include "xr_generated_loader.hpp"\n\n'
            preamble += '#include "api_layer_interface.hpp"\n'
            preamble += '#include "exception_handling.hpp"\n'
            preamble += '#include "hex_and_handles.h"\n'
            preamble += '#include "loader_instance.hpp"\n'
            preamble += '#include "loader_logger.hpp"\n'
            preamble += '#include "loader_platform.hpp"\n'
            preamble += '#include "runtime_interface.hpp"\n'
            preamble += '#include "xr_generated_dispatch_table.h"\n\n'

            preamble += '#include "xr_dependencies.h"\n'
            preamble += '#include <openxr/openxr.h>\n'
            preamble += '#include <openxr/openxr_platform.h>\n\n'

            preamble += '#include <cstring>\n'
            preamble += '#include <memory>\n'
            preamble += '#include <new>\n'
            preamble += '#include <string>\n'
            preamble += '#include <unordered_map>\n'

        write(preamble, file=self.outFile)
    def endFile(self):
        file_data = ''

        file_data += '#ifdef __cplusplus\n'
        file_data += 'extern "C" { \n'
        file_data += '#endif\n'

        if self.genOpts.filename == 'xr_generated_dispatch_table.h':
            file_data += self.outputDispatchTable()
            file_data += self.outputDispatchPrototypes()
        elif self.genOpts.filename == 'xr_generated_dispatch_table.c':
            file_data += self.outputDispatchTableHelper()
        else:
            raise RuntimeError("Unknown filename! " + self.genOpts.filename)

        file_data += '\n'
        file_data += '#ifdef __cplusplus\n'
        file_data += '} // extern "C"\n'
        file_data += '#endif\n'

        write(file_data, file=self.outFile)

        # Finish processing in superclass
        AutomaticSourceOutputGenerator.endFile(self)
 def beginFile(self, genOpts):
     AutomaticSourceOutputGenerator.beginFile(self, genOpts)
     self.template = JinjaTemplate(self.env, "template_{}".format(genOpts.filename))
Пример #9
0
    def endFile(self):
        sorted_cmds = self.core_commands + self.ext_commands

        self.dict_extensions = {}
        for ext in self.extensions:
            self.dict_extensions[ext.name] = ext

        self.dict_handles = {}
        for handle in self.api_handles:
            self.dict_handles[handle.name] = handle

        self.dict_enums = {}
        for enum in self.api_enums:
            self.dict_enums[enum.name] = enum
            if enum.name == 'XrResult':
                result_enum = enum

        self.dict_structs = {}
        for struct in self.api_structures:
            self.dict_structs[struct.name] = struct

        self.dict_bitmasks = {}
        for bitmask in self.api_bitmasks:
            self.dict_bitmasks[bitmask.name] = bitmask

        self.dict_atoms = {}
        for basetype in self.api_base_types:
            if basetype.type == "XR_DEFINE_ATOM":
                self.dict_atoms[basetype.name] = basetype

        self.projected_types = MANUALLY_PROJECTED.union(
            self.dict_handles.keys())
        self.projected_types.update(self.dict_enums.keys())
        self.projected_types.update(self.dict_structs.keys())
        self.projected_types.update(self.dict_bitmasks.keys())
        self.projected_types.update(self.dict_atoms.keys())
        self.projected_types.difference_update(SKIP_PROJECTION)

        # Every type mentioned in some other type's parentstruct attribute.
        struct_parents = ((otherType, otherType.elem.get('parentstruct'))
                          for otherType in self.registry.typedict.values())
        self.struct_parents = {
            child.elem.get('name'): parent
            for child, parent in struct_parents if parent is not None
        }
        self.parents = set(self.struct_parents.values())

        self.skip_projection = SKIP_PROJECTION

        def children_of(t):
            return set(child for child, parent in self.struct_parents.items()
                       if parent == t)

        self.struct_children = {
            parent: children_of(parent)
            for parent in self.parents
        }

        def fields_of(t):
            struct = self.dict_structs[t]
            members = struct.members
            return set(field.name for field in members
                       if not self._cpp_hidden_member(field))

        self.struct_fields = {
            parent: fields_of(parent)
            for parent in self.parents if parent in self.dict_structs
        }

        basic_cmds = {}
        enhanced_cmds = {}
        enhanced_cmds_no_exceptions = {}
        unique_cmds = {}
        unique_cmds_no_exceptions = {}
        for cmd in sorted_cmds:
            basic = MethodProjection(cmd, self)
            self._basic_method_projection(basic)
            basic_cmds[cmd.name] = basic

            enhanced = MethodProjection(cmd, self)
            self._enhanced_method_projection(enhanced)
            enhanced_cmds[cmd.name] = enhanced
            if enhanced.explicit_result_elided:

                # Now try again to make one without exceptions.
                enhanced_noexcept = MethodProjection(cmd, self)
                enhanced_noexcept.exceptions_permitted = False
                self._enhanced_method_projection(enhanced_noexcept)
                enhanced_cmds_no_exceptions[cmd.name] = enhanced_noexcept

            if enhanced.is_create:
                unique = MethodProjection(cmd, self)
                self._unique_method_projection(unique)
                unique_cmds[cmd.name] = unique

                # Now try again to make one without exceptions,
                if unique.explicit_result_elided:
                    # all creation calls can elide the result.
                    unique_noexcept = MethodProjection(cmd, self)
                    unique_noexcept.exceptions_permitted = False
                    self._unique_method_projection(unique_noexcept)
                    unique_cmds_no_exceptions[cmd.name] = unique_noexcept
                else:
                    # assumption violated
                    assert (False)
        # Verify
        self.selftests()

        file_data = self.template.render(
            gen=self,
            registry=self.registry,
            null_instance_ok=VALID_FOR_NULL_INSTANCE,
            sorted_cmds=sorted_cmds,
            create_enum_value=self.createEnumValue,
            create_flag_value=self.createFlagValue,
            project_type_name=_project_type_name,
            result_enum=result_enum,
            create_enum_exception=self.createEnumException,
            basic_cmds=basic_cmds,
            enhanced_cmds=enhanced_cmds,
            enhanced_cmds_no_exceptions=enhanced_cmds_no_exceptions,
            unique_cmds=unique_cmds,
            unique_cmds_no_exceptions=unique_cmds_no_exceptions,
            discouraged_begin=_discouraged_begin,
            discouraged_end=_discouraged_end,
            generate_structure_type_from_name=self.conventions.
            generate_structure_type_from_name,
            is_tagged_type=self._is_tagged_type,
            project_cppdecl=self._project_cppdecl,
            bitmask_for_flags=self._bitmask_for_flags,
            is_static_length_array=_is_static_length_array,
            is_static_length_string=_is_static_length_string,
            struct_parents=self.struct_parents,
            struct_children=self.struct_children,
            struct_fields=self.struct_fields,
            project_struct=(lambda s: StructProjection(s, self)),
            get_default_for_member=self._get_default_for_member,
            index0_of_first_visible_defaultable_member=self.
            _index0_of_first_visible_defaultable_member,
            manually_projected=MANUALLY_PROJECTED,
            skip=SKIP,
        )
        write(file_data, file=self.outFile)

        # Finish processing in superclass
        AutomaticSourceOutputGenerator.endFile(self)
Пример #10
0
    def endFile(self):
        sorted_cmds = self.core_commands + self.ext_commands

        self.dict_handles = {}
        for handle in self.api_handles:
            self.dict_handles[handle.name] = handle

        self.dict_enums = {}
        for enum in self.api_enums:
            self.dict_enums[enum.name] = enum
            if enum.name == 'XrResult':
                result_enum = enum

        self.dict_structs = {}
        for struct in self.api_structures:
            self.dict_structs[struct.name] = struct

        self.dict_bitmasks = {}
        for bitmask in self.api_bitmasks:
            self.dict_bitmasks[bitmask.name] = bitmask

        self.projected_types = MANUALLY_PROJECTED.union(self.dict_handles.keys())
        self.projected_types.update(self.dict_enums.keys())
        self.projected_types.update(self.dict_structs.keys())
        self.projected_types.update(self.dict_bitmasks.keys())

        # Every type mentioned in some other type's parentstruct attribute.
        struct_parents = ((otherType, otherType.elem.get('parentstruct'))
                          for otherType in self.registry.typedict.values())
        self.struct_parents = {child.elem.get('name'): parent for child, parent in struct_parents
                               if parent is not None}
        self.parents = set(self.struct_parents.values())

        def children_of(t):
            return set(child for child, parent in self.struct_parents.items() if parent == t)

        self.struct_children = {parent: children_of(parent) for parent in self.parents}

        def fields_of(t):
            struct = self.dict_structs[t]
            members = struct.members
            return set(field.name for field in members if not self._cpp_hidden_member(field))

        self.struct_fields = {parent: fields_of(parent) for parent in self.parents}

        basic_cmds = {}
        enhanced_cmds = {}
        unique_cmds = {}
        for cmd in sorted_cmds:
            basic = MethodProjection(cmd, self)
            self._basic_method_projection(basic)
            basic_cmds[cmd.name] = basic

            enhanced = MethodProjection(cmd, self)
            self._enhanced_method_projection(enhanced)
            enhanced_cmds[cmd.name] = enhanced

            if enhanced.is_create:
                unique = MethodProjection(cmd, self)
                self._unique_method_projection(unique)
                unique_cmds[cmd.name] = unique

        file_data = self.template.render(
            gen=self,
            registry=self.registry,
            null_instance_ok=VALID_FOR_NULL_INSTANCE,
            sorted_cmds=sorted_cmds,
            create_enum_value=self.createEnumValue,
            create_flag_value=self.createFlagValue,
            project_type_name=_project_type_name,
            result_enum=result_enum,
            create_enum_exception=self.createEnumException,
            basic_cmds=basic_cmds,
            enhanced_cmds=enhanced_cmds,
            unique_cmds=unique_cmds,
            discouraged_begin=_discouraged_begin,
            discouraged_end=_discouraged_end,
            generate_structure_type_from_name=self.conventions.generate_structure_type_from_name,
            is_tagged_type=self._is_tagged_type,
            project_cppdecl=self._project_cppdecl,
            cpp_hidden_member=self._cpp_hidden_member,
            struct_member_count=self._struct_member_count,
            bitmask_for_flags=self._bitmask_for_flags,
            is_static_length_string=_is_static_length_string,
            parents=self.parents,
            struct_parents=self.struct_parents,
            struct_children=self.struct_children,
            struct_fields=self.struct_fields,
            get_tag=self._get_tag,
            is_base_only=self._is_base_only
        )
        write(file_data, file=self.outFile)

        # Finish processing in superclass
        AutomaticSourceOutputGenerator.endFile(self)