Re: genmatch indent generated code

2015-07-10 Thread Richard Biener
On Thu, Jul 9, 2015 at 5:23 PM, Michael Matz m...@suse.de wrote:
 Hi,

 On Thu, 9 Jul 2015, Jakub Jelinek wrote:

 That violates the coding style by not using tabs ;)

 I knew it!  Somebody would notice, pffft.  Fixed in the committed version.

I also noticed it but didn't care ;)  But now I notice

  switch (TREE_CODE (t))
{
  case SSA_NAME:

cases are indented too much, it should be

  switch (TREE_CODE (t))
{
case SSA_NAME:

Richard.


 Ciao,
 Michael.
 PS: this still isn't fully correct, as sometimes I start the strings with
 spaces which don't count towards the indent parameter, I don't align code
 coming from (with ...) and long lines aren't broken up.  Left as an
 excercise for the reader ;)


Re: genmatch indent generated code

2015-07-10 Thread Richard Biener
On Fri, Jul 10, 2015 at 10:45 AM, Richard Biener
richard.guent...@gmail.com wrote:
 On Thu, Jul 9, 2015 at 5:23 PM, Michael Matz m...@suse.de wrote:
 Hi,

 On Thu, 9 Jul 2015, Jakub Jelinek wrote:

 That violates the coding style by not using tabs ;)

 I knew it!  Somebody would notice, pffft.  Fixed in the committed version.

 I also noticed it but didn't care ;)  But now I notice

   switch (TREE_CODE (t))
 {
   case SSA_NAME:

 cases are indented too much, it should be

   switch (TREE_CODE (t))
 {
 case SSA_NAME:

Fixed with the attached.

Richard.

2015-07-10  Richard Biener  rguent...@suse.de

* genmatch.c (dt_node::gen_kids_1): Fix indenting of
case labels.
(decision_tree::gen_gimple): Likewise.
(decision_tree::gen_generic): Likewise.


fix-genmatch-indent
Description: Binary data


Re: genmatch indent generated code

2015-07-10 Thread Michael Matz
Hi,

On Fri, 10 Jul 2015, Richard Biener wrote:

  I also noticed it but didn't care ;)  But now I notice
 
switch (TREE_CODE (t))
  {
case SSA_NAME:
 
  cases are indented too much, it should be
 
switch (TREE_CODE (t))
  {
  case SSA_NAME:

I like the first one better, but hey, be my guest ;-)


Ciao,
Michael.


Re: genmatch indent generated code

2015-07-09 Thread Jeff Law

On 07/09/2015 06:20 AM, Michael Matz wrote:

Hi,

while looking at gimple-match.c I got a minor stroke, so this patch makes
genmatch generated (mostly) properly indented code.  Sure, it could be
done post-fact by an editor or something when one looks at the file, but
all other generators also try to generate good looking code.  No
functional changes to the emitted code.
I've been indenting them with indent when I need to debug something 
going on inside *-match.c :-)


Looks like Richi already approved...

Jeff


Re: genmatch indent generated code

2015-07-09 Thread Jakub Jelinek
On Thu, Jul 09, 2015 at 02:20:08PM +0200, Michael Matz wrote:
 +/* Like fprintf, but print INDENT spaces at the beginning.  */
 +
 +static void
 +#if GCC_VERSION = 4001
 +__attribute__((format (printf, 3, 4)))
 +#endif
 +fprintf_indent (FILE *f, unsigned int indent, const char *format, ...)
 +{
 +  va_list ap;
 +  va_start (ap, format);
 +  fprintf (f, %*s, indent, );

That violates the coding style by not using tabs ;)

You could just emit indent / 8 tabs first and then indent % 8 spaces.
  const char tabs[] = \t\t\t\t\t\t\t\t;
  while (indent = 8 * 8)
{
  fwrite (tabs, 1, 8, f);
  indent -= 8 * 8;
}
  if (indent = 8)
fwrite (tabs, 1, indent / 8, f);
  fprintf (f, %*s, indent % 8, );

Jakub


Re: genmatch indent generated code

2015-07-09 Thread Michael Matz
Hi,

On Thu, 9 Jul 2015, Jakub Jelinek wrote:

 That violates the coding style by not using tabs ;)

I knew it!  Somebody would notice, pffft.  Fixed in the committed version.


Ciao,
Michael.
PS: this still isn't fully correct, as sometimes I start the strings with 
spaces which don't count towards the indent parameter, I don't align code 
coming from (with ...) and long lines aren't broken up.  Left as an 
excercise for the reader ;)


Re: genmatch indent generated code

2015-07-09 Thread Richard Biener
On Thu, Jul 9, 2015 at 2:20 PM, Michael Matz m...@suse.de wrote:
 Hi,

 while looking at gimple-match.c I got a minor stroke, so this patch makes
 genmatch generated (mostly) properly indented code.  Sure, it could be
 done post-fact by an editor or something when one looks at the file, but
 all other generators also try to generate good looking code.  No
 functional changes to the emitted code.

 Regstrapping on x86_64-linux in progress.  Okay if that passes?

