* src/SDCCmain.c (linkEdit): modifications only for pic16 port,
[fw/sdcc] / src / pic16 / main.c
index d295080d1ad48cc608923ccc8a8bec9b50e587fb..2cdd52ba7642a041fb1b40804e4739d7523da28f 100644 (file)
@@ -82,9 +82,19 @@ static int regParmFlg = 0;   /* determine if we can register a parameter */
 
 pic16_options_t pic16_options;
 
+extern set *includeDirsSet;
+extern set *dataDirsSet;
+extern set *libFilesSet;
+
 /* Also defined in gen.h, but the #include is commented out */
 /* for an unknowned reason. - EEP */
 void pic16_emitDebuggerSymbol (char *);
+extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
+extern void pic16_emitConfigRegs(FILE *of);
+extern void pic16_emitIDRegs(FILE *of);
+
+
 
 static void
 _pic16_init (void)
@@ -94,12 +104,15 @@ _pic16_init (void)
        maxInterrupts = 2;
 
        /* set pic16 port options to defaults */
-       pic16_options.gen_banksel = 0;
+       pic16_options.no_banksel = 0;
        pic16_options.opt_banksel = 0;
        pic16_options.omit_configw = 0;
        pic16_options.omit_ivt = 0;
        pic16_options.leave_reset = 0;
        pic16_options.stack_model = 0;                  /* 0 for 'small', 1 for 'large' */
+       pic16_options.ivt_loc = 0x000000;               /* default location of interrupt vectors */
+       pic16_options.nodefaultlibs = 0;                /* link default libraries */
+       pic16_options.dumpcalltree = 0;
 }
 
 static void
@@ -125,13 +138,18 @@ int initsfpnt=0;          /* set to 1 if source provides a pragma for stack
                                 * so glue() later emits code to initialize stack/frame pointers */
 set *absSymSet;
 
+set *sectNames=NULL;                   /* list of section listed in pragma directives */
+set *sectSyms=NULL;                    /* list of symbols set in a specific section */
+
+
 static int
 _process_pragma(const char *sz)
 {
-  static const char *WHITE = " \t";
+  static const char *WHITE = " \t\n";
   
   char *ptr = strtok((char *)sz, WHITE);
 
+       /* #pragma maxram [maxram] */
        if (startsWith (ptr, "maxram")) {
          char *maxRAM = strtok((char *)NULL, WHITE);
 
@@ -145,23 +163,30 @@ _process_pragma(const char *sz)
                }
        }
        
+       /* #pragma stack [stack-position] */
        if(startsWith(ptr, "stack")) {
          char *stackPosS = strtok((char *)NULL, WHITE);
          value *stackPosVal;
          regs *reg;
+         symbol *sym;
 
 //             fprintf(stderr, "Initializing stack pointer to 0x%x\n", (int)floatFromVal(constVal(stackPos)));
                stackPosVal = constVal( stackPosS );
                stackPos = (unsigned int)floatFromVal( stackPosVal );
 
-               reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "stack", 1, 0, NULL);
+               reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", 1, 0, NULL);
                addSet(&pic16_fix_udata, reg);
+
+               sym = newSymbol("stack", 0);
+               sprintf(sym->rname, "_%s", sym->name);
+               addSet(&publics, sym);
                
                initsfpnt = 1;          // force glue() to initialize stack/frame pointers */
 
          return 0;
        }
        
+       /* #pragma code [symbol] [location] */
        if(startsWith(ptr, "code")) {
          char *symname = strtok((char *)NULL, WHITE);
          char *location = strtok((char *)NULL, WHITE);
@@ -178,40 +203,76 @@ _process_pragma(const char *sz)
                        __FILE__, __LINE__, symname, absS->address);
 
          return 0;
-       }         
+       }
 
