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