emitcode (char *inst, char *fmt, ...)
{
va_list ap;
- char lb[MAX_INLINEASM];
+ char lb[INITIAL_INLINEASM];
char *lbp = lb;
va_start (ap, fmt);
va_end (ap);
}
+/*-----------------------------------------------------------------*/
+/* hasInc - operand is incremented before any other use */
+/*-----------------------------------------------------------------*/
+static iCode *
+hasInc (operand *op, iCode *ic)
+{
+ sym_link *type = operandType(op);
+ sym_link *retype = getSpec (type);
+ iCode *lic = ic->next;
+ int isize ;
+
+ if (IS_BITVAR(retype)||!IS_PTR(type)) return NULL;
+ isize = getSize(type->next);
+ while (lic) {
+ /* if operand of the form op = op + <sizeof *op> */
+ if (lic->op == '+' && isOperandEqual(IC_LEFT(lic),op) &&
+ isOperandEqual(IC_RESULT(lic),op) &&
+ isOperandLiteral(IC_RIGHT(lic)) &&
+ operandLitValue(IC_RIGHT(lic)) == isize) {
+ return lic;
+ }
+ /* if the operand used or deffed */
+ if (bitVectBitValue(ic->uses,op->key) || ((unsigned) ic->defKey == op->key)) {
+ return NULL;
+ }
+ lic = lic->next;
+ }
+ return NULL;
+}
+
/*-----------------------------------------------------------------*/
/* getFreePtr - returns X or Z whichever is free or can be pushed */
/*-----------------------------------------------------------------*/
return NULL;
}
- piCode (ic, stdout);
/* other wise this is true end of the world */
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"getFreePtr should never reach here");
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;
/* 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;
static void
genGoto (iCode * ic)
{
- emitcode ("rjmp", "L%05d:", (IC_LABEL (ic)->key + 100));
+ emitcode ("rjmp", "L%05d", (IC_LABEL (ic)->key + 100));
}
/*-----------------------------------------------------------------*/
return TRUE;
}
emitcode ("subi", "%s,lo8(%d)",
- aopGet (AOP (IC_LEFT (ic)), 0), -icount);
+ aopGet (AOP (IC_LEFT (ic)), 0), 0-icount);
return TRUE;
}
/* 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;
}
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 */
/* genNearPointerGet - emitcode for near pointer fetch */
/*-----------------------------------------------------------------*/
static void
-genMemPointerGet (operand * left, operand * result, iCode * ic)
+genMemPointerGet (operand * left, operand * result, iCode * ic, iCode *pi)
{
asmop *aop = NULL;
regs *preg = NULL;
aop = newAsmop (0);
preg = getFreePtr (ic, &aop, FALSE, 0);
if (isRegPair (AOP (left) )) {
- emitcode ("movw", "%s,%s",aop->aopu.aop_ptr->name);
+ emitcode ("movw", "%s,%s",
+ aop->aopu.aop_ptr->name,
+ aopGet(AOP(left),0));
} else {
emitcode ("mov", "%s,%s", aop->aopu.aop_ptr->name,
aopGet (AOP (left), 0));
exit (0);
}
- freeAsmop (left, NULL, ic, TRUE);
aopOp (result, ic, FALSE);
/* if bitfield then unpack the bits */
int offset = 0;
while (size--) {
- if (size) {
+ if (size || pi) {
emitcode ("ld","%s,%s+",aopGet(AOP(result),offset), rname);
} else {
emitcode ("ld","%s,%s",aopGet(AOP(result),offset), rname);
/* now some housekeeping stuff */
if (gotFreePtr) {
/* we had to allocate for this iCode */
+ if (pi) {
+ if (isRegPair (AOP (left) )) {
+ emitcode ("movw", "%s,%s",
+ aopGet (AOP(left),0),
+ aop->aopu.aop_ptr->name);
+ } else {
+ emitcode ("mov", "%s,%s",
+ aopGet (AOP (left), 0),
+ aop->aopu.aop_ptr->name);
+ emitcode ("mov", "%s,%s",
+ aopGet (AOP (left), 1),
+ aop->aop_ptr2->name);
+ }
+ }
freeAsmop (NULL, aop, ic, TRUE);
} else {
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (result) > 1 &&
- !OP_SYMBOL (left)->remat &&
- (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
+ if ((AOP_SIZE (result) > 1 &&
+ !OP_SYMBOL (left)->remat &&
+ (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) && !pi) {
int size = AOP_SIZE (result) - 1;
emitcode ("sbiw", "%s,%d",frname,size);
}
}
/* done */
+ if (pi) pi->generated = 1;
+ freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/* genCodePointerGet - gget value from code space */
/*-----------------------------------------------------------------*/
static void
-genCodePointerGet (operand * left, operand * result, iCode * ic)
+genCodePointerGet (operand * left, operand * result, iCode * ic, iCode *pi)
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
offset = 0;
while (size--) {
- if (size) {
+ if (size || pi) {
emitcode ("lpm","%s,Z+",aopGet(AOP(result),offset++));
} else {
emitcode ("lpm","%s,Z",aopGet(AOP(result),offset++));
}
}
- freeAsmop (left, NULL, ic, TRUE);
/* now some housekeeping stuff */
if (gotFreePtr) {
/* we had to allocate for this iCode */
+ if (pi) {
+ if (isRegPair(AOP (left))) {
+ emitcode ("movw","%s,r30",aopGet (AOP (left), 0));
+ } else {
+ emitcode ("mov", "%s,r30", aopGet (AOP (left), 0));
+ emitcode ("mov", "%s,r31", aopGet (AOP (left), 1));
+ }
+ }
freeAsmop (NULL, aop, ic, TRUE);
} else {
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (result) > 1 &&
- !OP_SYMBOL (left)->remat &&
- (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
+ if ((AOP_SIZE (result) > 1 &&
+ !OP_SYMBOL (left)->remat &&
+ (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) &&
+ !pi) {
int size = AOP_SIZE (result) - 1;
emitcode ("sbiw", "r30,%d",size);
}
}
/* done */
+ if (pi) pi->generated=1;
+ freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/* genGenPointerGet - gget value from generic pointer space */
/*-----------------------------------------------------------------*/
static void
-genGenPointerGet (operand * left, operand * result, iCode * ic)
+genGenPointerGet (operand * left, operand * result, iCode * ic, iCode *pi)
{
int size, offset;
int gotFreePtr = 0;
} 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;
}
offset = 0;
while (size--) {
- if (size)
+ if (size || pi)
emitcode ("call", "__gptrget_pi");
else
emitcode ("call", "__gptrget");
}
}
- freeAsmop (left, NULL, ic, TRUE);
+
/* now some housekeeping stuff */
if (gotFreePtr) {
/* we had to allocate for this iCode */
+ if (pi) {
+ if (isRegPair(AOP (left))) {
+ emitcode ("movw","%s,r30",aopGet (AOP (left), 0));
+ } else {
+ emitcode ("mov", "%s,r30", aopGet (AOP (left), 0));
+ emitcode ("mov", "%s,r31", aopGet (AOP (left), 1));
+ }
+ }
freeAsmop (NULL, aop, ic, TRUE);
} else {
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (result) > 1 &&
- !OP_SYMBOL (left)->remat &&
- (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
+ if ((AOP_SIZE (result) > 1 &&
+ !OP_SYMBOL (left)->remat &&
+ (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) &&
+ !pi) {
int size = AOP_SIZE (result) - 1;
emitcode ("sbiw", "r30,%d",size);
}
}
+ if (pi) pi->generated=1;
+ freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
static void
-genPointerGet (iCode * ic)
+genPointerGet (iCode * ic, iCode *pi)
{
operand *left, *result;
sym_link *type, *etype;
case IPOINTER:
case PPOINTER:
case FPOINTER:
- genMemPointerGet (left, result, ic);
+ genMemPointerGet (left, result, ic, pi);
break;
case CPOINTER:
- genCodePointerGet (left, result, ic);
+ genCodePointerGet (left, result, ic, pi);
break;
case GPOINTER:
- genGenPointerGet (left, result, ic);
+ genGenPointerGet (left, result, ic, pi);
break;
}
/* genNearPointerSet - emitcode for near pointer put */
/*-----------------------------------------------------------------*/
static void
-genMemPointerSet (operand * right, operand * result, iCode * ic)
+genMemPointerSet (operand * right, operand * result, iCode * ic, iCode *pi)
{
asmop *aop = NULL;
- char *frname, *rname, *l;
+ char *frname = NULL, *rname, *l;
int gotFreePtr = 0;
sym_link *retype;
sym_link *ptype = operandType (result);
aop = newAsmop (0);
getFreePtr (ic, &aop, FALSE, 0);
if (isRegPair (AOP (result) )) {
- emitcode ("movw", "%s,%s",aop->aopu.aop_ptr->name);
+ emitcode ("movw", "%s,%s",aop->aopu.aop_ptr->name,
+ aopGet(AOP (result), 0));
} else {
emitcode ("mov", "%s,%s", aop->aopu.aop_ptr->name,
aopGet (AOP (result), 0));
emitcode ("mov", "%s,%s", aop->aop_ptr2->name,
aopGet (AOP (result), 1));
}
- gotFreePtr = 1;
+ gotFreePtr = 1;
} else {
aop = AOP(result);
frname = aopGet(aop,0);
while (size--) {
l = aopGet (AOP (right), offset);
- if (size)
- emitcode ("sts", "%s+,%s", rname,l);
+ if (size || pi)
+ emitcode ("st", "%s+,%s", rname,l);
else
- emitcode ("sts", "%s,%s", rname,l);
+ emitcode ("st", "%s,%s", rname,l);
offset++;
}
}
/* now some housekeeping stuff */
- freeAsmop (result, NULL, ic, TRUE);
if (gotFreePtr) {
/* we had to allocate for this iCode */
+ if (pi) {
+ if (isRegPair (AOP (result) )) {
+ emitcode ("movw", "%s,%s",
+ aopGet(AOP(result),0),
+ aop->aopu.aop_ptr->name);
+ } else {
+ emitcode ("mov", "%s,%s", aop->aopu.aop_ptr->name,
+ aopGet (AOP (result), 0));
+ emitcode ("mov", "%s,%s", aop->aop_ptr2->name,
+ aopGet (AOP (result), 1));
+ }
+ }
freeAsmop (NULL, aop, ic, TRUE);
} else {
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (right) > 1 &&
- !OP_SYMBOL (result)->remat &&
- (OP_SYMBOL (right)->liveTo > ic->seq || ic->depth)) {
+ if ((AOP_SIZE (right) > 1 &&
+ !OP_SYMBOL (result)->remat &&
+ (OP_SYMBOL (right)->liveTo > ic->seq || ic->depth)) && !pi) {
int size = AOP_SIZE (right) - 1;
emitcode ("sbiw", "%s,%d",frname,size);
}
}
/* done */
+ if (pi) pi->generated = 1;
+ freeAsmop (result, NULL, ic, TRUE);
freeAsmop (right, NULL, ic, TRUE);
}
/* genGenPointerSet - set value from generic pointer space */
/*-----------------------------------------------------------------*/
static void
-genGenPointerSet (operand * right, operand * result, iCode * ic)
+genGenPointerSet (operand * right, operand * result, iCode * ic, iCode *pi)
{
int size, offset;
int gotFreePtr = 0;
} else {
aop = newAsmop(0);
getFreePtr(ic,&aop,FALSE,TRUE);
-
- emitcode ("mov", "r30,%s", aopGet (AOP (result), 0));
- emitcode ("mov", "r31,%s", aopGet (AOP (result), 1));
- emitcode ("mov", "r0,%s", aopGet (AOP (result), 2));
+ if (isRegPair(AOP(result))) {
+ emitcode ("movw", "r30,%s", aopGet (AOP (result), 0));
+ } else {
+ emitcode ("mov", "r30,%s", aopGet (AOP (result), 0));
+ emitcode ("mov", "r31,%s", aopGet (AOP (result), 1));
+ }
+ emitcode ("mov", "r24,%s", aopGet (AOP (result), 2));
gotFreePtr=1;
}
char *l = aopGet(AOP (right), offset++);
MOVR0(l);
- if (size)
+ if (size || pi)
emitcode ("call", "__gptrput_pi");
else
emitcode ("call", "__gptrput");
}
}
- freeAsmop (right, NULL, ic, TRUE);
/* now some housekeeping stuff */
if (gotFreePtr) {
/* we had to allocate for this iCode */
+ if (pi) {
+ if (isRegPair(AOP(result))) {
+ emitcode ("movw", "%s,r30", aopGet (AOP (result), 0));
+ } else {
+ emitcode ("mov", "%s,r30", aopGet (AOP (result), 0));
+ emitcode ("mov", "%s,r31", aopGet (AOP (result), 1));
+ }
+ }
freeAsmop (NULL, aop, ic, TRUE);
} else {
if size > 0 && this could be used again
we have to point it back to where it
belongs */
- if (AOP_SIZE (right) > 1 &&
- !OP_SYMBOL (result)->remat &&
- (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) {
+ if ((AOP_SIZE (right) > 1 &&
+ !OP_SYMBOL (result)->remat &&
+ (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) && !pi) {
int size = AOP_SIZE (right) - 1;
emitcode ("sbiw", "r30,%d",size);
}
}
+ if (pi) pi->generated = 1;
+ freeAsmop (right, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
static void
-genPointerSet (iCode * ic)
+genPointerSet (iCode * ic, iCode *pi)
{
operand *right, *result;
sym_link *type, *etype;
case IPOINTER:
case PPOINTER:
case FPOINTER:
- genMemPointerSet (right, result, ic);
+ genMemPointerSet (right, result, ic, pi);
break;
case GPOINTER:
- genGenPointerSet (right, result, ic);
+ genGenPointerSet (right, result, ic, pi);
break;
}
genIfx (iCode * ic, iCode * popIc)
{
operand *cond = IC_COND (ic);
- int isbit = 0;
+ char *cname ;
+ symbol *lbl;
aopOp (cond, ic, FALSE);
- /* get the value into acc */
- if (AOP_TYPE (cond) != AOP_CRY)
- toBoolean (cond, "", 0);
- else
- isbit = 1;
+ /* get the value into acc */
+ if (AOP_SIZE(cond) == 1 && AOP_ISHIGHREG(AOP(cond),0)) {
+ cname = aopGet(AOP(cond),0);
+ } else {
+ toBoolean (cond, "r24", 1);
+ cname = "r24";
+ }
/* the result is now in the accumulator */
freeAsmop (cond, NULL, ic, TRUE);
/* if there was something to be popped then do it */
if (popIc)
genIpop (popIc);
-
- /* if the condition is a bit variable */
- /* if (isbit && IS_ITEMP(cond) && SPIL_LOC(cond)) { */
- /* // genIfxJump(ic,SPIL_LOC(cond)->rname); */
- /* } */
- /* else */
- /* if (isbit && !IS_ITEMP(cond)) */
- /* // genIfxJump(ic,OP_SYMBOL(cond)->rname); */
- /* else */
- /* // genIfxJump(ic,"a"); */
-
+
+ emitcode("cpi","%s,0",cname);
+ lbl = newiTempLabel(NULL);
+ if (IC_TRUE(ic)) {
+ emitcode ("brne","L%05d",lbl->key);
+ emitcode ("jmp","L%05d",IC_TRUE(ic)->key);
+ emitcode ("","L%05d:",lbl->key);
+ } else {
+ emitcode ("breq","L%05d",lbl->key);
+ emitcode ("jmp","L%05d",IC_FALSE(ic)->key);
+ emitcode ("","L%05d:",lbl->key);
+ }
ic->generated = 1;
}
-
+/* here */
/*-----------------------------------------------------------------*/
/* genAddrOf - generates code for address of */
/*-----------------------------------------------------------------*/
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;
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++);
}
l = one;
break;
case CPOINTER:
- l = "#0x02";
+ l = "0x02";
break;
case PPOINTER:
- l = "#0x03";
+ l = "0x03";
break;
default:
break;
case GET_VALUE_AT_ADDRESS:
- genPointerGet (ic);
+ genPointerGet (ic, hasInc(IC_LEFT(ic),ic));
break;
case '=':
if (POINTER_SET (ic))
- genPointerSet (ic);
+ genPointerSet (ic, hasInc(IC_RESULT(ic),ic));
else
genAssign (ic);
break;
default:
ic = ic;
- /* piCode(ic,stdout); */
-
}
}