David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 1 | /* |
| 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 |
| 19 | */ |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 20 | %{ |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 23 | #include "dtc.h" |
| 24 | #include "srcpos.h" |
| 25 | |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 26 | extern int yylex(void); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 27 | extern void yyerror(char const *s); |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 28 | #define ERROR(loc, ...) \ |
| 29 | do { \ |
| 30 | srcpos_error((loc), "Error", __VA_ARGS__); \ |
| 31 | treesource_error = true; \ |
| 32 | } while (0) |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 33 | |
| 34 | extern struct boot_info *the_boot_info; |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 35 | extern bool treesource_error; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 36 | %} |
| 37 | |
| 38 | %union { |
| 39 | char *propnodename; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 40 | char *labelref; |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 41 | uint8_t byte; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 42 | struct data data; |
| 43 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 44 | struct { |
| 45 | struct data data; |
| 46 | int bits; |
| 47 | } array; |
| 48 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 49 | struct property *prop; |
| 50 | struct property *proplist; |
| 51 | struct node *node; |
| 52 | struct node *nodelist; |
| 53 | struct reserve_info *re; |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 54 | uint64_t integer; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | %token DT_V1 |
| 58 | %token DT_MEMRESERVE |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 59 | %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR |
| 60 | %token DT_BITS |
| 61 | %token DT_DEL_PROP |
| 62 | %token DT_DEL_NODE |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 63 | %token <propnodename> DT_PROPNODENAME |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 64 | %token <integer> DT_LITERAL |
| 65 | %token <integer> DT_CHAR_LITERAL |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 66 | %token <byte> DT_BYTE |
| 67 | %token <data> DT_STRING |
| 68 | %token <labelref> DT_LABEL |
| 69 | %token <labelref> DT_REF |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 70 | %token DT_INCBIN |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 71 | |
| 72 | %type <data> propdata |
| 73 | %type <data> propdataprefix |
| 74 | %type <re> memreserve |
| 75 | %type <re> memreserves |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 76 | %type <array> arrayprefix |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 77 | %type <data> bytestring |
| 78 | %type <prop> propdef |
| 79 | %type <proplist> proplist |
| 80 | |
| 81 | %type <node> devicetree |
| 82 | %type <node> nodedef |
| 83 | %type <node> subnode |
| 84 | %type <nodelist> subnodes |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 85 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 86 | %type <integer> integer_prim |
| 87 | %type <integer> integer_unary |
| 88 | %type <integer> integer_mul |
| 89 | %type <integer> integer_add |
| 90 | %type <integer> integer_shift |
| 91 | %type <integer> integer_rela |
| 92 | %type <integer> integer_eq |
| 93 | %type <integer> integer_bitand |
| 94 | %type <integer> integer_bitxor |
| 95 | %type <integer> integer_bitor |
| 96 | %type <integer> integer_and |
| 97 | %type <integer> integer_or |
| 98 | %type <integer> integer_trinary |
| 99 | %type <integer> integer_expr |
| 100 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 101 | %% |
| 102 | |
| 103 | sourcefile: |
| 104 | DT_V1 ';' memreserves devicetree |
| 105 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 106 | the_boot_info = build_boot_info($3, $4, |
| 107 | guess_boot_cpuid($4)); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 108 | } |
| 109 | ; |
| 110 | |
| 111 | memreserves: |
| 112 | /* empty */ |
| 113 | { |
| 114 | $$ = NULL; |
| 115 | } |
| 116 | | memreserve memreserves |
| 117 | { |
| 118 | $$ = chain_reserve_entry($1, $2); |
| 119 | } |
| 120 | ; |
| 121 | |
| 122 | memreserve: |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 123 | DT_MEMRESERVE integer_prim integer_prim ';' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 124 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 125 | $$ = build_reserve_entry($2, $3); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 126 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 127 | | DT_LABEL memreserve |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 128 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 129 | add_label(&$2->labels, $1); |
| 130 | $$ = $2; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 131 | } |
| 132 | ; |
| 133 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 134 | devicetree: |
| 135 | '/' nodedef |
| 136 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 137 | $$ = name_node($2, ""); |
| 138 | } |
| 139 | | devicetree '/' nodedef |
| 140 | { |
| 141 | $$ = merge_nodes($1, $3); |
| 142 | } |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 143 | |
| 144 | | devicetree DT_LABEL DT_REF nodedef |
| 145 | { |
| 146 | struct node *target = get_node_by_ref($1, $3); |
| 147 | |
| 148 | add_label(&target->labels, $2); |
| 149 | if (target) |
| 150 | merge_nodes(target, $4); |
| 151 | else |
| 152 | ERROR(&@3, "Label or path %s not found", $3); |
| 153 | $$ = $1; |
| 154 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 155 | | devicetree DT_REF nodedef |
| 156 | { |
| 157 | struct node *target = get_node_by_ref($1, $2); |
| 158 | |
| 159 | if (target) |
| 160 | merge_nodes(target, $3); |
| 161 | else |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 162 | ERROR(&@2, "Label or path %s not found", $2); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 163 | $$ = $1; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 164 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 165 | | devicetree DT_DEL_NODE DT_REF ';' |
| 166 | { |
| 167 | struct node *target = get_node_by_ref($1, $3); |
| 168 | |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 169 | if (target) |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 170 | delete_node(target); |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 171 | else |
| 172 | ERROR(&@3, "Label or path %s not found", $3); |
| 173 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 174 | |
| 175 | $$ = $1; |
| 176 | } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 177 | ; |
| 178 | |
| 179 | nodedef: |
| 180 | '{' proplist subnodes '}' ';' |
| 181 | { |
| 182 | $$ = build_node($2, $3); |
| 183 | } |
| 184 | ; |
| 185 | |
| 186 | proplist: |
| 187 | /* empty */ |
| 188 | { |
| 189 | $$ = NULL; |
| 190 | } |
| 191 | | proplist propdef |
| 192 | { |
| 193 | $$ = chain_property($2, $1); |
| 194 | } |
| 195 | ; |
| 196 | |
| 197 | propdef: |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 198 | DT_PROPNODENAME '=' propdata ';' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 199 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 200 | $$ = build_property($1, $3); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 201 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 202 | | DT_PROPNODENAME ';' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 203 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 204 | $$ = build_property($1, empty_data); |
| 205 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 206 | | DT_DEL_PROP DT_PROPNODENAME ';' |
| 207 | { |
| 208 | $$ = build_property_delete($2); |
| 209 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 210 | | DT_LABEL propdef |
| 211 | { |
| 212 | add_label(&$2->labels, $1); |
| 213 | $$ = $2; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 214 | } |
| 215 | ; |
| 216 | |
| 217 | propdata: |
| 218 | propdataprefix DT_STRING |
| 219 | { |
| 220 | $$ = data_merge($1, $2); |
| 221 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 222 | | propdataprefix arrayprefix '>' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 223 | { |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 224 | $$ = data_merge($1, $2.data); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 225 | } |
| 226 | | propdataprefix '[' bytestring ']' |
| 227 | { |
| 228 | $$ = data_merge($1, $3); |
| 229 | } |
| 230 | | propdataprefix DT_REF |
| 231 | { |
| 232 | $$ = data_add_marker($1, REF_PATH, $2); |
| 233 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 234 | | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 235 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 236 | FILE *f = srcfile_relative_open($4.val, NULL); |
| 237 | struct data d; |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 238 | |
| 239 | if ($6 != 0) |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 240 | if (fseek(f, $6, SEEK_SET) != 0) |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 241 | die("Couldn't seek to offset %llu in \"%s\": %s", |
| 242 | (unsigned long long)$6, $4.val, |
| 243 | strerror(errno)); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 244 | |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 245 | d = data_copy_file(f, $8); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 246 | |
| 247 | $$ = data_merge($1, d); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 248 | fclose(f); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 249 | } |
| 250 | | propdataprefix DT_INCBIN '(' DT_STRING ')' |
| 251 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 252 | FILE *f = srcfile_relative_open($4.val, NULL); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 253 | struct data d = empty_data; |
| 254 | |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 255 | d = data_copy_file(f, -1); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 256 | |
| 257 | $$ = data_merge($1, d); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 258 | fclose(f); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 259 | } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 260 | | propdata DT_LABEL |
| 261 | { |
| 262 | $$ = data_add_marker($1, LABEL, $2); |
| 263 | } |
| 264 | ; |
| 265 | |
| 266 | propdataprefix: |
| 267 | /* empty */ |
| 268 | { |
| 269 | $$ = empty_data; |
| 270 | } |
| 271 | | propdata ',' |
| 272 | { |
| 273 | $$ = $1; |
| 274 | } |
| 275 | | propdataprefix DT_LABEL |
| 276 | { |
| 277 | $$ = data_add_marker($1, LABEL, $2); |
| 278 | } |
| 279 | ; |
| 280 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 281 | arrayprefix: |
| 282 | DT_BITS DT_LITERAL '<' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 283 | { |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 284 | unsigned long long bits; |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 285 | |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 286 | bits = $2; |
| 287 | |
| 288 | if ((bits != 8) && (bits != 16) && |
| 289 | (bits != 32) && (bits != 64)) { |
| 290 | ERROR(&@2, "Array elements must be" |
| 291 | " 8, 16, 32 or 64-bits"); |
| 292 | bits = 32; |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 293 | } |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 294 | |
| 295 | $$.data = empty_data; |
| 296 | $$.bits = bits; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 297 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 298 | | '<' |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 299 | { |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 300 | $$.data = empty_data; |
| 301 | $$.bits = 32; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 302 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 303 | | arrayprefix integer_prim |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 304 | { |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 305 | if ($1.bits < 64) { |
| 306 | uint64_t mask = (1ULL << $1.bits) - 1; |
| 307 | /* |
| 308 | * Bits above mask must either be all zero |
| 309 | * (positive within range of mask) or all one |
| 310 | * (negative and sign-extended). The second |
| 311 | * condition is true if when we set all bits |
| 312 | * within the mask to one (i.e. | in the |
| 313 | * mask), all bits are one. |
| 314 | */ |
| 315 | if (($2 > mask) && (($2 | mask) != -1ULL)) |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 316 | ERROR(&@2, "Value out of range for" |
| 317 | " %d-bit array element", $1.bits); |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | $$.data = data_append_integer($1.data, $2, $1.bits); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 321 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 322 | | arrayprefix DT_REF |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 323 | { |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 324 | uint64_t val = ~0ULL >> (64 - $1.bits); |
| 325 | |
| 326 | if ($1.bits == 32) |
| 327 | $1.data = data_add_marker($1.data, |
| 328 | REF_PHANDLE, |
| 329 | $2); |
| 330 | else |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 331 | ERROR(&@2, "References are only allowed in " |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 332 | "arrays with 32-bit elements."); |
| 333 | |
| 334 | $$.data = data_append_integer($1.data, val, $1.bits); |
| 335 | } |
| 336 | | arrayprefix DT_LABEL |
| 337 | { |
| 338 | $$.data = data_add_marker($1.data, LABEL, $2); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 339 | } |
| 340 | ; |
| 341 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 342 | integer_prim: |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 343 | DT_LITERAL |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 344 | | DT_CHAR_LITERAL |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 345 | | '(' integer_expr ')' |
| 346 | { |
| 347 | $$ = $2; |
| 348 | } |
| 349 | ; |
| 350 | |
| 351 | integer_expr: |
| 352 | integer_trinary |
| 353 | ; |
| 354 | |
| 355 | integer_trinary: |
| 356 | integer_or |
| 357 | | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; } |
| 358 | ; |
| 359 | |
| 360 | integer_or: |
| 361 | integer_and |
| 362 | | integer_or DT_OR integer_and { $$ = $1 || $3; } |
| 363 | ; |
| 364 | |
| 365 | integer_and: |
| 366 | integer_bitor |
| 367 | | integer_and DT_AND integer_bitor { $$ = $1 && $3; } |
| 368 | ; |
| 369 | |
| 370 | integer_bitor: |
| 371 | integer_bitxor |
| 372 | | integer_bitor '|' integer_bitxor { $$ = $1 | $3; } |
| 373 | ; |
| 374 | |
| 375 | integer_bitxor: |
| 376 | integer_bitand |
| 377 | | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; } |
| 378 | ; |
| 379 | |
| 380 | integer_bitand: |
| 381 | integer_eq |
| 382 | | integer_bitand '&' integer_eq { $$ = $1 & $3; } |
| 383 | ; |
| 384 | |
| 385 | integer_eq: |
| 386 | integer_rela |
| 387 | | integer_eq DT_EQ integer_rela { $$ = $1 == $3; } |
| 388 | | integer_eq DT_NE integer_rela { $$ = $1 != $3; } |
| 389 | ; |
| 390 | |
| 391 | integer_rela: |
| 392 | integer_shift |
| 393 | | integer_rela '<' integer_shift { $$ = $1 < $3; } |
| 394 | | integer_rela '>' integer_shift { $$ = $1 > $3; } |
| 395 | | integer_rela DT_LE integer_shift { $$ = $1 <= $3; } |
| 396 | | integer_rela DT_GE integer_shift { $$ = $1 >= $3; } |
| 397 | ; |
| 398 | |
| 399 | integer_shift: |
| 400 | integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } |
| 401 | | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } |
| 402 | | integer_add |
| 403 | ; |
| 404 | |
| 405 | integer_add: |
| 406 | integer_add '+' integer_mul { $$ = $1 + $3; } |
| 407 | | integer_add '-' integer_mul { $$ = $1 - $3; } |
| 408 | | integer_mul |
| 409 | ; |
| 410 | |
| 411 | integer_mul: |
| 412 | integer_mul '*' integer_unary { $$ = $1 * $3; } |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 413 | | integer_mul '/' integer_unary |
| 414 | { |
| 415 | if ($3 != 0) { |
| 416 | $$ = $1 / $3; |
| 417 | } else { |
| 418 | ERROR(&@$, "Division by zero"); |
| 419 | $$ = 0; |
| 420 | } |
| 421 | } |
| 422 | | integer_mul '%' integer_unary |
| 423 | { |
| 424 | if ($3 != 0) { |
| 425 | $$ = $1 % $3; |
| 426 | } else { |
| 427 | ERROR(&@$, "Division by zero"); |
| 428 | $$ = 0; |
| 429 | } |
| 430 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 431 | | integer_unary |
| 432 | ; |
| 433 | |
| 434 | integer_unary: |
| 435 | integer_prim |
| 436 | | '-' integer_unary { $$ = -$2; } |
| 437 | | '~' integer_unary { $$ = ~$2; } |
| 438 | | '!' integer_unary { $$ = !$2; } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 439 | ; |
| 440 | |
| 441 | bytestring: |
| 442 | /* empty */ |
| 443 | { |
| 444 | $$ = empty_data; |
| 445 | } |
| 446 | | bytestring DT_BYTE |
| 447 | { |
| 448 | $$ = data_append_byte($1, $2); |
| 449 | } |
| 450 | | bytestring DT_LABEL |
| 451 | { |
| 452 | $$ = data_add_marker($1, LABEL, $2); |
| 453 | } |
| 454 | ; |
| 455 | |
| 456 | subnodes: |
| 457 | /* empty */ |
| 458 | { |
| 459 | $$ = NULL; |
| 460 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 461 | | subnode subnodes |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 462 | { |
| 463 | $$ = chain_node($1, $2); |
| 464 | } |
| 465 | | subnode propdef |
| 466 | { |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 467 | ERROR(&@2, "Properties must precede subnodes"); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 468 | YYERROR; |
| 469 | } |
| 470 | ; |
| 471 | |
| 472 | subnode: |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 473 | DT_PROPNODENAME nodedef |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 474 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 475 | $$ = name_node($2, $1); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 476 | } |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 477 | | DT_DEL_NODE DT_PROPNODENAME ';' |
| 478 | { |
| 479 | $$ = name_node(build_node_delete(), $2); |
| 480 | } |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 481 | | DT_LABEL subnode |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 482 | { |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 483 | add_label(&$2->labels, $1); |
| 484 | $$ = $2; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 485 | } |
| 486 | ; |
| 487 | |
| 488 | %% |
| 489 | |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 490 | void yyerror(char const *s) |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 491 | { |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 492 | ERROR(&yylloc, "%s", s); |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 493 | } |