* Re-added .dw for words, but now port dependent.
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 19 Apr 2000 02:56:55 +0000 (02:56 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 19 Apr 2000 02:56:55 +0000 (02:56 +0000)
* Fixed interesting load bug

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

src/SDCCglue.c
src/avr/main.c
src/mcs51/main.c
src/port.h
src/z80/gen.c
src/z80/main.c

index 8d7b1f9d9537ea610ec3241c2fb29532f30593f7..7d032076a57093c90a5895580e1538fd1a917f77 100644 (file)
@@ -515,13 +515,16 @@ void printIvalFuncPtr (link * type, initList * ilist, FILE * oFile)
     
     /* now generate the name */
     if (!val->sym) {
-       if (IS_LITERAL (val->etype))
-           fprintf(oFile, "\t.byte %s,%s\n", aopLiteral(val, 0),aopLiteral(val, 1));
-       else
+        if (port->use_dw_for_init)
+           tfprintf(oFile, "\t!dw %s\n", val->name);
+       else  
            fprintf(oFile, "\t.byte %s,(%s >> 8)\n", val->name,val->name);
     }
-    else 
-       fprintf(oFile, "\t.byte %s,(%s >> 8)\n", val->sym->rname,val->sym->rname);
+    else
+       if (port->use_dw_for_init)
+           tfprintf(oFile, "\t!dws\n", val->sym->rname);
+       else 
+           fprintf(oFile, "\t.byte %s,(%s >> 8)\n", val->sym->rname,val->sym->rname);
     
     return;
 }
@@ -546,7 +549,10 @@ int printIvalCharPtr (symbol * sym, link * type, value * val, FILE * oFile)
                    "\t!dbs\n", val->name) ;
            break;
        case 2:
-           tfprintf(oFile, "\t.byte %s,(%s >> 8)\n", val->name, val->name);
+           if (port->use_dw_for_init)
+               tfprintf(oFile, "\t!dws\n", val->name);
+           else
+               fprintf(oFile, "\t.byte %s,(%s >> 8)\n", val->name, val->name);
            break;
            /* PENDING: probably just 3 */
        default:
index 9b8b8d3c29b4ad31fa28bad725a37463d8b88e28..dd194986be6f34a46c221dcb3c25ae2cb6a60cde 100644 (file)
@@ -190,6 +190,7 @@ PORT avr_port = {
     _avr_genAssemblerPreamble,
     _avr_genIVT,
     _avr_reset_regparm,
-    _avr_regparm
+    _avr_regparm,
+    FALSE
 };
 
index cab02da9ab75fb292f7e1cfa44ba4ac77c0aa862..e480975e3c763058407a4f727e8c66470d6b2630 100644 (file)
@@ -248,6 +248,7 @@ PORT mcs51_port = {
     _mcs51_genIVT ,
     _mcs51_reset_regparm,
     _mcs51_regparm,
-    NULL
+    NULL,
+    FALSE
 };
 
index e380441ac12d274aaef735d3f2043a75d48e99f5..fb2bc1b765cc551c8b44b44807a85739d4305b08 100644 (file)
@@ -140,7 +140,10 @@ typedef struct {
        processed, 1 otherwise.  May be NULL.
     */
     int (*process_pragma)(const char *sz);
-   
+
+    /** If TRUE, then tprintf and !dw will be used for some initalisers
+     */
+    bool use_dw_for_init;
 } PORT;
 
 extern PORT *port;