+       /* #pragma udata [section-name] [symbol] */
+       if(startsWith(ptr, "udata")) {
+         char *sectname = strtok((char *)NULL, WHITE);
+         char *symname = strtok((char *)NULL, WHITE);
+         sectSym *ssym;
+         sectName *snam;
+         int found=0;
+         
+               while(symname) {
+
+                       ssym = Safe_calloc(1, sizeof(sectSyms));
+                       ssym->name = Safe_calloc(1, strlen(symname)+2);
+                       sprintf(ssym->name, "_%s", symname);
+                       ssym->reg = NULL;
+
+                       addSet(&sectSyms, ssym);
+
+                       found = 0;
+                       for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
+                               if(!strcmp(sectname, snam->name)){ found=1; break; }
+                       }
+                       
+                       if(!found) {
+                               snam = Safe_calloc(1, sizeof(sectNames));
+                               snam->name = Safe_strdup( sectname );
+                               snam->regsSet = NULL;
+                               
+                               addSet(&sectNames, snam);
+                       }
+                       
+                       ssym->section = snam;
+                               
+//                     fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
+//                             ssym->name, snam->name, snam);
+
+                       symname = strtok((char *)NULL, WHITE);
+               }
+
+         return 0;
+       }
+       
   return 1;
 }
 
 #define REP_UDATA      "--preplace-udata-with="
-#define REP_UDATAACS   "--preplace-udata-acs-with="
-#define REP_UDATAOVR   "--preplace-udata-ovr-with="
-#define REP_UDATASHR   "--preplace-udata-sht-with="
-
-#define NAME_CODE      "--psection-code-name="
-#define NAME_IDATA     "--psection-idata-name="
-#define NAME_UDATA     "--psection-udata-name="
-#define NAME_UDATAACS  "--psection-udata-acs-name="
-#define NAME_UDATAOVR  "--psection-udata-ovr-name="
-#define NAME_UDATASHR  "--psection-udata-shr-name="
-
-#define ADDR_CODE      "--psection-code-addr="
-#define ADDR_IDATA     "--psection-idata-addr="
-#define ADDR_UDATA     "--psection-udata-addr="
-#define ADDR_UDATAACS  "--psection-udata-acs-addr="
-#define ADDR_UDATAOVR  "--psection-udata-ovr-addr="
-#define ADDR_UDATASHR  "--psection-udata-shr-addr="
 
 #define STACK_MODEL    "--pstack-model="
 #define OPT_BANKSEL    "--obanksel="
 
+#define ALT_ASM                "--asm="
+#define ALT_LINK       "--link="
+
+#define IVT_LOC                "--ivt-loc"
+#define NO_DEFLIBS     "--nodefaultlibs"
+
+
+char *alt_asm=NULL;
+char *alt_link=NULL;
 
 extern int pic16_debug_verbose;
 extern int pic16_ralloc_debug;
 extern int pic16_pcode_verbose;
 
+int pic16_enable_peeps=0;
+
 OPTION pic16_optionsTable[]= {
-       { 0,    "--pgen-banksel",       &pic16_options.gen_banksel,     "generate BANKSEL assembler directives"},
+       { 0,    NO_DEFLIBS,             &pic16_options.nodefaultlibs,   "do not link default libraries when linking"},
+       { 0,    "--pno-banksel",        &pic16_options.no_banksel,      "do not generate BANKSEL assembler directives"},
        { 0,    OPT_BANKSEL,            NULL,                           "set banksel optimization level (default=0 no)"},
        { 0,    "--pomit-config-words", &pic16_options.omit_configw,    "omit the generation of configuration words"},
        { 0,    "--pomit-ivt",          &pic16_options.omit_ivt,        "omit the generation of the Interrupt Vector Table"},
@@ -224,30 +285,12 @@ OPTION pic16_optionsTable[]= {
                
        { 0,    REP_UDATA,      NULL,   "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
 
-#if 0
-       /* these may not be in any use -- VR */
-       { 0,    AT_UDATAACS,    NULL,   "Emit udata_acs variables at another section"},
-       { 0,    AT_UDATAOVR,    NULL,   "Emit udata_ovr variables at another section"},
-       { 0,    AT_UDATASHR,    NULL,   "Emit udata_shr variables at another section"},
-#endif
-
-#if 0
-       /* commented out for the time being -- VR */
-       { 0,    NAME_CODE,      NULL,   "Set code section name[,address]"},
-       { 0,    NAME_IDATA,     NULL,   "Set idata section name[,address]"},
-       { 0,    NAME_UDATA,     NULL,   "Set udata section name[,address]"},
-       { 0,    NAME_UDATAACS,  NULL,   "Set udata_acs section name[,address]"},
-       { 0,    NAME_UDATAOVR,  NULL,   "Set udata_ovr section name[,address]"},
-       { 0,    NAME_UDATASHR,  NULL,   "Set udata_shr section name[,address]"},
-       
-       { 0,    ADDR_CODE,      NULL,   "Set code section address"},
-       { 0,    ADDR_IDATA,     NULL,   "Set idata section address"},
-       { 0,    ADDR_UDATA,     NULL,   "Set udata section address"},
-       { 0,    ADDR_UDATAACS,  NULL,   "Set udata_acs section address"},
-       { 0,    ADDR_UDATAOVR,  NULL,   "Set udata_ovr section address"},
-       { 0,    ADDR_UDATASHR,  NULL,   "Set udata_shr section address"},
-#endif
+       { 0,    ALT_ASM,        NULL,   "Use alternative assembler"},
+       { 0,    ALT_LINK,       NULL,   "Use alternative linker"},
 
+       { 0,    "--denable-peeps",      &pic16_enable_peeps,    "explicit enable of peepholes"},
+       { 0,    IVT_LOC,        NULL,   "<nnnn> interrupt vector table location"},
+       { 0,    "--calltree",           &pic16_options.dumpcalltree,    "dump call tree in .calltree file"},
        { 0,    NULL,           NULL,   NULL}
        };
 
@@ -261,7 +304,6 @@ static bool
 _pic16_parseOptions (int *pargc, char **argv, int *i)
 {
   int j=0;
-//  set *tset;
   char *stkmodel;
   
   /* TODO: allow port-specific command line options to specify
@@ -298,122 +340,25 @@ _pic16_parseOptions (int *pargc, char **argv, int *i)
                return TRUE;
        }
        
-/*
-       if(ISOPT(AT_UDATAACS)) {
-               pic16_sectioninfo.at_udataacs = Safe_strdup( getStringArg(AT_UDATAACS, argv, i, *pargc));
-               return TRUE;
-       }
-
-       if(ISOPT(AT_UDATAOVR)) {
-               pic16_sectioninfo.at_udataovr = Safe_strdup( getStringArg(AT_UDATAOVR, argv, i, *pargc));
+       if(ISOPT(ALT_ASM)) {
+               alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc));
                return TRUE;
        }
        
-       if(ISOPT(AT_UDATASHR)) {
-               pic16_sectioninfo.at_udatashr = Safe_strdup( getStringArg(AT_UDATASHR, argv, i, *pargc));
+       if(ISOPT(ALT_LINK)) {
+               alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc));
                return TRUE;
        }
-*/
 
-#if 0
-       if(ISOPT(ADDR_CODE)) {
-               pic16_sectioninfo.addr_code = getIntArg(ADDR_CODE, argv, i, *pargc);
-               return TRUE;
-       }
-       
-       if(ISOPT(ADDR_IDATA)) {
-               pic16_sectioninfo.addr_idata = getIntArg(ADDR_IDATA, argv, i, *pargc);
-               return TRUE;
-       }
-       
-       if(ISOPT(ADDR_UDATA)) {
-               pic16_sectioninfo.addr_udata = getIntArg(ADDR_UDATA, argv, i, *pargc);
-               return TRUE;
-       }
-       
-       if(ISOPT(ADDR_UDATAACS)) {
-               pic16_sectioninfo.addr_udataacs = getIntArg(ADDR_UDATAACS, argv, i, *pargc);
-               return TRUE;
-       }
-       
-       if(ISOPT(ADDR_UDATAOVR)) {
-               pic16_sectioninfo.addr_udataovr = getIntArg(ADDR_UDATAOVR, argv, i, *pargc);
-               return TRUE;
-       }
-       
-       if(ISOPT(ADDR_UDATASHR)) {
-               pic16_sectioninfo.addr_udatashr = getIntArg(ADDR_UDATASHR, argv, i, *pargc);
-               return TRUE;
-       }
-
-       tset = newSet();
-       
-       if(ISOPT(NAME_CODE)) {
-               setParseWithComma(&tset, getStringArg(NAME_CODE, argv, i, *pargc));
-               if(elementsInSet(tset) > 0)
-                       pic16_sectioninfo.name_code = Safe_strdup( (char *)indexSet(tset, 0));
-               if(elementsInSet(tset) > 1)
-                       pic16_sectioninfo.addr_code = atoi( (char *)indexSet(tset, 1));
+       if(ISOPT(IVT_LOC)) {
+               pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
                return TRUE;
        }
 
-       if(ISOPT(NAME_IDATA)) {
-               setParseWithComma(&tset, getStringArg(NAME_IDATA, argv, i, *pargc));
-               if(elementsInSet(tset) > 0)
-                       pic16_sectioninfo.name_idata = Safe_strdup( (char *)indexSet(tset, 0));
-               if(elementsInSet(tset) > 1)
-                       pic16_sectioninfo.addr_idata = atoi( (char *)indexSet(tset, 1));
-               return TRUE;
-       }
-
-       if(ISOPT(NAME_UDATA)) {
-               setParseWithComma(&tset, getStringArg(NAME_UDATA, argv, i, *pargc));
-               if(elementsInSet(tset) > 0)
-                       pic16_sectioninfo.name_udata = Safe_strdup( (char *)indexSet(tset, 0));
-               if(elementsInSet(tset) > 1)
-                       pic16_sectioninfo.addr_udata = atoi( (char *)indexSet(tset, 1));
-               return TRUE;
-       }
-
-       if(ISOPT(NAME_UDATAACS)) {
-               setParseWithComma(&tset, getStringArg(NAME_UDATAACS, argv, i, *pargc));
-               if(elementsInSet(tset) > 0)
-                       pic16_sectioninfo.name_udataacs = Safe_strdup( (char *)indexSet(tset, 0));
-               if(elementsInSet(tset) > 1)
-                       pic16_sectioninfo.addr_udataacs = atoi( (char *)indexSet(tset, 1));
-               return TRUE;
-       }
-
-       if(ISOPT(NAME_UDATAOVR)) {
-               setParseWithComma(&tset, getStringArg(NAME_UDATAOVR, argv, i, *pargc));
-               if(elementsInSet(tset) > 0)
-                       pic16_sectioninfo.name_udataovr = Safe_strdup( (char *)indexSet(tset, 0));
-               if(elementsInSet(tset) > 1)
-                       pic16_sectioninfo.addr_udataovr = atoi( (char *)indexSet(tset, 1));
-               return TRUE;
-       }
-
-       if(ISOPT(NAME_UDATASHR)) {
-               setParseWithComma(&tset, getStringArg(NAME_UDATASHR, argv, i, *pargc));
-               if(elementsInSet(tset) > 0)
-                       pic16_sectioninfo.name_udatashr = Safe_strdup( (char *)indexSet(tset, 0));
-               if(elementsInSet(tset) > 1)
-                       pic16_sectioninfo.addr_udatashr = atoi( (char *)indexSet(tset, 1));
-               return TRUE;
-       }
-
-       deleteSet( &tset );
-#endif
-
   return FALSE;
 }
 
-extern set *includeDirsSet;
-extern set *dataDirsSet;
-extern set *libFilesSet;
-
-static void
-_pic16_finaliseOptions (void)
+static void _pic16_initPaths(void)
 {
   char pic16incDir[512];
   char pic16libDir[512];
@@ -421,18 +366,11 @@ _pic16_finaliseOptions (void)
   set *pic16libDirsSet;
   char devlib[512];
 
-       port->mem.default_local_map = data;
-       port->mem.default_globl_map = data;
-
-       options.all_callee_saves = 1;           // always callee saves
-       options.float_rent = 1;
-       options.intlong_rent = 1;
-       
-       setMainValue("mcu", pic16->name[2] );
+       setMainValue("mcu", pic16->name[2] );
        addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
 
-       sprintf(pic16incDir, "%s/pic16", INCLUDE_DIR_SUFFIX);
-       sprintf(pic16libDir, "%s/pic16", LIB_DIR_SUFFIX);
+       sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
+       sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
 
        if(!options.nostdinc) {
                /* setup pic16 include directory */
@@ -444,14 +382,46 @@ _pic16_finaliseOptions (void)
                /* setup pic16 library directory */
                pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
                mergeSets(&libDirsSet, pic16libDirsSet);
-       
-               /* now add the library for the device */
-               sprintf(devlib, "%s.lib", pic16->name[2]);
-               addSet(&libFilesSet, Safe_strdup(devlib));
+
+               if(!pic16_options.nodefaultlibs) {
+                       /* now add the library for the device */
+                       sprintf(devlib, "%s.lib", pic16->name[2]);
+                       addSet(&libFilesSet, Safe_strdup(devlib));
+               }
        }
 }
 
 
+/* forward declarations */
+extern const char *pic16_linkCmd[];
+extern const char *pic16_asmCmd[];
+
+static void
+_pic16_finaliseOptions (void)
+{
+       port->mem.default_local_map = data;
+       port->mem.default_globl_map = data;
+
+       /* peepholes are disabled for the time being */
+       options.nopeep = 1;
+
+       /* explicit enable peepholes for testing */
+       if(pic16_enable_peeps)
+               options.nopeep = 0;
+
+       options.all_callee_saves = 1;           // always callee saves
+//     options.float_rent = 1;
+//     options.intlong_rent = 1;
+       
+
+       if(alt_asm && strlen(alt_asm))
+               pic16_asmCmd[0] = alt_asm;
+       
+       if(alt_link && strlen(alt_link))
+               pic16_linkCmd[0] = alt_link;
+}
+
+
 /* all the rest is commented ifdef'd out */
 #if 0
   /* Hack-o-matic: if we are using the flat24 model,
@@ -515,25 +485,17 @@ _pic16_setDefaultOptions (void)
 {
        /* initialize to defaults section locations, names and addresses */
        pic16_sectioninfo.at_udata      = "udata";
-       pic16_sectioninfo.at_udataacs   = "udata_acs";
-       pic16_sectioninfo.at_udataovr   = "udata_ovr";
-       pic16_sectioninfo.at_udatashr   = "udata_shr";
-
-       /* initialize to nothing, so let linker decide about their names */
-       pic16_sectioninfo.name_code     =
-       pic16_sectioninfo.name_idata    =
-       pic16_sectioninfo.name_udata    =
-       pic16_sectioninfo.name_udataacs =
-       pic16_sectioninfo.name_udataovr =
-       pic16_sectioninfo.name_udatashr = "";
-
-       /* initialize to -1, so let linker decide about their address */
-       pic16_sectioninfo.addr_code     =
-       pic16_sectioninfo.addr_idata    =
-       pic16_sectioninfo.addr_udata    =
-       pic16_sectioninfo.addr_udataacs =
-       pic16_sectioninfo.addr_udataovr =
-       pic16_sectioninfo.addr_udatashr = -1;
+
+       /* set pic16 port options to defaults */
+       pic16_options.no_banksel = 0;
+       pic16_options.opt_banksel = 0;
+       pic16_options.omit_configw = 0;
+       pic16_options.omit_ivt = 0;
+       pic16_options.leave_reset = 0;
+       pic16_options.stack_model = 0;                  /* 0 for 'small', 1 for 'large' */
+       pic16_options.ivt_loc = 0x000000;
+       pic16_options.nodefaultlibs = 0;
+       pic16_options.dumpcalltree = 0;
 }
 
 static const char *
@@ -568,17 +530,9 @@ _pic16_genAssemblerPreamble (FILE * of)
        fprintf (of, "\tlist\tp=%s\n",&name[1]);
 
        if(!pic16_options.omit_configw) {
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300001, pic16_getConfigWord(0x300001));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300002, pic16_getConfigWord(0x300002));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300003, pic16_getConfigWord(0x300003));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300005, pic16_getConfigWord(0x300005));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300006, pic16_getConfigWord(0x300006));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300008, pic16_getConfigWord(0x300008));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300009, pic16_getConfigWord(0x300009));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000a, pic16_getConfigWord(0x30000a));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000b, pic16_getConfigWord(0x30000b));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000c, pic16_getConfigWord(0x30000c));
-               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000d, pic16_getConfigWord(0x30000d));
+               pic16_emitConfigRegs(of);
+               fprintf(of, "\n");
+               pic16_emitIDRegs(of);
        }
        
   fprintf (of, "\tradix dec\n");
@@ -588,6 +542,7 @@ _pic16_genAssemblerPreamble (FILE * of)
 static int
 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
 {
+#if 1
        /* PIC18F family has only two interrupts, the high and the low
         * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
 
@@ -616,7 +571,7 @@ _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
                        fprintf(of, "\tretfie\n");
                }
        }
-
+#endif
   return TRUE;
 }
 
@@ -624,59 +579,63 @@ _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
  * False to convert it to function call */
 static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
 {
-  //  sym_link *test = NULL;
-  //  value *val;
-
-//  fprintf(stderr,"checking for native mult\n");
+//     fprintf(stderr,"checking for native mult for %c (size: %d)\n", ic->op, getSize(OP_SYMBOL(IC_RESULT(ic))->type));
 
-       /* support mul for char/int */
-       if((getSize(OP_SYMBOL(IC_RESULT(ic))->type ) <= 2)
+#if 1
+       /* multiplication is fixed */
+       /* support mul for char/int/long */
+       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) <= 4)
                && (ic->op == '*'))return TRUE;
-       
-       /* support div for char */
-       if((getSize(OP_SYMBOL(IC_RESULT(ic))->type ) < 2)
+#endif
+
+#if 0
+       /* support div for char/int/long */
+       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) <= 0)
                && (ic->op == '/'))return TRUE;
