diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/aslcompiler.h | 4 | ||||
-rw-r--r-- | compiler/aslfiles.c | 222 | ||||
-rw-r--r-- | compiler/aslglobal.h | 3 | ||||
-rw-r--r-- | compiler/aslload.c | 1 | ||||
-rw-r--r-- | compiler/aslmain.c | 244 | ||||
-rw-r--r-- | compiler/asltypes.h | 8 |
6 files changed, 390 insertions, 92 deletions
diff --git a/compiler/aslcompiler.h b/compiler/aslcompiler.h index 54162a7..2678c59 100644 --- a/compiler/aslcompiler.h +++ b/compiler/aslcompiler.h @@ -556,6 +556,10 @@ AslAbort ( void); void +FlAddIncludeDirectory ( + char *Dir); + +void FlOpenIncludeFile ( ACPI_PARSE_OBJECT *Op); diff --git a/compiler/aslfiles.c b/compiler/aslfiles.c index cb38e900..3d24ab3 100644 --- a/compiler/aslfiles.c +++ b/compiler/aslfiles.c @@ -128,10 +128,11 @@ FlOpenFile ( char *Filename, char *Mode); -static FILE * -FlOpenLocalFile ( - char *LocalName, - char *Mode); +FILE * +FlOpenIncludeWithPrefix ( + char *PrefixDir, + char *Filename); + #ifdef ACPI_OBSOLETE_FUNCTIONS ACPI_STATUS @@ -172,45 +173,6 @@ AslAbort ( /******************************************************************************* * - * FUNCTION: FlOpenLocalFile - * - * PARAMETERS: LocalName - Single filename (not a pathname) - * Mode - Open mode for fopen - * - * RETURN: File descriptor - * - * DESCRIPTION: Build a complete pathname for the input filename and open - * the file. - * - ******************************************************************************/ - -static FILE * -FlOpenLocalFile ( - char *LocalName, - char *Mode) -{ - - StringBuffer[0] = 0; - - /* Check for an absolute pathname */ - - if ((LocalName[0] != '/') && /* Forward slash */ - (LocalName[0] != '\\') && /* backslash (Win) */ - (LocalName[1] != ':')) /* Device name (Win) */ - { - /* The include file path is relative, prepend the directory path */ - - strcat (StringBuffer, Gbl_DirectoryPath); - } - strcat (StringBuffer, LocalName); - - DbgPrint (ASL_PARSE_OUTPUT, "FlOpenLocalFile: %s\n", StringBuffer); - return (fopen (StringBuffer, (const char *) Mode)); -} - - -/******************************************************************************* - * * FUNCTION: FlFileError * * PARAMETERS: FileId - Index into file info array @@ -481,6 +443,122 @@ FlSetLineNumber ( /******************************************************************************* * + * FUNCTION: FlAddIncludeDirectory + * + * PARAMETERS: Dir - Directory pathname string + * + * RETURN: None + * + * DESCRIPTION: Add a directory the list of include prefix directories. + * + ******************************************************************************/ + +void +FlAddIncludeDirectory ( + char *Dir) +{ + ASL_INCLUDE_DIR *NewDir; + ASL_INCLUDE_DIR *NextDir; + ASL_INCLUDE_DIR *PrevDir = NULL; + UINT32 NeedsSeparator = 0; + size_t DirLength; + + + DirLength = strlen (Dir); + if (!DirLength) + { + return; + } + + /* Make sure that the pathname ends with a path separator */ + + if ((Dir[DirLength-1] != '/') && + (Dir[DirLength-1] != '\\')) + { + NeedsSeparator = 1; + } + + NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); + NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); + strcpy (NewDir->Dir, Dir); + if (NeedsSeparator) + { + strcat (NewDir->Dir, "/"); + } + + /* + * Preserve command line ordering of -I options by adding new elements + * at the end of the list + */ + NextDir = Gbl_IncludeDirList; + while (NextDir) + { + PrevDir = NextDir; + NextDir = NextDir->Next; + } + + if (PrevDir) + { + PrevDir->Next = NewDir; + } + else + { + Gbl_IncludeDirList = NewDir; + } +} + + +/******************************************************************************* + * + * 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. + * + ******************************************************************************/ + +FILE * +FlOpenIncludeWithPrefix ( + char *PrefixDir, + char *Filename) +{ + FILE *IncludeFile; + char *Pathname; + + + /* Build the full pathname to the file */ + + Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); + + strcpy (Pathname, PrefixDir); + strcat (Pathname, Filename); + + DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n", + Pathname); + + /* Attempt to open the file, push if successful */ + + IncludeFile = fopen (Pathname, "r"); + if (IncludeFile) + { + /* Push the include file on the open input file stack */ + + AslPushInputFileStack (IncludeFile, Pathname); + return (IncludeFile); + } + + ACPI_FREE (Pathname); + return (NULL); +} + + +/******************************************************************************* + * * FUNCTION: FlOpenIncludeFile * * PARAMETERS: Op - Parse node for the INCLUDE ASL statement @@ -495,7 +573,8 @@ void FlOpenIncludeFile ( ACPI_PARSE_OBJECT *Op) { - FILE *IncFile; + FILE *IncludeFile; + ASL_INCLUDE_DIR *NextDir; /* Op must be valid */ @@ -518,21 +597,58 @@ FlOpenIncludeFile ( FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); Gbl_CurrentLineOffset++; - /* Prepend the directory pathname and open the include file */ - DbgPrint (ASL_PARSE_OUTPUT, "\nOpen include file: path %s\n\n", - Op->Asl.Value.String); - IncFile = FlOpenLocalFile (Op->Asl.Value.String, "r"); - if (!IncFile) + /* Attempt to open the include file */ + + /* If the file specifies an absolute path, just open it */ + + if ((Op->Asl.Value.String[0] == '/') || + (Op->Asl.Value.String[0] == '\\') || + (Op->Asl.Value.String[1] == ':')) { - sprintf (MsgBuffer, "%s (%s)", Op->Asl.Value.String, strerror (errno)); - AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); + IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); + if (!IncludeFile) + { + goto ErrorExit; + } return; } - /* Push the include file on the open input file stack */ + /* + * 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. + */ + IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); + if (IncludeFile) + { + return; + } + + /* + * Second, search for the file within the (possibly multiple) directories + * specified by the -I option on the command line. + */ + NextDir = Gbl_IncludeDirList; + while (NextDir) + { + IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); + if (IncludeFile) + { + return; + } + + NextDir = NextDir->Next; + } + + /* We could not open the include file after trying very hard */ - AslPushInputFileStack (IncFile, Op->Asl.Value.String); +ErrorExit: + sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); + AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); } diff --git a/compiler/aslglobal.h b/compiler/aslglobal.h index 4cb9121..6aecfb6 100644 --- a/compiler/aslglobal.h +++ b/compiler/aslglobal.h @@ -148,7 +148,7 @@ extern char HexLookup[]; #define ASL_LINE_BUFFER_SIZE 512 #define ASL_MSG_BUFFER_SIZE 4096 #define HEX_TABLE_LINE_SIZE 8 -#define HEX_LISTING_LINE_SIZE 16 +#define HEX_LISTING_LINE_SIZE 8 /* Source code buffers and pointers for error reporting */ @@ -212,6 +212,7 @@ ASL_EXTERN char *Gbl_DirectoryPath; ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_ExternalFilename, NULL); ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_IncludeFilename, NULL); ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_OutputFilenamePrefix, NULL); +ASL_EXTERN ASL_INCLUDE_DIR ASL_INIT_GLOBAL (*Gbl_IncludeDirList, NULL); ASL_EXTERN char *Gbl_CurrentInputFilename; ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_HasIncludeFiles, FALSE); diff --git a/compiler/aslload.c b/compiler/aslload.c index e61e0622..8d06544 100644 --- a/compiler/aslload.c +++ b/compiler/aslload.c @@ -353,6 +353,7 @@ LdLoadResourceElements ( Node->Value = (UINT32) Op->Asl.Value.Integer; Node->Op = Op; + Op->Asl.Node = Node; /* * Now enter the predefined fields, for easy lookup when referenced diff --git a/compiler/aslmain.c b/compiler/aslmain.c index d006955..aa29ab8 100644 --- a/compiler/aslmain.c +++ b/compiler/aslmain.c @@ -150,6 +150,28 @@ AslCommandLine ( int argc, char **argv); +static int +AslDoOptions ( + int argc, + char **argv, + BOOLEAN IsResponseFile); + +static void +AslMergeOptionTokens ( + char *InBuffer, + char *OutBuffer); + +static int +AslDoResponseFile ( + char *Filename); + +extern int AcpiGbl_Opterr; +extern int AcpiGbl_Optind; + + +#define ASL_TOKEN_SEPARATORS " \t\n" +#define ASL_SUPPORTED_OPTIONS "@:2b:cd^e:fgh^i^I:l^o:p:r:s:t:v:w:x:" + /******************************************************************************* * @@ -168,8 +190,12 @@ Options ( void) { - printf ("General Output:\n"); - printf (" -p <prefix> Specify path/filename prefix for all output files\n"); + printf ("Global:\n"); + printf (" -@<file> Specify command file\n"); + printf (" -I<dir> Specify additional include directory\n"); + + printf ("\nGeneral Output:\n"); + printf (" -p<prefix> Specify path/filename prefix for all output files\n"); printf (" -va Disable all errors and warnings (summary only)\n"); printf (" -vi Less verbose errors and warnings for use with IDEs\n"); printf (" -vo Enable optimization comments\n"); @@ -310,39 +336,149 @@ AslInitialize ( /******************************************************************************* * - * FUNCTION: AslCommandLine + * FUNCTION: AslMergeOptionTokens * - * PARAMETERS: argc/argv + * PARAMETERS: InBuffer - Input containing an option string + * OutBuffer - Merged output buffer * * RETURN: None * - * DESCRIPTION: Command line processing + * DESCRIPTION: Remove all whitespace from an option string. + * + ******************************************************************************/ + +static void +AslMergeOptionTokens ( + char *InBuffer, + char *OutBuffer) +{ + char *Token; + + + *OutBuffer = 0; + + Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); + while (Token) + { + strcat (OutBuffer, Token); + Token = strtok (NULL, ASL_TOKEN_SEPARATORS); + } +} + + +/******************************************************************************* + * + * FUNCTION: AslDoResponseFile + * + * PARAMETERS: Filename - Name of the response file + * + * RETURN: Status + * + * DESCRIPTION: Open a response file and process all options within. * ******************************************************************************/ static int -AslCommandLine ( - int argc, - char **argv) +AslDoResponseFile ( + char *Filename) { - BOOLEAN BadCommandLine = FALSE; - int j; + char *argv = StringBuffer2; + FILE *ResponseFile; + int OptStatus = 0; + int Opterr; + int Optind; - /* Minimum command line contains at least one option or an input file */ + ResponseFile = fopen (Filename, "r"); + if (!ResponseFile) + { + printf ("Could not open command file %s, %s\n", + Filename, strerror (errno)); + return -1; + } - if (argc < 2) + /* Must save the current GetOpt globals */ + + Opterr = AcpiGbl_Opterr; + Optind = AcpiGbl_Optind; + + /* + * Process all lines in the response file. There must be one complete + * option per line + */ + while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) { - AslCompilerSignon (ASL_FILE_STDOUT); - Usage (); - exit (1); + /* Compress all tokens, allowing us to use a single argv entry */ + + AslMergeOptionTokens (StringBuffer, StringBuffer2); + + /* Process the option */ + + AcpiGbl_Opterr = 0; + AcpiGbl_Optind = 0; + + OptStatus = AslDoOptions (1, &argv, TRUE); + if (OptStatus) + { + printf ("Invalid option in command file %s: %s\n", + Filename, StringBuffer); + break; + } } + /* Restore the GetOpt globals */ + + AcpiGbl_Opterr = Opterr; + AcpiGbl_Optind = Optind; + + fclose (ResponseFile); + return (OptStatus); +} + + +/******************************************************************************* + * + * FUNCTION: AslDoOptions + * + * PARAMETERS: argc/argv - Standard argc/argv + * IsResponseFile - TRUE if executing a response file. + * + * RETURN: Status + * + * DESCRIPTION: Command line option processing + * + ******************************************************************************/ + +static int +AslDoOptions ( + int argc, + char **argv, + BOOLEAN IsResponseFile) +{ + int j; + + /* Get the command line options */ - while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^l^o:p:r:s:t:v:w:x:")) != EOF) switch (j) + while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) { + case '@': /* Begin a response file */ + + if (IsResponseFile) + { + printf ("Nested command files are not supported\n"); + return -1; + } + + if (AslDoResponseFile (AcpiGbl_Optarg)) + { + return -1; + } + break; + + case '2': + Gbl_Acpi2 = TRUE; break; @@ -364,8 +500,7 @@ AslCommandLine ( default: printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } /* Produce debug output file */ @@ -394,8 +529,7 @@ AslCommandLine ( default: printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } Gbl_DisasmFlag = TRUE; @@ -444,12 +578,17 @@ AslCommandLine ( default: printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; + case 'I': /* Add an include file search directory */ + + FlAddIncludeDirectory (AcpiGbl_Optarg); + break; + + case 'i': switch (AcpiGbl_Optarg[0]) @@ -470,8 +609,7 @@ AslCommandLine ( default: printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; @@ -500,8 +638,7 @@ AslCommandLine ( default: printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; @@ -549,8 +686,7 @@ AslCommandLine ( default: printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; @@ -589,8 +725,7 @@ AslCommandLine ( default: printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; @@ -611,8 +746,7 @@ AslCommandLine ( default: printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; @@ -647,8 +781,7 @@ AslCommandLine ( default: printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; @@ -671,8 +804,7 @@ AslCommandLine ( default: printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); - BadCommandLine = TRUE; - break; + return (-1); } break; @@ -685,10 +817,46 @@ AslCommandLine ( default: - BadCommandLine = TRUE; - break; + return (-1); + } + + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: AslCommandLine + * + * PARAMETERS: argc/argv + * + * RETURN: Last argv index + * + * DESCRIPTION: Command line processing + * + ******************************************************************************/ + +static int +AslCommandLine ( + int argc, + char **argv) +{ + int BadCommandLine = 0; + + + /* Minimum command line contains at least the command and an input file */ + + if (argc < 2) + { + AslCompilerSignon (ASL_FILE_STDOUT); + Usage (); + exit (1); } + /* Process all command line options */ + + BadCommandLine = AslDoOptions (argc, argv, FALSE); + /* Next parameter must be the input filename */ if (!argv[AcpiGbl_Optind] && diff --git a/compiler/asltypes.h b/compiler/asltypes.h index 6b3c424..fb2396f 100644 --- a/compiler/asltypes.h +++ b/compiler/asltypes.h @@ -255,6 +255,14 @@ typedef enum #define ASL_NUM_FILES (ASL_MAX_FILE_TYPE + 1) +typedef struct asl_include_dir +{ + char *Dir; + struct asl_include_dir *Next; + +} ASL_INCLUDE_DIR; + + /* An entry in the exception list, one for each error/warning */ typedef struct asl_error_msg |