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