aslcompile.c revision 281687
1119418Sobrien/****************************************************************************** 251694Sroger * 351694Sroger * Module Name: aslcompile - top level compile module 451694Sroger * 551694Sroger *****************************************************************************/ 651694Sroger 751694Sroger/* 851694Sroger * Copyright (C) 2000 - 2015, Intel Corp. 951694Sroger * All rights reserved. 1051694Sroger * 1151694Sroger * Redistribution and use in source and binary forms, with or without 1251694Sroger * modification, are permitted provided that the following conditions 1351694Sroger * are met: 1451694Sroger * 1. Redistributions of source code must retain the above copyright 1551694Sroger * notice, this list of conditions, and the following disclaimer, 1651694Sroger * without modification. 1751694Sroger * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1851694Sroger * substantially similar to the "NO WARRANTY" disclaimer below 1951694Sroger * ("Disclaimer") and any redistribution must be conditioned upon 2051694Sroger * including a substantially similar Disclaimer requirement for further 2151694Sroger * binary redistribution. 2251694Sroger * 3. Neither the names of the above-listed copyright holders nor the names 2351694Sroger * of any contributors may be used to endorse or promote products derived 2451694Sroger * from this software without specific prior written permission. 2551694Sroger * 2651694Sroger * Alternatively, this software may be distributed under the terms of the 2751694Sroger * GNU General Public License ("GPL") version 2 as published by the Free 2851694Sroger * Software Foundation. 2951694Sroger * 3051694Sroger * NO WARRANTY 3151694Sroger * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3251694Sroger * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3351694Sroger * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34119418Sobrien * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35119418Sobrien * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36119418Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37119418Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38119418Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39119418Sobrien * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40119418Sobrien * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41119418Sobrien * POSSIBILITY OF SUCH DAMAGES. 42119418Sobrien */ 43119418Sobrien 44119418Sobrien#include <contrib/dev/acpica/compiler/aslcompiler.h> 45119418Sobrien#include <contrib/dev/acpica/compiler/dtcompiler.h> 46119418Sobrien#include <contrib/dev/acpica/include/acnamesp.h> 47119418Sobrien 48119418Sobrien#include <stdio.h> 49119418Sobrien#include <time.h> 5059014Sroger#include <contrib/dev/acpica/include/acapps.h> 5152257Sroger 5251694Sroger#define _COMPONENT ACPI_COMPILER 5351694Sroger ACPI_MODULE_NAME ("aslcompile") 5451694Sroger 5559014Sroger/* 5667306Sroger * Main parser entry 5767306Sroger * External is here in case the parser emits the same external in the 5867306Sroger * generated header. (Newer versions of Bison) 59119277Simp */ 60119277Simpint 61139917SimpAslCompilerparse( 62139917Simp void); 63139917Simp 64119277Simp/* Local prototypes */ 6567306Sroger 6667306Srogerstatic void 6759014SrogerCmFlushSourceCode ( 6859014Sroger void); 6959014Sroger 7059014Srogerstatic void 7159014SrogerCmDumpAllEvents ( 7262112Sroger void); 7362112Sroger 7462112Sroger 7562112Sroger/******************************************************************************* 7662112Sroger * 7762112Sroger * FUNCTION: CmDoCompile 7859014Sroger * 79123291Sobrien * PARAMETERS: None 80123291Sobrien * 8151694Sroger * RETURN: Status (0 = OK) 8251694Sroger * 8351694Sroger * DESCRIPTION: This procedure performs the entire compile 8451694Sroger * 8551694Sroger ******************************************************************************/ 8659014Sroger 8759014Srogerint 8867306SrogerCmDoCompile ( 8967306Sroger void) 9067306Sroger{ 9167306Sroger ACPI_STATUS Status; 9267306Sroger UINT8 FullCompile; 9367306Sroger UINT8 Event; 9451694Sroger 9551694Sroger 9651694Sroger FullCompile = UtBeginEvent ("*** Total Compile time ***"); 9751694Sroger Event = UtBeginEvent ("Open input and output files"); 9851694Sroger UtEndEvent (Event); 9951694Sroger 10051694Sroger Event = UtBeginEvent ("Preprocess input file"); 10151694Sroger if (Gbl_PreprocessFlag) 10251694Sroger { 10351694Sroger /* Preprocessor */ 10451694Sroger 10551694Sroger PrDoPreprocess (); 10651694Sroger if (Gbl_PreprocessOnly) 10751694Sroger { 10851694Sroger UtEndEvent (Event); 10952593Sroger CmCleanupAndExit (); 11052593Sroger return (0); 11152593Sroger } 11251694Sroger } 11351694Sroger UtEndEvent (Event); 11451694Sroger 11551694Sroger /* Build the parse tree */ 11651694Sroger 11751694Sroger Event = UtBeginEvent ("Parse source code and build parse tree"); 11851694Sroger AslCompilerparse(); 11951694Sroger UtEndEvent (Event); 12051694Sroger 12151694Sroger /* Check for parser-detected syntax errors */ 12251694Sroger 123153084Sru if (Gbl_SyntaxError) 12451694Sroger { 12551694Sroger fprintf (stderr, "Compiler aborting due to parser-detected syntax error(s)\n"); 12651694Sroger LsDumpParseTree (); 12751694Sroger goto ErrorExit; 12851694Sroger } 12951694Sroger 13051694Sroger /* Did the parse tree get successfully constructed? */ 13151694Sroger 13251694Sroger if (!RootNode) 13351694Sroger { 13451694Sroger /* 13551694Sroger * If there are no errors, then we have some sort of 13651694Sroger * internal problem. 13751694Sroger */ 13851694Sroger AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, 13951694Sroger NULL, "- Could not resolve parse tree root node"); 14051694Sroger 14151694Sroger goto ErrorExit; 14251694Sroger } 14351694Sroger 14451694Sroger /* Flush out any remaining source after parse tree is complete */ 14551694Sroger 14652593Sroger Event = UtBeginEvent ("Flush source input"); 14751694Sroger CmFlushSourceCode (); 14851694Sroger 14951694Sroger /* Prune the parse tree if requested (debug purposes only) */ 15051694Sroger 15151694Sroger if (Gbl_PruneParseTree) 15251694Sroger { 15367306Sroger AslPruneParseTree (Gbl_PruneDepth, Gbl_PruneType); 15451694Sroger } 15551694Sroger 15651694Sroger /* Optional parse tree dump, compiler debug output only */ 15751694Sroger 15852593Sroger LsDumpParseTree (); 15951694Sroger 16051694Sroger OpcGetIntegerWidth (RootNode); 16151694Sroger UtEndEvent (Event); 16251694Sroger 16351694Sroger /* Pre-process parse tree for any operator transforms */ 16451694Sroger 16551694Sroger Event = UtBeginEvent ("Parse tree transforms"); 16651694Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n"); 16751694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 16851694Sroger TrAmlTransformWalk, NULL, NULL); 16951694Sroger UtEndEvent (Event); 17052593Sroger 17151694Sroger /* Generate AML opcodes corresponding to the parse tokens */ 17251694Sroger 17351694Sroger Event = UtBeginEvent ("Generate AML opcodes"); 17451694Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n"); 17551694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 17651694Sroger OpcAmlOpcodeWalk, NULL); 17751694Sroger UtEndEvent (Event); 17851694Sroger 17951694Sroger /* 18051694Sroger * Now that the input is parsed, we can open the AML output file. 18151694Sroger * Note: by default, the name of this file comes from the table descriptor 18252593Sroger * within the input file. 18351694Sroger */ 18451694Sroger Event = UtBeginEvent ("Open AML output file"); 18551694Sroger Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); 18651694Sroger UtEndEvent (Event); 18751694Sroger if (ACPI_FAILURE (Status)) 18851694Sroger { 18951694Sroger AePrintErrorLog (ASL_FILE_STDERR); 19051694Sroger return (-1); 19151694Sroger } 19251694Sroger 19351694Sroger /* Interpret and generate all compile-time constants */ 19451694Sroger 19551694Sroger Event = UtBeginEvent ("Constant folding via AML interpreter"); 19652593Sroger DbgPrint (ASL_DEBUG_OUTPUT, 19751694Sroger "\nInterpreting compile-time constant expressions\n\n"); 19851694Sroger 19951694Sroger if (Gbl_FoldConstants) 20051694Sroger { 20151694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 20251694Sroger OpcAmlConstantWalk, NULL, NULL); 20351694Sroger } 20451694Sroger else 20551694Sroger { 20652593Sroger DbgPrint (ASL_PARSE_OUTPUT, " Optional folding disabled\n"); 20751694Sroger } 20851694Sroger UtEndEvent (Event); 20951694Sroger 21051694Sroger /* Update AML opcodes if necessary, after constant folding */ 21151694Sroger 212141671Sjulian Event = UtBeginEvent ("Updating AML opcodes after constant folding"); 213141671Sjulian DbgPrint (ASL_DEBUG_OUTPUT, 214141671Sjulian "\nUpdating AML opcodes after constant folding\n\n"); 21551694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 216141671Sjulian NULL, OpcAmlOpcodeUpdateWalk, NULL); 21752593Sroger UtEndEvent (Event); 218141671Sjulian 219141671Sjulian /* Calculate all AML package lengths */ 220141671Sjulian 221141671Sjulian Event = UtBeginEvent ("Generate AML package lengths"); 22252593Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 22351694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 224141671Sjulian LnPackageLengthWalk, NULL); 225141671Sjulian UtEndEvent (Event); 226141671Sjulian 22751694Sroger if (Gbl_ParseOnlyFlag) 228141671Sjulian { 22952593Sroger AePrintErrorLog (ASL_FILE_STDERR); 230141671Sjulian UtDisplaySummary (ASL_FILE_STDERR); 23151694Sroger if (Gbl_DebugFlag) 23251694Sroger { 233141671Sjulian /* Print error summary to the stdout also */ 23451694Sroger 23551694Sroger AePrintErrorLog (ASL_FILE_STDOUT); 236141671Sjulian UtDisplaySummary (ASL_FILE_STDOUT); 237141671Sjulian } 238141671Sjulian UtEndEvent (FullCompile); 239141671Sjulian return (0); 240141671Sjulian } 24152593Sroger 242141671Sjulian /* 243141671Sjulian * Create an internal namespace and use it as a symbol table 244141671Sjulian */ 245141671Sjulian 24651694Sroger /* Namespace loading */ 24751694Sroger 248141671Sjulian Event = UtBeginEvent ("Create ACPI Namespace"); 249141671Sjulian Status = LdLoadNamespace (RootNode); 250141671Sjulian UtEndEvent (Event); 251141671Sjulian if (ACPI_FAILURE (Status)) 252141671Sjulian { 25352593Sroger goto ErrorExit; 254141671Sjulian } 255141671Sjulian 256141671Sjulian /* Namespace cross-reference */ 257141671Sjulian 25851694Sroger AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace"); 25951694Sroger Status = XfCrossReferenceNamespace (); 260141671Sjulian if (ACPI_FAILURE (Status)) 261141671Sjulian { 262141671Sjulian goto ErrorExit; 263141671Sjulian } 264141671Sjulian 265141671Sjulian /* Namespace - Check for non-referenced objects */ 266141671Sjulian 26751694Sroger LkFindUnreferencedObjects (); 26851694Sroger UtEndEvent (AslGbl_NamespaceEvent); 269141671Sjulian 27051694Sroger /* 27151694Sroger * Semantic analysis. This can happen only after the 27251694Sroger * namespace has been loaded and cross-referenced. 27351694Sroger * 274141671Sjulian * part one - check control methods 275141671Sjulian */ 276141671Sjulian Event = UtBeginEvent ("Analyze control method return types"); 277141671Sjulian AnalysisWalkInfo.MethodStack = NULL; 278141671Sjulian 27951694Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n"); 28051694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 28151694Sroger MtMethodAnalysisWalkBegin, 28251694Sroger MtMethodAnalysisWalkEnd, &AnalysisWalkInfo); 28351694Sroger UtEndEvent (Event); 28451694Sroger 28551694Sroger /* Semantic error checking part two - typing of method returns */ 286141671Sjulian 287141671Sjulian Event = UtBeginEvent ("Determine object types returned by methods"); 288141671Sjulian DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n"); 289141671Sjulian TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 290141671Sjulian NULL, AnMethodTypingWalkEnd, NULL); 29151694Sroger UtEndEvent (Event); 29251694Sroger 29351694Sroger /* Semantic error checking part three - operand type checking */ 29451694Sroger 29551694Sroger Event = UtBeginEvent ("Analyze AML operand types"); 29651694Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n"); 29751694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 298141671Sjulian NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo); 29951725Sroger UtEndEvent (Event); 30051725Sroger 30151725Sroger /* Semantic error checking part four - other miscellaneous checks */ 30252593Sroger 30351694Sroger Event = UtBeginEvent ("Miscellaneous analysis"); 30451694Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n"); 30551694Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 30651694Sroger AnOtherSemanticAnalysisWalkBegin, 30751694Sroger NULL, &AnalysisWalkInfo); 30851725Sroger UtEndEvent (Event); 30951725Sroger 31051725Sroger /* Calculate all AML package lengths */ 31151725Sroger 31251725Sroger Event = UtBeginEvent ("Finish AML package length generation"); 31351725Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 31452593Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 31551725Sroger LnInitLengthsWalk, NULL); 31651725Sroger TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 31756531Sroger LnPackageLengthWalk, NULL); 31856531Sroger UtEndEvent (Event); 31951725Sroger 32051725Sroger /* Code generation - emit the AML */ 32151725Sroger 32251725Sroger Event = UtBeginEvent ("Generate AML code and write output files"); 32351725Sroger CgGenerateAmlOutput (); 32451725Sroger UtEndEvent (Event); 32551725Sroger 32652593Sroger Event = UtBeginEvent ("Write optional output files"); 32751725Sroger CmDoOutputFiles (); 32851725Sroger UtEndEvent (Event); 32951925Sroger 33059014Sroger UtEndEvent (FullCompile); 33151925Sroger CmCleanupAndExit (); 33251725Sroger return (0); 333141671Sjulian 334141671SjulianErrorExit: 335141671Sjulian UtEndEvent (FullCompile); 33659014Sroger CmCleanupAndExit (); 33759014Sroger return (-1); 33859014Sroger} 33959014Sroger 34059014Sroger 34159014Sroger/******************************************************************************* 342141671Sjulian * 343141671Sjulian * FUNCTION: AslCompilerSignon 34451925Sroger * 345141671Sjulian * PARAMETERS: FileId - ID of the output file 346141671Sjulian * 347141671Sjulian * RETURN: None 348141671Sjulian * 349141671Sjulian * DESCRIPTION: Display compiler signon 350110237Sorion * 351141671Sjulian ******************************************************************************/ 352141671Sjulian 353141671Sjulianvoid 354110237SorionAslCompilerSignon ( 355110237Sorion UINT32 FileId) 356110237Sorion{ 357110237Sorion char *Prefix = ""; 358133300Ssanpei char *UtilityName; 359133300Ssanpei 360133300Ssanpei 361133300Ssanpei /* Set line prefix depending on the destination file type */ 362133300Ssanpei 363133300Ssanpei switch (FileId) 364133300Ssanpei { 365133300Ssanpei case ASL_FILE_ASM_SOURCE_OUTPUT: 366133300Ssanpei case ASL_FILE_ASM_INCLUDE_OUTPUT: 367133300Ssanpei 368133300Ssanpei Prefix = "; "; 369133300Ssanpei break; 370138936Sjulian 371138936Sjulian case ASL_FILE_HEX_OUTPUT: 372138936Sjulian 373138936Sjulian if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 374138936Sjulian { 375138936Sjulian Prefix = "; "; 376138936Sjulian } 377138936Sjulian else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) || 378138936Sjulian (Gbl_HexOutputFlag == HEX_OUTPUT_ASL)) 379138936Sjulian { 380138936Sjulian FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n"); 381138936Sjulian Prefix = " * "; 382141671Sjulian } 383141671Sjulian break; 384141671Sjulian 385141671Sjulian case ASL_FILE_C_SOURCE_OUTPUT: 386141671Sjulian case ASL_FILE_C_OFFSET_OUTPUT: 387141671Sjulian case ASL_FILE_C_INCLUDE_OUTPUT: 388141671Sjulian 389141671Sjulian Prefix = " * "; 390141671Sjulian break; 391141671Sjulian 392141671Sjulian default: 393139563Sjulian 394152375Snetchild /* No other output types supported */ 395152375Snetchild 396152375Snetchild break; 397152375Snetchild } 398152375Snetchild 399152375Snetchild /* Running compiler or disassembler? */ 400152375Snetchild 401152375Snetchild if (Gbl_DisasmFlag) 402152375Snetchild { 403152375Snetchild UtilityName = AML_DISASSEMBLER_NAME; 404152375Snetchild } 405152375Snetchild else 406152375Snetchild { 407152375Snetchild UtilityName = ASL_COMPILER_NAME; 408152375Snetchild } 409152375Snetchild 410152375Snetchild /* Compiler signon with copyright */ 411152375Snetchild 412152375Snetchild FlPrintFile (FileId, "%s\n", Prefix); 413152375Snetchild FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix)); 414152375Snetchild} 415152375Snetchild 416152375Snetchild 417152375Snetchild/******************************************************************************* 41851694Sroger * 41951694Sroger * FUNCTION: AslCompilerFileHeader 42051694Sroger * 42151694Sroger * PARAMETERS: FileId - ID of the output file 422110297Sorion * 42351694Sroger * RETURN: None 42451694Sroger * 42551694Sroger * DESCRIPTION: Header used at the beginning of output files 42651694Sroger * 42751694Sroger ******************************************************************************/ 42851694Sroger 42951694Srogervoid 43051694SrogerAslCompilerFileHeader ( 43151694Sroger UINT32 FileId) 43251694Sroger{ 43351694Sroger struct tm *NewTime; 43451694Sroger time_t Aclock; 43551694Sroger char *Prefix = ""; 436141671Sjulian 43751694Sroger 43851694Sroger /* Set line prefix depending on the destination file type */ 43951694Sroger 44051694Sroger switch (FileId) 44167306Sroger { 44251694Sroger case ASL_FILE_ASM_SOURCE_OUTPUT: 44351694Sroger case ASL_FILE_ASM_INCLUDE_OUTPUT: 44451694Sroger 44551694Sroger Prefix = "; "; 44651694Sroger break; 44751694Sroger 44851694Sroger case ASL_FILE_HEX_OUTPUT: 44951694Sroger 45051694Sroger if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 45151694Sroger { 45251694Sroger Prefix = "; "; 45351694Sroger } 45451694Sroger else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) || 45551694Sroger (Gbl_HexOutputFlag == HEX_OUTPUT_ASL)) 45651694Sroger { 45751694Sroger Prefix = " * "; 45851694Sroger } 45951694Sroger break; 46051694Sroger 46151694Sroger case ASL_FILE_C_SOURCE_OUTPUT: 46251694Sroger case ASL_FILE_C_OFFSET_OUTPUT: 46351694Sroger case ASL_FILE_C_INCLUDE_OUTPUT: 46451694Sroger 46551694Sroger Prefix = " * "; 46651694Sroger break; 46751694Sroger 46851694Sroger default: 46951694Sroger 47051694Sroger /* No other output types supported */ 47151694Sroger 47251694Sroger break; 47351694Sroger } 47451694Sroger 47551694Sroger /* Compilation header with timestamp */ 47651694Sroger 47751694Sroger (void) time (&Aclock); 47851694Sroger NewTime = localtime (&Aclock); 47951694Sroger 48051694Sroger FlPrintFile (FileId, 48151694Sroger "%sCompilation of \"%s\" - %s%s\n", 48251694Sroger Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime), 48351694Sroger Prefix); 48451694Sroger 48551694Sroger switch (FileId) 48651694Sroger { 48751694Sroger case ASL_FILE_C_SOURCE_OUTPUT: 48851694Sroger case ASL_FILE_C_OFFSET_OUTPUT: 48951694Sroger case ASL_FILE_C_INCLUDE_OUTPUT: 49051694Sroger 49151694Sroger FlPrintFile (FileId, " */\n"); 49251694Sroger break; 49351694Sroger 49451694Sroger default: 49551694Sroger 49651694Sroger /* Nothing to do for other output types */ 49751694Sroger 49851694Sroger break; 49951694Sroger } 50051694Sroger} 50151694Sroger 50251694Sroger 50351694Sroger/******************************************************************************* 50451694Sroger * 50551694Sroger * FUNCTION: CmFlushSourceCode 50651694Sroger * 50751694Sroger * PARAMETERS: None 50851694Sroger * 50951694Sroger * RETURN: None 51051694Sroger * 51151694Sroger * DESCRIPTION: Read in any remaining source code after the parse tree 51251694Sroger * has been constructed. 51351694Sroger * 51451694Sroger ******************************************************************************/ 51551694Sroger 51651694Srogerstatic void 51751694SrogerCmFlushSourceCode ( 51851694Sroger void) 51951694Sroger{ 52051694Sroger char Buffer; 52151694Sroger 52251694Sroger 52351694Sroger while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR) 52451694Sroger { 52551694Sroger AslInsertLineBuffer ((int) Buffer); 52651694Sroger } 52751694Sroger 52851694Sroger AslResetCurrentLineBuffer (); 52951694Sroger} 53051694Sroger 53151694Sroger 53251694Sroger/******************************************************************************* 53351694Sroger * 53451694Sroger * FUNCTION: CmDoOutputFiles 53551694Sroger * 53651694Sroger * PARAMETERS: None 53751694Sroger * 53851694Sroger * RETURN: None. 53951694Sroger * 54051694Sroger * DESCRIPTION: Create all "listing" type files 54151694Sroger * 54251694Sroger ******************************************************************************/ 54351694Sroger 54451694Srogervoid 54551694SrogerCmDoOutputFiles ( 54651694Sroger void) 54751694Sroger{ 54851694Sroger 54951694Sroger /* Create listings and hex files */ 55051694Sroger 55151694Sroger LsDoListings (); 55251694Sroger HxDoHexOutput (); 55351694Sroger 55451694Sroger /* Dump the namespace to the .nsp file if requested */ 55551694Sroger 55651694Sroger (void) NsDisplayNamespace (); 55751694Sroger 55851694Sroger /* Dump the device mapping file */ 55951694Sroger 56062112Sroger MpEmitMappingInfo (); 56162112Sroger} 56262112Sroger 56351694Sroger 56451694Sroger/******************************************************************************* 56551694Sroger * 56651694Sroger * FUNCTION: CmDumpAllEvents 56751694Sroger * 56851694Sroger * PARAMETERS: None 56951694Sroger * 57051694Sroger * RETURN: None. 57151694Sroger * 57251694Sroger * DESCRIPTION: Dump all compiler events 573218909Sbrucec * 57451694Sroger ******************************************************************************/ 57551694Sroger 57651694Srogerstatic void 57751694SrogerCmDumpAllEvents ( 57851694Sroger void) 57951694Sroger{ 58051694Sroger ASL_EVENT_INFO *Event; 58151694Sroger UINT32 Delta; 58251694Sroger UINT32 USec; 58351694Sroger UINT32 MSec; 58451694Sroger UINT32 i; 58551694Sroger 58651694Sroger 58751694Sroger Event = AslGbl_Events; 58851694Sroger 58951694Sroger DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n"); 59051694Sroger if (Gbl_CompileTimesFlag) 59151694Sroger { 59251694Sroger printf ("\nElapsed time for major events\n\n"); 59351694Sroger } 59451694Sroger 59551694Sroger for (i = 0; i < AslGbl_NextEvent; i++) 59651694Sroger { 59751694Sroger if (Event->Valid) 59851694Sroger { 59951694Sroger /* Delta will be in 100-nanosecond units */ 60051694Sroger 60151694Sroger Delta = (UINT32) (Event->EndTime - Event->StartTime); 60251694Sroger 60351694Sroger USec = Delta / ACPI_100NSEC_PER_USEC; 60467306Sroger MSec = Delta / ACPI_100NSEC_PER_MSEC; 60567306Sroger 60667306Sroger /* Round milliseconds up */ 60767306Sroger 60867306Sroger if ((USec - (MSec * ACPI_USEC_PER_MSEC)) >= 500) 609152375Snetchild { 61067306Sroger MSec++; 61167306Sroger } 61267306Sroger 61367306Sroger DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n", 614116106Sfjoe USec, MSec, Event->EventName); 615116106Sfjoe 61667306Sroger if (Gbl_CompileTimesFlag) 61767306Sroger { 618110237Sorion printf ("%8u usec %8u msec - %s\n", 619141669Sjulian USec, MSec, Event->EventName); 620138936Sjulian } 62151694Sroger } 622110237Sorion 623152375Snetchild Event++; 624152375Snetchild } 625152375Snetchild} 626152375Snetchild 627152375Snetchild 62851694Sroger/******************************************************************************* 62951694Sroger * 63051694Sroger * FUNCTION: CmCleanupAndExit 63151694Sroger * 63251694Sroger * PARAMETERS: None 63351694Sroger * 63451694Sroger * RETURN: None. 635141671Sjulian * 63651694Sroger * DESCRIPTION: Close all open files and exit the compiler 63751694Sroger * 63851694Sroger ******************************************************************************/ 63951694Sroger 64051694Srogervoid 64159014SrogerCmCleanupAndExit ( 64251694Sroger void) 64362112Sroger{ 64462112Sroger UINT32 i; 64551694Sroger BOOLEAN DeleteAmlFile = FALSE; 64651694Sroger 64751694Sroger 64851694Sroger AePrintErrorLog (ASL_FILE_STDERR); 64951694Sroger if (Gbl_DebugFlag) 65051694Sroger { 651141671Sjulian /* Print error summary to stdout also */ 652141671Sjulian 653141671Sjulian AePrintErrorLog (ASL_FILE_STDOUT); 654141671Sjulian } 655141671Sjulian 656141671Sjulian /* Emit compile times if enabled */ 657141671Sjulian 65851694Sroger CmDumpAllEvents (); 65951694Sroger 66051694Sroger if (Gbl_CompileTimesFlag) 661141671Sjulian { 66251694Sroger printf ("\nMiscellaneous compile statistics\n\n"); 66351694Sroger printf ("%11u : %s\n", TotalParseNodes, "Parse nodes"); 66451694Sroger printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches"); 66562112Sroger printf ("%11u : %s\n", TotalNamedObjects, "Named objects"); 66662112Sroger printf ("%11u : %s\n", TotalMethods, "Control methods"); 66751694Sroger printf ("%11u : %s\n", TotalAllocations, "Memory Allocations"); 66851694Sroger printf ("%11u : %s\n", TotalAllocated, "Total allocated memory"); 66951694Sroger printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded"); 67051694Sroger printf ("\n"); 67151694Sroger } 67251694Sroger 67351694Sroger if (Gbl_NsLookupCount) 67451694Sroger { 67551694Sroger DbgPrint (ASL_DEBUG_OUTPUT, 67651694Sroger "\n\nMiscellaneous compile statistics\n\n"); 677141671Sjulian 67851694Sroger DbgPrint (ASL_DEBUG_OUTPUT, 67951694Sroger "%32s : %u\n", "Total Namespace searches", 68051694Sroger Gbl_NsLookupCount); 68151694Sroger 68251694Sroger DbgPrint (ASL_DEBUG_OUTPUT, 68351694Sroger "%32s : %u usec\n", "Time per search", ((UINT32) 68451694Sroger (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - 685141671Sjulian AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) / 68651694Sroger Gbl_NsLookupCount); 68751694Sroger } 68851694Sroger 68951694Sroger if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) 690141671Sjulian { 691141671Sjulian printf ("\nMaximum error count (%u) exceeded\n", 69251694Sroger ASL_MAX_ERROR_COUNT); 69351694Sroger } 69451694Sroger 69551694Sroger UtDisplaySummary (ASL_FILE_STDOUT); 69651694Sroger 69751694Sroger /* 698141671Sjulian * We will delete the AML file if there are errors and the 699141671Sjulian * force AML output option has not been used. 700141671Sjulian */ 701141671Sjulian if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && 702141671Sjulian (!Gbl_IgnoreErrors) && 703141671Sjulian Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) 704141671Sjulian { 705141671Sjulian DeleteAmlFile = TRUE; 70651694Sroger } 707141671Sjulian 708141671Sjulian /* Close all open files */ 70959014Sroger 71051694Sroger /* 711141671Sjulian * Take care with the preprocessor file (.i), it might be the same 712141671Sjulian * as the "input" file, depending on where the compiler has terminated 71351694Sroger * or aborted. Prevent attempt to close the same file twice in 71451694Sroger * loop below. 715141671Sjulian */ 716141671Sjulian if (Gbl_Files[ASL_FILE_PREPROCESSOR].Handle == 71751694Sroger Gbl_Files[ASL_FILE_INPUT].Handle) 718141671Sjulian { 719141671Sjulian Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; 72051694Sroger } 72151694Sroger 722141671Sjulian /* Close the standard I/O files */ 723141671Sjulian 72451694Sroger for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++) 725141671Sjulian { 726141671Sjulian FlCloseFile (i); 727141671Sjulian } 72851694Sroger 72951694Sroger /* Delete AML file if there are errors */ 730141671Sjulian 731141671Sjulian if (DeleteAmlFile) 73251694Sroger { 733141671Sjulian FlDeleteFile (ASL_FILE_AML_OUTPUT); 734141671Sjulian } 73551694Sroger 73651694Sroger /* Delete the preprocessor output file (.i) unless -li flag is set */ 737141671Sjulian 738141671Sjulian if (!Gbl_PreprocessorOutputFlag && 73951694Sroger Gbl_PreprocessFlag) 740141671Sjulian { 741141671Sjulian FlDeleteFile (ASL_FILE_PREPROCESSOR); 74251725Sroger } 74351725Sroger 744141671Sjulian /* 745141671Sjulian * Delete intermediate ("combined") source file (if -ls flag not set) 74651725Sroger * This file is created during normal ASL/AML compiles. It is not 747141671Sjulian * created by the data table compiler. 748116106Sfjoe * 749116106Sfjoe * If the -ls flag is set, then the .SRC file should not be deleted. 750141671Sjulian * In this case, Gbl_SourceOutputFlag is set to TRUE. 75151725Sroger * 75251725Sroger * Note: Handles are cleared by FlCloseFile above, so we look at the 753141671Sjulian * filename instead, to determine if the .SRC file was actually 754141671Sjulian * created. 75551725Sroger * 756141669Sjulian * TBD: SourceOutput should be .TMP, then rename if we want to keep it? 757141669Sjulian */ 758141671Sjulian if (!Gbl_SourceOutputFlag) 75967306Sroger { 76067306Sroger FlDeleteFile (ASL_FILE_SOURCE_OUTPUT); 761141671Sjulian } 762141671Sjulian 76367306Sroger /* Final cleanup after compiling one file */ 764141669Sjulian 765141669Sjulian CmDeleteCaches (); 766110237Sorion} 767110237Sorion 768110237Sorion 769110237Sorion/******************************************************************************* 770110237Sorion * 771110237Sorion * FUNCTION: CmDeleteCaches 772152375Snetchild * 773152375Snetchild * PARAMETERS: None 774152375Snetchild * 775152375Snetchild * RETURN: None 776152375Snetchild * 777152375Snetchild * DESCRIPTION: Delete all local cache buffer blocks 778152375Snetchild * 779152375Snetchild ******************************************************************************/ 780152375Snetchild 781152375Snetchildvoid 782152375SnetchildCmDeleteCaches ( 783152375Snetchild void) 784152375Snetchild{ 785152375Snetchild UINT32 BufferCount; 786141671Sjulian ASL_CACHE_INFO *Next; 78751694Sroger 788141671Sjulian 78962112Sroger /* Parse Op cache */ 790141671Sjulian 79151694Sroger BufferCount = 0; 79251694Sroger while (Gbl_ParseOpCacheList) 793141671Sjulian { 79462112Sroger Next = Gbl_ParseOpCacheList->Next; 79551694Sroger ACPI_FREE (Gbl_ParseOpCacheList); 79651694Sroger Gbl_ParseOpCacheList = Next; 79751694Sroger BufferCount++; 79851694Sroger } 79951694Sroger 800141671Sjulian DbgPrint (ASL_DEBUG_OUTPUT, 80151694Sroger "%u ParseOps, Buffer size: %u ops (%u bytes), %u Buffers\n", 80251694Sroger Gbl_ParseOpCount, ASL_PARSEOP_CACHE_SIZE, 80351694Sroger (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE), BufferCount); 80451694Sroger 80551694Sroger Gbl_ParseOpCount = 0; 80651694Sroger Gbl_ParseOpCacheNext = NULL; 80751694Sroger Gbl_ParseOpCacheLast = NULL; 80851694Sroger RootNode = NULL; 80951694Sroger 810141671Sjulian /* Generic string cache */ 81151694Sroger 812141671Sjulian BufferCount = 0; 813141671Sjulian while (Gbl_StringCacheList) 81451694Sroger { 81551694Sroger Next = Gbl_StringCacheList->Next; 81651694Sroger ACPI_FREE (Gbl_StringCacheList); 81751694Sroger Gbl_StringCacheList = Next; 818141671Sjulian BufferCount++; 819141671Sjulian } 82051694Sroger 82151694Sroger DbgPrint (ASL_DEBUG_OUTPUT, 82251694Sroger "%u Strings (%u bytes), Buffer size: %u bytes, %u Buffers\n", 82351694Sroger Gbl_StringCount, Gbl_StringSize, ASL_STRING_CACHE_SIZE, BufferCount); 82451694Sroger 825141671Sjulian Gbl_StringSize = 0; 82651694Sroger Gbl_StringCount = 0; 82751694Sroger Gbl_StringCacheNext = NULL; 82851694Sroger Gbl_StringCacheLast = NULL; 829141671Sjulian} 83051694Sroger