* src/regression/empty.c: suppress warning
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 May 2008 08:11:40 +0000 (08:11 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 May 2008 08:11:40 +0000 (08:11 +0000)
* src/regression/pointer1.c: enabled index_by_pointer()
* src/regression/inline.c: now works for pic16 as well

* src/pic16/device.c: include dbuf declarations
* src/pic16/device.h: removed obsolete prototypes

* src/pic16/gen.c, src/pic16/gen.h: moved generic pointer tags
* src/pic16/glue.c: made purely local functions static,
  (pic16_printGPointerType, pic16_printIvalCharPtr,
  pic16_printIvalFuncPtr, pic16_printIvalPtr): fixed initialized
  generic pointers' tags (#1961866)

* src/pic16/pcode.c (assignValnums): optimize literal assignments

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

ChangeLog
src/pic16/device.c
src/pic16/device.h
src/pic16/gen.c
src/pic16/gen.h
src/pic16/glue.c
src/pic16/pcode.c
src/regression/empty.c
src/regression/inline.c
src/regression/pointer1.c

index ad4f7521005ce388fb62726ceea04c9288dda2b9..43e1fdde0ffe3c4cf9c18dc25528b8b35def9461 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2008-05-19 Raphael Neider <rneider AT web.de>
+
+       * src/regression/empty.c: suppress warning
+       * src/regression/pointer1.c: enabled index_by_pointer()
+       * src/regression/inline.c: now works for pic16 as well
+
+       * src/pic16/device.c: include dbuf declarations
+       * src/pic16/device.h: removed obsolete prototypes
+
+       * src/pic16/gen.c, src/pic16/gen.h: moved generic pointer tags
+       * src/pic16/glue.c: made purely local functions static,
+         (pic16_printGPointerType, pic16_printIvalCharPtr,
+         pic16_printIvalFuncPtr, pic16_printIvalPtr): fixed initialized
+         generic pointers' tags (#1961866)
+
+       * src/pic16/pcode.c (assignValnums): optimize literal assignments
+
 2008-05-19 Borut Razem <borut.razem AT siol.net>
 
        * support/scripts/sdcc.nsi: remove uninstall.exe after uninstallation,
index c22d8e78cae0c9cf63f89233729e6a5f67f79998..e8ce0575348db29e10f3a48d83d673196f21ced0 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "common.h"   // Include everything in the SDCC src directory
 #include "newalloc.h"
+#include "dbuf_string.h"
 
 
 #include "main.h"
index 5d7e87c576f89755b42f0f890e7b0f364c1a3bc3..0bda0f118f8e8cc39ca411c4577c064178fb20f9 100644 (file)
@@ -128,9 +128,6 @@ void pic16_assignConfigWordValue(int address, unsigned int value);
 void pic16_assignIdByteValue(int address, char value);
 int pic16_isREGinBank(regs *reg, int bank);
 int pic16_REGallBanks(regs *reg);
-int PIC16_IS_CONFIG_ADDRESS(int address);
-int PIC16_IS_IDLOC_ADDRESS(int address);
-int PIC16_IS_HWREG_ADDRESS(int address);
 
 int checkAddReg(set **set, regs *reg);
 int checkAddSym(set **set, symbol *reg);
index 3858e4489d563f25b80752a5170063aafa727730..1176cb87212cc1bdab2b803943a4933fe7b802b8 100644 (file)
 #define PIC_IS_TAGGED(x)        (IS_GENPTR(x) || IS_CODEPTR(x))
 #define IS_DIRECT(op)           ((AOP_TYPE(op) == AOP_PCODE) && (AOP(op)->aopu.pcop->type == PO_DIR))
 
-/* If you change these, you also have to update the library files
- * device/lib/pic16/libsdcc/gptr{get,put}{1,2,3,4}.c */
-#define GPTR_TAG_DATA   0x80
-#define GPTR_TAG_EEPROM 0x40
-#define GPTR_TAG_CODE   0x00    /* must be 0 becaue of UPPER(sym)==0 */
-
 /* Wrapper to execute `code' at most once. */
 #define PERFORM_ONCE(id,code)   do { static char id = 0; if (!id) { id = 1; code } } while (0)
 
index 9411174bc0182833281ded7314549ece0d480728..437fa83b72cf5e5beb99a6e4eb082f58d43b7324 100644 (file)
 #ifndef SDCCGENPIC16_H
 #define SDCCGENPIC16_H
 
+/* If you change these, you also have to update the library files
+ * device/lib/pic16/libsdcc/gptr{get,put}{1,2,3,4}.c */
+#define GPTR_TAG_DATA   0x80
+#define GPTR_TAG_EEPROM 0x40
+#define GPTR_TAG_CODE   0x00    /* must be 0 becaue of UPPER(sym)==0 */
+
 struct pCodeOp;
 
 enum
index 76a883c608b21a733621c81a96d06ba5d77c3710..22ef72f0a29a970e609d0f2565a3efdc780eb3f8 100644 (file)
@@ -374,7 +374,8 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 /*-----------------------------------------------------------------*/
 /* pic16_initPointer - pointer initialization code massaging       */
 /*-----------------------------------------------------------------*/
-value *pic16_initPointer (initList * ilist, sym_link *toType)
+static value *
+pic16_initPointer (initList * ilist, sym_link *toType)
 {
   value *val;
   ast *expr;
@@ -516,7 +517,8 @@ value *pic16_initPointer (initList * ilist, sym_link *toType)
 /*-----------------------------------------------------------------*/
 /* printPointerType - generates ival for pointer type              */
 /*-----------------------------------------------------------------*/
-void _pic16_printPointerType (const char *name, char ptype, void *p)
+static void
+_pic16_printPointerType (const char *name, char ptype, void *p)
 {
   char buf[256];
 
@@ -529,7 +531,8 @@ void _pic16_printPointerType (const char *name, char ptype, void *p)
 /*-----------------------------------------------------------------*/
 /* printPointerType - generates ival for pointer type              */
 /*-----------------------------------------------------------------*/
-void pic16_printPointerType (const char *name, char ptype, void *p)
+static void
+pic16_printPointerType (const char *name, char ptype, void *p)
 {
   _pic16_printPointerType (name, ptype, p);
   //pic16_flushDB(ptype, p); /* breaks char* const arr[] = {&c, &c, &c}; */
@@ -538,7 +541,8 @@ void pic16_printPointerType (const char *name, char ptype, void *p)
 /*-----------------------------------------------------------------*/
 /* printGPointerType - generates ival for generic pointer type     */
 /*-----------------------------------------------------------------*/
-void pic16_printGPointerType (const char *iname, const unsigned int itype,
+static void
+pic16_printGPointerType (const char *iname, const unsigned int itype,
   char ptype, void *p)
 {
   char buf[256];
@@ -547,15 +551,16 @@ void pic16_printGPointerType (const char *iname, const unsigned int itype,
 
   switch (itype)
     {
-    case CPOINTER:
-    case FUNCTION:
+    case CPOINTER: /* fall through */
+    case FUNCTION: /* fall through */
+    case GPOINTER:
+      /* GPTRs pointing to __data space should be reported as POINTERs */
       sprintf (buf, "UPPER(%s)", iname);
       pic16_emitDS (buf, ptype, p);
       break;
 
-    case GPOINTER:
-    case POINTER:
-      sprintf (buf, "0x80");
+    case POINTER: /* __data space */
+      sprintf (buf, "0x%02x", GPTR_TAG_DATA);
       pic16_emitDS (buf, ptype, p);
       break;
 
@@ -569,6 +574,10 @@ void pic16_printGPointerType (const char *iname, const unsigned int itype,
       assert (0);
     }
 
+    if (itype == GPOINTER) {
+      fprintf(stderr, "%s: initialized generic pointer with unknown storage class assumes object in code space\n", __func__);
+    }
+
   //pic16_flushDB(ptype, p); /* might break char* const arr[] = {...}; */
 }
 
@@ -772,7 +781,8 @@ pic16_printIvalArray (symbol * sym, sym_link * type, initList * ilist,
 /*-----------------------------------------------------------------*/
 /* pic16_printIvalBitFields - generate initializer for bitfields   */
 /*-----------------------------------------------------------------*/
-void pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
+static void
+pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
 {
   value *val ;
   symbol *lsym = *sym;
@@ -837,7 +847,8 @@ void pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *
 /*-----------------------------------------------------------------*/
 /* printIvalStruct - generates initial value for structures        */
 /*-----------------------------------------------------------------*/
-void pic16_printIvalStruct (symbol * sym, sym_link * type,
+static void
+pic16_printIvalStruct (symbol * sym, sym_link * type,
                  initList * ilist, char ptype, void *p)
 {
   symbol *sflds;
@@ -876,7 +887,8 @@ void pic16_printIvalStruct (symbol * sym, sym_link * type,
 /*-----------------------------------------------------------------*/
 /* printIvalUnion - generates initial value for unions             */
 /*-----------------------------------------------------------------*/
-void pic16_printIvalUnion (symbol * sym, sym_link * type,
+static void
+pic16_printIvalUnion (symbol * sym, sym_link * type,
                  initList * ilist, char ptype, void *p)
 {
   //symbol *sflds;
@@ -925,7 +937,8 @@ pic16_isUnion( symbol *sym, sym_link *type )
 /*--------------------------------------------------------------------------*/
 /* pic16_printIvalCharPtr - generates initial values for character pointers */
 /*--------------------------------------------------------------------------*/
-int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char ptype, void *p)
+static int
+pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char ptype, void *p)
 {
   int size = 0;
 
@@ -956,14 +969,10 @@ int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char pty
       else if (size == 3)
         {
           int type;
-          if (IS_PTR (val->type)) {
-            type = DCL_TYPE (val->type);
-          } else {
-            type = PTR_TYPE (SPEC_OCLS (val->etype));
-          }
+          type = PTR_TYPE (SPEC_OCLS (val->etype));
           if (val->sym && val->sym->isstrlit) {
             // this is a literal string
-            type=CPOINTER;
+            type = CPOINTER;
           }
           pic16_printGPointerType(val->name, type, ptype, p);
         }
@@ -1008,7 +1017,8 @@ int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char pty
 /*-----------------------------------------------------------------------*/
 /* pic16_printIvalFuncPtr - generate initial value for function pointers */
 /*-----------------------------------------------------------------------*/
-void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void *p)
+static void
+pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void *p)
 {
   value *val;
   int dLvl = 0;
@@ -1029,7 +1039,7 @@ void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void
   }
 
   if (IS_LITERAL(val->etype)) {
-    if (compareType(type, val->etype) == 0) {
+    if (0 && compareType(type, val->etype) == 0) {
       werrorfl (ilist->filename, ilist->lineno, E_INCOMPAT_TYPES);
       printFromToType (val->type, type);
     }
@@ -1046,9 +1056,9 @@ void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void
 
   /* now generate the name */
   if (!val->sym) {
-      pic16_printGPointerType (val->name, DCL_TYPE(val->type), ptype, p);
+      pic16_printGPointerType (val->name, CPOINTER /*DCL_TYPE(val->type)*/, ptype, p);
   } else {
-      pic16_printGPointerType (val->sym->rname, DCL_TYPE(val->type), ptype, p);
+      pic16_printGPointerType (val->sym->rname, CPOINTER /*DCL_TYPE(val->type)*/, ptype, p);
 
       if(IS_FUNC(val->sym->type) && !val->sym->used && !IS_STATIC(val->sym->etype)) {
 
@@ -1070,7 +1080,8 @@ void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void
 /*-----------------------------------------------------------------*/
 /* pic16_printIvalPtr - generates initial value for pointers       */
 /*-----------------------------------------------------------------*/
-void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p)
+static void
+pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p)
 {
   value *val;
   int size;
@@ -1142,8 +1153,9 @@ void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char p
     }
   else if (size == 3)
     {
-      pic16_printGPointerType (val->name, (IS_PTR(type)?DCL_TYPE(type):PTR_TYPE(SPEC_OCLS(sym->etype))),
-                          ptype, p);
+      int itype = 0;
+      itype = PTR_TYPE (SPEC_OCLS (val->etype));
+      pic16_printGPointerType (val->name, itype, ptype, p);
     } else
         assert(0);
   return;
@@ -1240,23 +1252,18 @@ void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptyp
     }
 }
 
-int PIC16_IS_CONFIG_ADDRESS(int address)
+static int
+PIC16_IS_CONFIG_ADDRESS(int address)
 {
   return ((address >= pic16->cwInfo.confAddrStart && address <= pic16->cwInfo.confAddrEnd));
 }
 
-int PIC16_IS_IDLOC_ADDRESS(int address)
+static int
+PIC16_IS_IDLOC_ADDRESS(int address)
 {
    return ((address >= pic16->idInfo.idAddrStart && address <= pic16->idInfo.idAddrEnd));
 }
 
-/* wrapper function for the above */
-int PIC16_IS_HWREG_ADDRESS(int address)
-{
-  return (PIC16_IS_CONFIG_ADDRESS(address) || PIC16_IS_IDLOC_ADDRESS(address));
-}
-
-
 /*-----------------------------------------------------------------*/
 /* emitStaticSeg - emitcode for the static segment                 */
 /*-----------------------------------------------------------------*/
@@ -1687,7 +1694,8 @@ pic16emitOverlay (struct dbuf_s *aBuf)
     }
 }
 
-void emitStatistics(FILE *asmFile)
+static void
+emitStatistics(FILE *asmFile)
 {
   unsigned long isize, udsize, ramsize;
   statistics.isize = pic16_countInstructions();
index f473a88048734401b3a48c990bc3f16f0e47c529..b0d1fceccdc57134add8c243bf18f09601b7576b 100644 (file)
@@ -11695,6 +11695,40 @@ static void assignValnums (pCode *pc) {
       if (val && oldval && (val->in_val != 0) && (val->in_val == oldval->in_val)) {
        //fprintf (stderr, "MOVFW: W already set up correctly (%x) at %p\n", oldval->in_val, pc);
        if (!pic16_isAlive (SPO_STATUS, pc)) pic16_safepCodeRemove (pc, "=DF= redundant MOVFW removed");
+      } else {
+          defmap_t *pred, *predpred;
+          /* Optimize MOVLW immd; MOVWF reg1; [...]; MOVFW reg1
+           * into MOVLW immd; MOVWF reg1; [...]; MOVLW immd
+           * This might allow removal of the first two assignments. */
+          pred = defmapFindDef (list, sym1, pc);
+          predpred = pred ? defmapFindDef (list, SPO_WREG, pred->pc) : NULL;
+          if (pred && predpred && (PCI(pred->pc)->op == POC_MOVWF) && (PCI(predpred->pc)->op == POC_MOVLW)
+                && !pic16_isAlive (SPO_STATUS, pc))
+          {
+              newpc = pic16_newpCode (POC_MOVLW, pic16_pCodeOpCopy (PCI(predpred->pc)->pcop));
+
+              if (pic16_debug_verbose || pic16_pcode_verbose) {
+                  pic16_InsertCommentAfter (pc->prev, "=DF= MOVFW: replaced last of MOVLW;MOVWF;MOVFW by MOVLW");
+              } // if
+              pic16_pCodeReplace (pc, newpc);
+              defmapReplaceSymRef (pc, sym1, 0, 1);
+              pic16_fixDefmap (pc, newpc);
+              pc = newpc;
+
+              /* This breaks the defmap chain's references to pCodes... fix it! */
+              if (!val->prev) PCI(pc)->pcflow->defmap = val->next;
+              if (!val->acc.access.isWrite) {
+                  deleteDefmap (val);  // delete reference to reg1 as in value
+                  val = NULL;
+              } else {
+                  val->acc.access.isRead = 0;  // delete reference to reg1 as in value
+              }
+              oldval = PCI(pc)->pcflow->defmap;
+              while (oldval) {
+                  if (oldval->pc == pc) oldval->pc = newpc;
+                  oldval = oldval->next;
+              } // while
+          } // if
       }
       if (val) defmapUpdate (list, SPO_WREG, pc, val->in_val);
     }
index 6052255934e0170922ecf303920c8d7a60a738c8..fb4fd262a481c916b7e2c82a1fa322288b5ca4dc 100644 (file)
@@ -6,6 +6,7 @@ void foo(void) {
 }
 
 void bar(int arg0) {
+    (void)arg0;
 }
 
 void
index bb86d661a2fa332eb7ed89a7c97ac34be60c8a84..3198d99f09293d5918f3d61d5302ec3efdf2d22a 100644 (file)
@@ -35,12 +35,21 @@ void main(void)
 {
   TRISA = 0x0f;
 
+#if defined(__pic14)
   _asm
     BSF   STATUS,RP0
     MOVF  TRISA,W
     BCF   STATUS,RP0
     MOVWF _test_tris
   _endasm;
+#else   // !defined(__pic14)
+  _asm
+    BANKSEL _TRISA
+    MOVF    _TRISA,W
+    BANKSEL _test_tris
+    MOVWF   _test_tris
+  _endasm;
+#endif  // !defined(__pic14)
 
   if(test_tris != 0x0f)
     failures++;
index a0236b1a8da13f41ea5eee4bf2fbe9a9d5023428..23075b42074f67cf3b426c2a6a209b9da03557fb 100644 (file)
@@ -11,7 +11,7 @@ unsigned char achar0 = 0;
 unsigned char achar1 = 0;
 unsigned char *acharP = 0;
 
-char buff[10];
+unsigned char buff[10];
 
 void
 done()
@@ -92,10 +92,8 @@ void check_array(char base_value)
 
 void index_by_pointer(unsigned char *index, unsigned char expected_value)
 {
-/*
   if(buff[*index] != expected_value)
     failures++;
-*/
 }