Search
lxdream.org :: lxdream :: r420:e6f43dec3cf0
lxdream 0.9.1
released Jun 29
Download Now
changeset420:e6f43dec3cf0
parent419:09f85e586ff2
child421:e51bf0aedd90
authornkeynes
dateSat Oct 06 08:48:47 2007 +0000 (12 years ago)
Fix compile warnings
src/tools/actparse.c
src/tools/gendec.c
src/tools/gendec.h
src/tools/insparse.c
1.1 --- a/src/tools/actparse.c Thu Oct 04 10:49:41 2007 +0000
1.2 +++ b/src/tools/actparse.c Sat Oct 06 08:48:47 2007 +0000
1.3 @@ -8,7 +8,7 @@
1.4
1.5 static int yyline;
1.6
1.7 -struct rule *new_action() {
1.8 +struct action *new_action() {
1.9 struct action *action = malloc( sizeof( struct action ) );
1.10 memset( action, 0, sizeof( struct action ) );
1.11 return action;
2.1 --- a/src/tools/gendec.c Thu Oct 04 10:49:41 2007 +0000
2.2 +++ b/src/tools/gendec.c Sat Oct 06 08:48:47 2007 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: gendec.c,v 1.1 2007-08-23 12:33:27 nkeynes Exp $
2.6 + * $Id: gendec.c,v 1.2 2007-10-06 08:48:47 nkeynes Exp $
2.7 *
2.8 * Parse the instruction and action files and generate an appropriate
2.9 * instruction decoder.
2.10 @@ -46,99 +46,6 @@
2.11 printf( "gendec <instruction-file> <action-file> [ -o <output-file> ]\n" );
2.12 }
2.13
2.14 -int main( int argc, char *argv[] )
2.15 -{
2.16 - int opt, i;
2.17 -
2.18 - /* Parse the command line */
2.19 - while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
2.20 - switch( opt ) {
2.21 - case 't':
2.22 - gen_mode = GEN_TEMPLATE;
2.23 - break;
2.24 - case 'o':
2.25 - out_filename = optarg;
2.26 - break;
2.27 - case 'h':
2.28 - usage();
2.29 - exit(0);
2.30 - }
2.31 - }
2.32 - if( optind < argc ) {
2.33 - ins_filename = argv[optind++];
2.34 - }
2.35 - if( optind < argc ) {
2.36 - act_filename = argv[optind++];
2.37 - }
2.38 -
2.39 - if( optind < argc || ins_filename == NULL || act_filename == NULL ) {
2.40 - usage();
2.41 - exit(1);
2.42 - }
2.43 -
2.44 - if( out_filename == NULL ) {
2.45 - if( gen_mode == GEN_TEMPLATE ) {
2.46 - out_filename = act_filename;
2.47 - } else {
2.48 - char tmp[strlen(act_filename)+1];
2.49 - strcpy( tmp, act_filename);
2.50 - char *c = strrchr( tmp, '.' );
2.51 - if( c != NULL ) {
2.52 - *c = '\0';
2.53 - }
2.54 - out_filename = g_strconcat( tmp, DEFAULT_OUT_EXT );
2.55 - }
2.56 - }
2.57 -
2.58 - /* Open the files */
2.59 - ins_file = fopen( ins_filename, "ro" );
2.60 - if( ins_file == NULL ) {
2.61 - fprintf( stderr, "Unable to open '%s' for reading (%s)\n", ins_filename, strerror(errno) );
2.62 - exit(2);
2.63 - }
2.64 -
2.65 - act_file = fopen( act_filename, "ro" );
2.66 - if( act_file == NULL ) {
2.67 - fprintf( stderr, "Unable to open '%s' for reading (%s)\n", act_filename, strerror(errno) );
2.68 - exit(3);
2.69 - }
2.70 -
2.71 - /* Parse the input */
2.72 - struct ruleset *rules = parse_ruleset_file( ins_file );
2.73 - fclose( ins_file );
2.74 - if( rules == NULL ) {
2.75 - exit(5);
2.76 - }
2.77 -
2.78 - struct actionset *actions = parse_action_file( rules, act_file );
2.79 - fclose( act_file );
2.80 - if( actions == NULL ) {
2.81 - exit(6);
2.82 - }
2.83 -
2.84 - /* Finally write out the results */
2.85 - out_file = fopen( out_filename, "wo" );
2.86 - if( out_file == NULL ) {
2.87 - fprintf( stderr, "Unable to open '%s' for writing (%s)\n", out_filename, strerror(errno) );
2.88 - exit(4);
2.89 - }
2.90 -
2.91 - switch( gen_mode ) {
2.92 - case GEN_SOURCE:
2.93 - if( generate_decoder( rules, actions, out_file ) != 0 ) {
2.94 - exit(7);
2.95 - }
2.96 - break;
2.97 - case GEN_TEMPLATE:
2.98 - if( generate_template( rules, actions, out_file ) != 0 ) {
2.99 - exit(7);
2.100 - }
2.101 - break;
2.102 - }
2.103 - fclose( out_file );
2.104 - return 0;
2.105 -}
2.106 -
2.107 /**
2.108 * Find a mask that can be used to split up the given rules
2.109 */
2.110 @@ -191,7 +98,7 @@
2.111 }
2.112 }
2.113
2.114 -fprint_indent( char *action, int depth, FILE *f )
2.115 +void fprint_indent( char *action, int depth, FILE *f )
2.116 {
2.117 int spaces = 0, needed = depth*8, i;
2.118 char *text = action;
2.119 @@ -219,10 +126,9 @@
2.120 }
2.121 }
2.122
2.123 -fprint_action( struct rule *rule, char *action, int depth, FILE *f )
2.124 +void fprint_action( struct rule *rule, char *action, int depth, FILE *f )
2.125 {
2.126 int i;
2.127 - char tmp[64];
2.128 if( action == NULL ) {
2.129 fprintf( f, "%*cUNIMP(ir); /* %s */\n", depth*8, ' ', rule->format );
2.130 } else {
2.131 @@ -255,10 +161,9 @@
2.132 }
2.133 }
2.134
2.135 -int split_and_generate( struct ruleset *rules, struct actionset *actions,
2.136 +void split_and_generate( struct ruleset *rules, struct actionset *actions,
2.137 int ruleidx[], int rule_count, int input_mask,
2.138 int depth, FILE *f ) {
2.139 - char tmp[64];
2.140 uint32_t mask;
2.141 int i,j;
2.142
2.143 @@ -272,7 +177,7 @@
2.144 if( mask == 0 ) { /* No matching mask? */
2.145 fprintf( stderr, "Error: unable to find a valid bitmask (%d rules, %08X input mask)\n", rule_count, input_mask );
2.146 dump_rulesubset( rules, ruleidx, rule_count, stderr );
2.147 - return -1;
2.148 + return;
2.149 }
2.150
2.151 /* break up the rules into sub-sets, and process each sub-set.
2.152 @@ -351,3 +256,97 @@
2.153
2.154 return 0;
2.155 }
2.156 +
2.157 +
2.158 +int main( int argc, char *argv[] )
2.159 +{
2.160 + int opt;
2.161 +
2.162 + /* Parse the command line */
2.163 + while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
2.164 + switch( opt ) {
2.165 + case 't':
2.166 + gen_mode = GEN_TEMPLATE;
2.167 + break;
2.168 + case 'o':
2.169 + out_filename = optarg;
2.170 + break;
2.171 + case 'h':
2.172 + usage();
2.173 + exit(0);
2.174 + }
2.175 + }
2.176 + if( optind < argc ) {
2.177 + ins_filename = argv[optind++];
2.178 + }
2.179 + if( optind < argc ) {
2.180 + act_filename = argv[optind++];
2.181 + }
2.182 +
2.183 + if( optind < argc || ins_filename == NULL || act_filename == NULL ) {
2.184 + usage();
2.185 + exit(1);
2.186 + }
2.187 +
2.188 + if( out_filename == NULL ) {
2.189 + if( gen_mode == GEN_TEMPLATE ) {
2.190 + out_filename = act_filename;
2.191 + } else {
2.192 + char tmp[strlen(act_filename)+1];
2.193 + strcpy( tmp, act_filename);
2.194 + char *c = strrchr( tmp, '.' );
2.195 + if( c != NULL ) {
2.196 + *c = '\0';
2.197 + }
2.198 + out_filename = g_strconcat( tmp, DEFAULT_OUT_EXT, NULL );
2.199 + }
2.200 + }
2.201 +
2.202 + /* Open the files */
2.203 + ins_file = fopen( ins_filename, "ro" );
2.204 + if( ins_file == NULL ) {
2.205 + fprintf( stderr, "Unable to open '%s' for reading (%s)\n", ins_filename, strerror(errno) );
2.206 + exit(2);
2.207 + }
2.208 +
2.209 + act_file = fopen( act_filename, "ro" );
2.210 + if( act_file == NULL ) {
2.211 + fprintf( stderr, "Unable to open '%s' for reading (%s)\n", act_filename, strerror(errno) );
2.212 + exit(3);
2.213 + }
2.214 +
2.215 + /* Parse the input */
2.216 + struct ruleset *rules = parse_ruleset_file( ins_file );
2.217 + fclose( ins_file );
2.218 + if( rules == NULL ) {
2.219 + exit(5);
2.220 + }
2.221 +
2.222 + struct actionset *actions = parse_action_file( rules, act_file );
2.223 + fclose( act_file );
2.224 + if( actions == NULL ) {
2.225 + exit(6);
2.226 + }
2.227 +
2.228 + /* Finally write out the results */
2.229 + out_file = fopen( out_filename, "wo" );
2.230 + if( out_file == NULL ) {
2.231 + fprintf( stderr, "Unable to open '%s' for writing (%s)\n", out_filename, strerror(errno) );
2.232 + exit(4);
2.233 + }
2.234 +
2.235 + switch( gen_mode ) {
2.236 + case GEN_SOURCE:
2.237 + if( generate_decoder( rules, actions, out_file ) != 0 ) {
2.238 + exit(7);
2.239 + }
2.240 + break;
2.241 + case GEN_TEMPLATE:
2.242 + if( generate_template( rules, actions, out_file ) != 0 ) {
2.243 + exit(7);
2.244 + }
2.245 + break;
2.246 + }
2.247 + fclose( out_file );
2.248 + return 0;
2.249 +}
3.1 --- a/src/tools/gendec.h Thu Oct 04 10:49:41 2007 +0000
3.2 +++ b/src/tools/gendec.h Sat Oct 06 08:48:47 2007 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: gendec.h,v 1.1 2007-08-23 12:33:27 nkeynes Exp $
3.6 + * $Id: gendec.h,v 1.2 2007-10-06 08:48:47 nkeynes Exp $
3.7 *
3.8 * mem is responsible for creating and maintaining the overall system memory
3.9 * map, as visible from the SH4 processor. (Note the ARM has a different map)
3.10 @@ -61,7 +61,8 @@
3.11 };
3.12
3.13 struct ruleset *parse_ruleset_file( FILE *f );
3.14 - void dump_ruleset( struct ruleset *rules, FILE *f );
3.15 +void dump_ruleset( struct ruleset *rules, FILE *f );
3.16 +void dump_rulesubset( struct ruleset *rules, int ruleidx[], int rule_count, FILE *f );
3.17
3.18 struct action {
3.19 char operand_names[MAX_OPERANDS][MAX_OPERAND_NAME+1];
4.1 --- a/src/tools/insparse.c Thu Oct 04 10:49:41 2007 +0000
4.2 +++ b/src/tools/insparse.c Sat Oct 06 08:48:47 2007 +0000
4.3 @@ -13,6 +13,16 @@
4.4 return rule;
4.5 }
4.6
4.7 +int parse_registers_block( char *buf, int buflen, FILE *f );
4.8 +int parse_rule( char **str, struct rule *rule );
4.9 +int parse_bitstring( char **str, struct rule *rule );
4.10 +int parse_bitoperand( char **str, struct rule *rule );
4.11 +int parse_integer( char **str );
4.12 +int parse_rule_format( char **str, struct rule *rule );
4.13 +int parse_operand_uses( char **str, struct rule *rule );
4.14 +
4.15 +
4.16 +
4.17 struct ruleset *parse_ruleset_file( FILE *f )
4.18 {
4.19 struct ruleset *rules = malloc( sizeof(struct ruleset ) );
4.20 @@ -44,6 +54,7 @@
4.21 break;
4.22 }
4.23 } while( fgets( buf, buflen, f ) != NULL );
4.24 + return 0;
4.25 }
4.26
4.27 /**
4.28 @@ -113,7 +124,6 @@
4.29 int parse_bitoperand( char **str, struct rule *rule )
4.30 {
4.31 char *p = rule->operands[rule->operand_count].name;
4.32 - char tmp[8];
4.33
4.34 if( rule->operand_count == MAX_OPERANDS ) {
4.35 fprintf( stderr, "Maximum operands/rule exceeded (%d) at line %d\n", MAX_OPERANDS, yyline );
4.36 @@ -187,7 +197,7 @@
4.37
4.38 int parse_operand_uses( char **str, struct rule *rule )
4.39 {
4.40 -
4.41 + return 0;
4.42 }
4.43
4.44 void dump_ruleset( struct ruleset *rules, FILE *f )
.