Jamie Madill | 5ad5299 | 2017-11-14 12:43:40 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright 2017 The ANGLE Project Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | # |
| 6 | # gen_proc_table.py: |
| 7 | # Code generation for entry point loading tables. |
| 8 | |
| 9 | # TODO(jmadill): Should be part of entry point generation. |
| 10 | |
| 11 | import sys |
| 12 | from datetime import date |
| 13 | |
| 14 | data_source_name = "proc_table_data.json" |
| 15 | out_file_name = "proc_table_autogen.cpp" |
| 16 | |
| 17 | template_cpp = """// GENERATED FILE - DO NOT EDIT. |
| 18 | // Generated by {script_name} using data from {data_source_name}. |
| 19 | // |
| 20 | // Copyright {copyright_year} The ANGLE Project Authors. All rights reserved. |
| 21 | // Use of this source code is governed by a BSD-style license that can be |
| 22 | // found in the LICENSE file. |
| 23 | // |
| 24 | // getProcAddress loader table: |
| 25 | // Mapping from a string entry point name to function address. |
| 26 | // |
| 27 | |
| 28 | #include "libGLESv2/proc_table.h" |
| 29 | |
| 30 | #include "libGLESv2/entry_points_egl.h" |
| 31 | #include "libGLESv2/entry_points_egl_ext.h" |
| 32 | #include "libGLESv2/entry_points_gles_2_0_autogen.h" |
| 33 | #include "libGLESv2/entry_points_gles_2_0_ext.h" |
| 34 | #include "libGLESv2/entry_points_gles_3_0_autogen.h" |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame^] | 35 | #include "libGLESv2/entry_points_gles_3_1_autogen.h" |
Jamie Madill | 5ad5299 | 2017-11-14 12:43:40 -0500 | [diff] [blame] | 36 | #include "platform/Platform.h" |
| 37 | |
| 38 | #define P(FUNC) reinterpret_cast<__eglMustCastToProperFunctionPointerType>(FUNC) |
| 39 | |
| 40 | namespace egl |
| 41 | {{ |
| 42 | ProcEntry g_procTable[] = {{ |
| 43 | {proc_data} |
| 44 | }}; |
| 45 | |
| 46 | size_t g_numProcs = {num_procs}; |
| 47 | }} // namespace egl |
| 48 | """ |
| 49 | |
| 50 | sys.path.append('../libANGLE/renderer') |
| 51 | import angle_format |
| 52 | |
| 53 | json_data = angle_format.load_json(data_source_name) |
| 54 | |
| 55 | all_functions = {} |
| 56 | |
| 57 | for description, functions in json_data.iteritems(): |
| 58 | for function in functions: |
| 59 | if function.startswith("gl"): |
| 60 | all_functions[function] = "gl::" + function[2:] |
| 61 | elif function.startswith("egl"): |
| 62 | all_functions[function] = "egl::" + function[3:] |
| 63 | else: |
| 64 | all_functions[function] = function |
| 65 | |
| 66 | proc_data = [(' {"%s", P(%s)}' % (func, angle_func)) for func, angle_func in sorted(all_functions.iteritems())] |
| 67 | |
| 68 | with open(out_file_name, 'wt') as out_file: |
| 69 | output_cpp = template_cpp.format( |
| 70 | script_name = sys.argv[0], |
| 71 | data_source_name = data_source_name, |
| 72 | copyright_year = date.today().year, |
| 73 | proc_data = ",\n".join(proc_data), |
| 74 | num_procs = len(proc_data)) |
| 75 | out_file.write(output_cpp) |
| 76 | out_file.close() |
| 77 | |