TSD PIC port
[fw/sdcc] / src / SDCCmain.c
index ff58b6090de9501d4f786e8ae460ef26b99e612c..9ae9871d39cb0cc80f91dd458ee4e6b1ea2399b9 100644 (file)
 
 #include "common.h"
 #include <ctype.h>
+
+#if NATIVE_WIN32
+#include <process.h>
+#else
 #include "spawn.h"
+#endif
 
-/* This is a bit messy.  We cant include unistd.h as it defines
-   'link' which we also use.
-*/
-int access(const char *path, int mode);
+// This is a bit messy because we define link ourself
+#ifndef __BORLANDC__
+#define link NoLiNk
+#include <unistd.h>
+#undef link
+#else
+// No unistd.h in Borland C++
+extern int access(const char *, int);
 #define X_OK 1
-int unlink(const char *path);
-
-extern void            initSymt                ();
-extern void            initMem                 ();
-extern void            initExpr                ();
-extern void             initiCode               ();
-extern void             initCSupport            ();
-extern void             initPeepHole            ();
-extern void            createObject    ();
-extern int             yyparse                 ();
-extern void             glue ();
-extern struct value    *constVal(char *s);
-extern double            floatFromVal(struct value *);
-extern int              fatalError ;
+#endif
+
+//REMOVE ME!!!
+extern int yyparse();
+
 FILE  *srcFile         ;/* source file          */
 FILE  *cdbFile = NULL  ;/* debugger information output file */
 char  *fullSrcFileName ;/* full name for the source file */
 char  *srcFileName     ;/* source file name with the .c stripped */
 char  *moduleName      ;/* module name is srcFilename stripped of any path */
-char *preArgv[128]        ;/* pre-processor arguments  */
+const char *preArgv[128]          ;/* pre-processor arguments  */
 int   currRegBank = 0 ;
 struct optimize optimize ;
 struct options  options ;
@@ -58,7 +58,7 @@ char *VersionString = SDCC_VERSION_STR /*"Version 2.1.8a"*/;
 short preProcOnly = 0;
 short noAssemble = 0;
 char *linkOptions[128];
-char *asmOptions[128];
+const char *asmOptions[128];
 char *libFiles[128] ;
 int nlibFiles = 0;
 char *libPaths[128] ;
@@ -66,12 +66,16 @@ int nlibPaths = 0;
 char *relFiles[128];
 int nrelFiles = 0;
 bool verboseExec = FALSE;
-//extern int wait (int *);
 char    *preOutName;
 
+/* Far functions, far data */
 #define OPTION_LARGE_MODEL "-model-large"
+/* Far functions, near data */
+#define OPTION_MEDIUM_MODEL "-model-medium"
 #define OPTION_SMALL_MODEL "-model-small"
+#define OPTION_FLAT24_MODEL "-model-flat24"
 #define OPTION_STACK_AUTO  "-stack-auto"
+#define OPTION_STACK_10BIT "-stack-10bit"
 #define OPTION_XSTACK      "-xstack"
 #define OPTION_GENERIC     "-generic"
 #define OPTION_NO_GCSE     "-nogcse"
@@ -108,39 +112,52 @@ char    *preOutName;
 #define OPTION_NOPEEP      "-no-peep"
 #define OPTION_ASMPEEP     "-peep-asm"
 #define OPTION_DEBUG       "-debug"
+#define OPTION_NODEBUG    "-nodebug"
 #define OPTION_VERSION     "-version"
 #define OPTION_STKAFTRDATA "-stack-after-data"
 #define OPTION_PREPROC_ONLY "-preprocessonly"
+#define OPTION_C1_MODE   "-c1mode"
 #define OPTION_HELP         "-help"
 #define OPTION_CALLEE_SAVES "-callee-saves"
 #define OPTION_NOREGPARMS   "-noregparms"
-
-static const char *linkCmd[] = {
-    "$1", "-nf", "$2", NULL
+#define OPTION_NOSTDLIB     "-nostdlib"
+#define OPTION_NOSTDINC     "-nostdinc"
+#define OPTION_VERBOSE      "-verbose"
+static const char *_preCmd[] = {
+    "sdcpp", "-Wall", "-lang-c++", "-DSDCC=1", 
+    "$l", "-I" SDCC_INCLUDE_DIR, "$1", "$2", NULL
 };
 
-static const char *preCmd[] = {
-    "sdcpp", "-version", "-Wall", "-lang-c++", "-DSDCC=1", 
-    "-I" SDCC_INCLUDE_DIR, "$l", "$1", "$2", NULL
-};
-
-static const char *asmCmd[] = {
-    "$1", "-plosgffc", "$2.asm", NULL
-};
-
-
-extern PORT mcs51_port;
-extern PORT z80_port;
-
 PORT *port;
 
 static PORT *_ports[] = {
-    &mcs51_port,
-    &z80_port
+#if !OPT_DISABLE_MCS51
+   &mcs51_port,
+#endif
+#if !OPT_DISABLE_GBZ80
+    &gbz80_port,
+#endif
+#if !OPT_DISABLE_Z80
+    &z80_port,
+#endif
+#if !OPT_DISABLE_AVR
+    &avr_port,
+#endif
+#if !OPT_DISABLE_DS390
+    &ds390_port,
+#endif
+#if !OPT_DISABLE_PIC
+    &pic14_port,
+#endif
 };
 
 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
 
+/**
+   remove me - TSD a hack to force sdcc to generate gpasm format .asm files.
+ */
+extern void             pic14glue();
+
 /** Sets the port to the one given by the command line option.
     @param             The name minus the option (eg 'mcs51')
     @return            0 on success.
@@ -155,10 +172,11 @@ static int _setPort(const char *name)
        }
     }
     /* Error - didnt find */
-    return 1;
+    werror(E_UNKNOWN_TARGET,name);
+    exit(1);
 }
 
