From 7a873fa453215d3a0a06b98acc781a814e866ad4 Mon Sep 17 00:00:00 2001 From: kvigor Date: Wed, 20 Mar 2002 21:52:10 +0000 Subject: [PATCH] Consolidate generic pointer code git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2003 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCglue.c | 18 ++++++++++-------- src/SDCCglue.h | 4 ++++ src/SDCCsymt.h | 8 ++++++++ src/avr/gen.c | 40 +++++++++++++++------------------------- src/ds390/gen.c | 40 ++++++++++++++++------------------------ src/mcs51/gen.c | 39 ++++++++++++--------------------------- 6 files changed, 65 insertions(+), 84 deletions(-) diff --git a/src/SDCCglue.c b/src/SDCCglue.c index b0860486..6d4fbe1b 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -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 : "", + oname ? oname : ""); 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; } diff --git a/src/SDCCglue.h b/src/SDCCglue.h index a2af316f..a9832354 100644 --- a/src/SDCCglue.h +++ b/src/SDCCglue.h @@ -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 diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index f8efacf5..e6737a56 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -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 */ diff --git a/src/avr/gen.c b/src/avr/gen.c index 651dab24..06c7476a 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -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 */ diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 95cefb1c..effd7cf8 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -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; } diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 31f6185f..4bea2466 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -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; } -- 2.47.2