Consolidate generic pointer code
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Mar 2002 21:52:10 +0000 (21:52 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Mar 2002 21:52:10 +0000 (21:52 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2003 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCglue.c
src/SDCCglue.h
src/SDCCsymt.h
src/avr/gen.c
src/ds390/gen.c
src/mcs51/gen.c

index b0860486c8d8e86acd7dc3695fc7e30f0dca7672..6d4fbe1b735997dbe7495e6e8b6b653a836f66bb 100644 (file)
@@ -502,16 +502,18 @@ pointerTypeToGPByte (const int p_type, const char *iname, const char *oname)
     {
     case IPOINTER:
     case POINTER:
-      return 0;
+      return GPTYPE_NEAR;
     case GPOINTER:
-      werror (E_CANNOT_USE_GENERIC_POINTER, iname, oname);
+       werror (E_CANNOT_USE_GENERIC_POINTER, 
+               iname ? iname : "<null>", 
+               oname ? oname : "<null>");
       exit (1);
     case FPOINTER:
-      return 1;
+      return GPTYPE_FAR;
     case CPOINTER:
-      return 2;
+      return GPTYPE_CODE;
     case PPOINTER:
-      return 3;
+      return GPTYPE_XSTACK;
     default:
       fprintf (stderr, "*** internal error: unknown pointer type %d in GPByte.\n",
               p_type);
@@ -996,9 +998,9 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
          else
            tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
          break;
-       case 3:
-         fprintf (oFile, "\t.byte %s,%s,#0x02\n",
-                  aopLiteral (val, 0), aopLiteral (val, 1));
+       case 3: // how about '390??
+         fprintf (oFile, "\t.byte %s,%s,#0x%d\n",
+                  aopLiteral (val, 0), aopLiteral (val, 1), GPTYPE_CODE);
        }
       return;
     }
index a2af316fb2f30247318a2777334ddc283d84e600..a98323549579f033c9c04971383dd65daf4ab93e 100644 (file)
@@ -41,4 +41,8 @@ extern set *tmpfileSet;
 #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
 void rm_tmpfiles (void);
 #endif
+
+int 
+pointerTypeToGPByte (const int p_type, const char *iname, const char *oname);
+
 #endif
index f8efacf5722fdc30919047fe17b6eb51af922055..e6737a566503cdd2600307e36284e75a009a8041 100644 (file)
@@ -51,6 +51,14 @@ enum {
     TYPEOF_EEPPOINTER
 };
 
+// values for first byte of generic pointer.
+#define GPTYPE_NEAR    0
+#define GPTYPE_FAR     1
+#define GPTYPE_CODE    2
+#define GPTYPE_XSTACK  3
+#define GPTYPE_GPTR    4       // Never used?
+#define GPTYPE_IDATA   5
+
 #define HASHTAB_SIZE 256
 
 /* hash table bucket */
index 651dab24039a843048a1072a0fc72193942024e8..06c7476a5c142b29bdc24215c922da173701b10b 100644 (file)
@@ -4945,8 +4945,6 @@ genCast (iCode * ic)
 
                /* pointer to generic pointer */
                if (IS_GENPTR (ctype)) {
-                       char *l = zero;
-
                        if (IS_PTR (type))
                                p_type = DCL_TYPE (type);
                        else {
@@ -4962,30 +4960,22 @@ genCast (iCode * ic)
                                        aopGet (AOP (right), offset), offset);
                                offset++;
                        }
-                       /* the last byte depending on type */
-                       switch (p_type) {
-                       case IPOINTER:
-                       case POINTER:
-                               l = zero;
-                               break;
-                       case FPOINTER:
-                               l = one;
-                               break;
-                       case CPOINTER:
-                               l = "0x02";
-                               break;
-                       case PPOINTER:
-                               l = "0x03";
-                               break;
-
-                       default:
-                               /* this should never happen */
-                               werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-                                       "got unknown pointer type");
-                               exit (1);
+                   
+                   /* the last byte depending on type */
+                   {
+                       int gpVal = pointerTypeToGPByte(p_type, NULL, NULL);
+                       char gpValStr[10];
+                       
+                       if (gpVal == -1)
+                       {
+                           // pointerTypeToGPByte will have bitched.
+                           exit(1);
                        }
-                       aopPut (AOP (result), l, GPTRSIZE - 1);
-                       goto release;
+                       
+                       sprintf(gpValStr, "#0x%d", gpVal);
+                       aopPut (AOP (result), gpValStr, GPTRSIZE - 1);
+                   }               
+                   goto release;
                }
 
                /* just copy the pointers */
