On Fri, Apr 25, 2014 at 10:12 PM, Richard Biener <richard.guent...@gmail.com> wrote: > On April 25, 2014 4:54:28 PM CEST, Prathamesh Kulkarni > <bilbotheelffri...@gmail.com> wrote: >>Hi, >> I have a daft question to ask. I was looking through genmatch, I >>couldn't figure out why is tree code class (TYPE) stringified in call >>to add_operator () ? >> >>#define DEFTREECODE (SYM, STRING, TYPE, NARGS) \ >> add_operator (SYM, #SYM, #TYPE, NARGS) >> >>In add_operator() tcc (argument corresponding to TYPE) is only used >>to check if the tree code belongs to one of (tcc_unary, tcc_binary, >>tcc_comparison, tcc_expression, tcc_reference) classes. Why can't we >>use enum tree_code_class for tcc ? > > Because there is no .def file for Tcc so we'd have to errors prone duplicate > the enum. I was wondering why we couldn't include tree-core.h in genmatch ? Something similar to the attached patch. Shall that be incorrect ?
Thanks and Regards, Prathamesh > > Richard. > >>Thanks and Regards, >>Prathamesh > >
Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 209800) +++ gcc/genmatch.c (working copy) @@ -29,7 +29,8 @@ along with GCC; see the file COPYING3. #include "hashtab.h" #include "hash-table.h" #include "vec.h" - +#include <string> +#include "tree-core.h" /* Grammar @@ -51,7 +52,7 @@ along with GCC; see the file COPYING3. (PLUS_EXPR { int_const_binop (PLUS_EXPR, captures[0], captures[2]); } @1)) */ - +/* #define DEFTREECODE(SYM, STRING, TYPE, NARGS) SYM, enum tree_code { #include "tree.def" @@ -65,6 +66,7 @@ enum built_in_function { END_BUILTINS }; #undef DEF_BUILTIN +*/ /* Hashtable of known pattern operators. This is pre-seeded from all known tree codes and all known builtin function ids. */ @@ -126,14 +128,10 @@ struct fn_id : public id_base static void add_operator (enum tree_code code, const char *id, - const char *tcc, unsigned nargs) + enum tree_code_class tcc, unsigned nargs) { - if (strcmp (tcc, "tcc_unary") != 0 - && strcmp (tcc, "tcc_binary") != 0 - && strcmp (tcc, "tcc_comparison") != 0 - && strcmp (tcc, "tcc_expression") != 0 - /* For {REAL,IMAG}PART_EXPR and VIEW_CONVERT_EXPR. */ - && strcmp (tcc, "tcc_reference") != 0) + if (tcc != tcc_unary && tcc != tcc_binary && tcc != tcc_comparison + && tcc != tcc_expression && tcc != tcc_reference) return; operator_id *op = new operator_id (code, id, nargs); id_base **slot = operators.find_slot_with_hash (op, op->hashval, INSERT); @@ -689,15 +687,17 @@ parse_c_expr (cpp_reader *r, cpp_ttype s cpp_ttype end; unsigned opencnt; char *code; + std::string cstr; + eat_token (r, start); if (start == CPP_OPEN_PAREN) { - code = xstrdup ("("); + cstr += "("; end = CPP_CLOSE_PAREN; } else if (start == CPP_OPEN_BRACE) { - code = xstrdup ("({"); + cstr += "({"; end = CPP_CLOSE_BRACE; } else @@ -714,13 +714,9 @@ parse_c_expr (cpp_reader *r, cpp_ttype s if (n->type == CPP_NUMBER && !(n->flags & PREV_WHITE)) { - code = (char *)xrealloc (code, strlen (code) - + strlen ("captures[") + 4); if (token->flags & PREV_WHITE) - strcat (code, " "); - strcat (code, "captures["); - strcat (code, get_number (r)); - strcat (code, "]"); + cstr += " "; + cstr.append ("captures[").append (get_number (r)).append ("]"); continue; } } @@ -734,24 +730,19 @@ parse_c_expr (cpp_reader *r, cpp_ttype s /* Output the token as string. */ char *tk = (char *)cpp_token_as_text (r, token); - code = (char *)xrealloc (code, strlen (code) + strlen (tk) + 2); if (token->flags & PREV_WHITE) - strcat (code, " "); - strcat (code, tk); + cstr += " "; + cstr += tk; } while (1); if (end == CPP_CLOSE_PAREN) - { - code = (char *)xrealloc (code, strlen (code) + 1 + 1); - strcat (code, ")"); - } + cstr += ")"; else if (end == CPP_CLOSE_BRACE) - { - code = (char *)xrealloc (code, strlen (code) + 1 + 2); - strcat (code, "})"); - } + cstr += "})"; else gcc_unreachable (); + + code = (char *) xstrdup (cstr.c_str ()); return new c_expr (code); } @@ -860,7 +851,7 @@ main(int argc, char **argv) /* Pre-seed operators. */ operators.create (1024); #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ - add_operator (SYM, # SYM, # TYPE, NARGS); + add_operator (SYM, # SYM, TYPE, NARGS); #define END_OF_BASE_TREE_CODES #include "tree.def" #undef END_OF_BASE_TREE_CODES