171e38f1dSchristos NoEcho(' 271e38f1dSchristos /****************************************************************************** 371e38f1dSchristos * 471e38f1dSchristos * Module Name: aslcstyle.y - Production rules for symbolic operators 571e38f1dSchristos * 671e38f1dSchristos *****************************************************************************/ 771e38f1dSchristos 871e38f1dSchristos /* 9*046a2985Schristos * Copyright (C) 2000 - 2023, Intel Corp. 1071e38f1dSchristos * All rights reserved. 1171e38f1dSchristos * 1271e38f1dSchristos * Redistribution and use in source and binary forms, with or without 1371e38f1dSchristos * modification, are permitted provided that the following conditions 1471e38f1dSchristos * are met: 1571e38f1dSchristos * 1. Redistributions of source code must retain the above copyright 1671e38f1dSchristos * notice, this list of conditions, and the following disclaimer, 1771e38f1dSchristos * without modification. 1871e38f1dSchristos * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1971e38f1dSchristos * substantially similar to the "NO WARRANTY" disclaimer below 2071e38f1dSchristos * ("Disclaimer") and any redistribution must be conditioned upon 2171e38f1dSchristos * including a substantially similar Disclaimer requirement for further 2271e38f1dSchristos * binary redistribution. 2371e38f1dSchristos * 3. Neither the names of the above-listed copyright holders nor the names 2471e38f1dSchristos * of any contributors may be used to endorse or promote products derived 2571e38f1dSchristos * from this software without specific prior written permission. 2671e38f1dSchristos * 2771e38f1dSchristos * Alternatively, this software may be distributed under the terms of the 2871e38f1dSchristos * GNU General Public License ("GPL") version 2 as published by the Free 2971e38f1dSchristos * Software Foundation. 3071e38f1dSchristos * 3171e38f1dSchristos * NO WARRANTY 3271e38f1dSchristos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3371e38f1dSchristos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3446a330b4Schristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3571e38f1dSchristos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3671e38f1dSchristos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3771e38f1dSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3871e38f1dSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3971e38f1dSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4071e38f1dSchristos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4171e38f1dSchristos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4271e38f1dSchristos * POSSIBILITY OF SUCH DAMAGES. 4371e38f1dSchristos */ 4471e38f1dSchristos 4571e38f1dSchristos ') 4671e38f1dSchristos 4771e38f1dSchristos /******************************************************************************* 4871e38f1dSchristos * 4971e38f1dSchristos * Production rules for the symbolic (c-style) operators 5071e38f1dSchristos * 5171e38f1dSchristos ******************************************************************************/ 5271e38f1dSchristos 5371e38f1dSchristos /* 5471e38f1dSchristos * ASL Extensions: C-style math/logical operators and expressions. 5571e38f1dSchristos * The implementation transforms these operators into the standard 5671e38f1dSchristos * AML opcodes and syntax. 5771e38f1dSchristos * 5871e38f1dSchristos * Supported operators and precedence rules (high-to-low) 5971e38f1dSchristos * 6071e38f1dSchristos * NOTE: The operator precedence and associativity rules are 6171e38f1dSchristos * implemented by the tokens in asltokens.y 6271e38f1dSchristos * 6371e38f1dSchristos * (left-to-right): 6471e38f1dSchristos * 1) ( ) expr++ expr-- 6571e38f1dSchristos * 6671e38f1dSchristos * (right-to-left): 6771e38f1dSchristos * 2) ! ~ 6871e38f1dSchristos * 6971e38f1dSchristos * (left-to-right): 7071e38f1dSchristos * 3) * / % 7171e38f1dSchristos * 4) + - 7271e38f1dSchristos * 5) >> << 7371e38f1dSchristos * 6) < > <= >= 7471e38f1dSchristos * 7) == != 7571e38f1dSchristos * 8) & 7671e38f1dSchristos * 9) ^ 7771e38f1dSchristos * 10) | 7871e38f1dSchristos * 11) && 7971e38f1dSchristos * 12) || 8071e38f1dSchristos * 8171e38f1dSchristos * (right-to-left): 8271e38f1dSchristos * 13) = += -= *= /= %= <<= >>= &= ^= |= 8371e38f1dSchristos */ 8471e38f1dSchristos 85d0e1da26Schristos 86d0e1da26Schristos /******************************************************************************* 87d0e1da26Schristos * 88d0e1da26Schristos * Basic operations for math and logical expressions. 89d0e1da26Schristos * 90d0e1da26Schristos ******************************************************************************/ 91d0e1da26Schristos 9271e38f1dSchristos Expression 9371e38f1dSchristos 9471e38f1dSchristos /* Unary operators */ 9571e38f1dSchristos 9689b8eb6cSchristos : PARSEOP_EXP_LOGICAL_NOT {$<n>$ = TrCreateLeafOp (PARSEOP_LNOT);} 9789b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>2,1,$3);} 9889b8eb6cSchristos | PARSEOP_EXP_NOT {$<n>$ = TrCreateLeafOp (PARSEOP_NOT);} 9989b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>2,2,$3,TrCreateNullTargetOp ());} 10071e38f1dSchristos 10189b8eb6cSchristos | SuperName PARSEOP_EXP_INCREMENT {$<n>$ = TrCreateLeafOp (PARSEOP_INCREMENT);} 10289b8eb6cSchristos {$$ = TrLinkOpChildren ($<n>3,1,$1);} 10389b8eb6cSchristos | SuperName PARSEOP_EXP_DECREMENT {$<n>$ = TrCreateLeafOp (PARSEOP_DECREMENT);} 10489b8eb6cSchristos {$$ = TrLinkOpChildren ($<n>3,1,$1);} 10571e38f1dSchristos 10671e38f1dSchristos /* Binary operators: math and logical */ 10771e38f1dSchristos 10889b8eb6cSchristos | TermArg PARSEOP_EXP_ADD {$<n>$ = TrCreateLeafOp (PARSEOP_ADD);} 10989b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 11089b8eb6cSchristos | TermArg PARSEOP_EXP_DIVIDE {$<n>$ = TrCreateLeafOp (PARSEOP_DIVIDE);} 11189b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,4,$1,$4,TrCreateNullTargetOp (), 11289b8eb6cSchristos TrCreateNullTargetOp ());} 11389b8eb6cSchristos | TermArg PARSEOP_EXP_MODULO {$<n>$ = TrCreateLeafOp (PARSEOP_MOD);} 11489b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 11589b8eb6cSchristos | TermArg PARSEOP_EXP_MULTIPLY {$<n>$ = TrCreateLeafOp (PARSEOP_MULTIPLY);} 11689b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 11789b8eb6cSchristos | TermArg PARSEOP_EXP_SHIFT_LEFT {$<n>$ = TrCreateLeafOp (PARSEOP_SHIFTLEFT);} 11889b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 11989b8eb6cSchristos | TermArg PARSEOP_EXP_SHIFT_RIGHT {$<n>$ = TrCreateLeafOp (PARSEOP_SHIFTRIGHT);} 12089b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 12189b8eb6cSchristos | TermArg PARSEOP_EXP_SUBTRACT {$<n>$ = TrCreateLeafOp (PARSEOP_SUBTRACT);} 12289b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 12371e38f1dSchristos 12489b8eb6cSchristos | TermArg PARSEOP_EXP_AND {$<n>$ = TrCreateLeafOp (PARSEOP_AND);} 12589b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 12689b8eb6cSchristos | TermArg PARSEOP_EXP_OR {$<n>$ = TrCreateLeafOp (PARSEOP_OR);} 12789b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 12889b8eb6cSchristos | TermArg PARSEOP_EXP_XOR {$<n>$ = TrCreateLeafOp (PARSEOP_XOR);} 12989b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4,TrCreateNullTargetOp ());} 13071e38f1dSchristos 13189b8eb6cSchristos | TermArg PARSEOP_EXP_GREATER {$<n>$ = TrCreateLeafOp (PARSEOP_LGREATER);} 13289b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 13389b8eb6cSchristos | TermArg PARSEOP_EXP_GREATER_EQUAL {$<n>$ = TrCreateLeafOp (PARSEOP_LGREATEREQUAL);} 13489b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 13589b8eb6cSchristos | TermArg PARSEOP_EXP_LESS {$<n>$ = TrCreateLeafOp (PARSEOP_LLESS);} 13689b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 13789b8eb6cSchristos | TermArg PARSEOP_EXP_LESS_EQUAL {$<n>$ = TrCreateLeafOp (PARSEOP_LLESSEQUAL);} 13889b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 13971e38f1dSchristos 14089b8eb6cSchristos | TermArg PARSEOP_EXP_EQUAL {$<n>$ = TrCreateLeafOp (PARSEOP_LEQUAL);} 14189b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 14289b8eb6cSchristos | TermArg PARSEOP_EXP_NOT_EQUAL {$<n>$ = TrCreateLeafOp (PARSEOP_LNOTEQUAL);} 14389b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 14471e38f1dSchristos 14589b8eb6cSchristos | TermArg PARSEOP_EXP_LOGICAL_AND {$<n>$ = TrCreateLeafOp (PARSEOP_LAND);} 14689b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 14789b8eb6cSchristos | TermArg PARSEOP_EXP_LOGICAL_OR {$<n>$ = TrCreateLeafOp (PARSEOP_LOR);} 14889b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,2,$1,$4);} 14971e38f1dSchristos 15071e38f1dSchristos /* Parentheses */ 15171e38f1dSchristos 1520b89cdedSchristos | PARSEOP_OPEN_PAREN 1530b89cdedSchristos Expression 1540b89cdedSchristos PARSEOP_CLOSE_PAREN {$$ = $2;} 15571e38f1dSchristos 15671e38f1dSchristos /* Index term -- "= BUF1[5]" on right-hand side of an equals (source) */ 15771e38f1dSchristos 1580b89cdedSchristos | IndexExpTerm 15971e38f1dSchristos ; 16071e38f1dSchristos 1610b89cdedSchristos /* 1620b89cdedSchristos * Index term -- "BUF1[5] = " or " = BUF1[5] on either the left side 1630b89cdedSchristos * of an equals (target) or the right side (source) 1640b89cdedSchristos * Currently used in these terms: 1650b89cdedSchristos * Expression 1660b89cdedSchristos * ObjectTypeSource 1670b89cdedSchristos * DerefOfSource 1680b89cdedSchristos * Type6Opcode 1690b89cdedSchristos */ 17071e38f1dSchristos IndexExpTerm 17171e38f1dSchristos 1720b89cdedSchristos : SuperName 1730b89cdedSchristos PARSEOP_EXP_INDEX_LEFT 1740b89cdedSchristos TermArg 17589b8eb6cSchristos PARSEOP_EXP_INDEX_RIGHT {$$ = TrCreateLeafOp (PARSEOP_INDEX); 17689b8eb6cSchristos TrLinkOpChildren ($$,3,$1,$3,TrCreateNullTargetOp ());} 17771e38f1dSchristos ; 17871e38f1dSchristos 179d0e1da26Schristos 180d0e1da26Schristos /******************************************************************************* 181d0e1da26Schristos * 182d0e1da26Schristos * All assignment-type operations -- math and logical. Includes simple 183d0e1da26Schristos * assignment and compound assignments. 184d0e1da26Schristos * 185d0e1da26Schristos ******************************************************************************/ 186d0e1da26Schristos 18771e38f1dSchristos EqualsTerm 18871e38f1dSchristos 1890b89cdedSchristos /* Allow parens anywhere */ 1900b89cdedSchristos 1910b89cdedSchristos : PARSEOP_OPEN_PAREN 1920b89cdedSchristos EqualsTerm 1930b89cdedSchristos PARSEOP_CLOSE_PAREN {$$ = $2;} 1940b89cdedSchristos 195d0e1da26Schristos /* Simple Store() operation */ 19671e38f1dSchristos 1970b89cdedSchristos | SuperName 1980b89cdedSchristos PARSEOP_EXP_EQUALS 19989b8eb6cSchristos TermArg {$$ = TrCreateAssignmentOp ($1, $3);} 20071e38f1dSchristos 2010b89cdedSchristos /* Chained equals: (a=RefOf)=b, a=b=c=d etc. */ 2020b89cdedSchristos 2030b89cdedSchristos | PARSEOP_OPEN_PAREN 2040b89cdedSchristos EqualsTerm 2050b89cdedSchristos PARSEOP_CLOSE_PAREN 2060b89cdedSchristos PARSEOP_EXP_EQUALS 20789b8eb6cSchristos TermArg {$$ = TrCreateAssignmentOp ($2, $5);} 2080b89cdedSchristos 209d0e1da26Schristos /* Compound assignments -- Add (operand, operand, target) */ 210d0e1da26Schristos 21189b8eb6cSchristos | TermArg PARSEOP_EXP_ADD_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_ADD);} 21289b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 21389b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 21471e38f1dSchristos 21589b8eb6cSchristos | TermArg PARSEOP_EXP_DIV_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_DIVIDE);} 21689b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,4,$1,$4,TrCreateNullTargetOp (), 21789b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 21871e38f1dSchristos 21989b8eb6cSchristos | TermArg PARSEOP_EXP_MOD_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_MOD);} 22089b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 22189b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 22271e38f1dSchristos 22389b8eb6cSchristos | TermArg PARSEOP_EXP_MUL_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_MULTIPLY);} 22489b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 22589b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 22671e38f1dSchristos 22789b8eb6cSchristos | TermArg PARSEOP_EXP_SHL_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_SHIFTLEFT);} 22889b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 22989b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 23071e38f1dSchristos 23189b8eb6cSchristos | TermArg PARSEOP_EXP_SHR_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_SHIFTRIGHT);} 23289b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 23389b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 23471e38f1dSchristos 23589b8eb6cSchristos | TermArg PARSEOP_EXP_SUB_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_SUBTRACT);} 23689b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 23789b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 23871e38f1dSchristos 23989b8eb6cSchristos | TermArg PARSEOP_EXP_AND_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_AND);} 24089b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 24189b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 24271e38f1dSchristos 24389b8eb6cSchristos | TermArg PARSEOP_EXP_OR_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_OR);} 24489b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 24589b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 24671e38f1dSchristos 24789b8eb6cSchristos | TermArg PARSEOP_EXP_XOR_EQ {$<n>$ = TrCreateLeafOp (PARSEOP_XOR);} 24889b8eb6cSchristos TermArg {$$ = TrLinkOpChildren ($<n>3,3,$1,$4, 24989b8eb6cSchristos TrSetOpFlags (TrCreateTargetOp ($1, NULL), OP_IS_TARGET));} 25071e38f1dSchristos ; 251