Home | History | Annotate | Line # | Download | only in compiler
dtparser.y revision 1.1.1.5
      1      1.1    jruoho %{
      2      1.1    jruoho /******************************************************************************
      3      1.1    jruoho  *
      4      1.1    jruoho  * Module Name: dtparser.y - Bison input file for table compiler parser
      5      1.1    jruoho  *
      6      1.1    jruoho  *****************************************************************************/
      7      1.1    jruoho 
      8      1.1    jruoho /*
      9  1.1.1.4  christos  * Copyright (C) 2000 - 2015, Intel Corp.
     10      1.1    jruoho  * All rights reserved.
     11      1.1    jruoho  *
     12      1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     13      1.1    jruoho  * modification, are permitted provided that the following conditions
     14      1.1    jruoho  * are met:
     15      1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     16      1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     17      1.1    jruoho  *    without modification.
     18      1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19      1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     20      1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     21      1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     22      1.1    jruoho  *    binary redistribution.
     23      1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     24      1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     25      1.1    jruoho  *    from this software without specific prior written permission.
     26      1.1    jruoho  *
     27      1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     28      1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     29      1.1    jruoho  * Software Foundation.
     30      1.1    jruoho  *
     31      1.1    jruoho  * NO WARRANTY
     32      1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33      1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34      1.1    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35      1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36      1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37      1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38      1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39      1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40      1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41      1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42      1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     43      1.1    jruoho  */
     44      1.1    jruoho 
     45      1.1    jruoho #include "aslcompiler.h"
     46      1.1    jruoho #include "dtcompiler.h"
     47      1.1    jruoho 
     48      1.1    jruoho #define _COMPONENT          DT_COMPILER
     49      1.1    jruoho         ACPI_MODULE_NAME    ("dtparser")
     50      1.1    jruoho 
     51  1.1.1.5  christos void *                      AslLocalAllocate (unsigned int Size);
     52  1.1.1.5  christos 
     53  1.1.1.5  christos /* Bison/yacc configuration */
     54  1.1.1.5  christos 
     55  1.1.1.5  christos #undef alloca
     56  1.1.1.5  christos #define alloca              AslLocalAllocate
     57  1.1.1.5  christos 
     58      1.1    jruoho int                         DtParserlex (void);
     59      1.1    jruoho int                         DtParserparse (void);
     60      1.1    jruoho void                        DtParsererror (char const *msg);
     61      1.1    jruoho extern char                 *DtParsertext;
     62      1.1    jruoho extern DT_FIELD             *Gbl_CurrentField;
     63      1.1    jruoho 
     64      1.1    jruoho UINT64                      DtParserResult; /* Expression return value */
     65      1.1    jruoho 
     66      1.1    jruoho /* Bison/yacc configuration */
     67      1.1    jruoho 
     68      1.1    jruoho #define yytname             DtParsername
     69      1.1    jruoho #define YYDEBUG             1               /* Enable debug output */
     70      1.1    jruoho #define YYERROR_VERBOSE     1               /* Verbose error messages */
     71      1.1    jruoho #define YYFLAG              -32768
     72      1.1    jruoho 
     73  1.1.1.2  christos /* Define YYMALLOC/YYFREE to prevent redefinition errors  */
     74  1.1.1.2  christos 
     75  1.1.1.2  christos #define YYMALLOC            malloc
     76  1.1.1.2  christos #define YYFREE              free
     77      1.1    jruoho %}
     78      1.1    jruoho 
     79      1.1    jruoho %union
     80      1.1    jruoho {
     81      1.1    jruoho      UINT64                 value;
     82      1.1    jruoho      UINT32                 op;
     83      1.1    jruoho }
     84      1.1    jruoho 
     85      1.1    jruoho /*! [Begin] no source code translation */
     86      1.1    jruoho 
     87      1.1    jruoho %type  <value>  Expression
     88      1.1    jruoho 
     89      1.1    jruoho %token <op>     EXPOP_EOF
     90      1.1    jruoho %token <op>     EXPOP_NEW_LINE
     91      1.1    jruoho %token <op>     EXPOP_NUMBER
     92      1.1    jruoho %token <op>     EXPOP_HEX_NUMBER
     93      1.1    jruoho %token <op>     EXPOP_DECIMAL_NUMBER
     94      1.1    jruoho %token <op>     EXPOP_LABEL
     95      1.1    jruoho %token <op>     EXPOP_PAREN_OPEN
     96      1.1    jruoho %token <op>     EXPOP_PAREN_CLOSE
     97      1.1    jruoho 
     98      1.1    jruoho %left <op>      EXPOP_LOGICAL_OR
     99      1.1    jruoho %left <op>      EXPOP_LOGICAL_AND
    100      1.1    jruoho %left <op>      EXPOP_OR
    101      1.1    jruoho %left <op>      EXPOP_XOR
    102      1.1    jruoho %left <op>      EXPOP_AND
    103      1.1    jruoho %left <op>      EXPOP_EQUAL EXPOP_NOT_EQUAL
    104      1.1    jruoho %left <op>      EXPOP_GREATER EXPOP_LESS EXPOP_GREATER_EQUAL EXPOP_LESS_EQUAL
    105      1.1    jruoho %left <op>      EXPOP_SHIFT_RIGHT EXPOP_SHIFT_LEFT
    106      1.1    jruoho %left <op>      EXPOP_ADD EXPOP_SUBTRACT
    107      1.1    jruoho %left <op>      EXPOP_MULTIPLY EXPOP_DIVIDE EXPOP_MODULO
    108      1.1    jruoho %right <op>     EXPOP_ONES_COMPLIMENT EXPOP_LOGICAL_NOT
    109      1.1    jruoho 
    110      1.1    jruoho %%
    111      1.1    jruoho 
    112      1.1    jruoho /*
    113      1.1    jruoho  *  Operator precedence rules (from K&R)
    114      1.1    jruoho  *
    115      1.1    jruoho  *  1)      ( )
    116      1.1    jruoho  *  2)      ! ~ (unary operators that are supported here)
    117      1.1    jruoho  *  3)      *   /   %
    118      1.1    jruoho  *  4)      +   -
    119      1.1    jruoho  *  5)      >>  <<
    120      1.1    jruoho  *  6)      <   >   <=  >=
    121      1.1    jruoho  *  7)      ==  !=
    122      1.1    jruoho  *  8)      &
    123      1.1    jruoho  *  9)      ^
    124      1.1    jruoho  *  10)     |
    125      1.1    jruoho  *  11)     &&
    126      1.1    jruoho  *  12)     ||
    127      1.1    jruoho  */
    128      1.1    jruoho Value
    129      1.1    jruoho     : Expression EXPOP_NEW_LINE                     { DtParserResult=$1; return 0; } /* End of line (newline) */
    130      1.1    jruoho     | Expression EXPOP_EOF                          { DtParserResult=$1; return 0; } /* End of string (0) */
    131      1.1    jruoho     ;
    132      1.1    jruoho 
    133      1.1    jruoho Expression
    134      1.1    jruoho 
    135      1.1    jruoho       /* Unary operators */
    136      1.1    jruoho 
    137      1.1    jruoho     : EXPOP_LOGICAL_NOT         Expression          { $$ = DtDoOperator ($2, EXPOP_LOGICAL_NOT,     $2);}
    138      1.1    jruoho     | EXPOP_ONES_COMPLIMENT     Expression          { $$ = DtDoOperator ($2, EXPOP_ONES_COMPLIMENT, $2);}
    139      1.1    jruoho 
    140      1.1    jruoho       /* Binary operators */
    141      1.1    jruoho 
    142      1.1    jruoho     | Expression EXPOP_MULTIPLY         Expression  { $$ = DtDoOperator ($1, EXPOP_MULTIPLY,        $3);}
    143      1.1    jruoho     | Expression EXPOP_DIVIDE           Expression  { $$ = DtDoOperator ($1, EXPOP_DIVIDE,          $3);}
    144      1.1    jruoho     | Expression EXPOP_MODULO           Expression  { $$ = DtDoOperator ($1, EXPOP_MODULO,          $3);}
    145      1.1    jruoho     | Expression EXPOP_ADD              Expression  { $$ = DtDoOperator ($1, EXPOP_ADD,             $3);}
    146      1.1    jruoho     | Expression EXPOP_SUBTRACT         Expression  { $$ = DtDoOperator ($1, EXPOP_SUBTRACT,        $3);}
    147      1.1    jruoho     | Expression EXPOP_SHIFT_RIGHT      Expression  { $$ = DtDoOperator ($1, EXPOP_SHIFT_RIGHT,     $3);}
    148      1.1    jruoho     | Expression EXPOP_SHIFT_LEFT       Expression  { $$ = DtDoOperator ($1, EXPOP_SHIFT_LEFT,      $3);}
    149      1.1    jruoho     | Expression EXPOP_GREATER          Expression  { $$ = DtDoOperator ($1, EXPOP_GREATER,         $3);}
    150      1.1    jruoho     | Expression EXPOP_LESS             Expression  { $$ = DtDoOperator ($1, EXPOP_LESS,            $3);}
    151      1.1    jruoho     | Expression EXPOP_GREATER_EQUAL    Expression  { $$ = DtDoOperator ($1, EXPOP_GREATER_EQUAL,   $3);}
    152      1.1    jruoho     | Expression EXPOP_LESS_EQUAL       Expression  { $$ = DtDoOperator ($1, EXPOP_LESS_EQUAL,      $3);}
    153      1.1    jruoho     | Expression EXPOP_EQUAL            Expression  { $$ = DtDoOperator ($1, EXPOP_EQUAL,           $3);}
    154      1.1    jruoho     | Expression EXPOP_NOT_EQUAL        Expression  { $$ = DtDoOperator ($1, EXPOP_NOT_EQUAL,       $3);}
    155      1.1    jruoho     | Expression EXPOP_AND              Expression  { $$ = DtDoOperator ($1, EXPOP_AND,             $3);}
    156      1.1    jruoho     | Expression EXPOP_XOR              Expression  { $$ = DtDoOperator ($1, EXPOP_XOR,             $3);}
    157      1.1    jruoho     | Expression EXPOP_OR               Expression  { $$ = DtDoOperator ($1, EXPOP_OR,              $3);}
    158      1.1    jruoho     | Expression EXPOP_LOGICAL_AND      Expression  { $$ = DtDoOperator ($1, EXPOP_LOGICAL_AND,     $3);}
    159      1.1    jruoho     | Expression EXPOP_LOGICAL_OR       Expression  { $$ = DtDoOperator ($1, EXPOP_LOGICAL_OR,      $3);}
    160      1.1    jruoho 
    161      1.1    jruoho       /* Parentheses: '(' Expression ')' */
    162      1.1    jruoho 
    163      1.1    jruoho     | EXPOP_PAREN_OPEN          Expression
    164      1.1    jruoho         EXPOP_PAREN_CLOSE                           { $$ = $2;}
    165      1.1    jruoho 
    166      1.1    jruoho       /* Label references (prefixed with $) */
    167      1.1    jruoho 
    168      1.1    jruoho     | EXPOP_LABEL                                   { $$ = DtResolveLabel (DtParsertext);}
    169      1.1    jruoho 
    170      1.1    jruoho       /* Default base for a non-prefixed integer is 16 */
    171      1.1    jruoho 
    172  1.1.1.5  christos     | EXPOP_NUMBER                                  { stroul64 (DtParsertext, 16, &$$);}
    173      1.1    jruoho 
    174      1.1    jruoho       /* Standard hex number (0x1234) */
    175      1.1    jruoho 
    176  1.1.1.5  christos     | EXPOP_HEX_NUMBER                              { stroul64 (DtParsertext, 16, &$$);}
    177      1.1    jruoho 
    178  1.1.1.5  christos       /* TBD: Decimal number with prefix (0d1234) - Not supported by stroul64 at this time */
    179      1.1    jruoho 
    180  1.1.1.5  christos     | EXPOP_DECIMAL_NUMBER                          { stroul64 (DtParsertext, 10, &$$);}
    181      1.1    jruoho     ;
    182      1.1    jruoho %%
    183      1.1    jruoho 
    184      1.1    jruoho /*! [End] no source code translation !*/
    185      1.1    jruoho 
    186      1.1    jruoho /*
    187      1.1    jruoho  * Local support functions, including parser entry point
    188      1.1    jruoho  */
    189      1.1    jruoho #define PR_FIRST_PARSE_OPCODE   EXPOP_EOF
    190      1.1    jruoho #define PR_YYTNAME_START        3
    191      1.1    jruoho 
    192      1.1    jruoho 
    193      1.1    jruoho /******************************************************************************
    194      1.1    jruoho  *
    195      1.1    jruoho  * FUNCTION:    DtParsererror
    196      1.1    jruoho  *
    197      1.1    jruoho  * PARAMETERS:  Message             - Parser-generated error message
    198      1.1    jruoho  *
    199      1.1    jruoho  * RETURN:      None
    200      1.1    jruoho  *
    201      1.1    jruoho  * DESCRIPTION: Handler for parser errors
    202      1.1    jruoho  *
    203      1.1    jruoho  *****************************************************************************/
    204      1.1    jruoho 
    205      1.1    jruoho void
    206      1.1    jruoho DtParsererror (
    207      1.1    jruoho     char const              *Message)
    208      1.1    jruoho {
    209      1.1    jruoho     DtError (ASL_ERROR, ASL_MSG_SYNTAX,
    210      1.1    jruoho         Gbl_CurrentField, (char *) Message);
    211      1.1    jruoho }
    212      1.1    jruoho 
    213      1.1    jruoho 
    214      1.1    jruoho /******************************************************************************
    215      1.1    jruoho  *
    216      1.1    jruoho  * FUNCTION:    DtGetOpName
    217      1.1    jruoho  *
    218      1.1    jruoho  * PARAMETERS:  ParseOpcode         - Parser token (EXPOP_*)
    219      1.1    jruoho  *
    220      1.1    jruoho  * RETURN:      Pointer to the opcode name
    221      1.1    jruoho  *
    222      1.1    jruoho  * DESCRIPTION: Get the ascii name of the parse opcode for debug output
    223      1.1    jruoho  *
    224      1.1    jruoho  *****************************************************************************/
    225      1.1    jruoho 
    226      1.1    jruoho char *
    227      1.1    jruoho DtGetOpName (
    228      1.1    jruoho     UINT32                  ParseOpcode)
    229      1.1    jruoho {
    230      1.1    jruoho #ifdef ASL_YYTNAME_START
    231      1.1    jruoho     /*
    232      1.1    jruoho      * First entries (PR_YYTNAME_START) in yytname are special reserved names.
    233      1.1    jruoho      * Ignore first 6 characters of name (EXPOP_)
    234      1.1    jruoho      */
    235      1.1    jruoho     return ((char *) yytname
    236      1.1    jruoho         [(ParseOpcode - PR_FIRST_PARSE_OPCODE) + PR_YYTNAME_START] + 6);
    237      1.1    jruoho #else
    238      1.1    jruoho     return ("[Unknown parser generator]");
    239      1.1    jruoho #endif
    240      1.1    jruoho }
    241      1.1    jruoho 
    242      1.1    jruoho 
    243      1.1    jruoho /******************************************************************************
    244      1.1    jruoho  *
    245      1.1    jruoho  * FUNCTION:    DtEvaluateExpression
    246      1.1    jruoho  *
    247      1.1    jruoho  * PARAMETERS:  ExprString          - Expression to be evaluated. Must be
    248      1.1    jruoho  *                                    terminated by either a newline or a NUL
    249      1.1    jruoho  *                                    string terminator
    250      1.1    jruoho  *
    251      1.1    jruoho  * RETURN:      64-bit value for the expression
    252      1.1    jruoho  *
    253      1.1    jruoho  * DESCRIPTION: Main entry point for the DT expression parser
    254      1.1    jruoho  *
    255      1.1    jruoho  *****************************************************************************/
    256      1.1    jruoho 
    257      1.1    jruoho UINT64
    258      1.1    jruoho DtEvaluateExpression (
    259      1.1    jruoho     char                    *ExprString)
    260      1.1    jruoho {
    261      1.1    jruoho 
    262      1.1    jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    263      1.1    jruoho         "**** Input expression: %s  (Base 16)\n", ExprString);
    264      1.1    jruoho 
    265      1.1    jruoho     /* Point lexer to the input string */
    266      1.1    jruoho 
    267      1.1    jruoho     if (DtInitLexer (ExprString))
    268      1.1    jruoho     {
    269      1.1    jruoho         DtError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
    270      1.1    jruoho             Gbl_CurrentField, "Could not initialize lexer");
    271      1.1    jruoho         return (0);
    272      1.1    jruoho     }
    273      1.1    jruoho 
    274      1.1    jruoho     /* Parse/Evaluate the input string (value returned in DtParserResult) */
    275      1.1    jruoho 
    276      1.1    jruoho     DtParserparse ();
    277      1.1    jruoho     DtTerminateLexer ();
    278      1.1    jruoho 
    279      1.1    jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    280      1.1    jruoho         "**** Parser returned value: %u (%8.8X%8.8X)\n",
    281      1.1    jruoho         (UINT32) DtParserResult, ACPI_FORMAT_UINT64 (DtParserResult));
    282      1.1    jruoho 
    283      1.1    jruoho     return (DtParserResult);
    284      1.1    jruoho }
    285