* .version,
[fw/sdcc] / src / pic16 / glue.c
index c8f77a159390ba83611a7f40cea1957d5df3cea4..22ef72f0a29a970e609d0f2565a3efdc780eb3f8 100644 (file)
@@ -360,7 +360,7 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                         }
 
                         if(ival) {
-                                setAstLineno(ival, sym->lineDef);
+                                setAstFileLine (ival, sym->fileDef, sym->lineDef);
                                 codeOutBuf = &statsg->oBuf;
                                 GcurMemmap = statsg;
                                 eBBlockFromiCode (iCodeFromAst (ival));
@@ -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,20 +517,22 @@ 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];
 
-        sprintf(buf, "LOW(%s)", name);
-        pic16_emitDS(buf, ptype, p);
-        sprintf(buf, "HIGH(%s)", name);
-        pic16_emitDS(buf, ptype, p);
+  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)
+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,33 +541,44 @@ 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];
 
-    _pic16_printPointerType (iname, ptype, p);
+  _pic16_printPointerType (iname, ptype, p);
 
-    switch( itype ) {
+  switch (itype)
+    {
+    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 POINTER: /* __data space */
+      sprintf (buf, "0x%02x", GPTR_TAG_DATA);
+      pic16_emitDS (buf, ptype, p);
+      break;
+
+    /*
+     * FPOINTER and IPOINTER are not used in pic16 port
       case FPOINTER:
-      case CPOINTER:
-      case GPOINTER:
-      case FUNCTION:
-        {
-          sprintf(buf, "UPPER(%s)", iname);
-          pic16_emitDS(buf, ptype, p);
-        }; break;
-      case POINTER:
       case IPOINTER:
-        sprintf(buf, "0x80");
-        pic16_emitDS(buf, ptype, p);
-        break;
-      default:
-        debugf("itype = %d\n", itype );
-        assert( 0 );
+     */
+    default:
+      debugf ("itype = %d\n", itype );
+      assert (0);
     }
 
-    //pic16_flushDB(ptype, p); /* might break char* const arr[] = {...}; */
+    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[] = {...}; */
 }
 
 
@@ -596,7 +610,7 @@ pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype,
 
   if (!(val = list2val (ilist))) {
     // assuming a warning has been thrown
-    val=constVal("0");
+    val = constCharVal (0);
   }
 
   if (val->type != type) {
@@ -767,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;
@@ -832,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;
@@ -871,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;
@@ -920,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;
 
@@ -951,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);
         }
@@ -1003,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;
@@ -1020,11 +1035,11 @@ void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void
 
   if (!val) {
     // an error has been thrown already
-    val=constVal("0");
+    val = constCharVal (0);
   }
 
   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);
     }
@@ -1041,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)) {
 
@@ -1065,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;
@@ -1137,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;
@@ -1235,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                 */
 /*-----------------------------------------------------------------*/
@@ -1383,7 +1395,7 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n", __FUNCTION__,
 
               /* symbol doesn't have absolute address but has initial value */
               dbuf_printf (&code->oBuf, "%s:\n", sym->rname);
-              noAlloc++;
+              ++noAlloc;
               resolveIvalSym (sym->ival, sym->type);
 
               pb = pic16_newpCodeChain(NULL, 'P',pic16_newpCodeCharP("; Starting pCode block for Ival"));
@@ -1400,7 +1412,7 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n", __FUNCTION__,
               //fprintf(stderr, "%s:%d [2] generating init for label: %s\n", __FILE__, __LINE__, sym->rname);
               pic16_printIval(sym, sym->type, sym->ival, 'p', (void *)pb);
               pic16_flushDB('p', (void *)pb);
-              noAlloc--;
+              --noAlloc;
             } else {
 
               /* symbol doesn't have absolute address and no initial value */
@@ -1503,19 +1515,21 @@ pic16createInterruptVect (struct dbuf_s * vBuf)
 static void
 pic16initialComments (FILE * afile)
 {
-        initialComments (afile);
-        fprintf (afile, "; PIC16 port for the Microchip 16-bit core micros\n");
-        if(xinst)
-          fprintf (afile, "; * Extended Instruction Set\n");
-
-        if(pic16_mplab_comp)
-                fprintf(afile, "; * MPLAB/MPASM/MPASMWIN/MPLINK compatibility mode enabled\n");
-        fprintf (afile, iComments2);
-
-        if(options.debug) {
-                fprintf (afile, "\n\t.ident \"SDCC version %s #%s [pic16 port]%s\"\n",
-                                SDCC_VERSION_STR, getBuildNumber(), (!xinst?"":" {extended}") );
-        }
+    initialComments (afile);
+    fprintf (afile, "; PIC16 port for the Microchip 16-bit core micros\n");
+    if (pic16_options.xinst) {
+        fprintf (afile, "; * Extended Instruction Set\n");
+    } // if
+
+    if (pic16_mplab_comp) {
+        fprintf(afile, "; * MPLAB/MPASM/MPASMWIN/MPLINK compatibility mode enabled\n");
+    } // if
+    fprintf (afile, iComments2);
+
+    if (options.debug) {
+        fprintf (afile, "\n\t.ident \"SDCC version %s #%s [pic16 port]%s\"\n",
+                SDCC_VERSION_STR, getBuildNumber(), (!pic16_options.xinst?"":" {extended}") );
+    } // if
 }
 
 int
@@ -1680,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();