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