+#endif
        
   return FALSE;
+}
+
 
 #if 0
-  if ( ic->op != '*')
-    {
-      return FALSE;
-    }
+/* Do CSE estimation */
+static bool cseCostEstimation (iCode *ic, iCode *pdic)
+{
+//    operand *result = IC_RESULT(ic);
+//    sym_link *result_type = operandType(result);
 
-  return TRUE;
-/*
-  if ( IS_LITERAL (left))
-    {
-      fprintf(stderr,"left is lit\n");
-      test = left;
-      val = OP_VALUE (IC_LEFT (ic));
-    }
-  else if ( IS_LITERAL (right))
-    {
-      fprintf(stderr,"right is lit\n");
-      test = left;
-      val = OP_VALUE (IC_RIGHT (ic));
-    }
-  else
-    {
-      fprintf(stderr,"oops, neither is lit so no\n");
-      return FALSE;
-    }
 
-  if ( getSize (test) <= 2)
-    {
-      fprintf(stderr,"yep\n");
-      return TRUE;
-    }
-  fprintf(stderr,"nope\n");
+       /* VR -- this is an adhoc. Put here after conversation
+        * with Erik Epetrich */
 
-  return FALSE;
-*/
+       if(ic->op == '<'
+               || ic->op == '>'
+               || ic->op == EQ_OP) {
+
+               fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__);
+         return 0;
+       }
+
+#if 0
+    /* if it is a pointer then return ok for now */
+    if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
+
+    /* if bitwise | add & subtract then no since mcs51 is pretty good at it
+       so we will cse only if they are local (i.e. both ic & pdic belong to
+       the same basic block */
+    if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
+        /* then if they are the same Basic block then ok */
+        if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
+        else return 0;
+    }
 #endif
 
