3 VfrCompiler main class and main function.
5 Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "VfrCompiler.h"
14 #include "CommonLib.h"
15 #include "EfiUtilityMsgs.h"
17 PACKAGE_DATA gCBuffer
;
18 PACKAGE_DATA gRBuffer
;
19 CVfrStringDB gCVfrStringDB
;
22 CVfrCompiler::DebugError (
25 IN UINT32 MessageCode
,
27 IN CONST CHAR8
*MsgFmt
,
32 va_start (List
, MsgFmt
);
33 PrintMessage ((CHAR8
*) "ERROR", FileName
, LineNumber
, MessageCode
, (CHAR8
*) Text
, (CHAR8
*) MsgFmt
, List
);
38 CVfrCompiler::SET_RUN_STATUS (
39 IN COMPILER_RUN_STATUS Status
46 CVfrCompiler::IS_RUN_STATUS (
47 IN COMPILER_RUN_STATUS Status
50 return mRunStatus
== Status
;
54 CVfrCompiler::OptionInitialization (
63 SetUtilityName ((CHAR8
*) PROGRAM_NAME
);
65 mOptions
.VfrFileName
= NULL
;
66 mOptions
.RecordListFile
= NULL
;
67 mOptions
.CreateRecordListFile
= FALSE
;
68 mOptions
.CreateIfrPkgFile
= FALSE
;
69 mOptions
.PkgOutputFileName
= NULL
;
70 mOptions
.COutputFileName
= NULL
;
71 mOptions
.OutputDirectory
= NULL
;
72 mOptions
.PreprocessorOutputFileName
= NULL
;
73 mOptions
.VfrBaseFileName
= NULL
;
74 mOptions
.IncludePaths
= NULL
;
75 mOptions
.SkipCPreprocessor
= TRUE
;
76 mOptions
.CPreprocessorOptions
= NULL
;
77 mOptions
.HasOverrideClassGuid
= FALSE
;
78 mOptions
.WarningAsError
= FALSE
;
79 mOptions
.AutoDefault
= FALSE
;
80 mOptions
.CheckDefault
= FALSE
;
81 memset (&mOptions
.OverrideClassGuid
, 0, sizeof (EFI_GUID
));
85 SET_RUN_STATUS (STATUS_DEAD
);
89 for (Index
= 1; (Index
< Argc
) && (Argv
[Index
][0] == '-'); Index
++) {
90 if ((stricmp(Argv
[Index
], "-h") == 0) || (stricmp(Argv
[Index
], "--help") == 0)) {
92 SET_RUN_STATUS (STATUS_DEAD
);
94 } else if (stricmp(Argv
[Index
], "--version") == 0) {
96 SET_RUN_STATUS (STATUS_DEAD
);
98 } else if (stricmp(Argv
[Index
], "-l") == 0) {
99 mOptions
.CreateRecordListFile
= TRUE
;
100 gCIfrRecordInfoDB
.TurnOn ();
101 } else if (stricmp(Argv
[Index
], "-i") == 0) {
103 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
104 DebugError (NULL
, 0, 1001, "Missing option", "-i missing path argument");
108 AppendIncludePath(Argv
[Index
]);
109 } else if (stricmp(Argv
[Index
], "-o") == 0 || stricmp(Argv
[Index
], "--output-directory") == 0 || stricmp(Argv
[Index
], "-od") == 0) {
111 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
112 DebugError (NULL
, 0, 1001, "Missing option", "-o missing output directory name");
116 mOptions
.OutputDirectory
= (CHAR8
*) malloc (strlen (Argv
[Index
]) + strlen ("\\") + 1);
117 if (mOptions
.OutputDirectory
== NULL
) {
118 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
121 strcpy (mOptions
.OutputDirectory
, Argv
[Index
]);
123 CHAR8 lastChar
= mOptions
.OutputDirectory
[strlen(mOptions
.OutputDirectory
) - 1];
124 if ((lastChar
!= '/') && (lastChar
!= '\\')) {
125 if (strchr(mOptions
.OutputDirectory
, '/') != NULL
) {
126 strcat (mOptions
.OutputDirectory
, "/");
128 strcat (mOptions
.OutputDirectory
, "\\");
131 DebugMsg (NULL
, 0, 9, (CHAR8
*) "Output Directory", (CHAR8
*) "%s", mOptions
.OutputDirectory
);
132 } else if (stricmp(Argv
[Index
], "-b") == 0 || stricmp(Argv
[Index
], "--create-ifr-package") == 0 || stricmp(Argv
[Index
], "-ibin") == 0) {
133 mOptions
.CreateIfrPkgFile
= TRUE
;
134 } else if (stricmp(Argv
[Index
], "-n") == 0 || stricmp(Argv
[Index
], "--no-pre-processing") == 0 || stricmp(Argv
[Index
], "-nopp") == 0) {
135 mOptions
.SkipCPreprocessor
= TRUE
;
136 } else if (stricmp(Argv
[Index
], "-f") == 0 || stricmp(Argv
[Index
], "--pre-processing-flag") == 0 || stricmp(Argv
[Index
], "-ppflag") == 0) {
138 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
139 DebugError (NULL
, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");
143 AppendCPreprocessorOptions (Argv
[Index
]);
144 } else if (stricmp(Argv
[Index
], "-s") == 0|| stricmp(Argv
[Index
], "--string-db") == 0) {
146 if ((Index
>= Argc
) || (Argv
[Index
][0] == '-')) {
147 DebugError (NULL
, 0, 1001, "Missing option", "-s missing input string file name");
150 gCVfrStringDB
.SetStringFileName(Argv
[Index
]);
151 DebugMsg (NULL
, 0, 9, (CHAR8
*) "Input string file path", (CHAR8
*) "%s", Argv
[Index
]);
152 } else if ((stricmp (Argv
[Index
], "-g") == 0) || (stricmp (Argv
[Index
], "--guid") == 0)) {
154 Status
= StringToGuid (Argv
[Index
], &mOptions
.OverrideClassGuid
);
155 if (EFI_ERROR (Status
)) {
156 DebugError (NULL
, 0, 1000, "Invalid format:", "%s", Argv
[Index
]);
159 mOptions
.HasOverrideClassGuid
= TRUE
;
160 } else if (stricmp(Argv
[Index
], "-w") == 0 || stricmp(Argv
[Index
], "--warning-as-error") == 0) {
161 mOptions
.WarningAsError
= TRUE
;
162 } else if (stricmp(Argv
[Index
], "-a") == 0 ||stricmp(Argv
[Index
], "--autodefault") == 0) {
163 mOptions
.AutoDefault
= TRUE
;
164 } else if (stricmp(Argv
[Index
], "-d") == 0 ||stricmp(Argv
[Index
], "--checkdefault") == 0) {
165 mOptions
.CheckDefault
= TRUE
;
167 DebugError (NULL
, 0, 1000, "Unknown option", "unrecognized option %s", Argv
[Index
]);
172 if (Index
!= Argc
- 1) {
173 DebugError (NULL
, 0, 1001, "Missing option", "VFR file name is not specified.");
176 mOptions
.VfrFileName
= (CHAR8
*) malloc (strlen (Argv
[Index
]) + 1);
177 if (mOptions
.VfrFileName
== NULL
) {
178 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
181 strcpy (mOptions
.VfrFileName
, Argv
[Index
]);
183 if (mOptions
.OutputDirectory
== NULL
) {
184 mOptions
.OutputDirectory
= (CHAR8
*) malloc (1);
185 if (mOptions
.OutputDirectory
== NULL
) {
186 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
189 mOptions
.OutputDirectory
[0] = '\0';
193 if (SetBaseFileName() != 0) {
196 if (SetPkgOutputFileName () != 0) {
199 if (SetCOutputFileName() != 0) {
202 if (SetPreprocessorOutputFileName () != 0) {
205 if (SetRecordListFileName () != 0) {
211 SET_RUN_STATUS (STATUS_DEAD
);
213 mOptions
.CreateRecordListFile
= FALSE
;
214 mOptions
.CreateIfrPkgFile
= FALSE
;
216 if (mOptions
.VfrFileName
!= NULL
) {
217 free (mOptions
.VfrFileName
);
218 mOptions
.VfrFileName
= NULL
;
220 if (mOptions
.VfrBaseFileName
!= NULL
) {
221 free (mOptions
.VfrBaseFileName
);
222 mOptions
.VfrBaseFileName
= NULL
;
224 if (mOptions
.OutputDirectory
!= NULL
) {
225 free (mOptions
.OutputDirectory
);
226 mOptions
.OutputDirectory
= NULL
;
228 if (mOptions
.PkgOutputFileName
!= NULL
) {
229 free (mOptions
.PkgOutputFileName
);
230 mOptions
.PkgOutputFileName
= NULL
;
232 if (mOptions
.COutputFileName
!= NULL
) {
233 free (mOptions
.COutputFileName
);
234 mOptions
.COutputFileName
= NULL
;
236 if (mOptions
.PreprocessorOutputFileName
!= NULL
) {
237 free (mOptions
.PreprocessorOutputFileName
);
238 mOptions
.PreprocessorOutputFileName
= NULL
;
240 if (mOptions
.RecordListFile
!= NULL
) {
241 free (mOptions
.RecordListFile
);
242 mOptions
.RecordListFile
= NULL
;
244 if (mOptions
.IncludePaths
!= NULL
) {
245 delete mOptions
.IncludePaths
;
246 mOptions
.IncludePaths
= NULL
;
248 if (mOptions
.CPreprocessorOptions
!= NULL
) {
249 delete mOptions
.CPreprocessorOptions
;
250 mOptions
.CPreprocessorOptions
= NULL
;
255 CVfrCompiler::AppendIncludePath (
260 CHAR8
*IncludePaths
= NULL
;
262 Len
= strlen (" -I ") + strlen (PathStr
) + 1;
263 if (mOptions
.IncludePaths
!= NULL
) {
264 Len
+= strlen (mOptions
.IncludePaths
);
266 IncludePaths
= new CHAR8
[Len
];
267 if (IncludePaths
== NULL
) {
268 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
271 IncludePaths
[0] = '\0';
272 if (mOptions
.IncludePaths
!= NULL
) {
273 strcat (IncludePaths
, mOptions
.IncludePaths
);
275 strcat (IncludePaths
, " -I ");
276 strcat (IncludePaths
, PathStr
);
277 if (mOptions
.IncludePaths
!= NULL
) {
278 delete[] mOptions
.IncludePaths
;
280 mOptions
.IncludePaths
= IncludePaths
;
284 CVfrCompiler::AppendCPreprocessorOptions (
291 Len
= strlen (Options
) + strlen (" ") + 1;
292 if (mOptions
.CPreprocessorOptions
!= NULL
) {
293 Len
+= strlen (mOptions
.CPreprocessorOptions
);
295 Opt
= new CHAR8
[Len
];
297 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
301 if (mOptions
.CPreprocessorOptions
!= NULL
) {
302 strcat (Opt
, mOptions
.CPreprocessorOptions
);
305 strcat (Opt
, Options
);
306 if (mOptions
.CPreprocessorOptions
!= NULL
) {
307 delete[] mOptions
.CPreprocessorOptions
;
309 mOptions
.CPreprocessorOptions
= Opt
;
313 CVfrCompiler::SetBaseFileName (
317 CHAR8
*pFileName
, *pPath
, *pExt
;
319 if (mOptions
.VfrFileName
== NULL
) {
323 pFileName
= mOptions
.VfrFileName
;
325 ((pPath
= strchr (pFileName
, '\\')) != NULL
) ||
326 ((pPath
= strchr (pFileName
, '/')) != NULL
)
329 pFileName
= pPath
+ 1;
332 if (pFileName
== NULL
) {
336 if ((pExt
= strchr (pFileName
, '.')) == NULL
) {
342 mOptions
.VfrBaseFileName
= (CHAR8
*) malloc (strlen (pFileName
) + 1);
343 if (mOptions
.VfrBaseFileName
== NULL
) {
348 strcpy (mOptions
.VfrBaseFileName
, pFileName
);
355 CVfrCompiler::SetPkgOutputFileName (
361 if (mOptions
.VfrBaseFileName
== NULL
) {
365 Length
= strlen (mOptions
.OutputDirectory
) +
366 strlen (mOptions
.VfrBaseFileName
) +
367 strlen (VFR_PACKAGE_FILENAME_EXTENSION
) +
370 mOptions
.PkgOutputFileName
= (CHAR8
*) malloc (Length
);
371 if (mOptions
.PkgOutputFileName
== NULL
) {
375 strcpy (mOptions
.PkgOutputFileName
, mOptions
.OutputDirectory
);
376 strcat (mOptions
.PkgOutputFileName
, mOptions
.VfrBaseFileName
);
377 strcat (mOptions
.PkgOutputFileName
, VFR_PACKAGE_FILENAME_EXTENSION
);
383 CVfrCompiler::SetCOutputFileName (
389 if (mOptions
.VfrBaseFileName
== NULL
) {
393 Length
= strlen (mOptions
.OutputDirectory
) +
394 strlen (mOptions
.VfrBaseFileName
) +
398 mOptions
.COutputFileName
= (CHAR8
*) malloc (Length
);
399 if (mOptions
.COutputFileName
== NULL
) {
403 strcpy (mOptions
.COutputFileName
, mOptions
.OutputDirectory
);
404 strcat (mOptions
.COutputFileName
, mOptions
.VfrBaseFileName
);
405 strcat (mOptions
.COutputFileName
, ".c");
411 CVfrCompiler::SetPreprocessorOutputFileName (
417 if (mOptions
.VfrBaseFileName
== NULL
) {
421 Length
= strlen (mOptions
.OutputDirectory
) +
422 strlen (mOptions
.VfrBaseFileName
) +
423 strlen (VFR_PREPROCESS_FILENAME_EXTENSION
) +
426 mOptions
.PreprocessorOutputFileName
= (CHAR8
*) malloc (Length
);
427 if (mOptions
.PreprocessorOutputFileName
== NULL
) {
431 strcpy (mOptions
.PreprocessorOutputFileName
, mOptions
.OutputDirectory
);
432 strcat (mOptions
.PreprocessorOutputFileName
, mOptions
.VfrBaseFileName
);
433 strcat (mOptions
.PreprocessorOutputFileName
, VFR_PREPROCESS_FILENAME_EXTENSION
);
439 CVfrCompiler::SetRecordListFileName (
445 if (mOptions
.VfrBaseFileName
== NULL
) {
449 Length
= strlen (mOptions
.OutputDirectory
) +
450 strlen (mOptions
.VfrBaseFileName
) +
451 strlen (VFR_RECORDLIST_FILENAME_EXTENSION
) +
454 mOptions
.RecordListFile
= (CHAR8
*) malloc (Length
);
455 if (mOptions
.RecordListFile
== NULL
) {
459 strcpy (mOptions
.RecordListFile
, mOptions
.OutputDirectory
);
460 strcat (mOptions
.RecordListFile
, mOptions
.VfrBaseFileName
);
461 strcat (mOptions
.RecordListFile
, VFR_RECORDLIST_FILENAME_EXTENSION
);
466 CVfrCompiler::CVfrCompiler (
471 mPreProcessCmd
= (CHAR8
*) PREPROCESSOR_COMMAND
;
472 mPreProcessOpt
= (CHAR8
*) PREPROCESSOR_OPTIONS
;
474 SET_RUN_STATUS (STATUS_STARTED
);
476 OptionInitialization(Argc
, Argv
);
478 if ((IS_RUN_STATUS(STATUS_FAILED
)) || (IS_RUN_STATUS(STATUS_DEAD
))) {
482 SET_RUN_STATUS(STATUS_INITIALIZED
);
485 CVfrCompiler::~CVfrCompiler (
489 if (mOptions
.VfrFileName
!= NULL
) {
490 free (mOptions
.VfrFileName
);
491 mOptions
.VfrFileName
= NULL
;
494 if (mOptions
.VfrBaseFileName
!= NULL
) {
495 free (mOptions
.VfrBaseFileName
);
496 mOptions
.VfrBaseFileName
= NULL
;
499 if (mOptions
.OutputDirectory
!= NULL
) {
500 free (mOptions
.OutputDirectory
);
501 mOptions
.OutputDirectory
= NULL
;
504 if (mOptions
.PkgOutputFileName
!= NULL
) {
505 free (mOptions
.PkgOutputFileName
);
506 mOptions
.PkgOutputFileName
= NULL
;
509 if (mOptions
.COutputFileName
!= NULL
) {
510 free (mOptions
.COutputFileName
);
511 mOptions
.COutputFileName
= NULL
;
514 if (mOptions
.PreprocessorOutputFileName
!= NULL
) {
515 free (mOptions
.PreprocessorOutputFileName
);
516 mOptions
.PreprocessorOutputFileName
= NULL
;
519 if (mOptions
.RecordListFile
!= NULL
) {
520 free (mOptions
.RecordListFile
);
521 mOptions
.RecordListFile
= NULL
;
524 if (mOptions
.IncludePaths
!= NULL
) {
525 delete[] mOptions
.IncludePaths
;
526 mOptions
.IncludePaths
= NULL
;
529 if (mOptions
.CPreprocessorOptions
!= NULL
) {
530 delete[] mOptions
.CPreprocessorOptions
;
531 mOptions
.CPreprocessorOptions
= NULL
;
534 SET_RUN_STATUS(STATUS_DEAD
);
538 CVfrCompiler::Usage (
543 CONST CHAR8
*Help
[] = {
545 "VfrCompile version " VFR_COMPILER_VERSION
"Build " __BUILD_VERSION
,
546 "Copyright (c) 2004-2016 Intel Corporation. All rights reserved.",
548 "Usage: VfrCompile [options] VfrFile",
551 " -h, --help prints this help",
552 " --version prints version info",
553 " -l create an output IFR listing file",
554 " -o DIR, --output-directory DIR",
555 " deposit all output files to directory OutputDir",
556 " default is current directory",
557 " -b, --create-ifr-package",
558 " create an IFR HII pack file",
559 " -n, --no-pre-processing",
560 " do not preprocessing input file",
562 " input uni string package file",
564 " override class guid input",
565 " format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
566 " -w --warning-as-error",
567 " treat warning as an error",
568 " -a --autodefaut generate default value for question opcode if some default is missing",
569 " -d --checkdefault check the default information in a question opcode",
572 for (Index
= 0; Help
[Index
] != NULL
; Index
++) {
573 fprintf (stdout
, "%s\n", Help
[Index
]);
578 CVfrCompiler::Version (
583 CONST CHAR8
*Help
[] = {
584 "VfrCompile version " VFR_COMPILER_VERSION
"Build " __BUILD_VERSION
,
587 for (Index
= 0; Help
[Index
] != NULL
; Index
++) {
588 fprintf (stdout
, "%s\n", Help
[Index
]);
593 CVfrCompiler::PreProcess (
597 FILE *pVfrFile
= NULL
;
599 CHAR8
*PreProcessCmd
= NULL
;
601 if (!IS_RUN_STATUS(STATUS_INITIALIZED
)) {
605 if (mOptions
.SkipCPreprocessor
== TRUE
) {
609 if ((pVfrFile
= fopen (LongFilePath (mOptions
.VfrFileName
), "r")) == NULL
) {
610 DebugError (NULL
, 0, 0001, "Error opening the input VFR file", "%s", mOptions
.VfrFileName
);
615 CmdLen
= strlen (mPreProcessCmd
) + strlen (mPreProcessOpt
) +
616 strlen (mOptions
.VfrFileName
) + strlen (mOptions
.PreprocessorOutputFileName
);
617 if (mOptions
.CPreprocessorOptions
!= NULL
) {
618 CmdLen
+= strlen (mOptions
.CPreprocessorOptions
);
620 if (mOptions
.IncludePaths
!= NULL
) {
621 CmdLen
+= strlen (mOptions
.IncludePaths
);
624 PreProcessCmd
= new CHAR8
[CmdLen
+ 10];
625 if (PreProcessCmd
== NULL
) {
626 DebugError (NULL
, 0, 4001, "Resource: memory can't be allocated", NULL
);
629 strcpy (PreProcessCmd
, mPreProcessCmd
), strcat (PreProcessCmd
, " ");
630 strcat (PreProcessCmd
, mPreProcessOpt
), strcat (PreProcessCmd
, " ");
631 if (mOptions
.IncludePaths
!= NULL
) {
632 strcat (PreProcessCmd
, mOptions
.IncludePaths
), strcat (PreProcessCmd
, " ");
634 if (mOptions
.CPreprocessorOptions
!= NULL
) {
635 strcat (PreProcessCmd
, mOptions
.CPreprocessorOptions
), strcat (PreProcessCmd
, " ");
637 strcat (PreProcessCmd
, mOptions
.VfrFileName
), strcat (PreProcessCmd
, " > ");
638 strcat (PreProcessCmd
, mOptions
.PreprocessorOutputFileName
);
640 if (system (PreProcessCmd
) != 0) {
641 DebugError (NULL
, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd
);
645 delete[] PreProcessCmd
;
648 SET_RUN_STATUS (STATUS_PREPROCESSED
);
652 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
653 SET_RUN_STATUS (STATUS_FAILED
);
655 delete[] PreProcessCmd
;
658 extern UINT8
VfrParserStart (IN
FILE *, IN INPUT_INFO_TO_SYNTAX
*);
661 CVfrCompiler::Compile (
665 FILE *pInFile
= NULL
;
666 CHAR8
*InFileName
= NULL
;
667 INPUT_INFO_TO_SYNTAX InputInfo
;
669 if (!IS_RUN_STATUS(STATUS_PREPROCESSED
)) {
673 InFileName
= (mOptions
.SkipCPreprocessor
== TRUE
) ? mOptions
.VfrFileName
: mOptions
.PreprocessorOutputFileName
;
675 gCVfrErrorHandle
.SetInputFile (InFileName
);
676 gCVfrErrorHandle
.SetWarningAsError(mOptions
.WarningAsError
);
678 if ((pInFile
= fopen (LongFilePath (InFileName
), "r")) == NULL
) {
679 DebugError (NULL
, 0, 0001, "Error opening the input file", "%s", InFileName
);
683 if (mOptions
.HasOverrideClassGuid
) {
684 InputInfo
.OverrideClassGuid
= &mOptions
.OverrideClassGuid
;
686 InputInfo
.OverrideClassGuid
= NULL
;
689 if (VfrParserStart (pInFile
, &InputInfo
) != 0) {
696 if (gCFormPkg
.HavePendingUnassigned () == TRUE
) {
697 gCFormPkg
.PendingAssignPrintAll ();
701 SET_RUN_STATUS (STATUS_COMPILEED
);
705 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
706 DebugError (NULL
, 0, 0003, "Error parsing", "compile error in file %s", InFileName
);
707 SET_RUN_STATUS (STATUS_FAILED
);
709 if (pInFile
!= NULL
) {
715 CVfrCompiler::AdjustBin (
719 EFI_VFR_RETURN_CODE Status
;
721 if (!IS_RUN_STATUS(STATUS_COMPILEED
)) {
725 if (gNeedAdjustOpcode
) {
727 // When parsing the Vfr, has created some opcodes, now need to update the record info.
729 gCIfrRecordInfoDB
.IfrUpdateRecordInfoForDynamicOpcode (FALSE
);
733 // Check whether need to check default info for question or auto add default for question.
735 if (mOptions
.AutoDefault
|| mOptions
.CheckDefault
) {
736 gCIfrRecordInfoDB
.IfrCheckAddDefaultRecord (mOptions
.AutoDefault
, mOptions
.CheckDefault
);
740 // Check Binary Code consistent between Form and IfrRecord
744 // Get Package Data and IfrRecord Data
746 gCFormPkg
.BuildPkg (gCBuffer
);
747 gCIfrRecordInfoDB
.IfrRecordOutput (gRBuffer
);
750 // Compare Form and Record data
752 if (gCBuffer
.Buffer
!= NULL
&& gRBuffer
.Buffer
!= NULL
) {
754 if (gCBuffer
.Size
!= gRBuffer
.Size
) {
755 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
);
757 for (Index
= 0; Index
< gCBuffer
.Size
; Index
++) {
758 if (gCBuffer
.Buffer
[Index
] != gRBuffer
.Buffer
[Index
]) {
762 if (Index
!= gCBuffer
.Size
) {
763 DebugError (NULL
, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions
.VfrFileName
, Index
);
765 DebugMsg (NULL
, 0, 9, (CHAR8
*) "IFR Buffer", (CHAR8
*) "Form Buffer same to Record Buffer and Size is 0x%X", Index
);
766 } else if (gCBuffer
.Buffer
== NULL
&& gRBuffer
.Buffer
== NULL
) {
769 DebugError (NULL
, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions
.VfrFileName
);
776 CVfrCompiler::GenBinary (
782 if (!IS_RUN_STATUS(STATUS_COMPILEED
)) {
786 if (mOptions
.CreateIfrPkgFile
== TRUE
) {
787 if ((pFile
= fopen (LongFilePath (mOptions
.PkgOutputFileName
), "wb")) == NULL
) {
788 DebugError (NULL
, 0, 0001, "Error opening file", "%s", mOptions
.PkgOutputFileName
);
791 if (gCFormPkg
.BuildPkg (pFile
, &gRBuffer
) != VFR_RETURN_SUCCESS
) {
798 SET_RUN_STATUS (STATUS_GENBINARY
);
803 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
804 SET_RUN_STATUS (STATUS_FAILED
);
808 static const char *gSourceFileHeader
[] = {
810 "// DO NOT EDIT -- auto-generated file",
812 "// This file is generated by the vfrcompiler utility",
818 CVfrCompiler::GenCFile (
825 if (!IS_RUN_STATUS(STATUS_GENBINARY
)) {
829 if (!mOptions
.CreateIfrPkgFile
) {
830 if ((pFile
= fopen (LongFilePath (mOptions
.COutputFileName
), "w")) == NULL
) {
831 DebugError (NULL
, 0, 0001, "Error opening output C file", "%s", mOptions
.COutputFileName
);
835 for (Index
= 0; gSourceFileHeader
[Index
] != NULL
; Index
++) {
836 fprintf (pFile
, "%s\n", gSourceFileHeader
[Index
]);
839 if (gCFormPkg
.GenCFile (mOptions
.VfrBaseFileName
, pFile
, &gRBuffer
) != VFR_RETURN_SUCCESS
) {
846 SET_RUN_STATUS (STATUS_FINISHED
);
850 if (!IS_RUN_STATUS(STATUS_DEAD
)) {
851 SET_RUN_STATUS (STATUS_FAILED
);
856 CVfrCompiler::GenRecordListFile (
860 CHAR8
*InFileName
= NULL
;
861 FILE *pInFile
= NULL
;
862 FILE *pOutFile
= NULL
;
863 CHAR8 LineBuf
[MAX_VFR_LINE_LEN
];
866 InFileName
= (mOptions
.SkipCPreprocessor
== TRUE
) ? mOptions
.VfrFileName
: mOptions
.PreprocessorOutputFileName
;
868 if (mOptions
.CreateRecordListFile
== TRUE
&& InFileName
!= NULL
&& mOptions
.RecordListFile
!= NULL
) {
869 if ((InFileName
[0] == '\0') || (mOptions
.RecordListFile
[0] == '\0')) {
873 if ((pInFile
= fopen (LongFilePath (InFileName
), "r")) == NULL
) {
874 DebugError (NULL
, 0, 0001, "Error opening the input VFR preprocessor output file", "%s", InFileName
);
878 if ((pOutFile
= fopen (LongFilePath (mOptions
.RecordListFile
), "w")) == NULL
) {
879 DebugError (NULL
, 0, 0001, "Error opening the record list file", "%s", mOptions
.RecordListFile
);
883 fprintf (pOutFile
, "//\n// VFR compiler version " VFR_COMPILER_VERSION __BUILD_VERSION
"\n//\n");
885 while (!feof (pInFile
)) {
886 if (fgets (LineBuf
, MAX_VFR_LINE_LEN
, pInFile
) != NULL
) {
887 fprintf (pOutFile
, "%s", LineBuf
);
889 gCIfrRecordInfoDB
.IfrRecordOutput (pOutFile
, LineNo
);
893 fprintf (pOutFile
, "\n//\n// All Opcode Record List \n//\n");
894 gCIfrRecordInfoDB
.IfrRecordOutput (pOutFile
, 0);
895 gCVfrVarDataTypeDB
.Dump(pOutFile
);
913 COMPILER_RUN_STATUS Status
;
915 SetPrintLevel(WARNING_LOG_LEVEL
);
916 CVfrCompiler
Compiler(Argc
, Argv
);
918 Compiler
.PreProcess();
920 Compiler
.AdjustBin();
921 Compiler
.GenBinary();
923 Compiler
.GenRecordListFile ();
925 Status
= Compiler
.RunStatus ();
926 if ((Status
== STATUS_DEAD
) || (Status
== STATUS_FAILED
)) {
930 if (gCBuffer
.Buffer
!= NULL
) {
931 delete[] gCBuffer
.Buffer
;
934 if (gRBuffer
.Buffer
!= NULL
) {
935 delete[] gRBuffer
.Buffer
;
938 return GetUtilityStatus ();