aslcompile.c (18b18078f267ba10cf14348bc333f2f81818f472) aslcompile.c (44b0f624aee0d43179bf3874c70e03b6ae49a4db)
1/******************************************************************************
2 *
3 * Module Name: aslcompile - top level compile module
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *

--- 164 unchanged lines hidden (view full) ---

173static void
174CmFlushSourceCode (
175 void);
176
177static void
178CmDumpAllEvents (
179 void);
180
1/******************************************************************************
2 *
3 * Module Name: aslcompile - top level compile module
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *

--- 164 unchanged lines hidden (view full) ---

173static void
174CmFlushSourceCode (
175 void);
176
177static void
178CmDumpAllEvents (
179 void);
180
181static void
182CmFinishFiles(
183 BOOLEAN DeleteAmlFile);
181
184
185
182/*******************************************************************************
183 *
184 * FUNCTION: CmDoCompile
185 *
186 * PARAMETERS: None
187 *
188 * RETURN: Status (0 = OK)
189 *
190 * DESCRIPTION: This procedure performs the entire compile
191 *
192 ******************************************************************************/
193
186/*******************************************************************************
187 *
188 * FUNCTION: CmDoCompile
189 *
190 * PARAMETERS: None
191 *
192 * RETURN: Status (0 = OK)
193 *
194 * DESCRIPTION: This procedure performs the entire compile
195 *
196 ******************************************************************************/
197
194int
198ACPI_STATUS
195CmDoCompile (
196 void)
197{
199CmDoCompile (
200 void)
201{
198 ACPI_STATUS Status;
199 UINT8 FullCompile;
200 UINT8 Event;
202 UINT8 FullCompile;
203 UINT8 Event;
204 ASL_GLOBAL_FILE_NODE *FileNode;
201
202
203 FullCompile = UtBeginEvent ("*** Total Compile time ***");
204 Event = UtBeginEvent ("Open input and output files");
205 UtEndEvent (Event);
206
207 Event = UtBeginEvent ("Preprocess input file");
208 if (AslGbl_PreprocessFlag)

--- 7 unchanged lines hidden (view full) ---

216 PrDoPreprocess ();
217 AslGbl_CurrentLineNumber = 1;
218 AslGbl_LogicalLineNumber = 1;
219
220 if (AslGbl_PreprocessOnly)
221 {
222 UtEndEvent (Event);
223 CmCleanupAndExit ();
205
206
207 FullCompile = UtBeginEvent ("*** Total Compile time ***");
208 Event = UtBeginEvent ("Open input and output files");
209 UtEndEvent (Event);
210
211 Event = UtBeginEvent ("Preprocess input file");
212 if (AslGbl_PreprocessFlag)

--- 7 unchanged lines hidden (view full) ---

220 PrDoPreprocess ();
221 AslGbl_CurrentLineNumber = 1;
222 AslGbl_LogicalLineNumber = 1;
223
224 if (AslGbl_PreprocessOnly)
225 {
226 UtEndEvent (Event);
227 CmCleanupAndExit ();
224 return (0);
228 return (AE_OK);
225 }
226 }
227 UtEndEvent (Event);
228
229
230 /* Build the parse tree */
231
232 Event = UtBeginEvent ("Parse source code and build parse tree");
233 AslCompilerparse();
234 UtEndEvent (Event);
235
236 /* Check for parser-detected syntax errors */
237
238 if (AslGbl_SyntaxError)
239 {
240 fprintf (stderr,
241 "Compiler aborting due to parser-detected syntax error(s)\n");
229 }
230 }
231 UtEndEvent (Event);
232
233
234 /* Build the parse tree */
235
236 Event = UtBeginEvent ("Parse source code and build parse tree");
237 AslCompilerparse();
238 UtEndEvent (Event);
239
240 /* Check for parser-detected syntax errors */
241
242 if (AslGbl_SyntaxError)
243 {
244 fprintf (stderr,
245 "Compiler aborting due to parser-detected syntax error(s)\n");
246
247 /* Flag this error in the FileNode for compilation summary */
248
249 FileNode = FlGetCurrentFileNode ();
250 FileNode->ParserErrorDetected = TRUE;
251 AslGbl_ParserErrorDetected = TRUE;
242 LsDumpParseTree ();
243 goto ErrorExit;
244 }
245
246 /* Did the parse tree get successfully constructed? */
247
248 if (!AslGbl_ParseTreeRoot)
249 {

--- 37 unchanged lines hidden (view full) ---

287 /* Generate AML opcodes corresponding to the parse tokens */
288
289 Event = UtBeginEvent ("Generate AML opcodes");
290 DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");
291 TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
292 OpcAmlOpcodeWalk, NULL);
293 UtEndEvent (Event);
294
252 LsDumpParseTree ();
253 goto ErrorExit;
254 }
255
256 /* Did the parse tree get successfully constructed? */
257
258 if (!AslGbl_ParseTreeRoot)
259 {

--- 37 unchanged lines hidden (view full) ---

297 /* Generate AML opcodes corresponding to the parse tokens */
298
299 Event = UtBeginEvent ("Generate AML opcodes");
300 DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");
301 TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
302 OpcAmlOpcodeWalk, NULL);
303 UtEndEvent (Event);
304
295 /*
296 * Now that the input is parsed, we can open the AML output file.
297 * Note: by default, the name of this file comes from the table
298 * descriptor within the input file.
299 */
300 Event = UtBeginEvent ("Open AML output file");
301 Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
302 UtEndEvent (Event);
303 if (ACPI_FAILURE (Status))
304 {
305 AePrintErrorLog (ASL_FILE_STDERR);
306 return (-1);
307 }
305 UtEndEvent (FullCompile);
306 return (AE_OK);
308
307
308ErrorExit:
309 UtEndEvent (FullCompile);
310 return (AE_ERROR);
311}
312
313
314/*******************************************************************************
315 *
316 * FUNCTION: CmDoAslMiddleAndBackEnd
317 *
318 * PARAMETERS: None
319 *
320 * RETURN: Status of middle-end and back-end
321 *
322 * DESCRIPTION: Perform compiler middle-end (type checking and semantic
323 * analysis) and back-end (code generation)
324 *
325 ******************************************************************************/
326
327int
328CmDoAslMiddleAndBackEnd (
329 void)
330{
331 UINT8 Event;
332 ACPI_STATUS Status;
333
334
309 /* Interpret and generate all compile-time constants */
310
311 Event = UtBeginEvent ("Constant folding via AML interpreter");
312 DbgPrint (ASL_DEBUG_OUTPUT,
313 "Interpreting compile-time constant expressions\n\n");
314
315 if (AslGbl_FoldConstants)
316 {

--- 29 unchanged lines hidden (view full) ---

346 UtDisplaySummary (ASL_FILE_STDERR);
347 if (AslGbl_DebugFlag)
348 {
349 /* Print error summary to the stdout also */
350
351 AePrintErrorLog (ASL_FILE_STDOUT);
352 UtDisplaySummary (ASL_FILE_STDOUT);
353 }
335 /* Interpret and generate all compile-time constants */
336
337 Event = UtBeginEvent ("Constant folding via AML interpreter");
338 DbgPrint (ASL_DEBUG_OUTPUT,
339 "Interpreting compile-time constant expressions\n\n");
340
341 if (AslGbl_FoldConstants)
342 {

--- 29 unchanged lines hidden (view full) ---

372 UtDisplaySummary (ASL_FILE_STDERR);
373 if (AslGbl_DebugFlag)
374 {
375 /* Print error summary to the stdout also */
376
377 AePrintErrorLog (ASL_FILE_STDOUT);
378 UtDisplaySummary (ASL_FILE_STDOUT);
379 }
354 UtEndEvent (FullCompile);
355 return (0);
356 }
357
358 /*
359 * Create an internal namespace and use it as a symbol table
360 */
361
362 /* Namespace loading */
363
364 Event = UtBeginEvent ("Create ACPI Namespace");
365 DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");
366 Status = LdLoadNamespace (AslGbl_ParseTreeRoot);
367 UtEndEvent (Event);
368 if (ACPI_FAILURE (Status))
369 {
380 return (0);
381 }
382
383 /*
384 * Create an internal namespace and use it as a symbol table
385 */
386
387 /* Namespace loading */
388
389 Event = UtBeginEvent ("Create ACPI Namespace");
390 DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");
391 Status = LdLoadNamespace (AslGbl_ParseTreeRoot);
392 UtEndEvent (Event);
393 if (ACPI_FAILURE (Status))
394 {
370 goto ErrorExit;
395 return (-1);
371 }
372
373 /* Namespace cross-reference */
374
375 AslGbl_NamespaceEvent = UtBeginEvent (
376 "Cross reference parse tree and Namespace");
377 DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");
378 Status = XfCrossReferenceNamespace ();
379 if (ACPI_FAILURE (Status))
380 {
396 }
397
398 /* Namespace cross-reference */
399
400 AslGbl_NamespaceEvent = UtBeginEvent (
401 "Cross reference parse tree and Namespace");
402 DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");
403 Status = XfCrossReferenceNamespace ();
404 if (ACPI_FAILURE (Status))
405 {
381 goto ErrorExit;
406 return (-1);
382 }
383
384 /* Namespace - Check for non-referenced objects */
385
386 LkFindUnreferencedObjects ();
387 UtEndEvent (AslGbl_NamespaceEvent);
388
389 /* Resolve External Declarations */

--- 91 unchanged lines hidden (view full) ---

481 TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
482 LnPackageLengthWalk, NULL);
483 UtEndEvent (Event);
484
485 /* Code generation - emit the AML */
486
487 Event = UtBeginEvent ("Generate AML code and write output files");
488 DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");
407 }
408
409 /* Namespace - Check for non-referenced objects */
410
411 LkFindUnreferencedObjects ();
412 UtEndEvent (AslGbl_NamespaceEvent);
413
414 /* Resolve External Declarations */

