aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/dtc-lexer.l
diff options
context:
space:
mode:
authorJohn Bonesio <bones@secretlab.ca>2010-11-17 18:28:20 -0500
committerGrant Likely <grant.likely@secretlab.ca>2011-01-03 18:02:49 -0500
commit658f29a51e9830e620bb9a1ce3534b318a38bfeb (patch)
treee6cc7cd9b9e17d97308619fd8516b77bcc038114 /scripts/dtc/dtc-lexer.l
parentcd1e65044d4473cca9a01bae7b7938f065044a4b (diff)
of/flattree: Update dtc to current mainline.
Pull in recent changes from the main dtc repository. These changes primarily allow multiple device trees to be declared which are merged by dtc. This feature allows us to include a basic dts file and then provide more information for the specific system through the merging functionality. Changes pulled from git://git.jdl.com/software/dtc.git commit id: 37c0b6a0, "dtc: Add code to make diffing trees easier" Signed-off-by: John Bonesio <bones@secretlab.ca> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'scripts/dtc/dtc-lexer.l')
-rw-r--r--scripts/dtc/dtc-lexer.l175
1 files changed, 23 insertions, 152 deletions
diff --git a/scripts/dtc/dtc-lexer.l b/scripts/dtc/dtc-lexer.l
index a627bbee91d4..e866ea5166ac 100644
--- a/scripts/dtc/dtc-lexer.l
+++ b/scripts/dtc/dtc-lexer.l
@@ -18,7 +18,7 @@
18 * USA 18 * USA
19 */ 19 */
20 20
21%option noyywrap noinput nounput yylineno 21%option noyywrap nounput noinput never-interactive
22 22
23%x INCLUDE 23%x INCLUDE
24%x BYTESTRING 24%x BYTESTRING
@@ -38,6 +38,13 @@ LINECOMMENT "//".*\n
38#include "srcpos.h" 38#include "srcpos.h"
39#include "dtc-parser.tab.h" 39#include "dtc-parser.tab.h"
40 40
41YYLTYPE yylloc;
42
43/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
44#define YY_USER_ACTION \
45 { \
46 srcpos_update(&yylloc, yytext, yyleng); \
47 }
41 48
42/*#define LEXDEBUG 1*/ 49/*#define LEXDEBUG 1*/
43 50
@@ -47,15 +54,10 @@ LINECOMMENT "//".*\n
47#define DPRINT(fmt, ...) do { } while (0) 54#define DPRINT(fmt, ...) do { } while (0)
48#endif 55#endif
49 56
50static int dts_version; /* = 0 */ 57static int dts_version = 1;
51 58
52#define BEGIN_DEFAULT() if (dts_version == 0) { \ 59#define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
53 DPRINT("<INITIAL>\n"); \
54 BEGIN(INITIAL); \
55 } else { \
56 DPRINT("<V1>\n"); \
57 BEGIN(V1); \ 60 BEGIN(V1); \
58 }
59 61
60static void push_input_file(const char *filename); 62static void push_input_file(const char *filename);
61static int pop_input_file(void); 63static int pop_input_file(void);
@@ -75,18 +77,13 @@ static int pop_input_file(void);
75 } 77 }
76 78
77<*>{STRING} { 79<*>{STRING} {
78 yylloc.file = srcpos_file;
79 yylloc.first_line = yylineno;
80 DPRINT("String: %s\n", yytext); 80 DPRINT("String: %s\n", yytext);
81 yylval.data = data_copy_escape_string(yytext+1, 81 yylval.data = data_copy_escape_string(yytext+1,
82 yyleng-2); 82 yyleng-2);
83 yylloc.first_line = yylineno;
84 return DT_STRING; 83 return DT_STRING;
85 } 84 }
86 85
87<*>"/dts-v1/" { 86<*>"/dts-v1/" {
88 yylloc.file = srcpos_file;
89 yylloc.first_line = yylineno;
90 DPRINT("Keyword: /dts-v1/\n"); 87 DPRINT("Keyword: /dts-v1/\n");
91 dts_version = 1; 88 dts_version = 1;
92 BEGIN_DEFAULT(); 89 BEGIN_DEFAULT();
@@ -94,106 +91,57 @@ static int pop_input_file(void);
94 } 91 }
95 92
96<*>"/memreserve/" { 93<*>"/memreserve/" {
97 yylloc.file = srcpos_file;
98 yylloc.first_line = yylineno;
99 DPRINT("Keyword: /memreserve/\n"); 94 DPRINT("Keyword: /memreserve/\n");
100 BEGIN_DEFAULT(); 95 BEGIN_DEFAULT();
101 return DT_MEMRESERVE; 96 return DT_MEMRESERVE;
102 } 97 }
103 98
104<*>{LABEL}: { 99<*>{LABEL}: {
105 yylloc.file = srcpos_file;
106 yylloc.first_line = yylineno;
107 DPRINT("Label: %s\n", yytext); 100 DPRINT("Label: %s\n", yytext);
108 yylval.labelref = strdup(yytext); 101 yylval.labelref = xstrdup(yytext);
109 yylval.labelref[yyleng-1] = '\0'; 102 yylval.labelref[yyleng-1] = '\0';
110 return DT_LABEL; 103 return DT_LABEL;
111 } 104 }
112 105
113<INITIAL>[bodh]# {
114 yylloc.file = srcpos_file;
115 yylloc.first_line = yylineno;
116 if (*yytext == 'b')
117 yylval.cbase = 2;
118 else if (*yytext == 'o')
119 yylval.cbase = 8;
120 else if (*yytext == 'd')
121 yylval.cbase = 10;
122 else
123 yylval.cbase = 16;
124 DPRINT("Base: %d\n", yylval.cbase);
125 return DT_BASE;
126 }
127
128<INITIAL>[0-9a-fA-F]+ {
129 yylloc.file = srcpos_file;
130 yylloc.first_line = yylineno;
131 yylval.literal = strdup(yytext);
132 DPRINT("Literal: '%s'\n", yylval.literal);
133 return DT_LEGACYLITERAL;
134 }
135
136<V1>[0-9]+|0[xX][0-9a-fA-F]+ { 106<V1>[0-9]+|0[xX][0-9a-fA-F]+ {
137 yylloc.file = srcpos_file; 107 yylval.literal = xstrdup(yytext);
138 yylloc.first_line = yylineno;
139 yylval.literal = strdup(yytext);
140 DPRINT("Literal: '%s'\n", yylval.literal); 108 DPRINT("Literal: '%s'\n", yylval.literal);
141 return DT_LITERAL; 109 return DT_LITERAL;
142 } 110 }
143 111
144\&{LABEL} { /* label reference */ 112<*>\&{LABEL} { /* label reference */
145 yylloc.file = srcpos_file;
146 yylloc.first_line = yylineno;
147 DPRINT("Ref: %s\n", yytext+1); 113 DPRINT("Ref: %s\n", yytext+1);
148 yylval.labelref = strdup(yytext+1); 114 yylval.labelref = xstrdup(yytext+1);
149 return DT_REF; 115 return DT_REF;
150 } 116 }
151 117
152"&{/"{PATHCHAR}+\} { /* new-style path reference */ 118<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
153 yylloc.file = srcpos_file;
154 yylloc.first_line = yylineno;
155 yytext[yyleng-1] = '\0'; 119 yytext[yyleng-1] = '\0';
156 DPRINT("Ref: %s\n", yytext+2); 120 DPRINT("Ref: %s\n", yytext+2);
157 yylval.labelref = strdup(yytext+2); 121 yylval.labelref = xstrdup(yytext+2);
158 return DT_REF;
159 }
160
161<INITIAL>"&/"{PATHCHAR}+ { /* old-style path reference */
162 yylloc.file = srcpos_file;
163 yylloc.first_line = yylineno;
164 DPRINT("Ref: %s\n", yytext+1);
165 yylval.labelref = strdup(yytext+1);
166 return DT_REF; 122 return DT_REF;
167 } 123 }
168 124
169<BYTESTRING>[0-9a-fA-F]{2} { 125<BYTESTRING>[0-9a-fA-F]{2} {
170 yylloc.file = srcpos_file;
171 yylloc.first_line = yylineno;
172 yylval.byte = strtol(yytext, NULL, 16); 126 yylval.byte = strtol(yytext, NULL, 16);
173 DPRINT("Byte: %02x\n", (int)yylval.byte); 127 DPRINT("Byte: %02x\n", (int)yylval.byte);
174 return DT_BYTE; 128 return DT_BYTE;
175 } 129 }
176 130
177<BYTESTRING>"]" { 131<BYTESTRING>"]" {
178 yylloc.file = srcpos_file;
179 yylloc.first_line = yylineno;
180 DPRINT("/BYTESTRING\n"); 132 DPRINT("/BYTESTRING\n");
181 BEGIN_DEFAULT(); 133 BEGIN_DEFAULT();
182 return ']'; 134 return ']';
183 } 135 }
184 136
185<PROPNODENAME>{PROPNODECHAR}+ { 137<PROPNODENAME>{PROPNODECHAR}+ {
186 yylloc.file = srcpos_file;
187 yylloc.first_line = yylineno;
188 DPRINT("PropNodeName: %s\n", yytext); 138 DPRINT("PropNodeName: %s\n", yytext);
189 yylval.propnodename = strdup(yytext); 139 yylval.propnodename = xstrdup(yytext);
190 BEGIN_DEFAULT(); 140 BEGIN_DEFAULT();
191 return DT_PROPNODENAME; 141 return DT_PROPNODENAME;
192 } 142 }
193 143
194"/incbin/" { 144"/incbin/" {
195 yylloc.file = srcpos_file;
196 yylloc.first_line = yylineno;
197 DPRINT("Binary Include\n"); 145 DPRINT("Binary Include\n");
198 return DT_INCBIN; 146 return DT_INCBIN;
199 } 147 }
@@ -203,8 +151,6 @@ static int pop_input_file(void);
203<*>{LINECOMMENT}+ /* eat C++-style comments */ 151<*>{LINECOMMENT}+ /* eat C++-style comments */
204 152
205<*>. { 153<*>. {
206 yylloc.file = srcpos_file;
207 yylloc.first_line = yylineno;
208 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 154 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
209 (unsigned)yytext[0]); 155 (unsigned)yytext[0]);
210 if (yytext[0] == '[') { 156 if (yytext[0] == '[') {
@@ -221,100 +167,25 @@ static int pop_input_file(void);
221 167
222%% 168%%
223 169
224
225/*
226 * Stack of nested include file contexts.
227 */
228
229struct incl_file {
230 struct dtc_file *file;
231 YY_BUFFER_STATE yy_prev_buf;
232 int yy_prev_lineno;
233 struct incl_file *prev;
234};
235
236static struct incl_file *incl_file_stack;
237
238
239/*
240 * Detect infinite include recursion.
241 */
242#define MAX_INCLUDE_DEPTH (100)
243
244static int incl_depth = 0;
245
246
247static void push_input_file(const char *filename) 170static void push_input_file(const char *filename)
248{ 171{
249 struct incl_file *incl_file;
250 struct dtc_file *newfile;
251 struct search_path search, *searchptr = NULL;
252
253 assert(filename); 172 assert(filename);
254 173
255 if (incl_depth++ >= MAX_INCLUDE_DEPTH) 174 srcfile_push(filename);
256 die("Includes nested too deeply");
257
258 if (srcpos_file) {
259 search.dir = srcpos_file->dir;
260 search.next = NULL;
261 search.prev = NULL;
262 searchptr = &search;
263 }
264
265 newfile = dtc_open_file(filename, searchptr);
266 175
267 incl_file = xmalloc(sizeof(struct incl_file)); 176 yyin = current_srcfile->f;
268 177
269 /* 178 yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
270 * Save current context.
271 */
272 incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
273 incl_file->yy_prev_lineno = yylineno;
274 incl_file->file = srcpos_file;
275 incl_file->prev = incl_file_stack;
276
277 incl_file_stack = incl_file;
278
279 /*
280 * Establish new context.
281 */
282 srcpos_file = newfile;
283 yylineno = 1;
284 yyin = newfile->file;
285 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
286} 179}
287 180
288 181
289static int pop_input_file(void) 182static int pop_input_file(void)
290{ 183{
291 struct incl_file *incl_file; 184 if (srcfile_pop() == 0)
292
293 if (incl_file_stack == 0)
294 return 0; 185 return 0;
295 186
296 dtc_close_file(srcpos_file); 187 yypop_buffer_state();
297 188 yyin = current_srcfile->f;
298 /*
299 * Pop.
300 */
301 --incl_depth;
302 incl_file = incl_file_stack;
303 incl_file_stack = incl_file->prev;
304
305 /*
306 * Recover old context.
307 */
308 yy_delete_buffer(YY_CURRENT_BUFFER);
309 yy_switch_to_buffer(incl_file->yy_prev_buf);
310 yylineno = incl_file->yy_prev_lineno;
311 srcpos_file = incl_file->file;
312 yyin = incl_file->file ? incl_file->file->file : NULL;
313
314 /*
315 * Free old state.
316 */
317 free(incl_file);
318 189
319 return 1; 190 return 1;
320} 191}