1.1 --- a/src/tools/gendec.c Wed Feb 04 00:58:54 2009 +0000
1.2 +++ b/src/tools/gendec.c Tue Feb 07 11:44:19 2012 +1000
1.5 FILE *ins_file, *act_file, *out_file;
1.7 -char *option_list = "tmho:";
1.8 +char *option_list = "tmho:w";
1.9 int gen_mode = GEN_SOURCE;
1.10 -struct option longopts[1] = { { NULL, 0, 0, 0 } };
1.11 +int emit_warnings = 0;
1.13 +struct option longopts[] = {
1.14 + { "help", no_argument, NULL, 'h' },
1.15 + { "output", required_argument, NULL, 'o' },
1.16 + { "template", no_argument, NULL, 't' },
1.17 + { "warnings", no_argument, NULL, 'w' },
1.18 + { NULL, 0, 0, 0 } };
1.20 static void usage() {
1.21 - printf( "gendec <instruction-file> <action-file> [ -o <output-file> ]\n" );
1.22 + printf( "Usage: gendec [options] <instruction-file> <action-file> [ -o <output-file> ]\n" );
1.23 + printf( "Options:\n" );
1.24 + printf( " -h, --help Print this help message\n" );
1.25 + printf( " -o, --output=FILE Generate output to the given file\n" );
1.26 + printf( " -t, --template Generate a template skeleton instead of an instruction matcher\n" );
1.27 + printf( " -w, --warnings Emit warnings when unmatched instructions are found\n" );
1.31 + * Check that rules are provided for all actions
1.33 +static void check_actions( struct ruleset *rules, const actiontoken_t token )
1.37 + for( i=0; i<rules->rule_count; i++ ) {
1.38 + if( token->actions[i].text == NULL ) {
1.39 + if( warnings == 0 ) {
1.40 + fprintf( stderr, "In action block starting at line %d of file %s:\n",
1.41 + token->lineno, token->filename );
1.43 + fprintf( stderr, "Warning: No action matches rule %d %s\n", i, rules->rules[i]->format );
1.46 + const char *s = token->actions[i].text;
1.48 + if( !isspace(*s) )
1.53 + if( warnings == 0 ) {
1.54 + fprintf( stderr, "In action block starting at line %d of file %s:\n",
1.55 + token->lineno, token->filename );
1.57 + fprintf( stderr, "Warning: Empty action for rule %d %s at line %d\n", i, rules->rules[i]->format,
1.58 + token->actions[i].lineno );
1.67 fprintf( stderr, "Error parsing action file" );
1.70 + if( emit_warnings ) {
1.71 + check_actions( rules, token );
1.73 split_and_generate( rules, token->actions, ruleidx, rules->rule_count, 0, 1, out );
1.75 token = action_file_next(af);
1.78 out_filename = optarg;
1.81 + emit_warnings = 1;