what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
-#define USE_SYSTEM_SYSTEM_CALLS
-
#include "common.h"
#include <ctype.h>
#include "newalloc.h"
#define OPTION_SMALL_MODEL "-model-small"
#define OPTION_FLAT24_MODEL "-model-flat24"
#define OPTION_STACK_AUTO "-stack-auto"
+#define OPTION_STACK_8BIT "-stack-8bit"
#define OPTION_STACK_10BIT "-stack-10bit"
#define OPTION_XSTACK "-xstack"
#define OPTION_GENERIC "-generic"
static const char *_preCmd[] =
{
"sdcpp", "-Wall", "-lang-c++", "-DSDCC=1",
- "$l", "-I" SDCC_INCLUDE_DIR, "$1", "$2", NULL
+ "$l", "$1", "$2", NULL
};
PORT *port;
&ds390_port,
#endif
#if !OPT_DISABLE_PIC
- &pic14_port,
+ &pic_port,
#endif
#if !OPT_DISABLE_I186
&i186_port,
/**
remove me - TSD a hack to force sdcc to generate gpasm format .asm files.
*/
-extern void pic14glue ();
+extern void picglue ();
/** Sets the port to the one given by the command line option.
@param The name minus the option (eg 'mcs51')
@return 0 on success.
*/
-static int
+static void
_setPort (const char *name)
{
int i;
if (!strcmp (_ports[i]->target, name))
{
port = _ports[i];
- return 0;
+ return;
}
}
/* Error - didnt find */
exit (1);
}
-static void
+static void
_validatePorts (void)
{
int i;
}
}
-#ifdef USE_SYSTEM_SYSTEM_CALLS
-void
+void
buildCmdLine (char *into, const char **cmds,
const char *p1, const char *p2,
const char *p3, const char **list)
strcat (into, " ");
}
}
-#else
-void
-buildCmdLine (char *into, char **args, const char **cmds,
- const char *p1, const char *p2,
- const char *p3, const char **list)
-{
- const char *p, *from;
-
- while (*cmds)
- {
- *args = into;
- args++;
-
- from = *cmds;
- cmds++;
- *into = '\0';
-
- /* See if it has a '$' anywhere - if not, just copy */
- if ((p = strchr (from, '$')))
- {
- strncpy (into, from, p - from);
- /* NULL terminate it */
- into[p - from] = '\0';
- from = p + 2;
- p++;
- switch (*p)
- {
- case '1':
- if (p1)
- strcat (into, p1);
- break;
- case '2':
- if (p2)
- strcat (into, p2);
- break;
- case '3':
- if (p3)
- strcat (into, p3);
- break;
- case 'l':
- {
- const char **tmp = list;
- if (tmp)
- {
- while (*tmp)
- {
- strcpy (into, *tmp);
- into += strlen (into) + 1;
- *args = into;
- args++;
- tmp++;
- }
- }
- break;
- }
- default:
- assert (0);
- }
- }
- strcat (into, from);
- if (strlen (into) == 0)
- args--;
- into += strlen (into) + 1;
- }
- *args = NULL;
-}
-#endif
/*-----------------------------------------------------------------*/
/* printVersionInfo - prints the version info */
/*-----------------------------------------------------------------*/
-void
+void
printVersionInfo ()
{
int i;
"SDCC : ");
for (i = 0; i < NUM_PORTS; i++)
fprintf (stderr, "%s%s", i == 0 ? "" : "/", _ports[i]->target);
+
fprintf (stderr, " %s"
#ifdef SDCC_SUB_VERSION_STR
"/" SDCC_SUB_VERSION_STR
#endif
- " ` "
#ifdef __CYGWIN32__
" (CYGWIN32)\n"
#else
#ifdef __DJGPP__
" (DJGPP) \n"
+#else
+#if defined(_MSC_VER)
+ " (WIN32) \n"
#else
" (UNIX) \n"
#endif
+#endif
#endif
,VersionString
/*-----------------------------------------------------------------*/
/* printUsage - prints command line syntax */
/*-----------------------------------------------------------------*/
-void
+void
printUsage ()
{
printVersionInfo ();
/*-----------------------------------------------------------------*/
/* parseWithComma - separates string with comma */
/*-----------------------------------------------------------------*/
-void
+void
parseWithComma (char **dest, char *src)
{
int i = 0;
/*-----------------------------------------------------------------*/
/* setDefaultOptions - sets the default options */
/*-----------------------------------------------------------------*/
-static void
+static void
setDefaultOptions ()
{
int i;
options.nostdinc = 0;
options.verbose = 0;
+ options.stack10bit=0;
+
/* now for the optimizations */
/* turn on the everything */
optimize.global_cse = 1;
optimize.loopInvariant = 1;
optimize.loopInduction = 1;
+ /* now for the ports */
port->setDefaultOptions ();
}
/*-----------------------------------------------------------------*/
/* processFile - determines the type of file from the extension */
/*-----------------------------------------------------------------*/
-static void
+static void
processFile (char *s)
{
char *fext = NULL;
}
-static void
+static void
_processC1Arg (char *s)
{
if (srcFileName)
}
}
-static void
+static void
_addToList (const char **list, const char *str)
{
/* This is the bad way to do things :) */
*(++list) = NULL;
}
-static void
+static void
_setModel (int model, const char *sz)
{
if (port->general.supported_models & model)
/*-----------------------------------------------------------------*/
/* parseCmdLine - parses the command line and sets the options */
/*-----------------------------------------------------------------*/
-int
+int
parseCmdLine (int argc, char **argv)
{
int i;
continue;
}
+ if (strcmp (&argv[i][1], OPTION_STACK_8BIT) == 0)
+ {
+ options.stack10bit = 0;
+ continue;
+ }
+
if (strcmp (&argv[i][1], OPTION_STACK_AUTO) == 0)
{
options.stackAuto = 1;
case 'm':
/* Used to select the port */
- if (_setPort (argv[i] + 2))
- {
- werror (W_UNSUPP_OPTION, "-m", "Unrecognised processor");
- }
+ _setPort (argv[i] + 2);
break;
case 'a':
/* my_system - will call a program with arguments */
/*-----------------------------------------------------------------*/
-#if defined(_MSC_VER)
-char *try_dir[] =
-{DefaultExePath, NULL}; // TODO : Fill in some default search list
-#else
//char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
char *try_dir[] =
-{NULL, NULL}; /* First entry may be overwritten, so use two. */
+{NULL, NULL}; /* First entry may be overwritten, so use two. */
-#endif
-#ifdef USE_SYSTEM_SYSTEM_CALLS
-int
+int
my_system (const char *cmd)
{
int argsStart, e, i = 0;
// try to find the command in predefined path's
while (try_dir[i])
{
- cmdLine = (char *) malloc (strlen (try_dir[i]) + strlen (cmd) + 10);
+ cmdLine = (char *) Safe_malloc (strlen (try_dir[i]) + strlen (cmd) + 10);
strcpy (cmdLine, try_dir[i]); // the path
- strcat (cmdLine, "/");
+ strcat (cmdLine, DIR_SEPARATOR_STRING);
strncat (cmdLine, cmd, argsStart); // the command
+
#if NATIVE_WIN32
strcat (cmdLine, ".exe");
- /* Mung slashes into backslashes to keep WIndoze happy. */
- {
- char *r = cmdLine;
- while (*r)
- {
- if (*r == '/')
- {
- *r = '\\';
- }
- r++;
- }
- }
#endif
+
if (access (cmdLine, X_OK) == 0)
{
// the arguments
return e;
}
-#else
-
-int
-my_system (const char *cmd, char **cmd_argv)
-{
- char *dir, *got = NULL;
- int i = 0;
-
- while (!got && try_dir[i])
- {
- dir = (char *) Safe_malloc (strlen (try_dir[i]) + strlen (cmd) + 10);
- strcpy (dir, try_dir[i]);
- strcat (dir, "/");
- strcat (dir, cmd);
-
-#if NATIVE_WIN32
- strcat (dir, ".exe");
-
- /* Mung slashes into backslashes to keep WIndoze happy. */
- {
- char *r;
- r = dir;
-
- while (*r)
- {
- if (*r == '/')
- {
- *r = '\\';
- }
- r++;
- }
- }
-#endif
-
- if (access (dir, X_OK) == 0)
- {
- got = strdup (dir);
- }
- free (dir);
- i++;
- }
-
- if (verboseExec)
- {
- char **pCmd = cmd_argv;
- printf ("+ ");
- while (*pCmd)
- {
- printf ("%s ", *pCmd);
- pCmd++;
- }
- printf ("\n");
- }
-
- if (got)
- {
- i = spawnv (P_WAIT, got, cmd_argv) == -1;
- free (got);
- }
- else
- i = spawnvp (P_WAIT, cmd, cmd_argv) == -1;
- if (i)
- {
- perror ("Cannot exec process ");
- return -1;
- }
-
- return 0;
-}
-#endif
/*-----------------------------------------------------------------*/
/* linkEdit : - calls the linkage editor with options */
/*-----------------------------------------------------------------*/
-static void
+static void
linkEdit (char **envp)
{
FILE *lnkfile;
-#ifndef USE_SYSTEM_SYSTEM_CALLS
- char *argv[128];
-#endif
char *segName, *c;
int i;
/* standard library path */
if (!options.nostdlib)
{
- if (IS_DS390_PORT)
+ if (TARGET_IS_DS390)
{
c = "ds390";
}
if (options.verbose)
printf ("sdcc: Calling linker...\n");
-#ifdef USE_SYSTEM_SYSTEM_CALLS
buildCmdLine (buffer, port->linker.cmd, srcFileName, NULL, NULL, NULL);
if (my_system (buffer))
{
- /* either system() or the linker itself has reported an error
- perror ("Cannot exec linker");
- */
exit (1);
}
-#else
- buildCmdLine (buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL);
- if (my_system (argv[0], argv))
- {
- perror ("Cannot exec linker");
- exit (1);
- }
-
-#endif
if (strcmp (srcFileName, "temp") == 0)
{
/*-----------------------------------------------------------------*/
/* assemble - spawns the assembler with arguments */
/*-----------------------------------------------------------------*/
-static void
+static void
assemble (char **envp)
{
-#ifdef USE_SYSTEM_SYSTEM_CALLS
buildCmdLine (buffer, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
if (my_system (buffer))
{
/* either system() or the assembler itself has reported an error
- perror ("Cannot exec assembler");
- */
- exit (1);
- }
-#else
- char *argv[128]; /* assembler arguments */
-
- buildCmdLine (buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
-
- if (my_system (argv[0], argv))
- {
- perror ("Cannot exec assembler");
+ perror ("Cannot exec assembler");
+ */
exit (1);
}
-#endif
}
/*-----------------------------------------------------------------*/
/* preProcess - spawns the preprocessor with arguments */
/*-----------------------------------------------------------------*/
-static int
+static int
preProcess (char **envp)
{
-#ifndef USE_SYSTEM_SYSTEM_CALLS
- char *argv[128];
-#endif
char procDef[128];
preOutName = NULL;
break;
}
+ /* standard include path */
+ if (!options.nostdinc) {
+ _addToList (preArgv, "-I" SDCC_INCLUDE_DIR);
+ }
/* add port (processor information to processor */
sprintf (procDef, "-DSDCC_%s", port->target);
_addToList (preArgv, procDef);
+ sprintf (procDef, "-D__%s", port->target);
+ _addToList (preArgv, procDef);
if (!preProcOnly)
preOutName = strdup (tmpnam (NULL));
if (options.verbose)
printf ("sdcc: Calling preprocessor...\n");
-#ifdef USE_SYSTEM_SYSTEM_CALLS
buildCmdLine (buffer, _preCmd, fullSrcFileName,
preOutName, srcFileName, preArgv);
if (my_system (buffer))
{
- /* either system() or the preprocessor itself has reported an error
- perror ("Cannot exec Preprocessor");
- */
exit (1);
}
-#else
- buildCmdLine (buffer, argv, _preCmd, fullSrcFileName,
- preOutName, srcFileName, preArgv);
- if (my_system (argv[0], argv))
- {
- unlink (preOutName);
- perror ("Cannot exec Preprocessor");
- exit (1);
- }
-
-#endif
if (preProcOnly)
exit (0);
}
return 0;
}
-static void
+static void
_findPort (int argc, char **argv)
{
_validatePorts ();
* initialises and calls the parser
*/
-int
+int
main (int argc, char **argv, char **envp)
{
/* turn all optimizations off by default */
/*printVersionInfo (); */
+ if (NUM_PORTS==0) {
+ fprintf (stderr, "Build error: no ports are enabled.\n");
+ exit (1);
+ }
+
_findPort (argc, argv);
/* Initalise the port. */
if (port->init)
port->init ();
-#if defined(_MSC_VER)
-
- {
- int i;
-
- // Create a default exe search path from the path to the sdcc command
-
- strcpy (DefaultExePath, argv[0]);
+ // Create a default exe search path from the path to the sdcc command
- for (i = strlen (DefaultExePath); i > 0; i--)
- if (DefaultExePath[i] == '\\')
- {
- DefaultExePath[i] = '\0';
- break;
- }
- if (i == 0)
- DefaultExePath[0] = '\0';
- }
-#else
- if (strchr(argv[0], '/'))
- {
- strcpy(DefaultExePath, argv[0]);
- *(strrchr(DefaultExePath, '/')) = 0;
+ if (strchr (argv[0], DIR_SEPARATOR_CHAR))
+ {
+ strcpy (DefaultExePath, argv[0]);
+ *(strrchr (DefaultExePath, DIR_SEPARATOR_CHAR)) = 0;
try_dir[0] = DefaultExePath;
- }
+ }
-#endif
setDefaultOptions ();
parseCmdLine (argc, argv);
if (!fatalError)
{
-/* TSD PIC port hack - if the PIC port option is enabled
- and SDCC is used to generate PIC code, then we will
- generate .asm files in gpasm's format instead of SDCC's
- assembler's format
- */
-#if !OPT_DISABLE_PIC
- if (IS_PIC_PORT)
- pic14glue ();
+ if (TARGET_IS_PIC) {
+ /* TSD PIC port hack - if the PIC port option is enabled
+ and SDCC is used to generate PIC code, then we will
+ generate .asm files in gpasm's format instead of SDCC's
+ assembler's format
+ */
+ picglue ();
+ }
else
-#endif
glue ();
if (fatalError)
{
{
if (options.verbose)
printf ("sdcc: Calling assembler...\n");
-
assemble (envp);
}
}