1 NoEcho(' 2 /****************************************************************************** 3 * 4 * Module Name: aslcstyle.y - Production rules for symbolic operators 5 * 6 *****************************************************************************/ 7 8 /* 9 * Copyright (C) 2000 - 2016, Intel Corp. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions, and the following disclaimer, 17 * without modification. 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19 * substantially similar to the "NO WARRANTY" disclaimer below 20 * ("Disclaimer") and any redistribution must be conditioned upon 21 * including a substantially similar Disclaimer requirement for further 22 * binary redistribution. 23 * 3. Neither the names of the above-listed copyright holders nor the names 24 * of any contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * Alternatively, this software may be distributed under the terms of the 28 * GNU General Public License ("GPL") version 2 as published by the Free 29 * Software Foundation. 30 * 31 * NO WARRANTY 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 * POSSIBILITY OF SUCH DAMAGES. 43 */ 44 45 ') 46 47 /******************************************************************************* 48 * 49 * Production rules for the symbolic (c-style) operators 50 * 51 ******************************************************************************/ 52 53 /* 54 * ASL Extensions: C-style math/logical operators and expressions. 55 * The implementation transforms these operators into the standard 56 * AML opcodes and syntax. 57 * 58 * Supported operators and precedence rules (high-to-low) 59 * 60 * NOTE: The operator precedence and associativity rules are 61 * implemented by the tokens in asltokens.y 62 * 63 * (left-to-right): 64 * 1) ( ) expr++ expr-- 65 * 66 * (right-to-left): 67 * 2) ! ~ 68 * 69 * (left-to-right): 70 * 3) * / % 71 * 4) + - 72 * 5) >> << 73 * 6) < > <= >= 74 * 7) == != 75 * 8) & 76 * 9) ^ 77 * 10) | 78 * 11) && 79 * 12) || 80 * 81 * (right-to-left): 82 * 13) = += -= *= /= %= <<= >>= &= ^= |= 83 */ 84 85 86 /******************************************************************************* 87 * 88 * Basic operations for math and logical expressions. 89 * 90 ******************************************************************************/ 91 92 Expression 93 94 /* Unary operators */ 95 96 : PARSEOP_EXP_LOGICAL_NOT {$<n>$ = TrCreateLeafNode (PARSEOP_LNOT);} 97 TermArg {$$ = TrLinkChildren ($<n>2,1,$3);} 98 | PARSEOP_EXP_NOT {$<n>$ = TrCreateLeafNode (PARSEOP_NOT);} 99 TermArg {$$ = TrLinkChildren ($<n>2,2,$3,TrCreateNullTarget ());} 100 101 | SuperName PARSEOP_EXP_INCREMENT {$<n>$ = TrCreateLeafNode (PARSEOP_INCREMENT);} 102 {$$ = TrLinkChildren ($<n>3,1,$1);} 103 | SuperName PARSEOP_EXP_DECREMENT {$<n>$ = TrCreateLeafNode (PARSEOP_DECREMENT);} 104 {$$ = TrLinkChildren ($<n>3,1,$1);} 105 106 /* Binary operators: math and logical */ 107 108 | TermArg PARSEOP_EXP_ADD {$<n>$ = TrCreateLeafNode (PARSEOP_ADD);} 109 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 110 | TermArg PARSEOP_EXP_DIVIDE {$<n>$ = TrCreateLeafNode (PARSEOP_DIVIDE);} 111 TermArg {$$ = TrLinkChildren ($<n>3,4,$1,$4,TrCreateNullTarget (), 112 TrCreateNullTarget ());} 113 | TermArg PARSEOP_EXP_MODULO {$<n>$ = TrCreateLeafNode (PARSEOP_MOD);} 114 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 115 | TermArg PARSEOP_EXP_MULTIPLY {$<n>$ = TrCreateLeafNode (PARSEOP_MULTIPLY);} 116 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 117 | TermArg PARSEOP_EXP_SHIFT_LEFT {$<n>$ = TrCreateLeafNode (PARSEOP_SHIFTLEFT);} 118 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 119 | TermArg PARSEOP_EXP_SHIFT_RIGHT {$<n>$ = TrCreateLeafNode (PARSEOP_SHIFTRIGHT);} 120 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 121 | TermArg PARSEOP_EXP_SUBTRACT {$<n>$ = TrCreateLeafNode (PARSEOP_SUBTRACT);} 122 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 123 124 | TermArg PARSEOP_EXP_AND {$<n>$ = TrCreateLeafNode (PARSEOP_AND);} 125 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 126 | TermArg PARSEOP_EXP_OR {$<n>$ = TrCreateLeafNode (PARSEOP_OR);} 127 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 128 | TermArg PARSEOP_EXP_XOR {$<n>$ = TrCreateLeafNode (PARSEOP_XOR);} 129 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4,TrCreateNullTarget ());} 130 131 | TermArg PARSEOP_EXP_GREATER {$<n>$ = TrCreateLeafNode (PARSEOP_LGREATER);} 132 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 133 | TermArg PARSEOP_EXP_GREATER_EQUAL {$<n>$ = TrCreateLeafNode (PARSEOP_LGREATEREQUAL);} 134 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 135 | TermArg PARSEOP_EXP_LESS {$<n>$ = TrCreateLeafNode (PARSEOP_LLESS);} 136 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 137 | TermArg PARSEOP_EXP_LESS_EQUAL {$<n>$ = TrCreateLeafNode (PARSEOP_LLESSEQUAL);} 138 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 139 140 | TermArg PARSEOP_EXP_EQUAL {$<n>$ = TrCreateLeafNode (PARSEOP_LEQUAL);} 141 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 142 | TermArg PARSEOP_EXP_NOT_EQUAL {$<n>$ = TrCreateLeafNode (PARSEOP_LNOTEQUAL);} 143 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 144 145 | TermArg PARSEOP_EXP_LOGICAL_AND {$<n>$ = TrCreateLeafNode (PARSEOP_LAND);} 146 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 147 | TermArg PARSEOP_EXP_LOGICAL_OR {$<n>$ = TrCreateLeafNode (PARSEOP_LOR);} 148 TermArg {$$ = TrLinkChildren ($<n>3,2,$1,$4);} 149 150 /* Parentheses */ 151 152 | PARSEOP_OPEN_PAREN 153 Expression 154 PARSEOP_CLOSE_PAREN {$$ = $2;} 155 156 /* Index term -- "= BUF1[5]" on right-hand side of an equals (source) */ 157 158 | IndexExpTerm 159 ; 160 161 /* 162 * Index term -- "BUF1[5] = " or " = BUF1[5] on either the left side 163 * of an equals (target) or the right side (source) 164 * Currently used in these terms: 165 * Expression 166 * ObjectTypeSource 167 * DerefOfSource 168 * Type6Opcode 169 */ 170 IndexExpTerm 171 172 : SuperName 173 PARSEOP_EXP_INDEX_LEFT 174 TermArg 175 PARSEOP_EXP_INDEX_RIGHT {$$ = TrCreateLeafNode (PARSEOP_INDEX); 176 TrLinkChildren ($$,3,$1,$3,TrCreateNullTarget ());} 177 ; 178 179 180 /******************************************************************************* 181 * 182 * All assignment-type operations -- math and logical. Includes simple 183 * assignment and compound assignments. 184 * 185 ******************************************************************************/ 186 187 EqualsTerm 188 189 /* Allow parens anywhere */ 190 191 : PARSEOP_OPEN_PAREN 192 EqualsTerm 193 PARSEOP_CLOSE_PAREN {$$ = $2;} 194 195 /* Simple Store() operation */ 196 197 | SuperName 198 PARSEOP_EXP_EQUALS 199 TermArg {$$ = TrCreateAssignmentNode ($1, $3);} 200 201 /* Chained equals: (a=RefOf)=b, a=b=c=d etc. */ 202 203 | PARSEOP_OPEN_PAREN 204 EqualsTerm 205 PARSEOP_CLOSE_PAREN 206 PARSEOP_EXP_EQUALS 207 TermArg {$$ = TrCreateAssignmentNode ($2, $5);} 208 209 /* Compound assignments -- Add (operand, operand, target) */ 210 211 | TermArg PARSEOP_EXP_ADD_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_ADD);} 212 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 213 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 214 215 | TermArg PARSEOP_EXP_DIV_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_DIVIDE);} 216 TermArg {$$ = TrLinkChildren ($<n>3,4,$1,$4,TrCreateNullTarget (), 217 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 218 219 | TermArg PARSEOP_EXP_MOD_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_MOD);} 220 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 221 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 222 223 | TermArg PARSEOP_EXP_MUL_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_MULTIPLY);} 224 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 225 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 226 227 | TermArg PARSEOP_EXP_SHL_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_SHIFTLEFT);} 228 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 229 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 230 231 | TermArg PARSEOP_EXP_SHR_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_SHIFTRIGHT);} 232 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 233 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 234 235 | TermArg PARSEOP_EXP_SUB_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_SUBTRACT);} 236 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 237 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 238 239 | TermArg PARSEOP_EXP_AND_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_AND);} 240 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 241 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 242 243 | TermArg PARSEOP_EXP_OR_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_OR);} 244 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 245 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 246 247 | TermArg PARSEOP_EXP_XOR_EQ {$<n>$ = TrCreateLeafNode (PARSEOP_XOR);} 248 TermArg {$$ = TrLinkChildren ($<n>3,3,$1,$4, 249 TrSetNodeFlags (TrCreateTargetOperand ($1, NULL), NODE_IS_TARGET));} 250 ; 251