<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 12:47 PM, Dylan Baker <span dir="ltr"><<a href="mailto:baker.dylan.c@gmail.com" target="_blank">baker.dylan.c@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Quoting Jason Ekstrand (2016-04-25 21:39:19)<br>
<div><div class="h5">> Previously, if an exception was encountered anywhere, nir_algebraic would<br>
> just die in a fire with no indication whatsoever as to where the actual bug<br>
> is.  This commit makes it print out the particular search-and-replace<br>
> expression that is causing problems along with the exception.  Also, it<br>
> will now report all of the errors it finds and then exit at the end like a<br>
> standard C compiler would do.<br>
><br>
> Cc: Dylan Baker <<a href="mailto:baker.dylan.c@gmail.com">baker.dylan.c@gmail.com</a>><br>
> ---<br>
>  src/compiler/nir/nir_algebraic.py | 17 ++++++++++++++++-<br>
>  1 file changed, 16 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py<br>
> index 7697171..3f770b6 100644<br>
> --- a/src/compiler/nir/nir_algebraic.py<br>
> +++ b/src/compiler/nir/nir_algebraic.py<br>
> @@ -24,11 +24,13 @@<br>
>  # Authors:<br>
>  #    Jason Ekstrand (<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>)<br>
><br>
> +from __future__ import print_function<br>
>  import itertools<br>
>  import struct<br>
>  import sys<br>
>  import mako.template<br>
>  import re<br>
> +import traceback<br>
><br>
>  # Represents a set of variables, each with a unique id<br>
>  class VarSet(object):<br>
> @@ -311,15 +313,28 @@ class AlgebraicPass(object):<br>
>        self.xform_dict = {}<br>
>        self.pass_name = pass_name<br>
><br>
> +      error = False<br>
> +<br>
>        for xform in transforms:<br>
>           if not isinstance(xform, SearchAndReplace):<br>
> -            xform = SearchAndReplace(xform)<br>
> +            try:<br>
> +               xform = SearchAndReplace(xform)<br>
> +            except:<br>
> +               print("Failed to parse transformation:", file=sys.stderr)<br>
> +               print("  " + str(xform), file=sys.stderr)<br>
> +               traceback.print_exc(file=sys.stderr)<br>
> +               print('', file=sys.stderr)<br>
> +               error = True<br>
> +               continue<br>
><br>
>           if xform.search.opcode not in self.xform_dict:<br>
>              self.xform_dict[xform.search.opcode] = []<br>
><br>
>           self.xform_dict[xform.search.opcode].append(xform)<br>
><br>
> +      if error:<br>
> +         raise RuntimeError("Error parsing transformations")<br>
> +<br>
<br>
</div></div>I'm going to admit that I have a bias against using RuntimeError, but I<br>
think in the vein you're going for just calling "sys.exit(1)" here would<br>
be better, since you won't get a meaningless stack trace.<span class=""><br></span></blockquote><div><br></div><div>I'd rather use sys.exit(1) anyway.  I just thought that might be "improper" in python.  Changed locally.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
>     def render(self):<br>
>        return _algebraic_pass_template.render(pass_name=self.pass_name,<br>
>                                               xform_dict=self.xform_dict,<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</span>Even with the one nit, either way:<br>
Reviewed-by: Dylan Baker <<a href="mailto:dylan@pnwbakers.com">dylan@pnwbakers.com</a>><br>
</blockquote></div><br></div></div>