Cleared out all warnings in sdcc. Moved all unused functions into an 'Unused' section.
[fw/sdcc] / src / avr / gen.c
index 731b98caae46646b16186d0b8e1f63ec16854e13..fe2a666f9e7b1c4ec7722cf052b1200206f935f6 100644 (file)
@@ -64,9 +64,21 @@ static char *spname;
 char *fReturnAVR[] = { "r16", "r17", "r18", "r19" };
 unsigned fAVRReturnSize = 4;   /* shared with ralloc.c */
 char **fAVRReturn = fReturnAVR;
-static short rbank = -1;
 static char *larray[4] = { "lo8", "hi8", "hlo8", "hhi8" };
+
+#if 0
+// PENDING: Unused
+static short rbank = -1;
 static char *tscr[4] = { "r0", "r1", "r24", "r25" };
+static unsigned char SLMask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0,
+       0xE0, 0xC0, 0x80, 0x00
+};
+static unsigned char SRMask[] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F,
+       0x07, 0x03, 0x01, 0x00
+};
+
+#endif
+
 static struct {
        short xPushed;
        short zPushed;
@@ -80,7 +92,6 @@ static struct {
 extern int avr_ptrRegReq;
 extern int avr_nRegs;
 extern FILE *codeOutFile;
-static void saverbank (int, iCode *, bool);
 #define RESULTONSTACK(x) \
                          (IC_RESULT(x) && IC_RESULT(x)->aop && \
                          IC_RESULT(x)->aop->type == AOP_STK )
@@ -96,18 +107,132 @@ static void saverbank (int, iCode *, bool);
 static lineNode *lineHead = NULL;
 static lineNode *lineCurr = NULL;
 
-static unsigned char SLMask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0,
-       0xE0, 0xC0, 0x80, 0x00
-};
-static unsigned char SRMask[] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F,
-       0x07, 0x03, 0x01, 0x00
-};
-
 #define LSB     0
 #define MSB16   1
 #define MSB24   2
 #define MSB32   3
 
