blob: 52c6852bcc94f6d7b9ee63bf2849c7d26e90aab8 [file] [log] [blame]
Jamie Madill5ad52992017-11-14 12:43:40 -05001#!/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
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"
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"
35#include "libGLESv2/entry_points_gles_3_1.h"
36#include "platform/Platform.h"
37
38#define P(FUNC) reinterpret_cast<__eglMustCastToProperFunctionPointerType>(FUNC)
39
40namespace egl
41{{
42ProcEntry g_procTable[] = {{
43{proc_data}
44}};
45
46size_t g_numProcs = {num_procs};
47}} // namespace egl
48"""
49
50sys.path.append('../libANGLE/renderer')
51import angle_format
52
53json_data = angle_format.load_json(data_source_name)
54
55all_functions = {}
56
57for 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
66proc_data = [(' {"%s", P(%s)}' % (func, angle_func)) for func, angle_func in sorted(all_functions.iteritems())]
67
68with 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