Ok.

Thanks,
Richard.


 Ciao,
 Michael.

 * genmatch.c (fprintf_indent): New function.
 (operand::gen_transform): Add indent parameter.
 (expr::gen_transform, c_expr::gen_transform,
 capture::gen_transform): Ditto and use fprintf_indent.
 (dt_node::gen, dt_node::gen_kids, dt_node::gen_kids_1): Ditto.
 (dt_operand::gen, dt_operand::gen_predicate,
 dt_operand::gen_match_op, dt_operand::gen_gimple_expr,
 dt_operand::gen_generic_expr, dt_simplify::gen): Ditto.
 (decision_tree::gen_gimple): Adjust calls and indent generated
 code.
 (decision_tree::gen_generic): Ditto.
 (write_predicate): Ditto.

 Index: gcc/genmatch.c
 ===
 --- gcc.orig/genmatch.c 2015-07-08 16:50:04.0 +0200
 +++ gcc/genmatch.c  2015-07-09 14:05:44.0 +0200
 @@ -126,6 +126,21 @@ warning_at (const cpp_token *tk, const c
va_end (ap);
  }

 +/* Like fprintf, but print INDENT spaces at the beginning.  */
 +
 +static void
 +#if GCC_VERSION = 4001
 +__attribute__((format (printf, 3, 4)))
 +#endif
 +fprintf_indent (FILE *f, unsigned int indent, const char *format, ...)
 +{
 +  va_list ap;
 +  va_start (ap, format);
 +  fprintf (f, %*s, indent, );
 +  vfprintf (f, format, ap);
 +  va_end (ap);
 +}
 +
  static void
  output_line_directive (FILE *f, source_location location,
bool dumpfile = false)
 @@ -468,7 +483,7 @@ struct operand {
enum op_type { OP_PREDICATE, OP_EXPR, OP_CAPTURE, OP_C_EXPR };
operand (enum op_type type_) : type (type_) {}
enum op_type type;
 -  virtual void gen_transform (FILE *, const char *, bool, int,
 +  virtual void gen_transform (FILE *, int, const char *, bool, int,
   const char *, capture_info *,
   dt_operand ** = 0,
   bool = true)
 @@ -503,7 +518,7 @@ struct expr : public operand
bool is_commutative;
/* Whether the expression is expected to be in GENERIC form.  */
bool is_generic;
 -  virtual void gen_transform (FILE *f, const char *, bool, int,
 +  virtual void gen_transform (FILE *f, int, const char *, bool, int,
   const char *, capture_info *,
   dt_operand ** = 0, bool = true);
  };
 @@ -534,7 +549,7 @@ struct c_expr : public operand
unsigned nr_stmts;
/* The identifier replacement vector.  */
vecid_tab ids;
 -  virtual void gen_transform (FILE *f, const char *, bool, int,
 +  virtual void gen_transform (FILE *f, int, const char *, bool, int,
   const char *, capture_info *,
   dt_operand ** = 0, bool = true);
  };
 @@ -549,7 +564,7 @@ struct capture : public operand
unsigned where;
/* The captured value.  */
operand *what;
 -  virtual void gen_transform (FILE *f, const char *, bool, int,
 +  virtual void gen_transform (FILE *f, int, const char *, bool, int,
   const char *, capture_info *,
   dt_operand ** = 0, bool = true);
  };
 @@ -1156,10 +1171,10 @@ struct dt_node
dt_node *append_match_op (dt_operand *, dt_node *parent = 0, unsigned pos 
 = 0);
dt_node *append_simplify (simplify *, unsigned, dt_operand **);

 -  virtual void gen (FILE *, bool) {}
 +  virtual void gen (FILE *, int, bool) {}

 -  void gen_kids (FILE *, bool);
 -  void gen_kids_1 (FILE *, bool,
 +  void gen_kids (FILE *, int, bool);
 +  void gen_kids_1 (FILE *, int, bool,
vecdt_operand *, vecdt_operand *, vecdt_operand *,
vecdt_operand *, vecdt_operand *, vecdt_node *);
  };
 @@ -1178,12 +1193,12 @@ struct dt_operand : public dt_node
: dt_node (type), op (op_), match_dop (match_dop_),
parent (parent_), pos (pos_) {}

 -  void gen (FILE *, bool);
 -  unsigned gen_predicate (FILE *, const char *, bool);
 -  unsigned gen_match_op (FILE *, const char *);
 +  void gen (FILE *, int, bool);
 +  unsigned gen_predicate (FILE *, int, const char *, bool);
 +  unsigned gen_match_op (FILE *, int, const char *);

 -  unsigned gen_gimple_expr (FILE *);
 -  unsigned gen_generic_expr (FILE *, const char *);
 +  unsigned gen_gimple_expr (FILE *, int);
 +  unsigned gen_generic_expr (FILE *, int, const char *);

char *get_name (char *);
void gen_opname (char *, unsigned);
 @@ -1201,7 +1216,7 @@ struct dt_simplify : public dt_node
 :