cvcompiler.c revision 1.1.1.8 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: cvcompiler - ASL-/ASL+ converter functions
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.8 christos * 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.8 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 #include "aslcompiler.h"
45 1.1 christos #include "aslcompiler.y.h"
46 1.1 christos #include "amlcode.h"
47 1.1 christos #include "acapps.h"
48 1.1 christos #include "acconvert.h"
49 1.1 christos
50 1.1 christos
51 1.1 christos /*******************************************************************************
52 1.1 christos *
53 1.1 christos * FUNCTION: CvProcessComment
54 1.1 christos *
55 1.1 christos * PARAMETERS: CurrentState Current comment parse state
56 1.1 christos * StringBuffer Buffer containing the comment being processed
57 1.1 christos * c1 Current input
58 1.1 christos *
59 1.1.1.2 christos * RETURN: None
60 1.1 christos *
61 1.1 christos * DESCRIPTION: Process a single line comment of a c Style comment. This
62 1.1 christos * function captures a line of a c style comment in a char* and
63 1.1.1.6 christos * places the comment in the appropriate global buffer.
64 1.1 christos *
65 1.1 christos ******************************************************************************/
66 1.1 christos
67 1.1 christos void
68 1.1 christos CvProcessComment (
69 1.1 christos ASL_COMMENT_STATE CurrentState,
70 1.1 christos char *StringBuffer,
71 1.1 christos int c1)
72 1.1 christos {
73 1.1 christos UINT64 i;
74 1.1 christos char *LineToken;
75 1.1 christos char *FinalLineToken;
76 1.1 christos BOOLEAN CharStart;
77 1.1 christos char *CommentString;
78 1.1 christos char *FinalCommentString;
79 1.1 christos
80 1.1 christos
81 1.1.1.4 christos if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
82 1.1 christos {
83 1.1 christos *StringBuffer = (char) c1;
84 1.1 christos ++StringBuffer;
85 1.1 christos *StringBuffer = 0;
86 1.1.1.2 christos
87 1.1 christos CvDbgPrint ("Multi-line comment\n");
88 1.1.1.5 christos CommentString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1);
89 1.1.1.5 christos strcpy (CommentString, AslGbl_MsgBuffer);
90 1.1 christos
91 1.1 christos CvDbgPrint ("CommentString: %s\n", CommentString);
92 1.1 christos
93 1.1 christos /*
94 1.1.1.2 christos * Determine whether if this comment spans multiple lines. If so,
95 1.1.1.2 christos * break apart the comment by storing each line in a different node
96 1.1.1.2 christos * within the comment list. This allows the disassembler to
97 1.1.1.2 christos * properly indent a multi-line comment.
98 1.1 christos */
99 1.1.1.2 christos LineToken = strtok (CommentString, "\n");
100 1.1.1.2 christos
101 1.1.1.2 christos if (LineToken)
102 1.1 christos {
103 1.1.1.3 christos FinalLineToken = UtLocalCacheCalloc (strlen (LineToken) + 1);
104 1.1 christos strcpy (FinalLineToken, LineToken);
105 1.1 christos
106 1.1 christos /* Get rid of any carriage returns */
107 1.1 christos
108 1.1 christos if (FinalLineToken[strlen (FinalLineToken) - 1] == 0x0D)
109 1.1 christos {
110 1.1 christos FinalLineToken[strlen(FinalLineToken)-1] = 0;
111 1.1 christos }
112 1.1.1.2 christos
113 1.1 christos CvAddToCommentList (FinalLineToken);
114 1.1 christos LineToken = strtok (NULL, "\n");
115 1.1 christos while (LineToken != NULL)
116 1.1 christos {
117 1.1 christos /*
118 1.1 christos * It is assumed that each line has some sort of indentation.
119 1.1.1.2 christos * This means that we need to find the first character that
120 1.1.1.2 christos * is not a white space within each line.
121 1.1 christos */
122 1.1 christos CharStart = FALSE;
123 1.1 christos for (i = 0; (i < (strlen (LineToken) + 1)) && !CharStart; i++)
124 1.1 christos {
125 1.1 christos if (LineToken[i] != ' ' && LineToken[i] != '\t')
126 1.1 christos {
127 1.1 christos CharStart = TRUE;
128 1.1 christos LineToken += i-1;
129 1.1 christos LineToken [0] = ' '; /* Pad for Formatting */
130 1.1 christos }
131 1.1 christos }
132 1.1.1.2 christos
133 1.1.1.3 christos FinalLineToken = UtLocalCacheCalloc (strlen (LineToken) + 1);
134 1.1 christos strcat (FinalLineToken, LineToken);
135 1.1 christos
136 1.1 christos /* Get rid of any carriage returns */
137 1.1 christos
138 1.1 christos if (FinalLineToken[strlen (FinalLineToken) - 1] == 0x0D)
139 1.1 christos {
140 1.1 christos FinalLineToken[strlen(FinalLineToken) - 1] = 0;
141 1.1 christos }
142 1.1.1.2 christos
143 1.1 christos CvAddToCommentList (FinalLineToken);
144 1.1 christos LineToken = strtok (NULL,"\n");
145 1.1 christos }
146 1.1 christos }
147 1.1 christos
148 1.1 christos /*
149 1.1.1.2 christos * If this only spans a single line, check to see whether if this
150 1.1.1.2 christos * comment appears on the same line as a line of code. If does,
151 1.1.1.2 christos * retain it's position for stylistic reasons. If it doesn't,
152 1.1.1.2 christos * add it to the comment list so that it can be associated with
153 1.1.1.2 christos * the next node that's created.
154 1.1 christos */
155 1.1 christos else
156 1.1 christos {
157 1.1 christos /*
158 1.1.1.2 christos * If this is not a regular comment, pad with extra spaces that
159 1.1.1.2 christos * appeared in the original source input to retain the original
160 1.1.1.2 christos * spacing.
161 1.1 christos */
162 1.1.1.2 christos FinalCommentString =
163 1.1.1.3 christos UtLocalCacheCalloc (strlen (CommentString) +
164 1.1.1.2 christos CurrentState.SpacesBefore + 1);
165 1.1.1.2 christos
166 1.1.1.2 christos for (i = 0; (CurrentState.CommentType != ASL_COMMENT_STANDARD) &&
167 1.1.1.2 christos (i < CurrentState.SpacesBefore); i++)
168 1.1 christos {
169 1.1 christos FinalCommentString[i] = ' ';
170 1.1 christos }
171 1.1.1.2 christos
172 1.1 christos strcat (FinalCommentString, CommentString);
173 1.1 christos CvPlaceComment (CurrentState.CommentType, FinalCommentString);
174 1.1 christos }
175 1.1 christos }
176 1.1 christos }
177 1.1 christos
178 1.1 christos
179 1.1 christos /*******************************************************************************
180 1.1 christos *
181 1.1 christos * FUNCTION: CvProcessCommentType2
182 1.1 christos *
183 1.1 christos * PARAMETERS: CurrentState Current comment parse state
184 1.1 christos * StringBuffer Buffer containing the comment being processed
185 1.1 christos *
186 1.1 christos * RETURN: none
187 1.1 christos *
188 1.1 christos * DESCRIPTION: Process a single line comment. This function captures a comment
189 1.1.1.6 christos * in a char* and places the comment in the appropriate global
190 1.1 christos * buffer through CvPlaceComment
191 1.1 christos *
192 1.1 christos ******************************************************************************/
193 1.1 christos
194 1.1 christos void
195 1.1 christos CvProcessCommentType2 (
196 1.1 christos ASL_COMMENT_STATE CurrentState,
197 1.1 christos char *StringBuffer)
198 1.1 christos {
199 1.1 christos UINT32 i;
200 1.1 christos char *CommentString;
201 1.1 christos char *FinalCommentString;
202 1.1 christos
203 1.1 christos
204 1.1.1.4 christos if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
205 1.1 christos {
206 1.1 christos *StringBuffer = 0; /* null terminate */
207 1.1 christos CvDbgPrint ("Single-line comment\n");
208 1.1.1.5 christos CommentString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1);
209 1.1.1.5 christos strcpy (CommentString, AslGbl_MsgBuffer);
210 1.1 christos
211 1.1.1.2 christos /* If this comment lies on the same line as the latest parse op,
212 1.1.1.2 christos * assign it to that op's CommentAfter field. Saving in this field
213 1.1.1.2 christos * will allow us to support comments that come after code on the
214 1.1.1.2 christos * same line as the code itself. For example,
215 1.1 christos * Name(A,"") //comment
216 1.1 christos *
217 1.1 christos * will be retained rather than transformed into
218 1.1 christos *
219 1.1 christos * Name(A,"")
220 1.1 christos * //comment
221 1.1 christos *
222 1.1 christos * For this case, we only need to add one comment since
223 1.1 christos *
224 1.1 christos * Name(A,"") //comment1 //comment2 ... more comments here.
225 1.1 christos *
226 1.1 christos * would be lexically analyzed as a single comment.
227 1.1 christos *
228 1.1.1.6 christos * Create a new string with the appropriate spaces. Since we need
229 1.1 christos * to account for the proper spacing, the actual comment,
230 1.1 christos * extra 2 spaces so that this comment can be converted to the "/ *"
231 1.1.1.2 christos * style and the null terminator, the string would look something
232 1.1.1.2 christos * like:
233 1.1 christos *
234 1.1 christos * [ (spaces) (comment) ( * /) ('\0') ]
235 1.1 christos *
236 1.1 christos */
237 1.1.1.3 christos FinalCommentString = UtLocalCacheCalloc (CurrentState.SpacesBefore +
238 1.1.1.2 christos strlen (CommentString) + 3 + 1);
239 1.1.1.2 christos
240 1.1.1.2 christos for (i = 0; (CurrentState.CommentType != 1) &&
241 1.1.1.2 christos (i < CurrentState.SpacesBefore); i++)
242 1.1 christos {
243 1.1 christos FinalCommentString[i] = ' ';
244 1.1 christos }
245 1.1.1.2 christos
246 1.1 christos strcat (FinalCommentString, CommentString);
247 1.1 christos
248 1.1 christos /* convert to a "/ *" style comment */
249 1.1 christos
250 1.1 christos strcat (FinalCommentString, " */");
251 1.1.1.2 christos FinalCommentString [CurrentState.SpacesBefore +
252 1.1.1.2 christos strlen (CommentString) + 3] = 0;
253 1.1 christos
254 1.1 christos /* get rid of the carriage return */
255 1.1 christos
256 1.1 christos if (FinalCommentString[strlen (FinalCommentString) - 1] == 0x0D)
257 1.1 christos {
258 1.1.1.2 christos FinalCommentString[strlen(FinalCommentString) - 1] = 0;
259 1.1 christos }
260 1.1.1.2 christos
261 1.1 christos CvPlaceComment (CurrentState.CommentType, FinalCommentString);
262 1.1 christos }
263 1.1 christos }
264 1.1 christos
265 1.1 christos
266 1.1 christos /*******************************************************************************
267 1.1 christos *
268 1.1 christos * FUNCTION: CgCalculateCommentLengths
269 1.1 christos *
270 1.1 christos * PARAMETERS: Op - Calculate all comments of this Op
271 1.1 christos *
272 1.1.1.2 christos * RETURN: TotalCommentLength - Length of all comments within this op.
273 1.1 christos *
274 1.1.1.2 christos * DESCRIPTION: Calculate the length that the each comment takes up within Op.
275 1.1.1.6 christos * Comments look like the following: [0xA9 OptionBtye comment 0x00]
276 1.1 christos * therefore, we add 1 + 1 + strlen (comment) + 1 to get the actual
277 1.1 christos * length of this comment.
278 1.1 christos *
279 1.1 christos ******************************************************************************/
280 1.1 christos
281 1.1 christos UINT32
282 1.1 christos CvCalculateCommentLengths(
283 1.1 christos ACPI_PARSE_OBJECT *Op)
284 1.1 christos {
285 1.1 christos UINT32 CommentLength = 0;
286 1.1 christos UINT32 TotalCommentLength = 0;
287 1.1 christos ACPI_COMMENT_NODE *Current = NULL;
288 1.1 christos
289 1.1 christos
290 1.1.1.4 christos if (!AcpiGbl_CaptureComments)
291 1.1 christos {
292 1.1 christos return (0);
293 1.1 christos }
294 1.1 christos
295 1.1.1.2 christos CvDbgPrint ("==Calculating comment lengths for %s\n",
296 1.1.1.2 christos Op->Asl.ParseOpName);
297 1.1.1.2 christos
298 1.1 christos if (Op->Asl.FileChanged)
299 1.1 christos {
300 1.1 christos TotalCommentLength += strlen (Op->Asl.Filename) + 3;
301 1.1 christos
302 1.1 christos if (Op->Asl.ParentFilename &&
303 1.1 christos AcpiUtStricmp (Op->Asl.Filename, Op->Asl.ParentFilename))
304 1.1 christos {
305 1.1 christos TotalCommentLength += strlen (Op->Asl.ParentFilename) + 3;
306 1.1 christos }
307 1.1 christos }
308 1.1.1.2 christos
309 1.1 christos if (Op->Asl.CommentList)
310 1.1 christos {
311 1.1 christos Current = Op->Asl.CommentList;
312 1.1 christos while (Current)
313 1.1 christos {
314 1.1 christos CommentLength = strlen (Current->Comment)+3;
315 1.1 christos CvDbgPrint ("Length of standard comment: %d\n", CommentLength);
316 1.1 christos CvDbgPrint (" Comment string: %s\n\n", Current->Comment);
317 1.1 christos TotalCommentLength += CommentLength;
318 1.1 christos Current = Current->Next;
319 1.1 christos }
320 1.1 christos }
321 1.1.1.2 christos
322 1.1 christos if (Op->Asl.EndBlkComment)
323 1.1 christos {
324 1.1 christos Current = Op->Asl.EndBlkComment;
325 1.1 christos while (Current)
326 1.1 christos {
327 1.1 christos CommentLength = strlen (Current->Comment)+3;
328 1.1 christos CvDbgPrint ("Length of endblkcomment: %d\n", CommentLength);
329 1.1 christos CvDbgPrint (" Comment string: %s\n\n", Current->Comment);
330 1.1 christos TotalCommentLength += CommentLength;
331 1.1 christos Current = Current->Next;
332 1.1 christos }
333 1.1 christos }
334 1.1.1.2 christos
335 1.1 christos if (Op->Asl.InlineComment)
336 1.1 christos {
337 1.1 christos CommentLength = strlen (Op->Asl.InlineComment)+3;
338 1.1 christos CvDbgPrint ("Length of inline comment: %d\n", CommentLength);
339 1.1 christos CvDbgPrint (" Comment string: %s\n\n", Op->Asl.InlineComment);
340 1.1 christos TotalCommentLength += CommentLength;
341 1.1 christos }
342 1.1.1.2 christos
343 1.1 christos if (Op->Asl.EndNodeComment)
344 1.1 christos {
345 1.1 christos CommentLength = strlen(Op->Asl.EndNodeComment)+3;
346 1.1 christos CvDbgPrint ("Length of end node comment +3: %d\n", CommentLength);
347 1.1 christos CvDbgPrint (" Comment string: %s\n\n", Op->Asl.EndNodeComment);
348 1.1 christos TotalCommentLength += CommentLength;
349 1.1 christos }
350 1.1 christos
351 1.1 christos if (Op->Asl.CloseBraceComment)
352 1.1 christos {
353 1.1 christos CommentLength = strlen (Op->Asl.CloseBraceComment)+3;
354 1.1 christos CvDbgPrint ("Length of close brace comment: %d\n", CommentLength);
355 1.1 christos CvDbgPrint (" Comment string: %s\n\n", Op->Asl.CloseBraceComment);
356 1.1 christos TotalCommentLength += CommentLength;
357 1.1 christos }
358 1.1 christos
359 1.1 christos CvDbgPrint("\n\n");
360 1.1.1.2 christos return (TotalCommentLength);
361 1.1 christos }
362 1.1 christos
363 1.1 christos
364 1.1 christos /*******************************************************************************
365 1.1 christos *
366 1.1 christos * FUNCTION: CgWriteAmlDefBlockComment
367 1.1 christos *
368 1.1 christos * PARAMETERS: Op - Current parse op
369 1.1 christos *
370 1.1 christos * RETURN: None
371 1.1 christos *
372 1.1 christos * DESCRIPTION: Write all comments for a particular definition block.
373 1.1 christos * For definition blocks, the comments need to come after the
374 1.1 christos * definition block header. The regular comments above the
375 1.1 christos * definition block would be categorized as
376 1.1 christos * STD_DEFBLK_COMMENT and comments after the closing brace
377 1.1 christos * is categorized as END_DEFBLK_COMMENT.
378 1.1 christos *
379 1.1 christos ******************************************************************************/
380 1.1 christos
381 1.1 christos void
382 1.1 christos CgWriteAmlDefBlockComment(
383 1.1 christos ACPI_PARSE_OBJECT *Op)
384 1.1 christos {
385 1.1 christos UINT8 CommentOption;
386 1.1 christos ACPI_COMMENT_NODE *Current;
387 1.1 christos char *NewFilename;
388 1.1 christos char *Position;
389 1.1 christos char *DirectoryPosition;
390 1.1 christos
391 1.1 christos
392 1.1.1.4 christos if (!AcpiGbl_CaptureComments ||
393 1.1 christos (Op->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK))
394 1.1 christos {
395 1.1 christos return;
396 1.1 christos }
397 1.1 christos
398 1.1 christos CvDbgPrint ("Printing comments for a definition block..\n");
399 1.1 christos
400 1.1.1.2 christos /* First, print the file name comment after changing .asl to .dsl */
401 1.1 christos
402 1.1.1.3 christos NewFilename = UtLocalCacheCalloc (strlen (Op->Asl.Filename));
403 1.1 christos strcpy (NewFilename, Op->Asl.Filename);
404 1.1 christos DirectoryPosition = strrchr (NewFilename, '/');
405 1.1 christos Position = strrchr (NewFilename, '.');
406 1.1 christos
407 1.1 christos if (Position && (Position > DirectoryPosition))
408 1.1 christos {
409 1.1 christos /* Tack on the new suffix */
410 1.1 christos
411 1.1 christos Position++;
412 1.1 christos *Position = 0;
413 1.1 christos strcat (Position, FILE_SUFFIX_DISASSEMBLY);
414 1.1 christos }
415 1.1 christos else
416 1.1 christos {
417 1.1 christos /* No dot, add one and then the suffix */
418 1.1 christos
419 1.1 christos strcat (NewFilename, ".");
420 1.1 christos strcat (NewFilename, FILE_SUFFIX_DISASSEMBLY);
421 1.1 christos }
422 1.1 christos
423 1.1 christos CommentOption = FILENAME_COMMENT;
424 1.1 christos CgWriteOneAmlComment(Op, NewFilename, CommentOption);
425 1.1 christos
426 1.1 christos Current = Op->Asl.CommentList;
427 1.1 christos CommentOption = STD_DEFBLK_COMMENT;
428 1.1.1.2 christos
429 1.1 christos while (Current)
430 1.1 christos {
431 1.1 christos CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
432 1.1 christos CvDbgPrint ("Printing comment: %s\n", Current->Comment);
433 1.1 christos Current = Current->Next;
434 1.1 christos }
435 1.1.1.2 christos
436 1.1 christos Op->Asl.CommentList = NULL;
437 1.1 christos
438 1.1.1.2 christos /* Print any Inline comments associated with this node */
439 1.1 christos
440 1.1 christos if (Op->Asl.CloseBraceComment)
441 1.1 christos {
442 1.1 christos CommentOption = END_DEFBLK_COMMENT;
443 1.1 christos CgWriteOneAmlComment(Op, Op->Asl.CloseBraceComment, CommentOption);
444 1.1 christos Op->Asl.CloseBraceComment = NULL;
445 1.1 christos }
446 1.1 christos }
447 1.1 christos
448 1.1 christos
449 1.1 christos /*******************************************************************************
450 1.1 christos *
451 1.1 christos * FUNCTION: CgWriteOneAmlComment
452 1.1 christos *
453 1.1 christos * PARAMETERS: Op - Current parse op
454 1.1 christos * CommentToPrint - Comment that's printed
455 1.1 christos * InputOption - Denotes the comment option.
456 1.1 christos *
457 1.1 christos * RETURN: None
458 1.1 christos *
459 1.1 christos * DESCRIPTION: write a single comment.
460 1.1 christos *
461 1.1 christos ******************************************************************************/
462 1.1 christos
463 1.1 christos void
464 1.1 christos CgWriteOneAmlComment(
465 1.1 christos ACPI_PARSE_OBJECT *Op,
466 1.1 christos char* CommentToPrint,
467 1.1 christos UINT8 InputOption)
468 1.1 christos {
469 1.1.1.2 christos UINT8 CommentOption = InputOption;
470 1.1.1.2 christos UINT8 CommentOpcode = (UINT8) AML_COMMENT_OP;
471 1.1.1.2 christos
472 1.1.1.2 christos
473 1.1.1.2 christos if (!CommentToPrint)
474 1.1.1.2 christos {
475 1.1.1.2 christos return;
476 1.1.1.2 christos }
477 1.1 christos
478 1.1 christos CgLocalWriteAmlData (Op, &CommentOpcode, 1);
479 1.1 christos CgLocalWriteAmlData (Op, &CommentOption, 1);
480 1.1 christos
481 1.1 christos /* The strlen (..) + 1 is to include the null terminator */
482 1.1 christos
483 1.1 christos CgLocalWriteAmlData (Op, CommentToPrint, strlen (CommentToPrint) + 1);
484 1.1 christos }
485 1.1 christos
486 1.1 christos
487 1.1 christos /*******************************************************************************
488 1.1 christos *
489 1.1 christos * FUNCTION: CgWriteAmlComment
490 1.1 christos *
491 1.1 christos * PARAMETERS: Op - Current parse op
492 1.1 christos *
493 1.1 christos * RETURN: None
494 1.1 christos *
495 1.1.1.2 christos * DESCRIPTION: Write all comments pertaining to the current parse op
496 1.1 christos *
497 1.1 christos ******************************************************************************/
498 1.1 christos
499 1.1 christos void
500 1.1 christos CgWriteAmlComment(
501 1.1 christos ACPI_PARSE_OBJECT *Op)
502 1.1 christos {
503 1.1 christos ACPI_COMMENT_NODE *Current;
504 1.1 christos UINT8 CommentOption;
505 1.1 christos char *NewFilename;
506 1.1 christos char *ParentFilename;
507 1.1 christos
508 1.1 christos
509 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) ||
510 1.1.1.4 christos !AcpiGbl_CaptureComments)
511 1.1 christos {
512 1.1 christos return;
513 1.1 christos }
514 1.1 christos
515 1.1 christos /* Print out the filename comment if needed */
516 1.1 christos
517 1.1 christos if (Op->Asl.FileChanged)
518 1.1 christos {
519 1.1 christos
520 1.1.1.2 christos /* First, print the file name comment after changing .asl to .dsl */
521 1.1 christos
522 1.1 christos NewFilename =
523 1.1 christos FlGenerateFilename (Op->Asl.Filename, FILE_SUFFIX_DISASSEMBLY);
524 1.1.1.2 christos if (NewFilename)
525 1.1.1.2 christos {
526 1.1.1.2 christos CvDbgPrint ("Writing file comment, \"%s\" for %s\n",
527 1.1.1.2 christos NewFilename, Op->Asl.ParseOpName);
528 1.1.1.2 christos }
529 1.1.1.2 christos
530 1.1 christos CgWriteOneAmlComment(Op, NewFilename, FILENAME_COMMENT);
531 1.1 christos
532 1.1 christos if (Op->Asl.ParentFilename &&
533 1.1 christos AcpiUtStricmp (Op->Asl.ParentFilename, Op->Asl.Filename))
534 1.1 christos {
535 1.1 christos ParentFilename = FlGenerateFilename (Op->Asl.ParentFilename,
536 1.1 christos FILE_SUFFIX_DISASSEMBLY);
537 1.1 christos CgWriteOneAmlComment(Op, ParentFilename, PARENTFILENAME_COMMENT);
538 1.1 christos }
539 1.1 christos
540 1.1.1.2 christos /* Prevent multiple writes of the same comment */
541 1.1 christos
542 1.1 christos Op->Asl.FileChanged = FALSE;
543 1.1 christos }
544 1.1 christos
545 1.1 christos /*
546 1.1 christos * Regular comments are stored in a list of comments within an Op.
547 1.1 christos * If there is a such list in this node, print out the comment
548 1.1 christos * as byte code.
549 1.1 christos */
550 1.1 christos Current = Op->Asl.CommentList;
551 1.1 christos if (Op->Asl.ParseOpcode == PARSEOP_INCLUDE)
552 1.1 christos {
553 1.1 christos CommentOption = INCLUDE_COMMENT;
554 1.1 christos }
555 1.1 christos else
556 1.1 christos {
557 1.1 christos CommentOption = STANDARD_COMMENT;
558 1.1 christos }
559 1.1 christos
560 1.1 christos while (Current)
561 1.1 christos {
562 1.1 christos CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
563 1.1 christos Current = Current->Next;
564 1.1 christos }
565 1.1.1.2 christos
566 1.1 christos Op->Asl.CommentList = NULL;
567 1.1 christos
568 1.1 christos Current = Op->Asl.EndBlkComment;
569 1.1 christos CommentOption = ENDBLK_COMMENT;
570 1.1 christos while (Current)
571 1.1 christos {
572 1.1 christos CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
573 1.1 christos Current = Current->Next;
574 1.1 christos }
575 1.1.1.2 christos
576 1.1 christos Op->Asl.EndBlkComment = NULL;
577 1.1 christos
578 1.1.1.2 christos /* Print any Inline comments associated with this node */
579 1.1 christos
580 1.1 christos if (Op->Asl.InlineComment)
581 1.1 christos {
582 1.1 christos CommentOption = INLINE_COMMENT;
583 1.1 christos CgWriteOneAmlComment(Op, Op->Asl.InlineComment, CommentOption);
584 1.1 christos Op->Asl.InlineComment = NULL;
585 1.1 christos }
586 1.1 christos
587 1.1 christos if (Op->Asl.EndNodeComment)
588 1.1 christos {
589 1.1 christos CommentOption = ENDNODE_COMMENT;
590 1.1 christos CgWriteOneAmlComment(Op, Op->Asl.EndNodeComment, CommentOption);
591 1.1 christos Op->Asl.EndNodeComment = NULL;
592 1.1 christos }
593 1.1 christos
594 1.1 christos if (Op->Asl.CloseBraceComment)
595 1.1 christos {
596 1.1 christos CommentOption = CLOSE_BRACE_COMMENT;
597 1.1 christos CgWriteOneAmlComment(Op, Op->Asl.CloseBraceComment, CommentOption);
598 1.1 christos Op->Asl.CloseBraceComment = NULL;
599 1.1 christos }
600 1.1 christos }
601 1.1 christos
602 1.1 christos
603 1.1 christos /*******************************************************************************
604 1.1 christos *
605 1.1 christos * FUNCTION: CvCommentNodeCalloc
606 1.1 christos *
607 1.1.1.2 christos * PARAMETERS: None
608 1.1 christos *
609 1.1 christos * RETURN: Pointer to the comment node. Aborts on allocation failure
610 1.1 christos *
611 1.1 christos * DESCRIPTION: Allocate a string node buffer.
612 1.1 christos *
613 1.1 christos ******************************************************************************/
614 1.1 christos
615 1.1.1.2 christos ACPI_COMMENT_NODE *
616 1.1 christos CvCommentNodeCalloc (
617 1.1 christos void)
618 1.1 christos {
619 1.1 christos ACPI_COMMENT_NODE *NewCommentNode;
620 1.1 christos
621 1.1 christos
622 1.1.1.2 christos NewCommentNode = UtLocalCalloc (sizeof (ACPI_COMMENT_NODE));
623 1.1 christos NewCommentNode->Next = NULL;
624 1.1.1.2 christos return (NewCommentNode);
625 1.1 christos }
626 1.1 christos
627 1.1 christos
628 1.1 christos /*******************************************************************************
629 1.1 christos *
630 1.1 christos * FUNCTION: CvParseOpBlockType
631 1.1 christos *
632 1.1 christos * PARAMETERS: Op - Object to be examined
633 1.1 christos *
634 1.1 christos * RETURN: BlockType - not a block, parens, braces, or even both.
635 1.1 christos *
636 1.1 christos * DESCRIPTION: Type of block for this ASL parseop (parens or braces)
637 1.1 christos * keep this in sync with aslprimaries.y, aslresources.y and
638 1.1 christos * aslrules.y
639 1.1 christos *
640 1.1 christos ******************************************************************************/
641 1.1 christos
642 1.1 christos UINT32
643 1.1 christos CvParseOpBlockType (
644 1.1 christos ACPI_PARSE_OBJECT *Op)
645 1.1 christos {
646 1.1.1.2 christos
647 1.1 christos if (!Op)
648 1.1 christos {
649 1.1 christos return (BLOCK_NONE);
650 1.1 christos }
651 1.1 christos
652 1.1 christos switch (Op->Asl.ParseOpcode)
653 1.1 christos {
654 1.1.1.2 christos /* From aslprimaries.y */
655 1.1 christos
656 1.1 christos case PARSEOP_VAR_PACKAGE:
657 1.1 christos case PARSEOP_BANKFIELD:
658 1.1 christos case PARSEOP_BUFFER:
659 1.1 christos case PARSEOP_CASE:
660 1.1 christos case PARSEOP_DEVICE:
661 1.1 christos case PARSEOP_FIELD:
662 1.1 christos case PARSEOP_FOR:
663 1.1 christos case PARSEOP_FUNCTION:
664 1.1 christos case PARSEOP_IF:
665 1.1 christos case PARSEOP_ELSEIF:
666 1.1 christos case PARSEOP_INDEXFIELD:
667 1.1 christos case PARSEOP_METHOD:
668 1.1 christos case PARSEOP_POWERRESOURCE:
669 1.1 christos case PARSEOP_PROCESSOR:
670 1.1 christos case PARSEOP_DATABUFFER:
671 1.1 christos case PARSEOP_SCOPE:
672 1.1 christos case PARSEOP_SWITCH:
673 1.1 christos case PARSEOP_THERMALZONE:
674 1.1 christos case PARSEOP_WHILE:
675 1.1 christos
676 1.1.1.2 christos /* From aslresources.y */
677 1.1 christos
678 1.1 christos case PARSEOP_RESOURCETEMPLATE: /* optional parens */
679 1.1 christos case PARSEOP_VENDORLONG:
680 1.1 christos case PARSEOP_VENDORSHORT:
681 1.1 christos case PARSEOP_INTERRUPT:
682 1.1 christos case PARSEOP_IRQNOFLAGS:
683 1.1 christos case PARSEOP_IRQ:
684 1.1 christos case PARSEOP_GPIO_INT:
685 1.1 christos case PARSEOP_GPIO_IO:
686 1.1 christos case PARSEOP_DMA:
687 1.1 christos
688 1.1.1.2 christos /* From aslrules.y */
689 1.1 christos
690 1.1 christos case PARSEOP_DEFINITION_BLOCK:
691 1.1 christos return (BLOCK_PAREN | BLOCK_BRACE);
692 1.1 christos
693 1.1 christos default:
694 1.1 christos return (BLOCK_NONE);
695 1.1 christos }
696 1.1 christos }
697 1.1 christos
698 1.1 christos
699 1.1 christos /*******************************************************************************
700 1.1 christos *
701 1.1 christos * FUNCTION: CvProcessCommentState
702 1.1 christos *
703 1.1.1.2 christos * PARAMETERS: Input - Input character
704 1.1 christos *
705 1.1 christos * RETURN: None
706 1.1 christos *
707 1.1 christos * DESCRIPTION: Take the given input. If this character is
708 1.1 christos * defined as a comment table entry, then update the state
709 1.1 christos * accordingly.
710 1.1 christos *
711 1.1 christos ******************************************************************************/
712 1.1 christos
713 1.1 christos void
714 1.1 christos CvProcessCommentState (
715 1.1.1.2 christos char Input)
716 1.1 christos {
717 1.1 christos
718 1.1.1.2 christos if (Input != ' ')
719 1.1 christos {
720 1.1.1.5 christos AslGbl_CommentState.SpacesBefore = 0;
721 1.1 christos }
722 1.1 christos
723 1.1.1.2 christos switch (Input)
724 1.1 christos {
725 1.1 christos case '\n':
726 1.1 christos
727 1.1.1.5 christos AslGbl_CommentState.CommentType = ASL_COMMENT_STANDARD;
728 1.1 christos break;
729 1.1 christos
730 1.1 christos case ' ':
731 1.1 christos
732 1.1 christos /* Keep the CommentType the same */
733 1.1 christos
734 1.1.1.5 christos AslGbl_CommentState.SpacesBefore++;
735 1.1 christos break;
736 1.1 christos
737 1.1 christos case '(':
738 1.1 christos
739 1.1.1.5 christos AslGbl_CommentState.CommentType = ASL_COMMENT_OPEN_PAREN;
740 1.1 christos break;
741 1.1 christos
742 1.1 christos case ')':
743 1.1 christos
744 1.1.1.5 christos AslGbl_CommentState.CommentType = ASL_COMMENT_CLOSE_PAREN;
745 1.1 christos break;
746 1.1 christos
747 1.1 christos case '{':
748 1.1 christos
749 1.1.1.5 christos AslGbl_CommentState.CommentType = ASL_COMMENT_STANDARD;
750 1.1.1.5 christos AslGbl_CommentState.ParsingParenBraceNode = NULL;
751 1.1 christos CvDbgPrint ("End Parsing paren/Brace node!\n");
752 1.1 christos break;
753 1.1 christos
754 1.1 christos case '}':
755 1.1 christos
756 1.1.1.5 christos AslGbl_CommentState.CommentType = ASL_COMMENT_CLOSE_BRACE;
757 1.1 christos break;
758 1.1 christos
759 1.1 christos case ',':
760 1.1 christos
761 1.1.1.5 christos AslGbl_CommentState.CommentType = ASLCOMMENT_INLINE;
762 1.1 christos break;
763 1.1 christos
764 1.1 christos default:
765 1.1 christos
766 1.1.1.5 christos AslGbl_CommentState.CommentType = ASLCOMMENT_INLINE;
767 1.1 christos break;
768 1.1 christos }
769 1.1 christos }
770 1.1 christos
771 1.1 christos
772 1.1 christos /*******************************************************************************
773 1.1 christos *
774 1.1 christos * FUNCTION: CvAddToCommentList
775 1.1 christos *
776 1.1.1.2 christos * PARAMETERS: ToAdd - Contains the comment to be inserted
777 1.1 christos *
778 1.1 christos * RETURN: None
779 1.1 christos *
780 1.1 christos * DESCRIPTION: Add the given char* to a list of comments in the global list
781 1.1 christos * of comments.
782 1.1 christos *
783 1.1 christos ******************************************************************************/
784 1.1 christos
785 1.1 christos void
786 1.1 christos CvAddToCommentList (
787 1.1.1.2 christos char *ToAdd)
788 1.1 christos {
789 1.1.1.2 christos
790 1.1.1.5 christos if (AslGbl_CommentListHead)
791 1.1 christos {
792 1.1.1.5 christos AslGbl_CommentListTail->Next = CvCommentNodeCalloc ();
793 1.1.1.5 christos AslGbl_CommentListTail = AslGbl_CommentListTail->Next;
794 1.1 christos }
795 1.1 christos else
796 1.1 christos {
797 1.1.1.5 christos AslGbl_CommentListHead = CvCommentNodeCalloc ();
798 1.1.1.5 christos AslGbl_CommentListTail = AslGbl_CommentListHead;
799 1.1 christos }
800 1.1 christos
801 1.1.1.5 christos AslGbl_CommentListTail->Comment = ToAdd;
802 1.1 christos }
803 1.1 christos
804 1.1.1.2 christos
805 1.1 christos /*******************************************************************************
806 1.1 christos *
807 1.1 christos * FUNCTION: CvAppendInlineComment
808 1.1 christos *
809 1.1 christos * PARAMETERS: InlineComment - Append to the end of this string.
810 1.1 christos * toAdd - Contains the comment to be inserted
811 1.1 christos *
812 1.1 christos * RETURN: Str - toAdd appended to InlineComment
813 1.1 christos *
814 1.1 christos * DESCRIPTION: Concatenate ToAdd to InlineComment
815 1.1 christos *
816 1.1 christos ******************************************************************************/
817 1.1 christos
818 1.1.1.2 christos char *
819 1.1 christos CvAppendInlineComment (
820 1.1 christos char *InlineComment,
821 1.1 christos char *ToAdd)
822 1.1 christos {
823 1.1 christos char* Str;
824 1.1 christos UINT32 Size = 0;
825 1.1 christos
826 1.1 christos
827 1.1 christos if (!InlineComment)
828 1.1 christos {
829 1.1.1.2 christos return (ToAdd);
830 1.1 christos }
831 1.1.1.2 christos
832 1.1.1.2 christos if (!ToAdd)
833 1.1 christos {
834 1.1.1.2 christos return (InlineComment);
835 1.1 christos }
836 1.1.1.2 christos
837 1.1.1.2 christos Size = strlen (ToAdd);
838 1.1 christos Size += strlen (InlineComment);
839 1.1.1.3 christos Str = UtLocalCacheCalloc (Size + 1);
840 1.1.1.2 christos
841 1.1 christos strcpy (Str, InlineComment);
842 1.1 christos strcat (Str, ToAdd);
843 1.1.1.2 christos Str[Size +1] = 0;
844 1.1.1.2 christos return (Str);
845 1.1 christos }
846 1.1 christos
847 1.1 christos
848 1.1 christos /*******************************************************************************
849 1.1 christos *
850 1.1 christos * FUNCTION: CvPlaceComment
851 1.1 christos *
852 1.1.1.2 christos * PARAMETERS: UINT8 - Type
853 1.1.1.2 christos * char * - CommentString
854 1.1 christos *
855 1.1 christos * RETURN: None
856 1.1 christos *
857 1.1 christos * DESCRIPTION: Given type and CommentString, this function places the
858 1.1.1.6 christos * CommentString in the appropriate global comment list or char*
859 1.1 christos *
860 1.1 christos ******************************************************************************/
861 1.1 christos
862 1.1 christos void
863 1.1 christos CvPlaceComment(
864 1.1 christos UINT8 Type,
865 1.1 christos char *CommentString)
866 1.1 christos {
867 1.1 christos ACPI_PARSE_OBJECT *LatestParseNode;
868 1.1 christos ACPI_PARSE_OBJECT *ParenBraceNode;
869 1.1 christos
870 1.1 christos
871 1.1.1.5 christos LatestParseNode = AslGbl_CommentState.LatestParseOp;
872 1.1.1.5 christos ParenBraceNode = AslGbl_CommentState.ParsingParenBraceNode;
873 1.1 christos CvDbgPrint ("Placing comment %s for type %d\n", CommentString, Type);
874 1.1 christos
875 1.1 christos switch (Type)
876 1.1 christos {
877 1.1 christos case ASL_COMMENT_STANDARD:
878 1.1 christos
879 1.1 christos CvAddToCommentList (CommentString);
880 1.1 christos break;
881 1.1 christos
882 1.1 christos case ASLCOMMENT_INLINE:
883 1.1 christos
884 1.1 christos LatestParseNode->Asl.InlineComment =
885 1.1 christos CvAppendInlineComment (LatestParseNode->Asl.InlineComment,
886 1.1 christos CommentString);
887 1.1 christos break;
888 1.1 christos
889 1.1 christos case ASL_COMMENT_OPEN_PAREN:
890 1.1 christos
891 1.1.1.5 christos AslGbl_InlineCommentBuffer =
892 1.1.1.5 christos CvAppendInlineComment(AslGbl_InlineCommentBuffer,
893 1.1 christos CommentString);
894 1.1 christos break;
895 1.1 christos
896 1.1 christos case ASL_COMMENT_CLOSE_PAREN:
897 1.1 christos
898 1.1 christos if (ParenBraceNode)
899 1.1 christos {
900 1.1 christos ParenBraceNode->Asl.EndNodeComment =
901 1.1 christos CvAppendInlineComment (ParenBraceNode->Asl.EndNodeComment,
902 1.1 christos CommentString);
903 1.1 christos }
904 1.1 christos else
905 1.1 christos {
906 1.1 christos LatestParseNode->Asl.EndNodeComment =
907 1.1 christos CvAppendInlineComment (LatestParseNode->Asl.EndNodeComment,
908 1.1 christos CommentString);
909 1.1 christos }
910 1.1 christos break;
911 1.1 christos
912 1.1 christos case ASL_COMMENT_CLOSE_BRACE:
913 1.1 christos
914 1.1 christos LatestParseNode->Asl.CloseBraceComment = CommentString;
915 1.1 christos break;
916 1.1 christos
917 1.1 christos default:
918 1.1 christos
919 1.1 christos break;
920 1.1 christos }
921 1.1 christos }
922