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