1 /* SPDX-License-Identifier: GPL-2.0-or-later * << 2 /* 1 /* 3 * (C) Copyright David Gibson <dwg@au1.ibm.com> 2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. >> 3 * >> 4 * >> 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. >> 9 * >> 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. >> 14 * >> 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 >> 18 * USA 4 */ 19 */ 5 20 6 %option noyywrap nounput noinput never-interac 21 %option noyywrap nounput noinput never-interactive 7 22 >> 23 %x INCLUDE 8 %x BYTESTRING 24 %x BYTESTRING 9 %x PROPNODENAME 25 %x PROPNODENAME 10 %s V1 26 %s V1 11 27 12 PROPNODECHAR [a-zA-Z0-9,._+*#?@-] 28 PROPNODECHAR [a-zA-Z0-9,._+*#?@-] 13 PATHCHAR ({PROPNODECHAR}|[/]) 29 PATHCHAR ({PROPNODECHAR}|[/]) 14 LABEL [a-zA-Z_][a-zA-Z0-9_]* 30 LABEL [a-zA-Z_][a-zA-Z0-9_]* 15 STRING \"([^\\"]|\\.)*\" 31 STRING \"([^\\"]|\\.)*\" 16 CHAR_LITERAL '([^']|\\')*' 32 CHAR_LITERAL '([^']|\\')*' 17 WS [[:space:]] 33 WS [[:space:]] 18 COMMENT "/*"([^*]|\*+[^*/])*\*+"/" 34 COMMENT "/*"([^*]|\*+[^*/])*\*+"/" 19 LINECOMMENT "//".*\n 35 LINECOMMENT "//".*\n 20 36 21 %{ 37 %{ 22 #include "dtc.h" 38 #include "dtc.h" 23 #include "srcpos.h" 39 #include "srcpos.h" 24 #include "dtc-parser.tab.h" 40 #include "dtc-parser.tab.h" 25 41 26 extern bool treesource_error; !! 42 YYLTYPE yylloc; 27 43 28 /* CAUTION: this will stop working if we ever 44 /* CAUTION: this will stop working if we ever use yyless() or yyunput() */ 29 #define YY_USER_ACTION \ 45 #define YY_USER_ACTION \ 30 { \ 46 { \ 31 srcpos_update(&yylloc, yytext, 47 srcpos_update(&yylloc, yytext, yyleng); \ 32 } 48 } 33 49 34 /*#define LEXDEBUG 1*/ 50 /*#define LEXDEBUG 1*/ 35 51 36 #ifdef LEXDEBUG 52 #ifdef LEXDEBUG 37 #define DPRINT(fmt, ...) fprintf(stderr 53 #define DPRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) 38 #else 54 #else 39 #define DPRINT(fmt, ...) do { } while ( 55 #define DPRINT(fmt, ...) do { } while (0) 40 #endif 56 #endif 41 57 42 static int dts_version = 1; 58 static int dts_version = 1; 43 59 44 #define BEGIN_DEFAULT() DPRINT("<V1>\n 60 #define BEGIN_DEFAULT() DPRINT("<V1>\n"); \ 45 BEGIN(V1); \ 61 BEGIN(V1); \ 46 62 47 static void push_input_file(const char *filena 63 static void push_input_file(const char *filename); 48 static bool pop_input_file(void); !! 64 static int pop_input_file(void); 49 static void PRINTF(1, 2) lexical_error(const c << 50 << 51 %} 65 %} 52 66 53 %% 67 %% 54 <*>"/include/"{WS}*{STRING} { 68 <*>"/include/"{WS}*{STRING} { 55 char *name = strchr(yy 69 char *name = strchr(yytext, '\"') + 1; 56 yytext[yyleng-1] = '\0 70 yytext[yyleng-1] = '\0'; 57 push_input_file(name); 71 push_input_file(name); 58 } 72 } 59 73 60 <*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t] !! 74 <*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? { 61 char *line, *fnstart, !! 75 char *line, *tmp, *fn; 62 struct data fn; << 63 /* skip text before li 76 /* skip text before line # */ 64 line = yytext; 77 line = yytext; 65 while (!isdigit((unsig !! 78 while (!isdigit(*line)) 66 line++; 79 line++; 67 !! 80 /* skip digits in line # */ 68 /* regexp ensures that !! 81 tmp = line; 69 * in the whole yytext !! 82 while (!isspace(*tmp)) 70 * beginning and end o !! 83 tmp++; 71 fnstart = memchr(yytex !! 84 /* "NULL"-terminate line # */ 72 for (fnend = yytext + !! 85 *tmp = '\0'; 73 *fnend != '"'; fn !! 86 /* start of filename */ 74 ; !! 87 fn = strchr(tmp + 1, '"') + 1; 75 assert(fnstart && fnen !! 88 /* strip trailing " from filename */ 76 !! 89 tmp = strchr(fn, '"'); 77 fn = data_copy_escape_ !! 90 *tmp = 0; 78 << 79 << 80 /* Don't allow nuls in << 81 if (memchr(fn.val, '\0 << 82 lexical_error( << 83 << 84 /* -1 since #line is t 91 /* -1 since #line is the number of the next line */ 85 srcpos_set_line(xstrdu !! 92 srcpos_set_line(xstrdup(fn), atoi(line) - 1); 86 data_free(fn); << 87 } 93 } 88 94 89 <*><<EOF>> { 95 <*><<EOF>> { 90 if (!pop_input_file()) 96 if (!pop_input_file()) { 91 yyterminate(); 97 yyterminate(); 92 } 98 } 93 } 99 } 94 100 95 <*>{STRING} { 101 <*>{STRING} { 96 DPRINT("String: %s\n", 102 DPRINT("String: %s\n", yytext); 97 yylval.data = data_cop 103 yylval.data = data_copy_escape_string(yytext+1, 98 yyleng 104 yyleng-2); 99 return DT_STRING; 105 return DT_STRING; 100 } 106 } 101 107 102 <*>"/dts-v1/" { 108 <*>"/dts-v1/" { 103 DPRINT("Keyword: /dts- 109 DPRINT("Keyword: /dts-v1/\n"); 104 dts_version = 1; 110 dts_version = 1; 105 BEGIN_DEFAULT(); 111 BEGIN_DEFAULT(); 106 return DT_V1; 112 return DT_V1; 107 } 113 } 108 114 109 <*>"/plugin/" { << 110 DPRINT("Keyword: /plug << 111 return DT_PLUGIN; << 112 } << 113 << 114 <*>"/memreserve/" { 115 <*>"/memreserve/" { 115 DPRINT("Keyword: /memr 116 DPRINT("Keyword: /memreserve/\n"); 116 BEGIN_DEFAULT(); 117 BEGIN_DEFAULT(); 117 return DT_MEMRESERVE; 118 return DT_MEMRESERVE; 118 } 119 } 119 120 120 <*>"/bits/" { 121 <*>"/bits/" { 121 DPRINT("Keyword: /bits 122 DPRINT("Keyword: /bits/\n"); 122 BEGIN_DEFAULT(); 123 BEGIN_DEFAULT(); 123 return DT_BITS; 124 return DT_BITS; 124 } 125 } 125 126 126 <*>"/delete-property/" { 127 <*>"/delete-property/" { 127 DPRINT("Keyword: /dele 128 DPRINT("Keyword: /delete-property/\n"); 128 DPRINT("<PROPNODENAME> 129 DPRINT("<PROPNODENAME>\n"); 129 BEGIN(PROPNODENAME); 130 BEGIN(PROPNODENAME); 130 return DT_DEL_PROP; 131 return DT_DEL_PROP; 131 } 132 } 132 133 133 <*>"/delete-node/" { 134 <*>"/delete-node/" { 134 DPRINT("Keyword: /dele 135 DPRINT("Keyword: /delete-node/\n"); 135 DPRINT("<PROPNODENAME> 136 DPRINT("<PROPNODENAME>\n"); 136 BEGIN(PROPNODENAME); 137 BEGIN(PROPNODENAME); 137 return DT_DEL_NODE; 138 return DT_DEL_NODE; 138 } 139 } 139 140 140 <*>"/omit-if-no-ref/" { << 141 DPRINT("Keyword: /omit << 142 DPRINT("<PROPNODENAME> << 143 BEGIN(PROPNODENAME); << 144 return DT_OMIT_NO_REF; << 145 } << 146 << 147 <*>{LABEL}: { 141 <*>{LABEL}: { 148 DPRINT("Label: %s\n", 142 DPRINT("Label: %s\n", yytext); 149 yylval.labelref = xstr 143 yylval.labelref = xstrdup(yytext); 150 yylval.labelref[yyleng 144 yylval.labelref[yyleng-1] = '\0'; 151 return DT_LABEL; 145 return DT_LABEL; 152 } 146 } 153 147 154 <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? 148 <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? { 155 char *e; !! 149 yylval.literal = xstrdup(yytext); 156 DPRINT("Integer Litera !! 150 DPRINT("Literal: '%s'\n", yylval.literal); 157 << 158 errno = 0; << 159 yylval.integer = strto << 160 << 161 if (*e && e[strspn(e, << 162 lexical_error( << 163 << 164 } << 165 << 166 if (errno == ERANGE) << 167 lexical_error( << 168 << 169 else << 170 /* ERANGE is t << 171 * by strings << 172 assert(errno = << 173 return DT_LITERAL; 151 return DT_LITERAL; 174 } 152 } 175 153 176 <*>{CHAR_LITERAL} { 154 <*>{CHAR_LITERAL} { 177 struct data d; !! 155 yytext[yyleng-1] = '\0'; 178 DPRINT("Character lite !! 156 yylval.literal = xstrdup(yytext+1); 179 !! 157 DPRINT("Character literal: %s\n", yylval.literal); 180 d = data_copy_escape_s << 181 if (d.len == 1) { << 182 lexical_error( << 183 yylval.integer << 184 } else { << 185 yylval.integer << 186 << 187 if (d.len > 2) << 188 lexica << 189 << 190 << 191 } << 192 << 193 data_free(d); << 194 return DT_CHAR_LITERAL 158 return DT_CHAR_LITERAL; 195 } 159 } 196 160 197 <*>\&{LABEL} { /* label reference */ 161 <*>\&{LABEL} { /* label reference */ 198 DPRINT("Ref: %s\n", yy 162 DPRINT("Ref: %s\n", yytext+1); 199 yylval.labelref = xstr 163 yylval.labelref = xstrdup(yytext+1); 200 return DT_LABEL_REF; !! 164 return DT_REF; 201 } 165 } 202 166 203 <*>"&{"{PATHCHAR}*\} { /* new-style p !! 167 <*>"&{/"{PATHCHAR}+\} { /* new-style path reference */ 204 yytext[yyleng-1] = '\0 168 yytext[yyleng-1] = '\0'; 205 DPRINT("Ref: %s\n", yy 169 DPRINT("Ref: %s\n", yytext+2); 206 yylval.labelref = xstr 170 yylval.labelref = xstrdup(yytext+2); 207 return DT_PATH_REF; !! 171 return DT_REF; 208 } 172 } 209 173 210 <BYTESTRING>[0-9a-fA-F]{2} { 174 <BYTESTRING>[0-9a-fA-F]{2} { 211 yylval.byte = strtol(y 175 yylval.byte = strtol(yytext, NULL, 16); 212 DPRINT("Byte: %02x\n", 176 DPRINT("Byte: %02x\n", (int)yylval.byte); 213 return DT_BYTE; 177 return DT_BYTE; 214 } 178 } 215 179 216 <BYTESTRING>"]" { 180 <BYTESTRING>"]" { 217 DPRINT("/BYTESTRING\n" 181 DPRINT("/BYTESTRING\n"); 218 BEGIN_DEFAULT(); 182 BEGIN_DEFAULT(); 219 return ']'; 183 return ']'; 220 } 184 } 221 185 222 <PROPNODENAME>\\?{PROPNODECHAR}+ { 186 <PROPNODENAME>\\?{PROPNODECHAR}+ { 223 DPRINT("PropNodeName: 187 DPRINT("PropNodeName: %s\n", yytext); 224 yylval.propnodename = 188 yylval.propnodename = xstrdup((yytext[0] == '\\') ? 225 189 yytext + 1 : yytext); 226 BEGIN_DEFAULT(); 190 BEGIN_DEFAULT(); 227 return DT_PROPNODENAME 191 return DT_PROPNODENAME; 228 } 192 } 229 193 230 "/incbin/" { 194 "/incbin/" { 231 DPRINT("Binary Include 195 DPRINT("Binary Include\n"); 232 return DT_INCBIN; 196 return DT_INCBIN; 233 } 197 } 234 198 235 <*>{WS}+ /* eat whitespace */ 199 <*>{WS}+ /* eat whitespace */ 236 <*>{COMMENT}+ /* eat C-style comments */ 200 <*>{COMMENT}+ /* eat C-style comments */ 237 <*>{LINECOMMENT}+ /* eat C++-style comments */ 201 <*>{LINECOMMENT}+ /* eat C++-style comments */ 238 202 239 <*>"<<" { return DT_LSHIFT; }; 203 <*>"<<" { return DT_LSHIFT; }; 240 <*>">>" { return DT_RSHIFT; }; 204 <*>">>" { return DT_RSHIFT; }; 241 <*>"<=" { return DT_LE; }; 205 <*>"<=" { return DT_LE; }; 242 <*>">=" { return DT_GE; }; 206 <*>">=" { return DT_GE; }; 243 <*>"==" { return DT_EQ; }; 207 <*>"==" { return DT_EQ; }; 244 <*>"!=" { return DT_NE; }; 208 <*>"!=" { return DT_NE; }; 245 <*>"&&" { return DT_AND; }; 209 <*>"&&" { return DT_AND; }; 246 <*>"||" { return DT_OR; }; 210 <*>"||" { return DT_OR; }; 247 211 248 <*>. { 212 <*>. { 249 DPRINT("Char: %c (\\x% 213 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 250 (unsigned)yyte 214 (unsigned)yytext[0]); 251 if (yytext[0] == '[') 215 if (yytext[0] == '[') { 252 DPRINT("<BYTES 216 DPRINT("<BYTESTRING>\n"); 253 BEGIN(BYTESTRI 217 BEGIN(BYTESTRING); 254 } 218 } 255 if ((yytext[0] == '{') 219 if ((yytext[0] == '{') 256 || (yytext[0] == ' 220 || (yytext[0] == ';')) { 257 DPRINT("<PROPN 221 DPRINT("<PROPNODENAME>\n"); 258 BEGIN(PROPNODE 222 BEGIN(PROPNODENAME); 259 } 223 } 260 return yytext[0]; 224 return yytext[0]; 261 } 225 } 262 226 263 %% 227 %% 264 228 265 static void push_input_file(const char *filena 229 static void push_input_file(const char *filename) 266 { 230 { 267 assert(filename); 231 assert(filename); 268 232 269 srcfile_push(filename); 233 srcfile_push(filename); 270 234 271 yyin = current_srcfile->f; 235 yyin = current_srcfile->f; 272 236 273 yypush_buffer_state(yy_create_buffer(y 237 yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE)); 274 } 238 } 275 239 276 240 277 static bool pop_input_file(void) !! 241 static int pop_input_file(void) 278 { 242 { 279 if (srcfile_pop() == 0) 243 if (srcfile_pop() == 0) 280 return false; !! 244 return 0; 281 245 282 yypop_buffer_state(); 246 yypop_buffer_state(); 283 yyin = current_srcfile->f; 247 yyin = current_srcfile->f; 284 248 285 return true; !! 249 return 1; 286 } << 287 << 288 static void lexical_error(const char *fmt, ... << 289 { << 290 va_list ap; << 291 << 292 va_start(ap, fmt); << 293 srcpos_verror(&yylloc, "Lexical error" << 294 va_end(ap); << 295 << 296 treesource_error = true; << 297 } 250 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.