Пример #1
0
def generate_func_table(entry_file, header_file):
    from func_table_template import header_template
    from func_table_template import entry_point_member

    global open_copyright
    global openSource
    global outputDir

    print("Generating %s from %s ..." % (header_file, entry_file))

    f = open(entry_file)
    lines = f.readlines()
    f.close()

    header_path = os.path.join(outputDir, header_file)
    header = open(header_path, 'w')

    entry_point_members = ''
    prev_ext = ''
    prev_ext_ep_count = 0
    reserved_ep_count = 0

    for line in lines:
        original = line.rstrip().lstrip()
        if original == "" or original[0] == '#':
            continue

        # Figure out if this entry point depends on an extension to be enabled by the compiler.  This is really
        # only relevant for platform-specific extensions e.g. win32 or xcb WSI extensions as most normal extensions
        # are always compiled in.
        cur_ext = ''

        if '@' in original:
            tokens = original.split('@', 2)
            cur_ext = get_compile_condition('@' + tokens[2])

        if cur_ext != prev_ext:
            preprocessor = ''
            if len(prev_ext) > 0:
                preprocessor += '#else\n'
                for num in range(0, prev_ext_ep_count):
                    preprocessor += '    PFN_vkVoidFunction reserved' + str(
                        reserved_ep_count) + ';\n'
                    reserved_ep_count += 1
                preprocessor += '#endif\n'

            if len(cur_ext) > 0:
                preprocessor += ('#if %s\n' % cur_ext)

            prev_ext = cur_ext
            prev_ext_ep_count = 0
            entry_point_members = entry_point_members + preprocessor

        func_name = line.split(' ')[0]

        prev_ext_ep_count += 1
        entry_point_members = entry_point_members + entry_point_member.replace(
            '$func_name$', func_name) + '\n'

    if len(prev_ext) > 0:
        preprocessor = '#else\n'
        for num in range(0, prev_ext_ep_count):
            preprocessor += '    PFN_vkVoidFunction reserved' + str(
                reserved_ep_count) + ';\n'
            reserved_ep_count += 1
        preprocessor += '#endif\n'
        entry_point_members = entry_point_members + preprocessor

    if openSource:
        header_template = header_template.replace('$copyright_string$',
                                                  open_copyright)
    header_template = header_template.replace('$entry_file$', entry_file)
    header_template = header_template.replace('$entry_point_members$',
                                              entry_point_members)

    header.write(header_template)
    header.close()
Пример #2
0
def generate_func_table(entry_file_prefix, header_file, impl_file):
    from func_table_template import header_template
    from func_table_template import impl_template
    from func_table_template import gnl_entry
    from func_table_template import entry_table_member

    global open_copyright
    global openSource;
    global PREFIX

    print("Generating %s and %s from %s ..." % (header_file, impl_file, entry_file_prefix))

    entry_file = ".%s" % (entry_file_prefix);
    f = open(entry_file)
    lines = f.readlines()
    f.close()

    header = open(PREFIX + header_file, 'w')
    impl = open(PREFIX + impl_file, 'w')

    entry_table_members = ''
    gnl_code = ''
    prev_ext = ''

    for line in lines:
        original = line.rstrip().lstrip()
        if original == "" or original[0] == '#':
            continue

        # Figure out if this entry point depends on an extension to be enabled by the compiler.  This is really
        # only relevant for platform-specific extensions e.g. win32 or xcb WSI extensions as most normal extensions
        # are always compiled in.
        cur_ext = ''

        if '@' in original:
            tokens = original.split('@', 1)
            ext_tokens = tokens[1].split(' ', 2)
            if ext_tokens[0] == 'iext' or ext_tokens[0] == 'dext':
                cur_ext = 'VK_' + ext_tokens[1]
            # Guard Vulkan 1.1 with a preprocessor define until public
            elif len(ext_tokens) == 2 and ext_tokens[1] =='1.1':
                cur_ext = 'ICD_VULKAN_1_1'

        if '$win32_only' in original:
            cur_ext = '_WIN32'

        if cur_ext != prev_ext:
            preprocessor = ''
            if len(prev_ext) > 0:
                preprocessor += '#endif\n'
            if len(cur_ext) > 0:
                preprocessor += ('#if %s\n' % cur_ext)

            prev_ext = cur_ext
            gnl_code = gnl_code + preprocessor
            entry_table_members = entry_table_members + preprocessor

        func_name = line.split(' ')[0]

        entry_table_members = entry_table_members + entry_table_member.replace('$func_name$', func_name) + '\n'
        gnl_code = gnl_code + gnl_entry.replace('$func_name$', func_name) + '\n'

    if len(prev_ext) > 0:
        preprocessor = '#endif\n'
        entry_table_members = entry_table_members + preprocessor
        gnl_code = gnl_code + preprocessor

    if openSource:
        header_template = header_template.replace('$copyright_string$', open_copyright)
        impl_template = impl_template.replace('$copyright_string$', open_copyright)
        impl_template = impl_template.replace('$header_file$', 'strings/strings.h')
    header_template = header_template.replace('$entry_file$', entry_file_prefix)
    header_template = header_template.replace('$entry_table_members$', entry_table_members)

    impl_template = impl_template.replace('$entry_file$', entry_file_prefix)
    impl_template = impl_template.replace('$gnl_code$', gnl_code)

    header.write(header_template)
    header.close()

    impl.write(impl_template)
    impl.close()