3 # Mesa 3-D graphics library
6 # Copyright (C) 2010 LunarG Inc.
8 # Permission is hereby granted, free of charge, to any person obtaining a
9 # copy of this software and associated documentation files (the "Software"),
10 # to deal in the Software without restriction, including without limitation
11 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 # and/or sell copies of the Software, and to permit persons to whom the
13 # Software is furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 # DEALINGS IN THE SOFTWARE.
27 # Chia-I Wu <olv@lunarg.com>
30 # make it possible to import glapi
32 GLAPI
= os
.path
.join(".", os
.path
.dirname(sys
.argv
[0]), "glapi/gen")
33 sys
.path
.append(GLAPI
)
36 from optparse
import OptionParser
41 # number of dynamic entries
42 ABI_NUM_DYNAMIC_ENTRIES
= 256
44 class ABIEntry(object):
45 """Represent an ABI entry."""
47 _match_c_param
= re
.compile(
48 '^(?P<type>[\w\s*]+?)(?P<name>\w+)(\[(?P<array>\d+)\])?$')
50 def __init__(self
, cols
, attrs
, xml_data
= None):
53 self
.slot
= attrs
['slot']
54 self
.hidden
= attrs
['hidden']
55 self
.alias
= attrs
['alias']
56 self
.handcode
= attrs
['handcode']
57 self
.xml_data
= xml_data
59 def c_prototype(self
):
60 return '%s %s(%s)' % (self
.c_return(), self
.name
, self
.c_params())
70 """Return the parameter list used in the entry prototype."""
72 for t
, n
, a
in self
.params
:
73 sep
= '' if t
.endswith('*') else ' '
74 arr
= '[%d]' % a
if a
else ''
75 c_params
.append(t
+ sep
+ n
+ arr
)
77 c_params
.append('void')
79 return ", ".join(c_params
)
82 """Return the argument list used in the entry invocation."""
84 for t
, n
, a
in self
.params
:
87 return ", ".join(c_args
)
89 def _parse(self
, cols
):
99 elif len(cols
) == 1 and cols
[0] == 'void':
103 params
.append(self
._parse
_param
(val
))
109 def _parse_param(self
, c_param
):
110 m
= self
._match
_c
_param
.match(c_param
)
112 raise Exception('unrecognized param ' + c_param
)
114 c_type
= m
.group('type').strip()
115 c_name
= m
.group('name')
116 c_array
= m
.group('array')
117 c_array
= int(c_array
) if c_array
else 0
119 return (c_type
, c_name
, c_array
)
122 return self
.c_prototype()
124 def __cmp__(self
, other
):
125 # compare slot, alias, and then name
126 res
= cmp(self
.slot
, other
.slot
)
130 elif not other
.alias
:
134 res
= cmp(self
.name
, other
.name
)
138 def abi_parse_xml(xml
):
139 """Parse a GLAPI XML file for ABI entries."""
140 api
= gl_XML
.parse_GL_API(xml
, glX_XML
.glx_item_factory())
143 for func
in api
.functionIterateByOffset():
144 # make sure func.name appear first
145 entry_points
= func
.entry_points
[:]
146 entry_points
.remove(func
.name
)
147 entry_points
.insert(0, func
.name
)
149 for name
in entry_points
:
152 'hidden': not func
.is_static_entry_point(name
),
153 'alias': None if name
== func
.name
else func
.name
,
154 'handcode': bool(func
.has_different_protocol(name
)),
160 alias
= entry_dict
[attrs
['alias']]
162 raise Exception('failed to alias %s' % attrs
['alias'])
164 raise Exception('recursive alias %s' % ent
.name
)
165 attrs
['alias'] = alias
166 if attrs
['handcode']:
167 attrs
['handcode'] = func
.static_glx_name(name
)
169 attrs
['handcode'] = None
171 if entry_dict
.has_key(name
):
172 raise Exception('%s is duplicated' % (name
))
175 cols
.append(func
.return_type
)
177 params
= func
.get_parameter_string(name
)
178 cols
.extend([p
.strip() for p
in params
.split(',')])
180 ent
= ABIEntry(cols
, attrs
, func
)
181 entry_dict
[ent
.name
] = ent
183 entries
= entry_dict
.values()
188 def abi_parse_line(line
):
189 cols
= [col
.strip() for col
in line
.split(',')]
198 # extract attributes from the first column
199 vals
= cols
[0].split(':')
202 if val
.startswith('slot='):
203 attrs
['slot'] = int(val
[5:])
204 elif val
== 'hidden':
205 attrs
['hidden'] = True
206 elif val
.startswith('alias='):
207 attrs
['alias'] = val
[6:]
208 elif val
.startswith('handcode='):
209 attrs
['handcode'] = val
[9:]
213 raise Exception('unknown attribute %s' % val
)
218 def abi_parse(filename
):
219 """Parse a CSV file for ABI entries."""
220 fp
= open(filename
) if filename
!= '-' else sys
.stdin
221 lines
= [line
.strip() for line
in fp
.readlines()
222 if not line
.startswith('#') and line
.strip()]
227 attrs
, cols
= abi_parse_line(line
)
229 # post-process attributes
232 alias
= entry_dict
[attrs
['alias']]
234 raise Exception('failed to alias %s' % attrs
['alias'])
236 raise Exception('recursive alias %s' % ent
.name
)
238 attrs
['alias'] = alias
243 if attrs
['slot'] < 0:
245 elif attrs
['slot'] != slot
:
246 raise Exception('invalid slot in %s' % (line
))
248 ent
= ABIEntry(cols
, attrs
)
249 if entry_dict
.has_key(ent
.name
):
250 raise Exception('%s is duplicated' % (ent
.name
))
251 entry_dict
[ent
.name
] = ent
253 entries
= entry_dict
.values()
258 def abi_sanity_check(entries
):
263 last_slot
= entries
[-1].slot
265 for slot
in xrange(last_slot
+ 1):
266 if entries
[i
].slot
!= slot
:
267 raise Exception('entries are not ordered by slots')
269 raise Exception('first entry of slot %d aliases %s'
270 % (slot
, entries
[i
].alias
.name
))
272 while i
< len(entries
) and entries
[i
].slot
== slot
:
274 if not handcode
and ent
.handcode
:
275 handcode
= ent
.handcode
276 elif ent
.handcode
!= handcode
:
277 raise Exception('two aliases with handcode %s != %s',
278 ent
.handcode
, handcode
)
280 if ent
.name
in all_names
:
281 raise Exception('%s is duplicated' % (ent
.name
))
282 if ent
.alias
and ent
.alias
.name
not in all_names
:
283 raise Exception('failed to alias %s' % (ent
.alias
.name
))
284 all_names
.append(ent
.name
)
287 raise Exception('there are %d invalid entries' % (len(entries
) - 1))
289 class ABIPrinter(object):
292 def __init__(self
, entries
):
293 self
.entries
= entries
295 # sort entries by their names
296 self
.entries_sorted_by_names
= self
.entries
[:]
297 self
.entries_sorted_by_names
.sort(lambda x
, y
: cmp(x
.name
, y
.name
))
299 self
.indent
= ' ' * 3
300 self
.noop_warn
= 'noop_warn'
301 self
.noop_generic
= 'noop_generic'
302 self
.current_get
= 'entry_current_get'
304 self
.api_defines
= []
305 self
.api_headers
= ['"KHR/khrplatform.h"']
306 self
.api_call
= 'KHRONOS_APICALL'
307 self
.api_entry
= 'KHRONOS_APIENTRY'
308 self
.api_attrs
= 'KHRONOS_APIATTRIBUTES'
312 self
.lib_need_table_size
= True
313 self
.lib_need_noop_array
= True
314 self
.lib_need_stubs
= True
315 self
.lib_need_all_entries
= True
316 self
.lib_need_non_hidden_entries
= False
319 return '/* This file is automatically generated by mapi_abi.py. Do not modify. */'
321 def c_public_includes(self
):
322 """Return includes of the client API headers."""
323 defines
= ['#define ' + d
for d
in self
.api_defines
]
324 includes
= ['#include ' + h
for h
in self
.api_headers
]
325 return "\n".join(defines
+ includes
)
327 def need_entry_point(self
, ent
):
328 """Return True if an entry point is needed for the entry."""
329 # non-handcode hidden aliases may share the entry they alias
330 use_alias
= (ent
.hidden
and ent
.alias
and not ent
.handcode
)
333 def c_public_declarations(self
, prefix
):
334 """Return the declarations of public entry points."""
336 for ent
in self
.entries
:
337 if not self
.need_entry_point(ent
):
339 export
= self
.api_call
if not ent
.hidden
else ''
340 decls
.append(self
._c
_decl
(ent
, prefix
, True, export
) + ';')
342 return "\n".join(decls
)
344 def c_mapi_table(self
):
345 """Return defines of the dispatch table size."""
346 num_static_entries
= self
.entries
[-1].slot
+ 1
347 return ('#define MAPI_TABLE_NUM_STATIC %d\n' + \
348 '#define MAPI_TABLE_NUM_DYNAMIC %d') % (
349 num_static_entries
, ABI_NUM_DYNAMIC_ENTRIES
)
351 def c_mapi_table_initializer(self
, prefix
):
352 """Return the array initializer for mapi_table_fill."""
353 entries
= [self
._c
_function
(ent
, prefix
)
354 for ent
in self
.entries
if not ent
.alias
]
355 pre
= self
.indent
+ '(mapi_proc) '
356 return pre
+ (',\n' + pre
).join(entries
)
358 def c_mapi_table_spec(self
):
359 """Return the spec for mapi_init."""
362 for ent
in self
.entries
:
367 line
+= '%s\\0' % ent
.name
371 return self
.indent
+ self
.indent
.join(specv1
)
373 def _c_function(self
, ent
, prefix
, mangle
=False, stringify
=False):
374 """Return the function name of an entry."""
376 True: { True: '%s_STR(%s)', False: '%s(%s)' },
377 False: { True: '"%s%s"', False: '%s%s' },
379 fmt
= formats
[prefix
.isupper()][stringify
]
381 if mangle
and ent
.hidden
:
382 name
= '_dispatch_stub_' + str(ent
.slot
)
383 return fmt
% (prefix
, name
)
385 def _c_function_call(self
, ent
, prefix
):
386 """Return the function name used for calling."""
388 # _c_function does not handle this case
389 formats
= { True: '%s(%s)', False: '%s%s' }
390 fmt
= formats
[prefix
.isupper()]
391 name
= fmt
% (prefix
, ent
.handcode
)
392 elif self
.need_entry_point(ent
):
393 name
= self
._c
_function
(ent
, prefix
, True)
395 name
= self
._c
_function
(ent
.alias
, prefix
, True)
398 def _c_decl(self
, ent
, prefix
, mangle
=False, export
=''):
399 """Return the C declaration for the entry."""
400 decl
= '%s %s %s(%s)' % (ent
.c_return(), self
.api_entry
,
401 self
._c
_function
(ent
, prefix
, mangle
), ent
.c_params())
403 decl
= export
+ ' ' + decl
405 decl
+= ' ' + self
.api_attrs
409 def _c_cast(self
, ent
):
410 """Return the C cast for the entry."""
411 cast
= '%s (%s *)(%s)' % (
412 ent
.c_return(), self
.api_entry
, ent
.c_params())
416 def c_private_declarations(self
, prefix
):
417 """Return the declarations of private functions."""
418 decls
= [self
._c
_decl
(ent
, prefix
) + ';'
419 for ent
in self
.entries
if not ent
.alias
]
421 return "\n".join(decls
)
423 def c_public_dispatches(self
, prefix
, no_hidden
):
424 """Return the public dispatch functions."""
426 for ent
in self
.entries
:
427 if ent
.hidden
and no_hidden
:
430 if not self
.need_entry_point(ent
):
433 export
= self
.api_call
if not ent
.hidden
else ''
435 proto
= self
._c
_decl
(ent
, prefix
, True, export
)
436 cast
= self
._c
_cast
(ent
)
442 stmt1
+= 'const struct mapi_table *_tbl = %s();' % (
445 stmt2
+= 'mapi_func _func = ((const mapi_func *) _tbl)[%d];' % (
448 stmt3
+= '%s((%s) _func)(%s);' % (ret
, cast
, ent
.c_args())
450 disp
= '%s\n{\n%s\n%s\n%s\n}' % (proto
, stmt1
, stmt2
, stmt3
)
453 disp
= '#if 0\n' + disp
+ '\n#endif'
455 dispatches
.append(disp
)
457 return '\n\n'.join(dispatches
)
459 def c_public_initializer(self
, prefix
):
460 """Return the initializer for public dispatch functions."""
462 for ent
in self
.entries
:
466 name
= '%s(mapi_func) %s' % (self
.indent
,
467 self
._c
_function
_call
(ent
, prefix
))
470 return ',\n'.join(names
)
472 def c_stub_string_pool(self
):
473 """Return the string pool for use by stubs."""
474 # sort entries by their names
475 sorted_entries
= self
.entries
[:]
476 sorted_entries
.sort(lambda x
, y
: cmp(x
.name
, y
.name
))
481 for ent
in sorted_entries
:
483 pool
.append('%s' % (ent
.name
))
484 count
+= len(ent
.name
) + 1
486 pool_str
= self
.indent
+ '"' + \
487 ('\\0"\n' + self
.indent
+ '"').join(pool
) + '";'
488 return (pool_str
, offsets
)
490 def c_stub_initializer(self
, prefix
, pool_offsets
):
491 """Return the initializer for struct mapi_stub array."""
493 for ent
in self
.entries_sorted_by_names
:
494 stubs
.append('%s{ (void *) %d, %d, NULL }' % (
495 self
.indent
, pool_offsets
[ent
], ent
.slot
))
497 return ',\n'.join(stubs
)
499 def c_noop_functions(self
, prefix
, warn_prefix
):
500 """Return the noop functions."""
502 for ent
in self
.entries
:
506 proto
= self
._c
_decl
(ent
, prefix
, False, 'static')
510 for t
, n
, a
in ent
.params
:
511 stmt1
+= "%s(void) %s;" % (space
, n
)
517 stmt1
+= self
.indent
+ '%s(%s);' % (self
.noop_warn
,
518 self
._c
_function
(ent
, warn_prefix
, False, True))
521 stmt2
= self
.indent
+ 'return (%s) 0;' % (ent
.ret
)
522 noop
= '%s\n{\n%s\n%s\n}' % (proto
, stmt1
, stmt2
)
524 noop
= '%s\n{\n%s\n}' % (proto
, stmt1
)
528 return '\n\n'.join(noops
)
530 def c_noop_initializer(self
, prefix
, use_generic
):
531 """Return an initializer for the noop dispatch table."""
532 entries
= [self
._c
_function
(ent
, prefix
)
533 for ent
in self
.entries
if not ent
.alias
]
535 entries
= [self
.noop_generic
] * len(entries
)
537 entries
.extend([self
.noop_generic
] * ABI_NUM_DYNAMIC_ENTRIES
)
539 pre
= self
.indent
+ '(mapi_func) '
540 return pre
+ (',\n' + pre
).join(entries
)
542 def c_asm_gcc(self
, prefix
, no_hidden
):
545 for ent
in self
.entries
:
546 if ent
.hidden
and no_hidden
:
549 if not self
.need_entry_point(ent
):
552 name
= self
._c
_function
(ent
, prefix
, True, True)
558 asm
.append('".hidden "%s"\\n"' % (name
))
560 if ent
.alias
and not (ent
.alias
.hidden
and no_hidden
):
561 asm
.append('".globl "%s"\\n"' % (name
))
562 asm
.append('".set "%s", "%s"\\n"' % (name
,
563 self
._c
_function
(ent
.alias
, prefix
, True, True)))
565 asm
.append('STUB_ASM_ENTRY(%s)"\\n"' % (name
))
566 asm
.append('"\\t"STUB_ASM_CODE("%d")"\\n"' % (ent
.slot
))
572 return "\n".join(asm
)
574 def output_for_lib(self
):
575 print self
.c_notice()
582 print '#ifdef MAPI_TMP_DEFINES'
583 print self
.c_public_includes()
585 print self
.c_public_declarations(self
.prefix_lib
)
586 print '#undef MAPI_TMP_DEFINES'
587 print '#endif /* MAPI_TMP_DEFINES */'
589 if self
.lib_need_table_size
:
591 print '#ifdef MAPI_TMP_TABLE'
592 print self
.c_mapi_table()
593 print '#undef MAPI_TMP_TABLE'
594 print '#endif /* MAPI_TMP_TABLE */'
596 if self
.lib_need_noop_array
:
598 print '#ifdef MAPI_TMP_NOOP_ARRAY'
601 print self
.c_noop_functions(self
.prefix_noop
, self
.prefix_warn
)
603 print 'const mapi_func table_%s_array[] = {' % (self
.prefix_noop
)
604 print self
.c_noop_initializer(self
.prefix_noop
, False)
607 print '#else /* DEBUG */'
609 print 'const mapi_func table_%s_array[] = {' % (self
.prefix_noop
)
610 print self
.c_noop_initializer(self
.prefix_noop
, True)
613 print '#endif /* DEBUG */'
614 print '#undef MAPI_TMP_NOOP_ARRAY'
615 print '#endif /* MAPI_TMP_NOOP_ARRAY */'
617 if self
.lib_need_stubs
:
618 pool
, pool_offsets
= self
.c_stub_string_pool()
620 print '#ifdef MAPI_TMP_PUBLIC_STUBS'
621 print 'static const char public_string_pool[] ='
624 print 'static const struct mapi_stub public_stubs[] = {'
625 print self
.c_stub_initializer(self
.prefix_lib
, pool_offsets
)
627 print '#undef MAPI_TMP_PUBLIC_STUBS'
628 print '#endif /* MAPI_TMP_PUBLIC_STUBS */'
630 if self
.lib_need_all_entries
:
632 print '#ifdef MAPI_TMP_PUBLIC_ENTRIES'
633 print self
.c_public_dispatches(self
.prefix_lib
, False)
635 print 'static const mapi_func public_entries[] = {'
636 print self
.c_public_initializer(self
.prefix_lib
)
638 print '#undef MAPI_TMP_PUBLIC_ENTRIES'
639 print '#endif /* MAPI_TMP_PUBLIC_ENTRIES */'
642 print '#ifdef MAPI_TMP_STUB_ASM_GCC'
644 print self
.c_asm_gcc(self
.prefix_lib
, False)
646 print '#undef MAPI_TMP_STUB_ASM_GCC'
647 print '#endif /* MAPI_TMP_STUB_ASM_GCC */'
649 if self
.lib_need_non_hidden_entries
:
651 for ent
in self
.entries
:
657 print '#ifdef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN'
658 print self
.c_public_dispatches(self
.prefix_lib
, True)
660 print '/* does not need public_entries */'
661 print '#undef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN'
662 print '#endif /* MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN */'
665 print '#ifdef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN'
667 print self
.c_asm_gcc(self
.prefix_lib
, True)
669 print '#undef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN'
670 print '#endif /* MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN */'
672 def output_for_app(self
):
673 print self
.c_notice()
675 print self
.c_private_declarations(self
.prefix_app
)
677 print '#ifdef API_TMP_DEFINE_SPEC'
679 print 'static const char %s_spec[] =' % (self
.prefix_app
)
680 print self
.c_mapi_table_spec()
682 print 'static const mapi_proc %s_procs[] = {' % (self
.prefix_app
)
683 print self
.c_mapi_table_initializer(self
.prefix_app
)
686 print '#endif /* API_TMP_DEFINE_SPEC */'
688 class GLAPIPrinter(ABIPrinter
):
689 """OpenGL API Printer"""
691 def __init__(self
, entries
):
693 self
._override
_for
_api
(ent
)
694 super(GLAPIPrinter
, self
).__init
__(entries
)
696 self
.api_defines
= ['GL_GLEXT_PROTOTYPES']
697 self
.api_headers
= ['"GL/gl.h"', '"GL/glext.h"']
698 self
.api_call
= 'GLAPI'
699 self
.api_entry
= 'APIENTRY'
702 self
.lib_need_table_size
= False
703 self
.lib_need_noop_array
= False
704 self
.lib_need_stubs
= False
705 self
.lib_need_all_entries
= False
706 self
.lib_need_non_hidden_entries
= True
708 self
.prefix_lib
= 'GLAPI_PREFIX'
709 self
.prefix_app
= '_mesa_'
710 self
.prefix_noop
= 'noop'
711 self
.prefix_warn
= self
.prefix_lib
713 self
.c_header
= self
._get
_c
_header
()
715 def _override_for_api(self
, ent
):
716 """Override attributes of an entry if necessary for this
718 # By default, no override is necessary.
721 def _get_c_header(self
):
722 header
= """#ifndef _GLAPI_TMP_H_
723 #define _GLAPI_TMP_H_
724 #ifdef USE_MGL_NAMESPACE
725 #define GLAPI_PREFIX(func) mgl##func
726 #define GLAPI_PREFIX_STR(func) "mgl"#func
728 #define GLAPI_PREFIX(func) gl##func
729 #define GLAPI_PREFIX_STR(func) "gl"#func
730 #endif /* USE_MGL_NAMESPACE */
733 typedef int GLclampx;
734 #endif /* _GLAPI_TMP_H_ */"""
738 class ES1APIPrinter(GLAPIPrinter
):
739 """OpenGL ES 1.x API Printer"""
741 def __init__(self
, entries
):
742 super(ES1APIPrinter
, self
).__init
__(entries
)
743 self
.prefix_lib
= 'gl'
744 self
.prefix_warn
= 'gl'
746 def _override_for_api(self
, ent
):
747 if ent
.xml_data
is None:
748 raise Exception('ES2 API printer requires XML input')
749 ent
.hidden
= ent
.name
not in \
750 ent
.xml_data
.entry_points_for_api_version('es1')
753 def _get_c_header(self
):
754 header
= """#ifndef _GLAPI_TMP_H_
755 #define _GLAPI_TMP_H_
757 typedef int GLclampx;
758 #endif /* _GLAPI_TMP_H_ */"""
762 class ES2APIPrinter(GLAPIPrinter
):
763 """OpenGL ES 2.x API Printer"""
765 def __init__(self
, entries
):
766 super(ES2APIPrinter
, self
).__init
__(entries
)
767 self
.prefix_lib
= 'gl'
768 self
.prefix_warn
= 'gl'
770 def _override_for_api(self
, ent
):
771 if ent
.xml_data
is None:
772 raise Exception('ES2 API printer requires XML input')
773 ent
.hidden
= ent
.name
not in \
774 ent
.xml_data
.entry_points_for_api_version('es2')
777 def _get_c_header(self
):
778 header
= """#ifndef _GLAPI_TMP_H_
779 #define _GLAPI_TMP_H_
781 typedef int GLclampx;
782 #endif /* _GLAPI_TMP_H_ */"""
786 class SharedGLAPIPrinter(GLAPIPrinter
):
787 """Shared GLAPI API Printer"""
789 def __init__(self
, entries
):
790 super(SharedGLAPIPrinter
, self
).__init
__(entries
)
792 self
.lib_need_table_size
= True
793 self
.lib_need_noop_array
= True
794 self
.lib_need_stubs
= True
795 self
.lib_need_all_entries
= True
796 self
.lib_need_non_hidden_entries
= False
798 self
.prefix_lib
= 'shared'
799 self
.prefix_warn
= 'gl'
801 def _override_for_api(self
, ent
):
805 def _get_c_header(self
):
806 header
= """#ifndef _GLAPI_TMP_H_
807 #define _GLAPI_TMP_H_
809 typedef int GLclampx;
810 #endif /* _GLAPI_TMP_H_ */"""
814 class VGAPIPrinter(ABIPrinter
):
815 """OpenVG API Printer"""
817 def __init__(self
, entries
):
818 super(VGAPIPrinter
, self
).__init
__(entries
)
820 self
.api_defines
= ['VG_VGEXT_PROTOTYPES']
821 self
.api_headers
= ['"VG/openvg.h"', '"VG/vgext.h"']
822 self
.api_call
= 'VG_API_CALL'
823 self
.api_entry
= 'VG_API_ENTRY'
824 self
.api_attrs
= 'VG_API_EXIT'
826 self
.prefix_lib
= 'vg'
827 self
.prefix_app
= 'vega'
828 self
.prefix_noop
= 'noop'
829 self
.prefix_warn
= 'vg'
832 printers
= ['vgapi', 'glapi', 'es1api', 'es2api', 'shared-glapi']
833 modes
= ['lib', 'app']
835 parser
= OptionParser(usage
='usage: %prog [options] <filename>')
836 parser
.add_option('-p', '--printer', dest
='printer',
837 help='printer to use: %s' % (", ".join(printers
)))
838 parser
.add_option('-m', '--mode', dest
='mode',
839 help='target user: %s' % (", ".join(modes
)))
841 options
, args
= parser
.parse_args()
842 if not args
or options
.printer
not in printers
or \
843 options
.mode
not in modes
:
847 return (args
[0], options
)
851 'vgapi': VGAPIPrinter
,
852 'glapi': GLAPIPrinter
,
853 'es1api': ES1APIPrinter
,
854 'es2api': ES2APIPrinter
,
855 'shared-glapi': SharedGLAPIPrinter
,
858 filename
, options
= parse_args()
860 if filename
.endswith('.xml'):
861 entries
= abi_parse_xml(filename
)
863 entries
= abi_parse(filename
)
864 abi_sanity_check(entries
)
866 printer
= printers
[options
.printer
](entries
)
867 if options
.mode
== 'lib':
868 printer
.output_for_lib()
870 printer
.output_for_app()
872 if __name__
== '__main__':