1233237Sjkim/******************************************************************************
2233237Sjkim *
3233237Sjkim * Module Name: preprocess.h - header for iASL Preprocessor
4233237Sjkim *
5233237Sjkim *****************************************************************************/
6233237Sjkim
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12233237Sjkim * All rights reserved.
13233237Sjkim *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119233237Sjkim * Redistribution and use in source and binary forms, with or without
120233237Sjkim * modification, are permitted provided that the following conditions
121233237Sjkim * are met:
122233237Sjkim * 1. Redistributions of source code must retain the above copyright
123233237Sjkim *    notice, this list of conditions, and the following disclaimer,
124233237Sjkim *    without modification.
125233237Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126233237Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127233237Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128233237Sjkim *    including a substantially similar Disclaimer requirement for further
129233237Sjkim *    binary redistribution.
130233237Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131233237Sjkim *    of any contributors may be used to endorse or promote products derived
132233237Sjkim *    from this software without specific prior written permission.
133233237Sjkim *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147233237Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148233237Sjkim * Software Foundation.
149233237Sjkim *
150316303Sjkim *****************************************************************************/
151233237Sjkim
152233237Sjkim#define __PREPROCESS_H__
153233237Sjkim
154233237Sjkim#ifndef _PREPROCESS
155233237Sjkim#define _PREPROCESS
156233237Sjkim
157233237Sjkim#undef PR_EXTERN
158233237Sjkim
159233237Sjkim#ifdef _DECLARE_PR_GLOBALS
160233237Sjkim#define PR_EXTERN
161233237Sjkim#define PR_INIT_GLOBAL(a,b)         (a)=(b)
162233237Sjkim#else
163233237Sjkim#define PR_EXTERN                   extern
164233237Sjkim#define PR_INIT_GLOBAL(a,b)         (a)
165233237Sjkim#endif
166233237Sjkim
167233237Sjkim
168233237Sjkim/*
169233237Sjkim * Configuration
170233237Sjkim */
171233237Sjkim#define PR_MAX_MACRO_ARGS       32              /* Max number of macro args */
172233237Sjkim#define PR_MAX_ARG_INSTANCES    24              /* Max instances of any one arg */
173233237Sjkim#define PR_LINES_PER_BLOCK      4096            /* Max input source lines per block */
174233237Sjkim
175233237Sjkim
176233237Sjkim/*
177233237Sjkim * Local defines and macros
178233237Sjkim */
179233237Sjkim#define PR_TOKEN_SEPARATORS     " ,(){}\t\n"
180233237Sjkim#define PR_MACRO_SEPARATORS     " ,(){}~!*/%+-<>=&^|\"\t\n"
181233237Sjkim#define PR_MACRO_ARGUMENTS      " ,\t\n"
182233237Sjkim#define PR_EXPR_SEPARATORS      " ,(){}~!*/%+-<>=&^|\"\t\n"
183233237Sjkim
184233237Sjkim#define PR_PREFIX_ID            "Pr(%.4u) - "             /* Used for debug output */
185233237Sjkim
186233237Sjkim#define THIS_TOKEN_OFFSET(t)    ((t-Gbl_MainTokenBuffer) + 1)
187233237Sjkim
188233237Sjkim
189233237Sjkim/*
190233237Sjkim * Preprocessor structures
191233237Sjkim */
192233237Sjkimtypedef struct pr_macro_arg
193233237Sjkim{
194233237Sjkim    char                        *Name;
195233237Sjkim    UINT32                      Offset[PR_MAX_ARG_INSTANCES];
196233237Sjkim    UINT16                      UseCount;
197233237Sjkim
198233237Sjkim} PR_MACRO_ARG;
199233237Sjkim
200233237Sjkimtypedef struct pr_define_info
201233237Sjkim{
202233237Sjkim    struct pr_define_info       *Previous;
203233237Sjkim    struct pr_define_info       *Next;
204233237Sjkim    char                        *Identifier;
205233237Sjkim    char                        *Replacement;
206233237Sjkim    char                        *Body;          /* Macro body */
207233237Sjkim    PR_MACRO_ARG                *Args;          /* Macro arg list */
208233237Sjkim    UINT16                      ArgCount;       /* Macro arg count */
209233237Sjkim    BOOLEAN                     Persist;        /* Keep for entire compiler run */
210233237Sjkim
211233237Sjkim} PR_DEFINE_INFO;
212233237Sjkim
213233237Sjkimtypedef struct pr_directive_info
214233237Sjkim{
215233237Sjkim    char                        *Name;          /* Directive name */
216233237Sjkim    UINT8                       ArgCount;       /* Required # of args */
217233237Sjkim
218233237Sjkim} PR_DIRECTIVE_INFO;
219233237Sjkim
220233237Sjkimtypedef struct pr_operator_info
221233237Sjkim{
222233237Sjkim    char                        *Op;
223233237Sjkim
224233237Sjkim} PR_OPERATOR_INFO;
225233237Sjkim
226233237Sjkimtypedef struct pr_file_node
227233237Sjkim{
228233237Sjkim    struct pr_file_node         *Next;
229233237Sjkim    FILE                        *File;
230233237Sjkim    char                        *Filename;
231233237Sjkim    UINT32                      CurrentLineNumber;
232233237Sjkim
233233237Sjkim} PR_FILE_NODE;
234233237Sjkim
235252279Sjkim#define MAX_ARGUMENT_LENGTH     24
236233237Sjkim
237252279Sjkimtypedef struct directive_info
238252279Sjkim{
239252279Sjkim    struct directive_info       *Next;
240252279Sjkim    char                        Argument[MAX_ARGUMENT_LENGTH];
241252279Sjkim    int                         Directive;
242252279Sjkim    BOOLEAN                     IgnoringThisCodeBlock;
243252279Sjkim
244252279Sjkim} DIRECTIVE_INFO;
245252279Sjkim
246252279Sjkim
247233237Sjkim/*
248233237Sjkim * Globals
249233237Sjkim */
250240716Sjkim#if 0 /* TBD for macros */
251240716SjkimPR_EXTERN char                  PR_INIT_GLOBAL (*XXXEvalBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
252240716Sjkim#endif
253233237Sjkim
254240716SjkimPR_EXTERN char                  PR_INIT_GLOBAL (*Gbl_MainTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
255240716SjkimPR_EXTERN char                  PR_INIT_GLOBAL (*Gbl_MacroTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
256240716SjkimPR_EXTERN char                  PR_INIT_GLOBAL (*Gbl_ExpressionTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
257240716Sjkim
258252279SjkimPR_EXTERN UINT32                Gbl_PreprocessorLineNumber;
259252279SjkimPR_EXTERN int                   Gbl_IfDepth;
260233237SjkimPR_EXTERN PR_FILE_NODE          *Gbl_InputFileList;
261233237SjkimPR_EXTERN PR_DEFINE_INFO        PR_INIT_GLOBAL (*Gbl_DefineList, NULL);
262233237SjkimPR_EXTERN BOOLEAN               PR_INIT_GLOBAL (Gbl_PreprocessorError, FALSE);
263252279SjkimPR_EXTERN BOOLEAN               PR_INIT_GLOBAL (Gbl_IgnoringThisCodeBlock, FALSE);
264252279SjkimPR_EXTERN DIRECTIVE_INFO        PR_INIT_GLOBAL (*Gbl_DirectiveStack, NULL);
265233237Sjkim
266233237Sjkim/*
267233237Sjkim * prscan - Preprocessor entry
268233237Sjkim */
269233237Sjkimvoid
270233237SjkimPrInitializePreprocessor (
271233237Sjkim    void);
272233237Sjkim
273233237Sjkimvoid
274233237SjkimPrInitializeGlobals (
275233237Sjkim    void);
276233237Sjkim
277233237Sjkimvoid
278233237SjkimPrTerminatePreprocessor (
279233237Sjkim    void);
280233237Sjkim
281252279Sjkimvoid
282233237SjkimPrDoPreprocess (
283233237Sjkim    void);
284233237Sjkim
285233237SjkimUINT64
286233237SjkimPrIsDefined (
287233237Sjkim    char                    *Identifier);
288233237Sjkim
289233237SjkimUINT64
290233237SjkimPrResolveDefine (
291233237Sjkim    char                    *Identifier);
292233237Sjkim
293233237Sjkimint
294233237SjkimPrInitLexer (
295233237Sjkim    char                    *String);
296233237Sjkim
297233237Sjkimvoid
298233237SjkimPrTerminateLexer (
299233237Sjkim    void);
300233237Sjkim
301233237Sjkim
302233237Sjkim/*
303233237Sjkim * prmacros - Support for #defines and macros
304233237Sjkim */
305233237Sjkimvoid
306233237SjkimPrDumpPredefinedNames (
307233237Sjkim    void);
308233237Sjkim
309233237SjkimPR_DEFINE_INFO *
310233237SjkimPrAddDefine (
311233237Sjkim    char                    *Token,
312233237Sjkim    char                    *Token2,
313233237Sjkim    BOOLEAN                 Persist);
314233237Sjkim
315233237Sjkimvoid
316233237SjkimPrRemoveDefine (
317233237Sjkim    char                    *DefineName);
318233237Sjkim
319233237SjkimPR_DEFINE_INFO *
320233237SjkimPrMatchDefine (
321233237Sjkim    char                    *MatchString);
322233237Sjkim
323233237Sjkimvoid
324233237SjkimPrAddMacro (
325233237Sjkim    char                    *Name,
326233237Sjkim    char                    **Next);
327233237Sjkim
328233237Sjkimvoid
329233237SjkimPrDoMacroInvocation (
330233237Sjkim    char                    *TokenBuffer,
331233237Sjkim    char                    *MacroStart,
332233237Sjkim    PR_DEFINE_INFO          *DefineInfo,
333233237Sjkim    char                    **Next);
334233237Sjkim
335233237Sjkim
336233237Sjkim/*
337233237Sjkim * prexpress - #if expression support
338233237Sjkim */
339233237SjkimACPI_STATUS
340233237SjkimPrResolveIntegerExpression (
341233237Sjkim    char                    *Line,
342233237Sjkim    UINT64                  *ReturnValue);
343233237Sjkim
344233237Sjkimchar *
345233237SjkimPrPrioritizeExpression (
346233237Sjkim    char                    *OriginalLine);
347233237Sjkim
348233237Sjkim/*
349233237Sjkim * prparser - lex/yacc expression parser
350233237Sjkim */
351233237SjkimUINT64
352233237SjkimPrEvaluateExpression (
353233237Sjkim    char                    *ExprString);
354233237Sjkim
355233237Sjkim
356233237Sjkim/*
357233237Sjkim * prutils - Preprocesor utilities
358233237Sjkim */
359233237Sjkimchar *
360233237SjkimPrGetNextToken (
361233237Sjkim    char                    *Buffer,
362233237Sjkim    char                    *MatchString,
363233237Sjkim    char                    **Next);
364233237Sjkim
365233237Sjkimvoid
366233237SjkimPrError (
367233237Sjkim    UINT8                   Level,
368272444Sjkim    UINT16                  MessageId,
369233237Sjkim    UINT32                  Column);
370233237Sjkim
371233237Sjkimvoid
372233237SjkimPrReplaceData (
373233237Sjkim    char                    *Buffer,
374233237Sjkim    UINT32                  LengthToRemove,
375233237Sjkim    char                    *BufferToAdd,
376233237Sjkim    UINT32                  LengthToAdd);
377233237Sjkim
378283092SjkimFILE *
379233237SjkimPrOpenIncludeFile (
380283092Sjkim    char                    *Filename,
381283092Sjkim    char                    *OpenMode,
382283092Sjkim    char                    **FullPathname);
383233237Sjkim
384233237SjkimFILE *
385233237SjkimPrOpenIncludeWithPrefix (
386233237Sjkim    char                    *PrefixDir,
387283092Sjkim    char                    *Filename,
388283092Sjkim    char                    *OpenMode,
389283092Sjkim    char                    **FullPathname);
390233237Sjkim
391233237Sjkimvoid
392233237SjkimPrPushInputFileStack (
393233237Sjkim    FILE                    *InputFile,
394233237Sjkim    char                    *Filename);
395233237Sjkim
396233237SjkimBOOLEAN
397233237SjkimPrPopInputFileStack (
398233237Sjkim    void);
399233237Sjkim
400233237Sjkim#endif
401