summaryrefslogtreecommitdiff
path: root/assembler
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2013-01-26 19:51:28 +0000
committerDamien Lespiau <damien.lespiau@intel.com>2013-03-04 15:54:39 +0000
commitd94e8a6cf0952e0a905699a47a50e57181fb414f (patch)
tree83058a98466637dcc2939ece276bd72ba272c47c /assembler
parent574a249142f0b3140bda599326e581bb36b328da (diff)
assembler: Add location support
Let's generate location information about the tokens we are parsing. This can be used to give accurate location when reporting errors and warnings. Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'assembler')
-rw-r--r--assembler/gram.y1
-rw-r--r--assembler/lex.l24
2 files changed, 19 insertions, 6 deletions
diff --git a/assembler/gram.y b/assembler/gram.y
index 8b56bd9a..9a4e5103 100644
--- a/assembler/gram.y
+++ b/assembler/gram.y
@@ -276,6 +276,7 @@ static void resolve_subnr(struct brw_reg *reg)
%}
+%locations
%start ROOT
diff --git a/assembler/lex.l b/assembler/lex.l
index 626042f6..769d98b1 100644
--- a/assembler/lex.l
+++ b/assembler/lex.l
@@ -9,6 +9,15 @@
int saved_state = 0;
extern char *input_filename;
+/* Locations */
+int yycolumn = 1;
+
+#define YY_USER_ACTION \
+ yylloc.first_line = yylloc.last_line = yylineno; \
+ yylloc.first_column = yycolumn; \
+ yylloc.last_column = yycolumn+yyleng-1; \
+ yycolumn += yyleng;
+
%}
%x BLOCK_COMMENT
%x CHANNEL
@@ -16,11 +25,11 @@ extern char *input_filename;
%x FILENAME
%%
-\/\/.*[\r\n] { } /* eat up single-line comments */
-"\.kernel".*[\r\n] { }
-"\.end_kernel".*[\r\n] { }
-"\.code".*[\r\n] { }
-"\.end_code".*[\r\n] { }
+\/\/.*[\r\n] { yycolumn = 1; } /* eat up single-line comments */
+"\.kernel".*[\r\n] { yycolumn = 1; }
+"\.end_kernel".*[\r\n] { yycolumn = 1; }
+"\.code".*[\r\n] { yycolumn = 1; }
+"\.end_code".*[\r\n] { yycolumn = 1; }
/* eat up multi-line comments, non-nesting. */
\/\* {
@@ -33,6 +42,7 @@ extern char *input_filename;
<BLOCK_COMMENT>. { }
<BLOCK_COMMENT>[\r\n] { }
"#line"" "* {
+ yycolumn = 1;
saved_state = YYSTATE;
BEGIN(LINENUMBER);
}
@@ -407,7 +417,9 @@ yylval.integer = BRW_CHANNEL_W;
return NUMBER;
}
-[ \t\n]+ { } /* eat up whitespace */
+[ \t]+ { } /* eat up whitespace */
+
+\n { yycolumn = 1; }
. {
fprintf(stderr, "%s: %d: %s at \"%s\"\n",