revision 979:2cc7b486ea6c
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 979:2cc7b486ea6c |
parent | 978:eed5089fcfdb |
child | 980:deb4361928fe |
author | nkeynes |
date | Wed Feb 04 00:58:54 2009 +0000 (15 years ago) |
Emit #line directives in output to make debugging a little easier
src/tools/actparse.c | view | annotate | diff | log | ||
src/tools/gendec.c | view | annotate | diff | log | ||
src/tools/gendec.h | view | annotate | diff | log |
1.1 --- a/src/tools/actparse.c Wed Feb 04 00:57:04 2009 +00001.2 +++ b/src/tools/actparse.c Wed Feb 04 00:58:54 2009 +00001.3 @@ -24,15 +24,7 @@1.4 #include <glib/gstrfuncs.h>1.5 #include "tools/gendec.h"1.7 -static int yyline;1.8 -1.9 -struct action *new_action() {1.10 - struct action *action = malloc( sizeof( struct action ) );1.11 - memset( action, 0, sizeof( struct action ) );1.12 - return action;1.13 -}1.14 -1.15 -static int add_action( char **actions, struct ruleset *rules, char *operation, char *action )1.16 +static int add_action( struct action *actions, struct ruleset *rules, char *operation, const char *file, int line, char *action )1.17 {1.18 char *act = g_strchomp(action);1.19 char opclean[strlen(operation)+1];1.20 @@ -60,16 +52,27 @@1.21 }1.22 }1.23 *q = '\0';1.24 -1.25 +1.26 + /* Drop any leading blank lines from the start of the action (and add them1.27 + * to the line number ) */1.28 + for( p=act; isspace(*p); p++ ) {1.29 + if( *p == '\n' ) {1.30 + act = p+1;1.31 + line++;1.32 + }1.33 + }1.34 +1.35 strcpy( operation, g_strstrip(opclean) );1.37 for( i=0; i<rules->rule_count; i++ ) {1.38 if( strcasecmp(rules->rules[i]->format, operation) == 0 ) {1.39 - if( actions[i] != NULL ) {1.40 + if( actions[i].text != NULL ) {1.41 fprintf( stderr, "Duplicate actions for operation '%s'\n", operation );1.42 return -1;1.43 }1.44 - actions[i] = act;1.45 + actions[i].filename = file;1.46 + actions[i].lineno = line;1.47 + actions[i].text = act;1.48 return 0;1.49 }1.50 }1.51 @@ -79,6 +82,7 @@1.53 struct actionfile {1.54 FILE *f;1.55 + const char *filename;1.56 char *text;1.57 int length;1.58 int yyposn;1.59 @@ -97,14 +101,17 @@1.61 actionfile_t af = malloc( sizeof(struct actionfile) );1.62 af->f = f;1.63 + af->filename = filename;1.64 af->length = st.st_size+1;1.65 af->text = malloc( st.st_size+1 );1.66 fread( af->text, st.st_size, 1, f );1.67 af->text[st.st_size] = '\0';1.68 - af->yyline = 0;1.69 + af->yyline = 1;1.70 af->yyposn = 0;1.71 af->rules = rules;1.72 af->token.symbol = NONE;1.73 + af->token.lineno = 1;1.74 + af->token.filename = filename;1.76 return af;1.77 }1.78 @@ -115,7 +122,7 @@1.79 /* Destroy previous actions */1.80 memset( af->token.actions, 0, sizeof(af->token.actions) );1.81 }1.82 -1.83 + af->token.lineno = af->yyline;1.84 if( af->yyposn == af->length ) {1.85 af->token.symbol = END;1.86 } else if( af->token.symbol == TEXT || /* ACTIONS must follow TEXT */1.87 @@ -126,7 +133,7 @@1.88 char *operation = &af->text[af->yyposn];1.89 while( af->yyposn < af->length ) {1.90 if( af->text[af->yyposn] == '\n' ) {1.91 - yyline++;1.92 + af->yyline++;1.93 if( af->text[af->yyposn+1] == '%' && af->text[af->yyposn+2] == '%' ) {1.94 af->yyposn += 3;1.95 break;1.96 @@ -135,18 +142,21 @@1.98 if( af->text[af->yyposn] == '{' && af->text[af->yyposn+1] == ':' ) {1.99 af->text[af->yyposn] = '\0';1.100 + int line = af->yyline;1.101 af->yyposn+=2;1.102 char *action = &af->text[af->yyposn];1.103 while( af->yyposn < af->length ) {1.104 if( af->text[af->yyposn] == ':' && af->text[af->yyposn+1] == '}' ) {1.105 af->text[af->yyposn] = '\0';1.106 af->yyposn++;1.107 - if( add_action( af->token.actions, af->rules, operation, action ) != 0 ) {1.108 + if( add_action( af->token.actions, af->rules, operation, af->filename, line, action ) != 0 ) {1.109 af->token.symbol = ERROR;1.110 return &af->token;1.111 }1.112 operation = &af->text[af->yyposn+1];1.113 break;1.114 + } else if( af->text[af->yyposn] == '\n' ) {1.115 + af->yyline++;1.116 }1.117 af->yyposn++;1.118 }
2.1 --- a/src/tools/gendec.c Wed Feb 04 00:57:04 2009 +00002.2 +++ b/src/tools/gendec.c Wed Feb 04 00:58:54 2009 +00002.3 @@ -98,10 +98,10 @@2.4 }2.5 }2.7 -static void fprint_indent( char *action, int depth, FILE *f )2.8 +static void fprint_indent( const char *action, int depth, FILE *f )2.9 {2.10 int spaces = 0, needed = depth*8, i;2.11 - char *text = action;2.12 + const char *text = action;2.14 /* Determine number of spaces in first line of input */2.15 for( i=0; isspace(action[i]); i++ ) {2.16 @@ -126,7 +126,7 @@2.17 }2.18 }2.20 -static void fprint_action( struct rule *rule, char *action, int depth, FILE *f )2.21 +static void fprint_action( struct rule *rule, const struct action *action, int depth, FILE *f )2.22 {2.23 int i;2.24 if( action == NULL ) {2.25 @@ -154,14 +154,15 @@2.26 }2.27 }2.28 fputs( "\n", f );2.29 - if( action[0] != '\0' ) {2.30 - fprint_indent( action, depth, f );2.31 + if( action->text && action->text[0] != '\0' ) {2.32 + fprintf( f, "#line %d \"%s\"\n", action->lineno, action->filename );2.33 + fprint_indent( action->text, depth, f );2.34 }2.35 fprintf( f, "%*c}\n", depth*8, ' ' );2.36 }2.37 }2.39 -static void split_and_generate( struct ruleset *rules, char **actions,2.40 +static void split_and_generate( struct ruleset *rules, const struct action *actions,2.41 int ruleidx[], int rule_count, int input_mask,2.42 int depth, FILE *f ) {2.43 uint32_t mask;2.44 @@ -170,7 +171,7 @@2.45 if( rule_count == 0 ) {2.46 fprintf( f, "%*cUNDEF(ir);\n", depth*8, ' ' );2.47 } else if( rule_count == 1 ) {2.48 - fprint_action( rules->rules[ruleidx[0]], actions[ruleidx[0]], depth, f );2.49 + fprint_action( rules->rules[ruleidx[0]], &actions[ruleidx[0]], depth, f );2.50 } else {2.52 mask = find_mask(rules, ruleidx, rule_count, input_mask);2.53 @@ -235,6 +236,7 @@2.54 actiontoken_t token = action_file_next(af);2.55 while( token->symbol != END ) {2.56 if( token->symbol == TEXT ) {2.57 + fprintf( out, "#line %d \"%s\"\n", token->lineno, token->filename );2.58 fputs( token->text, out );2.59 } else if( token->symbol == ERROR ) {2.60 fprintf( stderr, "Error parsing action file" );2.61 @@ -262,7 +264,7 @@2.62 fputs( "%%\n", out );2.63 for( i=0; i<rules->rule_count; i++ ) {2.64 fprintf( out, "%s {: %s :}\n", rules->rules[i]->format,2.65 - token->actions[i] == NULL ? "" : token->actions[i] );2.66 + token->actions[i].text == NULL ? "" : token->actions[i].text );2.67 }2.68 fputs( "%%\n", out );2.69 }
3.1 --- a/src/tools/gendec.h Wed Feb 04 00:57:04 2009 +00003.2 +++ b/src/tools/gendec.h Wed Feb 04 00:58:54 2009 +00003.3 @@ -65,20 +65,19 @@3.4 void dump_rulesubset( struct ruleset *rules, int ruleidx[], int rule_count, FILE *f );3.6 struct action {3.7 - char operand_names[MAX_OPERANDS][MAX_OPERAND_NAME+1];3.8 - char *body;3.9 -};3.10 -3.11 -struct actionset {3.12 - char *actions[MAX_RULES];3.13 + const char *filename;3.14 + int lineno;3.15 + const char *text;3.16 };3.18 typedef struct actionfile *actionfile_t;3.20 typedef struct actiontoken {3.21 enum { NONE, TEXT, ACTIONS, END, ERROR } symbol;3.22 + const char *filename;3.23 + int lineno;3.24 char *text;3.25 - char *actions[MAX_RULES];3.26 + struct action actions[MAX_RULES];3.27 } *actiontoken_t;3.29 actionfile_t action_file_open( const char *filename, struct ruleset *rules );
.