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