#include <errno.h>
#include "../common/cmdline.h"
+#include "../common/fname.h"
#include "../common/version.h"
+#include "../common/xmalloc.h"
#include "asmcode.h"
#include "compile.h"
#include "error.h"
#include "global.h"
#include "incpath.h"
-#include "io.h"
+#include "input.h"
#include "macrotab.h"
-#include "mem.h"
#include "optimize.h"
#include "scanner.h"
static void Usage (void)
{
fprintf (stderr,
- "Usage: cc65 [options] file\n"
+ "Usage: %s [options] file\n"
"Short options:\n"
" -d\t\t\tDebug mode\n"
" -g\t\t\tAdd debug info to object file\n"
- " -h\t\t\tPrint this help\n"
+ " -h\t\t\tHelp (this text)\n"
" -j\t\t\tDefault characters are signed\n"
" -o name\t\tName the output file\n"
" -t sys\t\tSet the target system\n"
" -A\t\t\tStrict ANSI mode\n"
" -Cl\t\t\tMake local variables static\n"
" -Dsym[=defn]\t\tDefine a symbol\n"
- " -I path\t\tSet an include directory search path\n"
+ " -I dir\t\tSet an include directory search path\n"
" -O\t\t\tOptimize code\n"
" -Oi\t\t\tOptimize code, inline more code\n"
" -Or\t\t\tEnable register variables\n"
"Long options:\n"
" --ansi\t\tStrict ANSI mode\n"
" --cpu type\t\tSet cpu type\n"
+ " --debug\t\tDebug mode\n"
" --debug-info\t\tAdd debug info to object file\n"
" --help\t\tHelp (this text)\n"
" --include-dir dir\tSet an include directory search path\n"
" --signed-chars\tDefault characters are signed\n"
+ " --static-locals\tMake local variables static\n"
" --target sys\t\tSet the target system\n"
" --verbose\t\tIncrease verbosity\n"
- " --version\t\tPrint the compiler version number\n");
+ " --version\t\tPrint the compiler version number\n",
+ ProgName);
}
+static void OptAddSource (const char* Opt, const char* Arg)
+/* Add source lines as comments in generated assembler file */
+{
+ AddSource = 1;
+}
+
+
+
static void OptAnsi (const char* Opt, const char* Arg)
/* Compile in strict ANSI mode */
{
+static void OptDebug (const char* Opt, const char* Arg)
+/* Compiler debug mode */
+{
+ Debug = 1;
+}
+
+
+
static void OptDebugInfo (const char* Opt, const char* Arg)
/* Add debug info to the object file */
{
+static void OptStaticLocals (const char* Opt, const char* Arg)
+/* Place local variables in static storage */
+{
+ StaticLocals = 1;
+}
+
+
+
static void OptTarget (const char* Opt, const char* Arg)
/* Set the target system */
{
{
/* Program long options */
static const LongOpt OptTab[] = {
+ { "--add-source", 0, OptAddSource },
{ "--ansi", 0, OptAnsi },
{ "--cpu", 1, OptCPU },
+ { "--debug", 0, OptDebug },
{ "--debug-info", 0, OptDebugInfo },
{ "--help", 0, OptHelp },
{ "--include-dir", 1, OptIncludeDir },
{ "--signed-chars", 0, OptSignedChars },
+ { "--static-locals", 0, OptStaticLocals },
{ "--target", 1, OptTarget },
{ "--verbose", 0, OptVerbose },
{ "--version", 0, OptVersion },
};
int I;
- char out_name [256];
/* Initialize the output file name */
- out_name [0] = '\0';
-
- fin = NULL;
+ const char* OutputFile = 0;
+ const char* InputFile = 0;
/* Initialize the cmdline module */
- InitCmdLine (argc, argv);
+ InitCmdLine (argc, argv, "cc65");
/* Parse the command line */
I = 1;
case '-':
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
- break;
+ break;
- case 'd': /* debug mode */
- Debug = 1;
+ case 'd':
+ OptDebug (Arg, 0);
break;
case 'h':
case '?':
- OptHelp (Arg, 0);
+ OptHelp (Arg, 0);
break;
case 'g':
case 'j':
OptSignedChars (Arg, 0);
- break;
+ break;
case 'o':
- strcpy (out_name, GetArg (&I, 2));
+ OutputFile = GetArg (&I, 2);
break;
case 't':
while (*P) {
switch (*P++) {
case 'l':
- LocalsAreStatic = 1;
- break;
+ OptStaticLocals (Arg, 0);
+ break;
+ default:
+ UnknownOption (Arg);
+ break;
}
}
break;
DefineSym (GetArg (&I, 2));
break;
- case 'I':
+ case 'I':
OptIncludeDir (Arg, GetArg (&I, 2));
break;
case 'f':
sscanf (P, "%lx", (long*) &OptDisable);
break;
- case 'i':
- FavourSize = 0;
- break;
- case 'r':
- EnableRegVars = 1;
- break;
- case 's':
- InlineStdFuncs = 1;
- break;
- }
- }
- break;
-
- case 'T':
- IncSource = 1;
- break;
-
- case 'V':
- OptVersion (Arg, 0);
- break;
-
- case 'W':
- NoWarn = 1;
- break;
-
- default:
+ case 'i':
+ FavourSize = 0;
+ break;
+ case 'r':
+ EnableRegVars = 1;
+ break;
+ case 's':
+ InlineStdFuncs = 1;
+ break;
+ }
+ }
+ break;
+
+ case 'T':
+ OptAddSource (Arg, 0);
+ break;
+
+ case 'V':
+ OptVersion (Arg, 0);
+ break;
+
+ case 'W':
+ NoWarn = 1;
+ break;
+
+ default:
UnknownOption (Arg);
- break;
- }
- } else {
- if (fin) {
- fprintf (stderr, "additional file specs ignored\n");
- } else {
- fin = xstrdup (Arg);
- inp = fopen (fin, "r");
- if (inp == 0) {
- Fatal (FAT_CANNOT_OPEN_INPUT, strerror (errno));
- }
+ break;
+ }
+ } else {
+ if (InputFile) {
+ fprintf (stderr, "additional file specs ignored\n");
+ } else {
+ InputFile = Arg;
}
}
}
/* Did we have a file spec on the command line? */
- if (!fin) {
+ if (InputFile == 0) {
fprintf (stderr, "%s: No input files\n", argv [0]);
exit (EXIT_FAILURE);
}
- /* Create the output file name. We should really have
- * some checks for string overflow, but I'll drop this because of the
- * additional code size it would need (as in other places). Sigh.
- * #### To be removed
- */
- if (out_name [0] == '\0') {
- char* p;
- /* No output name given, create default */
- strcpy (out_name, fin);
- if ((p = strrchr (out_name, '.'))) {
- *p = '\0';
- }
- strcat (out_name, ".s");
+ /* Open the input file */
+ OpenMainFile (InputFile);
+
+ /* Create the output file name if it was not explicitly given */
+ if (OutputFile == 0) {
+ OutputFile = MakeFilename (InputFile, ".s");
}
/* Go! */
}
/* Open the file */
- F = fopen (out_name, "w");
+ F = fopen (OutputFile, "w");
if (F == 0) {
Fatal (FAT_CANNOT_OPEN_OUTPUT, strerror (errno));
}
/* Close the file, check for errors */
if (fclose (F) != 0) {
- remove (out_name);
+ remove (OutputFile);
Fatal (FAT_CANNOT_WRITE_OUTPUT);
}
}