X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fmain.c;h=3ed7127e3120c9a31d4f8a0b1e6b7e126256e803;hb=aef8789873bd008d42aa50330ca98488fad91b31;hp=e4d0d1d8b6b4f564e3481e2c4e23e79c1bce48ec;hpb=4c87acbcc25ebb7765714e9e296285f14cca39a7;p=cc65 diff --git a/src/cc65/main.c b/src/cc65/main.c index e4d0d1d8b..3ed7127e3 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -6,9 +6,9 @@ /* */ /* */ /* */ -/* (C) 2000-2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ +/* (C) 2000-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ /* */ @@ -42,8 +42,11 @@ #include "abend.h" #include "chartype.h" #include "cmdline.h" +#include "cpu.h" +#include "debugflag.h" #include "fname.h" #include "print.h" +#include "segnames.h" #include "target.h" #include "tgttrans.h" #include "version.h" @@ -53,7 +56,6 @@ #include "asmcode.h" #include "compile.h" #include "codeopt.h" -#include "cpu.h" #include "error.h" #include "global.h" #include "incpath.h" @@ -91,6 +93,7 @@ static void Usage (void) " -h\t\t\tHelp (this text)\n" " -j\t\t\tDefault characters are signed\n" " -o name\t\tName the output file\n" + " -r\t\t\tEnable register variables\n" " -t sys\t\tSet the target system\n" " -v\t\t\tIncrease verbosity\n" "\n" @@ -101,7 +104,7 @@ static void Usage (void) " --check-stack\t\tGenerate stack overflow checks\n" " --code-name seg\tSet the name of the CODE segment\n" " --codesize x\t\tAccept larger code by factor x\n" - " --cpu type\t\tSet cpu type\n" + " --cpu type\t\tSet cpu type (6502, 65c02)\n" " --create-dep\t\tCreate a make dependency file\n" " --data-name seg\tSet the name of the DATA segment\n" " --debug\t\tDebug mode\n" @@ -109,9 +112,12 @@ static void Usage (void) " --debug-opt name\tDebug optimization steps\n" " --disable-opt name\tDisable an optimization step\n" " --enable-opt name\tEnable an optimization step\n" + " --forget-inc-paths\tForget include search paths\n" " --help\t\tHelp (this text)\n" " --include-dir dir\tSet an include directory search path\n" " --list-opt-steps\tList all optimizer steps and exit\n" + " --register-space b\tSet space available for register variables\n" + " --register-vars\tEnable register variables\n" " --rodata-name seg\tSet the name of the RODATA segment\n" " --signed-chars\tDefault characters are signed\n" " --static-locals\tMake local variables static\n" @@ -140,14 +146,26 @@ static void SetSys (const char* Sys) case TGT_NONE: break; + case TGT_MODULE: + AbEnd ("Cannot use `module' as a target for the compiler"); + break; + case TGT_ATARI: DefineNumericMacro ("__ATARI__", 1); break; + case TGT_C16: + cbmsys ("__C16__"); + break; + case TGT_C64: cbmsys ("__C64__"); break; + case TGT_VIC20: + cbmsys ("__VIC20__"); + break; + case TGT_C128: cbmsys ("__C128__"); break; @@ -185,8 +203,20 @@ static void SetSys (const char* Sys) DefineNumericMacro ("__GEOS__", 1); break; + case TGT_LUNIX: + DefineNumericMacro ("__LUNIX__", 1); + break; + + case TGT_ATMOS: + DefineNumericMacro ("__ATMOS__", 1); + break; + + case TGT_NES: + DefineNumericMacro ("__NES__", 1); + break; + default: - AbEnd ("Unknown target system type"); + AbEnd ("Unknown target system type %d", Target); } /* Initialize the translation tables for the target system */ @@ -277,7 +307,8 @@ static void CheckSegName (const char* Seg) -static void OptAddSource (const char* Opt, const char* Arg) +static void OptAddSource (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Add source lines as comments in generated assembler file */ { AddSource = 1; @@ -285,7 +316,8 @@ static void OptAddSource (const char* Opt, const char* Arg) -static void OptAnsi (const char* Opt, const char* Arg) +static void OptAnsi (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Compile in strict ANSI mode */ { ANSI = 1; @@ -293,7 +325,7 @@ static void OptAnsi (const char* Opt, const char* Arg) -static void OptBssName (const char* Opt, const char* Arg) +static void OptBssName (const char* Opt attribute ((unused)), const char* Arg) /* Handle the --bss-name option */ { /* Check for a valid name */ @@ -305,7 +337,8 @@ static void OptBssName (const char* Opt, const char* Arg) -static void OptCheckStack (const char* Opt, const char* Arg) +static void OptCheckStack (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Handle the --check-stack option */ { CheckStack = 1; @@ -313,7 +346,7 @@ static void OptCheckStack (const char* Opt, const char* Arg) -static void OptCodeName (const char* Opt, const char* Arg) +static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg) /* Handle the --code-name option */ { /* Check for a valid name */ @@ -338,7 +371,8 @@ static void OptCodeSize (const char* Opt, const char* Arg) -static void OptCreateDep (const char* Opt, const char* Arg) +static void OptCreateDep (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Handle the --create-dep option */ { CreateDep = 1; @@ -349,18 +383,16 @@ static void OptCreateDep (const char* Opt, const char* Arg) static void OptCPU (const char* Opt, const char* Arg) /* Handle the --cpu option */ { - if (strcmp (Arg, "6502") == 0) { - CPU = CPU_6502; - } else if (strcmp (Arg, "65C02") == 0) { - CPU = CPU_65C02; - } else { - AbEnd ("Invalid CPU: `%s'", Arg); + /* Find the CPU from the given name */ + CPU = FindCPU (Arg); + if (CPU != CPU_6502 && CPU != CPU_65C02) { + AbEnd ("Invalid argument for %s: `%s'", Opt, Arg); } } -static void OptDataName (const char* Opt, const char* Arg) +static void OptDataName (const char* Opt attribute ((unused)), const char* Arg) /* Handle the --data-name option */ { /* Check for a valid name */ @@ -372,15 +404,17 @@ static void OptDataName (const char* Opt, const char* Arg) -static void OptDebug (const char* Opt, const char* Arg) +static void OptDebug (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Compiler debug mode */ { - Debug = 1; + ++Debug; } -static void OptDebugInfo (const char* Opt, const char* Arg) +static void OptDebugInfo (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Add debug info to the object file */ { DebugInfo = 1; @@ -388,7 +422,7 @@ static void OptDebugInfo (const char* Opt, const char* Arg) -static void OptDebugOpt (const char* Opt, const char* Arg) +static void OptDebugOpt (const char* Opt attribute ((unused)), const char* Arg) /* Debug optimization steps */ { char Buf [128]; @@ -455,7 +489,7 @@ static void OptDebugOpt (const char* Opt, const char* Arg) -static void OptDisableOpt (const char* Opt, const char* Arg) +static void OptDisableOpt (const char* Opt attribute ((unused)), const char* Arg) /* Disable an optimization step */ { DisableOpt (Arg); @@ -463,7 +497,7 @@ static void OptDisableOpt (const char* Opt, const char* Arg) -static void OptEnableOpt (const char* Opt, const char* Arg) +static void OptEnableOpt (const char* Opt attribute ((unused)), const char* Arg) /* Enable an optimization step */ { EnableOpt (Arg); @@ -471,7 +505,17 @@ static void OptEnableOpt (const char* Opt, const char* Arg) -static void OptHelp (const char* Opt, const char* Arg) +static void OptForgetIncPaths (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Forget all currently defined include paths */ +{ + ForgetAllIncludePaths (); +} + + + +static void OptHelp (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Print usage information and exit */ { Usage (); @@ -480,7 +524,7 @@ static void OptHelp (const char* Opt, const char* Arg) -static void OptIncludeDir (const char* Opt, const char* Arg) +static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg) /* Add an include search path */ { AddIncludePath (Arg, INC_SYS | INC_USER); @@ -488,7 +532,8 @@ static void OptIncludeDir (const char* Opt, const char* Arg) -static void OptListOptSteps (const char* Opt, const char* Arg) +static void OptListOptSteps (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* List all optimizer steps */ { /* List the optimizer steps */ @@ -500,7 +545,27 @@ static void OptListOptSteps (const char* Opt, const char* Arg) -static void OptRodataName (const char* Opt, const char* Arg) +static void OptRegisterSpace (const char* Opt, const char* Arg) +/* Handle the --register-space option */ +{ + /* Numeric argument expected */ + if (sscanf (Arg, "%u", &RegisterSpace) != 1 || RegisterSpace > 256) { + AbEnd ("Argument for option %s is invalid", Opt); + } +} + + + +static void OptRegisterVars (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Handle the --register-vars option */ +{ + EnableRegVars = 1; +} + + + +static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg) /* Handle the --rodata-name option */ { /* Check for a valid name */ @@ -512,7 +577,8 @@ static void OptRodataName (const char* Opt, const char* Arg) -static void OptSignedChars (const char* Opt, const char* Arg) +static void OptSignedChars (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Make default characters signed */ { SignedChars = 1; @@ -520,7 +586,8 @@ static void OptSignedChars (const char* Opt, const char* Arg) -static void OptStaticLocals (const char* Opt, const char* Arg) +static void OptStaticLocals (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Place local variables in static storage */ { StaticLocals = 1; @@ -528,7 +595,7 @@ static void OptStaticLocals (const char* Opt, const char* Arg) -static void OptTarget (const char* Opt, const char* Arg) +static void OptTarget (const char* Opt attribute ((unused)), const char* Arg) /* Set the target system */ { SetSys (Arg); @@ -536,7 +603,8 @@ static void OptTarget (const char* Opt, const char* Arg) -static void OptVerbose (const char* Opt, const char* Arg) +static void OptVerbose (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Increase verbosity */ { ++Verbosity; @@ -544,7 +612,8 @@ static void OptVerbose (const char* Opt, const char* Arg) -static void OptVersion (const char* Opt, const char* Arg) +static void OptVersion (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Print the assembler version */ { fprintf (stderr, @@ -571,19 +640,22 @@ int main (int argc, char* argv[]) { "--debug-info", 0, OptDebugInfo }, { "--debug-opt", 1, OptDebugOpt }, { "--disable-opt", 1, OptDisableOpt }, - { "--enable-opt", 1, OptEnableOpt, }, + { "--enable-opt", 1, OptEnableOpt }, + { "--forget-inc-paths", 0, OptForgetIncPaths }, { "--help", 0, OptHelp }, { "--include-dir", 1, OptIncludeDir }, { "--list-opt-steps", 0, OptListOptSteps }, + { "--register-space", 1, OptRegisterSpace }, + { "--register-vars", 0, OptRegisterVars }, { "--rodata-name", 1, OptRodataName }, { "--signed-chars", 0, OptSignedChars }, { "--static-locals", 0, OptStaticLocals }, - { "--target", 1, OptTarget }, + { "--target", 1, OptTarget }, { "--verbose", 0, OptVerbose }, { "--version", 0, OptVersion }, }; - int I; + unsigned I; /* Initialize the output file name */ const char* OutputFile = 0; @@ -595,9 +667,12 @@ int main (int argc, char* argv[]) /* Initialize the default segment names */ InitSegNames (); + /* Initialize the include search paths */ + InitIncludePaths (); + /* Parse the command line */ I = 1; - while (I < (int)ArgCount) { + while (I < ArgCount) { const char* P; @@ -634,6 +709,10 @@ int main (int argc, char* argv[]) OutputFile = GetArg (&I, 2); break; + case 'r': + OptRegisterVars (Arg, 0); + break; + case 't': OptTarget (Arg, GetArg (&I, 2)); break; @@ -658,8 +737,8 @@ int main (int argc, char* argv[]) OptStaticLocals (Arg, 0); break; default: - UnknownOption (Arg); - break; + UnknownOption (Arg); + break; } } break; @@ -689,7 +768,7 @@ int main (int argc, char* argv[]) break; case 's': InlineStdFuncs = 1; - break; + break; } } break; @@ -732,23 +811,23 @@ int main (int argc, char* argv[]) OutputFile = MakeFilename (InputFile, ".s"); } + /* If no CPU given, use the default CPU for the target */ + if (CPU == CPU_UNKNOWN) { + if (Target != TGT_UNKNOWN) { + CPU = DefaultCPU[Target]; + } else { + CPU = CPU_6502; + } + } + /* Go! */ Compile (InputFile); /* Create the output file if we didn't had any errors */ if (ErrorCount == 0 || Debug) { - FILE* F; - -#if 0 - /* Optimize the output if requested */ - if (Optimize) { - OptDoOpt (); - } -#endif - /* Open the file */ - F = fopen (OutputFile, "w"); + FILE* F = fopen (OutputFile, "w"); if (F == 0) { Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno)); }