Commit 0889c52f by Richard Biener Committed by Richard Biener

genmatch.c (struct operand): Add location member.

2015-07-22  Richard Biener  <rguenther@suse.de>

	* genmatch.c (struct operand): Add location member.
	(predicate, expr, c_expr, capture, if_expr, with_expr): Adjust
	constructors.
	(struct simplify): Remove match_location and result_location
	members.
	(elsehwere): Adjust.

From-SVN: r226067
parent 6dd74463
2015-07-22 Richard Biener <rguenther@suse.de>
* genmatch.c (struct operand): Add location member.
(predicate, expr, c_expr, capture, if_expr, with_expr): Adjust
constructors.
(struct simplify): Remove match_location and result_location
members.
(elsehwere): Adjust.
2015-07-22 Prachi Godbole <prachi.godbole@imgtec.com> 2015-07-22 Prachi Godbole <prachi.godbole@imgtec.com>
* config/mips/m5100.md: New file. * config/mips/m5100.md: New file.
......
...@@ -483,8 +483,10 @@ struct capture_info; ...@@ -483,8 +483,10 @@ struct capture_info;
struct operand { struct operand {
enum op_type { OP_PREDICATE, OP_EXPR, OP_CAPTURE, OP_C_EXPR, OP_IF, OP_WITH }; enum op_type { OP_PREDICATE, OP_EXPR, OP_CAPTURE, OP_C_EXPR, OP_IF, OP_WITH };
operand (enum op_type type_) : type (type_) {} operand (enum op_type type_, source_location loc_)
: type (type_), location (loc_) {}
enum op_type type; enum op_type type;
source_location location;
virtual void gen_transform (FILE *, int, const char *, bool, int, virtual void gen_transform (FILE *, int, const char *, bool, int,
const char *, capture_info *, const char *, capture_info *,
dt_operand ** = 0, dt_operand ** = 0,
...@@ -496,7 +498,8 @@ struct operand { ...@@ -496,7 +498,8 @@ struct operand {
struct predicate : public operand struct predicate : public operand
{ {
predicate (predicate_id *p_) : operand (OP_PREDICATE), p (p_) {} predicate (predicate_id *p_, source_location loc)
: operand (OP_PREDICATE, loc), p (p_) {}
predicate_id *p; predicate_id *p;
}; };
...@@ -505,12 +508,12 @@ struct predicate : public operand ...@@ -505,12 +508,12 @@ struct predicate : public operand
struct expr : public operand struct expr : public operand
{ {
expr (id_base *operation_, bool is_commutative_ = false) expr (id_base *operation_, source_location loc, bool is_commutative_ = false)
: operand (OP_EXPR), operation (operation_), : operand (OP_EXPR, loc), operation (operation_),
ops (vNULL), expr_type (NULL), is_commutative (is_commutative_), ops (vNULL), expr_type (NULL), is_commutative (is_commutative_),
is_generic (false), force_single_use (false) {} is_generic (false), force_single_use (false) {}
expr (expr *e) expr (expr *e)
: operand (OP_EXPR), operation (e->operation), : operand (OP_EXPR, e->location), operation (e->operation),
ops (vNULL), expr_type (e->expr_type), is_commutative (e->is_commutative), ops (vNULL), expr_type (e->expr_type), is_commutative (e->is_commutative),
is_generic (e->is_generic), force_single_use (e->force_single_use) {} is_generic (e->is_generic), force_single_use (e->force_single_use) {}
void append_op (operand *op) { ops.safe_push (op); } void append_op (operand *op) { ops.safe_push (op); }
...@@ -546,10 +549,11 @@ struct c_expr : public operand ...@@ -546,10 +549,11 @@ struct c_expr : public operand
id_tab (const char *id_, const char *oper_): id (id_), oper (oper_) {} id_tab (const char *id_, const char *oper_): id (id_), oper (oper_) {}
}; };
c_expr (cpp_reader *r_, vec<cpp_token> code_, unsigned nr_stmts_, c_expr (cpp_reader *r_, source_location loc,
vec<cpp_token> code_, unsigned nr_stmts_,
vec<id_tab> ids_, cid_map_t *capture_ids_) vec<id_tab> ids_, cid_map_t *capture_ids_)
: operand (OP_C_EXPR), r (r_), code (code_), capture_ids (capture_ids_), : operand (OP_C_EXPR, loc), r (r_), code (code_),
nr_stmts (nr_stmts_), ids (ids_) {} capture_ids (capture_ids_), nr_stmts (nr_stmts_), ids (ids_) {}
/* cpplib tokens and state to transform this back to source. */ /* cpplib tokens and state to transform this back to source. */
cpp_reader *r; cpp_reader *r;
vec<cpp_token> code; vec<cpp_token> code;
...@@ -567,8 +571,8 @@ struct c_expr : public operand ...@@ -567,8 +571,8 @@ struct c_expr : public operand
struct capture : public operand struct capture : public operand
{ {
capture (unsigned where_, operand *what_) capture (source_location loc, unsigned where_, operand *what_)
: operand (OP_CAPTURE), where (where_), what (what_) {} : operand (OP_CAPTURE, loc), where (where_), what (what_) {}
/* Identifier index for the value. */ /* Identifier index for the value. */
unsigned where; unsigned where;
/* The captured value. */ /* The captured value. */
...@@ -582,8 +586,8 @@ struct capture : public operand ...@@ -582,8 +586,8 @@ struct capture : public operand
struct if_expr : public operand struct if_expr : public operand
{ {
if_expr () : operand (OP_IF), cond (NULL), trueexpr (NULL), if_expr (source_location loc)
falseexpr (NULL) {} : operand (OP_IF, loc), cond (NULL), trueexpr (NULL), falseexpr (NULL) {}
c_expr *cond; c_expr *cond;
operand *trueexpr; operand *trueexpr;
operand *falseexpr; operand *falseexpr;
...@@ -593,7 +597,8 @@ struct if_expr : public operand ...@@ -593,7 +597,8 @@ struct if_expr : public operand
struct with_expr : public operand struct with_expr : public operand
{ {
with_expr () : operand (OP_WITH), with (NULL), subexpr (NULL) {} with_expr (source_location loc)
: operand (OP_WITH, loc), with (NULL), subexpr (NULL) {}
c_expr *with; c_expr *with;
operand *subexpr; operand *subexpr;
}; };
...@@ -655,25 +660,20 @@ struct simplify ...@@ -655,25 +660,20 @@ struct simplify
{ {
enum simplify_kind { SIMPLIFY, MATCH }; enum simplify_kind { SIMPLIFY, MATCH };
simplify (simplify_kind kind_, simplify (simplify_kind kind_, operand *match_, operand *result_,
operand *match_, source_location match_location_,
struct operand *result_, source_location result_location_,
vec<vec<user_id *> > for_vec_, cid_map_t *capture_ids_) vec<vec<user_id *> > for_vec_, cid_map_t *capture_ids_)
: kind (kind_), match (match_), match_location (match_location_), : kind (kind_), match (match_), result (result_),
result (result_), result_location (result_location_),
for_vec (for_vec_), for_vec (for_vec_),
capture_ids (capture_ids_), capture_max (capture_ids_->elements () - 1) {} capture_ids (capture_ids_), capture_max (capture_ids_->elements () - 1) {}
simplify_kind kind; simplify_kind kind;
/* The expression that is matched against the GENERIC or GIMPLE IL. */ /* The expression that is matched against the GENERIC or GIMPLE IL. */
operand *match; operand *match;
source_location match_location;
/* For a (simplify ...) an expression with ifs and withs with the expression /* For a (simplify ...) an expression with ifs and withs with the expression
produced when the pattern applies in the leafs. produced when the pattern applies in the leafs.
For a (match ...) the leafs are either empty if it is a simple predicate For a (match ...) the leafs are either empty if it is a simple predicate
or the single expression specifying the matched operands. */ or the single expression specifying the matched operands. */
struct operand *result; struct operand *result;
source_location result_location;
/* Collected 'for' expression operators that have to be replaced /* Collected 'for' expression operators that have to be replaced
in the lowering phase. */ in the lowering phase. */
vec<vec<user_id *> > for_vec; vec<vec<user_id *> > for_vec;
...@@ -772,7 +772,7 @@ commutate (operand *op) ...@@ -772,7 +772,7 @@ commutate (operand *op)
vec<operand *> v = commutate (c->what); vec<operand *> v = commutate (c->what);
for (unsigned i = 0; i < v.length (); ++i) for (unsigned i = 0; i < v.length (); ++i)
{ {
capture *nc = new capture (c->where, v[i]); capture *nc = new capture (c->location, c->where, v[i]);
ret.safe_push (nc); ret.safe_push (nc);
} }
return ret; return ret;
...@@ -829,8 +829,7 @@ lower_commutative (simplify *s, vec<simplify *>& simplifiers) ...@@ -829,8 +829,7 @@ lower_commutative (simplify *s, vec<simplify *>& simplifiers)
vec<operand *> matchers = commutate (s->match); vec<operand *> matchers = commutate (s->match);
for (unsigned i = 0; i < matchers.length (); ++i) for (unsigned i = 0; i < matchers.length (); ++i)
{ {
simplify *ns = new simplify (s->kind, matchers[i], s->match_location, simplify *ns = new simplify (s->kind, matchers[i], s->result,
s->result, s->result_location,
s->for_vec, s->capture_ids); s->for_vec, s->capture_ids);
simplifiers.safe_push (ns); simplifiers.safe_push (ns);
} }
...@@ -846,7 +845,7 @@ lower_opt_convert (operand *o, enum tree_code oper, ...@@ -846,7 +845,7 @@ lower_opt_convert (operand *o, enum tree_code oper,
if (capture *c = dyn_cast<capture *> (o)) if (capture *c = dyn_cast<capture *> (o))
{ {
if (c->what) if (c->what)
return new capture (c->where, return new capture (c->location, c->where,
lower_opt_convert (c->what, oper, to_oper, strip)); lower_opt_convert (c->what, oper, to_oper, strip));
else else
return c; return c;
...@@ -958,8 +957,7 @@ lower_opt_convert (simplify *s, vec<simplify *>& simplifiers) ...@@ -958,8 +957,7 @@ lower_opt_convert (simplify *s, vec<simplify *>& simplifiers)
vec<operand *> matchers = lower_opt_convert (s->match); vec<operand *> matchers = lower_opt_convert (s->match);
for (unsigned i = 0; i < matchers.length (); ++i) for (unsigned i = 0; i < matchers.length (); ++i)
{ {
simplify *ns = new simplify (s->kind, matchers[i], s->match_location, simplify *ns = new simplify (s->kind, matchers[i], s->result,
s->result, s->result_location,
s->for_vec, s->capture_ids); s->for_vec, s->capture_ids);
simplifiers.safe_push (ns); simplifiers.safe_push (ns);
} }
...@@ -981,7 +979,7 @@ lower_cond (operand *o) ...@@ -981,7 +979,7 @@ lower_cond (operand *o)
lop = lower_cond (c->what); lop = lower_cond (c->what);
for (unsigned i = 0; i < lop.length (); ++i) for (unsigned i = 0; i < lop.length (); ++i)
ro.safe_push (new capture (c->where, lop[i])); ro.safe_push (new capture (c->location, c->where, lop[i]));
return ro; return ro;
} }
} }
...@@ -1031,7 +1029,7 @@ lower_cond (operand *o) ...@@ -1031,7 +1029,7 @@ lower_cond (operand *o)
for (unsigned j = 0; j < ocmp->ops.length (); ++j) for (unsigned j = 0; j < ocmp->ops.length (); ++j)
cmp->append_op (ocmp->ops[j]); cmp->append_op (ocmp->ops[j]);
cmp->is_generic = true; cmp->is_generic = true;
ne->ops[0] = new capture (c->where, cmp); ne->ops[0] = new capture (c->location, c->where, cmp);
} }
else else
{ {
...@@ -1058,8 +1056,7 @@ lower_cond (simplify *s, vec<simplify *>& simplifiers) ...@@ -1058,8 +1056,7 @@ lower_cond (simplify *s, vec<simplify *>& simplifiers)
vec<operand *> matchers = lower_cond (s->match); vec<operand *> matchers = lower_cond (s->match);
for (unsigned i = 0; i < matchers.length (); ++i) for (unsigned i = 0; i < matchers.length (); ++i)
{ {
simplify *ns = new simplify (s->kind, matchers[i], s->match_location, simplify *ns = new simplify (s->kind, matchers[i], s->result,
s->result, s->result_location,
s->for_vec, s->capture_ids); s->for_vec, s->capture_ids);
simplifiers.safe_push (ns); simplifiers.safe_push (ns);
} }
...@@ -1076,7 +1073,8 @@ replace_id (operand *o, user_id *id, id_base *with) ...@@ -1076,7 +1073,8 @@ replace_id (operand *o, user_id *id, id_base *with)
{ {
if (!c->what) if (!c->what)
return c; return c;
return new capture (c->where, replace_id (c->what, id, with)); return new capture (c->location, c->where,
replace_id (c->what, id, with));
} }
else if (expr *e = dyn_cast<expr *> (o)) else if (expr *e = dyn_cast<expr *> (o))
{ {
...@@ -1089,14 +1087,14 @@ replace_id (operand *o, user_id *id, id_base *with) ...@@ -1089,14 +1087,14 @@ replace_id (operand *o, user_id *id, id_base *with)
} }
else if (with_expr *w = dyn_cast <with_expr *> (o)) else if (with_expr *w = dyn_cast <with_expr *> (o))
{ {
with_expr *nw = new with_expr (); with_expr *nw = new with_expr (w->location);
nw->with = as_a <c_expr *> (replace_id (w->with, id, with)); nw->with = as_a <c_expr *> (replace_id (w->with, id, with));
nw->subexpr = replace_id (w->subexpr, id, with); nw->subexpr = replace_id (w->subexpr, id, with);
return nw; return nw;
} }
else if (if_expr *ife = dyn_cast <if_expr *> (o)) else if (if_expr *ife = dyn_cast <if_expr *> (o))
{ {
if_expr *nife = new if_expr (); if_expr *nife = new if_expr (ife->location);
nife->cond = as_a <c_expr *> (replace_id (ife->cond, id, with)); nife->cond = as_a <c_expr *> (replace_id (ife->cond, id, with));
nife->trueexpr = replace_id (ife->trueexpr, id, with); nife->trueexpr = replace_id (ife->trueexpr, id, with);
if (ife->falseexpr) if (ife->falseexpr)
...@@ -1110,7 +1108,8 @@ replace_id (operand *o, user_id *id, id_base *with) ...@@ -1110,7 +1108,8 @@ replace_id (operand *o, user_id *id, id_base *with)
{ {
vec<c_expr::id_tab> ids = ce->ids.copy (); vec<c_expr::id_tab> ids = ce->ids.copy ();
ids.safe_push (c_expr::id_tab (id->id, with->id)); ids.safe_push (c_expr::id_tab (id->id, with->id));
return new c_expr (ce->r, ce->code, ce->nr_stmts, ids, ce->capture_ids); return new c_expr (ce->r, ce->location,
ce->code, ce->nr_stmts, ids, ce->capture_ids);
} }
return o; return o;
...@@ -1155,8 +1154,7 @@ lower_for (simplify *sin, vec<simplify *>& simplifiers) ...@@ -1155,8 +1154,7 @@ lower_for (simplify *sin, vec<simplify *>& simplifiers)
if (result_op) if (result_op)
result_op = replace_id (result_op, id, oper); result_op = replace_id (result_op, id, oper);
} }
simplify *ns = new simplify (s->kind, match_op, s->match_location, simplify *ns = new simplify (s->kind, match_op, result_op,
result_op, s->result_location,
vNULL, s->capture_ids); vNULL, s->capture_ids);
worklist.safe_push (ns); worklist.safe_push (ns);
} }
...@@ -2582,7 +2580,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) ...@@ -2582,7 +2580,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
{ {
fprintf_indent (f, indent, "{\n"); fprintf_indent (f, indent, "{\n");
indent += 4; indent += 4;
output_line_directive (f, w->with->code[0].src_loc); output_line_directive (f, w->location);
w->with->gen_transform (f, indent, NULL, true, 1, "type", NULL); w->with->gen_transform (f, indent, NULL, true, 1, "type", NULL);
gen_1 (f, indent, gimple, w->subexpr); gen_1 (f, indent, gimple, w->subexpr);
indent -= 4; indent -= 4;
...@@ -2591,7 +2589,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) ...@@ -2591,7 +2589,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
} }
else if (if_expr *ife = dyn_cast <if_expr *> (result)) else if (if_expr *ife = dyn_cast <if_expr *> (result))
{ {
output_line_directive (f, ife->cond->code[0].src_loc); output_line_directive (f, ife->location);
fprintf_indent (f, indent, "if ("); fprintf_indent (f, indent, "if (");
ife->cond->gen_transform (f, indent, NULL, true, 1, "type", NULL); ife->cond->gen_transform (f, indent, NULL, true, 1, "type", NULL);
fprintf (f, ")\n"); fprintf (f, ")\n");
...@@ -2672,7 +2670,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) ...@@ -2672,7 +2670,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
fprintf_indent (f, indent, "if (dump_file && (dump_flags & TDF_DETAILS)) " fprintf_indent (f, indent, "if (dump_file && (dump_flags & TDF_DETAILS)) "
"fprintf (dump_file, \"Applying pattern "); "fprintf (dump_file, \"Applying pattern ");
output_line_directive (f, s->result_location, true); output_line_directive (f,
result ? result->location : s->match->location, true);
fprintf (f, ", %%s:%%d\\n\", __FILE__, __LINE__);\n"); fprintf (f, ", %%s:%%d\\n\", __FILE__, __LINE__);\n");
if (!result) if (!result)
...@@ -2868,7 +2867,8 @@ dt_simplify::gen (FILE *f, int indent, bool gimple) ...@@ -2868,7 +2867,8 @@ dt_simplify::gen (FILE *f, int indent, bool gimple)
{ {
fprintf_indent (f, indent, "{\n"); fprintf_indent (f, indent, "{\n");
indent += 2; indent += 2;
output_line_directive (f, s->result_location); output_line_directive (f,
s->result ? s->result->location : s->match->location);
if (s->capture_max >= 0) if (s->capture_max >= 0)
fprintf_indent (f, indent, "tree captures[%u] ATTRIBUTE_UNUSED = {};\n", fprintf_indent (f, indent, "tree captures[%u] ATTRIBUTE_UNUSED = {};\n",
s->capture_max + 1); s->capture_max + 1);
...@@ -3045,11 +3045,9 @@ private: ...@@ -3045,11 +3045,9 @@ private:
void parse_pattern (); void parse_pattern ();
operand *parse_result (operand *, predicate_id *); operand *parse_result (operand *, predicate_id *);
void push_simplify (simplify::simplify_kind, void push_simplify (simplify::simplify_kind,
vec<simplify *>&, operand *, source_location, vec<simplify *>&, operand *, operand *);
operand *, source_location);
void parse_simplify (simplify::simplify_kind, void parse_simplify (simplify::simplify_kind,
source_location, vec<simplify *>&, predicate_id *, vec<simplify *>&, predicate_id *, operand *);
operand *);
void parse_for (source_location); void parse_for (source_location);
void parse_if (source_location); void parse_if (source_location);
void parse_predicates (source_location); void parse_predicates (source_location);
...@@ -3269,7 +3267,7 @@ parser::parse_operation () ...@@ -3269,7 +3267,7 @@ parser::parse_operation ()
struct operand * struct operand *
parser::parse_capture (operand *op) parser::parse_capture (operand *op)
{ {
eat_token (CPP_ATSIGN); source_location src_loc = eat_token (CPP_ATSIGN)->src_loc;
const cpp_token *token = peek (); const cpp_token *token = peek ();
const char *id = NULL; const char *id = NULL;
if (token->type == CPP_NUMBER) if (token->type == CPP_NUMBER)
...@@ -3283,7 +3281,7 @@ parser::parse_capture (operand *op) ...@@ -3283,7 +3281,7 @@ parser::parse_capture (operand *op)
unsigned &num = capture_ids->get_or_insert (id, &existed); unsigned &num = capture_ids->get_or_insert (id, &existed);
if (!existed) if (!existed)
num = next_id; num = next_id;
return new capture (num, op); return new capture (src_loc, num, op);
} }
/* Parse an expression /* Parse an expression
...@@ -3292,8 +3290,9 @@ parser::parse_capture (operand *op) ...@@ -3292,8 +3290,9 @@ parser::parse_capture (operand *op)
struct operand * struct operand *
parser::parse_expr () parser::parse_expr ()
{ {
expr *e = new expr (parse_operation ());
const cpp_token *token = peek (); const cpp_token *token = peek ();
expr *e = new expr (parse_operation (), token->src_loc);
token = peek ();
operand *op; operand *op;
bool is_commutative = false; bool is_commutative = false;
bool force_capture = false; bool force_capture = false;
...@@ -3345,7 +3344,7 @@ parser::parse_expr () ...@@ -3345,7 +3344,7 @@ parser::parse_expr ()
capture_ids->get_or_insert (xstrdup (id), &existed); capture_ids->get_or_insert (xstrdup (id), &existed);
if (existed) if (existed)
fatal_at (token, "reserved capture id '%s' already used", id); fatal_at (token, "reserved capture id '%s' already used", id);
op = new capture (num, e); op = new capture (token->src_loc, num, e);
} }
else else
op = e; op = e;
...@@ -3386,7 +3385,7 @@ parser::parse_c_expr (cpp_ttype start) ...@@ -3386,7 +3385,7 @@ parser::parse_c_expr (cpp_ttype start)
unsigned opencnt; unsigned opencnt;
vec<cpp_token> code = vNULL; vec<cpp_token> code = vNULL;
unsigned nr_stmts = 0; unsigned nr_stmts = 0;
eat_token (start); source_location loc = eat_token (start)->src_loc;
if (start == CPP_OPEN_PAREN) if (start == CPP_OPEN_PAREN)
end = CPP_CLOSE_PAREN; end = CPP_CLOSE_PAREN;
else if (start == CPP_OPEN_BRACE) else if (start == CPP_OPEN_BRACE)
...@@ -3423,7 +3422,7 @@ parser::parse_c_expr (cpp_ttype start) ...@@ -3423,7 +3422,7 @@ parser::parse_c_expr (cpp_ttype start)
code.safe_push (*token); code.safe_push (*token);
} }
while (1); while (1);
return new c_expr (r, code, nr_stmts, vNULL, capture_ids); return new c_expr (r, loc, code, nr_stmts, vNULL, capture_ids);
} }
/* Parse an operand which is either an expression, a predicate or /* Parse an operand which is either an expression, a predicate or
...@@ -3460,7 +3459,7 @@ parser::parse_op () ...@@ -3460,7 +3459,7 @@ parser::parse_op ()
fatal_at (token, "using an operator with operands as predicate"); fatal_at (token, "using an operator with operands as predicate");
/* Parse the zero-operand operator "predicates" as /* Parse the zero-operand operator "predicates" as
expression. */ expression. */
op = new expr (opr); op = new expr (opr, token->src_loc);
} }
else if (user_id *code = dyn_cast <user_id *> (opr)) else if (user_id *code = dyn_cast <user_id *> (opr))
{ {
...@@ -3468,10 +3467,10 @@ parser::parse_op () ...@@ -3468,10 +3467,10 @@ parser::parse_op ()
fatal_at (token, "using an operator with operands as predicate"); fatal_at (token, "using an operator with operands as predicate");
/* Parse the zero-operand operator "predicates" as /* Parse the zero-operand operator "predicates" as
expression. */ expression. */
op = new expr (opr); op = new expr (opr, token->src_loc);
} }
else if (predicate_id *p = dyn_cast <predicate_id *> (opr)) else if (predicate_id *p = dyn_cast <predicate_id *> (opr))
op = new predicate (p); op = new predicate (p, token->src_loc);
else else
fatal_at (token, "using an unsupported operator as predicate"); fatal_at (token, "using an unsupported operator as predicate");
if (!parsing_match_operand) if (!parsing_match_operand)
...@@ -3499,15 +3498,14 @@ parser::parse_op () ...@@ -3499,15 +3498,14 @@ parser::parse_op ()
void void
parser::push_simplify (simplify::simplify_kind kind, parser::push_simplify (simplify::simplify_kind kind,
vec<simplify *>& simplifiers, vec<simplify *>& simplifiers,
operand *match, source_location match_loc, operand *match, operand *result)
operand *result, source_location result_loc)
{ {
/* Build and push a temporary for operator list uses in expressions. */ /* Build and push a temporary for operator list uses in expressions. */
if (!oper_lists.is_empty ()) if (!oper_lists.is_empty ())
active_fors.safe_push (oper_lists); active_fors.safe_push (oper_lists);
simplifiers.safe_push simplifiers.safe_push
(new simplify (kind, match, match_loc, result, result_loc, (new simplify (kind, match, result,
active_fors.copy (), capture_ids)); active_fors.copy (), capture_ids));
if (!oper_lists.is_empty ()) if (!oper_lists.is_empty ())
...@@ -3531,7 +3529,7 @@ parser::parse_result (operand *result, predicate_id *matcher) ...@@ -3531,7 +3529,7 @@ parser::parse_result (operand *result, predicate_id *matcher)
if (peek_ident ("if")) if (peek_ident ("if"))
{ {
eat_ident ("if"); eat_ident ("if");
if_expr *ife = new if_expr (); if_expr *ife = new if_expr (token->src_loc);
ife->cond = parse_c_expr (CPP_OPEN_PAREN); ife->cond = parse_c_expr (CPP_OPEN_PAREN);
if (peek ()->type == CPP_OPEN_PAREN) if (peek ()->type == CPP_OPEN_PAREN)
{ {
...@@ -3563,7 +3561,7 @@ parser::parse_result (operand *result, predicate_id *matcher) ...@@ -3563,7 +3561,7 @@ parser::parse_result (operand *result, predicate_id *matcher)
else if (peek_ident ("with")) else if (peek_ident ("with"))
{ {
eat_ident ("with"); eat_ident ("with");
with_expr *withe = new with_expr (); with_expr *withe = new with_expr (token->src_loc);
/* Parse (with c-expr expr) as (if-with (true) expr). */ /* Parse (with c-expr expr) as (if-with (true) expr). */
withe->with = parse_c_expr (CPP_OPEN_BRACE); withe->with = parse_c_expr (CPP_OPEN_BRACE);
withe->with->nr_stmts = 0; withe->with->nr_stmts = 0;
...@@ -3574,9 +3572,9 @@ parser::parse_result (operand *result, predicate_id *matcher) ...@@ -3574,9 +3572,9 @@ parser::parse_result (operand *result, predicate_id *matcher)
else if (peek_ident ("switch")) else if (peek_ident ("switch"))
{ {
token = eat_ident ("switch"); token = eat_ident ("switch");
eat_token (CPP_OPEN_PAREN); source_location ifloc = eat_token (CPP_OPEN_PAREN)->src_loc;
eat_ident ("if"); eat_ident ("if");
if_expr *ife = new if_expr (); if_expr *ife = new if_expr (ifloc);
operand *res = ife; operand *res = ife;
ife->cond = parse_c_expr (CPP_OPEN_PAREN); ife->cond = parse_c_expr (CPP_OPEN_PAREN);
if (peek ()->type == CPP_OPEN_PAREN) if (peek ()->type == CPP_OPEN_PAREN)
...@@ -3593,9 +3591,9 @@ parser::parse_result (operand *result, predicate_id *matcher) ...@@ -3593,9 +3591,9 @@ parser::parse_result (operand *result, predicate_id *matcher)
{ {
if (peek_ident ("if", 2)) if (peek_ident ("if", 2))
{ {
eat_token (CPP_OPEN_PAREN); ifloc = eat_token (CPP_OPEN_PAREN)->src_loc;
eat_ident ("if"); eat_ident ("if");
ife->falseexpr = new if_expr (); ife->falseexpr = new if_expr (ifloc);
ife = as_a <if_expr *> (ife->falseexpr); ife = as_a <if_expr *> (ife->falseexpr);
ife->cond = parse_c_expr (CPP_OPEN_PAREN); ife->cond = parse_c_expr (CPP_OPEN_PAREN);
if (peek ()->type == CPP_OPEN_PAREN) if (peek ()->type == CPP_OPEN_PAREN)
...@@ -3641,7 +3639,6 @@ parser::parse_result (operand *result, predicate_id *matcher) ...@@ -3641,7 +3639,6 @@ parser::parse_result (operand *result, predicate_id *matcher)
void void
parser::parse_simplify (simplify::simplify_kind kind, parser::parse_simplify (simplify::simplify_kind kind,
source_location match_location,
vec<simplify *>& simplifiers, predicate_id *matcher, vec<simplify *>& simplifiers, predicate_id *matcher,
operand *result) operand *result)
{ {
...@@ -3668,7 +3665,7 @@ parser::parse_simplify (simplify::simplify_kind kind, ...@@ -3668,7 +3665,7 @@ parser::parse_simplify (simplify::simplify_kind kind,
if_expr *active_if = NULL; if_expr *active_if = NULL;
for (int i = active_ifs.length (); i > 0; --i) for (int i = active_ifs.length (); i > 0; --i)
{ {
if_expr *ifc = new if_expr (); if_expr *ifc = new if_expr (active_ifs[i-1]->location);
ifc->cond = active_ifs[i-1]; ifc->cond = active_ifs[i-1];
ifc->trueexpr = active_if; ifc->trueexpr = active_if;
active_if = ifc; active_if = ifc;
...@@ -3690,8 +3687,7 @@ parser::parse_simplify (simplify::simplify_kind kind, ...@@ -3690,8 +3687,7 @@ parser::parse_simplify (simplify::simplify_kind kind,
active_if->trueexpr = result; active_if->trueexpr = result;
result = outermost_if; result = outermost_if;
} }
push_simplify (kind, simplifiers, match, match_location, push_simplify (kind, simplifiers, match, result);
result, token->src_loc);
return; return;
} }
...@@ -3704,8 +3700,7 @@ parser::parse_simplify (simplify::simplify_kind kind, ...@@ -3704,8 +3700,7 @@ parser::parse_simplify (simplify::simplify_kind kind,
else else
result = tem; result = tem;
push_simplify (kind, simplifiers, match, match_location, push_simplify (kind, simplifiers, match, result);
result, token->src_loc);
} }
/* Parsing of the outer control structures. */ /* Parsing of the outer control structures. */
...@@ -3930,13 +3925,13 @@ parser::parse_pattern () ...@@ -3930,13 +3925,13 @@ parser::parse_pattern ()
const char *id = get_ident (); const char *id = get_ident ();
if (strcmp (id, "simplify") == 0) if (strcmp (id, "simplify") == 0)
{ {
parse_simplify (simplify::SIMPLIFY, parse_simplify (simplify::SIMPLIFY, simplifiers, NULL, NULL);
token->src_loc, simplifiers, NULL, NULL);
capture_ids = NULL; capture_ids = NULL;
} }
else if (strcmp (id, "match") == 0) else if (strcmp (id, "match") == 0)
{ {
bool with_args = false; bool with_args = false;
source_location e_loc = peek ()->src_loc;
if (peek ()->type == CPP_OPEN_PAREN) if (peek ()->type == CPP_OPEN_PAREN)
{ {
eat_token (CPP_OPEN_PAREN); eat_token (CPP_OPEN_PAREN);
...@@ -3959,7 +3954,7 @@ parser::parse_pattern () ...@@ -3959,7 +3954,7 @@ parser::parse_pattern ()
if (with_args) if (with_args)
{ {
capture_ids = new cid_map_t; capture_ids = new cid_map_t;
e = new expr (p); e = new expr (p, e_loc);
while (peek ()->type == CPP_ATSIGN) while (peek ()->type == CPP_ATSIGN)
e->append_op (parse_capture (NULL)); e->append_op (parse_capture (NULL));
eat_token (CPP_CLOSE_PAREN); eat_token (CPP_CLOSE_PAREN);
...@@ -3969,7 +3964,7 @@ parser::parse_pattern () ...@@ -3969,7 +3964,7 @@ parser::parse_pattern ()
|| (!e && p->nargs != 0))) || (!e && p->nargs != 0)))
fatal_at (token, "non-matching number of match operands"); fatal_at (token, "non-matching number of match operands");
p->nargs = e ? e->ops.length () : 0; p->nargs = e ? e->ops.length () : 0;
parse_simplify (simplify::MATCH, token->src_loc, p->matchers, p, e); parse_simplify (simplify::MATCH, p->matchers, p, e);
capture_ids = NULL; capture_ids = NULL;
} }
else if (strcmp (id, "for") == 0) else if (strcmp (id, "for") == 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment