summaryrefslogtreecommitdiff
path: root/src/mapi/mapi
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapi/mapi')
-rw-r--r--src/mapi/mapi/entry_x86-64_tls.h17
-rw-r--r--src/mapi/mapi/entry_x86_tls.h15
-rw-r--r--src/mapi/mapi/mapi.c7
-rw-r--r--src/mapi/mapi/mapi_abi.py449
-rw-r--r--src/mapi/mapi/mapi_tmp.h180
-rw-r--r--src/mapi/mapi/sources.mak14
-rw-r--r--src/mapi/mapi/stub.c34
-rw-r--r--src/mapi/mapi/table.h8
-rw-r--r--src/mapi/mapi/u_current.c41
-rw-r--r--src/mapi/mapi/u_current.h50
-rw-r--r--src/mapi/mapi/u_thread.c6
-rw-r--r--src/mapi/mapi/u_thread.h6
12 files changed, 400 insertions, 427 deletions
diff --git a/src/mapi/mapi/entry_x86-64_tls.h b/src/mapi/mapi/entry_x86-64_tls.h
index 2fbe73b5b3..2c02933802 100644
--- a/src/mapi/mapi/entry_x86-64_tls.h
+++ b/src/mapi/mapi/entry_x86-64_tls.h
@@ -30,10 +30,23 @@
#include "u_execmem.h"
#include "u_macros.h"
+#ifdef __linux__
+__asm__(".section .note.ABI-tag, \"a\"\n\t"
+ ".p2align 2\n\t"
+ ".long 1f - 0f\n\t" /* name length */
+ ".long 3f - 2f\n\t" /* data length */
+ ".long 1\n\t" /* note length */
+ "0: .asciz \"GNU\"\n\t" /* vendor name */
+ "1: .p2align 2\n\t"
+ "2: .long 0\n\t" /* note data: the ABI tag */
+ ".long 2,4,20\n\t" /* Minimum kernel version w/TLS */
+ "3: .p2align 2\n\t"); /* pad out section */
+#endif /* __linux__ */
+
__asm__(".text");
__asm__("x86_64_current_tls:\n\t"
- "movq u_current_table_tls@GOTTPOFF(%rip), %rax\n\t"
+ "movq u_current_table@GOTTPOFF(%rip), %rax\n\t"
"ret");
#define STUB_ASM_ENTRY(func) \
@@ -43,7 +56,7 @@ __asm__("x86_64_current_tls:\n\t"
func ":"
#define STUB_ASM_CODE(slot) \
- "movq u_current_table_tls@GOTTPOFF(%rip), %rax\n\t" \
+ "movq u_current_table@GOTTPOFF(%rip), %rax\n\t" \
"movq %fs:(%rax), %r11\n\t" \
"jmp *(8 * " slot ")(%r11)"
diff --git a/src/mapi/mapi/entry_x86_tls.h b/src/mapi/mapi/entry_x86_tls.h
index d4f7d98cf1..3d0b7caffe 100644
--- a/src/mapi/mapi/entry_x86_tls.h
+++ b/src/mapi/mapi/entry_x86_tls.h
@@ -30,6 +30,19 @@
#include "u_execmem.h"
#include "u_macros.h"
+#ifdef __linux__
+__asm__(".section .note.ABI-tag, \"a\"\n\t"
+ ".p2align 2\n\t"
+ ".long 1f - 0f\n\t" /* name length */
+ ".long 3f - 2f\n\t" /* data length */
+ ".long 1\n\t" /* note length */
+ "0: .asciz \"GNU\"\n\t" /* vendor name */
+ "1: .p2align 2\n\t"
+ "2: .long 0\n\t" /* note data: the ABI tag */
+ ".long 2,4,20\n\t" /* Minimum kernel version w/TLS */
+ "3: .p2align 2\n\t"); /* pad out section */
+#endif /* __linux__ */
+
__asm__(".text");
__asm__("x86_current_tls:\n\t"
@@ -37,7 +50,7 @@ __asm__("x86_current_tls:\n\t"
"1:\n\t"
"popl %eax\n\t"
"addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t"
- "movl u_current_table_tls@GOTNTPOFF(%eax), %eax\n\t"
+ "movl u_current_table@GOTNTPOFF(%eax), %eax\n\t"
"ret");
#ifndef GLX_X86_READONLY_TEXT
diff --git a/src/mapi/mapi/mapi.c b/src/mapi/mapi/mapi.c
index 2f1c3fff6c..5476d37fdc 100644
--- a/src/mapi/mapi/mapi.c
+++ b/src/mapi/mapi/mapi.c
@@ -36,8 +36,7 @@
#include "table.h"
/* dynamic stubs will run out before this array */
-#define MAPI_MAX_STUBS (sizeof(struct mapi_table) / sizeof(mapi_func))
-static const struct mapi_stub *mapi_stub_map[MAPI_MAX_STUBS];
+static const struct mapi_stub *mapi_stub_map[MAPI_TABLE_NUM_SLOTS];
static int mapi_num_stubs;
static const struct mapi_stub *
@@ -145,9 +144,9 @@ mapi_table_create(void)
const struct mapi_table *noop = table_get_noop();
struct mapi_table *tbl;
- tbl = malloc(sizeof(*tbl));
+ tbl = malloc(MAPI_TABLE_SIZE);
if (tbl)
- memcpy(tbl, noop, sizeof(*tbl));
+ memcpy(tbl, noop, MAPI_TABLE_SIZE);
return tbl;
}
diff --git a/src/mapi/mapi/mapi_abi.py b/src/mapi/mapi/mapi_abi.py
index 440eb4bb9c..3a872666f9 100644
--- a/src/mapi/mapi/mapi_abi.py
+++ b/src/mapi/mapi/mapi_abi.py
@@ -202,201 +202,360 @@ def abi_parse(filename):
return entries
-def abi_dynamics():
- """Return the dynamic entries."""
- entries = []
- for i in xrange(ABI_NUM_DYNAMIC_ENTRIES):
- cols = ['void', 'dynamic%d' % (i), 'void']
- attrs = { 'slot': -1, 'hidden': False, 'alias': None }
- entries.append(ABIEntry(cols, attrs))
- return entries
-
class ABIPrinter(object):
- """ABIEntry Printer"""
+ """MAPI Printer"""
- def __init__(self, entries, options):
+ def __init__(self, entries):
self.entries = entries
- self.options = options
- self._undefs = []
- def _add_undefs(self, undefs):
- self._undefs.extend(undefs)
+ # 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))
- def output_header(self):
- print '/* This file is automatically generated. Do not modify. */'
- print
+ self.indent = ' ' * 3
+ self.noop_warn = 'noop_warn'
+ self.noop_generic = 'noop_generic'
- def output_footer(self):
- print '/* clean up */'
- for m in self._undefs:
- print '#undef %s' % (m)
+ self.api_defines = []
+ self.api_headers = ['"KHR/khrplatform.h"']
+ self.api_call = 'KHRONOS_APICALL'
+ self.api_entry = 'KHRONOS_APIENTRY'
+ self.api_attrs = 'KHRONOS_APIATTRIBUTES'
- def output_entry(self, ent):
- if ent.slot < 0:
- out_ent = 'MAPI_DYNAMIC_ENTRY(%s, %s, (%s))' % \
- (ent.c_return(), ent.name, ent.c_params())
- out_code = ''
- else:
+ def c_header(self):
+ return '/* This file is automatically generated by mapi_abi.py. Do not modify. */'
+
+ def c_includes(self):
+ """Return includes of the client API headers."""
+ defines = ['#define ' + d for d in self.api_defines]
+ includes = ['#include ' + h for h in self.api_headers]
+ return "\n".join(defines + includes)
+
+ def c_mapi_table(self):
+ """Return defines of the dispatch table size."""
+ num_static_entries = 0
+ for ent in self.entries:
+ if not ent.alias:
+ num_static_entries += 1
+
+ return ('#define MAPI_TABLE_NUM_STATIC %d\n' + \
+ '#define MAPI_TABLE_NUM_DYNAMIC %d') % (
+ num_static_entries, ABI_NUM_DYNAMIC_ENTRIES)
+
+ def c_mapi_table_initializer(self, prefix):
+ """Return the array initializer for mapi_table_fill."""
+ entries = [ent.name for ent in self.entries if not ent.alias]
+ pre = self.indent + '(mapi_proc) ' + prefix
+ return pre + (',\n' + pre).join(entries)
+
+ def c_mapi_table_spec(self):
+ """Return the spec for mapi_init."""
+ specv1 = []
+ line = '"1'
+ for ent in self.entries:
+ if not ent.alias:
+ line += '\\0"\n'
+ specv1.append(line)
+ line = '"'
+ line += '%s\\0' % ent.name
+ line += '";'
+ specv1.append(line)
+
+ return self.indent + self.indent.join(specv1)
+
+ def _c_decl(self, ent, prefix, need_attr=True):
+ """Return the C declaration for the entry."""
+ decl = '%s %s %s%s(%s)' % (ent.c_return(), self.api_entry,
+ prefix, ent.name, ent.c_params())
+ if need_attr and self.api_attrs:
+ decl += ' ' + self.api_attrs
+
+ return decl
+
+ def _c_cast(self, ent):
+ """Return the C cast for the entry."""
+ cast = '%s (%s *)(%s)' % (
+ ent.c_return(), self.api_entry, ent.c_params())
+
+ return cast
+
+ def c_private_declarations(self, prefix):
+ """Return the declarations of private functions."""
+ decls = [self._c_decl(ent, prefix)
+ for ent in self.entries if not ent.alias]
+
+ return ";\n".join(decls) + ";"
+
+ def c_public_dispatches(self, prefix):
+ """Return the public dispatch functions."""
+ dispatches = []
+ for ent in self.entries:
+ if ent.hidden:
+ continue
+
+ proto = self.api_call + ' ' + self._c_decl(ent, prefix)
+ cast = self._c_cast(ent)
+
+ ret = ''
+ if ent.ret:
+ ret = 'return '
+ stmt1 = self.indent
+ stmt1 += 'const struct mapi_table *tbl = u_current_get();'
+ stmt2 = self.indent
+ stmt2 += 'mapi_func func = ((const mapi_func *) tbl)[%d];' % (
+ ent.slot)
+ stmt3 = self.indent
+ stmt3 += '%s((%s) func)(%s);' % (ret, cast, ent.c_args())
+
+ disp = '%s\n{\n%s\n%s\n%s\n}' % (proto, stmt1, stmt2, stmt3)
+ dispatches.append(disp)
+
+ return '\n\n'.join(dispatches)
+
+ 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))
+
+ pool = []
+ offsets = {}
+ count = 0
+ for ent in sorted_entries:
+ offsets[ent] = count
+ pool.append('%s' % (ent.name))
+ count += len(ent.name) + 1
+
+ pool_str = self.indent + '"' + \
+ ('\\0"\n' + self.indent + '"').join(pool) + '";'
+ return (pool_str, offsets)
+
+ def c_stub_initializer(self, prefix, pool_offsets):
+ """Return the initializer for struct mapi_stub array."""
+ stubs = []
+ for ent in self.entries_sorted_by_names:
+ stubs.append('%s{ (mapi_func) %s%s, %d, (void *) %d }' % (
+ self.indent, prefix, ent.name, ent.slot, pool_offsets[ent]))
+
+ return ',\n'.join(stubs)
+
+ def c_noop_functions(self, prefix, warn_prefix):
+ """Return the noop functions."""
+ noops = []
+ for ent in self.entries:
if ent.alias:
- macro_ent = 'MAPI_ALIAS_ENTRY'
- macro_code = 'MAPI_ALIAS_CODE'
- else:
- macro_ent = 'MAPI_ABI_ENTRY'
- macro_code = 'MAPI_ABI_CODE'
+ continue
+
+ proto = 'static ' + self._c_decl(ent, prefix)
+
+ stmt1 = self.indent + '%s("%s%s");' % (
+ self.noop_warn, warn_prefix, ent.name)
if ent.ret:
- macro_code += '_RETURN'
+ stmt2 = self.indent + 'return (%s) 0;' % (ent.ret)
+ noop = '%s\n{\n%s\n%s\n}' % (proto, stmt1, stmt2)
+ else:
+ noop = '%s\n{\n%s\n}' % (proto, stmt1)
+
+ noops.append(noop)
+
+ return '\n\n'.join(noops)
+
+ def c_noop_initializer(self, prefix, use_generic):
+ """Return an initializer for the noop dispatch table."""
+ entries = [prefix + ent.name for ent in self.entries if not ent.alias]
+ if use_generic:
+ entries = [self.noop_generic] * len(entries)
+
+ entries.extend([self.noop_generic] * ABI_NUM_DYNAMIC_ENTRIES)
+
+ pre = self.indent + '(mapi_func) '
+ return pre + (',\n' + pre).join(entries)
+
+ def c_asm_gcc(self, prefix):
+ asm = []
+ to_name = None
+
+ asm.append('__asm__(')
+ for ent in self.entries:
+ name = prefix + ent.name
+
if ent.hidden:
- macro_ent += '_HIDDEN'
- macro_code += '_HIDDEN'
+ asm.append('".hidden %s\\n"' % (name))
if ent.alias:
- out_ent = '%s(%s, %s, %s, (%s))' % (macro_ent,
- ent.alias, ent.c_return(), ent.name, ent.c_params())
- out_code = '%s(%s, %s, %s, (%s))' % (macro_code,
- ent.alias, ent.c_return(), ent.name, ent.c_args())
- else:
- out_ent = '%s(%s, %s, (%s))' % (macro_ent,
- ent.c_return(), ent.name, ent.c_params())
- out_code = '%s(%s, %s, (%s))' % (macro_code,
- ent.c_return(), ent.name, ent.c_args())
-
- print out_ent
- if out_code:
- print ' ' + out_code
-
- def output_entries(self, pool_offsets):
- defs = [
- # normal entries
- ('MAPI_ABI_ENTRY', '(ret, name, params)', ''),
- ('MAPI_ABI_CODE', '(ret, name, args)', ''),
- ('MAPI_ABI_CODE_RETURN', '', 'MAPI_ABI_CODE'),
- # alias entries
- ('MAPI_ALIAS_ENTRY', '(alias, ret, name, params)', ''),
- ('MAPI_ALIAS_CODE', '(alias, ret, name, args)', ''),
- ('MAPI_ALIAS_CODE_RETURN', '', 'MAPI_ALIAS_CODE'),
- # hidden normal entries
- ('MAPI_ABI_ENTRY_HIDDEN', '', 'MAPI_ABI_ENTRY'),
- ('MAPI_ABI_CODE_HIDDEN', '', 'MAPI_ABI_CODE'),
- ('MAPI_ABI_CODE_RETURN_HIDDEN', '', 'MAPI_ABI_CODE_RETURN'),
- # hidden alias entries
- ('MAPI_ALIAS_ENTRY_HIDDEN', '', 'MAPI_ALIAS_ENTRY'),
- ('MAPI_ALIAS_CODE_HIDDEN', '', 'MAPI_ALIAS_CODE'),
- ('MAPI_ALIAS_CODE_RETURN_HIDDEN', '', 'MAPI_ALIAS_CODE_RETURN'),
- # dynamic entries
- ('MAPI_DYNAMIC_ENTRY', '(ret, name, params)', ''),
- ]
- undefs = [d[0] for d in defs]
-
- print '#if defined(MAPI_ABI_ENTRY) || defined(MAPI_ABI_ENTRY_HIDDEN)'
- print
- for d in defs:
- print '#ifndef %s' % (d[0])
- if d[2]:
- print '#define %s%s %s' % d
+ asm.append('".globl %s\\n"' % (name))
+ asm.append('".set %s, %s\\n"' % (name, to_name))
else:
- print '#define %s%s' % d[:2]
+ asm.append('STUB_ASM_ENTRY("%s")"\\n"' % (name))
+ asm.append('"\\t"STUB_ASM_CODE("%d")"\\n"' % (ent.slot))
+ to_name = name
+ asm.append(');')
- print '#endif'
+ return "\n".join(asm)
+
+ def output_for_lib(self):
+ print self.c_header()
+ print
+ print '#ifdef MAPI_TMP_DEFINES'
+ print self.c_includes()
+ print '#undef MAPI_TMP_DEFINES'
+ print '#endif /* MAPI_TMP_DEFINES */'
+ print
+ print '#ifdef MAPI_TMP_TABLE'
+ print self.c_mapi_table()
+ print '#undef MAPI_TMP_TABLE'
+ print '#endif /* MAPI_TMP_TABLE */'
print
- print '/* see MAPI_TMP_TABLE */'
- for ent in self.entries:
- print '#define MAPI_SLOT_%s %d' % (ent.name, ent.slot)
+ pool, pool_offsets = self.c_stub_string_pool()
+ print '#ifdef MAPI_TMP_PUBLIC_STUBS'
+ print 'static const char public_string_pool[] ='
+ print pool
print
- print '/* see MAPI_TMP_PUBLIC_STUBS */'
- for ent in self.entries:
- print '#define MAPI_POOL_%s %d' % (ent.name, pool_offsets[ent])
+ print 'static const struct mapi_stub public_stubs[] = {'
+ print self.c_stub_initializer(self.prefix_lib, pool_offsets)
+ print '};'
+ print '#undef MAPI_TMP_PUBLIC_STUBS'
+ print '#endif /* MAPI_TMP_PUBLIC_STUBS */'
print
- # define macros that generate code
- for ent in self.entries:
- self.output_entry(ent)
+ print '#ifdef MAPI_TMP_PUBLIC_ENTRIES'
+ print self.c_public_dispatches(self.prefix_lib)
+ print '#undef MAPI_TMP_PUBLIC_ENTRIES'
+ print '#endif /* MAPI_TMP_PUBLIC_ENTRIES */'
+ print
+
+ print '#ifdef MAPI_TMP_NOOP_ARRAY'
+ print '#ifdef DEBUG'
+ print
+ print self.c_noop_functions(self.prefix_noop, self.prefix_lib)
print
- dynamics = abi_dynamics()
- for ent in dynamics:
- self.output_entry(ent)
+ print 'const mapi_func table_%s_array[] = {' % (self.prefix_noop)
+ print self.c_noop_initializer(self.prefix_noop, False)
+ print '};'
+ print
+ print '#else /* DEBUG */'
+ print
+ print 'const mapi_func table_%s_array[] = {' % (self.prefix_noop)
+ print self.c_noop_initializer(self.prefix_noop, True)
+ print '};'
+ print '#endif /* DEBUG */'
+ print '#undef MAPI_TMP_NOOP_ARRAY'
+ print '#endif /* MAPI_TMP_NOOP_ARRAY */'
print
- for ent in self.entries:
- print '#undef MAPI_SLOT_%s' % (ent.name)
- for ent in self.entries:
- print '#undef MAPI_POOL_%s' % (ent.name)
+ print '#ifdef MAPI_TMP_STUB_ASM_GCC'
+ print self.c_asm_gcc(self.prefix_lib)
+ print '#undef MAPI_TMP_STUB_ASM_GCC'
+ print '#endif /* MAPI_TMP_STUB_ASM_GCC */'
+
+ def output_for_app(self):
+ print self.c_header()
+ print
+ print self.c_private_declarations(self.prefix_app)
print
- print '#endif /* defined(MAPI_ABI_ENTRY) || defined(MAPI_ABI_ENTRY_HIDDEN) */'
+ print '#ifdef API_TMP_DEFINE_SPEC'
print
+ print 'static const char %s_spec[] =' % (self.prefix_app)
+ print self.c_mapi_table_spec()
+ print
+ print 'static const mapi_proc %s_procs[] = {' % (self.prefix_app)
+ print self.c_mapi_table_initializer(self.prefix_app)
+ print '};'
+ print
+ print '#endif /* API_TMP_DEFINE_SPEC */'
- self._add_undefs(undefs)
+class GLAPIPrinter(ABIPrinter):
+ """OpenGL API Printer"""
- def _get_string_pool(self):
- """Get the string pool."""
- pool = []
- offsets = {}
+ def __init__(self, entries):
+ super(GLAPIPrinter, self).__init__(entries)
- count = 0
- for ent in self.entries:
- offsets[ent] = count
- pool.append(ent.name + '\\0')
- count += len(ent.name) + 1
+ self.api_defines = ['GL_GLEXT_PROTOTYPES']
+ self.api_headers = ['"GL/gl.h"', '"GL/glext.h"']
+ self.api_call = 'GLAPI'
+ self.api_entry = 'APIENTRY'
+ self.api_attrs = ''
- return (pool, offsets)
+ self.prefix_lib = 'gl'
+ self.prefix_app = '_mesa_'
+ self.prefix_noop = 'noop'
- def output_sorted_indices(self):
- entry_index_pairs = []
- for i in xrange(len(self.entries)):
- entry_index_pairs.append((self.entries[i], i))
- entry_index_pairs.sort(lambda x, y: cmp(x[0].name, y[0].name))
+ def output_for_app(self):
+ # not used
+ pass
- print '/* see MAPI_TMP_PUBLIC_STUBS */'
- print '#ifdef MAPI_ABI_SORTED_INDICES'
- print
- print 'static const int MAPI_ABI_SORTED_INDICES[] = {'
- for ent, idx in entry_index_pairs:
- print ' %d, /* %s */' % (idx, ent.name)
- print ' -1'
- print '};'
- print
- print '#endif /* MAPI_ABI_SORTED_INDICES */'
- print
+class ES1APIPrinter(GLAPIPrinter):
+ """OpenGL ES 1.x API Printer"""
- self._add_undefs(['MAPI_ABI_SORTED_INDICES'])
+ def __init__(self, entries):
+ super(ES1APIPrinter, self).__init__(entries)
- def output_defines(self):
- print '/* ABI defines */'
- print '#ifdef MAPI_ABI_DEFINES'
- print '#include "%s"' % (self.options.include)
- print '#endif /* MAPI_ABI_DEFINES */'
- print
+ self.api_headers = ['"GLES/gl.h"', '"GLES/glext.h"']
+ self.api_call = 'GL_API'
+ self.api_entry = 'GL_APIENTRY'
+
+class ES2APIPrinter(GLAPIPrinter):
+ """OpenGL ES 2.x API Printer"""
+
+ def __init__(self, entries):
+ super(ES2APIPrinter, self).__init__(entries)
+
+ self.api_headers = ['"GLES2/gl2.h"', '"GLES2/gl2ext.h"']
+ self.api_call = 'GL_APICALL'
+ self.api_entry = 'GL_APIENTRY'
- self._add_undefs(['MAPI_ABI_DEFINES'])
+class VGAPIPrinter(ABIPrinter):
+ """OpenVG API Printer"""
- def output(self):
- pool, pool_offsets = self._get_string_pool()
+ def __init__(self, entries):
+ super(VGAPIPrinter, self).__init__(entries)
- self.output_header()
- self.output_defines()
- self.output_entries(pool_offsets)
- self.output_sorted_indices()
- self.output_footer()
+ self.api_defines = ['VG_VGEXT_PROTOTYPES']
+ self.api_headers = ['"VG/openvg.h"', '"VG/vgext.h"']
+ self.api_call = 'VG_API_CALL'
+ self.api_entry = 'VG_API_ENTRY'
+ self.api_attrs = 'VG_API_EXIT'
+
+ self.prefix_lib = 'vg'
+ self.prefix_app = 'vega'
+ self.prefix_noop = 'noop'
def parse_args():
+ printers = ['glapi', 'es1api', 'es2api', 'vgapi']
+ modes = ['lib', 'app']
+
parser = OptionParser(usage='usage: %prog [options] <filename>')
- parser.add_option('-i', '--include', dest='include',
- help='include the header for API defines')
+ parser.add_option('-p', '--printer', dest='printer',
+ help='printer to use: %s' % (", ".join(printers)))
+ parser.add_option('-m', '--mode', dest='mode',
+ help='target user: %s' % (", ".join(modes)))
options, args = parser.parse_args()
- if not args or not options.include:
+ if not args or options.printer not in printers or \
+ options.mode not in modes:
parser.print_help()
sys.exit(1)
return (args[0], options)
def main():
+ printers = {
+ 'vgapi': VGAPIPrinter,
+ 'glapi': GLAPIPrinter,
+ 'es1api': ES1APIPrinter,
+ 'es2api': ES2APIPrinter
+ }
+
filename, options = parse_args()
entries = abi_parse(filename)
- printer = ABIPrinter(entries, options)
- printer.output()
+ printer = printers[options.printer](entries)
+ if options.mode == 'lib':
+ printer.output_for_lib()
+ else:
+ printer.output_for_app()
if __name__ == '__main__':
main()
diff --git a/src/mapi/mapi/mapi_tmp.h b/src/mapi/mapi/mapi_tmp.h
index 79beca47d2..a1b067fb73 100644
--- a/src/mapi/mapi/mapi_tmp.h
+++ b/src/mapi/mapi/mapi_tmp.h
@@ -26,186 +26,8 @@
* Chia-I Wu <olv@lunarg.com>
*/
-#include "u_macros.h"
-
#ifndef MAPI_ABI_HEADER
#error "MAPI_ABI_HEADER must be defined"
#endif
-
-/**
- * Get API defines.
- */
-#ifdef MAPI_TMP_DEFINES
-# define MAPI_ABI_DEFINES
-# include MAPI_ABI_HEADER
-
-#ifndef MAPI_ABI_PREFIX
-#error "MAPI_ABI_PREFIX must be defined"
-#endif
-#ifndef MAPI_ABI_PUBLIC
-#error "MAPI_ABI_PUBLIC must be defined"
-#endif
-#ifndef MAPI_ABI_ATTR
-#error "MAPI_ABI_ATTR must be defined"
-#endif
-
-#undef MAPI_TMP_DEFINES
-#endif /* MAPI_TMP_DEFINES */
-
-
-/**
- * Generate fields of struct mapi_table.
- */
-#ifdef MAPI_TMP_TABLE
-# define MAPI_ABI_ENTRY(ret, name, params) \
- ret (MAPI_ABI_ATTR *name) params;
-# define MAPI_DYNAMIC_ENTRY(ret, name, params) \
- ret (MAPI_ABI_ATTR *name) params;
-# include MAPI_ABI_HEADER
-#undef MAPI_TMP_TABLE
-#endif /* MAPI_TMP_TABLE */
-
-
-/**
- * Declare public entries.
- */
-#ifdef MAPI_TMP_PUBLIC_DECLARES
-# define MAPI_ABI_ENTRY(ret, name, params) \
- MAPI_ABI_PUBLIC ret MAPI_ABI_ATTR U_CONCAT(MAPI_ABI_PREFIX, name) params;
-# define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
- MAPI_ABI_ENTRY(ret, name, params);
-# define MAPI_ABI_ENTRY_HIDDEN(ret, name, params) \
- HIDDEN ret MAPI_ABI_ATTR U_CONCAT(MAPI_ABI_PREFIX, name) params;
-# define MAPI_ALIAS_ENTRY_HIDDEN(alias, ret, name, params) \
- MAPI_ABI_ENTRY_HIDDEN(ret, name, params)
-# include MAPI_ABI_HEADER
-#undef MAPI_TMP_PUBLIC_DECLARES
-#endif /* MAPI_TMP_PUBLIC_DECLARES */
-
-
-/**
- * Generate string pool and public stubs.
- */
-#ifdef MAPI_TMP_PUBLIC_STUBS
-/* define the string pool */
-static const char public_string_pool[] =
-# define MAPI_ABI_ENTRY(ret, name, params) \
- U_STRINGIFY(name) "\0"
-# define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
- MAPI_ABI_ENTRY(ret, name, params)
-# include MAPI_ABI_HEADER
- ;
-/* define public_sorted_indices */
-# define MAPI_ABI_SORTED_INDICES public_sorted_indices
-# include MAPI_ABI_HEADER
-
-/* define public_stubs */
-static const struct mapi_stub public_stubs[] = {
-# define MAPI_ABI_ENTRY(ret, name, params) \
- { (mapi_func) U_CONCAT(MAPI_ABI_PREFIX, name), \
- MAPI_SLOT_ ## name, (void *) MAPI_POOL_ ## name },
-# define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
- MAPI_ABI_ENTRY(ret, name, params)
-# include MAPI_ABI_HEADER
- { NULL, -1, (void *) -1 }
-};
-
-#undef MAPI_TMP_PUBLIC_STUBS
-#endif /* MAPI_TMP_PUBLIC_STUBS */
-
-
-/**
- * Generate public entries.
- */
-#ifdef MAPI_TMP_PUBLIC_ENTRIES
-# define MAPI_ABI_ENTRY(ret, name, params) \
- ret MAPI_ABI_ATTR U_CONCAT(MAPI_ABI_PREFIX, name) params
-# define MAPI_ABI_CODE(ret, name, args) \
- { \
- const struct mapi_table *tbl = u_current_get(); \
- tbl->name args; \
- }
-# define MAPI_ABI_CODE_RETURN(ret, name, args) \
- { \
- const struct mapi_table *tbl = u_current_get(); \
- return tbl->name args; \
- }
-# define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
- MAPI_ABI_ENTRY(ret, name, params)
-# define MAPI_ALIAS_CODE(alias, ret, name, args) \
- MAPI_ABI_CODE(ret, alias, args)
-# define MAPI_ALIAS_CODE_RETURN(alias, ret, name, args) \
- MAPI_ABI_CODE_RETURN(ret, alias, args)
-# include MAPI_ABI_HEADER
-#undef MAPI_TMP_PUBLIC_ENTRIES
-#endif /* MAPI_TMP_PUBLIC_ENTRIES */
-
-
-/**
- * Generate noop entries.
- */
-#ifdef MAPI_TMP_NOOP_ARRAY
-#ifdef DEBUG
-# define MAPI_ABI_ENTRY(ret, name, params) \
- static ret MAPI_ABI_ATTR U_CONCAT(noop_, name) params
-# define MAPI_ABI_CODE(ret, name, args) \
- { \
- noop_warn(U_CONCAT_STR(MAPI_ABI_PREFIX, name)); \
- }
-# define MAPI_ABI_CODE_RETURN(ret, name, args) \
- { \
- noop_warn(U_CONCAT_STR(MAPI_ABI_PREFIX, name)); \
- return (ret) 0; \
- }
-# include MAPI_ABI_HEADER
-
-/* define the noop function array that may be casted to mapi_table */
-const mapi_func table_noop_array[] = {
-# define MAPI_ABI_ENTRY(ret, name, params) \
- (mapi_func) U_CONCAT(noop_, name),
-# define MAPI_DYNAMIC_ENTRY(ret, name, params) \
- (mapi_func) noop_generic,
-# include MAPI_ABI_HEADER
- (mapi_func) noop_generic
-};
-
-#else /* DEBUG */
-
-const mapi_func table_noop_array[] = {
-# define MAPI_ABI_ENTRY(ret, name, params) \
- (mapi_func) noop_generic,
-# define MAPI_DYNAMIC_ENTRY(ret, name, params) \
- (mapi_func) noop_generic,
-# include MAPI_ABI_HEADER
- (mapi_func) noop_generic
-};
-
-#endif /* DEBUG */
-#undef MAPI_TMP_NOOP_ARRAY
-#endif /* MAPI_TMP_NOOP_ARRAY */
-
-
-#ifdef MAPI_TMP_STUB_ASM_GCC
-# define STUB_ASM_ALIAS(func, to) \
- ".globl " func "\n" \
- ".set " func ", " to
-# define STUB_ASM_HIDE(func) \
- ".hidden " func
-
-# define MAPI_ABI_ENTRY(ret, name, params) \
- __asm__(STUB_ASM_ENTRY(U_CONCAT_STR(MAPI_ABI_PREFIX, name)));
-# define MAPI_ABI_CODE(ret, name, args) \
- __asm__(STUB_ASM_CODE(U_STRINGIFY(MAPI_SLOT_ ## name)));
-# define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
- __asm__(STUB_ASM_ALIAS(U_CONCAT_STR(MAPI_ABI_PREFIX, name), \
- U_CONCAT_STR(MAPI_ABI_PREFIX, alias)));
-# define MAPI_ABI_ENTRY_HIDDEN(ret, name, params) \
- __asm__(STUB_ASM_HIDE(U_CONCAT_STR(MAPI_ABI_PREFIX, name))); \
- MAPI_ABI_ENTRY(ret, name, params);
-# define MAPI_ALIAS_ENTRY_HIDDEN(alias, ret, name, params) \
- __asm__(STUB_ASM_HIDE(U_CONCAT_STR(MAPI_ABI_PREFIX, name))); \
- MAPI_ALIAS_ENTRY(alias, ret, name, params);
-# include MAPI_ABI_HEADER
-#undef MAPI_TMP_STUB_ASM_GCC
-#endif /* MAPI_TMP_STUB_ASM_GCC */
+#include MAPI_ABI_HEADER
diff --git a/src/mapi/mapi/sources.mak b/src/mapi/mapi/sources.mak
index 5f327f3df6..ed36e1af48 100644
--- a/src/mapi/mapi/sources.mak
+++ b/src/mapi/mapi/sources.mak
@@ -1,12 +1,14 @@
# src/mapi/mapi/sources.mak
#
-# When MAPI_GLAPI_CURRENT is defined, MAPI_GLAPI_SOURCES can be built without
-# MAPI_SOURCES and it is used by glapi.
+# mapi may be used in several ways
#
-# Otherwise, MAPI_ABI_HEADER must be defined. It should expand to the header
-# generated by mapi_abi.py.
+# - In default mode, mapi implements the interface defined by mapi.h. To use
+# this mode, compile MAPI_SOURCES.
+#
+# - In util mode, mapi provides utility functions for use with glapi. To use
+# this mode, compile MAPI_UTIL_SOURCES with MAPI_MODE_UTIL defined.
-MAPI_GLAPI_SOURCES = \
+MAPI_UTIL_SOURCES = \
u_current.c \
u_execmem.c \
u_thread.c
@@ -16,4 +18,4 @@ MAPI_SOURCES = \
mapi.c \
stub.c \
table.c \
- $(MAPI_GLAPI_SOURCES)
+ $(MAPI_UTIL_SOURCES)
diff --git a/src/mapi/mapi/stub.c b/src/mapi/mapi/stub.c
index 8ceaec3132..3594eacb4e 100644
--- a/src/mapi/mapi/stub.c
+++ b/src/mapi/mapi/stub.c
@@ -37,23 +37,15 @@
#include "stub.h"
#include "table.h"
-#define MAPI_TABLE_FIRST_DYNAMIC \
- (offsetof(struct mapi_table, dynamic0) / sizeof(mapi_func))
-#define MAPI_TABLE_NUM_DYNAMIC \
- ((offsetof(struct mapi_table, last) - \
- offsetof(struct mapi_table, dynamic0)) / sizeof(mapi_func))
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-/*
- * This will define public_string_pool, public_sorted_indices, and
- * public_stubs.
- */
+/* define public_string_pool and public_stubs */
#define MAPI_TMP_PUBLIC_STUBS
#include "mapi_tmp.h"
static struct mapi_stub dynamic_stubs[MAPI_TABLE_NUM_DYNAMIC];
static int num_dynamic_stubs;
-static int next_dynamic_slot = MAPI_TABLE_FIRST_DYNAMIC;
+static int next_dynamic_slot = MAPI_TABLE_NUM_STATIC;
void
stub_init_once(void)
@@ -74,11 +66,9 @@ static int
stub_compare(const void *key, const void *elem)
{
const char *name = (const char *) key;
- const int *index = (const int *) elem;
- const struct mapi_stub *stub;
+ const struct mapi_stub *stub = (const struct mapi_stub *) elem;
const char *stub_name;
- stub = &public_stubs[*index];
stub_name = &public_string_pool[(unsigned long) stub->name];
return strcmp(name, stub_name);
@@ -90,13 +80,8 @@ stub_compare(const void *key, const void *elem)
const struct mapi_stub *
stub_find_public(const char *name)
{
- const int *index;
-
- index = (const int *) bsearch(name, public_sorted_indices,
- ARRAY_SIZE(public_sorted_indices) - 1,
- sizeof(public_sorted_indices[0]), stub_compare);
-
- return (index) ? &public_stubs[*index] : NULL;
+ return (const struct mapi_stub *) bsearch(name, public_stubs,
+ ARRAY_SIZE(public_stubs), sizeof(public_stubs[0]), stub_compare);
}
/**
@@ -109,14 +94,15 @@ stub_add_dynamic(const char *name)
int idx;
idx = num_dynamic_stubs;
- if (idx >= MAPI_TABLE_NUM_DYNAMIC)
+ /* minus 1 to make sure we can never reach the last slot */
+ if (idx >= MAPI_TABLE_NUM_DYNAMIC - 1)
return NULL;
stub = &dynamic_stubs[idx];
- /* dispatch to mapi_table->last, which is always no-op */
- stub->addr =
- entry_generate(MAPI_TABLE_FIRST_DYNAMIC + MAPI_TABLE_NUM_DYNAMIC);
+ /* dispatch to the last slot, which is reserved for no-op */
+ stub->addr = entry_generate(
+ MAPI_TABLE_NUM_STATIC + MAPI_TABLE_NUM_DYNAMIC - 1);
if (!stub->addr)
return NULL;
diff --git a/src/mapi/mapi/table.h b/src/mapi/mapi/table.h
index 48c99018aa..ca2be568c7 100644
--- a/src/mapi/mapi/table.h
+++ b/src/mapi/mapi/table.h
@@ -33,13 +33,11 @@
#include "stub.h"
#define MAPI_TMP_DEFINES
-#include "mapi_tmp.h"
-
-struct mapi_table {
#define MAPI_TMP_TABLE
#include "mapi_tmp.h"
- mapi_func last;
-};
+
+#define MAPI_TABLE_NUM_SLOTS (MAPI_TABLE_NUM_STATIC + MAPI_TABLE_NUM_DYNAMIC)
+#define MAPI_TABLE_SIZE (MAPI_TABLE_NUM_SLOTS * sizeof(mapi_func))
extern const mapi_func table_noop_array[];
diff --git a/src/mapi/mapi/u_current.c b/src/mapi/mapi/u_current.c
index ed9ccfe229..7946d2a274 100644
--- a/src/mapi/mapi/u_current.c
+++ b/src/mapi/mapi/u_current.c
@@ -51,7 +51,7 @@
#include "u_current.h"
#include "u_thread.h"
-#ifndef MAPI_GLAPI_CURRENT
+#ifndef MAPI_MODE_UTIL
#include "table.h"
#include "stub.h"
@@ -99,16 +99,13 @@ extern void (*__glapi_noop_table[])(void);
/*@{*/
#if defined(GLX_USE_TLS)
-__thread struct mapi_table *u_current_table_tls
+__thread struct mapi_table *u_current_table
__attribute__((tls_model("initial-exec")))
= (struct mapi_table *) table_noop_array;
-__thread void *u_current_user_tls
+__thread void *u_current_user
__attribute__((tls_model("initial-exec")));
-const struct mapi_table *u_current_table;
-const void *u_current_user;
-
#else
struct mapi_table *u_current_table =
@@ -128,7 +125,7 @@ static int ThreadSafe;
void
u_current_destroy(void)
{
-#if defined(THREADS) && defined(WIN32_THREADS)
+#if defined(THREADS) && defined(WIN32)
u_tsd_destroy(&u_current_table_tsd);
u_tsd_destroy(&u_current_user_tsd);
#endif
@@ -147,7 +144,7 @@ u_current_init_tsd(void)
/**
* Mutex for multithread check.
*/
-#ifdef WIN32_THREADS
+#ifdef WIN32
/* _glthread_DECLARE_STATIC_MUTEX is broken on windows. There will be race! */
#define CHECK_MULTITHREAD_LOCK()
#define CHECK_MULTITHREAD_UNLOCK()
@@ -179,8 +176,8 @@ u_current_init(void)
}
else if (knownID != u_thread_self()) {
ThreadSafe = 1;
- u_current_set_internal(NULL);
- u_current_set_user_internal(NULL);
+ u_current_set(NULL);
+ u_current_set_user(NULL);
}
CHECK_MULTITHREAD_UNLOCK();
}
@@ -202,17 +199,17 @@ u_current_init(void)
* void from the real context pointer type.
*/
void
-u_current_set_user_internal(void *ptr)
+u_current_set_user(const void *ptr)
{
u_current_init();
#if defined(GLX_USE_TLS)
- u_current_user_tls = ptr;
+ u_current_user = (void *) ptr;
#elif defined(THREADS)
- u_tsd_set(&u_current_user_tsd, ptr);
- u_current_user = (ThreadSafe) ? NULL : ptr;
+ u_tsd_set(&u_current_user_tsd, (void *) ptr);
+ u_current_user = (ThreadSafe) ? NULL : (void *) ptr;
#else
- u_current_user = ptr;
+ u_current_user = (void *) ptr;
#endif
}
@@ -225,7 +222,7 @@ void *
u_current_get_user_internal(void)
{
#if defined(GLX_USE_TLS)
- return u_current_user_tls;
+ return u_current_user;
#elif defined(THREADS)
return (ThreadSafe)
? u_tsd_get(&u_current_user_tsd)
@@ -241,22 +238,22 @@ u_current_get_user_internal(void)
* table (__glapi_noop_table).
*/
void
-u_current_set_internal(struct mapi_table *tbl)
+u_current_set(const struct mapi_table *tbl)
{
u_current_init();
stub_init_once();
if (!tbl)
- tbl = (struct mapi_table *) table_noop_array;
+ tbl = (const struct mapi_table *) table_noop_array;
#if defined(GLX_USE_TLS)
- u_current_table_tls = tbl;
+ u_current_table = (struct mapi_table *) tbl;
#elif defined(THREADS)
u_tsd_set(&u_current_table_tsd, (void *) tbl);
- u_current_table = (ThreadSafe) ? NULL : tbl;
+ u_current_table = (ThreadSafe) ? NULL : (void *) tbl;
#else
- u_current_table = tbl;
+ u_current_table = (struct mapi_table *) tbl;
#endif
}
@@ -267,7 +264,7 @@ struct mapi_table *
u_current_get_internal(void)
{
#if defined(GLX_USE_TLS)
- return u_current_table_tls;
+ return u_current_table;
#elif defined(THREADS)
return (struct mapi_table *) ((ThreadSafe) ?
u_tsd_get(&u_current_table_tsd) : (void *) u_current_table);
diff --git a/src/mapi/mapi/u_current.h b/src/mapi/mapi/u_current.h
index 62e54c6c93..061fccc949 100644
--- a/src/mapi/mapi/u_current.h
+++ b/src/mapi/mapi/u_current.h
@@ -1,28 +1,27 @@
#ifndef _U_CURRENT_H_
#define _U_CURRENT_H_
-#ifdef MAPI_GLAPI_CURRENT
+#ifdef MAPI_MODE_UTIL
#include "glapi/glapi.h"
/* ugly renames to match glapi.h */
#define mapi_table _glapi_table
-#define u_current_table_tls _glapi_tls_Dispatch
-#define u_current_user_tls _glapi_tls_Context
+#ifdef GLX_USE_TLS
+#define u_current_table _glapi_tls_Dispatch
+#define u_current_user _glapi_tls_Context
+#else
#define u_current_table _glapi_Dispatch
#define u_current_user _glapi_Context
+#endif
-#define u_current_destroy _glapi_destroy_multithread
-#define u_current_init _glapi_check_multithread
-#define u_current_set_internal _glapi_set_dispatch
#define u_current_get_internal _glapi_get_dispatch
-#define u_current_set_user_internal _glapi_set_context
#define u_current_get_user_internal _glapi_get_context
#define u_current_table_tsd _gl_DispatchTSD
-#else /* MAPI_GLAPI_CURRENT */
+#else /* MAPI_MODE_UTIL */
#include "u_compiler.h"
@@ -30,15 +29,12 @@ struct mapi_table;
#ifdef GLX_USE_TLS
-extern __thread struct mapi_table *u_current_table_tls
+extern __thread struct mapi_table *u_current_table
__attribute__((tls_model("initial-exec")));
-extern __thread void *u_current_user_tls
+extern __thread void *u_current_user
__attribute__((tls_model("initial-exec")));
-extern const struct mapi_table *u_current_table;
-extern const void *u_current_user;
-
#else /* GLX_USE_TLS */
extern struct mapi_table *u_current_table;
@@ -46,6 +42,8 @@ extern void *u_current_user;
#endif /* GLX_USE_TLS */
+#endif /* MAPI_MODE_UTIL */
+
void
u_current_init(void);
@@ -53,50 +51,36 @@ void
u_current_destroy(void);
void
-u_current_set_internal(struct mapi_table *tbl);
+u_current_set(const struct mapi_table *tbl);
struct mapi_table *
u_current_get_internal(void);
void
-u_current_set_user_internal(void *ptr);
+u_current_set_user(const void *ptr);
void *
u_current_get_user_internal(void);
-static INLINE void
-u_current_set(const struct mapi_table *tbl)
-{
- u_current_set_internal((struct mapi_table *) tbl);
-}
-
static INLINE const struct mapi_table *
u_current_get(void)
{
#ifdef GLX_USE_TLS
- return (const struct mapi_table *) u_current_table_tls;
+ return u_current_table;
#else
return (likely(u_current_table) ?
- (const struct mapi_table *) u_current_table : u_current_get_internal());
+ u_current_table : u_current_get_internal());
#endif
}
-static INLINE void
-u_current_set_user(void *ptr)
-{
- u_current_set_internal(ptr);
-}
-
-static INLINE void *
+static INLINE const void *
u_current_get_user(void)
{
#ifdef GLX_USE_TLS
- return u_current_user_tls;
+ return u_current_user;
#else
return likely(u_current_user) ? u_current_user : u_current_get_user_internal();
#endif
}
-#endif /* MAPI_GLAPI_CURRENT */
-
#endif /* _U_CURRENT_H_ */
diff --git a/src/mapi/mapi/u_thread.c b/src/mapi/mapi/u_thread.c
index e0fa64ae03..138db47b5c 100644
--- a/src/mapi/mapi/u_thread.c
+++ b/src/mapi/mapi/u_thread.c
@@ -111,7 +111,7 @@ u_tsd_set(struct u_tsd *tsd, void *ptr)
* Be sure that you compile using the Multithreaded runtime, otherwise
* bad things will happen.
*/
-#ifdef WIN32_THREADS
+#ifdef WIN32
static void InsteadOf_exit(int nCode)
{
@@ -172,7 +172,7 @@ u_tsd_set(struct u_tsd *tsd, void *ptr)
}
}
-#endif /* WIN32_THREADS */
+#endif /* WIN32 */
/*
* BeOS threads
@@ -222,7 +222,7 @@ u_tsd_set(struct u_tsd *tsd, void *ptr)
*/
unsigned long
-_glthread_GetID(void)
+u_thread_self(void)
{
return 0;
}
diff --git a/src/mapi/mapi/u_thread.h b/src/mapi/mapi/u_thread.h
index b4487a3400..92a0a3916d 100644
--- a/src/mapi/mapi/u_thread.h
+++ b/src/mapi/mapi/u_thread.h
@@ -44,7 +44,7 @@
#include "u_compiler.h"
-#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
+#if defined(PTHREADS) || defined(WIN32) || defined(BEOS_THREADS)
#ifndef THREADS
#define THREADS
#endif
@@ -85,7 +85,7 @@ typedef pthread_mutex_t u_mutex;
* IMPORTANT: Link with multithreaded runtime library when THREADS are
* used!
*/
-#ifdef WIN32_THREADS
+#ifdef WIN32
#include <windows.h>
struct u_tsd {
@@ -104,7 +104,7 @@ typedef CRITICAL_SECTION u_mutex;
#define u_mutex_lock(name) EnterCriticalSection(&name)
#define u_mutex_unlock(name) LeaveCriticalSection(&name)
-#endif /* WIN32_THREADS */
+#endif /* WIN32 */
/*