]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
BaseTools/VfrCompile: Explicitly state format string for DebugMsg()
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrCompiler.cpp
index 195727c2eb101828983569bc24b2d1045d0e371f..ff7057a64f4ca751f8da07bd45de8f9e2c5e6a50 100644 (file)
@@ -2,8 +2,8 @@
   \r
   VfrCompiler main class and main function.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -22,11 +22,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 PACKAGE_DATA  gCBuffer;\r
 PACKAGE_DATA  gRBuffer;\r
+CVfrStringDB  gCVfrStringDB;\r
 \r
 VOID \r
-CVfrCompiler::DebugError () {\r
-  Error (NULL, 0, 0001, "Error parsing vfr file", " %s", mOptions.VfrFileName);\r
-  //_asm int 3;\r
+CVfrCompiler::DebugError (\r
+  IN CHAR8         *FileName,\r
+  IN UINT32        LineNumber,\r
+  IN UINT32        MessageCode,\r
+  IN CONST CHAR8   *Text,\r
+  IN CONST CHAR8   *MsgFmt,\r
+  ...\r
+  ) \r
+{\r
+  va_list List;\r
+  va_start (List, MsgFmt);\r
+  PrintMessage ((CHAR8 *) "ERROR", FileName, LineNumber, MessageCode, (CHAR8 *) Text, (CHAR8 *) MsgFmt, List);\r
+  va_end (List);\r
 }\r
 \r
 VOID\r
@@ -52,22 +63,29 @@ CVfrCompiler::OptionInitialization (
   )\r
 {\r
   INT32         Index;\r
-  \r
-  SetUtilityName (PROGRAM_NAME);\r
+  EFI_STATUS    Status;\r
 \r
-  mOptions.VfrFileName[0]                = '\0';\r
-  mOptions.RecordListFile[0]             = '\0';\r
+  Status = EFI_SUCCESS;\r
+  SetUtilityName ((CHAR8*) PROGRAM_NAME);\r
+\r
+  mOptions.VfrFileName                   = NULL;\r
+  mOptions.RecordListFile                = NULL;\r
   mOptions.CreateRecordListFile          = FALSE;\r
   mOptions.CreateIfrPkgFile              = FALSE;\r
-  mOptions.PkgOutputFileName[0]          = '\0';\r
-  mOptions.COutputFileName[0]            = '\0';\r
-  mOptions.OutputDirectory[0]            = '\0';\r
-  mOptions.PreprocessorOutputFileName[0] = '\0';\r
-  mOptions.VfrBaseFileName[0]            = '\0';\r
+  mOptions.PkgOutputFileName             = NULL;\r
+  mOptions.COutputFileName               = NULL;\r
+  mOptions.OutputDirectory               = NULL;\r
+  mOptions.PreprocessorOutputFileName    = NULL;\r
+  mOptions.VfrBaseFileName               = NULL;\r
   mOptions.IncludePaths                  = NULL;\r
   mOptions.SkipCPreprocessor             = TRUE;\r
   mOptions.CPreprocessorOptions          = NULL;\r
   mOptions.CompatibleMode                = FALSE;\r
+  mOptions.HasOverrideClassGuid          = FALSE;\r
+  mOptions.WarningAsError                = FALSE;\r
+  mOptions.AutoDefault                   = FALSE;\r
+  mOptions.CheckDefault                  = FALSE;\r
+  memset (&mOptions.OverrideClassGuid, 0, sizeof (EFI_GUID));\r
   \r
   if (Argc == 1) {\r
     Usage ();\r
@@ -80,15 +98,17 @@ CVfrCompiler::OptionInitialization (
       Usage ();\r
       SET_RUN_STATUS (STATUS_DEAD);\r
       return;\r
+    } else if (stricmp(Argv[Index], "--version") == 0) {\r
+      Version ();\r
+      SET_RUN_STATUS (STATUS_DEAD);\r
+      return;\r
     } else if (stricmp(Argv[Index], "-l") == 0) {\r
       mOptions.CreateRecordListFile = TRUE;\r
       gCIfrRecordInfoDB.TurnOn ();\r
     } else if (stricmp(Argv[Index], "-i") == 0) {\r
-      Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
-      goto Fail;\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        Error (NULL, 0, 1001, "Missing option", "-i missing path argument"); \r
+        DebugError (NULL, 0, 1001, "Missing option", "-i missing path argument"); \r
         goto Fail;\r
       }\r
 \r
@@ -96,7 +116,17 @@ CVfrCompiler::OptionInitialization (
     } else if (stricmp(Argv[Index], "-o") == 0 || stricmp(Argv[Index], "--output-directory") == 0 || stricmp(Argv[Index], "-od") == 0) {\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        Error (NULL, 0, 1001, "Missing option", "-o missing output directory name");\r
+        DebugError (NULL, 0, 1001, "Missing option", "-o missing output directory name");\r
+        goto Fail;\r
+      }\r
+      if (strlen (Argv[Index]) > MAX_PATH - 1) {\r
+        DebugError (NULL, 0, 1003, "Invalid option value", "Output directory name %s is too long", Argv[Index]);\r
+        goto Fail;\r
+      }\r
+\r
+      mOptions.OutputDirectory = (CHAR8 *) malloc (strlen (Argv[Index]) + strlen ("\\") + 1);\r
+      if (mOptions.OutputDirectory == NULL) {\r
+        DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
         goto Fail;\r
       }\r
       strcpy (mOptions.OutputDirectory, Argv[Index]);\r
@@ -109,34 +139,72 @@ CVfrCompiler::OptionInitialization (
           strcat (mOptions.OutputDirectory, "\\");\r
         }\r
       }\r
-      DebugMsg (NULL, 0, 9, "Output Directory", mOptions.OutputDirectory);\r
+      DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", (CHAR8 *) "%s", mOptions.OutputDirectory);\r
     } else if (stricmp(Argv[Index], "-b") == 0 || stricmp(Argv[Index], "--create-ifr-package") == 0 || stricmp(Argv[Index], "-ibin") == 0) {\r
       mOptions.CreateIfrPkgFile = TRUE;\r
     } else if (stricmp(Argv[Index], "-n") == 0 || stricmp(Argv[Index], "--no-pre-processing") == 0 || stricmp(Argv[Index], "-nopp") == 0) {\r
       mOptions.SkipCPreprocessor = TRUE;\r
     } else if (stricmp(Argv[Index], "-f") == 0 || stricmp(Argv[Index], "--pre-processing-flag") == 0 || stricmp(Argv[Index], "-ppflag") == 0) {\r
-      Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
-      goto Fail;\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        Error (NULL, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");\r
+        DebugError (NULL, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");\r
         goto Fail;\r
       }\r
 \r
       AppendCPreprocessorOptions (Argv[Index]);\r
     } else if (stricmp(Argv[Index], "-c") == 0 || stricmp(Argv[Index], "--compatible-framework") == 0) {\r
       mOptions.CompatibleMode = TRUE;\r
+    } else if (stricmp(Argv[Index], "-s") == 0|| stricmp(Argv[Index], "--string-db") == 0) {\r
+      Index++;\r
+      if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
+        DebugError (NULL, 0, 1001, "Missing option", "-s missing input string file name");\r
+        goto Fail;\r
+      }\r
+      gCVfrStringDB.SetStringFileName(Argv[Index]);\r
+      DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", (CHAR8 *) "%s", Argv[Index]);\r
+    } else if ((stricmp (Argv[Index], "-g") == 0) || (stricmp (Argv[Index], "--guid") == 0)) {\r
+      Index++;\r
+      Status = StringToGuid (Argv[Index], &mOptions.OverrideClassGuid);\r
+      if (EFI_ERROR (Status)) {\r
+        DebugError (NULL, 0, 1000, "Invalid format:", "%s", Argv[Index]);\r
+        goto Fail;\r
+      }\r
+      mOptions.HasOverrideClassGuid = TRUE;\r
+    } else if (stricmp(Argv[Index], "-w") == 0 || stricmp(Argv[Index], "--warning-as-error") == 0) {\r
+      mOptions.WarningAsError = TRUE;\r
+    } else if (stricmp(Argv[Index], "-a") == 0 ||stricmp(Argv[Index], "--autodefault") == 0) {\r
+      mOptions.AutoDefault = TRUE;\r
+    } else if (stricmp(Argv[Index], "-d") == 0 ||stricmp(Argv[Index], "--checkdefault") == 0) {\r
+      mOptions.CheckDefault = TRUE;\r
     } else {\r
-      Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
+      DebugError (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
       goto Fail;\r
     }\r
   }\r
 \r
   if (Index != Argc - 1) {\r
-    Error (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");\r
+    DebugError (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");\r
     goto Fail;\r
   } else {\r
+    if (strlen (Argv[Index]) > MAX_PATH) {\r
+      DebugError (NULL, 0, 1003, "Invalid option value", "VFR file name %s is too long.", Argv[Index]);\r
+      goto Fail;\r
+    }\r
+    mOptions.VfrFileName = (CHAR8 *) malloc (strlen (Argv[Index]) + 1);\r
+    if (mOptions.VfrFileName == NULL) {\r
+      DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+      goto Fail;\r
+    }\r
     strcpy (mOptions.VfrFileName, Argv[Index]);\r
+\r
+    if (mOptions.OutputDirectory == NULL) {\r
+      mOptions.OutputDirectory = (CHAR8 *) malloc (1);\r
+      if (mOptions.OutputDirectory == NULL) {\r
+        DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+        goto Fail;\r
+      }\r
+      mOptions.OutputDirectory[0] = '\0';\r
+    }\r
   }\r
 \r
   if (SetBaseFileName() != 0) {\r
@@ -159,15 +227,37 @@ CVfrCompiler::OptionInitialization (
 Fail:\r
   SET_RUN_STATUS (STATUS_DEAD);\r
 \r
-  mOptions.VfrFileName[0]                = '\0';\r
-  mOptions.RecordListFile[0]             = '\0';\r
   mOptions.CreateRecordListFile          = FALSE;\r
   mOptions.CreateIfrPkgFile              = FALSE;\r
-  mOptions.PkgOutputFileName[0]          = '\0';\r
-  mOptions.COutputFileName[0]            = '\0';\r
-  mOptions.OutputDirectory[0]            = '\0';\r
-  mOptions.PreprocessorOutputFileName[0] = '\0';\r
-  mOptions.VfrBaseFileName[0]            = '\0';\r
+\r
+  if (mOptions.VfrFileName != NULL) {\r
+    free (mOptions.VfrFileName);\r
+    mOptions.VfrFileName                 = NULL;\r
+  }\r
+  if (mOptions.VfrBaseFileName != NULL) {\r
+    free (mOptions.VfrBaseFileName);\r
+    mOptions.VfrBaseFileName             = NULL;\r
+  }\r
+  if (mOptions.OutputDirectory != NULL) {\r
+    free (mOptions.OutputDirectory);\r
+    mOptions.OutputDirectory             = NULL;\r
+  }\r
+  if (mOptions.PkgOutputFileName != NULL) {\r
+    free (mOptions.PkgOutputFileName);\r
+    mOptions.PkgOutputFileName           = NULL;\r
+  }\r
+  if (mOptions.COutputFileName != NULL) {\r
+    free (mOptions.COutputFileName);\r
+    mOptions.COutputFileName             = NULL;\r
+  }\r
+  if (mOptions.PreprocessorOutputFileName != NULL) {\r
+    free (mOptions.PreprocessorOutputFileName);\r
+    mOptions.PreprocessorOutputFileName  = NULL;\r
+  }\r
+  if (mOptions.RecordListFile != NULL) {\r
+    free (mOptions.RecordListFile);\r
+    mOptions.RecordListFile              = NULL;\r
+  }\r
   if (mOptions.IncludePaths != NULL) {\r
     delete mOptions.IncludePaths;\r
     mOptions.IncludePaths                = NULL;\r
@@ -192,7 +282,7 @@ CVfrCompiler::AppendIncludePath (
   }\r
   IncludePaths = new CHAR8[Len];\r
   if (IncludePaths == NULL) {\r
-    Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+    DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
     return;\r
   }\r
   IncludePaths[0] = '\0';\r
@@ -221,7 +311,7 @@ CVfrCompiler::AppendCPreprocessorOptions (
   }\r
   Opt = new CHAR8[Len];\r
   if (Opt == NULL) {\r
-    Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+    DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
     return;\r
   }\r
   Opt[0] = 0;\r
@@ -243,7 +333,7 @@ CVfrCompiler::SetBaseFileName (
 {\r
   CHAR8         *pFileName, *pPath, *pExt;\r
 \r
-  if (mOptions.VfrFileName[0] == '\0') {\r
+  if (mOptions.VfrFileName == NULL) {\r
     return -1;\r
   }\r
 \r
@@ -264,8 +354,20 @@ CVfrCompiler::SetBaseFileName (
     return -1;\r
   }\r
 \r
-  strncpy (mOptions.VfrBaseFileName, pFileName, pExt - pFileName);\r
-  mOptions.VfrBaseFileName[pExt - pFileName] = '\0';\r
+  *pExt = '\0';\r
+  if (strlen (pFileName) > MAX_PATH - 1) {\r
+    *pExt = '.';\r
+    return -1;\r
+  }\r
+\r
+  mOptions.VfrBaseFileName = (CHAR8 *) malloc (strlen (pFileName) + 1);\r
+  if (mOptions.VfrBaseFileName == NULL) {\r
+    *pExt = '.';\r
+    return -1;\r
+  }\r
+\r
+  strcpy (mOptions.VfrBaseFileName, pFileName);\r
+  *pExt = '.';\r
 \r
   return 0;\r
 }\r
@@ -275,7 +377,22 @@ CVfrCompiler::SetPkgOutputFileName (
   VOID\r
   )\r
 {\r
-  if (mOptions.VfrBaseFileName[0] == '\0') {\r
+  INTN Length;\r
+\r
+  if (mOptions.VfrBaseFileName == NULL) {\r
+    return -1;\r
+  }\r
+\r
+  Length = strlen (mOptions.OutputDirectory) +\r
+           strlen (mOptions.VfrBaseFileName) +\r
+           strlen (VFR_PACKAGE_FILENAME_EXTENSION) +\r
+           1;\r
+  if (Length > MAX_PATH) {\r
+    return -1;\r
+  }\r
+\r
+  mOptions.PkgOutputFileName = (CHAR8 *) malloc (Length);\r
+  if (mOptions.PkgOutputFileName == NULL) {\r
     return -1;\r
   }\r
 \r
@@ -291,7 +408,22 @@ CVfrCompiler::SetCOutputFileName (
   VOID\r
   )\r
 {\r
-  if (mOptions.VfrBaseFileName[0] == '\0') {\r
+  INTN Length;\r
+\r
+  if (mOptions.VfrBaseFileName == NULL) {\r
+    return -1;\r
+  }\r
+\r
+  Length = strlen (mOptions.OutputDirectory) +\r
+           strlen (mOptions.VfrBaseFileName) +\r
+           strlen (".c") +\r
+           1;\r
+  if (Length > MAX_PATH) {\r
+    return -1;\r
+  }\r
+\r
+  mOptions.COutputFileName = (CHAR8 *) malloc (Length);\r
+  if (mOptions.COutputFileName == NULL) {\r
     return -1;\r
   }\r
 \r
@@ -307,7 +439,22 @@ CVfrCompiler::SetPreprocessorOutputFileName (
   VOID\r
   )\r
 {\r
-  if (mOptions.VfrBaseFileName[0] == '\0') {\r
+  INTN Length;\r
+\r
+  if (mOptions.VfrBaseFileName == NULL) {\r
+    return -1;\r
+  }\r
+\r
+  Length = strlen (mOptions.OutputDirectory) +\r
+           strlen (mOptions.VfrBaseFileName) +\r
+           strlen (VFR_PREPROCESS_FILENAME_EXTENSION) +\r
+           1;\r
+  if (Length > MAX_PATH) {\r
+    return -1;\r
+  }\r
+\r
+  mOptions.PreprocessorOutputFileName = (CHAR8 *) malloc (Length);\r
+  if (mOptions.PreprocessorOutputFileName == NULL) {\r
     return -1;\r
   }\r
 \r
@@ -323,7 +470,22 @@ CVfrCompiler::SetRecordListFileName (
   VOID\r
   )\r
 {\r
-  if (mOptions.VfrBaseFileName[0] == '\0') {\r
+  INTN Length;\r
+\r
+  if (mOptions.VfrBaseFileName == NULL) {\r
+    return -1;\r
+  }\r
+\r
+  Length = strlen (mOptions.OutputDirectory) +\r
+           strlen (mOptions.VfrBaseFileName) +\r
+           strlen (VFR_RECORDLIST_FILENAME_EXTENSION) +\r
+           1;\r
+  if (Length > MAX_PATH) {\r
+    return -1;\r
+  }\r
+\r
+  mOptions.RecordListFile = (CHAR8 *) malloc (Length);\r
+  if (mOptions.RecordListFile == NULL) {\r
     return -1;\r
   }\r
 \r
@@ -339,8 +501,10 @@ CVfrCompiler::CVfrCompiler (
   IN CHAR8      **Argv\r
   )\r
 {\r
-  mPreProcessCmd = PREPROCESSOR_COMMAND;\r
-  mPreProcessOpt = PREPROCESSOR_OPTIONS;\r
+  mPreProcessCmd = (CHAR8 *) PREPROCESSOR_COMMAND;\r
+  mPreProcessOpt = (CHAR8 *) PREPROCESSOR_OPTIONS;\r
+\r
+  SET_RUN_STATUS (STATUS_STARTED);\r
 \r
   OptionInitialization(Argc, Argv);\r
 \r
@@ -355,6 +519,41 @@ CVfrCompiler::~CVfrCompiler (
   VOID\r
   )\r
 {\r
+  if (mOptions.VfrFileName != NULL) {\r
+    free (mOptions.VfrFileName);\r
+    mOptions.VfrFileName = NULL;\r
+  }\r
+\r
+  if (mOptions.VfrBaseFileName != NULL) {\r
+    free (mOptions.VfrBaseFileName);\r
+    mOptions.VfrBaseFileName = NULL;\r
+  }\r
+\r
+  if (mOptions.OutputDirectory != NULL) {\r
+    free (mOptions.OutputDirectory);\r
+    mOptions.OutputDirectory = NULL;\r
+  }\r
+\r
+  if (mOptions.PkgOutputFileName != NULL) {\r
+    free (mOptions.PkgOutputFileName);\r
+    mOptions.PkgOutputFileName = NULL;\r
+  }\r
+\r
+  if (mOptions.COutputFileName != NULL) {\r
+    free (mOptions.COutputFileName);\r
+    mOptions.COutputFileName = NULL;\r
+  }\r
+\r
+  if (mOptions.PreprocessorOutputFileName != NULL) {\r
+    free (mOptions.PreprocessorOutputFileName);\r
+    mOptions.PreprocessorOutputFileName = NULL;\r
+  }\r
+\r
+  if (mOptions.RecordListFile != NULL) {\r
+    free (mOptions.RecordListFile);\r
+    mOptions.RecordListFile = NULL;\r
+  }\r
+\r
   if (mOptions.IncludePaths != NULL) {\r
     delete mOptions.IncludePaths;\r
     mOptions.IncludePaths = NULL;\r
@@ -376,12 +575,14 @@ CVfrCompiler::Usage (
   UINT32 Index;\r
   CONST  CHAR8 *Help[] = {\r
     " ", \r
-    "VfrCompile version " VFR_COMPILER_VERSION VFR_COMPILER_UPDATE_TIME,\r
+    "VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION,\r
+    "Copyright (c) 2004-2016 Intel Corporation. All rights reserved.",\r
     " ",\r
     "Usage: VfrCompile [options] VfrFile",\r
     " ",\r
     "Options:",\r
     "  -h, --help     prints this help",\r
+    "  --version      prints version info",\r
     "  -l             create an output IFR listing file",\r
     "  -o DIR, --output-directory DIR",\r
     "                 deposit all output files to directory OutputDir",\r
@@ -392,6 +593,30 @@ CVfrCompiler::Usage (
     "                 do not preprocessing input file",\r
     "  -c, --compatible-framework",\r
     "                 compatible framework vfr file",\r
+    "  -s, --string-db",\r
+    "                 input uni string package file",\r
+    "  -g, --guid",\r
+    "                 override class guid input",\r
+    "                 format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",\r
+    "  -w  --warning-as-error",\r
+    "                 treat warning as an error",\r
+    "  -a  --autodefaut    generate default value for question opcode if some default is missing",\r
+    "  -d  --checkdefault  check the default information in a question opcode",\r
+    NULL\r
+    };\r
+  for (Index = 0; Help[Index] != NULL; Index++) {\r
+    fprintf (stdout, "%s\n", Help[Index]);\r
+  }\r
+}\r
+\r
+VOID \r
+CVfrCompiler::Version (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 Index;\r
+  CONST  CHAR8 *Help[] = {\r
+    "VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION,\r
     NULL\r
     };\r
   for (Index = 0; Help[Index] != NULL; Index++) {\r
@@ -416,8 +641,8 @@ CVfrCompiler::PreProcess (
     goto Out;\r
   }\r
 \r
-  if ((pVfrFile = fopen (mOptions.VfrFileName, "r")) == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
+  if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) {\r
+    DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
     goto Fail;\r
   }\r
   fclose (pVfrFile);\r
@@ -433,7 +658,7 @@ CVfrCompiler::PreProcess (
 \r
   PreProcessCmd = new CHAR8[CmdLen + 10];\r
   if (PreProcessCmd == NULL) {\r
-    Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+    DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
     goto Fail;\r
   }\r
   strcpy (PreProcessCmd, mPreProcessCmd), strcat (PreProcessCmd, " ");\r
@@ -448,11 +673,11 @@ CVfrCompiler::PreProcess (
   strcat (PreProcessCmd, mOptions.PreprocessorOutputFileName);\r
 \r
   if (system (PreProcessCmd) != 0) {\r
-    Error (NULL, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd);\r
+    DebugError (NULL, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd);\r
     goto Fail;\r
   }\r
 \r
-  delete PreProcessCmd;\r
+  delete[] PreProcessCmd;\r
 \r
 Out:\r
   SET_RUN_STATUS (STATUS_PREPROCESSED);\r
@@ -462,10 +687,10 @@ Fail:
   if (!IS_RUN_STATUS(STATUS_DEAD)) {\r
     SET_RUN_STATUS (STATUS_FAILED);\r
   }\r
-  delete PreProcessCmd;\r
+  delete[] PreProcessCmd;\r
 }\r
 \r
-extern UINT8 VfrParserStart (IN FILE *, IN BOOLEAN);\r
+extern UINT8 VfrParserStart (IN FILE *, IN INPUT_INFO_TO_SYNTAX *);\r
 \r
 VOID\r
 CVfrCompiler::Compile (\r
@@ -474,6 +699,7 @@ CVfrCompiler::Compile (
 {\r
   FILE  *pInFile    = NULL;\r
   CHAR8 *InFileName = NULL;\r
+  INPUT_INFO_TO_SYNTAX InputInfo;\r
 \r
   if (!IS_RUN_STATUS(STATUS_PREPROCESSED)) {\r
     goto Fail;\r
@@ -482,13 +708,21 @@ CVfrCompiler::Compile (
   InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;\r
 \r
   gCVfrErrorHandle.SetInputFile (InFileName);\r
+  gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError);\r
 \r
-  if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening the input file", InFileName);\r
+  if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
+    DebugError (NULL, 0, 0001, "Error opening the input file", InFileName);\r
     goto Fail;\r
   }\r
 \r
-  if (VfrParserStart (pInFile, mOptions.CompatibleMode) != 0) {\r
+  InputInfo.CompatibleMode = mOptions.CompatibleMode;\r
+  if (mOptions.HasOverrideClassGuid) {\r
+    InputInfo.OverrideClassGuid = &mOptions.OverrideClassGuid;\r
+  } else {\r
+    InputInfo.OverrideClassGuid = NULL;\r
+  }\r
+\r
+  if (VfrParserStart (pInFile, &InputInfo) != 0) {\r
     goto Fail;\r
   }\r
 \r
@@ -504,7 +738,7 @@ CVfrCompiler::Compile (
 \r
 Fail:\r
   if (!IS_RUN_STATUS(STATUS_DEAD)) {\r
-    Error (NULL, 0, 0003, "Error parsing", "compile error in file %s", InFileName);\r
+    DebugError (NULL, 0, 0003, "Error parsing", "compile error in file %s", InFileName);\r
     SET_RUN_STATUS (STATUS_FAILED);\r
   }\r
   if (pInFile != NULL) {\r
@@ -518,6 +752,25 @@ CVfrCompiler::AdjustBin (
   )\r
 {\r
   EFI_VFR_RETURN_CODE Status;\r
+\r
+  if (!IS_RUN_STATUS(STATUS_COMPILEED)) {\r
+    return;\r
+  }\r
+\r
+  if (gNeedAdjustOpcode) {\r
+    //\r
+    // When parsing the Vfr, has created some opcodes, now need to update the record info.\r
+    //\r
+    gCIfrRecordInfoDB.IfrUpdateRecordInfoForDynamicOpcode (FALSE);\r
+  }\r
+\r
+  //\r
+  // Check whether need to check default info for question or auto add default for question.\r
+  //\r
+  if (mOptions.AutoDefault || mOptions.CheckDefault) {\r
+    gCIfrRecordInfoDB.IfrCheckAddDefaultRecord (mOptions.AutoDefault, mOptions.CheckDefault);\r
+  }\r
+\r
   //\r
   // Check Binary Code consistent between Form and IfrRecord\r
   //\r
@@ -534,7 +787,7 @@ CVfrCompiler::AdjustBin (
   if (gCBuffer.Buffer != NULL && gRBuffer.Buffer != NULL) {\r
     UINT32 Index;\r
     if (gCBuffer.Size != gRBuffer.Size) {\r
-      Error (NULL, 0, 0001, "Error parsing vfr file", " %s. FormBinary Size 0x%X is not same to RecordBuffer Size 0x%X", mOptions.VfrFileName, gCBuffer.Size, gRBuffer.Size);\r
+      DebugError (NULL, 0, 0001, "Error parsing vfr file", " %s. FormBinary Size 0x%X is not same to RecordBuffer Size 0x%X", mOptions.VfrFileName, gCBuffer.Size, gRBuffer.Size);\r
     }\r
     for (Index = 0; Index < gCBuffer.Size; Index ++) {\r
       if (gCBuffer.Buffer[Index] != gRBuffer.Buffer[Index]) {\r
@@ -542,13 +795,13 @@ CVfrCompiler::AdjustBin (
       }\r
     }\r
     if (Index != gCBuffer.Size) {\r
-      Error (NULL, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions.VfrFileName, Index);\r
+      DebugError (NULL, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions.VfrFileName, Index);\r
     }\r
-    DebugMsg (NULL, 0, 9, "IFR Buffer", "Form Buffer same to Record Buffer and Size is 0x%X", Index);\r
+    DebugMsg (NULL, 0, 9, (CHAR8 *) "IFR Buffer", (CHAR8 *) "Form Buffer same to Record Buffer and Size is 0x%X", Index);\r
   } else if (gCBuffer.Buffer == NULL && gRBuffer.Buffer == NULL) {\r
     //ok\r
   } else {\r
-    Error (NULL, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions.VfrFileName);\r
+    DebugError (NULL, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions.VfrFileName);\r
   }\r
 \r
   //\r
@@ -587,8 +840,8 @@ CVfrCompiler::GenBinary (
   }\r
 \r
   if (mOptions.CreateIfrPkgFile == TRUE) {\r
-    if ((pFile = fopen (mOptions.PkgOutputFileName, "wb")) == NULL) {\r
-      Error (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
+    if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) {\r
+      DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
       goto Fail;\r
     }\r
     if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {\r
@@ -628,23 +881,27 @@ CVfrCompiler::GenCFile (
   if (!IS_RUN_STATUS(STATUS_GENBINARY)) {\r
     goto Fail;\r
   }\r
+  \r
+  if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) {\r
+    if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) {\r
+      DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
+      goto Fail;\r
+    }\r
 \r
-  if ((pFile = fopen (mOptions.COutputFileName, "w")) == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
-    goto Fail;\r
-  }\r
-\r
-  for (Index = 0; gSourceFileHeader[Index] != NULL; Index++) {\r
-    fprintf (pFile, "%s\n", gSourceFileHeader[Index]);\r
-  }\r
+    for (Index = 0; gSourceFileHeader[Index] != NULL; Index++) {\r
+      fprintf (pFile, "%s\n", gSourceFileHeader[Index]);\r
+    }\r
 \r
-  gCVfrBufferConfig.OutputCFile (pFile, mOptions.VfrBaseFileName);\r
+    if (mOptions.CompatibleMode) { \r
+      gCVfrBufferConfig.OutputCFile (pFile, mOptions.VfrBaseFileName);\r
+    }\r
 \r
-  if (gCFormPkg.GenCFile (mOptions.VfrBaseFileName, pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {\r
+    if (gCFormPkg.GenCFile (mOptions.VfrBaseFileName, pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {\r
+      fclose (pFile);\r
+      goto Fail;\r
+    }\r
     fclose (pFile);\r
-    goto Fail;\r
   }\r
-  fclose (pFile);\r
 \r
   SET_RUN_STATUS (STATUS_FINISHED);\r
   return;\r
@@ -673,17 +930,17 @@ CVfrCompiler::GenRecordListFile (
       return;\r
     }\r
 \r
-    if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
-      Error (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);\r
+    if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
+      DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);\r
       return;\r
     }\r
 \r
-    if ((pOutFile = fopen (mOptions.RecordListFile, "w")) == NULL) {\r
-      Error (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
+    if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) {\r
+      DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
       goto Err1;\r
     }\r
 \r
-    fprintf (pOutFile, "//\n//  VFR compiler version " VFR_COMPILER_VERSION "\n//\n");\r
+    fprintf (pOutFile, "//\n//  VFR compiler version " VFR_COMPILER_VERSION __BUILD_VERSION "\n//\n");\r
     LineNo = 0;\r
     while (!feof (pInFile)) {\r
       if (fgets (LineBuf, MAX_VFR_LINE_LEN, pInFile) != NULL) {\r
@@ -709,11 +966,13 @@ Err1:
 \r
 int\r
 main (\r
-  IN INT32             Argc, \r
-  IN CHAR8             **Argv\r
+  IN int             Argc, \r
+  IN char            **Argv\r
   )\r
 {\r
   COMPILER_RUN_STATUS  Status;\r
+\r
+  SetPrintLevel(WARNING_LOG_LEVEL);\r
   CVfrCompiler         Compiler(Argc, Argv);\r
   \r
   Compiler.PreProcess();\r
@@ -739,3 +998,4 @@ main (
   return GetUtilityStatus ();\r
 }\r
 \r
+\r