preprocess.h revision 1.1.1.14 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.14 christos * Copyright (C) 2000 - 2023, 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.11 christos * 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.14 christos PR_EXTERN char PR_INIT_GLOBAL (*AslGbl_MacroTokenReplaceBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
145 1.1.1.8 christos PR_EXTERN char PR_INIT_GLOBAL (*AslGbl_ExpressionTokenBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
146 1.1.1.8 christos
147 1.1.1.8 christos PR_EXTERN UINT32 AslGbl_PreprocessorLineNumber;
148 1.1.1.8 christos PR_EXTERN int AslGbl_IfDepth;
149 1.1.1.8 christos PR_EXTERN PR_FILE_NODE *AslGbl_InputFileList;
150 1.1.1.8 christos PR_EXTERN BOOLEAN PR_INIT_GLOBAL (AslGbl_PreprocessorError, FALSE);
151 1.1.1.8 christos PR_EXTERN BOOLEAN PR_INIT_GLOBAL (AslGbl_IgnoringThisCodeBlock, FALSE);
152 1.1.1.8 christos PR_EXTERN PR_DEFINE_INFO PR_INIT_GLOBAL (*AslGbl_DefineList, NULL);
153 1.1.1.8 christos PR_EXTERN DIRECTIVE_INFO PR_INIT_GLOBAL (*AslGbl_DirectiveStack, NULL);
154 1.1.1.8 christos
155 1.1 christos #if 0 /* TBD for macros */
156 1.1 christos PR_EXTERN char PR_INIT_GLOBAL (*XXXEvalBuffer, NULL); /* [ASL_LINE_BUFFER_SIZE]; */
157 1.1 christos #endif
158 1.1 christos
159 1.1 christos
160 1.1 christos /*
161 1.1 christos * prscan - Preprocessor entry
162 1.1 christos */
163 1.1 christos void
164 1.1 christos PrInitializePreprocessor (
165 1.1 christos void);
166 1.1 christos
167 1.1 christos void
168 1.1 christos PrInitializeGlobals (
169 1.1 christos void);
170 1.1 christos
171 1.1 christos void
172 1.1 christos PrTerminatePreprocessor (
173 1.1 christos void);
174 1.1 christos
175 1.1 christos void
176 1.1 christos PrDoPreprocess (
177 1.1 christos void);
178 1.1 christos
179 1.1 christos UINT64
180 1.1 christos PrIsDefined (
181 1.1 christos char *Identifier);
182 1.1 christos
183 1.1 christos UINT64
184 1.1 christos PrResolveDefine (
185 1.1 christos char *Identifier);
186 1.1 christos
187 1.1 christos int
188 1.1 christos PrInitLexer (
189 1.1 christos char *String);
190 1.1 christos
191 1.1 christos void
192 1.1 christos PrTerminateLexer (
193 1.1 christos void);
194 1.1 christos
195 1.1 christos
196 1.1 christos /*
197 1.1 christos * prmacros - Support for #defines and macros
198 1.1 christos */
199 1.1 christos void
200 1.1 christos PrDumpPredefinedNames (
201 1.1 christos void);
202 1.1 christos
203 1.1 christos PR_DEFINE_INFO *
204 1.1 christos PrAddDefine (
205 1.1 christos char *Token,
206 1.1 christos char *Token2,
207 1.1 christos BOOLEAN Persist);
208 1.1 christos
209 1.1 christos void
210 1.1 christos PrRemoveDefine (
211 1.1 christos char *DefineName);
212 1.1 christos
213 1.1 christos PR_DEFINE_INFO *
214 1.1 christos PrMatchDefine (
215 1.1 christos char *MatchString);
216 1.1 christos
217 1.1 christos void
218 1.1 christos PrAddMacro (
219 1.1 christos char *Name,
220 1.1 christos char **Next);
221 1.1 christos
222 1.1 christos void
223 1.1 christos PrDoMacroInvocation (
224 1.1 christos char *TokenBuffer,
225 1.1 christos char *MacroStart,
226 1.1 christos PR_DEFINE_INFO *DefineInfo,
227 1.1 christos char **Next);
228 1.1 christos
229 1.1 christos
230 1.1 christos /*
231 1.1 christos * prexpress - #if expression support
232 1.1 christos */
233 1.1 christos ACPI_STATUS
234 1.1 christos PrResolveIntegerExpression (
235 1.1 christos char *Line,
236 1.1 christos UINT64 *ReturnValue);
237 1.1 christos
238 1.1 christos char *
239 1.1 christos PrPrioritizeExpression (
240 1.1 christos char *OriginalLine);
241 1.1 christos
242 1.1 christos /*
243 1.1 christos * prparser - lex/yacc expression parser
244 1.1 christos */
245 1.1 christos UINT64
246 1.1 christos PrEvaluateExpression (
247 1.1 christos char *ExprString);
248 1.1 christos
249 1.1 christos
250 1.1 christos /*
251 1.1.1.12 christos * prutils - Preprocessor utilities
252 1.1 christos */
253 1.1 christos char *
254 1.1 christos PrGetNextToken (
255 1.1 christos char *Buffer,
256 1.1 christos char *MatchString,
257 1.1 christos char **Next);
258 1.1 christos
259 1.1 christos void
260 1.1 christos PrError (
261 1.1 christos UINT8 Level,
262 1.1.1.2 christos UINT16 MessageId,
263 1.1 christos UINT32 Column);
264 1.1 christos
265 1.1 christos void
266 1.1.1.14 christos PrReplaceResizeSubstring(
267 1.1.1.14 christos PR_MACRO_ARG *Args,
268 1.1.1.14 christos UINT32 Diff1,
269 1.1.1.14 christos UINT32 Diff2,
270 1.1.1.14 christos UINT32 i,
271 1.1.1.14 christos char *Token);
272 1.1.1.14 christos
273 1.1.1.14 christos char *
274 1.1 christos PrReplaceData (
275 1.1 christos char *Buffer,
276 1.1 christos UINT32 LengthToRemove,
277 1.1 christos char *BufferToAdd,
278 1.1 christos UINT32 LengthToAdd);
279 1.1 christos
280 1.1.1.4 christos FILE *
281 1.1 christos PrOpenIncludeFile (
282 1.1.1.4 christos char *Filename,
283 1.1.1.4 christos char *OpenMode,
284 1.1.1.4 christos char **FullPathname);
285 1.1 christos
286 1.1 christos FILE *
287 1.1 christos PrOpenIncludeWithPrefix (
288 1.1 christos char *PrefixDir,
289 1.1.1.4 christos char *Filename,
290 1.1.1.4 christos char *OpenMode,
291 1.1.1.4 christos char **FullPathname);
292 1.1 christos
293 1.1 christos void
294 1.1 christos PrPushInputFileStack (
295 1.1 christos FILE *InputFile,
296 1.1 christos char *Filename);
297 1.1 christos
298 1.1 christos BOOLEAN
299 1.1 christos PrPopInputFileStack (
300 1.1 christos void);
301 1.1 christos
302 1.1 christos #endif
303