+#if 0
+// PENDING: Unused.
+/*-----------------------------------------------------------------*/
+/* reAdjustPreg - points a register back to where it should        */
+/*-----------------------------------------------------------------*/
+static void
+reAdjustPreg (asmop * aop)
+{
+       int size;
+
+       aop->coff = 0;
+       if ((size = aop->size) <= 1)
+               return;
+       size--;
+       switch (aop->type) {
+       case AOP_X:
+       case AOP_Z:
+               emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, size);
+               break;
+       }
+
+}
+
+/*-----------------------------------------------------------------*/
+/* outBitC - output a bit C                                        */
+/*-----------------------------------------------------------------*/
+static void
+outBitC (operand * result)
+{
+       emitcode ("clr", "r0");
+       emitcode ("rol", "r0");
+       outAcc (result);
+}
+
+/*-----------------------------------------------------------------*/
+/* inExcludeList - return 1 if the string is in exclude Reg list   */
+/*-----------------------------------------------------------------*/
+static bool
+inExcludeList (char *s)
+{
+       int i = 0;
+
+       if (options.excludeRegs[i] &&
+           STRCASECMP (options.excludeRegs[i], "none") == 0)
+               return FALSE;
+
+       for (i = 0; options.excludeRegs[i]; i++) {
+               if (options.excludeRegs[i] &&
+                   STRCASECMP (s, options.excludeRegs[i]) == 0)
+                       return TRUE;
+       }
+       return FALSE;
+}
+
+/*-----------------------------------------------------------------*/
+/* findLabelBackwards: walks back through the iCode chain looking  */
+/* for the given label. Returns number of iCode instructions     */
+/* between that label and given ic.          */
+/* Returns zero if label not found.          */
+/*-----------------------------------------------------------------*/
+static int
+findLabelBackwards (iCode * ic, int key)
+{
+       int count = 0;
+
+       while (ic->prev) {
+               ic = ic->prev;
+               count++;
+
+               if (ic->op == LABEL && IC_LABEL (ic)->key == key) {
+                       /* printf("findLabelBackwards = %d\n", count); */
+                       return count;
+               }
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------*/
+/* addSign - complete with sign                                    */
+/*-----------------------------------------------------------------*/
+static void
+addSign (operand * result, int offset, int sign)
+{
+       int size = (getDataSize (result) - offset);
+       if (size > 0) {
+               if (sign) {
+                       emitcode ("rlc", "a");
+                       emitcode ("subb", "a,acc");
+                       while (size--)
+                               aopPut (AOP (result), "a", offset++);
+               }
+               else
+                       while (size--)
+                               aopPut (AOP (result), zero, offset++);
+       }
+}
+
+/*-----------------------------------------------------------------*/
+/* isLiteralBit - test if lit == 2^n                               */
+/*-----------------------------------------------------------------*/
+static int
+isLiteralBit (unsigned long lit)
+{
+       unsigned long pw[32] = { 1L, 2L, 4L, 8L, 16L, 32L, 64L, 128L,
+               0x100L, 0x200L, 0x400L, 0x800L,
+               0x1000L, 0x2000L, 0x4000L, 0x8000L,
+               0x10000L, 0x20000L, 0x40000L, 0x80000L,
+               0x100000L, 0x200000L, 0x400000L, 0x800000L,
+               0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L,
+               0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
+       };
+       int idx;
+
+       for (idx = 0; idx < 32; idx++)
+               if (lit == pw[idx])
+                       return idx + 1;
+       return 0;
+}
+#endif // End Unused code section
+
 /*-----------------------------------------------------------------*/
 /* emitcode - writes the code into a file : for now it is simple    */
 /*-----------------------------------------------------------------*/
@@ -115,7 +240,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);
@@ -986,27 +1111,6 @@ aopPut (asmop * aop, char *s, int offset)
 
 }
 
-/*-----------------------------------------------------------------*/
-/* reAdjustPreg - points a register back to where it should        */
-/*-----------------------------------------------------------------*/
-static void
-reAdjustPreg (asmop * aop)
-{
-       int size;
-
-       aop->coff = 0;
-       if ((size = aop->size) <= 1)
-               return;
-       size--;
-       switch (aop->type) {
-       case AOP_X:
-       case AOP_Z:
-               emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, size);
-               break;
-       }
-
-}
-
 #define AOP(op) op->aop
 #define AOP_TYPE(op) AOP(op)->type
 #define AOP_SIZE(op) AOP(op)->size
@@ -1112,17 +1216,6 @@ outAcc (operand * result)
        }
 }
 
-/*-----------------------------------------------------------------*/
-/* outBitC - output a bit C                                        */
-/*-----------------------------------------------------------------*/
-static void
-outBitC (operand * result)
-{
-       emitcode ("clr", "r0");
-       emitcode ("rol", "r0");
-       outAcc (result);
-}
-
 /*-----------------------------------------------------------------*/
 /* toBoolean - emit code for orl a,operator(sizeop)                */
 /*-----------------------------------------------------------------*/
@@ -1600,26 +1693,6 @@ resultRemat (iCode * ic)
 #define STRCASECMP strcasecmp
 #endif
 
-/*-----------------------------------------------------------------*/
-/* inExcludeList - return 1 if the string is in exclude Reg list   */
-/*-----------------------------------------------------------------*/
-static bool
-inExcludeList (char *s)
-{
-       int i = 0;
-
-       if (options.excludeRegs[i] &&
-           STRCASECMP (options.excludeRegs[i], "none") == 0)
-               return FALSE;
-
-       for (i = 0; options.excludeRegs[i]; i++) {
-               if (options.excludeRegs[i] &&
-                   STRCASECMP (s, options.excludeRegs[i]) == 0)
-                       return TRUE;
-       }
-       return FALSE;
-}
-
 /*-----------------------------------------------------------------*/
 /* genFunction - generated code for function entry                 */
 /*-----------------------------------------------------------------*/
