]> git.sur5r.net Git - cc65/blob - src/cc65/main.c
Fixed a bug
[cc65] / src / cc65 / main.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  main.c                                   */
4 /*                                                                           */
5 /*                             cc65 main program                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2004 Ullrich von Bassewitz                                       */
10 /*               Römerstraße 52                                              */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <errno.h>
40
41 /* common */
42 #include "abend.h"
43 #include "chartype.h"
44 #include "cmdline.h"
45 #include "cpu.h"
46 #include "debugflag.h"
47 #include "fname.h"
48 #include "mmodel.h"
49 #include "print.h"
50 #include "segnames.h"
51 #include "target.h"
52 #include "tgttrans.h"
53 #include "version.h"
54 #include "xmalloc.h"
55
56 /* cc65 */
57 #include "asmcode.h"
58 #include "compile.h"
59 #include "codeopt.h"
60 #include "error.h"
61 #include "global.h"
62 #include "incpath.h"
63 #include "input.h"
64 #include "macrotab.h"
65 #include "scanner.h"
66 #include "segments.h"
67
68
69
70 /*****************************************************************************/
71 /*                                   Code                                    */
72 /*****************************************************************************/
73
74
75
76 static void Usage (void)
77 /* Print usage information to stderr */
78 {
79     fprintf (stderr,
80              "Usage: %s [options] file\n"
81              "Short options:\n"
82              "  -A\t\t\tStrict ANSI mode\n"
83              "  -Cl\t\t\tMake local variables static\n"
84              "  -Dsym[=defn]\t\tDefine a symbol\n"
85              "  -I dir\t\tSet an include directory search path\n"
86              "  -O\t\t\tOptimize code\n"
87              "  -Oi\t\t\tOptimize code, inline more code\n"
88              "  -Or\t\t\tEnable register variables\n"
89              "  -Os\t\t\tInline some known functions\n"
90              "  -T\t\t\tInclude source as comment\n"
91              "  -V\t\t\tPrint the compiler version number\n"
92              "  -W\t\t\tSuppress warnings\n"
93              "  -d\t\t\tDebug mode\n"
94              "  -g\t\t\tAdd debug info to object file\n"
95              "  -h\t\t\tHelp (this text)\n"
96              "  -j\t\t\tDefault characters are signed\n"
97              "  -mm model\t\tSet the memory model\n"
98              "  -o name\t\tName the output file\n"
99              "  -r\t\t\tEnable register variables\n"
100              "  -t sys\t\tSet the target system\n"
101              "  -v\t\t\tIncrease verbosity\n"
102              "\n"
103              "Long options:\n"
104              "  --add-source\t\tInclude source as comment\n"
105              "  --ansi\t\tStrict ANSI mode\n"
106              "  --bss-name seg\tSet the name of the BSS segment\n"
107              "  --check-stack\t\tGenerate stack overflow checks\n"
108              "  --code-name seg\tSet the name of the CODE segment\n"
109              "  --codesize x\t\tAccept larger code by factor x\n"
110              "  --cpu type\t\tSet cpu type (6502, 65c02)\n"
111              "  --create-dep\t\tCreate a make dependency file\n"
112              "  --data-name seg\tSet the name of the DATA segment\n"
113              "  --debug\t\tDebug mode\n"
114              "  --debug-info\t\tAdd debug info to object file\n"
115              "  --debug-opt name\tDebug optimization steps\n"
116              "  --disable-opt name\tDisable an optimization step\n"
117              "  --enable-opt name\tEnable an optimization step\n"
118              "  --forget-inc-paths\tForget include search paths\n"
119              "  --help\t\tHelp (this text)\n"
120              "  --include-dir dir\tSet an include directory search path\n"
121              "  --list-opt-steps\tList all optimizer steps and exit\n"
122              "  --memory-model model\tSet the memory model\n"
123              "  --register-space b\tSet space available for register variables\n"
124              "  --register-vars\tEnable register variables\n"
125              "  --rodata-name seg\tSet the name of the RODATA segment\n"
126              "  --signed-chars\tDefault characters are signed\n"
127              "  --static-locals\tMake local variables static\n"
128              "  --target sys\t\tSet the target system\n"
129              "  --verbose\t\tIncrease verbosity\n"
130              "  --version\t\tPrint the compiler version number\n",
131              ProgName);
132 }
133
134
135
136 static void cbmsys (const char* sys)
137 /* Define a CBM system */
138 {
139     DefineNumericMacro ("__CBM__", 1);
140     DefineNumericMacro (sys, 1);
141 }
142
143
144
145 static void SetSys (const char* Sys)
146 /* Define a target system */
147 {
148     switch (Target = FindTarget (Sys)) {
149
150         case TGT_NONE:
151             break;
152
153         case TGT_MODULE:
154             AbEnd ("Cannot use `module' as a target for the compiler");
155             break;
156
157         case TGT_ATARI:
158             DefineNumericMacro ("__ATARI__", 1);
159             break;
160
161         case TGT_C16:
162             cbmsys ("__C16__");
163             break;
164
165         case TGT_C64:
166             cbmsys ("__C64__");
167             break;
168
169         case TGT_VIC20:
170             cbmsys ("__VIC20__");
171             break;
172
173         case TGT_C128:
174             cbmsys ("__C128__");
175             break;
176
177         case TGT_ACE:
178             cbmsys ("__ACE__");
179             break;
180
181         case TGT_PLUS4:
182             cbmsys ("__PLUS4__");
183             break;
184
185         case TGT_CBM510:
186             cbmsys ("__CBM510__");
187             break;
188
189         case TGT_CBM610:
190             cbmsys ("__CBM610__");
191             break;
192
193         case TGT_PET:
194             cbmsys ("__PET__");
195             break;
196
197         case TGT_BBC:
198             DefineNumericMacro ("__BBC__", 1);
199             break;
200
201         case TGT_APPLE2:
202             DefineNumericMacro ("__APPLE2__", 1);
203             break;
204
205         case TGT_APPLE2ENH:
206             DefineNumericMacro ("__APPLE2ENH__", 1);
207             break;
208
209         case TGT_GEOS:
210             /* Do not handle as a CBM system */
211             DefineNumericMacro ("__GEOS__", 1);
212             break;
213
214         case TGT_LUNIX:
215             DefineNumericMacro ("__LUNIX__", 1);
216             break;
217
218         case TGT_ATMOS:
219             DefineNumericMacro ("__ATMOS__", 1);
220             break;
221
222         case TGT_NES:
223             DefineNumericMacro ("__NES__", 1);
224             break;
225
226         case TGT_SUPERVISION:
227             DefineNumericMacro ("__SUPERVISION__", 1);
228             break;
229
230         default:
231             AbEnd ("Unknown target system type %d", Target);
232     }
233
234     /* Initialize the translation tables for the target system */
235     TgtTranslateInit ();
236 }
237
238
239
240 static void DoCreateDep (const char* OutputName)
241 /* Create the dependency file */
242 {
243     /* Make the dependency file name from the output file name */
244     char* DepName = MakeFilename (OutputName, ".u");
245
246     /* Open the file */
247     FILE* F = fopen (DepName, "w");
248     if (F == 0) {
249         Fatal ("Cannot open dependency file `%s': %s", DepName, strerror (errno));
250     }
251
252     /* Write the dependencies to the file */
253     WriteDependencies (F, OutputName);
254
255     /* Close the file, check for errors */
256     if (fclose (F) != 0) {
257         remove (DepName);
258         Fatal ("Cannot write to dependeny file (disk full?)");
259     }
260
261     /* Free the name */
262     xfree (DepName);
263 }
264
265
266
267 static void DefineSym (const char* Def)
268 /* Define a symbol on the command line */
269 {
270     const char* P = Def;
271
272     /* The symbol must start with a character or underline */
273     if (Def [0] != '_' && !IsAlpha (Def [0])) {
274         InvDef (Def);
275     }
276
277     /* Check the symbol name */
278     while (IsAlNum (*P) || *P == '_') {
279         ++P;
280     }
281
282     /* Do we have a value given? */
283     if (*P != '=') {
284         if (*P != '\0') {
285             InvDef (Def);
286         }
287         /* No value given. Define the macro with the value 1 */
288         DefineNumericMacro (Def, 1);
289     } else {
290         /* We have a value, P points to the '=' character. Since the argument
291          * is const, create a copy and replace the '=' in the copy by a zero
292          * terminator.
293          */
294         char* Q;
295         unsigned Len = strlen (Def)+1;
296         char* S = (char*) xmalloc (Len);
297         memcpy (S, Def, Len);
298         Q = S + (P - Def);
299         *Q++ = '\0';
300
301         /* Define this as a macro */
302         DefineTextMacro (S, Q);
303
304         /* Release the allocated memory */
305         xfree (S);
306     }
307 }
308
309
310
311 static void CheckSegName (const char* Seg)
312 /* Abort if the given name is not a valid segment name */
313 {
314     /* Print an error and abort if the name is not ok */
315     if (!ValidSegName (Seg)) {
316         AbEnd ("Segment name `%s' is invalid", Seg);
317     }
318 }
319
320
321
322 static void OptAddSource (const char* Opt attribute ((unused)),
323                           const char* Arg attribute ((unused)))
324 /* Add source lines as comments in generated assembler file */
325 {
326     AddSource = 1;
327 }
328
329
330
331 static void OptAnsi (const char* Opt attribute ((unused)),
332                      const char* Arg attribute ((unused)))
333 /* Compile in strict ANSI mode */
334 {
335     ANSI = 1;
336 }
337
338
339
340 static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
341 /* Handle the --bss-name option */
342 {
343     /* Check for a valid name */
344     CheckSegName (Arg);
345
346     /* Set the name */
347     SetSegName (SEG_BSS, Arg);
348 }
349
350
351
352 static void OptCheckStack (const char* Opt attribute ((unused)),
353                            const char* Arg attribute ((unused)))
354 /* Handle the --check-stack option */
355 {
356     IS_Set (&CheckStack, 1);
357 }
358
359
360
361 static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg)
362 /* Handle the --code-name option */
363 {
364     /* Check for a valid name */
365     CheckSegName (Arg);
366
367     /* Set the name */
368     SetSegName (SEG_CODE, Arg);
369 }
370
371
372
373 static void OptCodeSize (const char* Opt, const char* Arg)
374 /* Handle the --codesize option */
375 {
376     /* Numeric argument expected */
377     if (sscanf (Arg, "%u", &CodeSizeFactor) != 1 ||
378         CodeSizeFactor < 100 ||
379         CodeSizeFactor > 1000) {
380         AbEnd ("Argument for %s is invalid", Opt);
381     }
382 }
383
384
385
386 static void OptCreateDep (const char* Opt attribute ((unused)),
387                           const char* Arg attribute ((unused)))
388 /* Handle the --create-dep option */
389 {
390     CreateDep = 1;
391 }
392
393
394
395 static void OptCPU (const char* Opt, const char* Arg)
396 /* Handle the --cpu option */
397 {
398     /* Find the CPU from the given name */
399     CPU = FindCPU (Arg);
400     if (CPU != CPU_6502 && CPU != CPU_65SC02 &&
401         CPU != CPU_65C02 && CPU != CPU_65816) {
402         AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
403     }
404 }
405
406
407
408 static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
409 /* Handle the --data-name option */
410 {
411     /* Check for a valid name */
412     CheckSegName (Arg);
413
414     /* Set the name */
415     SetSegName (SEG_DATA, Arg);
416 }
417
418
419
420 static void OptDebug (const char* Opt attribute ((unused)),
421                       const char* Arg attribute ((unused)))
422 /* Compiler debug mode */
423 {
424     ++Debug;
425 }
426
427
428
429 static void OptDebugInfo (const char* Opt attribute ((unused)),
430                           const char* Arg attribute ((unused)))
431 /* Add debug info to the object file */
432 {
433     DebugInfo = 1;
434 }
435
436
437
438 static void OptDebugOpt (const char* Opt attribute ((unused)), const char* Arg)
439 /* Debug optimization steps */
440 {
441     char Buf [128];
442     char* Line;
443
444     /* Open the file */
445     FILE* F = fopen (Arg, "r");
446     if (F == 0) {
447         AbEnd ("Cannot open `%s': %s", Arg, strerror (errno));
448     }
449
450     /* Read line by line, ignore empty lines and switch optimization
451      * steps on/off.
452      */
453     while (fgets (Buf, sizeof (Buf), F) != 0) {
454
455         /* Remove trailing control chars. This will also remove the
456          * trailing newline.
457          */
458         unsigned Len = strlen (Buf);
459         while (Len > 0 && IsControl (Buf[Len-1])) {
460             --Len;
461         }
462         Buf[Len] = '\0';
463
464         /* Get a pointer to the buffer and remove leading white space */
465         Line = Buf;
466         while (IsBlank (*Line)) {
467             ++Line;
468         }
469
470         /* Check the first character and enable/disable the step or
471          * ignore the line
472          */
473         switch (*Line) {
474
475             case '\0':
476             case '#':
477             case ';':
478                 /* Empty or comment line */
479                 continue;
480
481             case '-':
482                 DisableOpt (Line+1);
483                 break;
484
485             case '+':
486                 ++Line;
487                 /* FALLTHROUGH */
488
489             default:
490                 EnableOpt (Line);
491                 break;
492
493         }
494
495     }
496
497     /* Close the file, no error check here since we were just reading and
498      * this is only a debug function.
499      */
500     (void) fclose (F);
501 }
502
503
504
505 static void OptDisableOpt (const char* Opt attribute ((unused)), const char* Arg)
506 /* Disable an optimization step */
507 {
508     DisableOpt (Arg);
509 }
510
511
512
513 static void OptEnableOpt (const char* Opt attribute ((unused)), const char* Arg)
514 /* Enable an optimization step */
515 {
516     EnableOpt (Arg);
517 }
518
519
520
521 static void OptForgetIncPaths (const char* Opt attribute ((unused)),
522                                const char* Arg attribute ((unused)))
523 /* Forget all currently defined include paths */
524 {
525     ForgetAllIncludePaths ();
526 }
527
528
529
530 static void OptHelp (const char* Opt attribute ((unused)),
531                      const char* Arg attribute ((unused)))
532 /* Print usage information and exit */
533 {
534     Usage ();
535     exit (EXIT_SUCCESS);
536 }
537
538
539
540 static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
541 /* Add an include search path */
542 {
543     AddIncludePath (Arg, INC_SYS | INC_USER);
544 }
545
546
547
548 static void OptListOptSteps (const char* Opt attribute ((unused)),
549                              const char* Arg attribute ((unused)))
550 /* List all optimizer steps */
551 {
552     /* List the optimizer steps */
553     ListOptSteps (stdout);
554
555     /* Terminate */
556     exit (EXIT_SUCCESS);
557 }
558
559
560
561 static void OptMemoryModel (const char* Opt, const char* Arg)
562 /* Set the memory model */
563 {
564     mmodel_t M;
565
566     /* Check the current memory model */
567     if (MemoryModel != MMODEL_UNKNOWN) {
568         AbEnd ("Cannot use option `%s' twice", Opt);
569     }
570
571     /* Translate the memory model name and check it */
572     M = FindMemoryModel (Arg);
573     if (M == MMODEL_UNKNOWN) {
574         AbEnd ("Unknown memory model: %s", Arg);
575     } else if (M == MMODEL_HUGE) {
576         AbEnd ("Unsupported memory model: %s", Arg);
577     }
578
579     /* Set the memory model */
580     SetMemoryModel (M);
581 }
582
583
584
585 static void OptRegisterSpace (const char* Opt, const char* Arg)
586 /* Handle the --register-space option */
587 {
588     /* Numeric argument expected */
589     if (sscanf (Arg, "%u", &RegisterSpace) != 1 || RegisterSpace > 256) {
590         AbEnd ("Argument for option %s is invalid", Opt);
591     }
592 }
593
594
595
596 static void OptRegisterVars (const char* Opt attribute ((unused)),
597                              const char* Arg attribute ((unused)))
598 /* Handle the --register-vars option */
599 {
600     IS_Set (&EnableRegVars, 1);
601 }
602
603
604
605 static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg)
606 /* Handle the --rodata-name option */
607 {
608     /* Check for a valid name */
609     CheckSegName (Arg);
610
611     /* Set the name */
612     SetSegName (SEG_RODATA, Arg);
613 }
614
615
616
617 static void OptSignedChars (const char* Opt attribute ((unused)),
618                             const char* Arg attribute ((unused)))
619 /* Make default characters signed */
620 {
621     IS_Set (&SignedChars, 1);
622 }
623
624
625
626 static void OptStaticLocals (const char* Opt attribute ((unused)),
627                              const char* Arg attribute ((unused)))
628 /* Place local variables in static storage */
629 {
630     IS_Set (&StaticLocals, 1);
631 }
632
633
634
635 static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
636 /* Set the target system */
637 {
638     SetSys (Arg);
639 }
640
641
642
643 static void OptVerbose (const char* Opt attribute ((unused)),
644                         const char* Arg attribute ((unused)))
645 /* Increase verbosity */
646 {
647     ++Verbosity;
648 }
649
650
651
652 static void OptVersion (const char* Opt attribute ((unused)),
653                         const char* Arg attribute ((unused)))
654 /* Print the assembler version */
655 {
656     fprintf (stderr,
657              "cc65 V%u.%u.%u\n",
658              VER_MAJOR, VER_MINOR, VER_PATCH);
659 }
660
661
662
663 int main (int argc, char* argv[])
664 {
665     /* Program long options */
666     static const LongOpt OptTab[] = {
667         { "--add-source",       0,      OptAddSource            },
668         { "--ansi",             0,      OptAnsi                 },
669         { "--bss-name",         1,      OptBssName              },
670         { "--check-stack",      0,      OptCheckStack           },
671         { "--code-name",        1,      OptCodeName             },
672         { "--codesize",         1,      OptCodeSize             },
673         { "--cpu",              1,      OptCPU                  },
674         { "--create-dep",       0,      OptCreateDep            },
675         { "--data-name",        1,      OptDataName             },
676         { "--debug",            0,      OptDebug                },
677         { "--debug-info",       0,      OptDebugInfo            },
678         { "--debug-opt",        1,      OptDebugOpt             },
679         { "--disable-opt",      1,      OptDisableOpt           },
680         { "--enable-opt",       1,      OptEnableOpt            },
681         { "--forget-inc-paths", 0,      OptForgetIncPaths       },
682         { "--help",             0,      OptHelp                 },
683         { "--include-dir",      1,      OptIncludeDir           },
684         { "--list-opt-steps",   0,      OptListOptSteps         },
685         { "--memory-model",     1,      OptMemoryModel          },
686         { "--register-space",   1,      OptRegisterSpace        },
687         { "--register-vars",    0,      OptRegisterVars         },
688         { "--rodata-name",      1,      OptRodataName           },
689         { "--signed-chars",     0,      OptSignedChars          },
690         { "--static-locals",    0,      OptStaticLocals         },
691         { "--target",           1,      OptTarget               },
692         { "--verbose",          0,      OptVerbose              },
693         { "--version",          0,      OptVersion              },
694     };
695
696     unsigned I;
697
698     /* Initialize the output file name */
699     const char* OutputFile = 0;
700     const char* InputFile  = 0;
701
702     /* Initialize the cmdline module */
703     InitCmdLine (&argc, &argv, "cc65");
704
705     /* Initialize the default segment names */
706     InitSegNames ();
707
708     /* Initialize the include search paths */
709     InitIncludePaths ();
710
711     /* Parse the command line */
712     I = 1;
713     while (I < ArgCount) {
714
715         const char* P;
716
717         /* Get the argument */
718         const char* Arg = ArgVec[I];
719
720         /* Check for an option */
721         if (Arg [0] == '-') {
722
723             switch (Arg [1]) {
724
725                 case '-':
726                     LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
727                     break;
728
729                 case 'd':
730                     OptDebug (Arg, 0);
731                     break;
732
733                 case 'h':
734                 case '?':
735                     OptHelp (Arg, 0);
736                     break;
737
738                 case 'g':
739                     OptDebugInfo (Arg, 0);
740                     break;
741
742                 case 'j':
743                     OptSignedChars (Arg, 0);
744                     break;
745
746                 case 'o':
747                     OutputFile = GetArg (&I, 2);
748                     break;
749
750                 case 'r':
751                     OptRegisterVars (Arg, 0);
752                     break;
753
754                 case 't':
755                     OptTarget (Arg, GetArg (&I, 2));
756                     break;
757
758                 case 'u':
759                     OptCreateDep (Arg, 0);
760                     break;
761
762                 case 'v':
763                     OptVerbose (Arg, 0);
764                     break;
765
766                 case 'A':
767                     OptAnsi (Arg, 0);
768                     break;
769
770                 case 'C':
771                     P = Arg + 2;
772                     while (*P) {
773                         switch (*P++) {
774                             case 'l':
775                                 OptStaticLocals (Arg, 0);
776                                 break;
777                             default:
778                                 UnknownOption (Arg);
779                                 break;
780                         }
781                     }
782                     break;
783
784                 case 'D':
785                     DefineSym (GetArg (&I, 2));
786                     break;
787
788                 case 'I':
789                     OptIncludeDir (Arg, GetArg (&I, 2));
790                     break;
791
792                 case 'O':
793                     Optimize = 1;
794                     P = Arg + 2;
795                     while (*P) {
796                         switch (*P++) {
797                             case 'f':
798                                 sscanf (P, "%lx", (long*) &OptDisable);
799                                 break;
800                             case 'i':
801                                 FavourSize = 0;
802                                 CodeSizeFactor = 200;
803                                 break;
804                             case 'r':
805                                 IS_Set (&EnableRegVars, 1);
806                                 break;
807                             case 's':
808                                 IS_Set (&InlineStdFuncs, 1);
809                                 break;
810                         }
811                     }
812                     break;
813
814                 case 'T':
815                     OptAddSource (Arg, 0);
816                     break;
817
818                 case 'V':
819                     OptVersion (Arg, 0);
820                     break;
821
822                 case 'W':
823                     NoWarn = 1;
824                     break;
825
826                 default:
827                     UnknownOption (Arg);
828                     break;
829             }
830         } else {
831             if (InputFile) {
832                 fprintf (stderr, "additional file specs ignored\n");
833             } else {
834                 InputFile = Arg;
835             }
836         }
837
838         /* Next argument */
839         ++I;
840     }
841
842     /* Did we have a file spec on the command line? */
843     if (InputFile == 0) {
844         AbEnd ("No input files");
845     }
846
847     /* Create the output file name if it was not explicitly given */
848     if (OutputFile == 0) {
849         OutputFile = MakeFilename (InputFile, ".s");
850     }
851
852     /* If no CPU given, use the default CPU for the target */
853     if (CPU == CPU_UNKNOWN) {
854         if (Target != TGT_UNKNOWN) {
855             CPU = DefaultCPU[Target];
856         } else {
857             CPU = CPU_6502;
858         }
859     }
860
861     /* If no memory model was given, use the default */
862     if (MemoryModel == MMODEL_UNKNOWN) {
863         SetMemoryModel (MMODEL_NEAR);
864     }
865
866     /* Go! */
867     Compile (InputFile);
868
869     /* Create the output file if we didn't had any errors */
870     if (ErrorCount == 0 || Debug) {
871
872         /* Open the file */
873         FILE* F = fopen (OutputFile, "w");
874         if (F == 0) {
875             Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
876         }
877
878         /* Write the output to the file */
879         WriteOutput (F);
880
881         /* Close the file, check for errors */
882         if (fclose (F) != 0) {
883             remove (OutputFile);
884             Fatal ("Cannot write to output file (disk full?)");
885         }
886
887         /* Create dependencies if requested */
888         if (CreateDep) {
889             DoCreateDep (OutputFile);
890         }
891
892     }
893
894     /* Return an apropriate exit code */
895     return (ErrorCount > 0)? EXIT_FAILURE : EXIT_SUCCESS;
896 }
897
898
899