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