index 95cefb1ce61932211ee9d0cbb0d5ad4a3f4cab55..effd7cf8b919e2b01ff52c92489c789fd4a734ad 100644 (file)
@@ -9381,6 +9381,7 @@ genGenPointerGet (operand * left,
       else
        {                       /* we need to get it byte by byte */
          _startLazyDPSEvaluation ();
+#if 1  // I see no point at all to this code and will likely yank it soon.
          if (AOP(left)->type==AOP_DPTR2) {
            char *l;
            l=aopGet(AOP(left),0,FALSE,FALSE,TRUE);
@@ -9400,7 +9401,10 @@ genGenPointerGet (operand * left,
            } else {
              emitcode ("mov", "b,%s", aopGet (AOP(left),2,FALSE,FALSE,TRUE));
            }
-         } else {
+         } 
+         else 
+#endif         
+         {
            emitcode ("mov", "dpl,%s", aopGet (AOP(left),0,FALSE,FALSE,TRUE));
            emitcode ("mov", "dph,%s", aopGet (AOP(left),1,FALSE,FALSE,TRUE));
            if (options.model == MODEL_FLAT24) {
@@ -10781,8 +10785,6 @@ genCast (iCode * ic)
       /* pointer to generic pointer */
       if (IS_GENPTR (ctype))
        {
-         char *l = zero;
-
          if (IS_PTR (type))
            {
              p_type = DCL_TYPE (type);
@@ -10842,29 +10844,19 @@ genCast (iCode * ic)
          _endLazyDPSEvaluation ();
 
          /* the last byte depending on type */
-         switch (p_type)
            {
-           case IPOINTER:
-           case POINTER:
-             l = zero;
-             break;
-           case FPOINTER:
-             l = one;
-             break;
-           case CPOINTER:
-             l = "#0x02";
-             break;
-           case PPOINTER:
-             l = "#0x03";
-             break;
-
-           default:
-             /* this should never happen */
-             werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-                     "got unknown pointer type");
-             exit (1);
+               int gpVal = pointerTypeToGPByte(p_type, NULL, NULL);
+               char gpValStr[10];
+           
+               if (gpVal == -1)
+               {
+                   // pointerTypeToGPByte will have bitched.
+                   exit(1);
+               }
+           
+               sprintf(gpValStr, "#0x%d", gpVal);
+               aopPut (AOP (result), gpValStr, GPTRSIZE - 1);
            }
-         aopPut (AOP (result), l, GPTRSIZE - 1);
          goto release;
        }
 
index 31f6185f715385fee9e370062f7acdba187b9658..4bea24662430804bfef82bd5f414a59bc0eaa21b 100644 (file)
@@ -8552,8 +8552,6 @@ genCast (iCode * ic)
       /* pointer to generic pointer */
       if (IS_GENPTR (ctype))
        {
-         char *l = zero;
-
          if (IS_PTR (type))
            p_type = DCL_TYPE (type);
          else
@@ -8578,32 +8576,19 @@ genCast (iCode * ic)
              offset++;
            }
          /* the last byte depending on type */
-         switch (p_type)
            {
-           case IPOINTER:
-           case POINTER:
-             l = zero;
-             break;
-           case FPOINTER:
-             l = one;
-             break;
-           case CPOINTER:
-             l = "#0x02";
-             break;
-           case GPOINTER:
-             l = "0x03";
-             break;
-           case PPOINTER: // what the fck is this?
-             l = "#0x03";
-             break;
-
-           default:
-             /* this should never happen */
-             werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-                     "got unknown pointer type");
-             exit (1);
-           }
-         aopPut (AOP (result), l, GPTRSIZE - 1);
+               int gpVal = pointerTypeToGPByte(p_type, NULL, NULL);
+               char gpValStr[10];
+           
+               if (gpVal == -1)
+               {
+                   // pointerTypeToGPByte will have bitched.
+                   exit(1);
+               }
+           
+               sprintf(gpValStr, "#0x%d", gpVal);
+               aopPut (AOP (result), gpValStr, GPTRSIZE - 1);
+           }       
          goto release;
        }