blob: 3457a7ac9e7b38e36b3c3c4fea7e04191cb98500 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*Lex file for elf files output by cuobjdump*/
%{
#include <stdio.h>
#include <string.h>
#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]
%%
<cmem,INITIAL>\.nv\.constant1\.{notnewline}*{newline} {
BEGIN(cmem);
yylval.string_value = strdup(yytext);
return C1BEGIN;
}
<cmem,INITIAL>\.nv\.local{notnewline}*{newline} {
BEGIN(INITIAL);
yylval.string_value = strdup(yytext);
return LOCALMEM;
}
<cmem,INITIAL>\.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
}
<cmem,INITIAL>\.{notnewline}*{newline} {
BEGIN(INITIAL);
}
{notnewline}*{newline} {
//printf("Discarding line %s", yytext);
}
<cmem>" "{newline}? {
//printf("#SPACE#");
return SPACE2;
}
<cmem>0x[0-9a-fA-F]{8} {
//printf("CMEM VAL: %s \n", yytext);
yylval.string_value = strdup(yytext);
return CMEMVAL;
}
<symtab>{whitespace}*[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+[[:alpha:]]+{whitespace}+{newline} {
return STHEADER;
}
<symtab>{whitespace}+ {}
<symtab>{newline} {}
<symtab>{hexdigit}+ {
yylval.string_value = strdup(yytext);
return NUMBER;
}
<symtab>{ident}+ {
yylval.string_value = strdup(yytext);
return IDENTIFIER;
}
<symtab>{newline}{whitespace}*{newline}{whitespace}* {
BEGIN(INITIAL);
}
/*Reached end of file*/
<<EOF>> 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();
}
|