Home | History | Annotate | Line # | Download | only in compiler
preprocess.h revision 1.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  christos  * Copyright (C) 2000 - 2013, 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  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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  christos #define THIS_TOKEN_OFFSET(t)    ((t-Gbl_MainTokenBuffer) + 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  christos #if 0 /* TBD for macros */
    143  1.1  christos PR_EXTERN char                  PR_INIT_GLOBAL (*XXXEvalBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    144  1.1  christos #endif
    145  1.1  christos 
    146  1.1  christos PR_EXTERN char                  PR_INIT_GLOBAL (*Gbl_MainTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    147  1.1  christos PR_EXTERN char                  PR_INIT_GLOBAL (*Gbl_MacroTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    148  1.1  christos PR_EXTERN char                  PR_INIT_GLOBAL (*Gbl_ExpressionTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
    149  1.1  christos 
    150  1.1  christos PR_EXTERN UINT32                Gbl_PreprocessorLineNumber;
    151  1.1  christos PR_EXTERN int                   Gbl_IfDepth;
    152  1.1  christos PR_EXTERN PR_FILE_NODE          *Gbl_InputFileList;
    153  1.1  christos PR_EXTERN PR_DEFINE_INFO        PR_INIT_GLOBAL (*Gbl_DefineList, NULL);
    154  1.1  christos PR_EXTERN BOOLEAN               PR_INIT_GLOBAL (Gbl_PreprocessorError, FALSE);
    155  1.1  christos PR_EXTERN BOOLEAN               PR_INIT_GLOBAL (Gbl_IgnoringThisCodeBlock, FALSE);
    156  1.1  christos PR_EXTERN DIRECTIVE_INFO        PR_INIT_GLOBAL (*Gbl_DirectiveStack, NULL);
    157  1.1  christos 
    158  1.1  christos /*
    159  1.1  christos  * prscan - Preprocessor entry
    160  1.1  christos  */
    161  1.1  christos void
    162  1.1  christos PrInitializePreprocessor (
    163  1.1  christos     void);
    164  1.1  christos 
    165  1.1  christos void
    166  1.1  christos PrInitializeGlobals (
    167  1.1  christos     void);
    168  1.1  christos 
    169  1.1  christos void
    170  1.1  christos PrTerminatePreprocessor (
    171  1.1  christos     void);
    172  1.1  christos 
    173  1.1  christos void
    174  1.1  christos PrDoPreprocess (
    175  1.1  christos     void);
    176  1.1  christos 
    177  1.1  christos UINT64
    178  1.1  christos PrIsDefined (
    179  1.1  christos     char                    *Identifier);
    180  1.1  christos 
    181  1.1  christos UINT64
    182  1.1  christos PrResolveDefine (
    183  1.1  christos     char                    *Identifier);
    184  1.1  christos 
    185  1.1  christos int
    186  1.1  christos PrInitLexer (
    187  1.1  christos     char                    *String);
    188  1.1  christos 
    189  1.1  christos void
    190  1.1  christos PrTerminateLexer (
    191  1.1  christos     void);
    192  1.1  christos 
    193  1.1  christos 
    194  1.1  christos /*
    195  1.1  christos  * prmacros - Support for #defines and macros
    196  1.1  christos  */
    197  1.1  christos void
    198  1.1  christos PrDumpPredefinedNames (
    199  1.1  christos     void);
    200  1.1  christos 
    201  1.1  christos PR_DEFINE_INFO *
    202  1.1  christos PrAddDefine (
    203  1.1  christos     char                    *Token,
    204  1.1  christos     char                    *Token2,
    205  1.1  christos     BOOLEAN                 Persist);
    206  1.1  christos 
    207  1.1  christos void
    208  1.1  christos PrRemoveDefine (
    209  1.1  christos     char                    *DefineName);
    210  1.1  christos 
    211  1.1  christos PR_DEFINE_INFO *
    212  1.1  christos PrMatchDefine (
    213  1.1  christos     char                    *MatchString);
    214  1.1  christos 
    215  1.1  christos void
    216  1.1  christos PrAddMacro (
    217  1.1  christos     char                    *Name,
    218  1.1  christos     char                    **Next);
    219  1.1  christos 
    220  1.1  christos void
    221  1.1  christos PrDoMacroInvocation (
    222  1.1  christos     char                    *TokenBuffer,
    223  1.1  christos     char                    *MacroStart,
    224  1.1  christos     PR_DEFINE_INFO          *DefineInfo,
    225  1.1  christos     char                    **Next);
    226  1.1  christos 
    227  1.1  christos 
    228  1.1  christos /*
    229  1.1  christos  * prexpress - #if expression support
    230  1.1  christos  */
    231  1.1  christos ACPI_STATUS
    232  1.1  christos PrResolveIntegerExpression (
    233  1.1  christos     char                    *Line,
    234  1.1  christos     UINT64                  *ReturnValue);
    235  1.1  christos 
    236  1.1  christos char *
    237  1.1  christos PrPrioritizeExpression (
    238  1.1  christos     char                    *OriginalLine);
    239  1.1  christos 
    240  1.1  christos /*
    241  1.1  christos  * prparser - lex/yacc expression parser
    242  1.1  christos  */
    243  1.1  christos UINT64
    244  1.1  christos PrEvaluateExpression (
    245  1.1  christos     char                    *ExprString);
    246  1.1  christos 
    247  1.1  christos 
    248  1.1  christos /*
    249  1.1  christos  * prutils - Preprocesor utilities
    250  1.1  christos  */
    251  1.1  christos char *
    252  1.1  christos PrGetNextToken (
    253  1.1  christos     char                    *Buffer,
    254  1.1  christos     char                    *MatchString,
    255  1.1  christos     char                    **Next);
    256  1.1  christos 
    257  1.1  christos void
    258  1.1  christos PrError (
    259  1.1  christos     UINT8                   Level,
    260  1.1  christos     UINT8                   MessageId,
    261  1.1  christos     UINT32                  Column);
    262  1.1  christos 
    263  1.1  christos void
    264  1.1  christos PrReplaceData (
    265  1.1  christos     char                    *Buffer,
    266  1.1  christos     UINT32                  LengthToRemove,
    267  1.1  christos     char                    *BufferToAdd,
    268  1.1  christos     UINT32                  LengthToAdd);
    269  1.1  christos 
    270  1.1  christos void
    271  1.1  christos PrOpenIncludeFile (
    272  1.1  christos     char                    *Filename);
    273  1.1  christos 
    274  1.1  christos FILE *
    275  1.1  christos PrOpenIncludeWithPrefix (
    276  1.1  christos     char                    *PrefixDir,
    277  1.1  christos     char                    *Filename);
    278  1.1  christos 
    279  1.1  christos void
    280  1.1  christos PrPushInputFileStack (
    281  1.1  christos     FILE                    *InputFile,
    282  1.1  christos     char                    *Filename);
    283  1.1  christos 
    284  1.1  christos BOOLEAN
    285  1.1  christos PrPopInputFileStack (
    286  1.1  christos     void);
    287  1.1  christos 
    288  1.1  christos #endif
    289