2 # gnerate_wrappers.py: Parse header and output libhybris binding code
3 # Adapted for libhybris from apkenv-wrapper-generator
5 # apkenv-wrapper-generator version:
6 # Copyright (C) 2012 Thomas Perl <m@thp.io>; 2012-10-19
9 # Copyright (C) 2013 Jolla Ltd.
10 # Contact: Thomas Perl <thomas.perl@jollamobile.com>
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions are met:
15 # 1. Redistributions of source code must retain the above copyright notice, this
16 # list of conditions and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright notice,
18 # this list of conditions and the following disclaimer in the documentation
19 # and/or other materials provided with the distribution.
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 # Some special cases to to avoid having to parse the full C grammar
42 'GLuint *': 'GLuint *',
43 'GLsizei *': 'GLsizei *',
44 'GLfloat eqn[4]': 'GLfloat[4]',
45 'GLfixed eqn[4]': 'GLfixed[4]',
46 'GLfixed mantissa[16]': 'GLfixed[16]',
47 'GLint exponent[16]': 'GLint[16]',
48 'GLfloat eqn[4]': 'GLfloat[4]',
49 'GLvoid **': 'GLvoid **',
50 'GLfloat *': 'GLfloat *',
51 'GLfixed *': 'GLfixed *',
54 # Never generate wrappers for these functions
59 arg
= arg
.replace('__restrict', '')
60 arg
= arg
.replace('__const', '')
61 arg
= arg
.replace('const', '')
68 def __init__(self
, type_
, name
):
73 def __init__(self
, retval
, name
, args
):
77 self
.parsing_error
= None
78 self
.args
= list(self
._parse
_args
(args
))
80 def _parse_args(self
, args
):
81 for arg
in map(clean_arg
, args
.split(',')):
83 xarg
= re
.match(r
'^(.*?)([A-Za-z0-9_]+)$', arg
)
86 if arg
in FIXED_MAPPINGS
:
87 yield Argument(FIXED_MAPPINGS
[arg
], '__undefined__')
89 self
.parsing_error
= 'Could not parse: ' + repr(arg
)
90 print self
.parsing_error
92 type_
, name
= xarg
.groups()
95 name
= '__undefined__'
96 yield Argument(type_
, name
)
98 if len(sys
.argv
) != 2:
99 print >>sys
.stderr
, """
100 Usage: %s glesv1_functions.h
104 filename
= sys
.argv
[1]
106 for line
in open(filename
):
107 if line
.startswith('/*'):
109 retval
, funcname
, args
= re
.match(r
'^(.+ [*]?)([A-Za-z0-9_]+)\((.*)\);\s*$', line
).groups()
110 retval
, funcname
, args
= [x
.strip() for x
in (retval
, funcname
, args
)]
111 if funcname
not in BLACKLISTED_FUNCS
:
112 funcs
.append(Function(retval
, funcname
, args
))
114 LIBRARY_NAME
= 'glesv1_cm'
116 for function
in funcs
:
117 args
= [a
.type_
.strip() for a
in function
.args
if a
.type_
.strip() not in ('', 'void')]
118 if function
.retval
== 'void':
119 print 'HYBRIS_IMPLEMENT_VOID_FUNCTION%d(%s, %s);' % (len(args
), LIBRARY_NAME
, ', '.join([function
.name
] + args
))
121 print 'HYBRIS_IMPLEMENT_FUNCTION%d(%s, %s, %s);' % (len(args
), LIBRARY_NAME
, function
.retval
, ', '.join([function
.name
] + args
))