Home | History | Annotate | Line # | Download | only in compiler
preprocess.h revision 1.1.1.12
      1 /******************************************************************************
      2  *
      3  * Module Name: preprocess.h - header for iASL Preprocessor
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2021, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #define __PREPROCESS_H__
     45 
     46 #ifndef _PREPROCESS
     47 #define _PREPROCESS
     48 
     49 #undef PR_EXTERN
     50 
     51 #ifdef _DECLARE_PR_GLOBALS
     52 #define PR_EXTERN
     53 #define PR_INIT_GLOBAL(a,b)         (a)=(b)
     54 #else
     55 #define PR_EXTERN                   extern
     56 #define PR_INIT_GLOBAL(a,b)         (a)
     57 #endif
     58 
     59 
     60 /*
     61  * Configuration
     62  */
     63 #define PR_MAX_MACRO_ARGS       32              /* Max number of macro args */
     64 #define PR_MAX_ARG_INSTANCES    24              /* Max instances of any one arg */
     65 #define PR_LINES_PER_BLOCK      4096            /* Max input source lines per block */
     66 
     67 
     68 /*
     69  * Local defines and macros
     70  */
     71 #define PR_TOKEN_SEPARATORS     " ,(){}\t\n"
     72 #define PR_MACRO_SEPARATORS     " ,(){}~!*/%+-<>=&^|\"\t\n"
     73 #define PR_MACRO_ARGUMENTS      " ,\t\n"
     74 #define PR_EXPR_SEPARATORS      " ,(){}~!*/%+-<>=&^|\"\t\n"
     75 
     76 #define PR_PREFIX_ID            "Pr(%.4u) - "             /* Used for debug output */
     77 
     78 #define THIS_TOKEN_OFFSET(t)    ((AslGbl_MainTokenBuffer - t) + 1)
     79 
     80 
     81 /*
     82  * Preprocessor structures
     83  */
     84 typedef struct pr_macro_arg
     85 {
     86     char                        *Name;
     87     UINT32                      Offset[PR_MAX_ARG_INSTANCES];
     88     UINT16                      UseCount;
     89 
     90 } PR_MACRO_ARG;
     91 
     92 typedef struct pr_define_info
     93 {
     94     struct pr_define_info       *Previous;
     95     struct pr_define_info       *Next;
     96     char                        *Identifier;
     97     char                        *Replacement;
     98     char                        *Body;          /* Macro body */
     99     PR_MACRO_ARG                *Args;          /* Macro arg list */
    100     UINT16                      ArgCount;       /* Macro arg count */
    101     BOOLEAN                     Persist;        /* Keep for entire compiler run */
    102 
    103 } PR_DEFINE_INFO;
    104 
    105 typedef struct pr_directive_info
    106 {
    107     char                        *Name;          /* Directive name */
    108     UINT8                       ArgCount;       /* Required # of args */
    109 
    110 } PR_DIRECTIVE_INFO;
    111 
    112 typedef struct pr_operator_info
    113 {
    114     char                        *Op;
    115 
    116 } PR_OPERATOR_INFO;
    117 
    118 typedef struct pr_file_node
    119 {
    120     struct pr_file_node         *Next;
    121     FILE                        *File;
    122     char                        *Filename;
    123     UINT32                      CurrentLineNumber;
    124 
    125 } PR_FILE_NODE;
    126 
    127 #define MAX_ARGUMENT_LENGTH     24
    128 
    129 typedef struct directive_info
    130 {
    131     struct directive_info       *Next;
    132     char                        Argument[MAX_ARGUMENT_LENGTH];
    133     int                         Directive;
    134     BOOLEAN                     IgnoringThisCodeBlock;
    135 
    136 } DIRECTIVE_INFO;
    137 
    138 
    139 /*
    140  * Globals
    141  */
    142 PR_EXTERN char                  PR_INIT_GLOBAL (*AslGbl_MainTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    143 PR_EXTERN char                  PR_INIT_GLOBAL (*AslGbl_MacroTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    144 PR_EXTERN char                  PR_INIT_GLOBAL (*AslGbl_ExpressionTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    145 
    146 PR_EXTERN UINT32                AslGbl_PreprocessorLineNumber;
    147 PR_EXTERN int                   AslGbl_IfDepth;
    148 PR_EXTERN PR_FILE_NODE          *AslGbl_InputFileList;
    149 PR_EXTERN BOOLEAN               PR_INIT_GLOBAL (AslGbl_PreprocessorError, FALSE);
    150 PR_EXTERN BOOLEAN               PR_INIT_GLOBAL (AslGbl_IgnoringThisCodeBlock, FALSE);
    151 PR_EXTERN PR_DEFINE_INFO        PR_INIT_GLOBAL (*AslGbl_DefineList, NULL);
    152 PR_EXTERN DIRECTIVE_INFO        PR_INIT_GLOBAL (*AslGbl_DirectiveStack, NULL);
    153 
    154 #if 0 /* TBD for macros */
    155 PR_EXTERN char                  PR_INIT_GLOBAL (*XXXEvalBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    156 #endif
    157 
    158 
    159 /*
    160  * prscan - Preprocessor entry
    161  */
    162 void
    163 PrInitializePreprocessor (
    164     void);
    165 
    166 void
    167 PrInitializeGlobals (
    168     void);
    169 
    170 void
    171 PrTerminatePreprocessor (
    172     void);
    173 
    174 void
    175 PrDoPreprocess (
    176     void);
    177 
    178 UINT64
    179 PrIsDefined (
    180     char                    *Identifier);
    181 
    182 UINT64
    183 PrResolveDefine (
    184     char                    *Identifier);
    185 
    186 int
    187 PrInitLexer (
    188     char                    *String);
    189 
    190 void
    191 PrTerminateLexer (
    192     void);
    193 
    194 
    195 /*
    196  * prmacros - Support for #defines and macros
    197  */
    198 void
    199 PrDumpPredefinedNames (
    200     void);
    201 
    202 PR_DEFINE_INFO *
    203 PrAddDefine (
    204     char                    *Token,
    205     char                    *Token2,
    206     BOOLEAN                 Persist);
    207 
    208 void
    209 PrRemoveDefine (
    210     char                    *DefineName);
    211 
    212 PR_DEFINE_INFO *
    213 PrMatchDefine (
    214     char                    *MatchString);
    215 
    216 void
    217 PrAddMacro (
    218     char                    *Name,
    219     char                    **Next);
    220 
    221 void
    222 PrDoMacroInvocation (
    223     char                    *TokenBuffer,
    224     char                    *MacroStart,
    225     PR_DEFINE_INFO          *DefineInfo,
    226     char                    **Next);
    227 
    228 
    229 /*
    230  * prexpress - #if expression support
    231  */
    232 ACPI_STATUS
    233 PrResolveIntegerExpression (
    234     char                    *Line,
    235     UINT64                  *ReturnValue);
    236 
    237 char *
    238 PrPrioritizeExpression (
    239     char                    *OriginalLine);
    240 
    241 /*
    242  * prparser - lex/yacc expression parser
    243  */
    244 UINT64
    245 PrEvaluateExpression (
    246     char                    *ExprString);
    247 
    248 
    249 /*
    250  * prutils - Preprocessor utilities
    251  */
    252 char *
    253 PrGetNextToken (
    254     char                    *Buffer,
    255     char                    *MatchString,
    256     char                    **Next);
    257 
    258 void
    259 PrError (
    260     UINT8                   Level,
    261     UINT16                  MessageId,
    262     UINT32                  Column);
    263 
    264 void
    265 PrReplaceData (
    266     char                    *Buffer,
    267     UINT32                  LengthToRemove,
    268     char                    *BufferToAdd,
    269     UINT32                  LengthToAdd);
    270 
    271 FILE *
    272 PrOpenIncludeFile (
    273     char                    *Filename,
    274     char                    *OpenMode,
    275     char                    **FullPathname);
    276 
    277 FILE *
    278 PrOpenIncludeWithPrefix (
    279     char                    *PrefixDir,
    280     char                    *Filename,
    281     char                    *OpenMode,
    282     char                    **FullPathname);
    283 
    284 void
    285 PrPushInputFileStack (
    286     FILE                    *InputFile,
    287     char                    *Filename);
    288 
    289 BOOLEAN
    290 PrPopInputFileStack (
    291     void);
    292 
    293 #endif
    294