X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmapi%2Fmapi_abi.py;h=fd67ba68ef9f142425ac3566fb47df24246d65d5;hb=b9eef27920ca7b670225cdc529f200b30140dc39;hp=e4ce2b6cafde0845c24c97e63e6b60bda40dbf91;hpb=e1b88aee680bbdadd283b4a26db74672bb130df5;p=mesa.git diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index e4ce2b6cafd..fd67ba68ef9 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -29,9 +29,10 @@ from __future__ import print_function import sys # make it possible to import glapi import os -GLAPI = os.path.join(".", os.path.dirname(sys.argv[0]), "glapi/gen") -sys.path.append(GLAPI) +GLAPI = os.path.join(".", os.path.dirname(__file__), "glapi", "gen") +sys.path.insert(0, GLAPI) +from operator import attrgetter import re from optparse import OptionParser import gl_XML @@ -183,75 +184,6 @@ def abi_parse_xml(xml): return entries -def abi_parse_line(line): - cols = [col.strip() for col in line.split(',')] - - attrs = { - 'slot': -1, - 'hidden': False, - 'alias': None, - 'handcode': None, - } - - # extract attributes from the first column - vals = cols[0].split(':') - while len(vals) > 1: - val = vals.pop(0) - if val.startswith('slot='): - attrs['slot'] = int(val[5:]) - elif val == 'hidden': - attrs['hidden'] = True - elif val.startswith('alias='): - attrs['alias'] = val[6:] - elif val.startswith('handcode='): - attrs['handcode'] = val[9:] - elif not val: - pass - else: - raise Exception('unknown attribute %s' % val) - cols[0] = vals[0] - - return (attrs, cols) - -def abi_parse(filename): - """Parse a CSV file for ABI entries.""" - fp = open(filename) if filename != '-' else sys.stdin - lines = [line.strip() for line in fp.readlines() - if not line.startswith('#') and line.strip()] - - entry_dict = {} - next_slot = 0 - for line in lines: - attrs, cols = abi_parse_line(line) - - # post-process attributes - if attrs['alias']: - try: - alias = entry_dict[attrs['alias']] - except KeyError: - raise Exception('failed to alias %s' % attrs['alias']) - if alias.alias: - raise Exception('recursive alias %s' % ent.name) - slot = alias.slot - attrs['alias'] = alias - else: - slot = next_slot - next_slot += 1 - - if attrs['slot'] < 0: - attrs['slot'] = slot - elif attrs['slot'] != slot: - raise Exception('invalid slot in %s' % (line)) - - ent = ABIEntry(cols, attrs) - if ent.name in entry_dict: - raise Exception('%s is duplicated' % (ent.name)) - entry_dict[ent.name] = ent - - entries = sorted(entry_dict.values()) - - return entries - def abi_sanity_check(entries): if not entries: return @@ -290,8 +222,7 @@ class ABIPrinter(object): self.entries = entries # sort entries by their names - self.entries_sorted_by_names = self.entries[:] - self.entries_sorted_by_names.sort(lambda x, y: cmp(x.name, y.name)) + self.entries_sorted_by_names = sorted(self.entries, key=attrgetter('name')) self.indent = ' ' * 3 self.noop_warn = 'noop_warn' @@ -334,7 +265,8 @@ class ABIPrinter(object): if not self.need_entry_point(ent): continue export = self.api_call if not ent.hidden else '' - decls.append(self._c_decl(ent, prefix, True, export) + ';') + if not ent.hidden or not self.lib_need_non_hidden_entries: + decls.append(self._c_decl(ent, prefix, True, export) + ';') return "\n".join(decls) @@ -440,8 +372,7 @@ class ABIPrinter(object): def c_stub_string_pool(self): """Return the string pool for use by stubs.""" # sort entries by their names - sorted_entries = self.entries[:] - sorted_entries.sort(lambda x, y: cmp(x.name, y.name)) + sorted_entries = sorted(self.entries, key=attrgetter('name')) pool = [] offsets = {} @@ -672,70 +603,9 @@ class GLAPIPrinter(ABIPrinter): def _get_c_header(self): header = """#ifndef _GLAPI_TMP_H_ #define _GLAPI_TMP_H_ -#ifdef USE_MGL_NAMESPACE -#define GLAPI_PREFIX(func) mgl##func -#define GLAPI_PREFIX_STR(func) "mgl"#func -#else #define GLAPI_PREFIX(func) gl##func #define GLAPI_PREFIX_STR(func) "gl"#func -#endif /* USE_MGL_NAMESPACE */ -typedef int GLclampx; -#endif /* _GLAPI_TMP_H_ */""" - - return header - -class ES1APIPrinter(GLAPIPrinter): - """OpenGL ES 1.x API Printer""" - - def __init__(self, entries): - super(ES1APIPrinter, self).__init__(entries) - self.prefix_lib = 'gl' - self.prefix_warn = 'gl' - - def _override_for_api(self, ent): - if ent.xml_data is None: - raise Exception('ES2 API printer requires XML input') - ent.hidden = (ent.name not in \ - ent.xml_data.entry_points_for_api_version('es1')) \ - or ent.hidden - ent.handcode = False - - def _get_c_header(self): - header = """#ifndef _GLAPI_TMP_H_ -#define _GLAPI_TMP_H_ -typedef int GLclampx; -#endif /* _GLAPI_TMP_H_ */""" - - return header - -class ES2APIPrinter(GLAPIPrinter): - """OpenGL ES 2.x API Printer""" - - def __init__(self, entries): - super(ES2APIPrinter, self).__init__(entries) - self.prefix_lib = 'gl' - self.prefix_warn = 'gl' - - def _override_for_api(self, ent): - if ent.xml_data is None: - raise Exception('ES2 API printer requires XML input') - ent.hidden = (ent.name not in \ - ent.xml_data.entry_points_for_api_version('es2')) \ - or ent.hidden - - # This is hella ugly. The same-named function in desktop OpenGL is - # hidden, but it needs to be exposed by libGLESv2 for OpenGL ES 3.0. - # There's no way to express in the XML that a function should be be - # hidden in one API but exposed in another. - if ent.name == 'GetInternalformativ': - ent.hidden = False - - ent.handcode = False - - def _get_c_header(self): - header = """#ifndef _GLAPI_TMP_H_ -#define _GLAPI_TMP_H_ typedef int GLclampx; #endif /* _GLAPI_TMP_H_ */""" @@ -771,7 +641,7 @@ typedef int GLclampx; def parse_args(): printers = ['glapi', 'es1api', 'es2api', 'shared-glapi'] - parser = OptionParser(usage='usage: %prog [options] ') + parser = OptionParser(usage='usage: %prog [options] ') parser.add_option('-p', '--printer', dest='printer', help='printer to use: %s' % (", ".join(printers))) @@ -780,22 +650,21 @@ def parse_args(): parser.print_help() sys.exit(1) + if not args[0].endswith('.xml'): + parser.print_help() + sys.exit(1) + return (args[0], options) def main(): printers = { 'glapi': GLAPIPrinter, - 'es1api': ES1APIPrinter, - 'es2api': ES2APIPrinter, 'shared-glapi': SharedGLAPIPrinter, } filename, options = parse_args() - if filename.endswith('.xml'): - entries = abi_parse_xml(filename) - else: - entries = abi_parse(filename) + entries = abi_parse_xml(filename) abi_sanity_check(entries) printer = printers[options.printer](entries)