summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-02-13 17:55:34 -0800
committerDylan Baker <baker.dylan.c@gmail.com>2015-02-18 14:54:14 -0800
commit32c24cc6fbd6d6132c8883f9af581f28197274d7 (patch)
tree75b093b9d26b05e59f2dc4529e062f941de84b0f
parentdd5087e9104e0d46393e3abf794b4b36f835bdc3 (diff)
-rw-r--r--src/mapi/glapi/gen/glX_server_table.py37
-rw-r--r--src/mapi/glapi/gen/python/mako/filters.py12
-rw-r--r--src/mapi/glapi/gen/templates/indirect_table.c.mako93
3 files changed, 135 insertions, 7 deletions
diff --git a/src/mapi/glapi/gen/glX_server_table.py b/src/mapi/glapi/gen/glX_server_table.py
index 7d23669877..29a3075d0a 100644
--- a/src/mapi/glapi/gen/glX_server_table.py
+++ b/src/mapi/glapi/gen/glX_server_table.py
@@ -27,7 +27,12 @@
import argparse
+from mako.lookup import TemplateLookup
+
import gl_XML, glX_XML, glX_proto_common, license
+from python.mako.preprocessor import expand_tab
+
+_LOOKUP = TemplateLookup(['templates'], preprocessor=expand_tab)
def log2(value):
@@ -68,7 +73,6 @@ class function_table:
self.min_op_count = (1 << self.min_op_bits)
return
-
def append(self, opcode, func):
self.functions[opcode] = func
@@ -84,7 +88,6 @@ class function_table:
self.next_opcode_threshold = 1 << bits
return
-
def divide_group(self, min_opcode, total):
"""Divide the group starting min_opcode into subgroups.
Returns a tuple containing the number of bits consumed by
@@ -153,7 +156,6 @@ class function_table:
else:
return [M, children, count, depth]
-
def is_empty_leaf(self, base_opcode, M):
for op in xrange(base_opcode, base_opcode + (1 << M)):
if op in self.functions:
@@ -161,7 +163,6 @@ class function_table:
return True
-
def dump_tree(self, node, base_opcode, remaining_bits, base_entry, depth):
M = node[0]
children = node[1]
@@ -233,7 +234,6 @@ class function_table:
base_opcode += 1 << (remaining_bits - M)
-
def Print(self):
# Each dispatch table consists of two data structures.
#
@@ -383,6 +383,24 @@ class PrintGlxDispatchTables(glX_proto_common.glx_print_proto):
return
+def _make_tables(api):
+ """Build tables to pass into the template."""
+ rop_functions = function_table("Render", True)
+ sop_functions = function_table("Single", False)
+ vop_functions = function_table("VendorPriv", False)
+
+ for f in api.functionIterateAll():
+ if not f.ignore and f.vectorequiv is None:
+ if f.glx_rop != 0:
+ rop_functions.append(f.glx_rop, f)
+ if f.glx_sop != 0:
+ sop_functions.append(f.glx_sop, f)
+ if f.glx_vendorpriv != 0:
+ vop_functions.append(f.glx_vendorpriv, f)
+
+ return rop_functions, sop_functions, vop_functions
+
+
def _parser():
"""Parse arguments and return namespace."""
parser = argparse.ArgumentParser()
@@ -396,10 +414,15 @@ def _parser():
def main():
"""Main function."""
args = _parser()
- printer = PrintGlxDispatchTables()
+ template = _LOOKUP.get_template('indirect_table.c.mako')
api = gl_XML.parse_GL_API(args.filename, glX_XML.glx_item_factory())
- printer.Print(api)
+ try:
+ print template.render(tables=_make_tables(api))
+ except:
+ from mako.exceptions import text_error_template
+ import sys
+ print >> sys.stderr, text_error_template().render()
if __name__ == '__main__':
diff --git a/src/mapi/glapi/gen/python/mako/filters.py b/src/mapi/glapi/gen/python/mako/filters.py
index 0cf00b9ebc..aad73b72ea 100644
--- a/src/mapi/glapi/gen/python/mako/filters.py
+++ b/src/mapi/glapi/gen/python/mako/filters.py
@@ -25,6 +25,8 @@ templates through python functions.
"""
+import re
+
def trim_newlines(text):
"""Remove extra newlines from text.
@@ -39,3 +41,13 @@ def trim_newlines(text):
"""
return '\n'.join(l for l in text.splitlines() if l)
+
+
+def trim_left_space(text):
+ """Remove any leading space characters.
+
+ This removes only the literal space character, not tabs, returns, newlines,
+ etc.
+
+ """
+ return re.sub(r'^ +', '', text)
diff --git a/src/mapi/glapi/gen/templates/indirect_table.c.mako b/src/mapi/glapi/gen/templates/indirect_table.c.mako
new file mode 100644
index 0000000000..4787fe5f97
--- /dev/null
+++ b/src/mapi/glapi/gen/templates/indirect_table.c.mako
@@ -0,0 +1,93 @@
+## Copyright (C) 2015 Intel Corporation
+##
+## Permission is hereby granted, free of charge, to any person obtaining
+## a copy of this software and associated documentation files (the "Software"),
+## to deal in the Software without restriction, including without limitation
+## the rights to use, copy, modify, merge, publish, distribute, sublicense,
+## and/or sell copies of the Software, and to permit persons to whom the
+## Software is furnished to do so, subject to the following conditions:
+##
+## The above copyright notice and this permission notice shall be included
+## in all copies or substantial portions of the Software.
+##
+## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+## IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+## DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+## TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+## OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+##
+## In case it isn't obvious, this ## commented copyright header will not be
+## rendered into the actual template, it applies to the template.
+##
+<%!
+ from python.mako.filters import trim_newlines, trim_left_space
+%>
+<%namespace name="utils" file="utils.mako"/>
+
+<%def name="table_formatter(index, opcode, key, value)">
+ /* [${str(index).rjust(3)}] = ${str(opcode).rjust(5)} */ {${key}, ${value}},
+</%def>
+
+${utils.copyright(['2005, 2006 IBM Corporation'], 'glX_server_table.py (from Mesa)')}
+
+#include <inttypes.h>
+#include "glxserver.h"
+#include "glxext.h"
+#include "indirect_dispatch.h"
+#include "indirect_reqsize.h"
+#include "indirect_table.h"
+
+<%block>
+ % for table in tables:
+ <% tree = table.divide_group(0, 0) %>
+
+ /*****************************************************************/'
+ /* tree depth = ${tree[3]} */
+ static const int_fast16_t ${table.name_base}_dispatch_tree[${tree[2]}] = {'
+ ## TODO: This has to be converted... sigh
+ ##${table.dump_tree(tree, 0, table.max_bits, 0, 1)}
+ };
+
+ ## After dumping the tree, dump the function lookup table.
+
+ static const void *${table.name_base}_function_table[${len(table.lookup_table)}][2] = {
+ % for index, func in enumerate(table.lookup_table):
+ ${table_formatter(index, func[0], func[1], func[2])}
+ % endfor
+ };
+
+ % if table.do_size_check:
+ static const int_fast16_t ${table.name_base}_size_table[${len(table.lookup_table)}][2] = {
+ <% var_table = [] %>
+ % for index, func in enumerate(table.lookup_table):
+ <%
+ if func[4]:
+ var_table.append(func[4])
+ %>
+ ${table_formatter(index, func[0], func[3], str(len(var_table)).rjust(2) if func[4] else '~0')}
+ % endfor
+ };
+
+ static const gl_proto_size_func ${table.name_base}_size_func_tabel[${len(var_table)}] = {
+ % for func in var_table:
+ ${func}
+ % endfor
+ };
+ % endif
+
+ const struct __glXDispatchInfo ${table.name_base}_dispatch_info = {
+ ${table.max_bits}
+ ${table.name_base}_dispatch_tree,
+ ${table.name_base}_function_table,
+ % if table.do_size_check:
+ ${table.name_base}_size_table,
+ ${table.name_base}_size_func_table,
+ % else:
+ NULL
+ NULL
+ % endif
+ };
+ % endfor
+</%block>