]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
195727c2eb101828983569bc24b2d1045d0e371f
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrCompiler.cpp
1 /** @file
2
3 VfrCompiler main class and main function.
4
5 Copyright (c) 2004 - 2008, Intel Corporation
6 All rights reserved. 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
10
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.
13
14 **/
15
16 #include "stdio.h"
17 #include "stdlib.h"
18 #include "string.h"
19 #include "VfrCompiler.h"
20 #include "CommonLib.h"
21 #include "EfiUtilityMsgs.h"
22
23 PACKAGE_DATA gCBuffer;
24 PACKAGE_DATA gRBuffer;
25
26 VOID
27 CVfrCompiler::DebugError () {
28 Error (NULL, 0, 0001, "Error parsing vfr file", " %s", mOptions.VfrFileName);
29 //_asm int 3;
30 }
31
32 VOID
33 CVfrCompiler::SET_RUN_STATUS (
34 IN COMPILER_RUN_STATUS Status
35 )
36 {
37 mRunStatus = Status;
38 }
39
40 BOOLEAN
41 CVfrCompiler::IS_RUN_STATUS (
42 IN COMPILER_RUN_STATUS Status
43 )
44 {
45 return mRunStatus == Status;
46 }
47
48 VOID
49 CVfrCompiler::OptionInitialization (
50 IN INT32 Argc,
51 IN CHAR8 **Argv
52 )
53 {
54 INT32 Index;
55
56 SetUtilityName (PROGRAM_NAME);
57
58 mOptions.VfrFileName[0] = '\0';
59 mOptions.RecordListFile[0] = '\0';
60 mOptions.CreateRecordListFile = FALSE;
61 mOptions.CreateIfrPkgFile = FALSE;
62 mOptions.PkgOutputFileName[0] = '\0';
63 mOptions.COutputFileName[0] = '\0';
64 mOptions.OutputDirectory[0] = '\0';
65 mOptions.PreprocessorOutputFileName[0] = '\0';
66 mOptions.VfrBaseFileName[0] = '\0';
67 mOptions.IncludePaths = NULL;
68 mOptions.SkipCPreprocessor = TRUE;
69 mOptions.CPreprocessorOptions = NULL;
70 mOptions.CompatibleMode = FALSE;
71
72 if (Argc == 1) {
73 Usage ();
74 SET_RUN_STATUS (STATUS_DEAD);
75 return;
76 }
77
78 for (Index = 1; (Index < Argc) && (Argv[Index][0] == '-'); Index++) {
79 if ((stricmp(Argv[Index], "-h") == 0) || (stricmp(Argv[Index], "--help") == 0)) {
80 Usage ();
81 SET_RUN_STATUS (STATUS_DEAD);
82 return;
83 } else if (stricmp(Argv[Index], "-l") == 0) {
84 mOptions.CreateRecordListFile = TRUE;
85 gCIfrRecordInfoDB.TurnOn ();
86 } else if (stricmp(Argv[Index], "-i") == 0) {
87 Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);
88 goto Fail;
89 Index++;
90 if ((Index >= Argc) || (Argv[Index][0] == '-')) {
91 Error (NULL, 0, 1001, "Missing option", "-i missing path argument");
92 goto Fail;
93 }
94
95 AppendIncludePath(Argv[Index]);
96 } else if (stricmp(Argv[Index], "-o") == 0 || stricmp(Argv[Index], "--output-directory") == 0 || stricmp(Argv[Index], "-od") == 0) {
97 Index++;
98 if ((Index >= Argc) || (Argv[Index][0] == '-')) {
99 Error (NULL, 0, 1001, "Missing option", "-o missing output directory name");
100 goto Fail;
101 }
102 strcpy (mOptions.OutputDirectory, Argv[Index]);
103
104 CHAR8 lastChar = mOptions.OutputDirectory[strlen(mOptions.OutputDirectory) - 1];
105 if ((lastChar != '/') && (lastChar != '\\')) {
106 if (strchr(mOptions.OutputDirectory, '/') != NULL) {
107 strcat (mOptions.OutputDirectory, "/");
108 } else {
109 strcat (mOptions.OutputDirectory, "\\");
110 }
111 }
112 DebugMsg (NULL, 0, 9, "Output Directory", mOptions.OutputDirectory);
113 } else if (stricmp(Argv[Index], "-b") == 0 || stricmp(Argv[Index], "--create-ifr-package") == 0 || stricmp(Argv[Index], "-ibin") == 0) {
114 mOptions.CreateIfrPkgFile = TRUE;
115 } else if (stricmp(Argv[Index], "-n") == 0 || stricmp(Argv[Index], "--no-pre-processing") == 0 || stricmp(Argv[Index], "-nopp") == 0) {
116 mOptions.SkipCPreprocessor = TRUE;
117 } else if (stricmp(Argv[Index], "-f") == 0 || stricmp(Argv[Index], "--pre-processing-flag") == 0 || stricmp(Argv[Index], "-ppflag") == 0) {
118 Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);
119 goto Fail;
120 Index++;
121 if ((Index >= Argc) || (Argv[Index][0] == '-')) {
122 Error (NULL, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");
123 goto Fail;
124 }
125
126 AppendCPreprocessorOptions (Argv[Index]);
127 } else if (stricmp(Argv[Index], "-c") == 0 || stricmp(Argv[Index], "--compatible-framework") == 0) {
128 mOptions.CompatibleMode = TRUE;
129 } else {
130 Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);
131 goto Fail;
132 }
133 }
134
135 if (Index != Argc - 1) {
136 Error (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");
137 goto Fail;
138 } else {
139 strcpy (mOptions.VfrFileName, Argv[Index]);
140 }
141
142 if (SetBaseFileName() != 0) {
143 goto Fail;
144 }
145 if (SetPkgOutputFileName () != 0) {
146 goto Fail;
147 }
148 if (SetCOutputFileName() != 0) {
149 goto Fail;
150 }
151 if (SetPreprocessorOutputFileName () != 0) {
152 goto Fail;
153 }
154 if (SetRecordListFileName () != 0) {
155 goto Fail;
156 }
157 return;
158
159 Fail:
160 SET_RUN_STATUS (STATUS_DEAD);
161
162 mOptions.VfrFileName[0] = '\0';
163 mOptions.RecordListFile[0] = '\0';
164 mOptions.CreateRecordListFile = FALSE;
165 mOptions.CreateIfrPkgFile = FALSE;
166 mOptions.PkgOutputFileName[0] = '\0';
167 mOptions.COutputFileName[0] = '\0';
168 mOptions.OutputDirectory[0] = '\0';
169 mOptions.PreprocessorOutputFileName[0] = '\0';
170 mOptions.VfrBaseFileName[0] = '\0';
171 if (mOptions.IncludePaths != NULL) {
172 delete mOptions.IncludePaths;
173 mOptions.IncludePaths = NULL;
174 }
175 if (mOptions.CPreprocessorOptions != NULL) {
176 delete mOptions.CPreprocessorOptions;
177 mOptions.CPreprocessorOptions = NULL;
178 }
179 }
180
181 VOID
182 CVfrCompiler::AppendIncludePath (
183 IN CHAR8 *PathStr
184 )
185 {
186 UINT32 Len = 0;
187 CHAR8 *IncludePaths = NULL;
188
189 Len = strlen (" -I ") + strlen (PathStr) + 1;
190 if (mOptions.IncludePaths != NULL) {
191 Len += strlen (mOptions.IncludePaths);
192 }
193 IncludePaths = new CHAR8[Len];
194 if (IncludePaths == NULL) {
195 Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);
196 return;
197 }
198 IncludePaths[0] = '\0';
199 if (mOptions.IncludePaths != NULL) {
200 strcat (IncludePaths, mOptions.IncludePaths);
201 }
202 strcat (IncludePaths, " -I ");
203 strcat (IncludePaths, PathStr);
204 if (mOptions.IncludePaths != NULL) {
205 delete mOptions.IncludePaths;
206 }
207 mOptions.IncludePaths = IncludePaths;
208 }
209
210 VOID
211 CVfrCompiler::AppendCPreprocessorOptions (
212 IN CHAR8 *Options
213 )
214 {
215 UINT32 Len = 0;
216 CHAR8 *Opt = NULL;
217
218 Len = strlen (Options) + strlen (" ") + 1;
219 if (mOptions.CPreprocessorOptions != NULL) {
220 Len += strlen (mOptions.CPreprocessorOptions);
221 }
222 Opt = new CHAR8[Len];
223 if (Opt == NULL) {
224 Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);
225 return;
226 }
227 Opt[0] = 0;
228 if (mOptions.CPreprocessorOptions != NULL) {
229 strcat (Opt, mOptions.CPreprocessorOptions);
230 }
231 strcat (Opt, " ");
232 strcat (Opt, Options);
233 if (mOptions.CPreprocessorOptions != NULL) {
234 delete mOptions.CPreprocessorOptions;
235 }
236 mOptions.CPreprocessorOptions = Opt;
237 }
238
239 INT8
240 CVfrCompiler::SetBaseFileName (
241 VOID
242 )
243 {
244 CHAR8 *pFileName, *pPath, *pExt;
245
246 if (mOptions.VfrFileName[0] == '\0') {
247 return -1;
248 }
249
250 pFileName = mOptions.VfrFileName;
251 while (
252 ((pPath = strchr (pFileName, '\\')) != NULL) ||
253 ((pPath = strchr (pFileName, '/')) != NULL)
254 )
255 {
256 pFileName = pPath + 1;
257 }
258
259 if (pFileName == NULL) {
260 return -1;
261 }
262
263 if ((pExt = strchr (pFileName, '.')) == NULL) {
264 return -1;
265 }
266
267 strncpy (mOptions.VfrBaseFileName, pFileName, pExt - pFileName);
268 mOptions.VfrBaseFileName[pExt - pFileName] = '\0';
269
270 return 0;
271 }
272
273 INT8
274 CVfrCompiler::SetPkgOutputFileName (
275 VOID
276 )
277 {
278 if (mOptions.VfrBaseFileName[0] == '\0') {
279 return -1;
280 }
281
282 strcpy (mOptions.PkgOutputFileName, mOptions.OutputDirectory);
283 strcat (mOptions.PkgOutputFileName, mOptions.VfrBaseFileName);
284 strcat (mOptions.PkgOutputFileName, VFR_PACKAGE_FILENAME_EXTENSION);
285
286 return 0;
287 }
288
289 INT8
290 CVfrCompiler::SetCOutputFileName (
291 VOID
292 )
293 {
294 if (mOptions.VfrBaseFileName[0] == '\0') {
295 return -1;
296 }
297
298 strcpy (mOptions.COutputFileName, mOptions.OutputDirectory);
299 strcat (mOptions.COutputFileName, mOptions.VfrBaseFileName);
300 strcat (mOptions.COutputFileName, ".c");
301
302 return 0;
303 }
304
305 INT8
306 CVfrCompiler::SetPreprocessorOutputFileName (
307 VOID
308 )
309 {
310 if (mOptions.VfrBaseFileName[0] == '\0') {
311 return -1;
312 }
313
314 strcpy (mOptions.PreprocessorOutputFileName, mOptions.OutputDirectory);
315 strcat (mOptions.PreprocessorOutputFileName, mOptions.VfrBaseFileName);
316 strcat (mOptions.PreprocessorOutputFileName, VFR_PREPROCESS_FILENAME_EXTENSION);
317
318 return 0;
319 }
320
321 INT8
322 CVfrCompiler::SetRecordListFileName (
323 VOID
324 )
325 {
326 if (mOptions.VfrBaseFileName[0] == '\0') {
327 return -1;
328 }
329
330 strcpy (mOptions.RecordListFile, mOptions.OutputDirectory);
331 strcat (mOptions.RecordListFile, mOptions.VfrBaseFileName);
332 strcat (mOptions.RecordListFile, VFR_RECORDLIST_FILENAME_EXTENSION);
333
334 return 0;
335 }
336
337 CVfrCompiler::CVfrCompiler (
338 IN INT32 Argc,
339 IN CHAR8 **Argv
340 )
341 {
342 mPreProcessCmd = PREPROCESSOR_COMMAND;
343 mPreProcessOpt = PREPROCESSOR_OPTIONS;
344
345 OptionInitialization(Argc, Argv);
346
347 if ((IS_RUN_STATUS(STATUS_FAILED)) || (IS_RUN_STATUS(STATUS_DEAD))) {
348 return;
349 }
350
351 SET_RUN_STATUS(STATUS_INITIALIZED);
352 }
353
354 CVfrCompiler::~CVfrCompiler (
355 VOID
356 )
357 {
358 if (mOptions.IncludePaths != NULL) {
359 delete mOptions.IncludePaths;
360 mOptions.IncludePaths = NULL;
361 }
362
363 if (mOptions.CPreprocessorOptions != NULL) {
364 delete mOptions.CPreprocessorOptions;
365 mOptions.CPreprocessorOptions = NULL;
366 }
367
368 SET_RUN_STATUS(STATUS_DEAD);
369 }
370
371 VOID
372 CVfrCompiler::Usage (
373 VOID
374 )
375 {
376 UINT32 Index;
377 CONST CHAR8 *Help[] = {
378 " ",
379 "VfrCompile version " VFR_COMPILER_VERSION VFR_COMPILER_UPDATE_TIME,
380 " ",
381 "Usage: VfrCompile [options] VfrFile",
382 " ",
383 "Options:",
384 " -h, --help prints this help",
385 " -l create an output IFR listing file",
386 " -o DIR, --output-directory DIR",
387 " deposit all output files to directory OutputDir",
388 " default is current directory",
389 " -b, --create-ifr-package",
390 " create an IFR HII pack file",
391 " -n, --no-pre-processing",
392 " do not preprocessing input file",
393 " -c, --compatible-framework",
394 " compatible framework vfr file",
395 NULL
396 };
397 for (Index = 0; Help[Index] != NULL; Index++) {
398 fprintf (stdout, "%s\n", Help[Index]);
399 }
400 }
401
402 VOID
403 CVfrCompiler::PreProcess (
404 VOID
405 )
406 {
407 FILE *pVfrFile = NULL;
408 UINT32 CmdLen = 0;
409 CHAR8 *PreProcessCmd = NULL;
410
411 if (!IS_RUN_STATUS(STATUS_INITIALIZED)) {
412 goto Fail;
413 }
414
415 if (mOptions.SkipCPreprocessor == TRUE) {
416 goto Out;
417 }
418
419 if ((pVfrFile = fopen (mOptions.VfrFileName, "r")) == NULL) {
420 Error (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);
421 goto Fail;
422 }
423 fclose (pVfrFile);
424
425 CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) +
426 strlen (mOptions.VfrFileName) + strlen (mOptions.PreprocessorOutputFileName);
427 if (mOptions.CPreprocessorOptions != NULL) {
428 CmdLen += strlen (mOptions.CPreprocessorOptions);
429 }
430 if (mOptions.IncludePaths != NULL) {
431 CmdLen += strlen (mOptions.IncludePaths);
432 }
433
434 PreProcessCmd = new CHAR8[CmdLen + 10];
435 if (PreProcessCmd == NULL) {
436 Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);
437 goto Fail;
438 }
439 strcpy (PreProcessCmd, mPreProcessCmd), strcat (PreProcessCmd, " ");
440 strcat (PreProcessCmd, mPreProcessOpt), strcat (PreProcessCmd, " ");
441 if (mOptions.IncludePaths != NULL) {
442 strcat (PreProcessCmd, mOptions.IncludePaths), strcat (PreProcessCmd, " ");
443 }
444 if (mOptions.CPreprocessorOptions != NULL) {
445 strcat (PreProcessCmd, mOptions.CPreprocessorOptions), strcat (PreProcessCmd, " ");
446 }
447 strcat (PreProcessCmd, mOptions.VfrFileName), strcat (PreProcessCmd, " > ");
448 strcat (PreProcessCmd, mOptions.PreprocessorOutputFileName);
449
450 if (system (PreProcessCmd) != 0) {
451 Error (NULL, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd);
452 goto Fail;
453 }
454
455 delete PreProcessCmd;
456
457 Out:
458 SET_RUN_STATUS (STATUS_PREPROCESSED);
459 return;
460
461 Fail:
462 if (!IS_RUN_STATUS(STATUS_DEAD)) {
463 SET_RUN_STATUS (STATUS_FAILED);
464 }
465 delete PreProcessCmd;
466 }
467
468 extern UINT8 VfrParserStart (IN FILE *, IN BOOLEAN);
469
470 VOID
471 CVfrCompiler::Compile (
472 VOID
473 )
474 {
475 FILE *pInFile = NULL;
476 CHAR8 *InFileName = NULL;
477
478 if (!IS_RUN_STATUS(STATUS_PREPROCESSED)) {
479 goto Fail;
480 }
481
482 InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;
483
484 gCVfrErrorHandle.SetInputFile (InFileName);
485
486 if ((pInFile = fopen (InFileName, "r")) == NULL) {
487 Error (NULL, 0, 0001, "Error opening the input file", InFileName);
488 goto Fail;
489 }
490
491 if (VfrParserStart (pInFile, mOptions.CompatibleMode) != 0) {
492 goto Fail;
493 }
494
495 fclose (pInFile);
496
497 if (gCFormPkg.HavePendingUnassigned () == TRUE) {
498 gCFormPkg.PendingAssignPrintAll ();
499 goto Fail;
500 }
501
502 SET_RUN_STATUS (STATUS_COMPILEED);
503 return;
504
505 Fail:
506 if (!IS_RUN_STATUS(STATUS_DEAD)) {
507 Error (NULL, 0, 0003, "Error parsing", "compile error in file %s", InFileName);
508 SET_RUN_STATUS (STATUS_FAILED);
509 }
510 if (pInFile != NULL) {
511 fclose (pInFile);
512 }
513 }
514
515 VOID
516 CVfrCompiler::AdjustBin (
517 VOID
518 )
519 {
520 EFI_VFR_RETURN_CODE Status;
521 //
522 // Check Binary Code consistent between Form and IfrRecord
523 //
524
525 //
526 // Get Package Data and IfrRecord Data
527 //
528 gCFormPkg.BuildPkg (gCBuffer);
529 gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);
530
531 //
532 // Compare Form and Record data
533 //
534 if (gCBuffer.Buffer != NULL && gRBuffer.Buffer != NULL) {
535 UINT32 Index;
536 if (gCBuffer.Size != gRBuffer.Size) {
537 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);
538 }
539 for (Index = 0; Index < gCBuffer.Size; Index ++) {
540 if (gCBuffer.Buffer[Index] != gRBuffer.Buffer[Index]) {
541 break;
542 }
543 }
544 if (Index != gCBuffer.Size) {
545 Error (NULL, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions.VfrFileName, Index);
546 }
547 DebugMsg (NULL, 0, 9, "IFR Buffer", "Form Buffer same to Record Buffer and Size is 0x%X", Index);
548 } else if (gCBuffer.Buffer == NULL && gRBuffer.Buffer == NULL) {
549 //ok
550 } else {
551 Error (NULL, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions.VfrFileName);
552 }
553
554 //
555 // For UEFI mode, not do OpCode Adjust
556 //
557 if (mOptions.CompatibleMode) {
558 //
559 // Adjust Opcode to be compatible with framework vfr
560 //
561 Status = gCIfrRecordInfoDB.IfrRecordAdjust ();
562 if (Status != VFR_RETURN_SUCCESS) {
563 //
564 // Record List Adjust Failed
565 //
566 SET_RUN_STATUS (STATUS_FAILED);
567 return;
568 }
569 //
570 // Re get the IfrRecord Buffer.
571 //
572 gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);
573 }
574
575 return;
576 }
577
578 VOID
579 CVfrCompiler::GenBinary (
580 VOID
581 )
582 {
583 FILE *pFile = NULL;
584
585 if (!IS_RUN_STATUS(STATUS_COMPILEED)) {
586 goto Fail;
587 }
588
589 if (mOptions.CreateIfrPkgFile == TRUE) {
590 if ((pFile = fopen (mOptions.PkgOutputFileName, "wb")) == NULL) {
591 Error (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);
592 goto Fail;
593 }
594 if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {
595 fclose (pFile);
596 goto Fail;
597 }
598 fclose (pFile);
599 }
600
601 SET_RUN_STATUS (STATUS_GENBINARY);
602
603 return;
604
605 Fail:
606 if (!IS_RUN_STATUS(STATUS_DEAD)) {
607 SET_RUN_STATUS (STATUS_FAILED);
608 }
609 }
610
611 static const char *gSourceFileHeader[] = {
612 "//",
613 "// DO NOT EDIT -- auto-generated file",
614 "//",
615 "// This file is generated by the vfrcompiler utility",
616 "//",
617 NULL
618 };
619
620 VOID
621 CVfrCompiler::GenCFile (
622 VOID
623 )
624 {
625 FILE *pFile;
626 UINT32 Index;
627
628 if (!IS_RUN_STATUS(STATUS_GENBINARY)) {
629 goto Fail;
630 }
631
632 if ((pFile = fopen (mOptions.COutputFileName, "w")) == NULL) {
633 Error (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);
634 goto Fail;
635 }
636
637 for (Index = 0; gSourceFileHeader[Index] != NULL; Index++) {
638 fprintf (pFile, "%s\n", gSourceFileHeader[Index]);
639 }
640
641 gCVfrBufferConfig.OutputCFile (pFile, mOptions.VfrBaseFileName);
642
643 if (gCFormPkg.GenCFile (mOptions.VfrBaseFileName, pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {
644 fclose (pFile);
645 goto Fail;
646 }
647 fclose (pFile);
648
649 SET_RUN_STATUS (STATUS_FINISHED);
650 return;
651
652 Fail:
653 if (!IS_RUN_STATUS(STATUS_DEAD)) {
654 SET_RUN_STATUS (STATUS_FAILED);
655 }
656 }
657
658 VOID
659 CVfrCompiler::GenRecordListFile (
660 VOID
661 )
662 {
663 CHAR8 *InFileName = NULL;
664 FILE *pInFile = NULL;
665 FILE *pOutFile = NULL;
666 CHAR8 LineBuf[MAX_VFR_LINE_LEN];
667 UINT32 LineNo;
668
669 InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;
670
671 if (mOptions.CreateRecordListFile == TRUE) {
672 if ((InFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {
673 return;
674 }
675
676 if ((pInFile = fopen (InFileName, "r")) == NULL) {
677 Error (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);
678 return;
679 }
680
681 if ((pOutFile = fopen (mOptions.RecordListFile, "w")) == NULL) {
682 Error (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);
683 goto Err1;
684 }
685
686 fprintf (pOutFile, "//\n// VFR compiler version " VFR_COMPILER_VERSION "\n//\n");
687 LineNo = 0;
688 while (!feof (pInFile)) {
689 if (fgets (LineBuf, MAX_VFR_LINE_LEN, pInFile) != NULL) {
690 fprintf (pOutFile, "%s", LineBuf);
691 LineNo++;
692 gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, LineNo);
693 }
694 }
695
696 fprintf (pOutFile, "\n//\n// All Opcode Record List \n//\n");
697 gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, 0);
698 gCVfrVarDataTypeDB.Dump(pOutFile);
699
700 fclose (pOutFile);
701 fclose (pInFile);
702 }
703
704 return;
705
706 Err1:
707 fclose (pInFile);
708 }
709
710 int
711 main (
712 IN INT32 Argc,
713 IN CHAR8 **Argv
714 )
715 {
716 COMPILER_RUN_STATUS Status;
717 CVfrCompiler Compiler(Argc, Argv);
718
719 Compiler.PreProcess();
720 Compiler.Compile();
721 Compiler.AdjustBin();
722 Compiler.GenBinary();
723 Compiler.GenCFile();
724 Compiler.GenRecordListFile ();
725
726 Status = Compiler.RunStatus ();
727 if ((Status == STATUS_DEAD) || (Status == STATUS_FAILED)) {
728 return 2;
729 }
730
731 if (gCBuffer.Buffer != NULL) {
732 delete gCBuffer.Buffer;
733 }
734
735 if (gRBuffer.Buffer != NULL) {
736 delete gRBuffer.Buffer;
737 }
738
739 return GetUtilityStatus ();
740 }
741