]> git.sur5r.net Git - cc65/blob - src/cc65/main.c
Added the lynx target
[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 "standard.h"
67 #include "segments.h"
68
69
70
71 /*****************************************************************************/
72 /*                                   Code                                    */
73 /*****************************************************************************/
74
75
76
77 static void Usage (void)
78 /* Print usage information to stderr */
79 {
80     fprintf (stderr,
81              "Usage: %s [options] file\n"
82              "Short options:\n"
83              "  -Cl\t\t\tMake local variables static\n"
84              "  -Dsym[=defn]\t\tDefine a symbol\n"
85              "  -E\t\t\tStop after the preprocessing stage\n"
86              "  -I dir\t\tSet an include directory search path\n"
87              "  -O\t\t\tOptimize code\n"
88              "  -Oi\t\t\tOptimize code, inline more code\n"
89              "  -Or\t\t\tEnable register variables\n"
90              "  -Os\t\t\tInline some known functions\n"
91              "  -T\t\t\tInclude source as comment\n"
92              "  -V\t\t\tPrint the compiler version number\n"
93              "  -W\t\t\tSuppress warnings\n"
94              "  -d\t\t\tDebug mode\n"
95              "  -g\t\t\tAdd debug info to object file\n"
96              "  -h\t\t\tHelp (this text)\n"
97              "  -j\t\t\tDefault characters are signed\n"
98              "  -mm model\t\tSet the memory model\n"
99              "  -o name\t\tName the output file\n"
100              "  -r\t\t\tEnable register variables\n"
101              "  -t sys\t\tSet the target system\n"
102              "  -v\t\t\tIncrease verbosity\n"
103              "\n"
104              "Long options:\n"
105              "  --add-source\t\tInclude source as comment\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              "  --standard std\tLanguage standard (c89, c99, cc65)\n"
128              "  --static-locals\tMake local variables static\n"
129              "  --target sys\t\tSet the target system\n"
130              "  --verbose\t\tIncrease verbosity\n"
131              "  --version\t\tPrint the compiler version number\n"
132              "  --writable-strings\tMake string literals writable\n",
133              ProgName);
134 }
135
136
137
138 static void cbmsys (const char* sys)
139 /* Define a CBM system */
140 {
141     DefineNumericMacro ("__CBM__", 1);
142     DefineNumericMacro (sys, 1);
143 }
144
145
146
147 static void SetSys (const char* Sys)
148 /* Define a target system */
149 {
150     switch (Target = FindTarget (Sys)) {
151
152         case TGT_NONE:
153             break;
154
155         case TGT_MODULE:
156             AbEnd ("Cannot use `module' as a target for the compiler");
157             break;
158
159         case TGT_ATARI:
160             DefineNumericMacro ("__ATARI__", 1);
161             break;
162
163         case TGT_C16:
164             cbmsys ("__C16__");
165             break;
166
167         case TGT_C64:
168             cbmsys ("__C64__");
169             break;
170
171         case TGT_VIC20:
172             cbmsys ("__VIC20__");
173             break;
174
175         case TGT_C128:
176             cbmsys ("__C128__");
177             break;
178
179         case TGT_ACE:
180             cbmsys ("__ACE__");
181             break;
182
183         case TGT_PLUS4:
184             cbmsys ("__PLUS4__");
185             break;
186
187         case TGT_CBM510:
188             cbmsys ("__CBM510__");
189             break;
190
191         case TGT_CBM610:
192             cbmsys ("__CBM610__");
193             break;
194
195         case TGT_PET:
196             cbmsys ("__PET__");
197             break;
198
199         case TGT_BBC:
200             DefineNumericMacro ("__BBC__", 1);
201             break;
202
203         case TGT_APPLE2:
204             DefineNumericMacro ("__APPLE2__", 1);
205             break;
206
207         case TGT_APPLE2ENH:
208             DefineNumericMacro ("__APPLE2ENH__", 1);
209             break;
210
211         case TGT_GEOS:
212             /* Do not handle as a CBM system */
213             DefineNumericMacro ("__GEOS__", 1);
214             break;
215
216         case TGT_LUNIX:
217             DefineNumericMacro ("__LUNIX__", 1);
218             break;
219
220         case TGT_ATMOS:
221             DefineNumericMacro ("__ATMOS__", 1);
222             break;
223
224         case TGT_NES:
225             DefineNumericMacro ("__NES__", 1);
226             break;
227
228         case TGT_SUPERVISION:
229             DefineNumericMacro ("__SUPERVISION__", 1);
230             break;
231
232         case TGT_LYNX:
233             DefineNumericMacro ("__LYNX__", 1);
234             break;
235
236         default:
237             AbEnd ("Unknown target system type %d", Target);
238     }
239
240     /* Initialize the translation tables for the target system */
241     TgtTranslateInit ();
242 }
243
244
245
246 static void DoCreateDep (const char* OutputName)
247 /* Create the dependency file */
248 {
249     /* Make the dependency file name from the output file name */
250     char* DepName = MakeFilename (OutputName, ".u");
251
252     /* Open the file */
253     FILE* F = fopen (DepName, "w");
254     if (F == 0) {
255         Fatal ("Cannot open dependency file `%s': %s", DepName, strerror (errno));
256     }
257
258     /* Write the dependencies to the file */
259     WriteDependencies (F, OutputName);
260
261     /* Close the file, check for errors */
262     if (fclose (F) != 0) {
263         remove (DepName);
264         Fatal ("Cannot write to dependeny file (disk full?)");
265     }
266
267     /* Free the name */
268     xfree (DepName);
269 }
270
271
272
273 static void DefineSym (const char* Def)
274 /* Define a symbol on the command line */
275 {
276     const char* P = Def;
277
278     /* The symbol must start with a character or underline */
279     if (Def [0] != '_' && !IsAlpha (Def [0])) {
280         InvDef (Def);
281     }
282
283     /* Check the symbol name */
284     while (IsAlNum (*P) || *P == '_') {
285         ++P;
286     }
287
288     /* Do we have a value given? */
289     if (*P != '=') {
290         if (*P != '\0') {
291             InvDef (Def);
292         }
293         /* No value given. Define the macro with the value 1 */
294         DefineNumericMacro (Def, 1);
295     } else {
296         /* We have a value, P points to the '=' character. Since the argument
297          * is const, create a copy and replace the '=' in the copy by a zero
298          * terminator.
299          */
300         char* Q;
301         unsigned Len = strlen (Def)+1;
302         char* S = (char*) xmalloc (Len);
303         memcpy (S, Def, Len);
304         Q = S + (P - Def);
305         *Q++ = '\0';
306
307         /* Define this as a macro */
308         DefineTextMacro (S, Q);
309
310         /* Release the allocated memory */
311         xfree (S);
312     }
313 }
314
315
316
317 static void CheckSegName (const char* Seg)
318 /* Abort if the given name is not a valid segment name */
319 {
320     /* Print an error and abort if the name is not ok */
321     if (!ValidSegName (Seg)) {
322         AbEnd ("Segment name `%s' is invalid", Seg);
323     }
324 }
325
326
327
328 static void OptAddSource (const char* Opt attribute ((unused)),
329                           const char* Arg attribute ((unused)))
330 /* Add source lines as comments in generated assembler file */
331 {
332     AddSource = 1;
333 }
334
335
336
337 static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
338 /* Handle the --bss-name option */
339 {
340     /* Check for a valid name */
341     CheckSegName (Arg);
342
343     /* Set the name */
344     SetSegName (SEG_BSS, Arg);
345 }
346
347
348
349 static void OptCheckStack (const char* Opt attribute ((unused)),
350                            const char* Arg attribute ((unused)))
351 /* Handle the --check-stack option */
352 {
353     IS_Set (&CheckStack, 1);
354 }
355
356
357
358 static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg)
359 /* Handle the --code-name option */
360 {
361     /* Check for a valid name */
362     CheckSegName (Arg);
363
364     /* Set the name */
365     SetSegName (SEG_CODE, Arg);
366 }
367
368
369
370 static void OptCodeSize (const char* Opt, const char* Arg)
371 /* Handle the --codesize option */
372 {
373     unsigned Factor;
374     char     BoundsCheck;
375
376     /* Numeric argument expected */
377     if (sscanf (Arg, "%u%c", &Factor, &BoundsCheck) != 1 ||
378         Factor < 10 || Factor > 1000) {
379         AbEnd ("Argument for %s is invalid", Opt);
380     }
381     IS_Set (&CodeSizeFactor, Factor);
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_6502X && 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 OptStandard (const char* Opt, const char* Arg)
627 /* Handle the --standard option */
628 {
629     /* Find the standard from the given name */
630     standard_t Std = FindStandard (Arg);
631     if (Std == STD_UNKNOWN) {
632         AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
633     } else if (IS_Get (&Standard) != STD_UNKNOWN) {
634         AbEnd ("Option %s given more than once", Opt);
635     } else {
636         IS_Set (&Standard, Std);
637     }
638 }
639
640
641
642 static void OptStaticLocals (const char* Opt attribute ((unused)),
643                              const char* Arg attribute ((unused)))
644 /* Place local variables in static storage */
645 {
646     IS_Set (&StaticLocals, 1);
647 }
648
649
650
651 static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
652 /* Set the target system */
653 {
654     SetSys (Arg);
655 }
656
657
658
659 static void OptVerbose (const char* Opt attribute ((unused)),
660                         const char* Arg attribute ((unused)))
661 /* Increase verbosity */
662 {
663     ++Verbosity;
664 }
665
666
667
668 static void OptVersion (const char* Opt attribute ((unused)),
669                         const char* Arg attribute ((unused)))
670 /* Print the assembler version */
671 {
672     fprintf (stderr,
673              "cc65 V%u.%u.%u\n",
674              VER_MAJOR, VER_MINOR, VER_PATCH);
675 }
676
677
678
679 static void OptWritableStrings (const char* Opt attribute ((unused)),
680                                 const char* Arg attribute ((unused)))
681 /* Make string literals writable */
682 {
683     IS_Set (&WritableStrings, 1);
684 }
685
686
687
688 int main (int argc, char* argv[])
689 {
690     /* Program long options */
691     static const LongOpt OptTab[] = {
692         { "--add-source",       0,      OptAddSource            },
693         { "--bss-name",         1,      OptBssName              },
694         { "--check-stack",      0,      OptCheckStack           },
695         { "--code-name",        1,      OptCodeName             },
696         { "--codesize",         1,      OptCodeSize             },
697         { "--cpu",              1,      OptCPU                  },
698         { "--create-dep",       0,      OptCreateDep            },
699         { "--data-name",        1,      OptDataName             },
700         { "--debug",            0,      OptDebug                },
701         { "--debug-info",       0,      OptDebugInfo            },
702         { "--debug-opt",        1,      OptDebugOpt             },
703         { "--disable-opt",      1,      OptDisableOpt           },
704         { "--enable-opt",       1,      OptEnableOpt            },
705         { "--forget-inc-paths", 0,      OptForgetIncPaths       },
706         { "--help",             0,      OptHelp                 },
707         { "--include-dir",      1,      OptIncludeDir           },
708         { "--list-opt-steps",   0,      OptListOptSteps         },
709         { "--memory-model",     1,      OptMemoryModel          },
710         { "--register-space",   1,      OptRegisterSpace        },
711         { "--register-vars",    0,      OptRegisterVars         },
712         { "--rodata-name",      1,      OptRodataName           },
713         { "--signed-chars",     0,      OptSignedChars          },
714         { "--standard",         1,      OptStandard             },
715         { "--static-locals",    0,      OptStaticLocals         },
716         { "--target",           1,      OptTarget               },
717         { "--verbose",          0,      OptVerbose              },
718         { "--version",          0,      OptVersion              },
719         { "--writable-strings", 0,      OptWritableStrings      },
720     };
721
722     unsigned I;
723
724     /* Initialize the output file name */
725     const char* OutputFile = 0;
726     const char* InputFile  = 0;
727
728     /* Initialize the cmdline module */
729     InitCmdLine (&argc, &argv, "cc65");
730
731     /* Initialize the default segment names */
732     InitSegNames ();
733
734     /* Initialize the include search paths */
735     InitIncludePaths ();
736
737     /* Parse the command line */
738     I = 1;
739     while (I < ArgCount) {
740
741         const char* P;
742
743         /* Get the argument */
744         const char* Arg = ArgVec[I];
745
746         /* Check for an option */
747         if (Arg [0] == '-') {
748
749             switch (Arg [1]) {
750
751                 case '-':
752                     LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
753                     break;
754
755                 case 'd':
756                     OptDebug (Arg, 0);
757                     break;
758
759                 case 'h':
760                 case '?':
761                     OptHelp (Arg, 0);
762                     break;
763
764                 case 'g':
765                     OptDebugInfo (Arg, 0);
766                     break;
767
768                 case 'j':
769                     OptSignedChars (Arg, 0);
770                     break;
771
772                 case 'o':
773                     OutputFile = GetArg (&I, 2);
774                     break;
775
776                 case 'r':
777                     OptRegisterVars (Arg, 0);
778                     break;
779
780                 case 't':
781                     OptTarget (Arg, GetArg (&I, 2));
782                     break;
783
784                 case 'u':
785                     OptCreateDep (Arg, 0);
786                     break;
787
788                 case 'v':
789                     OptVerbose (Arg, 0);
790                     break;
791
792                 case 'C':
793                     P = Arg + 2;
794                     while (*P) {
795                         switch (*P++) {
796                             case 'l':
797                                 OptStaticLocals (Arg, 0);
798                                 break;
799                             default:
800                                 UnknownOption (Arg);
801                                 break;
802                         }
803                     }
804                     break;
805
806                 case 'D':
807                     DefineSym (GetArg (&I, 2));
808                     break;
809
810                 case 'E':
811                     PreprocessOnly = 1;
812                     break;
813
814                 case 'I':
815                     OptIncludeDir (Arg, GetArg (&I, 2));
816                     break;
817
818                 case 'O':
819                     IS_Set (&Optimize, 1);
820                     P = Arg + 2;
821                     while (*P) {
822                         switch (*P++) {
823                             case 'i':
824                                 IS_Set (&CodeSizeFactor, 200);
825                                 break;
826                             case 'r':
827                                 IS_Set (&EnableRegVars, 1);
828                                 break;
829                             case 's':
830                                 IS_Set (&InlineStdFuncs, 1);
831                                 break;
832                         }
833                     }
834                     break;
835
836                 case 'T':
837                     OptAddSource (Arg, 0);
838                     break;
839
840                 case 'V':
841                     OptVersion (Arg, 0);
842                     break;
843
844                 case 'W':
845                     IS_Set (&WarnDisable, 1);
846                     break;
847
848                 default:
849                     UnknownOption (Arg);
850                     break;
851             }
852         } else {
853             if (InputFile) {
854                 fprintf (stderr, "additional file specs ignored\n");
855             } else {
856                 InputFile = Arg;
857             }
858         }
859
860         /* Next argument */
861         ++I;
862     }
863
864     /* Did we have a file spec on the command line? */
865     if (InputFile == 0) {
866         AbEnd ("No input files");
867     }
868
869     /* Create the output file name if it was not explicitly given */
870     if (OutputFile == 0) {
871         OutputFile = MakeFilename (InputFile, ".s");
872     }
873
874     /* If no CPU given, use the default CPU for the target */
875     if (CPU == CPU_UNKNOWN) {
876         if (Target != TGT_UNKNOWN) {
877             CPU = DefaultCPU[Target];
878         } else {
879             CPU = CPU_6502;
880         }
881     }
882
883     /* If no memory model was given, use the default */
884     if (MemoryModel == MMODEL_UNKNOWN) {
885         SetMemoryModel (MMODEL_NEAR);
886     }
887
888     /* If no language standard was given, use the default one */
889     if (IS_Get (&Standard) == STD_UNKNOWN) {
890         IS_Set (&Standard, STD_DEFAULT);
891     }
892
893     /* Go! */
894     Compile (InputFile);
895
896     /* Create the output file if we didn't had any errors */
897     if (ErrorCount == 0 || Debug) {
898
899         /* Open the file */
900         FILE* F = fopen (OutputFile, "w");
901         if (F == 0) {
902             Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
903         }
904         Print (stdout, 1, "Opened output file `%s'\n", OutputFile);
905
906         /* Write the output to the file */
907         WriteOutput (F);
908         Print (stdout, 1, "Wrote output to `%s'\n", OutputFile);
909
910         /* Close the file, check for errors */
911         if (fclose (F) != 0) {
912             remove (OutputFile);
913             Fatal ("Cannot write to output file (disk full?)");
914         }
915         Print (stdout, 1, "Closed output file `%s'\n", OutputFile);
916
917         /* Create dependencies if requested */
918         if (CreateDep) {
919             DoCreateDep (OutputFile);
920             Print (stdout, 1, "Creating dependeny file\n");
921         }
922
923     }
924
925     /* Return an apropriate exit code */
926     return (ErrorCount > 0)? EXIT_FAILURE : EXIT_SUCCESS;
927 }
928
929
930