Made everything static
-------------------------------------------------------------------------*/
-#define D
+#define D(x)
//#define D(x) x
#include <stdio.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__)
+#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
#include "common.h"
#include "SDCCpeeph.h"
/* first check if r0 & r1 are used by this
instruction, in which case we are in trouble */
- if ((r0iu = bitVectBitValue (ic->rUsed, R0_IDX)) &&
- (r1iu = bitVectBitValue (ic->rUsed, R1_IDX)))
- {
+ r0iu = bitVectBitValue (ic->rUsed, R0_IDX);
+ r1iu = bitVectBitValue (ic->rUsed, R1_IDX);
+ if (r0iu && r1iu) {
goto endOfWorld;
}
/* other wise this is true end of the world */
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"getFreePtr should never reach here");
- exit (0);
+ exit (1);
}
/*-----------------------------------------------------------------*/
aopForSym (iCode * ic, symbol * sym, bool result)
{
asmop *aop;
- memmap *space = SPEC_OCLS (sym->etype);
+ memmap *space;
+
+ wassertl (ic != NULL, "Got a null iCode");
+ wassertl (sym != NULL, "Got a null symbol");
+
+ space = SPEC_OCLS (sym->etype);
/* if already has one */
if (sym->aop)
sym = OP_SYMBOL (op);
-
/* if the type is a conditional */
if (sym->regType == REG_CND)
{
if (sym->ruonly)
{
unsigned i;
+
aop = op->aop = sym->aop = newAsmop (AOP_STR);
aop->size = getSize (sym->type);
for (i = 0; i < fReturnSizeMCS51; i++)
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"aopget got unsupported aop->type");
- exit (0);
+ exit (1);
}
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop */
{
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"aopPut got offset > aop->size");
- exit (0);
+ exit (1);
}
/* will assign value to value */
{
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"aopPut writting to code space");
- exit (0);
+ exit (1);
}
while (offset > aop->coff)
}
{
symbol *lbl = newiTempLabel (NULL);
- emitcode ("clr", "c; oops");
+ emitcode ("clr", "c");
emitcode ("jz", "%05d$", lbl->key + 100);
emitcode ("cpl", "c");
emitcode ("", "%05d$:", lbl->key + 100);
default:
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"aopPut got unsupported aop->type");
- exit (0);
+ exit (1);
}
}
else
{
/* first add without previous c */
- if (!offset)
- emitcode ("add", "a,#0x%02x",
- (unsigned int) (lit & 0x0FFL));
- else
+ if (!offset) {
+ if (!size && lit==-1) {
+ emitcode ("dec", "a");
+ } else {
+ emitcode ("add", "a,#0x%02x",
+ (unsigned int) (lit & 0x0FFL));
+ }
+ } else {
emitcode ("addc", "a,#0x%02x",
(unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
+ }
}
aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
return lic;
}
/* if the operand used or deffed */
- if (bitVectBitValue(ic->uses,op->key) || (unsigned) ic->defKey == op->key) {
+ if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) {
return NULL;
}
lic = lic->next;
/* move it to the result */
size = AOP_SIZE (result);
offset = size - 1;
+ if (size == 1) { /* special case for 1 byte */
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rr", "a");
+ goto release;
+ }
CLRC;
while (size--)
{
MOVA (l);
}
emitcode ("mov", "acc.7,c");
+ release:
aopPut (AOP (result), "a", AOP_SIZE (result) - 1);
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
{
l = aopGet (AOP (left), offset, FALSE, FALSE);
MOVA (l);
+ if (size == 0) { /* special case for 1 byte */
+ emitcode("rl","a");
+ goto release;
+ }
emitcode ("add", "a,acc");
if (AOP_SIZE (result) > 1)
aopPut (AOP (result), "a", offset++);
MOVA (l);
}
emitcode ("mov", "acc.0,c");
+ release:
aopPut (AOP (result), "a", 0);
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
case CPOINTER:
emitcode ("clr", "a");
- emitcode ("movc", "a,%s", "@a+dptr");
+ emitcode ("movc", "a,@a+dptr");
break;
case GPOINTER:
case CPOINTER:
emitcode ("clr", "a");
emitcode ("inc", "dptr");
- emitcode ("movc", "a", "@a+dptr");
+ emitcode ("movc", "a,@a+dptr");
break;
case GPOINTER:
}
else
rname = aopGet (AOP (left), 0, FALSE, FALSE);
-
- aopOp (result, ic, FALSE);
+
+ //aopOp (result, ic, FALSE);
+ aopOp (result, ic, result?TRUE:FALSE);
/* if bitfield then unpack the bits */
if (IS_BITVAR (retype))
genDataPointerSet (right, result, ic);
return;
}
-
+
/* if the value is already in a pointer register
then don't need anything more */
if (!AOP_INPREG (AOP (result)))
int size, offset;
unsigned long lit = 0L;
+ D(emitcode(";","genAssign"));
+
result = IC_RESULT (ic);
right = IC_RIGHT (ic);
aopOp (result, ic, FALSE);
/* if the result is a bit */
- if (AOP_TYPE (result) == AOP_CRY)
+ // if (AOP_TYPE (result) == AOP_CRY /* works only for true symbols */
+ if (IS_BITVAR(OP_SYMBOL(result)->type))
{
/* if the right size is a literal then
we know what the value is */
freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
+/*-----------------------------------------------------------------*/
+/* gen51AggregateAssign - copy complete array's or structures */
+/*-----------------------------------------------------------------*/
+void gen51AggregateAssign(iCode *ic) {
+ operand *left=IC_LEFT(ic);
+ operand *right=IC_RIGHT(ic);
+ char *fromName=OP_SYMBOL(right)->rname;
+ char *toName=OP_SYMBOL(left)->rname;
+ int fromSize=getSize(OP_SYMBOL(right)->type);
+ int toSize=getSize(OP_SYMBOL(left)->type);
+ int count=toSize;
+
+ if (SPEC_OCLS(OP_SYMBOL(left)->etype)!=xdata ||
+ SPEC_OCLS(OP_SYMBOL(right)->etype)!=code) {
+ // well, this code isn't used yet from anywhere else as for initialising
+ fprintf (stderr, "*** error: %s:%d can only assign aggregates from cseg to xseg for now\n", ic->filename, ic->lineno);
+ exit (457);
+ }
+
+ if (fromSize!=toSize) {
+ fprintf (stderr, "*** error: %s:%d aggregates have different size\n",
+ ic->filename, ic->lineno);
+ exit (821);
+ }
+
+#if 1
+ // use the generic memcpy() for now
+ emitcode (";", "initialize %s", OP_SYMBOL(IC_LEFT(ic))->name);
+ emitcode ("mov", "dptr,#_memcpy_PARM_2");
+ emitcode ("mov", "a,#%s", fromName);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("inc", "dptr");
+ emitcode ("mov", "a,#(%s>>8)", fromName);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("inc", "dptr");
+ emitcode ("mov", "a,#%02x; only from cseg for now", 2);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("mov", "dptr,#_memcpy_PARM_3");
+ emitcode ("mov", "a,#(%d>>0); number of bytes", count);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("inc", "dptr");
+ emitcode ("mov", "a,#(%d>>8)", count);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("mov", "dptr,#%s", toName);
+ emitcode ("mov", "b,#%02x; only to xseg for now", 1);
+ emitcode ("lcall", "_memcpy");
+#else
+ // more efficient, but will require the native_memcpy_cs2xs
+ emitcode ("mov", "r0,#%s", fromName);
+ emitcode ("mov", "r1,#(%s>>8)", fromName);
+ emitcode ("mov", "r2,#%s", toName);
+ emitcode ("mov", "r3,#(%s>>8)", toName);
+ emitcode ("mov", "r4,#%d", count);
+ emitcode ("mov", "r5,#(%d>>8)", count);
+ emitcode ("lcall", "_native_memcpy_cs2xs");
+#endif
+}
+
/*-----------------------------------------------------------------*/
/* gen51Code - generate code for 8051 based controllers */
/*-----------------------------------------------------------------*/
addSet (&_G.sendSet, ic);
break;
+ case ARRAYINIT:
+ gen51AggregateAssign(ic);
+ break;
+
default:
ic = ic;
}