]> git.sur5r.net Git - cc65/blob - src/cc65/main.c
dc51736e57a03fc0457e9c1cf3ebf4b9817d3546
[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         AbEnd ("Argument for %s is invalid", Opt);
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         AbEnd ("Invalid argument for %s: `%s'", 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         AbEnd ("Argument for option %s is invalid", Opt);
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         AbEnd ("Invalid argument for %s: `%s'", 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%u.%u.%u\n"
671              "SVN version: %s\n",
672              VER_MAJOR, VER_MINOR, VER_PATCH, SVNVersion);
673     exit (EXIT_SUCCESS);
674 }
675
676
677
678 static void OptWritableStrings (const char* Opt attribute ((unused)),
679                                 const char* Arg attribute ((unused)))
680 /* Make string literals writable */
681 {
682     IS_Set (&WritableStrings, 1);
683 }
684
685
686
687 int main (int argc, char* argv[])
688 {
689     /* Program long options */
690     static const LongOpt OptTab[] = {
691         { "--add-source",       0,      OptAddSource            },
692         { "--bss-name",         1,      OptBssName              },
693         { "--check-stack",      0,      OptCheckStack           },
694         { "--code-name",        1,      OptCodeName             },
695         { "--codesize",         1,      OptCodeSize             },
696         { "--cpu",              1,      OptCPU                  },
697         { "--create-dep",       0,      OptCreateDep            },
698         { "--data-name",        1,      OptDataName             },
699         { "--debug",            0,      OptDebug                },
700         { "--debug-info",       0,      OptDebugInfo            },
701         { "--debug-opt",        1,      OptDebugOpt             },
702         { "--disable-opt",      1,      OptDisableOpt           },
703         { "--enable-opt",       1,      OptEnableOpt            },
704         { "--forget-inc-paths", 0,      OptForgetIncPaths       },
705         { "--help",             0,      OptHelp                 },
706         { "--include-dir",      1,      OptIncludeDir           },
707         { "--list-opt-steps",   0,      OptListOptSteps         },
708         { "--memory-model",     1,      OptMemoryModel          },
709         { "--register-space",   1,      OptRegisterSpace        },
710         { "--register-vars",    0,      OptRegisterVars         },
711         { "--rodata-name",      1,      OptRodataName           },
712         { "--signed-chars",     0,      OptSignedChars          },
713         { "--standard",         1,      OptStandard             },
714         { "--static-locals",    0,      OptStaticLocals         },
715         { "--target",           1,      OptTarget               },
716         { "--verbose",          0,      OptVerbose              },
717         { "--version",          0,      OptVersion              },
718         { "--writable-strings", 0,      OptWritableStrings      },
719     };
720
721     unsigned I;
722
723     /* Initialize the input file name */
724     const char* InputFile  = 0;
725
726     /* Initialize the cmdline module */
727     InitCmdLine (&argc, &argv, "cc65");
728
729     /* Initialize the default segment names */
730     InitSegNames ();
731
732     /* Initialize the include search paths */
733     InitIncludePaths ();
734
735     /* Parse the command line */
736     I = 1;
737     while (I < ArgCount) {
738
739         const char* P;
740
741         /* Get the argument */
742         const char* Arg = ArgVec[I];
743
744         /* Check for an option */
745         if (Arg [0] == '-') {
746
747             switch (Arg [1]) {
748
749                 case '-':
750                     LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
751                     break;
752
753                 case 'd':
754                     OptDebug (Arg, 0);
755                     break;
756
757                 case 'h':
758                 case '?':
759                     OptHelp (Arg, 0);
760                     break;
761
762                 case 'g':
763                     OptDebugInfo (Arg, 0);
764                     break;
765
766                 case 'j':
767                     OptSignedChars (Arg, 0);
768                     break;
769
770                 case 'o':
771                     SetOutputName (GetArg (&I, 2));
772                     break;
773
774                 case 'r':
775                     OptRegisterVars (Arg, 0);
776                     break;
777
778                 case 't':
779                     OptTarget (Arg, GetArg (&I, 2));
780                     break;
781
782                 case 'u':
783                     OptCreateDep (Arg, 0);
784                     break;
785
786                 case 'v':
787                     OptVerbose (Arg, 0);
788                     break;
789
790                 case 'C':
791                     P = Arg + 2;
792                     while (*P) {
793                         switch (*P++) {
794                             case 'l':
795                                 OptStaticLocals (Arg, 0);
796                                 break;
797                             default:
798                                 UnknownOption (Arg);
799                                 break;
800                         }
801                     }
802                     break;
803
804                 case 'D':
805                     DefineSym (GetArg (&I, 2));
806                     break;
807
808                 case 'E':
809                     PreprocessOnly = 1;
810                     break;
811
812                 case 'I':
813                     OptIncludeDir (Arg, GetArg (&I, 2));
814                     break;
815
816                 case 'O':
817                     IS_Set (&Optimize, 1);
818                     P = Arg + 2;
819                     while (*P) {
820                         switch (*P++) {
821                             case 'i':
822                                 IS_Set (&CodeSizeFactor, 200);
823                                 break;
824                             case 'r':
825                                 IS_Set (&EnableRegVars, 1);
826                                 break;
827                             case 's':
828                                 IS_Set (&InlineStdFuncs, 1);
829                                 break;
830                         }
831                     }
832                     break;
833
834                 case 'T':
835                     OptAddSource (Arg, 0);
836                     break;
837
838                 case 'V':
839                     OptVersion (Arg, 0);
840                     break;
841
842                 case 'W':
843                     IS_Set (&WarnDisable, 1);
844                     break;
845
846                 default:
847                     UnknownOption (Arg);
848                     break;
849             }
850         } else {
851             if (InputFile) {
852                 fprintf (stderr, "additional file specs ignored\n");
853             } else {
854                 InputFile = Arg;
855             }
856         }
857
858         /* Next argument */
859         ++I;
860     }
861
862     /* Did we have a file spec on the command line? */
863     if (InputFile == 0) {
864         AbEnd ("No input files");
865     }
866
867     /* Create the output file name if it was not explicitly given */
868     MakeDefaultOutputName (InputFile);
869
870     /* If no CPU given, use the default CPU for the target */
871     if (CPU == CPU_UNKNOWN) {
872         if (Target != TGT_UNKNOWN) {
873             CPU = DefaultCPU[Target];
874         } else {
875             CPU = CPU_6502;
876         }
877     }
878
879     /* If no memory model was given, use the default */
880     if (MemoryModel == MMODEL_UNKNOWN) {
881         SetMemoryModel (MMODEL_NEAR);
882     }
883
884     /* If no language standard was given, use the default one */
885     if (IS_Get (&Standard) == STD_UNKNOWN) {
886         IS_Set (&Standard, STD_DEFAULT);
887     }
888
889     /* Go! */
890     Compile (InputFile);
891
892     /* Create the output file if we didn't had any errors */
893     if (PreprocessOnly == 0 && (ErrorCount == 0 || Debug)) {
894
895         /* Open the file */
896         OpenOutputFile ();
897
898         /* Write the output to the file */
899         WriteAsmOutput ();
900         Print (stdout, 1, "Wrote output to `%s'\n", OutputFilename);
901
902         /* Close the file, check for errors */
903         CloseOutputFile ();
904
905         /* Create dependencies if requested */
906         if (CreateDep) {
907             DoCreateDep (OutputFilename);
908             Print (stdout, 1, "Creating dependeny file\n");
909         }
910
911     }
912
913     /* Return an apropriate exit code */
914     return (ErrorCount > 0)? EXIT_FAILURE : EXIT_SUCCESS;
915 }
916
917
918