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