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;
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 )
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 */
/*-----------------------------------------------------------------*/
emitcode (char *inst, char *fmt, ...)
{
va_list ap;
- char lb[MAX_INLINEASM];
+ char lb[INITIAL_INLINEASM];
char *lbp = lb;
va_start (ap, fmt);
}
-/*-----------------------------------------------------------------*/
-/* 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
}
}
-/*-----------------------------------------------------------------*/
-/* 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) */
/*-----------------------------------------------------------------*/
#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 */
/*-----------------------------------------------------------------*/
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 */
/*-----------------------------------------------------------------*/
}
-/*-----------------------------------------------------------------*/
-/* 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 */
/*-----------------------------------------------------------------*/
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
};
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 */
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",
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;
}
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--)
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 */