* src/port.h (PORT structure): added hook initPaths, now each
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 May 2004 10:30:27 +0000 (10:30 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 May 2004 10:30:27 +0000 (10:30 +0000)
port can declare its own default search paths,
which can been seen with the --print-search-dirs option,
see pic16 port for example,
* src/SDCCmain.c (setBinPaths, setIncludePaths, setLibPath,
setDataPaths): test to options.printSearchDirs is ifdef'ed out,
* (doPrintSearchDirs): NEW, replaces in a central manner the
printing of search dirs which was split in set*Paths functions,
* (main): added call to port->initPaths and doPrintSearchDirs,
* src/avr/main.c,
* src/ds390/main.c,
* src/hc08/main.c,
* src/izt/i186.c,
* src/izt/tlcs900h.c,
* src/mcs51/main.c,
* src/pic/main.c,
* src/pic16/main.c: modified port structures to reflect addition of
initPaths hook,

* src/pic16/device.c (regCompare): registers are finally sorted by name,
* (pic16_dump_section): for registers in same address reserve memory once,
* src/pic16/device.h (struct PIC16_device): changed variable gen_banksel
to no_banksel,
* src/pic16/genarith.c (pic16_genPlus): added code to handle cases where
result is greater in size than right or left,
* (pic16_genUMult8X8_8): there are some cases where the result can
be 16 bits size, so handle these,
* src/pic16/gen.c: changed some pic16_emitpcomment to DEBUGpic16_emitcode,
* (pic16_outBitC): modified to emit pcodes,
* (pic16_storeForReturn): using is_LitOp to see if operand is literal
or not,
* (genDivOneByte): implemented algorithm to divide 8-bits,
* (genCmp): uncommented goto, but issues still exist,
* (genAnd): fixed a bug with variables >8bits,
* (genPackBits): optimization added that uses BCF/BSF to change a
single bit,
* (genAssign): fixed bug when assigning floating point literals,
* src/pic16/glue.c (pic16glue): added assembler directive 'code' before
__sdcc_gsinit_startup label,
* src/pic16/main.c (_pic16_init): removed search directory
initialisations,
* (_pic16_initPaths): NEW, used to initialise search directories,
* (_hasNativeMulFor): support functions for all except char/int
multiplication, and char division,
* (PIC16_port struct): modified entry for native mul support,
* src/pic16/pcode.c (insertBankSwitch): modified to support the renamed
no_banksel option,
* (buildCallTree): call to register_usage is ifdef'ed out,

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3323 4a8a32a2-be11-0410-ad9d-d568d2c75423

19 files changed:
src/SDCCmain.c
src/avr/main.c
src/ds390/main.c
src/hc08/main.c
src/izt/i186.c
src/izt/tlcs900h.c
src/mcs51/main.c
src/pic/main.c
src/pic16/NOTES
src/pic16/device.c
src/pic16/device.h
src/pic16/gen.c
src/pic16/genarith.c
src/pic16/glue.c
src/pic16/main.c
src/pic16/pcode.c
src/pic16/peeph.def
src/pic16/ralloc.c
src/port.h

index 9b720b27f667e2da84a5518f082cb7a1a875b839..999bf9ca98e57492ef398d2c4682b7d178783d6d 100644 (file)
@@ -1900,10 +1900,12 @@ setBinPaths(const char *argv0)
     addSetHead(&binPathSet, Safe_strdup(buf));
   }
 
+#if 0
   if (options.printSearchDirs) {
     printf("programs:\n");
     fputStrSet(stdout, binPathSet);
   }
+#endif
 }
 
 /* Set system include path */
@@ -1926,10 +1928,12 @@ setIncludePath(void)
   if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
     addSetHead(&includeDirsSet, p);
 
+#if 0
   if (options.printSearchDirs) {
     printf("includedir:\n");
     fputStrSet(stdout, includeDirsSet);
   }
+#endif
 }
 
 /* Set system lib path */
@@ -1952,10 +1956,12 @@ setLibPath(void)
   if ((p = getenv(SDCC_LIB_NAME)) != NULL)
     addSetHead(&libDirsSet, p);
 
+#if 0
   if (options.printSearchDirs) {
     printf("libdir:\n");
     fputStrSet(stdout, libDirsSet);
   }
+#endif
 }
 
 /* Set data path */
@@ -1992,10 +1998,12 @@ setDataPaths(const char *argv0)
   addSet(&dataDirsSet, Safe_strdup(DATADIR));
 #endif
 
+#if 0
   if (options.printSearchDirs) {
     printf("datadir:\n");
     fputStrSet(stdout, dataDirsSet);
   }
+#endif
 
   setIncludePath();
   setLibPath();
@@ -2033,6 +2041,22 @@ initValues (void)
 
 }
 
