3 # Copyright (C) 2010 LunarG Inc.
4 # (C) Copyright 2015, NVIDIA CORPORATION.
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
25 # Kyle Brenneman <kbrenneman@nvidia.com>
27 # Based on code ogiginally by:
28 # Chia-I Wu <olv@lunarg.com>
32 Generates the glapi_mapi_tmp.h header file from Khronos's XML file.
36 import xml
.etree
.cElementTree
as etree
42 xmlFiles
= sys
.argv
[2:]
44 roots
= [ etree
.parse(filename
).getroot() for filename
in xmlFiles
]
45 allFunctions
= genCommon
.getFunctionsFromRoots(roots
)
47 names
= genCommon
.getExportNamesFromRoots(target
, roots
)
48 functions
= [f
for f
in allFunctions
if(f
.name
in names
)]
50 if (target
in ("gl", "gldispatch")):
51 assert(len(functions
) == len(allFunctions
))
52 assert(all(functions
[i
] == allFunctions
[i
] for i
in range(len(functions
))))
53 assert(all(functions
[i
].slot
== i
for i
in range(len(functions
))))
56 /* This file is automatically generated by mapi_abi.py. Do not modify. */
61 typedef void (APIENTRY *GLDEBUGPROCKHR)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
62 #endif /* _GLAPI_TMP_H_ */
65 print(generate_defines(functions
))
66 if target
== "gldispatch":
67 print(generate_table(functions
, allFunctions
))
68 print(generate_noop_array(functions
))
69 print(generate_public_stubs(functions
))
70 print(generate_public_entries(functions
))
71 if target
== "gldispatch":
72 print(generate_public_entries_table(functions
))
73 print(generate_undef_public_entries())
74 print(generate_stub_asm_gcc(functions
))
76 def generate_defines(functions
):
78 #ifdef MAPI_TMP_DEFINES
79 #define GL_GLEXT_PROTOTYPES
84 for func
in functions
:
85 text
+= "GLAPI {f.rt} APIENTRY {f.name}({f.decArgs});\n".format(f
=func
)
86 text
+= "#undef MAPI_TMP_DEFINES\n"
87 text
+= "#endif /* MAPI_TMP_DEFINES */\n"
90 def generate_table(functions
, allFunctions
):
91 text
= "#ifdef MAPI_TMP_TABLE\n"
92 text
+= "#define MAPI_TABLE_NUM_STATIC %d\n" % (len(allFunctions
))
93 text
+= "#define MAPI_TABLE_NUM_DYNAMIC %d\n" % (genCommon
.MAPI_TABLE_NUM_DYNAMIC
,)
94 text
+= "#undef MAPI_TMP_TABLE\n"
95 text
+= "#endif /* MAPI_TMP_TABLE */\n"
98 def generate_noop_array(functions
):
99 text
= "#ifdef MAPI_TMP_NOOP_ARRAY\n"
100 text
+= "#ifdef DEBUG\n\n"
102 for func
in functions
:
103 text
+= "static {f.rt} APIENTRY noop{f.basename}({f.decArgs})\n".format(f
=func
)
105 if (len(func
.args
) > 0):
107 for arg
in func
.args
:
108 text
+= " (void) {a.name};".format(a
=arg
)
110 text
+= " noop_warn(\"{f.name}\");\n".format(f
=func
)
111 if (func
.hasReturn()):
112 text
+= " return ({f.rt}) 0;\n".format(f
=func
)
115 text
+= "const mapi_func table_noop_array[] = {\n"
116 for func
in functions
:
117 text
+= " (mapi_func) noop{f.basename},\n".format(f
=func
)
118 for i
in range(genCommon
.MAPI_TABLE_NUM_DYNAMIC
- 1):
119 text
+= " (mapi_func) noop_generic,\n"
120 text
+= " (mapi_func) noop_generic\n"
122 text
+= "#else /* DEBUG */\n\n"
123 text
+= "const mapi_func table_noop_array[] = {\n"
124 for i
in range(len(functions
) + genCommon
.MAPI_TABLE_NUM_DYNAMIC
- 1):
125 text
+= " (mapi_func) noop_generic,\n"
126 text
+= " (mapi_func) noop_generic\n"
129 text
+= "#endif /* DEBUG */\n"
130 text
+= "#undef MAPI_TMP_NOOP_ARRAY\n"
131 text
+= "#endif /* MAPI_TMP_NOOP_ARRAY */\n"
134 def generate_public_stubs(functions
):
135 text
= "#ifdef MAPI_TMP_PUBLIC_STUBS\n"
137 text
+= "static const struct mapi_stub public_stubs[] = {\n"
138 for func
in functions
:
139 text
+= " { \"%s\", %d, NULL },\n" % (func
.name
, func
.slot
)
141 text
+= "#undef MAPI_TMP_PUBLIC_STUBS\n"
142 text
+= "#endif /* MAPI_TMP_PUBLIC_STUBS */\n"
145 def generate_public_entries(functions
):
146 text
= "#ifdef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN\n"
148 for func
in functions
:
149 retStr
= ("return " if func
.hasReturn() else "")
151 GLAPI {f.rt} APIENTRY {f.name}({f.decArgs})
153 const struct _glapi_table *_tbl = entry_current_get();
154 mapi_func _func = ((const mapi_func *) _tbl)[{f.slot}];
155 {retStr}(({f.rt} (APIENTRY *)({f.decArgs})) _func)({f.callArgs});
158 """.lstrip("\n").format(f
=func
, retStr
=retStr
)
161 text
+= "#endif /* MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN */\n"
164 def generate_public_entries_table(functions
):
165 text
= "#ifdef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN\n"
166 text
+= "static const mapi_func public_entries[] = {\n"
167 for func
in functions
:
168 text
+= " (mapi_func) %s,\n" % (func
.name
,)
170 text
+= "#endif /* MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN */\n"
173 def generate_undef_public_entries():
174 text
= "#ifdef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN\n"
175 text
+= "#undef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN\n"
176 text
+= "#endif /* MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN */\n"
179 def generate_stub_asm_gcc(functions
):
180 text
= "#ifdef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN\n"
183 for func
in functions
:
184 text
+= 'STUB_ASM_ENTRY("%s")"\\n"\n' % (func
.name
,)
185 text
+= '"\\t"STUB_ASM_CODE("%d")"\\n"\n\n' % (func
.slot
,)
188 text
+= "#undef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN\n"
189 text
+= "#endif /* MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN */\n"
192 if (__name__
== "__main__"):