filename | src/tools/gendec.c |
changeset | 1084:852412cf56e0 |
prev | 979:2cc7b486ea6c |
next | 1296:30ecee61f811 |
author | nkeynes |
date | Fri Mar 02 23:49:10 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Android WIP: * Rename gui_jni.c to gui_android.c - now quite android specific. * Implement generic EGL driver with very minimal Java wrapper * Run emulation in separate thread, and implement simple queue for inter-thread communication. * Add menu/action-bar items for start + reset |
file | annotate | diff | log | raw |
1.1 --- a/src/tools/gendec.c Wed Feb 04 00:58:54 2009 +00001.2 +++ b/src/tools/gendec.c Fri Mar 02 23:49:10 2012 +10001.3 @@ -38,12 +38,59 @@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.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.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 actions1.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.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);
.