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