<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
With this v2 change PATCH 10/10 has to be updated. V2 of 10/10 coming in a separate envelope.
<div class=""><br class="">
</div>
<div class="">With the 10/10 update, this patch:</div>
<div class=""><br class="">
</div>
<div class="">Reviewed-By: George Kyriazis <<a href="mailto:george.kyriazis@intel.com" class="">george.kyriazis@intel.com</a>><br class="">
<div class="">
<div class=""><br class="">
</div>
<div class="">George</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Mar 27, 2017, at 11:17 AM, Tim Rowley <<a href="mailto:timothy.o.rowley@intel.com" class="">timothy.o.rowley@intel.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Move common codegen functions into gen_common.py.<br class="">
<br class="">
v2: change gen_knobs.py to find the template file internally, like<br class="">
the rest of the gen scripts.<br class="">
---<br class="">
src/gallium/drivers/swr/Makefile.am | 20 ++-<br class="">
.../drivers/swr/rasterizer/codegen/gen_archrast.py | 30 +---<br class="">
.../drivers/swr/rasterizer/codegen/gen_backends.py | 30 +---<br class="">
.../drivers/swr/rasterizer/codegen/gen_common.py | 162 +++++++++++++++++++++<br class="">
.../drivers/swr/rasterizer/codegen/gen_knobs.py | 64 +++-----<br class="">
.../swr/rasterizer/codegen/gen_llvm_ir_macros.py | 35 +----<br class="">
.../swr/rasterizer/codegen/gen_llvm_types.py | 32 +---<br class="">
7 files changed, 215 insertions(+), 158 deletions(-)<br class="">
create mode 100644 src/gallium/drivers/swr/rasterizer/codegen/gen_common.py<br class="">
<br class="">
diff --git a/src/gallium/drivers/swr/Makefile.am b/src/gallium/drivers/swr/Makefile.am<br class="">
index 8ba9ac9..515a908 100644<br class="">
--- a/src/gallium/drivers/swr/Makefile.am<br class="">
+++ b/src/gallium/drivers/swr/Makefile.am<br class="">
@@ -71,30 +71,28 @@ gen_swr_context_llvm.h: rasterizer/codegen/gen_llvm_types.py rasterizer/codegen/<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--input $(srcdir)/swr_context.h \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output ./gen_swr_context_llvm.h<br class="">
<br class="">
-rasterizer/codegen/gen_knobs.cpp: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/gen_knobs.cpp<br class="">
+rasterizer/codegen/gen_knobs.cpp: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/gen_knobs.cpp rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_knobs.py \<br class="">
-<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"></span>--input $(srcdir)/rasterizer/codegen/templates/gen_knobs.cpp \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/codegen/gen_knobs.cpp \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--gen_cpp<br class="">
<br class="">
-rasterizer/codegen/gen_knobs.h: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/gen_knobs.cpp<br class="">
+rasterizer/codegen/gen_knobs.h: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/gen_knobs.cpp rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_knobs.py \<br class="">
-<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"></span>--input $(srcdir)/rasterizer/codegen/templates/gen_knobs.cpp \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/codegen/gen_knobs.h \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--gen_h<br class="">
<br class="">
-rasterizer/jitter/gen_state_llvm.h: rasterizer/codegen/gen_llvm_types.py rasterizer/codegen/templates/gen_llvm.hpp rasterizer/core/state.h<br class="">
+rasterizer/jitter/gen_state_llvm.h: rasterizer/codegen/gen_llvm_types.py rasterizer/codegen/templates/gen_llvm.hpp rasterizer/core/state.h rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_llvm_types.py \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--input $(srcdir)/rasterizer/core/state.h \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/jitter/gen_state_llvm.h<br class="">
<br class="">
-rasterizer/jitter/gen_builder.hpp: rasterizer/codegen/gen_llvm_ir_macros.py rasterizer/codegen/templates/gen_builder.hpp<br class="">
+rasterizer/jitter/gen_builder.hpp: rasterizer/codegen/gen_llvm_ir_macros.py rasterizer/codegen/templates/gen_builder.hpp rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_llvm_ir_macros.py \<br class="">
@@ -102,14 +100,14 @@ rasterizer/jitter/gen_builder.hpp: rasterizer/codegen/gen_llvm_ir_macros.py rast<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/jitter \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--gen_h<br class="">
<br class="">
-rasterizer/jitter/gen_builder_x86.hpp: rasterizer/codegen/gen_llvm_ir_macros.py rasterizer/codegen/templates/gen_builder.hpp<br class="">
+rasterizer/jitter/gen_builder_x86.hpp: rasterizer/codegen/gen_llvm_ir_macros.py rasterizer/codegen/templates/gen_builder.hpp rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_llvm_ir_macros.py \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/jitter \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--gen_x86_h<br class="">
<br class="">
-rasterizer/archrast/gen_ar_event.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.hpp rasterizer/archrast/events.proto<br class="">
+rasterizer/archrast/gen_ar_event.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.hpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_archrast.py \<br class="">
@@ -117,7 +115,7 @@ rasterizer/archrast/gen_ar_event.hpp: rasterizer/codegen/gen_archrast.py rasteri<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/archrast/gen_ar_event.hpp \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--gen_event_h<br class="">
<br class="">
-rasterizer/archrast/gen_ar_event.cpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.cpp rasterizer/archrast/events.proto<br class="">
+rasterizer/archrast/gen_ar_event.cpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.cpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_archrast.py \<br class="">
@@ -125,7 +123,7 @@ rasterizer/archrast/gen_ar_event.cpp: rasterizer/codegen/gen_archrast.py rasteri<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/archrast/gen_ar_event.cpp \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--gen_event_cpp<br class="">
<br class="">
-rasterizer/archrast/gen_ar_eventhandler.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandler.hpp rasterizer/archrast/events.proto<br class="">
+rasterizer/archrast/gen_ar_eventhandler.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandler.hpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_archrast.py \<br class="">
@@ -133,7 +131,7 @@ rasterizer/archrast/gen_ar_eventhandler.hpp: rasterizer/codegen/gen_archrast.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--output rasterizer/archrast/gen_ar_eventhandler.hpp \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>--gen_eventhandler_h<br class="">
<br class="">
-rasterizer/archrast/gen_ar_eventhandlerfile.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandlerfile.hpp rasterizer/archrast/events.proto<br class="">
+rasterizer/archrast/gen_ar_eventhandlerfile.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandlerfile.hpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(MKDIR_GEN)<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>$(PYTHON_GEN) \<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>$(srcdir)/rasterizer/codegen/gen_archrast.py \<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py<br class="">
index cbaa1be..efe42bb 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py<br class="">
@@ -24,25 +24,7 @@ from __future__ import print_function<br class="">
import os<br class="">
import sys<br class="">
import re<br class="">
-import argparse<br class="">
-from mako.template import Template<br class="">
-from mako.exceptions import RichTraceback<br class="">
-<br class="">
-def write_template_to_string(template_filename, **kwargs):<br class="">
- try:<br class="">
- template = Template(filename=template_filename)<br class="">
- # Split + Join fixes line-endings for whatever platform you are using<br class="">
- return '\n'.join(template.render(**kwargs).splitlines())<br class="">
- except:<br class="">
- traceback = RichTraceback()<br class="">
- for (filename, lineno, function, line) in traceback.traceback:<br class="">
- print('File %s, line %s, in %s' % (filename, lineno, function))<br class="">
- print(line, '\n')<br class="">
- print('%s: %s' % (str(traceback.error.__class__.__name__), traceback.error))<br class="">
-<br class="">
-def write_template_to_file(template_filename, output_filename, **kwargs):<br class="">
- with open(output_filename, 'w') as outfile:<br class="">
- print(write_template_to_string(template_filename, **kwargs), file=outfile)<br class="">
+from gen_common import ArgumentParser, MakoTemplateWriter<br class="">
<br class="">
def parse_event_fields(lines, idx, event_dict):<br class="">
field_names = []<br class="">
@@ -141,7 +123,7 @@ def parse_protos(filename):<br class="">
def main():<br class="">
<br class="">
# Parse args...<br class="">
- parser = argparse.ArgumentParser()<br class="">
+ parser = ArgumentParser()<br class="">
parser.add_argument('--proto', '-p', help='Path to proto file', required=True)<br class="">
parser.add_argument('--output', '-o', help='Output filename (i.e. event.hpp)', required=True)<br class="">
parser.add_argument('--gen_event_hpp', help='Generate event header', action='store_true', default=False)<br class="">
@@ -172,7 +154,7 @@ def main():<br class="">
template_file = os.sep.join([curdir, 'templates', 'gen_ar_event.hpp'])<br class="">
output_fullpath = os.sep.join([output_dir, output_filename])<br class="">
<br class="">
- write_template_to_file(template_file, output_fullpath,<br class="">
+ MakoTemplateWriter.to_file(template_file, output_fullpath,<br class="">
filename=output_filename,<br class="">
protos=protos)<br class="">
<br class="">
@@ -182,7 +164,7 @@ def main():<br class="">
template_file = os.sep.join([curdir, 'templates', 'gen_ar_event.cpp'])<br class="">
output_fullpath = os.sep.join([output_dir, output_filename])<br class="">
<br class="">
- write_template_to_file(template_file, output_fullpath,<br class="">
+ MakoTemplateWriter.to_file(template_file, output_fullpath,<br class="">
filename=output_filename,<br class="">
protos=protos)<br class="">
<br class="">
@@ -192,7 +174,7 @@ def main():<br class="">
template_file = os.sep.join([curdir, 'templates', 'gen_ar_eventhandler.hpp'])<br class="">
output_fullpath = os.sep.join([output_dir, output_filename])<br class="">
<br class="">
- write_template_to_file(template_file, output_fullpath,<br class="">
+ MakoTemplateWriter.to_file(template_file, output_fullpath,<br class="">
filename=output_filename,<br class="">
event_header='gen_ar_event.hpp',<br class="">
protos=protos)<br class="">
@@ -203,7 +185,7 @@ def main():<br class="">
template_file = os.sep.join([curdir, 'templates', 'gen_ar_eventhandlerfile.hpp'])<br class="">
output_fullpath = os.sep.join([output_dir, output_filename])<br class="">
<br class="">
- write_template_to_file(template_file, output_fullpath,<br class="">
+ MakoTemplateWriter.to_file(template_file, output_fullpath,<br class="">
filename=output_filename,<br class="">
event_header='gen_ar_eventhandler.hpp',<br class="">
protos=protos)<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py<br class="">
index f2a2272..242ab7a 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py<br class="">
@@ -24,36 +24,14 @@<br class="">
<br class="">
from __future__ import print_function<br class="">
import itertools<br class="">
-import math<br class="">
-import argparse<br class="">
import os<br class="">
import sys<br class="">
-from mako.template import Template<br class="">
-from mako.exceptions import RichTraceback<br class="">
-<br class="">
-def write_template_to_string(template_filename, **kwargs):<br class="">
- try:<br class="">
- template = Template(filename=os.path.abspath(template_filename))<br class="">
- # Split + Join fixes line-endings for whatever platform you are using<br class="">
- return '\n'.join(template.render(**kwargs).splitlines())<br class="">
- except:<br class="">
- traceback = RichTraceback()<br class="">
- for (filename, lineno, function, line) in traceback.traceback:<br class="">
- print("File %s, line %s, in %s" % (filename, lineno, function))<br class="">
- print(line, "\n")<br class="">
- print("%s: %s" % (str(traceback.error.__class__.__name__), traceback.error))<br class="">
-<br class="">
-def write_template_to_file(template_filename, output_filename, **kwargs):<br class="">
- output_dirname = os.path.dirname(output_filename)<br class="">
- if not os.path.exists(output_dirname):<br class="">
- os.makedirs(output_dirname)<br class="">
- with open(output_filename, "w") as outfile:<br class="">
- print(write_template_to_string(template_filename, **kwargs), file=outfile)<br class="">
+from gen_common import ArgumentParser, MakoTemplateWriter<br class="">
<br class="">
<br class="">
def main(args=sys.argv[1:]):<br class="">
thisDir = os.path.dirname(os.path.realpath(__file__))<br class="">
- parser = argparse.ArgumentParser("Generate files and initialization functions for all permutuations of BackendPixelRate.")<br class="">
+ parser = ArgumentParser("Generate files and initialization functions for all permutuations of BackendPixelRate.")<br class="">
parser.add_argument('--dim', help="gBackendPixelRateTable array dimensions", nargs='+', type=int, required=True)<br class="">
parser.add_argument('--outdir', help="output directory", nargs='?', type=str, default=thisDir)<br class="">
parser.add_argument('--split', help="how many lines of initialization per file [0=no split]", nargs='?', type=int, default='512')<br class="">
@@ -100,7 +78,7 @@ def main(args=sys.argv[1:]):<br class="">
for fileNum in range(numFiles):<br class="">
filename = baseCppName % str(fileNum)<br class="">
#print('Generating', filename)<br class="">
- write_template_to_file(<br class="">
+ MakoTemplateWriter.to_file(<br class="">
templateCpp,<br class="">
baseCppName % str(fileNum),<br class="">
cmdline=sys.argv,<br class="">
@@ -112,7 +90,7 @@ def main(args=sys.argv[1:]):<br class="">
templateCmake = os.path.join(thisDir, 'templates', 'gen_backend.cmake')<br class="">
cmakeFile = os.path.join(args.outdir, 'gen_backends.cmake')<br class="">
#print('Generating', cmakeFile)<br class="">
- write_template_to_file(<br class="">
+ MakoTemplateWriter.to_file(<br class="">
templateCmake,<br class="">
cmakeFile,<br class="">
cmdline=sys.argv,<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_common.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_common.py<br class="">
new file mode 100644<br class="">
index 0000000..07b455a<br class="">
--- /dev/null<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_common.py<br class="">
@@ -0,0 +1,162 @@<br class="">
+# Copyright (C) 2014-2016 Intel Corporation. All Rights Reserved.<br class="">
+#<br class="">
+# Permission is hereby granted, free of charge, to any person obtaining a<br class="">
+# copy of this software and associated documentation files (the "Software"),<br class="">
+# to deal in the Software without restriction, including without limitation<br class="">
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,<br class="">
+# and/or sell copies of the Software, and to permit persons to whom the<br class="">
+# Software is furnished to do so, subject to the following conditions:<br class="">
+#<br class="">
+# The above copyright notice and this permission notice (including the next<br class="">
+# paragraph) shall be included in all copies or substantial portions of the<br class="">
+# Software.<br class="">
+#<br class="">
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br class="">
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br class="">
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br class="">
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br class="">
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br class="">
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br class="">
+# IN THE SOFTWARE.<br class="">
+<br class="">
+# Python source<br class="">
+from __future__ import print_function<br class="">
+import os<br class="">
+import sys<br class="">
+import argparse<br class="">
+from mako.template import Template<br class="">
+from mako.exceptions import RichTraceback<br class="">
+<br class="">
+<br class="">
+#==============================================================================<br class="">
+class MakoTemplateWriter:<br class="">
+ '''<br class="">
+ MakoTemplateWriter - Class (namespace) for functions to generate strings<br class="">
+ or files using the Mako template module.<br class="">
+<br class="">
+ See <a href="http://docs.makotemplates.org/en/latest/" class="">http://docs.makotemplates.org/en/latest/</a> for<br class="">
+ mako documentation.<br class="">
+ '''<br class="">
+ <br class="">
+ @staticmethod<br class="">
+ def to_string(template_filename, **kwargs):<br class="">
+ '''<br class="">
+ Write template data to a string object and return the string<br class="">
+ '''<br class="">
+ from mako.template import Template<br class="">
+ from mako.exceptions import RichTraceback<br class="">
+<br class="">
+ try:<br class="">
+ template = Template(filename=template_filename)<br class="">
+ # Split + Join fixes line-endings for whatever platform you are using<br class="">
+ return '\n'.join(template.render(**kwargs).splitlines())<br class="">
+ except:<br class="">
+ traceback = RichTraceback()<br class="">
+ for (filename, lineno, function, line) in traceback.traceback:<br class="">
+ print('File %s, line %s, in %s' % (filename, lineno, function))<br class="">
+ print(line, '\n')<br class="">
+ print('%s: %s' % (str(traceback.error.__class__.__name__), traceback.error))<br class="">
+<br class="">
+ @staticmethod<br class="">
+ def to_file(template_filename, output_filename, **kwargs):<br class="">
+ '''<br class="">
+ Write template data to a file<br class="">
+ '''<br class="">
+ with open(output_filename, 'w') as outfile:<br class="">
+ print(MakoTemplateWriter.to_string(template_filename, **kwargs), file=outfile)<br class="">
+<br class="">
+<br class="">
+#==============================================================================<br class="">
+class ArgumentParser(argparse.ArgumentParser):<br class="">
+ '''<br class="">
+ Subclass of argparse.ArgumentParser<br class="">
+<br class="">
+ Allow parsing from command files that start with @<br class="">
+ Example:<br class="">
+ >bt run @myargs.txt<br class="">
+ <br class="">
+ Contents of myargs.txt:<br class="">
+ -m <machine><br class="">
+ --target cdv_win7<br class="">
+ <br class="">
+ The below function allows multiple args to be placed on the same text-file line.<br class="">
+ The default is one token per line, which is a little cumbersome.<br class="">
+ <br class="">
+ Also allow all characters after a '#' character to be ignored.<br class="">
+ '''<br class="">
+ <br class="">
+ #==============================================================================<br class="">
+ class _HelpFormatter(argparse.RawTextHelpFormatter):<br class="">
+ ''' Better help formatter for argument parser '''<br class="">
+<br class="">
+ def _split_lines(self, text, width):<br class="">
+ ''' optimized split lines algorighm, indents split lines '''<br class="">
+ lines = text.splitlines()<br class="">
+ out_lines = []<br class="">
+ if len(lines):<br class="">
+ out_lines.append(lines[0])<br class="">
+ for line in lines[1:]:<br class="">
+ out_lines.append(' ' + line)<br class="">
+ return out_lines<br class="">
+<br class="">
+ #==============================================================================<br class="">
+ def __init__(self, *args, **kwargs):<br class="">
+ ''' Constructor. Compatible with argparse.ArgumentParser(),<br class="">
+ but with some modifications for better usage and help display.<br class="">
+ '''<br class="">
+ super(ArgumentParser, self).__init__(<br class="">
+ *args,<br class="">
+ fromfile_prefix_chars='@',<br class="">
+ formatter_class=ArgumentParser._HelpFormatter,<br class="">
+ **kwargs)<br class="">
+<br class="">
+ #==========================================================================<br class="">
+ def convert_arg_line_to_args(self, arg_line):<br class="">
+ ''' convert one line of parsed file to arguments '''<br class="">
+ arg_line = arg_line.split('#', 1)[0]<br class="">
+ if sys.platform == 'win32':<br class="">
+ arg_line = arg_line.replace('\\', '\\\\')<br class="">
+ for arg in shlex.split(arg_line):<br class="">
+ if not arg.strip():<br class="">
+ continue<br class="">
+ yield arg<br class="">
+<br class="">
+ #==========================================================================<br class="">
+ def _read_args_from_files(self, arg_strings):<br class="">
+ ''' read arguments from files '''<br class="">
+ # expand arguments referencing files<br class="">
+ new_arg_strings = []<br class="">
+ for arg_string in arg_strings:<br class="">
+<br class="">
+ # for regular arguments, just add them back into the list<br class="">
+ if arg_string[0] not in self.fromfile_prefix_chars:<br class="">
+ new_arg_strings.append(arg_string)<br class="">
+<br class="">
+ # replace arguments referencing files with the file content<br class="">
+ else:<br class="">
+ filename = arg_string[1:]<br class="">
+<br class="">
+ # Search in sys.path<br class="">
+ if not os.path.exists(filename):<br class="">
+ for path in sys.path:<br class="">
+ filename = os.path.join(path, arg_string[1:])<br class="">
+ if os.path.exists(filename):<br class="">
+ break<br class="">
+<br class="">
+ try:<br class="">
+ args_file = open(filename)<br class="">
+ try:<br class="">
+ arg_strings = []<br class="">
+ for arg_line in args_file.read().splitlines():<br class="">
+ for arg in self.convert_arg_line_to_args(arg_line):<br class="">
+ arg_strings.append(arg)<br class="">
+ arg_strings = self._read_args_from_files(arg_strings)<br class="">
+ new_arg_strings.extend(arg_strings)<br class="">
+ finally:<br class="">
+ args_file.close()<br class="">
+ except IOError:<br class="">
+ err = sys.exc_info()[1]<br class="">
+ self.error(str(err))<br class="">
+<br class="">
+ # return the modified argument list<br class="">
+ return new_arg_strings<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py<br class="">
index e722b84..2c271c7 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py<br class="">
@@ -23,59 +23,41 @@<br class="">
from __future__ import print_function<br class="">
import os<br class="">
import sys<br class="">
-import argparse<br class="">
import knob_defs<br class="">
-from mako.template import Template<br class="">
-from mako.exceptions import RichTraceback<br class="">
-<br class="">
-def write_template_to_string(template_filename, **kwargs):<br class="">
- try:<br class="">
- template = Template(filename=os.path.abspath(template_filename))<br class="">
- # Split + Join fixes line-endings for whatever platform you are using<br class="">
- return '\n'.join(template.render(**kwargs).splitlines())<br class="">
- except:<br class="">
- traceback = RichTraceback()<br class="">
- for (filename, lineno, function, line) in traceback.traceback:<br class="">
- print("File %s, line %s, in %s" % (filename, lineno, function))<br class="">
- print(line, "\n")<br class="">
- print("%s: %s" % (str(traceback.error.__class__.__name__), traceback.error))<br class="">
-<br class="">
-def write_template_to_file(template_filename, output_filename, **kwargs):<br class="">
- output_dirname = os.path.dirname(output_filename)<br class="">
- if not os.path.exists(output_dirname):<br class="">
- os.makedirs(output_dirname)<br class="">
- with open(output_filename, "w") as outfile:<br class="">
- print(write_template_to_string(template_filename, **kwargs), file=outfile)<br class="">
+from gen_common import MakoTemplateWriter, ArgumentParser<br class="">
<br class="">
def main(args=sys.argv[1:]):<br class="">
<br class="">
# parse args<br class="">
- parser = argparse.ArgumentParser()<br class="">
- parser.add_argument("--input", "-i", help="Path to gen_knobs.cpp template", required=True)<br class="">
+ parser = ArgumentParser()<br class="">
parser.add_argument("--output", "-o", help="Path to output file", required=True)<br class="">
parser.add_argument("--gen_h", "-gen_h", help="Generate gen_knobs.h", action="store_true", default=False)<br class="">
parser.add_argument("--gen_cpp", "-gen_cpp", help="Generate gen_knobs.cpp", action="store_true", required=False)<br class="">
<br class="">
args = parser.parse_args()<br class="">
<br class="">
- if args.input:<br class="">
- if args.gen_h:<br class="">
- write_template_to_file(args.input,<br class="">
- args.output,<br class="">
- cmdline=sys.argv,<br class="">
- filename='gen_knobs',<br class="">
- knobs=knob_defs.KNOBS,<br class="">
- includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'],<br class="">
- gen_header=True)<br class="">
+ cur_dir = os.path.dirname(os.path.abspath(__file__))<br class="">
+ template_file = os.path.join(cur_dir, 'templates', 'gen_knobs.cpp')<br class="">
+<br class="">
+ if args.gen_h:<br class="">
+ MakoTemplateWriter.to_file(<br class="">
+ template_file,<br class="">
+ args.output,<br class="">
+ cmdline=sys.argv,<br class="">
+ filename='gen_knobs',<br class="">
+ knobs=knob_defs.KNOBS,<br class="">
+ includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'],<br class="">
+ gen_header=True)<br class="">
<br class="">
- if args.gen_cpp:<br class="">
- write_template_to_file(args.input,<br class="">
- args.output,<br class="">
- cmdline=sys.argv,<br class="">
- filename='gen_knobs',<br class="">
- knobs=knob_defs.KNOBS,<br class="">
- includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'],<br class="">
- gen_header=False)<br class="">
+ if args.gen_cpp:<br class="">
+ MakoTemplateWriter.to_file(<br class="">
+ template_file,<br class="">
+ args.output,<br class="">
+ cmdline=sys.argv,<br class="">
+ filename='gen_knobs',<br class="">
+ knobs=knob_defs.KNOBS,<br class="">
+ includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'],<br class="">
+ gen_header=False)<br class="">
<br class="">
return 0<br class="">
<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py<br class="">
index bd8e48e..dbf5647 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py<br class="">
@@ -21,31 +21,8 @@<br class="">
<br class="">
from __future__ import print_function<br class="">
import os, sys, re<br class="">
-import argparse<br class="">
-import json as JSON<br class="">
-import operator<br class="">
-from mako.template import Template<br class="">
-from mako.exceptions import RichTraceback<br class="">
-<br class="">
-def write_template_to_string(template_filename, **kwargs):<br class="">
- try:<br class="">
- template = Template(filename=os.path.abspath(template_filename))<br class="">
- # Split + Join fixes line-endings for whatever platform you are using<br class="">
- return '\n'.join(template.render(**kwargs).splitlines())<br class="">
- except:<br class="">
- traceback = RichTraceback()<br class="">
- for (filename, lineno, function, line) in traceback.traceback:<br class="">
- print('File %s, line %s, in %s' % (filename, lineno, function))<br class="">
- print(line, '\n')<br class="">
- print('%s: %s' % (str(traceback.error.__class__.__name__), traceback.error))<br class="">
-<br class="">
-def write_template_to_file(template_filename, output_filename, **kwargs):<br class="">
- output_dirname = os.path.dirname(output_filename)<br class="">
- if not os.path.exists(output_dirname):<br class="">
- os.makedirs(output_dirname)<br class="">
- with open(output_filename, 'w') as outfile:<br class="">
- print(write_template_to_string(template_filename, **kwargs), file=outfile)<br class="">
-<br class="">
+from gen_common import MakoTemplateWriter, ArgumentParser<br class="">
+from argparse import FileType<br class="">
<br class="">
inst_aliases = {<br class="">
'SHUFFLE_VECTOR': 'VSHUFFLE',<br class="">
@@ -215,7 +192,7 @@ def generate_gen_h(functions, output_dir):<br class="">
'args' : ', '.join(func['arg_names']),<br class="">
})<br class="">
<br class="">
- write_template_to_file(<br class="">
+ MakoTemplateWriter.to_file(<br class="">
template,<br class="">
output_filename,<br class="">
cmdline=sys.argv,<br class="">
@@ -242,7 +219,7 @@ def generate_x86_h(output_dir):<br class="">
'intrin' : inst[1],<br class="">
})<br class="">
<br class="">
- write_template_to_file(<br class="">
+ MakoTemplateWriter.to_file(<br class="">
template,<br class="">
output_filename,<br class="">
cmdline=sys.argv,<br class="">
@@ -259,8 +236,8 @@ def generate_x86_h(output_dir):<br class="">
def main():<br class="">
<br class="">
# Parse args...<br class="">
- parser = argparse.ArgumentParser()<br class="">
- parser.add_argument('--input', '-i', type=argparse.FileType('r'), help='Path to IRBuilder.h', required=False)<br class="">
+ parser = ArgumentParser()<br class="">
+ parser.add_argument('--input', '-i', type=FileType('r'), help='Path to IRBuilder.h', required=False)<br class="">
parser.add_argument('--output-dir', '-o', action='store', dest='output', help='Path to output directory', required=True)<br class="">
parser.add_argument('--gen_h', help='Generate builder_gen.h', action='store_true', default=False)<br class="">
parser.add_argument('--gen_x86_h', help='Generate x86 intrinsics. No input is needed.', action='store_true', default=False)<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_types.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_types.py<br class="">
index 72e6797..1e9593a 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_types.py<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_types.py<br class="">
@@ -21,30 +21,8 @@<br class="">
<br class="">
from __future__ import print_function<br class="">
import os, sys, re<br class="">
-import argparse<br class="">
-import json as JSON<br class="">
-import operator<br class="">
-from mako.template import Template<br class="">
-from mako.exceptions import RichTraceback<br class="">
-<br class="">
-def write_template_to_string(template_filename, **kwargs):<br class="">
- try:<br class="">
- template = Template(filename=os.path.abspath(template_filename))<br class="">
- # Split + Join fixes line-endings for whatever platform you are using<br class="">
- return '\n'.join(template.render(**kwargs).splitlines())<br class="">
- except:<br class="">
- traceback = RichTraceback()<br class="">
- for (filename, lineno, function, line) in traceback.traceback:<br class="">
- print('File %s, line %s, in %s' % (filename, lineno, function))<br class="">
- print(line, '\n')<br class="">
- print('%s: %s' % (str(traceback.error.__class__.__name__), traceback.error))<br class="">
-<br class="">
-def write_template_to_file(template_filename, output_filename, **kwargs):<br class="">
- output_dirname = os.path.dirname(output_filename)<br class="">
- if not os.path.exists(output_dirname):<br class="">
- os.makedirs(output_dirname)<br class="">
- with open(output_filename, 'w') as outfile:<br class="">
- print(write_template_to_string(template_filename, **kwargs), file=outfile)<br class="">
+from gen_common import MakoTemplateWriter, ArgumentParser<br class="">
+from argparse import FileType<br class="">
<br class="">
'''<br class="">
'''<br class="">
@@ -300,7 +278,7 @@ def gen_llvm_types(input_file, output_file):<br class="">
cur_dir = os.path.dirname(os.path.abspath(__file__))<br class="">
template = os.path.join(cur_dir, 'templates', 'gen_llvm.hpp')<br class="">
<br class="">
- write_template_to_file(<br class="">
+ MakoTemplateWriter.to_file(<br class="">
template,<br class="">
output_file,<br class="">
cmdline=sys.argv,<br class="">
@@ -315,8 +293,8 @@ def gen_llvm_types(input_file, output_file):<br class="">
def main():<br class="">
<br class="">
# Parse args...<br class="">
- parser = argparse.ArgumentParser()<br class="">
- parser.add_argument('--input', '-i', type=argparse.FileType('r'),<br class="">
+ parser = ArgumentParser()<br class="">
+ parser.add_argument('--input', '-i', type=FileType('r'),<br class="">
help='Path to input file containing structs', required=True)<br class="">
parser.add_argument('--output', '-o', action='store',<br class="">
help='Path to output file', required=True)<br class="">
-- <br class="">
2.7.4<br class="">
<br class="">
_______________________________________________<br class="">
mesa-dev mailing list<br class="">
<a href="mailto:mesa-dev@lists.freedesktop.org" class="">mesa-dev@lists.freedesktop.org</a><br class="">
https://lists.freedesktop.org/mailman/listinfo/mesa-dev<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</body>
</html>