-static void _buildCmdLine(char *into, char **args, const char **cmds, 
+void buildCmdLine(char *into, char **args, const char **cmds, 
                          const char *p1, const char *p2, 
                          const char *p3, const char **list)
 {
@@ -175,6 +193,8 @@ static void _buildCmdLine(char *into, char **args, const char **cmds,
        /* 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) {
@@ -226,8 +246,11 @@ void       printVersionInfo ()
             "SDCC : ");
     for (i=0; i<NUM_PORTS; i++)
        fprintf(stderr, "%s%s", i==0 ? "" : "/", _ports[i]->target);
-
-    fprintf(stderr, " %s `"
+    fprintf(stderr, " %s"
+#ifdef SDCC_SUB_VERSION_STR
+           "/" SDCC_SUB_VERSION_STR
+#endif
+           " ` "
 #ifdef __CYGWIN32__
                " (CYGWIN32)\n"
 #else
@@ -237,6 +260,7 @@ void        printVersionInfo ()
                " (UNIX) \n"
 # endif
 #endif
+
            , VersionString
            );
 }
@@ -268,7 +292,7 @@ void        printUsage ()
                 "PreProcessor Options :-\n"
                 "\t-Dmacro             -       Define Macro\n"          
                 "\t-Ipath              -       Include \"*.h\" path\n"
-                "Note: this is a complete list of options see docs for details\n",
+                "Note: this is NOT a complete list of options see docs for details\n",
                 _ports[0]->target
                 );             
        exit (0);
@@ -305,8 +329,8 @@ static void setDefaultOptions()
     int i ;
 
     for ( i = 0 ; i < 128 ; i++)
-       preArgv[i] = linkOptions [i] =
-           asmOptions[i] = relFiles[i] = libFiles[i] =
+       preArgv[i] = asmOptions [i] =
+           linkOptions[i] = relFiles[i] = libFiles[i] =
            libPaths[i] = NULL ;
 
     /* first the options part */
@@ -318,6 +342,10 @@ static void setDefaultOptions()
     options.idata_loc = 0x80;
     options.genericPtr = 1;   /* default on */
     options.nopeep    = 0;
+    options.model = port->general.default_model;
+    options.nostdlib=0;
+    options.nostdinc=0;
+    options.verbose=0;
 
     /* now for the optimizations */
     /* turn on the everything */
@@ -351,7 +379,7 @@ static void processFile (char *s)
     }
 
     /* otherwise depending on the file type */
-    if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) {
+    if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0 || options.c1mode) {
        /* source file name : not if we already have a 
           source file */
        if (srcFileName) {
@@ -392,8 +420,9 @@ static void processFile (char *s)
     /* if the extention is type .rel or .r or .REL or .R 
        addtional object file will be passed to the linker */
     if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 ||
-       strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) {
-       
+       strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0 ||
+       strcmp(fext, port->linker.rel_ext) == 0)
+       {
        relFiles[nrelFiles++] = s;
        return ;
     }
@@ -408,7 +437,21 @@ static void processFile (char *s)
   
 }
 
-static void _addToList(char **list, const char *str)
+static void _processC1Arg(char *s)
+{
+    if (srcFileName) {
+       if (options.out_name) {
+           werror(W_TOO_MANY_SRC,s);
+           return;
+       }
+       options.out_name = strdup(s);
+    }
+    else {
+       processFile(s);
+    }
+}
+
+static void _addToList(const char **list, const char *str)
 {
     /* This is the bad way to do things :) */
     while (*list)
@@ -421,6 +464,14 @@ static void _addToList(char **list, const char *str)
     *(++list) = NULL;
 }
 
+static void _setModel(int model, const char *sz)
+{
+    if (port->general.supported_models & model)
+       options.model = model;
+    else
+       werror(W_UNSUPPORTED_MODEL, sz, port->target);
+}
+
 /*-----------------------------------------------------------------*/
 /* parseCmdLine - parses the command line and sets the options     */
 /*-----------------------------------------------------------------*/
@@ -448,14 +499,29 @@ int   parseCmdLine ( int argc, char **argv )
            }
 
            if (strcmp(&argv[i][1],OPTION_LARGE_MODEL) == 0) {
-               options.model = 1;
+               _setModel(MODEL_LARGE, argv[i]);
+                continue;
+           }
+
+           if (strcmp(&argv[i][1],OPTION_MEDIUM_MODEL) == 0) {
+               _setModel(MODEL_MEDIUM, argv[i]);
                 continue;
            }
            
            if (strcmp(&argv[i][1],OPTION_SMALL_MODEL) == 0) {
-               options.model = 0;
+               _setModel(MODEL_SMALL, argv[i]);
                 continue;
            }
+           
+           if (strcmp(&argv[i][1],OPTION_FLAT24_MODEL) == 0) {
+               _setModel(MODEL_FLAT24, argv[i]);
+                continue;
+           }
+           
+           if (strcmp(&argv[i][1],OPTION_STACK_10BIT) == 0) {
+               options.stack10bit = 1;
+               continue;
+           }
 
            if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
                options.stackAuto = 1;
@@ -537,6 +603,11 @@ int   parseCmdLine ( int argc, char **argv )
                 continue;
            }
 
+           if (strcmp(&argv[i][1],OPTION_C1_MODE) == 0) {
+               options.c1mode = 1;
+                continue;
+           }
+
            
            if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) {
                options.dump_rassgn = 
@@ -574,6 +645,11 @@ int   parseCmdLine ( int argc, char **argv )
                 continue;
            }
 
+           if (strcmp(&argv[i][1],OPTION_NODEBUG) == 0) {
+               options.nodebug = 1;            
+                continue;
+           }
+
            if (strcmp(&argv[i][1],OPTION_NOREGPARMS) == 0) {
                options.noregparms = 1;         
                 continue;
@@ -725,15 +801,38 @@ int   parseCmdLine ( int argc, char **argv )
                 continue;
            }
 