--- 91 unchanged lines hidden (view full) ---

506 TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
507 LnPackageLengthWalk, NULL);
508 UtEndEvent (Event);
509
510 /* Code generation - emit the AML */
511
512 Event = UtBeginEvent ("Generate AML code and write output files");
513 DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");
489 CgGenerateAmlOutput ();
514
515 AslGbl_CurrentDB = AslGbl_ParseTreeRoot->Asl.Child;
516
517 while (AslGbl_CurrentDB)
518 {
519 switch (FlSwitchFileSet(AslGbl_CurrentDB->Asl.Filename))
520 {
521 case SWITCH_TO_DIFFERENT_FILE:
522 /*
523 * Reset these parameters when definition blocks belong in
524 * different files. If they belong in the same file, there is
525 * no need to reset these parameters
526 */
527 FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
528 AslGbl_SourceLine = 0;
529 AslGbl_NextError = AslGbl_ErrorLog;
530
531 /* fall-through */
532
533 case SWITCH_TO_SAME_FILE:
534
535 CgGenerateAmlOutput ();
536 CmDoOutputFiles ();
537 AslGbl_CurrentDB = AslGbl_CurrentDB->Asl.Next;
538
539 break;
540
541 default: /* FILE_NOT_FOUND */
542
543 /* The requested file could not be found. Get out of here */
544
545 AslGbl_CurrentDB = NULL;
546 break;
547 }
548 }
490 UtEndEvent (Event);
491
492 Event = UtBeginEvent ("Write optional output files");
549 UtEndEvent (Event);
550
551 Event = UtBeginEvent ("Write optional output files");
493 CmDoOutputFiles ();
494 UtEndEvent (Event);
495
552 UtEndEvent (Event);
553
496 UtEndEvent (FullCompile);
497 AslCheckExpectedExceptions ();
498 CmCleanupAndExit ();
499 return (0);
554 return (0);
500
501ErrorExit:
502 UtEndEvent (FullCompile);
503 CmCleanupAndExit ();
504 return (-1);
505}
506
507
508/*******************************************************************************
509 *
510 * FUNCTION: AslCompilerSignon
511 *
512 * PARAMETERS: FileId - ID of the output file

--- 290 unchanged lines hidden (view full) ---

803 * DESCRIPTION: Close all open files and exit the compiler
804 *
805 ******************************************************************************/
806
807void
808CmCleanupAndExit (
809 void)
810{
555}
556
557
558/*******************************************************************************
559 *
560 * FUNCTION: AslCompilerSignon
561 *
562 * PARAMETERS: FileId - ID of the output file

--- 290 unchanged lines hidden (view full) ---

853 * DESCRIPTION: Close all open files and exit the compiler
854 *
855 ******************************************************************************/
856
857void
858CmCleanupAndExit (
859 void)
860{
811 UINT32 i;
812 BOOLEAN DeleteAmlFile = FALSE;
861 BOOLEAN DeleteAmlFile = FALSE;
862 ASL_GLOBAL_FILE_NODE *CurrentFileNode = AslGbl_FilesList;
813
814
863
864
865 /* Check if any errors occurred during compile */
866
867 (void) AslCheckForErrorExit ();
868
815 AePrintErrorLog (ASL_FILE_STDERR);
816 if (AslGbl_DebugFlag)
817 {
818 /* Print error summary to stdout also */
819
820 AePrintErrorLog (ASL_FILE_STDOUT);
821 }
822

--- 37 unchanged lines hidden (view full) ---

860 }
861
862 UtDisplaySummary (ASL_FILE_STDOUT);
863
864 /*
865 * We will delete the AML file if there are errors and the
866 * force AML output option has not been used.
867 */
869 AePrintErrorLog (ASL_FILE_STDERR);
870 if (AslGbl_DebugFlag)
871 {
872 /* Print error summary to stdout also */
873
874 AePrintErrorLog (ASL_FILE_STDOUT);
875 }
876