+    /* for others it is cheaper to do the cse */
+    return 1;
 }
+#endif
+
 
 /* Indicate which extended bit operations this port supports */
 static bool
@@ -704,15 +663,15 @@ oclsExpense (struct memmap *oclass)
   return 0;
 }
 
-/** $1 is always the basename.
+/** $1 is the input object file (PIC16 specific)       // >>always the basename<<.
     $2 is always the output file.
     $3 -L path and -l libraries
     $l is the list of extra options that should be there somewhere...
     MUST be terminated with a NULL.
 */
-static const char *_linkCmd[] =
+const char *pic16_linkCmd[] =
 {
-  "gplink", "$3", "\"$1.o\"", "-o $1", "$l", NULL
+  "gplink", "$l", "-o \"$2\"", "\"$1\"","$3", NULL
 };
 
 
@@ -723,9 +682,9 @@ static const char *_linkCmd[] =
     $l is the list of extra options that should be there somewhere...
     MUST be terminated with a NULL.
 */
-static const char *_asmCmd[] =
+const char *pic16_asmCmd[] =
 {
-  "gpasm", "$l", "$3", "-c", "\"$1.asm\"", NULL
+  "gpasm", "$l", "$3", "-c", "\"$1.asm\"", "-o \"$2\"", NULL
 
 };
 
