Search
lxdream.org :: lxdream :: r1084:852412cf56e0
lxdream 0.9.1
released Jun 29
Download Now
changeset1084:852412cf56e0
parent1083:34895c8bab20
child1085:0be1958dd207
authornkeynes
dateWed Dec 02 11:08:03 2009 +1000 (11 years ago)
Gendec tweaks
- add more useful command line help + long options
- add action checks for missing or empty rules
src/tools/gendec.c
1.1 --- a/src/tools/gendec.c Wed Dec 02 10:36:49 2009 +1000
1.2 +++ b/src/tools/gendec.c Wed Dec 02 11:08:03 2009 +1000
1.3 @@ -38,12 +38,59 @@
1.4
1.5 FILE *ins_file, *act_file, *out_file;
1.6
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.12 +
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.19
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.28 +}
1.29 +
1.30 +/**
1.31 + * Check that rules are provided for all actions
1.32 + */
1.33 +static void check_actions( struct ruleset *rules, const actiontoken_t token )
1.34 +{
1.35 + int i;
1.36 + int warnings = 0;
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.42 + }
1.43 + fprintf( stderr, "Warning: No action matches rule %d %s\n", i, rules->rules[i]->format );
1.44 + warnings++;
1.45 + } else {
1.46 + const char *s = token->actions[i].text;
1.47 + while( *s ) {
1.48 + if( !isspace(*s) )
1.49 + break;
1.50 + s++;
1.51 + }
1.52 + if( !*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.56 + }
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.59 + warnings++;
1.60 + }
1.61 + }
1.62 + }
1.63 }
1.64
1.65 /**
1.66 @@ -242,6 +289,9 @@
1.67 fprintf( stderr, "Error parsing action file" );
1.68 return -1;
1.69 } else {
1.70 + if( emit_warnings ) {
1.71 + check_actions( rules, token );
1.72 + }
1.73 split_and_generate( rules, token->actions, ruleidx, rules->rule_count, 0, 1, out );
1.74 }
1.75 token = action_file_next(af);
1.76 @@ -288,6 +338,9 @@
1.77 case 'o':
1.78 out_filename = optarg;
1.79 break;
1.80 + case 'w':
1.81 + emit_warnings = 1;
1.82 + break;
1.83 case 'h':
1.84 usage();
1.85 exit(0);
.