blob: cd2a3abdda98589b2105398be90080d6ccd2cd84 [file] [log] [blame]
Jeff Gilbert3dddccf2017-11-14 16:44:36 -08001#!python
Jamie Madill5ad52992017-11-14 12:43:40 -05002# 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
11import sys
12from datetime import date
13
14data_source_name = "proc_table_data.json"
15out_file_name = "proc_table_autogen.cpp"
16
17template_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"
Geoff Lang2aaa7b42018-01-12 17:17:27 -050032#include "libGLESv2/entry_points_gles_1_0_autogen.h"
Jamie Madill5ad52992017-11-14 12:43:40 -050033#include "libGLESv2/entry_points_gles_2_0_autogen.h"
Jamie Madill5ad52992017-11-14 12:43:40 -050034#include "libGLESv2/entry_points_gles_3_0_autogen.h"
Jiajia Qincb59a902017-11-22 13:03:42 +080035#include "libGLESv2/entry_points_gles_3_1_autogen.h"
Geoff Lang2aaa7b42018-01-12 17:17:27 -050036#include "libGLESv2/entry_points_gles_ext_autogen.h"
Jamie Madill5ad52992017-11-14 12:43:40 -050037#include "platform/Platform.h"
38
39#define P(FUNC) reinterpret_cast<__eglMustCastToProperFunctionPointerType>(FUNC)
40
41namespace egl
42{{
43ProcEntry g_procTable[] = {{
44{proc_data}
45}};
46
47size_t g_numProcs = {num_procs};
48}} // namespace egl
49"""
50
51sys.path.append('../libANGLE/renderer')
52import angle_format
53
54json_data = angle_format.load_json(data_source_name)
55
56all_functions = {}
57
58for description, functions in json_data.iteritems():
59 for function in functions:
60 if function.startswith("gl"):
61 all_functions[function] = "gl::" + function[2:]
62 elif function.startswith("egl"):
63 all_functions[function] = "egl::" + function[3:]
64 else:
65 all_functions[function] = function
66
67proc_data = [(' {"%s", P(%s)}' % (func, angle_func)) for func, angle_func in sorted(all_functions.iteritems())]
68
Jeff Gilbert3dddccf2017-11-14 16:44:36 -080069with open(out_file_name, 'wb') as out_file:
Jamie Madill5ad52992017-11-14 12:43:40 -050070 output_cpp = template_cpp.format(
71 script_name = sys.argv[0],
72 data_source_name = data_source_name,
73 copyright_year = date.today().year,
74 proc_data = ",\n".join(proc_data),
75 num_procs = len(proc_data))
76 out_file.write(output_cpp)
77 out_file.close()
78