/*Lex file for elf files output by cuobjdump*/ %{ #include #include #include "elf_parser.hpp" #define yylval elf_lval void elf_error(const char*); %} %option stack %option noyywrap %option yylineno %x cmem %x symtab whitespace [ \t] newline [\n] notnewline [^\n] newlines {newline}+ ident [[:alnum:]_\.] hexdigit [[:digit:]abcdef] %% \.nv\.constant1\.{notnewline}*{newline} { BEGIN(cmem); yylval.string_value = strdup(yytext); return C1BEGIN; } \.nv\.local{notnewline}*{newline} { BEGIN(INITIAL); yylval.string_value = strdup(yytext); return LOCALMEM; } \.nv\.constant0{notnewline}*{newline} { BEGIN(cmem); return C0BEGIN; } \.section" "\.symtab\tSYMTAB{newline} { BEGIN(symtab); return STBEGIN; } \.section{notnewline}*{newline} { //These are the lines before the symtab } \.{notnewline}*{newline} { BEGIN(INITIAL); } {notnewline}*{newline} { //printf("Discarding line %s", yytext); } " "{newline}? { //printf("#SPACE#"); return SPACE2; } 0x[0-9a-fA-F]{8} { //printf("CMEM VAL: %s \n", yytext); yylval.string_value = strdup(yytext); return CMEMVAL; } {whitespace}*[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+{newline} { return STHEADER; } {whitespace}+ {} {newline} {} {hexdigit}+ { yylval.string_value = strdup(yytext); return NUMBER; } {ident}+ { yylval.string_value = strdup(yytext); return IDENTIFIER; } {newline}{whitespace}*{newline}{whitespace}* { BEGIN(INITIAL); } /*Reached end of file*/ <> return 0; /*No other rule matched. Throw an error*/ . elf_error("Invalid token"); %% void elf_error(const char* message) { printf(" "); printf(message); printf(" near \""); printf(yytext); printf("\""); printf(" on line "); char line[5]; sprintf(line, "%i", yylineno); printf(line); printf("\n"); abort(); }