The attached patch makes the tgsi assembly parser report, in an admittedly rather crude way, the line number at which a syntax error was detected. What do you think about that?
z
From 7a7784d69ebf6a8b16386821217a5af232213cbc Mon Sep 17 00:00:00 2001 From: Zack Rusin <za...@vmware.com> Date: Tue, 15 Dec 2009 09:09:00 -0500 Subject: [PATCH 2/2] tgsi: make the assembly parser report the line number on error --- src/gallium/auxiliary/tgsi/tgsi_text.c | 131 ++++++++++++++++++++------------ 1 files changed, 81 insertions(+), 50 deletions(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index b47daa5..33141b1 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -76,21 +76,31 @@ static boolean str_match_no_case( const char **pcur, const char *str ) } /* Eat zero or more whitespaces. + * Return the number of lines eaten. */ -static void eat_opt_white( const char **pcur ) +static int eat_opt_white( const char **pcur ) { - while (**pcur == ' ' || **pcur == '\t' || **pcur == '\n') + int lines = 0; + while (**pcur == ' ' || **pcur == '\t' || **pcur == '\n') { + if (**pcur == '\n') + ++lines; (*pcur)++; + } + return lines; } /* Eat one or more whitespaces. * Return TRUE if at least one whitespace eaten. */ -static boolean eat_white( const char **pcur ) +static boolean eat_white( const char **pcur, int *lines ) { + int l; const char *cur = *pcur; - eat_opt_white( pcur ); + l = eat_opt_white( pcur ); + if (lines) { + *lines = l; + } return *pcur > cur; } @@ -178,11 +188,12 @@ struct translate_ctx struct tgsi_token *tokens_cur; struct tgsi_token *tokens_end; struct tgsi_header *header; + unsigned lineno; }; static void report_error( struct translate_ctx *ctx, const char *msg ) { - debug_printf( "\nError: %s", msg ); + debug_printf( "\nTGSI asm error: %s : %d\n", msg, ctx->lineno ); } /* Parse shader header. @@ -221,12 +232,14 @@ static boolean parse_header( struct translate_ctx *ctx ) static boolean parse_label( struct translate_ctx *ctx, uint *val ) { const char *cur = ctx->cur; + int lines = 0; if (parse_uint( &cur, val )) { - eat_opt_white( &cur ); + lines = eat_opt_white( &cur ); if (*cur == ':') { cur++; ctx->cur = cur; + ctx->lineno += lines; return TRUE; } } @@ -273,13 +286,13 @@ parse_opt_writemask( uint *writemask ) { const char *cur; - + int lines = 0; cur = ctx->cur; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); if (*cur == '.') { cur++; *writemask = TGSI_WRITEMASK_NONE; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); if (uprcase( *cur ) == 'X') { cur++; *writemask |= TGSI_WRITEMASK_X; @@ -303,6 +316,7 @@ parse_opt_writemask( } ctx->cur = cur; + ctx->cur += lines; } else { *writemask = TGSI_WRITEMASK_XYZW; @@ -321,7 +335,7 @@ parse_register_file_bracket( report_error( ctx, "Unknown register file" ); return FALSE; } - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != '[') { report_error( ctx, "Expected `['" ); return FALSE; @@ -342,7 +356,7 @@ parse_register_file_bracket_index( if (!parse_register_file_bracket( ctx, file )) return FALSE; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (!parse_uint( &ctx->cur, &uindex )) { report_error( ctx, "Expected literal unsigned integer" ); return FALSE; @@ -362,7 +376,7 @@ parse_register_dst( { if (!parse_register_file_bracket_index( ctx, file, index )) return FALSE; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != ']') { report_error( ctx, "Expected `]'" ); return FALSE; @@ -392,16 +406,16 @@ parse_register_src( *ind_comp = TGSI_SWIZZLE_X; if (!parse_register_file_bracket( ctx, file )) return FALSE; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); cur = ctx->cur; if (parse_file( &cur, ind_file )) { if (!parse_register_dst( ctx, ind_file, ind_index )) return FALSE; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur == '.') { ctx->cur++; - eat_opt_white(&ctx->cur); + ctx->lineno += eat_opt_white(&ctx->cur); switch (uprcase(*ctx->cur)) { case 'X': @@ -421,7 +435,7 @@ parse_register_src( return FALSE; } ctx->cur++; - eat_opt_white(&ctx->cur); + ctx->lineno += eat_opt_white(&ctx->cur); } if (*ctx->cur == '+' || *ctx->cur == '-') { @@ -429,7 +443,7 @@ parse_register_src( negate = *ctx->cur == '-'; ctx->cur++; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (!parse_uint( &ctx->cur, &uindex )) { report_error( ctx, "Expected literal unsigned integer" ); return FALSE; @@ -452,7 +466,7 @@ parse_register_src( *ind_file = TGSI_FILE_NULL; *ind_index = 0; } - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != ']') { report_error( ctx, "Expected `]'" ); return FALSE; @@ -474,18 +488,18 @@ parse_register_dcl( { if (!parse_register_file_bracket_index( ctx, file, first )) return FALSE; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (ctx->cur[0] == '.' && ctx->cur[1] == '.') { uint uindex; ctx->cur += 2; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (!parse_uint( &ctx->cur, &uindex )) { report_error( ctx, "Expected literal integer" ); return FALSE; } *last = (int) uindex; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); } else { *last = *first; @@ -531,15 +545,16 @@ parse_optional_swizzle( boolean *parsed_swizzle ) { const char *cur = ctx->cur; + int lines = 0; *parsed_swizzle = FALSE; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); if (*cur == '.') { uint i; cur++; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); for (i = 0; i < 4; i++) { if (uprcase( *cur ) == 'X') swizzle[i] = TGSI_SWIZZLE_X; @@ -557,6 +572,7 @@ parse_optional_swizzle( } *parsed_swizzle = TRUE; ctx->cur = cur; + ctx->lineno += lines; } return TRUE; } @@ -576,13 +592,13 @@ parse_src_operand( if (*ctx->cur == '-') { ctx->cur++; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); src->Register.Negate = 1; } if (*ctx->cur == '|') { ctx->cur++; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); src->Register.Absolute = 1; } @@ -612,7 +628,7 @@ parse_src_operand( } if (src->Register.Absolute) { - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != '|') { report_error( ctx, "Expected `|'" ); return FALSE; @@ -660,9 +676,10 @@ parse_instruction( /* Parse instruction name. */ - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); for (i = 0; i < TGSI_OPCODE_LAST; i++) { const char *cur = ctx->cur; + int lines = 0; info = tgsi_get_opcode_info( i ); if (match_inst_mnemonic(&cur, info)) { @@ -677,8 +694,9 @@ parse_instruction( break; } } - else if (*cur == '\0' || eat_white( &cur )) { + else if (*cur == '\0' || eat_white( &cur, &lines )) { ctx->cur = cur; + ctx->lineno += lines; break; } } @@ -701,13 +719,13 @@ parse_instruction( */ for (i = 0; i < info->num_dst + info->num_src + info->is_tex; i++) { if (i > 0) { - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != ',') { report_error( ctx, "Expected `,'" ); return FALSE; } ctx->cur++; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); } if (i < info->num_dst) { @@ -740,13 +758,13 @@ parse_instruction( if (info->is_branch) { uint target; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != ':') { report_error( ctx, "Expected `:'" ); return FALSE; } ctx->cur++; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (!parse_uint( &ctx->cur, &target )) { report_error( ctx, "Expected a label" ); return FALSE; @@ -797,14 +815,16 @@ static boolean parse_declaration( struct translate_ctx *ctx ) uint writemask; const char *cur; uint advance; + int lines = 0; assert(Elements(semantic_names) == TGSI_SEMANTIC_COUNT); assert(Elements(interpolate_names) == TGSI_INTERPOLATE_COUNT); - if (!eat_white( &ctx->cur )) { + if (!eat_white( &ctx->cur, &lines )) { report_error( ctx, "Syntax error" ); return FALSE; } + ctx->lineno += lines; lines = 0; if (!parse_register_dcl( ctx, &file, &first, &last )) return FALSE; if (!parse_opt_writemask( ctx, &writemask )) @@ -817,28 +837,29 @@ static boolean parse_declaration( struct translate_ctx *ctx ) decl.Range.Last = last; cur = ctx->cur; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); if (*cur == ',') { uint i; cur++; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); for (i = 0; i < TGSI_SEMANTIC_COUNT; i++) { if (str_match_no_case( &cur, semantic_names[i] )) { const char *cur2 = cur; uint index; + int lines2 = 0; if (is_digit_alpha_underscore( cur )) continue; - eat_opt_white( &cur2 ); + lines2 += eat_opt_white( &cur2 ); if (*cur2 == '[') { cur2++; - eat_opt_white( &cur2 ); + lines2 += eat_opt_white( &cur2 ); if (!parse_uint( &cur2, &index )) { report_error( ctx, "Expected literal integer" ); return FALSE; } - eat_opt_white( &cur2 ); + lines2 += eat_opt_white( &cur2 ); if (*cur2 != ']') { report_error( ctx, "Expected `]'" ); return FALSE; @@ -848,24 +869,27 @@ static boolean parse_declaration( struct translate_ctx *ctx ) decl.Semantic.Index = index; cur = cur2; + lines += lines2; } decl.Declaration.Semantic = 1; decl.Semantic.Name = i; ctx->cur = cur; + ctx->lineno += lines; + lines = 0; break; } } } cur = ctx->cur; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); if (*cur == ',') { uint i; cur++; - eat_opt_white( &cur ); + lines += eat_opt_white( &cur ); for (i = 0; i < TGSI_INTERPOLATE_COUNT; i++) { if (str_match_no_case( &cur, interpolate_names[i] )) { if (is_digit_alpha_underscore( cur )) @@ -873,6 +897,7 @@ static boolean parse_declaration( struct translate_ctx *ctx ) decl.Declaration.Interpolate = i; ctx->cur = cur; + ctx->lineno += lines; break; } } @@ -900,37 +925,39 @@ static boolean parse_immediate( struct translate_ctx *ctx ) uint i; float values[4]; uint advance; + int lines = 0; - if (!eat_white( &ctx->cur )) { + if (!eat_white( &ctx->cur, &lines )) { report_error( ctx, "Syntax error" ); return FALSE; } + ctx->lineno += lines; lines = 0; if (!str_match_no_case( &ctx->cur, "FLT32" ) || is_digit_alpha_underscore( ctx->cur )) { report_error( ctx, "Expected `FLT32'" ); return FALSE; } - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != '{') { report_error( ctx, "Expected `{'" ); return FALSE; } ctx->cur++; for (i = 0; i < 4; i++) { - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (i > 0) { if (*ctx->cur != ',') { report_error( ctx, "Expected `,'" ); return FALSE; } ctx->cur++; - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); } if (!parse_float( &ctx->cur, &values[i] )) { report_error( ctx, "Expected literal floating point" ); return FALSE; } } - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (*ctx->cur != '}') { report_error( ctx, "Expected `}'" ); return FALSE; @@ -1003,11 +1030,13 @@ static boolean parse_property( struct translate_ctx *ctx ) uint values[8]; uint advance; char id[64]; + int lines = 0; - if (!eat_white( &ctx->cur )) { + if (!eat_white( &ctx->cur, &lines )) { report_error( ctx, "Syntax error" ); return FALSE; } + ctx->lineno += lines; lines = 0; if (!parse_identifier( &ctx->cur, id )) { report_error( ctx, "Syntax error" ); return FALSE; @@ -1024,7 +1053,7 @@ static boolean parse_property( struct translate_ctx *ctx ) return FALSE; } - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); switch(property_name) { case TGSI_PROPERTY_GS_INPUT_PRIM: case TGSI_PROPERTY_GS_OUTPUT_PRIM: @@ -1060,17 +1089,18 @@ static boolean parse_property( struct translate_ctx *ctx ) static boolean translate( struct translate_ctx *ctx ) { - eat_opt_white( &ctx->cur ); + ctx->lineno += eat_opt_white( &ctx->cur ); if (!parse_header( ctx )) return FALSE; while (*ctx->cur != '\0') { uint label_val = 0; - if (!eat_white( &ctx->cur )) { + int lines = 0; + if (!eat_white( &ctx->cur, &lines )) { report_error( ctx, "Syntax error" ); return FALSE; } - + ctx->lineno += lines; lines = 0; if (*ctx->cur == '\0') break; if (parse_label( ctx, &label_val )) { @@ -1110,6 +1140,7 @@ tgsi_text_translate( ctx.tokens = tokens; ctx.tokens_cur = tokens; ctx.tokens_end = tokens + num_tokens; + ctx.lineno = 0; if (!translate( &ctx )) return FALSE; -- 1.6.5.4
------------------------------------------------------------------------------ Return on Information: Google Enterprise Search pays you back Get the facts. http://p.sf.net/sfu/google-dev2dev
_______________________________________________ Mesa3d-dev mailing list Mesa3d-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mesa3d-dev