aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/boot/dtc-src/dtc-lexer.l
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/boot/dtc-src/dtc-lexer.l')
-rw-r--r--arch/powerpc/boot/dtc-src/dtc-lexer.l120
1 files changed, 56 insertions, 64 deletions
diff --git a/arch/powerpc/boot/dtc-src/dtc-lexer.l b/arch/powerpc/boot/dtc-src/dtc-lexer.l
index c811b221b31e..44dbfd3f0976 100644
--- a/arch/powerpc/boot/dtc-src/dtc-lexer.l
+++ b/arch/powerpc/boot/dtc-src/dtc-lexer.l
@@ -28,6 +28,10 @@
28PROPNODECHAR [a-zA-Z0-9,._+*#?@-] 28PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
29PATHCHAR ({PROPNODECHAR}|[/]) 29PATHCHAR ({PROPNODECHAR}|[/])
30LABEL [a-zA-Z_][a-zA-Z0-9_]* 30LABEL [a-zA-Z_][a-zA-Z0-9_]*
31STRING \"([^\\"]|\\.)*\"
32WS [[:space:]]
33COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
34LINECOMMENT "//".*\n
31 35
32%{ 36%{
33#include "dtc.h" 37#include "dtc.h"
@@ -52,29 +56,26 @@ static int dts_version; /* = 0 */
52 DPRINT("<V1>\n"); \ 56 DPRINT("<V1>\n"); \
53 BEGIN(V1); \ 57 BEGIN(V1); \
54 } 58 }
59
60static void push_input_file(const char *filename);
61static int pop_input_file(void);
55%} 62%}
56 63
57%% 64%%
58<*>"/include/" BEGIN(INCLUDE); 65<*>"/include/"{WS}*{STRING} {
59 66 char *name = strchr(yytext, '\"') + 1;
60<INCLUDE>\"[^"\n]*\" { 67 yytext[yyleng-1] = '\0';
61 yytext[strlen(yytext) - 1] = 0; 68 push_input_file(name);
62 if (!push_input_file(yytext + 1)) {
63 /* Some unrecoverable error.*/
64 exit(1);
65 }
66 BEGIN_DEFAULT();
67 } 69 }
68 70
69
70<*><<EOF>> { 71<*><<EOF>> {
71 if (!pop_input_file()) { 72 if (!pop_input_file()) {
72 yyterminate(); 73 yyterminate();
73 } 74 }
74 } 75 }
75 76
76<*>\"([^\\"]|\\.)*\" { 77<*>{STRING} {
77 yylloc.filenum = srcpos_filenum; 78 yylloc.file = srcpos_file;
78 yylloc.first_line = yylineno; 79 yylloc.first_line = yylineno;
79 DPRINT("String: %s\n", yytext); 80 DPRINT("String: %s\n", yytext);
80 yylval.data = data_copy_escape_string(yytext+1, 81 yylval.data = data_copy_escape_string(yytext+1,
@@ -84,7 +85,7 @@ static int dts_version; /* = 0 */
84 } 85 }
85 86
86<*>"/dts-v1/" { 87<*>"/dts-v1/" {
87 yylloc.filenum = srcpos_filenum; 88 yylloc.file = srcpos_file;
88 yylloc.first_line = yylineno; 89 yylloc.first_line = yylineno;
89 DPRINT("Keyword: /dts-v1/\n"); 90 DPRINT("Keyword: /dts-v1/\n");
90 dts_version = 1; 91 dts_version = 1;
@@ -93,7 +94,7 @@ static int dts_version; /* = 0 */
93 } 94 }
94 95
95<*>"/memreserve/" { 96<*>"/memreserve/" {
96 yylloc.filenum = srcpos_filenum; 97 yylloc.file = srcpos_file;
97 yylloc.first_line = yylineno; 98 yylloc.first_line = yylineno;
98 DPRINT("Keyword: /memreserve/\n"); 99 DPRINT("Keyword: /memreserve/\n");
99 BEGIN_DEFAULT(); 100 BEGIN_DEFAULT();
@@ -101,7 +102,7 @@ static int dts_version; /* = 0 */
101 } 102 }
102 103
103<*>{LABEL}: { 104<*>{LABEL}: {
104 yylloc.filenum = srcpos_filenum; 105 yylloc.file = srcpos_file;
105 yylloc.first_line = yylineno; 106 yylloc.first_line = yylineno;
106 DPRINT("Label: %s\n", yytext); 107 DPRINT("Label: %s\n", yytext);
107 yylval.labelref = strdup(yytext); 108 yylval.labelref = strdup(yytext);
@@ -110,7 +111,7 @@ static int dts_version; /* = 0 */
110 } 111 }
111 112
112<INITIAL>[bodh]# { 113<INITIAL>[bodh]# {
113 yylloc.filenum = srcpos_filenum; 114 yylloc.file = srcpos_file;
114 yylloc.first_line = yylineno; 115 yylloc.first_line = yylineno;
115 if (*yytext == 'b') 116 if (*yytext == 'b')
116 yylval.cbase = 2; 117 yylval.cbase = 2;
@@ -125,7 +126,7 @@ static int dts_version; /* = 0 */
125 } 126 }
126 127
127<INITIAL>[0-9a-fA-F]+ { 128<INITIAL>[0-9a-fA-F]+ {
128 yylloc.filenum = srcpos_filenum; 129 yylloc.file = srcpos_file;
129 yylloc.first_line = yylineno; 130 yylloc.first_line = yylineno;
130 yylval.literal = strdup(yytext); 131 yylval.literal = strdup(yytext);
131 DPRINT("Literal: '%s'\n", yylval.literal); 132 DPRINT("Literal: '%s'\n", yylval.literal);
@@ -133,7 +134,7 @@ static int dts_version; /* = 0 */
133 } 134 }
134 135
135<V1>[0-9]+|0[xX][0-9a-fA-F]+ { 136<V1>[0-9]+|0[xX][0-9a-fA-F]+ {
136 yylloc.filenum = srcpos_filenum; 137 yylloc.file = srcpos_file;
137 yylloc.first_line = yylineno; 138 yylloc.first_line = yylineno;
138 yylval.literal = strdup(yytext); 139 yylval.literal = strdup(yytext);
139 DPRINT("Literal: '%s'\n", yylval.literal); 140 DPRINT("Literal: '%s'\n", yylval.literal);
@@ -141,7 +142,7 @@ static int dts_version; /* = 0 */
141 } 142 }
142 143
143\&{LABEL} { /* label reference */ 144\&{LABEL} { /* label reference */
144 yylloc.filenum = srcpos_filenum; 145 yylloc.file = srcpos_file;
145 yylloc.first_line = yylineno; 146 yylloc.first_line = yylineno;
146 DPRINT("Ref: %s\n", yytext+1); 147 DPRINT("Ref: %s\n", yytext+1);
147 yylval.labelref = strdup(yytext+1); 148 yylval.labelref = strdup(yytext+1);
@@ -149,7 +150,7 @@ static int dts_version; /* = 0 */
149 } 150 }
150 151
151"&{/"{PATHCHAR}+\} { /* new-style path reference */ 152"&{/"{PATHCHAR}+\} { /* new-style path reference */
152 yylloc.filenum = srcpos_filenum; 153 yylloc.file = srcpos_file;
153 yylloc.first_line = yylineno; 154 yylloc.first_line = yylineno;
154 yytext[yyleng-1] = '\0'; 155 yytext[yyleng-1] = '\0';
155 DPRINT("Ref: %s\n", yytext+2); 156 DPRINT("Ref: %s\n", yytext+2);
@@ -158,7 +159,7 @@ static int dts_version; /* = 0 */
158 } 159 }
159 160
160<INITIAL>"&/"{PATHCHAR}+ { /* old-style path reference */ 161<INITIAL>"&/"{PATHCHAR}+ { /* old-style path reference */
161 yylloc.filenum = srcpos_filenum; 162 yylloc.file = srcpos_file;
162 yylloc.first_line = yylineno; 163 yylloc.first_line = yylineno;
163 DPRINT("Ref: %s\n", yytext+1); 164 DPRINT("Ref: %s\n", yytext+1);
164 yylval.labelref = strdup(yytext+1); 165 yylval.labelref = strdup(yytext+1);
@@ -166,7 +167,7 @@ static int dts_version; /* = 0 */
166 } 167 }
167 168
168<BYTESTRING>[0-9a-fA-F]{2} { 169<BYTESTRING>[0-9a-fA-F]{2} {
169 yylloc.filenum = srcpos_filenum; 170 yylloc.file = srcpos_file;
170 yylloc.first_line = yylineno; 171 yylloc.first_line = yylineno;
171 yylval.byte = strtol(yytext, NULL, 16); 172 yylval.byte = strtol(yytext, NULL, 16);
172 DPRINT("Byte: %02x\n", (int)yylval.byte); 173 DPRINT("Byte: %02x\n", (int)yylval.byte);
@@ -174,7 +175,7 @@ static int dts_version; /* = 0 */
174 } 175 }
175 176
176<BYTESTRING>"]" { 177<BYTESTRING>"]" {
177 yylloc.filenum = srcpos_filenum; 178 yylloc.file = srcpos_file;
178 yylloc.first_line = yylineno; 179 yylloc.first_line = yylineno;
179 DPRINT("/BYTESTRING\n"); 180 DPRINT("/BYTESTRING\n");
180 BEGIN_DEFAULT(); 181 BEGIN_DEFAULT();
@@ -182,7 +183,7 @@ static int dts_version; /* = 0 */
182 } 183 }
183 184
184<PROPNODENAME>{PROPNODECHAR}+ { 185<PROPNODENAME>{PROPNODECHAR}+ {
185 yylloc.filenum = srcpos_filenum; 186 yylloc.file = srcpos_file;
186 yylloc.first_line = yylineno; 187 yylloc.first_line = yylineno;
187 DPRINT("PropNodeName: %s\n", yytext); 188 DPRINT("PropNodeName: %s\n", yytext);
188 yylval.propnodename = strdup(yytext); 189 yylval.propnodename = strdup(yytext);
@@ -190,20 +191,19 @@ static int dts_version; /* = 0 */
190 return DT_PROPNODENAME; 191 return DT_PROPNODENAME;
191 } 192 }
192 193
193 194"/incbin/" {
194<*>[[:space:]]+ /* eat whitespace */ 195 yylloc.file = srcpos_file;
195
196<*>"/*"([^*]|\*+[^*/])*\*+"/" {
197 yylloc.filenum = srcpos_filenum;
198 yylloc.first_line = yylineno; 196 yylloc.first_line = yylineno;
199 DPRINT("Comment: %s\n", yytext); 197 DPRINT("Binary Include\n");
200 /* eat comments */ 198 return DT_INCBIN;
201 } 199 }
202 200
203<*>"//".*\n /* eat line comments */ 201<*>{WS}+ /* eat whitespace */
202<*>{COMMENT}+ /* eat C-style comments */
203<*>{LINECOMMENT}+ /* eat C++-style comments */
204 204
205<*>. { 205<*>. {
206 yylloc.filenum = srcpos_filenum; 206 yylloc.file = srcpos_file;
207 yylloc.first_line = yylineno; 207 yylloc.first_line = yylineno;
208 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 208 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
209 (unsigned)yytext[0]); 209 (unsigned)yytext[0]);
@@ -227,14 +227,13 @@ static int dts_version; /* = 0 */
227 */ 227 */
228 228
229struct incl_file { 229struct incl_file {
230 int filenum; 230 struct dtc_file *file;
231 FILE *file;
232 YY_BUFFER_STATE yy_prev_buf; 231 YY_BUFFER_STATE yy_prev_buf;
233 int yy_prev_lineno; 232 int yy_prev_lineno;
234 struct incl_file *prev; 233 struct incl_file *prev;
235}; 234};
236 235
237struct incl_file *incl_file_stack; 236static struct incl_file *incl_file_stack;
238 237
239 238
240/* 239/*
@@ -245,36 +244,34 @@ struct incl_file *incl_file_stack;
245static int incl_depth = 0; 244static int incl_depth = 0;
246 245
247 246
248int push_input_file(const char *filename) 247static void push_input_file(const char *filename)
249{ 248{
250 FILE *f;
251 struct incl_file *incl_file; 249 struct incl_file *incl_file;
250 struct dtc_file *newfile;
251 struct search_path search, *searchptr = NULL;
252 252
253 if (!filename) { 253 assert(filename);
254 yyerror("No include file name given.");
255 return 0;
256 }
257 254
258 if (incl_depth++ >= MAX_INCLUDE_DEPTH) { 255 if (incl_depth++ >= MAX_INCLUDE_DEPTH)
259 yyerror("Includes nested too deeply"); 256 die("Includes nested too deeply");
260 return 0; 257
258 if (srcpos_file) {
259 search.dir = srcpos_file->dir;
260 search.next = NULL;
261 search.prev = NULL;
262 searchptr = &search;
261 } 263 }
262 264
263 f = dtc_open_file(filename); 265 newfile = dtc_open_file(filename, searchptr);
264 266
265 incl_file = malloc(sizeof(struct incl_file)); 267 incl_file = xmalloc(sizeof(struct incl_file));
266 if (!incl_file) {
267 yyerror("Can not allocate include file space.");
268 return 0;
269 }
270 268
271 /* 269 /*
272 * Save current context. 270 * Save current context.
273 */ 271 */
274 incl_file->yy_prev_buf = YY_CURRENT_BUFFER; 272 incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
275 incl_file->yy_prev_lineno = yylineno; 273 incl_file->yy_prev_lineno = yylineno;
276 incl_file->filenum = srcpos_filenum; 274 incl_file->file = srcpos_file;
277 incl_file->file = yyin;
278 incl_file->prev = incl_file_stack; 275 incl_file->prev = incl_file_stack;
279 276
280 incl_file_stack = incl_file; 277 incl_file_stack = incl_file;
@@ -282,23 +279,21 @@ int push_input_file(const char *filename)
282 /* 279 /*
283 * Establish new context. 280 * Establish new context.
284 */ 281 */
285 srcpos_filenum = lookup_file_name(filename, 0); 282 srcpos_file = newfile;
286 yylineno = 1; 283 yylineno = 1;
287 yyin = f; 284 yyin = newfile->file;
288 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); 285 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
289
290 return 1;
291} 286}
292 287
293 288
294int pop_input_file(void) 289static int pop_input_file(void)
295{ 290{
296 struct incl_file *incl_file; 291 struct incl_file *incl_file;
297 292
298 if (incl_file_stack == 0) 293 if (incl_file_stack == 0)
299 return 0; 294 return 0;
300 295
301 fclose(yyin); 296 dtc_close_file(srcpos_file);
302 297
303 /* 298 /*
304 * Pop. 299 * Pop.
@@ -313,16 +308,13 @@ int pop_input_file(void)
313 yy_delete_buffer(YY_CURRENT_BUFFER); 308 yy_delete_buffer(YY_CURRENT_BUFFER);
314 yy_switch_to_buffer(incl_file->yy_prev_buf); 309 yy_switch_to_buffer(incl_file->yy_prev_buf);
315 yylineno = incl_file->yy_prev_lineno; 310 yylineno = incl_file->yy_prev_lineno;
316 srcpos_filenum = incl_file->filenum; 311 srcpos_file = incl_file->file;
317 yyin = incl_file->file; 312 yyin = incl_file->file ? incl_file->file->file : NULL;
318 313
319 /* 314 /*
320 * Free old state. 315 * Free old state.
321 */ 316 */
322 free(incl_file); 317 free(incl_file);
323 318
324 if (YY_CURRENT_BUFFER == 0)
325 return 0;
326
327 return 1; 319 return 1;
328} 320}