1e5412f1eSSascha Wildner %{ 2e5412f1eSSascha Wildner /****************************************************************************** 3e5412f1eSSascha Wildner * 4e5412f1eSSascha Wildner * Module Name: dtcompilerparser.l - Flex input file for table compiler lexer 5e5412f1eSSascha Wildner * 6e5412f1eSSascha Wildner *****************************************************************************/ 7e5412f1eSSascha Wildner 8e5412f1eSSascha Wildner /****************************************************************************** 9e5412f1eSSascha Wildner * 10e5412f1eSSascha Wildner * 1. Copyright Notice 11e5412f1eSSascha Wildner * 12*383048acSSascha Wildner * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp. 13e5412f1eSSascha Wildner * All rights reserved. 14e5412f1eSSascha Wildner * 15e5412f1eSSascha Wildner * 2. License 16e5412f1eSSascha Wildner * 17e5412f1eSSascha Wildner * 2.1. This is your license from Intel Corp. under its intellectual property 18e5412f1eSSascha Wildner * rights. You may have additional license terms from the party that provided 19e5412f1eSSascha Wildner * you this software, covering your right to use that party's intellectual 20e5412f1eSSascha Wildner * property rights. 21e5412f1eSSascha Wildner * 22e5412f1eSSascha Wildner * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23e5412f1eSSascha Wildner * copy of the source code appearing in this file ("Covered Code") an 24e5412f1eSSascha Wildner * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25e5412f1eSSascha Wildner * base code distributed originally by Intel ("Original Intel Code") to copy, 26e5412f1eSSascha Wildner * make derivatives, distribute, use and display any portion of the Covered 27e5412f1eSSascha Wildner * Code in any form, with the right to sublicense such rights; and 28e5412f1eSSascha Wildner * 29e5412f1eSSascha Wildner * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30e5412f1eSSascha Wildner * license (with the right to sublicense), under only those claims of Intel 31e5412f1eSSascha Wildner * patents that are infringed by the Original Intel Code, to make, use, sell, 32e5412f1eSSascha Wildner * offer to sell, and import the Covered Code and derivative works thereof 33e5412f1eSSascha Wildner * solely to the minimum extent necessary to exercise the above copyright 34e5412f1eSSascha Wildner * license, and in no event shall the patent license extend to any additions 35e5412f1eSSascha Wildner * to or modifications of the Original Intel Code. No other license or right 36e5412f1eSSascha Wildner * is granted directly or by implication, estoppel or otherwise; 37e5412f1eSSascha Wildner * 38e5412f1eSSascha Wildner * The above copyright and patent license is granted only if the following 39e5412f1eSSascha Wildner * conditions are met: 40e5412f1eSSascha Wildner * 41e5412f1eSSascha Wildner * 3. Conditions 42e5412f1eSSascha Wildner * 43e5412f1eSSascha Wildner * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44e5412f1eSSascha Wildner * Redistribution of source code of any substantial portion of the Covered 45e5412f1eSSascha Wildner * Code or modification with rights to further distribute source must include 46e5412f1eSSascha Wildner * the above Copyright Notice, the above License, this list of Conditions, 47e5412f1eSSascha Wildner * and the following Disclaimer and Export Compliance provision. In addition, 48e5412f1eSSascha Wildner * Licensee must cause all Covered Code to which Licensee contributes to 49e5412f1eSSascha Wildner * contain a file documenting the changes Licensee made to create that Covered 50e5412f1eSSascha Wildner * Code and the date of any change. Licensee must include in that file the 51e5412f1eSSascha Wildner * documentation of any changes made by any predecessor Licensee. Licensee 52e5412f1eSSascha Wildner * must include a prominent statement that the modification is derived, 53e5412f1eSSascha Wildner * directly or indirectly, from Original Intel Code. 54e5412f1eSSascha Wildner * 55e5412f1eSSascha Wildner * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56e5412f1eSSascha Wildner * Redistribution of source code of any substantial portion of the Covered 57e5412f1eSSascha Wildner * Code or modification without rights to further distribute source must 58e5412f1eSSascha Wildner * include the following Disclaimer and Export Compliance provision in the 59e5412f1eSSascha Wildner * documentation and/or other materials provided with distribution. In 60e5412f1eSSascha Wildner * addition, Licensee may not authorize further sublicense of source of any 61e5412f1eSSascha Wildner * portion of the Covered Code, and must include terms to the effect that the 62e5412f1eSSascha Wildner * license from Licensee to its licensee is limited to the intellectual 63e5412f1eSSascha Wildner * property embodied in the software Licensee provides to its licensee, and 64e5412f1eSSascha Wildner * not to intellectual property embodied in modifications its licensee may 65e5412f1eSSascha Wildner * make. 66e5412f1eSSascha Wildner * 67e5412f1eSSascha Wildner * 3.3. Redistribution of Executable. Redistribution in executable form of any 68e5412f1eSSascha Wildner * substantial portion of the Covered Code or modification must reproduce the 69e5412f1eSSascha Wildner * above Copyright Notice, and the following Disclaimer and Export Compliance 70e5412f1eSSascha Wildner * provision in the documentation and/or other materials provided with the 71e5412f1eSSascha Wildner * distribution. 72e5412f1eSSascha Wildner * 73e5412f1eSSascha Wildner * 3.4. Intel retains all right, title, and interest in and to the Original 74e5412f1eSSascha Wildner * Intel Code. 75e5412f1eSSascha Wildner * 76e5412f1eSSascha Wildner * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77e5412f1eSSascha Wildner * Intel shall be used in advertising or otherwise to promote the sale, use or 78e5412f1eSSascha Wildner * other dealings in products derived from or relating to the Covered Code 79e5412f1eSSascha Wildner * without prior written authorization from Intel. 80e5412f1eSSascha Wildner * 81e5412f1eSSascha Wildner * 4. Disclaimer and Export Compliance 82e5412f1eSSascha Wildner * 83e5412f1eSSascha Wildner * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84e5412f1eSSascha Wildner * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85e5412f1eSSascha Wildner * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86e5412f1eSSascha Wildner * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87e5412f1eSSascha Wildner * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88e5412f1eSSascha Wildner * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89e5412f1eSSascha Wildner * PARTICULAR PURPOSE. 90e5412f1eSSascha Wildner * 91e5412f1eSSascha Wildner * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92e5412f1eSSascha Wildner * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93e5412f1eSSascha Wildner * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94e5412f1eSSascha Wildner * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95e5412f1eSSascha Wildner * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96e5412f1eSSascha Wildner * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97e5412f1eSSascha Wildner * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98e5412f1eSSascha Wildner * LIMITED REMEDY. 99e5412f1eSSascha Wildner * 100e5412f1eSSascha Wildner * 4.3. Licensee shall not export, either directly or indirectly, any of this 101e5412f1eSSascha Wildner * software or system incorporating such software without first obtaining any 102e5412f1eSSascha Wildner * required license or other approval from the U. S. Department of Commerce or 103e5412f1eSSascha Wildner * any other agency or department of the United States Government. In the 104e5412f1eSSascha Wildner * event Licensee exports any such software from the United States or 105e5412f1eSSascha Wildner * re-exports any such software from a foreign destination, Licensee shall 106e5412f1eSSascha Wildner * ensure that the distribution and export/re-export of the software is in 107e5412f1eSSascha Wildner * compliance with all laws, regulations, orders, or other restrictions of the 108e5412f1eSSascha Wildner * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109e5412f1eSSascha Wildner * any of its subsidiaries will export/re-export any technical data, process, 110e5412f1eSSascha Wildner * software, or service, directly or indirectly, to any country for which the 111e5412f1eSSascha Wildner * United States government or any agency thereof requires an export license, 112e5412f1eSSascha Wildner * other governmental approval, or letter of assurance, without first obtaining 113e5412f1eSSascha Wildner * such license, approval or letter. 114e5412f1eSSascha Wildner * 115e5412f1eSSascha Wildner ***************************************************************************** 116e5412f1eSSascha Wildner * 117e5412f1eSSascha Wildner * Alternatively, you may choose to be licensed under the terms of the 118e5412f1eSSascha Wildner * following license: 119e5412f1eSSascha Wildner * 120e5412f1eSSascha Wildner * Redistribution and use in source and binary forms, with or without 121e5412f1eSSascha Wildner * modification, are permitted provided that the following conditions 122e5412f1eSSascha Wildner * are met: 123e5412f1eSSascha Wildner * 1. Redistributions of source code must retain the above copyright 124e5412f1eSSascha Wildner * notice, this list of conditions, and the following disclaimer, 125e5412f1eSSascha Wildner * without modification. 126e5412f1eSSascha Wildner * 2. Redistributions in binary form must reproduce at minimum a disclaimer 127e5412f1eSSascha Wildner * substantially similar to the "NO WARRANTY" disclaimer below 128e5412f1eSSascha Wildner * ("Disclaimer") and any redistribution must be conditioned upon 129e5412f1eSSascha Wildner * including a substantially similar Disclaimer requirement for further 130e5412f1eSSascha Wildner * binary redistribution. 131e5412f1eSSascha Wildner * 3. Neither the names of the above-listed copyright holders nor the names 132e5412f1eSSascha Wildner * of any contributors may be used to endorse or promote products derived 133e5412f1eSSascha Wildner * from this software without specific prior written permission. 134e5412f1eSSascha Wildner * 135e5412f1eSSascha Wildner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 136e5412f1eSSascha Wildner * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 137e5412f1eSSascha Wildner * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 138e5412f1eSSascha Wildner * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 139e5412f1eSSascha Wildner * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 140e5412f1eSSascha Wildner * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 141e5412f1eSSascha Wildner * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 142e5412f1eSSascha Wildner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 143e5412f1eSSascha Wildner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 144e5412f1eSSascha Wildner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 145e5412f1eSSascha Wildner * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 146e5412f1eSSascha Wildner * 147e5412f1eSSascha Wildner * Alternatively, you may choose to be licensed under the terms of the 148e5412f1eSSascha Wildner * GNU General Public License ("GPL") version 2 as published by the Free 149e5412f1eSSascha Wildner * Software Foundation. 150e5412f1eSSascha Wildner * 151e5412f1eSSascha Wildner *****************************************************************************/ 152e5412f1eSSascha Wildner 153e5412f1eSSascha Wildner #include "aslcompiler.h" 154e5412f1eSSascha Wildner #include "dtcompilerparser.y.h" 155e5412f1eSSascha Wildner 156e5412f1eSSascha Wildner 157e5412f1eSSascha Wildner #define _COMPONENT ACPI_COMPILER 158e5412f1eSSascha Wildner ACPI_MODULE_NAME ("dtcompilerscanner") 159e5412f1eSSascha Wildner 160e5412f1eSSascha Wildner /* handle locations */ 161e5412f1eSSascha Wildner 162e5412f1eSSascha Wildner int DtCompilerParsercolumn = 1; 163e5412f1eSSascha Wildner int DtLabelByteOffset = 0; 164e5412f1eSSascha Wildner int DtCompilerParserByteOffset = 0; 165e5412f1eSSascha Wildner 166e5412f1eSSascha Wildner UINT32 DtTokenFirstLine = 0; 167e5412f1eSSascha Wildner UINT32 DtTokenFirstColumn = 0; 168e5412f1eSSascha Wildner 169e5412f1eSSascha Wildner #define YY_USER_ACTION \ 170e5412f1eSSascha Wildner DtTokenFirstLine = DtCompilerParserlineno; \ 171e5412f1eSSascha Wildner DtTokenFirstColumn = DtCompilerParsercolumn; \ 172e5412f1eSSascha Wildner DtCompilerParsercolumn += DtCompilerParserleng; \ 173e5412f1eSSascha Wildner DtCompilerParserByteOffset += DtCompilerParserleng; \ 174e5412f1eSSascha Wildner DbgPrint (ASL_PARSE_OUTPUT,\ 175e5412f1eSSascha Wildner "user action occurred. DtCompilerParserlloc.first_line: %u\n",\ 176e5412f1eSSascha Wildner DtTokenFirstLine); 177e5412f1eSSascha Wildner %} 178e5412f1eSSascha Wildner 179e5412f1eSSascha Wildner %option nounput noinput yylineno 180e5412f1eSSascha Wildner 181e5412f1eSSascha Wildner /* Indicates a state used for parsing multiline C comments */ 182e5412f1eSSascha Wildner %x ML_COMMENT 183e5412f1eSSascha Wildner %x DATA_STATE 184e5412f1eSSascha Wildner 185e5412f1eSSascha Wildner WhiteSpace [ \t\v\r]+ 186e5412f1eSSascha Wildner NewLines [\n]+ 187e5412f1eSSascha Wildner 188e5412f1eSSascha Wildner /* Avoid ", \n, and [] as a part of label name. These are not valid characters of a label name */ 189e5412f1eSSascha Wildner LabelName [^ ":\n\[\]]([^":\n\[\]]*[^" :\n\[\]])? 190e5412f1eSSascha Wildner 191e5412f1eSSascha Wildner /* Avoid ", \n, \\, and [] as a part of data. These are not valid characters of data */ 192e5412f1eSSascha Wildner Data [^ \\":\n\[\]]([^":\n\[\]\\]*[^" :\n\[\]\\])? 193e5412f1eSSascha Wildner 194e5412f1eSSascha Wildner Text [^ ":\n][^":\n]* 195e5412f1eSSascha Wildner Comment \[[^\n\[\]]*\] 196e5412f1eSSascha Wildner CommentField {LabelName}{WhiteSpace}*:{WhiteSpace}{Comment}?$ 197e5412f1eSSascha Wildner 198e5412f1eSSascha Wildner 199e5412f1eSSascha Wildner %% 200e5412f1eSSascha Wildner 201e5412f1eSSascha Wildner <DATA_STATE>{WhiteSpace}"\\\n" { 202e5412f1eSSascha Wildner DbgPrint(ASL_PARSE_OUTPUT,"Continuation matched\n"); 203e5412f1eSSascha Wildner return (DT_PARSEOP_LINE_CONTINUATION); 204e5412f1eSSascha Wildner } 205e5412f1eSSascha Wildner 206e5412f1eSSascha Wildner ":" { 207e5412f1eSSascha Wildner DbgPrint(ASL_PARSE_OUTPUT, ": Matched\n"); 208e5412f1eSSascha Wildner BEGIN (DATA_STATE); 209e5412f1eSSascha Wildner return (':'); 210e5412f1eSSascha Wildner } 211e5412f1eSSascha Wildner 212e5412f1eSSascha Wildner <INITIAL,DATA_STATE>{WhiteSpace} { DbgPrint(ASL_PARSE_OUTPUT,"Whitespace matched\n"); } 213e5412f1eSSascha Wildner 214e5412f1eSSascha Wildner <INITIAL,DATA_STATE>{Comment} { DbgPrint(ASL_PARSE_OUTPUT,"Comment matched\n"); } 215e5412f1eSSascha Wildner 216e5412f1eSSascha Wildner "/*" { BEGIN (ML_COMMENT); } 217e5412f1eSSascha Wildner <ML_COMMENT>"*/" { BEGIN (INITIAL); } 218e5412f1eSSascha Wildner <ML_COMMENT>"*/\n" { BEGIN (INITIAL); } 219e5412f1eSSascha Wildner <ML_COMMENT>([^*]|\n)+|. /* Ignore */ 220e5412f1eSSascha Wildner "//".* /* Ignore */ 221e5412f1eSSascha Wildner 222e5412f1eSSascha Wildner 223e5412f1eSSascha Wildner <DATA_STATE>{Data} { 224e5412f1eSSascha Wildner char *s; 225e5412f1eSSascha Wildner int size = strlen (DtCompilerParsertext); 226e5412f1eSSascha Wildner s=UtLocalCacheCalloc (size + 1); 227e5412f1eSSascha Wildner AcpiUtSafeStrncpy (s, DtCompilerParsertext, size + 1); 228e5412f1eSSascha Wildner DtCompilerParserlval.s = s; 229e5412f1eSSascha Wildner DbgPrint (ASL_PARSE_OUTPUT, "Data: %s\n", s); 230e5412f1eSSascha Wildner return (DT_PARSEOP_DATA); 231e5412f1eSSascha Wildner } 232e5412f1eSSascha Wildner 233e5412f1eSSascha Wildner {CommentField} /* ignore */ 234e5412f1eSSascha Wildner 235e5412f1eSSascha Wildner {LabelName} { 236e5412f1eSSascha Wildner char *s; 237e5412f1eSSascha Wildner int size = strlen (DtCompilerParsertext); 238e5412f1eSSascha Wildner s=UtLocalCacheCalloc (size + 1); 239e5412f1eSSascha Wildner AcpiUtSafeStrncpy (s, DtCompilerParsertext, size + 1); 240e5412f1eSSascha Wildner DtCompilerParserlval.u = (DT_TABLE_UNIT *) UtLocalCacheCalloc (sizeof (DT_TABLE_UNIT)); 241e5412f1eSSascha Wildner DtCompilerParserlval.u->Value = s; 242e5412f1eSSascha Wildner DtCompilerParserlval.u->Line = DtCompilerParserlineno; 243e5412f1eSSascha Wildner DtCompilerParserlval.u->Column = DtCompilerParsercolumn; 244e5412f1eSSascha Wildner DtLabelByteOffset = DtCompilerParserByteOffset; 245e5412f1eSSascha Wildner DbgPrint (ASL_PARSE_OUTPUT, "Label: %s\n", s); 246e5412f1eSSascha Wildner return (DT_PARSEOP_LABEL); 247e5412f1eSSascha Wildner } 248e5412f1eSSascha Wildner 249e5412f1eSSascha Wildner 250e5412f1eSSascha Wildner <DATA_STATE>\"{Text}?\" { // remove outer quotes from the string, they are unnecessary 251e5412f1eSSascha Wildner char *s; 252e5412f1eSSascha Wildner int size = strlen (DtCompilerParsertext); 253e5412f1eSSascha Wildner s=UtLocalCacheCalloc (size - 1); 254e5412f1eSSascha Wildner AcpiUtSafeStrncpy (s, DtCompilerParsertext + 1, size - 1); 255e5412f1eSSascha Wildner DtCompilerParserlval.s = s; 256e5412f1eSSascha Wildner DbgPrint (ASL_PARSE_OUTPUT, "String Data: %s\n", s); 257e5412f1eSSascha Wildner BEGIN (INITIAL); 258e5412f1eSSascha Wildner return (DT_PARSEOP_STRING_DATA); 259e5412f1eSSascha Wildner } 260e5412f1eSSascha Wildner 261e5412f1eSSascha Wildner 262e5412f1eSSascha Wildner <INITIAL,DATA_STATE>{NewLines} { 263e5412f1eSSascha Wildner DbgPrint(ASL_PARSE_OUTPUT, 264e5412f1eSSascha Wildner "Newline matched (data state). Current line number: %u\n",DtCompilerParserlineno); 265e5412f1eSSascha Wildner BEGIN (INITIAL); DtCompilerParsercolumn = 1; 266e5412f1eSSascha Wildner } 267e5412f1eSSascha Wildner 268e5412f1eSSascha Wildner 269e5412f1eSSascha Wildner %% 270e5412f1eSSascha Wildner 271e5412f1eSSascha Wildner 272e5412f1eSSascha Wildner /* 273e5412f1eSSascha Wildner * Local support functions 274e5412f1eSSascha Wildner */ 275e5412f1eSSascha Wildner 276e5412f1eSSascha Wildner void 277e5412f1eSSascha Wildner DtCompilerInitLexer ( 278e5412f1eSSascha Wildner FILE *inFile) 279e5412f1eSSascha Wildner { 280e5412f1eSSascha Wildner yyin = inFile; 281e5412f1eSSascha Wildner } 282e5412f1eSSascha Wildner 283e5412f1eSSascha Wildner void 284e5412f1eSSascha Wildner DtCompilerTerminateLexer ( 285e5412f1eSSascha Wildner void) 286e5412f1eSSascha Wildner { 287e5412f1eSSascha Wildner /* 288e5412f1eSSascha Wildner * Flex/Bison increments the lineno for the EOF so decrement by 1 to get 289e5412f1eSSascha Wildner * the correct number of lines. 290e5412f1eSSascha Wildner */ 291e5412f1eSSascha Wildner AslGbl_CurrentLineNumber = DtCompilerParserlineno - 1; 292e5412f1eSSascha Wildner AslGbl_InputByteCount = DtCompilerParserByteOffset; 293e5412f1eSSascha Wildner } 294