/* */
/* */
/* */
-/* (C) 2000-2001 Ullrich von Bassewitz */
+/* (C) 2000-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
#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"
#include "asmcode.h"
#include "compile.h"
#include "codeopt.h"
-#include "cpu.h"
#include "error.h"
#include "global.h"
#include "incpath.h"
" -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"
" --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"
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;
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 */
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 {
+ CPU = FindCPU (Arg);
+ if (CPU != CPU_6502 && CPU != CPU_65C02) {
AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
}
}
static void OptDebug (const char* Opt attribute ((unused)),
- const char* Arg attribute ((unused)))
+ const char* Arg attribute ((unused)))
/* Compiler debug mode */
{
- Debug = 1;
+ ++Debug;
}
static void OptDebugInfo (const char* Opt attribute ((unused)),
- const char* Arg attribute ((unused)))
+ const char* Arg attribute ((unused)))
/* Add debug info to the object file */
{
DebugInfo = 1;
+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 */
{
{ "--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;
/* Parse the command line */
I = 1;
- while (I < (int)ArgCount) {
+ while (I < ArgCount) {
const char* P;
OutputFile = GetArg (&I, 2);
break;
+ case 'r':
+ OptRegisterVars (Arg, 0);
+ break;
+
case 't':
OptTarget (Arg, GetArg (&I, 2));
break;
OptStaticLocals (Arg, 0);
break;
default:
- UnknownOption (Arg);
- break;
+ UnknownOption (Arg);
+ break;
}
}
break;
break;
case 's':
InlineStdFuncs = 1;
- break;
+ break;
}
}
break;
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));
}