index 13a85e806ab275b171d115dc860459e67b44857e..c73d1ae22a70175bff287e0ab4deeba2cbdbc190 100644 (file)
@@ -344,6 +344,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool requires_a)
 
     /* Assign depending on the storage class */
     if (sym->onStack || sym->iaccess) {
+       emitcode("", "; AOP_STK for %s", sym->rname);
         sym->aop = aop = newAsmop(AOP_STK);
         aop->size = getSize(sym->type);
        aop->aopu.aop_stk = sym->stack;
@@ -361,7 +362,6 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool requires_a)
 
     if (IS_GB) {
        /* if it is in direct space */
-       printf("sname %s: regsp %u\n", space->sname, space->regsp);
        if (IN_REGSP(space) && !requires_a) {
            sym->aop = aop = newAsmop (AOP_SFR);
            aop->aopu.aop_dir = sym->rname ;
@@ -374,6 +374,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool requires_a)
     /* only remaining is far space */
     /* in which case DPTR gets the address */
     if (IS_GB) {
+       emitcode("", "; AOP_HL for %s", sym->rname);
        sym->aop = aop = newAsmop(AOP_HL);
     }
     else {
@@ -777,13 +778,15 @@ static void fetchLitPair(PAIR_ID pairId, asmop *left, int offset)
 
     if (isPtr(pair)) {
        if (pairId == PAIR_HL || pairId == PAIR_IY) {
-           if (_G.pairs[pairId].lit && !strcmp(_G.pairs[pairId].lit, l)) {
-               if (pairId == PAIR_HL && abs(_G.pairs[pairId].offset - offset) < 3) {
-                   adjustPair(pair, &_G.pairs[pairId].offset, offset);
-                   return;
-               }
-               if (pairId == PAIR_IY && abs(offset)<127) {
-                   return;
+           if (_G.pairs[pairId].last_type == left->type) {
+               if (_G.pairs[pairId].lit && !strcmp(_G.pairs[pairId].lit, l)) {
+                   if (pairId == PAIR_HL && abs(_G.pairs[pairId].offset - offset) < 3) {
+                       adjustPair(pair, &_G.pairs[pairId].offset, offset);
+                       return;
+                   }
+                   if (pairId == PAIR_IY && abs(offset)<127) {
+                       return;
+                   }
                }
            }
        }
@@ -1811,16 +1814,14 @@ static bool genPlusIncr (iCode *ic)
        ) {
        int offset = 0;
        symbol *tlbl = NULL;
+       tlbl = newiTempLabel(NULL);
        while (size--) {
-           if (offset) {
-               emitIntLabel(tlbl->key+100);
-           }
            emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)), offset++, FALSE));
            if (size) {
-               tlbl = newiTempLabel(NULL);
                emit2("!shortjp nz,!tlabel", tlbl->key+100);
            }
        }
+       emitLabel(tlbl->key+100);
         return TRUE;
     }
 
@@ -2830,9 +2831,9 @@ static void genAnd (iCode *ic, iCode *ifx)
                if (AOP_TYPE(left) == AOP_ACC) 
                    emitcode("and","a,%s",aopGet(AOP(right),offset,FALSE));
                else {
-                   MOVA(aopGet(AOP(right),offset,FALSE));
+                   MOVA(aopGet(AOP(left),offset,FALSE));
                    emitcode("and","a,%s",
-                            aopGet(AOP(left),offset,FALSE));
+                            aopGet(AOP(right),offset,FALSE));
                }
                aopPut(AOP(result),"a",offset);
            }
@@ -2950,9 +2951,9 @@ static void genOr (iCode *ic, iCode *ifx)
            if (AOP_TYPE(left) == AOP_ACC) 
                emitcode("or","a,%s",aopGet(AOP(right),offset,FALSE));
            else {
-               MOVA(aopGet(AOP(right),offset,FALSE));
+               MOVA(aopGet(AOP(left),offset,FALSE));
                emitcode("or","a,%s",
-                        aopGet(AOP(left),offset,FALSE));
+                        aopGet(AOP(right),offset,FALSE));
            }
            aopPut(AOP(result),"a",offset);                     
            /* PENDING: something weird is going on here.  Add exception. */
index b44921cba0967eb6fd65e9c38fd8be084df96101..b5d1849d2ed87f30f65eed22ead845a6c521968c 100644 (file)
@@ -92,12 +92,12 @@ static bool _parseOptions(int *pargc, char **argv, int *i)
            switch (argv[*i][2]) {
            case 'o':
                /* ROM bank */
-               sprintf(buffer, "_CODE_%u", bank);
+               sprintf(buffer, "CODE_%u", bank);
                gbz80_port.mem.code_name = gc_strdup(buffer);
                return TRUE;
            case 'a':
                /* RAM bank */
-               sprintf(buffer, "_DATA_%u", bank);
+               sprintf(buffer, "DATA_%u", bank);
                gbz80_port.mem.data_name = gc_strdup(buffer);
                return TRUE;
            }
@@ -245,7 +245,8 @@ PORT z80_port = {
     0, /* no assembler preamble */
     0, /* no local IVT generation code */
     _reset_regparm,
-    _reg_parm
+    _reg_parm,
+    TRUE
 };
 
 /* Globals */
@@ -305,5 +306,6 @@ PORT gbz80_port = {
     0, /* no local IVT generation code */
     _reset_regparm,
     _reg_parm,
-    _process_pragma
+    _process_pragma,
+    TRUE
 };