--- 37 unchanged lines hidden (view full) ---

914 }
915
916 UtDisplaySummary (ASL_FILE_STDOUT);
917
918 /*
919 * We will delete the AML file if there are errors and the
920 * force AML output option has not been used.
921 */
868 if ((AslGbl_ExceptionCount[ASL_ERROR] > 0) &&
922 if (AslGbl_ParserErrorDetected || ((AslGbl_ExceptionCount[ASL_ERROR] > 0) &&
869 (!AslGbl_IgnoreErrors) &&
923 (!AslGbl_IgnoreErrors) &&
870 AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle)
924 AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle))
871 {
872 DeleteAmlFile = TRUE;
873 }
874
875 /* Close all open files */
876
925 {
926 DeleteAmlFile = TRUE;
927 }
928
929 /* Close all open files */
930
931 while (CurrentFileNode)
932 {
933 switch (FlSwitchFileSet (CurrentFileNode->Files[ASL_FILE_INPUT].Filename))
934 {
935 case SWITCH_TO_SAME_FILE:
936 case SWITCH_TO_DIFFERENT_FILE:
937
938 CmFinishFiles (DeleteAmlFile);
939 CurrentFileNode = CurrentFileNode->Next;
940 break;
941
942 case FILE_NOT_FOUND:
943 default:
944
945 CurrentFileNode = NULL;
946 break;
947 }
948 }
949
950 /* Final cleanup after compiling one file */
951
952 if (!AslGbl_DoAslConversion)
953 {
954 UtDeleteLocalCaches ();
955 }
956}
957
958
959/*******************************************************************************
960 *
961 * FUNCTION: CmFinishFiles
962 *
963 * PARAMETERS: DeleteAmlFile
964 *
965 * RETURN: None.
966 *
967 * DESCRIPTION: Close all open files, delete AML files depending on the
968 * function parameter is true.
969 *
970 ******************************************************************************/
971
972static void
973CmFinishFiles(
974 BOOLEAN DeleteAmlFile)
975{
976 UINT32 i;
977
978
877 /*
878 * Take care with the preprocessor file (.pre), it might be the same
879 * as the "input" file, depending on where the compiler has terminated
880 * or aborted. Prevent attempt to close the same file twice in
881 * loop below.
882 */
883 if (AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
884 AslGbl_Files[ASL_FILE_INPUT].Handle)
885 {
886 AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
887 }
888
889 /* Close the standard I/O files */
890
891 for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
892 {
979 /*
980 * Take care with the preprocessor file (.pre), it might be the same
981 * as the "input" file, depending on where the compiler has terminated
982 * or aborted. Prevent attempt to close the same file twice in
983 * loop below.
984 */
985 if (AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
986 AslGbl_Files[ASL_FILE_INPUT].Handle)
987 {
988 AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
989 }
990
991 /* Close the standard I/O files */
992
993 for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
994 {
893 FlCloseFile (i);
995 /*
996 * Some files such as debug output files could be pointing to
997 * stderr or stdout. Leave these alone.
998 */
999 if (AslGbl_Files[i].Handle != stderr &&
1000 AslGbl_Files[i].Handle != stdout)
1001 {
1002 FlCloseFile (i);
1003 }
894 }
895
896 /* Delete AML file if there are errors */
897
898 if (DeleteAmlFile)
899 {
900 FlDeleteFile (ASL_FILE_AML_OUTPUT);
901 }

--- 16 unchanged lines hidden (view full) ---

918 * Note: Handles are cleared by FlCloseFile above, so we look at the
919 * filename instead, to determine if the .SRC file was actually
920 * created.
921 */
922 if (!AslGbl_SourceOutputFlag)
923 {
924 FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
925 }
1004 }
1005
1006 /* Delete AML file if there are errors */
1007
1008 if (DeleteAmlFile)
1009 {
1010 FlDeleteFile (ASL_FILE_AML_OUTPUT);
1011 }

--- 16 unchanged lines hidden (view full) ---

1028 * Note: Handles are cleared by FlCloseFile above, so we look at the
1029 * filename instead, to determine if the .SRC file was actually
1030 * created.
1031 */
1032 if (!AslGbl_SourceOutputFlag)
1033 {
1034 FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
1035 }
926
927 /* Final cleanup after compiling one file */
928
929 if (!AslGbl_DoAslConversion)
930 {
931 UtDeleteLocalCaches ();
932 }
933}
1036}