aslfiles.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: aslfiles - File support functions
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2015, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("aslfiles")
/* Local prototypes */
static FILE *
char *PrefixDir,
char *Filename);
#ifdef ACPI_OBSOLETE_FUNCTIONS
char *InputFilename);
#endif
/*******************************************************************************
*
* FUNCTION: FlSetLineNumber
*
* PARAMETERS: Op - Parse node for the LINE asl statement
*
* RETURN: None.
*
* DESCRIPTION: Set the current line number
*
******************************************************************************/
void
{
}
/*******************************************************************************
*
* FUNCTION: FlSetFilename
*
* PARAMETERS: Op - Parse node for the LINE asl statement
*
* RETURN: None.
*
* DESCRIPTION: Set the current filename
*
******************************************************************************/
void
char *Filename)
{
/* No need to free any existing filename */
}
/*******************************************************************************
*
* FUNCTION: FlAddIncludeDirectory
*
* PARAMETERS: Dir - Directory pathname string
*
* RETURN: None
*
* DESCRIPTION: Add a directory the list of include prefix directories.
*
******************************************************************************/
void
char *Dir)
{
UINT32 NeedsSeparator = 0;
if (!DirLength)
{
return;
}
/* Make sure that the pathname ends with a path separator */
{
NeedsSeparator = 1;
}
if (NeedsSeparator)
{
}
/*
* Preserve command line ordering of -I options by adding new elements
* at the end of the list
*/
while (NextDir)
{
}
if (PrevDir)
{
}
else
{
}
}
/*******************************************************************************
*
* FUNCTION: FlMergePathnames
*
* PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or
* a zero length string.
* FilePathname - The include filename from the source ASL.
*
* RETURN: Merged pathname string
*
* DESCRIPTION: Merge two pathnames that (probably) have common elements, to
* arrive at a minimal length string. Merge can occur if the
* FilePathname is relative to the PrefixDir.
*
******************************************************************************/
char *
char *PrefixDir,
char *FilePathname)
{
char *CommonPath;
char *Pathname;
char *LastElement;
"Include: FilePathname - \"%s\"\n",
/*
* If there is no prefix directory or if the file pathname is absolute,
* just return the original file pathname
*/
(*FilePathname == '/') ||
{
goto ConvertBackslashes;
}
/* Need a local copy of the prefix directory path */
/*
* Walk forward through the file path, and simultaneously backward
* through the prefix directory path until there are no more
* relative references at the start of the file path.
*/
{
/* Remove last element of the prefix directory path */
if (!LastElement)
{
goto ConcatenatePaths;
}
*LastElement = 0; /* Terminate CommonPath string */
}
/*
* Remove the last element of the prefix directory path (it is the same as
* the first element of the file pathname), and build the final merged
* pathname.
*/
if (LastElement)
{
*LastElement = 0;
}
/* Build the final merged pathname */
if (LastElement && *CommonPath)
{
}
/* Convert all backslashes to normal slashes */
Pathname);
return (Pathname);
}
/*******************************************************************************
*
* FUNCTION: FlOpenIncludeWithPrefix
*
* PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero
* length string.
* Filename - The include filename from the source ASL.
*
* RETURN: Valid file descriptor if successful. Null otherwise.
*
* DESCRIPTION: Open an include file and push it on the input file stack.
*
******************************************************************************/
static FILE *
char *PrefixDir,
char *Filename)
{
char *Pathname;
/* Build the full pathname to the file */
Pathname);
/* Attempt to open the file, push if successful */
if (!IncludeFile)
{
return (NULL);
}
/*
* Check the entire include file for any # preprocessor directives.
* This is because there may be some confusion between the #include
* preprocessor directive and the ASL Include statement. A file included
* by the ASL include cannot contain preprocessor directives because
* the preprocessor has already run by the time the ASL include is
* recognized (by the compiler, not the preprocessor.)
*
* Save current line number since DtGetNextLine modifies it.
*/
{
if (Gbl_CurrentLineBuffer[0] == '#')
{
Op, "use #include instead");
}
}
/* Must seek back to the start of the file */
/* Push the include file on the open input file stack */
return (IncludeFile);
}
/*******************************************************************************
*
* FUNCTION: FlOpenIncludeFile
*
* PARAMETERS: Op - Parse node for the INCLUDE ASL statement
*
* RETURN: None.
*
* DESCRIPTION: Open an include file and push it on the input file stack.
*
******************************************************************************/
void
{
/* Op must be valid */
if (!Op)
{
return;
}
/*
* Flush out the "include ()" statement on this line, start
* the actual include file on the next line
*/
/* Attempt to open the include file */
/* If the file specifies an absolute path, just open it */
{
if (!IncludeFile)
{
goto ErrorExit;
}
return;
}
/*
* The include filename is not an absolute path.
*
* First, search for the file within the "local" directory -- meaning
* the same directory that contains the source file.
*
* Construct the file pathname from the global directory name.
*/
if (IncludeFile)
{
return;
}
/*
* Second, search for the file within the (possibly multiple) directories
* specified by the -I option on the command line.
*/
while (NextDir)
{
if (IncludeFile)
{
return;
}
}
/* We could not open the include file after trying very hard */
}
/*******************************************************************************
*
* FUNCTION: FlOpenInputFile
*
* PARAMETERS: InputFilename - The user-specified ASL source file to be
* compiled
*
* RETURN: Status
*
* DESCRIPTION: Open the specified input file, and save the directory path to
* the file so that include files can be opened in
* the same directory.
*
******************************************************************************/
char *InputFilename)
{
/* Open the input ASL file, text mode */
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: FlOpenAmlOutputFile
*
* PARAMETERS: FilenamePrefix - The user-specified ASL source file
*
* RETURN: Status
*
* DESCRIPTION: Create the output filename (*.AML) and open the file. The file
* is created in the same directory as the parent input file.
*
******************************************************************************/
char *FilenamePrefix)
{
char *Filename;
/* Output filename usually comes from the ASL itself */
if (!Filename)
{
/* Create the output AML filename */
if (!Filename)
{
return (AE_ERROR);
}
}
/* Open the output AML file in binary mode */
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: FlOpenMiscOutputFiles
*
* PARAMETERS: FilenamePrefix - The user-specified ASL source file
*
* RETURN: Status
*
* DESCRIPTION: Create and open the various output files needed, depending on
* the command line options
*
******************************************************************************/
char *FilenamePrefix)
{
char *Filename;
if (Gbl_MapfileFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the hex file, text mode (closed at compiler exit) */
}
/* All done for disassembler */
{
return (AE_OK);
}
if (Gbl_HexOutputFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the hex file, text mode */
}
if (Gbl_DebugFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the debug file as STDERR, text mode */
{
/*
* A problem with freopen is that on error, we no longer
* have stderr and cannot emit normal error messages.
* Emit error to stdout, close files, and exit.
*/
"\nCould not open debug output file: %s\n\n", Filename);
CmCleanupAndExit ();
exit (1);
}
}
if (Gbl_ListingFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the listing file, text mode */
}
/* Create the preprocessor output temp file if preprocessor enabled */
if (Gbl_PreprocessFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
}
/*
* Create the "user" preprocessor output file if -li flag set.
* Note, this file contains no embedded #line directives.
*/
{
if (!Filename)
{
return (AE_ERROR);
}
}
/* All done for data table compiler */
{
return (AE_OK);
}
if (!Filename)
{
return (AE_ERROR);
}
/*
* Open the source output file, binary mode (so that LF does not get
* calculations.)
*/
/*
// TBD: TEMP
// AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
*/
if (Gbl_AsmOutputFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the assembly code source file, text mode */
}
if (Gbl_C_OutputFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the C code source file, text mode */
}
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the C code source file, text mode */
}
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the assembly include file, text mode */
}
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the C include file, text mode */
}
/* Create a namespace output file if asked */
if (Gbl_NsOutputFlag)
{
if (!Filename)
{
return (AE_ERROR);
}
/* Open the namespace file, text mode */
}
return (AE_OK);
}
#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
*
* FUNCTION: FlParseInputPathname
*
* PARAMETERS: InputFilename - The user-specified ASL source file to be
* compiled
*
* RETURN: Status
*
* DESCRIPTION: Split the input path into a directory and filename part
* 1) Directory part used to open include files
* 2) Filename part used to generate output filenames
*
******************************************************************************/
char *InputFilename)
{
char *Substring;
if (!InputFilename)
{
return (AE_OK);
}
/* Get the path to the input filename's directory */
if (!Gbl_DirectoryPath)
{
return (AE_NO_MEMORY);
}
if (!Substring)
{
if (!Substring)
{
}
}
if (!Substring)
{
Gbl_DirectoryPath[0] = 0;
{
}
}
else
{
{
}
*(Substring+1) = 0;
}
return (AE_OK);
}
#endif