Unified the per port Makefiles
[fw/sdcc] / src / avr / gen.c
index 5496080c9a98c37cc4a77dae35bd9b06c32cd1dc..0a9bd9a359390db66920aeb36e1f587de5795a45 100644 (file)
@@ -115,7 +115,7 @@ static void
 emitcode (char *inst, char *fmt, ...)
 {
        va_list ap;
-       char lb[MAX_INLINEASM];
+       char lb[INITIAL_INLINEASM];
        char *lbp = lb;
 
        va_start (ap, fmt);
@@ -164,7 +164,7 @@ hasInc (operand *op, iCode *ic)
       return lic;
     }
     /* if the operand used or deffed */
-    if (bitVectBitValue(ic->uses,op->key) || ic->defKey == op->key) {
+    if (bitVectBitValue(ic->uses,op->key) || ((unsigned) ic->defKey == op->key)) {
       return NULL;
     }
     lic = lic->next;
@@ -537,7 +537,7 @@ sameRegs (asmop * aop1, asmop * aop2)
 static int
 isRegPair (asmop * aop)
 {
-       if (!aop || aop->size != 2)
+       if (!aop || aop->size < 2)
                return 0;
        if (aop->type == AOP_X || aop->type == AOP_Z)
                return 1;
@@ -599,7 +599,7 @@ aopOp (operand * op, iCode * ic, bool result)
 
 
        /* if the type is a conditional */
-       if (sym->regType == REG_CND) {
+       if (sym->regType & REG_CND) {
                aop = op->aop = sym->aop = newAsmop (AOP_CRY);
                aop->size = 0;
                return;
@@ -1816,7 +1816,7 @@ genLabel (iCode * ic)
 static void
 genGoto (iCode * ic)
 {
-       emitcode ("rjmp", "L%05d:", (IC_LABEL (ic)->key + 100));
+       emitcode ("rjmp", "L%05d", (IC_LABEL (ic)->key + 100));
 }
 
 /*-----------------------------------------------------------------*/
@@ -1876,7 +1876,7 @@ genPlusIncr (iCode * ic)
                        return TRUE;
                }
                emitcode ("subi", "%s,lo8(%d)",
-                         aopGet (AOP (IC_LEFT (ic)), 0), -icount);
+                         aopGet (AOP (IC_LEFT (ic)), 0), 0-icount);
                return TRUE;
        }
 
@@ -1893,21 +1893,21 @@ genPlusIncr (iCode * ic)
 
                /* use subi */
                emitcode ("subi", "%s,lo8(%d)",
-                         aopGet (AOP (IC_RESULT (ic)), 0), -icount);
+                         aopGet (AOP (IC_RESULT (ic)), 0), 0-icount);
                emitcode ("sbci", "%s,hi8(%d)",
-                         aopGet (AOP (IC_RESULT (ic)), 1), -icount);
+                         aopGet (AOP (IC_RESULT (ic)), 1), 0-icount);
                return TRUE;
        }
 
        /* for 32 bit longs */
        emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_RESULT (ic)), 0),
-                 -icount);
+                 0-icount);
        emitcode ("sbci", "%s,hi8(%d)", aopGet (AOP (IC_RESULT (ic)), 1),
-                 -icount);
+                 0-icount);
        emitcode ("sbci", "%s,hlo8(%d)", aopGet (AOP (IC_RESULT (ic)), 2),
-                 -icount);
+                 0-icount);
        emitcode ("sbci", "%s,hhi8(%d)", aopGet (AOP (IC_RESULT (ic)), 3),
-                 -icount);
+                 0-icount);
        return TRUE;
 
 }
@@ -2886,11 +2886,11 @@ genXor (iCode * ic, iCode * ifx)
 static void
 genInline (iCode * ic)
 {
-       char buffer[MAX_INLINEASM];
-       char *bp = buffer;
-       char *bp1 = buffer;
+       char *buffer, *bp, *bp1;
 
        _G.inLine += (!options.asmpeep);
+
+       buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
        strcpy (buffer, IC_INLINE (ic));
 
        /* emit each line as a code */
@@ -4014,10 +4014,13 @@ genGenPointerGet (operand * left, operand * result, iCode * ic, iCode *pi)
        } else {
                aop = newAsmop(0);
                getFreePtr(ic,&aop,FALSE,TRUE);
-
-               emitcode ("mov", "r30,%s", aopGet (AOP (left), 0));
-               emitcode ("mov", "r31,%s", aopGet (AOP (left), 1));
-               emitcode ("mov", "r0,%s", aopGet (AOP (left), 2));
+               if (isRegPair(AOP(left))) {
+                       emitcode ("movw", "r30,%s", aopGet (AOP (left), 0));
+               } else {
+                       emitcode ("mov", "r30,%s", aopGet (AOP (left), 0));
+                       emitcode ("mov", "r31,%s", aopGet (AOP (left), 1));
+               }
+               emitcode ("mov", "r24,%s", aopGet (AOP (left), 2));
                gotFreePtr=1;
        }
 
@@ -4566,7 +4569,7 @@ genIfx (iCode * ic, iCode * popIc)
        }
        ic->generated = 1;
 }
-
+/* here */
 /*-----------------------------------------------------------------*/
 /* genAddrOf - generates code for address of                       */
 /*-----------------------------------------------------------------*/
@@ -4582,8 +4585,7 @@ genAddrOf (iCode * ic)
           need to get the stack offset of this
           variable */
        if (sym->onStack) {
-               /* if it has an offset then we need to compute
-                  it */
+               /* if it has an offset then we need to compute it */
                if (sym->stack) {
                        emitcode ("mov", "a,_bp");
                        emitcode ("add", "a,#0x%02x",
@@ -4595,24 +4597,10 @@ genAddrOf (iCode * ic)
                        aopPut (AOP (IC_RESULT (ic)), "_bp", 0);
                }
                /* fill the result with zero */
-               size = AOP_SIZE (IC_RESULT (ic)) - 1;
-
-
-               if (options.stack10bit && size < (FPTRSIZE - 1)) {
-                       fprintf (stderr,
-                                "*** warning: pointer to stack var truncated.\n");
-               }
-
-               offset = 1;
+               size = AOP_SIZE (IC_RESULT (ic)) - 2;
+               offset = 2;
                while (size--) {
-                       /* Yuck! */
-                       if (options.stack10bit && offset == 2) {
-                               aopPut (AOP (IC_RESULT (ic)), "#0x40",
-                                       offset++);
-                       }
-                       else {
-                               aopPut (AOP (IC_RESULT (ic)), zero, offset++);
-                       }
+                       aopPut (AOP (IC_RESULT (ic)), zero, offset++);
                }
 
                goto release;
@@ -4625,9 +4613,9 @@ genAddrOf (iCode * ic)
        while (size--) {
                char s[SDCC_NAME_MAX];
                if (offset)
-                       sprintf (s, "#(%s >> %d)", sym->rname, offset * 8);
+                       sprintf (s, "(%s >> %d)", sym->rname, offset * 8);
                else
-                       sprintf (s, "#%s", sym->rname);
+                       sprintf (s, "%s", sym->rname);
                aopPut (AOP (IC_RESULT (ic)), s, offset++);
        }
 
@@ -4885,10 +4873,10 @@ genCast (iCode * ic)
                                l = one;
                                break;
                        case CPOINTER:
-                               l = "#0x02";
+                               l = "0x02";
                                break;
                        case PPOINTER:
-                               l = "#0x03";
+                               l = "0x03";
                                break;
 
                        default: