Search
lxdream.org :: lxdream/src/tools/gendec.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/tools/gendec.c
changeset 948:545c85cc56f1
prev824:016cda9d0518
next969:3f178ca1398c
author nkeynes
date Wed Jan 07 04:39:04 2009 +0000 (11 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change Introduce sh4_finalize_instruction to clean-up on instruction exits
Remove the sh4_flush_icache special cases, now works through the
general case.
file annotate diff log raw
1.1 --- a/src/tools/gendec.c Sun Aug 24 01:43:17 2008 +0000
1.2 +++ b/src/tools/gendec.c Wed Jan 07 04:39:04 2009 +0000
1.3 @@ -161,7 +161,7 @@
1.4 }
1.5 }
1.6
1.7 -void split_and_generate( struct ruleset *rules, struct actionset *actions,
1.8 +void split_and_generate( struct ruleset *rules, char **actions,
1.9 int ruleidx[], int rule_count, int input_mask,
1.10 int depth, FILE *f ) {
1.11 uint32_t mask;
1.12 @@ -170,7 +170,7 @@
1.13 if( rule_count == 0 ) {
1.14 fprintf( f, "%*cUNDEF(ir);\n", depth*8, ' ' );
1.15 } else if( rule_count == 1 ) {
1.16 - fprint_action( rules->rules[ruleidx[0]], actions->actions[ruleidx[0]], depth, f );
1.17 + fprint_action( rules->rules[ruleidx[0]], actions[ruleidx[0]], depth, f );
1.18 } else {
1.19
1.20 mask = find_mask(rules, ruleidx, rule_count, input_mask);
1.21 @@ -223,7 +223,7 @@
1.22 }
1.23 }
1.24
1.25 -int generate_decoder( struct ruleset *rules, struct actionset *actions, FILE *f )
1.26 +int generate_decoder( struct ruleset *rules, actionfile_t af, FILE *out )
1.27 {
1.28 int ruleidx[rules->rule_count];
1.29 int i;
1.30 @@ -232,27 +232,42 @@
1.31 ruleidx[i] = i;
1.32 }
1.33
1.34 - fputs( actions->pretext, f );
1.35 -
1.36 - split_and_generate( rules, actions, ruleidx, rules->rule_count, 0, 1, f );
1.37 -
1.38 - fputs( actions->posttext, f );
1.39 -
1.40 + actiontoken_t token = action_file_next(af);
1.41 + while( token->symbol != END ) {
1.42 + if( token->symbol == TEXT ) {
1.43 + fputs( token->text, out );
1.44 + } else if( token->symbol == ERROR ) {
1.45 + fprintf( stderr, "Error parsing action file" );
1.46 + return -1;
1.47 + } else {
1.48 + split_and_generate( rules, token->actions, ruleidx, rules->rule_count, 0, 1, out );
1.49 + }
1.50 + token = action_file_next(af);
1.51 + }
1.52 return 0;
1.53 }
1.54
1.55 -int generate_template( struct ruleset *rules, struct actionset *actions, FILE *f )
1.56 +int generate_template( struct ruleset *rules, actionfile_t af, FILE *out )
1.57 {
1.58 int i;
1.59 - fputs( actions->pretext, f );
1.60 - fputs( "%%\n", f );
1.61 -
1.62 - for( i=0; i<rules->rule_count; i++ ) {
1.63 - fprintf( f, "%s {: %s :}\n", rules->rules[i]->format,
1.64 - actions->actions[i] == NULL ? "" : actions->actions[i] );
1.65 +
1.66 + actiontoken_t token = action_file_next(af);
1.67 + while( token->symbol != END ) {
1.68 + if( token->symbol == TEXT ) {
1.69 + fputs( token->text, out );
1.70 + } else if( token->symbol == ERROR ) {
1.71 + fprintf( stderr, "Error parsing action file" );
1.72 + return -1;
1.73 + } else {
1.74 + fputs( "%%\n", out );
1.75 + for( i=0; i<rules->rule_count; i++ ) {
1.76 + fprintf( out, "%s {: %s :}\n", rules->rules[i]->format,
1.77 + token->actions[i] == NULL ? "" : token->actions[i] );
1.78 + }
1.79 + fputs( "%%\n", out );
1.80 + }
1.81 + token = action_file_next(af);
1.82 }
1.83 - fputs( "%%\n", f );
1.84 - fputs( actions->posttext, f );
1.85
1.86 return 0;
1.87 }
1.88 @@ -309,26 +324,21 @@
1.89 exit(2);
1.90 }
1.91
1.92 - act_file = fopen( act_filename, "ro" );
1.93 - if( act_file == NULL ) {
1.94 - fprintf( stderr, "Unable to open '%s' for reading (%s)\n", act_filename, strerror(errno) );
1.95 - exit(3);
1.96 - }
1.97 -
1.98 /* Parse the input */
1.99 struct ruleset *rules = parse_ruleset_file( ins_file );
1.100 fclose( ins_file );
1.101 if( rules == NULL ) {
1.102 exit(5);
1.103 }
1.104 -
1.105 - struct actionset *actions = parse_action_file( rules, act_file );
1.106 - fclose( act_file );
1.107 - if( actions == NULL ) {
1.108 - exit(6);
1.109 +
1.110 + actionfile_t af = action_file_open( act_filename, rules );
1.111 + if( af == NULL ) {
1.112 + fprintf( stderr, "Unable to open '%s' for reading (%s)\n", act_filename, strerror(errno) );
1.113 + exit(3);
1.114 }
1.115
1.116 - /* Finally write out the results */
1.117 +
1.118 + /* Open the output file */
1.119 out_file = fopen( out_filename, "wo" );
1.120 if( out_file == NULL ) {
1.121 fprintf( stderr, "Unable to open '%s' for writing (%s)\n", out_filename, strerror(errno) );
1.122 @@ -337,16 +347,18 @@
1.123
1.124 switch( gen_mode ) {
1.125 case GEN_SOURCE:
1.126 - if( generate_decoder( rules, actions, out_file ) != 0 ) {
1.127 + if( generate_decoder( rules, af, out_file ) != 0 ) {
1.128 exit(7);
1.129 }
1.130 break;
1.131 case GEN_TEMPLATE:
1.132 - if( generate_template( rules, actions, out_file ) != 0 ) {
1.133 + if( generate_template( rules, af, out_file ) != 0 ) {
1.134 exit(7);
1.135 }
1.136 break;
1.137 }
1.138 +
1.139 + action_file_close(af);
1.140 fclose( out_file );
1.141 return 0;
1.142 }
.