Path: blob/main/sys/contrib/dev/acpica/compiler/aslcompile.c
48371 views
/******************************************************************************1*2* Module Name: aslcompile - top level compile module3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/compiler/aslcompiler.h>152#include <contrib/dev/acpica/include/acnamesp.h>153154#include <stdio.h>155#include <time.h>156#include <contrib/dev/acpica/include/acapps.h>157158#define _COMPONENT ACPI_COMPILER159ACPI_MODULE_NAME ("aslcompile")160161/*162* Main parser entry163* External is here in case the parser emits the same external in the164* generated header. (Newer versions of Bison)165*/166int167AslCompilerparse(168void);169170/* Local prototypes */171172static void173CmFlushSourceCode (174void);175176static void177CmDumpAllEvents (178void);179180static void181CmFinishFiles(182BOOLEAN DeleteAmlFile);183184185/*******************************************************************************186*187* FUNCTION: CmDoCompile188*189* PARAMETERS: None190*191* RETURN: Status (0 = OK)192*193* DESCRIPTION: This procedure performs the entire compile194*195******************************************************************************/196197ACPI_STATUS198CmDoCompile (199void)200{201UINT8 FullCompile;202UINT8 Event;203ASL_GLOBAL_FILE_NODE *FileNode;204205206FullCompile = UtBeginEvent ("*** Total Compile time ***");207Event = UtBeginEvent ("Open input and output files");208UtEndEvent (Event);209210Event = UtBeginEvent ("Preprocess input file");211if (AslGbl_PreprocessFlag)212{213/* Enter compiler name as a #define */214215PrAddDefine (ASL_DEFINE, "", FALSE);216217/* Preprocessor */218219PrDoPreprocess ();220AslGbl_CurrentLineNumber = 1;221AslGbl_LogicalLineNumber = 1;222AslGbl_CurrentLineOffset = 0;223224if (AslGbl_PreprocessOnly)225{226UtEndEvent (Event);227return (AE_OK);228}229}230UtEndEvent (Event);231232233/* Build the parse tree */234235Event = UtBeginEvent ("Parse source code and build parse tree");236AslCompilerparse();237UtEndEvent (Event);238239/* Check for parser-detected syntax errors */240241if (AslGbl_SyntaxError)242{243AslError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,244"Compiler aborting due to parser-detected syntax error(s)\n");245246/* Flag this error in the FileNode for compilation summary */247248FileNode = FlGetCurrentFileNode ();249FileNode->ParserErrorDetected = TRUE;250AslGbl_ParserErrorDetected = TRUE;251LsDumpParseTree ();252AePrintErrorLog(ASL_FILE_STDERR);253254goto ErrorExit;255}256257/* Did the parse tree get successfully constructed? */258259if (!AslGbl_ParseTreeRoot)260{261/*262* If there are no errors, then we have some sort of263* internal problem.264*/265AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,266NULL, "- Could not resolve parse tree root node");267268goto ErrorExit;269}270271AePrintErrorLog(ASL_FILE_STDERR);272273/* Flush out any remaining source after parse tree is complete */274275Event = UtBeginEvent ("Flush source input");276CmFlushSourceCode ();277278/* Prune the parse tree if requested (debug purposes only) */279280if (AslGbl_PruneParseTree)281{282AslPruneParseTree (AslGbl_PruneDepth, AslGbl_PruneType);283}284285/* Optional parse tree dump, compiler debug output only */286287LsDumpParseTree ();288289AslGbl_ParserErrorDetected = FALSE;290AslGbl_SyntaxError = FALSE;291UtEndEvent (Event);292UtEndEvent (FullCompile);293294AslGbl_ParserErrorDetected = FALSE;295AslGbl_SyntaxError = FALSE;296ErrorExit:297UtEndEvent (FullCompile);298return (AE_ERROR);299}300301302/*******************************************************************************303*304* FUNCTION: CmDoAslMiddleAndBackEnd305*306* PARAMETERS: None307*308* RETURN: Status of middle-end and back-end309*310* DESCRIPTION: Perform compiler middle-end (type checking and semantic311* analysis) and back-end (code generation)312*313******************************************************************************/314315int316CmDoAslMiddleAndBackEnd (317void)318{319UINT8 Event;320ACPI_STATUS Status;321322323OpcGetIntegerWidth (AslGbl_ParseTreeRoot->Asl.Child);324325/* Pre-process parse tree for any operator transforms */326327Event = UtBeginEvent ("Parse tree transforms");328DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");329TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,330TrAmlTransformWalkBegin, TrAmlTransformWalkEnd, NULL);331UtEndEvent (Event);332333/* Generate AML opcodes corresponding to the parse tokens */334335Event = UtBeginEvent ("Generate AML opcodes");336DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");337TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,338NULL, OpcAmlOpcodeWalk, NULL);339UtEndEvent (Event);340341342/* Interpret and generate all compile-time constants */343344Event = UtBeginEvent ("Constant folding via AML interpreter");345DbgPrint (ASL_DEBUG_OUTPUT,346"Interpreting compile-time constant expressions\n\n");347348if (AslGbl_FoldConstants)349{350TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,351NULL, OpcAmlConstantWalk, NULL);352}353else354{355DbgPrint (ASL_PARSE_OUTPUT, " Optional folding disabled\n");356}357UtEndEvent (Event);358359/* Update AML opcodes if necessary, after constant folding */360361Event = UtBeginEvent ("Updating AML opcodes after constant folding");362DbgPrint (ASL_DEBUG_OUTPUT,363"Updating AML opcodes after constant folding\n\n");364TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,365NULL, OpcAmlOpcodeUpdateWalk, NULL);366UtEndEvent (Event);367368/* Calculate all AML package lengths */369370Event = UtBeginEvent ("Generate AML package lengths");371DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");372TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,373LnPackageLengthWalk, NULL);374UtEndEvent (Event);375376if (AslGbl_ParseOnlyFlag)377{378AePrintErrorLog (ASL_FILE_STDERR);379UtDisplaySummary (ASL_FILE_STDERR);380if (AslGbl_DebugFlag)381{382/* Print error summary to the stdout also */383384AePrintErrorLog (ASL_FILE_STDOUT);385UtDisplaySummary (ASL_FILE_STDOUT);386}387return (0);388}389390/*391* Create an internal namespace and use it as a symbol table392*/393394/* Namespace loading */395396Event = UtBeginEvent ("Create ACPI Namespace");397DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");398Status = LdLoadNamespace (AslGbl_ParseTreeRoot);399UtEndEvent (Event);400if (ACPI_FAILURE (Status))401{402return (-1);403}404405/* Namespace cross-reference */406407AslGbl_NamespaceEvent = UtBeginEvent (408"Cross reference parse tree and Namespace");409DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");410Status = XfCrossReferenceNamespace ();411if (ACPI_FAILURE (Status))412{413return (-1);414}415416/* Namespace - Check for non-referenced objects */417418LkFindUnreferencedObjects ();419UtEndEvent (AslGbl_NamespaceEvent);420421/* Resolve External Declarations */422423Event = UtBeginEvent ("Resolve all Externals");424DbgPrint (ASL_DEBUG_OUTPUT, "\nResolve Externals\n\n");425426if (AslGbl_DoExternalsInPlace)427{428TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,429ExAmlExternalWalkBegin, NULL, NULL);430}431else432{433TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,434ExAmlExternalWalkBegin, ExAmlExternalWalkEnd, NULL);435}436UtEndEvent (Event);437438/*439* Semantic analysis. This can happen only after the440* namespace has been loaded and cross-referenced.441*442* part one - check control methods443*/444Event = UtBeginEvent ("Analyze control method return types");445AslGbl_AnalysisWalkInfo.MethodStack = NULL;446447DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method analysis\n\n");448449if (AslGbl_CrossReferenceOutput)450{451OtPrintHeaders ("Part 1: Object Reference Map "452"(Object references from within each control method)");453}454455TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,456MtMethodAnalysisWalkBegin,457MtMethodAnalysisWalkEnd, &AslGbl_AnalysisWalkInfo);458UtEndEvent (Event);459460/* Generate the object cross-reference file if requested */461462Event = UtBeginEvent ("Generate cross-reference file");463OtCreateXrefFile ();464UtEndEvent (Event);465466/* Semantic error checking part two - typing of method returns */467468Event = UtBeginEvent ("Determine object types returned by methods");469DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method typing\n\n");470TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,471NULL, AnMethodTypingWalkEnd, NULL);472UtEndEvent (Event);473474/* Semantic error checking part three - operand type checking */475476Event = UtBeginEvent ("Analyze AML operand types");477DbgPrint (ASL_DEBUG_OUTPUT,478"Semantic analysis - Operand type checking\n\n");479if (AslGbl_DoTypechecking)480{481TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,482NULL, AnOperandTypecheckWalkEnd, &AslGbl_AnalysisWalkInfo);483}484UtEndEvent (Event);485486/* Semantic error checking part four - other miscellaneous checks */487488Event = UtBeginEvent ("Miscellaneous analysis");489DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - miscellaneous\n\n");490TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,491AnOtherSemanticAnalysisWalkBegin,492NULL, &AslGbl_AnalysisWalkInfo);493UtEndEvent (Event);494495/*496* ASL-/ASL+ converter: Gbl_ParseTreeRoot->CommentList contains the497* very last comment of a given ASL file because it's the last constructed498* node during compilation. We take the very last comment and save it in a499* global for it to be used by the disassembler.500*/501if (AcpiGbl_CaptureComments)502{503AcpiGbl_LastListHead = AslGbl_ParseTreeRoot->Asl.CommentList;504AslGbl_ParseTreeRoot->Asl.CommentList = NULL;505}506507/* Calculate all AML package lengths */508509Event = UtBeginEvent ("Finish AML package length generation");510DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");511TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,512LnInitLengthsWalk, NULL);513TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,514LnPackageLengthWalk, NULL);515UtEndEvent (Event);516517/* Code generation - emit the AML */518519Event = UtBeginEvent ("Generate AML code and write output files");520DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");521522AslGbl_CurrentDB = AslGbl_ParseTreeRoot->Asl.Child;523524while (AslGbl_CurrentDB)525{526switch (FlSwitchFileSet(AslGbl_CurrentDB->Asl.Filename))527{528case SWITCH_TO_DIFFERENT_FILE:529/*530* Reset these parameters when definition blocks belong in531* different files. If they belong in the same file, there is532* no need to reset these parameters533*/534FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);535AslGbl_SourceLine = 0;536AslGbl_NextError = AslGbl_ErrorLog;537538/* fall-through */539540case SWITCH_TO_SAME_FILE:541542CgGenerateAmlOutput ();543CmDoOutputFiles ();544AslGbl_CurrentDB = AslGbl_CurrentDB->Asl.Next;545546break;547548default: /* FILE_NOT_FOUND */549550/* The requested file could not be found. Get out of here */551552AslGbl_CurrentDB = NULL;553break;554}555}556UtEndEvent (Event);557558Event = UtBeginEvent ("Write optional output files");559UtEndEvent (Event);560561return (0);562}563564565/*******************************************************************************566*567* FUNCTION: AslCompilerSignon568*569* PARAMETERS: FileId - ID of the output file570*571* RETURN: None572*573* DESCRIPTION: Display compiler signon574*575******************************************************************************/576577void578AslCompilerSignon (579UINT32 FileId)580{581char *Prefix = "";582char *UtilityName;583584585/* Set line prefix depending on the destination file type */586587switch (FileId)588{589case ASL_FILE_ASM_SOURCE_OUTPUT:590case ASL_FILE_ASM_INCLUDE_OUTPUT:591592Prefix = "; ";593break;594595case ASL_FILE_HEX_OUTPUT:596597if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)598{599Prefix = "; ";600}601else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||602(AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))603{604FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");605Prefix = " * ";606}607break;608609case ASL_FILE_C_SOURCE_OUTPUT:610case ASL_FILE_C_OFFSET_OUTPUT:611case ASL_FILE_C_INCLUDE_OUTPUT:612613Prefix = " * ";614break;615616default:617618/* No other output types supported */619620break;621}622623/* Running compiler or disassembler? */624625if (AcpiGbl_DisasmFlag)626{627UtilityName = AML_DISASSEMBLER_NAME;628}629else630{631UtilityName = ASL_COMPILER_NAME;632}633634/* Compiler signon with copyright */635636FlPrintFile (FileId, "%s\n", Prefix);637FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));638}639640641/*******************************************************************************642*643* FUNCTION: AslCompilerFileHeader644*645* PARAMETERS: FileId - ID of the output file646*647* RETURN: None648*649* DESCRIPTION: Header used at the beginning of output files650*651******************************************************************************/652653void654AslCompilerFileHeader (655UINT32 FileId)656{657char *NewTime;658time_t Aclock;659char *Prefix = "";660661662/* Set line prefix depending on the destination file type */663664switch (FileId)665{666case ASL_FILE_ASM_SOURCE_OUTPUT:667case ASL_FILE_ASM_INCLUDE_OUTPUT:668669Prefix = "; ";670break;671672case ASL_FILE_HEX_OUTPUT:673674if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)675{676Prefix = "; ";677}678else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||679(AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))680{681Prefix = " * ";682}683break;684685case ASL_FILE_C_SOURCE_OUTPUT:686case ASL_FILE_C_OFFSET_OUTPUT:687case ASL_FILE_C_INCLUDE_OUTPUT:688689Prefix = " * ";690break;691692default:693694/* No other output types supported */695696break;697}698699/* Compilation header (with timestamp) */700701FlPrintFile (FileId,702"%sCompilation of \"%s\"",703Prefix, AslGbl_Files[ASL_FILE_INPUT].Filename);704705if (!AslGbl_Deterministic)706{707Aclock = time (NULL);708NewTime = ctime (&Aclock);709if (NewTime)710{711FlPrintFile (FileId, " - %s%s\n", NewTime, Prefix);712}713}714else715{716FlPrintFile (FileId, "\n");717}718719switch (FileId)720{721case ASL_FILE_C_SOURCE_OUTPUT:722case ASL_FILE_C_OFFSET_OUTPUT:723case ASL_FILE_C_INCLUDE_OUTPUT:724725FlPrintFile (FileId, " */\n");726break;727728default:729730/* Nothing to do for other output types */731732break;733}734}735736737/*******************************************************************************738*739* FUNCTION: CmFlushSourceCode740*741* PARAMETERS: None742*743* RETURN: None744*745* DESCRIPTION: Read in any remaining source code after the parse tree746* has been constructed.747*748******************************************************************************/749750static void751CmFlushSourceCode (752void)753{754char Buffer;755756757while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)758{759AslInsertLineBuffer ((int) Buffer);760}761762AslResetCurrentLineBuffer ();763}764765766/*******************************************************************************767*768* FUNCTION: CmDoOutputFiles769*770* PARAMETERS: None771*772* RETURN: None.773*774* DESCRIPTION: Create all "listing" type files775*776******************************************************************************/777778void779CmDoOutputFiles (780void)781{782783/* Create listings and hex files */784785LsDoListings ();786HxDoHexOutput ();787788/* Dump the namespace to the .nsp file if requested */789790(void) NsDisplayNamespace ();791792/* Dump the device mapping file */793794MpEmitMappingInfo ();795}796797798/*******************************************************************************799*800* FUNCTION: CmDumpAllEvents801*802* PARAMETERS: None803*804* RETURN: None.805*806* DESCRIPTION: Dump all compiler events807*808******************************************************************************/809810static void811CmDumpAllEvents (812void)813{814ASL_EVENT_INFO *Event;815UINT32 Delta;816UINT32 MicroSeconds;817UINT32 MilliSeconds;818UINT32 i;819820821Event = AslGbl_Events;822823DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");824if (AslGbl_CompileTimesFlag)825{826printf ("\nElapsed time for major events\n\n");827}828829for (i = 0; i < AslGbl_NextEvent; i++)830{831if (Event->Valid)832{833/* Delta will be in 100-nanosecond units */834835Delta = (UINT32) (Event->EndTime - Event->StartTime);836837MicroSeconds = Delta / ACPI_100NSEC_PER_USEC;838MilliSeconds = Delta / ACPI_100NSEC_PER_MSEC;839840/* Round milliseconds up */841842if ((MicroSeconds - (MilliSeconds * ACPI_USEC_PER_MSEC)) >= 500)843{844MilliSeconds++;845}846847DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",848MicroSeconds, MilliSeconds, Event->EventName);849850if (AslGbl_CompileTimesFlag)851{852printf ("%8u usec %8u msec - %s\n",853MicroSeconds, MilliSeconds, Event->EventName);854}855}856857Event++;858}859}860861862/*******************************************************************************863*864* FUNCTION: CmCleanupAndExit865*866* PARAMETERS: None867*868* RETURN: None.869*870* DESCRIPTION: Close all open files and exit the compiler871*872******************************************************************************/873874int875CmCleanupAndExit (876void)877{878int Status = 0;879BOOLEAN DeleteAmlFile = FALSE;880ASL_GLOBAL_FILE_NODE *CurrentFileNode = AslGbl_FilesList;881882883/* Check if any errors occurred during compile */884885(void) AslCheckForErrorExit ();886887AePrintErrorLog (ASL_FILE_STDERR);888if (AslGbl_DebugFlag)889{890/* Print error summary to stdout also */891892AePrintErrorLog (ASL_FILE_STDOUT);893}894895/* Emit compile times if enabled */896897CmDumpAllEvents ();898899if (AslGbl_CompileTimesFlag)900{901printf ("\nMiscellaneous compile statistics\n\n");902printf ("%11u : %s\n", AslGbl_TotalParseNodes, "Parse nodes");903printf ("%11u : %s\n", AslGbl_NsLookupCount, "Namespace searches");904printf ("%11u : %s\n", AslGbl_TotalNamedObjects, "Named objects");905printf ("%11u : %s\n", AslGbl_TotalMethods, "Control methods");906printf ("%11u : %s\n", AslGbl_TotalAllocations, "Memory Allocations");907printf ("%11u : %s\n", AslGbl_TotalAllocated, "Total allocated memory");908printf ("%11u : %s\n", AslGbl_TotalFolds, "Constant subtrees folded");909printf ("\n");910}911912if (AslGbl_NsLookupCount)913{914DbgPrint (ASL_DEBUG_OUTPUT,915"\n\nMiscellaneous compile statistics\n\n");916917DbgPrint (ASL_DEBUG_OUTPUT,918"%32s : %u\n", "Total Namespace searches",919AslGbl_NsLookupCount);920921DbgPrint (ASL_DEBUG_OUTPUT,922"%32s : %u usec\n", "Time per search", ((UINT32)923(AslGbl_Events[AslGbl_NamespaceEvent].EndTime -924AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /925AslGbl_NsLookupCount);926}927928if (AslGbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)929{930printf ("\nMaximum error count (%d) exceeded (aslcompile.c)\n",931ASL_MAX_ERROR_COUNT);932}933934UtDisplaySummary (ASL_FILE_STDOUT);935936/*937* Delete the AML file if there are errors and the force AML output option938* (-f) has not been used.939*940* Return -1 as a status of the compiler if no AML files are generated. If941* the AML file is generated in the presence of errors, return 0. In the942* latter case, the errors were ignored by the user so the compilation is943* considered successful.944*/945if (AslGbl_ParserErrorDetected || AslGbl_PreprocessOnly ||946((AslGbl_ExceptionCount[ASL_ERROR] > 0) &&947(!AslGbl_IgnoreErrors) &&948AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle))949{950DeleteAmlFile = TRUE;951Status = -1;952}953954/* Close all open files */955956while (CurrentFileNode)957{958/*959* Set the program return status based on file errors. If there are any960* errors and during compilation, the command is not considered961* successful.962*/963if (Status != -1 && !AslGbl_IgnoreErrors &&964CurrentFileNode->ParserErrorDetected)965{966Status = -1;967}968969switch (FlSwitchFileSet (CurrentFileNode->Files[ASL_FILE_INPUT].Filename))970{971case SWITCH_TO_SAME_FILE:972case SWITCH_TO_DIFFERENT_FILE:973974CmFinishFiles (DeleteAmlFile);975CurrentFileNode = CurrentFileNode->Next;976break;977978case FILE_NOT_FOUND:979default:980981CurrentFileNode = NULL;982break;983}984}985986/* Final cleanup after compiling one file */987988if (!AslGbl_DoAslConversion)989{990UtDeleteLocalCaches ();991}992993return (Status);994}995996997/*******************************************************************************998*999* FUNCTION: CmFinishFiles1000*1001* PARAMETERS: DeleteAmlFile1002*1003* RETURN: None.1004*1005* DESCRIPTION: Close all open files, delete AML files depending on the1006* function parameter is true.1007*1008******************************************************************************/10091010static void1011CmFinishFiles(1012BOOLEAN DeleteAmlFile)1013{1014UINT32 i;101510161017/*1018* Take care with the preprocessor file (.pre), it might be the same1019* as the "input" file, depending on where the compiler has terminated1020* or aborted. Prevent attempt to close the same file twice in1021* loop below.1022*/1023if (AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle ==1024AslGbl_Files[ASL_FILE_INPUT].Handle)1025{1026AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;1027}10281029/* Close the standard I/O files */10301031for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)1032{1033/*1034* Some files such as debug output files could be pointing to1035* stderr or stdout. Leave these alone.1036*/1037if (AslGbl_Files[i].Handle != stderr &&1038AslGbl_Files[i].Handle != stdout)1039{1040FlCloseFile (i);1041}1042}10431044/* Delete AML file if there are errors */10451046if (DeleteAmlFile)1047{1048FlDeleteFile (ASL_FILE_AML_OUTPUT);1049}10501051/* Delete the preprocessor temp file unless full debug was specified */10521053if (AslGbl_PreprocessFlag && !AslGbl_KeepPreprocessorTempFile)1054{1055FlDeleteFile (ASL_FILE_PREPROCESSOR);1056}10571058/*1059* Delete intermediate ("combined") source file (if -ls flag not set)1060* This file is created during normal ASL/AML compiles. It is not1061* created by the data table compiler.1062*1063* If the -ls flag is set, then the .SRC file should not be deleted.1064* In this case, Gbl_SourceOutputFlag is set to TRUE.1065*1066* Note: Handles are cleared by FlCloseFile above, so we look at the1067* filename instead, to determine if the .SRC file was actually1068* created.1069*/1070if (!AslGbl_SourceOutputFlag)1071{1072FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);1073}1074}107510761077