@@ -743,16 +702,16 @@ PORT pic16_port =
     MODEL_SMALL
   },
   {
-    _asmCmd,                   /* assembler command and arguments */
+    pic16_asmCmd,              /* assembler command and arguments */
     NULL,                      /* alternate macro based form */
-    NULL,                      /* arguments for debug mode */
+    "-g",                      /* arguments for debug mode */
     NULL,                      /* arguments for normal mode */
     0,                         /* print externs as global */
     ".asm",                    /* assembler file extension */
     NULL                       /* no do_assemble function */
   },
   {
-    _linkCmd,                  /* linker command and arguments */
+    pic16_linkCmd,             /* linker command and arguments */
     NULL,                      /* alternate macro based form */
     NULL,                      /* no do_link function */
     ".o",                      /* extension for object files */
@@ -808,7 +767,7 @@ PORT pic16_port =
   },
     /* pic16 has an 8 bit mul */
   {
-    1, -1
+     0, -1
   },
   {
     pic16_emitDebuggerSymbol
@@ -817,6 +776,7 @@ PORT pic16_port =
   _pic16_init,
   _pic16_parseOptions,
   pic16_optionsTable,
+  _pic16_initPaths,
   _pic16_finaliseOptions,
   _pic16_setDefaultOptions,
   pic16_assignRegisters,
@@ -843,7 +803,7 @@ PORT pic16_port =
   1,                           /* transform != to !(a == b) */
   0,                           /* leave == */
   FALSE,                        /* No array initializer support. */
-  0,                            /* no CSE cost estimation yet */
+  0,   //cseCostEstimation,            /* !!!no CSE cost estimation yet */
   NULL,                        /* no builtin functions */
   GPOINTER,                    /* treat unqualified pointers as "generic" pointers */
   1,                           /* reset labelKey to 1 */