+static void doPrintSearchDirs(void)
+{
+    printf("programs:\n");
+    fputStrSet(stdout, binPathSet);
+
+    printf("datadir:\n");
+    fputStrSet(stdout, dataDirsSet);
+
+    printf("includedir:\n");
+    fputStrSet(stdout, includeDirsSet);
+
+    printf("libdir:\n");
+    fputStrSet(stdout, libDirsSet);
+}
+
+
 static void
 sig_handler (int signal)
 {
@@ -2126,6 +2150,12 @@ main (int argc, char **argv, char **envp)
   setBinPaths(argv[0]);
   setDataPaths(argv[0]);
 
+  if(port->initPaths)
+       port->initPaths();
+  
+  if(options.printSearchDirs)
+       doPrintSearchDirs();
+
   /* if no input then printUsage & exit */
   if (!options.c1mode && !fullSrcFileName && peekSet(relFilesSet) == NULL) {
     if (!options.printSearchDirs)
index d0faac3cdc4d01d97b26a6d997ba2fc67da429c7..9f5a4fcd1c33aa3102cf466e3839057ee90bf9da 100644 (file)
@@ -234,6 +234,7 @@ PORT avr_port = {
        _avr_init,
        _avr_parseOptions,
        NULL,
+       NULL,
        _avr_finaliseOptions,
        _avr_setDefaultOptions,
        avr_assignRegisters,
index 2a9889e3a912db974b12504f07fb921c4663057a..27e4f5fc6aa1ce35c12a2b74e24aecdb7fb8280c 100644 (file)
@@ -874,6 +874,7 @@ PORT ds390_port =
   _ds390_init,
   _ds390_parseOptions,
   NULL,
+  NULL,
   _ds390_finaliseOptions,
   _ds390_setDefaultOptions,
   ds390_assignRegisters,
@@ -1176,6 +1177,7 @@ PORT tininative_port =
   _tininative_init,
   _ds390_parseOptions,
   NULL,
+  NULL,
   _tininative_finaliseOptions,
   _tininative_setDefaultOptions,
   ds390_assignRegisters,
@@ -1393,6 +1395,7 @@ PORT ds400_port =
   _ds390_init,
   _ds390_parseOptions,
   NULL,
+  NULL,
   _ds400_finaliseOptions,
   _ds390_setDefaultOptions,
   ds390_assignRegisters,
index d28b72a51158447c20c45cd813fa9ca9c0676710..5b72405e24ffe8c479f44deacea3f59545627164 100644 (file)
@@ -466,6 +466,7 @@ PORT hc08_port =
   _hc08_init,
   _hc08_parseOptions,
   _hc08_options,
+  NULL,
   _hc08_finaliseOptions,
   _hc08_setDefaultOptions,
   hc08_assignRegisters,
index 57cd968fc17ff55b79eb2629439fd834b7c202fd..1a3f0fe6bff05dcfe3b44db413707b6ef98002aa 100644 (file)
@@ -194,6 +194,7 @@ PORT i186_port = {
     "_",
     _i186_init,
     _i186_parseOptions,
+    NULL,
     _i186_finaliseOptions,
     _i186_setDefaultOptions,
     izt_assignRegisters,
index 732f93a1313bb8af39b6336def3f53a4029988a7..7810233f6843490b04997e912e7242fd637b432d 100644 (file)
@@ -193,6 +193,7 @@ PORT tlcs900h_port =
   "_",
   _tlcs900h_init,
   _tlcs900h_parseOptions,
+  NULL,
   _tlcs900h_finaliseOptions,
   _tlcs900h_setDefaultOptions,
   tlcs900h_assignRegisters,
index d484941277740b3e67c6a56c7d2f0f0371d01fe8..8473028416c1258983ac3a130dcdffeebcae1a53 100644 (file)
@@ -719,6 +719,7 @@ PORT mcs51_port =
   _mcs51_init,
   _mcs51_parseOptions,
   NULL,
+  NULL,
   _mcs51_finaliseOptions,
   _mcs51_setDefaultOptions,
   mcs51_assignRegisters,
index 2d5fedb5ab9b5836cda4ac5c7fe38be3c4be0b95..a15a4684aaa48c8fab7fcd2d2f957df853809aca 100644 (file)
@@ -464,6 +464,7 @@ PORT pic_port =
        _pic14_init,
        _pic14_parseOptions,
        NULL,
+       NULL,
        _pic14_finaliseOptions,
        _pic14_setDefaultOptions,
        pic14_assignRegisters,
index c2ce6ca38cce167212b1c1b6295e77923a120711..0f8574fb3edf2122376299961ab62bd93354f778 100644 (file)
@@ -18,6 +18,19 @@ Scott Dattalo        <scott AT dattalo.com>
 
 ======================================================================
 ======================================================================
+2004-May-23 Vangelis Rokas
+
+1. The improvement of the port has been stalled a bit. But, struct/union
+SFR headers are ready for the PIC18F[45][45][28] chips along with their
+respective sources.
+
+2. The genCmp function should be rewritten from scratch.
+
+3. The internal helper functions for char/int/long/float arithmetic
+now compile and will be placed in the appropriate directory under device/
+
+
+
 2004-Feb-20 Vangelis Rokas
 Major update with many bugfixes.
 
index eb66b6e4a9b4028e6fba752c4abb88e56be74a0f..294fc187bc79789be7b9d059677512d0d00ee113 100644 (file)
@@ -265,7 +265,11 @@ int regCompare(const void *a, const void *b)
        /* and secondarily by size */
        if( (*i)->size > (*j)->size)return 1;
        if( (*i)->size < (*j)->size)return -1;
-
+       
+       /* register size sorting may have strange results use with care */
+       
+       /* finally if in same address and same size sort by name */
+       return (strcmp( (*i)->name, (*j)->name));
 
   return 0;
 }
@@ -299,19 +303,30 @@ void pic16_dump_section(FILE *of, set *section, int fix)
                }
        } else {
          int j=0;
-                 
+         regs *r1;
+         
                rprev = NULL;
                init_addr = rlist[j]->address;
                fprintf(of, "\n\nstatic_%s_%02d\tudata\t0X%04X\n", moduleName, abs_section_no++, init_addr);
        
                for(j=0;j<i;j++) {
                        r = rlist[j];
+                       if(j < i-1)r1 = rlist[j+1]; else r1 = NULL;
+                       
                        init_addr = r->address;
-                       if(rprev && (init_addr != (rprev->address + rprev->size))) {
+
+                       if(rprev && (init_addr != (rprev->address + rprev->size))
+                               && !(r1 && (init_addr != r1->address))) {
                                fprintf(of, "\nstatic_%s_%02d\tudata\t0X%04X\n", moduleName, abs_section_no++, init_addr);
                        }
 
-                       fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+
+                       if(r1 && (init_addr == r1->address)) {
+                               fprintf(of, "%s\tres\t0\n\n", r->name);
+                       } else {
+                               fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       }
+                       
                        rprev = r;
                }
        }
index 62c5fef2503ad906f0f7f0358bdcde6604d0e4f7..ca6e9b36df8ae6875e7f5a9777fdc6c019f96b42 100644 (file)
@@ -56,7 +56,7 @@ typedef struct PIC16_device {
 
 
 typedef struct {
-       int gen_banksel;
+       int no_banksel;
        int opt_banksel;
        int omit_configw;
        int omit_ivt;
index 5ba5432747b5e260276a6d7147f7927c04ee9989..a6291d5557dbb17628cccd0f4463a0621bd142c6 100644 (file)
@@ -82,6 +82,7 @@ static iCode *ifxForOp ( operand *op, iCode *ic );
 void pic16_pushpCodeOp(pCodeOp *pcop);
 void pic16_poppCodeOp(pCodeOp *pcop);
 
+static bool is_LitOp(operand *op);
 
 
 #define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff)
@@ -330,6 +331,7 @@ void pic16_emitcode (char *inst,char *fmt, ...)
 }
 #endif
 
+
 /*-----------------------------------------------------------------*/
 /* pic16_emitDebuggerSymbol - associate the current code location  */
 /*   with a debugger symbol                                        */
@@ -342,6 +344,7 @@ pic16_emitDebuggerSymbol (char * debugSym)
   _G.debugLine = 0;
 }
 
+
 /*-----------------------------------------------------------------*/
 /* getFreePtr - returns r0 or r1 whichever is free or can be pushed*/
 /*-----------------------------------------------------------------*/
@@ -484,12 +487,13 @@ static void resolveIfx(resolvedIfx *resIfx, iCode *ifx)
       resIfx->lbl = IC_FALSE(ifx);
       resIfx->condition = 0;
     }
-/*
+
+#if 1
     if(IC_TRUE(ifx)) 
       DEBUGpic16_emitcode("; ***","ifx true is non-null");
     if(IC_FALSE(ifx)) 
       DEBUGpic16_emitcode("; ***","ifx false is non-null");
-*/
+#endif
   }
 
   DEBUGpic16_emitcode("; ***","%s lbl->key=%d, (lab offset=%d)",__FUNCTION__,resIfx->lbl->key,labelOffset);
