#include "SDCCglobl.h"
#include "newalloc.h"
-#ifdef HAVE_SYS_ISA_DEFS_H
-#include <sys/isa_defs.h>
-#else
-#ifdef HAVE_MACHINE_ENDIAN_H
-#include <machine/endian.h>
-#else
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#else
-#if !defined(__BORLANDC__) && !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__CYGWIN__)
-#warning "Cannot determine ENDIANESS of this machine assuming LITTLE_ENDIAN"
-#warning "If you running sdcc on an INTEL 80x86 Platform you are okay"
-#endif
-#endif
-#endif
-#endif
-
#define BETTER_LITERAL_SHIFT
char *aopLiteral (value * val, int offset);
(IC_RESULT(x) && IC_RESULT(x)->aop && \
IC_RESULT(x)->aop->type == AOP_STK )
-/* #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) emitcode("mov","a,%s",x); */
-#define MOVA(x) { \
- char *_mova_tmp = strdup(x); \
- if (strcmp(_mova_tmp,"a") && strcmp(_mova_tmp,"acc")) \
- { \
- emitcode("mov","a,%s",_mova_tmp); \
- } \
- free(_mova_tmp); \
- }
-#define MOVB(x) { char *_movb_tmp = strdup(x); \
- if (strcmp(_movb_tmp,"b")) \
- { \
- emitcode("mov","b,%s",_movb_tmp); \
- } \
- free(_movb_tmp); \
- }
+#define MOVA(x) _movA(x)
+#define MOVB(x) _movB(x)
+
#define CLRC emitcode("clr","c")
#define SETC emitcode("setb","c")
va_end (ap);
}
+//
+// Move the passed value into A unless it is already there.
+//
+static void
+_movA(const char *s)
+{
+ if (strcmp(s,"a") && strcmp(s,"acc"))
+ {
+ emitcode("mov","a,%s",s);
+ }
+}
+
+//
+// Move the passed value into B unless it is already there.
+//
+static void
+_movB(const char *s)
+{
+ if (strcmp(s,"b"))
+ {
+ emitcode("mov","b,%s",s);
+ }
+}
+
/*-----------------------------------------------------------------*/
/* getFreePtr - returns r0 or r1 whichever is free or can be pushed */
/*-----------------------------------------------------------------*/
"(%s %c 0x%04x)",
OP_SYMBOL (IC_LEFT (ic))->rname,
val >= 0 ? '+' : '-',
- abs (val) & 0xffff);
+ abs (val) & 0xffffff);
}
else
{
if (saveAcc)
{
TR_AP("#1");
- if (aop->type != AOP_DPTR2)
- {
- if (saveAccWarn) { fprintf(stderr, "saveAcc for DPTR...\n"); }
- emitcode(";", "spanky: saveAcc for DPTR");
- }
+// if (aop->type != AOP_DPTR2)
+// {
+// if (saveAccWarn) { fprintf(stderr, "saveAcc for DPTR...\n"); }
+// emitcode(";", "spanky: saveAcc for DPTR");
+// }
emitcode ("xch", "a, %s", saveAcc);
}
{
TR_AP("#2");
emitcode ("xch", "a, %s", saveAcc);
- if (strcmp(saveAcc, "_ap"))
- {
- emitcode(";", "spiffy: non _ap return from aopGet.");
- }
+// if (strcmp(saveAcc, "_ap"))
+// {
+// emitcode(";", "spiffy: non _ap return from aopGet.");
+// }
return saveAcc;
}
genNotFloat (operand * op, operand * res)
{
int size, offset;
- char *l;
symbol *tlbl;
D (emitcode (";", "genNotFloat "););
offset = 1;
_startLazyDPSEvaluation ();
- l = aopGet (op->aop, offset++, FALSE, FALSE, NULL);
- MOVA (l);
+ MOVA(aopGet(op->aop, offset++, FALSE, FALSE, NULL));
while (size--)
{
else
{
emitcode ("orl", "a,%s",
- aopGet (AOP (oper), offset++, FALSE, FALSE, DP2_RESULT_REG));
+ aopGet (AOP (oper), offset++, FALSE, FALSE, NULL));
}
}
_endLazyDPSEvaluation ();
{
int offset = 0;
int size = AOP_SIZE (oper);
+ bool pushedAcc = FALSE;
+ if (size == fReturnSizeDS390)
+ {
+ /* I don't think this case can ever happen... */
+ /* ACC is the last part of this. If writing the result
+ * uses AC, we must preserve it.
+ */
+ if (AOP_NEEDSACC(oper))
+ {
+ emitcode(";", "assignResultValue special case for ACC.");
+ emitcode("push", "acc");
+ pushedAcc = TRUE;
+ size--;
+ }
+ }
+
+
_startLazyDPSEvaluation ();
while (size--)
{
offset++;
}
_endLazyDPSEvaluation ();
+
+ if (pushedAcc)
+ {
+ emitcode("pop", "acc");
+ aopPut(AOP(oper), "a", offset);
+ }
}
MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, NULL));
if (offset == 0)
emitcode ("add", "a,%s",
- aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, DP2_RESULT_REG));
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, NULL));
else
emitcode ("addc", "a,%s",
- aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, DP2_RESULT_REG));
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, NULL));
}
else
{
emitcode ("mov", "a,#!constbyte",0xff);
emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
}
- l = aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, NULL, NULL);
+ l = aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE, NULL);
emitcode ("dec", "%s", l);
if (size > 2)
{
emitcode ("mov", "a,#!constbyte",0xff);
emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
}
- l = aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, NULL, NULL);
+ l = aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE, NULL);
emitcode ("dec", "%s", l);
}
if (size > 3)
emitcode ("mov", "a,#!constbyte",0xff);
emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
}
- l = aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, NULL, NULL);
+ l = aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE, NULL);
emitcode ("dec", "%s", l);
}
if (emitTlbl)
{
MOVA (aopGet (AOP (left), offset, FALSE, FALSE, NULL));
emitcode ("cjne", "a,%s,!tlabel",
- aopGet (AOP (right), offset, FALSE, FALSE, DP2_RESULT_REG),
+ aopGet (AOP (right), offset, FALSE, FALSE, NULL),
lbl->key + 100);
offset++;
}
else
emitcode ("anl", "%s,%s",
aopGet (AOP (left), offset, FALSE, TRUE, NULL),
- aopGet (AOP (right), offset, FALSE, FALSE, DP2_RESULT_REG));
+ aopGet (AOP (right), offset, FALSE, FALSE, NULL));
}
else
{
else
{
/* We need to generate a load to DPTR indirect through DPTR. */
- D (emitcode (";", "genFarPointerGet -- indirection special case.");
- );
+ D (emitcode (";", "genFarPointerGet -- indirection special case."););
emitcode ("push", "%s", aopGet (AOP (left), 0, FALSE, TRUE, NULL));
emitcode ("push", "%s", aopGet (AOP (left), 1, FALSE, TRUE, NULL));
if (options.model == MODEL_FLAT24)
}
if (dopi && pi && AOP_TYPE (left) != AOP_IMMD) {
if (!AOP_INDPTRn(left)) {
+ _startLazyDPSEvaluation ();
aopPut ( AOP (left), "dpl", 0);
aopPut ( AOP (left), "dph", 1);
if (options.model == MODEL_FLAT24)
aopPut ( AOP (left), "dpx", 2);
+ _endLazyDPSEvaluation ();
}
pi->generated = 1;
- } else if ((OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) &&
+ } else if ((AOP_IS_STR(left) || AOP_INDPTRn(left)) &&
AOP_SIZE(result) > 1 &&
- (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
+ IS_SYMOP(left) &&
+ (OP_SYMBOL(left)->liveTo > ic->seq || ic->depth)) {
size = AOP_SIZE (result) - 1;
if (AOP_INDPTRn(left)) {
else
{
/* We need to generate a load to DPTR indirect through DPTR. */
- D (emitcode (";", "gencodePointerGet -- indirection special case.");
- );
+ D (emitcode (";", "gencodePointerGet -- indirection special case."););
emitcode ("push", "%s", aopGet (AOP (left), 0, FALSE, TRUE, NULL));
emitcode ("push", "%s", aopGet (AOP (left), 1, FALSE, TRUE, NULL));
if (options.model == MODEL_FLAT24)
}
if (dopi && pi && AOP_TYPE (left) != AOP_IMMD) {
if (!AOP_INDPTRn(left)) {
+ _startLazyDPSEvaluation ();
+
aopPut ( AOP (left), "dpl", 0);
aopPut ( AOP (left), "dph", 1);
if (options.model == MODEL_FLAT24)
aopPut ( AOP (left), "dpx", 2);
+
+ _endLazyDPSEvaluation ();
}
pi->generated = 1;
} else if ((OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) &&
}
if (pi && AOP_TYPE (left) != AOP_IMMD) {
+ _startLazyDPSEvaluation ();
+
aopPut ( AOP (left), "dpl", 0);
aopPut ( AOP (left), "dph", 1);
if (options.model == MODEL_FLAT24) {
aopPut ( AOP (left), "dpx", 2);
aopPut ( AOP (left), "b", 3);
} else aopPut ( AOP (left), "b", 2);
+
+ _endLazyDPSEvaluation ();
+
pi->generated = 1;
} else if (OP_SYMBOL(left)->ruonly && AOP_SIZE(result) > 1 &&
(OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
if (dopi && pi && AOP_TYPE (result) != AOP_IMMD) {
if (!AOP_INDPTRn(result)) {
+ _startLazyDPSEvaluation ();
+
aopPut (AOP(result),"dpl",0);
aopPut (AOP(result),"dph",1);
if (options.model == MODEL_FLAT24)
aopPut (AOP(result),"dpx",2);
+
+ _endLazyDPSEvaluation ();
}
pi->generated=1;
} else if ((OP_SYMBOL(result)->ruonly || AOP_INDPTRn(result)) &&
}
_endLazyDPSEvaluation ();
}
- /* so dptr know contains the address */
+ /* so dptr + b now contains the address */
+ _G.bInUse++;
aopOp (right, ic, FALSE, TRUE);
+ _G.bInUse--;
+
/* if bit then unpack */
if (IS_BITVAR (retype) || IS_BITVAR (letype))
- genPackBits ((IS_BITVAR (retype) ? retype : letype), right, "dptr", GPOINTER);
+ {
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, "dptr", GPOINTER);
+ }
else
{
- size = AOP_SIZE (right);
- offset = 0;
+ size = AOP_SIZE (right);
+ offset = 0;
- _startLazyDPSEvaluation ();
- while (size--)
+ _startLazyDPSEvaluation ();
+ while (size--)
{
- MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, NULL));
-
- genSetDPTR (0);
- _flushLazyDPS ();
+ if (size)
+ {
+ // Set two bytes at a time, passed in _AP & A.
+ // dptr will be incremented ONCE by __gptrputWord.
+ //
+ // Note: any change here must be coordinated
+ // with the implementation of __gptrputWord
+ // in device/lib/_gptrput.c
+ emitcode("mov", "_ap, %s",
+ aopGet (AOP (right), offset++, FALSE, FALSE, NULL));
+ MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, NULL));
+
+ genSetDPTR (0);
+ _flushLazyDPS ();
+ emitcode ("lcall", "__gptrputWord");
+ size--;
+ }
+ else
+ {
+ // Only one byte to put.
+ MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, NULL));
- emitcode ("lcall", "__gptrput");
- if (size || (pi && AOP_TYPE (result) != AOP_IMMD))
- emitcode ("inc", "dptr");
+ genSetDPTR (0);
+ _flushLazyDPS ();
+ emitcode ("lcall", "__gptrput");
+ }
+
+ if (size || (pi && AOP_TYPE (result) != AOP_IMMD))
+ {
+ emitcode ("inc", "dptr");
+ }
}
- _endLazyDPSEvaluation ();
+ _endLazyDPSEvaluation ();
}
if (pi && AOP_TYPE (result) != AOP_IMMD) {
+ _startLazyDPSEvaluation ();
+
aopPut (AOP(result),"dpl",0);
aopPut (AOP(result),"dph",1);
if (options.model == MODEL_FLAT24) {
} else {
aopPut (AOP(result),"b",2);
}
+ _endLazyDPSEvaluation ();
+
pi->generated=1;
} else if (OP_SYMBOL(result)->ruonly && AOP_SIZE(right) > 1 &&
(OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) {
static void
genReceive (iCode * ic)
{
-
int size = getSize (operandType (IC_RESULT (ic)));
int offset = 0;
int rb1off ;
- D (emitcode (";", "genReceive ");
- );
+ D (emitcode (";", "genReceive "););
- if (ic->argreg == 1) { /* first parameter */
- if (isOperandInFarSpace (IC_RESULT (ic)) &&
- (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
- IS_TRUE_SYMOP (IC_RESULT (ic))))
- {
- offset = fReturnSizeDS390 - size;
- while (size--)
- {
- emitcode ("push", "%s", (strcmp (fReturn[fReturnSizeDS390 - offset - 1], "a") ?
- fReturn[fReturnSizeDS390 - offset - 1] : "acc"));
- offset++;
- }
- aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
- size = AOP_SIZE (IC_RESULT (ic));
- offset = 0;
- while (size--)
- {
- emitcode ("pop", "acc");
- aopPut (AOP (IC_RESULT (ic)), "a", offset++);
- }
-
- } else {
- _G.accInUse++;
- aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
- _G.accInUse--;
- assignResultValue (IC_RESULT (ic));
- }
- } else { /* second receive onwards */
- /* this gets a little tricky since unused recevies will be
+ if (ic->argreg == 1)
+ {
+ /* first parameter */
+ if (AOP_IS_STR(IC_RESULT(ic)))
+ {
+ /* Nothing to do: it's already in the proper place. */
+ return;
+ }
+ else
+ {
+ bool useDp2;
+
+ useDp2 = isOperandInFarSpace (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)));
+
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE, useDp2);
+ _G.accInUse--;
+
+ /* Sanity checking... */
+ if (AOP_USESDPTR(IC_RESULT(ic)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "genReceive got unexpected DPTR.");
+ }
+ assignResultValue (IC_RESULT (ic));
+ }
+ }
+ else
+ {
+ /* second receive onwards */
+ /* this gets a little tricky since unused recevies will be
eliminated, we have saved the reg in the type field . and
we use that to figure out which register to use */
- aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
- rb1off = ic->argreg;
- while (size--) {
- aopPut (AOP (IC_RESULT (ic)), rb1regs[rb1off++ -5], offset++);
- }
-
- }
- freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+ rb1off = ic->argreg;
+ while (size--)
+ {
+ aopPut (AOP (IC_RESULT (ic)), rb1regs[rb1off++ -5], offset++);
+ }
+ }
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
if (rsym->liveFrom != rsym->liveTo) {
aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
if (AOP_TYPE(IC_RESULT(ic)) != AOP_STR) {
+ _startLazyDPSEvaluation ();
+
aopPut(AOP(IC_RESULT(ic)),"dpl",0);
aopPut(AOP(IC_RESULT(ic)),"dph",1);
aopPut(AOP(IC_RESULT(ic)),"dpx",2);
+
+ _endLazyDPSEvaluation ();
+
}
}
}