@@ -1819,30 +1892,6 @@ genGoto (iCode * ic)
        emitcode ("rjmp", "L%05d", (IC_LABEL (ic)->key + 100));
 }
 
-/*-----------------------------------------------------------------*/
-/* findLabelBackwards: walks back through the iCode chain looking  */
-/* for the given label. Returns number of iCode instructions     */
-/* between that label and given ic.          */
-/* Returns zero if label not found.          */
-/*-----------------------------------------------------------------*/
-static int
-findLabelBackwards (iCode * ic, int key)
-{
-       int count = 0;
-
-       while (ic->prev) {
-               ic = ic->prev;
-               count++;
-
-               if (ic->op == LABEL && IC_LABEL (ic)->key == key) {
-                       /* printf("findLabelBackwards = %d\n", count); */
-                       return count;
-               }
-       }
-
-       return 0;
-}
-
 /*-----------------------------------------------------------------*/
 /* genPlusIncr :- does addition with increment if possible         */
 /*-----------------------------------------------------------------*/
@@ -2080,26 +2129,6 @@ genMinusDec (iCode * ic)
 
 }
 
-/*-----------------------------------------------------------------*/
-/* addSign - complete with sign                                    */
-/*-----------------------------------------------------------------*/
-static void
-addSign (operand * result, int offset, int sign)
-{
-       int size = (getDataSize (result) - offset);
-       if (size > 0) {
-               if (sign) {
-                       emitcode ("rlc", "a");
-                       emitcode ("subb", "a,acc");
-                       while (size--)
-                               aopPut (AOP (result), "a", offset++);
-               }
-               else
-                       while (size--)
-                               aopPut (AOP (result), zero, offset++);
-       }
-}
-
 /*-----------------------------------------------------------------*/
 /* genMinus - generates code for subtraction                       */
 /*-----------------------------------------------------------------*/
@@ -2566,28 +2595,6 @@ genOrOp (iCode * ic)
        freeAsmop (result, NULL, ic, TRUE);
 }
 
-/*-----------------------------------------------------------------*/
-/* isLiteralBit - test if lit == 2^n                               */
-/*-----------------------------------------------------------------*/
-static int
-isLiteralBit (unsigned long lit)
-{
-       unsigned long pw[32] = { 1L, 2L, 4L, 8L, 16L, 32L, 64L, 128L,
-               0x100L, 0x200L, 0x400L, 0x800L,
-               0x1000L, 0x2000L, 0x4000L, 0x8000L,
-               0x10000L, 0x20000L, 0x40000L, 0x80000L,
-               0x100000L, 0x200000L, 0x400000L, 0x800000L,
-               0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L,
-               0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
-       };
-       int idx;
-
-       for (idx = 0; idx < 32; idx++)
-               if (lit == pw[idx])
-                       return idx + 1;
-       return 0;
-}
-
 enum {
        AVR_AND = 0, AVR_OR, AVR_XOR
 };
@@ -2886,11 +2893,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 */
@@ -4585,8 +4592,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",
@@ -4598,24 +4604,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;
@@ -4934,8 +4926,11 @@ genCast (iCode * ic)
        }
        else {
                /* we need to extend the sign :{ */
+                // PENDING: Does nothing on avr
+#if 0
                char *l = aopGet (AOP (right), AOP_SIZE (right) - 1);
                MOVA (l);
+#endif
                emitcode ("rlc", "a");
                emitcode ("subb", "a,acc");
                while (size--)
@@ -5007,7 +5002,8 @@ genDjnz (iCode * ic, iCode * ifx)
 static char *recvregs[8] = {
        "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23"
 };
-static recvCnt = 0;
+
+static int recvCnt = 0;
 
 /*-----------------------------------------------------------------*/
 /* genReceive - generate code for a receive iCode                  */