1 /******************************************************************************
2 *
3 * Module Name: aslparseop - Parse op create/allocate/cache interfaces
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2022, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
46 #include "acapps.h"
47 #include "acconvert.h"
48
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslparseop")
51
52
53 /*******************************************************************************
54 *
55 * FUNCTION: TrCreateOp
56 *
57 * PARAMETERS: ParseOpcode - Opcode to be assigned to the op
58 * NumChildren - Number of children to follow
59 * ... - A list of child ops to link to the new
60 * op. NumChildren long.
61 *
62 * RETURN: Pointer to the new op. Aborts on allocation failure
63 *
64 * DESCRIPTION: Create a new parse op and link together a list of child
65 * ops underneath the new op.
66 *
67 ******************************************************************************/
68
69 ACPI_PARSE_OBJECT *
TrCreateOp(UINT32 ParseOpcode,UINT32 NumChildren,...)70 TrCreateOp (
71 UINT32 ParseOpcode,
72 UINT32 NumChildren,
73 ...)
74 {
75 ACPI_PARSE_OBJECT *Op;
76 ACPI_PARSE_OBJECT *Child;
77 ACPI_PARSE_OBJECT *PrevChild;
78 va_list ap;
79 UINT32 i;
80 BOOLEAN FirstChild;
81
82
83 va_start (ap, NumChildren);
84
85 /* Allocate one new op */
86
87 Op = TrAllocateOp (ParseOpcode);
88
89 DbgPrint (ASL_PARSE_OUTPUT,
90 "\nCreateOp Ln/Col %u/%u NewParent %p Child %u Op %s ",
91 Op->Asl.LineNumber, Op->Asl.Column, Op,
92 NumChildren, UtGetOpName(ParseOpcode));
93
94 /* Some extra debug output based on the parse opcode */
95
96 switch (ParseOpcode)
97 {
98 case PARSEOP_ASL_CODE:
99
100 AslGbl_ParseTreeRoot = Op;
101 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
102 DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
103 break;
104
105 case PARSEOP_DEFINITION_BLOCK:
106
107 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
108 break;
109
110 case PARSEOP_OPERATIONREGION:
111
112 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
113 break;
114
115 case PARSEOP_OR:
116
117 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
118 break;
119
120 default:
121
122 /* Nothing to do for other opcodes */
123
124 break;
125 }
126
127 /* Link the new op to its children */
128
129 PrevChild = NULL;
130 FirstChild = TRUE;
131 for (i = 0; i < NumChildren; i++)
132 {
133 /* Get the next child */
134
135 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
136 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
137
138 /*
139 * If child is NULL, this means that an optional argument
140 * was omitted. We must create a placeholder with a special
141 * opcode (DEFAULT_ARG) so that the code generator will know
142 * that it must emit the correct default for this argument
143 */
144 if (!Child)
145 {
146 Child = TrAllocateOp (PARSEOP_DEFAULT_ARG);
147 }
148
149 /* Link first child to parent */
150
151 if (FirstChild)
152 {
153 FirstChild = FALSE;
154 Op->Asl.Child = Child;
155
156 /*
157 * For the ASL-/ASL+ converter: if the ParseOp is a Connection,
158 * External, Offset or AccessAs, it means that the comments in the
159 * FirstChild belongs to their parent due to the parsing order in
160 * the .y files. To correct this, take the comments in the
161 * FirstChild place it in the parent. This also means that
162 * legitimate comments for the child gets put to the parent.
163 */
164 if (AcpiGbl_CaptureComments &&
165 ((ParseOpcode == PARSEOP_CONNECTION) ||
166 (ParseOpcode == PARSEOP_EXTERNAL) ||
167 (ParseOpcode == PARSEOP_OFFSET) ||
168 (ParseOpcode == PARSEOP_ACCESSAS)))
169 {
170 Op->Asl.CommentList = Child->Asl.CommentList;
171 Op->Asl.EndBlkComment = Child->Asl.EndBlkComment;
172 Op->Asl.InlineComment = Child->Asl.InlineComment;
173 Op->Asl.FileChanged = Child->Asl.FileChanged;
174
175 Child->Asl.CommentList = NULL;
176 Child->Asl.EndBlkComment = NULL;
177 Child->Asl.InlineComment = NULL;
178 Child->Asl.FileChanged = FALSE;
179
180 /*
181 * These do not need to be "passed off". They can be copied
182 * because the code for these opcodes should be printed in the
183 * same file.
184 */
185 Op->Asl.Filename = Child->Asl.Filename;
186 Op->Asl.ParentFilename = Child->Asl.ParentFilename;
187 }
188 }
189
190 /* Point all children to parent */
191
192 Child->Asl.Parent = Op;
193
194 /* Link children in a peer list */
195
196 if (PrevChild)
197 {
198 PrevChild->Asl.Next = Child;
199 };
200
201 /* Get the comment from last child in the resource template call */
202
203 if (AcpiGbl_CaptureComments &&
204 (Op->Asl.ParseOpcode == PARSEOP_RESOURCETEMPLATE))
205 {
206 CvDbgPrint ("Transferred current comment list to this op.\n");
207 Op->Asl.CommentList = Child->Asl.CommentList;
208 Child->Asl.CommentList = NULL;
209
210 Op->Asl.InlineComment = Child->Asl.InlineComment;
211 Child->Asl.InlineComment = NULL;
212 }
213
214 /*
215 * This child might be a list, point all ops in the list
216 * to the same parent
217 */
218 while (Child->Asl.Next)
219 {
220 Child = Child->Asl.Next;
221 Child->Asl.Parent = Op;
222 }
223
224 PrevChild = Child;
225 }
226
227 va_end(ap);
228 DbgPrint (ASL_PARSE_OUTPUT, "\n");
229 return (Op);
230 }
231
232
233 /*******************************************************************************
234 *
235 * FUNCTION: TrCreateLeafOp
236 *
237 * PARAMETERS: ParseOpcode - New opcode to be assigned to the op
238 *
239 * RETURN: Pointer to the new op. Aborts on allocation failure
240 *
241 * DESCRIPTION: Create a simple leaf op (no children or peers, and no value
242 * assigned to the op)
243 *
244 ******************************************************************************/
245
246 ACPI_PARSE_OBJECT *
TrCreateLeafOp(UINT32 ParseOpcode)247 TrCreateLeafOp (
248 UINT32 ParseOpcode)
249 {
250 ACPI_PARSE_OBJECT *Op;
251
252
253 Op = TrAllocateOp (ParseOpcode);
254
255 DbgPrint (ASL_PARSE_OUTPUT,
256 "\nCreateLeafOp Ln/Col %u/%u NewOp %p Op %s\n\n",
257 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode));
258
259 return (Op);
260 }
261
262
263 /*******************************************************************************
264 *
265 * FUNCTION: TrCreateValuedLeafOp
266 *
267 * PARAMETERS: ParseOpcode - New opcode to be assigned to the op
268 * Value - Value to be assigned to the op
269 *
270 * RETURN: Pointer to the new op. Aborts on allocation failure
271 *
272 * DESCRIPTION: Create a leaf op (no children or peers) with a value
273 * assigned to it
274 *
275 ******************************************************************************/
276
277 ACPI_PARSE_OBJECT *
TrCreateValuedLeafOp(UINT32 ParseOpcode,UINT64 Value)278 TrCreateValuedLeafOp (
279 UINT32 ParseOpcode,
280 UINT64 Value)
281 {
282 ACPI_PARSE_OBJECT *Op;
283 UINT32 i;
284 char *StringPtr = NULL;
285
286
287 Op = TrAllocateOp (ParseOpcode);
288 Op->Asl.Value.Integer = Value;
289
290 DbgPrint (ASL_PARSE_OUTPUT,
291 "\nCreateValuedLeafOp Ln/Col %u/%u NewOp %p "
292 "Op %s Value %8.8X%8.8X ",
293 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode),
294 ACPI_FORMAT_UINT64 (Value));
295
296 switch (ParseOpcode)
297 {
298 case PARSEOP_STRING_LITERAL:
299
300 DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Op->Asl.Value.String);
301 break;
302
303 case PARSEOP_NAMESEG:
304
305 /* Check for mixed case (or all lower case). Issue a remark in this case */
306
307 for (i = 0; i < ACPI_NAMESEG_SIZE; i++)
308 {
309 if (islower ((int) Op->Asl.Value.Name[i]))
310 {
311 AcpiUtStrupr (&Op->Asl.Value.Name[i]);
312 AslError (ASL_REMARK, ASL_MSG_LOWER_CASE_NAMESEG, Op, Op->Asl.Value.Name);
313 break;
314 }
315 }
316 DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Op->Asl.Value.String);
317 break;
318
319 case PARSEOP_NAMESTRING:
320
321 /* Check for mixed case (or all lower case). Issue a remark in this case */
322
323 StringPtr = Op->Asl.Value.Name;
324 for (i = 0; *StringPtr; i++)
325 {
326 if (islower ((int) *StringPtr))
327 {
328 AcpiUtStrupr (&Op->Asl.Value.Name[i]);
329 AslError (ASL_REMARK, ASL_MSG_LOWER_CASE_NAMEPATH, Op, Op->Asl.Value.Name);
330 break;
331 }
332 StringPtr++;
333 }
334 DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Op->Asl.Value.String);
335 break;
336
337 case PARSEOP_EISAID:
338
339 DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Op->Asl.Value.String);
340 break;
341
342 case PARSEOP_METHOD:
343
344 DbgPrint (ASL_PARSE_OUTPUT, "METHOD");
345 break;
346
347 case PARSEOP_INTEGER:
348
349 DbgPrint (ASL_PARSE_OUTPUT, "INTEGER->%8.8X%8.8X",
350 ACPI_FORMAT_UINT64 (Value));
351 break;
352
353 default:
354 break;
355 }
356
357 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
358 return (Op);
359 }
360
361
362 /*******************************************************************************
363 *
364 * FUNCTION: TrCreateTargetOp
365 *
366 * PARAMETERS: OriginalOp - Op to be copied
367 *
368 * RETURN: Pointer to the new op. Aborts on allocation failure
369 *
370 * DESCRIPTION: Copy an existing op (and subtree). Used in ASL+ (C-style)
371 * expressions where the target is the same as one of the
372 * operands. A new op and subtree must be created from the
373 * original so that the parse tree can be linked properly.
374 *
375 * NOTE: This code is specific to target operands that are the last
376 * operand in an ASL/AML operator. Meaning that the top-level
377 * parse Op in a possible subtree has a NULL Next pointer.
378 * This simplifies the recursion.
379 *
380 * Subtree example:
381 * DeRefOf (Local1) += 32
382 *
383 * This gets converted to:
384 * Add (DeRefOf (Local1), 32, DeRefOf (Local1))
385 *
386 * Each DeRefOf has a single child, Local1. Even more complex
387 * subtrees can be created via the Index and DeRefOf operators.
388 *
389 ******************************************************************************/
390
391 ACPI_PARSE_OBJECT *
TrCreateTargetOp(ACPI_PARSE_OBJECT * OriginalOp,ACPI_PARSE_OBJECT * ParentOp)392 TrCreateTargetOp (
393 ACPI_PARSE_OBJECT *OriginalOp,
394 ACPI_PARSE_OBJECT *ParentOp)
395 {
396 ACPI_PARSE_OBJECT *Op;
397
398
399 if (!OriginalOp)
400 {
401 return (NULL);
402 }
403
404 Op = UtParseOpCacheCalloc ();
405
406 /* Copy the pertinent values (omit link pointer fields) */
407
408 Op->Asl.Value = OriginalOp->Asl.Value;
409 Op->Asl.Filename = OriginalOp->Asl.Filename;
410 Op->Asl.LineNumber = OriginalOp->Asl.LineNumber;
411 Op->Asl.LogicalLineNumber = OriginalOp->Asl.LogicalLineNumber;
412 Op->Asl.LogicalByteOffset = OriginalOp->Asl.LogicalByteOffset;
413 Op->Asl.Column = OriginalOp->Asl.Column;
414 Op->Asl.Flags = OriginalOp->Asl.Flags;
415 Op->Asl.CompileFlags = OriginalOp->Asl.CompileFlags;
416 Op->Asl.AmlOpcode = OriginalOp->Asl.AmlOpcode;
417 Op->Asl.ParseOpcode = OriginalOp->Asl.ParseOpcode;
418 Op->Asl.Parent = ParentOp;
419
420 UtSetParseOpName (Op);
421
422 /* Copy a possible subtree below this op */
423
424 if (OriginalOp->Asl.Child)
425 {
426 Op->Asl.Child = TrCreateTargetOp (OriginalOp->Asl.Child, Op);
427 }
428
429 if (OriginalOp->Asl.Next) /* Null for top-level op */
430 {
431 Op->Asl.Next = TrCreateTargetOp (OriginalOp->Asl.Next, ParentOp);
432 }
433
434 return (Op);
435 }
436
437
438 /*******************************************************************************
439 *
440 * FUNCTION: TrCreateAssignmentOp
441 *
442 * PARAMETERS: Target - Assignment target
443 * Source - Assignment source
444 *
445 * RETURN: Pointer to the new op. Aborts on allocation failure
446 *
447 * DESCRIPTION: Implements the C-style '=' operator. It changes the parse
448 * tree if possible to utilize the last argument of the math
449 * operators which is a target operand -- thus saving invocation
450 * of and additional Store() operator. An optimization.
451 *
452 ******************************************************************************/
453
454 ACPI_PARSE_OBJECT *
TrCreateAssignmentOp(ACPI_PARSE_OBJECT * Target,ACPI_PARSE_OBJECT * Source)455 TrCreateAssignmentOp (
456 ACPI_PARSE_OBJECT *Target,
457 ACPI_PARSE_OBJECT *Source)
458 {
459 ACPI_PARSE_OBJECT *TargetOp;
460 ACPI_PARSE_OBJECT *SourceOp1;
461 ACPI_PARSE_OBJECT *SourceOp2;
462 ACPI_PARSE_OBJECT *Operator;
463
464
465 DbgPrint (ASL_PARSE_OUTPUT,
466 "\nTrCreateAssignmentOp Line [%u to %u] Source %s Target %s\n",
467 Source->Asl.LineNumber, Source->Asl.EndLine,
468 UtGetOpName (Source->Asl.ParseOpcode),
469 UtGetOpName (Target->Asl.ParseOpcode));
470
471 TrSetOpFlags (Target, OP_IS_TARGET);
472
473 switch (Source->Asl.ParseOpcode)
474 {
475 /*
476 * Only these operators can be optimized because they have
477 * a target operand
478 */
479 case PARSEOP_ADD:
480 case PARSEOP_AND:
481 case PARSEOP_DIVIDE:
482 case PARSEOP_INDEX:
483 case PARSEOP_MOD:
484 case PARSEOP_MULTIPLY:
485 case PARSEOP_NOT:
486 case PARSEOP_OR:
487 case PARSEOP_SHIFTLEFT:
488 case PARSEOP_SHIFTRIGHT:
489 case PARSEOP_SUBTRACT:
490 case PARSEOP_XOR:
491
492 break;
493
494 /* Otherwise, just create a normal Store operator */
495
496 default:
497 goto CannotOptimize;
498 }
499
500 /*
501 * Transform the parse tree such that the target is moved to the
502 * last operand of the operator
503 */
504 SourceOp1 = Source->Asl.Child;
505 SourceOp2 = SourceOp1->Asl.Next;
506
507 /* NOT only has one operand, but has a target */
508
509 if (Source->Asl.ParseOpcode == PARSEOP_NOT)
510 {
511 SourceOp2 = SourceOp1;
512 }
513
514 /* DIVIDE has an extra target operand (remainder) */
515
516 if (Source->Asl.ParseOpcode == PARSEOP_DIVIDE)
517 {
518 SourceOp2 = SourceOp2->Asl.Next;
519 }
520
521 TargetOp = SourceOp2->Asl.Next;
522
523 /*
524 * Can't perform this optimization if there already is a target
525 * for the operator (ZERO is a "no target" placeholder).
526 */
527 if (TargetOp->Asl.ParseOpcode != PARSEOP_ZERO)
528 {
529 goto CannotOptimize;
530 }
531
532 /* Link in the target as the final operand */
533
534 SourceOp2->Asl.Next = Target;
535 Target->Asl.Parent = Source;
536 return (Source);
537
538
539 CannotOptimize:
540
541 Operator = TrAllocateOp (PARSEOP_STORE);
542 TrLinkOpChildren (Operator, 2, Source, Target);
543
544 /* Set the appropriate line numbers for the new op */
545
546 Operator->Asl.LineNumber = Target->Asl.LineNumber;
547 Operator->Asl.LogicalLineNumber = Target->Asl.LogicalLineNumber;
548 Operator->Asl.LogicalByteOffset = Target->Asl.LogicalByteOffset;
549 Operator->Asl.Column = Target->Asl.Column;
550
551 return (Operator);
552 }
553
554
555 /*******************************************************************************
556 *
557 * FUNCTION: TrCreateNullTargetOp
558 *
559 * PARAMETERS: None
560 *
561 * RETURN: Pointer to the new op. Aborts on allocation failure
562 *
563 * DESCRIPTION: Create a "null" target op. This is defined by the ACPI
564 * specification to be a zero AML opcode, and indicates that
565 * no target has been specified for the parent operation
566 *
567 ******************************************************************************/
568
569 ACPI_PARSE_OBJECT *
TrCreateNullTargetOp(void)570 TrCreateNullTargetOp (
571 void)
572 {
573 ACPI_PARSE_OBJECT *Op;
574
575
576 Op = TrAllocateOp (PARSEOP_ZERO);
577 Op->Asl.CompileFlags |= (OP_IS_TARGET | OP_COMPILE_TIME_CONST);
578
579 DbgPrint (ASL_PARSE_OUTPUT,
580 "\nCreateNullTargetOp Ln/Col %u/%u NewOp %p Op %s\n",
581 Op->Asl.LineNumber, Op->Asl.Column, Op,
582 UtGetOpName (Op->Asl.ParseOpcode));
583
584 return (Op);
585 }
586
587
588 /*******************************************************************************
589 *
590 * FUNCTION: TrCreateConstantLeafOp
591 *
592 * PARAMETERS: ParseOpcode - The constant opcode
593 *
594 * RETURN: Pointer to the new op. Aborts on allocation failure
595 *
596 * DESCRIPTION: Create a leaf op (no children or peers) for one of the
597 * special constants - __LINE__, __FILE__, and __DATE__.
598 *
599 * Note: The fullimplemenation of __METHOD__ cannot happen here because we
600 * don't have a full parse tree at this time and cannot find the parent
601 * control method. __METHOD__ must be implemented later, after the parse
602 * tree has been fully constructed.
603 *
604 ******************************************************************************/
605
606 ACPI_PARSE_OBJECT *
TrCreateConstantLeafOp(UINT32 ParseOpcode)607 TrCreateConstantLeafOp (
608 UINT32 ParseOpcode)
609 {
610 ACPI_PARSE_OBJECT *Op = NULL;
611 time_t CurrentTime;
612 char *StaticTimeString;
613 char *TimeString;
614 char *Filename = NULL;
615 ACPI_STATUS Status;
616
617
618 switch (ParseOpcode)
619 {
620 case PARSEOP___LINE__:
621
622 Op = TrAllocateOp (PARSEOP_INTEGER);
623 Op->Asl.Value.Integer = Op->Asl.LineNumber;
624 break;
625
626 case PARSEOP___METHOD__:
627
628 /* Will become a string literal later */
629
630 Op = TrAllocateOp (PARSEOP___METHOD__);
631 Op->Asl.Value.String = NULL;
632 break;
633
634 case PARSEOP___PATH__:
635
636 Op = TrAllocateOp (PARSEOP_STRING_LITERAL);
637
638 /* Op.Asl.Filename contains the full pathname to the file */
639
640 Op->Asl.Value.String = Op->Asl.Filename;
641 break;
642
643 case PARSEOP___FILE__:
644
645 Op = TrAllocateOp (PARSEOP_STRING_LITERAL);
646
647 /* Get the simple filename from the full path */
648
649 Status = FlSplitInputPathname (Op->Asl.Filename, NULL, &Filename);
650 if (ACPI_FAILURE (Status))
651 {
652 return (NULL);
653 }
654
655 Op->Asl.Value.String = Filename;
656 break;
657
658 case PARSEOP___DATE__:
659
660 Op = TrAllocateOp (PARSEOP_STRING_LITERAL);
661
662 /* Get a copy of the current time */
663
664 Op->Asl.Value.String = "";
665 CurrentTime = time (NULL);
666
667 StaticTimeString = ctime (&CurrentTime);
668 if (StaticTimeString)
669 {
670 TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1);
671 strcpy (TimeString, StaticTimeString);
672
673 TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */
674 Op->Asl.Value.String = TimeString;
675 }
676 break;
677
678 default: /* This would be an internal error */
679
680 return (NULL);
681 }
682
683 DbgPrint (ASL_PARSE_OUTPUT,
684 "\nCreateConstantLeafOp Ln/Col %u/%u NewOp %p "
685 "Op %s Value %8.8X%8.8X \n",
686 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode),
687 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
688
689 return (Op);
690 }
691
692
693 /*******************************************************************************
694 *
695 * FUNCTION: TrAllocateOp
696 *
697 * PARAMETERS: ParseOpcode - Opcode to be assigned to the op
698 *
699 * RETURN: New parse op. Aborts on allocation failure
700 *
701 * DESCRIPTION: Allocate and initialize a new parse op for the parse tree
702 *
703 ******************************************************************************/
704
705 ACPI_PARSE_OBJECT *
TrAllocateOp(UINT32 ParseOpcode)706 TrAllocateOp (
707 UINT32 ParseOpcode)
708 {
709 ACPI_PARSE_OBJECT *Op;
710 ACPI_PARSE_OBJECT *LatestOp;
711
712
713 Op = UtParseOpCacheCalloc ();
714
715 Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
716 Op->Asl.Filename = AslGbl_Files[ASL_FILE_INPUT].Filename;
717 Op->Asl.LineNumber = AslGbl_CurrentLineNumber;
718 Op->Asl.LogicalLineNumber = AslGbl_LogicalLineNumber;
719 Op->Asl.LogicalByteOffset = AslGbl_CurrentLineOffset;
720 Op->Asl.Column = AslGbl_CurrentColumn;
721
722 UtSetParseOpName (Op);
723
724 /* The following is for capturing comments */
725
726 if (AcpiGbl_CaptureComments)
727 {
728 LatestOp = AslGbl_CommentState.LatestParseOp;
729 Op->Asl.InlineComment = NULL;
730 Op->Asl.EndNodeComment = NULL;
731 Op->Asl.CommentList = NULL;
732 Op->Asl.FileChanged = FALSE;
733
734 /*
735 * Check to see if the file name has changed before resetting the
736 * latest parse op.
737 */
738 if (LatestOp &&
739 (ParseOpcode != PARSEOP_INCLUDE) &&
740 (ParseOpcode != PARSEOP_INCLUDE_END) &&
741 strcmp (LatestOp->Asl.Filename, Op->Asl.Filename))
742 {
743 CvDbgPrint ("latest op: %s\n", LatestOp->Asl.ParseOpName);
744 Op->Asl.FileChanged = TRUE;
745 if (AslGbl_IncludeFileStack)
746 {
747 Op->Asl.ParentFilename = AslGbl_IncludeFileStack->Filename;
748 }
749 else
750 {
751 Op->Asl.ParentFilename = NULL;
752 }
753 }
754
755 AslGbl_CommentState.LatestParseOp = Op;
756 CvDbgPrint ("TrAllocateOp=Set latest parse op to this op.\n");
757 CvDbgPrint (" Op->Asl.ParseOpName = %s\n",
758 AslGbl_CommentState.LatestParseOp->Asl.ParseOpName);
759 CvDbgPrint (" Op->Asl.ParseOpcode = 0x%x\n", ParseOpcode);
760
761 if (Op->Asl.FileChanged)
762 {
763 CvDbgPrint(" file has been changed!\n");
764 }
765
766 /*
767 * if this parse op's syntax uses () and {} (i.e. Package(1){0x00}) then
768 * set a flag in the comment state. This facilitates paring comments for
769 * these types of opcodes.
770 */
771 if ((CvParseOpBlockType(Op) == (BLOCK_PAREN | BLOCK_BRACE)) &&
772 (ParseOpcode != PARSEOP_DEFINITION_BLOCK))
773 {
774 CvDbgPrint ("Parsing paren/Brace op now!\n");
775 AslGbl_CommentState.ParsingParenBraceNode = Op;
776 }
777
778 if (AslGbl_CommentListHead)
779 {
780 CvDbgPrint ("Transferring...\n");
781 Op->Asl.CommentList = AslGbl_CommentListHead;
782 AslGbl_CommentListHead = NULL;
783 AslGbl_CommentListTail = NULL;
784 CvDbgPrint (" Transferred current comment list to this op.\n");
785 CvDbgPrint (" %s\n", Op->Asl.CommentList->Comment);
786 }
787
788 if (AslGbl_InlineCommentBuffer)
789 {
790 Op->Asl.InlineComment = AslGbl_InlineCommentBuffer;
791 AslGbl_InlineCommentBuffer = NULL;
792 CvDbgPrint ("Transferred current inline comment list to this op.\n");
793 }
794 }
795
796 return (Op);
797 }
798
799
800 /*******************************************************************************
801 *
802 * FUNCTION: TrPrintOpFlags
803 *
804 * PARAMETERS: Flags - Flags word to be decoded
805 * OutputLevel - Debug output level: ASL_TREE_OUTPUT etc.
806 *
807 * RETURN: None
808 *
809 * DESCRIPTION: Decode a flags word to text. Displays all flags that are set.
810 *
811 ******************************************************************************/
812
813 void
TrPrintOpFlags(UINT32 Flags,UINT32 OutputLevel)814 TrPrintOpFlags (
815 UINT32 Flags,
816 UINT32 OutputLevel)
817 {
818 UINT32 FlagBit = 1;
819 UINT32 i;
820
821
822 for (i = 0; i < ACPI_NUM_OP_FLAGS; i++)
823 {
824 if (Flags & FlagBit)
825 {
826 DbgPrint (OutputLevel, " %s", AslGbl_OpFlagNames[i]);
827 }
828
829 FlagBit <<= 1;
830 }
831 }
832