-           if (!port->parseOption(&argc, argv))
+           if (strcmp(&argv[i][1],OPTION_NOSTDLIB) == 0) {
+               options.nostdlib=1;
+               continue;
+           }
+
+           if (strcmp(&argv[i][1],OPTION_NOSTDINC) == 0) {
+               options.nostdinc=1;
+               continue;
+           }
+
+           if (strcmp(&argv[i][1],OPTION_VERBOSE) == 0) {
+               options.verbose=1;
+               continue;
+           }
+
+           if (!port->parseOption(&argc, argv, &i))
+           {
                werror(W_UNKNOWN_OPTION,argv[i]);
+           }
+           else
+           {
+               continue;
+           }
        }      
 
        /* these are undocumented options */
        /* if preceded by '/' then turn off certain optmizations, used
           for debugging only these are also the legacy options from
-          version 1.xx will be removed gradually */
-       if ( *argv[i] == '/') {
+          version 1.xx will be removed gradually.
+          It may be an absolute filename.
+       */
+       if ( *argv[i] == '/' && strlen(argv[i]) < 3) {
            switch (argv[i][1]) {
                
            case 'p':
@@ -861,9 +960,9 @@ int   parseCmdLine ( int argc, char **argv )
                    /* assembler options */
                    if (argv[i][2] == 'a') {
                        if (argv[i][3])
-                           parseWithComma(asmOptions,&argv[i][3]);
+                           parseWithComma((char **)asmOptions,&argv[i][3]);
                        else
-                           parseWithComma(asmOptions,argv[++i]);
+                           parseWithComma((char **)asmOptions,argv[++i]);
                        
                    } else {
                        werror(W_UNKNOWN_OPTION,argv[i]);                      
@@ -874,21 +973,30 @@ int   parseCmdLine ( int argc, char **argv )
                noAssemble = 1;
                break;
 
+           case 'V':
+             verboseExec = TRUE;
+             break;
+
            case 'v':
-#if FEATURE_VERBOSE_EXEC
-               verboseExec = TRUE;
-#else
                printVersionInfo();
                exit(0);
-#endif
                break;
 
                /* preprocessor options */              
+           case 'M':
+             {
+               preProcOnly=1;
+               _addToList(preArgv, "-M");
+               break;
+             }
+           case 'C':
+             {
+               _addToList(preArgv, "-C");
+               break;
+             }
            case 'd':
            case 'D':
            case 'I':
-           case 'M':
-           case 'C':
            case 'A':
            case 'U':
                {
@@ -904,8 +1012,6 @@ int   parseCmdLine ( int argc, char **argv )
                    
                    if ( argv[i][1] == 'Y' )
                        argv[i][1] = 'I';
-                   if (argv[i][1] == 'M')
-                       preProcOnly = 1;
 
                    sprintf(buffer, "-%c%s", sOpt, rest);
                    _addToList(preArgv, buffer);
@@ -913,15 +1019,18 @@ int   parseCmdLine ( int argc, char **argv )
                break ;
 
            default:
-               if (!port->parseOption(&argc, argv))
+               if (!port->parseOption(&argc, argv, &i))
                    werror(W_UNKNOWN_OPTION,argv[i]);
            }
            continue ;
        }
 
-       if (!port->parseOption(&argc, argv)) {
+       if (!port->parseOption(&argc, argv, &i)) {
            /* no option must be a filename */
-           processFile(argv[i]);
+           if (options.c1mode)
+               _processC1Arg(argv[i]);
+           else
+               processFile(argv[i]);
        }
     }  
 
@@ -930,7 +1039,7 @@ int   parseCmdLine ( int argc, char **argv )
        options.xstack_loc = options.xdata_loc ;
 
     /* if debug option is set the open the cdbFile */
-    if (/* options.debug && */ srcFileName) {
+    if (!options.nodebug && srcFileName) {
        sprintf(cdbfnbuf,"%s.cdb",srcFileName);
        if ((cdbFile = fopen(cdbfnbuf,"w")) == NULL)
            werror(E_FILE_OPEN_ERR,cdbfnbuf);
@@ -939,7 +1048,6 @@ int   parseCmdLine ( int argc, char **argv )
            fprintf(cdbFile,"M:%s\n",moduleName);
        }
     }
-    port->finaliseOptions();
     return 0;
 }
 
@@ -949,26 +1057,52 @@ int   parseCmdLine ( int argc, char **argv )
 char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL};
 int my_system (const char *cmd, char **cmd_argv)
 {    
-
     char *dir, *got= NULL; int i= 0;
-    while (!got && try_dir[i]) {
-       dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10);
-       strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd);
-       if (access(dir, X_OK) == 0)
-           got= strdup(dir);
-       free(dir);
-       i++;
+
+    while (!got && try_dir[i])
+    {
+        dir= (char*)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 FEATURE_VERBOSE_EXEC
+
     if (verboseExec) {
        char **pCmd = cmd_argv;
+       printf ("+ ");
        while (*pCmd) {
            printf("%s ", *pCmd);
            pCmd++;
        }
        printf("\n");
     }
-#endif
+
     if (got)
       i= spawnv(P_WAIT,got,cmd_argv) == -1;
     else
@@ -988,6 +1122,7 @@ static void linkEdit (char **envp)
 {
     FILE *lnkfile ;
     char *argv[128];
+    char *segName, *c;
 
     int i;
     if (!srcFileName)
@@ -1009,34 +1144,69 @@ static void linkEdit (char **envp)
     
     /*if (options.debug) */
     fprintf(lnkfile,"-z\n");
+
+#define WRITE_SEG_LOC(N, L) \
+    segName = strdup(N); \
+    c = strtok(segName, " \t"); \
+    fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
+    if (segName) { free(segName); } 
+    
     /* code segment start */
-    fprintf (lnkfile,"-b CODE = 0x%04x\n",options.code_loc);
-    /* data segment start */
-    fprintf (lnkfile,"-b DSEG = 0x%04x\n",options.data_loc);
+    WRITE_SEG_LOC(CODE_NAME, options.code_loc);
+    
+     /* data segment start */
+     WRITE_SEG_LOC(DATA_NAME, options.data_loc);
+                 
     /* xdata start */
-    fprintf (lnkfile,"-b XSEG = 0x%04x\n",options.xdata_loc);
+    WRITE_SEG_LOC(XDATA_NAME, options. xdata_loc);
+
     /* indirect data */
-    fprintf (lnkfile,"-b ISEG = 0x%04x\n",options.idata_loc);
+    WRITE_SEG_LOC(IDATA_NAME, options.idata_loc);
+
     /* bit segment start */
-    fprintf (lnkfile,"-b BSEG = 0x%04x\n",0);
+    WRITE_SEG_LOC(BIT_NAME, 0);
     
     /* add the extra linker options */
     for (i=0; linkOptions[i] ; i++)
        fprintf(lnkfile,"%s\n",linkOptions[i]);
 
-    /* standard library path */
-    fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,
-            ( (options.model==0) ? "small": "large"));
-           
     /* other library paths if specified */
     for (i = 0 ; i < nlibPaths ; i++ )
        fprintf (lnkfile,"-k %s\n",libPaths[i]);
-        
-    /* standard library files */
-    fprintf (lnkfile,"-l %s\n",STD_LIB);
-    fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
-    fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
-    fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
+
+    /* standard library path */
+    if (!options.nostdlib) {
+      if (IS_DS390_PORT) {
+       c="ds390";
+      } else {
+       switch(options.model)
+         {
+         case MODEL_SMALL:
+           c = "small";
+           break;
+         case MODEL_LARGE:
+           c = "large";
+           break;
+         case MODEL_FLAT24:
+           c = "flat24";
+           break;
+         default:
+           werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
+           c = "unknown";
+           break;
+         }
+      }
+      fprintf (lnkfile,"-k %s/%s\n",SDCC_LIB_DIR/*STD_LIB_PATH*/,c);
+      
+      /* standard library files */
+      if (strcmp(port->target, "ds390")==0) {
+       fprintf (lnkfile,"-l %s\n",STD_DS390_LIB);
+      }
+      fprintf (lnkfile,"-l %s\n",STD_LIB);
+      fprintf (lnkfile,"-l %s\n",STD_INT_LIB);
+      fprintf (lnkfile,"-l %s\n",STD_LONG_LIB);
+      fprintf (lnkfile,"-l %s\n",STD_FP_LIB);
+    }
 
     /* additional libraries if any */
     for (i = 0 ; i < nlibFiles; i++)
@@ -1052,9 +1222,10 @@ static void linkEdit (char **envp)
     fprintf (lnkfile,"\n-e\n");
     fclose(lnkfile);
 
-    _buildCmdLine(buffer, argv, linkCmd, port->linker.exec_name, srcFileName, NULL, NULL);
+    buildCmdLine(buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL);
 
-    /* call the linker */
+    if (options.verbose)
+      printf ("sdcc: Calling linker...\n");
     if (my_system(argv[0], argv)) {
        perror("Cannot exec linker");
        exit(1);
@@ -1076,7 +1247,7 @@ static void assemble (char **envp)
 {
     char *argv[128];  /* assembler arguments */
 
-    _buildCmdLine(buffer, argv, asmCmd, port->assembler.exec_name, srcFileName, NULL, asmOptions);
+    buildCmdLine(buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
 
     if (my_system(argv[0], argv)) {
        perror("Cannot exec assember");
@@ -1092,39 +1263,74 @@ static void assemble (char **envp)
 static int preProcess (char **envp)
 {
     char *argv[128];
+    char procDef[128];
 
     preOutName = NULL;
 
-    /* if using external stack define the macro */
-    if ( options.useXstack )
-       _addToList(preArgv, "-DSDCC_USE_XSTACK");
-    
-    /* set the macro for stack autos   */
-    if ( options.stackAuto )
-       _addToList(preArgv, "-DSDCC_STACK_AUTO");
+    if (!options.c1mode) {
+       /* if using external stack define the macro */
+       if ( options.useXstack )
+           _addToList(preArgv, "-DSDCC_USE_XSTACK");
+       
+       /* set the macro for stack autos        */
+       if ( options.stackAuto )
+           _addToList(preArgv, "-DSDCC_STACK_AUTO");
+           
+       /* set the macro for stack autos        */
+       if ( options.stack10bit )
+           _addToList(preArgv, "-DSDCC_STACK_TENBIT"); 
     
-    /* set the macro for large model   */
-    if ( options.model )
-       _addToList(preArgv, "-DSDCC_MODEL_LARGE");
-    else
-       _addToList(preArgv, "-DSDCC_MODEL_SMALL");
+       /* set the macro for large model        */
+       switch(options.model)
+           {
+           case MODEL_LARGE:
+               _addToList(preArgv, "-DSDCC_MODEL_LARGE");
+               break;
+           case MODEL_SMALL:
+               _addToList(preArgv, "-DSDCC_MODEL_SMALL");
+               break;
+           case MODEL_COMPACT:
+               _addToList(preArgv, "-DSDCC_MODEL_COMPACT");
+               break;
+           case MODEL_MEDIUM:
+               _addToList(preArgv, "-DSDCC_MODEL_MEDIUM");
+               break;
+           case MODEL_FLAT24:
+               _addToList(preArgv, "-DSDCC_MODEL_FLAT24");
+               break;
+           default:
+               werror(W_UNKNOWN_MODEL, __FILE__, __LINE__);
+               break;
+           }       
+           
     
-    if (!preProcOnly)
-       preOutName = strdup(tmpnam(NULL));
+       /* add port (processor information to processor */
+       sprintf(procDef,"-DSDCC_%s",port->target);
+       _addToList(preArgv,procDef);
 
-    _buildCmdLine(buffer, argv, preCmd, fullSrcFileName, 
-                 preOutName, srcFileName, preArgv);
+       if (!preProcOnly)
+           preOutName = strdup(tmpnam(NULL));
 
-    if (my_system(argv[0], argv)) {
-       unlink (preOutName);
-       perror("Cannot exec Preprocessor");
-       exit(1);
-    }
+       buildCmdLine(buffer, argv, _preCmd, fullSrcFileName, 
+                     preOutName, srcFileName, preArgv);
 
-    if (preProcOnly)
-       exit(0);
+       if (options.verbose)
+         printf ("sdcc: Calling preprocessor...\n");
+
+       if (my_system(argv[0], argv)) {
+           unlink (preOutName);
+           perror("Cannot exec Preprocessor");
+           exit(1);
+       }
+
+       if (preProcOnly)
+           exit(0);
+    }
+    else {
+       preOutName = fullSrcFileName;
+    }
 
-    yyin = fopen(preOutName,"r");
+    yyin = fopen(preOutName, "r");
     if (yyin == NULL) {
        perror("Preproc file not found\n");
        exit(1);
@@ -1157,35 +1363,62 @@ int main ( int argc, char **argv , char **envp)
 {
     /* turn all optimizations off by default */
     memset(&optimize,0,sizeof(struct optimize));
-    
+
     /*printVersionInfo ();*/
 
     _findPort(argc, argv);
+    /* Initalise the port. */
+    if (port->init)
+       port->init();
+
     setDefaultOptions();
     parseCmdLine(argc,argv);
 
+    initMem();
+
+    port->finaliseOptions();
+
     /* if no input then printUsage & exit */
-    if (!srcFileName && !nrelFiles) {
+    if ((!options.c1mode && !srcFileName && !nrelFiles) || (options.c1mode && !srcFileName && !options.out_name)) {
        printUsage();
        exit(0);
     }
        
-    if (srcFileName)
-       preProcess(envp) ;
-
     if (srcFileName) {
+       preProcess(envp) ;
 
        initSymt();
-       initMem();                  
        initiCode();
        initCSupport ();
        initPeepHole();
+
+       if (options.verbose)
+         printf ("sdcc: Generating code...\n");
+
        yyparse();
 
-       if (!fatalError) {
+       if (!fatalError) 
+       {
+         if(IS_PIC_PORT)
+           pic14glue();
+         else
            glue();
-           assemble(envp);
+           if (fatalError)
+           {
+               return 1;
+           }
+           if (!options.c1mode)
+           {
+               if (options.verbose)
+                 printf ("sdcc: Calling assembler...\n");
+
+               assemble(envp);
+           }
        }
+       else 
+       {
+           return 1;
+        }
        
     }
     
@@ -1195,16 +1428,22 @@ int main ( int argc, char **argv , char **envp)
     if (!options.cc_only && 
        !fatalError      &&
        !noAssemble      &&
-       (srcFileName || nrelFiles))
-       linkEdit (envp);
+       !options.c1mode  &&
+       (srcFileName || nrelFiles)) {
+       if (port->linker.do_link)
+           port->linker.do_link();
+       else
+         linkEdit (envp);
+    }
 
     if (yyin && yyin != stdin)
        fclose(yyin);
 
-    if (preOutName) {
-       unlink(preOutName);
-       free(preOutName);
+    if (preOutName && !options.c1mode) {
+        unlink(preOutName);
+        free(preOutName);
     }
+
     return 0;
     
 }