@@ -722,7 +726,7 @@ static asmop *aopForRemat (operand *op) // x symbol *sym)
        if(IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))
                || viaimmd) {
 
-               pic16_emitpcomment("%s:%d immediate", __FILE__, __LINE__);
+               DEBUGpic16_emitcode("%s:%d immediate", __FILE__, __LINE__);
 
                aop->aopu.pcop = pic16_popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname, 0, val);
 
@@ -734,7 +738,7 @@ static asmop *aopForRemat (operand *op) // x symbol *sym)
 
                PCOI(aop->aopu.pcop)->index = val;
        } else {
-               pic16_emitpcomment("%s:%d dir", __FILE__, __LINE__);
+               DEBUGpic16_emitcode("%s:%d dir", __FILE__, __LINE__);
 
                aop->aopu.pcop = pic16_popRegFromString(OP_SYMBOL(IC_LEFT(ic))->rname, getSize( OP_SYMBOL( IC_LEFT(ic))->type), val);
 //             aop->size = AOP_SIZE( IC_LEFT(ic) );
@@ -1612,7 +1616,7 @@ pCodeOp *pic16_popGet (asmop *aop, int offset) //, bool bit16, bool dname)
        PCOR(pcop)->instance = offset;
        pcop->type = PCOR(pcop)->r->pc_type;
        rs = aop->aopu.aop_reg[offset]->name;
-       DEBUGpic16_emitcode(";","%d regiser idx = %d name =%s",__LINE__,rIdx,rs);
+       DEBUGpic16_emitcode(";","%d regiser idx = %d name = %s",__LINE__,rIdx,rs);
        return pcop;
       }
 
@@ -2082,19 +2086,31 @@ void pic16_outAcc(operand *result)
 }
 
 /*-----------------------------------------------------------------*/
-/* pic16_outBitC - output a bit C                                        */
+/* pic16_outBitC - output a bit C                                  */
+/*                 Move to result the value of Carry flag -- VR    */
 /*-----------------------------------------------------------------*/
 void pic16_outBitC(operand *result)
 {
+  int i;
 
     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     /* if the result is bit */
-    if (AOP_TYPE(result) == AOP_CRY) 
+    if (AOP_TYPE(result) == AOP_CRY) {
+       fprintf(stderr, "%s:%d: pic16 port warning: unsupported case\n", __FILE__, __LINE__);
         pic16_aopPut(AOP(result),"c",0);
-    else {
+    } else {
+
+       i = AOP_SIZE(result);
+       while(i--) {
+               pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result), i));
+       }
+       pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result), 0));
+       
+/*
         pic16_emitcode("clr","a  ; %d", __LINE__);
         pic16_emitcode("rlc","a");
         pic16_outAcc(result);
+*/
     }
 }
 
@@ -2254,55 +2270,54 @@ static void genUminus (iCode *ic)
   int size, i;
   sym_link *optype, *rtype;
 
+       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+       
+       /* assign asmops */
+       pic16_aopOp(IC_LEFT(ic),ic,FALSE);
+       pic16_aopOp(IC_RESULT(ic),ic,TRUE);
 
-  DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-  /* assign asmops */
-  pic16_aopOp(IC_LEFT(ic),ic,FALSE);
-  pic16_aopOp(IC_RESULT(ic),ic,TRUE);
-
-  /* if both in bit space then special
-     case */
-  if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
-      AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) { 
-
-    pic16_emitpcode(POC_BCF,   pic16_popGet(AOP(IC_RESULT(ic)),0));
-    pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(IC_LEFT(ic)),0));
-    pic16_emitpcode(POC_BSF,   pic16_popGet(AOP(IC_RESULT(ic)),0));
+       /* if both in bit space then special case */
+       if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY
+               && AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) { 
 
-    goto release; 
-  } 
+               pic16_emitpcode(POC_BCF,   pic16_popGet(AOP(IC_RESULT(ic)),0));
+               pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(IC_LEFT(ic)),0));
+               pic16_emitpcode(POC_BSF,   pic16_popGet(AOP(IC_RESULT(ic)),0));
+               
+               goto release; 
+       } 
 
-  optype = operandType(IC_LEFT(ic));
-  rtype = operandType(IC_RESULT(ic));
+       optype = operandType(IC_LEFT(ic));
+       rtype = operandType(IC_RESULT(ic));
 
-  /* if float then do float stuff */
-  if (IS_FLOAT(optype)) {
-    genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
-    goto release;
-  }
+       /* if float then do float stuff */
+       if (IS_FLOAT(optype)) {
+               genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
+               goto release;
+       }
 
-  /* otherwise subtract from zero by taking the 2's complement */
-  size = AOP_SIZE(IC_LEFT(ic));
+       /* otherwise subtract from zero by taking the 2's complement */
+       size = AOP_SIZE(IC_LEFT(ic));
 
-  for(i=0; i<size; i++) {
-    if (pic16_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
-      pic16_emitpcode(POC_COMF,  pic16_popGet(AOP(IC_LEFT(ic)),i));
-    else {
-      pic16_emitpcode(POC_COMFW, pic16_popGet(AOP(IC_LEFT(ic)),i));
-      pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),i));
-    }
-  }
+       for(i=0; i<size; i++) {
+               if (pic16_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
+                       pic16_emitpcode(POC_COMF,  pic16_popGet(AOP(IC_LEFT(ic)),i));
+               else {
+                       pic16_emitpcode(POC_COMFW, pic16_popGet(AOP(IC_LEFT(ic)),i));
+                       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),i));
+               }
+       }
 
-  pic16_emitpcode(POC_INCF,  pic16_popGet(AOP(IC_RESULT(ic)),0));
-  for(i=1; i<size; i++) {
-    emitSKPNZ;
-    pic16_emitpcode(POC_INCF,  pic16_popGet(AOP(IC_RESULT(ic)),i));
-  }
+       pic16_emitpcode(POC_INCF,  pic16_popGet(AOP(IC_RESULT(ic)),0));
+       for(i=1; i<size; i++) {
+               emitSKPNZ;
+               pic16_emitpcode(POC_INCF,  pic16_popGet(AOP(IC_RESULT(ic)),i));
+       }
 
- release:
-  /* release the aops */
-  pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
-  pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);    
+release:
+       /* release the aops */
+       pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
+       pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);    
 }
 
 /*-----------------------------------------------------------------*/
@@ -3589,11 +3604,15 @@ static void genEndFunction (iCode *ic)
 
 void pic16_storeForReturn(operand *op, int offset, pCodeOp *dest)
 {
-//             (AOP(left)->aopu.pcop->type == PO_DIR)?
 
-       if(AOP(op)->aopu.pcop->type == PO_IMMEDIATE) {
+       if(is_LitOp(op))
+//     if((AOP(op)->aopu.pcop->type == PO_IMMEDIATE)
+//             || (AOP(op)->aopu.pcop->type == PO_LITERAL))
+       {
                pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(op), offset)); // patch 12
-               pic16_emitpcode(POC_MOVWF, dest);
+
+               if(dest->type != PO_WREG)
+                       pic16_emitpcode(POC_MOVWF, dest);
        } else {
                pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
                        pic16_popGet(AOP(op), offset), dest));
@@ -3805,62 +3824,6 @@ static void genMultOneByte (operand *left,
        }
        
        pic16_genMult8X8_8 (left, right,result);
-
-
-#if 0
-    pic16_emitcode("multiply (size>1) ","variable :%s by variable %s and store in %s", 
-                  pic16_aopGet(AOP(right),0,FALSE,FALSE), 
-                  pic16_aopGet(AOP(left),0,FALSE,FALSE), 
-                  pic16_aopGet(AOP(result),0,FALSE,FALSE));
-
-    if (SPEC_USIGN(opetype)){
-      pic16_emitcode("multiply ","unsigned result. size = %d",AOP_SIZE(result));
-      pic16_genUMult8X8_16 (left, right, result, NULL);
-
-      if (size > 2) {
-       /* for filling the MSBs */
-       pic16_emitpcode(POC_CLRF,  pic16_popGet(AOP(result),2));
-       pic16_emitpcode(POC_CLRF,  pic16_popGet(AOP(result),3));
-      }
-    }
-    else{
-      pic16_emitcode("multiply ","signed result. size = %d",AOP_SIZE(result));
-
-      pic16_emitcode("mov","a,b");
-
-      /* adjust the MSB if left or right neg */
-
-      /* if one literal */
-      if (AOP_TYPE(right) == AOP_LIT){
-       pic16_emitcode("multiply ","right is a lit");
-       /* AND literal negative */
-       if((int) floatFromVal (AOP(right)->aopu.aop_lit) < 0){
-         /* adjust MSB (c==0 after mul) */
-         pic16_emitcode("subb","a,%s", pic16_aopGet(AOP(left),0,FALSE,FALSE));
-       }
-      }
-      else{
-       pic16_genSMult8X8_16 (left, right, result, NULL);
-      }
-
-      if(size > 2){
-       pic16_emitcode("multiply ","size is greater than 2, so propogate sign");
-       /* get the sign */
-       pic16_emitcode("rlc","a");
-       pic16_emitcode("subb","a,acc");
-      }
-    }
-
-    size -= 2;   
-    offset = 2;
-    if (size > 0)
-      while (size--)
-       pic16_emitcode("multiply ","size is way greater than 2, so propogate sign");
-    //pic16_aopPut(AOP(result),"a",offset++);
-  }
-#endif
-
-
 }
 
 /*-----------------------------------------------------------------*/
@@ -4034,19 +3997,83 @@ static void genDivOneByte (operand *left,
     symbol *lbl ;
     int size,offset;
 
+       /* result = divident / divisor
+        * - divident may be a register or a literal,
+        * - divisor may be a register or a literal,
+        * so there are 3 cases (literal / literal is optimized
+        * by the front-end) to handle.
+        * In addition we must handle signed and unsigned, which
+        * result in 6 final different cases -- VR */
+
     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     size = AOP_SIZE(result) - 1;
     offset = 1;
     /* signed or unsigned */
     if (SPEC_USIGN(opetype)) {
+      pCodeOp *pct1,   /* count */
+               *pct2,  /* reste */
+               *pct3;  /* temp */
+      symbol *label1, *label2, *label3;;
+
+
         /* unsigned is easy */
-        pic16_emitcode("mov","b,%s", pic16_aopGet(AOP(right),0,FALSE,FALSE));
-        l = pic16_aopGet(AOP(left),0,FALSE,FALSE);
-        MOVA(l);        
-        pic16_emitcode("div","ab");
-        pic16_aopPut(AOP(result),"a",0);
-        while (size--)
-            pic16_aopPut(AOP(result),zero,offset++);
+
+       pct1 = pic16_popGetTempReg();
+       pct2 = pic16_popGetTempReg();
+       pct3 = pic16_popGetTempReg();
+       
+       label1 = newiTempLabel(NULL);
+       label2 = newiTempLabel(NULL);
+       label3 = newiTempLabel(NULL);
+
+       /* the following algorithm is extracted from divuint.c */
+
+       pic16_emitpcode(POC_MOVLW, pic16_popGetLit( 8 ));
+       pic16_emitpcode(POC_MOVWF, pic16_pCodeOpCopy( pct1 ));
+       
+       pic16_emitpcode(POC_CLRF, pic16_pCodeOpCopy( pct2 ));
+
+       pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), 0));
+       
+       pic16_emitpLabel(label1->key);
+       
+       emitCLRC;
+       pic16_emitpcode(POC_RLCF, pic16_pCodeOpCopy( pct2 ));
+
+
+       emitCLRC;
+       pic16_emitpcode(POC_RLCF, pic16_popCopyReg( &pic16_pc_wreg ));
+       
+
+       emitSKPNC;
+       pic16_emitpcode(POC_INCF, pic16_pCodeOpCopy( pct2 ));
+       
+       pic16_emitpcode(POC_MOVWF, pic16_pCodeOpCopy( pct3 ));
+       pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), 0));
+       
+       pic16_emitpcode(POC_CPFSLT, pic16_pCodeOpCopy(pct2));
+       pic16_emitpcode(POC_BRA, pic16_popGetLabel(label3->key));
+       pic16_emitpcode(POC_BRA, pic16_popGetLabel(label2->key));
+       
+       pic16_emitpLabel( label3->key );
+       pic16_emitpcode(POC_SUBWF, pic16_pCodeOpCopy(pct2));
+       pic16_emitpcode(POC_INCF, pic16_pCodeOpCopy(pct3));
+       
+       
+
+       pic16_emitpLabel(label2->key);
+       pic16_emitpcode(POC_MOVFW, pic16_pCodeOpCopy(pct3));
+       pic16_emitpcode(POC_DECFSZ, pic16_pCodeOpCopy(pct1));
+       pic16_emitpcode(POC_BRA, pic16_popGetLabel( label1->key ));
+       
+       /* result is in wreg */
+       if(AOP_TYPE(result) != AOP_ACC)
+               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 0));
+
+       pic16_popReleaseTempReg( pct3 );
+       pic16_popReleaseTempReg( pct2 );
+       pic16_popReleaseTempReg( pct1 );
+
         return ;
     }
 
@@ -4115,6 +4142,12 @@ static void genDiv (iCode *ic)
     operand *right = IC_RIGHT(ic);
     operand *result= IC_RESULT(ic);   
 
+
+       /* Division is a very lengthy algorithm, so it is better
+        * to call support routines than inlining algorithm.
+        * Division functions written here just in case someone
+        * wants to inline and not use the support libraries -- VR */
+
     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     /* assign the amsops */
     pic16_aopOp (left,ic,FALSE);
@@ -4562,7 +4595,7 @@ static void genCmp (operand *left,operand *right,
 
       //lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
 
-      DEBUGpic16_emitcode(";right lit","lit = 0x%x,sign=%d",lit,sign);
+      DEBUGpic16_emitcode(";right lit","%d lit = 0x%x,sign=%d",__LINE__, lit,sign);
 
       /* special cases */
 
@@ -4888,8 +4921,8 @@ static void genCmp (operand *left,operand *right,
        }
 
        if(ifx) ifx->generated = 1;
-       //goto check_carry;
-       return;
+       goto check_carry;
+//     return;
 
       } else {
 
@@ -5153,9 +5186,12 @@ static void genCmp (operand *left,operand *right,
 
   }
 
-  // check_carry:
-  if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
+check_carry:
+  if ((AOP_TYPE(result) != AOP_CRY) 
+       && AOP_SIZE(result)) {
     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+//    pic16_emitpLabel( rFalseIfx.lbl->key );
+
     pic16_outBitC(result);
   } else {
     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
@@ -5997,11 +6033,14 @@ static iCode *ifxForOp ( operand *op, iCode *ic )
     /* if this has register type condition and
     the next instruction is ifx with the same operand
     and live to of the operand is upto the ifx only then */
-    if (ic->next &&
-        ic->next->op == IFX &&
-        IC_COND(ic->next)->key == op->key &&
-        OP_SYMBOL(op)->liveTo <= ic->next->seq )
-        return ic->next;
+    if (ic->next
+       && ic->next->op == IFX
+        && IC_COND(ic->next)->key == op->key
+        && OP_SYMBOL(op)->liveTo <= ic->next->seq
+        ) {
+               DEBUGpic16_emitcode(";", "%d %s", __LINE__, __FUNCTION__);
+          return ic->next;
+    }
 
     if (ic->next &&
         ic->next->op == IFX &&
@@ -6053,6 +6092,7 @@ static iCode *ifxForOp ( operand *op, iCode *ic )
 
 //  return ic->next->next;             /* this just might work */ /* FIXME FIXME */
 #endif
+
     return NULL;
 }
 /*-----------------------------------------------------------------*/
@@ -6331,8 +6371,25 @@ static void genAnd (iCode *ic, iCode *ifx)
            pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ic)->key));
          }
 */
+       DEBUGpic16_emitcode("***", "%d %s", __LINE__, __FUNCTION__);
+       size = AOP_SIZE(left);
+
+       {
+         int bp = posbit, ofs=0;
+         
+           while(bp > 7) {
+             bp -= 8;
+             ofs++;
+           }
+       
+         pic16_emitpcode(((rIfx.condition) ? POC_BTFSC : POC_BTFSS),
+                   pic16_newpCodeOpBit(pic16_aopGet(AOP(left),ofs,FALSE,FALSE),bp,0));
+
+       }
+/*
          pic16_emitpcode(((rIfx.condition) ? POC_BTFSC : POC_BTFSS),
                    pic16_newpCodeOpBit(pic16_aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
+*/
          pic16_emitpcode(POC_GOTO,pic16_popGetLabel(rIfx.lbl->key));
          
          ifx->generated = 1;
@@ -9669,14 +9726,30 @@ static void genPackBits (sym_link    *etype ,
        bstr = SPEC_BSTR(etype);
 
        if(AOP_TYPE(right) == AOP_LIT) {
+               if((blen == 1) && (bstr < 8)) {
+                 unsigned long lit;
+                       /* it is a single bit, so use the appropriate bit instructions */
+
+                       DEBUGpic16_emitcode (";","%s %d optimize bit assignment",__FUNCTION__,__LINE__);
+
+                       lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+//                     pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_indf0));
+                       if(lit) {
+                               pic16_emitpcode(POC_BSF,
+                                       pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_indf0), bstr));
+                       } else {
+                               pic16_emitpcode(POC_BCF,
+                                       pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_indf0), bstr));
+                       }
+       
+                 return;
+               }
+
                pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right), 0));
                offset++;
        } else
                pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), offset++));
 
-/*     l = pic16_aopGet(AOP(right),offset++,FALSE,FALSE);
-       MOVA(l);   
-*/
        /* if the bit lenth is less than or    */
        /* it exactly fits a byte then         */
        if((shCnt=SPEC_BSTR(etype))
@@ -9705,28 +9778,6 @@ static void genPackBits (sym_link    *etype ,
                pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_indf0));
 #endif
 
-#if 0
-               pic16_emitcode ("anl","a,#0x%02x",(unsigned char)
-                                       ((unsigned char)(0xFF << (blen+bstr)) | 
-                                       (unsigned char)(0xFF >> (8-bstr)) ) );
-               pic16_emitcode ("orl","a,b");
-               if (p_type == GPOINTER)
-                       pic16_emitcode("pop","b");
-
-               
-               switch (p_type) {
-                       case POINTER:
-                               pic16_emitcode("mov","@%s,a",rname);
-                               break;
-                       case FPOINTER:
-                               pic16_emitcode("movx","@dptr,a");
-                               break;
-                       case GPOINTER:
-                               DEBUGpic16_emitcode(";lcall","__gptrput");
-                               break;
-               }
-#endif
-
          return;
        }
 
@@ -10392,10 +10443,10 @@ static void genAddrOf (iCode *ic)
 
        size = AOP_SIZE(IC_RESULT(ic));
 
-       if(pic16_debug_verbose) {
-               fprintf(stderr, "%s:%d %s symbol %s , codespace=%d\n",
-                       __FILE__, __LINE__, __FUNCTION__, sym->name, IN_CODESPACE( SPEC_OCLS(sym->etype)));
-       }
+//     if(pic16_debug_verbose) {
+//             fprintf(stderr, "%s:%d %s symbol %s , codespace=%d\n",
+//                     __FILE__, __LINE__, __FUNCTION__, sym->name, IN_CODESPACE( SPEC_OCLS(sym->etype)));
+//     }
        
        /* Assume that what we want the address of is in data space
         * since there is no stack on the PIC, yet! -- VR */
@@ -10539,8 +10590,24 @@ static void genAssign (iCode *ic)
   /* general case */
   size = AOP_SIZE(result);
   offset = 0 ;
-  if(AOP_TYPE(right) == AOP_LIT)
-    lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+
+  if(AOP_TYPE(right) == AOP_LIT) {
+       if(!IS_FLOAT(operandType( right )))
+               lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+       else {
+          union {
+             unsigned long lit_int;
+             float lit_float;
+           } info;
+       
+               /* take care if literal is a float */
+               info.lit_float = floatFromVal(AOP(right)->aopu.aop_lit);
+               lit = info.lit_int;
+       }
+  }
+
+//  fprintf(stderr, "%s:%d: assigning value 0x%04lx (%d:%d)\n", __FUNCTION__, __LINE__, lit,
+//                     sizeof(unsigned long int), sizeof(float));
 
 /* VR - What is this?! */
   if( AOP_TYPE(right) == AOP_DIR  && (AOP_TYPE(result) == AOP_REG) && size==1)  {
index a4cfca9ff48b24086e6d7606e8a7890ebfbb7c18..ae71c24a3173c7cbff812e47c89330864f354f15 100644 (file)
@@ -979,10 +979,16 @@ void pic16_genPlus (iCode *ic)
                DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);    
 
                size = min( AOP_SIZE(result), AOP_SIZE(right) );
+               size = min( size, AOP_SIZE(left) );
                offset = 0;
 
-               if(pic16_debug_verbose)
-                       fprintf(stderr, "%s:%d size of operands: %d\n", __FILE__, __LINE__, size);
+               if(pic16_debug_verbose) {
+//                     fprintf(stderr, "%s:%d result: %d\tleft: %d\tright: %d\n", __FILE__, __LINE__,
+//                             AOP_SIZE(result), AOP_SIZE(left), AOP_SIZE(right));
+//                     fprintf(stderr, "%s:%d size of operands: %d\n", __FILE__, __LINE__, size);
+               }
+
+
 
                if ((AOP_TYPE(left) == AOP_PCODE) && (
                                (AOP(left)->aopu.pcop->type == PO_LITERAL) || 
@@ -1068,15 +1074,20 @@ void pic16_genPlus (iCode *ic)
                        } else {
                                // right is signed
                                for(i=size; i< AOP_SIZE(result); i++) {
-                                       pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
-                                       pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size-1,FALSE,FALSE),7,0));
-                                       pic16_emitpcode(POC_COMFW, pic16_popCopyReg(&pic16_pc_wreg));
-                                       if (pic16_sameRegs(AOP(left), AOP(result)))
-                                       {
-                                               pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(left),i));
-                                       } else { // not same
-                                               pic16_emitpcode(POC_ADDFWC, pic16_popGet(AOP(left),i));
-                                               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),i));
+                                       if(size < AOP_SIZE(left)) {
+                                               pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
+                                               pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size-1,FALSE,FALSE),7,0));
+                                               pic16_emitpcode(POC_COMFW, pic16_popCopyReg(&pic16_pc_wreg));
+                                               if (pic16_sameRegs(AOP(left), AOP(result)))
+                                               {
+                                                       pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(left),i));
+                                               } else { // not same
+                                                       pic16_emitpcode(POC_ADDFWC, pic16_popGet(AOP(left),i));
+                                                       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),i));
+                                               }
+                                       } else {
+                                               pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
+                                               pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(result), i));
                                        }
                                }
                        }
@@ -1858,6 +1869,17 @@ void pic16_genUMult8X8_8 (operand *left,
        if(AOP_TYPE(result) != AOP_ACC) {
                pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_prodl),
                        pic16_popGet(AOP(result), 0)));
+
+
+               if(AOP_SIZE(result)>1) {
+                 int i;
+
+                       pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_prodh),
+                       pic16_popGet(AOP(result), 1)));
+                       
+                       for(i=2;i<AOP_SIZE(result);i++)
+                               pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result), i));
+               }
        } else {
                pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_prodl));
        }
index 1d9c80d2e0f71869a88b8ca301f67607f7f581a3..25bf22e38894da115318c11977eeed4aecb04e42 100644 (file)
@@ -32,6 +32,8 @@
 #include "main.h"
 #include <string.h>
 
+#include <string.h>
+
 
 #ifdef WORDS_BIGENDIAN
   #define _ENDIAN(x)  (3-x)
@@ -106,6 +108,11 @@ int pic16aopLiteral (value *val, int offset)
 
 }
 
+iCode *tic;
+symbol *nsym;
+char tbuffer[512], *tbuf=tbuffer;;
+
+
 /*-----------------------------------------------------------------*/
 /* emitRegularMap - emit code for maps with no special cases       */
 /*-----------------------------------------------------------------*/
@@ -299,14 +306,62 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                        if (IS_AGGREGATE (sym->type))
                                ival = initAggregates (sym, sym->ival, NULL);
                        else {
-                               addSet(&idataSymSet, copySymbol(sym));
-                               ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
-                                       decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK));
+#if 0
+                               tic = iCodeFromAst(decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK));
+
+                               if(IS_PTR(sym->type)
+                                       && !IS_CODEPTR(sym->type)
+                                       && IS_AGGREGATE(OP_SYMBOL(IC_LEFT(tic))->type)) {
+                                       
+                                               fprintf(stderr, "symbol %s is a non-code pointer with aggregate initialiser\n", sym->name);
+
+                                               nsym = copySymbol( sym );
+                                               sprintf(tbuffer, "_tempbuf_%s", sym->name);
+                                               strcpy(nsym->name, tbuffer);
+                                               
+//                                             nsym->name = Safe_strdup( tbuf );
+                                               
+                                               codeOutFile = statsg->oFile;
+                                               GcurMemmap = statsg;
+                                               /* assignment of temporary buffer initialiser */
+                                               ival = initAggregates(nsym, nsym->ival, NULL);
+
+/*
+                                               ival = newNode ('=', newAst_VALUE(symbolVal (nsym)),
+                                                       decorateType (resolveSymbols (list2expr (nsym->ival)), RESULT_CHECK));
+*/
+
+                                               fprintf(stderr, "%s:%d: iCode: %s\n", __FILE__, __LINE__,
+                                                       strdup( printILine(iCodeFromAst(ival) )));
+
+                                               eBBlockFromiCode(iCodeFromAst(ival));
+                                               
+                                               /* assignment of symbol to temporary buffer */
+                                               ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
+                                                       newAst_VALUE(symbolVal(nsym)));
+
+                                               fprintf(stderr, "%s:%d: iCode: %s\n", __FILE__, __LINE__,
+                                                       strdup( printILine(iCodeFromAst(ival) )));
+
+
+                                               eBBlockFromiCode(iCodeFromAst(ival));
+                                               
+                                               sym->ival = NULL;
+                                               ival = NULL;
+                               } else {
+#endif
+                                       addSet(&idataSymSet, copySymbol(sym));
+                                       ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
+                                               decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK));
+//                             }
+                       }
+
+                       if(ival) {
+                               codeOutFile = statsg->oFile;
+                               GcurMemmap = statsg;
+                               eBBlockFromiCode (iCodeFromAst (ival));
+                               sym->ival = NULL;
                        }
-                       codeOutFile = statsg->oFile;
-                       GcurMemmap = statsg;
-                       eBBlockFromiCode (iCodeFromAst (ival));
-                       sym->ival = NULL;
                }
 #endif
        }
@@ -1095,7 +1150,8 @@ pic16glue ()
 
 
        if(mainf && IFFUNC_HASBODY(mainf->type)) {
-               fprintf (asmFile,"__sdcc_gsinit_startup:\t\t;VRokas\n");
+               fprintf(asmFile, "\tcode\n");
+               fprintf(asmFile,"__sdcc_gsinit_startup:\n");
 
 #if 0
                /* FIXME 8051 legacy (?!) - VR 20-Jun-2003 */
index d295080d1ad48cc608923ccc8a8bec9b50e587fb..df0b1a49bc53e3128c09c17f78a0699d35a0554b 100644 (file)
@@ -82,24 +82,62 @@ 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 *);
 
 static void
 _pic16_init (void)
 {
+#if 0
+  char pic16incDir[512];
+  char pic16libDir[512];
+  set *pic16incDirsSet;
+  set *pic16libDirsSet;
+  char devlib[512];
+#endif
+
        asm_addTree (&asm_asxxxx_mapping);
        pic16_pCodeInitRegisters();
        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' */
+
+
+#if 0
+       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);
+
+       if(!options.nostdinc) {
+               /* setup pic16 include directory */
+               pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
+               mergeSets(&includeDirsSet, pic16incDirsSet);
+       }
+       
+       if(!options.nostdlib) {
+               /* 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));
+       }
+#endif
 }
 
 static void
@@ -184,23 +222,6 @@ _process_pragma(const char *sz)
 }
 
 #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="
@@ -211,7 +232,7 @@ extern int pic16_ralloc_debug;
 extern int pic16_pcode_verbose;
 
 OPTION pic16_optionsTable[]= {
-       { 0,    "--pgen-banksel",       &pic16_options.gen_banksel,     "generate BANKSEL assembler directives"},
+       { 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 +245,6 @@ 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,    NULL,           NULL,   NULL}
        };
 
@@ -261,7 +258,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,137 +294,64 @@ _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));
-               return TRUE;
-       }
-       
-       if(ISOPT(AT_UDATASHR)) {
-               pic16_sectioninfo.at_udatashr = Safe_strdup( getStringArg(AT_UDATASHR, 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));
-               return TRUE;
-       }
+  return FALSE;
+}
 
-       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;
-       }
+static void _pic16_initPaths(void)
+{
+#if 1
+  char pic16incDir[512];
+  char pic16libDir[512];
+  set *pic16incDirsSet;
+  set *pic16libDirsSet;
+  char devlib[512];
+#endif
 
-       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 1
+       setMainValue("mcu", pic16->name[2] );
+       addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
 
-       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;
-       }
+       sprintf(pic16incDir, "%s/pic16", INCLUDE_DIR_SUFFIX);
+       sprintf(pic16libDir, "%s/pic16", LIB_DIR_SUFFIX);
 
-       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(!options.nostdinc) {
+               /* setup pic16 include directory */
+               pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
+               mergeSets(&includeDirsSet, pic16incDirsSet);
        }
-
-       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;
+       
+       if(!options.nostdlib) {
+               /* 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));
        }
-
-       deleteSet( &tset );
 #endif
-
-  return FALSE;
 }
 
-extern set *includeDirsSet;
-extern set *dataDirsSet;
-extern set *libFilesSet;
 
 static void
 _pic16_finaliseOptions (void)
 {
+#if 0
   char pic16incDir[512];
   char pic16libDir[512];
   set *pic16incDirsSet;
   set *pic16libDirsSet;
   char devlib[512];
-
+#endif
        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;
+//     options.float_rent = 1;
+//     options.intlong_rent = 1;
        
-       setMainValue("mcu", pic16->name[2] );
+#if 0
+       setMainValue("mcu", pic16->name[2] );
        addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
 
        sprintf(pic16incDir, "%s/pic16", INCLUDE_DIR_SUFFIX);
@@ -449,6 +372,7 @@ _pic16_finaliseOptions (void)
                sprintf(devlib, "%s.lib", pic16->name[2]);
                addSet(&libFilesSet, Safe_strdup(devlib));
        }
+#endif
 }
 
 
@@ -534,6 +458,16 @@ _pic16_setDefaultOptions (void)
        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' */
 }
 
 static const char *
@@ -588,6 +522,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 +551,7 @@ _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
                        fprintf(of, "\tretfie\n");
                }
        }
-
+#endif
   return TRUE;
 }
 
@@ -624,59 +559,58 @@ _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 for %c (size: %d)\n", ic->op, getSize(OP_SYMBOL(IC_RESULT(ic))->type));
 
-//  fprintf(stderr,"checking for native mult\n");
-
-       /* support mul for char/int */
-       if((getSize(OP_SYMBOL(IC_RESULT(ic))->type ) <= 2)
+       /* support mul for char/int {/long} */
+       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2)
                && (ic->op == '*'))return TRUE;
        
-       /* support div for char */
-       if((getSize(OP_SYMBOL(IC_RESULT(ic))->type ) < 2)
+       /* support div for char/int/long */
+       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0)
                && (ic->op == '/'))return TRUE;
        
   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
@@ -808,7 +742,7 @@ PORT pic16_port =
   },
     /* pic16 has an 8 bit mul */
   {
-    1, -1
+     0, -1
   },
   {
     pic16_emitDebuggerSymbol
@@ -817,6 +751,7 @@ PORT pic16_port =
   _pic16_init,
   _pic16_parseOptions,
   pic16_optionsTable,
+  _pic16_initPaths,
   _pic16_finaliseOptions,
   _pic16_setDefaultOptions,
   pic16_assignRegisters,
@@ -843,7 +778,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 */
index 743b214e972afe8bdb3677824557e694396adac0..49d1862e18230c705654b804ccec8b5905101653 100644 (file)
@@ -5822,7 +5822,7 @@ static void insertBankSwitch(int position, pCode *pc, int bsr)
  * bank at linking time
  */
 
-       if(!pic16_options.gen_banksel || bsr != -1) {
+       if(pic16_options.no_banksel || bsr != -1) {
 //             new_pc = pic16_newpCode(POC_MOVLB, pic16_newpCodeOpLit(bsr));
                return;
        } else {
@@ -6337,7 +6337,7 @@ static void pic16_FixRegisterBanking(pBlock *pb)
                         * before SKIP, but we have to check if the SKIP uses BANKSEL, etc... */
                        if(!pcprev || (pcprev && !isPCI_SKIP(pcprev))) {
                                prevreg = reg;
-                               insertBankSwitch(0, pc, (pic16_options.gen_banksel)?-1:0);
+                               insertBankSwitch(0, pc, (pic16_options.no_banksel)?0:-1);
                        }
                }
 
@@ -6692,6 +6692,11 @@ static void buildCallTree(void    )
     }
   }
 
+
+#if 0
+  /* This is not needed because currently all register used
+   * by a function are stored in stack -- VR */
+   
   /* Re-allocate the registers so that there are no collisions
    * between local variables when one function call another */
 
@@ -6702,6 +6707,7 @@ static void buildCallTree(void    )
     if(!pb->visited)
       register_usage(pb);
   }
+#endif
 
 }
 
index 15987cef412c858ed30390ce8931d4fd198b352c..6189beb920aee74664141c919a2822137d5d5108 100644 (file)
@@ -286,7 +286,7 @@ replace restart {
 }
 
 
-// From: Vangelis Rokas (vrokas@otenet.gr)
+// From: Vangelis Rokas (vrokas AT otenet dot gr)
 // movff peeps are disabled for the moment
 // until support is added in the pcodepeeph.c
 
index 1fd35e61ff2a3f1c0b894d2bc610c79673825dfe..655a3d5821fcf08f448bf91c1764b0c19c60efe1 100644 (file)
@@ -361,8 +361,6 @@ regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alia
 
        dReg->isFree = 0;
        dReg->wasUsed = 1;
-
-//     dReg->isMapped = 0;
        dReg->isEmitted = 0;
 
        if(type == REG_SFR) {
@@ -470,10 +468,10 @@ pic16_allocInternalRegister(int rIdx, char * name, short po_type, int alias)
 
 //  fprintf(stderr,"%s:%d: %s  %s addr =0x%x\n",__FILE__, __LINE__, __FUNCTION__, name, rIdx);
 
-  if(reg) {
-    reg->wasUsed = 0;
-    return addSet(&pic16_dynInternalRegs,reg);
-  }
+    if(reg) {
+      reg->wasUsed = 0;
+      return addSet(&pic16_dynInternalRegs,reg);
+    }
 
   return NULL;
 }
@@ -493,10 +491,17 @@ allocReg (short type)
        /* try to reuse some unused registers */
        reg = regFindFree( pic16_dynAllocRegs );
 
+       if(reg) {
+//             fprintf(stderr, "%s: found FREE register %s\n", __FILE__, reg->name);
+       }
+
        if(!reg) {
                reg = newReg(REG_GPR, PO_GPR_TEMP, dynrIdx++, NULL, 1, 0, NULL);
-               addSet(&pic16_dynAllocRegs, reg);
+//             addSet(&pic16_dynAllocRegs, reg);
        }
+
+       addSet(&pic16_dynAllocRegs, reg);
+
        reg->isFree=0;
 
 //     debugLog ("%s of type %s\n", __FUNCTION__, debugLogRegType (type));
@@ -649,8 +654,8 @@ pic16_allocDirReg (operand *op )
                 * dynDirectRegNames set */
                if(IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) {
                        if(pic16_debug_verbose)
-                               fprintf(stderr, "%s:%d symbol %s in codespace\n", __FILE__, __LINE__,
-                                       OP_SYMBOL(op)->name);
+//                             fprintf(stderr, "%s:%d symbol %s in codespace\n", __FILE__, __LINE__,
+//                                     OP_SYMBOL(op)->name);
                        debugLog("%s:%d sym: %s in codespace\n", __FUNCTION__, __LINE__, OP_SYMBOL(op)->name);
                  return NULL;
                }
@@ -753,7 +758,7 @@ pic16_allocRegByName (char *name, int size)
     reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,size,0, NULL);
 
     debugLog ("%d  -- added %s to hash, size = %d\n", __LINE__, name,reg->size);
-    //fprintf(stderr, "  -- added %s to hash, size = %d\n", name,reg->size);
+       //fprintf(stderr, "  -- added %s to hash, size = %d\n", name,reg->size);
 
     //hTabAddItem(&dynDirectRegNames, regname2key(name), reg); /* initially commented out */
     addSet(&pic16_dynDirectRegs, reg);
index 2005ddfd89a30cd477db76a6f33fdebb7e28f77b..605ddf51dfb6bc87ecdc9448b0a4a5ae7f87f672 100644 (file)
@@ -226,6 +226,8 @@ typedef struct
 /** Optional list of automatically parsed options.  Should be
     implemented to at least show the help text correctly. */
     OPTION *poptions;
+/** Initialise port spectific paths */
+    void (*initPaths)(void);
 /** Called after all the options have been parsed. */
     void (*finaliseOptions) (void);
     /** Called after the port has been selected but before any