2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 %option noyywrap nounput noinput never-interactive
28 PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
29 PATHCHAR ({PROPNODECHAR}|[/])
30 LABEL [a-zA-Z_][a-zA-Z0-9_]*
31 STRING \"([^\\"]|\\.)*\"
32 CHAR_LITERAL '([^']|\\')*'
34 COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
40 #include "dtc-parser.tab.h"
42 #define MAX_INCLUDE_NESTING 100
43 YY_BUFFER_STATE include_stack[MAX_INCLUDE_NESTING];
44 int include_stack_pointer = 0;
48 /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
49 #define YY_USER_ACTION \
51 srcpos_update(&yylloc, yytext, yyleng); \
54 /*#define LEXDEBUG 1*/
57 #define DPRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
59 #define DPRINT(fmt, ...) do { } while (0)
62 static int dts_version = 1;
64 #define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
67 static void push_input_file(const char *filename);
68 static int pop_input_file(void);
72 <*>"/include/"{WS}*{STRING} {
73 char *name = strchr(yytext, '\"') + 1;
74 yytext[yyleng-1] = '\0';
75 push_input_file(name);
79 if (!pop_input_file()) {
85 DPRINT("String: %s\n", yytext);
86 yylval.data = data_copy_escape_string(yytext+1,
92 DPRINT("Keyword: /dts-v1/\n");
99 DPRINT("Keyword: /memreserve/\n");
101 return DT_MEMRESERVE;
105 DPRINT("Keyword: /bits/\n");
111 DPRINT("Label: %s\n", yytext);
112 yylval.labelref = xstrdup(yytext);
113 yylval.labelref[yyleng-1] = '\0';
117 <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
118 yylval.literal = xstrdup(yytext);
119 DPRINT("Literal: '%s'\n", yylval.literal);
124 yytext[yyleng-1] = '\0';
125 yylval.literal = xstrdup(yytext+1);
126 DPRINT("Character literal: %s\n", yylval.literal);
127 return DT_CHAR_LITERAL;
130 <*>\&{LABEL} { /* label reference */
131 DPRINT("Ref: %s\n", yytext+1);
132 yylval.labelref = xstrdup(yytext+1);
136 <*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
137 yytext[yyleng-1] = '\0';
138 DPRINT("Ref: %s\n", yytext+2);
139 yylval.labelref = xstrdup(yytext+2);
143 <BYTESTRING>[0-9a-fA-F]{2} {
144 yylval.byte = strtol(yytext, NULL, 16);
145 DPRINT("Byte: %02x\n", (int)yylval.byte);
150 DPRINT("/BYTESTRING\n");
155 <PROPNODENAME>{PROPNODECHAR}+ {
156 DPRINT("PropNodeName: %s\n", yytext);
157 yylval.propnodename = xstrdup(yytext);
159 return DT_PROPNODENAME;
163 DPRINT("Binary Include\n");
167 <*>{WS}+ /* eat whitespace */
168 <*>{COMMENT}+ /* eat C-style comments */
169 <*>{LINECOMMENT}+ /* eat C++-style comments */
171 <*>"<<" { return DT_LSHIFT; };
172 <*>">>" { return DT_RSHIFT; };
173 <*>"<=" { return DT_LE; };
174 <*>">=" { return DT_GE; };
175 <*>"==" { return DT_EQ; };
176 <*>"!=" { return DT_NE; };
177 <*>"&&" { return DT_AND; };
178 <*>"||" { return DT_OR; };
181 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
182 (unsigned)yytext[0]);
183 if (yytext[0] == '[') {
184 DPRINT("<BYTESTRING>\n");
187 if ((yytext[0] == '{')
188 || (yytext[0] == ';')) {
189 DPRINT("<PROPNODENAME>\n");
197 static void push_input_file(const char *filename)
201 assert(include_stack_pointer < MAX_INCLUDE_NESTING);
203 srcfile_push(filename);
205 yyin = current_srcfile->f;
207 include_stack[include_stack_pointer++] = YY_CURRENT_BUFFER;
209 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
213 static int pop_input_file(void)
215 if (srcfile_pop() == 0)
218 assert(include_stack_pointer > 0);
220 yy_delete_buffer( YY_CURRENT_BUFFER );
222 yy_switch_to_buffer( include_stack[--include_stack_pointer] );
224 yyin = current_srcfile->f;