From b2fc784cbb1c2e65736cea88d61509d08fddd83f Mon Sep 17 00:00:00 2001 From: ElTantawy Date: Thu, 12 May 2016 13:36:03 -0700 Subject: initial support for cuda 7.5 parsing --- libcuda/cuobjdump.l | 60 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index d7086ad..c86a861 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -52,8 +52,11 @@ void cuobjdump_error(const char*); %s ptxcode %s sasscode %s elfcode -%s header +%s elfheader +%s ptxheader %s endheader +%s identifier +%s identifierF alpha [a-zA-Z] numeric [0-9] @@ -67,16 +70,20 @@ newlines {newline}+ "ptxasOptions"{notnewline}*{newline} [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(header); + yy_push_state(identifier); + yy_push_state(ptxheader); yylval.string_value = strdup(yytext); return PTXHEADER; } "Fatbin elf code:"{newline} { yy_push_state(elfcode); - yy_push_state(header); + yy_push_state(identifier); + yy_push_state(elfheader); yylval.string_value = strdup(yytext); return ELFHEADER; } @@ -94,22 +101,45 @@ newlines {newline}+ /*SASS code tokens*/ {notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; +"identifier = " BEGIN(identifierF); return H_IDENTIFIER; +"\n" yy_pop_state(); + +{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; + + + + /*Header tokens*/ +[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +"================" return H_SEPARATOR; +"arch = " return H_ARCH; +"code version = " return H_CODEVERSION; +\[{numeric},{numeric}\] return CODEVERSION; +"producer = " return H_PRODUCER; +"" return H_UNKNOWN; +"host = " return H_HOST; +"compile_size = " BEGIN(endheader); return H_COMPILESIZE; + + /*Header tokens*/ -
[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; -
"================" return H_SEPARATOR; -
"arch = " return H_ARCH; -
"code version = " return H_CODEVERSION; -
\[{numeric},{numeric}\] return CODEVERSION; -
"producer = " return H_PRODUCER; -
"host = " return H_HOST; -
"compile_size = " return H_COMPILESIZE; -
"compressed"{newline} -
"identifier = " BEGIN(endheader); return H_IDENTIFIER; -
"has debug info"{newline} +[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +"================" return H_SEPARATOR; +"arch = " return H_ARCH; +"code version = " return H_CODEVERSION; +\[{numeric},{numeric}\] return CODEVERSION; +"producer = " return H_PRODUCER; +"host = " return H_HOST; +"compile_size = " return H_COMPILESIZE; +"compressed"{newline} yy_pop_state(); return H_COMPRESSED; + + + + + /* Looking for the identifier (filename) then the header is done */ /* [[:alnum:]_\./]+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; */ -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; +{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return IDENTIFIER; + {newline} return NEWLINE; -- cgit v1.3 From 0b95282e887e6cc6eb48d93d5aa51252588c3260 Mon Sep 17 00:00:00 2001 From: Ahmed ElTantawy Date: Fri, 13 May 2016 08:06:17 -0700 Subject: getting the parsing compatible with previous version - tested on 4.2, 5.5 and 7.5 --- libcuda/cuobjdump.l | 20 +++++++++++++------- libcuda/cuobjdump.y | 21 +++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index c86a861..f63ee73 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -55,8 +55,9 @@ void cuobjdump_error(const char*); %s elfheader %s ptxheader %s endheader -%s identifier -%s identifierF +%x identifier +%x conidentifier +%s endidentifier alpha [a-zA-Z] numeric [0-9] @@ -101,10 +102,16 @@ newlines {newline}+ /*SASS code tokens*/ {notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; -"identifier = " BEGIN(identifierF); return H_IDENTIFIER; -"\n" yy_pop_state(); +{newline}"compressed"{newline} BEGIN(conidentifier); return H_COMPRESSED; +{newline}"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; +{newline}{newline} yy_pop_state(); -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; + +"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; +{newline} yy_pop_state(); + + +{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; @@ -128,8 +135,7 @@ newlines {newline}+ \[{numeric},{numeric}\] return CODEVERSION; "producer = " return H_PRODUCER; "host = " return H_HOST; -"compile_size = " return H_COMPILESIZE; -"compressed"{newline} yy_pop_state(); return H_COMPRESSED; +"compile_size = " BEGIN(endheader); return H_COMPILESIZE; diff --git a/libcuda/cuobjdump.y b/libcuda/cuobjdump.y index 5fc0c8f..29509e8 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -39,7 +39,7 @@ void setCuobjdumpelffilename(const char* filename); void setCuobjdumpsassfilename(const char* filename); int elfserial = 1; int ptxserial = 1; - +int yydebug = 1; FILE *ptxfile; FILE *elffile; FILE *sassfile; @@ -75,7 +75,7 @@ section : PTXHEADER { snprintf(filename, 1024, "_cuobjdump_%d.ptx", ptxserial++); ptxfile = fopen(filename, "w"); setCuobjdumpptxfilename(filename); - } headerinfo identifier ptxcode { + } headerinfo compressedkeyword identifier ptxcode { fclose(ptxfile); } | ELFHEADER { @@ -84,6 +84,7 @@ section : PTXHEADER { elffile = fopen(filename, "w"); setCuobjdumpelffilename(filename); } headerinfo identifier{ + printf("\nHeader Info and Identifier Parsed\n"); } elfcode { fclose(elffile); snprintf(filename, 1024, "_cuobjdump_%d.sass", elfserial++); @@ -98,24 +99,20 @@ headerinfo : H_SEPARATOR NEWLINE H_CODEVERSION CODEVERSION NEWLINE H_PRODUCER H_UNKNOWN NEWLINE H_HOST IDENTIFIER NEWLINE - H_COMPILESIZE IDENTIFIER emptylines {setCuobjdumparch($4);}; + H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4);}; | H_SEPARATOR NEWLINE H_ARCH IDENTIFIER NEWLINE H_CODEVERSION CODEVERSION NEWLINE H_PRODUCER IDENTIFIER NEWLINE H_HOST IDENTIFIER NEWLINE - H_COMPILESIZE IDENTIFIER emptylines {setCuobjdumparch($4);}; - | H_SEPARATOR NEWLINE - H_ARCH IDENTIFIER NEWLINE - H_CODEVERSION CODEVERSION NEWLINE - H_PRODUCER IDENTIFIER NEWLINE - H_HOST IDENTIFIER NEWLINE - H_COMPILESIZE IDENTIFIER NEWLINE - H_COMPRESSED emptylines {setCuobjdumparch($4);}; + H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4);}; -identifier : H_IDENTIFIER FILENAME {setCuobjdumpidentifier($2);}; +identifier : H_IDENTIFIER FILENAME emptylines {setCuobjdumpidentifier($2);}; | ; +compressedkeyword : H_COMPRESSED emptylines + | ; + ptxcode : ptxcode PTXLINE {fprintf(ptxfile, "%s", $2);} | ; -- cgit v1.3