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 %locations << 6 << 7 %{ 20 %{ 8 #include <stdio.h> 21 #include <stdio.h> 9 #include <inttypes.h> 22 #include <inttypes.h> 10 23 11 #include "dtc.h" 24 #include "dtc.h" 12 #include "srcpos.h" 25 #include "srcpos.h" 13 26 14 extern int yylex(void); 27 extern int yylex(void); 15 extern void yyerror(char const *s); 28 extern void yyerror(char const *s); 16 #define ERROR(loc, ...) \ 29 #define ERROR(loc, ...) \ 17 do { \ 30 do { \ 18 srcpos_error((loc), "Error", _ 31 srcpos_error((loc), "Error", __VA_ARGS__); \ 19 treesource_error = true; \ 32 treesource_error = true; \ 20 } while (0) 33 } while (0) 21 34 22 #define YYERROR_CALL(msg) yyerror(msg) << 23 << 24 extern struct dt_info *parser_output; 35 extern struct dt_info *parser_output; 25 extern bool treesource_error; 36 extern bool treesource_error; 26 << 27 static bool is_ref_relative(const char *ref) << 28 { << 29 return ref[0] != '/' && strchr(&ref[1] << 30 } << 31 << 32 %} 37 %} 33 38 34 %union { 39 %union { 35 char *propnodename; 40 char *propnodename; 36 char *labelref; 41 char *labelref; 37 uint8_t byte; 42 uint8_t byte; 38 struct data data; 43 struct data data; 39 44 40 struct { 45 struct { 41 struct data data; 46 struct data data; 42 int bits; 47 int bits; 43 } array; 48 } array; 44 49 45 struct property *prop; 50 struct property *prop; 46 struct property *proplist; 51 struct property *proplist; 47 struct node *node; 52 struct node *node; 48 struct node *nodelist; 53 struct node *nodelist; 49 struct reserve_info *re; 54 struct reserve_info *re; 50 uint64_t integer; 55 uint64_t integer; 51 unsigned int flags; 56 unsigned int flags; 52 } 57 } 53 58 54 %token DT_V1 59 %token DT_V1 55 %token DT_PLUGIN 60 %token DT_PLUGIN 56 %token DT_MEMRESERVE 61 %token DT_MEMRESERVE 57 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ D 62 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR 58 %token DT_BITS 63 %token DT_BITS 59 %token DT_DEL_PROP 64 %token DT_DEL_PROP 60 %token DT_DEL_NODE 65 %token DT_DEL_NODE 61 %token DT_OMIT_NO_REF 66 %token DT_OMIT_NO_REF 62 %token <propnodename> DT_PROPNODENAME 67 %token <propnodename> DT_PROPNODENAME 63 %token <integer> DT_LITERAL 68 %token <integer> DT_LITERAL 64 %token <integer> DT_CHAR_LITERAL 69 %token <integer> DT_CHAR_LITERAL 65 %token <byte> DT_BYTE 70 %token <byte> DT_BYTE 66 %token <data> DT_STRING 71 %token <data> DT_STRING 67 %token <labelref> DT_LABEL 72 %token <labelref> DT_LABEL 68 %token <labelref> DT_LABEL_REF 73 %token <labelref> DT_LABEL_REF 69 %token <labelref> DT_PATH_REF 74 %token <labelref> DT_PATH_REF 70 %token DT_INCBIN 75 %token DT_INCBIN 71 76 72 %type <data> propdata 77 %type <data> propdata 73 %type <data> propdataprefix 78 %type <data> propdataprefix 74 %type <flags> header 79 %type <flags> header 75 %type <flags> headers 80 %type <flags> headers 76 %type <re> memreserve 81 %type <re> memreserve 77 %type <re> memreserves 82 %type <re> memreserves 78 %type <array> arrayprefix 83 %type <array> arrayprefix 79 %type <data> bytestring 84 %type <data> bytestring 80 %type <prop> propdef 85 %type <prop> propdef 81 %type <proplist> proplist 86 %type <proplist> proplist 82 %type <labelref> dt_ref 87 %type <labelref> dt_ref 83 88 84 %type <node> devicetree 89 %type <node> devicetree 85 %type <node> nodedef 90 %type <node> nodedef 86 %type <node> subnode 91 %type <node> subnode 87 %type <nodelist> subnodes 92 %type <nodelist> subnodes 88 93 89 %type <integer> integer_prim 94 %type <integer> integer_prim 90 %type <integer> integer_unary 95 %type <integer> integer_unary 91 %type <integer> integer_mul 96 %type <integer> integer_mul 92 %type <integer> integer_add 97 %type <integer> integer_add 93 %type <integer> integer_shift 98 %type <integer> integer_shift 94 %type <integer> integer_rela 99 %type <integer> integer_rela 95 %type <integer> integer_eq 100 %type <integer> integer_eq 96 %type <integer> integer_bitand 101 %type <integer> integer_bitand 97 %type <integer> integer_bitxor 102 %type <integer> integer_bitxor 98 %type <integer> integer_bitor 103 %type <integer> integer_bitor 99 %type <integer> integer_and 104 %type <integer> integer_and 100 %type <integer> integer_or 105 %type <integer> integer_or 101 %type <integer> integer_trinary 106 %type <integer> integer_trinary 102 %type <integer> integer_expr 107 %type <integer> integer_expr 103 108 104 %% 109 %% 105 110 106 sourcefile: 111 sourcefile: 107 headers memreserves devicetree 112 headers memreserves devicetree 108 { 113 { 109 parser_output = build_ 114 parser_output = build_dt_info($1, $2, $3, 110 115 guess_boot_cpuid($3)); 111 } 116 } 112 ; 117 ; 113 118 114 header: 119 header: 115 DT_V1 ';' 120 DT_V1 ';' 116 { 121 { 117 $$ = DTSF_V1; 122 $$ = DTSF_V1; 118 } 123 } 119 | DT_V1 ';' DT_PLUGIN ';' 124 | DT_V1 ';' DT_PLUGIN ';' 120 { 125 { 121 $$ = DTSF_V1 | DTSF_PL 126 $$ = DTSF_V1 | DTSF_PLUGIN; 122 } 127 } 123 ; 128 ; 124 129 125 headers: 130 headers: 126 header 131 header 127 | header headers 132 | header headers 128 { 133 { 129 if ($2 != $1) 134 if ($2 != $1) 130 ERROR(&@2, "He 135 ERROR(&@2, "Header flags don't match earlier ones"); 131 $$ = $1; 136 $$ = $1; 132 } 137 } 133 ; 138 ; 134 139 135 memreserves: 140 memreserves: 136 /* empty */ 141 /* empty */ 137 { 142 { 138 $$ = NULL; 143 $$ = NULL; 139 } 144 } 140 | memreserve memreserves 145 | memreserve memreserves 141 { 146 { 142 $$ = chain_reserve_ent 147 $$ = chain_reserve_entry($1, $2); 143 } 148 } 144 ; 149 ; 145 150 146 memreserve: 151 memreserve: 147 DT_MEMRESERVE integer_prim integer_p 152 DT_MEMRESERVE integer_prim integer_prim ';' 148 { 153 { 149 $$ = build_reserve_ent 154 $$ = build_reserve_entry($2, $3); 150 } 155 } 151 | DT_LABEL memreserve 156 | DT_LABEL memreserve 152 { 157 { 153 add_label(&$2->labels, 158 add_label(&$2->labels, $1); 154 $$ = $2; 159 $$ = $2; 155 } 160 } 156 ; 161 ; 157 162 158 dt_ref: DT_LABEL_REF | DT_PATH_REF; 163 dt_ref: DT_LABEL_REF | DT_PATH_REF; 159 164 160 devicetree: 165 devicetree: 161 '/' nodedef 166 '/' nodedef 162 { 167 { 163 $$ = name_node($2, "") 168 $$ = name_node($2, ""); 164 } 169 } 165 | devicetree '/' nodedef 170 | devicetree '/' nodedef 166 { 171 { 167 $$ = merge_nodes($1, $ 172 $$ = merge_nodes($1, $3); 168 } 173 } 169 | dt_ref nodedef 174 | dt_ref nodedef 170 { 175 { 171 /* 176 /* 172 * We rely on the rule 177 * We rely on the rule being always: 173 * versioninfo plugi 178 * versioninfo plugindecl memreserves devicetree 174 * so $-1 is what we w 179 * so $-1 is what we want (plugindecl) 175 */ 180 */ 176 if (!($<flags>-1 & DTS 181 if (!($<flags>-1 & DTSF_PLUGIN)) 177 ERROR(&@2, "La 182 ERROR(&@2, "Label or path %s not found", $1); 178 else if (is_ref_relati << 179 ERROR(&@2, "La << 180 $$ = add_orphan_node( 183 $$ = add_orphan_node( 181 name_n 184 name_node(build_node(NULL, NULL, NULL), 182 185 ""), 183 $2, $1 186 $2, $1); 184 } 187 } 185 | devicetree DT_LABEL dt_ref nodedef 188 | devicetree DT_LABEL dt_ref nodedef 186 { 189 { 187 struct node *target = 190 struct node *target = get_node_by_ref($1, $3); 188 191 189 if (($<flags>-1 & DTSF << 190 ERROR(&@2, "La << 191 << 192 if (target) { 192 if (target) { 193 add_label(&tar 193 add_label(&target->labels, $2); 194 merge_nodes(ta 194 merge_nodes(target, $4); 195 } else 195 } else 196 ERROR(&@3, "La 196 ERROR(&@3, "Label or path %s not found", $3); 197 $$ = $1; 197 $$ = $1; 198 } 198 } 199 | devicetree DT_PATH_REF nodedef 199 | devicetree DT_PATH_REF nodedef 200 { 200 { 201 /* 201 /* 202 * We rely on the rule 202 * We rely on the rule being always: 203 * versioninfo plugi 203 * versioninfo plugindecl memreserves devicetree 204 * so $-1 is what we w 204 * so $-1 is what we want (plugindecl) 205 */ 205 */ 206 if ($<flags>-1 & DTSF_ 206 if ($<flags>-1 & DTSF_PLUGIN) { 207 if (is_ref_rel << 208 ERROR( << 209 add_orphan_nod 207 add_orphan_node($1, $3, $2); 210 } else { 208 } else { 211 struct node *t 209 struct node *target = get_node_by_ref($1, $2); 212 210 213 if (target) 211 if (target) 214 merge_ 212 merge_nodes(target, $3); 215 else 213 else 216 ERROR( 214 ERROR(&@2, "Label or path %s not found", $2); 217 } 215 } 218 $$ = $1; 216 $$ = $1; 219 } 217 } 220 | devicetree DT_LABEL_REF nodedef 218 | devicetree DT_LABEL_REF nodedef 221 { 219 { 222 struct node *target = 220 struct node *target = get_node_by_ref($1, $2); 223 221 224 if (target) { 222 if (target) { 225 merge_nodes(ta 223 merge_nodes(target, $3); 226 } else { 224 } else { 227 /* 225 /* 228 * We rely on 226 * We rely on the rule being always: 229 * versionin 227 * versioninfo plugindecl memreserves devicetree 230 * so $-1 is w 228 * so $-1 is what we want (plugindecl) 231 */ 229 */ 232 if ($<flags>-1 230 if ($<flags>-1 & DTSF_PLUGIN) 233 add_or 231 add_orphan_node($1, $3, $2); 234 else 232 else 235 ERROR( 233 ERROR(&@2, "Label or path %s not found", $2); 236 } 234 } 237 $$ = $1; 235 $$ = $1; 238 } 236 } 239 | devicetree DT_DEL_NODE dt_ref ';' 237 | devicetree DT_DEL_NODE dt_ref ';' 240 { 238 { 241 struct node *target = 239 struct node *target = get_node_by_ref($1, $3); 242 240 243 if (target) 241 if (target) 244 delete_node(ta 242 delete_node(target); 245 else 243 else 246 ERROR(&@3, "La 244 ERROR(&@3, "Label or path %s not found", $3); 247 245 248 246 249 $$ = $1; 247 $$ = $1; 250 } 248 } 251 | devicetree DT_OMIT_NO_REF dt_ref ';' 249 | devicetree DT_OMIT_NO_REF dt_ref ';' 252 { 250 { 253 struct node *target = 251 struct node *target = get_node_by_ref($1, $3); 254 252 255 if (target) 253 if (target) 256 omit_node_if_u 254 omit_node_if_unused(target); 257 else 255 else 258 ERROR(&@3, "La 256 ERROR(&@3, "Label or path %s not found", $3); 259 257 260 258 261 $$ = $1; 259 $$ = $1; 262 } 260 } 263 ; 261 ; 264 262 265 nodedef: 263 nodedef: 266 '{' proplist subnodes '}' ';' 264 '{' proplist subnodes '}' ';' 267 { 265 { 268 $$ = build_node($2, $3 266 $$ = build_node($2, $3, &@$); 269 } 267 } 270 ; 268 ; 271 269 272 proplist: 270 proplist: 273 /* empty */ 271 /* empty */ 274 { 272 { 275 $$ = NULL; 273 $$ = NULL; 276 } 274 } 277 | proplist propdef 275 | proplist propdef 278 { 276 { 279 $$ = chain_property($2 277 $$ = chain_property($2, $1); 280 } 278 } 281 ; 279 ; 282 280 283 propdef: 281 propdef: 284 DT_PROPNODENAME '=' propdata ';' 282 DT_PROPNODENAME '=' propdata ';' 285 { 283 { 286 $$ = build_property($1 284 $$ = build_property($1, $3, &@$); 287 free($1); << 288 } 285 } 289 | DT_PROPNODENAME ';' 286 | DT_PROPNODENAME ';' 290 { 287 { 291 $$ = build_property($1 288 $$ = build_property($1, empty_data, &@$); 292 free($1); << 293 } 289 } 294 | DT_DEL_PROP DT_PROPNODENAME ';' 290 | DT_DEL_PROP DT_PROPNODENAME ';' 295 { 291 { 296 $$ = build_property_de 292 $$ = build_property_delete($2); 297 free($2); << 298 } 293 } 299 | DT_LABEL propdef 294 | DT_LABEL propdef 300 { 295 { 301 add_label(&$2->labels, 296 add_label(&$2->labels, $1); 302 $$ = $2; 297 $$ = $2; 303 } 298 } 304 ; 299 ; 305 300 306 propdata: 301 propdata: 307 propdataprefix DT_STRING 302 propdataprefix DT_STRING 308 { 303 { 309 $$ = data_merge($1, $2 304 $$ = data_merge($1, $2); 310 } 305 } 311 | propdataprefix arrayprefix '>' 306 | propdataprefix arrayprefix '>' 312 { 307 { 313 $$ = data_merge($1, $2 308 $$ = data_merge($1, $2.data); 314 } 309 } 315 | propdataprefix '[' bytestring ']' 310 | propdataprefix '[' bytestring ']' 316 { 311 { 317 $$ = data_merge($1, $3 312 $$ = data_merge($1, $3); 318 } 313 } 319 | propdataprefix dt_ref 314 | propdataprefix dt_ref 320 { 315 { 321 $1 = data_add_marker($ 316 $1 = data_add_marker($1, TYPE_STRING, $2); 322 $$ = data_add_marker($ 317 $$ = data_add_marker($1, REF_PATH, $2); 323 } 318 } 324 | propdataprefix DT_INCBIN '(' DT_STRI 319 | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' 325 { 320 { 326 FILE *f = srcfile_rela 321 FILE *f = srcfile_relative_open($4.val, NULL); 327 struct data d; 322 struct data d; 328 323 329 if ($6 != 0) 324 if ($6 != 0) 330 if (fseek(f, $ 325 if (fseek(f, $6, SEEK_SET) != 0) 331 die("C 326 die("Couldn't seek to offset %llu in \"%s\": %s", 332 (u 327 (unsigned long long)$6, $4.val, 333 st 328 strerror(errno)); 334 329 335 d = data_copy_file(f, 330 d = data_copy_file(f, $8); 336 331 337 $$ = data_merge($1, d) 332 $$ = data_merge($1, d); 338 fclose(f); 333 fclose(f); 339 } 334 } 340 | propdataprefix DT_INCBIN '(' DT_STRI 335 | propdataprefix DT_INCBIN '(' DT_STRING ')' 341 { 336 { 342 FILE *f = srcfile_rela 337 FILE *f = srcfile_relative_open($4.val, NULL); 343 struct data d = empty_ 338 struct data d = empty_data; 344 339 345 d = data_copy_file(f, 340 d = data_copy_file(f, -1); 346 341 347 $$ = data_merge($1, d) 342 $$ = data_merge($1, d); 348 fclose(f); 343 fclose(f); 349 } 344 } 350 | propdata DT_LABEL 345 | propdata DT_LABEL 351 { 346 { 352 $$ = data_add_marker($ 347 $$ = data_add_marker($1, LABEL, $2); 353 } 348 } 354 ; 349 ; 355 350 356 propdataprefix: 351 propdataprefix: 357 /* empty */ 352 /* empty */ 358 { 353 { 359 $$ = empty_data; 354 $$ = empty_data; 360 } 355 } 361 | propdata ',' 356 | propdata ',' 362 { 357 { 363 $$ = $1; 358 $$ = $1; 364 } 359 } 365 | propdataprefix DT_LABEL 360 | propdataprefix DT_LABEL 366 { 361 { 367 $$ = data_add_marker($ 362 $$ = data_add_marker($1, LABEL, $2); 368 } 363 } 369 ; 364 ; 370 365 371 arrayprefix: 366 arrayprefix: 372 DT_BITS DT_LITERAL '<' 367 DT_BITS DT_LITERAL '<' 373 { 368 { 374 unsigned long long bit 369 unsigned long long bits; 375 enum markertype type = 370 enum markertype type = TYPE_UINT32; 376 371 377 bits = $2; 372 bits = $2; 378 373 379 switch (bits) { 374 switch (bits) { 380 case 8: type = TYPE_UI 375 case 8: type = TYPE_UINT8; break; 381 case 16: type = TYPE_U 376 case 16: type = TYPE_UINT16; break; 382 case 32: type = TYPE_U 377 case 32: type = TYPE_UINT32; break; 383 case 64: type = TYPE_U 378 case 64: type = TYPE_UINT64; break; 384 default: 379 default: 385 ERROR(&@2, "Ar 380 ERROR(&@2, "Array elements must be" 386 " 8, 16, 381 " 8, 16, 32 or 64-bits"); 387 bits = 32; 382 bits = 32; 388 } 383 } 389 384 390 $$.data = data_add_mar 385 $$.data = data_add_marker(empty_data, type, NULL); 391 $$.bits = bits; 386 $$.bits = bits; 392 } 387 } 393 | '<' 388 | '<' 394 { 389 { 395 $$.data = data_add_mar 390 $$.data = data_add_marker(empty_data, TYPE_UINT32, NULL); 396 $$.bits = 32; 391 $$.bits = 32; 397 } 392 } 398 | arrayprefix integer_prim 393 | arrayprefix integer_prim 399 { 394 { 400 if ($1.bits < 64) { 395 if ($1.bits < 64) { 401 uint64_t mask 396 uint64_t mask = (1ULL << $1.bits) - 1; 402 /* 397 /* 403 * Bits above 398 * Bits above mask must either be all zero 404 * (positive w 399 * (positive within range of mask) or all one 405 * (negative a 400 * (negative and sign-extended). The second 406 * condition i 401 * condition is true if when we set all bits 407 * within the 402 * within the mask to one (i.e. | in the 408 * mask), all 403 * mask), all bits are one. 409 */ 404 */ 410 if (($2 > mask !! 405 if (($2 > mask) && (($2 | mask) != -1ULL)) 411 char * !! 406 ERROR(&@2, "Value out of range for" 412 fprint !! 407 " %d-bit array element", $1.bits); 413 << 414 << 415 << 416 free(l << 417 } << 418 } 408 } 419 409 420 $$.data = data_append_ 410 $$.data = data_append_integer($1.data, $2, $1.bits); 421 } 411 } 422 | arrayprefix dt_ref 412 | arrayprefix dt_ref 423 { 413 { 424 uint64_t val = ~0ULL > 414 uint64_t val = ~0ULL >> (64 - $1.bits); 425 415 426 if ($1.bits == 32) 416 if ($1.bits == 32) 427 $1.data = data 417 $1.data = data_add_marker($1.data, 428 418 REF_PHANDLE, 429 419 $2); 430 else 420 else 431 ERROR(&@2, "Re 421 ERROR(&@2, "References are only allowed in " 432 "a 422 "arrays with 32-bit elements."); 433 423 434 $$.data = data_append_ 424 $$.data = data_append_integer($1.data, val, $1.bits); 435 } 425 } 436 | arrayprefix DT_LABEL 426 | arrayprefix DT_LABEL 437 { 427 { 438 $$.data = data_add_mar 428 $$.data = data_add_marker($1.data, LABEL, $2); 439 } 429 } 440 ; 430 ; 441 431 442 integer_prim: 432 integer_prim: 443 DT_LITERAL 433 DT_LITERAL 444 | DT_CHAR_LITERAL 434 | DT_CHAR_LITERAL 445 | '(' integer_expr ')' 435 | '(' integer_expr ')' 446 { 436 { 447 $$ = $2; 437 $$ = $2; 448 } 438 } 449 ; 439 ; 450 440 451 integer_expr: 441 integer_expr: 452 integer_trinary 442 integer_trinary 453 ; 443 ; 454 444 455 integer_trinary: 445 integer_trinary: 456 integer_or 446 integer_or 457 | integer_or '?' integer_expr ':' inte 447 | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; } 458 ; 448 ; 459 449 460 integer_or: 450 integer_or: 461 integer_and 451 integer_and 462 | integer_or DT_OR integer_and { $$ = 452 | integer_or DT_OR integer_and { $$ = $1 || $3; } 463 ; 453 ; 464 454 465 integer_and: 455 integer_and: 466 integer_bitor 456 integer_bitor 467 | integer_and DT_AND integer_bitor { $ 457 | integer_and DT_AND integer_bitor { $$ = $1 && $3; } 468 ; 458 ; 469 459 470 integer_bitor: 460 integer_bitor: 471 integer_bitxor 461 integer_bitxor 472 | integer_bitor '|' integer_bitxor { $ 462 | integer_bitor '|' integer_bitxor { $$ = $1 | $3; } 473 ; 463 ; 474 464 475 integer_bitxor: 465 integer_bitxor: 476 integer_bitand 466 integer_bitand 477 | integer_bitxor '^' integer_bitand { 467 | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; } 478 ; 468 ; 479 469 480 integer_bitand: 470 integer_bitand: 481 integer_eq 471 integer_eq 482 | integer_bitand '&' integer_eq { $$ = 472 | integer_bitand '&' integer_eq { $$ = $1 & $3; } 483 ; 473 ; 484 474 485 integer_eq: 475 integer_eq: 486 integer_rela 476 integer_rela 487 | integer_eq DT_EQ integer_rela { $$ = 477 | integer_eq DT_EQ integer_rela { $$ = $1 == $3; } 488 | integer_eq DT_NE integer_rela { $$ = 478 | integer_eq DT_NE integer_rela { $$ = $1 != $3; } 489 ; 479 ; 490 480 491 integer_rela: 481 integer_rela: 492 integer_shift 482 integer_shift 493 | integer_rela '<' integer_shift { $$ 483 | integer_rela '<' integer_shift { $$ = $1 < $3; } 494 | integer_rela '>' integer_shift { $$ 484 | integer_rela '>' integer_shift { $$ = $1 > $3; } 495 | integer_rela DT_LE integer_shift { $ 485 | integer_rela DT_LE integer_shift { $$ = $1 <= $3; } 496 | integer_rela DT_GE integer_shift { $ 486 | integer_rela DT_GE integer_shift { $$ = $1 >= $3; } 497 ; 487 ; 498 488 499 integer_shift: 489 integer_shift: 500 integer_shift DT_LSHIFT integer_add !! 490 integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } 501 | integer_shift DT_RSHIFT integer_add !! 491 | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } 502 | integer_add 492 | integer_add 503 ; 493 ; 504 494 505 integer_add: 495 integer_add: 506 integer_add '+' integer_mul { $$ = $ 496 integer_add '+' integer_mul { $$ = $1 + $3; } 507 | integer_add '-' integer_mul { $$ = $ 497 | integer_add '-' integer_mul { $$ = $1 - $3; } 508 | integer_mul 498 | integer_mul 509 ; 499 ; 510 500 511 integer_mul: 501 integer_mul: 512 integer_mul '*' integer_unary { $$ = 502 integer_mul '*' integer_unary { $$ = $1 * $3; } 513 | integer_mul '/' integer_unary 503 | integer_mul '/' integer_unary 514 { 504 { 515 if ($3 != 0) { 505 if ($3 != 0) { 516 $$ = $1 / $3; 506 $$ = $1 / $3; 517 } else { 507 } else { 518 ERROR(&@$, "Di 508 ERROR(&@$, "Division by zero"); 519 $$ = 0; 509 $$ = 0; 520 } 510 } 521 } 511 } 522 | integer_mul '%' integer_unary 512 | integer_mul '%' integer_unary 523 { 513 { 524 if ($3 != 0) { 514 if ($3 != 0) { 525 $$ = $1 % $3; 515 $$ = $1 % $3; 526 } else { 516 } else { 527 ERROR(&@$, "Di 517 ERROR(&@$, "Division by zero"); 528 $$ = 0; 518 $$ = 0; 529 } 519 } 530 } 520 } 531 | integer_unary 521 | integer_unary 532 ; 522 ; 533 523 534 integer_unary: 524 integer_unary: 535 integer_prim 525 integer_prim 536 | '-' integer_unary { $$ = -$2; } 526 | '-' integer_unary { $$ = -$2; } 537 | '~' integer_unary { $$ = ~$2; } 527 | '~' integer_unary { $$ = ~$2; } 538 | '!' integer_unary { $$ = !$2; } 528 | '!' integer_unary { $$ = !$2; } 539 ; 529 ; 540 530 541 bytestring: 531 bytestring: 542 /* empty */ 532 /* empty */ 543 { 533 { 544 $$ = data_add_marker(e 534 $$ = data_add_marker(empty_data, TYPE_UINT8, NULL); 545 } 535 } 546 | bytestring DT_BYTE 536 | bytestring DT_BYTE 547 { 537 { 548 $$ = data_append_byte( 538 $$ = data_append_byte($1, $2); 549 } 539 } 550 | bytestring DT_LABEL 540 | bytestring DT_LABEL 551 { 541 { 552 $$ = data_add_marker($ 542 $$ = data_add_marker($1, LABEL, $2); 553 } 543 } 554 ; 544 ; 555 545 556 subnodes: 546 subnodes: 557 /* empty */ 547 /* empty */ 558 { 548 { 559 $$ = NULL; 549 $$ = NULL; 560 } 550 } 561 | subnode subnodes 551 | subnode subnodes 562 { 552 { 563 $$ = chain_node($1, $2 553 $$ = chain_node($1, $2); 564 } 554 } 565 | subnode propdef 555 | subnode propdef 566 { 556 { 567 ERROR(&@2, "Properties 557 ERROR(&@2, "Properties must precede subnodes"); 568 YYERROR; 558 YYERROR; 569 } 559 } 570 ; 560 ; 571 561 572 subnode: 562 subnode: 573 DT_PROPNODENAME nodedef 563 DT_PROPNODENAME nodedef 574 { 564 { 575 $$ = name_node($2, $1) 565 $$ = name_node($2, $1); 576 free($1); << 577 } 566 } 578 | DT_DEL_NODE DT_PROPNODENAME ';' 567 | DT_DEL_NODE DT_PROPNODENAME ';' 579 { 568 { 580 $$ = name_node(build_n 569 $$ = name_node(build_node_delete(&@$), $2); 581 free($2); << 582 } 570 } 583 | DT_OMIT_NO_REF subnode 571 | DT_OMIT_NO_REF subnode 584 { 572 { 585 $$ = omit_node_if_unus 573 $$ = omit_node_if_unused($2); 586 } 574 } 587 | DT_LABEL subnode 575 | DT_LABEL subnode 588 { 576 { 589 add_label(&$2->labels, 577 add_label(&$2->labels, $1); 590 $$ = $2; 578 $$ = $2; 591 } 579 } 592 ; 580 ; 593 581 594 %% 582 %% 595 583 596 void yyerror(char const *s) 584 void yyerror(char const *s) 597 { 585 { 598 ERROR(&yylloc, "%s", s); 586 ERROR(&yylloc, "%s", s); 599 } 587 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.