3 VfrCompiler main class and main function.
5 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "VfrCompiler.h"
20 #include "CommonLib.h"
21 #include "EfiUtilityMsgs.h"
23 PACKAGE_DATA gCBuffer
;
24 PACKAGE_DATA gRBuffer
;
25 CVfrStringDB gCVfrStringDB
;
28 CVfrCompiler::DebugError (
31 IN UINT32 MessageCode
,
33 IN CONST CHAR8
*MsgFmt
,
38 va_start (List
, MsgFmt
);
39 PrintMessage ((CHAR8
*) "ERROR", FileName
, LineNumber
, MessageCode
, (CHAR8
*) Text
, (CHAR8
*) MsgFmt
, List
);
44 CVfrCompiler::SET_RUN_STATUS (
45 IN COMPILER_RUN_STATUS Status
52 CVfrCompiler::IS_RUN_STATUS (
53 IN COMPILER_RUN_STATUS Status
56 return mRunStatus
== Status
;
60 CVfrCompiler::OptionInitialization (
69 SetUtilityName ((CHAR8
*) PROGRAM_NAME
);
71 mOptions
.VfrFileName
= NULL
;
72 mOptions
.RecordListFile
= NULL
;
73 mOptions
.CreateRecordListFile
= FALSE
;
74 mOptions
.CreateIfrPkgFile
= FALSE
;
75 mOptions
.PkgOutputFileName
= NULL
;
76 mOptions
.COutputFileName
= NULL
;
77 mOptions
.OutputDirectory
= NULL
;
78 mOptions
.PreprocessorOutputFileName
= NULL
;
79 mOptions
.VfrBaseFileName
= NULL
;
80 mOptions
.IncludePaths
= NULL
;
81 mOptions
.SkipCPreprocessor
= TRUE
;
82 mOptions
.CPreprocessorOptions
= NULL
;
83 mOptions
.CompatibleMode
= FALSE
;
84 mOptions
.HasOverrideClassGuid
= FALSE
;
85 mOptions
.WarningAsError
= FALSE
;
86 mOptions
.AutoDefault
= FALSE
;
87 mOptions
.CheckDefault
= FALSE
;
88 memset (&mOptions
.OverrideClassGuid
, 0, sizeof (EFI_GUID
));
92 SET_RUN_STATUS (STATUS_DEAD
);
96 for (Index
= 1; (Index
< Argc
) && (Argv
[Index
][0] == '-'); Index
++) {
97 if ((stricmp(Argv
[Index
], "-h") == 0) || (stricmp(Argv
[Index
], "--help") == 0)) {
99 SET_RUN_STATUS (STATUS_DEAD
);
101 } else if (stricmp(Argv
[Index
], "--version") == 0) {
103 SET_RUN_STATUS (STATUS_DEAD
);
105 } else if (stricmp(Argv
[Index
], "-l") == 0) {
106 mOptions
.CreateRecordListFile
= TRUE
;
107 gCIfrRecordInfoDB
.TurnOn ();
108 } else if (stricmp(Argv
[Index
], "-i") == 0) {
110 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
111 DebugError (NULL
, 0, 1001, "Missing option", "-i missing path argument");
115 AppendIncludePath(Argv
[Index
]);
116 } else if (stricmp(Argv
[Index
], "-o") == 0 || stricmp(Argv
[Index
], "--output-directory") == 0 || stricmp(Argv
[Index
], "-od") == 0) {
118 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
119 DebugError (NULL
, 0, 1001, "Missing option", "-o missing output directory name");
122 if (strlen (Argv
[Index
]) > MAX_PATH
- 1) {
123 DebugError (NULL
, 0, 1003, "Invalid option value", "Output directory name %s is too long", Argv
[Index
]);
127 mOptions
.OutputDirectory
= (CHAR8
*) malloc (strlen (Argv
[Index
]) + strlen ("\\") + 1);
128 if (mOptions
.OutputDirectory
== NULL
) {
129 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
132 strcpy (mOptions
.OutputDirectory
, Argv
[Index
]);
134 CHAR8 lastChar
= mOptions
.OutputDirectory
[strlen(mOptions
.OutputDirectory
) - 1];
135 if ((lastChar
!= '/') && (lastChar
!= '\\')) {
136 if (strchr(mOptions
.OutputDirectory
, '/') != NULL
) {
137 strcat (mOptions
.OutputDirectory
, "/");
139 strcat (mOptions
.OutputDirectory
, "\\");
142 DebugMsg (NULL
, 0, 9, (CHAR8
*) "Output Directory", (CHAR8
*) "%s", mOptions
.OutputDirectory
);
143 } else if (stricmp(Argv
[Index
], "-b") == 0 || stricmp(Argv
[Index
], "--create-ifr-package") == 0 || stricmp(Argv
[Index
], "-ibin") == 0) {
144 mOptions
.CreateIfrPkgFile
= TRUE
;
145 } else if (stricmp(Argv
[Index
], "-n") == 0 || stricmp(Argv
[Index
], "--no-pre-processing") == 0 || stricmp(Argv
[Index
], "-nopp") == 0) {
146 mOptions
.SkipCPreprocessor
= TRUE
;
147 } else if (stricmp(Argv
[Index
], "-f") == 0 || stricmp(Argv
[Index
], "--pre-processing-flag") == 0 || stricmp(Argv
[Index
], "-ppflag") == 0) {
149 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
150 DebugError (NULL
, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");
154 AppendCPreprocessorOptions (Argv
[Index
]);
155 } else if (stricmp(Argv
[Index
], "-c") == 0 || stricmp(Argv
[Index
], "--compatible-framework") == 0) {
156 mOptions
.CompatibleMode
= TRUE
;
157 } else if (stricmp(Argv
[Index
], "-s") == 0|| stricmp(Argv
[Index
], "--string-db") == 0) {
159 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
160 DebugError (NULL
, 0, 1001, "Missing option", "-s missing input string file name");
163 gCVfrStringDB
.SetStringFileName(Argv
[Index
]);
164 DebugMsg (NULL
, 0, 9, (CHAR8
*) "Input string file path", (CHAR8
*) "%s", Argv
[Index
]);
165 } else if ((stricmp (Argv
[Index
], "-g") == 0) || (stricmp (Argv
[Index
], "--guid") == 0)) {
167 Status
= StringToGuid (Argv
[Index
], &mOptions
.OverrideClassGuid
);
168 if (EFI_ERROR (Status
)) {
169 DebugError (NULL
, 0, 1000, "Invalid format:", "%s", Argv
[Index
]);
172 mOptions
.HasOverrideClassGuid
= TRUE
;
173 } else if (stricmp(Argv
[Index
], "-w") == 0 || stricmp(Argv
[Index
], "--warning-as-error") == 0) {
174 mOptions
.WarningAsError
= TRUE
;
175 } else if (stricmp(Argv
[Index
], "-a") == 0 ||stricmp(Argv
[Index
], "--autodefault") == 0) {
176 mOptions
.AutoDefault
= TRUE
;
177 } else if (stricmp(Argv
[Index
], "-d") == 0 ||stricmp(Argv
[Index
], "--checkdefault") == 0) {
178 mOptions
.CheckDefault
= TRUE
;
180 DebugError (NULL
, 0, 1000, "Unknown option", "unrecognized option %s", Argv
[Index
]);
185 if (Index
!= Argc
- 1) {
186 DebugError (NULL
, 0, 1001, "Missing option", "VFR file name is not specified.");
189 if (strlen (Argv
[Index
]) > MAX_PATH
) {
190 DebugError (NULL
, 0, 1003, "Invalid option value", "VFR file name %s is too long.", Argv
[Index
]);
193 mOptions
.VfrFileName
= (CHAR8
*) malloc (strlen (Argv
[Index
]) + 1);
194 if (mOptions
.VfrFileName
== NULL
) {
195 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
198 strcpy (mOptions
.VfrFileName
, Argv
[Index
]);
200 if (mOptions
.OutputDirectory
== NULL
) {
201 mOptions
.OutputDirectory
= (CHAR8
*) malloc (1);
202 if (mOptions
.OutputDirectory
== NULL
) {
203 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
206 mOptions
.OutputDirectory
[0] = '\0';
210 if (SetBaseFileName() != 0) {
213 if (SetPkgOutputFileName () != 0) {
216 if (SetCOutputFileName() != 0) {
219 if (SetPreprocessorOutputFileName () != 0) {
222 if (SetRecordListFileName () != 0) {
228 SET_RUN_STATUS (STATUS_DEAD
);
230 mOptions
.CreateRecordListFile
= FALSE
;
231 mOptions
.CreateIfrPkgFile
= FALSE
;
233 if (mOptions
.VfrFileName
!= NULL
) {
234 free (mOptions
.VfrFileName
);
235 mOptions
.VfrFileName
= NULL
;
237 if (mOptions
.VfrBaseFileName
!= NULL
) {
238 free (mOptions
.VfrBaseFileName
);
239 mOptions
.VfrBaseFileName
= NULL
;
241 if (mOptions
.OutputDirectory
!= NULL
) {
242 free (mOptions
.OutputDirectory
);
243 mOptions
.OutputDirectory
= NULL
;
245 if (mOptions
.PkgOutputFileName
!= NULL
) {
246 free (mOptions
.PkgOutputFileName
);
247 mOptions
.PkgOutputFileName
= NULL
;
249 if (mOptions
.COutputFileName
!= NULL
) {
250 free (mOptions
.COutputFileName
);
251 mOptions
.COutputFileName
= NULL
;
253 if (mOptions
.PreprocessorOutputFileName
!= NULL
) {
254 free (mOptions
.PreprocessorOutputFileName
);
255 mOptions
.PreprocessorOutputFileName
= NULL
;
257 if (mOptions
.RecordListFile
!= NULL
) {
258 free (mOptions
.RecordListFile
);
259 mOptions
.RecordListFile
= NULL
;
261 if (mOptions
.IncludePaths
!= NULL
) {
262 delete mOptions
.IncludePaths
;
263 mOptions
.IncludePaths
= NULL
;
265 if (mOptions
.CPreprocessorOptions
!= NULL
) {
266 delete mOptions
.CPreprocessorOptions
;
267 mOptions
.CPreprocessorOptions
= NULL
;
272 CVfrCompiler::AppendIncludePath (
277 CHAR8
*IncludePaths
= NULL
;
279 Len
= strlen (" -I ") + strlen (PathStr
) + 1;
280 if (mOptions
.IncludePaths
!= NULL
) {
281 Len
+= strlen (mOptions
.IncludePaths
);
283 IncludePaths
= new CHAR8
[Len
];
284 if (IncludePaths
== NULL
) {
285 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
288 IncludePaths
[0] = '\0';
289 if (mOptions
.IncludePaths
!= NULL
) {
290 strcat (IncludePaths
, mOptions
.IncludePaths
);
292 strcat (IncludePaths
, " -I ");
293 strcat (IncludePaths
, PathStr
);
294 if (mOptions
.IncludePaths
!= NULL
) {
295 delete mOptions
.IncludePaths
;
297 mOptions
.IncludePaths
= IncludePaths
;
301 CVfrCompiler::AppendCPreprocessorOptions (
308 Len
= strlen (Options
) + strlen (" ") + 1;
309 if (mOptions
.CPreprocessorOptions
!= NULL
) {
310 Len
+= strlen (mOptions
.CPreprocessorOptions
);
312 Opt
= new CHAR8
[Len
];
314 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
318 if (mOptions
.CPreprocessorOptions
!= NULL
) {
319 strcat (Opt
, mOptions
.CPreprocessorOptions
);
322 strcat (Opt
, Options
);
323 if (mOptions
.CPreprocessorOptions
!= NULL
) {
324 delete mOptions
.CPreprocessorOptions
;
326 mOptions
.CPreprocessorOptions
= Opt
;
330 CVfrCompiler::SetBaseFileName (
334 CHAR8
*pFileName
, *pPath
, *pExt
;
336 if (mOptions
.VfrFileName
== NULL
) {
340 pFileName
= mOptions
.VfrFileName
;
342 ((pPath
= strchr (pFileName
, '\\')) != NULL
) ||
343 ((pPath
= strchr (pFileName
, '/')) != NULL
)
346 pFileName
= pPath
+ 1;
349 if (pFileName
== NULL
) {
353 if ((pExt
= strchr (pFileName
, '.')) == NULL
) {
358 if (strlen (pFileName
) > MAX_PATH
- 1) {
363 mOptions
.VfrBaseFileName
= (CHAR8
*) malloc (strlen (pFileName
) + 1);
364 if (mOptions
.VfrBaseFileName
== NULL
) {
369 strcpy (mOptions
.VfrBaseFileName
, pFileName
);
376 CVfrCompiler::SetPkgOutputFileName (
382 if (mOptions
.VfrBaseFileName
== NULL
) {
386 Length
= strlen (mOptions
.OutputDirectory
) +
387 strlen (mOptions
.VfrBaseFileName
) +
388 strlen (VFR_PACKAGE_FILENAME_EXTENSION
) +
390 if (Length
> MAX_PATH
) {
394 mOptions
.PkgOutputFileName
= (CHAR8
*) malloc (Length
);
395 if (mOptions
.PkgOutputFileName
== NULL
) {
399 strcpy (mOptions
.PkgOutputFileName
, mOptions
.OutputDirectory
);
400 strcat (mOptions
.PkgOutputFileName
, mOptions
.VfrBaseFileName
);
401 strcat (mOptions
.PkgOutputFileName
, VFR_PACKAGE_FILENAME_EXTENSION
);
407 CVfrCompiler::SetCOutputFileName (
413 if (mOptions
.VfrBaseFileName
== NULL
) {
417 Length
= strlen (mOptions
.OutputDirectory
) +
418 strlen (mOptions
.VfrBaseFileName
) +
421 if (Length
> MAX_PATH
) {
425 mOptions
.COutputFileName
= (CHAR8
*) malloc (Length
);
426 if (mOptions
.COutputFileName
== NULL
) {
430 strcpy (mOptions
.COutputFileName
, mOptions
.OutputDirectory
);
431 strcat (mOptions
.COutputFileName
, mOptions
.VfrBaseFileName
);
432 strcat (mOptions
.COutputFileName
, ".c");
438 CVfrCompiler::SetPreprocessorOutputFileName (
444 if (mOptions
.VfrBaseFileName
== NULL
) {
448 Length
= strlen (mOptions
.OutputDirectory
) +
449 strlen (mOptions
.VfrBaseFileName
) +
450 strlen (VFR_PREPROCESS_FILENAME_EXTENSION
) +
452 if (Length
> MAX_PATH
) {
456 mOptions
.PreprocessorOutputFileName
= (CHAR8
*) malloc (Length
);
457 if (mOptions
.PreprocessorOutputFileName
== NULL
) {
461 strcpy (mOptions
.PreprocessorOutputFileName
, mOptions
.OutputDirectory
);
462 strcat (mOptions
.PreprocessorOutputFileName
, mOptions
.VfrBaseFileName
);
463 strcat (mOptions
.PreprocessorOutputFileName
, VFR_PREPROCESS_FILENAME_EXTENSION
);
469 CVfrCompiler::SetRecordListFileName (
475 if (mOptions
.VfrBaseFileName
== NULL
) {
479 Length
= strlen (mOptions
.OutputDirectory
) +
480 strlen (mOptions
.VfrBaseFileName
) +
481 strlen (VFR_RECORDLIST_FILENAME_EXTENSION
) +
483 if (Length
> MAX_PATH
) {
487 mOptions
.RecordListFile
= (CHAR8
*) malloc (Length
);
488 if (mOptions
.RecordListFile
== NULL
) {
492 strcpy (mOptions
.RecordListFile
, mOptions
.OutputDirectory
);
493 strcat (mOptions
.RecordListFile
, mOptions
.VfrBaseFileName
);
494 strcat (mOptions
.RecordListFile
, VFR_RECORDLIST_FILENAME_EXTENSION
);
499 CVfrCompiler::CVfrCompiler (
504 mPreProcessCmd
= (CHAR8
*) PREPROCESSOR_COMMAND
;
505 mPreProcessOpt
= (CHAR8
*) PREPROCESSOR_OPTIONS
;
507 SET_RUN_STATUS (STATUS_STARTED
);
509 OptionInitialization(Argc
, Argv
);
511 if ((IS_RUN_STATUS(STATUS_FAILED
)) || (IS_RUN_STATUS(STATUS_DEAD
))) {
515 SET_RUN_STATUS(STATUS_INITIALIZED
);
518 CVfrCompiler::~CVfrCompiler (
522 if (mOptions
.VfrFileName
!= NULL
) {
523 free (mOptions
.VfrFileName
);
524 mOptions
.VfrFileName
= NULL
;
527 if (mOptions
.VfrBaseFileName
!= NULL
) {
528 free (mOptions
.VfrBaseFileName
);
529 mOptions
.VfrBaseFileName
= NULL
;
532 if (mOptions
.OutputDirectory
!= NULL
) {
533 free (mOptions
.OutputDirectory
);
534 mOptions
.OutputDirectory
= NULL
;
537 if (mOptions
.PkgOutputFileName
!= NULL
) {
538 free (mOptions
.PkgOutputFileName
);
539 mOptions
.PkgOutputFileName
= NULL
;
542 if (mOptions
.COutputFileName
!= NULL
) {
543 free (mOptions
.COutputFileName
);
544 mOptions
.COutputFileName
= NULL
;
547 if (mOptions
.PreprocessorOutputFileName
!= NULL
) {
548 free (mOptions
.PreprocessorOutputFileName
);
549 mOptions
.PreprocessorOutputFileName
= NULL
;
552 if (mOptions
.RecordListFile
!= NULL
) {
553 free (mOptions
.RecordListFile
);
554 mOptions
.RecordListFile
= NULL
;
557 if (mOptions
.IncludePaths
!= NULL
) {
558 delete mOptions
.IncludePaths
;
559 mOptions
.IncludePaths
= NULL
;
562 if (mOptions
.CPreprocessorOptions
!= NULL
) {
563 delete mOptions
.CPreprocessorOptions
;
564 mOptions
.CPreprocessorOptions
= NULL
;
567 SET_RUN_STATUS(STATUS_DEAD
);
571 CVfrCompiler::Usage (
576 CONST CHAR8
*Help
[] = {
578 "VfrCompile version " VFR_COMPILER_VERSION
"Build " __BUILD_VERSION
,
579 "Copyright (c) 2004-2016 Intel Corporation. All rights reserved.",
581 "Usage: VfrCompile [options] VfrFile",
584 " -h, --help prints this help",
585 " --version prints version info",
586 " -l create an output IFR listing file",
587 " -o DIR, --output-directory DIR",
588 " deposit all output files to directory OutputDir",
589 " default is current directory",
590 " -b, --create-ifr-package",
591 " create an IFR HII pack file",
592 " -n, --no-pre-processing",
593 " do not preprocessing input file",
594 " -c, --compatible-framework",
595 " compatible framework vfr file",
597 " input uni string package file",
599 " override class guid input",
600 " format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
601 " -w --warning-as-error",
602 " treat warning as an error",
603 " -a --autodefaut generate default value for question opcode if some default is missing",
604 " -d --checkdefault check the default information in a question opcode",
607 for (Index
= 0; Help
[Index
] != NULL
; Index
++) {
608 fprintf (stdout
, "%s\n", Help
[Index
]);
613 CVfrCompiler::Version (
618 CONST CHAR8
*Help
[] = {
619 "VfrCompile version " VFR_COMPILER_VERSION
"Build " __BUILD_VERSION
,
622 for (Index
= 0; Help
[Index
] != NULL
; Index
++) {
623 fprintf (stdout
, "%s\n", Help
[Index
]);
628 CVfrCompiler::PreProcess (
632 FILE *pVfrFile
= NULL
;
634 CHAR8
*PreProcessCmd
= NULL
;
636 if (!IS_RUN_STATUS(STATUS_INITIALIZED
)) {
640 if (mOptions
.SkipCPreprocessor
== TRUE
) {
644 if ((pVfrFile
= fopen (LongFilePath (mOptions
.VfrFileName
), "r")) == NULL
) {
645 DebugError (NULL
, 0, 0001, "Error opening the input VFR file", mOptions
.VfrFileName
);
650 CmdLen
= strlen (mPreProcessCmd
) + strlen (mPreProcessOpt
) +
651 strlen (mOptions
.VfrFileName
) + strlen (mOptions
.PreprocessorOutputFileName
);
652 if (mOptions
.CPreprocessorOptions
!= NULL
) {
653 CmdLen
+= strlen (mOptions
.CPreprocessorOptions
);
655 if (mOptions
.IncludePaths
!= NULL
) {
656 CmdLen
+= strlen (mOptions
.IncludePaths
);
659 PreProcessCmd
= new CHAR8
[CmdLen
+ 10];
660 if (PreProcessCmd
== NULL
) {
661 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
664 strcpy (PreProcessCmd
, mPreProcessCmd
), strcat (PreProcessCmd
, " ");
665 strcat (PreProcessCmd
, mPreProcessOpt
), strcat (PreProcessCmd
, " ");
666 if (mOptions
.IncludePaths
!= NULL
) {
667 strcat (PreProcessCmd
, mOptions
.IncludePaths
), strcat (PreProcessCmd
, " ");
669 if (mOptions
.CPreprocessorOptions
!= NULL
) {
670 strcat (PreProcessCmd
, mOptions
.CPreprocessorOptions
), strcat (PreProcessCmd
, " ");
672 strcat (PreProcessCmd
, mOptions
.VfrFileName
), strcat (PreProcessCmd
, " > ");
673 strcat (PreProcessCmd
, mOptions
.PreprocessorOutputFileName
);
675 if (system (PreProcessCmd
) != 0) {
676 DebugError (NULL
, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd
);
680 delete[] PreProcessCmd
;
683 SET_RUN_STATUS (STATUS_PREPROCESSED
);
687 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
688 SET_RUN_STATUS (STATUS_FAILED
);
690 delete[] PreProcessCmd
;
693 extern UINT8
VfrParserStart (IN
FILE *, IN INPUT_INFO_TO_SYNTAX
*);
696 CVfrCompiler::Compile (
700 FILE *pInFile
= NULL
;
701 CHAR8
*InFileName
= NULL
;
702 INPUT_INFO_TO_SYNTAX InputInfo
;
704 if (!IS_RUN_STATUS(STATUS_PREPROCESSED
)) {
708 InFileName
= (mOptions
.SkipCPreprocessor
== TRUE
) ? mOptions
.VfrFileName
: mOptions
.PreprocessorOutputFileName
;
710 gCVfrErrorHandle
.SetInputFile (InFileName
);
711 gCVfrErrorHandle
.SetWarningAsError(mOptions
.WarningAsError
);
713 if ((pInFile
= fopen (LongFilePath (InFileName
), "r")) == NULL
) {
714 DebugError (NULL
, 0, 0001, "Error opening the input file", InFileName
);
718 InputInfo
.CompatibleMode
= mOptions
.CompatibleMode
;
719 if (mOptions
.HasOverrideClassGuid
) {
720 InputInfo
.OverrideClassGuid
= &mOptions
.OverrideClassGuid
;
722 InputInfo
.OverrideClassGuid
= NULL
;
725 if (VfrParserStart (pInFile
, &InputInfo
) != 0) {
731 if (gCFormPkg
.HavePendingUnassigned () == TRUE
) {
732 gCFormPkg
.PendingAssignPrintAll ();
736 SET_RUN_STATUS (STATUS_COMPILEED
);
740 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
741 DebugError (NULL
, 0, 0003, "Error parsing", "compile error in file %s", InFileName
);
742 SET_RUN_STATUS (STATUS_FAILED
);
744 if (pInFile
!= NULL
) {
750 CVfrCompiler::AdjustBin (
754 EFI_VFR_RETURN_CODE Status
;
756 if (!IS_RUN_STATUS(STATUS_COMPILEED
)) {
760 if (gNeedAdjustOpcode
) {
762 // When parsing the Vfr, has created some opcodes, now need to update the record info.
764 gCIfrRecordInfoDB
.IfrUpdateRecordInfoForDynamicOpcode (FALSE
);
768 // Check whether need to check default info for question or auto add default for question.
770 if (mOptions
.AutoDefault
|| mOptions
.CheckDefault
) {
771 gCIfrRecordInfoDB
.IfrCheckAddDefaultRecord (mOptions
.AutoDefault
, mOptions
.CheckDefault
);
775 // Check Binary Code consistent between Form and IfrRecord
779 // Get Package Data and IfrRecord Data
781 gCFormPkg
.BuildPkg (gCBuffer
);
782 gCIfrRecordInfoDB
.IfrRecordOutput (gRBuffer
);
785 // Compare Form and Record data
787 if (gCBuffer
.Buffer
!= NULL
&& gRBuffer
.Buffer
!= NULL
) {
789 if (gCBuffer
.Size
!= gRBuffer
.Size
) {
790 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
);
792 for (Index
= 0; Index
< gCBuffer
.Size
; Index
++) {
793 if (gCBuffer
.Buffer
[Index
] != gRBuffer
.Buffer
[Index
]) {
797 if (Index
!= gCBuffer
.Size
) {
798 DebugError (NULL
, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions
.VfrFileName
, Index
);
800 DebugMsg (NULL
, 0, 9, (CHAR8
*) "IFR Buffer", (CHAR8
*) "Form Buffer same to Record Buffer and Size is 0x%X", Index
);
801 } else if (gCBuffer
.Buffer
== NULL
&& gRBuffer
.Buffer
== NULL
) {
804 DebugError (NULL
, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions
.VfrFileName
);
808 // For UEFI mode, not do OpCode Adjust
810 if (mOptions
.CompatibleMode
) {
812 // Adjust Opcode to be compatible with framework vfr
814 Status
= gCIfrRecordInfoDB
.IfrRecordAdjust ();
815 if (Status
!= VFR_RETURN_SUCCESS
) {
817 // Record List Adjust Failed
819 SET_RUN_STATUS (STATUS_FAILED
);
823 // Re get the IfrRecord Buffer.
825 gCIfrRecordInfoDB
.IfrRecordOutput (gRBuffer
);
832 CVfrCompiler::GenBinary (
838 if (!IS_RUN_STATUS(STATUS_COMPILEED
)) {
842 if (mOptions
.CreateIfrPkgFile
== TRUE
) {
843 if ((pFile
= fopen (LongFilePath (mOptions
.PkgOutputFileName
), "wb")) == NULL
) {
844 DebugError (NULL
, 0, 0001, "Error opening file", mOptions
.PkgOutputFileName
);
847 if (gCFormPkg
.BuildPkg (pFile
, &gRBuffer
) != VFR_RETURN_SUCCESS
) {
854 SET_RUN_STATUS (STATUS_GENBINARY
);
859 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
860 SET_RUN_STATUS (STATUS_FAILED
);
864 static const char *gSourceFileHeader
[] = {
866 "// DO NOT EDIT -- auto-generated file",
868 "// This file is generated by the vfrcompiler utility",
874 CVfrCompiler::GenCFile (
881 if (!IS_RUN_STATUS(STATUS_GENBINARY
)) {
885 if (!mOptions
.CreateIfrPkgFile
|| mOptions
.CompatibleMode
) {
886 if ((pFile
= fopen (LongFilePath (mOptions
.COutputFileName
), "w")) == NULL
) {
887 DebugError (NULL
, 0, 0001, "Error opening output C file", mOptions
.COutputFileName
);
891 for (Index
= 0; gSourceFileHeader
[Index
] != NULL
; Index
++) {
892 fprintf (pFile
, "%s\n", gSourceFileHeader
[Index
]);
895 if (mOptions
.CompatibleMode
) {
896 gCVfrBufferConfig
.OutputCFile (pFile
, mOptions
.VfrBaseFileName
);
899 if (gCFormPkg
.GenCFile (mOptions
.VfrBaseFileName
, pFile
, &gRBuffer
) != VFR_RETURN_SUCCESS
) {
906 SET_RUN_STATUS (STATUS_FINISHED
);
910 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
911 SET_RUN_STATUS (STATUS_FAILED
);
916 CVfrCompiler::GenRecordListFile (
920 CHAR8
*InFileName
= NULL
;
921 FILE *pInFile
= NULL
;
922 FILE *pOutFile
= NULL
;
923 CHAR8 LineBuf
[MAX_VFR_LINE_LEN
];
926 InFileName
= (mOptions
.SkipCPreprocessor
== TRUE
) ? mOptions
.VfrFileName
: mOptions
.PreprocessorOutputFileName
;
928 if (mOptions
.CreateRecordListFile
== TRUE
) {
929 if ((InFileName
[0] == '\0') || (mOptions
.RecordListFile
[0] == '\0')) {
933 if ((pInFile
= fopen (LongFilePath (InFileName
), "r")) == NULL
) {
934 DebugError (NULL
, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName
);
938 if ((pOutFile
= fopen (LongFilePath (mOptions
.RecordListFile
), "w")) == NULL
) {
939 DebugError (NULL
, 0, 0001, "Error opening the record list file", mOptions
.RecordListFile
);
943 fprintf (pOutFile
, "//\n// VFR compiler version " VFR_COMPILER_VERSION __BUILD_VERSION
"\n//\n");
945 while (!feof (pInFile
)) {
946 if (fgets (LineBuf
, MAX_VFR_LINE_LEN
, pInFile
) != NULL
) {
947 fprintf (pOutFile
, "%s", LineBuf
);
949 gCIfrRecordInfoDB
.IfrRecordOutput (pOutFile
, LineNo
);
953 fprintf (pOutFile
, "\n//\n// All Opcode Record List \n//\n");
954 gCIfrRecordInfoDB
.IfrRecordOutput (pOutFile
, 0);
955 gCVfrVarDataTypeDB
.Dump(pOutFile
);
973 COMPILER_RUN_STATUS Status
;
975 SetPrintLevel(WARNING_LOG_LEVEL
);
976 CVfrCompiler
Compiler(Argc
, Argv
);
978 Compiler
.PreProcess();
980 Compiler
.AdjustBin();
981 Compiler
.GenBinary();
983 Compiler
.GenRecordListFile ();
985 Status
= Compiler
.RunStatus ();
986 if ((Status
== STATUS_DEAD
) || (Status
== STATUS_FAILED
)) {
990 if (gCBuffer
.Buffer
!= NULL
) {
991 delete gCBuffer
.Buffer
;
994 if (gRBuffer
.Buffer
!= NULL
) {
995 delete gRBuffer
.Buffer
;
998 return GetUtilityStatus ();