Added checks to see if either cmmand-line options is not repeated, and generates match-and-simplify code on both GENERIC and GIMPLE if both -generic and -gimple are specified.
* genmatch.c (cmd_options): New struct. (check_repeated_arg): New function. (parse_cmd_arg): Likewise. (main): Emit diagnostic if no command line options are given. Add call to parse_cmd_arg. Thanks, Prathamesh
Index: genmatch.c =================================================================== --- genmatch.c (revision 212928) +++ genmatch.c (working copy) @@ -2118,6 +2118,34 @@ parse_pattern (cpp_reader *r, vec<simpli eat_token (r, CPP_CLOSE_PAREN); } +struct cmd_options +{ + bool generic; + bool gimple; + bool verbose; + + cmd_options (): generic (false), gimple (false), verbose (false) {} +}; + +void +check_repeated_arg (const char *arg, const char *expected_arg, bool& option) +{ + if (strcmp (arg, expected_arg) == 0) + { + if (option) + fatal ("%s repeated", arg); + option = true; + } +} + +void +parse_cmd_arg (const char *arg, cmd_options& opt) +{ + check_repeated_arg (arg, "-gimple", opt.gimple); + check_repeated_arg (arg, "-generic", opt.generic); + check_repeated_arg (arg, "-v", opt.verbose); +} + int main(int argc, char **argv) { @@ -2126,25 +2154,12 @@ main(int argc, char **argv) progname = "genmatch"; if (argc < 2) - return 1; + fatal ("pd file not specified"); - bool gimple = true; - bool verbose = false; + cmd_options opt; char *input = argv[argc-1]; for (int i = 1; i < argc - 1; ++i) - { - if (strcmp (argv[i], "-gimple") == 0) - gimple = true; - else if (strcmp (argv[i], "-generic") == 0) - gimple = false; - else if (strcmp (argv[i], "-v") == 0) - verbose = true; - else - { - fprintf (stderr, "Usage: genmatch [-gimple] [-generic] [-v] input\n"); - return 1; - } - } + parse_cmd_arg (argv[i], opt); line_table = XCNEW (struct line_maps); linemap_init (line_table); @@ -2157,7 +2172,7 @@ main(int argc, char **argv) if (!cpp_read_main_file (r, input)) return 1; - cpp_define (r, gimple ? "GIMPLE=1": "GENERIC=1"); + cpp_define (r, opt.gimple ? "GIMPLE=1": "GENERIC=1"); /* Pre-seed operators. */ operators.create (1024); @@ -2188,7 +2203,7 @@ main(int argc, char **argv) for (unsigned i = 0; i < simplifiers.length (); ++i) lower_commutative (simplifiers[i], out_simplifiers); - if (verbose) + if (opt.verbose) for (unsigned i = 0; i < out_simplifiers.length (); ++i) print_matches (out_simplifiers[i]); @@ -2196,15 +2211,16 @@ main(int argc, char **argv) for (unsigned i = 0; i < out_simplifiers.length (); ++i) dt.insert (out_simplifiers[i], i); - if (verbose) + if (opt.verbose) dt.print (stderr); - if (gimple) + if (opt.gimple) { write_header (stdout, out_simplifiers, "gimple-match-head.c"); dt.gen_gimple (stdout); } - else + + if (opt.generic) { write_header (stdout, out_simplifiers, "generic-match-head.c"); dt.gen_generic (stdout);