1.1 --- a/src/tools/gendec.c Thu Aug 23 12:33:27 2007 +0000
1.2 +++ b/src/tools/gendec.c Wed Nov 21 11:45:33 2007 +0000
1.5 - * $Id: gendec.c,v 1.1 2007-08-23 12:33:27 nkeynes Exp $
1.6 + * $Id: gendec.c,v 1.2 2007-10-06 08:48:47 nkeynes Exp $
1.8 * Parse the instruction and action files and generate an appropriate
1.9 * instruction decoder.
1.11 printf( "gendec <instruction-file> <action-file> [ -o <output-file> ]\n" );
1.14 -int main( int argc, char *argv[] )
1.18 - /* Parse the command line */
1.19 - while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
1.22 - gen_mode = GEN_TEMPLATE;
1.25 - out_filename = optarg;
1.32 - if( optind < argc ) {
1.33 - ins_filename = argv[optind++];
1.35 - if( optind < argc ) {
1.36 - act_filename = argv[optind++];
1.39 - if( optind < argc || ins_filename == NULL || act_filename == NULL ) {
1.44 - if( out_filename == NULL ) {
1.45 - if( gen_mode == GEN_TEMPLATE ) {
1.46 - out_filename = act_filename;
1.48 - char tmp[strlen(act_filename)+1];
1.49 - strcpy( tmp, act_filename);
1.50 - char *c = strrchr( tmp, '.' );
1.54 - out_filename = g_strconcat( tmp, DEFAULT_OUT_EXT );
1.58 - /* Open the files */
1.59 - ins_file = fopen( ins_filename, "ro" );
1.60 - if( ins_file == NULL ) {
1.61 - fprintf( stderr, "Unable to open '%s' for reading (%s)\n", ins_filename, strerror(errno) );
1.65 - act_file = fopen( act_filename, "ro" );
1.66 - if( act_file == NULL ) {
1.67 - fprintf( stderr, "Unable to open '%s' for reading (%s)\n", act_filename, strerror(errno) );
1.71 - /* Parse the input */
1.72 - struct ruleset *rules = parse_ruleset_file( ins_file );
1.73 - fclose( ins_file );
1.74 - if( rules == NULL ) {
1.78 - struct actionset *actions = parse_action_file( rules, act_file );
1.79 - fclose( act_file );
1.80 - if( actions == NULL ) {
1.84 - /* Finally write out the results */
1.85 - out_file = fopen( out_filename, "wo" );
1.86 - if( out_file == NULL ) {
1.87 - fprintf( stderr, "Unable to open '%s' for writing (%s)\n", out_filename, strerror(errno) );
1.91 - switch( gen_mode ) {
1.93 - if( generate_decoder( rules, actions, out_file ) != 0 ) {
1.97 - case GEN_TEMPLATE:
1.98 - if( generate_template( rules, actions, out_file ) != 0 ) {
1.103 - fclose( out_file );
1.108 * Find a mask that can be used to split up the given rules
1.114 -fprint_indent( char *action, int depth, FILE *f )
1.115 +void fprint_indent( char *action, int depth, FILE *f )
1.117 int spaces = 0, needed = depth*8, i;
1.118 char *text = action;
1.119 @@ -219,10 +126,9 @@
1.123 -fprint_action( struct rule *rule, char *action, int depth, FILE *f )
1.124 +void fprint_action( struct rule *rule, char *action, int depth, FILE *f )
1.128 if( action == NULL ) {
1.129 fprintf( f, "%*cUNIMP(ir); /* %s */\n", depth*8, ' ', rule->format );
1.131 @@ -255,10 +161,9 @@
1.135 -int split_and_generate( struct ruleset *rules, struct actionset *actions,
1.136 +void split_and_generate( struct ruleset *rules, struct actionset *actions,
1.137 int ruleidx[], int rule_count, int input_mask,
1.138 int depth, FILE *f ) {
1.143 @@ -272,7 +177,7 @@
1.144 if( mask == 0 ) { /* No matching mask? */
1.145 fprintf( stderr, "Error: unable to find a valid bitmask (%d rules, %08X input mask)\n", rule_count, input_mask );
1.146 dump_rulesubset( rules, ruleidx, rule_count, stderr );
1.151 /* break up the rules into sub-sets, and process each sub-set.
1.152 @@ -351,3 +256,97 @@
1.158 +int main( int argc, char *argv[] )
1.162 + /* Parse the command line */
1.163 + while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
1.166 + gen_mode = GEN_TEMPLATE;
1.169 + out_filename = optarg;
1.176 + if( optind < argc ) {
1.177 + ins_filename = argv[optind++];
1.179 + if( optind < argc ) {
1.180 + act_filename = argv[optind++];
1.183 + if( optind < argc || ins_filename == NULL || act_filename == NULL ) {
1.188 + if( out_filename == NULL ) {
1.189 + if( gen_mode == GEN_TEMPLATE ) {
1.190 + out_filename = act_filename;
1.192 + char tmp[strlen(act_filename)+1];
1.193 + strcpy( tmp, act_filename);
1.194 + char *c = strrchr( tmp, '.' );
1.195 + if( c != NULL ) {
1.198 + out_filename = g_strconcat( tmp, DEFAULT_OUT_EXT, NULL );
1.202 + /* Open the files */
1.203 + ins_file = fopen( ins_filename, "ro" );
1.204 + if( ins_file == NULL ) {
1.205 + fprintf( stderr, "Unable to open '%s' for reading (%s)\n", ins_filename, strerror(errno) );
1.209 + act_file = fopen( act_filename, "ro" );
1.210 + if( act_file == NULL ) {
1.211 + fprintf( stderr, "Unable to open '%s' for reading (%s)\n", act_filename, strerror(errno) );
1.215 + /* Parse the input */
1.216 + struct ruleset *rules = parse_ruleset_file( ins_file );
1.217 + fclose( ins_file );
1.218 + if( rules == NULL ) {
1.222 + struct actionset *actions = parse_action_file( rules, act_file );
1.223 + fclose( act_file );
1.224 + if( actions == NULL ) {
1.228 + /* Finally write out the results */
1.229 + out_file = fopen( out_filename, "wo" );
1.230 + if( out_file == NULL ) {
1.231 + fprintf( stderr, "Unable to open '%s' for writing (%s)\n", out_filename, strerror(errno) );
1.235 + switch( gen_mode ) {
1.237 + if( generate_decoder( rules, actions, out_file ) != 0 ) {
1.241 + case GEN_TEMPLATE:
1.242 + if( generate_template( rules, actions, out_file ) != 0 ) {
1.247 + fclose( out_file );