From a7ae218e89859b5a5b8433f57029590b8877fc18 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Sun, 21 Apr 2019 15:55:21 -0400 Subject: Move cuobjdump parser to reentrant Signed-off-by: Mengchi Zhang --- libcuda/cuobjdump.l | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index 2b0dac8..9a468ba 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -38,9 +38,7 @@ #define YYDEBUG 1 -#define yylval cuobjdump_lval - -void cuobjdump_error(const char*); +void print_error(const char*, const char*, int); %} %option stack @@ -48,6 +46,8 @@ void cuobjdump_error(const char*); %option yylineno %option nounput +%option bison-bridge +%option reentrant %s ptxcode %s sasscode @@ -69,54 +69,54 @@ newlines {newline}+ "ptxasOptions"{notnewline}*{newline} -[1-9]{numeric}* yylval.string_value = strdup(yytext); return DECIMAL; +[1-9]{numeric}* yylval->string_value = strdup(yytext); return DECIMAL; "has debug info"{newline} "Fatbin ptx code:"{newline} { - yy_push_state(ptxcode); - yy_push_state(identifier); - yy_push_state(ptxheader); - yylval.string_value = strdup(yytext); + yy_push_state(ptxcode, yyscanner); + yy_push_state(identifier, yyscanner); + yy_push_state(ptxheader, yyscanner); + yylval->string_value = strdup(yytext); return PTXHEADER; } "Fatbin elf code:"{newline} { - yy_push_state(elfcode); - yy_push_state(identifier); - yy_push_state(elfheader); - yylval.string_value = strdup(yytext); + yy_push_state(elfcode, yyscanner); + yy_push_state(identifier, yyscanner); + yy_push_state(elfheader, yyscanner); + yylval->string_value = strdup(yytext); return ELFHEADER; } /*PTX code tokens*/ -{notnewline}*{newline} yylval.string_value = strdup(yytext); return PTXLINE; +{notnewline}*{newline} yylval->string_value = strdup(yytext); return PTXLINE; /*ELF code tokens*/ {whitespace}*"code for sm_"{numeric}+{newline} { BEGIN(sasscode); - yylval.string_value = strdup(yytext); + yylval->string_value = strdup(yytext); return SASSLINE; } -{notnewline}*{newline} yylval.string_value = strdup(yytext); return ELFLINE; +{notnewline}*{newline} yylval->string_value = strdup(yytext); return ELFLINE; /*SASS code tokens*/ -{notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; +{notnewline}*{newline} yylval->string_value = strdup(yytext); return SASSLINE; {newline}"compressed"{newline} BEGIN(conidentifier); return H_COMPRESSED; {newline}"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; -{newline}{newline} yy_pop_state(); +{newline}{newline} yy_pop_state(yyscanner); "identifier = " BEGIN(endidentifier); return H_IDENTIFIER; -{newline} yy_pop_state(); +{newline} yy_pop_state(yyscanner); -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; +{notnewline}+ yylval->string_value = strdup(yytext); yy_pop_state(yyscanner); return FILENAME; /*Header tokens*/ -[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +[[:alnum:]_]+ yylval->string_value = strdup(yytext); return IDENTIFIER; "================" return H_SEPARATOR; "arch = " return H_ARCH; "code version = " return H_CODEVERSION; @@ -128,7 +128,7 @@ newlines {newline}+ /*Header tokens*/ -[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +[[:alnum:]_]+ yylval->string_value = strdup(yytext); return IDENTIFIER; "================" return H_SEPARATOR; "arch = " return H_ARCH; "code version = " return H_CODEVERSION; @@ -143,7 +143,7 @@ newlines {newline}+ /* Looking for the identifier (filename) then the header is done */ -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return IDENTIFIER; +{notnewline}+ yylval->string_value = strdup(yytext); yy_pop_state(yyscanner); return IDENTIFIER; @@ -153,11 +153,11 @@ newlines {newline}+ <> BEGIN(INITIAL);return 0; /*No other rule matched. Throw an error*/ -. cuobjdump_error("Invalid token"); +. print_error("Invalid token", yytext, yylineno); %% -void cuobjdump_error(const char* message) +void print_error(const char* message, const char* text, int lineno) { - printf(" %s near \"%s\"",message, yytext); - printf(" on line %i\n",yylineno); + printf(" %s near \"%s\"",message, text); + printf(" on line %i\n",lineno); } -- cgit v1.3