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
: