⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vfrcompile.g

📁 EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是EFI BIOS源代码中的与平台无关部分的代码
💻 G
📖 第 1 页 / 共 5 页
字号:
/*++

Copyright (c) 2004 - 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:

  VfrCompile.g

Abstract:

  PCCTS parser and lexer definitions for the EFI VFR forms compiler
  
--*/  

#header<<

#include "Tiano.h"
#include "EfiUtilityMsgs.h"
#include "EfiVfr.h"
#include "VfrServices.h"
#include EFI_PROTOCOL_DEFINITION (Hii)

#include <ctype.h>
#include <direct.h>
#include <process.h> // for spawn functions

>>

<<

//
// Base info for DLG-generated scanner
//
#include "DLexerBase.h"    

//
// Include the scanner file generated by DLG
//
#include "DLGLexer.h"    

class DLGLexerVfr : public DLGLexer
{
public:
  DLGLexerVfr (DLGFileInput *F) : DLGLexer (F) {};
  INT32 errstd (char *Text) 
  { 
    printf ("unrecognized input '%s'\n", Text); 
  }
};

//
// Base token definitions for ANTLR
//
#include "AToken.h"

//
// This is how we invoke the C preprocessor on the VFR source file
// to resolve #defines, #includes, etc. To make C source files
// shareable between VFR and drivers, define VFRCOMPILE so that
// #ifdefs can be used in shared .h files.
//
#define PREPROCESSOR_COMMAND        "cl.exe "
#define PREPROCESSOR_OPTIONS        "/nologo /P /TC /DVFRCOMPILE "

typedef ANTLRCommonToken ANTLRToken;

//
// Specify the filename extensions for the files we generate.
//
#define VFR_BINARY_FILENAME_EXTENSION       ".c"
#define VFR_LIST_FILENAME_EXTENSION         ".lst"

static 
VOID 
Usage ();

static 
STATUS 
ProcessArgs (
  int         Argc, 
  char        *Argv[]
  );

static 
VOID 
Cleanup ();

//
// Globals
//
OPTIONS gOptions;

int 
main (
  int   argc, 
  char  **argv
  )
/*++

Routine Description:
  Application entry point function. Parse command-line arguments, 
  invoke the parser, clean up, and return.

Arguments:
  argc - standard argc passed to main() per C conventions
  argv - standard argv passed to main() per C conventions

Returns:
  STATUS_SUCCESS - program executed with no errors or warnings
  STATUS_WARNING - program executed with warnings
  STATUS_ERROR   - non-recoverable errors encountered while processing

--*/
{
  FILE      *VfrFptr;
  char      *Cmd;
  char      *Cptr;
  int       Len;
  STATUS    Status;
    
  //
  // Set our program name for the error printing routines.
  // Then set printing limits.
  //
  SetUtilityName (PROGRAM_NAME);
  SetPrintLimits (20, 20, 30);
  //
  // Process the command-line arguments
  //
  if (ProcessArgs (argc, argv) != STATUS_SUCCESS) {
    Usage ();
    Cleanup();
    return STATUS_ERROR;
  }
  VfrFptr = NULL;
  //
  // Verify the VFR script file exists
  //
  if ((VfrFptr = fopen (gOptions.VfrFileName, "r")) == NULL) {
    Error (PROGRAM_NAME, 0, 0, gOptions.VfrFileName, "could not open input VFR file");
    Cleanup();
    return STATUS_ERROR;
  }
  //
  // Now close the file and make a system call to run the preprocessor
  // on it.
  //
  fclose (VfrFptr);
  Len = strlen (PREPROCESSOR_OPTIONS) + strlen (gOptions.VfrFileName) + 10;
  if (gOptions.CPreprocessorOptions != NULL) {
    Len += strlen (gOptions.CPreprocessorOptions) + 1;
  }
  if (gOptions.IncludePaths != NULL) {
    Len += strlen (gOptions.IncludePaths) + 1;
  }
  Cmd = (char *)malloc (Len);
  if (Cmd == NULL) {
    Error (PROGRAM_NAME, 0, 0, NULL, "could not allocate memory");
    Cleanup();
    return STATUS_ERROR;
  }  
  strcpy (Cmd, PREPROCESSOR_OPTIONS);
  if (gOptions.IncludePaths != NULL) {
    strcat (Cmd, gOptions.IncludePaths);
    strcat (Cmd, " ");
  }
  if (gOptions.CPreprocessorOptions != NULL) {
    strcat (Cmd, gOptions.CPreprocessorOptions);
    strcat (Cmd, " ");
  }
  strcat (Cmd, gOptions.VfrFileName);
  Status = _spawnlp (_P_WAIT, PREPROCESSOR_COMMAND, Cmd, NULL);
  if (Status != 0) {
    Error (PROGRAM_NAME, 0, 0, gOptions.VfrFileName, "failed to spawn C preprocessor on VFR file");
    printf ("Command: '%s %s'\n", PREPROCESSOR_COMMAND, Cmd);
    Cleanup();
    return STATUS_ERROR;
  }
  free (Cmd);
  //
  // Open the preprocessor output file
  //
  if ((VfrFptr = fopen (gOptions.PreprocessorOutputFileName, "r")) == NULL) {
    Error (PROGRAM_NAME, 0, 0, "failed to open input VFR preprocessor output file", 
      gOptions.PreprocessorOutputFileName);
    Cleanup();
    return STATUS_ERROR;
  }
  //
  // Define input VFR file
  //
  DLGFileInput InputFile (VfrFptr);
  //
  // Define an instance of the scanner    
  //
  DLGLexerVfr Scanner (&InputFile);
  //
  // Define token buffer between scanner and parser
  //
  ANTLRTokenBuffer Pipe (&Scanner);    
  //
  // Create a token to use as a model
  //
  ANTLRToken Tok;     
  //
  // Tell the scanner what type the token is
  //
  Scanner.setToken (&Tok);    
  //
  // Create an instance of our parser
  //
  EfiVfrParser Parser (&Pipe);    
  //
  // Initialize the parser    
  //
  Parser.init ();
  Status = GetUtilityStatus ();
  if (Status != STATUS_SUCCESS) {
    Cleanup();
    return Status;
  }  
  //
  // Start the first rule    
  //
  Parser.program ();
  //
  // Close the input script file
  //
  fclose (VfrFptr);
  Parser.WriteIfrBytes ();
  //
  // Call cleanup, which does some extra checking of the script
  //
  Parser.Cleanup ();
  Cleanup();
  //
  // If we had an error somewhere, delete our output files so that
  // a subsequent build will rebuild them.
  //
  Status = GetUtilityStatus ();
  if (Status == STATUS_ERROR) {
    remove (gOptions.IfrOutputFileName);
  }
  return Status;
}
static
VOID
Cleanup ()
/*++

Routine Description:
  Free up memory allocated during parsing.

Arguments:
  None

Returns:
  None

--*/
{
  //
  // Free up our string we allocated to track the include paths
  //
  if (gOptions.IncludePaths != NULL) {
    free (gOptions.IncludePaths);
    gOptions.IncludePaths = NULL;
  }
  //
  // Free up our string we allocated to track preprocessor options
  //
  if (gOptions.CPreprocessorOptions != NULL) {
    free (gOptions.CPreprocessorOptions);
    gOptions.CPreprocessorOptions = NULL;
  }
}  

static
STATUS
ProcessArgs (
  int         Argc, 
  char        *Argv[]
  )
/*++

Routine Description:
  Process the command-line arguments.

Arguments:
  Argc - standard argc passed to main()
  Argv - standard argv passed to main()

Returns:
  STATUS_SUCCESS - program should continue (all args ok)

--*/
{
  char    *IncludePaths;
  char    *CPreprocessorOptions;
  int     Len;  
  char    CopyStr[MAX_PATH];
  char    *Cptr;

  //
  // Put options in known state.
  //
  memset ((char *)&gOptions, 0, sizeof (OPTIONS));
  //
  // Go through all the arguments that start with '-'
  //
  Argc--;
  Argv++;
  while ((Argc > 0) && (Argv[0][0] == '-')) {
    //
    // -? or -h help option -- return an error for printing usage
    //
    if ((_stricmp (Argv[0], "-?") == 0) || (_stricmp (Argv[0], "-h") == 0)) {
      return STATUS_ERROR;
      break;
    //
    // -l to create a listing output file
    //
    } else if (_stricmp (Argv[0], "-l") == 0) {
      gOptions.CreateListFile = 1;
    //
    // -I include_path option for finding include files. We'll pass this
    // to the preprocessor. Turn them all into a single include string.
    //
    } else if (_stricmp (Argv[0], "-i") == 0) {
      if ((Argc < 2) || (Argv[1][0] == '-')) {
        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing path argument");
        return STATUS_ERROR;
      }
      Argc--;
      Argv++;
      Len = strlen (" -I ");
      Len += strlen (Argv[0]) + 2;
      if (gOptions.IncludePaths != NULL) {
        Len += strlen (gOptions.IncludePaths);
      }
      IncludePaths = (INT8 *)malloc (Len);
      if (IncludePaths == NULL) {
        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
        return STATUS_ERROR;
      }
      IncludePaths[0] = 0;
      if (gOptions.IncludePaths != NULL) {
        strcpy (IncludePaths, gOptions.IncludePaths);
        free (gOptions.IncludePaths);
      }
      strcat (IncludePaths, " -I ");
      strcat (IncludePaths, Argv[0]);
      gOptions.IncludePaths = IncludePaths;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -