* .version: increased version number to 2.4.2,
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 8 Jun 2004 14:30:25 +0000 (14:30 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 8 Jun 2004 14:30:25 +0000 (14:30 +0000)
Cumulative patch for pic16 port
* src/pic16/device.c: changed scheme to dump initial values for
variables in idata segment, all print_idata* functions were removed,
now the pic16_printIval* will be called,
* src/pic16/glue.c: (pic16_initPointer, pic16_pointerTypeToGPByte,
* _pic16_printPointerType, pic16_printPointerType,
* pic16_printGPointerType, pic16_printIvalArray, pic16_printIvalStruct,
* pic16_printIvalBitFields, pic16_printIvalFuncPtr, pic16_printIvalPtr:
NEW, similar to the respective functions in SDCCglue.c,
* src/pic16/pcode.c (pic16_emitDB, pic16_flushDB): reverted to old
way, emitting hex bytes,
* (pic16_emitDS): NEW, emits a string for pointer initialisation,

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

.version
ChangeLog
src/pic16/device.c
src/pic16/glue.c
src/pic16/pcode.c
src/pic16/pcode.h

index 005119baaa0653ca59d923010341d8341daa8c43..8e8299dcc068356889b365e23c948b92c6dfcd78 100644 (file)
--- a/.version
+++ b/.version
@@ -1 +1 @@
-2.4.1
+2.4.2
index 1f5c40e1950411478bf1f5a77e8c19d80a8eb311..47f770c60216a4d6206873d4ce69068bae41b44a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2004-06-07 Vangelis Rokas <vrokas AT otenet.gr>
+
+       * .version: increased version number to 2.4.2,
+
+       Cumulative patch for pic16 port
+       * src/pic16/device.c: changed scheme to dump initial values for
+       variables in idata segment, all print_idata* functions were removed,
+       now the pic16_printIval* will be called,
+       * src/pic16/glue.c: (pic16_initPointer, pic16_pointerTypeToGPByte,
+       * _pic16_printPointerType, pic16_printPointerType,
+       * pic16_printGPointerType, pic16_printIvalArray, pic16_printIvalStruct,
+       * pic16_printIvalBitFields, pic16_printIvalFuncPtr, pic16_printIvalPtr:
+       NEW, similar to the respective functions in SDCCglue.c,
+       * src/pic16/pcode.c (pic16_emitDB, pic16_flushDB): reverted to old
+       way, emitting hex bytes,
+       * (pic16_emitDS): NEW, emits a string for pointer initialisation,
+
 2004-06-08 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
 
        * src/avr/ralloc.c (serialRegAssign),
index f63d5095ebede308303a215e72d6bae59227b497..730ea9e809a9ddbec2849c7a33a24bd4f69ac4d5 100644 (file)
@@ -511,7 +511,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
 
 
 /* forward declaration */
-void print_idata(FILE *of, symbol * sym, sym_link * type, initList * ilist);
+void pic16_printIval(symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
 
 void pic16_dump_isection(FILE *of, set *section, int fix)
 {
@@ -535,10 +535,14 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
        /* sort symbols according to their address */
        qsort(slist, i, sizeof(symbol *), symCompare);
        
+       pic16_initDB();
+
        if(!fix) {
                fprintf(of, "\n\n\tidata\n");
                for(s = setFirstItem(section); s; s = setNextItem(section)) {
-                       print_idata(of, s, s->type, s->ival);
+                       fprintf(of, "%s", s->rname);
+                       pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
+                       pic16_flushDB('f', (void *)of);
                }
        } else {
          int j=0;
@@ -558,16 +562,10 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
                                fprintf(of, "\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
                        }
 
-                       print_idata(of, s, s->type, s->ival);
-                       
-#if 0
-                       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);
-                       }
-#endif
-                       
+                       fprintf(of, "%s", s->rname);
+                       pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
+                       pic16_flushDB('f', (void *)of);
+
                        sprev = s;
                }
        }
@@ -615,250 +613,6 @@ void pic16_dump_int_registers(FILE *of, set *section)
 #define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff)
 
 
-
-/*-----------------------------------------------------------------*/
-/* printIvalType - generates ival for int/char                     */
-/*-----------------------------------------------------------------*/
-void print_idataType (FILE *of, symbol *sym, sym_link * type, initList * ilist)
-{
-  value *val;
-  unsigned long ulval;
-
-  //fprintf(stderr, "%s\n",__FUNCTION__);
-
-  /* if initList is deep */
-  if (ilist->type == INIT_DEEP)
-    ilist = ilist->init.deep;
-
-  if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) {
-    werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef);
-  }
-
-  if (!(val = list2val (ilist))) {
-    // assuming a warning has been thrown
-    val=constVal("0");
-  }
-
-  if (val->type != type) {
-    val = valCastLiteral(type, floatFromVal(val));
-  }
-
-  if(val) 
-    ulval = (unsigned long) floatFromVal (val);
-  else
-    ulval =0;
-
-  switch (getSize (type)) {
-    case 1:
-       if(isprint(BYTE_IN_LONG(ulval, 0)))
-               fprintf(of, "%s\tdata\t\"%c\"\n", sym->rname, (unsigned char)BYTE_IN_LONG(ulval, 0));
-       else
-               fprintf(of, "%s\tdata\t0x%02x\n", sym->rname, (unsigned char)BYTE_IN_LONG(ulval, 0));
-//     pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
-       break;
-
-    case 2:
-       fprintf(of, "%s\tdw\t0x%02x, 0x%02x\n", sym->rname, (unsigned int)(BYTE_IN_LONG(ulval, 0)),
-                                       (unsigned int)(BYTE_IN_LONG(ulval, 1)));
-//     fprintf(of, "%s\tdata\t0x%04x\n", sym->rname, (unsigned int)BYTE_IN_LONG(ulval, 0) +
-//                                     (unsigned int)(BYTE_IN_LONG(ulval, 1) << 8));
-       break;
-
-    case 4:
-       fprintf(of, "%s\tdw\t0x%04x,0x%04x\n", sym->rname, (unsigned int)(BYTE_IN_LONG(ulval, 0)
-                                       + (BYTE_IN_LONG(ulval, 1) << 8)),
-                                       (unsigned)(BYTE_IN_LONG(ulval, 2)
-                                       + (BYTE_IN_LONG(ulval, 3) << 8)));
-//     pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
-//     pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1))));
-//     pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2))));
-//     pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3))));
-       break;
-  }
-}
-
-
-/*-----------------------------------------------------------------*/
-/* print_idataChar - generates initital value for character array    */
-/*-----------------------------------------------------------------*/
-static int 
-print_idataChar (FILE *of, symbol *sym, sym_link * type, initList * ilist, char *s)
-{
-  value *val;
-  int remain;
-  char old_ch=0, *vchar;
-
-  // fprintf(stderr, "%s\n",__FUNCTION__);
-  if (!s)
-    {
-
-      val = list2val (ilist);
-      /* if the value is a character string  */
-      if (IS_ARRAY (val->type) && IS_CHAR (val->etype))
-       {
-         if (!DCL_ELEM (type))
-           DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
-
-
-         fprintf(of, "%s\tdata\t", sym->rname);
-         vchar = SPEC_CVAL(val->etype).v_char;
-         for(remain=0; remain<DCL_ELEM(type); remain++) {
-               if(!isprint(old_ch)) {
-                       if(isprint(vchar[remain]))fprintf(of, "%s\"%c", (remain?", ":""), vchar[remain]);
-                       else fprintf(of, "0x%02x", vchar[remain]);
-               } else
-                       if(!isprint(vchar[remain]))fprintf(of, "\", 0x%02x", vchar[remain]);
-                       else fprintf(of, "%c", vchar[remain]);
-               old_ch = vchar[ remain ];
-         }
-//          fprintf(of, "0x%02x%s", SPEC_CVAL(val->etype).v_char[ remain ], (remain==DCL_ELEM(type)-1?"":","));
-                       
-
-         if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0)
-            {
-             while (remain--)
-                {
-                 fprintf(of, "0x%02x%s", 0x00 /*SPEC_CVAL(val->etype).v_char[ remain ]*/ , (remain==DCL_ELEM(type)-1?"":","));
-                }
-            }
-               fprintf(of, "\n");
-         return 1;
-       }
-      else
-       return 0;
-    }
-  else {
-    fprintf(of, "%s\tdata\t", sym->rname);
-    vchar = s; old_ch = 0;
-    for(remain=0; remain<strlen(s); remain++) 
-      {
-       if(!isprint(old_ch)) {
-               if(isprint(vchar[remain]))fprintf(of, "%s\"%c", (remain?", ":""), vchar[remain]);
-               else fprintf(of, "0x%02x", vchar[remain]);
-       } else
-               if(!isprint(vchar[remain]))fprintf(of, "\", 0x%02x", vchar[remain]);
-               else fprintf(of, "%c", vchar[remain]);
-       old_ch = vchar[ remain ];
-//     fprintf(of, "0x%02x%s", s[ remain ], (remain==strlen(s)-1?"":","));
-      }
-  }
-  return 1;
-}
-
-/*-----------------------------------------------------------------*/
-/* print_idataArray - generates code for array initialization        */
-/*-----------------------------------------------------------------*/
-static void 
-print_idataArray (FILE *of, symbol * sym, sym_link * type, initList * ilist)
-{
-  initList *iloop;
-  int lcnt = 0, size = 0;
-
-  /* take care of the special   case  */
-  /* array of characters can be init  */
-  /* by a string                      */
-  if (IS_CHAR (type->next)) {
-//    fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__);
-    if (!IS_LITERAL(list2val(ilist)->etype)) {
-      werror (W_INIT_WRONG);
-      return;
-    }
-    if (print_idataChar (of, sym, type,
-                      (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
-                      SPEC_CVAL (sym->etype).v_char))
-      return;
-  }
-  /* not the special case             */
-  if (ilist->type != INIT_DEEP)
-    {
-      werror (E_INIT_STRUCT, sym->name);
-      return;
-    }
-
-  iloop = ilist->init.deep;
-  lcnt = DCL_ELEM (type);
-
-  for (;;)
-    {
-      //fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__);
-      size++;
-      print_idata (of, sym, type->next, iloop);
-      iloop = (iloop ? iloop->next : NULL);
-
-
-      /* if not array limits given & we */
-      /* are out of initialisers then   */
-      if (!DCL_ELEM (type) && !iloop)
-       break;
-
-      /* no of elements given and we    */
-      /* have generated for all of them */
-      if (!--lcnt) {
-       /* if initializers left */
-       if (iloop) {
-         werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
-       }
-       break;
-      }
-    }
-
-  /* if we have not been given a size  */
-  if (!DCL_ELEM (type))
-    DCL_ELEM (type) = size;
-
-  return;
-}
-
-/*-----------------------------------------------------------------*/
-/* print_idata - generates code for initial value                    */
-/*-----------------------------------------------------------------*/
-void print_idata(FILE *of, symbol * sym, sym_link * type, initList * ilist)
-{
-  if (!ilist)
-    return;
-
-  /* if structure then    */
-  if (IS_STRUCT (type))
-    {
-      //fprintf(stderr,"%s struct\n",__FUNCTION__);
-      //printIvalStruct (sym, type, ilist, oFile);
-      fprintf(stderr, "%s:%d: PIC16 port error: structure initialisation is not implemented yet.\n",
-       __FILE__, __LINE__);
-      abort();
-      return;
-    }
-
-  /* if this is a pointer */
-  if (IS_PTR (type))
-    {
-      //fprintf(stderr,"%s pointer\n",__FUNCTION__);
-      //printIvalPtr (sym, type, ilist, oFile);
-      fprintf(stderr, "%s:%d: PIC16 port error: pointer initialisation is not immplemented yet.\n",
-       __FILE__, __LINE__);
-      abort();
-      return;
-    }
-
-  /* if this is an array   */
-  if (IS_ARRAY (type))
-    {
-      //fprintf(stderr,"%s array\n",__FUNCTION__);
-      print_idataArray (of, sym, type, ilist);
-      return;
-    }
-
-  /* if type is SPECIFIER */
-  if (IS_SPEC (type))
-    {
-//     fprintf(stderr,"%s spec\n",__FUNCTION__);
-      print_idataType(of, sym, type, ilist);
-      return;
-    }
-}
-
-
-
-
 /*-----------------------------------------------------------------*
  *  void pic16_list_valid_pics(int ncols, int list_alias)
  *
index 52e6d7799db94702a7e2e3f4fc2c7fafb0db6342..4c60e4d5dce7433c20e3857d2391084a7d3e7f6a 100644 (file)
@@ -44,7 +44,7 @@
 #define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff)
 
 extern symbol *interrupts[256];
-static void printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb);
+void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
 extern int noAlloc;
 extern set *publics;
 extern set *externs;
@@ -321,7 +321,10 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                        }
 #endif
 
-//                     fprintf(stderr, "'%s': sym '%s' has initial value\n", map->sname, sym->name);
+#if 0
+                       fprintf(stderr, "'%s': sym '%s' has initial value SPEC_ABSA: %d, IS_AGGREGATE: %d\n",
+                               map->sname, sym->name, SPEC_ABSA(sym->etype), IS_AGGREGATE(sym->type));
+#endif
 
                        if (IS_AGGREGATE (sym->type)) {
                                if(SPEC_ABSA(sym->etype))
@@ -352,10 +355,219 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 
 
 /*-----------------------------------------------------------------*/
-/* printIvalType - generates ival for int/char                     */
+/* pic16_initPointer - pointer initialization code massaging       */
+/*-----------------------------------------------------------------*/
+value *pic16_initPointer (initList * ilist, sym_link *toType)
+{
+  value *val;
+  ast *expr;
+
+  if (!ilist) {
+      return valCastLiteral(toType, 0.0);
+  }
+
+  expr = list2expr (ilist);
+  
+  if (!expr)
+    goto wrong;
+  
+  /* try it the old way first */
+  if ((val = constExprValue (expr, FALSE)))
+    return val;
+  
+  /* ( ptr + constant ) */
+  if (IS_AST_OP (expr) &&
+      (expr->opval.op == '+' || expr->opval.op == '-') &&
+      IS_AST_SYM_VALUE (expr->left) &&
+      (IS_ARRAY(expr->left->ftype) || IS_PTR(expr->left->ftype)) &&
+      compareType(toType, expr->left->ftype) &&
+      IS_AST_LIT_VALUE (expr->right)) {
+    return valForCastAggr (expr->left, expr->left->ftype,
+                           expr->right,
+                           expr->opval.op);
+  }
+  
+  /* (char *)&a */
+  if (IS_AST_OP(expr) && expr->opval.op==CAST &&
+      IS_AST_OP(expr->right) && expr->right->opval.op=='&') {
+    if (compareType(toType, expr->left->ftype)!=1) {
+      werror (W_INIT_WRONG);
+      printFromToType(expr->left->ftype, toType);
+    }
+    // skip the cast ???
+    expr=expr->right;
+  }
+
+  /* no then we have to do these cludgy checks */
+  /* pointers can be initialized with address of
+     a variable or address of an array element */
+  if (IS_AST_OP (expr) && expr->opval.op == '&') {
+    /* address of symbol */
+    if (IS_AST_SYM_VALUE (expr->left)) {
+      val = copyValue (AST_VALUE (expr->left));
+      val->type = newLink (DECLARATOR);
+      if (SPEC_SCLS (expr->left->etype) == S_CODE) {
+        DCL_TYPE (val->type) = CPOINTER;
+        DCL_PTR_CONST (val->type) = port->mem.code_ro;
+      }
+      else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
+        DCL_TYPE (val->type) = FPOINTER;
+      else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
+        DCL_TYPE (val->type) = PPOINTER;
+      else if (SPEC_SCLS (expr->left->etype) == S_IDATA)
+        DCL_TYPE (val->type) = IPOINTER;
+      else if (SPEC_SCLS (expr->left->etype) == S_EEPROM)
+        DCL_TYPE (val->type) = EEPPOINTER;
+      else
+        DCL_TYPE (val->type) = POINTER;
+      val->type->next = expr->left->ftype;
+      val->etype = getSpec (val->type);
+      return val;
+    }
+
+    /* if address of indexed array */
+    if (IS_AST_OP (expr->left) && expr->left->opval.op == '[')
+      return valForArray (expr->left);
+
+    /* if address of structure element then
+       case 1. a.b ; */
+    if (IS_AST_OP (expr->left) &&
+        expr->left->opval.op == '.') {
+      return valForStructElem (expr->left->left,
+                               expr->left->right);
+    }
+
+    /* case 2. (&a)->b ;
+       (&some_struct)->element */
+    if (IS_AST_OP (expr->left) &&
+        expr->left->opval.op == PTR_OP &&
+        IS_ADDRESS_OF_OP (expr->left->left)) {
+      return valForStructElem (expr->left->left->left,
+                               expr->left->right);
+    }
+  }
+  /* case 3. (((char *) &a) +/- constant) */
+  if (IS_AST_OP (expr) &&
+      (expr->opval.op == '+' || expr->opval.op == '-') &&
+      IS_AST_OP (expr->left) && expr->left->opval.op == CAST &&
+      IS_AST_OP (expr->left->right) &&
+      expr->left->right->opval.op == '&' &&
+      IS_AST_LIT_VALUE (expr->right)) {
+
+    return valForCastAggr (expr->left->right->left,
+                           expr->left->left->opval.lnk,
+                           expr->right, expr->opval.op);
+
+  }
+  /* case 4. (char *)(array type) */
+  if (IS_CAST_OP(expr) && IS_AST_SYM_VALUE (expr->right) &&
+      IS_ARRAY(expr->right->ftype)) {
+
+    val = copyValue (AST_VALUE (expr->right));
+    val->type = newLink (DECLARATOR);
+    if (SPEC_SCLS (expr->right->etype) == S_CODE) {
+      DCL_TYPE (val->type) = CPOINTER;
+      DCL_PTR_CONST (val->type) = port->mem.code_ro;
+    }
+    else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
+      DCL_TYPE (val->type) = FPOINTER;
+    else if (SPEC_SCLS (expr->right->etype) == S_XSTACK)
+      DCL_TYPE (val->type) = PPOINTER;
+    else if (SPEC_SCLS (expr->right->etype) == S_IDATA)
+      DCL_TYPE (val->type) = IPOINTER;
+    else if (SPEC_SCLS (expr->right->etype) == S_EEPROM)
+      DCL_TYPE (val->type) = EEPPOINTER;
+    else
+      DCL_TYPE (val->type) = POINTER;
+    val->type->next = expr->right->ftype->next;
+    val->etype = getSpec (val->type);
+    return val;
+  }
+ wrong:
+  if (expr)
+    werrorfl (expr->filename, expr->lineno, E_INCOMPAT_PTYPES);
+  else
+    werror (E_INCOMPAT_PTYPES);
+  return NULL;
+
+}
+
+
+/*-----------------------------------------------------------------*/
+/* return the generic pointer high byte for a given pointer type.  */
+/*-----------------------------------------------------------------*/
+int pic16_pointerTypeToGPByte (const int p_type, const char *iname, const char *oname)
+{
+  switch (p_type)
+    {
+    case IPOINTER:
+    case POINTER:
+       fprintf(stderr, "%s:%d pointer is IPOINTER/POINTER\n", __FILE__, __LINE__);
+      return GPTYPE_NEAR;
+    case GPOINTER:
+       fprintf(stderr, "%s:%d pointer is GPOINTER\n", __FILE__, __LINE__);
+      werror (E_CANNOT_USE_GENERIC_POINTER, 
+              iname ? iname : "<null>", 
+              oname ? oname : "<null>");
+      exit (1);
+    case FPOINTER:
+       fprintf(stderr, "%s:%d pointer is FPOINTER\n", __FILE__, __LINE__);
+      return GPTYPE_FAR;
+    case CPOINTER:
+       fprintf(stderr, "%s:%d pointer is CPOINTER\n", __FILE__, __LINE__);
+      return GPTYPE_CODE;
+    case PPOINTER:
+       fprintf(stderr, "%s:%d pointer is PPOINTER\n", __FILE__, __LINE__);
+      return GPTYPE_XSTACK;
+    default:
+      fprintf (stderr, "*** internal error: unknown pointer type %d in GPByte.\n",
+               p_type);
+      break;
+    }
+  return -1;
+}
+
+
+/*-----------------------------------------------------------------*/
+/* printPointerType - generates ival for pointer type              */
+/*-----------------------------------------------------------------*/
+void _pic16_printPointerType (const char *name, char ptype, void *p)
+{
+  char buf[256];
+
+       sprintf(buf, "LOW(%s)", name);
+       pic16_emitDS(buf, ptype, p);
+       sprintf(buf, "HIGH(%s)", name);
+       pic16_emitDS(buf, ptype, p);
+}
+
+/*-----------------------------------------------------------------*/
+/* printPointerType - generates ival for pointer type              */
+/*-----------------------------------------------------------------*/
+void pic16_printPointerType (const char *name, char ptype, void *p)
+{
+  _pic16_printPointerType (name, ptype, p);
+  pic16_flushDB(ptype, p);
+}
+
+/*-----------------------------------------------------------------*/
+/* printGPointerType - generates ival for generic pointer type     */
+/*-----------------------------------------------------------------*/
+void pic16_printGPointerType (const char *iname, const char *oname,
+                   const unsigned int type, char ptype, void *p)
+{
+  _pic16_printPointerType (iname, ptype, p);
+  pic16_emitDB(pic16_pointerTypeToGPByte(type, iname, oname), ptype, p);
+  pic16_flushDB(ptype, p);
+}
+
+
+
+/*-----------------------------------------------------------------*/
+/* pic16_printIvalType - generates ival for int/char               */
 /*-----------------------------------------------------------------*/
 static void 
-printIvalType (symbol *sym, sym_link * type, initList * ilist, pBlock *pb)
+pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype, void *p)
 {
   value *val;
   unsigned long ulval;
@@ -363,7 +575,7 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, pBlock *pb)
   //fprintf(stderr, "%s\n",__FUNCTION__);
 
   /* if initList is deep */
-  if (ilist->type == INIT_DEEP)
+  if (ilist && ilist->type == INIT_DEEP)
     ilist = ilist->init.deep;
 
   if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) {
@@ -386,42 +598,36 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, pBlock *pb)
 
   switch (getSize (type)) {
   case 1:
-    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
-    pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); 
+    pic16_emitDB(BYTE_IN_LONG(ulval,0), ptype, p);
     break;
 
   case 2:
-    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
-    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1))));
-    pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); 
-    pic16_emitDB(pb, BYTE_IN_LONG(ulval,1)); 
+    pic16_emitDB(BYTE_IN_LONG(ulval,0), ptype, p);
+    pic16_emitDB(BYTE_IN_LONG(ulval,1), ptype, p);
     break;
 
   case 4:
-    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
-    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1))));
-    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2))));
-    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3))));
-    pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); 
-    pic16_emitDB(pb, BYTE_IN_LONG(ulval,1)); 
-    pic16_emitDB(pb, BYTE_IN_LONG(ulval,2)); 
-    pic16_emitDB(pb, BYTE_IN_LONG(ulval,3)); 
+    pic16_emitDB(BYTE_IN_LONG(ulval,0), ptype, p);
+    pic16_emitDB(BYTE_IN_LONG(ulval,1), ptype, p);
+    pic16_emitDB(BYTE_IN_LONG(ulval,2), ptype, p);
+    pic16_emitDB(BYTE_IN_LONG(ulval,3), ptype, p);
     break;
   }
 }
 
-/*-----------------------------------------------------------------*/
-/* printIvalChar - generates initital value for character array    */
-/*-----------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+/* pic16_printIvalChar - generates initital value for character array */
+/*--------------------------------------------------------------------*/
 static int 
-printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
+pic16_printIvalChar (sym_link * type, initList * ilist, char *s, char ptype, void *p)
 {
   value *val;
   int remain;
 
-  if(!pb)
+  if(!p)
     return 0;
 
+
   // fprintf(stderr, "%s\n",__FUNCTION__);
   if (!s)
     {
@@ -433,50 +639,38 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
          if (!DCL_ELEM (type))
            DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
 
-               for(remain=0; remain<DCL_ELEM(type); remain++)
-                       pic16_emitDB(pb, SPEC_CVAL(val->etype).v_char[ remain ]);
+           for(remain=0; remain<DCL_ELEM(type); remain++)
+               pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
                        
-//       pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";omitting call to printChar"));
-
-         if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0)
-            {
-             while (remain--)
-                {
-                 //tfprintf (oFile, "\t!db !constbyte\n", 0);
-                 // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(0)));
-                  pic16_emitDB(pb,0);
-                }
-            }
+         if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) {
+             while (remain--) {
+                  pic16_emitDB(0x00, ptype, p);
+              }
+          }
          return 1;
        }
       else
        return 0;
     }
   else {
-    //printChar (oFile, s, strlen (s) + 1);
-
-    for(remain=0; remain<strlen(s); remain++) 
-      {
-        // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(s[remain])));
-        //fprintf(stderr,"0x%02x ",s[remain]);
-        pic16_emitDB(pb, s[remain]);
-      }
-    //fprintf(stderr,"\n");
+    for(remain=0; remain<strlen(s); remain++) {
+        pic16_emitDB(s[remain], ptype, p);
+    }
   }
   return 1;
 }
 
 /*-----------------------------------------------------------------*/
-/* printIvalArray - generates code for array initialization        */
+/* pic16_printIvalArray - generates code for array initialization        */
 /*-----------------------------------------------------------------*/
 static void 
-printIvalArray (symbol * sym, sym_link * type, initList * ilist,
-               pBlock *pb)
+pic16_printIvalArray (symbol * sym, sym_link * type, initList * ilist,
+               char ptype, void *p)
 {
   initList *iloop;
   int lcnt = 0, size = 0;
 
-  if(!pb)
+  if(!p)
     return;
 
 
@@ -484,25 +678,18 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
   /* array of characters can be init  */
   /* by a string                      */
   if (IS_CHAR (type->next)) {
-    fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__);
     if (!IS_LITERAL(list2val(ilist)->etype)) {
       werror (W_INIT_WRONG);
       return;
     }
 
-       fprintf(stderr, "%s:%d adding %s to idata\n", __FILE__, __LINE__, sym->name);
-       if(SPEC_ABSA(sym->etype))
-               addSet(&fix_idataSymSet, copySymbol(sym));
-       else
-               addSet(&rel_idataSymSet, copySymbol(sym));
-
-    if (printIvalChar (type,
+    if(pic16_printIvalChar (type,
                       (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
-                      pb, SPEC_CVAL (sym->etype).v_char))
+                      SPEC_CVAL (sym->etype).v_char, ptype, p))
       return;
   }
   /* not the special case             */
-  if (ilist->type != INIT_DEEP)
+  if (ilist && ilist->type != INIT_DEEP)
     {
       werror (E_INIT_STRUCT, sym->name);
       return;
@@ -513,9 +700,8 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
 
   for (;;)
     {
-      //fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__);
       size++;
-      printIval (sym, type->next, iloop, pb);
+      pic16_printIval (sym, type->next, iloop, ptype, p);
       iloop = (iloop ? iloop->next : NULL);
 
 
@@ -542,15 +728,342 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
   return;
 }
 
+/*-----------------------------------------------------------------*/
+/* pic16_printIvalBitFields - generate initializer for bitfields   */
+/*-----------------------------------------------------------------*/
+void pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
+{
+  value *val ;
+  symbol *lsym = *sym;
+  initList *lilist = *ilist ;
+  unsigned long ival = 0;
+  int size =0;
+
+
+  do {
+    unsigned long i;
+    val = list2val(lilist);
+    if (size) {
+      if (SPEC_BLEN(lsym->etype) > 8) {
+        size += ((SPEC_BLEN (lsym->etype) / 8) +
+                 (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
+      }
+    } else {
+      size = ((SPEC_BLEN (lsym->etype) / 8) +
+              (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
+    }
+    i = (unsigned long)floatFromVal(val);
+    i <<= SPEC_BSTR (lsym->etype);
+    ival |= i;
+    if (! ( lsym->next &&
+          (IS_BITFIELD(lsym->next->type)) &&
+          (SPEC_BSTR(lsym->next->etype)))) break;
+    lsym = lsym->next;
+    lilist = lilist->next;
+  } while (1);
+  switch (size) {
+  case 1:
+       pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
+        break;
 
+  case 2:
+       pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
+       pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
+        break;
+
+  case 4: /* EEP: why is this db and not dw? */
+       pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
+       pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
+       pic16_emitDB(BYTE_IN_LONG(ival, 2), ptype, p);
+       pic16_emitDB(BYTE_IN_LONG(ival, 3), ptype, p);
+        break;
+  default:
+       /* VR - only 1,2,4 size long can be handled???? Why? */
+       fprintf(stderr, "%s:%d: unhandled case. Contact author.\n", __FILE__, __LINE__);
+  }
+  *sym = lsym;
+  *ilist = lilist;
+}
 
 /*-----------------------------------------------------------------*/
-/* printIval - generates code for initial value                    */
+/* printIvalStruct - generates initial value for structures        */
 /*-----------------------------------------------------------------*/
-static void 
-printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb)
+void pic16_printIvalStruct (symbol * sym, sym_link * type,
+                 initList * ilist, char ptype, void *p)
+{
+  symbol *sflds;
+  initList *iloop = NULL;
+
+  sflds = SPEC_STRUCT (type)->fields;
+
+  if (ilist) {
+    if (ilist->type != INIT_DEEP) {
+      werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
+      return;
+    }
+
+    iloop = ilist->init.deep;
+  }
+
+  for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
+//    fprintf(stderr, "%s:%d sflds: %p\tiloop = %p\n", __FILE__, __LINE__, sflds, iloop);
+    if (IS_BITFIELD(sflds->type)) {
+      pic16_printIvalBitFields(&sflds, &iloop, ptype, p);
+    } else {
+      pic16_printIval (sym, sflds->type, iloop, ptype, p);
+    }
+  }
+  if (iloop) {
+    werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "struct", sym->name);
+  }
+  return;
+}
+
+/*--------------------------------------------------------------------------*/
+/* pic16_printIvalCharPtr - generates initial values for character pointers */
+/*--------------------------------------------------------------------------*/
+int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char ptype, void *p)
+{
+  int size = 0;
+
+  /* PENDING: this is _very_ mcs51 specific, including a magic
+     number...
+     It's also endin specific.
+
+     VR - Attempting to port this function to pic16 port - 8-Jun-2004
+   */
+
+       fprintf(stderr, "%s\n",__FUNCTION__);
+
+  size = getSize (type);
+
+  if (val->name && strlen (val->name))
+    {
+      if (size == 1)            /* This appears to be Z80 specific?? */
+        {
+         pic16_emitDS(val->name, ptype, p);
+        }
+      else if (size == FPTRSIZE)
+        {
+          pic16_printPointerType (val->name, ptype, p);
+        }
+      else if (size == GPTRSIZE)
+        {
+          int type;
+          if (IS_PTR (val->type)) {
+            type = DCL_TYPE (val->type);
+          } else {
+            type = PTR_TYPE (SPEC_OCLS (val->etype));
+          }
+          if (val->sym && val->sym->isstrlit) {
+            // this is a literal string
+            type=CPOINTER;
+          }
+          pic16_printGPointerType(val->name, sym->name, type, ptype, p);
+        }
+      else
+        {
+          fprintf (stderr, "*** internal error: unknown size in "
+                   "printIvalCharPtr.\n");
+        }
+    }
+  else
+    {
+      // these are literals assigned to pointers
+      switch (size)
+        {
+        case 1:
+         pic16_emitDS(aopLiteral(val, 0), ptype, p);
+//          tfprintf (oFile, "\t!dbs\n", aopLiteral (val, 0));
+          break;
+        case 2:
+         pic16_emitDS(aopLiteral(val, 0), ptype, p);
+         pic16_emitDS(aopLiteral(val, 1), ptype, p);
+//            tfprintf (oFile, "\t.byte %s,%s\n",
+//                      aopLiteral (val, 0), aopLiteral (val, 1));
+          break;
+        case 3:
+          if (IS_GENPTR(type) && floatFromVal(val)!=0) {
+            // non-zero mcs51 generic pointer
+            werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
+          }
+
+         pic16_emitDS(aopLiteral(val, 0), ptype, p);
+         pic16_emitDS(aopLiteral(val, 1), ptype, p);
+         pic16_emitDS(aopLiteral(val, 2), ptype, p);
+         
+//          fprintf (oFile, "\t.byte %s,%s,%s\n",
+//                     aopLiteral (val, 0), 
+//                     aopLiteral (val, 1),
+//                    aopLiteral (val, 2));
+          break;
+
+
+/* no 4 bytes size long for pic16 port */
+        case 4:
+          if (IS_GENPTR(type) && floatFromVal(val)!=0) {
+            // non-zero ds390 generic pointer
+            werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
+          }
+
+//          fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+//                     aopLiteral (val, 0), 
+//                     aopLiteral (val, 1), 
+//                     aopLiteral (val, 2),
+//                     aopLiteral (val, 3));
+          break;
+        default:
+          assert (0);
+        }
+    }
+
+  if (val->sym && val->sym->isstrlit && !isinSet(statsg->syms, val->sym)) {
+    addSet (&statsg->syms, val->sym);
+  }
+
+  return 1;
+}
+
+/*-----------------------------------------------------------------------*/
+/* pic16_printIvalFuncPtr - generate initial value for function pointers */
+/*-----------------------------------------------------------------------*/
+void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void *p)
 {
-  if (!ilist || !pb)
+  value *val;
+  int dLvl = 0;
+
+  if (ilist)
+    val = list2val (ilist);
+  else
+    val = valCastLiteral(type, 0.0);
+
+  if (!val) {
+    // an error has been thrown already
+    val=constVal("0");
+  }
+
+  if (IS_LITERAL(val->etype)) {
+    if (compareType(type, val->etype) == 0) {
+      werrorfl (ilist->filename, ilist->lineno, E_INCOMPAT_TYPES);
+      printFromToType (val->type, type);
+    }
+    pic16_printIvalCharPtr (NULL, type, val, ptype, p);
+    return;
+  }
+
+  /* check the types   */
+  if ((dLvl = compareType (val->type, type->next)) <= 0)
+    {
+      pic16_emitDB(0x00, ptype, p);
+      return;
+    }
+
+  /* now generate the name */
+  if (!val->sym)
+    {
+      pic16_printPointerType (val->name, ptype, p);
+    }
+  else
+    {
+      pic16_printPointerType (val->sym->rname, ptype, p);
+    }
+
+  return;
+}
+
+
+/*-----------------------------------------------------------------*/
+/* pic16_printIvalPtr - generates initial value for pointers       */
+/*-----------------------------------------------------------------*/
+void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p)
+{
+  value *val;
+  int size;
+
+  /* if deep then   */
+  if (ilist && (ilist->type == INIT_DEEP))
+    ilist = ilist->init.deep;
+
+  /* function pointer     */
+  if (IS_FUNC (type->next))
+    {
+      pic16_printIvalFuncPtr (type, ilist, ptype, p);
+      return;
+    }
+
+  if (!(val = pic16_initPointer (ilist, type)))
+    return;
+
+  /* if character pointer */
+  if (IS_CHAR (type->next))
+    if (pic16_printIvalCharPtr (sym, type, val, ptype, p))
+      return;
+
+  /* check the type      */
+  if (compareType (type, val->type) == 0) {
+    werrorfl (ilist->filename, ilist->lineno, W_INIT_WRONG);
+    printFromToType (val->type, type);
+  }
+
+  /* if val is literal */
+  if (IS_LITERAL (val->etype))
+    {
+      switch (getSize (type))
+        {
+        case 1:
+            pic16_emitDB((unsigned int)floatFromVal(val) & 0xff, ptype, p);
+//            tfprintf (oFile, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff);
+            break;
+        case 2:
+            pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
+            pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
+//            tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
+            break;
+        case 3:
+            pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
+            pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
+
+          if (IS_GENPTR (val->type))
+            pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
+          else if (IS_PTR (val->type))
+            pic16_emitDB(pic16_pointerTypeToGPByte(DCL_TYPE(val->type), NULL, NULL), ptype, p);
+          else
+            pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
+        }
+      return;
+    }
+
+
+  size = getSize (type);
+
+  if (size == 1)                /* Z80 specific?? */
+    {
+      pic16_emitDS(val->name, ptype, p);
+    }
+  else if (size == FPTRSIZE)
+    {
+        pic16_printPointerType (val->name, ptype, p);
+    }
+  else if (size == GPTRSIZE)
+    {
+      pic16_printGPointerType (val->name, sym->name,
+                         (IS_PTR (val->type) ? DCL_TYPE (val->type) :
+                          PTR_TYPE (SPEC_OCLS (val->etype))), ptype, p);
+    }
+  return;
+}
+
+
+
+/*-----------------------------------------------------------------*/
+/* pic16_printIval - generates code for initial value                    */
+/*-----------------------------------------------------------------*/
+void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p)
+{
+  sym_link *itype;
+  
+  if (!p)
     return;
 
 //     fprintf(stderr, "%s:%d generating init for %s\n", __FILE__, __LINE__, sym->name);
@@ -558,38 +1071,66 @@ printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb)
   /* if structure then    */
   if (IS_STRUCT (type))
     {
-      //fprintf(stderr,"%s struct\n",__FUNCTION__);
-      //printIvalStruct (sym, type, ilist, oFile);
-       fprintf(stderr, "%s:%d: PIC16 port error: structure initialisation is not implemented yet.\n",
-               __FILE__, __LINE__);
-       abort();
+      fprintf(stderr,"%s struct\n",__FUNCTION__);
+      pic16_printIvalStruct (sym, type, ilist, ptype, p);
       return;
     }
 
-  /* if this is a pointer */
-  if (IS_PTR (type))
+  /* if this is an array   */
+  if (IS_ARRAY (type))
     {
-      //fprintf(stderr,"%s pointer\n",__FUNCTION__);
-      //printIvalPtr (sym, type, ilist, oFile);
-       fprintf(stderr, "%s:%d: PIC16 port error: pointer initialisation is not implemented yet.\n",
-               __FILE__, __LINE__);
-       abort();
+//     fprintf(stderr,"%s array\n",__FUNCTION__);
+      pic16_printIvalArray (sym, type, ilist, ptype, p);
       return;
     }
 
-  /* if this is an array   */
-  if (IS_ARRAY (type))
+#if 0
+  if (ilist)
     {
-      //fprintf(stderr,"%s array\n",__FUNCTION__);
-      printIvalArray (sym, type, ilist, pb);
+      // not an aggregate, ilist must be a node
+      if (ilist->type!=INIT_NODE) {
+          // or a 1-element list
+        if (ilist->init.deep->next) {
+          werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "scalar",
+                  sym->name);
+        } else {
+          ilist=ilist->init.deep;
+        }
+      }
+
+#if 1
+      // and the type must match
+      itype=ilist->init.node->ftype;
+
+      if (compareType(type, itype)==0) {
+        // special case for literal strings
+        if (IS_ARRAY (itype) && IS_CHAR (getSpec(itype)) &&
+            // which are really code pointers
+            IS_PTR(type) && DCL_TYPE(type)==CPOINTER) {
+          // no sweat
+        } else {
+//          werrorfl (ilist->filename, ilist->lineno, E_TYPE_MISMATCH, "assignment", " ");
+//          printFromToType(itype, type);
+        }
+      }
+#endif
+    }
+#endif
+
+  /* if this is a pointer */
+  if (IS_PTR (type))
+    {
+      fprintf(stderr,"%s pointer\n",__FUNCTION__);
+      pic16_printIvalPtr (sym, type, ilist, ptype, p);
       return;
     }
 
+
   /* if type is SPECIFIER */
   if (IS_SPEC (type))
     {
-      //fprintf(stderr,"%s spec\n",__FUNCTION__);
-      printIvalType (sym, type, ilist, pb);
+//     fprintf(stderr,"%s spec\n",__FUNCTION__);
+      pic16_printIvalType (sym, type, ilist, ptype, p);
       return;
     }
 }
@@ -612,13 +1153,19 @@ pic16emitStaticSeg (memmap * map)
 
   //fprintf(stderr, "%s\n",__FUNCTION__);
 
+  pic16_initDB();
+
   /* for all variables in this segment do */
   for (sym = setFirstItem (map->syms); sym;
        sym = setNextItem (map->syms))
     {
 
 #if 0
-       fprintf(stderr, "\t%s: sym: %s\tused: %d\n", map->sname, sym->name, sym->used);
+       fprintf(stderr, "\t%s: sym: %s\tused: %d\tSPEC_ABSA: %d\tSPEC_AGGREGATE: %d\tCODE: %d\n\
+CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n",
+               map->sname, sym->name, sym->used, SPEC_ABSA(sym->etype), IS_AGGREGATE(sym->type),
+               IS_CODE(sym->etype), IN_CODESPACE( SPEC_OCLS(sym->etype)), IS_CONSTANT(sym->etype),
+               IS_PTR_CONST(sym->etype), SPEC_CONST(sym->etype));
        printTypeChain( sym->type, stderr );
        fprintf(stderr, "\n");
 #endif
@@ -710,8 +1257,8 @@ pic16emitStaticSeg (memmap * map)
              
              pic16_addpCode2pBlock(pb,pcf);
              pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
-             printIval (sym, sym->type, sym->ival, pb);
-              pic16_flushDB(pb);
+             pic16_printIval(sym, sym->type, sym->ival, 'p', (void *)pb);
+              pic16_flushDB('p', (void *)pb);
 
              pic16_addpCode2pBlock(pb, pic16_newpCodeFunction(NULL, NULL));
              noAlloc--;
@@ -747,13 +1294,13 @@ pic16emitStaticSeg (memmap * map)
              fprintf (code->oFile, "%s:\n", sym->rname);
              noAlloc++;
              resolveIvalSym (sym->ival, sym->type);
-             //printIval (sym, sym->type, sym->ival, code->oFile);
+
              pb = pic16_newpCodeChain(NULL, 'P',pic16_newpCodeCharP("; Starting pCode block for Ival"));
              pic16_addpBlock(pb);
              pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
 
-             printIval (sym, sym->type, sym->ival, pb);
-              pic16_flushDB(pb);
+             pic16_printIval(sym, sym->type, sym->ival, 'p', (void *)pb);
+              pic16_flushDB('p', (void *)pb);
              noAlloc--;
            }
          else
index 206add78693c7b705aedf0bbce2e2a88ca85140f..dc8360e8ca74c0fa1d522d174611975f72a6e494 100644 (file)
@@ -4034,18 +4034,46 @@ typedef struct DBdata
 
 struct DBdata DBd;
 static int DBd_init = -1;
-static int DB_prev = -1;
+
+/*-----------------------------------------------------------------*/
+/*    Initialiase "DB" data buffer                                 */
+/*-----------------------------------------------------------------*/
+void pic16_initDB(void)
+{
+       DBd_init = -1;
+}
+
+
+/*-----------------------------------------------------------------*/
+/*    Flush pending "DB" data to a pBlock                          */
+/*                                                                 */
+/* ptype - type of p pointer, 'f' file pointer, 'p' pBlock pointer */
+/*-----------------------------------------------------------------*/
+void pic16_flushDB(char ptype, void *p)
+{
+       if (DBd.count>0) {
+               if(ptype == 'p')
+                       pic16_addpCode2pBlock(((pBlock *)p),pic16_newpCodeAsmDir("DB", "%s", DBd.buffer));
+               else
+               if(ptype == 'f')
+                       fprintf(((FILE *)p), "\tdb\t%s\n", DBd.buffer);
+                else {
+                       /* sanity check */
+                       fprintf(stderr, "PIC16 port error: could not emit initial value data\n");
+                }
+
+               DBd.count = 0;
+               DBd.buffer[0] = '\0';
+       }
+}
+
 
 /*-----------------------------------------------------------------*/
 /*    Add "DB" directives to a pBlock                              */
 /*-----------------------------------------------------------------*/
-void pic16_emitDB(pBlock *pb, char c)
+void pic16_emitDB(char c, char ptype, void *p)
 {
   int l;
-  char *frm, tbuf[8];
-  char frm_alnum[]="%c";
-  char frm_other[]="0x%02x";
-
 
        if (DBd_init<0) {
         // we need to initialize
@@ -4055,55 +4083,33 @@ void pic16_emitDB(pBlock *pb, char c)
        }
 
        l = strlen(DBd.buffer);
+       sprintf(DBd.buffer+l,"%s0x%02x", (DBd.count>0?", ":""), c & 0xff);
 
-       if(isprint( c ))frm = frm_alnum;
-       else frm = frm_other;
-       sprintf(tbuf, frm, c & 0xff);
-       
-       if(!isprint(DB_prev)) {
-               if(isprint(c))
-                       if(DBd.count)strcat(DBd.buffer, ", \"");
-                       else strcat(DBd.buffer, "\"");
-               else if(DBd.count) strcat(DBd.buffer, ", ");
-       } else
-               if(!isprint(c))strcat(DBd.buffer, "\", ");
-       
-       strcat(DBd.buffer, tbuf);
+       DBd.count++;
+       if (DBd.count>=16)
+               pic16_flushDB(ptype, p);
+}
 
-#if 0          
-       if (DBd.count>0) {
-               sprintf(DBd.buffer+l,", 0x%02x", c & 0xff);
-       } else {
-               sprintf(DBd.buffer,"0x%02x", c & 0xff);
-       }
-#endif
+void pic16_emitDS(char *s, char ptype, void *p)
+{
+  int l;
 
-       DBd.count++;
-       DB_prev = c;
-       
-       if (DBd.count>=16) {
-               if(isprint(c))strcat(DBd.buffer, "\"");
-               pic16_addpCode2pBlock(pb,pic16_newpCodeAsmDir("DB", "%s", DBd.buffer));
+       if (DBd_init<0) {
+        // we need to initialize
+               DBd_init = 0;
                DBd.count = 0;
                DBd.buffer[0] = '\0';
-               DB_prev = 0;
        }
-}
 
-/*-----------------------------------------------------------------*/
-/*    Flush pending "DB" data to a pBlock                          */
-/*-----------------------------------------------------------------*/
-void pic16_flushDB(pBlock *pb)
-{
-  if (DBd.count>0)
-    {
-       if(isprint(DB_prev))strcat(DBd.buffer, "\"");
-       pic16_addpCode2pBlock(pb,pic16_newpCodeAsmDir("DB", "%s", DBd.buffer));
-       DBd.count = 0;
-       DBd.buffer[0] = '\0';
-    }
+       l = strlen(DBd.buffer);
+       sprintf(DBd.buffer+l,"%s%s", (DBd.count>0?", ":""), s);
+
+       DBd.count++;    //=strlen(s);
+       if (DBd.count>=16)
+               pic16_flushDB(ptype, p);
 }
 
+
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
 void pic16_pCodeConstString(char *name, char *value)
@@ -4125,9 +4131,9 @@ void pic16_pCodeConstString(char *name, char *value)
   pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(name,-1));
 
   do {
-        pic16_emitDB(pb, *value);
+        pic16_emitDB(*value, 'p', (void *)pb);
   }while (*value++);
-  pic16_flushDB(pb);
+  pic16_flushDB('p', (void *)pb);
 }
 
 /*-----------------------------------------------------------------*/
index 7c1bd2d503d09e5e460238c833fe1ebbf390748a..fd0516e3a35d89c865450a2f35055cd1bee408f2 100644 (file)
@@ -914,8 +914,10 @@ void pic16_printCallTree(FILE *of);
 void pCodePeepInit(void);
 void pic16_pBlockConvert2ISR(pBlock *pb);
 void pic16_pBlockConvert2Absolute(pBlock *pb);
-void pic16_emitDB(pBlock *pb, char c);           // Add DB directives to a pBlock
-void pic16_flushDB(pBlock *pb);                          // Add pending DB data to a pBlock
+void pic16_initDB(void);
+void pic16_emitDB(char c, char ptype, void *p);                  // Add DB directives to a pBlock
+void pic16_emitDS(char *s, char ptype, void *p);
+void pic16_flushDB(char ptype, void *p);                         // Add pending DB data to a pBlock
 
 pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...);