aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dtc')
-rw-r--r--scripts/dtc/Makefile3
-rw-r--r--scripts/dtc/checks.c105
-rw-r--r--scripts/dtc/dtc-lexer.l175
-rw-r--r--scripts/dtc/dtc-lexer.lex.c_shipped551
-rw-r--r--scripts/dtc/dtc-parser.tab.c_shipped892
-rw-r--r--scripts/dtc/dtc-parser.tab.h_shipped82
-rw-r--r--scripts/dtc/dtc-parser.y160
-rw-r--r--scripts/dtc/dtc.c57
-rw-r--r--scripts/dtc/dtc.h77
-rw-r--r--scripts/dtc/flattree.c192
-rw-r--r--scripts/dtc/fstree.c12
-rw-r--r--scripts/dtc/livetree.c345
-rw-r--r--scripts/dtc/srcpos.c258
-rw-r--r--scripts/dtc/srcpos.h99
-rw-r--r--scripts/dtc/treesource.c48
-rw-r--r--scripts/dtc/util.c59
-rw-r--r--scripts/dtc/util.h56
-rw-r--r--scripts/dtc/version_gen.h2
18 files changed, 1721 insertions, 1452 deletions
diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile
index 01cdb36fc583..04a31c17639f 100644
--- a/scripts/dtc/Makefile
+++ b/scripts/dtc/Makefile
@@ -4,7 +4,7 @@ hostprogs-y := dtc
4always := $(hostprogs-y) 4always := $(hostprogs-y)
5 5
6dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ 6dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \
7 srcpos.o checks.o 7 srcpos.o checks.o util.o
8dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o 8dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o
9 9
10# Source files need to get at the userspace version of libfdt_env.h to compile 10# Source files need to get at the userspace version of libfdt_env.h to compile
@@ -19,6 +19,7 @@ HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC)
19HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC) 19HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC)
20HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC) 20HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC)
21HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC) 21HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC)
22HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC)
22 23
23HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC) 24HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC)
24HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC) 25HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)
diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c
index 95485796f253..a662a0044798 100644
--- a/scripts/dtc/checks.c
+++ b/scripts/dtc/checks.c
@@ -278,32 +278,112 @@ static void check_property_name_chars(struct check *c, struct node *dt,
278} 278}
279PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR); 279PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR);
280 280
281#define DESCLABEL_FMT "%s%s%s%s%s"
282#define DESCLABEL_ARGS(node,prop,mark) \
283 ((mark) ? "value of " : ""), \
284 ((prop) ? "'" : ""), \
285 ((prop) ? (prop)->name : ""), \
286 ((prop) ? "' in " : ""), (node)->fullpath
287
288static void check_duplicate_label(struct check *c, struct node *dt,
289 const char *label, struct node *node,
290 struct property *prop, struct marker *mark)
291{
292 struct node *othernode = NULL;
293 struct property *otherprop = NULL;
294 struct marker *othermark = NULL;
295
296 othernode = get_node_by_label(dt, label);
297
298 if (!othernode)
299 otherprop = get_property_by_label(dt, label, &othernode);
300 if (!othernode)
301 othermark = get_marker_label(dt, label, &othernode,
302 &otherprop);
303
304 if (!othernode)
305 return;
306
307 if ((othernode != node) || (otherprop != prop) || (othermark != mark))
308 FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT
309 " and " DESCLABEL_FMT,
310 label, DESCLABEL_ARGS(node, prop, mark),
311 DESCLABEL_ARGS(othernode, otherprop, othermark));
312}
313
314static void check_duplicate_label_node(struct check *c, struct node *dt,
315 struct node *node)
316{
317 struct label *l;
318
319 for_each_label(node->labels, l)
320 check_duplicate_label(c, dt, l->label, node, NULL, NULL);
321}
322static void check_duplicate_label_prop(struct check *c, struct node *dt,
323 struct node *node, struct property *prop)
324{
325 struct marker *m = prop->val.markers;
326 struct label *l;
327
328 for_each_label(prop->labels, l)
329 check_duplicate_label(c, dt, l->label, node, prop, NULL);
330
331 for_each_marker_of_type(m, LABEL)
332 check_duplicate_label(c, dt, m->ref, node, prop, m);
333}
334CHECK(duplicate_label, NULL, check_duplicate_label_node,
335 check_duplicate_label_prop, NULL, ERROR);
336
281static void check_explicit_phandles(struct check *c, struct node *root, 337static void check_explicit_phandles(struct check *c, struct node *root,
282 struct node *node) 338 struct node *node, struct property *prop)
283{ 339{
284 struct property *prop; 340 struct marker *m;
285 struct node *other; 341 struct node *other;
286 cell_t phandle; 342 cell_t phandle;
287 343
288 prop = get_property(node, "linux,phandle"); 344 if (!streq(prop->name, "phandle")
289 if (! prop) 345 && !streq(prop->name, "linux,phandle"))
290 return; /* No phandle, that's fine */ 346 return;
291 347
292 if (prop->val.len != sizeof(cell_t)) { 348 if (prop->val.len != sizeof(cell_t)) {
293 FAIL(c, "%s has bad length (%d) linux,phandle property", 349 FAIL(c, "%s has bad length (%d) %s property",
294 node->fullpath, prop->val.len); 350 node->fullpath, prop->val.len, prop->name);
351 return;
352 }
353
354 m = prop->val.markers;
355 for_each_marker_of_type(m, REF_PHANDLE) {
356 assert(m->offset == 0);
357 if (node != get_node_by_ref(root, m->ref))
358 /* "Set this node's phandle equal to some
359 * other node's phandle". That's nonsensical
360 * by construction. */ {
361 FAIL(c, "%s in %s is a reference to another node",
362 prop->name, node->fullpath);
363 return;
364 }
365 /* But setting this node's phandle equal to its own
366 * phandle is allowed - that means allocate a unique
367 * phandle for this node, even if it's not otherwise
368 * referenced. The value will be filled in later, so
369 * no further checking for now. */
295 return; 370 return;
296 } 371 }
297 372
298 phandle = propval_cell(prop); 373 phandle = propval_cell(prop);
374
299 if ((phandle == 0) || (phandle == -1)) { 375 if ((phandle == 0) || (phandle == -1)) {
300 FAIL(c, "%s has invalid linux,phandle value 0x%x", 376 FAIL(c, "%s has bad value (0x%x) in %s property",
301 node->fullpath, phandle); 377 node->fullpath, phandle, prop->name);
302 return; 378 return;
303 } 379 }
304 380
381 if (node->phandle && (node->phandle != phandle))
382 FAIL(c, "%s has %s property which replaces existing phandle information",
383 node->fullpath, prop->name);
384
305 other = get_node_by_phandle(root, phandle); 385 other = get_node_by_phandle(root, phandle);
306 if (other) { 386 if (other && (other != node)) {
307 FAIL(c, "%s has duplicated phandle 0x%x (seen before at %s)", 387 FAIL(c, "%s has duplicated phandle 0x%x (seen before at %s)",
308 node->fullpath, phandle, other->fullpath); 388 node->fullpath, phandle, other->fullpath);
309 return; 389 return;
@@ -311,7 +391,7 @@ static void check_explicit_phandles(struct check *c, struct node *root,
311 391
312 node->phandle = phandle; 392 node->phandle = phandle;
313} 393}
314NODE_CHECK(explicit_phandles, NULL, ERROR); 394PROP_CHECK(explicit_phandles, NULL, ERROR);
315 395
316static void check_name_properties(struct check *c, struct node *root, 396static void check_name_properties(struct check *c, struct node *root,
317 struct node *node) 397 struct node *node)
@@ -549,6 +629,9 @@ static struct check *check_table[] = {
549 &duplicate_node_names, &duplicate_property_names, 629 &duplicate_node_names, &duplicate_property_names,
550 &node_name_chars, &node_name_format, &property_name_chars, 630 &node_name_chars, &node_name_format, &property_name_chars,
551 &name_is_string, &name_properties, 631 &name_is_string, &name_properties,
632
633 &duplicate_label,
634
552 &explicit_phandles, 635 &explicit_phandles,
553 &phandle_references, &path_references, 636 &phandle_references, &path_references,
554 637
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}
diff --git a/scripts/dtc/dtc-lexer.lex.c_shipped b/scripts/dtc/dtc-lexer.lex.c_shipped
index e27cc636e326..50c4420b4b2c 100644
--- a/scripts/dtc/dtc-lexer.lex.c_shipped
+++ b/scripts/dtc/dtc-lexer.lex.c_shipped
@@ -170,20 +170,7 @@ extern FILE *yyin, *yyout;
170#define EOB_ACT_END_OF_FILE 1 170#define EOB_ACT_END_OF_FILE 1
171#define EOB_ACT_LAST_MATCH 2 171#define EOB_ACT_LAST_MATCH 2
172 172
173 /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires 173 #define YY_LESS_LINENO(n)
174 * access to the local variable yy_act. Since yyless() is a macro, it would break
175 * existing scanners that call yyless() from OUTSIDE yylex.
176 * One obvious solution it to make yy_act a global. I tried that, and saw
177 * a 5% performance hit in a non-yylineno scanner, because yy_act is
178 * normally declared as a register variable-- so it is not worth it.
179 */
180 #define YY_LESS_LINENO(n) \
181 do { \
182 int yyl;\
183 for ( yyl = n; yyl < yyleng; ++yyl )\
184 if ( yytext[yyl] == '\n' )\
185 --yylineno;\
186 }while(0)
187 174
188/* Return all but the first "n" matched characters back to the input stream. */ 175/* Return all but the first "n" matched characters back to the input stream. */
189#define yyless(n) \ 176#define yyless(n) \
@@ -385,8 +372,8 @@ static void yy_fatal_error (yyconst char msg[] );
385 *yy_cp = '\0'; \ 372 *yy_cp = '\0'; \
386 (yy_c_buf_p) = yy_cp; 373 (yy_c_buf_p) = yy_cp;
387 374
388#define YY_NUM_RULES 20 375#define YY_NUM_RULES 17
389#define YY_END_OF_BUFFER 21 376#define YY_END_OF_BUFFER 18
390/* This struct is not used in this scanner, 377/* This struct is not used in this scanner,
391 but its presence is necessary. */ 378 but its presence is necessary. */
392struct yy_trans_info 379struct yy_trans_info
@@ -394,20 +381,19 @@ struct yy_trans_info
394 flex_int32_t yy_verify; 381 flex_int32_t yy_verify;
395 flex_int32_t yy_nxt; 382 flex_int32_t yy_nxt;
396 }; 383 };
397static yyconst flex_int16_t yy_accept[104] = 384static yyconst flex_int16_t yy_accept[94] =
398 { 0, 385 { 0,
399 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 386 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
400 21, 19, 16, 16, 19, 19, 19, 7, 7, 19, 387 18, 16, 13, 13, 16, 16, 16, 16, 16, 16,
401 7, 19, 19, 19, 19, 13, 14, 14, 19, 8, 388 16, 10, 11, 11, 6, 6, 13, 0, 2, 0,
402 8, 16, 0, 2, 0, 0, 9, 0, 0, 0, 389 7, 0, 0, 0, 0, 0, 0, 0, 5, 0,
403 0, 0, 0, 7, 7, 5, 0, 6, 0, 12, 390 9, 9, 11, 11, 6, 0, 7, 0, 0, 0,
404 12, 14, 14, 8, 0, 11, 9, 0, 0, 0, 391 0, 15, 0, 0, 0, 0, 6, 0, 14, 0,
405 0, 18, 0, 0, 0, 0, 8, 0, 17, 0, 392 0, 0, 0, 0, 8, 0, 0, 0, 0, 0,
406 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 393 0, 0, 0, 0, 0, 0, 0, 0, 3, 12,
407 0, 0, 0, 0, 0, 0, 0, 0, 3, 15,
408 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 394 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
409
410 0, 4, 0 395 0, 4, 0
396
411 } ; 397 } ;
412 398
413static yyconst flex_int32_t yy_ec[256] = 399static yyconst flex_int32_t yy_ec[256] =
@@ -416,16 +402,16 @@ static yyconst flex_int32_t yy_ec[256] =
416 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 402 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
417 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 403 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
418 1, 2, 1, 4, 5, 1, 1, 6, 1, 1, 404 1, 2, 1, 4, 5, 1, 1, 6, 1, 1,
419 1, 7, 8, 8, 9, 8, 10, 11, 12, 13, 405 1, 7, 5, 5, 8, 5, 9, 10, 11, 12,
420 13, 13, 13, 13, 13, 13, 13, 14, 1, 1, 406 12, 12, 12, 12, 12, 12, 12, 13, 1, 1,
421 1, 1, 8, 8, 15, 15, 15, 15, 15, 15, 407 1, 1, 5, 5, 14, 14, 14, 14, 14, 14,
422 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 408 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
423 16, 16, 16, 16, 16, 16, 16, 17, 16, 16, 409 15, 15, 15, 15, 15, 15, 15, 16, 15, 15,
424 1, 18, 19, 1, 16, 1, 15, 20, 21, 22, 410 1, 17, 18, 1, 15, 1, 14, 19, 20, 21,
425 411
426 23, 15, 16, 24, 25, 16, 16, 26, 27, 28, 412 22, 14, 15, 15, 23, 15, 15, 24, 25, 26,
427 24, 16, 16, 29, 30, 31, 32, 33, 16, 17, 413 15, 15, 15, 27, 28, 29, 30, 31, 15, 16,
428 16, 16, 34, 1, 35, 1, 1, 1, 1, 1, 414 15, 15, 32, 1, 33, 1, 1, 1, 1, 1,
429 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 415 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
430 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 416 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
431 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 417 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -442,136 +428,114 @@ static yyconst flex_int32_t yy_ec[256] =
442 1, 1, 1, 1, 1 428 1, 1, 1, 1, 1
443 } ; 429 } ;
444 430
445static yyconst flex_int32_t yy_meta[36] = 431static yyconst flex_int32_t yy_meta[34] =
446 { 0, 432 { 0,
447 1, 1, 1, 1, 2, 1, 2, 2, 2, 3, 433 1, 1, 1, 1, 2, 1, 2, 2, 3, 4,
448 4, 4, 4, 5, 6, 7, 7, 1, 1, 6, 434 4, 4, 5, 6, 7, 7, 1, 1, 6, 6,
449 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 435 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
450 7, 7, 7, 8, 1 436 7, 8, 1
451 } ; 437 } ;
452 438
453static yyconst flex_int16_t yy_base[117] = 439static yyconst flex_int16_t yy_base[106] =
454 { 0, 440 { 0,
455 0, 0, 30, 0, 44, 0, 67, 0, 97, 105, 441 0, 0, 237, 236, 25, 0, 47, 0, 30, 71,
456 302, 303, 35, 44, 40, 94, 112, 0, 129, 152, 442 244, 247, 82, 84, 84, 211, 95, 229, 218, 0,
457 296, 295, 159, 0, 176, 303, 0, 116, 95, 165, 443 111, 247, 0, 84, 83, 95, 106, 86, 247, 237,
458 49, 46, 102, 303, 296, 0, 0, 288, 290, 293, 444 0, 230, 231, 234, 207, 209, 212, 220, 247, 206,
459 264, 266, 270, 0, 0, 303, 0, 303, 264, 303, 445 247, 218, 0, 106, 116, 0, 0, 0, 223, 89,
460 0, 0, 195, 101, 0, 0, 0, 0, 284, 125, 446 226, 219, 199, 206, 200, 204, 0, 190, 213, 212,
461 277, 265, 225, 230, 216, 218, 0, 202, 224, 221, 447 202, 91, 178, 161, 247, 172, 144, 150, 140, 130,
462 217, 107, 196, 188, 303, 206, 179, 186, 178, 185, 448 140, 124, 128, 120, 138, 137, 123, 122, 247, 247,
463 183, 162, 161, 150, 169, 160, 145, 125, 303, 303, 449 134, 114, 132, 86, 135, 125, 90, 136, 247, 97,
464 137, 109, 190, 103, 203, 167, 108, 197, 303, 123, 450 29, 247, 247, 153, 156, 161, 165, 170, 176, 180,
465 451
466 29, 303, 303, 215, 221, 226, 229, 234, 240, 246, 452 187, 195, 200, 205, 212
467 250, 257, 265, 270, 275, 282
468 } ; 453 } ;
469 454
470static yyconst flex_int16_t yy_def[117] = 455static yyconst flex_int16_t yy_def[106] =
471 { 0, 456 { 0,
472 103, 1, 1, 3, 3, 5, 103, 7, 3, 3, 457 93, 1, 1, 1, 1, 5, 93, 7, 1, 1,
473 103, 103, 103, 103, 104, 105, 103, 106, 103, 19, 458 93, 93, 93, 93, 94, 95, 93, 96, 17, 97,
474 19, 20, 103, 107, 20, 103, 108, 109, 105, 103, 459 96, 93, 98, 99, 93, 93, 93, 94, 93, 94,
475 103, 103, 104, 103, 104, 110, 111, 103, 112, 113, 460 100, 93, 101, 102, 93, 93, 93, 96, 93, 93,
476 103, 103, 103, 106, 19, 103, 20, 103, 103, 103, 461 93, 96, 98, 99, 93, 103, 100, 104, 101, 101,
477 20, 108, 109, 103, 114, 110, 111, 115, 112, 112, 462 102, 93, 93, 93, 93, 93, 103, 104, 93, 93,
478 113, 103, 103, 103, 103, 103, 114, 115, 103, 103, 463 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
479 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 464 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
480 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 465 93, 93, 93, 93, 93, 105, 93, 105, 93, 105,
481 103, 103, 103, 103, 103, 116, 103, 116, 103, 116, 466 93, 93, 0, 93, 93, 93, 93, 93, 93, 93,
482 467
483 103, 103, 0, 103, 103, 103, 103, 103, 103, 103, 468 93, 93, 93, 93, 93
484 103, 103, 103, 103, 103, 103
485 } ; 469 } ;
486 470
487static yyconst flex_int16_t yy_nxt[339] = 471static yyconst flex_int16_t yy_nxt[281] =
488 { 0, 472 { 0,
489 12, 13, 14, 15, 12, 16, 12, 12, 12, 17, 473 12, 13, 14, 15, 12, 16, 12, 12, 17, 12,
490 18, 18, 18, 12, 19, 20, 20, 12, 12, 21, 474 12, 12, 12, 18, 18, 18, 12, 12, 18, 18,
491 19, 21, 19, 22, 20, 20, 20, 20, 20, 20, 475 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
492 20, 20, 20, 12, 12, 12, 32, 32, 102, 23, 476 18, 12, 12, 19, 20, 20, 20, 92, 21, 25,
493 12, 12, 12, 34, 20, 32, 32, 32, 32, 20, 477 26, 26, 22, 21, 21, 21, 21, 12, 13, 14,
494 20, 20, 20, 20, 24, 24, 24, 35, 25, 54, 478 15, 23, 16, 23, 23, 19, 23, 23, 23, 12,
495 54, 54, 26, 25, 25, 25, 25, 12, 13, 14, 479 24, 24, 24, 12, 12, 24, 24, 24, 24, 24,
496 15, 27, 12, 27, 27, 27, 23, 27, 27, 27, 480 24, 24, 24, 24, 24, 24, 24, 24, 12, 12,
497 12, 28, 28, 28, 12, 12, 28, 28, 28, 28, 481 25, 26, 26, 27, 27, 27, 27, 29, 43, 29,
498 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 482 43, 43, 45, 45, 45, 50, 39, 59, 46, 93,
499 483
500 12, 12, 29, 36, 103, 34, 17, 30, 31, 31, 484 30, 33, 30, 34, 45, 45, 45, 27, 27, 68,
501 29, 54, 54, 54, 17, 30, 31, 31, 39, 35, 485 43, 91, 43, 43, 69, 35, 87, 36, 39, 37,
502 52, 40, 52, 52, 52, 103, 78, 38, 38, 46, 486 42, 42, 42, 39, 42, 45, 45, 45, 89, 42,
503 101, 60, 79, 41, 69, 97, 42, 94, 43, 45, 487 42, 42, 42, 85, 85, 86, 85, 85, 86, 89,
504 45, 45, 46, 45, 47, 47, 93, 92, 45, 45, 488 84, 90, 83, 82, 81, 80, 79, 78, 77, 76,
505 45, 45, 47, 47, 47, 47, 47, 47, 47, 47, 489 75, 74, 90, 28, 28, 28, 28, 28, 28, 28,
506 47, 47, 47, 47, 47, 39, 47, 91, 40, 90, 490 28, 31, 31, 31, 38, 38, 38, 38, 41, 73,
507 99, 47, 47, 47, 47, 54, 54, 54, 89, 88, 491 41, 43, 72, 43, 71, 43, 43, 44, 33, 44,
508 41, 55, 87, 49, 100, 43, 51, 51, 51, 86, 492 44, 44, 44, 47, 69, 47, 47, 49, 49, 49,
509 51, 95, 95, 96, 85, 51, 51, 51, 51, 52, 493 49, 49, 49, 49, 49, 51, 51, 51, 51, 51,
510 494
511 99, 52, 52, 52, 95, 95, 96, 84, 46, 83, 495 51, 51, 51, 57, 70, 57, 58, 58, 58, 67,
512 82, 81, 39, 79, 100, 33, 33, 33, 33, 33, 496 58, 58, 88, 88, 88, 88, 88, 88, 88, 88,
513 33, 33, 33, 37, 80, 77, 37, 37, 37, 44, 497 34, 66, 65, 64, 63, 62, 61, 60, 52, 50,
514 40, 44, 50, 76, 50, 52, 75, 52, 74, 52, 498 39, 56, 39, 55, 54, 53, 52, 50, 48, 93,
515 52, 53, 73, 53, 53, 53, 53, 56, 56, 56, 499 40, 39, 32, 93, 19, 19, 11, 93, 93, 93,
516 72, 56, 56, 57, 71, 57, 57, 59, 59, 59, 500 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
517 59, 59, 59, 59, 59, 61, 61, 61, 61, 61, 501 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
518 61, 61, 61, 67, 70, 67, 68, 68, 68, 62, 502 93, 93, 93, 93, 93, 93, 93, 93, 93, 93
519 68, 68, 98, 98, 98, 98, 98, 98, 98, 98,
520 60, 66, 65, 64, 63, 62, 60, 58, 103, 48,
521
522 48, 103, 11, 103, 103, 103, 103, 103, 103, 103,
523 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
524 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
525 103, 103, 103, 103, 103, 103, 103, 103
526 } ; 503 } ;
527 504
528static yyconst flex_int16_t yy_chk[339] = 505static yyconst flex_int16_t yy_chk[281] =
529 { 0, 506 { 0,
530 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 507 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
531 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 508 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
532 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 509 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
533 1, 1, 1, 1, 1, 3, 13, 13, 101, 3, 510 1, 1, 1, 5, 5, 5, 5, 91, 5, 9,
534 3, 3, 3, 15, 3, 14, 14, 32, 32, 3, 511 9, 9, 5, 5, 5, 5, 5, 7, 7, 7,
535 3, 3, 3, 3, 5, 5, 5, 15, 5, 31,
536 31, 31, 5, 5, 5, 5, 5, 7, 7, 7,
537 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 512 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
538 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 513 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
539 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 514 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
540 515 10, 10, 10, 13, 13, 14, 14, 15, 24, 28,
541 7, 7, 9, 16, 29, 33, 9, 9, 9, 9, 516 24, 24, 25, 25, 25, 50, 24, 50, 25, 90,
542 10, 54, 54, 54, 10, 10, 10, 10, 17, 33, 517
543 28, 17, 28, 28, 28, 100, 72, 16, 29, 28, 518 15, 17, 28, 17, 26, 26, 26, 27, 27, 62,
544 97, 60, 72, 17, 60, 94, 17, 92, 17, 19, 519 44, 87, 44, 44, 62, 17, 84, 17, 44, 17,
545 19, 19, 19, 19, 19, 19, 91, 88, 19, 19, 520 21, 21, 21, 21, 21, 45, 45, 45, 86, 21,
546 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 521 21, 21, 21, 83, 83, 83, 85, 85, 85, 88,
547 19, 19, 20, 20, 20, 23, 20, 87, 23, 86, 522 82, 86, 81, 78, 77, 76, 75, 74, 73, 72,
548 96, 20, 20, 20, 20, 30, 30, 30, 85, 84, 523 71, 70, 88, 94, 94, 94, 94, 94, 94, 94,
549 23, 30, 83, 23, 96, 23, 25, 25, 25, 82, 524 94, 95, 95, 95, 96, 96, 96, 96, 97, 69,
550 25, 93, 93, 93, 81, 25, 25, 25, 25, 53, 525 97, 98, 68, 98, 67, 98, 98, 99, 66, 99,
551 526 99, 99, 99, 100, 64, 100, 100, 101, 101, 101,
552 98, 53, 53, 53, 95, 95, 95, 80, 53, 79, 527 101, 101, 101, 101, 101, 102, 102, 102, 102, 102,
553 78, 77, 76, 74, 98, 104, 104, 104, 104, 104, 528
554 104, 104, 104, 105, 73, 71, 105, 105, 105, 106, 529 102, 102, 102, 103, 63, 103, 104, 104, 104, 61,
555 70, 106, 107, 69, 107, 108, 68, 108, 66, 108, 530 104, 104, 105, 105, 105, 105, 105, 105, 105, 105,
556 108, 109, 65, 109, 109, 109, 109, 110, 110, 110, 531 60, 59, 58, 56, 55, 54, 53, 52, 51, 49,
557 64, 110, 110, 111, 63, 111, 111, 112, 112, 112, 532 42, 40, 38, 37, 36, 35, 34, 33, 32, 30,
558 112, 112, 112, 112, 112, 113, 113, 113, 113, 113, 533 19, 18, 16, 11, 4, 3, 93, 93, 93, 93,
559 113, 113, 113, 114, 62, 114, 115, 115, 115, 61, 534 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
560 115, 115, 116, 116, 116, 116, 116, 116, 116, 116, 535 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
561 59, 49, 43, 42, 41, 40, 39, 38, 35, 22, 536 93, 93, 93, 93, 93, 93, 93, 93, 93, 93
562
563 21, 11, 103, 103, 103, 103, 103, 103, 103, 103,
564 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
565 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
566 103, 103, 103, 103, 103, 103, 103, 103
567 } ; 537 } ;
568 538
569/* Table of booleans, true if rule could match eol. */
570static yyconst flex_int32_t yy_rule_can_match_eol[21] =
571 { 0,
5721, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
573 0, };
574
575static yy_state_type yy_last_accepting_state; 539static yy_state_type yy_last_accepting_state;
576static char *yy_last_accepting_cpos; 540static char *yy_last_accepting_cpos;
577 541
@@ -616,6 +580,13 @@ char *yytext;
616#include "srcpos.h" 580#include "srcpos.h"
617#include "dtc-parser.tab.h" 581#include "dtc-parser.tab.h"
618 582
583YYLTYPE yylloc;
584
585/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
586#define YY_USER_ACTION \
587 { \
588 srcpos_update(&yylloc, yytext, yyleng); \
589 }
619 590
620/*#define LEXDEBUG 1*/ 591/*#define LEXDEBUG 1*/
621 592
@@ -625,19 +596,14 @@ char *yytext;
625#define DPRINT(fmt, ...) do { } while (0) 596#define DPRINT(fmt, ...) do { } while (0)
626#endif 597#endif
627 598
628static int dts_version; /* = 0 */ 599static int dts_version = 1;
629 600
630#define BEGIN_DEFAULT() if (dts_version == 0) { \ 601#define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
631 DPRINT("<INITIAL>\n"); \
632 BEGIN(INITIAL); \
633 } else { \
634 DPRINT("<V1>\n"); \
635 BEGIN(V1); \ 602 BEGIN(V1); \
636 }
637 603
638static void push_input_file(const char *filename); 604static void push_input_file(const char *filename);
639static int pop_input_file(void); 605static int pop_input_file(void);
640#line 641 "dtc-lexer.lex.c" 606#line 607 "dtc-lexer.lex.c"
641 607
642#define INITIAL 0 608#define INITIAL 0
643#define INCLUDE 1 609#define INCLUDE 1
@@ -826,9 +792,9 @@ YY_DECL
826 register char *yy_cp, *yy_bp; 792 register char *yy_cp, *yy_bp;
827 register int yy_act; 793 register int yy_act;
828 794
829#line 64 "dtc-lexer.l" 795#line 66 "dtc-lexer.l"
830 796
831#line 832 "dtc-lexer.lex.c" 797#line 798 "dtc-lexer.lex.c"
832 798
833 if ( !(yy_init) ) 799 if ( !(yy_init) )
834 { 800 {
@@ -881,35 +847,21 @@ yy_match:
881 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 847 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
882 { 848 {
883 yy_current_state = (int) yy_def[yy_current_state]; 849 yy_current_state = (int) yy_def[yy_current_state];
884 if ( yy_current_state >= 104 ) 850 if ( yy_current_state >= 94 )
885 yy_c = yy_meta[(unsigned int) yy_c]; 851 yy_c = yy_meta[(unsigned int) yy_c];
886 } 852 }
887 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 853 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
888 ++yy_cp; 854 ++yy_cp;
889 } 855 }
890 while ( yy_base[yy_current_state] != 303 ); 856 while ( yy_current_state != 93 );
857 yy_cp = (yy_last_accepting_cpos);
858 yy_current_state = (yy_last_accepting_state);
891 859
892yy_find_action: 860yy_find_action:
893 yy_act = yy_accept[yy_current_state]; 861 yy_act = yy_accept[yy_current_state];
894 if ( yy_act == 0 )
895 { /* have to back up */
896 yy_cp = (yy_last_accepting_cpos);
897 yy_current_state = (yy_last_accepting_state);
898 yy_act = yy_accept[yy_current_state];
899 }
900 862
901 YY_DO_BEFORE_ACTION; 863 YY_DO_BEFORE_ACTION;
902 864
903 if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
904 {
905 int yyl;
906 for ( yyl = 0; yyl < yyleng; ++yyl )
907 if ( yytext[yyl] == '\n' )
908
909 yylineno++;
910;
911 }
912
913do_action: /* This label is used only to access EOF actions. */ 865do_action: /* This label is used only to access EOF actions. */
914 866
915 switch ( yy_act ) 867 switch ( yy_act )
@@ -924,7 +876,7 @@ do_action: /* This label is used only to access EOF actions. */
924case 1: 876case 1:
925/* rule 1 can match eol */ 877/* rule 1 can match eol */
926YY_RULE_SETUP 878YY_RULE_SETUP
927#line 65 "dtc-lexer.l" 879#line 67 "dtc-lexer.l"
928{ 880{
929 char *name = strchr(yytext, '\"') + 1; 881 char *name = strchr(yytext, '\"') + 1;
930 yytext[yyleng-1] = '\0'; 882 yytext[yyleng-1] = '\0';
@@ -936,7 +888,7 @@ case YY_STATE_EOF(INCLUDE):
936case YY_STATE_EOF(BYTESTRING): 888case YY_STATE_EOF(BYTESTRING):
937case YY_STATE_EOF(PROPNODENAME): 889case YY_STATE_EOF(PROPNODENAME):
938case YY_STATE_EOF(V1): 890case YY_STATE_EOF(V1):
939#line 71 "dtc-lexer.l" 891#line 73 "dtc-lexer.l"
940{ 892{
941 if (!pop_input_file()) { 893 if (!pop_input_file()) {
942 yyterminate(); 894 yyterminate();
@@ -946,23 +898,18 @@ case YY_STATE_EOF(V1):
946case 2: 898case 2:
947/* rule 2 can match eol */ 899/* rule 2 can match eol */
948YY_RULE_SETUP 900YY_RULE_SETUP
949#line 77 "dtc-lexer.l" 901#line 79 "dtc-lexer.l"
950{ 902{
951 yylloc.file = srcpos_file;
952 yylloc.first_line = yylineno;
953 DPRINT("String: %s\n", yytext); 903 DPRINT("String: %s\n", yytext);
954 yylval.data = data_copy_escape_string(yytext+1, 904 yylval.data = data_copy_escape_string(yytext+1,
955 yyleng-2); 905 yyleng-2);
956 yylloc.first_line = yylineno;
957 return DT_STRING; 906 return DT_STRING;
958 } 907 }
959 YY_BREAK 908 YY_BREAK
960case 3: 909case 3:
961YY_RULE_SETUP 910YY_RULE_SETUP
962#line 87 "dtc-lexer.l" 911#line 86 "dtc-lexer.l"
963{ 912{
964 yylloc.file = srcpos_file;
965 yylloc.first_line = yylineno;
966 DPRINT("Keyword: /dts-v1/\n"); 913 DPRINT("Keyword: /dts-v1/\n");
967 dts_version = 1; 914 dts_version = 1;
968 BEGIN_DEFAULT(); 915 BEGIN_DEFAULT();
@@ -971,10 +918,8 @@ YY_RULE_SETUP
971 YY_BREAK 918 YY_BREAK
972case 4: 919case 4:
973YY_RULE_SETUP 920YY_RULE_SETUP
974#line 96 "dtc-lexer.l" 921#line 93 "dtc-lexer.l"
975{ 922{
976 yylloc.file = srcpos_file;
977 yylloc.first_line = yylineno;
978 DPRINT("Keyword: /memreserve/\n"); 923 DPRINT("Keyword: /memreserve/\n");
979 BEGIN_DEFAULT(); 924 BEGIN_DEFAULT();
980 return DT_MEMRESERVE; 925 return DT_MEMRESERVE;
@@ -982,158 +927,100 @@ YY_RULE_SETUP
982 YY_BREAK 927 YY_BREAK
983case 5: 928case 5:
984YY_RULE_SETUP 929YY_RULE_SETUP
985#line 104 "dtc-lexer.l" 930#line 99 "dtc-lexer.l"
986{ 931{
987 yylloc.file = srcpos_file;
988 yylloc.first_line = yylineno;
989 DPRINT("Label: %s\n", yytext); 932 DPRINT("Label: %s\n", yytext);
990 yylval.labelref = strdup(yytext); 933 yylval.labelref = xstrdup(yytext);
991 yylval.labelref[yyleng-1] = '\0'; 934 yylval.labelref[yyleng-1] = '\0';
992 return DT_LABEL; 935 return DT_LABEL;
993 } 936 }
994 YY_BREAK 937 YY_BREAK
995case 6: 938case 6:
996YY_RULE_SETUP 939YY_RULE_SETUP
997#line 113 "dtc-lexer.l" 940#line 106 "dtc-lexer.l"
998{
999 yylloc.file = srcpos_file;
1000 yylloc.first_line = yylineno;
1001 if (*yytext == 'b')
1002 yylval.cbase = 2;
1003 else if (*yytext == 'o')
1004 yylval.cbase = 8;
1005 else if (*yytext == 'd')
1006 yylval.cbase = 10;
1007 else
1008 yylval.cbase = 16;
1009 DPRINT("Base: %d\n", yylval.cbase);
1010 return DT_BASE;
1011 }
1012 YY_BREAK
1013case 7:
1014YY_RULE_SETUP
1015#line 128 "dtc-lexer.l"
1016{ 941{
1017 yylloc.file = srcpos_file; 942 yylval.literal = xstrdup(yytext);
1018 yylloc.first_line = yylineno;
1019 yylval.literal = strdup(yytext);
1020 DPRINT("Literal: '%s'\n", yylval.literal);
1021 return DT_LEGACYLITERAL;
1022 }
1023 YY_BREAK
1024case 8:
1025YY_RULE_SETUP
1026#line 136 "dtc-lexer.l"
1027{
1028 yylloc.file = srcpos_file;
1029 yylloc.first_line = yylineno;
1030 yylval.literal = strdup(yytext);
1031 DPRINT("Literal: '%s'\n", yylval.literal); 943 DPRINT("Literal: '%s'\n", yylval.literal);
1032 return DT_LITERAL; 944 return DT_LITERAL;
1033 } 945 }
1034 YY_BREAK 946 YY_BREAK
1035case 9: 947case 7:
1036YY_RULE_SETUP 948YY_RULE_SETUP
1037#line 144 "dtc-lexer.l" 949#line 112 "dtc-lexer.l"
1038{ /* label reference */ 950{ /* label reference */
1039 yylloc.file = srcpos_file;
1040 yylloc.first_line = yylineno;
1041 DPRINT("Ref: %s\n", yytext+1); 951 DPRINT("Ref: %s\n", yytext+1);
1042 yylval.labelref = strdup(yytext+1); 952 yylval.labelref = xstrdup(yytext+1);
1043 return DT_REF; 953 return DT_REF;
1044 } 954 }
1045 YY_BREAK 955 YY_BREAK
1046case 10: 956case 8:
1047YY_RULE_SETUP 957YY_RULE_SETUP
1048#line 152 "dtc-lexer.l" 958#line 118 "dtc-lexer.l"
1049{ /* new-style path reference */ 959{ /* new-style path reference */
1050 yylloc.file = srcpos_file;
1051 yylloc.first_line = yylineno;
1052 yytext[yyleng-1] = '\0'; 960 yytext[yyleng-1] = '\0';
1053 DPRINT("Ref: %s\n", yytext+2); 961 DPRINT("Ref: %s\n", yytext+2);
1054 yylval.labelref = strdup(yytext+2); 962 yylval.labelref = xstrdup(yytext+2);
1055 return DT_REF; 963 return DT_REF;
1056 } 964 }
1057 YY_BREAK 965 YY_BREAK
1058case 11: 966case 9:
1059YY_RULE_SETUP
1060#line 161 "dtc-lexer.l"
1061{ /* old-style path reference */
1062 yylloc.file = srcpos_file;
1063 yylloc.first_line = yylineno;
1064 DPRINT("Ref: %s\n", yytext+1);
1065 yylval.labelref = strdup(yytext+1);
1066 return DT_REF;
1067 }
1068 YY_BREAK
1069case 12:
1070YY_RULE_SETUP 967YY_RULE_SETUP
1071#line 169 "dtc-lexer.l" 968#line 125 "dtc-lexer.l"
1072{ 969{
1073 yylloc.file = srcpos_file;
1074 yylloc.first_line = yylineno;
1075 yylval.byte = strtol(yytext, NULL, 16); 970 yylval.byte = strtol(yytext, NULL, 16);
1076 DPRINT("Byte: %02x\n", (int)yylval.byte); 971 DPRINT("Byte: %02x\n", (int)yylval.byte);
1077 return DT_BYTE; 972 return DT_BYTE;
1078 } 973 }
1079 YY_BREAK 974 YY_BREAK
1080case 13: 975case 10:
1081YY_RULE_SETUP 976YY_RULE_SETUP
1082#line 177 "dtc-lexer.l" 977#line 131 "dtc-lexer.l"
1083{ 978{
1084 yylloc.file = srcpos_file;
1085 yylloc.first_line = yylineno;
1086 DPRINT("/BYTESTRING\n"); 979 DPRINT("/BYTESTRING\n");
1087 BEGIN_DEFAULT(); 980 BEGIN_DEFAULT();
1088 return ']'; 981 return ']';
1089 } 982 }
1090 YY_BREAK 983 YY_BREAK
1091case 14: 984case 11:
1092YY_RULE_SETUP 985YY_RULE_SETUP
1093#line 185 "dtc-lexer.l" 986#line 137 "dtc-lexer.l"
1094{ 987{
1095 yylloc.file = srcpos_file;
1096 yylloc.first_line = yylineno;
1097 DPRINT("PropNodeName: %s\n", yytext); 988 DPRINT("PropNodeName: %s\n", yytext);
1098 yylval.propnodename = strdup(yytext); 989 yylval.propnodename = xstrdup(yytext);
1099 BEGIN_DEFAULT(); 990 BEGIN_DEFAULT();
1100 return DT_PROPNODENAME; 991 return DT_PROPNODENAME;
1101 } 992 }
1102 YY_BREAK 993 YY_BREAK
1103case 15: 994case 12:
1104YY_RULE_SETUP 995YY_RULE_SETUP
1105#line 194 "dtc-lexer.l" 996#line 144 "dtc-lexer.l"
1106{ 997{
1107 yylloc.file = srcpos_file;
1108 yylloc.first_line = yylineno;
1109 DPRINT("Binary Include\n"); 998 DPRINT("Binary Include\n");
1110 return DT_INCBIN; 999 return DT_INCBIN;
1111 } 1000 }
1112 YY_BREAK 1001 YY_BREAK
1113case 16: 1002case 13:
1114/* rule 16 can match eol */ 1003/* rule 13 can match eol */
1115YY_RULE_SETUP 1004YY_RULE_SETUP
1116#line 201 "dtc-lexer.l" 1005#line 149 "dtc-lexer.l"
1117/* eat whitespace */ 1006/* eat whitespace */
1118 YY_BREAK 1007 YY_BREAK
1119case 17: 1008case 14:
1120/* rule 17 can match eol */ 1009/* rule 14 can match eol */
1121YY_RULE_SETUP 1010YY_RULE_SETUP
1122#line 202 "dtc-lexer.l" 1011#line 150 "dtc-lexer.l"
1123/* eat C-style comments */ 1012/* eat C-style comments */
1124 YY_BREAK 1013 YY_BREAK
1125case 18: 1014case 15:
1126/* rule 18 can match eol */ 1015/* rule 15 can match eol */
1127YY_RULE_SETUP 1016YY_RULE_SETUP
1128#line 203 "dtc-lexer.l" 1017#line 151 "dtc-lexer.l"
1129/* eat C++-style comments */ 1018/* eat C++-style comments */
1130 YY_BREAK 1019 YY_BREAK
1131case 19: 1020case 16:
1132YY_RULE_SETUP 1021YY_RULE_SETUP
1133#line 205 "dtc-lexer.l" 1022#line 153 "dtc-lexer.l"
1134{ 1023{
1135 yylloc.file = srcpos_file;
1136 yylloc.first_line = yylineno;
1137 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 1024 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
1138 (unsigned)yytext[0]); 1025 (unsigned)yytext[0]);
1139 if (yytext[0] == '[') { 1026 if (yytext[0] == '[') {
@@ -1148,12 +1035,12 @@ YY_RULE_SETUP
1148 return yytext[0]; 1035 return yytext[0];
1149 } 1036 }
1150 YY_BREAK 1037 YY_BREAK
1151case 20: 1038case 17:
1152YY_RULE_SETUP 1039YY_RULE_SETUP
1153#line 222 "dtc-lexer.l" 1040#line 168 "dtc-lexer.l"
1154ECHO; 1041ECHO;
1155 YY_BREAK 1042 YY_BREAK
1156#line 1157 "dtc-lexer.lex.c" 1043#line 1044 "dtc-lexer.lex.c"
1157 1044
1158 case YY_END_OF_BUFFER: 1045 case YY_END_OF_BUFFER:
1159 { 1046 {
@@ -1218,7 +1105,8 @@ ECHO;
1218 1105
1219 else 1106 else
1220 { 1107 {
1221 yy_cp = (yy_c_buf_p); 1108 yy_cp = (yy_last_accepting_cpos);
1109 yy_current_state = (yy_last_accepting_state);
1222 goto yy_find_action; 1110 goto yy_find_action;
1223 } 1111 }
1224 } 1112 }
@@ -1443,7 +1331,7 @@ static int yy_get_next_buffer (void)
1443 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1331 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1444 { 1332 {
1445 yy_current_state = (int) yy_def[yy_current_state]; 1333 yy_current_state = (int) yy_def[yy_current_state];
1446 if ( yy_current_state >= 104 ) 1334 if ( yy_current_state >= 94 )
1447 yy_c = yy_meta[(unsigned int) yy_c]; 1335 yy_c = yy_meta[(unsigned int) yy_c];
1448 } 1336 }
1449 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 1337 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1471,11 +1359,11 @@ static int yy_get_next_buffer (void)
1471 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1359 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1472 { 1360 {
1473 yy_current_state = (int) yy_def[yy_current_state]; 1361 yy_current_state = (int) yy_def[yy_current_state];
1474 if ( yy_current_state >= 104 ) 1362 if ( yy_current_state >= 94 )
1475 yy_c = yy_meta[(unsigned int) yy_c]; 1363 yy_c = yy_meta[(unsigned int) yy_c];
1476 } 1364 }
1477 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 1365 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1478 yy_is_jam = (yy_current_state == 103); 1366 yy_is_jam = (yy_current_state == 93);
1479 1367
1480 return yy_is_jam ? 0 : yy_current_state; 1368 return yy_is_jam ? 0 : yy_current_state;
1481} 1369}
@@ -1550,11 +1438,6 @@ static int yy_get_next_buffer (void)
1550 *(yy_c_buf_p) = '\0'; /* preserve yytext */ 1438 *(yy_c_buf_p) = '\0'; /* preserve yytext */
1551 (yy_hold_char) = *++(yy_c_buf_p); 1439 (yy_hold_char) = *++(yy_c_buf_p);
1552 1440
1553 if ( c == '\n' )
1554
1555 yylineno++;
1556;
1557
1558 return c; 1441 return c;
1559} 1442}
1560#endif /* ifndef YY_NO_INPUT */ 1443#endif /* ifndef YY_NO_INPUT */
@@ -1669,10 +1552,6 @@ static void yy_load_buffer_state (void)
1669 yyfree((void *) b ); 1552 yyfree((void *) b );
1670} 1553}
1671 1554
1672#ifndef __cplusplus
1673extern int isatty (int );
1674#endif /* __cplusplus */
1675
1676/* Initializes or reinitializes a buffer. 1555/* Initializes or reinitializes a buffer.
1677 * This function is sometimes called more than once on the same buffer, 1556 * This function is sometimes called more than once on the same buffer,
1678 * such as during a yyrestart() or at EOF. 1557 * such as during a yyrestart() or at EOF.
@@ -1696,7 +1575,7 @@ extern int isatty (int );
1696 b->yy_bs_column = 0; 1575 b->yy_bs_column = 0;
1697 } 1576 }
1698 1577
1699 b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; 1578 b->yy_is_interactive = 0;
1700 1579
1701 errno = oerrno; 1580 errno = oerrno;
1702} 1581}
@@ -2025,9 +1904,6 @@ static int yy_init_globals (void)
2025 * This function is called from yylex_destroy(), so don't allocate here. 1904 * This function is called from yylex_destroy(), so don't allocate here.
2026 */ 1905 */
2027 1906
2028 /* We do not touch yylineno unless the option is enabled. */
2029 yylineno = 1;
2030
2031 (yy_buffer_stack) = 0; 1907 (yy_buffer_stack) = 0;
2032 (yy_buffer_stack_top) = 0; 1908 (yy_buffer_stack_top) = 0;
2033 (yy_buffer_stack_max) = 0; 1909 (yy_buffer_stack_max) = 0;
@@ -2120,104 +1996,29 @@ void yyfree (void * ptr )
2120 1996
2121#define YYTABLES_NAME "yytables" 1997#define YYTABLES_NAME "yytables"
2122 1998
2123#line 222 "dtc-lexer.l" 1999#line 168 "dtc-lexer.l"
2124
2125
2126
2127
2128/*
2129 * Stack of nested include file contexts.
2130 */
2131
2132struct incl_file {
2133 struct dtc_file *file;
2134 YY_BUFFER_STATE yy_prev_buf;
2135 int yy_prev_lineno;
2136 struct incl_file *prev;
2137};
2138
2139static struct incl_file *incl_file_stack;
2140 2000
2141 2001
2142/*
2143 * Detect infinite include recursion.
2144 */
2145#define MAX_INCLUDE_DEPTH (100)
2146
2147static int incl_depth = 0;
2148
2149 2002
2150static void push_input_file(const char *filename) 2003static void push_input_file(const char *filename)
2151{ 2004{
2152 struct incl_file *incl_file;
2153 struct dtc_file *newfile;
2154 struct search_path search, *searchptr = NULL;
2155
2156 assert(filename); 2005 assert(filename);
2157 2006
2158 if (incl_depth++ >= MAX_INCLUDE_DEPTH) 2007 srcfile_push(filename);
2159 die("Includes nested too deeply");
2160
2161 if (srcpos_file) {
2162 search.dir = srcpos_file->dir;
2163 search.next = NULL;
2164 search.prev = NULL;
2165 searchptr = &search;
2166 }
2167
2168 newfile = dtc_open_file(filename, searchptr);
2169 2008
2170 incl_file = xmalloc(sizeof(struct incl_file)); 2009 yyin = current_srcfile->f;
2171 2010
2172 /* 2011 yypush_buffer_state(yy_create_buffer(yyin,YY_BUF_SIZE));
2173 * Save current context.
2174 */
2175 incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
2176 incl_file->yy_prev_lineno = yylineno;
2177 incl_file->file = srcpos_file;
2178 incl_file->prev = incl_file_stack;
2179
2180 incl_file_stack = incl_file;
2181
2182 /*
2183 * Establish new context.
2184 */
2185 srcpos_file = newfile;
2186 yylineno = 1;
2187 yyin = newfile->file;
2188 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
2189} 2012}
2190 2013
2191 2014
2192static int pop_input_file(void) 2015static int pop_input_file(void)
2193{ 2016{
2194 struct incl_file *incl_file; 2017 if (srcfile_pop() == 0)
2195
2196 if (incl_file_stack == 0)
2197 return 0; 2018 return 0;
2198 2019
2199 dtc_close_file(srcpos_file); 2020 yypop_buffer_state();
2200 2021 yyin = current_srcfile->f;
2201 /*
2202 * Pop.
2203 */
2204 --incl_depth;
2205 incl_file = incl_file_stack;
2206 incl_file_stack = incl_file->prev;
2207
2208 /*
2209 * Recover old context.
2210 */
2211 yy_delete_buffer(YY_CURRENT_BUFFER);
2212 yy_switch_to_buffer(incl_file->yy_prev_buf);
2213 yylineno = incl_file->yy_prev_lineno;
2214 srcpos_file = incl_file->file;
2215 yyin = incl_file->file ? incl_file->file->file : NULL;
2216
2217 /*
2218 * Free old state.
2219 */
2220 free(incl_file);
2221 2022
2222 return 1; 2023 return 1;
2223} 2024}
diff --git a/scripts/dtc/dtc-parser.tab.c_shipped b/scripts/dtc/dtc-parser.tab.c_shipped
index 27129377e5d2..9be2eea18a30 100644
--- a/scripts/dtc/dtc-parser.tab.c_shipped
+++ b/scripts/dtc/dtc-parser.tab.c_shipped
@@ -1,24 +1,23 @@
1/* A Bison parser, made by GNU Bison 2.3. */
2 1
3/* Skeleton implementation for Bison's Yacc-like parsers in C 2/* A Bison parser, made by GNU Bison 2.4.1. */
4 3
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 4/* Skeleton implementation for Bison's Yacc-like parsers in C
5
6 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc. 7 Free Software Foundation, Inc.
7 8
8 This program is free software; you can redistribute it and/or modify 9 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option) 11 the Free Software Foundation, either version 3 of the License, or
11 any later version. 12 (at your option) any later version.
12 13
13 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 17 GNU General Public License for more details.
17 18
18 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22 21
23/* As a special exception, you may create a larger work that contains 22/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work 23 part or all of the Bison parser skeleton and distribute that work
@@ -29,7 +28,7 @@
29 special exception, which will cause the skeleton and the resulting 28 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public 29 Bison output files to be licensed under the GNU General Public
31 License without this special exception. 30 License without this special exception.
32 31
33 This special exception was added by the Free Software Foundation in 32 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */ 33 version 2.2 of Bison. */
35 34
@@ -47,7 +46,7 @@
47#define YYBISON 1 46#define YYBISON 1
48 47
49/* Bison version. */ 48/* Bison version. */
50#define YYBISON_VERSION "2.3" 49#define YYBISON_VERSION "2.4.1"
51 50
52/* Skeleton name. */ 51/* Skeleton name. */
53#define YYSKELETON_NAME "yacc.c" 52#define YYSKELETON_NAME "yacc.c"
@@ -55,55 +54,32 @@
55/* Pure parsers. */ 54/* Pure parsers. */
56#define YYPURE 0 55#define YYPURE 0
57 56
58/* Using locations. */ 57/* Push parsers. */
59#define YYLSP_NEEDED 1 58#define YYPUSH 0
60
61 59
60/* Pull parsers. */
61#define YYPULL 1
62 62
63/* Tokens. */ 63/* Using locations. */
64#ifndef YYTOKENTYPE 64#define YYLSP_NEEDED 0
65# define YYTOKENTYPE
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
67 know about them. */
68 enum yytokentype {
69 DT_V1 = 258,
70 DT_MEMRESERVE = 259,
71 DT_PROPNODENAME = 260,
72 DT_LITERAL = 261,
73 DT_LEGACYLITERAL = 262,
74 DT_BASE = 263,
75 DT_BYTE = 264,
76 DT_STRING = 265,
77 DT_LABEL = 266,
78 DT_REF = 267,
79 DT_INCBIN = 268
80 };
81#endif
82/* Tokens. */
83#define DT_V1 258
84#define DT_MEMRESERVE 259
85#define DT_PROPNODENAME 260
86#define DT_LITERAL 261
87#define DT_LEGACYLITERAL 262
88#define DT_BASE 263
89#define DT_BYTE 264
90#define DT_STRING 265
91#define DT_LABEL 266
92#define DT_REF 267
93#define DT_INCBIN 268
94
95 65
96 66
97 67
98/* Copy the first part of user declarations. */ 68/* Copy the first part of user declarations. */
99#line 23 "dtc-parser.y" 69
70/* Line 189 of yacc.c */
71#line 21 "dtc-parser.y"
100 72
101#include <stdio.h> 73#include <stdio.h>
102 74
103#include "dtc.h" 75#include "dtc.h"
104#include "srcpos.h" 76#include "srcpos.h"
105 77
78YYLTYPE yylloc;
79
106extern int yylex(void); 80extern int yylex(void);
81extern void print_error(char const *fmt, ...);
82extern void yyerror(char const *s);
107 83
108extern struct boot_info *the_boot_info; 84extern struct boot_info *the_boot_info;
109extern int treesource_error; 85extern int treesource_error;
@@ -111,6 +87,9 @@ extern int treesource_error;
111static unsigned long long eval_literal(const char *s, int base, int bits); 87static unsigned long long eval_literal(const char *s, int base, int bits);
112 88
113 89
90/* Line 189 of yacc.c */
91#line 92 "dtc-parser.tab.c"
92
114/* Enabling traces. */ 93/* Enabling traces. */
115#ifndef YYDEBUG 94#ifndef YYDEBUG
116# define YYDEBUG 0 95# define YYDEBUG 0
@@ -129,10 +108,35 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
129# define YYTOKEN_TABLE 0 108# define YYTOKEN_TABLE 0
130#endif 109#endif
131 110
111
112/* Tokens. */
113#ifndef YYTOKENTYPE
114# define YYTOKENTYPE
115 /* Put the tokens into the symbol table, so that GDB and other debuggers
116 know about them. */
117 enum yytokentype {
118 DT_V1 = 258,
119 DT_MEMRESERVE = 259,
120 DT_PROPNODENAME = 260,
121 DT_LITERAL = 261,
122 DT_BASE = 262,
123 DT_BYTE = 263,
124 DT_STRING = 264,
125 DT_LABEL = 265,
126 DT_REF = 266,
127 DT_INCBIN = 267
128 };
129#endif
130
131
132
132#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 133#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
133typedef union YYSTYPE 134typedef union YYSTYPE
134#line 37 "dtc-parser.y"
135{ 135{
136
137/* Line 214 of yacc.c */
138#line 39 "dtc-parser.y"
139
136 char *propnodename; 140 char *propnodename;
137 char *literal; 141 char *literal;
138 char *labelref; 142 char *labelref;
@@ -147,34 +151,23 @@ typedef union YYSTYPE
147 struct node *node; 151 struct node *node;
148 struct node *nodelist; 152 struct node *nodelist;
149 struct reserve_info *re; 153 struct reserve_info *re;
150} 154
151/* Line 187 of yacc.c. */ 155
152#line 153 "dtc-parser.tab.c" 156
153 YYSTYPE; 157/* Line 214 of yacc.c */
158#line 159 "dtc-parser.tab.c"
159} YYSTYPE;
160# define YYSTYPE_IS_TRIVIAL 1
154# define yystype YYSTYPE /* obsolescent; will be withdrawn */ 161# define yystype YYSTYPE /* obsolescent; will be withdrawn */
155# define YYSTYPE_IS_DECLARED 1 162# define YYSTYPE_IS_DECLARED 1
156# define YYSTYPE_IS_TRIVIAL 1
157#endif
158
159#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
160typedef struct YYLTYPE
161{
162 int first_line;
163 int first_column;
164 int last_line;
165 int last_column;
166} YYLTYPE;
167# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
168# define YYLTYPE_IS_DECLARED 1
169# define YYLTYPE_IS_TRIVIAL 1
170#endif 163#endif
171 164
172 165
173/* Copy the second part of user declarations. */ 166/* Copy the second part of user declarations. */
174 167
175 168
176/* Line 216 of yacc.c. */ 169/* Line 264 of yacc.c */
177#line 178 "dtc-parser.tab.c" 170#line 171 "dtc-parser.tab.c"
178 171
179#ifdef short 172#ifdef short
180# undef short 173# undef short
@@ -249,14 +242,14 @@ typedef short int yytype_int16;
249#if (defined __STDC__ || defined __C99__FUNC__ \ 242#if (defined __STDC__ || defined __C99__FUNC__ \
250 || defined __cplusplus || defined _MSC_VER) 243 || defined __cplusplus || defined _MSC_VER)
251static int 244static int
252YYID (int i) 245YYID (int yyi)
253#else 246#else
254static int 247static int
255YYID (i) 248YYID (yyi)
256 int i; 249 int yyi;
257#endif 250#endif
258{ 251{
259 return i; 252 return yyi;
260} 253}
261#endif 254#endif
262 255
@@ -332,15 +325,13 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
332 325
333#if (! defined yyoverflow \ 326#if (! defined yyoverflow \
334 && (! defined __cplusplus \ 327 && (! defined __cplusplus \
335 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ 328 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
336 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
337 329
338/* A type that is properly aligned for any stack member. */ 330/* A type that is properly aligned for any stack member. */
339union yyalloc 331union yyalloc
340{ 332{
341 yytype_int16 yyss; 333 yytype_int16 yyss_alloc;
342 YYSTYPE yyvs; 334 YYSTYPE yyvs_alloc;
343 YYLTYPE yyls;
344}; 335};
345 336
346/* The size of the maximum gap between one aligned stack and the next. */ 337/* The size of the maximum gap between one aligned stack and the next. */
@@ -349,8 +340,8 @@ union yyalloc
349/* The size of an array large to enough to hold all stacks, each with 340/* The size of an array large to enough to hold all stacks, each with
350 N elements. */ 341 N elements. */
351# define YYSTACK_BYTES(N) \ 342# define YYSTACK_BYTES(N) \
352 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ 343 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
353 + 2 * YYSTACK_GAP_MAXIMUM) 344 + YYSTACK_GAP_MAXIMUM)
354 345
355/* Copy COUNT objects from FROM to TO. The source and destination do 346/* Copy COUNT objects from FROM to TO. The source and destination do
356 not overlap. */ 347 not overlap. */
@@ -375,12 +366,12 @@ union yyalloc
375 elements in the stack, and YYPTR gives the new location of the 366 elements in the stack, and YYPTR gives the new location of the
376 stack. Advance YYPTR to a properly aligned location for the next 367 stack. Advance YYPTR to a properly aligned location for the next
377 stack. */ 368 stack. */
378# define YYSTACK_RELOCATE(Stack) \ 369# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
379 do \ 370 do \
380 { \ 371 { \
381 YYSIZE_T yynewbytes; \ 372 YYSIZE_T yynewbytes; \
382 YYCOPY (&yyptr->Stack, Stack, yysize); \ 373 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
383 Stack = &yyptr->Stack; \ 374 Stack = &yyptr->Stack_alloc; \
384 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ 375 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
385 yyptr += yynewbytes / sizeof (*yyptr); \ 376 yyptr += yynewbytes / sizeof (*yyptr); \
386 } \ 377 } \
@@ -389,22 +380,22 @@ union yyalloc
389#endif 380#endif
390 381
391/* YYFINAL -- State number of the termination state. */ 382/* YYFINAL -- State number of the termination state. */
392#define YYFINAL 9 383#define YYFINAL 4
393/* YYLAST -- Last index in YYTABLE. */ 384/* YYLAST -- Last index in YYTABLE. */
394#define YYLAST 73 385#define YYLAST 56
395 386
396/* YYNTOKENS -- Number of terminals. */ 387/* YYNTOKENS -- Number of terminals. */
397#define YYNTOKENS 27 388#define YYNTOKENS 25
398/* YYNNTS -- Number of nonterminals. */ 389/* YYNNTS -- Number of nonterminals. */
399#define YYNNTS 20 390#define YYNNTS 16
400/* YYNRULES -- Number of rules. */ 391/* YYNRULES -- Number of rules. */
401#define YYNRULES 45 392#define YYNRULES 39
402/* YYNRULES -- Number of states. */ 393/* YYNRULES -- Number of states. */
403#define YYNSTATES 76 394#define YYNSTATES 67
404 395
405/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ 396/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
406#define YYUNDEFTOK 2 397#define YYUNDEFTOK 2
407#define YYMAXUTOK 268 398#define YYMAXUTOK 267
408 399
409#define YYTRANSLATE(YYX) \ 400#define YYTRANSLATE(YYX) \
410 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 401 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -416,15 +407,15 @@ static const yytype_uint8 yytranslate[] =
416 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 407 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
417 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 408 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
418 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 409 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
419 24, 26, 2, 2, 25, 15, 2, 16, 2, 2, 410 22, 24, 2, 2, 23, 2, 2, 14, 2, 2,
420 2, 2, 2, 2, 2, 2, 2, 2, 2, 14, 411 2, 2, 2, 2, 2, 2, 2, 2, 2, 13,
421 20, 19, 21, 2, 2, 2, 2, 2, 2, 2, 412 18, 17, 19, 2, 2, 2, 2, 2, 2, 2,
422 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 413 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
423 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 414 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
424 2, 22, 2, 23, 2, 2, 2, 2, 2, 2, 415 2, 20, 2, 21, 2, 2, 2, 2, 2, 2,
425 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 416 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
426 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 417 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
427 2, 2, 2, 17, 2, 18, 2, 2, 2, 2, 418 2, 2, 2, 15, 2, 16, 2, 2, 2, 2,
428 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 419 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
429 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 420 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
430 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 421 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@@ -438,7 +429,7 @@ static const yytype_uint8 yytranslate[] =
438 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 429 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
439 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 430 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
440 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 431 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
441 5, 6, 7, 8, 9, 10, 11, 12, 13 432 5, 6, 7, 8, 9, 10, 11, 12
442}; 433};
443 434
444#if YYDEBUG 435#if YYDEBUG
@@ -446,41 +437,37 @@ static const yytype_uint8 yytranslate[] =
446 YYRHS. */ 437 YYRHS. */
447static const yytype_uint8 yyprhs[] = 438static const yytype_uint8 yyprhs[] =
448{ 439{
449 0, 0, 3, 8, 11, 12, 15, 21, 22, 25, 440 0, 0, 3, 8, 9, 12, 17, 20, 22, 25,
450 27, 34, 36, 38, 41, 47, 48, 51, 57, 61, 441 29, 33, 39, 40, 43, 48, 51, 54, 57, 62,
451 64, 69, 74, 77, 87, 93, 96, 97, 100, 103, 442 67, 70, 80, 86, 89, 90, 93, 96, 97, 100,
452 104, 107, 110, 113, 114, 116, 118, 121, 122, 125, 443 103, 106, 108, 109, 112, 115, 116, 119, 122, 125
453 128, 129, 132, 135, 139, 140
454}; 444};
455 445
456/* YYRHS -- A `-1'-separated list of the rules' RHS. */ 446/* YYRHS -- A `-1'-separated list of the rules' RHS. */
457static const yytype_int8 yyrhs[] = 447static const yytype_int8 yyrhs[] =
458{ 448{
459 28, 0, -1, 3, 14, 29, 34, -1, 31, 34, 449 26, 0, -1, 3, 13, 27, 30, -1, -1, 28,
460 -1, -1, 30, 29, -1, 46, 4, 33, 33, 14, 450 27, -1, 4, 29, 29, 13, -1, 10, 28, -1,
461 -1, -1, 32, 31, -1, 30, -1, 46, 4, 33, 451 6, -1, 14, 31, -1, 30, 14, 31, -1, 30,
462 15, 33, 14, -1, 6, -1, 7, -1, 16, 35, 452 11, 31, -1, 15, 32, 39, 16, 13, -1, -1,
463 -1, 17, 36, 44, 18, 14, -1, -1, 36, 37, 453 32, 33, -1, 5, 17, 34, 13, -1, 5, 13,
464 -1, 46, 5, 19, 38, 14, -1, 46, 5, 14, 454 -1, 10, 33, -1, 35, 9, -1, 35, 18, 36,
465 -1, 39, 10, -1, 39, 20, 40, 21, -1, 39, 455 19, -1, 35, 20, 38, 21, -1, 35, 11, -1,
466 22, 43, 23, -1, 39, 12, -1, 39, 13, 24, 456 35, 12, 22, 9, 23, 29, 23, 29, 24, -1,
467 10, 25, 33, 25, 33, 26, -1, 39, 13, 24, 457 35, 12, 22, 9, 24, -1, 34, 10, -1, -1,
468 10, 26, -1, 38, 11, -1, -1, 38, 25, -1, 458 34, 23, -1, 35, 10, -1, -1, 36, 37, -1,
469 39, 11, -1, -1, 40, 42, -1, 40, 12, -1, 459 36, 11, -1, 36, 10, -1, 6, -1, -1, 38,
470 40, 11, -1, -1, 8, -1, 6, -1, 41, 7, 460 8, -1, 38, 10, -1, -1, 40, 39, -1, 40,
471 -1, -1, 43, 9, -1, 43, 11, -1, -1, 45, 461 33, -1, 5, 31, -1, 10, 40, -1
472 44, -1, 45, 37, -1, 46, 5, 35, -1, -1,
473 11, -1
474}; 462};
475 463
476/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 464/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
477static const yytype_uint16 yyrline[] = 465static const yytype_uint16 yyrline[] =
478{ 466{
479 0, 89, 89, 93, 101, 104, 111, 119, 122, 129, 467 0, 86, 86, 95, 98, 105, 109, 117, 124, 128,
480 133, 140, 144, 151, 158, 166, 169, 176, 180, 187, 468 132, 145, 153, 156, 163, 167, 171, 179, 183, 187,
481 191, 195, 199, 203, 220, 231, 239, 242, 246, 254, 469 191, 195, 212, 222, 230, 233, 237, 245, 248, 252,
482 257, 261, 266, 274, 277, 281, 285, 293, 296, 300, 470 257, 264, 272, 275, 279, 287, 290, 294, 302, 306
483 308, 311, 315, 323, 331, 334
484}; 471};
485#endif 472#endif
486 473
@@ -490,13 +477,12 @@ static const yytype_uint16 yyrline[] =
490static const char *const yytname[] = 477static const char *const yytname[] =
491{ 478{
492 "$end", "error", "$undefined", "DT_V1", "DT_MEMRESERVE", 479 "$end", "error", "$undefined", "DT_V1", "DT_MEMRESERVE",
493 "DT_PROPNODENAME", "DT_LITERAL", "DT_LEGACYLITERAL", "DT_BASE", 480 "DT_PROPNODENAME", "DT_LITERAL", "DT_BASE", "DT_BYTE", "DT_STRING",
494 "DT_BYTE", "DT_STRING", "DT_LABEL", "DT_REF", "DT_INCBIN", "';'", "'-'", 481 "DT_LABEL", "DT_REF", "DT_INCBIN", "';'", "'/'", "'{'", "'}'", "'='",
495 "'/'", "'{'", "'}'", "'='", "'<'", "'>'", "'['", "']'", "'('", "','", 482 "'<'", "'>'", "'['", "']'", "'('", "','", "')'", "$accept", "sourcefile",
496 "')'", "$accept", "sourcefile", "memreserves", "memreserve", 483 "memreserves", "memreserve", "addr", "devicetree", "nodedef", "proplist",
497 "v0_memreserves", "v0_memreserve", "addr", "devicetree", "nodedef", 484 "propdef", "propdata", "propdataprefix", "celllist", "cellval",
498 "proplist", "propdef", "propdata", "propdataprefix", "celllist", 485 "bytestring", "subnodes", "subnode", 0
499 "cellbase", "cellval", "bytestring", "subnodes", "subnode", "label", 0
500}; 486};
501#endif 487#endif
502 488
@@ -506,29 +492,27 @@ static const char *const yytname[] =
506static const yytype_uint16 yytoknum[] = 492static const yytype_uint16 yytoknum[] =
507{ 493{
508 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 494 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
509 265, 266, 267, 268, 59, 45, 47, 123, 125, 61, 495 265, 266, 267, 59, 47, 123, 125, 61, 60, 62,
510 60, 62, 91, 93, 40, 44, 41 496 91, 93, 40, 44, 41
511}; 497};
512# endif 498# endif
513 499
514/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 500/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
515static const yytype_uint8 yyr1[] = 501static const yytype_uint8 yyr1[] =
516{ 502{
517 0, 27, 28, 28, 29, 29, 30, 31, 31, 32, 503 0, 25, 26, 27, 27, 28, 28, 29, 30, 30,
518 32, 33, 33, 34, 35, 36, 36, 37, 37, 38, 504 30, 31, 32, 32, 33, 33, 33, 34, 34, 34,
519 38, 38, 38, 38, 38, 38, 39, 39, 39, 40, 505 34, 34, 34, 34, 35, 35, 35, 36, 36, 36,
520 40, 40, 40, 41, 41, 42, 42, 43, 43, 43, 506 36, 37, 38, 38, 38, 39, 39, 39, 40, 40
521 44, 44, 44, 45, 46, 46
522}; 507};
523 508
524/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ 509/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
525static const yytype_uint8 yyr2[] = 510static const yytype_uint8 yyr2[] =
526{ 511{
527 0, 2, 4, 2, 0, 2, 5, 0, 2, 1, 512 0, 2, 4, 0, 2, 4, 2, 1, 2, 3,
528 6, 1, 1, 2, 5, 0, 2, 5, 3, 2, 513 3, 5, 0, 2, 4, 2, 2, 2, 4, 4,
529 4, 4, 2, 9, 5, 2, 0, 2, 2, 0, 514 2, 9, 5, 2, 0, 2, 2, 0, 2, 2,
530 2, 2, 2, 0, 1, 1, 2, 0, 2, 2, 515 2, 1, 0, 2, 2, 0, 2, 2, 2, 2
531 0, 2, 2, 3, 0, 1
532}; 516};
533 517
534/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state 518/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@@ -536,86 +520,79 @@ static const yytype_uint8 yyr2[] =
536 means the default is an error. */ 520 means the default is an error. */
537static const yytype_uint8 yydefact[] = 521static const yytype_uint8 yydefact[] =
538{ 522{
539 7, 0, 45, 0, 9, 0, 7, 0, 4, 1, 523 0, 0, 0, 3, 1, 0, 0, 0, 3, 7,
540 0, 3, 8, 0, 0, 4, 0, 15, 13, 11, 524 0, 6, 0, 2, 4, 0, 12, 8, 0, 0,
541 12, 0, 2, 5, 0, 40, 0, 0, 0, 16, 525 5, 35, 10, 9, 0, 0, 13, 0, 35, 15,
542 0, 40, 0, 0, 6, 0, 42, 41, 0, 10, 526 24, 38, 16, 39, 0, 37, 36, 0, 0, 11,
543 14, 18, 26, 43, 0, 0, 25, 17, 27, 19, 527 23, 14, 25, 17, 26, 20, 0, 27, 32, 0,
544 28, 22, 0, 29, 37, 0, 33, 0, 0, 35, 528 0, 0, 0, 31, 30, 29, 18, 28, 33, 34,
545 34, 32, 31, 20, 0, 30, 38, 39, 21, 0, 529 19, 0, 22, 0, 0, 0, 21
546 24, 36, 0, 0, 0, 23
547}; 530};
548 531
549/* YYDEFGOTO[NTERM-NUM]. */ 532/* YYDEFGOTO[NTERM-NUM]. */
550static const yytype_int8 yydefgoto[] = 533static const yytype_int8 yydefgoto[] =
551{ 534{
552 -1, 3, 14, 4, 5, 6, 27, 11, 18, 25, 535 -1, 2, 7, 8, 10, 13, 17, 21, 26, 37,
553 29, 44, 45, 56, 64, 65, 57, 30, 31, 7 536 38, 50, 57, 51, 27, 28
554}; 537};
555 538
556/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 539/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
557 STATE-NUM. */ 540 STATE-NUM. */
558#define YYPACT_NINF -14 541#define YYPACT_NINF -12
559static const yytype_int8 yypact[] = 542static const yytype_int8 yypact[] =
560{ 543{
561 30, -11, -14, 7, -14, -1, 27, 13, 27, -14, 544 10, -11, 18, -1, -12, 22, -1, 15, -1, -12,
562 8, -14, -14, 40, -1, 27, 35, -14, -14, -14, 545 22, -12, 20, 1, -12, 17, -12, -12, 20, 20,
563 -14, 21, -14, -14, 40, 24, 40, 28, 40, -14, 546 -12, 6, -12, -12, 21, 6, -12, 23, 6, -12,
564 32, 24, 46, 38, -14, 39, -14, -14, 26, -14, 547 -12, -12, -12, -12, 28, -12, -12, -6, 13, -12,
565 -14, -14, -14, -14, -9, 10, -14, -14, -14, -14, 548 -12, -12, -12, -12, -12, -12, 24, -12, -12, 33,
566 -14, -14, 31, -14, -14, 44, -2, 3, 23, -14, 549 -5, 0, -4, -12, -12, -12, -12, -12, -12, -12,
567 -14, -14, -14, -14, 50, -14, -14, -14, -14, 40, 550 -12, 22, -12, 25, 22, 19, -12
568 -14, -14, 33, 40, 36, -14
569}; 551};
570 552
571/* YYPGOTO[NTERM-NUM]. */ 553/* YYPGOTO[NTERM-NUM]. */
572static const yytype_int8 yypgoto[] = 554static const yytype_int8 yypgoto[] =
573{ 555{
574 -14, -14, 48, 29, 53, -14, -13, 47, 34, -14, 556 -12, -12, 36, 39, -10, -12, 8, -12, 12, -12,
575 37, -14, -14, -14, -14, -14, -14, 42, -14, -7 557 -12, -12, -12, -12, 27, 31
576}; 558};
577 559
578/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 560/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
579 positive, shift that token. If negative, reduce the rule which 561 positive, shift that token. If negative, reduce the rule which
580 number is the opposite. If zero, do what YYDEFACT says. 562 number is the opposite. If zero, do what YYDEFACT says.
581 If YYTABLE_NINF, syntax error. */ 563 If YYTABLE_NINF, syntax error. */
582#define YYTABLE_NINF -45 564#define YYTABLE_NINF -1
583static const yytype_int8 yytable[] = 565static const yytype_uint8 yytable[] =
584{ 566{
585 21, 16, 46, 8, 59, 47, 60, 9, 16, 61, 567 15, 53, 3, 5, 40, 54, 55, 41, 58, 6,
586 62, 28, 66, 33, 67, 10, 48, 13, 32, 63, 568 59, 24, 18, 1, 56, 19, 25, 42, 4, 61,
587 49, 50, 51, 52, 32, 17, 68, 19, 20, -44, 569 62, 60, 43, 44, 45, 46, 22, 23, 9, 12,
588 53, -44, 54, 1, -44, 2, 26, 15, 2, 24, 570 20, 47, 31, 48, 29, 16, 16, 32, 30, 34,
589 41, 2, 34, 17, 15, 42, 19, 20, 69, 70, 571 35, 39, 52, 66, 14, 11, 49, 0, 64, 0,
590 35, 38, 39, 40, 58, 55, 72, 71, 73, 12, 572 0, 63, 0, 0, 65, 36, 33
591 74, 22, 75, 23, 0, 0, 0, 0, 36, 0,
592 0, 0, 43, 37
593}; 573};
594 574
595static const yytype_int8 yycheck[] = 575static const yytype_int8 yycheck[] =
596{ 576{
597 13, 8, 11, 14, 6, 14, 8, 0, 15, 11, 577 10, 6, 13, 4, 10, 10, 11, 13, 8, 10,
598 12, 24, 9, 26, 11, 16, 25, 4, 25, 21, 578 10, 5, 11, 3, 19, 14, 10, 23, 0, 23,
599 10, 11, 12, 13, 31, 17, 23, 6, 7, 5, 579 24, 21, 9, 10, 11, 12, 18, 19, 6, 14,
600 20, 4, 22, 3, 4, 11, 15, 8, 11, 4, 580 13, 18, 24, 20, 13, 15, 15, 25, 17, 16,
601 14, 11, 14, 17, 15, 19, 6, 7, 25, 26, 581 28, 13, 9, 24, 8, 6, 22, -1, 23, -1,
602 18, 5, 14, 14, 10, 24, 69, 7, 25, 6, 582 -1, 61, -1, -1, 64, 28, 25
603 73, 14, 26, 15, -1, -1, -1, -1, 31, -1,
604 -1, -1, 38, 31
605}; 583};
606 584
607/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 585/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
608 symbol of state STATE-NUM. */ 586 symbol of state STATE-NUM. */
609static const yytype_uint8 yystos[] = 587static const yytype_uint8 yystos[] =
610{ 588{
611 0, 3, 11, 28, 30, 31, 32, 46, 14, 0, 589 0, 3, 26, 13, 0, 4, 10, 27, 28, 6,
612 16, 34, 31, 4, 29, 30, 46, 17, 35, 6, 590 29, 28, 14, 30, 27, 29, 15, 31, 11, 14,
613 7, 33, 34, 29, 4, 36, 15, 33, 33, 37, 591 13, 32, 31, 31, 5, 10, 33, 39, 40, 13,
614 44, 45, 46, 33, 14, 18, 37, 44, 5, 14, 592 17, 31, 33, 40, 16, 33, 39, 34, 35, 13,
615 14, 14, 19, 35, 38, 39, 11, 14, 25, 10, 593 10, 13, 23, 9, 10, 11, 12, 18, 20, 22,
616 11, 12, 13, 20, 22, 24, 40, 43, 10, 6, 594 36, 38, 9, 6, 10, 11, 19, 37, 8, 10,
617 8, 11, 12, 21, 41, 42, 9, 11, 23, 25, 595 21, 23, 24, 29, 23, 29, 24
618 26, 7, 33, 25, 33, 26
619}; 596};
620 597
621#define yyerrok (yyerrstatus = 0) 598#define yyerrok (yyerrstatus = 0)
@@ -728,7 +705,7 @@ do { \
728 { \ 705 { \
729 YYFPRINTF (stderr, "%s ", Title); \ 706 YYFPRINTF (stderr, "%s ", Title); \
730 yy_symbol_print (stderr, \ 707 yy_symbol_print (stderr, \
731 Type, Value, Location); \ 708 Type, Value); \
732 YYFPRINTF (stderr, "\n"); \ 709 YYFPRINTF (stderr, "\n"); \
733 } \ 710 } \
734} while (YYID (0)) 711} while (YYID (0))
@@ -742,19 +719,17 @@ do { \
742#if (defined __STDC__ || defined __C99__FUNC__ \ 719#if (defined __STDC__ || defined __C99__FUNC__ \
743 || defined __cplusplus || defined _MSC_VER) 720 || defined __cplusplus || defined _MSC_VER)
744static void 721static void
745yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) 722yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
746#else 723#else
747static void 724static void
748yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp) 725yy_symbol_value_print (yyoutput, yytype, yyvaluep)
749 FILE *yyoutput; 726 FILE *yyoutput;
750 int yytype; 727 int yytype;
751 YYSTYPE const * const yyvaluep; 728 YYSTYPE const * const yyvaluep;
752 YYLTYPE const * const yylocationp;
753#endif 729#endif
754{ 730{
755 if (!yyvaluep) 731 if (!yyvaluep)
756 return; 732 return;
757 YYUSE (yylocationp);
758# ifdef YYPRINT 733# ifdef YYPRINT
759 if (yytype < YYNTOKENS) 734 if (yytype < YYNTOKENS)
760 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 735 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
@@ -776,14 +751,13 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
776#if (defined __STDC__ || defined __C99__FUNC__ \ 751#if (defined __STDC__ || defined __C99__FUNC__ \
777 || defined __cplusplus || defined _MSC_VER) 752 || defined __cplusplus || defined _MSC_VER)
778static void 753static void
779yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) 754yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
780#else 755#else
781static void 756static void
782yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp) 757yy_symbol_print (yyoutput, yytype, yyvaluep)
783 FILE *yyoutput; 758 FILE *yyoutput;
784 int yytype; 759 int yytype;
785 YYSTYPE const * const yyvaluep; 760 YYSTYPE const * const yyvaluep;
786 YYLTYPE const * const yylocationp;
787#endif 761#endif
788{ 762{
789 if (yytype < YYNTOKENS) 763 if (yytype < YYNTOKENS)
@@ -791,9 +765,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
791 else 765 else
792 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); 766 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
793 767
794 YY_LOCATION_PRINT (yyoutput, *yylocationp); 768 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
795 YYFPRINTF (yyoutput, ": ");
796 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
797 YYFPRINTF (yyoutput, ")"); 769 YYFPRINTF (yyoutput, ")");
798} 770}
799 771
@@ -805,17 +777,20 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
805#if (defined __STDC__ || defined __C99__FUNC__ \ 777#if (defined __STDC__ || defined __C99__FUNC__ \
806 || defined __cplusplus || defined _MSC_VER) 778 || defined __cplusplus || defined _MSC_VER)
807static void 779static void
808yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) 780yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
809#else 781#else
810static void 782static void
811yy_stack_print (bottom, top) 783yy_stack_print (yybottom, yytop)
812 yytype_int16 *bottom; 784 yytype_int16 *yybottom;
813 yytype_int16 *top; 785 yytype_int16 *yytop;
814#endif 786#endif
815{ 787{
816 YYFPRINTF (stderr, "Stack now"); 788 YYFPRINTF (stderr, "Stack now");
817 for (; bottom <= top; ++bottom) 789 for (; yybottom <= yytop; yybottom++)
818 YYFPRINTF (stderr, " %d", *bottom); 790 {
791 int yybot = *yybottom;
792 YYFPRINTF (stderr, " %d", yybot);
793 }
819 YYFPRINTF (stderr, "\n"); 794 YYFPRINTF (stderr, "\n");
820} 795}
821 796
@@ -833,12 +808,11 @@ do { \
833#if (defined __STDC__ || defined __C99__FUNC__ \ 808#if (defined __STDC__ || defined __C99__FUNC__ \
834 || defined __cplusplus || defined _MSC_VER) 809 || defined __cplusplus || defined _MSC_VER)
835static void 810static void
836yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) 811yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
837#else 812#else
838static void 813static void
839yy_reduce_print (yyvsp, yylsp, yyrule) 814yy_reduce_print (yyvsp, yyrule)
840 YYSTYPE *yyvsp; 815 YYSTYPE *yyvsp;
841 YYLTYPE *yylsp;
842 int yyrule; 816 int yyrule;
843#endif 817#endif
844{ 818{
@@ -850,18 +824,18 @@ yy_reduce_print (yyvsp, yylsp, yyrule)
850 /* The symbols being reduced. */ 824 /* The symbols being reduced. */
851 for (yyi = 0; yyi < yynrhs; yyi++) 825 for (yyi = 0; yyi < yynrhs; yyi++)
852 { 826 {
853 fprintf (stderr, " $%d = ", yyi + 1); 827 YYFPRINTF (stderr, " $%d = ", yyi + 1);
854 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], 828 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
855 &(yyvsp[(yyi + 1) - (yynrhs)]) 829 &(yyvsp[(yyi + 1) - (yynrhs)])
856 , &(yylsp[(yyi + 1) - (yynrhs)]) ); 830 );
857 fprintf (stderr, "\n"); 831 YYFPRINTF (stderr, "\n");
858 } 832 }
859} 833}
860 834
861# define YY_REDUCE_PRINT(Rule) \ 835# define YY_REDUCE_PRINT(Rule) \
862do { \ 836do { \
863 if (yydebug) \ 837 if (yydebug) \
864 yy_reduce_print (yyvsp, yylsp, Rule); \ 838 yy_reduce_print (yyvsp, Rule); \
865} while (YYID (0)) 839} while (YYID (0))
866 840
867/* Nonzero means print parse trace. It is left uninitialized so that 841/* Nonzero means print parse trace. It is left uninitialized so that
@@ -1112,18 +1086,16 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
1112#if (defined __STDC__ || defined __C99__FUNC__ \ 1086#if (defined __STDC__ || defined __C99__FUNC__ \
1113 || defined __cplusplus || defined _MSC_VER) 1087 || defined __cplusplus || defined _MSC_VER)
1114static void 1088static void
1115yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) 1089yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1116#else 1090#else
1117static void 1091static void
1118yydestruct (yymsg, yytype, yyvaluep, yylocationp) 1092yydestruct (yymsg, yytype, yyvaluep)
1119 const char *yymsg; 1093 const char *yymsg;
1120 int yytype; 1094 int yytype;
1121 YYSTYPE *yyvaluep; 1095 YYSTYPE *yyvaluep;
1122 YYLTYPE *yylocationp;
1123#endif 1096#endif
1124{ 1097{
1125 YYUSE (yyvaluep); 1098 YYUSE (yyvaluep);
1126 YYUSE (yylocationp);
1127 1099
1128 if (!yymsg) 1100 if (!yymsg)
1129 yymsg = "Deleting"; 1101 yymsg = "Deleting";
@@ -1136,10 +1108,8 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1136 break; 1108 break;
1137 } 1109 }
1138} 1110}
1139
1140 1111
1141/* Prevent warnings from -Wmissing-prototypes. */ 1112/* Prevent warnings from -Wmissing-prototypes. */
1142
1143#ifdef YYPARSE_PARAM 1113#ifdef YYPARSE_PARAM
1144#if defined __STDC__ || defined __cplusplus 1114#if defined __STDC__ || defined __cplusplus
1145int yyparse (void *YYPARSE_PARAM); 1115int yyparse (void *YYPARSE_PARAM);
@@ -1155,23 +1125,20 @@ int yyparse ();
1155#endif /* ! YYPARSE_PARAM */ 1125#endif /* ! YYPARSE_PARAM */
1156 1126
1157 1127
1158 1128/* The lookahead symbol. */
1159/* The look-ahead symbol. */
1160int yychar; 1129int yychar;
1161 1130
1162/* The semantic value of the look-ahead symbol. */ 1131/* The semantic value of the lookahead symbol. */
1163YYSTYPE yylval; 1132YYSTYPE yylval;
1164 1133
1165/* Number of syntax errors so far. */ 1134/* Number of syntax errors so far. */
1166int yynerrs; 1135int yynerrs;
1167/* Location data for the look-ahead symbol. */
1168YYLTYPE yylloc;
1169 1136
1170 1137
1171 1138
1172/*----------. 1139/*-------------------------.
1173| yyparse. | 1140| yyparse or yypush_parse. |
1174`----------*/ 1141`-------------------------*/
1175 1142
1176#ifdef YYPARSE_PARAM 1143#ifdef YYPARSE_PARAM
1177#if (defined __STDC__ || defined __C99__FUNC__ \ 1144#if (defined __STDC__ || defined __C99__FUNC__ \
@@ -1195,79 +1162,70 @@ yyparse ()
1195#endif 1162#endif
1196#endif 1163#endif
1197{ 1164{
1198
1199 int yystate;
1200 int yyn;
1201 int yyresult;
1202 /* Number of tokens to shift before error messages enabled. */
1203 int yyerrstatus;
1204 /* Look-ahead token as an internal (translated) token number. */
1205 int yytoken = 0;
1206#if YYERROR_VERBOSE
1207 /* Buffer for error messages, and its allocated size. */
1208 char yymsgbuf[128];
1209 char *yymsg = yymsgbuf;
1210 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1211#endif
1212 1165
1213 /* Three stacks and their tools:
1214 `yyss': related to states,
1215 `yyvs': related to semantic values,
1216 `yyls': related to locations.
1217 1166
1218 Refer to the stacks thru separate pointers, to allow yyoverflow 1167 int yystate;
1219 to reallocate them elsewhere. */ 1168 /* Number of tokens to shift before error messages enabled. */
1169 int yyerrstatus;
1220 1170
1221 /* The state stack. */ 1171 /* The stacks and their tools:
1222 yytype_int16 yyssa[YYINITDEPTH]; 1172 `yyss': related to states.
1223 yytype_int16 *yyss = yyssa; 1173 `yyvs': related to semantic values.
1224 yytype_int16 *yyssp;
1225 1174
1226 /* The semantic value stack. */ 1175 Refer to the stacks thru separate pointers, to allow yyoverflow
1227 YYSTYPE yyvsa[YYINITDEPTH]; 1176 to reallocate them elsewhere. */
1228 YYSTYPE *yyvs = yyvsa;
1229 YYSTYPE *yyvsp;
1230 1177
1231 /* The location stack. */ 1178 /* The state stack. */
1232 YYLTYPE yylsa[YYINITDEPTH]; 1179 yytype_int16 yyssa[YYINITDEPTH];
1233 YYLTYPE *yyls = yylsa; 1180 yytype_int16 *yyss;
1234 YYLTYPE *yylsp; 1181 yytype_int16 *yyssp;
1235 /* The locations where the error started and ended. */
1236 YYLTYPE yyerror_range[2];
1237 1182
1238#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) 1183 /* The semantic value stack. */
1184 YYSTYPE yyvsa[YYINITDEPTH];
1185 YYSTYPE *yyvs;
1186 YYSTYPE *yyvsp;
1239 1187
1240 YYSIZE_T yystacksize = YYINITDEPTH; 1188 YYSIZE_T yystacksize;
1241 1189
1190 int yyn;
1191 int yyresult;
1192 /* Lookahead token as an internal (translated) token number. */
1193 int yytoken;
1242 /* The variables used to return semantic value and location from the 1194 /* The variables used to return semantic value and location from the
1243 action routines. */ 1195 action routines. */
1244 YYSTYPE yyval; 1196 YYSTYPE yyval;
1245 YYLTYPE yyloc; 1197
1198#if YYERROR_VERBOSE
1199 /* Buffer for error messages, and its allocated size. */
1200 char yymsgbuf[128];
1201 char *yymsg = yymsgbuf;
1202 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1203#endif
1204
1205#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1246 1206
1247 /* The number of symbols on the RHS of the reduced rule. 1207 /* The number of symbols on the RHS of the reduced rule.
1248 Keep to zero when no symbol should be popped. */ 1208 Keep to zero when no symbol should be popped. */
1249 int yylen = 0; 1209 int yylen = 0;
1250 1210
1211 yytoken = 0;
1212 yyss = yyssa;
1213 yyvs = yyvsa;
1214 yystacksize = YYINITDEPTH;
1215
1251 YYDPRINTF ((stderr, "Starting parse\n")); 1216 YYDPRINTF ((stderr, "Starting parse\n"));
1252 1217
1253 yystate = 0; 1218 yystate = 0;
1254 yyerrstatus = 0; 1219 yyerrstatus = 0;
1255 yynerrs = 0; 1220 yynerrs = 0;
1256 yychar = YYEMPTY; /* Cause a token to be read. */ 1221 yychar = YYEMPTY; /* Cause a token to be read. */
1257 1222
1258 /* Initialize stack pointers. 1223 /* Initialize stack pointers.
1259 Waste one element of value and location stack 1224 Waste one element of value and location stack
1260 so that they stay on the same level as the state stack. 1225 so that they stay on the same level as the state stack.
1261 The wasted elements are never initialized. */ 1226 The wasted elements are never initialized. */
1262
1263 yyssp = yyss; 1227 yyssp = yyss;
1264 yyvsp = yyvs; 1228 yyvsp = yyvs;
1265 yylsp = yyls;
1266#if YYLTYPE_IS_TRIVIAL
1267 /* Initialize the default location before parsing starts. */
1268 yylloc.first_line = yylloc.last_line = 1;
1269 yylloc.first_column = yylloc.last_column = 0;
1270#endif
1271 1229
1272 goto yysetstate; 1230 goto yysetstate;
1273 1231
@@ -1294,7 +1252,6 @@ yyparse ()
1294 memory. */ 1252 memory. */
1295 YYSTYPE *yyvs1 = yyvs; 1253 YYSTYPE *yyvs1 = yyvs;
1296 yytype_int16 *yyss1 = yyss; 1254 yytype_int16 *yyss1 = yyss;
1297 YYLTYPE *yyls1 = yyls;
1298 1255
1299 /* Each stack pointer address is followed by the size of the 1256 /* Each stack pointer address is followed by the size of the
1300 data in use in that stack, in bytes. This used to be a 1257 data in use in that stack, in bytes. This used to be a
@@ -1303,9 +1260,8 @@ yyparse ()
1303 yyoverflow (YY_("memory exhausted"), 1260 yyoverflow (YY_("memory exhausted"),
1304 &yyss1, yysize * sizeof (*yyssp), 1261 &yyss1, yysize * sizeof (*yyssp),
1305 &yyvs1, yysize * sizeof (*yyvsp), 1262 &yyvs1, yysize * sizeof (*yyvsp),
1306 &yyls1, yysize * sizeof (*yylsp),
1307 &yystacksize); 1263 &yystacksize);
1308 yyls = yyls1; 1264
1309 yyss = yyss1; 1265 yyss = yyss1;
1310 yyvs = yyvs1; 1266 yyvs = yyvs1;
1311 } 1267 }
@@ -1326,9 +1282,8 @@ yyparse ()
1326 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 1282 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1327 if (! yyptr) 1283 if (! yyptr)
1328 goto yyexhaustedlab; 1284 goto yyexhaustedlab;
1329 YYSTACK_RELOCATE (yyss); 1285 YYSTACK_RELOCATE (yyss_alloc, yyss);
1330 YYSTACK_RELOCATE (yyvs); 1286 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1331 YYSTACK_RELOCATE (yyls);
1332# undef YYSTACK_RELOCATE 1287# undef YYSTACK_RELOCATE
1333 if (yyss1 != yyssa) 1288 if (yyss1 != yyssa)
1334 YYSTACK_FREE (yyss1); 1289 YYSTACK_FREE (yyss1);
@@ -1338,7 +1293,6 @@ yyparse ()
1338 1293
1339 yyssp = yyss + yysize - 1; 1294 yyssp = yyss + yysize - 1;
1340 yyvsp = yyvs + yysize - 1; 1295 yyvsp = yyvs + yysize - 1;
1341 yylsp = yyls + yysize - 1;
1342 1296
1343 YYDPRINTF ((stderr, "Stack size increased to %lu\n", 1297 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1344 (unsigned long int) yystacksize)); 1298 (unsigned long int) yystacksize));
@@ -1349,6 +1303,9 @@ yyparse ()
1349 1303
1350 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1304 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1351 1305
1306 if (yystate == YYFINAL)
1307 YYACCEPT;
1308
1352 goto yybackup; 1309 goto yybackup;
1353 1310
1354/*-----------. 1311/*-----------.
@@ -1357,16 +1314,16 @@ yyparse ()
1357yybackup: 1314yybackup:
1358 1315
1359 /* Do appropriate processing given the current state. Read a 1316 /* Do appropriate processing given the current state. Read a
1360 look-ahead token if we need one and don't already have one. */ 1317 lookahead token if we need one and don't already have one. */
1361 1318
1362 /* First try to decide what to do without reference to look-ahead token. */ 1319 /* First try to decide what to do without reference to lookahead token. */
1363 yyn = yypact[yystate]; 1320 yyn = yypact[yystate];
1364 if (yyn == YYPACT_NINF) 1321 if (yyn == YYPACT_NINF)
1365 goto yydefault; 1322 goto yydefault;
1366 1323
1367 /* Not known => get a look-ahead token if don't already have one. */ 1324 /* Not known => get a lookahead token if don't already have one. */
1368 1325
1369 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ 1326 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1370 if (yychar == YYEMPTY) 1327 if (yychar == YYEMPTY)
1371 { 1328 {
1372 YYDPRINTF ((stderr, "Reading a token: ")); 1329 YYDPRINTF ((stderr, "Reading a token: "));
@@ -1398,24 +1355,20 @@ yybackup:
1398 goto yyreduce; 1355 goto yyreduce;
1399 } 1356 }
1400 1357
1401 if (yyn == YYFINAL)
1402 YYACCEPT;
1403
1404 /* Count tokens shifted since error; after three, turn off error 1358 /* Count tokens shifted since error; after three, turn off error
1405 status. */ 1359 status. */
1406 if (yyerrstatus) 1360 if (yyerrstatus)
1407 yyerrstatus--; 1361 yyerrstatus--;
1408 1362
1409 /* Shift the look-ahead token. */ 1363 /* Shift the lookahead token. */
1410 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1364 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1411 1365
1412 /* Discard the shifted token unless it is eof. */ 1366 /* Discard the shifted token. */
1413 if (yychar != YYEOF) 1367 yychar = YYEMPTY;
1414 yychar = YYEMPTY;
1415 1368
1416 yystate = yyn; 1369 yystate = yyn;
1417 *++yyvsp = yylval; 1370 *++yyvsp = yylval;
1418 *++yylsp = yylloc; 1371
1419 goto yynewstate; 1372 goto yynewstate;
1420 1373
1421 1374
@@ -1446,337 +1399,387 @@ yyreduce:
1446 GCC warning that YYVAL may be used uninitialized. */ 1399 GCC warning that YYVAL may be used uninitialized. */
1447 yyval = yyvsp[1-yylen]; 1400 yyval = yyvsp[1-yylen];
1448 1401
1449 /* Default location. */ 1402
1450 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1451 YY_REDUCE_PRINT (yyn); 1403 YY_REDUCE_PRINT (yyn);
1452 switch (yyn) 1404 switch (yyn)
1453 { 1405 {
1454 case 2: 1406 case 2:
1455#line 90 "dtc-parser.y" 1407
1408/* Line 1455 of yacc.c */
1409#line 87 "dtc-parser.y"
1456 { 1410 {
1457 the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node), 0); 1411 the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node),
1412 guess_boot_cpuid((yyvsp[(4) - (4)].node)));
1458 ;} 1413 ;}
1459 break; 1414 break;
1460 1415
1461 case 3: 1416 case 3:
1462#line 94 "dtc-parser.y" 1417
1418/* Line 1455 of yacc.c */
1419#line 95 "dtc-parser.y"
1463 { 1420 {
1464 the_boot_info = build_boot_info((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].node), 0); 1421 (yyval.re) = NULL;
1465 ;} 1422 ;}
1466 break; 1423 break;
1467 1424
1468 case 4: 1425 case 4:
1469#line 101 "dtc-parser.y" 1426
1427/* Line 1455 of yacc.c */
1428#line 99 "dtc-parser.y"
1470 { 1429 {
1471 (yyval.re) = NULL; 1430 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re));
1472 ;} 1431 ;}
1473 break; 1432 break;
1474 1433
1475 case 5: 1434 case 5:
1476#line 105 "dtc-parser.y" 1435
1436/* Line 1455 of yacc.c */
1437#line 106 "dtc-parser.y"
1477 { 1438 {
1478 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re)); 1439 (yyval.re) = build_reserve_entry((yyvsp[(2) - (4)].addr), (yyvsp[(3) - (4)].addr));
1479 ;} 1440 ;}
1480 break; 1441 break;
1481 1442
1482 case 6: 1443 case 6:
1483#line 112 "dtc-parser.y" 1444
1445/* Line 1455 of yacc.c */
1446#line 110 "dtc-parser.y"
1484 { 1447 {
1485 (yyval.re) = build_reserve_entry((yyvsp[(3) - (5)].addr), (yyvsp[(4) - (5)].addr), (yyvsp[(1) - (5)].labelref)); 1448 add_label(&(yyvsp[(2) - (2)].re)->labels, (yyvsp[(1) - (2)].labelref));
1449 (yyval.re) = (yyvsp[(2) - (2)].re);
1486 ;} 1450 ;}
1487 break; 1451 break;
1488 1452
1489 case 7: 1453 case 7:
1490#line 119 "dtc-parser.y" 1454
1455/* Line 1455 of yacc.c */
1456#line 118 "dtc-parser.y"
1491 { 1457 {
1492 (yyval.re) = NULL; 1458 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 0, 64);
1493 ;} 1459 ;}
1494 break; 1460 break;
1495 1461
1496 case 8: 1462 case 8:
1497#line 123 "dtc-parser.y" 1463
1464/* Line 1455 of yacc.c */
1465#line 125 "dtc-parser.y"
1498 { 1466 {
1499 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re)); 1467 (yyval.node) = name_node((yyvsp[(2) - (2)].node), "");
1500 ;} 1468 ;}
1501 break; 1469 break;
1502 1470
1503 case 9: 1471 case 9:
1504#line 130 "dtc-parser.y" 1472
1473/* Line 1455 of yacc.c */
1474#line 129 "dtc-parser.y"
1505 { 1475 {
1506 (yyval.re) = (yyvsp[(1) - (1)].re); 1476 (yyval.node) = merge_nodes((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node));
1507 ;} 1477 ;}
1508 break; 1478 break;
1509 1479
1510 case 10: 1480 case 10:
1511#line 134 "dtc-parser.y" 1481
1482/* Line 1455 of yacc.c */
1483#line 133 "dtc-parser.y"
1512 { 1484 {
1513 (yyval.re) = build_reserve_entry((yyvsp[(3) - (6)].addr), (yyvsp[(5) - (6)].addr) - (yyvsp[(3) - (6)].addr) + 1, (yyvsp[(1) - (6)].labelref)); 1485 struct node *target = get_node_by_ref((yyvsp[(1) - (3)].node), (yyvsp[(2) - (3)].labelref));
1486
1487 if (target)
1488 merge_nodes(target, (yyvsp[(3) - (3)].node));
1489 else
1490 print_error("label or path, '%s', not found", (yyvsp[(2) - (3)].labelref));
1491 (yyval.node) = (yyvsp[(1) - (3)].node);
1514 ;} 1492 ;}
1515 break; 1493 break;
1516 1494
1517 case 11: 1495 case 11:
1518#line 141 "dtc-parser.y" 1496
1497/* Line 1455 of yacc.c */
1498#line 146 "dtc-parser.y"
1519 { 1499 {
1520 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 0, 64); 1500 (yyval.node) = build_node((yyvsp[(2) - (5)].proplist), (yyvsp[(3) - (5)].nodelist));
1521 ;} 1501 ;}
1522 break; 1502 break;
1523 1503
1524 case 12: 1504 case 12:
1525#line 145 "dtc-parser.y" 1505
1506/* Line 1455 of yacc.c */
1507#line 153 "dtc-parser.y"
1526 { 1508 {
1527 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 16, 64); 1509 (yyval.proplist) = NULL;
1528 ;} 1510 ;}
1529 break; 1511 break;
1530 1512
1531 case 13: 1513 case 13:
1532#line 152 "dtc-parser.y" 1514
1515/* Line 1455 of yacc.c */
1516#line 157 "dtc-parser.y"
1533 { 1517 {
1534 (yyval.node) = name_node((yyvsp[(2) - (2)].node), "", NULL); 1518 (yyval.proplist) = chain_property((yyvsp[(2) - (2)].prop), (yyvsp[(1) - (2)].proplist));
1535 ;} 1519 ;}
1536 break; 1520 break;
1537 1521
1538 case 14: 1522 case 14:
1539#line 159 "dtc-parser.y" 1523
1524/* Line 1455 of yacc.c */
1525#line 164 "dtc-parser.y"
1540 { 1526 {
1541 (yyval.node) = build_node((yyvsp[(2) - (5)].proplist), (yyvsp[(3) - (5)].nodelist)); 1527 (yyval.prop) = build_property((yyvsp[(1) - (4)].propnodename), (yyvsp[(3) - (4)].data));
1542 ;} 1528 ;}
1543 break; 1529 break;
1544 1530
1545 case 15: 1531 case 15:
1546#line 166 "dtc-parser.y" 1532
1533/* Line 1455 of yacc.c */
1534#line 168 "dtc-parser.y"
1547 { 1535 {
1548 (yyval.proplist) = NULL; 1536 (yyval.prop) = build_property((yyvsp[(1) - (2)].propnodename), empty_data);
1549 ;} 1537 ;}
1550 break; 1538 break;
1551 1539
1552 case 16: 1540 case 16:
1553#line 170 "dtc-parser.y" 1541
1542/* Line 1455 of yacc.c */
1543#line 172 "dtc-parser.y"
1554 { 1544 {
1555 (yyval.proplist) = chain_property((yyvsp[(2) - (2)].prop), (yyvsp[(1) - (2)].proplist)); 1545 add_label(&(yyvsp[(2) - (2)].prop)->labels, (yyvsp[(1) - (2)].labelref));
1546 (yyval.prop) = (yyvsp[(2) - (2)].prop);
1556 ;} 1547 ;}
1557 break; 1548 break;
1558 1549
1559 case 17: 1550 case 17:
1560#line 177 "dtc-parser.y" 1551
1552/* Line 1455 of yacc.c */
1553#line 180 "dtc-parser.y"
1561 { 1554 {
1562 (yyval.prop) = build_property((yyvsp[(2) - (5)].propnodename), (yyvsp[(4) - (5)].data), (yyvsp[(1) - (5)].labelref)); 1555 (yyval.data) = data_merge((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].data));
1563 ;} 1556 ;}
1564 break; 1557 break;
1565 1558
1566 case 18: 1559 case 18:
1567#line 181 "dtc-parser.y" 1560
1561/* Line 1455 of yacc.c */
1562#line 184 "dtc-parser.y"
1568 { 1563 {
1569 (yyval.prop) = build_property((yyvsp[(2) - (3)].propnodename), empty_data, (yyvsp[(1) - (3)].labelref)); 1564 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
1570 ;} 1565 ;}
1571 break; 1566 break;
1572 1567
1573 case 19: 1568 case 19:
1569
1570/* Line 1455 of yacc.c */
1574#line 188 "dtc-parser.y" 1571#line 188 "dtc-parser.y"
1575 { 1572 {
1576 (yyval.data) = data_merge((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].data)); 1573 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
1577 ;} 1574 ;}
1578 break; 1575 break;
1579 1576
1580 case 20: 1577 case 20:
1578
1579/* Line 1455 of yacc.c */
1581#line 192 "dtc-parser.y" 1580#line 192 "dtc-parser.y"
1582 { 1581 {
1583 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data)); 1582 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), REF_PATH, (yyvsp[(2) - (2)].labelref));
1584 ;} 1583 ;}
1585 break; 1584 break;
1586 1585
1587 case 21: 1586 case 21:
1588#line 196 "dtc-parser.y"
1589 {
1590 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data));
1591 ;}
1592 break;
1593
1594 case 22:
1595#line 200 "dtc-parser.y"
1596 {
1597 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), REF_PATH, (yyvsp[(2) - (2)].labelref));
1598 ;}
1599 break;
1600 1587
1601 case 23: 1588/* Line 1455 of yacc.c */
1602#line 204 "dtc-parser.y" 1589#line 196 "dtc-parser.y"
1603 { 1590 {
1604 struct search_path path = { srcpos_file->dir, NULL, NULL }; 1591 FILE *f = srcfile_relative_open((yyvsp[(4) - (9)].data).val, NULL);
1605 struct dtc_file *file = dtc_open_file((yyvsp[(4) - (9)].data).val, &path); 1592 struct data d;
1606 struct data d = empty_data;
1607 1593
1608 if ((yyvsp[(6) - (9)].addr) != 0) 1594 if ((yyvsp[(6) - (9)].addr) != 0)
1609 if (fseek(file->file, (yyvsp[(6) - (9)].addr), SEEK_SET) != 0) 1595 if (fseek(f, (yyvsp[(6) - (9)].addr), SEEK_SET) != 0)
1610 yyerrorf("Couldn't seek to offset %llu in \"%s\": %s", 1596 print_error("Couldn't seek to offset %llu in \"%s\": %s",
1611 (unsigned long long)(yyvsp[(6) - (9)].addr), 1597 (unsigned long long)(yyvsp[(6) - (9)].addr),
1612 (yyvsp[(4) - (9)].data).val, strerror(errno)); 1598 (yyvsp[(4) - (9)].data).val,
1599 strerror(errno));
1613 1600
1614 d = data_copy_file(file->file, (yyvsp[(8) - (9)].addr)); 1601 d = data_copy_file(f, (yyvsp[(8) - (9)].addr));
1615 1602
1616 (yyval.data) = data_merge((yyvsp[(1) - (9)].data), d); 1603 (yyval.data) = data_merge((yyvsp[(1) - (9)].data), d);
1617 dtc_close_file(file); 1604 fclose(f);
1618 ;} 1605 ;}
1619 break; 1606 break;
1620 1607
1621 case 24: 1608 case 22:
1622#line 221 "dtc-parser.y" 1609
1610/* Line 1455 of yacc.c */
1611#line 213 "dtc-parser.y"
1623 { 1612 {
1624 struct search_path path = { srcpos_file->dir, NULL, NULL }; 1613 FILE *f = srcfile_relative_open((yyvsp[(4) - (5)].data).val, NULL);
1625 struct dtc_file *file = dtc_open_file((yyvsp[(4) - (5)].data).val, &path);
1626 struct data d = empty_data; 1614 struct data d = empty_data;
1627 1615
1628 d = data_copy_file(file->file, -1); 1616 d = data_copy_file(f, -1);
1629 1617
1630 (yyval.data) = data_merge((yyvsp[(1) - (5)].data), d); 1618 (yyval.data) = data_merge((yyvsp[(1) - (5)].data), d);
1631 dtc_close_file(file); 1619 fclose(f);
1632 ;} 1620 ;}
1633 break; 1621 break;
1634 1622
1635 case 25: 1623 case 23:
1636#line 232 "dtc-parser.y" 1624
1625/* Line 1455 of yacc.c */
1626#line 223 "dtc-parser.y"
1637 { 1627 {
1638 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1628 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1639 ;} 1629 ;}
1640 break; 1630 break;
1641 1631
1642 case 26: 1632 case 24:
1643#line 239 "dtc-parser.y" 1633
1634/* Line 1455 of yacc.c */
1635#line 230 "dtc-parser.y"
1644 { 1636 {
1645 (yyval.data) = empty_data; 1637 (yyval.data) = empty_data;
1646 ;} 1638 ;}
1647 break; 1639 break;
1648 1640
1649 case 27: 1641 case 25:
1650#line 243 "dtc-parser.y" 1642
1643/* Line 1455 of yacc.c */
1644#line 234 "dtc-parser.y"
1651 { 1645 {
1652 (yyval.data) = (yyvsp[(1) - (2)].data); 1646 (yyval.data) = (yyvsp[(1) - (2)].data);
1653 ;} 1647 ;}
1654 break; 1648 break;
1655 1649
1656 case 28: 1650 case 26:
1657#line 247 "dtc-parser.y" 1651
1652/* Line 1455 of yacc.c */
1653#line 238 "dtc-parser.y"
1658 { 1654 {
1659 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1655 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1660 ;} 1656 ;}
1661 break; 1657 break;
1662 1658
1663 case 29: 1659 case 27:
1664#line 254 "dtc-parser.y" 1660
1661/* Line 1455 of yacc.c */
1662#line 245 "dtc-parser.y"
1665 { 1663 {
1666 (yyval.data) = empty_data; 1664 (yyval.data) = empty_data;
1667 ;} 1665 ;}
1668 break; 1666 break;
1669 1667
1670 case 30: 1668 case 28:
1671#line 258 "dtc-parser.y" 1669
1670/* Line 1455 of yacc.c */
1671#line 249 "dtc-parser.y"
1672 { 1672 {
1673 (yyval.data) = data_append_cell((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].cell)); 1673 (yyval.data) = data_append_cell((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].cell));
1674 ;} 1674 ;}
1675 break; 1675 break;
1676 1676
1677 case 31: 1677 case 29:
1678#line 262 "dtc-parser.y" 1678
1679/* Line 1455 of yacc.c */
1680#line 253 "dtc-parser.y"
1679 { 1681 {
1680 (yyval.data) = data_append_cell(data_add_marker((yyvsp[(1) - (2)].data), REF_PHANDLE, 1682 (yyval.data) = data_append_cell(data_add_marker((yyvsp[(1) - (2)].data), REF_PHANDLE,
1681 (yyvsp[(2) - (2)].labelref)), -1); 1683 (yyvsp[(2) - (2)].labelref)), -1);
1682 ;} 1684 ;}
1683 break; 1685 break;
1684 1686
1685 case 32: 1687 case 30:
1686#line 267 "dtc-parser.y" 1688
1689/* Line 1455 of yacc.c */
1690#line 258 "dtc-parser.y"
1687 { 1691 {
1688 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1692 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1689 ;} 1693 ;}
1690 break; 1694 break;
1691 1695
1692 case 33: 1696 case 31:
1693#line 274 "dtc-parser.y"
1694 {
1695 (yyval.cbase) = 16;
1696 ;}
1697 break;
1698 1697
1699 case 35: 1698/* Line 1455 of yacc.c */
1700#line 282 "dtc-parser.y" 1699#line 265 "dtc-parser.y"
1701 { 1700 {
1702 (yyval.cell) = eval_literal((yyvsp[(1) - (1)].literal), 0, 32); 1701 (yyval.cell) = eval_literal((yyvsp[(1) - (1)].literal), 0, 32);
1703 ;} 1702 ;}
1704 break; 1703 break;
1705 1704
1706 case 36: 1705 case 32:
1707#line 286 "dtc-parser.y"
1708 {
1709 (yyval.cell) = eval_literal((yyvsp[(2) - (2)].literal), (yyvsp[(1) - (2)].cbase), 32);
1710 ;}
1711 break;
1712 1706
1713 case 37: 1707/* Line 1455 of yacc.c */
1714#line 293 "dtc-parser.y" 1708#line 272 "dtc-parser.y"
1715 { 1709 {
1716 (yyval.data) = empty_data; 1710 (yyval.data) = empty_data;
1717 ;} 1711 ;}
1718 break; 1712 break;
1719 1713
1720 case 38: 1714 case 33:
1721#line 297 "dtc-parser.y" 1715
1716/* Line 1455 of yacc.c */
1717#line 276 "dtc-parser.y"
1722 { 1718 {
1723 (yyval.data) = data_append_byte((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].byte)); 1719 (yyval.data) = data_append_byte((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].byte));
1724 ;} 1720 ;}
1725 break; 1721 break;
1726 1722
1727 case 39: 1723 case 34:
1728#line 301 "dtc-parser.y" 1724
1725/* Line 1455 of yacc.c */
1726#line 280 "dtc-parser.y"
1729 { 1727 {
1730 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1728 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref));
1731 ;} 1729 ;}
1732 break; 1730 break;
1733 1731
1734 case 40: 1732 case 35:
1735#line 308 "dtc-parser.y" 1733
1734/* Line 1455 of yacc.c */
1735#line 287 "dtc-parser.y"
1736 { 1736 {
1737 (yyval.nodelist) = NULL; 1737 (yyval.nodelist) = NULL;
1738 ;} 1738 ;}
1739 break; 1739 break;
1740 1740
1741 case 41: 1741 case 36:
1742#line 312 "dtc-parser.y" 1742
1743/* Line 1455 of yacc.c */
1744#line 291 "dtc-parser.y"
1743 { 1745 {
1744 (yyval.nodelist) = chain_node((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].nodelist)); 1746 (yyval.nodelist) = chain_node((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].nodelist));
1745 ;} 1747 ;}
1746 break; 1748 break;
1747 1749
1748 case 42: 1750 case 37:
1749#line 316 "dtc-parser.y" 1751
1752/* Line 1455 of yacc.c */
1753#line 295 "dtc-parser.y"
1750 { 1754 {
1751 yyerror("syntax error: properties must precede subnodes"); 1755 print_error("syntax error: properties must precede subnodes");
1752 YYERROR; 1756 YYERROR;
1753 ;} 1757 ;}
1754 break; 1758 break;
1755 1759
1756 case 43: 1760 case 38:
1757#line 324 "dtc-parser.y"
1758 {
1759 (yyval.node) = name_node((yyvsp[(3) - (3)].node), (yyvsp[(2) - (3)].propnodename), (yyvsp[(1) - (3)].labelref));
1760 ;}
1761 break;
1762 1761
1763 case 44: 1762/* Line 1455 of yacc.c */
1764#line 331 "dtc-parser.y" 1763#line 303 "dtc-parser.y"
1765 { 1764 {
1766 (yyval.labelref) = NULL; 1765 (yyval.node) = name_node((yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].propnodename));
1767 ;} 1766 ;}
1768 break; 1767 break;
1769 1768
1770 case 45: 1769 case 39:
1771#line 335 "dtc-parser.y" 1770
1771/* Line 1455 of yacc.c */
1772#line 307 "dtc-parser.y"
1772 { 1773 {
1773 (yyval.labelref) = (yyvsp[(1) - (1)].labelref); 1774 add_label(&(yyvsp[(2) - (2)].node)->labels, (yyvsp[(1) - (2)].labelref));
1775 (yyval.node) = (yyvsp[(2) - (2)].node);
1774 ;} 1776 ;}
1775 break; 1777 break;
1776 1778
1777 1779
1778/* Line 1267 of yacc.c. */ 1780
1779#line 1780 "dtc-parser.tab.c" 1781/* Line 1455 of yacc.c */
1782#line 1783 "dtc-parser.tab.c"
1780 default: break; 1783 default: break;
1781 } 1784 }
1782 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); 1785 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1786,7 +1789,6 @@ yyreduce:
1786 YY_STACK_PRINT (yyss, yyssp); 1789 YY_STACK_PRINT (yyss, yyssp);
1787 1790
1788 *++yyvsp = yyval; 1791 *++yyvsp = yyval;
1789 *++yylsp = yyloc;
1790 1792
1791 /* Now `shift' the result of the reduction. Determine what state 1793 /* Now `shift' the result of the reduction. Determine what state
1792 that goes to, based on the state we popped back to and the rule 1794 that goes to, based on the state we popped back to and the rule
@@ -1848,11 +1850,11 @@ yyerrlab:
1848#endif 1850#endif
1849 } 1851 }
1850 1852
1851 yyerror_range[0] = yylloc; 1853
1852 1854
1853 if (yyerrstatus == 3) 1855 if (yyerrstatus == 3)
1854 { 1856 {
1855 /* If just tried and failed to reuse look-ahead token after an 1857 /* If just tried and failed to reuse lookahead token after an
1856 error, discard it. */ 1858 error, discard it. */
1857 1859
1858 if (yychar <= YYEOF) 1860 if (yychar <= YYEOF)
@@ -1864,12 +1866,12 @@ yyerrlab:
1864 else 1866 else
1865 { 1867 {
1866 yydestruct ("Error: discarding", 1868 yydestruct ("Error: discarding",
1867 yytoken, &yylval, &yylloc); 1869 yytoken, &yylval);
1868 yychar = YYEMPTY; 1870 yychar = YYEMPTY;
1869 } 1871 }
1870 } 1872 }
1871 1873
1872 /* Else will try to reuse look-ahead token after shifting the error 1874 /* Else will try to reuse lookahead token after shifting the error
1873 token. */ 1875 token. */
1874 goto yyerrlab1; 1876 goto yyerrlab1;
1875 1877
@@ -1885,7 +1887,6 @@ yyerrorlab:
1885 if (/*CONSTCOND*/ 0) 1887 if (/*CONSTCOND*/ 0)
1886 goto yyerrorlab; 1888 goto yyerrorlab;
1887 1889
1888 yyerror_range[0] = yylsp[1-yylen];
1889 /* Do not reclaim the symbols of the rule which action triggered 1890 /* Do not reclaim the symbols of the rule which action triggered
1890 this YYERROR. */ 1891 this YYERROR. */
1891 YYPOPSTACK (yylen); 1892 YYPOPSTACK (yylen);
@@ -1919,24 +1920,16 @@ yyerrlab1:
1919 if (yyssp == yyss) 1920 if (yyssp == yyss)
1920 YYABORT; 1921 YYABORT;
1921 1922
1922 yyerror_range[0] = *yylsp; 1923
1923 yydestruct ("Error: popping", 1924 yydestruct ("Error: popping",
1924 yystos[yystate], yyvsp, yylsp); 1925 yystos[yystate], yyvsp);
1925 YYPOPSTACK (1); 1926 YYPOPSTACK (1);
1926 yystate = *yyssp; 1927 yystate = *yyssp;
1927 YY_STACK_PRINT (yyss, yyssp); 1928 YY_STACK_PRINT (yyss, yyssp);
1928 } 1929 }
1929 1930
1930 if (yyn == YYFINAL)
1931 YYACCEPT;
1932
1933 *++yyvsp = yylval; 1931 *++yyvsp = yylval;
1934 1932
1935 yyerror_range[1] = yylloc;
1936 /* Using YYLLOC is tempting, but would change the location of
1937 the look-ahead. YYLOC is available though. */
1938 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
1939 *++yylsp = yyloc;
1940 1933
1941 /* Shift the error token. */ 1934 /* Shift the error token. */
1942 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); 1935 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
@@ -1959,7 +1952,7 @@ yyabortlab:
1959 yyresult = 1; 1952 yyresult = 1;
1960 goto yyreturn; 1953 goto yyreturn;
1961 1954
1962#ifndef yyoverflow 1955#if !defined(yyoverflow) || YYERROR_VERBOSE
1963/*-------------------------------------------------. 1956/*-------------------------------------------------.
1964| yyexhaustedlab -- memory exhaustion comes here. | 1957| yyexhaustedlab -- memory exhaustion comes here. |
1965`-------------------------------------------------*/ 1958`-------------------------------------------------*/
@@ -1970,9 +1963,9 @@ yyexhaustedlab:
1970#endif 1963#endif
1971 1964
1972yyreturn: 1965yyreturn:
1973 if (yychar != YYEOF && yychar != YYEMPTY) 1966 if (yychar != YYEMPTY)
1974 yydestruct ("Cleanup: discarding lookahead", 1967 yydestruct ("Cleanup: discarding lookahead",
1975 yytoken, &yylval, &yylloc); 1968 yytoken, &yylval);
1976 /* Do not reclaim the symbols of the rule which action triggered 1969 /* Do not reclaim the symbols of the rule which action triggered
1977 this YYABORT or YYACCEPT. */ 1970 this YYABORT or YYACCEPT. */
1978 YYPOPSTACK (yylen); 1971 YYPOPSTACK (yylen);
@@ -1980,7 +1973,7 @@ yyreturn:
1980 while (yyssp != yyss) 1973 while (yyssp != yyss)
1981 { 1974 {
1982 yydestruct ("Cleanup: popping", 1975 yydestruct ("Cleanup: popping",
1983 yystos[*yyssp], yyvsp, yylsp); 1976 yystos[*yyssp], yyvsp);
1984 YYPOPSTACK (1); 1977 YYPOPSTACK (1);
1985 } 1978 }
1986#ifndef yyoverflow 1979#ifndef yyoverflow
@@ -1996,29 +1989,24 @@ yyreturn:
1996} 1989}
1997 1990
1998 1991
1999#line 340 "dtc-parser.y" 1992
1993/* Line 1675 of yacc.c */
1994#line 313 "dtc-parser.y"
2000 1995
2001 1996
2002void yyerrorf(char const *s, ...) 1997void print_error(char const *fmt, ...)
2003{ 1998{
2004 const char *fname = srcpos_file ? srcpos_file->name : "<no-file>";
2005 va_list va; 1999 va_list va;
2006 va_start(va, s);
2007
2008 if (strcmp(fname, "-") == 0)
2009 fname = "stdin";
2010 2000
2011 fprintf(stderr, "%s:%d ", fname, yylloc.first_line); 2001 va_start(va, fmt);
2012 vfprintf(stderr, s, va); 2002 srcpos_verror(&yylloc, fmt, va);
2013 fprintf(stderr, "\n"); 2003 va_end(va);
2014 2004
2015 treesource_error = 1; 2005 treesource_error = 1;
2016 va_end(va);
2017} 2006}
2018 2007
2019void yyerror (char const *s) 2008void yyerror(char const *s) {
2020{ 2009 print_error("%s", s);
2021 yyerrorf("%s", s);
2022} 2010}
2023 2011
2024static unsigned long long eval_literal(const char *s, int base, int bits) 2012static unsigned long long eval_literal(const char *s, int base, int bits)
@@ -2029,12 +2017,12 @@ static unsigned long long eval_literal(const char *s, int base, int bits)
2029 errno = 0; 2017 errno = 0;
2030 val = strtoull(s, &e, base); 2018 val = strtoull(s, &e, base);
2031 if (*e) 2019 if (*e)
2032 yyerror("bad characters in literal"); 2020 print_error("bad characters in literal");
2033 else if ((errno == ERANGE) 2021 else if ((errno == ERANGE)
2034 || ((bits < 64) && (val >= (1ULL << bits)))) 2022 || ((bits < 64) && (val >= (1ULL << bits))))
2035 yyerror("literal out of range"); 2023 print_error("literal out of range");
2036 else if (errno != 0) 2024 else if (errno != 0)
2037 yyerror("bad literal"); 2025 print_error("bad literal");
2038 return val; 2026 return val;
2039} 2027}
2040 2028
diff --git a/scripts/dtc/dtc-parser.tab.h_shipped b/scripts/dtc/dtc-parser.tab.h_shipped
index ba99100d55c9..95c9547adea5 100644
--- a/scripts/dtc/dtc-parser.tab.h_shipped
+++ b/scripts/dtc/dtc-parser.tab.h_shipped
@@ -1,24 +1,23 @@
1/* A Bison parser, made by GNU Bison 2.3. */
2 1
3/* Skeleton interface for Bison's Yacc-like parsers in C 2/* A Bison parser, made by GNU Bison 2.4.1. */
4 3
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 4/* Skeleton interface for Bison's Yacc-like parsers in C
5
6 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc. 7 Free Software Foundation, Inc.
7 8
8 This program is free software; you can redistribute it and/or modify 9 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option) 11 the Free Software Foundation, either version 3 of the License, or
11 any later version. 12 (at your option) any later version.
12 13
13 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 17 GNU General Public License for more details.
17 18
18 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22 21
23/* As a special exception, you may create a larger work that contains 22/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work 23 part or all of the Bison parser skeleton and distribute that work
@@ -29,10 +28,11 @@
29 special exception, which will cause the skeleton and the resulting 28 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public 29 Bison output files to be licensed under the GNU General Public
31 License without this special exception. 30 License without this special exception.
32 31
33 This special exception was added by the Free Software Foundation in 32 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */ 33 version 2.2 of Bison. */
35 34
35
36/* Tokens. */ 36/* Tokens. */
37#ifndef YYTOKENTYPE 37#ifndef YYTOKENTYPE
38# define YYTOKENTYPE 38# define YYTOKENTYPE
@@ -43,35 +43,24 @@
43 DT_MEMRESERVE = 259, 43 DT_MEMRESERVE = 259,
44 DT_PROPNODENAME = 260, 44 DT_PROPNODENAME = 260,
45 DT_LITERAL = 261, 45 DT_LITERAL = 261,
46 DT_LEGACYLITERAL = 262, 46 DT_BASE = 262,
47 DT_BASE = 263, 47 DT_BYTE = 263,
48 DT_BYTE = 264, 48 DT_STRING = 264,
49 DT_STRING = 265, 49 DT_LABEL = 265,
50 DT_LABEL = 266, 50 DT_REF = 266,
51 DT_REF = 267, 51 DT_INCBIN = 267
52 DT_INCBIN = 268
53 }; 52 };
54#endif 53#endif
55/* Tokens. */
56#define DT_V1 258
57#define DT_MEMRESERVE 259
58#define DT_PROPNODENAME 260
59#define DT_LITERAL 261
60#define DT_LEGACYLITERAL 262
61#define DT_BASE 263
62#define DT_BYTE 264
63#define DT_STRING 265
64#define DT_LABEL 266
65#define DT_REF 267
66#define DT_INCBIN 268
67
68 54
69 55
70 56
71#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 57#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
72typedef union YYSTYPE 58typedef union YYSTYPE
73#line 37 "dtc-parser.y"
74{ 59{
60
61/* Line 1676 of yacc.c */
62#line 39 "dtc-parser.y"
63
75 char *propnodename; 64 char *propnodename;
76 char *literal; 65 char *literal;
77 char *labelref; 66 char *labelref;
@@ -86,28 +75,17 @@ typedef union YYSTYPE
86 struct node *node; 75 struct node *node;
87 struct node *nodelist; 76 struct node *nodelist;
88 struct reserve_info *re; 77 struct reserve_info *re;
89} 78
90/* Line 1489 of yacc.c. */ 79
91#line 92 "dtc-parser.tab.h" 80
92 YYSTYPE; 81/* Line 1676 of yacc.c */
82#line 83 "dtc-parser.tab.h"
83} YYSTYPE;
84# define YYSTYPE_IS_TRIVIAL 1
93# define yystype YYSTYPE /* obsolescent; will be withdrawn */ 85# define yystype YYSTYPE /* obsolescent; will be withdrawn */
94# define YYSTYPE_IS_DECLARED 1 86# define YYSTYPE_IS_DECLARED 1
95# define YYSTYPE_IS_TRIVIAL 1
96#endif 87#endif
97 88
98extern YYSTYPE yylval; 89extern YYSTYPE yylval;
99 90
100#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
101typedef struct YYLTYPE
102{
103 int first_line;
104 int first_column;
105 int last_line;
106 int last_column;
107} YYLTYPE;
108# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
109# define YYLTYPE_IS_DECLARED 1
110# define YYLTYPE_IS_TRIVIAL 1
111#endif
112 91
113extern YYLTYPE yylloc;
diff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y
index b2ab562420ea..5e84a67fc1d2 100644
--- a/scripts/dtc/dtc-parser.y
+++ b/scripts/dtc/dtc-parser.y
@@ -18,15 +18,17 @@
18 * USA 18 * USA
19 */ 19 */
20 20
21%locations
22
23%{ 21%{
24#include <stdio.h> 22#include <stdio.h>
25 23
26#include "dtc.h" 24#include "dtc.h"
27#include "srcpos.h" 25#include "srcpos.h"
28 26
27YYLTYPE yylloc;
28
29extern int yylex(void); 29extern int yylex(void);
30extern void print_error(char const *fmt, ...);
31extern void yyerror(char const *s);
30 32
31extern struct boot_info *the_boot_info; 33extern struct boot_info *the_boot_info;
32extern int treesource_error; 34extern int treesource_error;
@@ -55,7 +57,6 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
55%token DT_MEMRESERVE 57%token DT_MEMRESERVE
56%token <propnodename> DT_PROPNODENAME 58%token <propnodename> DT_PROPNODENAME
57%token <literal> DT_LITERAL 59%token <literal> DT_LITERAL
58%token <literal> DT_LEGACYLITERAL
59%token <cbase> DT_BASE 60%token <cbase> DT_BASE
60%token <byte> DT_BYTE 61%token <byte> DT_BYTE
61%token <data> DT_STRING 62%token <data> DT_STRING
@@ -67,11 +68,8 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
67%type <data> propdataprefix 68%type <data> propdataprefix
68%type <re> memreserve 69%type <re> memreserve
69%type <re> memreserves 70%type <re> memreserves
70%type <re> v0_memreserve
71%type <re> v0_memreserves
72%type <addr> addr 71%type <addr> addr
73%type <data> celllist 72%type <data> celllist
74%type <cbase> cellbase
75%type <cell> cellval 73%type <cell> cellval
76%type <data> bytestring 74%type <data> bytestring
77%type <prop> propdef 75%type <prop> propdef
@@ -81,18 +79,14 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
81%type <node> nodedef 79%type <node> nodedef
82%type <node> subnode 80%type <node> subnode
83%type <nodelist> subnodes 81%type <nodelist> subnodes
84%type <labelref> label
85 82
86%% 83%%
87 84
88sourcefile: 85sourcefile:
89 DT_V1 ';' memreserves devicetree 86 DT_V1 ';' memreserves devicetree
90 { 87 {
91 the_boot_info = build_boot_info($3, $4, 0); 88 the_boot_info = build_boot_info($3, $4,
92 } 89 guess_boot_cpuid($4));
93 | v0_memreserves devicetree
94 {
95 the_boot_info = build_boot_info($1, $2, 0);
96 } 90 }
97 ; 91 ;
98 92
@@ -108,31 +102,14 @@ memreserves:
108 ; 102 ;
109 103
110memreserve: 104memreserve:
111 label DT_MEMRESERVE addr addr ';' 105 DT_MEMRESERVE addr addr ';'
112 { 106 {
113 $$ = build_reserve_entry($3, $4, $1); 107 $$ = build_reserve_entry($2, $3);
114 } 108 }
115 ; 109 | DT_LABEL memreserve
116
117v0_memreserves:
118 /* empty */
119 { 110 {
120 $$ = NULL; 111 add_label(&$2->labels, $1);
121 } 112 $$ = $2;
122 | v0_memreserve v0_memreserves
123 {
124 $$ = chain_reserve_entry($1, $2);
125 };
126 ;
127
128v0_memreserve:
129 memreserve
130 {
131 $$ = $1;
132 }
133 | label DT_MEMRESERVE addr '-' addr ';'
134 {
135 $$ = build_reserve_entry($3, $5 - $3 + 1, $1);
136 } 113 }
137 ; 114 ;
138 115
@@ -141,16 +118,26 @@ addr:
141 { 118 {
142 $$ = eval_literal($1, 0, 64); 119 $$ = eval_literal($1, 0, 64);
143 } 120 }
144 | DT_LEGACYLITERAL
145 {
146 $$ = eval_literal($1, 16, 64);
147 }
148 ; 121 ;
149 122
150devicetree: 123devicetree:
151 '/' nodedef 124 '/' nodedef
152 { 125 {
153 $$ = name_node($2, "", NULL); 126 $$ = name_node($2, "");
127 }
128 | devicetree '/' nodedef
129 {
130 $$ = merge_nodes($1, $3);
131 }
132 | devicetree DT_REF nodedef
133 {
134 struct node *target = get_node_by_ref($1, $2);
135
136 if (target)
137 merge_nodes(target, $3);
138 else
139 print_error("label or path, '%s', not found", $2);
140 $$ = $1;
154 } 141 }
155 ; 142 ;
156 143
@@ -173,13 +160,18 @@ proplist:
173 ; 160 ;
174 161
175propdef: 162propdef:
176 label DT_PROPNODENAME '=' propdata ';' 163 DT_PROPNODENAME '=' propdata ';'
164 {
165 $$ = build_property($1, $3);
166 }
167 | DT_PROPNODENAME ';'
177 { 168 {
178 $$ = build_property($2, $4, $1); 169 $$ = build_property($1, empty_data);
179 } 170 }
180 | label DT_PROPNODENAME ';' 171 | DT_LABEL propdef
181 { 172 {
182 $$ = build_property($2, empty_data, $1); 173 add_label(&$2->labels, $1);
174 $$ = $2;
183 } 175 }
184 ; 176 ;
185 177
@@ -202,31 +194,30 @@ propdata:
202 } 194 }
203 | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')' 195 | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')'
204 { 196 {
205 struct search_path path = { srcpos_file->dir, NULL, NULL }; 197 FILE *f = srcfile_relative_open($4.val, NULL);
206 struct dtc_file *file = dtc_open_file($4.val, &path); 198 struct data d;
207 struct data d = empty_data;
208 199
209 if ($6 != 0) 200 if ($6 != 0)
210 if (fseek(file->file, $6, SEEK_SET) != 0) 201 if (fseek(f, $6, SEEK_SET) != 0)
211 yyerrorf("Couldn't seek to offset %llu in \"%s\": %s", 202 print_error("Couldn't seek to offset %llu in \"%s\": %s",
212 (unsigned long long)$6, 203 (unsigned long long)$6,
213 $4.val, strerror(errno)); 204 $4.val,
205 strerror(errno));
214 206
215 d = data_copy_file(file->file, $8); 207 d = data_copy_file(f, $8);
216 208
217 $$ = data_merge($1, d); 209 $$ = data_merge($1, d);
218 dtc_close_file(file); 210 fclose(f);
219 } 211 }
220 | propdataprefix DT_INCBIN '(' DT_STRING ')' 212 | propdataprefix DT_INCBIN '(' DT_STRING ')'
221 { 213 {
222 struct search_path path = { srcpos_file->dir, NULL, NULL }; 214 FILE *f = srcfile_relative_open($4.val, NULL);
223 struct dtc_file *file = dtc_open_file($4.val, &path);
224 struct data d = empty_data; 215 struct data d = empty_data;
225 216
226 d = data_copy_file(file->file, -1); 217 d = data_copy_file(f, -1);
227 218
228 $$ = data_merge($1, d); 219 $$ = data_merge($1, d);
229 dtc_close_file(file); 220 fclose(f);
230 } 221 }
231 | propdata DT_LABEL 222 | propdata DT_LABEL
232 { 223 {
@@ -269,23 +260,11 @@ celllist:
269 } 260 }
270 ; 261 ;
271 262
272cellbase:
273 /* empty */
274 {
275 $$ = 16;
276 }
277 | DT_BASE
278 ;
279
280cellval: 263cellval:
281 DT_LITERAL 264 DT_LITERAL
282 { 265 {
283 $$ = eval_literal($1, 0, 32); 266 $$ = eval_literal($1, 0, 32);
284 } 267 }
285 | cellbase DT_LEGACYLITERAL
286 {
287 $$ = eval_literal($2, $1, 32);
288 }
289 ; 268 ;
290 269
291bytestring: 270bytestring:
@@ -308,57 +287,44 @@ subnodes:
308 { 287 {
309 $$ = NULL; 288 $$ = NULL;
310 } 289 }
311 | subnode subnodes 290 | subnode subnodes
312 { 291 {
313 $$ = chain_node($1, $2); 292 $$ = chain_node($1, $2);
314 } 293 }
315 | subnode propdef 294 | subnode propdef
316 { 295 {
317 yyerror("syntax error: properties must precede subnodes"); 296 print_error("syntax error: properties must precede subnodes");
318 YYERROR; 297 YYERROR;
319 } 298 }
320 ; 299 ;
321 300
322subnode: 301subnode:
323 label DT_PROPNODENAME nodedef 302 DT_PROPNODENAME nodedef
324 { 303 {
325 $$ = name_node($3, $2, $1); 304 $$ = name_node($2, $1);
326 } 305 }
327 ; 306 | DT_LABEL subnode
328
329label:
330 /* empty */
331 { 307 {
332 $$ = NULL; 308 add_label(&$2->labels, $1);
333 } 309 $$ = $2;
334 | DT_LABEL
335 {
336 $$ = $1;
337 } 310 }
338 ; 311 ;
339 312
340%% 313%%
341 314
342void yyerrorf(char const *s, ...) 315void print_error(char const *fmt, ...)
343{ 316{
344 const char *fname = srcpos_file ? srcpos_file->name : "<no-file>";
345 va_list va; 317 va_list va;
346 va_start(va, s);
347
348 if (strcmp(fname, "-") == 0)
349 fname = "stdin";
350 318
351 fprintf(stderr, "%s:%d ", fname, yylloc.first_line); 319 va_start(va, fmt);
352 vfprintf(stderr, s, va); 320 srcpos_verror(&yylloc, fmt, va);
353 fprintf(stderr, "\n"); 321 va_end(va);
354 322
355 treesource_error = 1; 323 treesource_error = 1;
356 va_end(va);
357} 324}
358 325
359void yyerror (char const *s) 326void yyerror(char const *s) {
360{ 327 print_error("%s", s);
361 yyerrorf("%s", s);
362} 328}
363 329
364static unsigned long long eval_literal(const char *s, int base, int bits) 330static unsigned long long eval_literal(const char *s, int base, int bits)
@@ -369,11 +335,11 @@ static unsigned long long eval_literal(const char *s, int base, int bits)
369 errno = 0; 335 errno = 0;
370 val = strtoull(s, &e, base); 336 val = strtoull(s, &e, base);
371 if (*e) 337 if (*e)
372 yyerror("bad characters in literal"); 338 print_error("bad characters in literal");
373 else if ((errno == ERANGE) 339 else if ((errno == ERANGE)
374 || ((bits < 64) && (val >= (1ULL << bits)))) 340 || ((bits < 64) && (val >= (1ULL << bits))))
375 yyerror("literal out of range"); 341 print_error("literal out of range");
376 else if (errno != 0) 342 else if (errno != 0)
377 yyerror("bad literal"); 343 print_error("bad literal");
378 return val; 344 return val;
379} 345}
diff --git a/scripts/dtc/dtc.c b/scripts/dtc/dtc.c
index d8fd43b4ac1a..cbc0193098e4 100644
--- a/scripts/dtc/dtc.c
+++ b/scripts/dtc/dtc.c
@@ -30,30 +30,7 @@ int quiet; /* Level of quietness */
30int reservenum; /* Number of memory reservation slots */ 30int reservenum; /* Number of memory reservation slots */
31int minsize; /* Minimum blob size */ 31int minsize; /* Minimum blob size */
32int padsize; /* Additional padding to blob */ 32int padsize; /* Additional padding to blob */
33 33int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
34char *join_path(const char *path, const char *name)
35{
36 int lenp = strlen(path);
37 int lenn = strlen(name);
38 int len;
39 int needslash = 1;
40 char *str;
41
42 len = lenp + lenn + 2;
43 if ((lenp > 0) && (path[lenp-1] == '/')) {
44 needslash = 0;
45 len--;
46 }
47
48 str = xmalloc(len);
49 memcpy(str, path, lenp);
50 if (needslash) {
51 str[lenp] = '/';
52 lenp++;
53 }
54 memcpy(str+lenp, name, lenn+1);
55 return str;
56}
57 34
58static void fill_fullpaths(struct node *tree, const char *prefix) 35static void fill_fullpaths(struct node *tree, const char *prefix)
59{ 36{
@@ -104,8 +81,15 @@ static void __attribute__ ((noreturn)) usage(void)
104 fprintf(stderr, "\t\tSet the physical boot cpu\n"); 81 fprintf(stderr, "\t\tSet the physical boot cpu\n");
105 fprintf(stderr, "\t-f\n"); 82 fprintf(stderr, "\t-f\n");
106 fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n"); 83 fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n");
84 fprintf(stderr, "\t-s\n");
85 fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n");
107 fprintf(stderr, "\t-v\n"); 86 fprintf(stderr, "\t-v\n");
108 fprintf(stderr, "\t\tPrint DTC version and exit\n"); 87 fprintf(stderr, "\t\tPrint DTC version and exit\n");
88 fprintf(stderr, "\t-H <phandle format>\n");
89 fprintf(stderr, "\t\tphandle formats are:\n");
90 fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n");
91 fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n");
92 fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n");
109 exit(3); 93 exit(3);
110} 94}
111 95
@@ -115,7 +99,7 @@ int main(int argc, char *argv[])
115 const char *inform = "dts"; 99 const char *inform = "dts";
116 const char *outform = "dts"; 100 const char *outform = "dts";
117 const char *outname = "-"; 101 const char *outname = "-";
118 int force = 0, check = 0; 102 int force = 0, check = 0, sort = 0;
119 const char *arg; 103 const char *arg;
120 int opt; 104 int opt;
121 FILE *outf = NULL; 105 FILE *outf = NULL;
@@ -127,7 +111,7 @@ int main(int argc, char *argv[])
127 minsize = 0; 111 minsize = 0;
128 padsize = 0; 112 padsize = 0;
129 113
130 while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:v")) != EOF) { 114 while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:vH:s")) != EOF) {
131 switch (opt) { 115 switch (opt) {
132 case 'I': 116 case 'I':
133 inform = optarg; 117 inform = optarg;
@@ -165,6 +149,22 @@ int main(int argc, char *argv[])
165 case 'v': 149 case 'v':
166 printf("Version: %s\n", DTC_VERSION); 150 printf("Version: %s\n", DTC_VERSION);
167 exit(0); 151 exit(0);
152 case 'H':
153 if (streq(optarg, "legacy"))
154 phandle_format = PHANDLE_LEGACY;
155 else if (streq(optarg, "epapr"))
156 phandle_format = PHANDLE_EPAPR;
157 else if (streq(optarg, "both"))
158 phandle_format = PHANDLE_BOTH;
159 else
160 die("Invalid argument \"%s\" to -H option\n",
161 optarg);
162 break;
163
164 case 's':
165 sort = 1;
166 break;
167
168 case 'h': 168 case 'h':
169 default: 169 default:
170 usage(); 170 usage();
@@ -182,6 +182,9 @@ int main(int argc, char *argv[])
182 if (minsize && padsize) 182 if (minsize && padsize)
183 die("Can't set both -p and -S\n"); 183 die("Can't set both -p and -S\n");
184 184
185 if (minsize)
186 fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead\n");
187
185 fprintf(stderr, "DTC: %s->%s on file \"%s\"\n", 188 fprintf(stderr, "DTC: %s->%s on file \"%s\"\n",
186 inform, outform, arg); 189 inform, outform, arg);
187 190
@@ -200,6 +203,8 @@ int main(int argc, char *argv[])
200 fill_fullpaths(bi->dt, ""); 203 fill_fullpaths(bi->dt, "");
201 process_checks(force, bi); 204 process_checks(force, bi);
202 205
206 if (sort)
207 sort_tree(bi);
203 208
204 if (streq(outname, "-")) { 209 if (streq(outname, "-")) {
205 outf = stdout; 210 outf = stdout;
diff --git a/scripts/dtc/dtc.h b/scripts/dtc/dtc.h
index 08d54c870086..f37c97eb3dfc 100644
--- a/scripts/dtc/dtc.h
+++ b/scripts/dtc/dtc.h
@@ -34,7 +34,17 @@
34#include <libfdt_env.h> 34#include <libfdt_env.h>
35#include <fdt.h> 35#include <fdt.h>
36 36
37#include "util.h"
38
39#ifdef DEBUG
40#define debug(fmt,args...) printf(fmt, ##args)
41#else
42#define debug(fmt,args...)
43#endif
44
45
37#define DEFAULT_FDT_VERSION 17 46#define DEFAULT_FDT_VERSION 17
47
38/* 48/*
39 * Command line options 49 * Command line options
40 */ 50 */
@@ -42,36 +52,11 @@ extern int quiet; /* Level of quietness */
42extern int reservenum; /* Number of memory reservation slots */ 52extern int reservenum; /* Number of memory reservation slots */
43extern int minsize; /* Minimum blob size */ 53extern int minsize; /* Minimum blob size */
44extern int padsize; /* Additional padding to blob */ 54extern int padsize; /* Additional padding to blob */
55extern int phandle_format; /* Use linux,phandle or phandle properties */
45 56
46static inline void __attribute__((noreturn)) die(char * str, ...) 57#define PHANDLE_LEGACY 0x1
47{ 58#define PHANDLE_EPAPR 0x2
48 va_list ap; 59#define PHANDLE_BOTH 0x3
49
50 va_start(ap, str);
51 fprintf(stderr, "FATAL ERROR: ");
52 vfprintf(stderr, str, ap);
53 exit(1);
54}
55
56static inline void *xmalloc(size_t len)
57{
58 void *new = malloc(len);
59
60 if (! new)
61 die("malloc() failed\n");
62
63 return new;
64}
65
66static inline void *xrealloc(void *p, size_t len)
67{
68 void *new = realloc(p, len);
69
70 if (! new)
71 die("realloc() failed (len=%d)\n", len);
72
73 return new;
74}
75 60
76typedef uint32_t cell_t; 61typedef uint32_t cell_t;
77 62
@@ -140,13 +125,18 @@ int data_is_one_string(struct data d);
140#define MAX_NODENAME_LEN 31 125#define MAX_NODENAME_LEN 31
141 126
142/* Live trees */ 127/* Live trees */
128struct label {
129 char *label;
130 struct label *next;
131};
132
143struct property { 133struct property {
144 char *name; 134 char *name;
145 struct data val; 135 struct data val;
146 136
147 struct property *next; 137 struct property *next;
148 138
149 char *label; 139 struct label *labels;
150}; 140};
151 141
152struct node { 142struct node {
@@ -163,22 +153,28 @@ struct node {
163 cell_t phandle; 153 cell_t phandle;
164 int addr_cells, size_cells; 154 int addr_cells, size_cells;
165 155
166 char *label; 156 struct label *labels;
167}; 157};
168 158
159#define for_each_label(l0, l) \
160 for ((l) = (l0); (l); (l) = (l)->next)
161
169#define for_each_property(n, p) \ 162#define for_each_property(n, p) \
170 for ((p) = (n)->proplist; (p); (p) = (p)->next) 163 for ((p) = (n)->proplist; (p); (p) = (p)->next)
171 164
172#define for_each_child(n, c) \ 165#define for_each_child(n, c) \
173 for ((c) = (n)->children; (c); (c) = (c)->next_sibling) 166 for ((c) = (n)->children; (c); (c) = (c)->next_sibling)
174 167
175struct property *build_property(char *name, struct data val, char *label); 168void add_label(struct label **labels, char *label);
169
170struct property *build_property(char *name, struct data val);
176struct property *chain_property(struct property *first, struct property *list); 171struct property *chain_property(struct property *first, struct property *list);
177struct property *reverse_properties(struct property *first); 172struct property *reverse_properties(struct property *first);
178 173
179struct node *build_node(struct property *proplist, struct node *children); 174struct node *build_node(struct property *proplist, struct node *children);
180struct node *name_node(struct node *node, char *name, char *label); 175struct node *name_node(struct node *node, char *name);
181struct node *chain_node(struct node *first, struct node *list); 176struct node *chain_node(struct node *first, struct node *list);
177struct node *merge_nodes(struct node *old_node, struct node *new_node);
182 178
183void add_property(struct node *node, struct property *prop); 179void add_property(struct node *node, struct property *prop);
184void add_child(struct node *parent, struct node *child); 180void add_child(struct node *parent, struct node *child);
@@ -186,6 +182,10 @@ void add_child(struct node *parent, struct node *child);
186const char *get_unitname(struct node *node); 182const char *get_unitname(struct node *node);
187struct property *get_property(struct node *node, const char *propname); 183struct property *get_property(struct node *node, const char *propname);
188cell_t propval_cell(struct property *prop); 184cell_t propval_cell(struct property *prop);
185struct property *get_property_by_label(struct node *tree, const char *label,
186 struct node **node);
187struct marker *get_marker_label(struct node *tree, const char *label,
188 struct node **node, struct property **prop);
189struct node *get_subnode(struct node *node, const char *nodename); 189struct node *get_subnode(struct node *node, const char *nodename);
190struct node *get_node_by_path(struct node *tree, const char *path); 190struct node *get_node_by_path(struct node *tree, const char *path);
191struct node *get_node_by_label(struct node *tree, const char *label); 191struct node *get_node_by_label(struct node *tree, const char *label);
@@ -193,6 +193,8 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
193struct node *get_node_by_ref(struct node *tree, const char *ref); 193struct node *get_node_by_ref(struct node *tree, const char *ref);
194cell_t get_node_phandle(struct node *root, struct node *node); 194cell_t get_node_phandle(struct node *root, struct node *node);
195 195
196uint32_t guess_boot_cpuid(struct node *tree);
197
196/* Boot info (tree plus memreserve information */ 198/* Boot info (tree plus memreserve information */
197 199
198struct reserve_info { 200struct reserve_info {
@@ -200,10 +202,10 @@ struct reserve_info {
200 202
201 struct reserve_info *next; 203 struct reserve_info *next;
202 204
203 char *label; 205 struct label *labels;
204}; 206};
205 207
206struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len, char *label); 208struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len);
207struct reserve_info *chain_reserve_entry(struct reserve_info *first, 209struct reserve_info *chain_reserve_entry(struct reserve_info *first,
208 struct reserve_info *list); 210 struct reserve_info *list);
209struct reserve_info *add_reserve_entry(struct reserve_info *list, 211struct reserve_info *add_reserve_entry(struct reserve_info *list,
@@ -218,6 +220,7 @@ struct boot_info {
218 220
219struct boot_info *build_boot_info(struct reserve_info *reservelist, 221struct boot_info *build_boot_info(struct reserve_info *reservelist,
220 struct node *tree, uint32_t boot_cpuid_phys); 222 struct node *tree, uint32_t boot_cpuid_phys);
223void sort_tree(struct boot_info *bi);
221 224
222/* Checks */ 225/* Checks */
223 226
@@ -239,8 +242,4 @@ struct boot_info *dt_from_source(const char *f);
239 242
240struct boot_info *dt_from_fs(const char *dirname); 243struct boot_info *dt_from_fs(const char *dirname);
241 244
242/* misc */
243
244char *join_path(const char *path, const char *name);
245
246#endif /* _DTC_H */ 245#endif /* _DTC_H */
diff --git a/scripts/dtc/flattree.c b/scripts/dtc/flattree.c
index 76acd28c068d..ead0332c87e1 100644
--- a/scripts/dtc/flattree.c
+++ b/scripts/dtc/flattree.c
@@ -52,9 +52,9 @@ struct emitter {
52 void (*string)(void *, char *, int); 52 void (*string)(void *, char *, int);
53 void (*align)(void *, int); 53 void (*align)(void *, int);
54 void (*data)(void *, struct data); 54 void (*data)(void *, struct data);
55 void (*beginnode)(void *, const char *); 55 void (*beginnode)(void *, struct label *labels);
56 void (*endnode)(void *, const char *); 56 void (*endnode)(void *, struct label *labels);
57 void (*property)(void *, const char *); 57 void (*property)(void *, struct label *labels);
58}; 58};
59 59
60static void bin_emit_cell(void *e, cell_t val) 60static void bin_emit_cell(void *e, cell_t val)
@@ -89,17 +89,17 @@ static void bin_emit_data(void *e, struct data d)
89 *dtbuf = data_append_data(*dtbuf, d.val, d.len); 89 *dtbuf = data_append_data(*dtbuf, d.val, d.len);
90} 90}
91 91
92static void bin_emit_beginnode(void *e, const char *label) 92static void bin_emit_beginnode(void *e, struct label *labels)
93{ 93{
94 bin_emit_cell(e, FDT_BEGIN_NODE); 94 bin_emit_cell(e, FDT_BEGIN_NODE);
95} 95}
96 96
97static void bin_emit_endnode(void *e, const char *label) 97static void bin_emit_endnode(void *e, struct label *labels)
98{ 98{
99 bin_emit_cell(e, FDT_END_NODE); 99 bin_emit_cell(e, FDT_END_NODE);
100} 100}
101 101
102static void bin_emit_property(void *e, const char *label) 102static void bin_emit_property(void *e, struct label *labels)
103{ 103{
104 bin_emit_cell(e, FDT_PROP); 104 bin_emit_cell(e, FDT_PROP);
105} 105}
@@ -127,11 +127,21 @@ static void emit_offset_label(FILE *f, const char *label, int offset)
127 fprintf(f, "%s\t= . + %d\n", label, offset); 127 fprintf(f, "%s\t= . + %d\n", label, offset);
128} 128}
129 129
130#define ASM_EMIT_BELONG(f, fmt, ...) \
131 { \
132 fprintf((f), "\t.byte\t((" fmt ") >> 24) & 0xff\n", __VA_ARGS__); \
133 fprintf((f), "\t.byte\t((" fmt ") >> 16) & 0xff\n", __VA_ARGS__); \
134 fprintf((f), "\t.byte\t((" fmt ") >> 8) & 0xff\n", __VA_ARGS__); \
135 fprintf((f), "\t.byte\t(" fmt ") & 0xff\n", __VA_ARGS__); \
136 }
137
130static void asm_emit_cell(void *e, cell_t val) 138static void asm_emit_cell(void *e, cell_t val)
131{ 139{
132 FILE *f = e; 140 FILE *f = e;
133 141
134 fprintf(f, "\t.long\t0x%x\n", val); 142 fprintf(f, "\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n",
143 (val >> 24) & 0xff, (val >> 16) & 0xff,
144 (val >> 8) & 0xff, val & 0xff);
135} 145}
136 146
137static void asm_emit_string(void *e, char *str, int len) 147static void asm_emit_string(void *e, char *str, int len)
@@ -156,7 +166,7 @@ static void asm_emit_align(void *e, int a)
156{ 166{
157 FILE *f = e; 167 FILE *f = e;
158 168
159 fprintf(f, "\t.balign\t%d\n", a); 169 fprintf(f, "\t.balign\t%d, 0\n", a);
160} 170}
161 171
162static void asm_emit_data(void *e, struct data d) 172static void asm_emit_data(void *e, struct data d)
@@ -169,8 +179,7 @@ static void asm_emit_data(void *e, struct data d)
169 emit_offset_label(f, m->ref, m->offset); 179 emit_offset_label(f, m->ref, m->offset);
170 180
171 while ((d.len - off) >= sizeof(uint32_t)) { 181 while ((d.len - off) >= sizeof(uint32_t)) {
172 fprintf(f, "\t.long\t0x%x\n", 182 asm_emit_cell(e, fdt32_to_cpu(*((uint32_t *)(d.val+off))));
173 fdt32_to_cpu(*((uint32_t *)(d.val+off))));
174 off += sizeof(uint32_t); 183 off += sizeof(uint32_t);
175 } 184 }
176 185
@@ -182,37 +191,43 @@ static void asm_emit_data(void *e, struct data d)
182 assert(off == d.len); 191 assert(off == d.len);
183} 192}
184 193
185static void asm_emit_beginnode(void *e, const char *label) 194static void asm_emit_beginnode(void *e, struct label *labels)
186{ 195{
187 FILE *f = e; 196 FILE *f = e;
197 struct label *l;
188 198
189 if (label) { 199 for_each_label(labels, l) {
190 fprintf(f, "\t.globl\t%s\n", label); 200 fprintf(f, "\t.globl\t%s\n", l->label);
191 fprintf(f, "%s:\n", label); 201 fprintf(f, "%s:\n", l->label);
192 } 202 }
193 fprintf(f, "\t.long\tFDT_BEGIN_NODE\n"); 203 fprintf(f, "\t/* FDT_BEGIN_NODE */\n");
204 asm_emit_cell(e, FDT_BEGIN_NODE);
194} 205}
195 206
196static void asm_emit_endnode(void *e, const char *label) 207static void asm_emit_endnode(void *e, struct label *labels)
197{ 208{
198 FILE *f = e; 209 FILE *f = e;
210 struct label *l;
199 211
200 fprintf(f, "\t.long\tFDT_END_NODE\n"); 212 fprintf(f, "\t/* FDT_END_NODE */\n");
201 if (label) { 213 asm_emit_cell(e, FDT_END_NODE);
202 fprintf(f, "\t.globl\t%s_end\n", label); 214 for_each_label(labels, l) {
203 fprintf(f, "%s_end:\n", label); 215 fprintf(f, "\t.globl\t%s_end\n", l->label);
216 fprintf(f, "%s_end:\n", l->label);
204 } 217 }
205} 218}
206 219
207static void asm_emit_property(void *e, const char *label) 220static void asm_emit_property(void *e, struct label *labels)
208{ 221{
209 FILE *f = e; 222 FILE *f = e;
223 struct label *l;
210 224
211 if (label) { 225 for_each_label(labels, l) {
212 fprintf(f, "\t.globl\t%s\n", label); 226 fprintf(f, "\t.globl\t%s\n", l->label);
213 fprintf(f, "%s:\n", label); 227 fprintf(f, "%s:\n", l->label);
214 } 228 }
215 fprintf(f, "\t.long\tFDT_PROP\n"); 229 fprintf(f, "\t/* FDT_PROP */\n");
230 asm_emit_cell(e, FDT_PROP);
216} 231}
217 232
218static struct emitter asm_emitter = { 233static struct emitter asm_emitter = {
@@ -248,7 +263,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
248 struct node *child; 263 struct node *child;
249 int seen_name_prop = 0; 264 int seen_name_prop = 0;
250 265
251 emit->beginnode(etarget, tree->label); 266 emit->beginnode(etarget, tree->labels);
252 267
253 if (vi->flags & FTF_FULLPATH) 268 if (vi->flags & FTF_FULLPATH)
254 emit->string(etarget, tree->fullpath, 0); 269 emit->string(etarget, tree->fullpath, 0);
@@ -265,7 +280,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
265 280
266 nameoff = stringtable_insert(strbuf, prop->name); 281 nameoff = stringtable_insert(strbuf, prop->name);
267 282
268 emit->property(etarget, prop->label); 283 emit->property(etarget, prop->labels);
269 emit->cell(etarget, prop->val.len); 284 emit->cell(etarget, prop->val.len);
270 emit->cell(etarget, nameoff); 285 emit->cell(etarget, nameoff);
271 286
@@ -292,7 +307,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
292 flatten_tree(child, emit, etarget, strbuf, vi); 307 flatten_tree(child, emit, etarget, strbuf, vi);
293 } 308 }
294 309
295 emit->endnode(etarget, tree->label); 310 emit->endnode(etarget, tree->labels);
296} 311}
297 312
298static struct data flatten_reserve_list(struct reserve_info *reservelist, 313static struct data flatten_reserve_list(struct reserve_info *reservelist,
@@ -413,10 +428,13 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
413 if (padlen > 0) 428 if (padlen > 0)
414 blob = data_append_zeroes(blob, padlen); 429 blob = data_append_zeroes(blob, padlen);
415 430
416 fwrite(blob.val, blob.len, 1, f); 431 if (fwrite(blob.val, blob.len, 1, f) != 1) {
417 432 if (ferror(f))
418 if (ferror(f)) 433 die("Error writing device tree blob: %s\n",
419 die("Error writing device tree blob: %s\n", strerror(errno)); 434 strerror(errno));
435 else
436 die("Short write on device tree blob\n");
437 }
420 438
421 /* 439 /*
422 * data_merge() frees the right-hand element so only the blob 440 * data_merge() frees the right-hand element so only the blob
@@ -455,39 +473,44 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version)
455 die("Unknown device tree blob version %d\n", version); 473 die("Unknown device tree blob version %d\n", version);
456 474
457 fprintf(f, "/* autogenerated by dtc, do not edit */\n\n"); 475 fprintf(f, "/* autogenerated by dtc, do not edit */\n\n");
458 fprintf(f, "#define FDT_MAGIC 0x%x\n", FDT_MAGIC);
459 fprintf(f, "#define FDT_BEGIN_NODE 0x%x\n", FDT_BEGIN_NODE);
460 fprintf(f, "#define FDT_END_NODE 0x%x\n", FDT_END_NODE);
461 fprintf(f, "#define FDT_PROP 0x%x\n", FDT_PROP);
462 fprintf(f, "#define FDT_END 0x%x\n", FDT_END);
463 fprintf(f, "\n");
464 476
465 emit_label(f, symprefix, "blob_start"); 477 emit_label(f, symprefix, "blob_start");
466 emit_label(f, symprefix, "header"); 478 emit_label(f, symprefix, "header");
467 fprintf(f, "\t.long\tFDT_MAGIC\t\t\t\t/* magic */\n"); 479 fprintf(f, "\t/* magic */\n");
468 fprintf(f, "\t.long\t_%s_blob_abs_end - _%s_blob_start\t/* totalsize */\n", 480 asm_emit_cell(f, FDT_MAGIC);
469 symprefix, symprefix); 481 fprintf(f, "\t/* totalsize */\n");
470 fprintf(f, "\t.long\t_%s_struct_start - _%s_blob_start\t/* off_dt_struct */\n", 482 ASM_EMIT_BELONG(f, "_%s_blob_abs_end - _%s_blob_start",
483 symprefix, symprefix);
484 fprintf(f, "\t/* off_dt_struct */\n");
485 ASM_EMIT_BELONG(f, "_%s_struct_start - _%s_blob_start",
471 symprefix, symprefix); 486 symprefix, symprefix);
472 fprintf(f, "\t.long\t_%s_strings_start - _%s_blob_start\t/* off_dt_strings */\n", 487 fprintf(f, "\t/* off_dt_strings */\n");
488 ASM_EMIT_BELONG(f, "_%s_strings_start - _%s_blob_start",
473 symprefix, symprefix); 489 symprefix, symprefix);
474 fprintf(f, "\t.long\t_%s_reserve_map - _%s_blob_start\t/* off_dt_strings */\n", 490 fprintf(f, "\t/* off_mem_rsvmap */\n");
491 ASM_EMIT_BELONG(f, "_%s_reserve_map - _%s_blob_start",
475 symprefix, symprefix); 492 symprefix, symprefix);
476 fprintf(f, "\t.long\t%d\t\t\t\t\t/* version */\n", vi->version); 493 fprintf(f, "\t/* version */\n");
477 fprintf(f, "\t.long\t%d\t\t\t\t\t/* last_comp_version */\n", 494 asm_emit_cell(f, vi->version);
478 vi->last_comp_version); 495 fprintf(f, "\t/* last_comp_version */\n");
479 496 asm_emit_cell(f, vi->last_comp_version);
480 if (vi->flags & FTF_BOOTCPUID) 497
481 fprintf(f, "\t.long\t%i\t\t\t\t\t/* boot_cpuid_phys */\n", 498 if (vi->flags & FTF_BOOTCPUID) {
482 bi->boot_cpuid_phys); 499 fprintf(f, "\t/* boot_cpuid_phys */\n");
500 asm_emit_cell(f, bi->boot_cpuid_phys);
501 }
483 502
484 if (vi->flags & FTF_STRTABSIZE) 503 if (vi->flags & FTF_STRTABSIZE) {
485 fprintf(f, "\t.long\t_%s_strings_end - _%s_strings_start\t/* size_dt_strings */\n", 504 fprintf(f, "\t/* size_dt_strings */\n");
486 symprefix, symprefix); 505 ASM_EMIT_BELONG(f, "_%s_strings_end - _%s_strings_start",
506 symprefix, symprefix);
507 }
487 508
488 if (vi->flags & FTF_STRUCTSIZE) 509 if (vi->flags & FTF_STRUCTSIZE) {
489 fprintf(f, "\t.long\t_%s_struct_end - _%s_struct_start\t/* size_dt_struct */\n", 510 fprintf(f, "\t/* size_dt_struct */\n");
511 ASM_EMIT_BELONG(f, "_%s_struct_end - _%s_struct_start",
490 symprefix, symprefix); 512 symprefix, symprefix);
513 }
491 514
492 /* 515 /*
493 * Reserve map entries. 516 * Reserve map entries.
@@ -505,16 +528,17 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version)
505 * as it appears .quad isn't available in some assemblers. 528 * as it appears .quad isn't available in some assemblers.
506 */ 529 */
507 for (re = bi->reservelist; re; re = re->next) { 530 for (re = bi->reservelist; re; re = re->next) {
508 if (re->label) { 531 struct label *l;
509 fprintf(f, "\t.globl\t%s\n", re->label); 532
510 fprintf(f, "%s:\n", re->label); 533 for_each_label(re->labels, l) {
534 fprintf(f, "\t.globl\t%s\n", l->label);
535 fprintf(f, "%s:\n", l->label);
511 } 536 }
512 fprintf(f, "\t.long\t0x%08x, 0x%08x\n", 537 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.address >> 32));
513 (unsigned int)(re->re.address >> 32), 538 ASM_EMIT_BELONG(f, "0x%08x",
514 (unsigned int)(re->re.address & 0xffffffff)); 539 (unsigned int)(re->re.address & 0xffffffff));
515 fprintf(f, "\t.long\t0x%08x, 0x%08x\n", 540 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size >> 32));
516 (unsigned int)(re->re.size >> 32), 541 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size & 0xffffffff));
517 (unsigned int)(re->re.size & 0xffffffff));
518 } 542 }
519 for (i = 0; i < reservenum; i++) { 543 for (i = 0; i < reservenum; i++) {
520 fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n"); 544 fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n");
@@ -524,7 +548,9 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version)
524 548
525 emit_label(f, symprefix, "struct_start"); 549 emit_label(f, symprefix, "struct_start");
526 flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi); 550 flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi);
527 fprintf(f, "\t.long\tFDT_END\n"); 551
552 fprintf(f, "\t/* FDT_END */\n");
553 asm_emit_cell(f, FDT_END);
528 emit_label(f, symprefix, "struct_end"); 554 emit_label(f, symprefix, "struct_end");
529 555
530 emit_label(f, symprefix, "strings_start"); 556 emit_label(f, symprefix, "strings_start");
@@ -601,7 +627,7 @@ static char *flat_read_string(struct inbuf *inb)
601 len++; 627 len++;
602 } while ((*p++) != '\0'); 628 } while ((*p++) != '\0');
603 629
604 str = strdup(inb->ptr); 630 str = xstrdup(inb->ptr);
605 631
606 inb->ptr += len; 632 inb->ptr += len;
607 633
@@ -643,7 +669,7 @@ static char *flat_read_stringtable(struct inbuf *inb, int offset)
643 p++; 669 p++;
644 } 670 }
645 671
646 return strdup(inb->base + offset); 672 return xstrdup(inb->base + offset);
647} 673}
648 674
649static struct property *flat_read_property(struct inbuf *dtbuf, 675static struct property *flat_read_property(struct inbuf *dtbuf,
@@ -663,7 +689,7 @@ static struct property *flat_read_property(struct inbuf *dtbuf,
663 689
664 val = flat_read_data(dtbuf, proplen); 690 val = flat_read_data(dtbuf, proplen);
665 691
666 return build_property(name, val, NULL); 692 return build_property(name, val);
667} 693}
668 694
669 695
@@ -688,7 +714,7 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
688 if (re.size == 0) 714 if (re.size == 0)
689 break; 715 break;
690 716
691 new = build_reserve_entry(re.address, re.size, NULL); 717 new = build_reserve_entry(re.address, re.size);
692 reservelist = add_reserve_entry(reservelist, new); 718 reservelist = add_reserve_entry(reservelist, new);
693 } 719 }
694 720
@@ -710,7 +736,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath)
710 if (!streq(ppath, "/")) 736 if (!streq(ppath, "/"))
711 plen++; 737 plen++;
712 738
713 return strdup(cpath + plen); 739 return xstrdup(cpath + plen);
714} 740}
715 741
716static struct node *unflatten_tree(struct inbuf *dtbuf, 742static struct node *unflatten_tree(struct inbuf *dtbuf,
@@ -776,7 +802,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
776 802
777struct boot_info *dt_from_blob(const char *fname) 803struct boot_info *dt_from_blob(const char *fname)
778{ 804{
779 struct dtc_file *dtcf; 805 FILE *f;
780 uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys; 806 uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys;
781 uint32_t off_dt, off_str, off_mem_rsvmap; 807 uint32_t off_dt, off_str, off_mem_rsvmap;
782 int rc; 808 int rc;
@@ -791,14 +817,14 @@ struct boot_info *dt_from_blob(const char *fname)
791 uint32_t val; 817 uint32_t val;
792 int flags = 0; 818 int flags = 0;
793 819
794 dtcf = dtc_open_file(fname, NULL); 820 f = srcfile_relative_open(fname, NULL);
795 821
796 rc = fread(&magic, sizeof(magic), 1, dtcf->file); 822 rc = fread(&magic, sizeof(magic), 1, f);
797 if (ferror(dtcf->file)) 823 if (ferror(f))
798 die("Error reading DT blob magic number: %s\n", 824 die("Error reading DT blob magic number: %s\n",
799 strerror(errno)); 825 strerror(errno));
800 if (rc < 1) { 826 if (rc < 1) {
801 if (feof(dtcf->file)) 827 if (feof(f))
802 die("EOF reading DT blob magic number\n"); 828 die("EOF reading DT blob magic number\n");
803 else 829 else
804 die("Mysterious short read reading magic number\n"); 830 die("Mysterious short read reading magic number\n");
@@ -808,11 +834,11 @@ struct boot_info *dt_from_blob(const char *fname)
808 if (magic != FDT_MAGIC) 834 if (magic != FDT_MAGIC)
809 die("Blob has incorrect magic number\n"); 835 die("Blob has incorrect magic number\n");
810 836
811 rc = fread(&totalsize, sizeof(totalsize), 1, dtcf->file); 837 rc = fread(&totalsize, sizeof(totalsize), 1, f);
812 if (ferror(dtcf->file)) 838 if (ferror(f))
813 die("Error reading DT blob size: %s\n", strerror(errno)); 839 die("Error reading DT blob size: %s\n", strerror(errno));
814 if (rc < 1) { 840 if (rc < 1) {
815 if (feof(dtcf->file)) 841 if (feof(f))
816 die("EOF reading DT blob size\n"); 842 die("EOF reading DT blob size\n");
817 else 843 else
818 die("Mysterious short read reading blob size\n"); 844 die("Mysterious short read reading blob size\n");
@@ -832,12 +858,12 @@ struct boot_info *dt_from_blob(const char *fname)
832 p = blob + sizeof(magic) + sizeof(totalsize); 858 p = blob + sizeof(magic) + sizeof(totalsize);
833 859
834 while (sizeleft) { 860 while (sizeleft) {
835 if (feof(dtcf->file)) 861 if (feof(f))
836 die("EOF before reading %d bytes of DT blob\n", 862 die("EOF before reading %d bytes of DT blob\n",
837 totalsize); 863 totalsize);
838 864
839 rc = fread(p, 1, sizeleft, dtcf->file); 865 rc = fread(p, 1, sizeleft, f);
840 if (ferror(dtcf->file)) 866 if (ferror(f))
841 die("Error reading DT blob: %s\n", 867 die("Error reading DT blob: %s\n",
842 strerror(errno)); 868 strerror(errno));
843 869
@@ -900,7 +926,7 @@ struct boot_info *dt_from_blob(const char *fname)
900 926
901 free(blob); 927 free(blob);
902 928
903 dtc_close_file(dtcf); 929 fclose(f);
904 930
905 return build_boot_info(reservelist, tree, boot_cpuid_phys); 931 return build_boot_info(reservelist, tree, boot_cpuid_phys);
906} 932}
diff --git a/scripts/dtc/fstree.c b/scripts/dtc/fstree.c
index 8fe1bdf239f0..f3774530170a 100644
--- a/scripts/dtc/fstree.c
+++ b/scripts/dtc/fstree.c
@@ -58,10 +58,9 @@ static struct node *read_fstree(const char *dirname)
58 "WARNING: Cannot open %s: %s\n", 58 "WARNING: Cannot open %s: %s\n",
59 tmpnam, strerror(errno)); 59 tmpnam, strerror(errno));
60 } else { 60 } else {
61 prop = build_property(strdup(de->d_name), 61 prop = build_property(xstrdup(de->d_name),
62 data_copy_file(pfile, 62 data_copy_file(pfile,
63 st.st_size), 63 st.st_size));
64 NULL);
65 add_property(tree, prop); 64 add_property(tree, prop);
66 fclose(pfile); 65 fclose(pfile);
67 } 66 }
@@ -69,8 +68,7 @@ static struct node *read_fstree(const char *dirname)
69 struct node *newchild; 68 struct node *newchild;
70 69
71 newchild = read_fstree(tmpnam); 70 newchild = read_fstree(tmpnam);
72 newchild = name_node(newchild, strdup(de->d_name), 71 newchild = name_node(newchild, xstrdup(de->d_name));
73 NULL);
74 add_child(tree, newchild); 72 add_child(tree, newchild);
75 } 73 }
76 74
@@ -86,8 +84,8 @@ struct boot_info *dt_from_fs(const char *dirname)
86 struct node *tree; 84 struct node *tree;
87 85
88 tree = read_fstree(dirname); 86 tree = read_fstree(dirname);
89 tree = name_node(tree, "", NULL); 87 tree = name_node(tree, "");
90 88
91 return build_boot_info(NULL, tree, 0); 89 return build_boot_info(NULL, tree, guess_boot_cpuid(tree));
92} 90}
93 91
diff --git a/scripts/dtc/livetree.c b/scripts/dtc/livetree.c
index 0ca3de550b3f..c9209d5c999e 100644
--- a/scripts/dtc/livetree.c
+++ b/scripts/dtc/livetree.c
@@ -24,17 +24,30 @@
24 * Tree building functions 24 * Tree building functions
25 */ 25 */
26 26
27struct property *build_property(char *name, struct data val, char *label) 27void add_label(struct label **labels, char *label)
28{
29 struct label *new;
30
31 /* Make sure the label isn't already there */
32 for_each_label(*labels, new)
33 if (streq(new->label, label))
34 return;
35
36 new = xmalloc(sizeof(*new));
37 new->label = label;
38 new->next = *labels;
39 *labels = new;
40}
41
42struct property *build_property(char *name, struct data val)
28{ 43{
29 struct property *new = xmalloc(sizeof(*new)); 44 struct property *new = xmalloc(sizeof(*new));
30 45
46 memset(new, 0, sizeof(*new));
47
31 new->name = name; 48 new->name = name;
32 new->val = val; 49 new->val = val;
33 50
34 new->next = NULL;
35
36 new->label = label;
37
38 return new; 51 return new;
39} 52}
40 53
@@ -78,17 +91,82 @@ struct node *build_node(struct property *proplist, struct node *children)
78 return new; 91 return new;
79} 92}
80 93
81struct node *name_node(struct node *node, char *name, char * label) 94struct node *name_node(struct node *node, char *name)
82{ 95{
83 assert(node->name == NULL); 96 assert(node->name == NULL);
84 97
85 node->name = name; 98 node->name = name;
86 99
87 node->label = label;
88
89 return node; 100 return node;
90} 101}
91 102
103struct node *merge_nodes(struct node *old_node, struct node *new_node)
104{
105 struct property *new_prop, *old_prop;
106 struct node *new_child, *old_child;
107 struct label *l;
108
109 /* Add new node labels to old node */
110 for_each_label(new_node->labels, l)
111 add_label(&old_node->labels, l->label);
112
113 /* Move properties from the new node to the old node. If there
114 * is a collision, replace the old value with the new */
115 while (new_node->proplist) {
116 /* Pop the property off the list */
117 new_prop = new_node->proplist;
118 new_node->proplist = new_prop->next;
119 new_prop->next = NULL;
120
121 /* Look for a collision, set new value if there is */
122 for_each_property(old_node, old_prop) {
123 if (streq(old_prop->name, new_prop->name)) {
124 /* Add new labels to old property */
125 for_each_label(new_prop->labels, l)
126 add_label(&old_prop->labels, l->label);
127
128 old_prop->val = new_prop->val;
129 free(new_prop);
130 new_prop = NULL;
131 break;
132 }
133 }
134
135 /* if no collision occurred, add property to the old node. */
136 if (new_prop)
137 add_property(old_node, new_prop);
138 }
139
140 /* Move the override child nodes into the primary node. If
141 * there is a collision, then merge the nodes. */
142 while (new_node->children) {
143 /* Pop the child node off the list */
144 new_child = new_node->children;
145 new_node->children = new_child->next_sibling;
146 new_child->parent = NULL;
147 new_child->next_sibling = NULL;
148
149 /* Search for a collision. Merge if there is */
150 for_each_child(old_node, old_child) {
151 if (streq(old_child->name, new_child->name)) {
152 merge_nodes(old_child, new_child);
153 new_child = NULL;
154 break;
155 }
156 }
157
158 /* if no collision occured, add child to the old node. */
159 if (new_child)
160 add_child(old_node, new_child);
161 }
162
163 /* The new node contents are now merged into the old node. Free
164 * the new node. */
165 free(new_node);
166
167 return old_node;
168}
169
92struct node *chain_node(struct node *first, struct node *list) 170struct node *chain_node(struct node *first, struct node *list)
93{ 171{
94 assert(first->next_sibling == NULL); 172 assert(first->next_sibling == NULL);
@@ -124,18 +202,15 @@ void add_child(struct node *parent, struct node *child)
124 *p = child; 202 *p = child;
125} 203}
126 204
127struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size, 205struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size)
128 char *label)
129{ 206{
130 struct reserve_info *new = xmalloc(sizeof(*new)); 207 struct reserve_info *new = xmalloc(sizeof(*new));
131 208
209 memset(new, 0, sizeof(*new));
210
132 new->re.address = address; 211 new->re.address = address;
133 new->re.size = size; 212 new->re.size = size;
134 213
135 new->next = NULL;
136
137 new->label = label;
138
139 return new; 214 return new;
140} 215}
141 216
@@ -208,6 +283,60 @@ cell_t propval_cell(struct property *prop)
208 return fdt32_to_cpu(*((cell_t *)prop->val.val)); 283 return fdt32_to_cpu(*((cell_t *)prop->val.val));
209} 284}
210 285
286struct property *get_property_by_label(struct node *tree, const char *label,
287 struct node **node)
288{
289 struct property *prop;
290 struct node *c;
291
292 *node = tree;
293
294 for_each_property(tree, prop) {
295 struct label *l;
296
297 for_each_label(prop->labels, l)
298 if (streq(l->label, label))
299 return prop;
300 }
301
302 for_each_child(tree, c) {
303 prop = get_property_by_label(c, label, node);
304 if (prop)
305 return prop;
306 }
307
308 *node = NULL;
309 return NULL;
310}
311
312struct marker *get_marker_label(struct node *tree, const char *label,
313 struct node **node, struct property **prop)
314{
315 struct marker *m;
316 struct property *p;
317 struct node *c;
318
319 *node = tree;
320
321 for_each_property(tree, p) {
322 *prop = p;
323 m = p->val.markers;
324 for_each_marker_of_type(m, LABEL)
325 if (streq(m->ref, label))
326 return m;
327 }
328
329 for_each_child(tree, c) {
330 m = get_marker_label(c, label, node, prop);
331 if (m)
332 return m;
333 }
334
335 *prop = NULL;
336 *node = NULL;
337 return NULL;
338}
339
211struct node *get_subnode(struct node *node, const char *nodename) 340struct node *get_subnode(struct node *node, const char *nodename)
212{ 341{
213 struct node *child; 342 struct node *child;
@@ -245,11 +374,13 @@ struct node *get_node_by_path(struct node *tree, const char *path)
245struct node *get_node_by_label(struct node *tree, const char *label) 374struct node *get_node_by_label(struct node *tree, const char *label)
246{ 375{
247 struct node *child, *node; 376 struct node *child, *node;
377 struct label *l;
248 378
249 assert(label && (strlen(label) > 0)); 379 assert(label && (strlen(label) > 0));
250 380
251 if (tree->label && streq(tree->label, label)) 381 for_each_label(tree->labels, l)
252 return tree; 382 if (streq(l->label, label))
383 return tree;
253 384
254 for_each_child(tree, child) { 385 for_each_child(tree, child) {
255 node = get_node_by_label(child, label); 386 node = get_node_by_label(child, label);
@@ -293,16 +424,186 @@ cell_t get_node_phandle(struct node *root, struct node *node)
293 if ((node->phandle != 0) && (node->phandle != -1)) 424 if ((node->phandle != 0) && (node->phandle != -1))
294 return node->phandle; 425 return node->phandle;
295 426
296 assert(! get_property(node, "linux,phandle"));
297
298 while (get_node_by_phandle(root, phandle)) 427 while (get_node_by_phandle(root, phandle))
299 phandle++; 428 phandle++;
300 429
301 node->phandle = phandle; 430 node->phandle = phandle;
302 add_property(node, 431
303 build_property("linux,phandle", 432 if (!get_property(node, "linux,phandle")
304 data_append_cell(empty_data, phandle), 433 && (phandle_format & PHANDLE_LEGACY))
305 NULL)); 434 add_property(node,
435 build_property("linux,phandle",
436 data_append_cell(empty_data, phandle)));
437
438 if (!get_property(node, "phandle")
439 && (phandle_format & PHANDLE_EPAPR))
440 add_property(node,
441 build_property("phandle",
442 data_append_cell(empty_data, phandle)));
443
444 /* If the node *does* have a phandle property, we must
445 * be dealing with a self-referencing phandle, which will be
446 * fixed up momentarily in the caller */
306 447
307 return node->phandle; 448 return node->phandle;
308} 449}
450
451uint32_t guess_boot_cpuid(struct node *tree)
452{
453 struct node *cpus, *bootcpu;
454 struct property *reg;
455
456 cpus = get_node_by_path(tree, "/cpus");
457 if (!cpus)
458 return 0;
459
460
461 bootcpu = cpus->children;
462 if (!bootcpu)
463 return 0;
464
465 reg = get_property(bootcpu, "reg");
466 if (!reg || (reg->val.len != sizeof(uint32_t)))
467 return 0;
468
469 /* FIXME: Sanity check node? */
470
471 return propval_cell(reg);
472}
473
474static int cmp_reserve_info(const void *ax, const void *bx)
475{
476 const struct reserve_info *a, *b;
477
478 a = *((const struct reserve_info * const *)ax);
479 b = *((const struct reserve_info * const *)bx);
480
481 if (a->re.address < b->re.address)
482 return -1;
483 else if (a->re.address > b->re.address)
484 return 1;
485 else if (a->re.size < b->re.size)
486 return -1;
487 else if (a->re.size > b->re.size)
488 return 1;
489 else
490 return 0;
491}
492
493static void sort_reserve_entries(struct boot_info *bi)
494{
495 struct reserve_info *ri, **tbl;
496 int n = 0, i = 0;
497
498 for (ri = bi->reservelist;
499 ri;
500 ri = ri->next)
501 n++;
502
503 if (n == 0)
504 return;
505
506 tbl = xmalloc(n * sizeof(*tbl));
507
508 for (ri = bi->reservelist;
509 ri;
510 ri = ri->next)
511 tbl[i++] = ri;
512
513 qsort(tbl, n, sizeof(*tbl), cmp_reserve_info);
514
515 bi->reservelist = tbl[0];
516 for (i = 0; i < (n-1); i++)
517 tbl[i]->next = tbl[i+1];
518 tbl[n-1]->next = NULL;
519
520 free(tbl);
521}
522
523static int cmp_prop(const void *ax, const void *bx)
524{
525 const struct property *a, *b;
526
527 a = *((const struct property * const *)ax);
528 b = *((const struct property * const *)bx);
529
530 return strcmp(a->name, b->name);
531}
532
533static void sort_properties(struct node *node)
534{
535 int n = 0, i = 0;
536 struct property *prop, **tbl;
537
538 for_each_property(node, prop)
539 n++;
540
541 if (n == 0)
542 return;
543
544 tbl = xmalloc(n * sizeof(*tbl));
545
546 for_each_property(node, prop)
547 tbl[i++] = prop;
548
549 qsort(tbl, n, sizeof(*tbl), cmp_prop);
550
551 node->proplist = tbl[0];
552 for (i = 0; i < (n-1); i++)
553 tbl[i]->next = tbl[i+1];
554 tbl[n-1]->next = NULL;
555
556 free(tbl);
557}
558
559static int cmp_subnode(const void *ax, const void *bx)
560{
561 const struct node *a, *b;
562
563 a = *((const struct node * const *)ax);
564 b = *((const struct node * const *)bx);
565
566 return strcmp(a->name, b->name);
567}
568
569static void sort_subnodes(struct node *node)
570{
571 int n = 0, i = 0;
572 struct node *subnode, **tbl;
573
574 for_each_child(node, subnode)
575 n++;
576
577 if (n == 0)
578 return;
579
580 tbl = xmalloc(n * sizeof(*tbl));
581
582 for_each_child(node, subnode)
583 tbl[i++] = subnode;
584
585 qsort(tbl, n, sizeof(*tbl), cmp_subnode);
586
587 node->children = tbl[0];
588 for (i = 0; i < (n-1); i++)
589 tbl[i]->next_sibling = tbl[i+1];
590 tbl[n-1]->next_sibling = NULL;
591
592 free(tbl);
593}
594
595static void sort_node(struct node *node)
596{
597 struct node *c;
598
599 sort_properties(node);
600 sort_subnodes(node);
601 for_each_child(node, c)
602 sort_node(c);
603}
604
605void sort_tree(struct boot_info *bi)
606{
607 sort_reserve_entries(bi);
608 sort_node(bi->dt);
609}
diff --git a/scripts/dtc/srcpos.c b/scripts/dtc/srcpos.c
index 9641b7628b4d..2dbc874288ca 100644
--- a/scripts/dtc/srcpos.c
+++ b/scripts/dtc/srcpos.c
@@ -17,100 +17,232 @@
17 * USA 17 * USA
18 */ 18 */
19 19
20#define _GNU_SOURCE
21
22#include <stdio.h>
23
20#include "dtc.h" 24#include "dtc.h"
21#include "srcpos.h" 25#include "srcpos.h"
22 26
23/*
24 * Like yylineno, this is the current open file pos.
25 */
26 27
27struct dtc_file *srcpos_file; 28static char *dirname(const char *path)
29{
30 const char *slash = strrchr(path, '/');
31
32 if (slash) {
33 int len = slash - path;
34 char *dir = xmalloc(len + 1);
35
36 memcpy(dir, path, len);
37 dir[len] = '\0';
38 return dir;
39 }
40 return NULL;
41}
42
43struct srcfile_state *current_srcfile; /* = NULL */
28 44
29static int dtc_open_one(struct dtc_file *file, 45/* Detect infinite include recursion. */
30 const char *search, 46#define MAX_SRCFILE_DEPTH (100)
31 const char *fname) 47static int srcfile_depth; /* = 0 */
48
49FILE *srcfile_relative_open(const char *fname, char **fullnamep)
32{ 50{
51 FILE *f;
33 char *fullname; 52 char *fullname;
34 53
35 if (search) { 54 if (streq(fname, "-")) {
36 fullname = xmalloc(strlen(search) + strlen(fname) + 2); 55 f = stdin;
37 56 fullname = xstrdup("<stdin>");
38 strcpy(fullname, search);
39 strcat(fullname, "/");
40 strcat(fullname, fname);
41 } else { 57 } else {
42 fullname = strdup(fname); 58 if (!current_srcfile || !current_srcfile->dir
59 || (fname[0] == '/'))
60 fullname = xstrdup(fname);
61 else
62 fullname = join_path(current_srcfile->dir, fname);
63
64 f = fopen(fullname, "r");
65 if (!f)
66 die("Couldn't open \"%s\": %s\n", fname,
67 strerror(errno));
43 } 68 }
44 69
45 file->file = fopen(fullname, "r"); 70 if (fullnamep)
46 if (!file->file) { 71 *fullnamep = fullname;
72 else
47 free(fullname); 73 free(fullname);
48 return 0;
49 }
50 74
51 file->name = fullname; 75 return f;
52 return 1;
53} 76}
54 77
78void srcfile_push(const char *fname)
79{
80 struct srcfile_state *srcfile;
81
82 if (srcfile_depth++ >= MAX_SRCFILE_DEPTH)
83 die("Includes nested too deeply");
84
85 srcfile = xmalloc(sizeof(*srcfile));
86
87 srcfile->f = srcfile_relative_open(fname, &srcfile->name);
88 srcfile->dir = dirname(srcfile->name);
89 srcfile->prev = current_srcfile;
90
91 srcfile->lineno = 1;
92 srcfile->colno = 1;
93
94 current_srcfile = srcfile;
95}
55 96
56struct dtc_file *dtc_open_file(const char *fname, 97int srcfile_pop(void)
57 const struct search_path *search)
58{ 98{
59 static const struct search_path default_search = { NULL, NULL, NULL }; 99 struct srcfile_state *srcfile = current_srcfile;
60 100
61 struct dtc_file *file; 101 assert(srcfile);
62 const char *slash;
63 102
64 file = xmalloc(sizeof(struct dtc_file)); 103 current_srcfile = srcfile->prev;
65 104
66 slash = strrchr(fname, '/'); 105 if (fclose(srcfile->f))
67 if (slash) { 106 die("Error closing \"%s\": %s\n", srcfile->name,
68 char *dir = xmalloc(slash - fname + 1); 107 strerror(errno));
69 108
70 memcpy(dir, fname, slash - fname); 109 /* FIXME: We allow the srcfile_state structure to leak,
71 dir[slash - fname] = 0; 110 * because it could still be referenced from a location
72 file->dir = dir; 111 * variable being carried through the parser somewhere. To
73 } else { 112 * fix this we could either allocate all the files from a
74 file->dir = NULL; 113 * table, or use a pool allocator. */
75 }
76 114
77 if (streq(fname, "-")) { 115 return current_srcfile ? 1 : 0;
78 file->name = "stdin"; 116}
79 file->file = stdin;
80 return file;
81 }
82 117
83 if (fname[0] == '/') { 118/*
84 file->file = fopen(fname, "r"); 119 * The empty source position.
85 if (!file->file) 120 */
86 goto fail;
87 121
88 file->name = strdup(fname); 122struct srcpos srcpos_empty = {
89 return file; 123 .first_line = 0,
90 } 124 .first_column = 0,
125 .last_line = 0,
126 .last_column = 0,
127 .file = NULL,
128};
91 129
92 if (!search) 130#define TAB_SIZE 8
93 search = &default_search;
94 131
95 while (search) { 132void srcpos_update(struct srcpos *pos, const char *text, int len)
96 if (dtc_open_one(file, search->dir, fname)) 133{
97 return file; 134 int i;
135
136 pos->file = current_srcfile;
137
138 pos->first_line = current_srcfile->lineno;
139 pos->first_column = current_srcfile->colno;
140
141 for (i = 0; i < len; i++)
142 if (text[i] == '\n') {
143 current_srcfile->lineno++;
144 current_srcfile->colno = 1;
145 } else if (text[i] == '\t') {
146 current_srcfile->colno =
147 ALIGN(current_srcfile->colno, TAB_SIZE);
148 } else {
149 current_srcfile->colno++;
150 }
151
152 pos->last_line = current_srcfile->lineno;
153 pos->last_column = current_srcfile->colno;
154}
98 155
99 if (errno != ENOENT) 156struct srcpos *
100 goto fail; 157srcpos_copy(struct srcpos *pos)
158{
159 struct srcpos *pos_new;
101 160
102 search = search->next; 161 pos_new = xmalloc(sizeof(struct srcpos));
103 } 162 memcpy(pos_new, pos, sizeof(struct srcpos));
163
164 return pos_new;
165}
166
167
168
169void
170srcpos_dump(struct srcpos *pos)
171{
172 printf("file : \"%s\"\n",
173 pos->file ? (char *) pos->file : "<no file>");
174 printf("first_line : %d\n", pos->first_line);
175 printf("first_column: %d\n", pos->first_column);
176 printf("last_line : %d\n", pos->last_line);
177 printf("last_column : %d\n", pos->last_column);
178 printf("file : %s\n", pos->file->name);
179}
104 180
105fail: 181
106 die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); 182char *
183srcpos_string(struct srcpos *pos)
184{
185 const char *fname = "<no-file>";
186 char *pos_str;
187 int rc;
188
189 if (pos)
190 fname = pos->file->name;
191
192
193 if (pos->first_line != pos->last_line)
194 rc = asprintf(&pos_str, "%s:%d.%d-%d.%d", fname,
195 pos->first_line, pos->first_column,
196 pos->last_line, pos->last_column);
197 else if (pos->first_column != pos->last_column)
198 rc = asprintf(&pos_str, "%s:%d.%d-%d", fname,
199 pos->first_line, pos->first_column,
200 pos->last_column);
201 else
202 rc = asprintf(&pos_str, "%s:%d.%d", fname,
203 pos->first_line, pos->first_column);
204
205 if (rc == -1)
206 die("Couldn't allocate in srcpos string");
207
208 return pos_str;
209}
210
211void
212srcpos_verror(struct srcpos *pos, char const *fmt, va_list va)
213{
214 const char *srcstr;
215
216 srcstr = srcpos_string(pos);
217
218 fprintf(stdout, "Error: %s ", srcstr);
219 vfprintf(stdout, fmt, va);
220 fprintf(stdout, "\n");
107} 221}
108 222
109void dtc_close_file(struct dtc_file *file) 223void
224srcpos_error(struct srcpos *pos, char const *fmt, ...)
110{ 225{
111 if (fclose(file->file)) 226 va_list va;
112 die("Error closing \"%s\": %s\n", file->name, strerror(errno)); 227
228 va_start(va, fmt);
229 srcpos_verror(pos, fmt, va);
230 va_end(va);
231}
232
233
234void
235srcpos_warn(struct srcpos *pos, char const *fmt, ...)
236{
237 const char *srcstr;
238 va_list va;
239 va_start(va, fmt);
240
241 srcstr = srcpos_string(pos);
242
243 fprintf(stderr, "Warning: %s ", srcstr);
244 vfprintf(stderr, fmt, va);
245 fprintf(stderr, "\n");
113 246
114 free(file->dir); 247 va_end(va);
115 free(file);
116} 248}
diff --git a/scripts/dtc/srcpos.h b/scripts/dtc/srcpos.h
index e17c7c04db8e..bd7966e56a53 100644
--- a/scripts/dtc/srcpos.h
+++ b/scripts/dtc/srcpos.h
@@ -17,69 +17,70 @@
17 * USA 17 * USA
18 */ 18 */
19 19
20/* 20#ifndef _SRCPOS_H_
21 * Augment the standard YYLTYPE with a filenum index into an 21#define _SRCPOS_H_
22 * array of all opened filenames.
23 */
24 22
25#include <stdio.h> 23#include <stdio.h>
26 24
27struct dtc_file { 25struct srcfile_state {
26 FILE *f;
27 char *name;
28 char *dir; 28 char *dir;
29 const char *name; 29 int lineno, colno;
30 FILE *file; 30 struct srcfile_state *prev;
31}; 31};
32 32
33#if ! defined(YYLTYPE) && ! defined(YYLTYPE_IS_DECLARED) 33extern struct srcfile_state *current_srcfile; /* = NULL */
34typedef struct YYLTYPE { 34
35FILE *srcfile_relative_open(const char *fname, char **fullnamep);
36void srcfile_push(const char *fname);
37int srcfile_pop(void);
38
39struct srcpos {
35 int first_line; 40 int first_line;
36 int first_column; 41 int first_column;
37 int last_line; 42 int last_line;
38 int last_column; 43 int last_column;
39 struct dtc_file *file; 44 struct srcfile_state *file;
40} YYLTYPE; 45};
41
42#define YYLTYPE_IS_DECLARED 1
43#define YYLTYPE_IS_TRIVIAL 1
44#endif
45
46/* Cater to old parser templates. */
47#ifndef YYID
48#define YYID(n) (n)
49#endif
50 46
51#define YYLLOC_DEFAULT(Current, Rhs, N) \ 47#define YYLTYPE struct srcpos
52 do \
53 if (YYID (N)) \
54 { \
55 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
56 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
57 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
58 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
59 (Current).file = YYRHSLOC (Rhs, N).file; \
60 } \
61 else \
62 { \
63 (Current).first_line = (Current).last_line = \
64 YYRHSLOC (Rhs, 0).last_line; \
65 (Current).first_column = (Current).last_column = \
66 YYRHSLOC (Rhs, 0).last_column; \
67 (Current).file = YYRHSLOC (Rhs, 0).file; \
68 } \
69 while (YYID (0))
70 48
49#define YYLLOC_DEFAULT(Current, Rhs, N) \
50 do { \
51 if (N) { \
52 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
53 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
54 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
55 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
56 (Current).file = YYRHSLOC(Rhs, N).file; \
57 } else { \
58 (Current).first_line = (Current).last_line = \
59 YYRHSLOC(Rhs, 0).last_line; \
60 (Current).first_column = (Current).last_column = \
61 YYRHSLOC(Rhs, 0).last_column; \
62 (Current).file = YYRHSLOC (Rhs, 0).file; \
63 } \
64 } while (0)
71 65
72 66
73extern void yyerror(char const *); 67/*
74extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2))); 68 * Fictional source position used for IR nodes that are
69 * created without otherwise knowing a true source position.
70 * For example,constant definitions from the command line.
71 */
72extern struct srcpos srcpos_empty;
75 73
76extern struct dtc_file *srcpos_file; 74extern void srcpos_update(struct srcpos *pos, const char *text, int len);
75extern struct srcpos *srcpos_copy(struct srcpos *pos);
76extern char *srcpos_string(struct srcpos *pos);
77extern void srcpos_dump(struct srcpos *pos);
77 78
78struct search_path { 79extern void srcpos_verror(struct srcpos *pos, char const *, va_list va)
79 const char *dir; /* NULL for current directory */ 80 __attribute__((format(printf, 2, 0)));
80 struct search_path *prev, *next; 81extern void srcpos_error(struct srcpos *pos, char const *, ...)
81}; 82 __attribute__((format(printf, 2, 3)));
83extern void srcpos_warn(struct srcpos *pos, char const *, ...)
84 __attribute__((format(printf, 2, 3)));
82 85
83extern struct dtc_file *dtc_open_file(const char *fname, 86#endif /* _SRCPOS_H_ */
84 const struct search_path *search);
85extern void dtc_close_file(struct dtc_file *file);
diff --git a/scripts/dtc/treesource.c b/scripts/dtc/treesource.c
index 1521ff11bb97..c09aafade313 100644
--- a/scripts/dtc/treesource.c
+++ b/scripts/dtc/treesource.c
@@ -32,8 +32,8 @@ struct boot_info *dt_from_source(const char *fname)
32 the_boot_info = NULL; 32 the_boot_info = NULL;
33 treesource_error = 0; 33 treesource_error = 0;
34 34
35 srcpos_file = dtc_open_file(fname, NULL); 35 srcfile_push(fname);
36 yyin = srcpos_file->file; 36 yyin = current_srcfile->f;
37 37
38 if (yyparse() != 0) 38 if (yyparse() != 0)
39 die("Unable to parse input tree\n"); 39 die("Unable to parse input tree\n");
@@ -63,26 +63,20 @@ static void write_propval_string(FILE *f, struct data val)
63{ 63{
64 const char *str = val.val; 64 const char *str = val.val;
65 int i; 65 int i;
66 int newchunk = 1;
67 struct marker *m = val.markers; 66 struct marker *m = val.markers;
68 67
69 assert(str[val.len-1] == '\0'); 68 assert(str[val.len-1] == '\0');
70 69
70 while (m && (m->offset == 0)) {
71 if (m->type == LABEL)
72 fprintf(f, "%s: ", m->ref);
73 m = m->next;
74 }
75 fprintf(f, "\"");
76
71 for (i = 0; i < (val.len-1); i++) { 77 for (i = 0; i < (val.len-1); i++) {
72 char c = str[i]; 78 char c = str[i];
73 79
74 if (newchunk) {
75 while (m && (m->offset <= i)) {
76 if (m->type == LABEL) {
77 assert(m->offset == i);
78 fprintf(f, "%s: ", m->ref);
79 }
80 m = m->next;
81 }
82 fprintf(f, "\"");
83 newchunk = 0;
84 }
85
86 switch (c) { 80 switch (c) {
87 case '\a': 81 case '\a':
88 fprintf(f, "\\a"); 82 fprintf(f, "\\a");
@@ -113,7 +107,14 @@ static void write_propval_string(FILE *f, struct data val)
113 break; 107 break;
114 case '\0': 108 case '\0':
115 fprintf(f, "\", "); 109 fprintf(f, "\", ");
116 newchunk = 1; 110 while (m && (m->offset < i)) {
111 if (m->type == LABEL) {
112 assert(m->offset == (i+1));
113 fprintf(f, "%s: ", m->ref);
114 }
115 m = m->next;
116 }
117 fprintf(f, "\"");
117 break; 118 break;
118 default: 119 default:
119 if (isprint(c)) 120 if (isprint(c))
@@ -234,10 +235,11 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
234{ 235{
235 struct property *prop; 236 struct property *prop;
236 struct node *child; 237 struct node *child;
238 struct label *l;
237 239
238 write_prefix(f, level); 240 write_prefix(f, level);
239 if (tree->label) 241 for_each_label(tree->labels, l)
240 fprintf(f, "%s: ", tree->label); 242 fprintf(f, "%s: ", l->label);
241 if (tree->name && (*tree->name)) 243 if (tree->name && (*tree->name))
242 fprintf(f, "%s {\n", tree->name); 244 fprintf(f, "%s {\n", tree->name);
243 else 245 else
@@ -245,8 +247,8 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
245 247
246 for_each_property(tree, prop) { 248 for_each_property(tree, prop) {
247 write_prefix(f, level+1); 249 write_prefix(f, level+1);
248 if (prop->label) 250 for_each_label(prop->labels, l)
249 fprintf(f, "%s: ", prop->label); 251 fprintf(f, "%s: ", l->label);
250 fprintf(f, "%s", prop->name); 252 fprintf(f, "%s", prop->name);
251 write_propval(f, prop); 253 write_propval(f, prop);
252 } 254 }
@@ -266,8 +268,10 @@ void dt_to_source(FILE *f, struct boot_info *bi)
266 fprintf(f, "/dts-v1/;\n\n"); 268 fprintf(f, "/dts-v1/;\n\n");
267 269
268 for (re = bi->reservelist; re; re = re->next) { 270 for (re = bi->reservelist; re; re = re->next) {
269 if (re->label) 271 struct label *l;
270 fprintf(f, "%s: ", re->label); 272
273 for_each_label(re->labels, l)
274 fprintf(f, "%s: ", l->label);
271 fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n", 275 fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n",
272 (unsigned long long)re->re.address, 276 (unsigned long long)re->re.address,
273 (unsigned long long)re->re.size); 277 (unsigned long long)re->re.size);
diff --git a/scripts/dtc/util.c b/scripts/dtc/util.c
new file mode 100644
index 000000000000..d7ac27d2ae15
--- /dev/null
+++ b/scripts/dtc/util.c
@@ -0,0 +1,59 @@
1/*
2 * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 * USA
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <stdarg.h>
23#include <string.h>
24
25#include "util.h"
26
27char *xstrdup(const char *s)
28{
29 int len = strlen(s) + 1;
30 char *dup = xmalloc(len);
31
32 memcpy(dup, s, len);
33
34 return dup;
35}
36
37char *join_path(const char *path, const char *name)
38{
39 int lenp = strlen(path);
40 int lenn = strlen(name);
41 int len;
42 int needslash = 1;
43 char *str;
44
45 len = lenp + lenn + 2;
46 if ((lenp > 0) && (path[lenp-1] == '/')) {
47 needslash = 0;
48 len--;
49 }
50
51 str = xmalloc(len);
52 memcpy(str, path, lenp);
53 if (needslash) {
54 str[lenp] = '/';
55 lenp++;
56 }
57 memcpy(str+lenp, name, lenn+1);
58 return str;
59}
diff --git a/scripts/dtc/util.h b/scripts/dtc/util.h
new file mode 100644
index 000000000000..9cead842c11e
--- /dev/null
+++ b/scripts/dtc/util.h
@@ -0,0 +1,56 @@
1#ifndef _UTIL_H
2#define _UTIL_H
3
4/*
5 * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22
23static inline void __attribute__((noreturn)) die(char * str, ...)
24{
25 va_list ap;
26
27 va_start(ap, str);
28 fprintf(stderr, "FATAL ERROR: ");
29 vfprintf(stderr, str, ap);
30 exit(1);
31}
32
33static inline void *xmalloc(size_t len)
34{
35 void *new = malloc(len);
36
37 if (!new)
38 die("malloc() failed\n");
39
40 return new;
41}
42
43static inline void *xrealloc(void *p, size_t len)
44{
45 void *new = realloc(p, len);
46
47 if (!new)
48 die("realloc() failed (len=%d)\n", len);
49
50 return new;
51}
52
53extern char *xstrdup(const char *s);
54extern char *join_path(const char *path, const char *name);
55
56#endif /* _UTIL_H */
diff --git a/scripts/dtc/version_gen.h b/scripts/dtc/version_gen.h
index 658ff42429d6..6158b867df99 100644
--- a/scripts/dtc/version_gen.h
+++ b/scripts/dtc/version_gen.h
@@ -1 +1 @@
#define DTC_VERSION "DTC 1.2.0" #define DTC_VERSION "DTC 1.2.0-g37c0b6a0"