Deleted Added
full compact
aslfiles.c (118611) aslfiles.c (126372)
1
2/******************************************************************************
3 *
4 * Module Name: aslfiles - file I/O suppoert
1
2/******************************************************************************
3 *
4 * Module Name: aslfiles - file I/O suppoert
5 * $Revision: 46 $
5 * $Revision: 47 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#include "aslcompiler.h"
119#include "acapps.h"
120
121#define _COMPONENT ACPI_COMPILER
122 ACPI_MODULE_NAME ("aslfiles")
123
124
125/*******************************************************************************
126 *
127 * FUNCTION: AslAbort
128 *
129 * PARAMETERS: None
130 *
131 * RETURN: None
132 *
133 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
134 * I/O errors
135 *
136 ******************************************************************************/
137
138void
139AslAbort (void)
140{
141
142 AePrintErrorLog (ASL_FILE_STDOUT);
143 if (Gbl_DebugFlag)
144 {
145 /* Print error summary to the debug file */
146
147 AePrintErrorLog (ASL_FILE_STDERR);
148 }
149
150 exit (0);
151}
152
153
154/*******************************************************************************
155 *
156 * FUNCTION: FlOpenLocalFile
157 *
158 * PARAMETERS: LocalName - Single filename (not a pathname)
159 * Mode - Open mode for fopen
160 *
161 * RETURN: File descriptor
162 *
163 * DESCRIPTION: Build a complete pathname for the input filename and open
164 * the file.
165 *
166 ******************************************************************************/
167
168FILE *
169FlOpenLocalFile (
170 char *LocalName,
171 char *Mode)
172{
173
174 strcpy (StringBuffer, Gbl_DirectoryPath);
175 strcat (StringBuffer, LocalName);
176
177 DbgPrint (ASL_PARSE_OUTPUT, "FlOpenLocalFile: %s\n", StringBuffer);
178 return (fopen (StringBuffer, (const char *) Mode));
179}
180
181
182/*******************************************************************************
183 *
184 * FUNCTION: FlFileError
185 *
186 * PARAMETERS: FileId - Index into file info array
187 * ErrorId - Index into error message array
188 *
189 * RETURN: None
190 *
191 * DESCRIPTION: Decode errno to an error message and add the entire error
192 * to the error log.
193 *
194 ******************************************************************************/
195
196void
197FlFileError (
198 UINT32 FileId,
199 UINT8 ErrorId)
200{
201
202 sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, strerror (errno));
203 AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer);
204}
205
206
207/*******************************************************************************
208 *
209 * FUNCTION: FlOpenFile
210 *
211 * PARAMETERS: FileId - Index into file info array
212 * Filename - file pathname to open
213 * Mode - Open mode for fopen
214 *
215 * RETURN: File descriptor
216 *
217 * DESCRIPTION: Open a file.
218 * NOTE: Aborts compiler on any error.
219 *
220 ******************************************************************************/
221
222void
223FlOpenFile (
224 UINT32 FileId,
225 char *Filename,
226 char *Mode)
227{
228 FILE *File;
229
230
231 File = fopen (Filename, Mode);
232
233 Gbl_Files[FileId].Filename = Filename;
234 Gbl_Files[FileId].Handle = File;
235
236 if (!File)
237 {
238 FlFileError (FileId, ASL_MSG_OPEN);
239 AslAbort ();
240 }
241}
242
243
244/*******************************************************************************
245 *
246 * FUNCTION: FlReadFile
247 *
248 * PARAMETERS: FileId - Index into file info array
249 * Buffer - Where to place the data
250 * Length - Amount to read
251 *
252 * RETURN: Status. AE_ERROR indicates EOF.
253 *
254 * DESCRIPTION: Read data from an open file.
255 * NOTE: Aborts compiler on any error.
256 *
257 ******************************************************************************/
258
259ACPI_STATUS
260FlReadFile (
261 UINT32 FileId,
262 void *Buffer,
263 UINT32 Length)
264{
265 UINT32 Actual;
266
267
268 /* Read and check for error */
269
270 Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle);
271 if (Actual != Length)
272 {
273 if (feof (Gbl_Files[FileId].Handle))
274 {
275 /* End-of-file, just return error */
276
277 return (AE_ERROR);
278 }
279
280 FlFileError (FileId, ASL_MSG_READ);
281 AslAbort ();
282 }
283
284 return (AE_OK);
285}
286
287
288/*******************************************************************************
289 *
290 * FUNCTION: FlWriteFile
291 *
292 * PARAMETERS: FileId - Index into file info array
293 * Buffer - Data to write
294 * Length - Amount of data to write
295 *
296 * RETURN: Status
297 *
298 * DESCRIPTION: Write data to an open file.
299 * NOTE: Aborts compiler on any error.
300 *
301 ******************************************************************************/
302
303void
304FlWriteFile (
305 UINT32 FileId,
306 void *Buffer,
307 UINT32 Length)
308{
309 UINT32 Actual;
310
311
312 /* Write and check for error */
313
314 Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle);
315 if (Actual != Length)
316 {
317 FlFileError (FileId, ASL_MSG_WRITE);
318 AslAbort ();
319 }
320}
321
322
323/*******************************************************************************
324 *
325 * FUNCTION: FlPrintFile
326 *
327 * PARAMETERS: FileId - Index into file info array
328 * Format - Printf format string
329 * ... - Printf arguments
330 *
331 * RETURN: None
332 *
333 * DESCRIPTION: Formatted write to an open file.
334 * NOTE: Aborts compiler on any error.
335 *
336 ******************************************************************************/
337
338void
339FlPrintFile (
340 UINT32 FileId,
341 char *Format,
342 ...)
343{
344 INT32 Actual;
345 va_list Args;
346
347
348 va_start (Args, Format);
349
350 Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args);
351 if (Actual == -1)
352 {
353 FlFileError (FileId, ASL_MSG_WRITE);
354 AslAbort ();
355 }
356}
357
358
359/*******************************************************************************
360 *
361 * FUNCTION: FlSeekFile
362 *
363 * PARAMETERS: FileId - Index into file info array
364 * Offset - Absolute byte offset in file
365 *
366 * RETURN: Status
367 *
368 * DESCRIPTION: Seek to absolute offset
369 * NOTE: Aborts compiler on any error.
370 *
371 ******************************************************************************/
372
373void
374FlSeekFile (
375 UINT32 FileId,
376 long Offset)
377{
378 int Error;
379
380
381 Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET);
382 if (Error)
383 {
384 FlFileError (FileId, ASL_MSG_SEEK);
385 AslAbort ();
386 }
387}
388
389
390/*******************************************************************************
391 *
392 * FUNCTION: FlCloseFile
393 *
394 * PARAMETERS: FileId - Index into file info array
395 *
396 * RETURN: Status
397 *
398 * DESCRIPTION: Close an open file. Aborts compiler on error
399 *
400 ******************************************************************************/
401
402void
403FlCloseFile (
404 UINT32 FileId)
405{
406 int Error;
407
408
409 if (!Gbl_Files[FileId].Handle)
410 {
411 return;
412 }
413
414 Error = fclose (Gbl_Files[FileId].Handle);
415 Gbl_Files[FileId].Handle = NULL;
416
417 if (Error)
418 {
419 FlFileError (FileId, ASL_MSG_CLOSE);
420 AslAbort ();
421 }
422
423 return;
424}
425
426
427/*******************************************************************************
428 *
429 * FUNCTION: FlSetLineNumber
430 *
431 * PARAMETERS: Op - Parse node for the LINE asl statement
432 *
433 * RETURN: None.
434 *
435 * DESCRIPTION: Set the current line number
436 *
437 ******************************************************************************/
438
439void
440FlSetLineNumber (
441 ACPI_PARSE_OBJECT *Op)
442{
443
444 Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer;
445 Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer;
446}
447
448
449/*******************************************************************************
450 *
451 * FUNCTION: FlOpenIncludeFile
452 *
453 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement
454 *
455 * RETURN: None.
456 *
457 * DESCRIPTION: Open an include file and push it on the input file stack.
458 *
459 ******************************************************************************/
460
461void
462FlOpenIncludeFile (
463 ACPI_PARSE_OBJECT *Op)
464{
465 FILE *IncFile;
466
467
468 /* Op must be valid */
469
470 if (!Op)
471 {
472 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
473 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
474 Gbl_InputByteCount, Gbl_CurrentColumn,
475 Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
476
477 return;
478 }
479
480 /*
481 * Flush out the "include ()" statement on this line, start
482 * the actual include file on the next line
483 */
484 ResetCurrentLineBuffer ();
485 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
486 Gbl_CurrentLineOffset++;
487
488 /* Prepend the directory pathname and open the include file */
489
490 DbgPrint (ASL_PARSE_OUTPUT, "\nOpen include file: path %s\n\n", Op->Asl.Value.String);
491 IncFile = FlOpenLocalFile (Op->Asl.Value.String, "r");
492 if (!IncFile)
493 {
494 sprintf (MsgBuffer, "%s (%s)", Op->Asl.Value.String, strerror (errno));
495 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
496 return;
497 }
498
499 /* Push the include file on the open input file stack */
500
501 AslPushInputFileStack (IncFile, Op->Asl.Value.String);
502}
503
504
505/*******************************************************************************
506 *
507 * FUNCTION: FlParseInputPathname
508 *
509 * PARAMETERS: InputFilename - The user-specified ASL source file to be
510 * compiled
511 *
512 * RETURN: Status
513 *
514 * DESCRIPTION: Split the input path into a directory and filename part
515 * 1) Directory part used to open include files
516 * 2) Filename part used to generate output filenames
517 *
518 ******************************************************************************/
519
520ACPI_STATUS
521FlParseInputPathname (
522 char *InputFilename)
523{
524 char *Substring;
525
526
527 if (!InputFilename)
528 {
529 return (AE_OK);
530 }
531
532 /* Get the path to the input filename's directory */
533
534 Gbl_DirectoryPath = strdup (InputFilename);
535 if (!Gbl_DirectoryPath)
536 {
537 return (AE_NO_MEMORY);
538 }
539
540 Substring = strrchr (Gbl_DirectoryPath, '\\');
541 if (!Substring)
542 {
543 Substring = strrchr (Gbl_DirectoryPath, '/');
544 if (!Substring)
545 {
546 Substring = strrchr (Gbl_DirectoryPath, ':');
547 }
548 }
549
550 if (!Substring)
551 {
552 Gbl_DirectoryPath[0] = 0;
553 if (Gbl_UseDefaultAmlFilename)
554 {
555 Gbl_OutputFilenamePrefix = strdup (InputFilename);
556 }
557 }
558 else
559 {
560 if (Gbl_UseDefaultAmlFilename)
561 {
562 Gbl_OutputFilenamePrefix = strdup (Substring + 1);
563 }
564 *(Substring+1) = 0;
565 }
566
567 return (AE_OK);
568}
569
570
571/*******************************************************************************
572 *
573 * FUNCTION: FlOpenInputFile
574 *
575 * PARAMETERS: InputFilename - The user-specified ASL source file to be
576 * compiled
577 *
578 * RETURN: Status
579 *
580 * DESCRIPTION: Open the specified input file, and save the directory path to
581 * the file so that include files can be opened in
582 * the same directory.
583 *
584 ******************************************************************************/
585
586ACPI_STATUS
587FlOpenInputFile (
588 char *InputFilename)
589{
590
591
592 /* Open the input ASL file, text mode */
593
594 FlOpenFile (ASL_FILE_INPUT, InputFilename, "r");
595 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
596
597 return (AE_OK);
598}
599
600
601/*******************************************************************************
602 *
603 * FUNCTION: FlOpenAmlOutputFile
604 *
605 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
606 *
607 * RETURN: Status
608 *
609 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
610 * is created in the same directory as the parent input file.
611 *
612 ******************************************************************************/
613
614ACPI_STATUS
615FlOpenAmlOutputFile (
616 char *FilenamePrefix)
617{
618 char *Filename;
619
620
621 /* Output filename usually comes from the ASL itself */
622
623 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
624 if (!Filename)
625 {
626 /* Create the output AML filename */
627
628 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
629 if (!Filename)
630 {
631 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 0, 0, 0, 0, NULL, NULL);
632 return (AE_ERROR);
633 }
634 }
635
636 /* Open the output AML file in binary mode */
637
638 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
639 return (AE_OK);
640}
641
642
643/*******************************************************************************
644 *
645 * FUNCTION: FlOpenMiscOutputFiles
646 *
647 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
648 *
649 * RETURN: Status
650 *
651 * DESCRIPTION: Create and open the various output files needed, depending on
652 * the command line options
653 *
654 ******************************************************************************/
655
656ACPI_STATUS
657FlOpenMiscOutputFiles (
658 char *FilenamePrefix)
659{
660 char *Filename;
661
662
663 /* Create/Open a combined source output file */
664
665 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
666 if (!Filename)
667 {
668 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
669 return (AE_ERROR);
670 }
671
672 /*
673 * Open the source output file, binary mode (so that LF does not get
674 * expanded to CR/LF on some systems, messing up our seek
675 * calculations.)
676 */
677 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
678
679 /* Create/Open a listing output file if asked */
680
681 if (Gbl_ListingFlag)
682 {
683 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
684 if (!Filename)
685 {
686 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
687 return (AE_ERROR);
688 }
689
690 /* Open the listing file, text mode */
691
692 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+");
693
694 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
695 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
696 }
697
698 /* Create/Open a assembly code source output file if asked */
699
700 if (Gbl_AsmOutputFlag)
701 {
702 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
703 if (!Filename)
704 {
705 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
706 return (AE_ERROR);
707 }
708
709 /* Open the assembly code source file, text mode */
710
711 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+");
712
713 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
714 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
715 }
716
717 /* Create/Open a C code source output file if asked */
718
719 if (Gbl_C_OutputFlag)
720 {
721 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
722 if (!Filename)
723 {
724 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
725 return (AE_ERROR);
726 }
727
728 /* Open the C code source file, text mode */
729
730 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+");
731
732 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
733 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
734 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
735 }
736
737 /* Create/Open a assembly include output file if asked */
738
739 if (Gbl_AsmIncludeOutputFlag)
740 {
741 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
742 if (!Filename)
743 {
744 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
745 return (AE_ERROR);
746 }
747
748 /* Open the assembly include file, text mode */
749
750 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+");
751
752 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
753 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
754 }
755
756 /* Create/Open a C include output file if asked */
757
758 if (Gbl_C_IncludeOutputFlag)
759 {
760 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
761 if (!Filename)
762 {
763 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
764 return (AE_ERROR);
765 }
766
767 /* Open the C include file, text mode */
768
769 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+");
770
771 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
772 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
773 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
774 }
775
776 /* Create/Open a hex output file if asked */
777
778 if (Gbl_HexOutputFlag)
779 {
780 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
781 if (!Filename)
782 {
783 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
784 return (AE_ERROR);
785 }
786
787 /* Open the hex file, text mode */
788
789 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+");
790
791 AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
792 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
793 }
794
795 /* Create a namespace output file if asked */
796
797 if (Gbl_NsOutputFlag)
798 {
799 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
800 if (!Filename)
801 {
802 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
803 return (AE_ERROR);
804 }
805
806 /* Open the namespace file, text mode */
807
808 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+");
809
810 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
811 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
812 }
813
814 /* Create/Open a debug output file if asked */
815
816 if (Gbl_DebugFlag)
817 {
818 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
819 if (!Filename)
820 {
821 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 0, 0, 0, 0, NULL, NULL);
822 return (AE_ERROR);
823 }
824
825 /* Open the debug file as STDERR, text mode */
826
827 /* TBD: hide this behind a FlReopenFile function */
828
829 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
830 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = freopen (Filename, "w+t", stderr);
831
832 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
833 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
834 }
835
836 return (AE_OK);
837}
838
839
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#include "aslcompiler.h"
119#include "acapps.h"
120
121#define _COMPONENT ACPI_COMPILER
122 ACPI_MODULE_NAME ("aslfiles")
123
124
125/*******************************************************************************
126 *
127 * FUNCTION: AslAbort
128 *
129 * PARAMETERS: None
130 *
131 * RETURN: None
132 *
133 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
134 * I/O errors
135 *
136 ******************************************************************************/
137
138void
139AslAbort (void)
140{
141
142 AePrintErrorLog (ASL_FILE_STDOUT);
143 if (Gbl_DebugFlag)
144 {
145 /* Print error summary to the debug file */
146
147 AePrintErrorLog (ASL_FILE_STDERR);
148 }
149
150 exit (0);
151}
152
153
154/*******************************************************************************
155 *
156 * FUNCTION: FlOpenLocalFile
157 *
158 * PARAMETERS: LocalName - Single filename (not a pathname)
159 * Mode - Open mode for fopen
160 *
161 * RETURN: File descriptor
162 *
163 * DESCRIPTION: Build a complete pathname for the input filename and open
164 * the file.
165 *
166 ******************************************************************************/
167
168FILE *
169FlOpenLocalFile (
170 char *LocalName,
171 char *Mode)
172{
173
174 strcpy (StringBuffer, Gbl_DirectoryPath);
175 strcat (StringBuffer, LocalName);
176
177 DbgPrint (ASL_PARSE_OUTPUT, "FlOpenLocalFile: %s\n", StringBuffer);
178 return (fopen (StringBuffer, (const char *) Mode));
179}
180
181
182/*******************************************************************************
183 *
184 * FUNCTION: FlFileError
185 *
186 * PARAMETERS: FileId - Index into file info array
187 * ErrorId - Index into error message array
188 *
189 * RETURN: None
190 *
191 * DESCRIPTION: Decode errno to an error message and add the entire error
192 * to the error log.
193 *
194 ******************************************************************************/
195
196void
197FlFileError (
198 UINT32 FileId,
199 UINT8 ErrorId)
200{
201
202 sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, strerror (errno));
203 AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer);
204}
205
206
207/*******************************************************************************
208 *
209 * FUNCTION: FlOpenFile
210 *
211 * PARAMETERS: FileId - Index into file info array
212 * Filename - file pathname to open
213 * Mode - Open mode for fopen
214 *
215 * RETURN: File descriptor
216 *
217 * DESCRIPTION: Open a file.
218 * NOTE: Aborts compiler on any error.
219 *
220 ******************************************************************************/
221
222void
223FlOpenFile (
224 UINT32 FileId,
225 char *Filename,
226 char *Mode)
227{
228 FILE *File;
229
230
231 File = fopen (Filename, Mode);
232
233 Gbl_Files[FileId].Filename = Filename;
234 Gbl_Files[FileId].Handle = File;
235
236 if (!File)
237 {
238 FlFileError (FileId, ASL_MSG_OPEN);
239 AslAbort ();
240 }
241}
242
243
244/*******************************************************************************
245 *
246 * FUNCTION: FlReadFile
247 *
248 * PARAMETERS: FileId - Index into file info array
249 * Buffer - Where to place the data
250 * Length - Amount to read
251 *
252 * RETURN: Status. AE_ERROR indicates EOF.
253 *
254 * DESCRIPTION: Read data from an open file.
255 * NOTE: Aborts compiler on any error.
256 *
257 ******************************************************************************/
258
259ACPI_STATUS
260FlReadFile (
261 UINT32 FileId,
262 void *Buffer,
263 UINT32 Length)
264{
265 UINT32 Actual;
266
267
268 /* Read and check for error */
269
270 Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle);
271 if (Actual != Length)
272 {
273 if (feof (Gbl_Files[FileId].Handle))
274 {
275 /* End-of-file, just return error */
276
277 return (AE_ERROR);
278 }
279
280 FlFileError (FileId, ASL_MSG_READ);
281 AslAbort ();
282 }
283
284 return (AE_OK);
285}
286
287
288/*******************************************************************************
289 *
290 * FUNCTION: FlWriteFile
291 *
292 * PARAMETERS: FileId - Index into file info array
293 * Buffer - Data to write
294 * Length - Amount of data to write
295 *
296 * RETURN: Status
297 *
298 * DESCRIPTION: Write data to an open file.
299 * NOTE: Aborts compiler on any error.
300 *
301 ******************************************************************************/
302
303void
304FlWriteFile (
305 UINT32 FileId,
306 void *Buffer,
307 UINT32 Length)
308{
309 UINT32 Actual;
310
311
312 /* Write and check for error */
313
314 Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle);
315 if (Actual != Length)
316 {
317 FlFileError (FileId, ASL_MSG_WRITE);
318 AslAbort ();
319 }
320}
321
322
323/*******************************************************************************
324 *
325 * FUNCTION: FlPrintFile
326 *
327 * PARAMETERS: FileId - Index into file info array
328 * Format - Printf format string
329 * ... - Printf arguments
330 *
331 * RETURN: None
332 *
333 * DESCRIPTION: Formatted write to an open file.
334 * NOTE: Aborts compiler on any error.
335 *
336 ******************************************************************************/
337
338void
339FlPrintFile (
340 UINT32 FileId,
341 char *Format,
342 ...)
343{
344 INT32 Actual;
345 va_list Args;
346
347
348 va_start (Args, Format);
349
350 Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args);
351 if (Actual == -1)
352 {
353 FlFileError (FileId, ASL_MSG_WRITE);
354 AslAbort ();
355 }
356}
357
358
359/*******************************************************************************
360 *
361 * FUNCTION: FlSeekFile
362 *
363 * PARAMETERS: FileId - Index into file info array
364 * Offset - Absolute byte offset in file
365 *
366 * RETURN: Status
367 *
368 * DESCRIPTION: Seek to absolute offset
369 * NOTE: Aborts compiler on any error.
370 *
371 ******************************************************************************/
372
373void
374FlSeekFile (
375 UINT32 FileId,
376 long Offset)
377{
378 int Error;
379
380
381 Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET);
382 if (Error)
383 {
384 FlFileError (FileId, ASL_MSG_SEEK);
385 AslAbort ();
386 }
387}
388
389
390/*******************************************************************************
391 *
392 * FUNCTION: FlCloseFile
393 *
394 * PARAMETERS: FileId - Index into file info array
395 *
396 * RETURN: Status
397 *
398 * DESCRIPTION: Close an open file. Aborts compiler on error
399 *
400 ******************************************************************************/
401
402void
403FlCloseFile (
404 UINT32 FileId)
405{
406 int Error;
407
408
409 if (!Gbl_Files[FileId].Handle)
410 {
411 return;
412 }
413
414 Error = fclose (Gbl_Files[FileId].Handle);
415 Gbl_Files[FileId].Handle = NULL;
416
417 if (Error)
418 {
419 FlFileError (FileId, ASL_MSG_CLOSE);
420 AslAbort ();
421 }
422
423 return;
424}
425
426
427/*******************************************************************************
428 *
429 * FUNCTION: FlSetLineNumber
430 *
431 * PARAMETERS: Op - Parse node for the LINE asl statement
432 *
433 * RETURN: None.
434 *
435 * DESCRIPTION: Set the current line number
436 *
437 ******************************************************************************/
438
439void
440FlSetLineNumber (
441 ACPI_PARSE_OBJECT *Op)
442{
443
444 Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer;
445 Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer;
446}
447
448
449/*******************************************************************************
450 *
451 * FUNCTION: FlOpenIncludeFile
452 *
453 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement
454 *
455 * RETURN: None.
456 *
457 * DESCRIPTION: Open an include file and push it on the input file stack.
458 *
459 ******************************************************************************/
460
461void
462FlOpenIncludeFile (
463 ACPI_PARSE_OBJECT *Op)
464{
465 FILE *IncFile;
466
467
468 /* Op must be valid */
469
470 if (!Op)
471 {
472 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
473 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
474 Gbl_InputByteCount, Gbl_CurrentColumn,
475 Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
476
477 return;
478 }
479
480 /*
481 * Flush out the "include ()" statement on this line, start
482 * the actual include file on the next line
483 */
484 ResetCurrentLineBuffer ();
485 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
486 Gbl_CurrentLineOffset++;
487
488 /* Prepend the directory pathname and open the include file */
489
490 DbgPrint (ASL_PARSE_OUTPUT, "\nOpen include file: path %s\n\n", Op->Asl.Value.String);
491 IncFile = FlOpenLocalFile (Op->Asl.Value.String, "r");
492 if (!IncFile)
493 {
494 sprintf (MsgBuffer, "%s (%s)", Op->Asl.Value.String, strerror (errno));
495 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer);
496 return;
497 }
498
499 /* Push the include file on the open input file stack */
500
501 AslPushInputFileStack (IncFile, Op->Asl.Value.String);
502}
503
504
505/*******************************************************************************
506 *
507 * FUNCTION: FlParseInputPathname
508 *
509 * PARAMETERS: InputFilename - The user-specified ASL source file to be
510 * compiled
511 *
512 * RETURN: Status
513 *
514 * DESCRIPTION: Split the input path into a directory and filename part
515 * 1) Directory part used to open include files
516 * 2) Filename part used to generate output filenames
517 *
518 ******************************************************************************/
519
520ACPI_STATUS
521FlParseInputPathname (
522 char *InputFilename)
523{
524 char *Substring;
525
526
527 if (!InputFilename)
528 {
529 return (AE_OK);
530 }
531
532 /* Get the path to the input filename's directory */
533
534 Gbl_DirectoryPath = strdup (InputFilename);
535 if (!Gbl_DirectoryPath)
536 {
537 return (AE_NO_MEMORY);
538 }
539
540 Substring = strrchr (Gbl_DirectoryPath, '\\');
541 if (!Substring)
542 {
543 Substring = strrchr (Gbl_DirectoryPath, '/');
544 if (!Substring)
545 {
546 Substring = strrchr (Gbl_DirectoryPath, ':');
547 }
548 }
549
550 if (!Substring)
551 {
552 Gbl_DirectoryPath[0] = 0;
553 if (Gbl_UseDefaultAmlFilename)
554 {
555 Gbl_OutputFilenamePrefix = strdup (InputFilename);
556 }
557 }
558 else
559 {
560 if (Gbl_UseDefaultAmlFilename)
561 {
562 Gbl_OutputFilenamePrefix = strdup (Substring + 1);
563 }
564 *(Substring+1) = 0;
565 }
566
567 return (AE_OK);
568}
569
570
571/*******************************************************************************
572 *
573 * FUNCTION: FlOpenInputFile
574 *
575 * PARAMETERS: InputFilename - The user-specified ASL source file to be
576 * compiled
577 *
578 * RETURN: Status
579 *
580 * DESCRIPTION: Open the specified input file, and save the directory path to
581 * the file so that include files can be opened in
582 * the same directory.
583 *
584 ******************************************************************************/
585
586ACPI_STATUS
587FlOpenInputFile (
588 char *InputFilename)
589{
590
591
592 /* Open the input ASL file, text mode */
593
594 FlOpenFile (ASL_FILE_INPUT, InputFilename, "r");
595 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
596
597 return (AE_OK);
598}
599
600
601/*******************************************************************************
602 *
603 * FUNCTION: FlOpenAmlOutputFile
604 *
605 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
606 *
607 * RETURN: Status
608 *
609 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
610 * is created in the same directory as the parent input file.
611 *
612 ******************************************************************************/
613
614ACPI_STATUS
615FlOpenAmlOutputFile (
616 char *FilenamePrefix)
617{
618 char *Filename;
619
620
621 /* Output filename usually comes from the ASL itself */
622
623 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename;
624 if (!Filename)
625 {
626 /* Create the output AML filename */
627
628 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
629 if (!Filename)
630 {
631 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 0, 0, 0, 0, NULL, NULL);
632 return (AE_ERROR);
633 }
634 }
635
636 /* Open the output AML file in binary mode */
637
638 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
639 return (AE_OK);
640}
641
642
643/*******************************************************************************
644 *
645 * FUNCTION: FlOpenMiscOutputFiles
646 *
647 * PARAMETERS: FilenamePrefix - The user-specified ASL source file
648 *
649 * RETURN: Status
650 *
651 * DESCRIPTION: Create and open the various output files needed, depending on
652 * the command line options
653 *
654 ******************************************************************************/
655
656ACPI_STATUS
657FlOpenMiscOutputFiles (
658 char *FilenamePrefix)
659{
660 char *Filename;
661
662
663 /* Create/Open a combined source output file */
664
665 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
666 if (!Filename)
667 {
668 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
669 return (AE_ERROR);
670 }
671
672 /*
673 * Open the source output file, binary mode (so that LF does not get
674 * expanded to CR/LF on some systems, messing up our seek
675 * calculations.)
676 */
677 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
678
679 /* Create/Open a listing output file if asked */
680
681 if (Gbl_ListingFlag)
682 {
683 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
684 if (!Filename)
685 {
686 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
687 return (AE_ERROR);
688 }
689
690 /* Open the listing file, text mode */
691
692 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+");
693
694 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
695 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
696 }
697
698 /* Create/Open a assembly code source output file if asked */
699
700 if (Gbl_AsmOutputFlag)
701 {
702 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
703 if (!Filename)
704 {
705 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
706 return (AE_ERROR);
707 }
708
709 /* Open the assembly code source file, text mode */
710
711 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+");
712
713 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
714 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
715 }
716
717 /* Create/Open a C code source output file if asked */
718
719 if (Gbl_C_OutputFlag)
720 {
721 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
722 if (!Filename)
723 {
724 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
725 return (AE_ERROR);
726 }
727
728 /* Open the C code source file, text mode */
729
730 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+");
731
732 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
733 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
734 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
735 }
736
737 /* Create/Open a assembly include output file if asked */
738
739 if (Gbl_AsmIncludeOutputFlag)
740 {
741 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
742 if (!Filename)
743 {
744 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
745 return (AE_ERROR);
746 }
747
748 /* Open the assembly include file, text mode */
749
750 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+");
751
752 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
753 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
754 }
755
756 /* Create/Open a C include output file if asked */
757
758 if (Gbl_C_IncludeOutputFlag)
759 {
760 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
761 if (!Filename)
762 {
763 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
764 return (AE_ERROR);
765 }
766
767 /* Open the C include file, text mode */
768
769 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+");
770
771 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
772 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
773 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
774 }
775
776 /* Create/Open a hex output file if asked */
777
778 if (Gbl_HexOutputFlag)
779 {
780 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
781 if (!Filename)
782 {
783 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
784 return (AE_ERROR);
785 }
786
787 /* Open the hex file, text mode */
788
789 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+");
790
791 AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
792 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
793 }
794
795 /* Create a namespace output file if asked */
796
797 if (Gbl_NsOutputFlag)
798 {
799 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
800 if (!Filename)
801 {
802 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 0, 0, 0, 0, NULL, NULL);
803 return (AE_ERROR);
804 }
805
806 /* Open the namespace file, text mode */
807
808 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+");
809
810 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
811 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
812 }
813
814 /* Create/Open a debug output file if asked */
815
816 if (Gbl_DebugFlag)
817 {
818 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
819 if (!Filename)
820 {
821 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 0, 0, 0, 0, NULL, NULL);
822 return (AE_ERROR);
823 }
824
825 /* Open the debug file as STDERR, text mode */
826
827 /* TBD: hide this behind a FlReopenFile function */
828
829 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
830 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = freopen (Filename, "w+t", stderr);
831
832 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
833 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
834 }
835
836 return (AE_OK);
837}
838
839