#include "ralloc.h"
#include "gen.h"
-char *aopLiteral (value *val, int offset);
+char *aopLiteral (value * val, int offset);
extern int allocInfo;
/* this is the down and dirty file with all kinds of
routines may be reusable, will have to see */
static char *zero = "0x00";
-static char *one = "0x01";
-static char *spname ;
+static char *one = "0x01";
+static char *spname;
-char *fReturnAVR[] = {"r16","r17","r18","r19" };
-unsigned fAVRReturnSize = 4; /* shared with ralloc.c */
+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"};
-static char *tscr[4] = {"r0","r1","r24","r25"};
-static struct {
- short xPushed;
- short zPushed;
- short accInUse;
- short inLine;
- short debugLine;
- short nRegsSaved;
- set *sendSet;
-} _G;
-
-extern int avr_ptrRegReq ;
+static char *larray[4] =
+{"lo8", "hi8", "hlo8", "hhi8"};
+static char *tscr[4] =
+{"r0", "r1", "r24", "r25"};
+static struct
+ {
+ short xPushed;
+ short zPushed;
+ short accInUse;
+ short inLine;
+ short debugLine;
+ short nRegsSaved;
+ set *sendSet;
+ }
+_G;
+
+extern int avr_ptrRegReq;
extern int avr_nRegs;
extern FILE *codeOutFile;
-static void saverbank (int, iCode *,bool);
+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};
+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
/*-----------------------------------------------------------------*/
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
-static void emitcode (char *inst,char *fmt, ...)
+static void
+emitcode (char *inst, char *fmt,...)
{
va_list ap;
char lb[MAX_INLINEASM];
char *lbp = lb;
- va_start(ap,fmt);
+ va_start (ap, fmt);
- if (inst && *inst) {
- if (fmt && *fmt)
- sprintf(lb,"%s\t",inst);
- else
- sprintf(lb,"%s",inst);
- vsprintf(lb+(strlen(lb)),fmt,ap);
- } else
- vsprintf(lb,fmt,ap);
+ if (inst && *inst)
+ {
+ if (fmt && *fmt)
+ sprintf (lb, "%s\t", inst);
+ else
+ sprintf (lb, "%s", inst);
+ vsprintf (lb + (strlen (lb)), fmt, ap);
+ }
+ else
+ vsprintf (lb, fmt, ap);
- while (isspace(*lbp)) lbp++;
+ while (isspace (*lbp))
+ lbp++;
if (lbp && *lbp)
lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(lb)) :
- (lineHead = newLineNode(lb)));
+ connectLine (lineCurr, newLineNode (lb)) :
+ (lineHead = newLineNode (lb)));
lineCurr->isInline = _G.inLine;
- lineCurr->isDebug = _G.debugLine;
- va_end(ap);
+ lineCurr->isDebug = _G.debugLine;
+ va_end (ap);
}
/*-----------------------------------------------------------------*/
/* getFreePtr - returns X or Z whichever is free or can be pushed */
/*-----------------------------------------------------------------*/
-static regs *getFreePtr (iCode *ic, asmop **aopp, bool result, bool zonly)
+static regs *
+getFreePtr (iCode * ic, asmop ** aopp, bool result, bool zonly)
{
- bool xiu = FALSE , ziu = FALSE;
- bool xou = FALSE , zou = FALSE;
+ bool xiu = FALSE, ziu = FALSE;
+ bool xou = FALSE, zou = FALSE;
/* the logic: if x & z used in the instruction
then we are in trouble otherwise */
/* first check if x & z are used by this
instruction, in which case we are in trouble */
- if ((xiu = bitVectBitValue(ic->rUsed,X_IDX)) &&
- (ziu = bitVectBitValue(ic->rUsed,Z_IDX)))
+ if ((xiu = bitVectBitValue (ic->rUsed, X_IDX)) &&
+ (ziu = bitVectBitValue (ic->rUsed, Z_IDX)))
{
goto endOfWorld;
}
- xou = bitVectBitValue(ic->rMask,X_IDX);
- zou = bitVectBitValue(ic->rMask,Z_IDX);
+ xou = bitVectBitValue (ic->rMask, X_IDX);
+ zou = bitVectBitValue (ic->rMask, Z_IDX);
/* if no usage of Z then return it */
- if (!ziu && !zou) {
- ic->rUsed = bitVectSetBit(ic->rUsed,Z_IDX);
- (*aopp)->type = AOP_Z;
+ if (!ziu && !zou)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, Z_IDX);
+ (*aopp)->type = AOP_Z;
- (*aopp)->aop_ptr2 = avr_regWithIdx(R31_IDX);
- return (*aopp)->aopu.aop_ptr = avr_regWithIdx(R30_IDX);
- }
+ (*aopp)->aop_ptr2 = avr_regWithIdx (R31_IDX);
+ return (*aopp)->aopu.aop_ptr = avr_regWithIdx (R30_IDX);
+ }
/* if no usage of X then return it */
- if (!xiu && !xou && !zonly) {
- ic->rUsed = bitVectSetBit(ic->rUsed,X_IDX);
- (*aopp)->type = AOP_X;
+ if (!xiu && !xou && !zonly)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, X_IDX);
+ (*aopp)->type = AOP_X;
- (*aopp)->aop_ptr2 = avr_regWithIdx(R27_IDX);
- return (*aopp)->aopu.aop_ptr = avr_regWithIdx(R26_IDX);
- }
+ (*aopp)->aop_ptr2 = avr_regWithIdx (R27_IDX);
+ return (*aopp)->aopu.aop_ptr = avr_regWithIdx (R26_IDX);
+ }
/* if z not used then */
- if (!ziu) {
- /* push it if not already pushed */
- if (!_G.zPushed) {
- emitcode ("push","%s",
- avr_regWithIdx(R30_IDX)->dname);
- emitcode ("push","%s",
- avr_regWithIdx(R31_IDX)->dname);
- _G.zPushed++ ;
+ if (!ziu)
+ {
+ /* push it if not already pushed */
+ if (!_G.zPushed)
+ {
+ emitcode ("push", "%s",
+ avr_regWithIdx (R30_IDX)->dname);
+ emitcode ("push", "%s",
+ avr_regWithIdx (R31_IDX)->dname);
+ _G.zPushed++;
+ }
+
+ ic->rUsed = bitVectSetBit (ic->rUsed, Z_IDX);
+ (*aopp)->type = AOP_Z;
+ (*aopp)->aop_ptr2 = avr_regWithIdx (R31_IDX);
+ return (*aopp)->aopu.aop_ptr = avr_regWithIdx (R30_IDX);
}
- ic->rUsed = bitVectSetBit(ic->rUsed,Z_IDX);
- (*aopp)->type = AOP_Z;
- (*aopp)->aop_ptr2 = avr_regWithIdx(R31_IDX);
- return (*aopp)->aopu.aop_ptr = avr_regWithIdx(R30_IDX);
- }
-
/* now we know they both have usage */
/* if x not used in this instruction */
- if (!xiu && !zonly) {
- /* push it if not already pushed */
- if (!_G.xPushed) {
- emitcode ("push","%s",
- avr_regWithIdx(R26_IDX)->dname);
- emitcode ("push","%s",
- avr_regWithIdx(R27_IDX)->dname);
- _G.xPushed++ ;
+ if (!xiu && !zonly)
+ {
+ /* push it if not already pushed */
+ if (!_G.xPushed)
+ {
+ emitcode ("push", "%s",
+ avr_regWithIdx (R26_IDX)->dname);
+ emitcode ("push", "%s",
+ avr_regWithIdx (R27_IDX)->dname);
+ _G.xPushed++;
+ }
+
+ ic->rUsed = bitVectSetBit (ic->rUsed, X_IDX);
+ (*aopp)->type = AOP_X;
+
+ (*aopp)->aop_ptr2 = avr_regWithIdx (R27_IDX);
+ return (*aopp)->aopu.aop_ptr = avr_regWithIdx (R26_IDX);
}
- ic->rUsed = bitVectSetBit(ic->rUsed,X_IDX);
- (*aopp)->type = AOP_X;
-
- (*aopp)->aop_ptr2 = avr_regWithIdx(R27_IDX);
- return (*aopp)->aopu.aop_ptr = avr_regWithIdx(R26_IDX);
- }
-
- endOfWorld :
- /* I said end of world but not quite end of world yet */
- /* if this is a result then we can push it on the stack*/
- if (result) {
+endOfWorld:
+ /* I said end of world but not quite end of world yet */
+ /* if this is a result then we can push it on the stack */
+ if (result)
+ {
(*aopp)->type = AOP_STK;
return NULL;
}
- piCode(ic,stdout);
+ piCode (ic, stdout);
/* other wise this is true end of the world */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "getFreePtr should never reach here");
- exit(0);
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "getFreePtr should never reach here");
+ exit (0);
}
/*-----------------------------------------------------------------*/
/* newAsmop - creates a new asmOp */
/*-----------------------------------------------------------------*/
-static asmop *newAsmop (short type)
+static asmop *
+newAsmop (short type)
{
asmop *aop;
- aop = Safe_calloc(1,sizeof(asmop));
+ aop = Safe_calloc (1, sizeof (asmop));
aop->type = type;
return aop;
}
/*-----------------------------------------------------------------*/
/* pointerCode - returns the code for a pointer type */
/*-----------------------------------------------------------------*/
-static int pointerCode (sym_link *etype)
+static int
+pointerCode (sym_link * etype)
{
- return PTR_TYPE(SPEC_OCLS(etype));
+ return PTR_TYPE (SPEC_OCLS (etype));
}
/*-----------------------------------------------------------------*/
/* aopForSym - for a true symbol */
/*-----------------------------------------------------------------*/
-static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
+static asmop *
+aopForSym (iCode * ic, symbol * sym, bool result)
{
asmop *aop;
- memmap *space= SPEC_OCLS(sym->etype);
+ memmap *space = SPEC_OCLS (sym->etype);
/* if already has one */
if (sym->aop)
/* assign depending on the storage class */
/* if it is on the stack */
- if (sym->onStack) {
- sym->aop = aop = newAsmop(0);
- aop->size = getSize(sym->type);
-
- /* we can use std / ldd instruction */
- if (sym->stack > 0 && (sym->stack + getSize(sym->type) - 1) <= 63) {
- aop->type = AOP_STK_D;
- aop->aopu.aop_stk = sym->stack;
+ if (sym->onStack)
+ {
+ sym->aop = aop = newAsmop (0);
+ aop->size = getSize (sym->type);
+
+ /* we can use std / ldd instruction */
+ if (sym->stack > 0 && (sym->stack + getSize (sym->type) - 1) <= 63)
+ {
+ aop->type = AOP_STK_D;
+ aop->aopu.aop_stk = sym->stack;
+ return aop;
+ }
+
+ /* otherwise get a free pointer register X/Z */
+ aop->aopu.aop_ptr = getFreePtr (ic, &aop, result, FALSE);
+
+ /* now assign the address of the variable to
+ the pointer register */
+ if (aop->type != AOP_STK)
+ {
+ emitcode ("movw", "%s,r28", aop->aopu.aop_ptr->name);
+ if (sym->stack < 0)
+ {
+ if ((sym->stack - _G.nRegsSaved) > -63)
+ {
+ emitcode ("sbiw", "%s,0x%02x",
+ aop->aopu.aop_ptr->name,
+ (sym->stack - _G.nRegsSaved));
+ }
+ else
+ {
+ emitcode ("subi", "%s,lo8(%d)", aop->aopu.aop_ptr->name,
+ sym->stack - _G.nRegsSaved);
+ emitcode ("sbci", "%s,hi8(%d)", aop->aop_ptr2->name,
+ sym->stack - _G.nRegsSaved);
+ }
+ }
+ else
+ {
+ if (sym->stack <= 63)
+ {
+ emitcode ("adiw", "%s,0x%02x", aop->aopu.aop_ptr->name, sym->stack);
+ }
+ else
+ {
+ emitcode ("subi", "%s,lo8(-%d)", aop->aopu.aop_ptr->name, sym->stack);
+ emitcode ("sbci", "%s,hi8(-%d)", aop->aop_ptr2->name, sym->stack);
+ }
+ }
+ }
return aop;
}
- /* otherwise get a free pointer register X/Z */
- aop->aopu.aop_ptr = getFreePtr(ic,&aop,result,FALSE);
-
- /* now assign the address of the variable to
- the pointer register */
- if (aop->type != AOP_STK) {
- emitcode("movw","%s,r28",aop->aopu.aop_ptr->name);
- if (sym->stack < 0) {
- if ((sym->stack - _G.nRegsSaved) > -63) {
- emitcode("sbiw","%s,0x%02x",
- aop->aopu.aop_ptr->name,
- (sym->stack - _G.nRegsSaved));
- } else {
- emitcode("subi","%s,lo8(%d)", aop->aopu.aop_ptr->name,
- sym->stack - _G.nRegsSaved);
- emitcode("sbci","%s,hi8(%d)",aop->aop_ptr2->name,
- sym->stack - _G.nRegsSaved);
- }
- } else {
- if (sym->stack <= 63) {
- emitcode("adiw","%s,0x%02x",aop->aopu.aop_ptr->name,sym->stack);
- } else {
- emitcode("subi","%s,lo8(-%d)",aop->aopu.aop_ptr->name,sym->stack);
- emitcode("sbci","%s,hi8(-%d)",aop->aop_ptr2->name,sym->stack);
- }
- }
- }
- return aop;
- }
-
/* if in bit space */
- if (IN_BITSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_CRY);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- return aop;
- }
+ if (IN_BITSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_CRY);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ return aop;
+ }
/* if it is in direct space */
- if (IN_DIRSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_DIR);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- return aop;
- }
+ if (IN_DIRSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_DIR);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ return aop;
+ }
/* special case for a function */
- if (IS_FUNC(sym->type)) {
- sym->aop = aop = newAsmop(AOP_IMMD);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(sym->rname)+1);
- strcpy(aop->aopu.aop_immd,sym->rname);
- aop->size = FPTRSIZE;
- return aop;
- }
+ if (IS_FUNC (sym->type))
+ {
+ sym->aop = aop = newAsmop (AOP_IMMD);
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (sym->rname) + 1);
+ strcpy (aop->aopu.aop_immd, sym->rname);
+ aop->size = FPTRSIZE;
+ return aop;
+ }
/* only remaining is code / eeprom which will need pointer reg */
/* if it is in code space */
- sym->aop = aop = newAsmop(0);
+ sym->aop = aop = newAsmop (0);
- if (IN_CODESPACE(space))
+ if (IN_CODESPACE (space))
aop->code = 1;
- aop->aopu.aop_ptr = getFreePtr(ic,&aop,result,aop->code);
- aop->size = getSize(sym->type);
- emitcode ("ldi","%s,lo8(%s)",aop->aopu.aop_ptr->name,sym->rname);
- emitcode ("ldi","%s,hi8(%s)",aop->aop_ptr2);
+ aop->aopu.aop_ptr = getFreePtr (ic, &aop, result, aop->code);
+ aop->size = getSize (sym->type);
+ emitcode ("ldi", "%s,lo8(%s)", aop->aopu.aop_ptr->name, sym->rname);
+ emitcode ("ldi", "%s,hi8(%s)", aop->aop_ptr2);
return aop;
}
/*-----------------------------------------------------------------*/
/* aopForRemat - rematerialzes an object */
/*-----------------------------------------------------------------*/
-static asmop *aopForRemat (symbol *sym)
+static asmop *
+aopForRemat (symbol * sym)
{
iCode *ic = sym->rematiCode;
- asmop *aop = newAsmop(AOP_IMMD);
+ asmop *aop = newAsmop (AOP_IMMD);
int val = 0;
- for (;;) {
- if (ic->op == '+')
- val += (int) operandLitValue(IC_RIGHT(ic));
- else if (ic->op == '-')
- val -= (int) operandLitValue(IC_RIGHT(ic));
- else
- break;
+ for (;;)
+ {
+ if (ic->op == '+')
+ val += (int) operandLitValue (IC_RIGHT (ic));
+ else if (ic->op == '-')
+ val -= (int) operandLitValue (IC_RIGHT (ic));
+ else
+ break;
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- }
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ }
if (val)
- sprintf(buffer,"(%s %c 0x%04x)",
- OP_SYMBOL(IC_LEFT(ic))->rname,
- val >= 0 ? '+' : '-',
- abs(val) & 0xffff);
+ sprintf (buffer, "(%s %c 0x%04x)",
+ OP_SYMBOL (IC_LEFT (ic))->rname,
+ val >= 0 ? '+' : '-',
+ abs (val) & 0xffff);
else
- strcpy(buffer,OP_SYMBOL(IC_LEFT(ic))->rname);
+ strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(buffer)+1);
- strcpy(aop->aopu.aop_immd,buffer);
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (buffer) + 1);
+ strcpy (aop->aopu.aop_immd, buffer);
return aop;
}
/*-----------------------------------------------------------------*/
/* regsInCommon - two operands have some registers in common */
/*-----------------------------------------------------------------*/
-static bool regsInCommon (operand *op1, operand *op2)
+static bool
+regsInCommon (operand * op1, operand * op2)
{
symbol *sym1, *sym2;
int i;
/* if they have registers in common */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE ;
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
if (sym1->nRegs == 0 || sym2->nRegs == 0)
- return FALSE ;
-
- for (i = 0 ; i < sym1->nRegs ; i++) {
- int j;
- if (!sym1->regs[i])
- continue ;
-
- for (j = 0 ; j < sym2->nRegs ;j++ ) {
- if (!sym2->regs[j])
- continue ;
+ return FALSE;
- if (sym2->regs[j] == sym1->regs[i])
- return TRUE ;
+ for (i = 0; i < sym1->nRegs; i++)
+ {
+ int j;
+ if (!sym1->regs[i])
+ continue;
+
+ for (j = 0; j < sym2->nRegs; j++)
+ {
+ if (!sym2->regs[j])
+ continue;
+
+ if (sym2->regs[j] == sym1->regs[i])
+ return TRUE;
+ }
}
- }
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* operandsEqu - equivalent */
/*-----------------------------------------------------------------*/
-static bool operandsEqu ( operand *op1, operand *op2)
+static bool
+operandsEqu (operand * op1, operand * op2)
{
symbol *sym1, *sym2;
/* if they not symbols */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
/* if both are itemps & one is spilt
and the other is not then false */
- if (IS_ITEMP(op1) && IS_ITEMP(op2) &&
- sym1->isspilt != sym2->isspilt )
- return FALSE ;
+ if (IS_ITEMP (op1) && IS_ITEMP (op2) &&
+ sym1->isspilt != sym2->isspilt)
+ return FALSE;
/* if they are the same */
if (sym1 == sym2)
- return TRUE ;
+ return TRUE;
- if (strcmp(sym1->rname,sym2->rname) == 0)
+ if (strcmp (sym1->rname, sym2->rname) == 0)
return TRUE;
/* if left is a tmp & right is not */
- if (IS_ITEMP(op1) &&
- !IS_ITEMP(op2) &&
- sym1->isspilt &&
+ if (IS_ITEMP (op1) &&
+ !IS_ITEMP (op2) &&
+ sym1->isspilt &&
(sym1->usl.spillLoc == sym2))
return TRUE;
- if (IS_ITEMP(op2) &&
- !IS_ITEMP(op1) &&
- sym2->isspilt &&
+ if (IS_ITEMP (op2) &&
+ !IS_ITEMP (op1) &&
+ sym2->isspilt &&
sym1->level > 0 &&
(sym2->usl.spillLoc == sym1))
- return TRUE ;
+ return TRUE;
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* sameRegs - two asmops have the same registers */
/*-----------------------------------------------------------------*/
-static bool sameRegs (asmop *aop1, asmop *aop2 )
+static bool
+sameRegs (asmop * aop1, asmop * aop2)
{
int i;
if (aop1 == aop2)
- return TRUE ;
+ return TRUE;
if (aop1->type != AOP_REG ||
- aop2->type != AOP_REG )
- return FALSE ;
+ aop2->type != AOP_REG)
+ return FALSE;
- if (aop1->size != aop2->size )
- return FALSE ;
+ if (aop1->size != aop2->size)
+ return FALSE;
- for (i = 0 ; i < aop1->size ; i++ )
+ for (i = 0; i < aop1->size; i++)
if (aop1->aopu.aop_reg[i] !=
- aop2->aopu.aop_reg[i] )
- return FALSE ;
+ aop2->aopu.aop_reg[i])
+ return FALSE;
- return TRUE ;
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* isRegPair - for size 2 if this operand has a register pair */
/*-----------------------------------------------------------------*/
-static int isRegPair (asmop *aop)
+static int
+isRegPair (asmop * aop)
{
- if (!aop || aop->size != 2) return 0;
- if (aop->type == AOP_X || aop->type == AOP_Z) return 1;
- if (aop->type != AOP_REG) return 0;
+ if (!aop || aop->size != 2)
+ return 0;
+ if (aop->type == AOP_X || aop->type == AOP_Z)
+ return 1;
+ if (aop->type != AOP_REG)
+ return 0;
if ((aop->aopu.aop_reg[1]->rIdx -
- aop->aopu.aop_reg[0]->rIdx) == 1) return 1;
+ aop->aopu.aop_reg[0]->rIdx) == 1)
+ return 1;
return 0;
}
/*-----------------------------------------------------------------*/
/* aopOp - allocates an asmop for an operand : */
/*-----------------------------------------------------------------*/
-static void aopOp (operand *op, iCode *ic, bool result)
+static void
+aopOp (operand * op, iCode * ic, bool result)
{
asmop *aop;
symbol *sym;
int i;
if (!op)
- return ;
+ return;
/* if this a literal */
- if (IS_OP_LITERAL(op)) {
- op->aop = aop = newAsmop(AOP_LIT);
- aop->aopu.aop_lit = op->operand.valOperand;
- aop->size = getSize(operandType(op));
- return;
- }
+ if (IS_OP_LITERAL (op))
+ {
+ op->aop = aop = newAsmop (AOP_LIT);
+ aop->aopu.aop_lit = op->operand.valOperand;
+ aop->size = getSize (operandType (op));
+ return;
+ }
/* if already has a asmop then continue */
if (op->aop)
- return ;
+ return;
/* if the underlying symbol has a aop */
- if (IS_SYMOP(op) && OP_SYMBOL(op)->aop) {
- op->aop = OP_SYMBOL(op)->aop;
- return;
- }
+ if (IS_SYMOP (op) && OP_SYMBOL (op)->aop)
+ {
+ op->aop = OP_SYMBOL (op)->aop;
+ return;
+ }
/* if this is a true symbol */
- if (IS_TRUE_SYMOP(op)) {
- op->aop = aopForSym(ic,OP_SYMBOL(op),result);
- return ;
- }
+ if (IS_TRUE_SYMOP (op))
+ {
+ op->aop = aopForSym (ic, OP_SYMBOL (op), result);
+ return;
+ }
/* this is a temporary : this has
only four choices :
d) conditional
e) can be a return use only */
- sym = OP_SYMBOL(op);
+ sym = OP_SYMBOL (op);
/* if the type is a conditional */
- if (sym->regType == REG_CND) {
- aop = op->aop = sym->aop = newAsmop(AOP_CRY);
- aop->size = 0;
- return;
- }
+ if (sym->regType == REG_CND)
+ {
+ aop = op->aop = sym->aop = newAsmop (AOP_CRY);
+ aop->size = 0;
+ return;
+ }
/* if it is spilt then two situations
a) is rematerialize
b) has a spill location */
- if (sym->isspilt || sym->nRegs == 0) {
+ if (sym->isspilt || sym->nRegs == 0)
+ {
- /* rematerialize it NOW */
- if (sym->remat) {
+ /* rematerialize it NOW */
+ if (sym->remat)
+ {
+ sym->aop = op->aop = aop =
+ aopForRemat (sym);
+ aop->size = getSize (sym->type);
+ return;
+ }
+
+ if (sym->accuse)
+ {
+ assert ("ACC_USE cannot happen in AVR\n");
+ }
+
+ if (sym->ruonly)
+ {
+ int i;
+ aop = op->aop = sym->aop = newAsmop (AOP_STR);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < (int) fAVRReturnSize; i++)
+ aop->aopu.aop_str[i] = fAVRReturn[i];
+ return;
+ }
+
+ /* else spill location */
sym->aop = op->aop = aop =
- aopForRemat (sym);
- aop->size = getSize(sym->type);
- return;
- }
-
- if (sym->accuse) {
- assert("ACC_USE cannot happen in AVR\n");
- }
-
- if (sym->ruonly ) {
- int i;
- aop = op->aop = sym->aop = newAsmop(AOP_STR);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < (int) fAVRReturnSize ; i++ )
- aop->aopu.aop_str[i] = fAVRReturn[i];
+ aopForSym (ic, sym->usl.spillLoc, result);
+ aop->size = getSize (sym->type);
return;
}
- /* else spill location */
- sym->aop = op->aop = aop =
- aopForSym(ic,sym->usl.spillLoc,result);
- aop->size = getSize(sym->type);
- return;
- }
-
/* must be in a register */
- sym->aop = op->aop = aop = newAsmop(AOP_REG);
+ sym->aop = op->aop = aop = newAsmop (AOP_REG);
aop->size = sym->nRegs;
- for ( i = 0 ; i < sym->nRegs ;i++)
+ for (i = 0; i < sym->nRegs; i++)
aop->aopu.aop_reg[i] = sym->regs[i];
}
/*-----------------------------------------------------------------*/
/* freeAsmop - free up the asmop given to an operand */
/*----------------------------------------------------------------*/
-static void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
+static void
+freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
{
- asmop *aop ;
+ asmop *aop;
if (!op)
aop = aaop;
aop = op->aop;
if (!aop)
- return ;
+ return;
if (aop->freed)
goto dealloc;
/* depending on the asmop type only three cases need work AOP_RO
, AOP_R1 && AOP_STK */
- switch (aop->type) {
- case AOP_X :
- if (_G.xPushed ) {
- if (pop) {
- emitcode ("pop","r26");
- emitcode ("pop","r27");
- _G.xPushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,X_IDX);
- break;
-
- case AOP_Z :
- if (_G.zPushed ) {
- if (pop) {
- emitcode ("pop","r30");
- emitcode ("pop","r31");
- _G.zPushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,Z_IDX);
- break;
-
- case AOP_STK :
+ switch (aop->type)
{
- int sz = aop->size;
- int stk = aop->aopu.aop_stk + aop->size;
- bitVectUnSetBit(ic->rUsed,X_IDX);
- bitVectUnSetBit(ic->rUsed,Z_IDX);
-
- getFreePtr(ic,&aop,FALSE,0);
-
- emitcode ("movw","%s,r28");
- if (stk) {
- if (stk <= 63 && stk > 0) {
- emitcode ("adiw","%s,0x%02x",aop->aopu.aop_ptr->name,stk+1);
- } else {
- emitcode ("subi","%s,lo8(%d)",aop->aopu.aop_ptr->name,-(stk+1));
- emitcode ("sbci","%s,hi8(%d)",aop->aop_ptr2->name,-(stk+1));
- }
- }
+ case AOP_X:
+ if (_G.xPushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "r26");
+ emitcode ("pop", "r27");
+ _G.xPushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, X_IDX);
+ break;
- while (sz--) {
- emitcode("pop","r24");
- emitcode("st","-%s,r24",aop->type == AOP_X ? "X" : "Z");
- if (!sz) break;
- }
- op->aop = aop;
- freeAsmop(op,NULL,ic,TRUE);
- if (_G.xPushed) {
- emitcode("pop","r26");
- emitcode("pop","r27");
- _G.xPushed--;
- }
+ case AOP_Z:
+ if (_G.zPushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "r30");
+ emitcode ("pop", "r31");
+ _G.zPushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, Z_IDX);
+ break;
- if (_G.zPushed) {
- emitcode("pop","r30");
- emitcode("pop","r31");
- _G.zPushed--;
+ case AOP_STK:
+ {
+ int sz = aop->size;
+ int stk = aop->aopu.aop_stk + aop->size;
+ bitVectUnSetBit (ic->rUsed, X_IDX);
+ bitVectUnSetBit (ic->rUsed, Z_IDX);
+
+ getFreePtr (ic, &aop, FALSE, 0);
+
+ emitcode ("movw", "%s,r28");
+ if (stk)
+ {
+ if (stk <= 63 && stk > 0)
+ {
+ emitcode ("adiw", "%s,0x%02x", aop->aopu.aop_ptr->name, stk + 1);
+ }
+ else
+ {
+ emitcode ("subi", "%s,lo8(%d)", aop->aopu.aop_ptr->name, -(stk + 1));
+ emitcode ("sbci", "%s,hi8(%d)", aop->aop_ptr2->name, -(stk + 1));
+ }
+ }
+
+ while (sz--)
+ {
+ emitcode ("pop", "r24");
+ emitcode ("st", "-%s,r24", aop->type == AOP_X ? "X" : "Z");
+ if (!sz)
+ break;
+ }
+ op->aop = aop;
+ freeAsmop (op, NULL, ic, TRUE);
+ if (_G.xPushed)
+ {
+ emitcode ("pop", "r26");
+ emitcode ("pop", "r27");
+ _G.xPushed--;
+ }
+
+ if (_G.zPushed)
+ {
+ emitcode ("pop", "r30");
+ emitcode ("pop", "r31");
+ _G.zPushed--;
+ }
}
}
- }
- dealloc:
+dealloc:
/* all other cases just dealloc */
- if (op ) {
- op->aop = NULL;
- if (IS_SYMOP(op)) {
- OP_SYMBOL(op)->aop = NULL;
- /* if the symbol has a spill */
- if (SPIL_LOC(op))
- SPIL_LOC(op)->aop = NULL;
+ if (op)
+ {
+ op->aop = NULL;
+ if (IS_SYMOP (op))
+ {
+ OP_SYMBOL (op)->aop = NULL;
+ /* if the symbol has a spill */
+ if (SPIL_LOC (op))
+ SPIL_LOC (op)->aop = NULL;
+ }
}
- }
}
/*-----------------------------------------------------------------*/
/* aopGet - for fetching value of the aop */
/*-----------------------------------------------------------------*/
-static char *aopGet (asmop *aop, int offset)
+static char *
+aopGet (asmop * aop, int offset)
{
- char *s = buffer ;
+ char *s = buffer;
char *rs;
/* offset is greater than
return zero;
/* depending on type */
- switch (aop->type) {
+ switch (aop->type)
+ {
- case AOP_X:
- if (offset > aop->coff) {
- emitcode ("adiw","%s,%d",aop->aopu.aop_ptr->name,offset - aop->coff);
- }
+ case AOP_X:
+ if (offset > aop->coff)
+ {
+ emitcode ("adiw", "%s,%d", aop->aopu.aop_ptr->name, offset - aop->coff);
+ }
+
+ if (offset < aop->coff)
+ {
+ emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, aop->coff - offset);
+ }
+
+ aop->coff = offset;
+ emitcode ("ld", "%s,x",
+ (rs = ((offset & 1) ? "r25" : "r24")));
+ return rs;
+
+ case AOP_Z:
+ if (aop->code)
+ {
+ if (offset > aop->coff)
+ {
+ emitcode ("adiw", "r30,%d", offset - aop->coff);
+ }
+ else
+ {
+ emitcode ("sbiw", "r30,%d", aop->coff - offset);
+ }
+ emitcode ("lpm", "%s,z", (rs = ((offset & 1) ? "r25" : "r24")));
+ }
+ else
+ {
+ /* we can use lds */
+ if (offset > aop->coff)
+ {
+ emitcode ("ldd", "%s,z+%d", (rs = ((offset & 1) ? "r25" : "r24")),
+ offset - aop->coff);
+ }
+ else
+ {
+ emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, aop->coff - offset);
+ aop->coff = offset;
+ emitcode ("ld", "%s,z", (rs = ((offset & 1) ? "r25" : "r24")));
+ }
+ }
+ return rs;
+
+ case AOP_IMMD:
+
+ emitcode ("lds", "%s,(%s)+%d",
+ (rs = ((offset & 1) ? "r25" : "r24")),
+ aop->aopu.aop_immd, offset);
+ return rs;
+
+ case AOP_DIR:
+ emitcode ("lds", "%s,(%s)+%d",
+ (rs = ((offset & 1) ? "r25" : "r24")),
+ aop->aopu.aop_dir, offset);
+ return rs;
+
+ case AOP_REG:
+ return aop->aopu.aop_reg[offset]->name;
+
+ case AOP_CRY:
+ assert ("cannot be in bit space AOP_CRY\n");
+ break;
- if (offset < aop->coff) {
- emitcode("sbiw","%s,%d",aop->aopu.aop_ptr->name,aop->coff - offset);
- }
+ case AOP_LIT:
+ s = aopLiteral (aop->aopu.aop_lit, offset);
+ emitcode ("ldi", "%s,lo8(%s)", (rs = ((offset & 1) ? "r24" : "r25")), s);
+ return rs;
- aop->coff = offset ;
- emitcode("ld","%s,x",
- (rs = ((offset & 1) ? "r25" : "r24")));
- return rs;
+ case AOP_STR:
+ aop->coff = offset;
+ return aop->aopu.aop_str[offset];
- case AOP_Z:
- if (aop->code) {
- if (offset > aop->coff) {
- emitcode("adiw","r30,%d",offset - aop->coff);
- } else {
- emitcode("sbiw","r30,%d",aop->coff - offset);
- }
- emitcode("lpm","%s,z",(rs = ((offset & 1) ? "r25" : "r24")));
- } else {
- /* we can use lds */
- if (offset > aop->coff) {
- emitcode ("ldd","%s,z+%d",(rs = ((offset & 1) ? "r25" : "r24")),
- offset - aop->coff);
- } else {
- emitcode("sbiw","%s,%d",aop->aopu.aop_ptr->name,aop->coff - offset);
- aop->coff = offset;
- emitcode ("ld","%s,z",(rs = ((offset & 1) ? "r25" : "r24")));
- }
+ case AOP_STK_D:
+ emitcode ("ldd", "%s,Y+%d",
+ (rs = ((offset & 1) ? "r25" : "r24")),
+ aop->aopu.aop_stk + offset);
+ return rs;
}
- return rs;
- case AOP_IMMD:
-
- emitcode ("lds","%s,(%s)+%d",
- (rs = ((offset & 1) ? "r25" : "r24")),
- aop->aopu.aop_immd, offset);
- return rs;
-
- case AOP_DIR:
- emitcode ("lds","%s,(%s)+%d",
- (rs = ((offset & 1) ? "r25" : "r24")),
- aop->aopu.aop_dir, offset);
- return rs;
-
- case AOP_REG:
- return aop->aopu.aop_reg[offset]->name;
-
- case AOP_CRY:
- assert("cannot be in bit space AOP_CRY\n");
- break;
-
- case AOP_LIT:
- s = aopLiteral(aop->aopu.aop_lit,offset);
- emitcode("ldi","%s,lo8(%s)",(rs = ((offset & 1)?"r24" : "r25")),s);
- return rs;
-
- case AOP_STR:
- aop->coff = offset ;
- return aop->aopu.aop_str[offset];
-
- case AOP_STK_D:
- emitcode ("ldd","%s,Y+%d",
- (rs = ((offset & 1) ? "r25" : "r24")),
- aop->aopu.aop_stk+offset);
- return rs;
- }
-
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopget got unsupported aop->type");
- exit(0);
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopget got unsupported aop->type");
+ exit (0);
}
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop */
/*-----------------------------------------------------------------*/
-static void aopPut (asmop *aop, char *s, int offset)
+static void
+aopPut (asmop * aop, char *s, int offset)
{
- char *d = buffer ;
+ char *d = buffer;
- if (aop->size && offset > ( aop->size - 1)) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got offset > aop->size");
- exit(0);
- }
+ if (aop->size && offset > (aop->size - 1))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got offset > aop->size");
+ exit (0);
+ }
/* will assign value to value */
/* depending on where it is ofcourse */
- switch (aop->type) {
- case AOP_DIR:
- if (offset) {
- sprintf(d,"(%s)+%d", aop->aopu.aop_dir,offset);
- }
- else {
- sprintf(d,"%s",aop->aopu.aop_dir);
- }
+ switch (aop->type)
+ {
+ case AOP_DIR:
+ if (offset)
+ {
+ sprintf (d, "(%s)+%d", aop->aopu.aop_dir, offset);
+ }
+ else
+ {
+ sprintf (d, "%s", aop->aopu.aop_dir);
+ }
- emitcode("sts","%s,%s",d,s);
- break;
+ emitcode ("sts", "%s,%s", d, s);
+ break;
- case AOP_REG:
- if (toupper(*s) != 'R') {
- if (s == zero) {
- emitcode("clr","%s",aop->aopu.aop_reg[offset]->name);
- } else {
- emitcode("ldi","r25,%s",s);
- emitcode("mov","%s,r35",aop->aopu.aop_reg[offset]->name);
- }
- } else {
- if (strcmp( aop->aopu.aop_reg[offset]->name,s)) {
- emitcode("mov","%s,%s", aop->aopu.aop_reg[offset]->name,s);
- }
- }
- break;
+ case AOP_REG:
+ if (toupper (*s) != 'R')
+ {
+ if (s == zero)
+ {
+ emitcode ("clr", "%s", aop->aopu.aop_reg[offset]->name);
+ }
+ else
+ {
+ emitcode ("ldi", "r25,%s", s);
+ emitcode ("mov", "%s,r35", aop->aopu.aop_reg[offset]->name);
+ }
+ }
+ else
+ {
+ if (strcmp (aop->aopu.aop_reg[offset]->name, s))
+ {
+ emitcode ("mov", "%s,%s", aop->aopu.aop_reg[offset]->name, s);
+ }
+ }
+ break;
- case AOP_X:
- if (offset > aop->coff) {
- emitcode ("adiw","%s,%d",aop->aopu.aop_ptr->name,offset - aop->coff);
- }
+ case AOP_X:
+ if (offset > aop->coff)
+ {
+ emitcode ("adiw", "%s,%d", aop->aopu.aop_ptr->name, offset - aop->coff);
+ }
- if (offset < aop->coff) {
- emitcode("sbiw","%s,%d",aop->aopu.aop_ptr->name,aop->coff - offset);
- }
+ if (offset < aop->coff)
+ {
+ emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, aop->coff - offset);
+ }
- aop->coff = offset ;
- emitcode("st","x,%s", s);
- break;
+ aop->coff = offset;
+ emitcode ("st", "x,%s", s);
+ break;
- case AOP_Z:
- if (aop->code) {
- if (offset > aop->coff) {
- emitcode("adiw","r30,%d",offset - aop->coff);
- } else {
- emitcode("sbiw","r30,%d",aop->coff - offset);
- }
- emitcode("lpm","%s,z",s);
- } else {
- /* we can use lds */
- if (offset > aop->coff) {
- emitcode ("sdd","z+%d,%s",offset - aop->coff,s);
- } else {
- emitcode("sbiw","%s,%d",aop->aopu.aop_ptr->name,aop->coff - offset);
- aop->coff = offset;
- emitcode ("ld","%s,z",s);
- }
- }
- break;
+ case AOP_Z:
+ if (aop->code)
+ {
+ if (offset > aop->coff)
+ {
+ emitcode ("adiw", "r30,%d", offset - aop->coff);
+ }
+ else
+ {
+ emitcode ("sbiw", "r30,%d", aop->coff - offset);
+ }
+ emitcode ("lpm", "%s,z", s);
+ }
+ else
+ {
+ /* we can use lds */
+ if (offset > aop->coff)
+ {
+ emitcode ("sdd", "z+%d,%s", offset - aop->coff, s);
+ }
+ else
+ {
+ emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, aop->coff - offset);
+ aop->coff = offset;
+ emitcode ("ld", "%s,z", s);
+ }
+ }
+ break;
- case AOP_STK:
- emitcode("push","%s",s);
- break;
+ case AOP_STK:
+ emitcode ("push", "%s", s);
+ break;
- case AOP_CRY:
- /* if used only for a condition code check */
- assert(toupper(*s) == 'R');
- if (offset == 0) {
- emitcode("xrl","r0,r0");
- emitcode("cpi","%s,0",s);
- }
- else {
- emitcode("cpc","r0,%s",s);
- }
- break;
+ case AOP_CRY:
+ /* if used only for a condition code check */
+ assert (toupper (*s) == 'R');
+ if (offset == 0)
+ {
+ emitcode ("xrl", "r0,r0");
+ emitcode ("cpi", "%s,0", s);
+ }
+ else
+ {
+ emitcode ("cpc", "r0,%s", s);
+ }
+ break;
- case AOP_STR:
- aop->coff = offset;
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("mov","%s,%s",aop->aopu.aop_str[offset],s);
- break;
+ case AOP_STR:
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("mov", "%s,%s", aop->aopu.aop_str[offset], s);
+ break;
- case AOP_STK_D:
- emitcode ("std","y+%d,%s",offset,s);
- break;
+ case AOP_STK_D:
+ emitcode ("std", "y+%d,%s", offset, s);
+ break;
- default :
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got unsupported aop->type");
- exit(0);
- }
+ default:
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got unsupported aop->type");
+ exit (0);
+ }
}
/*-----------------------------------------------------------------*/
/* reAdjustPreg - points a register back to where it should */
/*-----------------------------------------------------------------*/
-static void reAdjustPreg (asmop *aop)
+static void
+reAdjustPreg (asmop * aop)
{
- int size ;
+ 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;
- }
+ return;
+ size--;
+ switch (aop->type)
+ {
+ case AOP_X:
+ case AOP_Z:
+ emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, size);
+ break;
+ }
}
/*-----------------------------------------------------------------*/
/* genNotFloat - generates not for float operations */
/*-----------------------------------------------------------------*/
-static void genNotFloat (operand *op, operand *res)
+static void
+genNotFloat (operand * op, operand * res)
{
int size, offset;
char *l;
- symbol *tlbl ;
+ symbol *tlbl;
/* we will put 127 in the first byte of
the result */
- aopPut(AOP(res),"127",0);
- size = AOP_SIZE(op) - 1;
+ aopPut (AOP (res), "127", 0);
+ size = AOP_SIZE (op) - 1;
offset = 1;
- l = aopGet(op->aop,offset++);
- MOVR0(l);
+ l = aopGet (op->aop, offset++);
+ MOVR0 (l);
- while(size--) {
- emitcode("or","R0,%s", aopGet(op->aop, offset++));
- }
- tlbl = newiTempLabel(NULL);
+ while (size--)
+ {
+ emitcode ("or", "R0,%s", aopGet (op->aop, offset++));
+ }
+ tlbl = newiTempLabel (NULL);
- tlbl = newiTempLabel(NULL);
- aopPut(res->aop,zero,1);
- emitcode("cpi","r0,0");
- emitcode("breq","L%05d",tlbl->key);
- aopPut(res->aop,one,1);
- emitcode("","L%05d:",tlbl->key);
+ tlbl = newiTempLabel (NULL);
+ aopPut (res->aop, zero, 1);
+ emitcode ("cpi", "r0,0");
+ emitcode ("breq", "L%05d", tlbl->key);
+ aopPut (res->aop, one, 1);
+ emitcode ("", "L%05d:", tlbl->key);
size = res->aop->size - 2;
offset = 2;
/* put zeros in the rest */
while (size--)
- aopPut(res->aop,zero,offset++);
+ aopPut (res->aop, zero, offset++);
}
/*-----------------------------------------------------------------*/
/* opIsGptr: returns non-zero if the passed operand is */
/* a generic pointer type. */
/*-----------------------------------------------------------------*/
-static int opIsGptr(operand *op)
+static int
+opIsGptr (operand * op)
{
- sym_link *type = operandType(op);
+ sym_link *type = operandType (op);
- if ((AOP_SIZE(op) == GPTRSIZE) && IS_GENPTR(type))
+ if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
{
return 1;
}
/*-----------------------------------------------------------------*/
/* getDataSize - get the operand data size */
/*-----------------------------------------------------------------*/
-static int getDataSize(operand *op)
+static int
+getDataSize (operand * op)
{
int size;
- size = AOP_SIZE(op);
+ size = AOP_SIZE (op);
if (size == GPTRSIZE)
{
- sym_link *type = operandType(op);
- if (IS_GENPTR(type))
- {
- /* generic pointer; arithmetic operations
- * should ignore the high byte (pointer type).
- */
- size--;
- }
+ sym_link *type = operandType (op);
+ if (IS_GENPTR (type))
+ {
+ /* generic pointer; arithmetic operations
+ * should ignore the high byte (pointer type).
+ */
+ size--;
+ }
}
return size;
}
/*-----------------------------------------------------------------*/
/* outAcc - output Acc */
/*-----------------------------------------------------------------*/
-static void outAcc(operand *result)
+static void
+outAcc (operand * result)
{
int size, offset;
- size = getDataSize(result);
- if(size){
- aopPut(AOP(result),"r0",0);
- size--;
- offset = 1;
- /* unsigned or positive */
- while(size--){
- aopPut(AOP(result),zero,offset++);
+ size = getDataSize (result);
+ if (size)
+ {
+ aopPut (AOP (result), "r0", 0);
+ size--;
+ offset = 1;
+ /* unsigned or positive */
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
}
- }
}
/*-----------------------------------------------------------------*/
/* outBitC - output a bit C */
/*-----------------------------------------------------------------*/
-static void outBitC(operand *result)
+static void
+outBitC (operand * result)
{
- emitcode("clr","r0");
- emitcode("rol","r0");
- outAcc(result);
+ emitcode ("clr", "r0");
+ emitcode ("rol", "r0");
+ outAcc (result);
}
/*-----------------------------------------------------------------*/
/* toBoolean - emit code for orl a,operator(sizeop) */
/*-----------------------------------------------------------------*/
-static void toBoolean(operand *oper, char *r, bool clr)
+static void
+toBoolean (operand * oper, char *r, bool clr)
{
- int size = AOP_SIZE(oper) ;
+ int size = AOP_SIZE (oper);
int offset = 0;
- if (clr) emitcode ("clr","%s",r);
+ if (clr)
+ emitcode ("clr", "%s", r);
while (size--)
- emitcode("or","%s,%s",r,aopGet(AOP(oper),offset++));
+ emitcode ("or", "%s,%s", r, aopGet (AOP (oper), offset++));
}
/*-----------------------------------------------------------------*/
/* genNot - generate code for ! operation */
/*-----------------------------------------------------------------*/
-static void genNot (iCode *ic)
+static void
+genNot (iCode * ic)
{
symbol *tlbl;
- sym_link *optype = operandType(IC_LEFT(ic));
+ sym_link *optype = operandType (IC_LEFT (ic));
int size, offset = 1;
/* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
/* if type float then do float */
- if (IS_FLOAT(optype)) {
- genNotFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
- }
- emitcode("clr","r0");
- tlbl = newiTempLabel(NULL);
- size = AOP_SIZE(IC_LEFT(ic));
+ if (IS_FLOAT (optype))
+ {
+ genNotFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
+ }
+ emitcode ("clr", "r0");
+ tlbl = newiTempLabel (NULL);
+ size = AOP_SIZE (IC_LEFT (ic));
offset = 0;
- if (size == 1) {
- emitcode("cpse","%s,r0",aopGet(AOP(IC_LEFT(ic)),0));
- }
- else {
- while (size--) {
- if (offset) emitcode("cpc","%s,r0",aopGet(AOP(IC_LEFT(ic)),offset));
- else emitcode("cpi","%s,0",aopGet(AOP(IC_LEFT(ic)),offset));
- offset++;
+ if (size == 1)
+ {
+ emitcode ("cpse", "%s,r0", aopGet (AOP (IC_LEFT (ic)), 0));
}
- emitcode("bne","L%05d",tlbl->key);
- }
- emitcode("ldi","r0,1");
- emitcode("","L%05d:",tlbl->key);
- aopPut(AOP(IC_RESULT(ic)),"r0",0);
- size = AOP_SIZE(IC_RESULT(ic)) -1;
+ else
+ {
+ while (size--)
+ {
+ if (offset)
+ emitcode ("cpc", "%s,r0", aopGet (AOP (IC_LEFT (ic)), offset));
+ else
+ emitcode ("cpi", "%s,0", aopGet (AOP (IC_LEFT (ic)), offset));
+ offset++;
+ }
+ emitcode ("bne", "L%05d", tlbl->key);
+ }
+ emitcode ("ldi", "r0,1");
+ emitcode ("", "L%05d:", tlbl->key);
+ aopPut (AOP (IC_RESULT (ic)), "r0", 0);
+ size = AOP_SIZE (IC_RESULT (ic)) - 1;
offset = 1;
- while (size--) aopPut(AOP(IC_RESULT(ic)),zero,offset++);
+ while (size--)
+ aopPut (AOP (IC_RESULT (ic)), zero, offset++);
- release:
+release:
/* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCpl - generate code for complement */
/*-----------------------------------------------------------------*/
-static void genCpl (iCode *ic)
+static void
+genCpl (iCode * ic)
{
int offset = 0;
- int size ;
+ int size;
int samer;
/* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
- samer = sameRegs(AOP(IC_LEFT(ic)),AOP(IC_RESULT(ic)));
- size = AOP_SIZE(IC_RESULT(ic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset);
- if (samer) {
- emitcode ("com","%s",l);
- } else {
- aopPut(AOP(IC_RESULT(ic)),l,offset);
- emitcode ("com","%s",aopGet(AOP(IC_RESULT(ic)),offset));
- }
- offset++;
- }
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
+ samer = sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic)));
+ size = AOP_SIZE (IC_RESULT (ic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset);
+ if (samer)
+ {
+ emitcode ("com", "%s", l);
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), l, offset);
+ emitcode ("com", "%s", aopGet (AOP (IC_RESULT (ic)), offset));
+ }
+ offset++;
+ }
/* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genUminusFloat - unary minus for floating points */
/*-----------------------------------------------------------------*/
-static void genUminusFloat(operand *op,operand *result)
+static void
+genUminusFloat (operand * op, operand * result)
{
- int size ,offset =0 ;
+ int size, offset = 0;
char *l;
/* for this we just need to flip the
first it then copy the rest in place */
- size = AOP_SIZE(op) - 1;
- l = aopGet(AOP(op),3);
-
- emitcode("ldi","r24,0x80");
- if (sameRegs(AOP(op),AOP(result))) {
- emitcode("eor","%s,r24",l);
- } else {
- aopPut(AOP(result),l,3);
- emitcode("eor","%s,r24",aopGet(AOP(result),3));
- }
- while(size--) {
- aopPut(AOP(result), aopGet(AOP(op),offset), offset);
- offset++;
- }
+ size = AOP_SIZE (op) - 1;
+ l = aopGet (AOP (op), 3);
+
+ emitcode ("ldi", "r24,0x80");
+ if (sameRegs (AOP (op), AOP (result)))
+ {
+ emitcode ("eor", "%s,r24", l);
+ }
+ else
+ {
+ aopPut (AOP (result), l, 3);
+ emitcode ("eor", "%s,r24", aopGet (AOP (result), 3));
+ }
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (op), offset), offset);
+ offset++;
+ }
}
/*-----------------------------------------------------------------*/
/* genUminus - unary minus code generation */
/*-----------------------------------------------------------------*/
-static void genUminus (iCode *ic)
+static void
+genUminus (iCode * ic)
{
- int offset ,size ;
+ int offset, size;
sym_link *optype, *rtype;
- int samer ;
+ int samer;
/* assign asmops */
- aopOp(IC_LEFT(ic),ic,FALSE);
- aopOp(IC_RESULT(ic),ic,TRUE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- optype = operandType(IC_LEFT(ic));
- rtype = operandType(IC_RESULT(ic));
+ optype = operandType (IC_LEFT (ic));
+ rtype = operandType (IC_RESULT (ic));
/* if float then do float stuff */
- if (IS_FLOAT(optype)) {
- genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
- }
+ if (IS_FLOAT (optype))
+ {
+ genUminusFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
+ }
/* otherwise subtract from zero */
- size = AOP_SIZE(IC_LEFT(ic));
- offset = 0 ;
- samer = sameRegs(AOP(IC_LEFT(ic)),AOP(IC_RESULT(ic)));
- if (size == 1) {
- if (samer) {
- emitcode("neg","%s",aopGet(AOP(IC_LEFT(ic)),0));
- } else {
- aopPut(AOP(IC_RESULT(ic)),aopGet(AOP(IC_LEFT(ic)),0),0);
- emitcode("neg","%s",aopGet(AOP(IC_RESULT(ic)),0));
- }
- } else {
- offset = size - 1;
- while(size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset);
- if (!samer) {
- aopPut(AOP(IC_RESULT(ic)),l,offset);
- l = aopGet(AOP(IC_RESULT(ic)),offset);
- }
- if (offset) emitcode("com","%s",l);
- else emitcode("neg","%s",l);
- offset--;
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = 0;
+ samer = sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic)));
+ if (size == 1)
+ {
+ if (samer)
+ {
+ emitcode ("neg", "%s", aopGet (AOP (IC_LEFT (ic)), 0));
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), aopGet (AOP (IC_LEFT (ic)), 0), 0);
+ emitcode ("neg", "%s", aopGet (AOP (IC_RESULT (ic)), 0));
+ }
}
- size = AOP_SIZE(IC_LEFT(ic)) -1;
- offset = 1 ;
- while (size--) {
- emitcode("sbci","%s,lo8(-1)",aopGet(AOP(IC_RESULT(ic)),offset++));
+ else
+ {
+ offset = size - 1;
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset);
+ if (!samer)
+ {
+ aopPut (AOP (IC_RESULT (ic)), l, offset);
+ l = aopGet (AOP (IC_RESULT (ic)), offset);
+ }
+ if (offset)
+ emitcode ("com", "%s", l);
+ else
+ emitcode ("neg", "%s", l);
+ offset--;
+ }
+ size = AOP_SIZE (IC_LEFT (ic)) - 1;
+ offset = 1;
+ while (size--)
+ {
+ emitcode ("sbci", "%s,lo8(-1)", aopGet (AOP (IC_RESULT (ic)), offset++));
+ }
}
- }
/* if any remaining bytes in the result */
/* we just need to propagate the sign */
- if ((size = (AOP_SIZE(IC_RESULT(ic)) - AOP_SIZE(IC_LEFT(ic))))) {
- symbol *tlbl = newiTempLabel(NULL);
- emitcode("clr","r0");
- emitcode("brcc","L%05d",tlbl->key);
- emitcode("com","r0");
- emitcode("","L%05d:",tlbl->key);
- while (size--)
- aopPut(AOP(IC_RESULT(ic)),"r0",offset++);
- }
+ if ((size = (AOP_SIZE (IC_RESULT (ic)) - AOP_SIZE (IC_LEFT (ic)))))
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ emitcode ("clr", "r0");
+ emitcode ("brcc", "L%05d", tlbl->key);
+ emitcode ("com", "r0");
+ emitcode ("", "L%05d:", tlbl->key);
+ while (size--)
+ aopPut (AOP (IC_RESULT (ic)), "r0", offset++);
+ }
- release:
+release:
/* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* assignResultValue - */
/*-----------------------------------------------------------------*/
-static void assignResultValue(operand * oper)
+static void
+assignResultValue (operand * oper)
{
int offset = 0;
- int size = AOP_SIZE(oper);
- while (size--) {
- aopPut(AOP(oper),fAVRReturn[offset],offset);
- offset++;
- }
+ int size = AOP_SIZE (oper);
+ while (size--)
+ {
+ aopPut (AOP (oper), fAVRReturn[offset], offset);
+ offset++;
+ }
}
/*-----------------------------------------------------------------*/
/* saveZreg - if indirect call then save z-pointer register */
/*-----------------------------------------------------------------*/
-static void saveZreg (iCode *ic)
+static void
+saveZreg (iCode * ic)
{
/* only if live accross this call */
if (ic->regsSaved == 0 &&
- (bitVectBitValue(ic->rMask,R30_IDX) ||
- bitVectBitValue(ic->rMask,R31_IDX))) {
- ic->regsSaved = 1;
- emitcode("push","r30");
- emitcode("push","r31");
- }
+ (bitVectBitValue (ic->rMask, R30_IDX) ||
+ bitVectBitValue (ic->rMask, R31_IDX)))
+ {
+ ic->regsSaved = 1;
+ emitcode ("push", "r30");
+ emitcode ("push", "r31");
+ }
}
/*-----------------------------------------------------------------*/
/* popZreg - restore values of zreg */
/*-----------------------------------------------------------------*/
-static void popZreg (iCode *ic)
+static void
+popZreg (iCode * ic)
{
- if (ic->regsSaved) {
- emitcode ("pop","r31");
- emitcode ("pop","r30");
- }
+ if (ic->regsSaved)
+ {
+ emitcode ("pop", "r31");
+ emitcode ("pop", "r30");
+ }
}
/*-----------------------------------------------------------------*/
/* genIpush - genrate code for pushing this gets a little complex */
/*-----------------------------------------------------------------*/
-static void genIpush (iCode *ic)
+static void
+genIpush (iCode * ic)
{
- int size, offset = 0 ;
+ int size, offset = 0;
char *l;
- if (!ic->parmPush) {
- /* and the item is spilt then do nothing */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
- } else {
- iCode *lic ;
- for (lic = ic->next ; lic ; lic = lic->next)
- if (lic->op == PCALL) break;
- if (lic) saveZreg(lic);
- }
+ if (!ic->parmPush)
+ {
+ /* and the item is spilt then do nothing */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
+ }
+ else
+ {
+ iCode *lic;
+ for (lic = ic->next; lic; lic = lic->next)
+ if (lic->op == PCALL)
+ break;
+ if (lic)
+ saveZreg (lic);
+ }
/* this is a paramter push */
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- while (size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++);
- emitcode("push","%s",l);
- }
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++);
+ emitcode ("push", "%s", l);
+ }
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIpop - recover the registers: can happen only for spilling */
/*-----------------------------------------------------------------*/
-static void genIpop (iCode *ic)
+static void
+genIpop (iCode * ic)
{
- int size,offset ;
+ int size, offset;
/* if the temp was not pushed then */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- offset = (size-1);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = (size - 1);
while (size--)
- emitcode("pop","%s",aopGet(AOP(IC_LEFT(ic)),offset--));
+ emitcode ("pop", "%s", aopGet (AOP (IC_LEFT (ic)), offset--));
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
-static void genCall (iCode *ic)
+static void
+genCall (iCode * ic)
{
/* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
- int rnum = 16;
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
- aopOp(IC_LEFT(sic),sic,FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset);
- char *b = buffer;
- sprintf(buffer,"r%d",rnum++);
- if (strcmp(l,b))
- emitcode("mov","%s,%s",b,l);
- offset++;
- }
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
+ if (_G.sendSet)
+ {
+ iCode *sic;
+ int rnum = 16;
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+ aopOp (IC_LEFT (sic), sic, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset);
+ char *b = buffer;
+ sprintf (buffer, "r%d", rnum++);
+ if (strcmp (l, b))
+ emitcode ("mov", "%s,%s", b, l);
+ offset++;
+ }
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
+ _G.sendSet = NULL;
}
- _G.sendSet = NULL;
- }
/* make the call */
- emitcode("call","%s",(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
- OP_SYMBOL(IC_LEFT(ic))->rname :
- OP_SYMBOL(IC_LEFT(ic))->name));
+ emitcode ("call", "%s", (OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
+ OP_SYMBOL (IC_LEFT (ic))->rname :
+ OP_SYMBOL (IC_LEFT (ic))->name));
/* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
-
- aopOp(IC_RESULT(ic),ic,FALSE);
- assignResultValue(IC_RESULT(ic));
- freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
- }
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
+
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ assignResultValue (IC_RESULT (ic));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ }
/* adjust the stack for parameters if required */
- if (IC_LEFT(ic)->parmBytes) {
- if (IC_LEFT(ic)->parmBytes > 63) {
- emitcode("sbiw","r28,%d",IC_LEFT(ic)->parmBytes);
- } else {
- emitcode("subi","r28,lo8(%d)",IC_LEFT(ic)->parmBytes);
- emitcode("sbci","r29,hi8(%d)",IC_LEFT(ic)->parmBytes);
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ if (IC_LEFT (ic)->parmBytes > 63)
+ {
+ emitcode ("sbiw", "r28,%d", IC_LEFT (ic)->parmBytes);
+ }
+ else
+ {
+ emitcode ("subi", "r28,lo8(%d)", IC_LEFT (ic)->parmBytes);
+ emitcode ("sbci", "r29,hi8(%d)", IC_LEFT (ic)->parmBytes);
+ }
}
- }
}
/*-----------------------------------------------------------------*/
/* genPcall - generates a call by pointer statement */
/*-----------------------------------------------------------------*/
-static void genPcall (iCode *ic)
+static void
+genPcall (iCode * ic)
{
- if (!ic->regsSaved) saveZreg(ic);
+ if (!ic->regsSaved)
+ saveZreg (ic);
- aopOp(IC_LEFT(ic),ic,FALSE);
- emitcode("mov","r30",aopGet(AOP(IC_LEFT(ic)),0));
- emitcode("mov","r31",aopGet(AOP(IC_RIGHT(ic)),0));
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ emitcode ("mov", "r30", aopGet (AOP (IC_LEFT (ic)), 0));
+ emitcode ("mov", "r31", aopGet (AOP (IC_RIGHT (ic)), 0));
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
/* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
- int rnum = 16;
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
- aopOp(IC_LEFT(sic),sic,FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset);
- char *b = buffer;
- sprintf(b,"r%d",rnum++);
- if (strcmp(l,b))
- emitcode("mov","%s,%s",b,l);
- offset++;
- }
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
+ if (_G.sendSet)
+ {
+ iCode *sic;
+ int rnum = 16;
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+ aopOp (IC_LEFT (sic), sic, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset);
+ char *b = buffer;
+ sprintf (b, "r%d", rnum++);
+ if (strcmp (l, b))
+ emitcode ("mov", "%s,%s", b, l);
+ offset++;
+ }
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
+ _G.sendSet = NULL;
}
- _G.sendSet = NULL;
- }
- emitcode("icall","");
+ emitcode ("icall", "");
/* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir)) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
- aopOp(IC_RESULT(ic),ic,FALSE);
+ aopOp (IC_RESULT (ic), ic, FALSE);
- assignResultValue(IC_RESULT(ic));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
- }
+ assignResultValue (IC_RESULT (ic));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ }
/* adjust the stack for parameters if
required */
- if (IC_LEFT(ic)->parmBytes) {
- int i;
- if (IC_LEFT(ic)->parmBytes > 3) {
- emitcode("mov","a,%s",spname);
- emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff);
- emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++)
- emitcode("dec","%s",spname);
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i;
+ if (IC_LEFT (ic)->parmBytes > 3)
+ {
+ emitcode ("mov", "a,%s", spname);
+ emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff);
+ emitcode ("mov", "%s,a", spname);
+ }
+ else
+ for (i = 0; i < IC_LEFT (ic)->parmBytes; i++)
+ emitcode ("dec", "%s", spname);
- }
+ }
/* adjust the stack for parameters if required */
- if (IC_LEFT(ic)->parmBytes) {
- if (IC_LEFT(ic)->parmBytes > 63) {
- emitcode("sbiw","r28,%d",IC_LEFT(ic)->parmBytes);
- } else {
- emitcode("subi","r28,lo8(%d)",IC_LEFT(ic)->parmBytes);
- emitcode("sbci","r29,hi8(%d)",IC_LEFT(ic)->parmBytes);
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ if (IC_LEFT (ic)->parmBytes > 63)
+ {
+ emitcode ("sbiw", "r28,%d", IC_LEFT (ic)->parmBytes);
+ }
+ else
+ {
+ emitcode ("subi", "r28,lo8(%d)", IC_LEFT (ic)->parmBytes);
+ emitcode ("sbci", "r29,hi8(%d)", IC_LEFT (ic)->parmBytes);
+ }
}
- }
- if (ic->regsSaved) popZreg(ic);
+ if (ic->regsSaved)
+ popZreg (ic);
}
/*-----------------------------------------------------------------*/
/* resultRemat - result is rematerializable */
/*-----------------------------------------------------------------*/
-static int resultRemat (iCode *ic)
+static int
+resultRemat (iCode * ic)
{
- if (SKIP_IC(ic) || ic->op == IFX)
+ if (SKIP_IC (ic) || ic->op == IFX)
return 0;
- if (IC_RESULT(ic) && IS_ITEMP(IC_RESULT(ic))) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- if (sym->remat && !POINTER_SET(ic))
- return 1;
- }
+ if (IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic)))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ if (sym->remat && !POINTER_SET (ic))
+ return 1;
+ }
return 0;
}
/*-----------------------------------------------------------------*/
/* inExcludeList - return 1 if the string is in exclude Reg list */
/*-----------------------------------------------------------------*/
-static bool inExcludeList(char *s)
+static bool
+inExcludeList (char *s)
{
- int i =0;
+ int i = 0;
if (options.excludeRegs[i] &&
- STRCASECMP(options.excludeRegs[i],"none") == 0)
- return FALSE ;
+ 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 ;
+ 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 */
/*-----------------------------------------------------------------*/
-static void genFunction (iCode *ic)
+static void
+genFunction (iCode * ic)
{
symbol *sym;
sym_link *fetype;
_G.nRegsSaved = 0;
/* create the function header */
- emitcode(";","-----------------------------------------");
- emitcode(";"," function %s",(sym = OP_SYMBOL(IC_LEFT(ic)))->name);
- emitcode(";","-----------------------------------------");
+ emitcode (";", "-----------------------------------------");
+ emitcode (";", " function %s", (sym = OP_SYMBOL (IC_LEFT (ic)))->name);
+ emitcode (";", "-----------------------------------------");
- emitcode("","%s:",sym->rname);
- fetype = getSpec(operandType(IC_LEFT(ic)));
+ emitcode ("", "%s:", sym->rname);
+ fetype = getSpec (operandType (IC_LEFT (ic)));
/* if critical function then turn interrupts off */
- if (SPEC_CRTCL(fetype))
- emitcode("cli","");
+ if (SPEC_CRTCL (fetype))
+ emitcode ("cli", "");
- if (IS_ISR(sym->etype)) {
- }
+ if (IS_ISR (sym->etype))
+ {
+ }
/* save the preserved registers that are used in this function */
- for (i = R2_IDX ; i <= R15_IDX ; i++ ) {
- if (bitVectBitValue(sym->regsUsed,i)) {
- _G.nRegsSaved++;
- emitcode("push","%s",avr_regWithIdx(i)->name);
+ for (i = R2_IDX; i <= R15_IDX; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i))
+ {
+ _G.nRegsSaved++;
+ emitcode ("push", "%s", avr_regWithIdx (i)->name);
+ }
}
- }
/* now for the pointer registers */
- if (bitVectBitValue(sym->regsUsed,R26_IDX)) {
- _G.nRegsSaved++;
- emitcode("push","r26");
- }
- if (bitVectBitValue(sym->regsUsed,R27_IDX)) {
- _G.nRegsSaved++;
- emitcode("push","r27");
- }
- if (bitVectBitValue(sym->regsUsed,R30_IDX)) {
- _G.nRegsSaved++;
- emitcode("push","r30");
- }
- if (bitVectBitValue(sym->regsUsed,R31_IDX)) {
- _G.nRegsSaved++;
- emitcode("push","r31");
- }
+ if (bitVectBitValue (sym->regsUsed, R26_IDX))
+ {
+ _G.nRegsSaved++;
+ emitcode ("push", "r26");
+ }
+ if (bitVectBitValue (sym->regsUsed, R27_IDX))
+ {
+ _G.nRegsSaved++;
+ emitcode ("push", "r27");
+ }
+ if (bitVectBitValue (sym->regsUsed, R30_IDX))
+ {
+ _G.nRegsSaved++;
+ emitcode ("push", "r30");
+ }
+ if (bitVectBitValue (sym->regsUsed, R31_IDX))
+ {
+ _G.nRegsSaved++;
+ emitcode ("push", "r31");
+ }
/* adjust the stack for the function */
- if (sym->stack) {
- emitcode ("push","r28");
- emitcode ("push","r29");
- emitcode ("in","r28,__SP_L__");
- emitcode ("in","r29,__SP_H__");
- if (sym->stack <= 63) {
- emitcode("sbiw","r28,%d",sym->stack);
- } else {
- emitcode ("subi","r28,lo8(%d)",sym->stack);
- emitcode ("sbci","r29,hi8(%d)",sym->stack);
- }
- emitcode("out","__SP_L__,r28");
- emitcode("out","__SP_H__,r29");
- }
+ if (sym->stack)
+ {
+ emitcode ("push", "r28");
+ emitcode ("push", "r29");
+ emitcode ("in", "r28,__SP_L__");
+ emitcode ("in", "r29,__SP_H__");
+ if (sym->stack <= 63)
+ {
+ emitcode ("sbiw", "r28,%d", sym->stack);
+ }
+ else
+ {
+ emitcode ("subi", "r28,lo8(%d)", sym->stack);
+ emitcode ("sbci", "r29,hi8(%d)", sym->stack);
+ }
+ emitcode ("out", "__SP_L__,r28");
+ emitcode ("out", "__SP_H__,r29");
+ }
}
/*-----------------------------------------------------------------*/
/* genEndFunction - generates epilogue for functions */
/*-----------------------------------------------------------------*/
-static void genEndFunction (iCode *ic)
+static void
+genEndFunction (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
int i;
/* restore stack pointer */
- if (sym->stack) {
- if (sym->stack <= 63) {
- emitcode("adiw","r28,%d",sym->stack);
- } else {
- emitcode ("subi","r28,lo8(-%d)",sym->stack);
- emitcode ("sbci","r29,hi8(-%d)",sym->stack);
- }
- emitcode("out","__SP_L__,r28");
- emitcode("out","__SP_H__,r29");
-
- /* pop frame pointer */
- emitcode ("pop","r29");
- emitcode ("pop","r28");
- }
+ if (sym->stack)
+ {
+ if (sym->stack <= 63)
+ {
+ emitcode ("adiw", "r28,%d", sym->stack);
+ }
+ else
+ {
+ emitcode ("subi", "r28,lo8(-%d)", sym->stack);
+ emitcode ("sbci", "r29,hi8(-%d)", sym->stack);
+ }
+ emitcode ("out", "__SP_L__,r28");
+ emitcode ("out", "__SP_H__,r29");
+
+ /* pop frame pointer */
+ emitcode ("pop", "r29");
+ emitcode ("pop", "r28");
+ }
/* restore preserved registers */
- if (bitVectBitValue(sym->regsUsed,R31_IDX)) {
- _G.nRegsSaved--;
- emitcode("pop","r31");
- }
- if (bitVectBitValue(sym->regsUsed,R30_IDX)) {
- _G.nRegsSaved--;
- emitcode("pop","r30");
- }
- if (bitVectBitValue(sym->regsUsed,R27_IDX)) {
- _G.nRegsSaved--;
- emitcode("push","r27");
- }
- if (bitVectBitValue(sym->regsUsed,R26_IDX)) {
- _G.nRegsSaved--;
- emitcode("push","r26");
- }
- for (i = R15_IDX ; i >= R2_IDX ; i-- ) {
- if (bitVectBitValue(sym->regsUsed,i)) {
+ if (bitVectBitValue (sym->regsUsed, R31_IDX))
+ {
_G.nRegsSaved--;
- emitcode("pop","%s",avr_regWithIdx(i)->name);
+ emitcode ("pop", "r31");
+ }
+ if (bitVectBitValue (sym->regsUsed, R30_IDX))
+ {
+ _G.nRegsSaved--;
+ emitcode ("pop", "r30");
+ }
+ if (bitVectBitValue (sym->regsUsed, R27_IDX))
+ {
+ _G.nRegsSaved--;
+ emitcode ("push", "r27");
+ }
+ if (bitVectBitValue (sym->regsUsed, R26_IDX))
+ {
+ _G.nRegsSaved--;
+ emitcode ("push", "r26");
+ }
+ for (i = R15_IDX; i >= R2_IDX; i--)
+ {
+ if (bitVectBitValue (sym->regsUsed, i))
+ {
+ _G.nRegsSaved--;
+ emitcode ("pop", "%s", avr_regWithIdx (i)->name);
+ }
}
- }
- if (SPEC_CRTCL(sym->etype))
- emitcode("sti","");
+ if (SPEC_CRTCL (sym->etype))
+ emitcode ("sti", "");
- if (IS_ISR(sym->etype)) {
- emitcode("rti","");
- } else {
- emitcode("ret","");
- }
+ if (IS_ISR (sym->etype))
+ {
+ emitcode ("rti", "");
+ }
+ else
+ {
+ emitcode ("ret", "");
+ }
}
/*-----------------------------------------------------------------*/
/* genRet - generate code for return statement */
/*-----------------------------------------------------------------*/
-static void genRet (iCode *ic)
+static void
+genRet (iCode * ic)
{
- int size,offset = 0 ;
+ int size, offset = 0;
/* if we have no return value then
just generate the "ret" */
- if (!IC_LEFT(ic))
+ if (!IC_LEFT (ic))
goto jumpret;
/* we have something to return then
move the return value into place */
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
-
- while (size--) {
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) {
- emitcode("ldi","%s,%s(%d)",fAVRReturn[offset],larray[offset],
- (int)floatFromVal (AOP(IC_LEFT(ic))->aopu.aop_lit),offset);
- } else {
- char *l ;
- l = aopGet(AOP(IC_LEFT(ic)),offset);
- if (strcmp(fAVRReturn[offset],l))
- emitcode("mov","%s,%s",fAVRReturn[offset],l);
- }
- offset++;
- }
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+
+ while (size--)
+ {
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_LIT)
+ {
+ emitcode ("ldi", "%s,%s(%d)", fAVRReturn[offset], larray[offset],
+ (int) floatFromVal (AOP (IC_LEFT (ic))->aopu.aop_lit), offset);
+ }
+ else
+ {
+ char *l;
+ l = aopGet (AOP (IC_LEFT (ic)), offset);
+ if (strcmp (fAVRReturn[offset], l))
+ emitcode ("mov", "%s,%s", fAVRReturn[offset], l);
+ }
+ offset++;
+ }
- freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
- jumpret:
+jumpret:
/* generate a jump to the return label
if the next is not the return statement */
if (!(ic->next && ic->next->op == LABEL &&
- IC_LABEL(ic->next) == returnLabel))
+ IC_LABEL (ic->next) == returnLabel))
- emitcode("rjmp","L%05d",returnLabel->key);
+ emitcode ("rjmp", "L%05d", returnLabel->key);
}
/*-----------------------------------------------------------------*/
/* genLabel - generates a label */
/*-----------------------------------------------------------------*/
-static void genLabel (iCode *ic)
+static void
+genLabel (iCode * ic)
{
/* special case never generate */
- if (IC_LABEL(ic) == entryLabel)
- return ;
+ if (IC_LABEL (ic) == entryLabel)
+ return;
- emitcode("","L%05d:",IC_LABEL(ic)->key);
+ emitcode ("", "L%05d:", IC_LABEL (ic)->key);
}
/*-----------------------------------------------------------------*/
/* genGoto - generates a ljmp */
/*-----------------------------------------------------------------*/
-static void genGoto (iCode *ic)
+static void
+genGoto (iCode * ic)
{
- emitcode ("rjmp","L%05d:",(IC_LABEL(ic)->key+100));
+ emitcode ("rjmp", "L%05d:", (IC_LABEL (ic)->key + 100));
}
/*-----------------------------------------------------------------*/
/* between that label and given ic. */
/* Returns zero if label not found. */
/*-----------------------------------------------------------------*/
-static int findLabelBackwards(iCode *ic, int key)
+static int
+findLabelBackwards (iCode * ic, int key)
{
int count = 0;
ic = ic->prev;
count++;
- if (ic->op == LABEL && IC_LABEL(ic)->key == key)
- {
- /* printf("findLabelBackwards = %d\n", count); */
- return 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 */
/*-----------------------------------------------------------------*/
-static bool genPlusIncr (iCode *ic)
+static bool
+genPlusIncr (iCode * ic)
{
- unsigned int icount ;
+ unsigned int icount;
/* will try to generate an increment */
/* if the right side is not a literal
we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
- icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit);
+ icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
/* if the sizes are greater than 2 or they are not the same regs
then we cannot */
- if (!sameRegs(AOP(IC_LEFT(ic)),AOP(IC_RESULT(ic))))
- return FALSE ;
+ if (!sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ return FALSE;
/* so we know LEFT & RESULT in the same registers and add
amount <= 63 */
/* for short & char types */
- if (AOP_SIZE(IC_RESULT(ic)) < 2) {
- if (icount == 1) {
- emitcode("inc","%s",aopGet(AOP(IC_LEFT(ic)),0));
+ if (AOP_SIZE (IC_RESULT (ic)) < 2)
+ {
+ if (icount == 1)
+ {
+ emitcode ("inc", "%s", aopGet (AOP (IC_LEFT (ic)), 0));
+ return TRUE;
+ }
+ emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_LEFT (ic)), 0), -icount);
return TRUE;
}
- emitcode("subi","%s,lo8(%d)",aopGet(AOP(IC_LEFT(ic)),0),-icount);
- return TRUE;
- }
- if (AOP_SIZE(IC_RESULT(ic)) <= 3) {
- /* if register pair and starts with 26/30 then adiw */
- if (isRegPair(AOP(IC_RESULT(ic))) && icount > 0 && icount < 64 &&
- ( IS_REGIDX(AOP(IC_RESULT(ic)),R26_IDX) ||
- IS_REGIDX(AOP(IC_RESULT(ic)),R30_IDX) )) {
- emitcode("adiw","%s,%d",aopGet(AOP(IC_RESULT(ic)),0),icount);
+ if (AOP_SIZE (IC_RESULT (ic)) <= 3)
+ {
+ /* if register pair and starts with 26/30 then adiw */
+ if (isRegPair (AOP (IC_RESULT (ic))) && icount > 0 && icount < 64 &&
+ (IS_REGIDX (AOP (IC_RESULT (ic)), R26_IDX) ||
+ IS_REGIDX (AOP (IC_RESULT (ic)), R30_IDX)))
+ {
+ emitcode ("adiw", "%s,%d", aopGet (AOP (IC_RESULT (ic)), 0), icount);
+ return TRUE;
+ }
+
+ /* use subi */
+ emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_RESULT (ic)), 0), -icount);
+ emitcode ("sbci", "%s,hi8(%d)", aopGet (AOP (IC_RESULT (ic)), 1), -icount);
return TRUE;
}
- /* use subi */
- emitcode("subi","%s,lo8(%d)",aopGet(AOP(IC_RESULT(ic)),0),-icount);
- emitcode("sbci","%s,hi8(%d)",aopGet(AOP(IC_RESULT(ic)),1),-icount);
- return TRUE;
- }
-
/* for 32 bit longs */
- emitcode("subi","%s,lo8(%d)",aopGet(AOP(IC_RESULT(ic)),0),-icount);
- emitcode("sbci","%s,hi8(%d)",aopGet(AOP(IC_RESULT(ic)),1),-icount);
- emitcode("sbci","%s,hlo8(%d)",aopGet(AOP(IC_RESULT(ic)),2),-icount);
- emitcode("sbci","%s,hhi8(%d)",aopGet(AOP(IC_RESULT(ic)),3),-icount);
+ emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_RESULT (ic)), 0), -icount);
+ emitcode ("sbci", "%s,hi8(%d)", aopGet (AOP (IC_RESULT (ic)), 1), -icount);
+ emitcode ("sbci", "%s,hlo8(%d)", aopGet (AOP (IC_RESULT (ic)), 2), -icount);
+ emitcode ("sbci", "%s,hhi8(%d)", aopGet (AOP (IC_RESULT (ic)), 3), -icount);
return TRUE;
}
* I'm pretty certain it's right, but not enough to toss the old
* code just yet...
*/
-static void adjustArithmeticResult (iCode *ic)
+static void
+adjustArithmeticResult (iCode * ic)
{
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_LEFT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_LEFT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_LEFT(ic)), GPTRSIZE - 1),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_LEFT (ic)), GPTRSIZE - 1),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_RIGHT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_RIGHT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_RIGHT(ic)),GPTRSIZE - 1),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_RIGHT (ic)), GPTRSIZE - 1),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- AOP_SIZE(IC_LEFT(ic)) < GPTRSIZE &&
- AOP_SIZE(IC_RIGHT(ic)) < GPTRSIZE &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
- char buffer[5];
- sprintf(buffer,"%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
- aopPut(AOP(IC_RESULT(ic)),buffer,GPTRSIZE - 1);
- }
+ if (opIsGptr (IC_RESULT (ic)) &&
+ AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+ AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ {
+ char buffer[5];
+ sprintf (buffer, "%d", pointerCode (getSpec (operandType (IC_LEFT (ic)))));
+ aopPut (AOP (IC_RESULT (ic)), buffer, GPTRSIZE - 1);
+ }
}
/*-----------------------------------------------------------------*/
/* genPlus - generates code for addition */
/*-----------------------------------------------------------------*/
-static void genPlus (iCode *ic)
+static void
+genPlus (iCode * ic)
{
int size, offset = 0;
int samer;
/* special cases :- */
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
/* if I can do an increment instead
of add then GOOD for ME */
if (genPlusIncr (ic) == TRUE)
goto release;
- size = getDataSize(IC_RESULT(ic));
- samer = sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic)));
-
- while(size--) {
- if (!samer)
- aopPut(AOP(IC_RESULT(ic)),aopGet(AOP(IC_LEFT(ic)),offset),offset);
+ size = getDataSize (IC_RESULT (ic));
+ samer = sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)));
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT) {
+ while (size--)
+ {
+ if (!samer)
+ aopPut (AOP (IC_RESULT (ic)), aopGet (AOP (IC_LEFT (ic)), offset), offset);
- if(offset == 0) l = "add";
- else l = "adc";
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ {
- emitcode(l,"%s,%s",aopGet(AOP(IC_RESULT(ic)),offset),
- aopGet(AOP(IC_RIGHT(ic)),offset));
- } else {
- if (offset == 0) l = "subi";
- else l = "sbci";
+ if (offset == 0)
+ l = "add";
+ else
+ l = "adc";
- emitcode(l,"%s,%s(-%d)",aopGet(AOP(IC_RESULT(ic)),offset),
- larray[offset],
- (int)floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
+ emitcode (l, "%s,%s", aopGet (AOP (IC_RESULT (ic)), offset),
+ aopGet (AOP (IC_RIGHT (ic)), offset));
+ }
+ else
+ {
+ if (offset == 0)
+ l = "subi";
+ else
+ l = "sbci";
+
+ emitcode (l, "%s,%s(-%d)", aopGet (AOP (IC_RESULT (ic)), offset),
+ larray[offset],
+ (int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit));
+ }
+ offset++;
}
- offset++;
- }
- adjustArithmeticResult(ic);
+ adjustArithmeticResult (ic);
- release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+release:
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMinusDec :- does subtraction with deccrement if possible */
/*-----------------------------------------------------------------*/
-static bool genMinusDec (iCode *ic)
+static bool
+genMinusDec (iCode * ic)
{
- unsigned int icount ;
+ unsigned int icount;
/* will try to generate an increment */
/* if the right side is not a literal
we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
- icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit);
+ icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
/* if the sizes are greater than 2 or they are not the same regs
then we cannot */
- if (!sameRegs(AOP(IC_LEFT(ic)),AOP(IC_RIGHT(ic))))
- return FALSE ;
+ if (!sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RIGHT (ic))))
+ return FALSE;
/* so we know LEFT & RESULT in the same registers and add
amount <= 63 */
/* for short & char types */
- if (AOP_SIZE(IC_RESULT(ic)) < 2) {
- if (icount == 1) {
- emitcode("dec","%s",aopGet(AOP(IC_LEFT(ic)),0));
+ if (AOP_SIZE (IC_RESULT (ic)) < 2)
+ {
+ if (icount == 1)
+ {
+ emitcode ("dec", "%s", aopGet (AOP (IC_LEFT (ic)), 0));
+ return TRUE;
+ }
+ emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_LEFT (ic)), 0), icount);
return TRUE;
}
- emitcode("subi","%s,lo8(%d)",aopGet(AOP(IC_LEFT(ic)),0),icount);
- return TRUE;
- }
- if (AOP_SIZE(IC_RESULT(ic)) <= 3) {
- /* if register pair and starts with 26/30 then adiw */
- if (isRegPair(AOP(IC_RESULT(ic))) && icount > 0 && icount < 64 &&
- ( IS_REGIDX(AOP(IC_RESULT(ic)),R26_IDX) ||
- IS_REGIDX(AOP(IC_RESULT(ic)),R30_IDX) )) {
- emitcode("sbiw","%s,%d",aopGet(AOP(IC_RESULT(ic)),0),icount);
+ if (AOP_SIZE (IC_RESULT (ic)) <= 3)
+ {
+ /* if register pair and starts with 26/30 then adiw */
+ if (isRegPair (AOP (IC_RESULT (ic))) && icount > 0 && icount < 64 &&
+ (IS_REGIDX (AOP (IC_RESULT (ic)), R26_IDX) ||
+ IS_REGIDX (AOP (IC_RESULT (ic)), R30_IDX)))
+ {
+ emitcode ("sbiw", "%s,%d", aopGet (AOP (IC_RESULT (ic)), 0), icount);
+ return TRUE;
+ }
+
+ /* use subi */
+ emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_RESULT (ic)), 0), icount);
+ emitcode ("sbci", "%s,hi8(%d)", aopGet (AOP (IC_RESULT (ic)), 1), icount);
return TRUE;
}
-
- /* use subi */
- emitcode("subi","%s,lo8(%d)",aopGet(AOP(IC_RESULT(ic)),0),icount);
- emitcode("sbci","%s,hi8(%d)",aopGet(AOP(IC_RESULT(ic)),1),icount);
- return TRUE;
- }
/* for 32 bit longs */
- emitcode("subi","%s,lo8(%d)",aopGet(AOP(IC_RESULT(ic)),0),icount);
- emitcode("sbci","%s,hi8(%d)",aopGet(AOP(IC_RESULT(ic)),1),icount);
- emitcode("sbci","%s,hlo8(%d)",aopGet(AOP(IC_RESULT(ic)),2),icount);
- emitcode("sbci","%s,hhi8(%d)",aopGet(AOP(IC_RESULT(ic)),3),icount);
+ emitcode ("subi", "%s,lo8(%d)", aopGet (AOP (IC_RESULT (ic)), 0), icount);
+ emitcode ("sbci", "%s,hi8(%d)", aopGet (AOP (IC_RESULT (ic)), 1), icount);
+ emitcode ("sbci", "%s,hlo8(%d)", aopGet (AOP (IC_RESULT (ic)), 2), icount);
+ emitcode ("sbci", "%s,hhi8(%d)", aopGet (AOP (IC_RESULT (ic)), 3), icount);
return TRUE;
}
/*-----------------------------------------------------------------*/
/* addSign - complete with sign */
/*-----------------------------------------------------------------*/
-static void addSign(operand *result, int offset, int 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++);
- }
+ 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 */
/*-----------------------------------------------------------------*/
-static void genMinus (iCode *ic)
+static void
+genMinus (iCode * ic)
{
int size, offset = 0, samer;
char *l;
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
/* if I can do an decrement instead
of subtract then GOOD for ME */
if (genMinusDec (ic) == TRUE)
goto release;
- size = getDataSize(IC_RESULT(ic));
- samer = sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic)));
- while (size--) {
- if (!samer)
- aopPut(AOP(IC_RESULT(ic)),aopGet(AOP(IC_LEFT(ic)),offset),offset);
-
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT) {
+ size = getDataSize (IC_RESULT (ic));
+ samer = sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)));
+ while (size--)
+ {
+ if (!samer)
+ aopPut (AOP (IC_RESULT (ic)), aopGet (AOP (IC_LEFT (ic)), offset), offset);
- if(offset == 0) l = "sub";
- else l = "sbc";
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ {
- emitcode(l,"%s,%s",aopGet(AOP(IC_RESULT(ic)),offset),
- aopGet(AOP(IC_RIGHT(ic)),offset));
- } else {
- if (offset == 0) l = "subi";
- else l = "sbci";
+ if (offset == 0)
+ l = "sub";
+ else
+ l = "sbc";
- emitcode(l,"%s,%s(%d)",aopGet(AOP(IC_RESULT(ic)),offset),
- larray[offset],
- (int)floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
+ emitcode (l, "%s,%s", aopGet (AOP (IC_RESULT (ic)), offset),
+ aopGet (AOP (IC_RIGHT (ic)), offset));
+ }
+ else
+ {
+ if (offset == 0)
+ l = "subi";
+ else
+ l = "sbci";
+
+ emitcode (l, "%s,%s(%d)", aopGet (AOP (IC_RESULT (ic)), offset),
+ larray[offset],
+ (int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit));
+ }
+ offset++;
}
- offset++;
- }
- adjustArithmeticResult(ic);
+ adjustArithmeticResult (ic);
- release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+release:
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMultOneByte : 8 bit multiplication & division */
/*-----------------------------------------------------------------*/
-static void genMultOneByte (operand *left,
- operand *right,
- operand *result)
+static void
+genMultOneByte (operand * left,
+ operand * right,
+ operand * result)
{
- sym_link *opetype = operandType(result);
- symbol *lbl ;
- int size,offset;
+ sym_link *opetype = operandType (result);
+ symbol *lbl;
+ int size, offset;
/* (if two literals, the value is computed before) */
/* if one literal, literal on the right */
- if (AOP_TYPE(left) == AOP_LIT){
- operand *t = right;
- right = left;
- left = t;
- }
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
- size = AOP_SIZE(result);
+ size = AOP_SIZE (result);
- if (SPEC_USIGN(opetype)) {
- emitcode("mul","%s,%s", aopGet(AOP(left),0),aopGet(AOP(right),0));
- } else {
- emitcode("muls","%s,%s", aopGet(AOP(left),0),
- aopGet(AOP(right),0));
- }
- aopPut(AOP(result),"r0",0);
- if (size > 1){
- aopPut(AOP(result),"r1",1);
- offset = 2;
- size -= 2;
- if (SPEC_USIGN(opetype)) {
- while(size--) {
- aopPut(AOP(result),zero,offset++);
- }
- } else {
- if (size) {
- lbl = newiTempLabel(NULL);
- emitcode("ldi","r24,0");
- emitcode("brcc","L%05d",lbl->key);
- emitcode("ldi","r24,lo8(-1)");
- emitcode("","L%05d:",lbl->key);
- while (size--) aopPut(AOP(result),"r24",offset++);
- }
+ if (SPEC_USIGN (opetype))
+ {
+ emitcode ("mul", "%s,%s", aopGet (AOP (left), 0), aopGet (AOP (right), 0));
+ }
+ else
+ {
+ emitcode ("muls", "%s,%s", aopGet (AOP (left), 0),
+ aopGet (AOP (right), 0));
+ }
+ aopPut (AOP (result), "r0", 0);
+ if (size > 1)
+ {
+ aopPut (AOP (result), "r1", 1);
+ offset = 2;
+ size -= 2;
+ if (SPEC_USIGN (opetype))
+ {
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
+ }
+ else
+ {
+ if (size)
+ {
+ lbl = newiTempLabel (NULL);
+ emitcode ("ldi", "r24,0");
+ emitcode ("brcc", "L%05d", lbl->key);
+ emitcode ("ldi", "r24,lo8(-1)");
+ emitcode ("", "L%05d:", lbl->key);
+ while (size--)
+ aopPut (AOP (result), "r24", offset++);
+ }
+ }
}
- }
return;
}
/*-----------------------------------------------------------------*/
/* genMult - generates code for multiplication */
/*-----------------------------------------------------------------*/
-static void genMult (iCode *ic)
+static void
+genMult (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
/* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
/* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genMultOneByte(left,right,result);
- goto release ;
- }
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genMultOneByte (left, right, result);
+ goto release;
+ }
/* should have been converted to function call */
- assert(1) ;
+ assert (1);
- release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDiv - generates code for division */
/*-----------------------------------------------------------------*/
-static void genDiv (iCode *ic)
+static void
+genDiv (iCode * ic)
{
/* should have been converted to function call */
- assert(1);
+ assert (1);
}
/*-----------------------------------------------------------------*/
/* genMod - generates code for division */
/*-----------------------------------------------------------------*/
-static void genMod (iCode *ic)
+static void
+genMod (iCode * ic)
{
/* should have been converted to function call */
- assert(1);
+ assert (1);
}
-enum {
+enum
+{
AVR_EQ = 0,
AVR_NE,
AVR_LT,
/*-----------------------------------------------------------------*/
/* revavrcnd - reverse a conditional for avr */
/*-----------------------------------------------------------------*/
-static int revavrcnd(int type)
+static int
+revavrcnd (int type)
{
- static struct {
- int type, rtype;
- } rar[] = { { AVR_EQ, AVR_NE}, {AVR_LT, AVR_GE}};
+ static struct
+ {
+ int type, rtype;
+ }
+ rar[] =
+ {
+ {
+ AVR_EQ, AVR_NE
+ }
+ ,
+ {
+ AVR_LT, AVR_GE
+ }
+ };
int i;
- for (i = 0 ; i < (sizeof(rar)/sizeof(rar[0]));i++) {
- if (rar[i].type == type) return rar[i].rtype;
- if (rar[i].rtype== type) return rar[i].type;
- }
- assert(1); /* cannot happen */
- return 0; /* makes the compiler happy */
+ for (i = 0; i < (sizeof (rar) / sizeof (rar[0])); i++)
+ {
+ if (rar[i].type == type)
+ return rar[i].rtype;
+ if (rar[i].rtype == type)
+ return rar[i].type;
+ }
+ assert (1); /* cannot happen */
+ return 0; /* makes the compiler happy */
}
-static char *br_name[4] = {"breq","brne","brlt","brge"};
-static char *br_uname[4]= {"breq","brne","brlo","brcc"};
+static char *br_name[4] =
+{"breq", "brne", "brlt", "brge"};
+static char *br_uname[4] =
+{"breq", "brne", "brlo", "brcc"};
/*-----------------------------------------------------------------*/
/* genBranch - generate the branch instruction */
/*-----------------------------------------------------------------*/
-static void genBranch (iCode *ifx, int br_type, int sign)
+static void
+genBranch (iCode * ifx, int br_type, int sign)
{
- int tj = (IC_TRUE(ifx) ? 1 : 0) ;
-
- if (tj) { /* if true jump */
- char *nm = (sign ? br_name[br_type] : br_uname[br_type]);
- emitcode(nm,"L%05d",IC_TRUE(ifx)->key);
- } else { /* if false jump */
- int rtype = revavrcnd(br_type);
- char *nm = (sign ? br_name[rtype] : br_uname[rtype]);
- emitcode(nm,"L%05d",IC_FALSE(ifx)->key);
- }
+ int tj = (IC_TRUE (ifx) ? 1 : 0);
+
+ if (tj)
+ { /* if true jump */
+ char *nm = (sign ? br_name[br_type] : br_uname[br_type]);
+ emitcode (nm, "L%05d", IC_TRUE (ifx)->key);
+ }
+ else
+ { /* if false jump */
+ int rtype = revavrcnd (br_type);
+ char *nm = (sign ? br_name[rtype] : br_uname[rtype]);
+ emitcode (nm, "L%05d", IC_FALSE (ifx)->key);
+ }
ifx->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genCmp - compare & jump */
/*-----------------------------------------------------------------*/
-static void genCmp (iCode *ic, iCode *ifx, int br_type)
+static void
+genCmp (iCode * ic, iCode * ifx, int br_type)
{
operand *left, *right, *result;
- sym_link *letype , *retype;
+ sym_link *letype, *retype;
symbol *lbl;
- int sign, size, offset =0;
+ int sign, size, offset = 0;
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
/* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
- size = AOP_SIZE(left);
-
- if (ifx) {
- if (size == 1) {
- if (AOP_TYPE(right) == AOP_LIT) {
- emitcode("cpi","%s,lo8(%d)",aopGet(AOP(left),0),
- (int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
- genBranch(ifx,br_type,sign);
- } else { /* right != literal */
- emitcode("cp","%s,%s",aopGet(AOP(left),0),aopGet(AOP(right),0));
- genBranch(ifx,br_type,sign);
- }
- } else { /* size != 1 */
- while (size--) {
- if (offset == 0)
- emitcode("cp","%s,%s",aopGet(AOP(left),0),aopGet(AOP(right),0));
- else
- emitcode("cpc","%s,%s",aopGet(AOP(left),offset),aopGet(AOP(right),offset));
- offset++;
- }
- genBranch(ifx,br_type,sign);
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
+ size = AOP_SIZE (left);
+
+ if (ifx)
+ {
+ if (size == 1)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ emitcode ("cpi", "%s,lo8(%d)", aopGet (AOP (left), 0),
+ (int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit));
+ genBranch (ifx, br_type, sign);
+ }
+ else
+ { /* right != literal */
+ emitcode ("cp", "%s,%s", aopGet (AOP (left), 0), aopGet (AOP (right), 0));
+ genBranch (ifx, br_type, sign);
+ }
+ }
+ else
+ { /* size != 1 */
+ while (size--)
+ {
+ if (offset == 0)
+ emitcode ("cp", "%s,%s", aopGet (AOP (left), 0), aopGet (AOP (right), 0));
+ else
+ emitcode ("cpc", "%s,%s", aopGet (AOP (left), offset), aopGet (AOP (right), offset));
+ offset++;
+ }
+ genBranch (ifx, br_type, sign);
+ }
}
- } else { /* no ifx */
- emitcode("clr","r0");
- while (size--) {
- if (offset == 0)
- emitcode("cp","%s,%s",aopGet(AOP(left),0),aopGet(AOP(right),0));
+ else
+ { /* no ifx */
+ emitcode ("clr", "r0");
+ while (size--)
+ {
+ if (offset == 0)
+ emitcode ("cp", "%s,%s", aopGet (AOP (left), 0), aopGet (AOP (right), 0));
+ else
+ emitcode ("cpc", "%s,%s", aopGet (AOP (left), offset), aopGet (AOP (right), offset));
+ offset++;
+ }
+ lbl = newiTempLabel (NULL);
+ br_type = revavrcnd (br_type);
+ if (sign)
+ emitcode (br_uname[br_type], "L%05d", lbl->key);
else
- emitcode("cpc","%s,%s",aopGet(AOP(left),offset),aopGet(AOP(right),offset));
- offset++;
+ emitcode (br_name[br_type], "L%05d", lbl->key);
+ emitcode ("inc", "r0");
+ emitcode ("", "L%05d:", lbl->key);
+ aopPut (AOP (result), "r0", 0);
+ size = AOP_SIZE (result) - 1;
+ offset = 1;
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
}
- lbl = newiTempLabel(NULL);
- br_type = revavrcnd(br_type);
- if (sign) emitcode(br_uname[br_type],"L%05d",lbl->key);
- else emitcode(br_name[br_type],"L%05d",lbl->key);
- emitcode("inc","r0");
- emitcode("","L%05d:",lbl->key);
- aopPut(AOP(result),"r0",0);
- size = AOP_SIZE(result) - 1;
- offset = 1;
- while (size--) aopPut(AOP(result),zero,offset++);
- }
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCmpGt :- greater than comparison */
/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
+static void
+genCmpGt (iCode * ic, iCode * ifx)
{
/* should have transformed by the parser */
- assert(1);
+ assert (1);
}
/*-----------------------------------------------------------------*/
/* genCmpLt - less than comparisons */
/*-----------------------------------------------------------------*/
-static void genCmpLt (iCode *ic, iCode *ifx)
+static void
+genCmpLt (iCode * ic, iCode * ifx)
{
- genCmp(ic,ifx,AVR_LT);
+ genCmp (ic, ifx, AVR_LT);
}
/*-----------------------------------------------------------------*/
/* genCmpEq - generates code for equal to */
/*-----------------------------------------------------------------*/
-static void genCmpEq (iCode *ic, iCode *ifx)
+static void
+genCmpEq (iCode * ic, iCode * ifx)
{
- genCmp(ic,ifx,AVR_EQ);
+ genCmp (ic, ifx, AVR_EQ);
}
/*-----------------------------------------------------------------*/
/* genCmpNe - generates code for not equal to */
/*-----------------------------------------------------------------*/
-static void genCmpNe (iCode *ic, iCode *ifx)
+static void
+genCmpNe (iCode * ic, iCode * ifx)
{
- genCmp(ic,ifx,AVR_NE);
+ genCmp (ic, ifx, AVR_NE);
}
/*-----------------------------------------------------------------*/
/* genCmpGe - generates code for greater than equal to */
/*-----------------------------------------------------------------*/
-static void genCmpGe (iCode *ic, iCode *ifx)
+static void
+genCmpGe (iCode * ic, iCode * ifx)
{
- genCmp(ic,ifx,AVR_GE);
+ genCmp (ic, ifx, AVR_GE);
}
/*-----------------------------------------------------------------*/
/* genCmpLe - generates code for less than equal to */
/*-----------------------------------------------------------------*/
-static void genCmpLe (iCode *ic, iCode *ifx)
+static void
+genCmpLe (iCode * ic, iCode * ifx)
{
- operand *left = IC_LEFT(ic);
- operand *right= IC_RIGHT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
- IC_RIGHT(ic) = left;
- IC_LEFT(ic) = right;
- genCmp(ic,ifx,AVR_GE);
+ IC_RIGHT (ic) = left;
+ IC_LEFT (ic) = right;
+ genCmp (ic, ifx, AVR_GE);
}
/*-----------------------------------------------------------------*/
/* ifxForOp - returns the icode containing the ifx for operand */
/*-----------------------------------------------------------------*/
-static iCode *ifxForOp ( operand *op, iCode *ic )
+static iCode *
+ifxForOp (operand * op, iCode * ic)
{
/* if true symbol then needs to be assigned */
- if (IS_TRUE_SYMOP(op))
- return NULL ;
+ if (IS_TRUE_SYMOP (op))
+ return NULL;
- /* if this has register type condition and
- the next instruction is ifx with the same operand
- and live to of the operand is upto the ifx only then */
+ /* if this has register type condition and
+ the next instruction is ifx with the same operand
+ and live to of the operand is upto the ifx only then */
if (ic->next &&
ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key &&
- OP_SYMBOL(op)->liveTo <= ic->next->seq )
+ IC_COND (ic->next)->key == op->key &&
+ OP_SYMBOL (op)->liveTo <= ic->next->seq)
return ic->next;
return NULL;
/*-----------------------------------------------------------------*/
/* genAndOp - for && operation */
/*-----------------------------------------------------------------*/
-static void genAndOp (iCode *ic)
+static void
+genAndOp (iCode * ic)
{
- operand *left,*right, *result;
+ operand *left, *right, *result;
symbol *tlbl;
- int size , offset;
+ int size, offset;
/* note here that && operations that are in an
if statement are taken away by backPatchLabels
only those used in arthmetic operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE);
-
- tlbl = newiTempLabel(NULL);
- toBoolean(left,"r0",TRUE);
- toBoolean(right,"r1",TRUE);
- emitcode("and","r0,r1");
- emitcode("ldi","r24,1");
- emitcode("breq","L%05d",tlbl->key);
- emitcode("dec","r24");
- emitcode("","L%05d:",tlbl->key);
- aopPut(AOP(result),"r24",0);
- size = AOP_SIZE(result) -1;
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE);
+
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left, "r0", TRUE);
+ toBoolean (right, "r1", TRUE);
+ emitcode ("and", "r0,r1");
+ emitcode ("ldi", "r24,1");
+ emitcode ("breq", "L%05d", tlbl->key);
+ emitcode ("dec", "r24");
+ emitcode ("", "L%05d:", tlbl->key);
+ aopPut (AOP (result), "r24", 0);
+ size = AOP_SIZE (result) - 1;
offset = 1;
- while (size--) aopPut(AOP(result),zero,offset++);
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genOrOp - for || operation */
/*-----------------------------------------------------------------*/
-static void genOrOp (iCode *ic)
+static void
+genOrOp (iCode * ic)
{
- operand *left,*right, *result;
+ operand *left, *right, *result;
symbol *tlbl;
- int size , offset;
+ int size, offset;
/* note here that || operations that are in an
if statement are taken away by backPatchLabels
only those used in arthmetic operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE);
-
- tlbl = newiTempLabel(NULL);
- toBoolean(left,"r0",TRUE);
- toBoolean(right,"r0",FALSE);
- emitcode("ldi","r24,1");
- emitcode("breq","L%05d",tlbl->key);
- emitcode("dec","r24");
- emitcode("","L%05d:",tlbl->key);
- aopPut(AOP(result),"r24",0);
- size = AOP_SIZE(result) -1;
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE);
+
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left, "r0", TRUE);
+ toBoolean (right, "r0", FALSE);
+ emitcode ("ldi", "r24,1");
+ emitcode ("breq", "L%05d", tlbl->key);
+ emitcode ("dec", "r24");
+ emitcode ("", "L%05d:", tlbl->key);
+ aopPut (AOP (result), "r24", 0);
+ size = AOP_SIZE (result) - 1;
offset = 1;
- while (size--) aopPut(AOP(result),zero,offset++);
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* isLiteralBit - test if lit == 2^n */
/*-----------------------------------------------------------------*/
-static int isLiteralBit(unsigned long lit)
+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};
+ 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;
+ for (idx = 0; idx < 32; idx++)
+ if (lit == pw[idx])
+ return idx + 1;
return 0;
}
-enum { AVR_AND = 0, AVR_OR, AVR_XOR };
-static char *bopnames_lit[] = {"andi","ori"};
-static char *bopnames[] = {"and","or","eor"};
+enum
+{
+ AVR_AND = 0, AVR_OR, AVR_XOR
+};
+static char *bopnames_lit[] =
+{"andi", "ori"};
+static char *bopnames[] =
+{"and", "or", "eor"};
/*-----------------------------------------------------------------*/
/* genBitWise - generate bitwise operations */
/*-----------------------------------------------------------------*/
-static void genBitWise(iCode *ic, iCode *ifx, int bitop)
+static void
+genBitWise (iCode * ic, iCode * ifx, int bitop)
{
operand *left, *right, *result;
- int size, offset=0;
+ int size, offset = 0;
char *l;
symbol *lbl, *lbl1;
- int samerl, samerr ;
+ int samerl, samerr;
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
- size = AOP_SIZE(left);
+ size = AOP_SIZE (left);
offset = 0;
- if (ifx) { /* used only for jumps */
- if (AOP_TYPE(right) == AOP_LIT &&
- (bitop == AVR_AND || bitop == AVR_OR)) {
- int lit = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int p2 = powof2(lit);
- if (bitop == AVR_AND && p2) { /* right side is a power of 2 */
- l = aopGet(AOP(left),p2 / 8);
- if (IC_TRUE(ifx)) {
- emitcode("sbrc","%s,%d",l,(p2 % 8));
- emitcode("rjmp","L%05d",IC_TRUE(ifx)->key);
- } else {
- emitcode("sbrs","%s,%d",l,(p2 % 8));
- emitcode("rjmp","L%05d",IC_FALSE(ifx)->key);
- }
- } else { /* right not power of two */
- int eh = OP_SYMBOL(left)->liveTo <= ic->seq;
- if (size == 1) {
- if (eh) {
- emitcode(bopnames_lit[bitop],"%s,lo8(%d)",
- aopGet(AOP(IC_LEFT(ic)),0), lit);
- } else {
- MOVR0(aopGet(AOP(IC_LEFT(ic)),0));
- emitcode(bopnames_lit[bitop],"r0,lo8(%d)",lit);
- }
- lbl = newiTempLabel(NULL);
- if (IC_TRUE(ifx)) {
- emitcode("breq","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_TRUE(ifx)->key);
- } else {
- emitcode("brne","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_FALSE(ifx)->key);
- }
- emitcode("","L%05d:",lbl->key);
- } else if (size == 2) {
- emitcode("mov","r24,%s",aopGet(AOP(IC_LEFT(ic)),0));
- emitcode("mov","r25,%s",aopGet(AOP(IC_LEFT(ic)),1));
- emitcode(bopnames_lit[bitop],"r24,lo8(%d)",lit);
- emitcode(bopnames_lit[bitop],"r25,hi8(%d)",lit);
- emitcode("sbiw","r24,0");
- lbl = newiTempLabel(NULL);
- if (IC_TRUE(ifx)) {
- emitcode("breq","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_TRUE(ifx)->key);
- } else {
- emitcode("brne","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_FALSE(ifx)->key);
- }
- emitcode("","L%05d:",lbl->key);
- } else {
- lbl = newiTempLabel(NULL);
- lbl1 = newiTempLabel(NULL);
- while (size--) {
- if (eh) {
- emitcode(bopnames_lit[bitop],"%s,lo8(%d)",
- aopGet(AOP(IC_LEFT(ic)),offset), lit);
- } else {
- MOVR0(aopGet(AOP(IC_LEFT(ic)),offset));
- emitcode("andi","r0,lo8(%d)",lit);
- }
- emitcode("brne","L%05d",lbl->key);
- offset++;
- }
- /* all are zero */
- if (IC_FALSE(ifx)) emitcode("rjmp","L%05d",IC_FALSE(ifx)->key);
- else emitcode("rjmp","L%05d",lbl1->key);
- emitcode("","L%05d:",lbl->key);
- /* not zero */
- if (IC_TRUE(ifx)) emitcode("rjmp","L%05d",IC_TRUE(ifx)->key);
- emitcode("","L%05d:",lbl1->key);
-
- }
- }
- } else { /* right is not a literal */
- int eh = OP_SYMBOL(left)->liveTo <= ic->seq;
- int reh = OP_SYMBOL(right)->liveTo <= ic->seq;
- if (size == 1) {
- if (eh) {
- emitcode(bopnames[bitop],"%s,%s",
- aopGet(AOP(IC_LEFT(ic)),0),
- aopGet(AOP(IC_RIGHT(ic)),0));
- } else if (reh) {
- emitcode(bopnames[bitop],"%s,%s",
- aopGet(AOP(IC_RIGHT(ic)),0),
- aopGet(AOP(IC_LEFT(ic)),0));
- } else {
- MOVR0(aopGet(AOP(IC_LEFT(ic)),0));
- emitcode(bopnames[bitop],"r0,%s",aopGet(AOP(IC_RIGHT(ic)),0));
- }
- lbl = newiTempLabel(NULL);
- if (IC_TRUE(ifx)) {
- emitcode("breq","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_TRUE(ifx)->key);
- } else {
- emitcode("brne","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_FALSE(ifx)->key);
- }
- emitcode("","L%05d:",lbl->key);
- } else if (size == 2) {
- emitcode("mov","r24,%s",aopGet(AOP(IC_LEFT(ic)),0));
- emitcode("mov","r25,%s",aopGet(AOP(IC_LEFT(ic)),1));
- emitcode(bopnames[bitop],"r24,%s",aopGet(AOP(IC_RIGHT(ic)),0));
- emitcode(bopnames[bitop],"r25,%s",aopGet(AOP(IC_RIGHT(ic)),1));
- emitcode("sbiw","r24,0");
- lbl = newiTempLabel(NULL);
- if (IC_TRUE(ifx)) {
- emitcode("breq","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_TRUE(ifx)->key);
- } else {
- emitcode("brne","L%05d",lbl->key);
- emitcode("rjmp","L%05d",IC_FALSE(ifx)->key);
- }
- emitcode("","L%05d:",lbl->key);
- } else {
- lbl = newiTempLabel(NULL);
- lbl1 = newiTempLabel(NULL);
- while (size--) {
- if (eh) {
- emitcode(bopnames[bitop],"%s,%s",
- aopGet(AOP(IC_LEFT(ic)),offset),
- aopGet(AOP(IC_RIGHT(ic)),offset));
- } else if (reh) {
- emitcode(bopnames[bitop],"%s,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset),
- aopGet(AOP(IC_LEFT(ic)),offset));
- } else {
- MOVR0(aopGet(AOP(IC_LEFT(ic)),offset));
- emitcode(bopnames[bitop],"r0,%s",aopGet(AOP(IC_RIGHT(ic)),offset));
- }
- emitcode("brne","L%05d",lbl->key);
- offset++;
- }
- /* all are zero */
- if (IC_FALSE(ifx)) emitcode("rjmp","L%05d",IC_FALSE(ifx)->key);
- else emitcode("rjmp","L%05d",lbl1->key);
- emitcode("","L%05d:",lbl->key);
- /* not zero */
- if (IC_TRUE(ifx)) emitcode("rjmp","L%05d",IC_TRUE(ifx)->key);
- emitcode("","L%05d:",lbl1->key);
-
- }
+ if (ifx)
+ { /* used only for jumps */
+ if (AOP_TYPE (right) == AOP_LIT &&
+ (bitop == AVR_AND || bitop == AVR_OR))
+ {
+ int lit = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int p2 = powof2 (lit);
+ if (bitop == AVR_AND && p2)
+ { /* right side is a power of 2 */
+ l = aopGet (AOP (left), p2 / 8);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("sbrc", "%s,%d", l, (p2 % 8));
+ emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
+ }
+ else
+ {
+ emitcode ("sbrs", "%s,%d", l, (p2 % 8));
+ emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
+ }
+ }
+ else
+ { /* right not power of two */
+ int eh = OP_SYMBOL (left)->liveTo <= ic->seq;
+ if (size == 1)
+ {
+ if (eh)
+ {
+ emitcode (bopnames_lit[bitop], "%s,lo8(%d)",
+ aopGet (AOP (IC_LEFT (ic)), 0), lit);
+ }
+ else
+ {
+ MOVR0 (aopGet (AOP (IC_LEFT (ic)), 0));
+ emitcode (bopnames_lit[bitop], "r0,lo8(%d)", lit);
+ }
+ lbl = newiTempLabel (NULL);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("breq", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
+ }
+ else
+ {
+ emitcode ("brne", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
+ }
+ emitcode ("", "L%05d:", lbl->key);
+ }
+ else if (size == 2)
+ {
+ emitcode ("mov", "r24,%s", aopGet (AOP (IC_LEFT (ic)), 0));
+ emitcode ("mov", "r25,%s", aopGet (AOP (IC_LEFT (ic)), 1));
+ emitcode (bopnames_lit[bitop], "r24,lo8(%d)", lit);
+ emitcode (bopnames_lit[bitop], "r25,hi8(%d)", lit);
+ emitcode ("sbiw", "r24,0");
+ lbl = newiTempLabel (NULL);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("breq", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
+ }
+ else
+ {
+ emitcode ("brne", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
+ }
+ emitcode ("", "L%05d:", lbl->key);
+ }
+ else
+ {
+ lbl = newiTempLabel (NULL);
+ lbl1 = newiTempLabel (NULL);
+ while (size--)
+ {
+ if (eh)
+ {
+ emitcode (bopnames_lit[bitop], "%s,lo8(%d)",
+ aopGet (AOP (IC_LEFT (ic)), offset), lit);
+ }
+ else
+ {
+ MOVR0 (aopGet (AOP (IC_LEFT (ic)), offset));
+ emitcode ("andi", "r0,lo8(%d)", lit);
+ }
+ emitcode ("brne", "L%05d", lbl->key);
+ offset++;
+ }
+ /* all are zero */
+ if (IC_FALSE (ifx))
+ emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
+ else
+ emitcode ("rjmp", "L%05d", lbl1->key);
+ emitcode ("", "L%05d:", lbl->key);
+ /* not zero */
+ if (IC_TRUE (ifx))
+ emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
+ emitcode ("", "L%05d:", lbl1->key);
+
+ }
+ }
+ }
+ else
+ { /* right is not a literal */
+ int eh = OP_SYMBOL (left)->liveTo <= ic->seq;
+ int reh = OP_SYMBOL (right)->liveTo <= ic->seq;
+ if (size == 1)
+ {
+ if (eh)
+ {
+ emitcode (bopnames[bitop], "%s,%s",
+ aopGet (AOP (IC_LEFT (ic)), 0),
+ aopGet (AOP (IC_RIGHT (ic)), 0));
+ }
+ else if (reh)
+ {
+ emitcode (bopnames[bitop], "%s,%s",
+ aopGet (AOP (IC_RIGHT (ic)), 0),
+ aopGet (AOP (IC_LEFT (ic)), 0));
+ }
+ else
+ {
+ MOVR0 (aopGet (AOP (IC_LEFT (ic)), 0));
+ emitcode (bopnames[bitop], "r0,%s", aopGet (AOP (IC_RIGHT (ic)), 0));
+ }
+ lbl = newiTempLabel (NULL);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("breq", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
+ }
+ else
+ {
+ emitcode ("brne", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
+ }
+ emitcode ("", "L%05d:", lbl->key);
+ }
+ else if (size == 2)
+ {
+ emitcode ("mov", "r24,%s", aopGet (AOP (IC_LEFT (ic)), 0));
+ emitcode ("mov", "r25,%s", aopGet (AOP (IC_LEFT (ic)), 1));
+ emitcode (bopnames[bitop], "r24,%s", aopGet (AOP (IC_RIGHT (ic)), 0));
+ emitcode (bopnames[bitop], "r25,%s", aopGet (AOP (IC_RIGHT (ic)), 1));
+ emitcode ("sbiw", "r24,0");
+ lbl = newiTempLabel (NULL);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("breq", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
+ }
+ else
+ {
+ emitcode ("brne", "L%05d", lbl->key);
+ emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
+ }
+ emitcode ("", "L%05d:", lbl->key);
+ }
+ else
+ {
+ lbl = newiTempLabel (NULL);
+ lbl1 = newiTempLabel (NULL);
+ while (size--)
+ {
+ if (eh)
+ {
+ emitcode (bopnames[bitop], "%s,%s",
+ aopGet (AOP (IC_LEFT (ic)), offset),
+ aopGet (AOP (IC_RIGHT (ic)), offset));
+ }
+ else if (reh)
+ {
+ emitcode (bopnames[bitop], "%s,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset),
+ aopGet (AOP (IC_LEFT (ic)), offset));
+ }
+ else
+ {
+ MOVR0 (aopGet (AOP (IC_LEFT (ic)), offset));
+ emitcode (bopnames[bitop], "r0,%s", aopGet (AOP (IC_RIGHT (ic)), offset));
+ }
+ emitcode ("brne", "L%05d", lbl->key);
+ offset++;
+ }
+ /* all are zero */
+ if (IC_FALSE (ifx))
+ emitcode ("rjmp", "L%05d", IC_FALSE (ifx)->key);
+ else
+ emitcode ("rjmp", "L%05d", lbl1->key);
+ emitcode ("", "L%05d:", lbl->key);
+ /* not zero */
+ if (IC_TRUE (ifx))
+ emitcode ("rjmp", "L%05d", IC_TRUE (ifx)->key);
+ emitcode ("", "L%05d:", lbl1->key);
+
+ }
+ }
+ goto release;
}
- goto release ;
- }
/* result needs to go a register */
- samerl = sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic)));
- samerr = sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)));
- while (size--) {
- if (AOP_TYPE(right) == AOP_LIT) {
- unsigned int lit = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- if (((lit >> (8*offset)) & 0xff) == 0) {
- if (bitop == AVR_AND) {
- aopPut(AOP(result),zero,offset++);
- continue;
- } else if (bitop == AVR_OR) {
- if (!samerl)
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
- continue;
- }
- }
+ samerl = sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)));
+ samerr = sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)));
+ while (size--)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned int lit = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ if (((lit >> (8 * offset)) & 0xff) == 0)
+ {
+ if (bitop == AVR_AND)
+ {
+ aopPut (AOP (result), zero, offset++);
+ continue;
+ }
+ else if (bitop == AVR_OR)
+ {
+ if (!samerl)
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ continue;
+ }
+ }
+ }
+ if (samerl)
+ {
+ if (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT && (bitop == AVR_AND || bitop == AVR_OR))
+ {
+ emitcode (bopnames_lit[bitop], "%s,%s(%d)", aopGet (AOP (IC_LEFT (ic)), offset),
+ larray[offset], (int) floatFromVal (AOP (right)->aopu.aop_lit));
+ }
+ else
+ {
+ emitcode (bopnames[bitop], "%s,%s", aopGet (AOP (IC_LEFT (ic)), offset),
+ aopGet (AOP (IC_RIGHT (ic)), offset));
+ }
+ }
+ else if (samerr)
+ {
+ emitcode (bopnames[bitop], "%s,%s", aopGet (AOP (IC_RIGHT (ic)), offset),
+ aopGet (AOP (IC_LEFT (ic)), offset));
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), aopGet (AOP (IC_LEFT (ic)), offset), offset);
+ emitcode (bopnames[bitop], aopGet (AOP (IC_RESULT (ic)), offset),
+ aopGet (AOP (IC_RIGHT (ic)), offset));
+ }
+ offset++;
}
- if (samerl) {
- if (AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT && (bitop == AVR_AND || bitop == AVR_OR)) {
- emitcode(bopnames_lit[bitop],"%s,%s(%d)",aopGet(AOP(IC_LEFT(ic)),offset),
- larray[offset],(int) floatFromVal (AOP(right)->aopu.aop_lit));
- } else {
- emitcode(bopnames[bitop],"%s,%s",aopGet(AOP(IC_LEFT(ic)),offset),
- aopGet(AOP(IC_RIGHT(ic)),offset));
- }
- } else if (samerr) {
- emitcode(bopnames[bitop],"%s,%s",aopGet(AOP(IC_RIGHT(ic)),offset),
- aopGet(AOP(IC_LEFT(ic)),offset));
- } else {
- aopPut(AOP(IC_RESULT(ic)),aopGet(AOP(IC_LEFT(ic)),offset),offset);
- emitcode(bopnames[bitop],aopGet(AOP(IC_RESULT(ic)),offset),
- aopGet(AOP(IC_RIGHT(ic)),offset));
- }
- offset++;
- }
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genAnd - code for and */
/*-----------------------------------------------------------------*/
-static void genAnd (iCode *ic, iCode *ifx)
+static void
+genAnd (iCode * ic, iCode * ifx)
{
- genBitWise(ic,ifx,AVR_AND);
+ genBitWise (ic, ifx, AVR_AND);
}
/*-----------------------------------------------------------------*/
/* genOr - code for or */
/*-----------------------------------------------------------------*/
-static void genOr (iCode *ic, iCode *ifx)
+static void
+genOr (iCode * ic, iCode * ifx)
{
- genBitWise(ic,ifx,AVR_OR);
+ genBitWise (ic, ifx, AVR_OR);
}
/*-----------------------------------------------------------------*/
/* genXor - code for xclusive or */
/*-----------------------------------------------------------------*/
-static void genXor (iCode *ic, iCode *ifx)
+static void
+genXor (iCode * ic, iCode * ifx)
{
- genBitWise(ic,ifx,AVR_XOR);
+ genBitWise (ic, ifx, AVR_XOR);
}
/*-----------------------------------------------------------------*/
/* genInline - write the inline code out */
/*-----------------------------------------------------------------*/
-static void genInline (iCode *ic)
+static void
+genInline (iCode * ic)
{
char buffer[MAX_INLINEASM];
char *bp = buffer;
- char *bp1= buffer;
+ char *bp1 = buffer;
_G.inLine += (!options.asmpeep);
- strcpy(buffer,IC_INLINE(ic));
+ strcpy (buffer, IC_INLINE (ic));
/* emit each line as a code */
- while (*bp) {
- if (*bp == '\n') {
- *bp++ = '\0';
- emitcode(bp1,"");
- bp1 = bp;
- } else {
- if (*bp == ':') {
- bp++;
- *bp = '\0';
- bp++;
- emitcode(bp1,"");
- bp1 = bp;
- } else
- bp++;
+ while (*bp)
+ {
+ if (*bp == '\n')
+ {
+ *bp++ = '\0';
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ {
+ if (*bp == ':')
+ {
+ bp++;
+ *bp = '\0';
+ bp++;
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ bp++;
+ }
}
- }
if (bp1 != bp)
- emitcode(bp1,"");
+ emitcode (bp1, "");
/* emitcode("",buffer); */
_G.inLine -= (!options.asmpeep);
}
/*-----------------------------------------------------------------*/
/* genRotC - rotate right/left with carry , lr = 1 rotate right */
/*-----------------------------------------------------------------*/
-static void genRotC (iCode *ic, int lr)
+static void
+genRotC (iCode * ic, int lr)
{
- operand *left , *result ;
+ operand *left, *result;
int size, offset = 0;
/* rotate right with carry */
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
/* move it to the result */
- size = AOP_SIZE(result);
- if (!sameRegs(AOP(left),AOP(result))) {
- offset = 0;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(left),offset),
- offset);
- offset++;
+ size = AOP_SIZE (result);
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset),
+ offset);
+ offset++;
+ }
+ size = AOP_SIZE (result);
}
- size = AOP_SIZE(result);
- }
- if (lr) offset = size - 1;
- else offset = 0;
+ if (lr)
+ offset = size - 1;
+ else
+ offset = 0;
CLRC;
- emitcode ("sbrc","%s,%d",aopGet(AOP(result),offset),
- (lr ? 0 : 7));
- emitcode("sec","");
-
- while (size--) {
- emitcode((lr ? "ror" : "rol"),"%s",aopGet(AOP(result),offset));
- if (lr) offset--;
- else offset++;
- }
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ emitcode ("sbrc", "%s,%d", aopGet (AOP (result), offset),
+ (lr ? 0 : 7));
+ emitcode ("sec", "");
+
+ while (size--)
+ {
+ emitcode ((lr ? "ror" : "rol"), "%s", aopGet (AOP (result), offset));
+ if (lr)
+ offset--;
+ else
+ offset++;
+ }
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRRC - rotate right with carry */
/*-----------------------------------------------------------------*/
-static void genRRC (iCode *ic)
+static void
+genRRC (iCode * ic)
{
- genRotC(ic,1);
+ genRotC (ic, 1);
}
/*-----------------------------------------------------------------*/
/* genRLC - generate code for rotate left with carry */
/*-----------------------------------------------------------------*/
-static void genRLC (iCode *ic)
+static void
+genRLC (iCode * ic)
{
- genRotC(ic,0);
+ genRotC (ic, 0);
}
/*-----------------------------------------------------------------*/
/* genGetHbit - generates code get highest order bit */
/*-----------------------------------------------------------------*/
-static void genGetHbit (iCode *ic)
+static void
+genGetHbit (iCode * ic)
{
operand *left, *result;
- int size, offset ;
-
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
-
- size = AOP_SIZE(result);
- if (!sameRegs(AOP(left),AOP(result))) {
- emitcode("clr","%s",aopGet(AOP(result),size -1));
- emitcode("sbrc","%s,7",aopGet(AOP(left),size -1));
- emitcode("subi","%s,lo8(-1)",aopGet(AOP(result),size-1));
- } else {
- emitcode("clr","r0");
- emitcode("sbrc","%s,7",aopGet(AOP(left),size-1));
- emitcode("subi","r0,lo8(-1)");
- aopPut(AOP(result),"r0",0);
- }
+ int size, offset;
+
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ size = AOP_SIZE (result);
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
+ emitcode ("clr", "%s", aopGet (AOP (result), size - 1));
+ emitcode ("sbrc", "%s,7", aopGet (AOP (left), size - 1));
+ emitcode ("subi", "%s,lo8(-1)", aopGet (AOP (result), size - 1));
+ }
+ else
+ {
+ emitcode ("clr", "r0");
+ emitcode ("sbrc", "%s,7", aopGet (AOP (left), size - 1));
+ emitcode ("subi", "r0,lo8(-1)");
+ aopPut (AOP (result), "r0", 0);
+ }
offset = 1;
- size --;
- while (size--) {
- emitcode("clr",aopGet(AOP(result),offset++));
- }
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ size--;
+ while (size--)
+ {
+ emitcode ("clr", aopGet (AOP (result), offset++));
+ }
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genShiftLeftLit - shift left by a known amount */
/*-----------------------------------------------------------------*/
-static void genShiftLeftLit (iCode *ic)
+static void
+genShiftLeftLit (iCode * ic)
{
- operand *left,*right, *result;
- int size , shCount, offset =0;
- int lByteZ=0;
+ operand *left, *right, *result;
+ int size, shCount, offset = 0;
+ int lByteZ = 0;
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
- size = AOP_SIZE(result);
- shCount = (int)floatFromVal (AOP(right)->aopu.aop_lit);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+ size = AOP_SIZE (result);
+ shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
- if (shCount > (size*8 -1)) {
- while (size--) aopPut(AOP(result),zero,offset++);
- goto release;
- }
- switch(size) {
- case 1:
- if (!sameRegs(AOP(left),AOP(result)))
- aopPut(AOP(result),aopGet(AOP(left),0),0);
- if (shCount >= 4) {
- emitcode("swap","%s",aopGet(AOP(result),0));
- emitcode("andi","%s,0xf0");
- shCount -= 4;
- }
- if (shCount == 1) {
- emitcode("add","%s,%s",aopGet(AOP(result),0),aopGet(AOP(result),0));
- shCount--;
- }
- while (shCount--)
- emitcode("lsl","%s",aopGet(AOP(result),0));
- break;
- case 2:
- if (shCount >= 12) {
- aopPut(AOP(result),aopGet(AOP(left),0),1);
- aopPut(AOP(result),zero,0);
- emitcode("swap","%s",aopGet(AOP(result),1));
- emitcode("andi","%s,0xf0",aopGet(AOP(result),1));
- shCount -= 12;
- lByteZ = 1;
- }
- if (shCount >= 8) {
- aopPut(AOP(result),aopGet(AOP(left),0),1);
- aopPut(AOP(result),zero,0);
- shCount -= 8;
- lByteZ = 1;
- }
- if (shCount >= 4) {
- shCount -= 4;
- if (!sameRegs(AOP(left),AOP(result))) {
- aopPut(AOP(result),aopGet(AOP(left),0),0);
- aopPut(AOP(result),aopGet(AOP(left),1),1);
- }
- emitcode("mov","r1,%s",aopGet(AOP(result),0));
- emitcode("swap","%s",aopGet(AOP(result),0));
- emitcode("andi","%s,0xf0",aopGet(AOP(result),0));
- emitcode("andi","r1,0x0f");
- emitcode("swap","%s",aopGet(AOP(result),1));
- emitcode("andi","%s,0xf0",aopGet(AOP(result),1));
- emitcode("or","%s,r1",aopGet(AOP(result),1));
- while(shCount--) {
- emitcode("lsl","%s",aopGet(AOP(result),0));
- emitcode("rol","%s",aopGet(AOP(result),1));
- }
- }
- if (!lByteZ && !sameRegs(AOP(result),AOP(left)) && shCount) {
- offset = 0;
- while(size--) {
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
- }
- }
- while (shCount--) {
- if (lByteZ) {
- emitcode("lsl","%s",aopGet(AOP(result),1));
- } else {
- emitcode("lsl","%s",aopGet(AOP(result),0));
- emitcode("rol","%s",aopGet(AOP(result),1));
- }
+ if (shCount > (size * 8 - 1))
+ {
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ goto release;
}
- break;
- case 3:
- assert("shifting generic pointer ?\n");
- break;
- case 4:
- /* 32 bits we do only byte boundaries */
- if (shCount >= 24) {
- aopPut(AOP(result),aopGet(AOP(left),0),3);
- aopPut(AOP(result),zero,2);
- aopPut(AOP(result),zero,1);
- aopPut(AOP(result),zero,0);
- lByteZ = 3;
- shCount -= 24;
- }
- if (shCount >= 16) {
- aopPut(AOP(result),aopGet(AOP(left),0),3);
- aopPut(AOP(result),aopGet(AOP(left),1),2);
- aopPut(AOP(result),zero,1);
- aopPut(AOP(result),zero,0);
- lByteZ = 2;
- shCount -= 16;
- }
- if (shCount >= 8) {
- aopPut(AOP(result),aopGet(AOP(left),0),3);
- aopPut(AOP(result),aopGet(AOP(left),1),2);
- aopPut(AOP(result),aopGet(AOP(left),2),1);
- aopPut(AOP(result),zero,0);
- shCount -= 8;
- lByteZ = 1;
- }
- if (!lByteZ && !sameRegs(AOP(left),AOP(right))) {
- offset = 0;
- while (size--) {
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
- }
- offset = 0;
- size = AOP_SIZE(result);
- }
- if (shCount) {
- switch (lByteZ) {
- case 0:
- while (shCount--) {
- emitcode("lsl","%s",aopGet(AOP(result),0));
- emitcode("rol","%s",aopGet(AOP(result),1));
- emitcode("rol","%s",aopGet(AOP(result),2));
- emitcode("rol","%s",aopGet(AOP(result),3));
- }
- break;
- case 1:
- while (shCount--) {
- emitcode("lsl","%s",aopGet(AOP(result),1));
- emitcode("rol","%s",aopGet(AOP(result),2));
- emitcode("rol","%s",aopGet(AOP(result),3));
- }
- break;
- case 2:
- while (shCount--) {
- emitcode("lsl","%s",aopGet(AOP(result),2));
- emitcode("rol","%s",aopGet(AOP(result),3));
- }
- break;
- case 3:
- while (shCount--) {
- emitcode("lsl","%s",aopGet(AOP(result),3));
- }
- break;
- }
+ switch (size)
+ {
+ case 1:
+ if (!sameRegs (AOP (left), AOP (result)))
+ aopPut (AOP (result), aopGet (AOP (left), 0), 0);
+ if (shCount >= 4)
+ {
+ emitcode ("swap", "%s", aopGet (AOP (result), 0));
+ emitcode ("andi", "%s,0xf0");
+ shCount -= 4;
+ }
+ if (shCount == 1)
+ {
+ emitcode ("add", "%s,%s", aopGet (AOP (result), 0), aopGet (AOP (result), 0));
+ shCount--;
+ }
+ while (shCount--)
+ emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+ break;
+ case 2:
+ if (shCount >= 12)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 0), 1);
+ aopPut (AOP (result), zero, 0);
+ emitcode ("swap", "%s", aopGet (AOP (result), 1));
+ emitcode ("andi", "%s,0xf0", aopGet (AOP (result), 1));
+ shCount -= 12;
+ lByteZ = 1;
+ }
+ if (shCount >= 8)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 0), 1);
+ aopPut (AOP (result), zero, 0);
+ shCount -= 8;
+ lByteZ = 1;
+ }
+ if (shCount >= 4)
+ {
+ shCount -= 4;
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 0), 0);
+ aopPut (AOP (result), aopGet (AOP (left), 1), 1);
+ }
+ emitcode ("mov", "r1,%s", aopGet (AOP (result), 0));
+ emitcode ("swap", "%s", aopGet (AOP (result), 0));
+ emitcode ("andi", "%s,0xf0", aopGet (AOP (result), 0));
+ emitcode ("andi", "r1,0x0f");
+ emitcode ("swap", "%s", aopGet (AOP (result), 1));
+ emitcode ("andi", "%s,0xf0", aopGet (AOP (result), 1));
+ emitcode ("or", "%s,r1", aopGet (AOP (result), 1));
+ while (shCount--)
+ {
+ emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+ emitcode ("rol", "%s", aopGet (AOP (result), 1));
+ }
+ }
+ if (!lByteZ && !sameRegs (AOP (result), AOP (left)) && shCount)
+ {
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ }
+ }
+ while (shCount--)
+ {
+ if (lByteZ)
+ {
+ emitcode ("lsl", "%s", aopGet (AOP (result), 1));
+ }
+ else
+ {
+ emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+ emitcode ("rol", "%s", aopGet (AOP (result), 1));
+ }
+ }
+ break;
+ case 3:
+ assert ("shifting generic pointer ?\n");
+ break;
+ case 4:
+ /* 32 bits we do only byte boundaries */
+ if (shCount >= 24)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 0), 3);
+ aopPut (AOP (result), zero, 2);
+ aopPut (AOP (result), zero, 1);
+ aopPut (AOP (result), zero, 0);
+ lByteZ = 3;
+ shCount -= 24;
+ }
+ if (shCount >= 16)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 0), 3);
+ aopPut (AOP (result), aopGet (AOP (left), 1), 2);
+ aopPut (AOP (result), zero, 1);
+ aopPut (AOP (result), zero, 0);
+ lByteZ = 2;
+ shCount -= 16;
+ }
+ if (shCount >= 8)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 0), 3);
+ aopPut (AOP (result), aopGet (AOP (left), 1), 2);
+ aopPut (AOP (result), aopGet (AOP (left), 2), 1);
+ aopPut (AOP (result), zero, 0);
+ shCount -= 8;
+ lByteZ = 1;
+ }
+ if (!lByteZ && !sameRegs (AOP (left), AOP (right)))
+ {
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ }
+ offset = 0;
+ size = AOP_SIZE (result);
+ }
+ if (shCount)
+ {
+ switch (lByteZ)
+ {
+ case 0:
+ while (shCount--)
+ {
+ emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+ emitcode ("rol", "%s", aopGet (AOP (result), 1));
+ emitcode ("rol", "%s", aopGet (AOP (result), 2));
+ emitcode ("rol", "%s", aopGet (AOP (result), 3));
+ }
+ break;
+ case 1:
+ while (shCount--)
+ {
+ emitcode ("lsl", "%s", aopGet (AOP (result), 1));
+ emitcode ("rol", "%s", aopGet (AOP (result), 2));
+ emitcode ("rol", "%s", aopGet (AOP (result), 3));
+ }
+ break;
+ case 2:
+ while (shCount--)
+ {
+ emitcode ("lsl", "%s", aopGet (AOP (result), 2));
+ emitcode ("rol", "%s", aopGet (AOP (result), 3));
+ }
+ break;
+ case 3:
+ while (shCount--)
+ {
+ emitcode ("lsl", "%s", aopGet (AOP (result), 3));
+ }
+ break;
+ }
+ }
}
- }
- release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genLeftShift - generates code for left shifting */
/*-----------------------------------------------------------------*/
-static void genLeftShift (iCode *ic)
+static void
+genLeftShift (iCode * ic)
{
- operand *left,*right, *result;
+ operand *left, *right, *result;
int size, offset;
symbol *tlbl;
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- aopOp(right,ic,FALSE);
+ aopOp (right, ic, FALSE);
- if (AOP_TYPE(right) == AOP_LIT) {
- genShiftLeftLit(ic);
- return ;
- }
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genShiftLeftLit (ic);
+ return;
+ }
/* unknown count */
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
- size = AOP_SIZE(result);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+ size = AOP_SIZE (result);
offset = 0;
- if (AOP_SIZE(right) > 1) {
- if (isRegPair(AOP(right))) {
- emitcode("movw","r24,%s",aopGet(AOP(right),0));
- } else {
- emitcode("mov","r24,%s",aopGet(AOP(right),0));
- emitcode("mov","r25,%s",aopGet(AOP(right),1));
- }
- } else {
- emitcode("mov","r24,%s",aopGet(AOP(right),0));
- }
- if (!sameRegs(AOP(left),AOP(result))) {
- while (size--) {
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
+ if (AOP_SIZE (right) > 1)
+ {
+ if (isRegPair (AOP (right)))
+ {
+ emitcode ("movw", "r24,%s", aopGet (AOP (right), 0));
+ }
+ else
+ {
+ emitcode ("mov", "r24,%s", aopGet (AOP (right), 0));
+ emitcode ("mov", "r25,%s", aopGet (AOP (right), 1));
+ }
}
- size = AOP_SIZE(result);
- }
- tlbl = newiTempLabel(NULL);
- emitcode("","L%05d:",tlbl->key);
- offset = 0;
- while (size--) {
- if (offset) emitcode("rol","%s",aopGet(AOP(result),offset));
- else emitcode("lsl","%s",aopGet(AOP(result),0));
- offset++;
- }
- if (AOP_SIZE(right) > 1) emitcode("sbiw","r24,1");
- else emitcode("dec","r24");
- emitcode("brne","L%05d",tlbl->key);
+ else
+ {
+ emitcode ("mov", "r24,%s", aopGet (AOP (right), 0));
+ }
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ }
+ size = AOP_SIZE (result);
+ }
+ tlbl = newiTempLabel (NULL);
+ emitcode ("", "L%05d:", tlbl->key);
+ offset = 0;
+ while (size--)
+ {
+ if (offset)
+ emitcode ("rol", "%s", aopGet (AOP (result), offset));
+ else
+ emitcode ("lsl", "%s", aopGet (AOP (result), 0));
+ offset++;
+ }
+ if (AOP_SIZE (right) > 1)
+ emitcode ("sbiw", "r24,1");
+ else
+ emitcode ("dec", "r24");
+ emitcode ("brne", "L%05d", tlbl->key);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genShiftRightLit - generate for right shift with known count */
/*-----------------------------------------------------------------*/
-static void genShiftRightLit (iCode *ic)
+static void
+genShiftRightLit (iCode * ic)
{
- operand *left = IC_LEFT(ic)
- ,*right= IC_RIGHT(ic)
- ,*result=IC_RESULT(ic);
- int size , shCount, offset =0;
- int hByteZ=0;
- sym_link *letype = getSpec(operandType(left));
- int sign = !SPEC_USIGN(letype);
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
- size = AOP_SIZE(result);
- shCount = (int)floatFromVal (AOP(right)->aopu.aop_lit);
+ operand *left = IC_LEFT (ic)
+ ,*right = IC_RIGHT (ic)
+ ,*result = IC_RESULT (ic);
+ int size, shCount, offset = 0;
+ int hByteZ = 0;
+ sym_link *letype = getSpec (operandType (left));
+ int sign = !SPEC_USIGN (letype);
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+ size = AOP_SIZE (result);
+ shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
/* if signed then give up and use a loop to shift */
- if (sign) {
- symbol *tlbl ;
- if (!sameRegs(AOP(left),AOP(result))) {
- while (size--) {
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
- }
- size = size = AOP_SIZE(result);
- offset = 0;
+ if (sign)
+ {
+ symbol *tlbl;
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ }
+ size = size = AOP_SIZE (result);
+ offset = 0;
+ }
+ /* be as economical as possible */
+ if (shCount <= 4)
+ {
+ offset = size - 1;
+ while (shCount--)
+ {
+ offset = size - 1;
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ if (offset == (size - 1))
+ emitcode ("asr", "%s", aopGet (AOP (result), offset));
+ else
+ emitcode ("lsr", "%s", aopGet (AOP (result), offset));
+ offset--;
+ }
+ }
+ }
+ else
+ {
+ emitcode ("ldi", "r24,lo8(%d)", shCount);
+ tlbl = newiTempLabel (NULL);
+ emitcode ("", "L%05d:", tlbl->key);
+ offset = size - 1;
+ while (size--)
+ {
+ if (offset == (size - 1))
+ emitcode ("asr", "%s", aopGet (AOP (result), offset));
+ else
+ emitcode ("lsr", "%s", aopGet (AOP (result), offset));
+ offset--;
+ }
+ emitcode ("dec", "r24");
+ emitcode ("brne", "L%05d", tlbl->key);
+ }
+ goto release;
}
- /* be as economical as possible */
- if (shCount <= 4) {
- offset = size -1;
- while (shCount--) {
- offset = size -1;
- size = AOP_SIZE(result);
- while (size--) {
- if (offset == (size-1))
- emitcode("asr","%s",aopGet(AOP(result),offset));
- else
- emitcode("lsr","%s",aopGet(AOP(result),offset));
- offset--;
- }
- }
- } else {
- emitcode("ldi","r24,lo8(%d)",shCount);
- tlbl = newiTempLabel(NULL);
- emitcode("","L%05d:",tlbl->key);
- offset = size -1;
- while (size--) {
- if (offset == (size-1)) emitcode("asr","%s",aopGet(AOP(result),offset));
- else emitcode("lsr","%s",aopGet(AOP(result),offset));
- offset--;
- }
- emitcode("dec","r24");
- emitcode("brne","L%05d",tlbl->key);
+ if (shCount > (size * 8 - 1))
+ {
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ goto release;
}
- goto release;
- }
- if (shCount > (size*8 -1)) {
- while (size--) aopPut(AOP(result),zero,offset++);
- goto release;
- }
/* for unsigned we can much more efficient */
- switch (size) {
- case 1:
- if (!sameRegs(AOP(left),AOP(result)))
- aopPut(AOP(result),aopGet(AOP(left),0),0);
- if (shCount >= 4) {
- emitcode("swap","%s",aopGet(AOP(result),0));
- emitcode("andi","%s,0x0f");
- shCount -= 4;
- }
- while (shCount--)
- emitcode("lsr","%s",aopGet(AOP(result),0));
- break;
- case 2:
- if (shCount >= 12) {
- aopPut(AOP(result),aopGet(AOP(left),1),0);
- aopPut(AOP(result),zero,1);
- emitcode("swap","%s",aopGet(AOP(result),0));
- emitcode("andi","%s,0x0f",aopGet(AOP(result),0));
- shCount -= 12;
- hByteZ = 1;
- }
- if (shCount >= 8) {
- aopPut(AOP(result),aopGet(AOP(left),1),0);
- aopPut(AOP(result),zero,1);
- shCount -= 8;
- hByteZ = 1;
- }
- if (shCount >= 4) {
- shCount -= 4;
- if (!sameRegs(AOP(left),AOP(result))) {
- aopPut(AOP(result),aopGet(AOP(left),0),0);
- aopPut(AOP(result),aopGet(AOP(left),1),1);
- }
- emitcode("mov","r1,%s",aopGet(AOP(result),1));
- emitcode("swap","%s",aopGet(AOP(result),0));
- emitcode("andi","%s,0x0f",aopGet(AOP(result),0));
- emitcode("andi","r1,0xf0");
- emitcode("or","%s,r1",aopGet(AOP(result),0));
- emitcode("swap","%s",aopGet(AOP(result),1));
- emitcode("andi","%s,0x0f",aopGet(AOP(result),1));
- while(shCount--) {
- emitcode("lsr","%s",aopGet(AOP(result),1));
- emitcode("ror","%s",aopGet(AOP(result),0));
- }
+ switch (size)
+ {
+ case 1:
+ if (!sameRegs (AOP (left), AOP (result)))
+ aopPut (AOP (result), aopGet (AOP (left), 0), 0);
+ if (shCount >= 4)
+ {
+ emitcode ("swap", "%s", aopGet (AOP (result), 0));
+ emitcode ("andi", "%s,0x0f");
+ shCount -= 4;
+ }
+ while (shCount--)
+ emitcode ("lsr", "%s", aopGet (AOP (result), 0));
+ break;
+ case 2:
+ if (shCount >= 12)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 1), 0);
+ aopPut (AOP (result), zero, 1);
+ emitcode ("swap", "%s", aopGet (AOP (result), 0));
+ emitcode ("andi", "%s,0x0f", aopGet (AOP (result), 0));
+ shCount -= 12;
+ hByteZ = 1;
+ }
+ if (shCount >= 8)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 1), 0);
+ aopPut (AOP (result), zero, 1);
+ shCount -= 8;
+ hByteZ = 1;
+ }
+ if (shCount >= 4)
+ {
+ shCount -= 4;
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 0), 0);
+ aopPut (AOP (result), aopGet (AOP (left), 1), 1);
+ }
+ emitcode ("mov", "r1,%s", aopGet (AOP (result), 1));
+ emitcode ("swap", "%s", aopGet (AOP (result), 0));
+ emitcode ("andi", "%s,0x0f", aopGet (AOP (result), 0));
+ emitcode ("andi", "r1,0xf0");
+ emitcode ("or", "%s,r1", aopGet (AOP (result), 0));
+ emitcode ("swap", "%s", aopGet (AOP (result), 1));
+ emitcode ("andi", "%s,0x0f", aopGet (AOP (result), 1));
+ while (shCount--)
+ {
+ emitcode ("lsr", "%s", aopGet (AOP (result), 1));
+ emitcode ("ror", "%s", aopGet (AOP (result), 0));
+ }
+
+ }
+ if (!hByteZ && !sameRegs (AOP (result), AOP (left)) && shCount)
+ {
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ }
+ }
+ while (shCount--)
+ {
+ if (hByteZ)
+ {
+ emitcode ("lsr", "%s", aopGet (AOP (result), 0));
+ }
+ else
+ {
+ emitcode ("lsr", "%s", aopGet (AOP (result), 1));
+ emitcode ("ror", "%s", aopGet (AOP (result), 0));
+ }
+ }
+ break;
+ case 3:
+ assert ("shifting generic pointer ?\n");
+ break;
+ case 4:
+ /* 32 bits we do only byte boundaries */
+ if (shCount >= 24)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 3), 0);
+ aopPut (AOP (result), zero, 1);
+ aopPut (AOP (result), zero, 2);
+ aopPut (AOP (result), zero, 3);
+ hByteZ = 3;
+ shCount -= 24;
+ }
+ if (shCount >= 16)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 3), 1);
+ aopPut (AOP (result), aopGet (AOP (left), 2), 0);
+ aopPut (AOP (result), zero, 2);
+ aopPut (AOP (result), zero, 3);
+ hByteZ = 2;
+ shCount -= 16;
+ }
+ if (shCount >= 8)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), 1), 0);
+ aopPut (AOP (result), aopGet (AOP (left), 2), 1);
+ aopPut (AOP (result), aopGet (AOP (left), 3), 2);
+ aopPut (AOP (result), zero, 3);
+ shCount -= 8;
+ hByteZ = 1;
+ }
+ if (!hByteZ && !sameRegs (AOP (left), AOP (right)))
+ {
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ }
+ offset = 0;
+ size = AOP_SIZE (result);
+ }
+ if (shCount)
+ {
+ switch (hByteZ)
+ {
+ case 0:
+ while (shCount--)
+ {
+ emitcode ("lsr", "%s", aopGet (AOP (result), 3));
+ emitcode ("ror", "%s", aopGet (AOP (result), 2));
+ emitcode ("ror", "%s", aopGet (AOP (result), 1));
+ emitcode ("ror", "%s", aopGet (AOP (result), 0));
+ }
+ break;
+ case 1:
+ while (shCount--)
+ {
+ emitcode ("lsr", "%s", aopGet (AOP (result), 2));
+ emitcode ("ror", "%s", aopGet (AOP (result), 1));
+ emitcode ("ror", "%s", aopGet (AOP (result), 0));
+ }
+ break;
+ case 2:
+ while (shCount--)
+ {
+ emitcode ("lsr", "%s", aopGet (AOP (result), 1));
+ emitcode ("ror", "%s", aopGet (AOP (result), 0));
+ }
+ break;
+ case 3:
+ while (shCount--)
+ {
+ emitcode ("lsr", "%s", aopGet (AOP (result), 0));
+ }
+ break;
+ }
+ }
}
- if (!hByteZ && !sameRegs(AOP(result),AOP(left)) && shCount) {
- offset = 0;
- while(size--) {
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
- }
- }
- while (shCount--) {
- if (hByteZ) {
- emitcode("lsr","%s",aopGet(AOP(result),0));
- } else {
- emitcode("lsr","%s",aopGet(AOP(result),1));
- emitcode("ror","%s",aopGet(AOP(result),0));
- }
- }
- break;
-
- case 3:
- assert("shifting generic pointer ?\n");
- break;
- case 4:
- /* 32 bits we do only byte boundaries */
- if (shCount >= 24) {
- aopPut(AOP(result),aopGet(AOP(left),3),0);
- aopPut(AOP(result),zero,1);
- aopPut(AOP(result),zero,2);
- aopPut(AOP(result),zero,3);
- hByteZ = 3;
- shCount -= 24;
- }
- if (shCount >= 16) {
- aopPut(AOP(result),aopGet(AOP(left),3),1);
- aopPut(AOP(result),aopGet(AOP(left),2),0);
- aopPut(AOP(result),zero,2);
- aopPut(AOP(result),zero,3);
- hByteZ = 2;
- shCount -= 16;
- }
- if (shCount >= 8) {
- aopPut(AOP(result),aopGet(AOP(left),1),0);
- aopPut(AOP(result),aopGet(AOP(left),2),1);
- aopPut(AOP(result),aopGet(AOP(left),3),2);
- aopPut(AOP(result),zero,3);
- shCount -= 8;
- hByteZ = 1;
- }
- if (!hByteZ && !sameRegs(AOP(left),AOP(right))) {
- offset = 0;
- while (size--) {
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
- }
- offset = 0;
- size = AOP_SIZE(result);
- }
- if (shCount) {
- switch (hByteZ) {
- case 0:
- while (shCount--) {
- emitcode("lsr","%s",aopGet(AOP(result),3));
- emitcode("ror","%s",aopGet(AOP(result),2));
- emitcode("ror","%s",aopGet(AOP(result),1));
- emitcode("ror","%s",aopGet(AOP(result),0));
- }
- break;
- case 1:
- while (shCount--) {
- emitcode("lsr","%s",aopGet(AOP(result),2));
- emitcode("ror","%s",aopGet(AOP(result),1));
- emitcode("ror","%s",aopGet(AOP(result),0));
- }
- break;
- case 2:
- while (shCount--) {
- emitcode("lsr","%s",aopGet(AOP(result),1));
- emitcode("ror","%s",aopGet(AOP(result),0));
- }
- break;
- case 3:
- while (shCount--) {
- emitcode("lsr","%s",aopGet(AOP(result),0));
- }
- break;
- }
- }
- }
- release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRightShift - generate code for right shifting */
/*-----------------------------------------------------------------*/
-static void genRightShift (iCode *ic)
+static void
+genRightShift (iCode * ic)
{
operand *right, *left, *result;
- sym_link *letype ;
+ sym_link *letype;
int size, offset;
- int sign = 0, first =1;
+ int sign = 0, first = 1;
symbol *tlbl;
- aopOp(right=IC_RIGHT(ic),ic,FALSE);
- if (AOP_TYPE(right) == AOP_LIT) {
- genShiftRightLit(ic);
- return ;
- }
+ aopOp (right = IC_RIGHT (ic), ic, FALSE);
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genShiftRightLit (ic);
+ return;
+ }
/* unknown count */
- if (AOP_SIZE(right) > 1) {
- if (isRegPair(AOP(right))) {
- emitcode("movw","r24,%s",aopGet(AOP(right),0));
- } else {
- emitcode("mov","r24,%s",aopGet(AOP(right),0));
- emitcode("mov","r25,%s",aopGet(AOP(right),1));
- }
- } else {
- emitcode("mov","r24,%s",aopGet(AOP(right),0));
- }
- aopOp(left=IC_LEFT(ic),ic,FALSE);
- aopOp(result=IC_RESULT(ic),ic,FALSE);
- size = AOP_SIZE(result);
- tlbl = newiTempLabel(NULL);
- emitcode("","L%05d:",tlbl->key);
- offset = size -1;
- letype = getSpec(operandType(left));
- sign = !SPEC_USIGN(letype);
- if (!sameRegs(AOP(left),AOP(result))) {
- while (size--) {
- aopPut(AOP(result),aopGet(AOP(left),offset),offset);
- offset++;
+ if (AOP_SIZE (right) > 1)
+ {
+ if (isRegPair (AOP (right)))
+ {
+ emitcode ("movw", "r24,%s", aopGet (AOP (right), 0));
+ }
+ else
+ {
+ emitcode ("mov", "r24,%s", aopGet (AOP (right), 0));
+ emitcode ("mov", "r25,%s", aopGet (AOP (right), 1));
+ }
}
- size = AOP_SIZE(result);
- }
- size = AOP_SIZE(result);
- while (size--) {
- if (first) {
- if (sign) emitcode("asr","%s",aopGet(AOP(result),offset));
- else emitcode("lsr","%s",aopGet(AOP(result),offset));
- first = 0;
- }
- else emitcode("ror","%s",aopGet(AOP(result),offset));
- offset--;
- }
- if (AOP_SIZE(right) > 1) emitcode("sbiw","r24,1");
- else emitcode("dec","r24");
- emitcode("brne","L%05d",tlbl->key);
+ else
+ {
+ emitcode ("mov", "r24,%s", aopGet (AOP (right), 0));
+ }
+ aopOp (left = IC_LEFT (ic), ic, FALSE);
+ aopOp (result = IC_RESULT (ic), ic, FALSE);
+ size = AOP_SIZE (result);
+ tlbl = newiTempLabel (NULL);
+ emitcode ("", "L%05d:", tlbl->key);
+ offset = size - 1;
+ letype = getSpec (operandType (left));
+ sign = !SPEC_USIGN (letype);
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
+ while (size--)
+ {
+ aopPut (AOP (result), aopGet (AOP (left), offset), offset);
+ offset++;
+ }
+ size = AOP_SIZE (result);
+ }
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ if (first)
+ {
+ if (sign)
+ emitcode ("asr", "%s", aopGet (AOP (result), offset));
+ else
+ emitcode ("lsr", "%s", aopGet (AOP (result), offset));
+ first = 0;
+ }
+ else
+ emitcode ("ror", "%s", aopGet (AOP (result), offset));
+ offset--;
+ }
+ if (AOP_SIZE (right) > 1)
+ emitcode ("sbiw", "r24,1");
+ else
+ emitcode ("dec", "r24");
+ emitcode ("brne", "L%05d", tlbl->key);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* R0Rsh - shift right r0 by known count */
/*-----------------------------------------------------------------*/
-static void R0Rsh (int shCount)
+static void
+R0Rsh (int shCount)
{
- shCount &= 0x0007; // shCount : 0..7
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("lsr","r0");
- break;
- case 2 :
- emitcode("lsr","r0");
- emitcode("lsr","r0");
- break;
- case 3 :
- emitcode("swap","r0");
- emitcode("lsl","r0");
- break;
- case 4 :
- emitcode("swap","r0");
- break;
- case 5 :
- emitcode("swap","r0");
- emitcode("lsr","r0");
- break;
- case 6 :
- emitcode("swap","r0");
- emitcode("lsr","r0");
- emitcode("lsr","r0");
- break;
- case 7 :
- emitcode("swap","r0");
- emitcode("lsr","r0");
- emitcode("lsr","r0");
- emitcode("lsr","r0");
- break;
- }
+ shCount &= 0x0007; // shCount : 0..7
+
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("lsr", "r0");
+ break;
+ case 2:
+ emitcode ("lsr", "r0");
+ emitcode ("lsr", "r0");
+ break;
+ case 3:
+ emitcode ("swap", "r0");
+ emitcode ("lsl", "r0");
+ break;
+ case 4:
+ emitcode ("swap", "r0");
+ break;
+ case 5:
+ emitcode ("swap", "r0");
+ emitcode ("lsr", "r0");
+ break;
+ case 6:
+ emitcode ("swap", "r0");
+ emitcode ("lsr", "r0");
+ emitcode ("lsr", "r0");
+ break;
+ case 7:
+ emitcode ("swap", "r0");
+ emitcode ("lsr", "r0");
+ emitcode ("lsr", "r0");
+ emitcode ("lsr", "r0");
+ break;
+ }
}
/*-----------------------------------------------------------------*/
/* genUnpackBits - generates code for unpacking bits */
/*-----------------------------------------------------------------*/
-static void genUnpackBits (operand *result, char *rname, int ptype)
+static void
+genUnpackBits (operand * result, char *rname, int ptype)
{
- int shCnt ;
- int rlen = 0 ;
+ int shCnt;
+ int rlen = 0;
sym_link *etype;
- int offset = 0 ;
+ int offset = 0;
- etype = getSpec(operandType(result));
+ etype = getSpec (operandType (result));
/* read the first byte */
- switch (ptype) {
-
- case POINTER:
- case IPOINTER:
- case PPOINTER:
- case FPOINTER:
- emitcode("ld","r0,%s+",rname);
- break;
-
- case CPOINTER:
- emitcode("ldm","r0,%s+",rname);
- break;
-
- case GPOINTER:
- emitcode("call","__gptrget_pi");
- break;
- }
-
- /* if we have bitdisplacement then it fits */
- /* into this byte completely or if length is */
- /* less than a byte */
- if ((shCnt = SPEC_BSTR(etype)) || (SPEC_BLEN(etype) <= 8)) {
-
- /* shift right r0 */
- R0Rsh(shCnt);
- emitcode("andi","r0,0x%02x",
- ((unsigned char) -1)>>(8 - SPEC_BLEN(etype)));
-
- aopPut(AOP(result),"r0",offset);
- return ;
- }
-
- /* bit field did not fit in a byte */
- rlen = SPEC_BLEN(etype) - 8;
- aopPut(AOP(result),"a",offset++);
-
- while (1) {
+ switch (ptype)
+ {
- switch (ptype) {
case POINTER:
case IPOINTER:
case PPOINTER:
case FPOINTER:
- emitcode("ld","r0,%s+",rname);
+ emitcode ("ld", "r0,%s+", rname);
break;
case CPOINTER:
- emitcode("ldm","r0,%s+",rname);
+ emitcode ("ldm", "r0,%s+", rname);
break;
case GPOINTER:
- emitcode("lcall","__gptrget_pi");
+ emitcode ("call", "__gptrget_pi");
break;
}
- rlen -= 8;
- /* if we are done */
- if ( rlen <= 0 )
- break ;
+ /* if we have bitdisplacement then it fits */
+ /* into this byte completely or if length is */
+ /* less than a byte */
+ if ((shCnt = SPEC_BSTR (etype)) || (SPEC_BLEN (etype) <= 8))
+ {
- aopPut(AOP(result),"r0",offset++);
+ /* shift right r0 */
+ R0Rsh (shCnt);
+ emitcode ("andi", "r0,0x%02x",
+ ((unsigned char) -1) >> (8 - SPEC_BLEN (etype)));
- }
+ aopPut (AOP (result), "r0", offset);
+ return;
+ }
- if (rlen) {
- emitcode("andi","r0,#0x%02x",((unsigned char)-1)>>(-rlen));
- aopPut(AOP(result),"r0",offset);
- }
+ /* bit field did not fit in a byte */
+ rlen = SPEC_BLEN (etype) - 8;
+ aopPut (AOP (result), "a", offset++);
+
+ while (1)
+ {
+
+ switch (ptype)
+ {
+ case POINTER:
+ case IPOINTER:
+ case PPOINTER:
+ case FPOINTER:
+ emitcode ("ld", "r0,%s+", rname);
+ break;
+
+ case CPOINTER:
+ emitcode ("ldm", "r0,%s+", rname);
+ break;
- return ;
+ case GPOINTER:
+ emitcode ("lcall", "__gptrget_pi");
+ break;
+ }
+
+ rlen -= 8;
+ /* if we are done */
+ if (rlen <= 0)
+ break;
+
+ aopPut (AOP (result), "r0", offset++);
+
+ }
+
+ if (rlen)
+ {
+ emitcode ("andi", "r0,#0x%02x", ((unsigned char) -1) >> (-rlen));
+ aopPut (AOP (result), "r0", offset);
+ }
+
+ return;
}
/*-----------------------------------------------------------------*/
/* genDataPointerGet - generates code when ptr offset is known */
/*-----------------------------------------------------------------*/
-static void genDataPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genDataPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
char *l;
char buffer[256];
- int size , offset = 0;
- aopOp(result,ic,TRUE);
+ int size, offset = 0;
+ aopOp (result, ic, TRUE);
/* get the string representation of the name */
- l = aopGet(AOP(left),0);
- size = AOP_SIZE(result);
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l+1,offset);
- else
- sprintf(buffer,"%s",l+1);
- emitcode("lds","%s,%s",aopGet(AOP(result),offset++),buffer);
- }
+ l = aopGet (AOP (left), 0);
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l + 1, offset);
+ else
+ sprintf (buffer, "%s", l + 1);
+ emitcode ("lds", "%s,%s", aopGet (AOP (result), offset++), buffer);
+ }
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerGet - emitcode for near pointer fetch */
/*-----------------------------------------------------------------*/
-static void genNearPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genNearPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
+ regs *preg = NULL;
+ char *rname;
sym_link *rtype, *retype;
- sym_link *ltype = operandType(left);
+ sym_link *ltype = operandType (left);
char buffer[80];
- rtype = operandType(result);
- retype= getSpec(rtype);
+ rtype = operandType (result);
+ retype = getSpec (rtype);
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
/* if left is rematerialisable and
result is not bit variable type and
the left is pointer to data space i.e
lower 128 bytes of space */
- if (AOP_TYPE(left) == AOP_IMMD &&
- !IS_BITVAR(retype) &&
- DCL_TYPE(ltype) == POINTER) {
- genDataPointerGet (left,result,ic);
- return ;
- }
+ if (AOP_TYPE (left) == AOP_IMMD &&
+ !IS_BITVAR (retype) &&
+ DCL_TYPE (ltype) == POINTER)
+ {
+ genDataPointerGet (left, result, ic);
+ return;
+ }
/* if the value is already in a pointer register
then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE,0);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE);
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE, 0);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0));
+ rname = preg->name;
+ }
+ else
+ rname = aopGet (AOP (left), 0);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genUnpackBits (result,rname,POINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
- if (IS_AOP_PREG(result) || AOP_TYPE(result) == AOP_STK ) {
-
- emitcode("mov","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
- } else {
- sprintf(buffer,"@%s",rname);
- aopPut(AOP(result),buffer,offset);
- }
- offset++ ;
- if (size)
- emitcode("inc","%s",rname);
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, rname, POINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
+
+ while (size--)
+ {
+ if (IS_AOP_PREG (result) || AOP_TYPE (result) == AOP_STK)
+ {
+
+ emitcode ("mov", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ {
+ sprintf (buffer, "@%s", rname);
+ aopPut (AOP (result), buffer, offset);
+ }
+ offset++;
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
}
- }
/* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
- while (size--)
- emitcode("dec","%s",rname);
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- }
/* done */
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerGet - emitcode for paged pointer fetch */
/*-----------------------------------------------------------------*/
-static void genPagedPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genPagedPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
+ regs *preg = NULL;
+ char *rname;
sym_link *rtype, *retype;
- rtype = operandType(result);
- retype= getSpec(rtype);
+ rtype = operandType (result);
+ retype = getSpec (rtype);
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
/* if the value is already in a pointer register
then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE,0);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE);
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE, 0);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0));
+ rname = preg->name;
+ }
+ else
+ rname = aopGet (AOP (left), 0);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genUnpackBits (result,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
- while (size--) {
+ while (size--)
+ {
- emitcode("movx","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
+ emitcode ("movx", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
- offset++ ;
+ offset++;
- if (size)
- emitcode("inc","%s",rname);
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
}
- }
/* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
- while (size--)
- emitcode("dec","%s",rname);
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- }
/* done */
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerGet - gget value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genFarPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
/* if the operand is already in dptr
then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(left),0));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0));
- emitcode("mov","dph,%s",aopGet(AOP(left),1));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2));
- }
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2));
+ }
+ }
}
- }
/* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- emitcode("movx","a,@dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
+
+ while (size--)
+ {
+ emitcode ("movx", "a,@dptr");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- }
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* emitcodePointerGet - gget value from code space */
/*-----------------------------------------------------------------*/
-static void emitcodePointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+emitcodePointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
/* if the operand is already in dptr
then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(left),0));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0));
- emitcode("mov","dph,%s",aopGet(AOP(left),1));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2));
- }
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2));
+ }
+ }
}
- }
/* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",CPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- emitcode("clr","a");
- emitcode("movc","a,@a+dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", CPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
+
+ while (size--)
+ {
+ emitcode ("clr", "a");
+ emitcode ("movc", "a,@a+dptr");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- }
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerGet - gget value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genGenPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
/* if the operand is already in dptr
then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(left),0));
- emitcode("mov","b,#%d",pointerCode(retype));
- }
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0));
- emitcode("mov","dph,%s",aopGet(AOP(left),1));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2));
- emitcode("mov","b,%s",aopGet(AOP(left),3));
- }
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0));
+ emitcode ("mov", "b,#%d", pointerCode (retype));
+ }
else
- {
- emitcode("mov","b,%s",aopGet(AOP(left),2));
- }
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2));
+ emitcode ("mov", "b,%s", aopGet (AOP (left), 3));
+ }
+ else
+ {
+ emitcode ("mov", "b,%s", aopGet (AOP (left), 2));
+ }
+ }
}
- }
/* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- emitcode("lcall","__gptrget");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
+
+ while (size--)
+ {
+ emitcode ("lcall", "__gptrget");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- }
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
-static void genPointerGet (iCode *ic)
+static void
+genPointerGet (iCode * ic)
{
- operand *left, *result ;
+ operand *left, *result;
sym_link *type, *etype;
int p_type;
- left = IC_LEFT(ic);
- result = IC_RESULT(ic) ;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
/* depending on the type of pointer we need to
move it to the correct pointer register */
- type = operandType(left);
- etype = getSpec(type);
+ type = operandType (left);
+ etype = getSpec (type);
/* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next))
- p_type = DCL_TYPE(type);
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
-
- /* if (SPEC_OCLS(etype)->codesp ) { */
- /* p_type = CPOINTER ; */
- /* } */
- /* else */
- /* if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) */
- /* p_type = FPOINTER ; */
- /* else */
- /* if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) */
- /* p_type = PPOINTER; */
- /* else */
- /* if (SPEC_OCLS(etype) == idata ) */
- /* p_type = IPOINTER; */
- /* else */
- /* p_type = POINTER ; */
- }
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ p_type = DCL_TYPE (type);
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
+
+ /* if (SPEC_OCLS(etype)->codesp ) { */
+ /* p_type = CPOINTER ; */
+ /* } */
+ /* else */
+ /* if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) */
+ /* p_type = FPOINTER ; */
+ /* else */
+ /* if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) */
+ /* p_type = PPOINTER; */
+ /* else */
+ /* if (SPEC_OCLS(etype) == idata ) */
+ /* p_type = IPOINTER; */
+ /* else */
+ /* p_type = POINTER ; */
+ }
/* now that we have the pointer type we assign
the pointer values */
- switch (p_type) {
+ switch (p_type)
+ {
- case POINTER:
- case IPOINTER:
- genNearPointerGet (left,result,ic);
- break;
+ case POINTER:
+ case IPOINTER:
+ genNearPointerGet (left, result, ic);
+ break;
- case PPOINTER:
- genPagedPointerGet(left,result,ic);
- break;
+ case PPOINTER:
+ genPagedPointerGet (left, result, ic);
+ break;
- case FPOINTER:
- genFarPointerGet (left,result,ic);
- break;
+ case FPOINTER:
+ genFarPointerGet (left, result, ic);
+ break;
- case CPOINTER:
- emitcodePointerGet (left,result,ic);
- break;
+ case CPOINTER:
+ emitcodePointerGet (left, result, ic);
+ break;
- case GPOINTER:
- genGenPointerGet (left,result,ic);
- break;
- }
+ case GPOINTER:
+ genGenPointerGet (left, result, ic);
+ break;
+ }
}
/*-----------------------------------------------------------------*/
/* genPackBits - generates code for packed bit storage */
/*-----------------------------------------------------------------*/
-static void genPackBits (sym_link *etype ,
- operand *right ,
- char *rname, int p_type)
+static void
+genPackBits (sym_link * etype,
+ operand * right,
+ char *rname, int p_type)
{
- int shCount = 0 ;
- int offset = 0 ;
- int rLen = 0 ;
- int blen, bstr ;
- char *l ;
+ int shCount = 0;
+ int offset = 0;
+ int rLen = 0;
+ int blen, bstr;
+ char *l;
- blen = SPEC_BLEN(etype);
- bstr = SPEC_BSTR(etype);
+ blen = SPEC_BLEN (etype);
+ bstr = SPEC_BSTR (etype);
- l = aopGet(AOP(right),offset++);
- MOVA(l);
+ l = aopGet (AOP (right), offset++);
+ MOVA (l);
/* if the bit lenth is less than or */
/* it exactly fits a byte then */
- if (SPEC_BLEN(etype) <= 8 ) {
- shCount = SPEC_BSTR(etype) ;
-
- /* shift left acc */
- // AccLsh(shCount);
-
- if (SPEC_BLEN(etype) < 8 ) { /* if smaller than a byte */
-
-
- switch (p_type) {
- case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
- break;
-
- case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
- break;
-
- case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
- break;
- }
-
- emitcode ("anl","a,#0x%02x",(unsigned char)
- ((unsigned char)(0xFF << (blen+bstr)) |
- (unsigned char)(0xFF >> (8-bstr)) ) );
- emitcode ("orl","a,b");
- if (p_type == GPOINTER)
- emitcode("pop","b");
+ if (SPEC_BLEN (etype) <= 8)
+ {
+ shCount = SPEC_BSTR (etype);
+
+ /* shift left acc */
+ // AccLsh(shCount);
+
+ if (SPEC_BLEN (etype) < 8)
+ { /* if smaller than a byte */
+
+
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
+
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
+
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
+
+ emitcode ("anl", "a,#0x%02x", (unsigned char)
+ ((unsigned char) (0xFF << (blen + bstr)) |
+ (unsigned char) (0xFF >> (8 - bstr))));
+ emitcode ("orl", "a,b");
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+ }
}
- }
- switch (p_type) {
- case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "@%s,a", rname);
+ break;
- case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
+ case FPOINTER:
+ emitcode ("movx", "@dptr,a");
+ break;
- case GPOINTER:
- emitcode("lcall","__gptrput");
- break;
- }
+ case GPOINTER:
+ emitcode ("lcall", "__gptrput");
+ break;
+ }
/* if we r done */
- if ( SPEC_BLEN(etype) <= 8 )
- return ;
+ if (SPEC_BLEN (etype) <= 8)
+ return;
- emitcode("inc","%s",rname);
- rLen = SPEC_BLEN(etype) ;
+ emitcode ("inc", "%s", rname);
+ rLen = SPEC_BLEN (etype);
/* now generate for lengths greater than one byte */
- while (1) {
-
- l = aopGet(AOP(right),offset++);
-
- rLen -= 8 ;
- if (rLen <= 0 )
- break ;
+ while (1)
+ {
- switch (p_type) {
- case POINTER:
- if (*l == '@') {
- MOVA(l);
- emitcode("mov","@%s,a",rname);
- } else
- emitcode("mov","@%s,%s",rname,l);
- break;
+ l = aopGet (AOP (right), offset++);
+
+ rLen -= 8;
+ if (rLen <= 0)
+ break;
+
+ switch (p_type)
+ {
+ case POINTER:
+ if (*l == '@')
+ {
+ MOVA (l);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, l);
+ break;
+
+ case FPOINTER:
+ MOVA (l);
+ emitcode ("movx", "@dptr,a");
+ break;
+
+ case GPOINTER:
+ MOVA (l);
+ emitcode ("lcall", "__gptrput");
+ break;
+ }
+ emitcode ("inc", "%s", rname);
+ }
- case FPOINTER:
- MOVA(l);
- emitcode("movx","@dptr,a");
- break;
+ MOVA (l);
- case GPOINTER:
- MOVA(l);
- emitcode("lcall","__gptrput");
- break;
+ /* last last was not complete */
+ if (rLen)
+ {
+ /* save the byte & read byte */
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
+
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
+
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
+
+ emitcode ("anl", "a,#0x%02x", ((unsigned char) -1 << -rLen));
+ emitcode ("orl", "a,b");
}
- emitcode ("inc","%s",rname);
- }
- MOVA(l);
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+
+ switch (p_type)
+ {
- /* last last was not complete */
- if (rLen) {
- /* save the byte & read byte */
- switch (p_type) {
case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
+ emitcode ("mov", "@%s,a", rname);
break;
case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
+ emitcode ("movx", "@dptr,a");
break;
case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
+ emitcode ("lcall", "__gptrput");
break;
}
-
- emitcode ("anl","a,#0x%02x",((unsigned char)-1 << -rLen) );
- emitcode ("orl","a,b");
- }
-
- if (p_type == GPOINTER)
- emitcode("pop","b");
-
- switch (p_type) {
-
- case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
-
- case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
-
- case GPOINTER:
- emitcode("lcall","__gptrput");
- break;
- }
}
/*-----------------------------------------------------------------*/
/* genDataPointerSet - remat pointer to data space */
/*-----------------------------------------------------------------*/
-static void genDataPointerSet(operand *right,
- operand *result,
- iCode *ic)
+static void
+genDataPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
- int size, offset = 0 ;
+ int size, offset = 0;
char *l, buffer[256];
- aopOp(right,ic,FALSE);
-
- l = aopGet(AOP(result),0);
- size = AOP_SIZE(right);
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l+1,offset);
- else
- sprintf(buffer,"%s",l+1);
- emitcode("mov","%s,%s",buffer,
- aopGet(AOP(right),offset++));
- }
+ aopOp (right, ic, FALSE);
+
+ l = aopGet (AOP (result), 0);
+ size = AOP_SIZE (right);
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l + 1, offset);
+ else
+ sprintf (buffer, "%s", l + 1);
+ emitcode ("mov", "%s,%s", buffer,
+ aopGet (AOP (right), offset++));
+ }
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerSet - emitcode for near pointer put */
/*-----------------------------------------------------------------*/
-static void genNearPointerSet (operand *right,
- operand *result,
- iCode *ic)
+static void
+genNearPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname , *l;
+ regs *preg = NULL;
+ char *rname, *l;
sym_link *retype;
- sym_link *ptype = operandType(result);
+ sym_link *ptype = operandType (result);
- retype= getSpec(operandType(right));
+ retype = getSpec (operandType (right));
- aopOp(result,ic,FALSE);
+ aopOp (result, ic, FALSE);
/* if the result is rematerializable &
in data space & not a bit variable */
- if (AOP_TYPE(result) == AOP_IMMD &&
- DCL_TYPE(ptype) == POINTER &&
- !IS_BITVAR(retype)) {
- genDataPointerSet (right,result,ic);
- return;
- }
+ if (AOP_TYPE (result) == AOP_IMMD &&
+ DCL_TYPE (ptype) == POINTER &&
+ !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))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE,0);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(result),0));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(result),0);
-
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE);
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE, 0);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0));
+ rname = preg->name;
+ }
+ else
+ rname = aopGet (AOP (result), 0);
+
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genPackBits (retype,right,rname,POINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
-
- while (size--) {
- l = aopGet(AOP(right),offset);
- if (*l == '@' ) {
- MOVA(l);
- emitcode("mov","@%s,a",rname);
- } else
- emitcode("mov","@%s,%s",rname,l);
- if (size)
- emitcode("inc","%s",rname);
- offset++;
+ if (IS_BITVAR (retype))
+ genPackBits (retype, right, rname, POINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
+
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset);
+ if (*l == '@')
+ {
+ MOVA (l);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, l);
+ if (size)
+ emitcode ("inc", "%s", rname);
+ offset++;
+ }
}
- }
/* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(right) - 1;
- while (size--)
- emitcode("dec","%s",rname);
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- }
/* done */
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerSet - emitcode for Paged pointer put */
/*-----------------------------------------------------------------*/
-static void genPagedPointerSet (operand *right,
- operand *result,
- iCode *ic)
+static void
+genPagedPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname , *l;
+ regs *preg = NULL;
+ char *rname, *l;
sym_link *retype;
- retype= getSpec(operandType(right));
+ retype = getSpec (operandType (right));
- aopOp(result,ic,FALSE);
+ aopOp (result, ic, FALSE);
/* if the value is already in a pointer register
then don't need anything more */
- if (!AOP_INPREG(AOP(result))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE,0);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(result),0));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(result),0);
-
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE);
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE, 0);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0));
+ rname = preg->name;
+ }
+ else
+ rname = aopGet (AOP (result), 0);
+
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genPackBits (retype,right,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
+ if (IS_BITVAR (retype))
+ genPackBits (retype, right, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
- while (size--) {
- l = aopGet(AOP(right),offset);
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset);
- MOVA(l);
- emitcode("movx","@%s,a",rname);
+ MOVA (l);
+ emitcode ("movx", "@%s,a", rname);
- if (size)
- emitcode("inc","%s",rname);
+ if (size)
+ emitcode ("inc", "%s", rname);
- offset++;
+ offset++;
+ }
}
- }
/* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(right) - 1;
- while (size--)
- emitcode("dec","%s",rname);
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- }
/* done */
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerSet - set value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerSet (operand *right,
- operand *result, iCode *ic)
+static void
+genFarPointerSet (operand * right,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
- aopOp(result,ic,FALSE);
+ aopOp (result, ic, FALSE);
/* if the operand is already in dptr
then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(result),0));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(result),0));
- emitcode("mov","dph,%s",aopGet(AOP(result),1));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(result),2));
- }
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0));
+ emitcode ("mov", "dph,%s", aopGet (AOP (result), 1));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2));
+ }
+ }
}
- }
/* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE);
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
- genPackBits(retype,right,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
-
- while (size--) {
- char *l = aopGet(AOP(right),offset++);
- MOVA(l);
- emitcode("movx","@dptr,a");
- if (size)
- emitcode("inc","dptr");
+ if (IS_BITVAR (retype))
+ genPackBits (retype, right, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
+
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset++);
+ MOVA (l);
+ emitcode ("movx", "@dptr,a");
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- }
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerSet - set value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerSet (operand *right,
- operand *result, iCode *ic)
+static void
+genGenPointerSet (operand * right,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
- aopOp(result,ic,FALSE);
+ aopOp (result, ic, FALSE);
/* if the operand is already in dptr
then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(result),0));
- emitcode("mov","b,%s + 1",aopGet(AOP(result),0));
- }
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(result),0));
- emitcode("mov","dph,%s",aopGet(AOP(result),1));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(result),2));
- emitcode("mov","b,%s",aopGet(AOP(result),3));
- }
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0));
+ emitcode ("mov", "b,%s + 1", aopGet (AOP (result), 0));
+ }
else
- {
- emitcode("mov","b,%s",aopGet(AOP(result),2));
- }
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0));
+ emitcode ("mov", "dph,%s", aopGet (AOP (result), 1));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2));
+ emitcode ("mov", "b,%s", aopGet (AOP (result), 3));
+ }
+ else
+ {
+ emitcode ("mov", "b,%s", aopGet (AOP (result), 2));
+ }
+ }
}
- }
/* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE);
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
- genPackBits(retype,right,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
-
- while (size--) {
- char *l = aopGet(AOP(right),offset++);
- MOVA(l);
- emitcode("lcall","__gptrput");
- if (size)
- emitcode("inc","dptr");
+ if (IS_BITVAR (retype))
+ genPackBits (retype, right, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
+
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset++);
+ MOVA (l);
+ emitcode ("lcall", "__gptrput");
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- }
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
-static void genPointerSet (iCode *ic)
+static void
+genPointerSet (iCode * ic)
{
- operand *right, *result ;
+ operand *right, *result;
sym_link *type, *etype;
int p_type;
- right = IC_RIGHT(ic);
- result = IC_RESULT(ic) ;
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
/* depending on the type of pointer we need to
move it to the correct pointer register */
- type = operandType(result);
- etype = getSpec(type);
+ type = operandType (result);
+ etype = getSpec (type);
/* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next)) {
- p_type = DCL_TYPE(type);
- }
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
-
- /* if (SPEC_OCLS(etype)->codesp ) { */
- /* p_type = CPOINTER ; */
- /* } */
- /* else */
- /* if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) */
- /* p_type = FPOINTER ; */
- /* else */
- /* if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) */
- /* p_type = PPOINTER ; */
- /* else */
- /* if (SPEC_OCLS(etype) == idata ) */
- /* p_type = IPOINTER ; */
- /* else */
- /* p_type = POINTER ; */
- }
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ {
+ p_type = DCL_TYPE (type);
+ }
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
+
+ /* if (SPEC_OCLS(etype)->codesp ) { */
+ /* p_type = CPOINTER ; */
+ /* } */
+ /* else */
+ /* if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) */
+ /* p_type = FPOINTER ; */
+ /* else */
+ /* if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) */
+ /* p_type = PPOINTER ; */
+ /* else */
+ /* if (SPEC_OCLS(etype) == idata ) */
+ /* p_type = IPOINTER ; */
+ /* else */
+ /* p_type = POINTER ; */
+ }
/* now that we have the pointer type we assign
the pointer values */
- switch (p_type) {
+ switch (p_type)
+ {
- case POINTER:
- case IPOINTER:
- genNearPointerSet (right,result,ic);
- break;
+ case POINTER:
+ case IPOINTER:
+ genNearPointerSet (right, result, ic);
+ break;
- case PPOINTER:
- genPagedPointerSet (right,result,ic);
- break;
+ case PPOINTER:
+ genPagedPointerSet (right, result, ic);
+ break;
- case FPOINTER:
- genFarPointerSet (right,result,ic);
- break;
+ case FPOINTER:
+ genFarPointerSet (right, result, ic);
+ break;
- case GPOINTER:
- genGenPointerSet (right,result,ic);
- break;
- }
+ case GPOINTER:
+ genGenPointerSet (right, result, ic);
+ break;
+ }
}
/*-----------------------------------------------------------------*/
/* genIfx - generate code for Ifx statement */
/*-----------------------------------------------------------------*/
-static void genIfx (iCode *ic, iCode *popIc)
+static void
+genIfx (iCode * ic, iCode * popIc)
{
- operand *cond = IC_COND(ic);
- int isbit =0;
+ operand *cond = IC_COND (ic);
+ int isbit = 0;
- aopOp(cond,ic,FALSE);
+ aopOp (cond, ic, FALSE);
/* get the value into acc */
- if (AOP_TYPE(cond) != AOP_CRY)
- toBoolean(cond,"",0);
+ if (AOP_TYPE (cond) != AOP_CRY)
+ toBoolean (cond, "", 0);
else
isbit = 1;
/* the result is now in the accumulator */
- freeAsmop(cond,NULL,ic,TRUE);
+ freeAsmop (cond, NULL, ic, TRUE);
/* if there was something to be popped then do it */
if (popIc)
- genIpop(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"); */
-
- ic->generated = 1;
+ /* } */
+ /* else */
+ /* if (isbit && !IS_ITEMP(cond)) */
+ /* // genIfxJump(ic,OP_SYMBOL(cond)->rname); */
+ /* else */
+ /* // genIfxJump(ic,"a"); */
+
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAddrOf - generates code for address of */
/*-----------------------------------------------------------------*/
-static void genAddrOf (iCode *ic)
+static void
+genAddrOf (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
- int size, offset ;
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+ int size, offset;
- aopOp(IC_RESULT(ic),ic,FALSE);
+ aopOp (IC_RESULT (ic), ic, FALSE);
/* if the operand is on the stack then we
need to get the stack offset of this
variable */
- if (sym->onStack) {
- /* if it has an offset then we need to compute
- it */
- if (sym->stack) {
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",((char) sym->stack & 0xff));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- } else {
- /* we can just move _bp */
- 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");
- }
+ if (sym->onStack)
+ {
+ /* if it has an offset then we need to compute
+ it */
+ if (sym->stack)
+ {
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ }
+ else
+ {
+ /* we can just move _bp */
+ aopPut (AOP (IC_RESULT (ic)), "_bp", 0);
+ }
+ /* fill the result with zero */
+ size = AOP_SIZE (IC_RESULT (ic)) - 1;
- offset = 1;
- while (size--)
- {
- /* Yuck! */
- if (options.stack10bit && offset == 2)
- {
- aopPut(AOP(IC_RESULT(ic)),"#0x40", offset++);
- }
- else
- {
- aopPut(AOP(IC_RESULT(ic)),zero,offset++);
- }
- }
- goto release;
- }
+ if (options.stack10bit && size < (FPTRSIZE - 1))
+ {
+ fprintf (stderr,
+ "*** warning: pointer to stack var truncated.\n");
+ }
+
+ offset = 1;
+ while (size--)
+ {
+ /* Yuck! */
+ if (options.stack10bit && offset == 2)
+ {
+ aopPut (AOP (IC_RESULT (ic)), "#0x40", offset++);
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), zero, offset++);
+ }
+ }
+
+ goto release;
+ }
/* object not on stack then we need the name */
- size = AOP_SIZE(IC_RESULT(ic));
+ size = AOP_SIZE (IC_RESULT (ic));
offset = 0;
- while (size--) {
- char s[SDCC_NAME_MAX];
- if (offset)
- sprintf(s,"#(%s >> %d)",
- sym->rname,
- offset*8);
- else
- sprintf(s,"#%s",sym->rname);
- aopPut(AOP(IC_RESULT(ic)),s,offset++);
- }
+ while (size--)
+ {
+ char s[SDCC_NAME_MAX];
+ if (offset)
+ sprintf (s, "#(%s >> %d)",
+ sym->rname,
+ offset * 8);
+ else
+ sprintf (s, "#%s", sym->rname);
+ aopPut (AOP (IC_RESULT (ic)), s, offset++);
+ }
- release:
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+release:
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarFarAssign - assignment when both are in far space */
/*-----------------------------------------------------------------*/
-static void genFarFarAssign (operand *result, operand *right, iCode *ic)
+static void
+genFarFarAssign (operand * result, operand * right, iCode * ic)
{
- int size = AOP_SIZE(right);
+ int size = AOP_SIZE (right);
int offset = 0;
- char *l ;
+ char *l;
/* first push the right side on to the stack */
- while (size--) {
- l = aopGet(AOP(right),offset++);
- MOVA(l);
- emitcode ("push","acc");
- }
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset++);
+ MOVA (l);
+ emitcode ("push", "acc");
+ }
- freeAsmop(right,NULL,ic,FALSE);
+ freeAsmop (right, NULL, ic, FALSE);
/* now assign DPTR to result */
- aopOp(result,ic,FALSE);
- size = AOP_SIZE(result);
- while (size--) {
- emitcode ("pop","acc");
- aopPut(AOP(result),"a",--offset);
- }
- freeAsmop(result,NULL,ic,FALSE);
+ aopOp (result, ic, FALSE);
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ emitcode ("pop", "acc");
+ aopPut (AOP (result), "a", --offset);
+ }
+ freeAsmop (result, NULL, ic, FALSE);
}
/*-----------------------------------------------------------------*/
/* genAssign - generate code for assignment */
/*-----------------------------------------------------------------*/
-static void genAssign (iCode *ic)
+static void
+genAssign (iCode * ic)
{
operand *result, *right;
- int size, offset ;
+ int size, offset;
unsigned long lit = 0L;
- result = IC_RESULT(ic);
- right = IC_RIGHT(ic) ;
+ result = IC_RESULT (ic);
+ right = IC_RIGHT (ic);
/* if they are the same */
- if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
- aopOp(right,ic,FALSE);
+ aopOp (right, ic, FALSE);
/* special case both in far space */
- if (AOP_TYPE(right) == AOP_DPTR &&
- IS_TRUE_SYMOP(result) &&
- isOperandInFarSpace(result)) {
+ if (AOP_TYPE (right) == AOP_DPTR &&
+ IS_TRUE_SYMOP (result) &&
+ isOperandInFarSpace (result))
+ {
- genFarFarAssign (result,right,ic);
- return ;
- }
+ genFarFarAssign (result, right, ic);
+ return;
+ }
- aopOp(result,ic,TRUE);
+ aopOp (result, ic, TRUE);
/* if they are the same registers */
- if (sameRegs(AOP(right),AOP(result)))
+ if (sameRegs (AOP (right), AOP (result)))
goto release;
/* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- if (((int) operandLitValue(right)))
- aopPut(AOP(result),one,0);
- else
- aopPut(AOP(result),zero,0);
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((int) operandLitValue (right)))
+ aopPut (AOP (result), one, 0);
+ else
+ aopPut (AOP (result), zero, 0);
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ aopPut (AOP (result), "c", 0);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right, "", 0);
+ aopPut (AOP (result), "a", 0);
goto release;
}
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- aopPut(AOP(result),"c",0);
- goto release ;
- }
-
- /* we need to or */
- toBoolean(right,"",0);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
/* bit variables done */
/* general case */
- size = AOP_SIZE(result);
- offset = 0 ;
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if((size > 1) &&
- (AOP_TYPE(result) != AOP_REG) &&
- (AOP_TYPE(right) == AOP_LIT) &&
- !IS_FLOAT(operandType(right)) &&
- (lit < 256L)){
- emitcode("clr","a");
- while (size--) {
- if((unsigned int)((lit >> (size*8)) & 0x0FFL)== 0)
- aopPut(AOP(result),"a",size);
- else
- aopPut(AOP(result),
- aopGet(AOP(right),size),
- size);
- }
- } else {
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset),
- offset);
- offset++;
+ size = AOP_SIZE (result);
+ offset = 0;
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ if ((size > 1) &&
+ (AOP_TYPE (result) != AOP_REG) &&
+ (AOP_TYPE (right) == AOP_LIT) &&
+ !IS_FLOAT (operandType (right)) &&
+ (lit < 256L))
+ {
+ emitcode ("clr", "a");
+ while (size--)
+ {
+ if ((unsigned int) ((lit >> (size * 8)) & 0x0FFL) == 0)
+ aopPut (AOP (result), "a", size);
+ else
+ aopPut (AOP (result),
+ aopGet (AOP (right), size),
+ size);
+ }
+ }
+ else
+ {
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset),
+ offset);
+ offset++;
+ }
}
- }
- release:
- freeAsmop (right,NULL,ic,FALSE);
- freeAsmop (result,NULL,ic,TRUE);
+release:
+ freeAsmop (right, NULL, ic, FALSE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genJumpTab - genrates code for jump table */
/*-----------------------------------------------------------------*/
-static void genJumpTab (iCode *ic)
+static void
+genJumpTab (iCode * ic)
{
symbol *jtab;
char *l;
- aopOp(IC_JTCOND(ic),ic,FALSE);
+ aopOp (IC_JTCOND (ic), ic, FALSE);
/* get the condition into accumulator */
- l = aopGet(AOP(IC_JTCOND(ic)),0);
- MOVA(l);
+ l = aopGet (AOP (IC_JTCOND (ic)), 0);
+ MOVA (l);
/* multiply by three */
- emitcode("add","a,acc");
- emitcode("add","a,%s",aopGet(AOP(IC_JTCOND(ic)),0));
- freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
-
- jtab = newiTempLabel(NULL);
- emitcode("mov","dptr,#%05d$",jtab->key+100);
- emitcode("jmp","@a+dptr");
- emitcode("","%05d$:",jtab->key+100);
+ emitcode ("add", "a,acc");
+ emitcode ("add", "a,%s", aopGet (AOP (IC_JTCOND (ic)), 0));
+ freeAsmop (IC_JTCOND (ic), NULL, ic, TRUE);
+
+ jtab = newiTempLabel (NULL);
+ emitcode ("mov", "dptr,#%05d$", jtab->key + 100);
+ emitcode ("jmp", "@a+dptr");
+ emitcode ("", "%05d$:", jtab->key + 100);
/* now generate the jump labels */
- for (jtab = setFirstItem(IC_JTLABELS(ic)) ; jtab;
- jtab = setNextItem(IC_JTLABELS(ic)))
- emitcode("ljmp","%05d$",jtab->key+100);
+ for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
+ jtab = setNextItem (IC_JTLABELS (ic)))
+ emitcode ("ljmp", "%05d$", jtab->key + 100);
}
/*-----------------------------------------------------------------*/
/* genCast - gen code for casting */
/*-----------------------------------------------------------------*/
-static void genCast (iCode *ic)
+static void
+genCast (iCode * ic)
{
- operand *result = IC_RESULT(ic);
- sym_link *ctype = operandType(IC_LEFT(ic));
- sym_link *rtype = operandType(IC_RIGHT(ic));
- operand *right = IC_RIGHT(ic);
- int size, offset ;
+ operand *result = IC_RESULT (ic);
+ sym_link *ctype = operandType (IC_LEFT (ic));
+ sym_link *rtype = operandType (IC_RIGHT (ic));
+ operand *right = IC_RIGHT (ic);
+ int size, offset;
/* if they are equivalent then do nothing */
- if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
- aopOp(right,ic,FALSE) ;
- aopOp(result,ic,FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, FALSE);
/* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- if (((int) operandLitValue(right)))
- aopPut(AOP(result),one,0);
- else
- aopPut(AOP(result),zero,0);
-
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((int) operandLitValue (right)))
+ aopPut (AOP (result), one, 0);
+ else
+ aopPut (AOP (result), zero, 0);
+
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ aopPut (AOP (result), "c", 0);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right, "", 0);
+ aopPut (AOP (result), "a", 0);
goto release;
}
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- aopPut(AOP(result),"c",0);
- goto release ;
- }
-
- /* we need to or */
- toBoolean(right,"",0);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
/* if they are the same size : or less */
- if (AOP_SIZE(result) <= AOP_SIZE(right)) {
+ if (AOP_SIZE (result) <= AOP_SIZE (right))
+ {
- /* if they are in the same place */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
+ /* if they are in the same place */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
- /* if they in different places then copy */
- size = AOP_SIZE(result);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset),
- offset);
- offset++;
+ /* if they in different places then copy */
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset),
+ offset);
+ offset++;
+ }
+ goto release;
}
- goto release;
- }
/* if the result is of type pointer */
- if (IS_PTR(ctype)) {
-
- int p_type;
- sym_link *type = operandType(right);
- sym_link *etype = getSpec(type);
-
- /* pointer to generic pointer */
- if (IS_GENPTR(ctype)) {
- char *l = zero;
-
- if (IS_PTR(type))
- p_type = DCL_TYPE(type);
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
- }
-
- /* the first two bytes are known */
- size = GPTRSIZE - 1;
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset),
- offset);
- offset++;
- }
- /* the last byte depending on type */
- switch (p_type) {
- case IPOINTER:
- case POINTER:
- l = zero;
- break;
- case FPOINTER:
- l = one;
- break;
- case CPOINTER:
- l = "#0x02";
- break;
- case PPOINTER:
- l = "#0x03";
- break;
-
- default:
- /* this should never happen */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got unknown pointer type");
- exit(1);
- }
- aopPut(AOP(result),l, GPTRSIZE - 1);
- goto release ;
- }
+ if (IS_PTR (ctype))
+ {
- /* just copy the pointers */
- size = AOP_SIZE(result);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset),
- offset);
- offset++;
+ int p_type;
+ sym_link *type = operandType (right);
+ sym_link *etype = getSpec (type);
+
+ /* pointer to generic pointer */
+ if (IS_GENPTR (ctype))
+ {
+ char *l = zero;
+
+ if (IS_PTR (type))
+ p_type = DCL_TYPE (type);
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
+ }
+
+ /* the first two bytes are known */
+ size = GPTRSIZE - 1;
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset),
+ offset);
+ offset++;
+ }
+ /* the last byte depending on type */
+ switch (p_type)
+ {
+ case IPOINTER:
+ case POINTER:
+ l = zero;
+ break;
+ case FPOINTER:
+ l = one;
+ break;
+ case CPOINTER:
+ l = "#0x02";
+ break;
+ case PPOINTER:
+ l = "#0x03";
+ break;
+
+ default:
+ /* this should never happen */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got unknown pointer type");
+ exit (1);
+ }
+ aopPut (AOP (result), l, GPTRSIZE - 1);
+ goto release;
+ }
+
+ /* just copy the pointers */
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset),
+ offset);
+ offset++;
+ }
+ goto release;
}
- goto release ;
- }
/* so we now know that the size of destination is greater
than the size of the source */
/* we move to result for the size of source */
- size = AOP_SIZE(right);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset),
- offset);
- offset++;
- }
+ size = AOP_SIZE (right);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset),
+ offset);
+ offset++;
+ }
/* now depending on the sign of the source && destination */
- size = AOP_SIZE(result) - AOP_SIZE(right);
+ size = AOP_SIZE (result) - AOP_SIZE (right);
/* if unsigned or not an integral type */
- if (SPEC_USIGN(rtype) || !IS_SPEC(rtype)) {
- while (size--)
- aopPut(AOP(result),zero,offset++);
- } else {
- /* we need to extend the sign :{ */
- char *l = aopGet(AOP(right),AOP_SIZE(right) - 1);
- MOVA(l);
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- while (size--)
- aopPut(AOP(result),"a",offset++);
- }
+ if (SPEC_USIGN (rtype) || !IS_SPEC (rtype))
+ {
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ }
+ else
+ {
+ /* we need to extend the sign :{ */
+ char *l = aopGet (AOP (right), AOP_SIZE (right) - 1);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
+ }
/* we are done hurray !!!! */
- release:
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDjnz - generate decrement & jump if not zero instrucion */
/*-----------------------------------------------------------------*/
-static int genDjnz (iCode *ic, iCode *ifx)
+static int
+genDjnz (iCode * ic, iCode * ifx)
{
symbol *lbl, *lbl1;
if (!ifx)
/* if the if condition has a false label
then we cannot save */
- if (IC_FALSE(ifx))
+ if (IC_FALSE (ifx))
return 0;
/* if the minus is not of the form
a = a - 1 */
- if (!isOperandEqual(IC_RESULT(ic),IC_LEFT(ic)) ||
- !IS_OP_LITERAL(IC_RIGHT(ic)))
+ if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
+ !IS_OP_LITERAL (IC_RIGHT (ic)))
return 0;
- if (operandLitValue(IC_RIGHT(ic)) != 1)
+ if (operandLitValue (IC_RIGHT (ic)) != 1)
return 0;
/* if the size of this greater than one then no
saving */
- if (getSize(operandType(IC_RESULT(ic))) > 1)
+ if (getSize (operandType (IC_RESULT (ic))) > 1)
return 0;
/* otherwise we can save BIG */
- lbl = newiTempLabel(NULL);
- lbl1= newiTempLabel(NULL);
-
- aopOp(IC_RESULT(ic),ic,FALSE);
-
- if (IS_AOP_PREG(IC_RESULT(ic))) {
- emitcode("dec","%s",
- aopGet(AOP(IC_RESULT(ic)),0));
- emitcode("mov","a,%s",aopGet(AOP(IC_RESULT(ic)),0));
- emitcode("jnz","%05d$",lbl->key+100);
- } else {
- emitcode ("djnz","%s,%05d$",aopGet(AOP(IC_RESULT(ic)),0),
- lbl->key+100);
- }
- emitcode ("sjmp","%05d$",lbl1->key+100);
- emitcode ("","%05d$:",lbl->key+100);
- emitcode ("ljmp","%05d$",IC_TRUE(ifx)->key+100);
- emitcode ("","%05d$:",lbl1->key+100);
+ lbl = newiTempLabel (NULL);
+ lbl1 = newiTempLabel (NULL);
+
+ aopOp (IC_RESULT (ic), ic, FALSE);
+
+ if (IS_AOP_PREG (IC_RESULT (ic)))
+ {
+ emitcode ("dec", "%s",
+ aopGet (AOP (IC_RESULT (ic)), 0));
+ emitcode ("mov", "a,%s", aopGet (AOP (IC_RESULT (ic)), 0));
+ emitcode ("jnz", "%05d$", lbl->key + 100);
+ }
+ else
+ {
+ emitcode ("djnz", "%s,%05d$", aopGet (AOP (IC_RESULT (ic)), 0),
+ lbl->key + 100);
+ }
+ emitcode ("sjmp", "%05d$", lbl1->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
+ emitcode ("", "%05d$:", lbl1->key + 100);
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
ifx->generated = 1;
return 1;
}
static char *recvregs[8] =
{
- "r16","r17","r18","r19","r20","r21","r22","r23"
+ "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23"
};
static recvCnt = 0;
/*-----------------------------------------------------------------*/
/* genReceive - generate code for a receive iCode */
/*-----------------------------------------------------------------*/
-static void genReceive (iCode *ic)
+static void
+genReceive (iCode * ic)
{
- int size , offset =0;
- aopOp(IC_RESULT(ic),ic,FALSE);
- size = AOP_SIZE(IC_RESULT(ic));
- while (size--) {
- aopPut(AOP(IC_RESULT(ic)),recvregs[recvCnt++],offset);
- offset++;
- }
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ int size, offset = 0;
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_RESULT (ic));
+ while (size--)
+ {
+ aopPut (AOP (IC_RESULT (ic)), recvregs[recvCnt++], offset);
+ offset++;
+ }
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* gen51Code - generate code for 8051 based controllers */
/*-----------------------------------------------------------------*/
-void genAVRCode (iCode *lic)
+void
+genAVRCode (iCode * lic)
{
iCode *ic;
int cln = 0;
lineHead = lineCurr = NULL;
- recvCnt =0;
+ recvCnt = 0;
/* print the allocation information */
if (allocInfo)
- printAllocInfo( currFunc, codeOutFile);
+ printAllocInfo (currFunc, codeOutFile);
/* if debug information required */
/* if (options.debug && currFunc) { */
- if (currFunc) {
- cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
- _G.debugLine = 1;
- if (IS_STATIC(currFunc->etype))
- emitcode("","F%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","G$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
+ if (currFunc)
+ {
+ cdbSymbol (currFunc, cdbFile, FALSE, TRUE);
+ _G.debugLine = 1;
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode ("", "G$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
/* stack pointer name */
if (options.useXstack)
spname = "_spx";
spname = "sp";
- for (ic = lic ; ic ; ic = ic->next ) {
-
- if ( cln != ic->lineno ) {
- if ( options.debug ) {
- _G.debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),ic->lineno,
- ic->level,ic->block);
- _G.debugLine = 0;
- }
- emitcode(";","%s %d",ic->filename,ic->lineno);
- cln = ic->lineno ;
- }
- /* if the result is marked as
- spilt and rematerializable or code for
- this has already been generated then
- do nothing */
- if (resultRemat(ic) || ic->generated )
- continue ;
-
- /* depending on the operation */
- switch (ic->op) {
- case '!' :
- genNot(ic);
- break;
-
- case '~' :
- genCpl(ic);
- break;
-
- case UNARYMINUS:
- genUminus (ic);
- break;
-
- case IPUSH:
- genIpush (ic);
- break;
-
- case IPOP:
- /* IPOP happens only when trying to restore a
- spilt live range, if there is an ifx statement
- following this pop then the if statement might
- be using some of the registers being popped which
- would destory the contents of the register so
- we need to check for this condition and handle it */
- if (ic->next &&
- ic->next->op == IFX &&
- regsInCommon(IC_LEFT(ic),IC_COND(ic->next)))
- genIfx (ic->next,ic);
- else
- genIpop (ic);
- break;
-
- case CALL:
- genCall (ic);
- break;
-
- case PCALL:
- genPcall (ic);
- break;
-
- case FUNCTION:
- genFunction (ic);
- break;
-
- case ENDFUNCTION:
- genEndFunction (ic);
- break;
-
- case RETURN:
- genRet (ic);
- break;
-
- case LABEL:
- genLabel (ic);
- break;
-
- case GOTO:
- genGoto (ic);
- break;
-
- case '+' :
- genPlus (ic) ;
- break;
-
- case '-' :
- if ( ! genDjnz (ic,ifxForOp(IC_RESULT(ic),ic)))
- genMinus (ic);
- break;
-
- case '*' :
- genMult (ic);
- break;
-
- case '/' :
- genDiv (ic) ;
- break;
-
- case '%' :
- genMod (ic);
- break;
-
- case '>' :
- genCmpGt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case '<' :
- genCmpLt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case LE_OP:
- genCmpLe (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case GE_OP:
- genCmpGe (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case NE_OP:
- genCmpNe (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case EQ_OP:
- genCmpEq (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case AND_OP:
- genAndOp (ic);
- break;
-
- case OR_OP:
- genOrOp (ic);
- break;
-
- case '^' :
- genXor (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case '|' :
- genOr (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case BITWISEAND:
- genAnd (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case INLINEASM:
- genInline (ic);
- break;
-
- case RRC:
- genRRC (ic);
- break;
-
- case RLC:
- genRLC (ic);
- break;
-
- case GETHBIT:
- genGetHbit (ic);
- break;
-
- case LEFT_OP:
- genLeftShift (ic);
- break;
-
- case RIGHT_OP:
- genRightShift (ic);
- break;
-
- case GET_VALUE_AT_ADDRESS:
- genPointerGet(ic);
- break;
+ for (ic = lic; ic; ic = ic->next)
+ {
- case '=' :
- if (POINTER_SET(ic))
- genPointerSet(ic);
- else
- genAssign(ic);
- break;
+ if (cln != ic->lineno)
+ {
+ if (options.debug)
+ {
+ _G.debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), ic->lineno,
+ ic->level, ic->block);
+ _G.debugLine = 0;
+ }
+ emitcode (";", "%s %d", ic->filename, ic->lineno);
+ cln = ic->lineno;
+ }
+ /* if the result is marked as
+ spilt and rematerializable or code for
+ this has already been generated then
+ do nothing */
+ if (resultRemat (ic) || ic->generated)
+ continue;
+
+ /* depending on the operation */
+ switch (ic->op)
+ {
+ case '!':
+ genNot (ic);
+ break;
+
+ case '~':
+ genCpl (ic);
+ break;
+
+ case UNARYMINUS:
+ genUminus (ic);
+ break;
+
+ case IPUSH:
+ genIpush (ic);
+ break;
+
+ case IPOP:
+ /* IPOP happens only when trying to restore a
+ spilt live range, if there is an ifx statement
+ following this pop then the if statement might
+ be using some of the registers being popped which
+ would destory the contents of the register so
+ we need to check for this condition and handle it */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
+ genIfx (ic->next, ic);
+ else
+ genIpop (ic);
+ break;
+
+ case CALL:
+ genCall (ic);
+ break;
+
+ case PCALL:
+ genPcall (ic);
+ break;
+
+ case FUNCTION:
+ genFunction (ic);
+ break;
+
+ case ENDFUNCTION:
+ genEndFunction (ic);
+ break;
+
+ case RETURN:
+ genRet (ic);
+ break;
+
+ case LABEL:
+ genLabel (ic);
+ break;
+
+ case GOTO:
+ genGoto (ic);
+ break;
+
+ case '+':
+ genPlus (ic);
+ break;
+
+ case '-':
+ if (!genDjnz (ic, ifxForOp (IC_RESULT (ic), ic)))
+ genMinus (ic);
+ break;
+
+ case '*':
+ genMult (ic);
+ break;
+
+ case '/':
+ genDiv (ic);
+ break;
+
+ case '%':
+ genMod (ic);
+ break;
+
+ case '>':
+ genCmpGt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '<':
+ genCmpLt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case LE_OP:
+ genCmpLe (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case GE_OP:
+ genCmpGe (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case NE_OP:
+ genCmpNe (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case EQ_OP:
+ genCmpEq (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case AND_OP:
+ genAndOp (ic);
+ break;
+
+ case OR_OP:
+ genOrOp (ic);
+ break;
+
+ case '^':
+ genXor (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '|':
+ genOr (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case BITWISEAND:
+ genAnd (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case INLINEASM:
+ genInline (ic);
+ break;
+
+ case RRC:
+ genRRC (ic);
+ break;
+
+ case RLC:
+ genRLC (ic);
+ break;
+
+ case GETHBIT:
+ genGetHbit (ic);
+ break;
+
+ case LEFT_OP:
+ genLeftShift (ic);
+ break;
+
+ case RIGHT_OP:
+ genRightShift (ic);
+ break;
+
+ case GET_VALUE_AT_ADDRESS:
+ genPointerGet (ic);
+ break;
+
+ case '=':
+ if (POINTER_SET (ic))
+ genPointerSet (ic);
+ else
+ genAssign (ic);
+ break;
- case IFX:
- genIfx (ic,NULL);
- break;
+ case IFX:
+ genIfx (ic, NULL);
+ break;
- case ADDRESS_OF:
- genAddrOf (ic);
- break;
+ case ADDRESS_OF:
+ genAddrOf (ic);
+ break;
- case JUMPTABLE:
- genJumpTab (ic);
- break;
+ case JUMPTABLE:
+ genJumpTab (ic);
+ break;
- case CAST:
- genCast (ic);
- break;
+ case CAST:
+ genCast (ic);
+ break;
- case RECEIVE:
- genReceive(ic);
- break;
+ case RECEIVE:
+ genReceive (ic);
+ break;
- case SEND:
- addSet(&_G.sendSet,ic);
- break;
+ case SEND:
+ addSet (&_G.sendSet, ic);
+ break;
- default :
- ic = ic;
- /* piCode(ic,stdout); */
+ default:
+ ic = ic;
+ /* piCode(ic,stdout); */
+ }
}
- }
/* now we are ready to call the
peepHole (&lineHead);
/* now do the actual printing */
- printLine (lineHead,codeOutFile);
+ printLine (lineHead, codeOutFile);
return;
}
#ifndef SDCCGEN51_H
#define SDCCGEN51_H
-enum {
+enum
+ {
AOP_LIT = 1,
- AOP_REG, AOP_DIR,
- AOP_DPTR,AOP_X,AOP_Z,
- AOP_STK ,AOP_IMMD, AOP_STR,
- AOP_CRY, AOP_ACC , AOP_STK_D};
+ AOP_REG, AOP_DIR,
+ AOP_DPTR, AOP_X, AOP_Z,
+ AOP_STK, AOP_IMMD, AOP_STR,
+ AOP_CRY, AOP_ACC, AOP_STK_D
+ };
/* type asmop : a homogenised type for
all the different spaces an operand can be
in */
-typedef struct asmop {
-
- short type ; /* can have values
- AOP_LIT - operand is a literal value
- AOP_REG - is in registers
- AOP_DIR - direct just a name
- AOP_DPTR - dptr contains address of operand
- AOP_R0/R1 - r0/r1 contains address of operand
- AOP_STK - should be pushed on stack this
- can happen only for the result
- AOP_IMMD - immediate value for eg. remateriazable
- AOP_CRY - carry contains the value of this
- AOP_STR - array of strings
- AOP_ACC - result is in the acc:b pair
- */
- short coff ; /* current offset */
- short size ; /* total size */
- unsigned code :1 ; /* is in Code space */
- unsigned paged:1 ; /* in paged memory */
- unsigned freed:1 ; /* already freed */
- union {
- value *aop_lit ; /* if literal */
- regs *aop_reg[4]; /* array of registers */
- char *aop_dir ; /* if direct */
- regs *aop_ptr ; /* either -> R26 or R30 */
- char *aop_immd; /* if immediate others are implied */
- int aop_stk ; /* stack offset when AOP_STK */
- char *aop_str[4]; /* just a string array containing the location */
- } aopu;
- regs *aop_ptr2; /* either -> R27 or R31 */
-} asmop;
+typedef struct asmop
+ {
+
+ short type; /* can have values
+ AOP_LIT - operand is a literal value
+ AOP_REG - is in registers
+ AOP_DIR - direct just a name
+ AOP_DPTR - dptr contains address of operand
+ AOP_R0/R1 - r0/r1 contains address of operand
+ AOP_STK - should be pushed on stack this
+ can happen only for the result
+ AOP_IMMD - immediate value for eg. remateriazable
+ AOP_CRY - carry contains the value of this
+ AOP_STR - array of strings
+ AOP_ACC - result is in the acc:b pair
+ */
+ short coff; /* current offset */
+ short size; /* total size */
+ unsigned code:1; /* is in Code space */
+ unsigned paged:1; /* in paged memory */
+ unsigned freed:1; /* already freed */
+ union
+ {
+ value *aop_lit; /* if literal */
+ regs *aop_reg[4]; /* array of registers */
+ char *aop_dir; /* if direct */
+ regs *aop_ptr; /* either -> R26 or R30 */
+ char *aop_immd; /* if immediate others are implied */
+ int aop_stk; /* stack offset when AOP_STK */
+ char *aop_str[4]; /* just a string array containing the location */
+ }
+ aopu;
+ regs *aop_ptr2; /* either -> R27 or R31 */
+ }
+asmop;
void gen51Code (iCode *);
};
/* list of key words used by msc51 */
-static char *_avr_keywords[] = {
- "at",
- "code",
- "critical",
- "eeprom",
- "interrupt",
- "sfr",
- "xdata",
- "_code",
- "_eeprom",
- "_generic",
- "_xdata",
- "sram" ,
- "_sram",
- "flash",
- "_flash",
- NULL
+static char *_avr_keywords[] =
+{
+ "at",
+ "code",
+ "critical",
+ "eeprom",
+ "interrupt",
+ "sfr",
+ "xdata",
+ "_code",
+ "_eeprom",
+ "_generic",
+ "_xdata",
+ "sram",
+ "_sram",
+ "flash",
+ "_flash",
+ NULL
};
-static int regParmFlg = 0; /* determine if we can register a parameter */
+static int regParmFlg = 0; /* determine if we can register a parameter */
-static void _avr_init(void)
+static void
+_avr_init (void)
{
- asm_addTree(&asm_asxxxx_mapping);
+ asm_addTree (&asm_asxxxx_mapping);
}
-static void _avr_reset_regparm()
+static void
+_avr_reset_regparm ()
{
- regParmFlg = 0;
+ regParmFlg = 0;
}
-static int _avr_regparm( sym_link *l)
+static int
+_avr_regparm (sym_link * l)
{
- /* the first eight bytes will be passed in
- registers r16-r23. but we won't split variables
- i.e. if not enough registers left to hold
- the parameter then the whole parameter along
- with rest of the parameters go onto the stack */
- if (regParmFlg < 8 ) {
- int size ;
- if ((size = getSize(l)) > (8 - regParmFlg)) {
- /* all remaining go on stack */
- regParmFlg = 8;
- return 0;
+ /* the first eight bytes will be passed in
+ registers r16-r23. but we won't split variables
+ i.e. if not enough registers left to hold
+ the parameter then the whole parameter along
+ with rest of the parameters go onto the stack */
+ if (regParmFlg < 8)
+ {
+ int size;
+ if ((size = getSize (l)) > (8 - regParmFlg))
+ {
+ /* all remaining go on stack */
+ regParmFlg = 8;
+ return 0;
}
- regParmFlg += size;
- return 1;
+ regParmFlg += size;
+ return 1;
}
-
- return 0;
+
+ return 0;
}
-void avr_assignRegisters (eBBlock **ebbs, int count);
+void avr_assignRegisters (eBBlock ** ebbs, int count);
-static bool _avr_parseOptions(int *pargc, char **argv, int *i)
+static bool
+_avr_parseOptions (int *pargc, char **argv, int *i)
{
- /* TODO: allow port-specific command line options to specify
- * segment names here.
- */
- return FALSE;
+ /* TODO: allow port-specific command line options to specify
+ * segment names here.
+ */
+ return FALSE;
}
-static void _avr_finaliseOptions(void)
+static void
+_avr_finaliseOptions (void)
{
- port->mem.default_local_map =
- port->mem.default_globl_map = xdata;
- /* change stack to be in far space */
- /* internal stack segment ;
- SFRSPACE - NO
- FAR-SPACE - YES
- PAGED - NO
- DIRECT-ACCESS - NO
- BIT-ACCESS - NO
- CODE-ACESS - NO
- DEBUG-NAME - 'B'
- POINTER-TYPE - FPOINTER
- */
- istack = allocMap (0, 1, 0, 0, 0, 0,options.stack_loc, ISTACK_NAME,'B',FPOINTER);
-
- /* also change xdata to be direct space since we can use lds/sts */
- xdata->direct = 1;
+ port->mem.default_local_map =
+ port->mem.default_globl_map = xdata;
+ /* change stack to be in far space */
+ /* internal stack segment ;
+ SFRSPACE - NO
+ FAR-SPACE - YES
+ PAGED - NO
+ DIRECT-ACCESS - NO
+ BIT-ACCESS - NO
+ CODE-ACESS - NO
+ DEBUG-NAME - 'B'
+ POINTER-TYPE - FPOINTER
+ */
+ istack = allocMap (0, 1, 0, 0, 0, 0, options.stack_loc, ISTACK_NAME, 'B', FPOINTER);
+
+ /* also change xdata to be direct space since we can use lds/sts */
+ xdata->direct = 1;
}
-static void _avr_setDefaultOptions(void)
+static void
+_avr_setDefaultOptions (void)
{
- options.stackAuto = 1;
+ options.stackAuto = 1;
}
-static const char *_avr_getRegName(struct regs *reg)
+static const char *
+_avr_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- return "err";
+ if (reg)
+ return reg->name;
+ return "err";
}
-static void _avr_genAssemblerPreamble(FILE *of)
+static void
+_avr_genAssemblerPreamble (FILE * of)
{
}
/* Generate interrupt vector table. */
-static int _avr_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
+static int
+_avr_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
{
- return TRUE;
+ return TRUE;
}
/** $1 is always the basename.
$l is the list of extra options that should be there somewhere...
MUST be terminated with a NULL.
*/
-static const char *_linkCmd[] = {
- "aslink", "-nf", "$1", NULL
+static const char *_linkCmd[] =
+{
+ "aslink", "-nf", "$1", NULL
};
-static const char *_asmCmd[] = {
- "asx8051", "-plosgffc", "$1.asm", NULL
+static const char *_asmCmd[] =
+{
+ "asx8051", "-plosgffc", "$1.asm", NULL
};
/* Globals */
-PORT avr_port = {
- "avr",
- "ATMEL AVR", /* Target name */
- {
- TRUE, /* Emit glue around main */
- MODEL_LARGE | MODEL_SMALL,
- MODEL_SMALL
- },
- {
- _asmCmd,
- "-plosgffc", /* Options with debug */
- "-plosgff", /* Options without debug */
- 0
- },
- {
- _linkCmd,
- NULL,
- ".rel"
- },
- {
- _defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 1, 2, 4, 2, 2, 3, 1, 4, 4
- },
- {
- "XSEG (XDATA)",
- "STACK (DATA)",
- "CSEG (CODE)",
- "DSEG (DATA)",
- "ISEG (DATA)",
- "XSEG (XDATA)",
- "BSEG (BIT)",
- "RSEG (DATA)",
- "GSINIT (CODE)",
- "OSEG (OVR,DATA)",
- "GSFINAL (CODE)",
- "HOME (CODE)",
- NULL,
- NULL,
- 0,
- },
- {
- -1, 1, 4, 1, 1, 0
- },
- /* avr has an 8 bit mul */
- {
- 1, 0
- },
- "_",
- _avr_init,
- _avr_parseOptions,
- _avr_finaliseOptions,
- _avr_setDefaultOptions,
- avr_assignRegisters,
- _avr_getRegName ,
- _avr_keywords,
- _avr_genAssemblerPreamble,
- _avr_genIVT,
- _avr_reset_regparm,
- _avr_regparm,
+PORT avr_port =
+{
+ "avr",
+ "ATMEL AVR", /* Target name */
+ {
+ TRUE, /* Emit glue around main */
+ MODEL_LARGE | MODEL_SMALL,
+ MODEL_SMALL
+ },
+ {
+ _asmCmd,
+ "-plosgffc", /* Options with debug */
+ "-plosgff", /* Options without debug */
+ 0
+ },
+ {
+ _linkCmd,
NULL,
- FALSE,
- 0, /* leave lt */
- 1, /* transform gt ==> not le */
- 0, /* leave le */
- 0, /* leave ge */
- 0, /* leave != */
- 0, /* leave == */
- PORT_MAGIC
+ ".rel"
+ },
+ {
+ _defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 1, 2, 4, 2, 2, 3, 1, 4, 4
+ },
+ {
+ "XSEG (XDATA)",
+ "STACK (DATA)",
+ "CSEG (CODE)",
+ "DSEG (DATA)",
+ "ISEG (DATA)",
+ "XSEG (XDATA)",
+ "BSEG (BIT)",
+ "RSEG (DATA)",
+ "GSINIT (CODE)",
+ "OSEG (OVR,DATA)",
+ "GSFINAL (CODE)",
+ "HOME (CODE)",
+ NULL,
+ NULL,
+ 0,
+ },
+ {
+ -1, 1, 4, 1, 1, 0
+ },
+ /* avr has an 8 bit mul */
+ {
+ 1, 0
+ },
+ "_",
+ _avr_init,
+ _avr_parseOptions,
+ _avr_finaliseOptions,
+ _avr_setDefaultOptions,
+ avr_assignRegisters,
+ _avr_getRegName,
+ _avr_keywords,
+ _avr_genAssemblerPreamble,
+ _avr_genIVT,
+ _avr_reset_regparm,
+ _avr_regparm,
+ NULL,
+ FALSE,
+ 0, /* leave lt */
+ 1, /* transform gt ==> not le */
+ 0, /* leave le */
+ 0, /* leave ge */
+ 0, /* leave != */
+ 0, /* leave == */
+ PORT_MAGIC
};
-
#ifndef MAIN_INCLUDE
#define MAIN_INCLUDE
-bool x_parseOptions(char **argv, int *pargc);
-void x_setDefaultOptions(void);
-void x_finaliseOptions(void);
+bool x_parseOptions (char **argv, int *pargc);
+void x_setDefaultOptions (void);
+void x_finaliseOptions (void);
#endif
/* some routines are non-processor specific & can be reused when */
/* targetting other processors. The decision for this will have */
/* to be made on a routine by routine basis */
-/* routines used to pack registers are most definitely not reusable*/
+/* routines used to pack registers are most definitely not reusable */
/* since the pack the registers depending strictly on the MCU */
/*-----------------------------------------------------------------*/
-extern void genAVRCode(iCode *);
+extern void genAVRCode (iCode *);
/* Global data */
-static struct {
+static struct
+ {
bitVect *spiltSet;
set *stackSpil;
bitVect *regAssigned;
short blockSpil;
int slocNum;
- bitVect *funcrUsed; /* registers used in a function */
+ bitVect *funcrUsed; /* registers used in a function */
int stackExtend;
int dataExtend;
-} _G;
+ }
+_G;
/* Shared with gen.c */
-int avr_ptrRegReq; /* pointer register required */
+int avr_ptrRegReq; /* pointer register required */
/* AVR registers */
-regs regsAVR[] =
+regs regsAVR[] =
{
- { REG_GPR ,R0_IDX , REG_GPR , "r0", "r0" , "" , 0, 0, 0 }, /* used as scratch */
- { REG_GPR ,R1_IDX , REG_GPR , "r1", "r1" , "" , 0, 0, 0 }, /* used as scratch */
- { REG_GPR ,R2_IDX , REG_GPR , "r2", "r2" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R3_IDX , REG_GPR , "r3", "r3" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R4_IDX , REG_GPR , "r4", "r4" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R5_IDX , REG_GPR , "r5", "r5" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R6_IDX , REG_GPR , "r6", "r6" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R7_IDX , REG_GPR , "r7", "r7" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R8_IDX , REG_GPR , "r8", "r8" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R9_IDX , REG_GPR , "r9", "r9" , "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R10_IDX, REG_GPR , "r10", "r10", "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R11_IDX, REG_GPR , "r11", "r11", "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R12_IDX, REG_GPR , "r12", "r12", "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R13_IDX, REG_GPR , "r13", "r13", "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R14_IDX, REG_GPR , "r14", "r14", "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R15_IDX, REG_GPR , "r15", "r15", "" , 0, 1, 1 }, /* gpr */
- { REG_GPR ,R16_IDX, REG_GPR , "r16", "r16", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R17_IDX, REG_GPR , "r17", "r17", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R18_IDX, REG_GPR , "r18", "r18", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R19_IDX, REG_GPR , "r19", "r19", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R20_IDX, REG_GPR , "r20", "r20", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R21_IDX, REG_GPR , "r21", "r21", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R22_IDX, REG_GPR , "r22", "r22", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R23_IDX, REG_GPR , "r23", "r23", "" , 0, 1, 0 }, /* parm/gpr */
- { REG_GPR ,R24_IDX, REG_GPR , "r24", "r24", "" , 0, 0, 0 }, /* scratch */
- { REG_GPR ,R25_IDX, REG_GPR , "r25", "r25", "" , 0, 0, 0 }, /* scratch */
- { REG_GPR ,R26_IDX, REG_GPR , "r26", "r26", "" , 0, 1, 1 }, /* used as pointer reg X */
- { REG_GPR ,R27_IDX, REG_GPR , "r27", "r27", "" , 0, 1, 1 }, /* used as pointer reg X */
- { REG_GPR ,R28_IDX, REG_GPR , "r28", "r28", "" , 0, 1, 0 }, /* stack frame Y */
- { REG_GPR ,R29_IDX, REG_GPR , "r29", "r29", "" , 0, 1, 0 }, /* stack frame Y */
- { REG_GPR ,R30_IDX, REG_GPR , "r30", "r30", "" , 0, 1, 1 }, /* used as pointer reg Z */
- { REG_GPR ,R31_IDX, REG_GPR , "r31", "r31", "" , 0, 1, 1 }, /* used as pointer reg Z */
- { REG_PTR ,X_IDX , REG_PTR , "X" , "X" , "" , 0, 1, 0 },
- { REG_PTR ,Z_IDX , REG_PTR , "Z" , "Z" , "" , 0, 1, 0 },
+ {REG_GPR, R0_IDX, REG_GPR, "r0", "r0", "", 0, 0, 0}, /* used as scratch */
+ {REG_GPR, R1_IDX, REG_GPR, "r1", "r1", "", 0, 0, 0}, /* used as scratch */
+ {REG_GPR, R2_IDX, REG_GPR, "r2", "r2", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R3_IDX, REG_GPR, "r3", "r3", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R4_IDX, REG_GPR, "r4", "r4", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R5_IDX, REG_GPR, "r5", "r5", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R6_IDX, REG_GPR, "r6", "r6", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R7_IDX, REG_GPR, "r7", "r7", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R8_IDX, REG_GPR, "r8", "r8", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R9_IDX, REG_GPR, "r9", "r9", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R10_IDX, REG_GPR, "r10", "r10", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R11_IDX, REG_GPR, "r11", "r11", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R12_IDX, REG_GPR, "r12", "r12", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R13_IDX, REG_GPR, "r13", "r13", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R14_IDX, REG_GPR, "r14", "r14", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R15_IDX, REG_GPR, "r15", "r15", "", 0, 1, 1}, /* gpr */
+ {REG_GPR, R16_IDX, REG_GPR, "r16", "r16", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R17_IDX, REG_GPR, "r17", "r17", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R18_IDX, REG_GPR, "r18", "r18", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R19_IDX, REG_GPR, "r19", "r19", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R20_IDX, REG_GPR, "r20", "r20", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R21_IDX, REG_GPR, "r21", "r21", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R22_IDX, REG_GPR, "r22", "r22", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R23_IDX, REG_GPR, "r23", "r23", "", 0, 1, 0}, /* parm/gpr */
+ {REG_GPR, R24_IDX, REG_GPR, "r24", "r24", "", 0, 0, 0}, /* scratch */
+ {REG_GPR, R25_IDX, REG_GPR, "r25", "r25", "", 0, 0, 0}, /* scratch */
+ {REG_GPR, R26_IDX, REG_GPR, "r26", "r26", "", 0, 1, 1}, /* used as pointer reg X */
+ {REG_GPR, R27_IDX, REG_GPR, "r27", "r27", "", 0, 1, 1}, /* used as pointer reg X */
+ {REG_GPR, R28_IDX, REG_GPR, "r28", "r28", "", 0, 1, 0}, /* stack frame Y */
+ {REG_GPR, R29_IDX, REG_GPR, "r29", "r29", "", 0, 1, 0}, /* stack frame Y */
+ {REG_GPR, R30_IDX, REG_GPR, "r30", "r30", "", 0, 1, 1}, /* used as pointer reg Z */
+ {REG_GPR, R31_IDX, REG_GPR, "r31", "r31", "", 0, 1, 1}, /* used as pointer reg Z */
+ {REG_PTR, X_IDX, REG_PTR, "X", "X", "", 0, 1, 0},
+ {REG_PTR, Z_IDX, REG_PTR, "Z", "Z", "", 0, 1, 0},
};
int avr_nRegs = 32;
-int avr_fReg = 0; /* first allocatable register */
+int avr_fReg = 0; /* first allocatable register */
static void spillThis (symbol *);
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
-static regs *allocReg (short type)
+static regs *
+allocReg (short type)
{
- int i;
-
- for ( i = avr_fReg ; i < avr_nRegs ; i++ ) {
-
- /* if type is given as 0 then any
- free register will do */
- if (!type &&
- regsAVR[i].isFree ) {
- regsAVR[i].isFree = 0;
- if (currFunc)
- currFunc->regsUsed = bitVectSetBit(currFunc->regsUsed,i);
- return ®sAVR[i];
+ int i;
+
+ for (i = avr_fReg; i < avr_nRegs; i++)
+ {
+
+ /* if type is given as 0 then any
+ free register will do */
+ if (!type &&
+ regsAVR[i].isFree)
+ {
+ regsAVR[i].isFree = 0;
+ if (currFunc)
+ currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, i);
+ return ®sAVR[i];
}
- /* other wise look for specific type
- of register */
- if (regsAVR[i].isFree &&
- regsAVR[i].type == type) {
- regsAVR[i].isFree = 0;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- return ®sAVR[i];
+ /* other wise look for specific type
+ of register */
+ if (regsAVR[i].isFree &&
+ regsAVR[i].type == type)
+ {
+ regsAVR[i].isFree = 0;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ return ®sAVR[i];
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* avr_regWithIdx - returns pointer to register wit index number */
/*-----------------------------------------------------------------*/
-regs *avr_regWithIdx (int idx)
+regs *
+avr_regWithIdx (int idx)
{
- int i ;
-
- for (i=0 ; i < avr_nRegs;i++)
- if (regsAVR[i].rIdx == idx)
- return ®sAVR[i];
-
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "regWithIdx not found");
- exit(1);
+ int i;
+
+ for (i = 0; i < avr_nRegs; i++)
+ if (regsAVR[i].rIdx == idx)
+ return ®sAVR[i];
+
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "regWithIdx not found");
+ exit (1);
}
/*-----------------------------------------------------------------*/
/* freeReg - frees a register */
/*-----------------------------------------------------------------*/
-static void freeReg (regs *reg)
+static void
+freeReg (regs * reg)
{
- reg->isFree = 1;
+ reg->isFree = 1;
}
/*-----------------------------------------------------------------*/
/* nFreeRegs - returns number of free registers */
/*-----------------------------------------------------------------*/
-static int nFreeRegs (int type)
+static int
+nFreeRegs (int type)
{
- int i;
- int nfr=0;
-
- for (i = avr_fReg ; i < avr_nRegs; i++ )
- if (regsAVR[i].isFree && regsAVR[i].type == type)
- nfr++;
- return nfr;
+ int i;
+ int nfr = 0;
+
+ for (i = avr_fReg; i < avr_nRegs; i++)
+ if (regsAVR[i].isFree && regsAVR[i].type == type)
+ nfr++;
+ return nfr;
}
/*-----------------------------------------------------------------*/
/* nfreeRegsType - free registers with type */
/*-----------------------------------------------------------------*/
-static int nfreeRegsType (int type)
+static int
+nfreeRegsType (int type)
{
- int nfr ;
- if (type == REG_PTR) {
- if ((nfr = nFreeRegs(type)) == 0)
- return nFreeRegs(REG_GPR);
- }
-
- return nFreeRegs(type);
+ int nfr;
+ if (type == REG_PTR)
+ {
+ if ((nfr = nFreeRegs (type)) == 0)
+ return nFreeRegs (REG_GPR);
+ }
+
+ return nFreeRegs (type);
}
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
/*-----------------------------------------------------------------*/
-static bool allDefsOutOfRange (bitVect *defs,int fseq, int toseq)
+static bool
+allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
{
- int i ;
+ int i;
+
+ if (!defs)
+ return TRUE;
- if (!defs)
- return TRUE ;
+ for (i = 0; i < defs->size; i++)
+ {
+ iCode *ic;
- for ( i = 0 ;i < defs->size ; i++ ) {
- iCode *ic;
+ if (bitVectBitValue (defs, i) &&
+ (ic = hTabItemWithKey (iCodehTab, i)) &&
+ (ic->seq >= fseq && ic->seq <= toseq))
- if (bitVectBitValue(defs,i) &&
- (ic = hTabItemWithKey(iCodehTab,i)) &&
- ( ic->seq >= fseq && ic->seq <= toseq))
-
- return FALSE;
+ return FALSE;
}
-
- return TRUE;
+
+ return TRUE;
}
-
+
/*-----------------------------------------------------------------*/
/* computeSpillable - given a point find the spillable live ranges */
/*-----------------------------------------------------------------*/
-static bitVect *computeSpillable (iCode *ic)
+static bitVect *
+computeSpillable (iCode * ic)
{
- bitVect *spillable ;
-
- /* spillable live ranges are those that are live at this
- point . the following categories need to be subtracted
- from this set.
- a) - those that are already spilt
- b) - if being used by this one
- c) - defined by this one */
-
- spillable = bitVectCopy(ic->rlive);
- spillable =
- bitVectCplAnd(spillable,_G.spiltSet); /* those already spilt */
- spillable =
- bitVectCplAnd(spillable,ic->uses); /* used in this one */
- bitVectUnSetBit(spillable,ic->defKey);
- spillable = bitVectIntersect(spillable,_G.regAssigned);
- return spillable;
-
+ bitVect *spillable;
+
+ /* spillable live ranges are those that are live at this
+ point . the following categories need to be subtracted
+ from this set.
+ a) - those that are already spilt
+ b) - if being used by this one
+ c) - defined by this one */
+
+ spillable = bitVectCopy (ic->rlive);
+ spillable =
+ bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
+ spillable =
+ bitVectCplAnd (spillable, ic->uses); /* used in this one */
+ bitVectUnSetBit (spillable, ic->defKey);
+ spillable = bitVectIntersect (spillable, _G.regAssigned);
+ return spillable;
+
}
/*-----------------------------------------------------------------*/
/* noSpilLoc - return true if a variable has no spil location */
/*-----------------------------------------------------------------*/
-static int noSpilLoc (symbol *sym, eBBlock *ebp,iCode *ic)
+static int
+noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 0 : 1);
+ return (sym->usl.spillLoc ? 0 : 1);
}
/*-----------------------------------------------------------------*/
/* hasSpilLoc - will return 1 if the symbol has spil location */
/*-----------------------------------------------------------------*/
-static int hasSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 1 : 0);
+ return (sym->usl.spillLoc ? 1 : 0);
}
/*-----------------------------------------------------------------*/
-/* hasSpilLocnoUptr - will return 1 if the symbol has spil location*/
+/* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
/* but is not used as a pointer */
/*-----------------------------------------------------------------*/
-static int hasSpilLocnoUptr (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
+ return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* rematable - will return 1 if the remat flag is set */
/*-----------------------------------------------------------------*/
-static int rematable (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+rematable (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return sym->remat;
+ return sym->remat;
}
/*-----------------------------------------------------------------*/
/* notUsedInBlock - not used in this block */
/*-----------------------------------------------------------------*/
-static int notUsedInBlock (symbol *sym, eBBlock *ebp, iCode *ic)
-{
- return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs) &&
- allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
+static int
+notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
+{
+ return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
+ allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
}
/*-----------------------------------------------------------------*/
/* notUsedInRemaining - not used or defined in remain of the block */
/*-----------------------------------------------------------------*/
-static int notUsedInRemaining (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return ((usedInRemaining (operandFromSymbol(sym),ic) ? 0 : 1) &&
- allDefsOutOfRange (sym->defs,ic->seq,ebp->lSeq));
+ return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
+ allDefsOutOfRange (sym->defs, ic->seq, ebp->lSeq));
}
/*-----------------------------------------------------------------*/
/* allLRs - return true for all */
/*-----------------------------------------------------------------*/
-static int allLRs (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* liveRangesWith - applies function to a given set of live range */
/*-----------------------------------------------------------------*/
-static set *liveRangesWith (bitVect *lrs,
- int (func)(symbol *,eBBlock *, iCode *),
- eBBlock *ebp, iCode *ic)
+static set *
+liveRangesWith (bitVect * lrs,
+ int (func) (symbol *, eBBlock *, iCode *),
+ eBBlock * ebp, iCode * ic)
{
- set *rset = NULL;
- int i;
+ set *rset = NULL;
+ int i;
- if (!lrs || !lrs->size)
- return NULL;
+ if (!lrs || !lrs->size)
+ return NULL;
- for ( i = 1 ; i < lrs->size ; i++ ) {
- symbol *sym;
- if (!bitVectBitValue(lrs,i))
- continue ;
-
- /* if we don't find it in the live range
- hash table we are in serious trouble */
- if (!(sym = hTabItemWithKey(liveRanges,i))) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "liveRangesWith could not find liveRange");
- exit(1);
+ for (i = 1; i < lrs->size; i++)
+ {
+ symbol *sym;
+ if (!bitVectBitValue (lrs, i))
+ continue;
+
+ /* if we don't find it in the live range
+ hash table we are in serious trouble */
+ if (!(sym = hTabItemWithKey (liveRanges, i)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "liveRangesWith could not find liveRange");
+ exit (1);
}
-
- if (func(sym,ebp,ic) && bitVectBitValue(_G.regAssigned,sym->key))
- addSetHead(&rset,sym);
+
+ if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
+ addSetHead (&rset, sym);
}
- return rset;
+ return rset;
}
/*-----------------------------------------------------------------*/
/* leastUsedLR - given a set determines which is the least used */
/*-----------------------------------------------------------------*/
-static symbol *leastUsedLR (set *sset)
+static symbol *
+leastUsedLR (set * sset)
{
- symbol *sym = NULL, *lsym = NULL ;
-
- sym = lsym = setFirstItem(sset);
+ symbol *sym = NULL, *lsym = NULL;
- if (!lsym)
- return NULL;
+ sym = lsym = setFirstItem (sset);
+
+ if (!lsym)
+ return NULL;
+
+ for (; lsym; lsym = setNextItem (sset))
+ {
- for (; lsym; lsym = setNextItem(sset)) {
-
- /* if usage is the same then prefer
- the spill the smaller of the two */
- if ( lsym->used == sym->used )
- if (getSize(lsym->type) < getSize(sym->type))
- sym = lsym;
-
- /* if less usage */
- if (lsym->used < sym->used )
- sym = lsym;
-
- }
-
- setToNull((void **)&sset);
- sym->blockSpil = 0;
- return sym;
+ /* if usage is the same then prefer
+ the spill the smaller of the two */
+ if (lsym->used == sym->used)
+ if (getSize (lsym->type) < getSize (sym->type))
+ sym = lsym;
+
+ /* if less usage */
+ if (lsym->used < sym->used)
+ sym = lsym;
+
+ }
+
+ setToNull ((void **) &sset);
+ sym->blockSpil = 0;
+ return sym;
}
/*-----------------------------------------------------------------*/
/* noOverLap - will iterate through the list looking for over lap */
/*-----------------------------------------------------------------*/
-static int noOverLap (set *itmpStack, symbol *fsym)
+static int
+noOverLap (set * itmpStack, symbol * fsym)
{
- symbol *sym;
-
+ symbol *sym;
+
+
+ for (sym = setFirstItem (itmpStack); sym;
+ sym = setNextItem (itmpStack))
+ {
+ if (sym->liveTo > fsym->liveFrom)
+ return 0;
- for (sym = setFirstItem(itmpStack); sym;
- sym = setNextItem(itmpStack)) {
- if (sym->liveTo > fsym->liveFrom )
- return 0;
-
}
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* isFree - will return 1 if the a free spil location is found */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(isFree)
+static
+DEFSETFUNC (isFree)
{
- symbol *sym = item;
- V_ARG(symbol **,sloc);
- V_ARG(symbol *,fsym);
+ symbol *sym = item;
+ V_ARG (symbol **, sloc);
+ V_ARG (symbol *, fsym);
- /* if already found */
- if (*sloc)
- return 0;
+ /* if already found */
+ if (*sloc)
+ return 0;
- /* if it is free && and the itmp assigned to
- this does not have any overlapping live ranges
- with the one currently being assigned and
- the size can be accomodated */
- if (sym->isFree &&
- noOverLap(sym->usl.itmpStack,fsym) &&
- getSize(sym->type) >= getSize(fsym->type)) {
- *sloc = sym;
- return 1;
+ /* if it is free && and the itmp assigned to
+ this does not have any overlapping live ranges
+ with the one currently being assigned and
+ the size can be accomodated */
+ if (sym->isFree &&
+ noOverLap (sym->usl.itmpStack, fsym) &&
+ getSize (sym->type) >= getSize (fsym->type))
+ {
+ *sloc = sym;
+ return 1;
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* spillLRWithPtrReg :- will spil those live ranges which use PTR */
/*-----------------------------------------------------------------*/
-static void spillLRWithPtrReg (symbol *forSym)
+static void
+spillLRWithPtrReg (symbol * forSym)
{
- symbol *lrsym;
- regs *X,*Z;
- int k;
-
- if (!_G.regAssigned ||
- bitVectIsZero(_G.regAssigned))
- return;
-
- X = avr_regWithIdx(X_IDX);
- Z = avr_regWithIdx(Z_IDX);
-
- /* for all live ranges */
- for (lrsym = hTabFirstItem(liveRanges,&k) ; lrsym ;
- lrsym = hTabNextItem(liveRanges,&k) ) {
- int j;
-
- /* if no registers assigned to it or
- spilt */
- /* if it does not overlap with this then
- not need to spill it */
-
- if (lrsym->isspilt || !lrsym->nRegs ||
- (lrsym->liveTo < forSym->liveFrom))
- continue ;
-
- /* go thru the registers : if it is either
- r0 or r1 then spil it */
- for (j = 0 ; j < lrsym->nRegs ; j++ )
- if (lrsym->regs[j] == X || lrsym->regs[j] == Z ) {
- spillThis (lrsym);
- break;
- }
+ symbol *lrsym;
+ regs *X, *Z;
+ int k;
+
+ if (!_G.regAssigned ||
+ bitVectIsZero (_G.regAssigned))
+ return;
+
+ X = avr_regWithIdx (X_IDX);
+ Z = avr_regWithIdx (Z_IDX);
+
+ /* for all live ranges */
+ for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
+ lrsym = hTabNextItem (liveRanges, &k))
+ {
+ int j;
+
+ /* if no registers assigned to it or
+ spilt */
+ /* if it does not overlap with this then
+ not need to spill it */
+
+ if (lrsym->isspilt || !lrsym->nRegs ||
+ (lrsym->liveTo < forSym->liveFrom))
+ continue;
+
+ /* go thru the registers : if it is either
+ r0 or r1 then spil it */
+ for (j = 0; j < lrsym->nRegs; j++)
+ if (lrsym->regs[j] == X || lrsym->regs[j] == Z)
+ {
+ spillThis (lrsym);
+ break;
+ }
}
}
/*-----------------------------------------------------------------*/
/* createStackSpil - create a location on the stack to spil */
/*-----------------------------------------------------------------*/
-static symbol *createStackSpil (symbol *sym)
+static symbol *
+createStackSpil (symbol * sym)
{
- symbol *sloc= NULL;
- int useXstack, model, noOverlay;
- int stackAuto;
-
- char slocBuffer[30];
-
- /* first go try and find a free one that is already
- existing on the stack */
- if (applyToSet(_G.stackSpil,isFree,&sloc, sym)) {
- /* found a free one : just update & return */
- sym->usl.spillLoc = sloc;
- sym->stackSpil= 1;
- sloc->isFree = 0;
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ symbol *sloc = NULL;
+ int useXstack, model, noOverlay;
+ int stackAuto;
+
+ char slocBuffer[30];
+
+ /* first go try and find a free one that is already
+ existing on the stack */
+ if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
+ {
+ /* found a free one : just update & return */
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+ sloc->isFree = 0;
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
- /* could not then have to create one , this is the hard part
- we need to allocate this on the stack : this is really a
- hack!! but cannot think of anything better at this time */
-
- if (sprintf(slocBuffer,"sloc%d",_G.slocNum++) >= sizeof(slocBuffer))
+ /* could not then have to create one , this is the hard part
+ we need to allocate this on the stack : this is really a
+ hack!! but cannot think of anything better at this time */
+
+ if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
{
- fprintf(stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
- __FILE__, __LINE__);
- exit(1);
+ fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
+ __FILE__, __LINE__);
+ exit (1);
}
- sloc = newiTemp(slocBuffer);
-
- /* set the type to the spilling symbol */
- sloc->type = copyLinkChain(sym->type);
- sloc->etype = getSpec(sloc->type);
- SPEC_SCLS(sloc->etype) = S_AUTO ;
- SPEC_EXTR(sloc->etype) = 0;
-
- /* we don't allow it to be allocated`
- onto the external stack since : so we
- temporarily turn it off ; we also
- turn off memory model to prevent
- the spil from going to the external storage
- and turn off overlaying
- */
-
- useXstack = options.useXstack;
- model = options.model;
- noOverlay = options.noOverlay;
- stackAuto = options.stackAuto;
- options.noOverlay = 1;
- options.model = options.useXstack = 0;
-
- allocLocal(sloc);
-
- options.useXstack = useXstack;
- options.model = model;
- options.noOverlay = noOverlay;
- options.stackAuto = stackAuto;
- sloc->isref = 1; /* to prevent compiler warning */
-
- /* if it is on the stack then update the stack */
- if (IN_STACK(sloc->etype)) {
- currFunc->stack += getSize(sloc->type);
- _G.stackExtend += getSize(sloc->type);
- } else
- _G.dataExtend += getSize(sloc->type);
-
- /* add it to the _G.stackSpil set */
- addSetHead(&_G.stackSpil,sloc);
- sym->usl.spillLoc = sloc;
- sym->stackSpil = 1;
-
- /* add it to the set of itempStack set
- of the spill location */
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ sloc = newiTemp (slocBuffer);
+
+ /* set the type to the spilling symbol */
+ sloc->type = copyLinkChain (sym->type);
+ sloc->etype = getSpec (sloc->type);
+ SPEC_SCLS (sloc->etype) = S_AUTO;
+ SPEC_EXTR (sloc->etype) = 0;
+
+ /* we don't allow it to be allocated`
+ onto the external stack since : so we
+ temporarily turn it off ; we also
+ turn off memory model to prevent
+ the spil from going to the external storage
+ and turn off overlaying
+ */
+
+ useXstack = options.useXstack;
+ model = options.model;
+ noOverlay = options.noOverlay;
+ stackAuto = options.stackAuto;
+ options.noOverlay = 1;
+ options.model = options.useXstack = 0;
+
+ allocLocal (sloc);
+
+ options.useXstack = useXstack;
+ options.model = model;
+ options.noOverlay = noOverlay;
+ options.stackAuto = stackAuto;
+ sloc->isref = 1; /* to prevent compiler warning */
+
+ /* if it is on the stack then update the stack */
+ if (IN_STACK (sloc->etype))
+ {
+ currFunc->stack += getSize (sloc->type);
+ _G.stackExtend += getSize (sloc->type);
+ }
+ else
+ _G.dataExtend += getSize (sloc->type);
+
+ /* add it to the _G.stackSpil set */
+ addSetHead (&_G.stackSpil, sloc);
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+
+ /* add it to the set of itempStack set
+ of the spill location */
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
/*-----------------------------------------------------------------*/
/* isSpiltOnStack - returns true if the spil location is on stack */
/*-----------------------------------------------------------------*/
-static bool isSpiltOnStack (symbol *sym)
+static bool
+isSpiltOnStack (symbol * sym)
{
- sym_link *etype;
+ sym_link *etype;
- if (!sym)
- return FALSE ;
-
- if (!sym->isspilt)
- return FALSE ;
+ if (!sym)
+ return FALSE;
-
- if (!sym->usl.spillLoc)
- return FALSE;
+ if (!sym->isspilt)
+ return FALSE;
- etype = getSpec(sym->usl.spillLoc->type);
- if (IN_STACK(etype))
- return TRUE;
- return FALSE ;
+ if (!sym->usl.spillLoc)
+ return FALSE;
+
+ etype = getSpec (sym->usl.spillLoc->type);
+ if (IN_STACK (etype))
+ return TRUE;
+
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* spillThis - spils a specific operand */
/*-----------------------------------------------------------------*/
-static void spillThis (symbol *sym)
+static void
+spillThis (symbol * sym)
{
- int i;
- /* if this is rematerializable or has a spillLocation
- we are okay, else we need to create a spillLocation
- for it */
- if (!(sym->remat || sym->usl.spillLoc))
- createStackSpil (sym);
-
-
- /* mark it has spilt & put it in the spilt set */
- sym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,sym->key);
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- for (i = 0 ; i < sym->nRegs ; i++)
-
- if (sym->regs[i]) {
- freeReg(sym->regs[i]);
- sym->regs[i] = NULL;
- }
-
- if (sym->usl.spillLoc && !sym->remat)
- sym->usl.spillLoc->allocreq = 1;
- return;
+ int i;
+ /* if this is rematerializable or has a spillLocation
+ we are okay, else we need to create a spillLocation
+ for it */
+ if (!(sym->remat || sym->usl.spillLoc))
+ createStackSpil (sym);
+
+
+ /* mark it has spilt & put it in the spilt set */
+ sym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ for (i = 0; i < sym->nRegs; i++)
+
+ if (sym->regs[i])
+ {
+ freeReg (sym->regs[i]);
+ sym->regs[i] = NULL;
+ }
+
+ if (sym->usl.spillLoc && !sym->remat)
+ sym->usl.spillLoc->allocreq = 1;
+ return;
}
/*-----------------------------------------------------------------*/
/* selectSpil - select a iTemp to spil : rather a simple procedure */
/*-----------------------------------------------------------------*/
-static symbol *selectSpil (iCode *ic, eBBlock *ebp, symbol *forSym)
+static symbol *
+selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- bitVect *lrcs= NULL ;
- set *selectS ;
- symbol *sym;
+ bitVect *lrcs = NULL;
+ set *selectS;
+ symbol *sym;
- /* get the spillable live ranges */
- lrcs = computeSpillable (ic);
+ /* get the spillable live ranges */
+ lrcs = computeSpillable (ic);
- /* get all live ranges that are rematerizable */
- if ((selectS = liveRangesWith(lrcs,rematable,ebp,ic))) {
+ /* get all live ranges that are rematerizable */
+ if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
+ {
- /* return the least used of these */
- return leastUsedLR(selectS);
+ /* return the least used of these */
+ return leastUsedLR (selectS);
}
- /* if the symbol is local to the block then */
- if (forSym->liveTo < ebp->lSeq ) {
-
- /* check if there are any live ranges allocated
- to registers that are not used in this block */
- if (!_G.blockSpil &&
- (selectS = liveRangesWith(lrcs,notUsedInBlock,ebp,ic))) {
- sym = leastUsedLR(selectS);
- /* if this is not rematerializable */
- if (!sym->remat) {
- _G.blockSpil++;
- sym->blockSpil = 1;
+ /* if the symbol is local to the block then */
+ if (forSym->liveTo < ebp->lSeq)
+ {
+
+ /* check if there are any live ranges allocated
+ to registers that are not used in this block */
+ if (!_G.blockSpil &&
+ (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ /* if this is not rematerializable */
+ if (!sym->remat)
+ {
+ _G.blockSpil++;
+ sym->blockSpil = 1;
}
- return sym;
- }
-
- /* check if there are any live ranges that not
- used in the remainder of the block */
- if (!_G.blockSpil &&
- (selectS = liveRangesWith(lrcs,notUsedInRemaining,ebp,ic))) {
- sym = leastUsedLR (selectS);
- if (sym != forSym) {
- if (!sym->remat) {
- sym->remainSpil = 1;
- _G.blockSpil++;
+ return sym;
+ }
+
+ /* check if there are any live ranges that not
+ used in the remainder of the block */
+ if (!_G.blockSpil &&
+ (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ if (sym != forSym)
+ {
+ if (!sym->remat)
+ {
+ sym->remainSpil = 1;
+ _G.blockSpil++;
}
- return sym;
+ return sym;
}
}
- }
-
- /* find live ranges with spillocation && not used as pointers */
- if ((selectS = liveRangesWith(lrcs,hasSpilLocnoUptr,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- /* mark this as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
}
- /* find live ranges with spillocation */
- if ((selectS = liveRangesWith(lrcs,hasSpilLoc,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation && not used as pointers */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ /* mark this as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
+ }
+
+ /* find live ranges with spillocation */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* couldn't find then we need to create a spil
- location on the stack , for which one? the least
- used ofcourse */
- if ((selectS = liveRangesWith(lrcs,noSpilLoc,ebp,ic))) {
-
- /* return a created spil location */
- sym = createStackSpil(leastUsedLR(selectS));
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* couldn't find then we need to create a spil
+ location on the stack , for which one? the least
+ used ofcourse */
+ if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
+ {
+
+ /* return a created spil location */
+ sym = createStackSpil (leastUsedLR (selectS));
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
-
- /* this is an extreme situation we will spill
- this one : happens very rarely but it does happen */
- spillThis ( forSym );
- return forSym ;
-
+
+ /* this is an extreme situation we will spill
+ this one : happens very rarely but it does happen */
+ spillThis (forSym);
+ return forSym;
+
}
/*-----------------------------------------------------------------*/
/* spilSomething - spil some variable & mark registers as free */
/*-----------------------------------------------------------------*/
-static bool spilSomething (iCode *ic, eBBlock *ebp, symbol *forSym)
+static bool
+spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- symbol *ssym;
- int i ;
-
- /* get something we can spil */
- ssym = selectSpil(ic,ebp,forSym);
-
- /* mark it as spilt */
- ssym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,ssym->key);
-
- /* mark it as not register assigned &
- take it away from the set */
- bitVectUnSetBit(_G.regAssigned,ssym->key);
-
- /* mark the registers as free */
- for (i = 0 ; i < ssym->nRegs ;i++ )
- if (ssym->regs[i])
- freeReg(ssym->regs[i]);
-
- /* if this was a block level spil then insert push & pop
- at the start & end of block respectively */
- if (ssym->blockSpil) {
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push to the start of the block */
- addiCodeToeBBlock(ebp,nic,( ebp->sch->op == LABEL ?
+ symbol *ssym;
+ int i;
+
+ /* get something we can spil */
+ ssym = selectSpil (ic, ebp, forSym);
+
+ /* mark it as spilt */
+ ssym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
+
+ /* mark it as not register assigned &
+ take it away from the set */
+ bitVectUnSetBit (_G.regAssigned, ssym->key);
+
+ /* mark the registers as free */
+ for (i = 0; i < ssym->nRegs; i++)
+ if (ssym->regs[i])
+ freeReg (ssym->regs[i]);
+
+ /* if this was a block level spil then insert push & pop
+ at the start & end of block respectively */
+ if (ssym->blockSpil)
+ {
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push to the start of the block */
+ addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
ebp->sch->next : ebp->sch));
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
- }
-
- /* if spilt because not used in the remainder of the
- block then add a push before this instruction and
- a pop at the end of the block */
- if (ssym->remainSpil) {
-
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push just before this instruction */
- addiCodeToeBBlock(ebp,nic,ic);
-
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
}
- if (ssym == forSym )
- return FALSE ;
- else
- return TRUE ;
+ /* if spilt because not used in the remainder of the
+ block then add a push before this instruction and
+ a pop at the end of the block */
+ if (ssym->remainSpil)
+ {
+
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push just before this instruction */
+ addiCodeToeBBlock (ebp, nic, ic);
+
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
+ }
+
+ if (ssym == forSym)
+ return FALSE;
+ else
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* getRegPtr - will try for PTR if not a GPR type if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegPtr (iCode *ic, eBBlock *ebp, symbol *sym)
+static regs *
+getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
+ regs *reg;
- tryAgain:
- /* try for a ptr type */
- if ((reg = allocReg(REG_PTR)))
- return reg;
+tryAgain:
+ /* try for a ptr type */
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* getRegScr - will try for SCR if not a GPR type if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegScr (iCode *ic, eBBlock *ebp, symbol *sym)
+static regs *
+getRegScr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
+ regs *reg;
- tryAgain:
- /* try for a ptr type */
- if ((reg = allocReg(REG_SCR)))
- return reg;
+tryAgain:
+ /* try for a ptr type */
+ if ((reg = allocReg (REG_SCR)))
+ return reg;
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* getRegGpr - will try for GPR if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegGpr (iCode *ic, eBBlock *ebp,symbol *sym)
+static regs *
+getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
-
- tryAgain:
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
-
- if (!avr_ptrRegReq)
- if ((reg = allocReg(REG_PTR)))
- return reg ;
-
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
-
- /* this looks like an infinite loop but
- in reality selectSpil will abort */
- goto tryAgain ;
+ regs *reg;
+
+tryAgain:
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
+
+ if (!avr_ptrRegReq)
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
+
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
+
+ /* this looks like an infinite loop but
+ in reality selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* symHasReg - symbol has a given register */
/*-----------------------------------------------------------------*/
-static bool symHasReg(symbol *sym,regs *reg)
+static bool
+symHasReg (symbol * sym, regs * reg)
{
- int i;
+ int i;
- for ( i = 0 ; i < sym->nRegs ; i++)
- if (sym->regs[i] == reg)
- return TRUE;
-
- return FALSE;
+ for (i = 0; i < sym->nRegs; i++)
+ if (sym->regs[i] == reg)
+ return TRUE;
+
+ return FALSE;
}
/*-----------------------------------------------------------------*/
-/* deassignLRs - check the live to and if they have registers & are*/
+/* deassignLRs - check the live to and if they have registers & are */
/* not spilt then free up the registers */
/*-----------------------------------------------------------------*/
-static void deassignLRs (iCode *ic, eBBlock *ebp)
+static void
+deassignLRs (iCode * ic, eBBlock * ebp)
{
- symbol *sym;
- int k;
- symbol *result;
-
- for (sym = hTabFirstItem(liveRanges,&k); sym;
- sym = hTabNextItem(liveRanges,&k)) {
-
- symbol *psym= NULL;
- /* if it does not end here */
- if (sym->liveTo > ic->seq )
- continue ;
-
- /* if it was spilt on stack then we can
- mark the stack spil location as free */
- if (sym->isspilt ) {
- if (sym->stackSpil) {
- sym->usl.spillLoc->isFree = 1;
- sym->stackSpil = 0;
+ symbol *sym;
+ int k;
+ symbol *result;
+
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
+
+ symbol *psym = NULL;
+ /* if it does not end here */
+ if (sym->liveTo > ic->seq)
+ continue;
+
+ /* if it was spilt on stack then we can
+ mark the stack spil location as free */
+ if (sym->isspilt)
+ {
+ if (sym->stackSpil)
+ {
+ sym->usl.spillLoc->isFree = 1;
+ sym->stackSpil = 0;
}
- continue ;
+ continue;
}
-
- if (!bitVectBitValue(_G.regAssigned,sym->key))
- continue;
-
- /* special case check if this is an IFX &
- the privious one was a pop and the
- previous one was not spilt then keep track
- of the symbol */
- if (ic->op == IFX && ic->prev &&
- ic->prev->op == IPOP &&
- !ic->prev->parmPush &&
- !OP_SYMBOL(IC_LEFT(ic->prev))->isspilt)
- psym = OP_SYMBOL(IC_LEFT(ic->prev));
-
- if (sym->nRegs) {
- int i = 0;
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- /* if the result of this one needs registers
- and does not have it then assign it right
- away */
- if (IC_RESULT(ic) &&
- ! (SKIP_IC2(ic) || /* not a special icode */
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- ic->op == RETURN ||
- POINTER_SET(ic)) &&
- (result = OP_SYMBOL(IC_RESULT(ic))) && /* has a result */
- result->liveTo > ic->seq && /* and will live beyond this */
- result->liveTo <= ebp->lSeq && /* does not go beyond this block */
- result->regType == sym->regType && /* same register types */
- result->nRegs && /* which needs registers */
- ! result->isspilt && /* and does not already have them */
- ! result->remat &&
- ! bitVectBitValue(_G.regAssigned,result->key) &&
- /* the number of free regs + number of regs in this LR
- can accomodate the what result Needs */
- ((nfreeRegsType(result->regType) +
- sym->nRegs) >= result->nRegs)
- ) {
-
- for (i = 0 ; i < result->nRegs ; i++)
- if (i < sym->nRegs )
- result->regs[i] = sym->regs[i] ;
- else if (result->regType == REG_SCR)
- result->regs[i] = getRegScr(ic,ebp,result);
- else
- result->regs[i] = getRegGpr (ic,ebp,result);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,result->key);
-
- }
-
- /* free the remaining */
- for (; i < sym->nRegs ; i++) {
- if (psym) {
- if (!symHasReg(psym,sym->regs[i]))
- freeReg(sym->regs[i]);
- } else
- freeReg(sym->regs[i]);
+
+ if (!bitVectBitValue (_G.regAssigned, sym->key))
+ continue;
+
+ /* special case check if this is an IFX &
+ the privious one was a pop and the
+ previous one was not spilt then keep track
+ of the symbol */
+ if (ic->op == IFX && ic->prev &&
+ ic->prev->op == IPOP &&
+ !ic->prev->parmPush &&
+ !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
+ psym = OP_SYMBOL (IC_LEFT (ic->prev));
+
+ if (sym->nRegs)
+ {
+ int i = 0;
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ /* if the result of this one needs registers
+ and does not have it then assign it right
+ away */
+ if (IC_RESULT (ic) &&
+ !(SKIP_IC2 (ic) || /* not a special icode */
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ ic->op == RETURN ||
+ POINTER_SET (ic)) &&
+ (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
+ result->liveTo > ic->seq && /* and will live beyond this */
+ result->liveTo <= ebp->lSeq && /* does not go beyond this block */
+ result->regType == sym->regType && /* same register types */
+ result->nRegs && /* which needs registers */
+ !result->isspilt && /* and does not already have them */
+ !result->remat &&
+ !bitVectBitValue (_G.regAssigned, result->key) &&
+ /* the number of free regs + number of regs in this LR
+ can accomodate the what result Needs */
+ ((nfreeRegsType (result->regType) +
+ sym->nRegs) >= result->nRegs)
+ )
+ {
+
+ for (i = 0; i < result->nRegs; i++)
+ if (i < sym->nRegs)
+ result->regs[i] = sym->regs[i];
+ else if (result->regType == REG_SCR)
+ result->regs[i] = getRegScr (ic, ebp, result);
+ else
+ result->regs[i] = getRegGpr (ic, ebp, result);
+
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
+
+ }
+
+ /* free the remaining */
+ for (; i < sym->nRegs; i++)
+ {
+ if (psym)
+ {
+ if (!symHasReg (psym, sym->regs[i]))
+ freeReg (sym->regs[i]);
+ }
+ else
+ freeReg (sym->regs[i]);
}
}
}
/*-----------------------------------------------------------------*/
/* reassignLR - reassign this to registers */
/*-----------------------------------------------------------------*/
-static void reassignLR (operand *op)
+static void
+reassignLR (operand * op)
{
- symbol *sym = OP_SYMBOL(op);
- int i;
+ symbol *sym = OP_SYMBOL (op);
+ int i;
+
+ /* not spilt any more */
+ sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
+ bitVectUnSetBit (_G.spiltSet, sym->key);
- /* not spilt any more */
- sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
- bitVectUnSetBit(_G.spiltSet,sym->key);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- _G.blockSpil--;
+ _G.blockSpil--;
- for (i=0;i<sym->nRegs;i++)
- sym->regs[i]->isFree = 0;
+ for (i = 0; i < sym->nRegs; i++)
+ sym->regs[i]->isFree = 0;
}
/*-----------------------------------------------------------------*/
/* willCauseSpill - determines if allocating will cause a spill */
/*-----------------------------------------------------------------*/
-static int willCauseSpill ( int nr, int rt)
+static int
+willCauseSpill (int nr, int rt)
{
- /* first check if there are any avlb registers
- of te type required */
- if (rt == REG_PTR) {
- /* special case for pointer type
- if pointer type not avlb then
- check for type gpr */
- if (nFreeRegs(rt) >= nr)
+ /* first check if there are any avlb registers
+ of te type required */
+ if (rt == REG_PTR)
+ {
+ /* special case for pointer type
+ if pointer type not avlb then
+ check for type gpr */
+ if (nFreeRegs (rt) >= nr)
+ return 0;
+ if (nFreeRegs (REG_GPR) >= nr)
+ return 0;
+ }
+ else
+ {
+ if (avr_ptrRegReq)
+ {
+ if (nFreeRegs (rt) >= nr)
return 0;
- if (nFreeRegs(REG_GPR) >= nr)
+ }
+ else
+ {
+ if (nFreeRegs (REG_PTR) +
+ nFreeRegs (REG_GPR) >= nr)
return 0;
- } else {
- if (avr_ptrRegReq) {
- if (nFreeRegs(rt) >= nr)
- return 0;
- } else {
- if (nFreeRegs(REG_PTR) +
- nFreeRegs(REG_GPR) >= nr)
- return 0;
}
}
- /* it will cause a spil */
- return 1;
+ /* it will cause a spil */
+ return 1;
}
/*-----------------------------------------------------------------*/
-/* positionRegs - the allocator can allocate same registers to res-*/
+/* positionRegs - the allocator can allocate same registers to res- */
/* ult and operand, if this happens make sure they are in the same */
/* position as the operand otherwise chaos results */
/*-----------------------------------------------------------------*/
-static void positionRegs (symbol *result, symbol *opsym, int lineno)
+static void
+positionRegs (symbol * result, symbol * opsym, int lineno)
{
- int count = min(result->nRegs,opsym->nRegs);
- int i , j = 0, shared = 0;
-
- /* if the result has been spilt then cannot share */
- if (opsym->isspilt)
- return ;
- again:
- shared = 0;
- /* first make sure that they actually share */
- for ( i = 0 ; i < count; i++ ) {
- for (j = 0 ; j < count ; j++ ) {
- if (result->regs[i] == opsym->regs[j] && i !=j) {
- shared = 1;
- goto xchgPositions;
+ int count = min (result->nRegs, opsym->nRegs);
+ int i, j = 0, shared = 0;
+
+ /* if the result has been spilt then cannot share */
+ if (opsym->isspilt)
+ return;
+again:
+ shared = 0;
+ /* first make sure that they actually share */
+ for (i = 0; i < count; i++)
+ {
+ for (j = 0; j < count; j++)
+ {
+ if (result->regs[i] == opsym->regs[j] && i != j)
+ {
+ shared = 1;
+ goto xchgPositions;
}
}
}
- xchgPositions:
- if (shared) {
- regs *tmp = result->regs[i];
- result->regs[i] = result->regs[j];
- result->regs[j] = tmp;
- goto again;
+xchgPositions:
+ if (shared)
+ {
+ regs *tmp = result->regs[i];
+ result->regs[i] = result->regs[j];
+ result->regs[j] = tmp;
+ goto again;
}
}
/*-----------------------------------------------------------------*/
/* serialRegAssign - serially allocate registers to the variables */
/*-----------------------------------------------------------------*/
-static void serialRegAssign (eBBlock **ebbs, int count)
+static void
+serialRegAssign (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
-
- iCode *ic;
-
- if (ebbs[i]->noPath &&
- (ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* of all instructions do */
- for (ic = ebbs[i]->sch ; ic ; ic = ic->next) {
-
- /* if this is an ipop that means some live
- range will have to be assigned again */
- if (ic->op == IPOP)
- reassignLR (IC_LEFT(ic));
-
- /* if result is present && is a true symbol */
- if (IC_RESULT(ic) && ic->op != IFX &&
- IS_TRUE_SYMOP(IC_RESULT(ic)))
- OP_SYMBOL(IC_RESULT(ic))->allocreq = 1;
-
- /* take away registers from live
- ranges that end at this instruction */
- deassignLRs (ic, ebbs[i]) ;
-
- /* some don't need registers */
- if (SKIP_IC2(ic) ||
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- (IC_RESULT(ic) &&POINTER_SET(ic)) )
- continue;
-
- /* now we need to allocate registers
- only for the result */
- if (IC_RESULT(ic)) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- bitVect *spillable;
- int willCS ;
- int j;
-
- /* if it does not need or is spilt
- or is already assigned to registers
- or will not live beyond this instructions */
- if (!sym->nRegs ||
- sym->isspilt ||
- bitVectBitValue(_G.regAssigned,sym->key) ||
- sym->liveTo <= ic->seq)
- continue ;
-
- /* if some liverange has been spilt at the block level
- and this one live beyond this block then spil this
- to be safe */
- if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq) {
- spillThis (sym);
- continue ;
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* of all instructions do */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an ipop that means some live
+ range will have to be assigned again */
+ if (ic->op == IPOP)
+ reassignLR (IC_LEFT (ic));
+
+ /* if result is present && is a true symbol */
+ if (IC_RESULT (ic) && ic->op != IFX &&
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
+
+ /* take away registers from live
+ ranges that end at this instruction */
+ deassignLRs (ic, ebbs[i]);
+
+ /* some don't need registers */
+ if (SKIP_IC2 (ic) ||
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ (IC_RESULT (ic) && POINTER_SET (ic)))
+ continue;
+
+ /* now we need to allocate registers
+ only for the result */
+ if (IC_RESULT (ic))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ bitVect *spillable;
+ int willCS;
+ int j;
+
+ /* if it does not need or is spilt
+ or is already assigned to registers
+ or will not live beyond this instructions */
+ if (!sym->nRegs ||
+ sym->isspilt ||
+ bitVectBitValue (_G.regAssigned, sym->key) ||
+ sym->liveTo <= ic->seq)
+ continue;
+
+ /* if some liverange has been spilt at the block level
+ and this one live beyond this block then spil this
+ to be safe */
+ if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
+ {
+ spillThis (sym);
+ continue;
}
- /* if trying to allocate this will cause
- a spill and there is nothing to spill
- or this one is rematerializable then
- spill this one */
- willCS = willCauseSpill(sym->nRegs,sym->regType);
- spillable = computeSpillable(ic);
- if ( sym->remat ||
- (willCS && bitVectIsZero(spillable) ) ) {
-
- spillThis (sym) ;
- continue ;
+ /* if trying to allocate this will cause
+ a spill and there is nothing to spill
+ or this one is rematerializable then
+ spill this one */
+ willCS = willCauseSpill (sym->nRegs, sym->regType);
+ spillable = computeSpillable (ic);
+ if (sym->remat ||
+ (willCS && bitVectIsZero (spillable)))
+ {
+
+ spillThis (sym);
+ continue;
}
- /* if it has a spillocation & is used less than
- all other live ranges then spill this */
- if ( willCS && sym->usl.spillLoc ) {
-
- symbol *leastUsed =
- leastUsedLR(liveRangesWith (spillable ,
- allLRs,
- ebbs[i],
- ic));
- if (leastUsed &&
- leastUsed->used > sym->used) {
- spillThis (sym);
- continue;
+ /* if it has a spillocation & is used less than
+ all other live ranges then spill this */
+ if (willCS && sym->usl.spillLoc)
+ {
+
+ symbol *leastUsed =
+ leastUsedLR (liveRangesWith (spillable,
+ allLRs,
+ ebbs[i],
+ ic));
+ if (leastUsed &&
+ leastUsed->used > sym->used)
+ {
+ spillThis (sym);
+ continue;
}
- }
-
- /* we assign registers to it */
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
-
- for (j = 0 ; j < sym->nRegs ;j++ ) {
- if (sym->regType == REG_PTR)
- sym->regs[j] = getRegPtr(ic,ebbs[i],sym);
- else if (sym->regType == REG_SCR)
- sym->regs[j] = getRegScr(ic,ebbs[i],sym);
- else
- sym->regs[j] = getRegGpr(ic,ebbs[i],sym);
-
- /* if the allocation falied which means
- this was spilt then break */
- if (!sym->regs[j])
- break;
}
- /* if it shares registers with operands make sure
- that they are in the same position */
- if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->nRegs && ic->op != '=')
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_LEFT(ic)),ic->lineno);
- /* do the same for the right operand */
- if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->nRegs )
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_RIGHT(ic)),ic->lineno);
-
- }
+
+ /* we assign registers to it */
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ if (sym->regType == REG_PTR)
+ sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
+ else if (sym->regType == REG_SCR)
+ sym->regs[j] = getRegScr (ic, ebbs[i], sym);
+ else
+ sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
+
+ /* if the allocation falied which means
+ this was spilt then break */
+ if (!sym->regs[j])
+ break;
+ }
+ /* if it shares registers with operands make sure
+ that they are in the same position */
+ if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
+ /* do the same for the right operand */
+ if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->nRegs)
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
+
+ }
}
}
}
/*-----------------------------------------------------------------*/
/* rUmaskForOp :- returns register mask for an operand */
/*-----------------------------------------------------------------*/
-static bitVect *rUmaskForOp (operand *op)
+static bitVect *
+rUmaskForOp (operand * op)
{
- bitVect *rumask;
- symbol *sym;
- int j;
-
- /* only temporaries are assigned registers */
- if (!IS_ITEMP(op))
- return NULL;
+ bitVect *rumask;
+ symbol *sym;
+ int j;
- sym = OP_SYMBOL(op);
-
- /* if spilt or no registers assigned to it
- then nothing */
- if (sym->isspilt || !sym->nRegs)
- return NULL;
+ /* only temporaries are assigned registers */
+ if (!IS_ITEMP (op))
+ return NULL;
+
+ sym = OP_SYMBOL (op);
- rumask = newBitVect(avr_nRegs);
+ /* if spilt or no registers assigned to it
+ then nothing */
+ if (sym->isspilt || !sym->nRegs)
+ return NULL;
- for (j = 0; j < sym->nRegs; j++) {
- rumask = bitVectSetBit(rumask,
- sym->regs[j]->rIdx);
+ rumask = newBitVect (avr_nRegs);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ rumask = bitVectSetBit (rumask,
+ sym->regs[j]->rIdx);
}
- return rumask;
+ return rumask;
}
/*-----------------------------------------------------------------*/
-/* regsUsedIniCode :- returns bit vector of registers used in iCode*/
+/* regsUsedIniCode :- returns bit vector of registers used in iCode */
/*-----------------------------------------------------------------*/
-static bitVect *regsUsedIniCode (iCode *ic)
+static bitVect *
+regsUsedIniCode (iCode * ic)
{
- bitVect *rmask = newBitVect(avr_nRegs);
+ bitVect *rmask = newBitVect (avr_nRegs);
- /* do the special cases first */
- if (ic->op == IFX ) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_COND(ic)));
- goto ret;
+ /* do the special cases first */
+ if (ic->op == IFX)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_COND (ic)));
+ goto ret;
}
- /* for the jumptable */
- if (ic->op == JUMPTABLE) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_JTCOND(ic)));
+ /* for the jumptable */
+ if (ic->op == JUMPTABLE)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_JTCOND (ic)));
- goto ret;
+ goto ret;
}
- /* of all other cases */
- if (IC_LEFT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_LEFT(ic)));
-
-
- if (IC_RIGHT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RIGHT(ic)));
-
- if (IC_RESULT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RESULT(ic)));
-
- ret:
- return rmask;
+ /* of all other cases */
+ if (IC_LEFT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_LEFT (ic)));
+
+
+ if (IC_RIGHT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RIGHT (ic)));
+
+ if (IC_RESULT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RESULT (ic)));
+
+ret:
+ return rmask;
}
/*-----------------------------------------------------------------*/
-/* createRegMask - for each instruction will determine the regsUsed*/
+/* createRegMask - for each instruction will determine the regsUsed */
/*-----------------------------------------------------------------*/
-static void createRegMask (eBBlock **ebbs, int count)
+static void
+createRegMask (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
- iCode *ic ;
-
- if ( ebbs[i]->noPath &&
- ( ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* for all instructions */
- for ( ic = ebbs[i]->sch ; ic ; ic = ic->next ) {
-
- int j;
-
- if (SKIP_IC2(ic) || !ic->rlive)
- continue ;
-
- /* first mark the registers used in this
- instruction */
- ic->rUsed = regsUsedIniCode(ic);
- _G.funcrUsed = bitVectUnion(_G.funcrUsed,ic->rUsed);
-
- /* now create the register mask for those
- registers that are in use : this is a
- super set of ic->rUsed */
- ic->rMask = newBitVect(avr_nRegs+1);
-
- /* for all live Ranges alive at this point */
- for (j = 1; j < ic->rlive->size; j++ ) {
- symbol *sym;
- int k;
-
- /* if not alive then continue */
- if (!bitVectBitValue(ic->rlive,j))
- continue ;
-
- /* find the live range we are interested in */
- if (!(sym = hTabItemWithKey(liveRanges,j))) {
- werror (E_INTERNAL_ERROR,__FILE__,__LINE__,
- "createRegMask cannot find live range");
- exit(0);
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* for all instructions */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ int j;
+
+ if (SKIP_IC2 (ic) || !ic->rlive)
+ continue;
+
+ /* first mark the registers used in this
+ instruction */
+ ic->rUsed = regsUsedIniCode (ic);
+ _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
+
+ /* now create the register mask for those
+ registers that are in use : this is a
+ super set of ic->rUsed */
+ ic->rMask = newBitVect (avr_nRegs + 1);
+
+ /* for all live Ranges alive at this point */
+ for (j = 1; j < ic->rlive->size; j++)
+ {
+ symbol *sym;
+ int k;
+
+ /* if not alive then continue */
+ if (!bitVectBitValue (ic->rlive, j))
+ continue;
+
+ /* find the live range we are interested in */
+ if (!(sym = hTabItemWithKey (liveRanges, j)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "createRegMask cannot find live range");
+ exit (0);
}
- /* if no register assigned to it */
- if (!sym->nRegs || sym->isspilt)
- continue ;
-
- /* for all the registers allocated to it */
- for (k = 0 ; k < sym->nRegs ;k++) {
- if (sym->regs[k]) {
- ic->rMask =
- bitVectSetBit(ic->rMask,sym->regs[k]->rIdx);
- /* special case for X & Z registers */
- if (k == R26_IDX || k == R27_IDX)
- ic->rMask = bitVectSetBit(ic->rMask,X_IDX);
- if (k == R30_IDX || k == R31_IDX)
- ic->rMask = bitVectSetBit(ic->rMask,Z_IDX);
+ /* if no register assigned to it */
+ if (!sym->nRegs || sym->isspilt)
+ continue;
+
+ /* for all the registers allocated to it */
+ for (k = 0; k < sym->nRegs; k++)
+ {
+ if (sym->regs[k])
+ {
+ ic->rMask =
+ bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
+ /* special case for X & Z registers */
+ if (k == R26_IDX || k == R27_IDX)
+ ic->rMask = bitVectSetBit (ic->rMask, X_IDX);
+ if (k == R30_IDX || k == R31_IDX)
+ ic->rMask = bitVectSetBit (ic->rMask, Z_IDX);
}
}
}
/*-----------------------------------------------------------------*/
/* rematStr - returns the rematerialized string for a remat var */
/*-----------------------------------------------------------------*/
-static char *rematStr (symbol *sym)
+static char *
+rematStr (symbol * sym)
{
- char *s = buffer;
- iCode *ic = sym->rematiCode;
-
- while (1) {
-
- /* if plus or minus print the right hand side */
- if (ic->op == '+' || ic->op == '-') {
- sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
- ic->op );
- s += strlen(s);
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- continue ;
- }
-
- /* we reached the end */
- sprintf(s,"%s",OP_SYMBOL(IC_LEFT(ic))->rname);
- break;
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
+
+ while (1)
+ {
+
+ /* if plus or minus print the right hand side */
+ if (ic->op == '+' || ic->op == '-')
+ {
+ sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+ ic->op);
+ s += strlen (s);
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ continue;
+ }
+
+ /* we reached the end */
+ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ break;
}
- return buffer ;
+ return buffer;
}
/*-----------------------------------------------------------------*/
/* regTypeNum - computes the type & number of registers required */
/*-----------------------------------------------------------------*/
-static void regTypeNum ()
+static void
+regTypeNum ()
{
- symbol *sym;
- int k;
- iCode *ic;
+ symbol *sym;
+ int k;
+ iCode *ic;
+
+ /* for each live range do */
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
- /* for each live range do */
- for ( sym = hTabFirstItem(liveRanges,&k); sym ;
- sym = hTabNextItem(liveRanges,&k)) {
+ /* if used zero times then no registers needed */
+ if ((sym->liveTo - sym->liveFrom) == 0)
+ continue;
- /* if used zero times then no registers needed */
- if ((sym->liveTo - sym->liveFrom) == 0)
- continue ;
+ /* if the live range is a temporary */
+ if (sym->isitmp)
+ {
- /* if the live range is a temporary */
- if (sym->isitmp) {
+ /* if the type is marked as a conditional */
+ if (sym->regType == REG_CND)
+ continue;
+
+ /* if used in return only then we don't
+ need registers */
+ if (sym->ruonly || sym->accuse)
+ {
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ sym->type = aggrToPtr (sym->type, FALSE);
+ continue;
+ }
- /* if the type is marked as a conditional */
- if (sym->regType == REG_CND)
- continue ;
+ /* if the symbol has only one definition &
+ that definition is a get_pointer and the
+ pointer we are getting is rematerializable and
+ in "data" space */
+
+ if (bitVectnBitsOn (sym->defs) == 1 &&
+ (ic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (sym->defs))) &&
+ POINTER_GET (ic) &&
+ !IS_BITVAR (sym->etype))
+ {
+
+ /* if in data space or idata space then try to
+ allocate pointer register */
- /* if used in return only then we don't
- need registers */
- if (sym->ruonly || sym->accuse) {
- if (IS_AGGREGATE(sym->type) || sym->isptr)
- sym->type = aggrToPtr(sym->type,FALSE);
- continue ;
}
-
- /* if the symbol has only one definition &
- that definition is a get_pointer and the
- pointer we are getting is rematerializable and
- in "data" space */
-
- if (bitVectnBitsOn(sym->defs) == 1 &&
- (ic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(sym->defs))) &&
- POINTER_GET(ic) &&
- !IS_BITVAR(sym->etype)) {
-
- /* if in data space or idata space then try to
- allocate pointer register */
-
+
+ /* if not then we require registers */
+ sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
+ getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
+ getSize (sym->type));
+
+ if (sym->nRegs > 4)
+ {
+ fprintf (stderr, "allocated more than 4 or 0 registers for type ");
+ printTypeChain (sym->type, stderr);
+ fprintf (stderr, "\n");
}
-
- /* if not then we require registers */
- sym->nRegs = ((IS_AGGREGATE(sym->type) || sym->isptr ) ?
- getSize(sym->type = aggrToPtr(sym->type,FALSE)) :
- getSize(sym->type));
-
- if (sym->nRegs > 4) {
- fprintf(stderr,"allocated more than 4 or 0 registers for type ");
- printTypeChain(sym->type,stderr);fprintf(stderr,"\n");
- }
-
- /* determine the type of register required */
- if (sym->nRegs == 2 && /* size is two */
- IS_PTR(sym->type) && /* is a pointer */
- sym->uptr) { /* has pointer usage i.e. get/set pointer */
- sym->regType = REG_PTR ;
- avr_ptrRegReq++;
+
+ /* determine the type of register required */
+ if (sym->nRegs == 2 && /* size is two */
+ IS_PTR (sym->type) && /* is a pointer */
+ sym->uptr)
+ { /* has pointer usage i.e. get/set pointer */
+ sym->regType = REG_PTR;
+ avr_ptrRegReq++;
}
- else {
- /* live accross a function call then gpr else scratch */
- if (sym->isLiveFcall)
- sym->regType = REG_GPR ;
- else
- sym->regType = REG_SCR ;
+ else
+ {
+ /* live accross a function call then gpr else scratch */
+ if (sym->isLiveFcall)
+ sym->regType = REG_GPR;
+ else
+ sym->regType = REG_SCR;
}
- } else
- /* for the first run we don't provide */
- /* registers for true symbols we will */
- /* see how things go */
- sym->nRegs = 0 ;
+ }
+ else
+ /* for the first run we don't provide */
+ /* registers for true symbols we will */
+ /* see how things go */
+ sym->nRegs = 0;
}
-
+
}
/*-----------------------------------------------------------------*/
/* deallocStackSpil - this will set the stack pointer back */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(deallocStackSpil)
+static
+DEFSETFUNC (deallocStackSpil)
{
- symbol *sym = item;
+ symbol *sym = item;
- deallocLocal(sym);
- return 0;
+ deallocLocal (sym);
+ return 0;
}
/*-----------------------------------------------------------------*/
/* farSpacePackable - returns the packable icode for far variables */
/*-----------------------------------------------------------------*/
-static iCode *farSpacePackable (iCode *ic)
+static iCode *
+farSpacePackable (iCode * ic)
{
- iCode *dic ;
-
- /* go thru till we find a definition for the
- symbol on the right */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if the definition is a call then no */
- if ((dic->op == CALL || dic->op == PCALL) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- return NULL;
+ iCode *dic;
+
+ /* go thru till we find a definition for the
+ symbol on the right */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if the definition is a call then no */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ return NULL;
}
-
- /* if shift by unknown amount then not */
- if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key)
- return NULL;
- /* if pointer get and size > 1 */
- if (POINTER_GET(dic) &&
- getSize(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if shift by unknown amount then not */
+ if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ return NULL;
- if (POINTER_SET(dic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if pointer get and size > 1 */
+ if (POINTER_GET (dic) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
+ return NULL;
- /* if any three is a true symbol in far space */
- if (IC_RESULT(dic) &&
- IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- isOperandInFarSpace(IC_RESULT(dic)))
- return NULL;
+ if (POINTER_SET (dic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
+ return NULL;
- if (IC_RIGHT(dic) &&
- IS_TRUE_SYMOP(IC_RIGHT(dic)) &&
- isOperandInFarSpace(IC_RIGHT(dic)) &&
- !isOperandEqual(IC_RIGHT(dic),IC_RESULT(ic)))
- return NULL;
+ /* if any three is a true symbol in far space */
+ if (IC_RESULT (dic) &&
+ IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ isOperandInFarSpace (IC_RESULT (dic)))
+ return NULL;
+
+ if (IC_RIGHT (dic) &&
+ IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
+ isOperandInFarSpace (IC_RIGHT (dic)) &&
+ !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
+ return NULL;
- if (IC_LEFT(dic) &&
- IS_TRUE_SYMOP(IC_LEFT(dic)) &&
- isOperandInFarSpace(IC_LEFT(dic)) &&
- !isOperandEqual(IC_LEFT(dic),IC_RESULT(ic)))
+ if (IC_LEFT (dic) &&
+ IS_TRUE_SYMOP (IC_LEFT (dic)) &&
+ isOperandInFarSpace (IC_LEFT (dic)) &&
+ !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
+ return NULL;
+
+ if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
+ {
+ if ((dic->op == LEFT_OP ||
+ dic->op == RIGHT_OP ||
+ dic->op == '-') &&
+ IS_OP_LITERAL (IC_RIGHT (dic)))
return NULL;
-
- if (isOperandEqual(IC_RIGHT(ic),IC_RESULT(dic))) {
- if ( (dic->op == LEFT_OP ||
- dic->op == RIGHT_OP ||
- dic->op == '-') &&
- IS_OP_LITERAL(IC_RIGHT(dic)))
- return NULL;
- else
- return dic;
+ else
+ return dic;
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* packRegsForAssign - register reduction for assignment */
/*-----------------------------------------------------------------*/
-static int packRegsForAssign (iCode *ic,eBBlock *ebp)
+static int
+packRegsForAssign (iCode * ic, eBBlock * ebp)
{
- iCode *dic, *sic;
-
- if (!IS_ITEMP(IC_RIGHT(ic)) ||
- OP_SYMBOL(IC_RIGHT(ic))->isind ||
- OP_LIVETO(IC_RIGHT(ic)) > ic->seq) {
- return 0;
+ iCode *dic, *sic;
+
+ if (!IS_ITEMP (IC_RIGHT (ic)) ||
+ OP_SYMBOL (IC_RIGHT (ic))->isind ||
+ OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
+ {
+ return 0;
}
-
- /* find the definition of iTempNN scanning backwards if we find a
- a use of the true symbol in before we find the definition then
- we cannot */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if there is a function call and this is
- a parameter & not my parameter then don't pack it */
- if ( (dic->op == CALL || dic->op == PCALL) &&
- (OP_SYMBOL(IC_RESULT(ic))->_isparm &&
- !OP_SYMBOL(IC_RESULT(ic))->ismyparm)) {
- dic = NULL;
- break;
- }
- if (SKIP_IC2(dic))
- continue;
+ /* find the definition of iTempNN scanning backwards if we find a
+ a use of the true symbol in before we find the definition then
+ we cannot */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
- if (IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- IS_OP_VOLATILE(IC_RESULT(dic))) {
- dic = NULL;
- break;
+ /* if there is a function call and this is
+ a parameter & not my parameter then don't pack it */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ (OP_SYMBOL (IC_RESULT (ic))->_isparm &&
+ !OP_SYMBOL (IC_RESULT (ic))->ismyparm))
+ {
+ dic = NULL;
+ break;
}
- if (IS_SYMOP(IC_RESULT(dic)) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- if (POINTER_SET(dic))
- dic = NULL;
+ if (SKIP_IC2 (dic))
+ continue;
- break;
+ if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ IS_OP_VOLATILE (IC_RESULT (dic)))
+ {
+ dic = NULL;
+ break;
}
- if (IS_SYMOP(IC_RIGHT(dic)) &&
- (IC_RIGHT(dic)->key == IC_RESULT(ic)->key ||
- IC_RIGHT(dic)->key == IC_RIGHT(ic)->key)) {
+ if (IS_SYMOP (IC_RESULT (dic)) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ if (POINTER_SET (dic))
dic = NULL;
- break;
+
+ break;
}
-
- if (IS_SYMOP(IC_LEFT(dic)) &&
- (IC_LEFT(dic)->key == IC_RESULT(ic)->key ||
- IC_LEFT(dic)->key == IC_RIGHT(ic)->key)) {
- dic = NULL;
- break;
+
+ if (IS_SYMOP (IC_RIGHT (dic)) &&
+ (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
+ IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
}
- if (POINTER_SET(dic) &&
- IC_RESULT(dic)->key == IC_RESULT(ic)->key ) {
- dic = NULL ;
- break;
+ if (IS_SYMOP (IC_LEFT (dic)) &&
+ (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
+ IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
+ }
+
+ if (POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == IC_RESULT (ic)->key)
+ {
+ dic = NULL;
+ break;
}
}
-
- if (!dic)
- return 0 ; /* did not find */
-
- /* if the result is on stack or iaccess then it must be
- the same atleast one of the operands */
- if (OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess ) {
-
- /* the operation has only one symbol
- operator then we can pack */
- if ((IC_LEFT(dic) && !IS_SYMOP(IC_LEFT(dic))) ||
- (IC_RIGHT(dic) && !IS_SYMOP(IC_RIGHT(dic))))
- goto pack;
-
- if (!((IC_LEFT(dic) &&
- IC_RESULT(ic)->key == IC_LEFT(dic)->key) ||
- (IC_RIGHT(dic) &&
- IC_RESULT(ic)->key == IC_RIGHT(dic)->key)))
- return 0;
+
+ if (!dic)
+ return 0; /* did not find */
+
+ /* if the result is on stack or iaccess then it must be
+ the same atleast one of the operands */
+ if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess)
+ {
+
+ /* the operation has only one symbol
+ operator then we can pack */
+ if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
+ (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
+ goto pack;
+
+ if (!((IC_LEFT (dic) &&
+ IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
+ (IC_RIGHT (dic) &&
+ IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
+ return 0;
}
pack:
- /* if in far space & tru symbol then don't */
- if ((IS_TRUE_SYMOP(IC_RESULT(ic))) && isOperandInFarSpace(IC_RESULT(ic)))
- return 0;
- /* found the definition */
- /* replace the result with the result of */
- /* this assignment and remove this assignment */
- IC_RESULT(dic) = IC_RESULT(ic) ;
+ /* if in far space & tru symbol then don't */
+ if ((IS_TRUE_SYMOP (IC_RESULT (ic))) && isOperandInFarSpace (IC_RESULT (ic)))
+ return 0;
+ /* found the definition */
+ /* replace the result with the result of */
+ /* this assignment and remove this assignment */
+ IC_RESULT (dic) = IC_RESULT (ic);
- if (IS_ITEMP(IC_RESULT(dic)) && OP_SYMBOL(IC_RESULT(dic))->liveFrom > dic->seq) {
- OP_SYMBOL(IC_RESULT(dic))->liveFrom = dic->seq;
+ if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
+ {
+ OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
}
- /* delete from liverange table also
- delete from all the points inbetween and the new
- one */
- for ( sic = dic; sic != ic ; sic = sic->next ) {
- bitVectUnSetBit(sic->rlive,IC_RESULT(ic)->key);
- if (IS_ITEMP(IC_RESULT(dic)))
- bitVectSetBit(sic->rlive,IC_RESULT(dic)->key);
+ /* delete from liverange table also
+ delete from all the points inbetween and the new
+ one */
+ for (sic = dic; sic != ic; sic = sic->next)
+ {
+ bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
+ if (IS_ITEMP (IC_RESULT (dic)))
+ bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
}
-
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- return 1;
-
+
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ return 1;
+
}
/*-----------------------------------------------------------------*/
-/* findAssignToSym : scanning backwards looks for first assig found*/
+/* findAssignToSym : scanning backwards looks for first assig found */
/*-----------------------------------------------------------------*/
-static iCode *findAssignToSym (operand *op,iCode *ic)
+static iCode *
+findAssignToSym (operand * op, iCode * ic)
{
- iCode *dic;
-
- for (dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if definition by assignment */
- if (dic->op == '=' &&
- !POINTER_SET(dic) &&
- IC_RESULT(dic)->key == op->key
-/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
- ) {
-
- /* we are interested only if defined in far space */
- /* or in stack space in case of + & - */
-
- /* if assigned to a non-symbol then return
- true */
- if (!IS_SYMOP(IC_RIGHT(dic)))
- break ;
-
- /* if the symbol is in far space then
- we should not */
- if (isOperandInFarSpace(IC_RIGHT(dic)))
- return NULL ;
-
- /* for + & - operations make sure that
- if it is on the stack it is the same
- as one of the three operands */
- if ((ic->op == '+' || ic->op == '-') &&
- OP_SYMBOL(IC_RIGHT(dic))->onStack) {
-
- if ( IC_RESULT(ic)->key != IC_RIGHT(dic)->key &&
- IC_LEFT(ic)->key != IC_RIGHT(dic)->key &&
- IC_RIGHT(ic)->key != IC_RIGHT(dic)->key)
- return NULL;
- }
-
- break ;
-
- }
+ iCode *dic;
- /* if we find an usage then we cannot delete it */
- if (IC_LEFT(dic) && IC_LEFT(dic)->key == op->key)
- return NULL;
-
- if (IC_RIGHT(dic) && IC_RIGHT(dic)->key == op->key)
- return NULL;
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if definition by assignment */
+ if (dic->op == '=' &&
+ !POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == op->key
+/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
+ )
+ {
+
+ /* we are interested only if defined in far space */
+ /* or in stack space in case of + & - */
+
+ /* if assigned to a non-symbol then return
+ true */
+ if (!IS_SYMOP (IC_RIGHT (dic)))
+ break;
- if (POINTER_SET(dic) && IC_RESULT(dic)->key == op->key)
+ /* if the symbol is in far space then
+ we should not */
+ if (isOperandInFarSpace (IC_RIGHT (dic)))
return NULL;
- }
- /* now make sure that the right side of dic
- is not defined between ic & dic */
- if (dic) {
- iCode *sic = dic->next ;
+ /* for + & - operations make sure that
+ if it is on the stack it is the same
+ as one of the three operands */
+ if ((ic->op == '+' || ic->op == '-') &&
+ OP_SYMBOL (IC_RIGHT (dic))->onStack)
+ {
- for (; sic != ic ; sic = sic->next)
- if (IC_RESULT(sic) &&
- IC_RESULT(sic)->key == IC_RIGHT(dic)->key)
+ if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
return NULL;
+ }
+
+ break;
+
+ }
+
+ /* if we find an usage then we cannot delete it */
+ if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
+ return NULL;
+
+ if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
+ return NULL;
+
+ if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
+ return NULL;
}
- return dic;
-
-
+ /* now make sure that the right side of dic
+ is not defined between ic & dic */
+ if (dic)
+ {
+ iCode *sic = dic->next;
+
+ for (; sic != ic; sic = sic->next)
+ if (IC_RESULT (sic) &&
+ IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
+ return NULL;
+ }
+
+ return dic;
+
+
}
/*-----------------------------------------------------------------*/
/* packRegsForSupport :- reduce some registers for support calls */
/*-----------------------------------------------------------------*/
-static int packRegsForSupport (iCode *ic, eBBlock *ebp)
+static int
+packRegsForSupport (iCode * ic, eBBlock * ebp)
{
- int change = 0 ;
- /* for the left & right operand :- look to see if the
- left was assigned a true symbol in far space in that
- case replace them */
- if (IS_ITEMP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_LEFT(ic),ic);
- iCode *sic;
-
- if (!dic)
- goto right ;
-
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_LEFT(ic)->key);
-
- IC_LEFT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_LEFT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change++;
+ int change = 0;
+ /* for the left & right operand :- look to see if the
+ left was assigned a true symbol in far space in that
+ case replace them */
+ if (IS_ITEMP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ goto right;
+
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
+
+ IC_LEFT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- /* do the same for the right operand */
- right:
- if (!change &&
- IS_ITEMP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_RIGHT(ic),ic);
- iCode *sic;
-
- if (!dic)
- return change ;
-
- /* if this is a subtraction & the result
- is a true symbol in far space then don't pack */
- if (ic->op == '-' && IS_TRUE_SYMOP(IC_RESULT(dic))) {
- sym_link *etype =getSpec(operandType(IC_RESULT(dic)));
- if (IN_FARSPACE(SPEC_OCLS(etype)))
- return change ;
+
+ /* do the same for the right operand */
+right:
+ if (!change &&
+ IS_ITEMP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ return change;
+
+ /* if this is a subtraction & the result
+ is a true symbol in far space then don't pack */
+ if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
+ {
+ sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
+ if (IN_FARSPACE (SPEC_OCLS (etype)))
+ return change;
}
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_RIGHT(ic)->key);
-
- IC_RIGHT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_RIGHT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
-
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change ++;
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
+
+ IC_RIGHT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- return change ;
+
+ return change;
}
#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
/*-----------------------------------------------------------------*/
-/* packRegsForOneuse : - will reduce some registers for single Use */
+/* packRegsForOneuse : - will reduce some registers for single Use */
/*-----------------------------------------------------------------*/
-static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp)
+static iCode *
+packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
{
- bitVect *uses ;
- iCode *dic, *sic;
+ bitVect *uses;
+ iCode *dic, *sic;
- /* if returning a literal then do nothing */
- if (!IS_SYMOP(op))
- return NULL;
-
- /* returns only */
- if (ic->op != RETURN) return NULL;
-
- /* this routine will mark the a symbol as used in one
- instruction use only && if the defintion is local
- (ie. within the basic block) && has only one definition &&
- that definiion is either a return value from a
- function or does not contain any variables in
- far space */
- uses = bitVectCopy(OP_USES(op));
- bitVectUnSetBit(uses,ic->key); /* take away this iCode */
- if (!bitVectIsZero(uses)) /* has other uses */
- return NULL ;
-
- /* if it has only one defintion */
- if (bitVectnBitsOn(OP_DEFS(op)) > 1)
- return NULL ; /* has more than one definition */
-
- /* get the that definition */
- if (!(dic =
- hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(op)))))
- return NULL ;
-
- /* found the definition now check if it is local */
- if (dic->seq < ebp->fSeq ||
- dic->seq > ebp->lSeq)
- return NULL ; /* non-local */
-
- /* now check if it is the return from
- a function call */
- if (dic->op == CALL || dic->op == PCALL ) {
- if (ic->op != SEND && ic->op != RETURN) {
- OP_SYMBOL(op)->ruonly = 1;
- return dic;
+ /* if returning a literal then do nothing */
+ if (!IS_SYMOP (op))
+ return NULL;
+
+ /* returns only */
+ if (ic->op != RETURN)
+ return NULL;
+
+ /* this routine will mark the a symbol as used in one
+ instruction use only && if the defintion is local
+ (ie. within the basic block) && has only one definition &&
+ that definiion is either a return value from a
+ function or does not contain any variables in
+ far space */
+ uses = bitVectCopy (OP_USES (op));
+ bitVectUnSetBit (uses, ic->key); /* take away this iCode */
+ if (!bitVectIsZero (uses)) /* has other uses */
+ return NULL;
+
+ /* if it has only one defintion */
+ if (bitVectnBitsOn (OP_DEFS (op)) > 1)
+ return NULL; /* has more than one definition */
+
+ /* get the that definition */
+ if (!(dic =
+ hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (op)))))
+ return NULL;
+
+ /* found the definition now check if it is local */
+ if (dic->seq < ebp->fSeq ||
+ dic->seq > ebp->lSeq)
+ return NULL; /* non-local */
+
+ /* now check if it is the return from
+ a function call */
+ if (dic->op == CALL || dic->op == PCALL)
+ {
+ if (ic->op != SEND && ic->op != RETURN)
+ {
+ OP_SYMBOL (op)->ruonly = 1;
+ return dic;
}
- dic = dic->next ;
+ dic = dic->next;
}
-
-
- /* otherwise check that the definition does
- not contain any symbols in far space */
- if (IS_OP_RUONLY(IC_LEFT(ic)) ||
- IS_OP_RUONLY(IC_RIGHT(ic)) ) {
- return NULL;
+
+
+ /* otherwise check that the definition does
+ not contain any symbols in far space */
+ if (IS_OP_RUONLY (IC_LEFT (ic)) ||
+ IS_OP_RUONLY (IC_RIGHT (ic)))
+ {
+ return NULL;
}
-
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- sic = dic;
-
- /* also make sure the intervenening instructions
- don't have any thing in far space */
- for (dic = dic->next ; dic && dic != ic ; dic = dic->next) {
-
- /* if there is an intervening function call then no */
- if (dic->op == CALL || dic->op == PCALL)
- return NULL;
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- /* if address of & the result is remat the okay */
- if (dic->op == ADDRESS_OF &&
- OP_SYMBOL(IC_RESULT(dic))->remat)
- continue ;
-
- /* if operand has size of three or more & this
- operation is a '*','/' or '%' then 'b' may
- cause a problem */
- if (( dic->op == '%' || dic->op == '/' || dic->op == '*') &&
- getSize(operandType(op)) >= 3)
- return NULL;
- /* if left or right or result is in far space */
- if (IS_OP_RUONLY(IC_LEFT(dic)) ||
- IS_OP_RUONLY(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_RESULT(dic)) ) {
- return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ sic = dic;
+
+ /* also make sure the intervenening instructions
+ don't have any thing in far space */
+ for (dic = dic->next; dic && dic != ic; dic = dic->next)
+ {
+
+ /* if there is an intervening function call then no */
+ if (dic->op == CALL || dic->op == PCALL)
+ return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ /* if address of & the result is remat the okay */
+ if (dic->op == ADDRESS_OF &&
+ OP_SYMBOL (IC_RESULT (dic))->remat)
+ continue;
+
+ /* if operand has size of three or more & this
+ operation is a '*','/' or '%' then 'b' may
+ cause a problem */
+ if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
+ getSize (operandType (op)) >= 3)
+ return NULL;
+
+ /* if left or right or result is in far space */
+ if (IS_OP_RUONLY (IC_LEFT (dic)) ||
+ IS_OP_RUONLY (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_RESULT (dic)))
+ {
+ return NULL;
}
}
-
- OP_SYMBOL(op)->ruonly = 1;
- return sic;
-
+
+ OP_SYMBOL (op)->ruonly = 1;
+ return sic;
+
}
/*-----------------------------------------------------------------*/
/* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
/*-----------------------------------------------------------------*/
-static bool isBitwiseOptimizable (iCode *ic)
+static bool
+isBitwiseOptimizable (iCode * ic)
{
- sym_link *ltype = getSpec(operandType(IC_LEFT(ic)));
- sym_link *rtype = getSpec(operandType(IC_RIGHT(ic)));
-
- /* bitwise operations are considered optimizable
- under the following conditions (Jean-Louis VERN)
-
- x & lit
- bit & bit
- bit & x
- bit ^ bit
- bit ^ x
- x ^ lit
- x | lit
- bit | bit
- bit | x
- */
- if ( IS_LITERAL(rtype) ||
- (IS_BITVAR(ltype) && IN_BITSPACE(SPEC_OCLS(ltype))))
- return TRUE ;
- else
- return FALSE ;
+ sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
+ sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
+
+ /* bitwise operations are considered optimizable
+ under the following conditions (Jean-Louis VERN)
+
+ x & lit
+ bit & bit
+ bit & x
+ bit ^ bit
+ bit ^ x
+ x ^ lit
+ x | lit
+ bit | bit
+ bit | x
+ */
+ if (IS_LITERAL (rtype) ||
+ (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
+ return TRUE;
+ else
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* packForPush - hueristics to reduce iCode for pushing */
/*-----------------------------------------------------------------*/
-static void packForPush(iCode *ic, eBBlock *ebp)
+static void
+packForPush (iCode * ic, eBBlock * ebp)
{
- iCode *dic;
-
- if (ic->op != IPUSH || !IS_ITEMP(IC_LEFT(ic)))
- return ;
-
- /* must have only definition & one usage */
- if (bitVectnBitsOn(OP_DEFS(IC_LEFT(ic))) != 1 ||
- bitVectnBitsOn(OP_USES(IC_LEFT(ic))) != 1 )
- return ;
-
- /* find the definition */
- if (!(dic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(IC_LEFT(ic))))))
- return ;
-
- if (dic->op != '=' || POINTER_SET(dic))
- return;
-
- /* we now we know that it has one & only one def & use
- and the that the definition is an assignment */
- IC_LEFT(ic) = IC_RIGHT(dic);
-
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
+ iCode *dic;
+
+ if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
+ return;
+
+ /* must have only definition & one usage */
+ if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
+ bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
+ return;
+
+ /* find the definition */
+ if (!(dic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
+ return;
+
+ if (dic->op != '=' || POINTER_SET (dic))
+ return;
+
+ /* we now we know that it has one & only one def & use
+ and the that the definition is an assignment */
+ IC_LEFT (ic) = IC_RIGHT (dic);
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
}
/*-----------------------------------------------------------------*/
/* packRegisters - does some transformations to reduce register */
/* pressure */
/*-----------------------------------------------------------------*/
-static void packRegisters (eBBlock *ebp)
+static void
+packRegisters (eBBlock * ebp)
{
- iCode *ic ;
- int change = 0 ;
-
- while (1) {
-
- change = 0;
-
- /* look for assignments of the form */
- /* iTempNN = TRueSym (someoperation) SomeOperand */
- /* .... */
- /* TrueSym := iTempNN:1 */
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
-
- /* find assignment of the form TrueSym := iTempNN:1 */
- if (ic->op == '=' && !POINTER_SET(ic))
- change += packRegsForAssign(ic,ebp);
+ iCode *ic;
+ int change = 0;
+
+ while (1)
+ {
+
+ change = 0;
+
+ /* look for assignments of the form */
+ /* iTempNN = TRueSym (someoperation) SomeOperand */
+ /* .... */
+ /* TrueSym := iTempNN:1 */
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+
+ /* find assignment of the form TrueSym := iTempNN:1 */
+ if (ic->op == '=' && !POINTER_SET (ic))
+ change += packRegsForAssign (ic, ebp);
}
- if (!change)
- break;
+ if (!change)
+ break;
}
-
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
- /* if this is an itemp & result of a address of a true sym
- then mark this as rematerialisable */
- if (ic->op == ADDRESS_OF &&
- IS_ITEMP(IC_RESULT(ic)) &&
- IS_TRUE_SYMOP(IC_LEFT(ic)) &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- !OP_SYMBOL(IC_LEFT(ic))->onStack ) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an itemp & result of a address of a true sym
+ then mark this as rematerialisable */
+ if (ic->op == ADDRESS_OF &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ IS_TRUE_SYMOP (IC_LEFT (ic)) &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ !OP_SYMBOL (IC_LEFT (ic))->onStack)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
-
- /* if straight assignment then carry remat flag if
- this is the only definition */
- if (ic->op == '=' &&
- !POINTER_SET(ic) &&
- IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->remat &&
- bitVectnBitsOn(OP_SYMBOL(IC_RESULT(ic))->defs) <= 1) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat =
- OP_SYMBOL(IC_RIGHT(ic))->remat;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode =
- OP_SYMBOL(IC_RIGHT(ic))->rematiCode ;
+
+ /* if straight assignment then carry remat flag if
+ this is the only definition */
+ if (ic->op == '=' &&
+ !POINTER_SET (ic) &&
+ IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->remat &&
+ bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat =
+ OP_SYMBOL (IC_RIGHT (ic))->remat;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode =
+ OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
}
- /* if this is a +/- operation with a rematerizable
- then mark this as rematerializable as well only
- if the literal value is within the range -255 and + 255
- the assembler cannot handle it other wise */
- if ((ic->op == '+' || ic->op == '-') &&
-
- (IS_SYMOP(IC_LEFT(ic)) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->remat &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- IS_OP_LITERAL(IC_RIGHT(ic))) ) {
-
- int i = (int) operandLitValue(IC_RIGHT(ic));
- if ( i < 255 && i > -255) {
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+ /* if this is a +/- operation with a rematerizable
+ then mark this as rematerializable as well only
+ if the literal value is within the range -255 and + 255
+ the assembler cannot handle it other wise */
+ if ((ic->op == '+' || ic->op == '-') &&
+
+ (IS_SYMOP (IC_LEFT (ic)) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->remat &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ IS_OP_LITERAL (IC_RIGHT (ic))))
+ {
+
+ int i = (int) operandLitValue (IC_RIGHT (ic));
+ if (i < 255 && i > -255)
+ {
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
}
- /* mark the pointer usages */
- if (POINTER_SET(ic))
- OP_SYMBOL(IC_RESULT(ic))->uptr = 1;
-
- if (POINTER_GET(ic))
- OP_SYMBOL(IC_LEFT(ic))->uptr = 1;
-
- /* if the condition of an if instruction
- is defined in the previous instruction then
- mark the itemp as a conditional */
- if ((IS_CONDITIONAL(ic) ||
- ( ( ic->op == BITWISEAND ||
- ic->op == '|' ||
- ic->op == '^' ) &&
- isBitwiseOptimizable(ic))) &&
- ic->next && ic->next->op == IFX &&
- isOperandEqual(IC_RESULT(ic),IC_COND(ic->next)) &&
- OP_SYMBOL(IC_RESULT(ic))->liveTo <= ic->next->seq) {
-
- OP_SYMBOL(IC_RESULT(ic))->regType = REG_CND;
- continue ;
+ /* mark the pointer usages */
+ if (POINTER_SET (ic))
+ OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
+
+ if (POINTER_GET (ic))
+ OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
+
+ /* if the condition of an if instruction
+ is defined in the previous instruction then
+ mark the itemp as a conditional */
+ if ((IS_CONDITIONAL (ic) ||
+ ((ic->op == BITWISEAND ||
+ ic->op == '|' ||
+ ic->op == '^') &&
+ isBitwiseOptimizable (ic))) &&
+ ic->next && ic->next->op == IFX &&
+ isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
+ OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
+ continue;
}
-
- /* some cases the redundant moves can
- can be eliminated for return statements */
- if ((ic->op == RETURN || ic->op == SEND))
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
-
- /* if this is cast for intergral promotion then
- check if only use of the definition of the
- operand being casted/ if yes then replace
- the result of that arithmetic operation with
- this result and get rid of the cast */
- if (ic->op == CAST) {
- sym_link *fromType = operandType(IC_RIGHT(ic));
- sym_link *toType = operandType(IC_LEFT(ic));
-
- if (IS_INTEGRAL(fromType) && IS_INTEGRAL(toType) &&
- getSize(fromType) != getSize(toType) &&
- SPEC_USIGN(fromType) == SPEC_USIGN(toType)) {
-
- iCode *dic = packRegsForOneuse(ic,IC_RIGHT(ic),ebp);
- if (dic) {
- if (IS_ARITHMETIC_OP(dic)) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- ic = ic->prev;
- } else
- OP_SYMBOL(IC_RIGHT(ic))->ruonly = 0;
- }
- } else {
-
- /* if the type from and type to are the same
- then if this is the only use then packit */
- if (checkType(operandType(IC_RIGHT(ic)),
- operandType(IC_LEFT(ic))) == 1) {
- iCode *dic = packRegsForOneuse (ic,IC_RIGHT(ic),ebp);
- if (dic) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- ic = ic->prev;
+
+ /* some cases the redundant moves can
+ can be eliminated for return statements */
+ if ((ic->op == RETURN || ic->op == SEND))
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+
+ /* if this is cast for intergral promotion then
+ check if only use of the definition of the
+ operand being casted/ if yes then replace
+ the result of that arithmetic operation with
+ this result and get rid of the cast */
+ if (ic->op == CAST)
+ {
+ sym_link *fromType = operandType (IC_RIGHT (ic));
+ sym_link *toType = operandType (IC_LEFT (ic));
+
+ if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
+ getSize (fromType) != getSize (toType) &&
+ SPEC_USIGN (fromType) == SPEC_USIGN (toType))
+ {
+
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ if (IS_ARITHMETIC_OP (dic))
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ ic = ic->prev;
+ }
+ else
+ OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
+ }
+ }
+ else
+ {
+
+ /* if the type from and type to are the same
+ then if this is the only use then packit */
+ if (checkType (operandType (IC_RIGHT (ic)),
+ operandType (IC_LEFT (ic))) == 1)
+ {
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ ic = ic->prev;
}
}
}
/*-----------------------------------------------------------------*/
/* preAssignParms - we have a leaf function preassign registers */
/*-----------------------------------------------------------------*/
-static void preAssignParms (iCode *ic)
+static void
+preAssignParms (iCode * ic)
{
- int i = R16_IDX;
- /* look for receives and assign registers
- to the result of the receives */
- while (ic) {
- /* if it is a receive */
- if (ic->op == RECEIVE) {
- symbol *r = OP_SYMBOL(IC_RESULT(ic));
- int size = getSize(r->type);
- if (r->regType == REG_GPR || r->regType == REG_SCR) {
- int j = 0;
- while (size--) {
- r->regs[j++] = ®sAVR[i++];
- regsAVR[i-1].isFree = 0;
+ int i = R16_IDX;
+ /* look for receives and assign registers
+ to the result of the receives */
+ while (ic)
+ {
+ /* if it is a receive */
+ if (ic->op == RECEIVE)
+ {
+ symbol *r = OP_SYMBOL (IC_RESULT (ic));
+ int size = getSize (r->type);
+ if (r->regType == REG_GPR || r->regType == REG_SCR)
+ {
+ int j = 0;
+ while (size--)
+ {
+ r->regs[j++] = ®sAVR[i++];
+ regsAVR[i - 1].isFree = 0;
}
- /* put in the regassigned vector */
- _G.regAssigned = bitVectSetBit(_G.regAssigned,r->key);
- } else {
- /* not a GPR then we should mark as free */
- while (size--) {
- regsAVR[i++].isFree =1;
+ /* put in the regassigned vector */
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, r->key);
+ }
+ else
+ {
+ /* not a GPR then we should mark as free */
+ while (size--)
+ {
+ regsAVR[i++].isFree = 1;
}
}
}
- ic = ic->next;
+ ic = ic->next;
}
- /* mark anything remaining as free */
- while (i <= R23_IDX)
- regsAVR[i++].isFree =1;
+ /* mark anything remaining as free */
+ while (i <= R23_IDX)
+ regsAVR[i++].isFree = 1;
}
/*-----------------------------------------------------------------*/
/* setdefaultRegs - do setup stuff for register allocation */
/*-----------------------------------------------------------------*/
-static void setDefaultRegs(eBBlock **ebbs,int count)
+static void
+setDefaultRegs (eBBlock ** ebbs, int count)
{
- int i ;
-
- /* if no pointer registers required in this function
- then mark r26-27 & r30-r31 as GPR & free */
- regsAVR[R26_IDX].isFree =
- regsAVR[R27_IDX].isFree =
- regsAVR[R30_IDX].isFree =
- regsAVR[R31_IDX].isFree = 1;
-
- if (!avr_ptrRegReq) {
- regsAVR[R26_IDX].type =
- regsAVR[R27_IDX].type =
- regsAVR[R30_IDX].type =
- regsAVR[R31_IDX].type = REG_GPR ;
- } else {
- regsAVR[R26_IDX].type =
- regsAVR[R27_IDX].type =
- regsAVR[R30_IDX].type =
- regsAVR[R31_IDX].type = REG_PTR ;
+ int i;
+
+ /* if no pointer registers required in this function
+ then mark r26-27 & r30-r31 as GPR & free */
+ regsAVR[R26_IDX].isFree =
+ regsAVR[R27_IDX].isFree =
+ regsAVR[R30_IDX].isFree =
+ regsAVR[R31_IDX].isFree = 1;
+
+ if (!avr_ptrRegReq)
+ {
+ regsAVR[R26_IDX].type =
+ regsAVR[R27_IDX].type =
+ regsAVR[R30_IDX].type =
+ regsAVR[R31_IDX].type = REG_GPR;
+ }
+ else
+ {
+ regsAVR[R26_IDX].type =
+ regsAVR[R27_IDX].type =
+ regsAVR[R30_IDX].type =
+ regsAVR[R31_IDX].type = REG_PTR;
}
- /* registers 0-1 / 24-25 used as scratch */
- regsAVR[R0_IDX].isFree =
- regsAVR[R1_IDX].isFree =
- regsAVR[R24_IDX].isFree =
- regsAVR[R25_IDX].isFree = 0;
-
- /* if this has no function calls then we need
- to do something special
- a) pre-assign registers to parameters RECEIVE
- b) mark the remaining parameter regs as free */
- if (!currFunc->hasFcall) {
- /* mark the parameter regs as GPR */
- for (i= R16_IDX ; i <= R23_IDX ;i++) {
- regsAVR[i].type = REG_SCR;
- regsAVR[i].isFree = 1;
+ /* registers 0-1 / 24-25 used as scratch */
+ regsAVR[R0_IDX].isFree =
+ regsAVR[R1_IDX].isFree =
+ regsAVR[R24_IDX].isFree =
+ regsAVR[R25_IDX].isFree = 0;
+
+ /* if this has no function calls then we need
+ to do something special
+ a) pre-assign registers to parameters RECEIVE
+ b) mark the remaining parameter regs as free */
+ if (!currFunc->hasFcall)
+ {
+ /* mark the parameter regs as GPR */
+ for (i = R16_IDX; i <= R23_IDX; i++)
+ {
+ regsAVR[i].type = REG_SCR;
+ regsAVR[i].isFree = 1;
}
- preAssignParms(ebbs[0]->sch);
- } else {
+ preAssignParms (ebbs[0]->sch);
+ }
+ else
+ {
- /* otherwise mark them as free scratch */
- for (i= R16_IDX ; i <= R23_IDX ;i++) {
- regsAVR[i].type = REG_SCR;
- regsAVR[i].isFree = 1;
+ /* otherwise mark them as free scratch */
+ for (i = R16_IDX; i <= R23_IDX; i++)
+ {
+ regsAVR[i].type = REG_SCR;
+ regsAVR[i].isFree = 1;
}
}
- /* Y - is not allocated (it is the stack frame) */
- regsAVR[R28_IDX].isFree =
- regsAVR[R28_IDX].isFree =0;
+ /* Y - is not allocated (it is the stack frame) */
+ regsAVR[R28_IDX].isFree =
+ regsAVR[R28_IDX].isFree = 0;
}
-
+
/*-----------------------------------------------------------------*/
/* assignRegisters - assigns registers to each live range as need */
/*-----------------------------------------------------------------*/
-void avr_assignRegisters (eBBlock **ebbs, int count)
+void
+avr_assignRegisters (eBBlock ** ebbs, int count)
{
- iCode *ic;
- int i ;
-
- setToNull((void *)&_G.funcrUsed);
- avr_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
-
- /* change assignments this will remove some
- live ranges reducing some register pressure */
- for (i = 0 ; i < count ;i++ )
- packRegisters (ebbs[i]);
-
- if (options.dump_pack)
- dumpEbbsToFileExt(".dumppack",ebbs,count);
-
- /* first determine for each live range the number of
- registers & the type of registers required for each */
- regTypeNum ();
-
- /* setup the default registers */
- setDefaultRegs(ebbs,count);
-
- /* and serially allocate registers */
- serialRegAssign(ebbs,count);
-
- /* if stack was extended then tell the user */
- if (_G.stackExtend) {
-/* werror(W_TOOMANY_SPILS,"stack", */
-/* _G.stackExtend,currFunc->name,""); */
- _G.stackExtend = 0 ;
+ iCode *ic;
+ int i;
+
+ setToNull ((void *) &_G.funcrUsed);
+ avr_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
+
+ /* change assignments this will remove some
+ live ranges reducing some register pressure */
+ for (i = 0; i < count; i++)
+ packRegisters (ebbs[i]);
+
+ if (options.dump_pack)
+ dumpEbbsToFileExt (".dumppack", ebbs, count);
+
+ /* first determine for each live range the number of
+ registers & the type of registers required for each */
+ regTypeNum ();
+
+ /* setup the default registers */
+ setDefaultRegs (ebbs, count);
+
+ /* and serially allocate registers */
+ serialRegAssign (ebbs, count);
+
+ /* if stack was extended then tell the user */
+ if (_G.stackExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"stack", */
+/* _G.stackExtend,currFunc->name,""); */
+ _G.stackExtend = 0;
}
- if (_G.dataExtend) {
-/* werror(W_TOOMANY_SPILS,"data space", */
-/* _G.dataExtend,currFunc->name,""); */
- _G.dataExtend = 0 ;
- }
+ if (_G.dataExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"data space", */
+/* _G.dataExtend,currFunc->name,""); */
+ _G.dataExtend = 0;
+ }
- /* after that create the register mask
- for each of the instruction */
- createRegMask (ebbs,count);
+ /* after that create the register mask
+ for each of the instruction */
+ createRegMask (ebbs, count);
- /* redo that offsets for stacked automatic variables */
- redoStackOffsets ();
+ /* redo that offsets for stacked automatic variables */
+ redoStackOffsets ();
- if (options.dump_rassgn)
- dumpEbbsToFileExt(".dumprassgn",ebbs,count);
+ if (options.dump_rassgn)
+ dumpEbbsToFileExt (".dumprassgn", ebbs, count);
- /* now get back the chain */
- ic = iCodeLabelOptimize(iCodeFromeBBlock (ebbs,count));
+ /* now get back the chain */
+ ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
- genAVRCode(ic);
+ genAVRCode (ic);
/* for (; ic ; ic = ic->next) */
-/* piCode(ic,stdout); */
- /* free up any _G.stackSpil locations allocated */
- applyToSet(_G.stackSpil,deallocStackSpil);
- _G.slocNum = 0;
- setToNull((void **)&_G.stackSpil);
- setToNull((void **)&_G.spiltSet);
- /* mark all registers as free */
-
- return ;
+/* piCode(ic,stdout); */
+ /* free up any _G.stackSpil locations allocated */
+ applyToSet (_G.stackSpil, deallocStackSpil);
+ _G.slocNum = 0;
+ setToNull ((void **) &_G.stackSpil);
+ setToNull ((void **) &_G.spiltSet);
+ /* mark all registers as free */
+
+ return;
}
#ifndef SDCCRALLOC_H
#define SDCCRALLOC_H 1
-enum { R0_IDX = 0, R1_IDX , R2_IDX , R3_IDX , R4_IDX ,
- R5_IDX , R6_IDX , R7_IDX , R8_IDX , R9_IDX ,
- R10_IDX , R11_IDX, R12_IDX, R13_IDX, R14_IDX,
- R15_IDX , R16_IDX, R17_IDX, R18_IDX, R19_IDX,
- R20_IDX , R21_IDX, R22_IDX, R23_IDX, R24_IDX,
- R25_IDX , R26_IDX, R27_IDX, R28_IDX, R29_IDX,
- R30_IDX , R31_IDX, X_IDX , Z_IDX , CND_IDX };
+enum
+ {
+ R0_IDX = 0, R1_IDX, R2_IDX, R3_IDX, R4_IDX,
+ R5_IDX, R6_IDX, R7_IDX, R8_IDX, R9_IDX,
+ R10_IDX, R11_IDX, R12_IDX, R13_IDX, R14_IDX,
+ R15_IDX, R16_IDX, R17_IDX, R18_IDX, R19_IDX,
+ R20_IDX, R21_IDX, R22_IDX, R23_IDX, R24_IDX,
+ R25_IDX, R26_IDX, R27_IDX, R28_IDX, R29_IDX,
+ R30_IDX, R31_IDX, X_IDX, Z_IDX, CND_IDX
+ };
#define REG_PTR 0x01
/* definition for the registers */
typedef struct regs
-{
- short type; /* can have value
- REG_GPR, REG_PTR or REG_CND */
- short rIdx ; /* index into register table */
- short otype;
- char *name ; /* name */
- char *dname; /* name when direct access needed */
- char *base ; /* base address */
- short offset; /* offset from the base */
- unsigned isFree :1; /* is currently unassigned */
- unsigned saveReq:1; /* save required @ function entry ? */
-} regs;
+ {
+ short type; /* can have value
+ REG_GPR, REG_PTR or REG_CND */
+ short rIdx; /* index into register table */
+ short otype;
+ char *name; /* name */
+ char *dname; /* name when direct access needed */
+ char *base; /* base address */
+ short offset; /* offset from the base */
+ unsigned isFree:1; /* is currently unassigned */
+ unsigned saveReq:1; /* save required @ function entry ? */
+ }
+regs;
extern regs regsAVR[];
-regs *avr_regWithIdx (int);
+regs *avr_regWithIdx (int);
#endif
#endif
#endif
-char *aopLiteral (value *val, int offset);
+char *aopLiteral (value * val, int offset);
#if 0
//REMOVE ME!!!
extern int allocInfo;
routines may be reusable, will have to see */
static char *zero = "#0x00";
-static char *one = "#0x01";
-static char *spname ;
+static char *one = "#0x01";
+static char *spname;
#define D(x) x
-unsigned fReturnSize_390 = 5; /* shared with ralloc.c */
-static char *fReturn[] = {"dpl","dph","dpx", "b","a" };
-static char *accUse[] = {"a","b"};
+unsigned fReturnSize_390 = 5; /* shared with ralloc.c */
+static char *fReturn[] =
+{"dpl", "dph", "dpx", "b", "a"};
+static char *accUse[] =
+{"a", "b"};
static short rbank = -1;
-static struct {
+static struct
+ {
short r0Pushed;
short r1Pushed;
short accInUse;
short debugLine;
short nRegsSaved;
set *sendSet;
-} _G;
+ }
+_G;
-static void saverbank (int, iCode *,bool);
+static void saverbank (int, iCode *, bool);
#define RESULTONSTACK(x) \
(IC_RESULT(x) && IC_RESULT(x)->aop && \
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};
+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
/*-----------------------------------------------------------------*/
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
-static void emitcode (char *inst,char *fmt, ...)
+static void
+emitcode (char *inst, char *fmt,...)
{
- va_list ap;
- char lb[MAX_INLINEASM];
- char *lbp = lb;
+ va_list ap;
+ char lb[MAX_INLINEASM];
+ char *lbp = lb;
- va_start(ap,fmt);
+ va_start (ap, fmt);
- if (inst && *inst) {
- if (fmt && *fmt)
- sprintf(lb,"%s\t",inst);
+ if (inst && *inst)
+ {
+ if (fmt && *fmt)
+ sprintf (lb, "%s\t", inst);
+ else
+ sprintf (lb, "%s", inst);
+ vsprintf (lb + (strlen (lb)), fmt, ap);
+ }
else
- sprintf(lb,"%s",inst);
- vsprintf(lb+(strlen(lb)),fmt,ap);
- } else
- vsprintf(lb,fmt,ap);
+ vsprintf (lb, fmt, ap);
- while (isspace(*lbp)) lbp++;
+ while (isspace (*lbp))
+ lbp++;
- if (lbp && *lbp)
- lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(lb)) :
- (lineHead = newLineNode(lb)));
- lineCurr->isInline = _G.inLine;
- lineCurr->isDebug = _G.debugLine;
- va_end(ap);
+ if (lbp && *lbp)
+ lineCurr = (lineCurr ?
+ connectLine (lineCurr, newLineNode (lb)) :
+ (lineHead = newLineNode (lb)));
+ lineCurr->isInline = _G.inLine;
+ lineCurr->isDebug = _G.debugLine;
+ va_end (ap);
}
/*-----------------------------------------------------------------*/
-/* getFreePtr - returns r0 or r1 whichever is free or can be pushed*/
+/* getFreePtr - returns r0 or r1 whichever is free or can be pushed */
/*-----------------------------------------------------------------*/
-static regs *getFreePtr (iCode *ic, asmop **aopp, bool result)
+static regs *
+getFreePtr (iCode * ic, asmop ** aopp, bool result)
{
- bool r0iu = FALSE , r1iu = FALSE;
- bool r0ou = FALSE , r1ou = FALSE;
+ bool r0iu = FALSE, r1iu = FALSE;
+ bool r0ou = FALSE, r1ou = FALSE;
- /* the logic: if r0 & r1 used in the instruction
- then we are in trouble otherwise */
+ /* the logic: if r0 & r1 used in the instruction
+ then we are in trouble otherwise */
- /* 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)))
+ /* 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)))
{
- goto endOfWorld;
+ goto endOfWorld;
}
- r0ou = bitVectBitValue(ic->rMask,R0_IDX);
- r1ou = bitVectBitValue(ic->rMask,R1_IDX);
+ r0ou = bitVectBitValue (ic->rMask, R0_IDX);
+ r1ou = bitVectBitValue (ic->rMask, R1_IDX);
- /* if no usage of r0 then return it */
- if (!r0iu && !r0ou) {
- ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
- (*aopp)->type = AOP_R0;
+ /* if no usage of r0 then return it */
+ if (!r0iu && !r0ou)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
+ (*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = ds390_regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = ds390_regWithIdx (R0_IDX);
}
- /* if no usage of r1 then return it */
- if (!r1iu && !r1ou) {
- ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
- (*aopp)->type = AOP_R1;
+ /* if no usage of r1 then return it */
+ if (!r1iu && !r1ou)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
+ (*aopp)->type = AOP_R1;
- return (*aopp)->aopu.aop_ptr = ds390_regWithIdx(R1_IDX);
+ return (*aopp)->aopu.aop_ptr = ds390_regWithIdx (R1_IDX);
}
- /* now we know they both have usage */
- /* if r0 not used in this instruction */
- if (!r0iu) {
- /* push it if not already pushed */
- if (!_G.r0Pushed) {
- emitcode ("push","%s",
- ds390_regWithIdx(R0_IDX)->dname);
- _G.r0Pushed++ ;
- }
+ /* now we know they both have usage */
+ /* if r0 not used in this instruction */
+ if (!r0iu)
+ {
+ /* push it if not already pushed */
+ if (!_G.r0Pushed)
+ {
+ emitcode ("push", "%s",
+ ds390_regWithIdx (R0_IDX)->dname);
+ _G.r0Pushed++;
+ }
- ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
- (*aopp)->type = AOP_R0;
+ ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
+ (*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = ds390_regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = ds390_regWithIdx (R0_IDX);
}
- /* if r1 not used then */
+ /* if r1 not used then */
- if (!r1iu) {
- /* push it if not already pushed */
- if (!_G.r1Pushed) {
- emitcode ("push","%s",
- ds390_regWithIdx(R1_IDX)->dname);
- _G.r1Pushed++ ;
- }
-
- ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
- (*aopp)->type = AOP_R1;
- return ds390_regWithIdx(R1_IDX);
- }
-
-endOfWorld :
- /* I said end of world but not quite end of world yet */
- /* if this is a result then we can push it on the stack*/
- if (result) {
- (*aopp)->type = AOP_STK;
- return NULL;
+ if (!r1iu)
+ {
+ /* push it if not already pushed */
+ if (!_G.r1Pushed)
+ {
+ emitcode ("push", "%s",
+ ds390_regWithIdx (R1_IDX)->dname);
+ _G.r1Pushed++;
+ }
+
+ ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
+ (*aopp)->type = AOP_R1;
+ return ds390_regWithIdx (R1_IDX);
+ }
+
+endOfWorld:
+ /* I said end of world but not quite end of world yet */
+ /* if this is a result then we can push it on the stack */
+ if (result)
+ {
+ (*aopp)->type = AOP_STK;
+ 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");
- exit(1);
+ piCode (ic, stdout);
+ /* other wise this is true end of the world */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "getFreePtr should never reach here");
+ exit (1);
}
/*-----------------------------------------------------------------*/
/* newAsmop - creates a new asmOp */
/*-----------------------------------------------------------------*/
-static asmop *newAsmop (short type)
+static asmop *
+newAsmop (short type)
{
- asmop *aop;
+ asmop *aop;
- aop = Safe_calloc(1,sizeof(asmop));
- aop->type = type;
- return aop;
+ aop = Safe_calloc (1, sizeof (asmop));
+ aop->type = type;
+ return aop;
}
-static int _currentDPS; /* Current processor DPS. */
-static int _desiredDPS; /* DPS value compiler thinks we should be using. */
-static int _lazyDPS = 0; /* if non-zero, we are doing lazy evaluation of DPS changes. */
+static int _currentDPS; /* Current processor DPS. */
+static int _desiredDPS; /* DPS value compiler thinks we should be using. */
+static int _lazyDPS = 0; /* if non-zero, we are doing lazy evaluation of DPS changes. */
/*-----------------------------------------------------------------*/
/* genSetDPTR: generate code to select which DPTR is in use (zero */
/* selects standard DPTR (DPL/DPH/DPX), non-zero selects DS390 */
/* alternate DPTR (DPL1/DPH1/DPX1). */
/*-----------------------------------------------------------------*/
-static void genSetDPTR(int n)
+static void
+genSetDPTR (int n)
{
- /* If we are doing lazy evaluation, simply note the desired
- * change, but don't emit any code yet.
- */
- if (_lazyDPS)
+ /* If we are doing lazy evaluation, simply note the desired
+ * change, but don't emit any code yet.
+ */
+ if (_lazyDPS)
{
- _desiredDPS = n;
- return;
+ _desiredDPS = n;
+ return;
}
- if (!n)
+ if (!n)
{
- emitcode("mov", "dps, #0x00");
+ emitcode ("mov", "dps, #0x00");
}
- else
+ else
{
- emitcode("mov", "dps, #0x01");
+ emitcode ("mov", "dps, #0x01");
}
}
/*-----------------------------------------------------------------*/
-/* _startLazyDPSEvaluation: call to start doing lazy DPS evaluation*/
+/* _startLazyDPSEvaluation: call to start doing lazy DPS evaluation */
/* */
/* Any code that operates on DPTR (NB: not on the individual */
/* components, like DPH) *must* call _flushLazyDPS() before using */
/* Lazy DPS evaluation is simply an optimization (though an */
/* important one), so if in doubt, leave it out. */
/*-----------------------------------------------------------------*/
-static void _startLazyDPSEvaluation(void)
+static void
+_startLazyDPSEvaluation (void)
{
- _currentDPS = 0;
- _desiredDPS = 0;
- _lazyDPS = 1;
+ _currentDPS = 0;
+ _desiredDPS = 0;
+ _lazyDPS = 1;
}
/*-----------------------------------------------------------------*/
/* _flushLazyDPS: emit code to force the actual DPS setting to the */
-/* desired one. Call before using DPTR within a lazy DPS evaluation*/
+/* desired one. Call before using DPTR within a lazy DPS evaluation */
/* block. */
/*-----------------------------------------------------------------*/
-static void _flushLazyDPS(void)
+static void
+_flushLazyDPS (void)
{
- if (!_lazyDPS)
+ if (!_lazyDPS)
{
- /* nothing to do. */
- return;
+ /* nothing to do. */
+ return;
}
- if (_desiredDPS != _currentDPS)
+ if (_desiredDPS != _currentDPS)
{
if (_desiredDPS)
- {
- emitcode("inc", "dps");
- }
+ {
+ emitcode ("inc", "dps");
+ }
else
- {
- emitcode("dec", "dps");
- }
+ {
+ emitcode ("dec", "dps");
+ }
_currentDPS = _desiredDPS;
}
}
/* */
/* Forces us back to the safe state (standard DPTR selected). */
/*-----------------------------------------------------------------*/
-static void _endLazyDPSEvaluation(void)
+static void
+_endLazyDPSEvaluation (void)
{
- if (_currentDPS)
- {
- genSetDPTR(0);
- _flushLazyDPS();
- }
- _lazyDPS = 0;
- _currentDPS = 0;
- _desiredDPS = 0;
+ if (_currentDPS)
+ {
+ genSetDPTR (0);
+ _flushLazyDPS ();
+ }
+ _lazyDPS = 0;
+ _currentDPS = 0;
+ _desiredDPS = 0;
}
/*-----------------------------------------------------------------*/
/* pointerCode - returns the code for a pointer type */
/*-----------------------------------------------------------------*/
-static int pointerCode (sym_link *etype)
+static int
+pointerCode (sym_link * etype)
{
- return PTR_TYPE(SPEC_OCLS(etype));
+ return PTR_TYPE (SPEC_OCLS (etype));
}
/*-----------------------------------------------------------------*/
/* aopForSym - for a true symbol */
/*-----------------------------------------------------------------*/
-static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool useDP2)
-{
- asmop *aop;
- memmap *space= SPEC_OCLS(sym->etype);
-
- /* if already has one */
- if (sym->aop)
- return sym->aop;
-
- /* assign depending on the storage class */
- /* if it is on the stack or indirectly addressable */
- /* space we need to assign either r0 or r1 to it */
- if ((sym->onStack && !options.stack10bit) || sym->iaccess) {
- sym->aop = aop = newAsmop(0);
- aop->aopu.aop_ptr = getFreePtr(ic,&aop,result);
- aop->size = getSize(sym->type);
-
- /* now assign the address of the variable to
- the pointer register */
- if (aop->type != AOP_STK) {
-
- if (sym->onStack) {
- if ( _G.accInUse )
- emitcode("push","acc");
-
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",
- ((sym->stack < 0) ?
- ((char)(sym->stack - _G.nRegsSaved )) :
- ((char)sym->stack)) & 0xff);
- emitcode("mov","%s,a",
- aop->aopu.aop_ptr->name);
-
- if ( _G.accInUse )
- emitcode("pop","acc");
- } else
- emitcode("mov","%s,#%s",
- aop->aopu.aop_ptr->name,
- sym->rname);
- aop->paged = space->paged;
- } else
- aop->aopu.aop_stk = sym->stack;
- return aop;
- }
-
- if (sym->onStack && options.stack10bit)
- {
- /* It's on the 10 bit stack, which is located in
- * far data space.
- */
-
- if ( _G.accInUse )
- emitcode("push","acc");
-
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",
- ((sym->stack < 0) ?
- ((char)(sym->stack - _G.nRegsSaved )) :
- ((char)sym->stack)) & 0xff);
+static asmop *
+aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
+{
+ asmop *aop;
+ memmap *space = SPEC_OCLS (sym->etype);
- if (useDP2)
- {
- /* genSetDPTR(1); */
- emitcode ("mov","dpx1,#0x40");
- emitcode ("mov","dph1,#0x00");
- emitcode ("mov","dpl1, a");
- /* genSetDPTR(0); */
- }
- else
- {
- emitcode ("mov","dpx,#0x40");
- emitcode ("mov","dph,#0x00");
- emitcode ("mov","dpl, a");
- }
-
- if ( _G.accInUse )
- emitcode("pop","acc");
-
- sym->aop = aop = newAsmop((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
- aop->size = getSize(sym->type);
+ /* if already has one */
+ if (sym->aop)
+ return sym->aop;
+
+ /* assign depending on the storage class */
+ /* if it is on the stack or indirectly addressable */
+ /* space we need to assign either r0 or r1 to it */
+ if ((sym->onStack && !options.stack10bit) || sym->iaccess)
+ {
+ sym->aop = aop = newAsmop (0);
+ aop->aopu.aop_ptr = getFreePtr (ic, &aop, result);
+ aop->size = getSize (sym->type);
+
+ /* now assign the address of the variable to
+ the pointer register */
+ if (aop->type != AOP_STK)
+ {
+
+ if (sym->onStack)
+ {
+ if (_G.accInUse)
+ emitcode ("push", "acc");
+
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x",
+ ((sym->stack < 0) ?
+ ((char) (sym->stack - _G.nRegsSaved)) :
+ ((char) sym->stack)) & 0xff);
+ emitcode ("mov", "%s,a",
+ aop->aopu.aop_ptr->name);
+
+ if (_G.accInUse)
+ emitcode ("pop", "acc");
+ }
+ else
+ emitcode ("mov", "%s,#%s",
+ aop->aopu.aop_ptr->name,
+ sym->rname);
+ aop->paged = space->paged;
+ }
+ else
+ aop->aopu.aop_stk = sym->stack;
+ return aop;
+ }
+
+ if (sym->onStack && options.stack10bit)
+ {
+ /* It's on the 10 bit stack, which is located in
+ * far data space.
+ */
+
+ if (_G.accInUse)
+ emitcode ("push", "acc");
+
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x",
+ ((sym->stack < 0) ?
+ ((char) (sym->stack - _G.nRegsSaved)) :
+ ((char) sym->stack)) & 0xff);
+
+ if (useDP2)
+ {
+ /* genSetDPTR(1); */
+ emitcode ("mov", "dpx1,#0x40");
+ emitcode ("mov", "dph1,#0x00");
+ emitcode ("mov", "dpl1, a");
+ /* genSetDPTR(0); */
+ }
+ else
+ {
+ emitcode ("mov", "dpx,#0x40");
+ emitcode ("mov", "dph,#0x00");
+ emitcode ("mov", "dpl, a");
+ }
+
+ if (_G.accInUse)
+ emitcode ("pop", "acc");
+
+ sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
+ aop->size = getSize (sym->type);
return aop;
}
- /* if in bit space */
- if (IN_BITSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_CRY);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- return aop;
+ /* if in bit space */
+ if (IN_BITSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_CRY);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ return aop;
}
- /* if it is in direct space */
- if (IN_DIRSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_DIR);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- return aop;
+ /* if it is in direct space */
+ if (IN_DIRSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_DIR);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ return aop;
}
- /* special case for a function */
- if (IS_FUNC(sym->type)) {
- sym->aop = aop = newAsmop(AOP_IMMD);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(sym->rname)+1);
- strcpy(aop->aopu.aop_immd,sym->rname);
- aop->size = FPTRSIZE;
- return aop;
+ /* special case for a function */
+ if (IS_FUNC (sym->type))
+ {
+ sym->aop = aop = newAsmop (AOP_IMMD);
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (sym->rname) + 1);
+ strcpy (aop->aopu.aop_immd, sym->rname);
+ aop->size = FPTRSIZE;
+ return aop;
}
- /* only remaining is far space */
- /* in which case DPTR gets the address */
- sym->aop = aop = newAsmop((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
- if (useDP2)
+ /* only remaining is far space */
+ /* in which case DPTR gets the address */
+ sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
+ if (useDP2)
{
- genSetDPTR(1);
- _flushLazyDPS();
- emitcode ("mov","dptr,#%s", sym->rname);
- genSetDPTR(0);
+ genSetDPTR (1);
+ _flushLazyDPS ();
+ emitcode ("mov", "dptr,#%s", sym->rname);
+ genSetDPTR (0);
}
- else
+ else
{
- emitcode ("mov","dptr,#%s", sym->rname);
+ emitcode ("mov", "dptr,#%s", sym->rname);
}
- aop->size = getSize(sym->type);
+ aop->size = getSize (sym->type);
- /* if it is in code space */
- if (IN_CODESPACE(space))
- aop->code = 1;
+ /* if it is in code space */
+ if (IN_CODESPACE (space))
+ aop->code = 1;
- return aop;
+ return aop;
}
/*-----------------------------------------------------------------*/
/* aopForRemat - rematerialzes an object */
/*-----------------------------------------------------------------*/
-static asmop *aopForRemat (symbol *sym)
+static asmop *
+aopForRemat (symbol * sym)
{
- iCode *ic = sym->rematiCode;
- asmop *aop = newAsmop(AOP_IMMD);
+ iCode *ic = sym->rematiCode;
+ asmop *aop = newAsmop (AOP_IMMD);
- int val = 0;
+ int val = 0;
- for (;;) {
+ for (;;)
+ {
if (ic->op == '+')
- val += (int) operandLitValue(IC_RIGHT(ic));
- else if (ic->op == '-')
- val -= (int) operandLitValue(IC_RIGHT(ic));
- else
- break;
+ val += (int) operandLitValue (IC_RIGHT (ic));
+ else if (ic->op == '-')
+ val -= (int) operandLitValue (IC_RIGHT (ic));
+ else
+ break;
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
}
- if (val)
- sprintf(buffer,"(%s %c 0x%04x)",
- OP_SYMBOL(IC_LEFT(ic))->rname,
- val >= 0 ? '+' : '-',
- abs(val) & 0xffff);
- else
- strcpy(buffer,OP_SYMBOL(IC_LEFT(ic))->rname);
+ if (val)
+ sprintf (buffer, "(%s %c 0x%04x)",
+ OP_SYMBOL (IC_LEFT (ic))->rname,
+ val >= 0 ? '+' : '-',
+ abs (val) & 0xffff);
+ else
+ strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(buffer)+1);
- strcpy(aop->aopu.aop_immd,buffer);
- return aop;
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (buffer) + 1);
+ strcpy (aop->aopu.aop_immd, buffer);
+ return aop;
}
/*-----------------------------------------------------------------*/
/* regsInCommon - two operands have some registers in common */
/*-----------------------------------------------------------------*/
-static bool regsInCommon (operand *op1, operand *op2)
+static bool
+regsInCommon (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
- int i;
+ symbol *sym1, *sym2;
+ int i;
- /* if they have registers in common */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE ;
+ /* if they have registers in common */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- if (sym1->nRegs == 0 || sym2->nRegs == 0)
- return FALSE ;
+ if (sym1->nRegs == 0 || sym2->nRegs == 0)
+ return FALSE;
- for (i = 0 ; i < sym1->nRegs ; i++) {
- int j;
- if (!sym1->regs[i])
- continue ;
+ for (i = 0; i < sym1->nRegs; i++)
+ {
+ int j;
+ if (!sym1->regs[i])
+ continue;
- for (j = 0 ; j < sym2->nRegs ;j++ ) {
- if (!sym2->regs[j])
- continue ;
+ for (j = 0; j < sym2->nRegs; j++)
+ {
+ if (!sym2->regs[j])
+ continue;
- if (sym2->regs[j] == sym1->regs[i])
- return TRUE ;
- }
+ if (sym2->regs[j] == sym1->regs[i])
+ return TRUE;
+ }
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* operandsEqu - equivalent */
/*-----------------------------------------------------------------*/
-static bool operandsEqu ( operand *op1, operand *op2)
+static bool
+operandsEqu (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
+ symbol *sym1, *sym2;
- /* if they not symbols */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE;
+ /* if they not symbols */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- /* if both are itemps & one is spilt
- and the other is not then false */
- if (IS_ITEMP(op1) && IS_ITEMP(op2) &&
- sym1->isspilt != sym2->isspilt )
- return FALSE ;
+ /* if both are itemps & one is spilt
+ and the other is not then false */
+ if (IS_ITEMP (op1) && IS_ITEMP (op2) &&
+ sym1->isspilt != sym2->isspilt)
+ return FALSE;
- /* if they are the same */
- if (sym1 == sym2)
- return TRUE ;
+ /* if they are the same */
+ if (sym1 == sym2)
+ return TRUE;
- if (strcmp(sym1->rname,sym2->rname) == 0)
- return TRUE;
+ if (strcmp (sym1->rname, sym2->rname) == 0)
+ return TRUE;
- /* if left is a tmp & right is not */
- if (IS_ITEMP(op1) &&
- !IS_ITEMP(op2) &&
- sym1->isspilt &&
- (sym1->usl.spillLoc == sym2))
- return TRUE;
+ /* if left is a tmp & right is not */
+ if (IS_ITEMP (op1) &&
+ !IS_ITEMP (op2) &&
+ sym1->isspilt &&
+ (sym1->usl.spillLoc == sym2))
+ return TRUE;
- if (IS_ITEMP(op2) &&
- !IS_ITEMP(op1) &&
- sym2->isspilt &&
- sym1->level > 0 &&
- (sym2->usl.spillLoc == sym1))
- return TRUE ;
+ if (IS_ITEMP (op2) &&
+ !IS_ITEMP (op1) &&
+ sym2->isspilt &&
+ sym1->level > 0 &&
+ (sym2->usl.spillLoc == sym1))
+ return TRUE;
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* sameRegs - two asmops have the same registers */
/*-----------------------------------------------------------------*/
-static bool sameRegs (asmop *aop1, asmop *aop2 )
+static bool
+sameRegs (asmop * aop1, asmop * aop2)
{
- int i;
+ int i;
- if (aop1 == aop2)
+ if (aop1 == aop2)
{
- if (aop1->type == AOP_DPTR || aop1->type == AOP_DPTR2)
- {
- return FALSE;
- }
- return TRUE ;
+ if (aop1->type == AOP_DPTR || aop1->type == AOP_DPTR2)
+ {
+ return FALSE;
+ }
+ return TRUE;
}
- if (aop1->type != AOP_REG ||
- aop2->type != AOP_REG )
- return FALSE ;
+ if (aop1->type != AOP_REG ||
+ aop2->type != AOP_REG)
+ return FALSE;
- if (aop1->size != aop2->size )
- return FALSE ;
+ if (aop1->size != aop2->size)
+ return FALSE;
- for (i = 0 ; i < aop1->size ; i++ )
- if (aop1->aopu.aop_reg[i] !=
- aop2->aopu.aop_reg[i] )
- return FALSE ;
+ for (i = 0; i < aop1->size; i++)
+ if (aop1->aopu.aop_reg[i] !=
+ aop2->aopu.aop_reg[i])
+ return FALSE;
- return TRUE ;
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* aopOp - allocates an asmop for an operand : */
/*-----------------------------------------------------------------*/
-static void aopOp (operand *op, iCode *ic, bool result, bool useDP2)
+static void
+aopOp (operand * op, iCode * ic, bool result, bool useDP2)
{
- asmop *aop;
- symbol *sym;
- int i;
+ asmop *aop;
+ symbol *sym;
+ int i;
- if (!op)
- return ;
+ if (!op)
+ return;
- /* if this a literal */
- if (IS_OP_LITERAL(op)) {
- op->aop = aop = newAsmop(AOP_LIT);
- aop->aopu.aop_lit = op->operand.valOperand;
- aop->size = getSize(operandType(op));
- return;
+ /* if this a literal */
+ if (IS_OP_LITERAL (op))
+ {
+ op->aop = aop = newAsmop (AOP_LIT);
+ aop->aopu.aop_lit = op->operand.valOperand;
+ aop->size = getSize (operandType (op));
+ return;
}
- /* if already has a asmop then continue */
- if (op->aop)
- return ;
+ /* if already has a asmop then continue */
+ if (op->aop)
+ return;
- /* if the underlying symbol has a aop */
- if (IS_SYMOP(op) && OP_SYMBOL(op)->aop) {
- op->aop = OP_SYMBOL(op)->aop;
- return;
+ /* if the underlying symbol has a aop */
+ if (IS_SYMOP (op) && OP_SYMBOL (op)->aop)
+ {
+ op->aop = OP_SYMBOL (op)->aop;
+ return;
}
- /* if this is a true symbol */
- if (IS_TRUE_SYMOP(op)) {
- op->aop = aopForSym(ic,OP_SYMBOL(op),result, useDP2);
- return ;
+ /* if this is a true symbol */
+ if (IS_TRUE_SYMOP (op))
+ {
+ op->aop = aopForSym (ic, OP_SYMBOL (op), result, useDP2);
+ return;
}
- /* this is a temporary : this has
- only four choices :
- a) register
- b) spillocation
- c) rematerialize
- d) conditional
- e) can be a return use only */
+ /* this is a temporary : this has
+ only four choices :
+ a) register
+ b) spillocation
+ c) rematerialize
+ d) conditional
+ e) can be a return use only */
- sym = OP_SYMBOL(op);
+ sym = OP_SYMBOL (op);
- /* if the type is a conditional */
- if (sym->regType == REG_CND) {
- aop = op->aop = sym->aop = newAsmop(AOP_CRY);
- aop->size = 0;
- return;
+ /* if the type is a conditional */
+ if (sym->regType == REG_CND)
+ {
+ aop = op->aop = sym->aop = newAsmop (AOP_CRY);
+ aop->size = 0;
+ return;
}
- /* if it is spilt then two situations
- a) is rematerialize
- b) has a spill location */
- if (sym->isspilt || sym->nRegs == 0) {
-
- /* rematerialize it NOW */
- if (sym->remat) {
- sym->aop = op->aop = aop =
- aopForRemat (sym);
- aop->size = getSize(sym->type);
- return;
- }
-
- if (sym->accuse) {
- int i;
- aop = op->aop = sym->aop = newAsmop(AOP_ACC);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < 2 ; i++ )
- aop->aopu.aop_str[i] = accUse[i];
- return;
- }
-
- if (sym->ruonly) {
- int i;
-
- if (useDP2)
- {
- /* a AOP_STR uses DPTR, but DPTR is already in use;
- * we're just hosed.
- */
- fprintf(stderr, "*** Internal error: AOP_STR with DPTR in use!\n");
- }
-
- aop = op->aop = sym->aop = newAsmop(AOP_STR);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < (int) fReturnSize_390 ; i++ )
- aop->aopu.aop_str[i] = fReturn[i];
- return;
- }
-
- /* else spill location */
- sym->aop = op->aop = aop =
- aopForSym(ic,sym->usl.spillLoc,result, useDP2);
- aop->size = getSize(sym->type);
- return;
- }
+ /* if it is spilt then two situations
+ a) is rematerialize
+ b) has a spill location */
+ if (sym->isspilt || sym->nRegs == 0)
+ {
- /* must be in a register */
- sym->aop = op->aop = aop = newAsmop(AOP_REG);
- aop->size = sym->nRegs;
- for ( i = 0 ; i < sym->nRegs ;i++)
- aop->aopu.aop_reg[i] = sym->regs[i];
+ /* rematerialize it NOW */
+ if (sym->remat)
+ {
+ sym->aop = op->aop = aop =
+ aopForRemat (sym);
+ aop->size = getSize (sym->type);
+ return;
+ }
+
+ if (sym->accuse)
+ {
+ int i;
+ aop = op->aop = sym->aop = newAsmop (AOP_ACC);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < 2; i++)
+ aop->aopu.aop_str[i] = accUse[i];
+ return;
+ }
+
+ if (sym->ruonly)
+ {
+ int i;
+
+ if (useDP2)
+ {
+ /* a AOP_STR uses DPTR, but DPTR is already in use;
+ * we're just hosed.
+ */
+ fprintf (stderr, "*** Internal error: AOP_STR with DPTR in use!\n");
+ }
+
+ aop = op->aop = sym->aop = newAsmop (AOP_STR);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < (int) fReturnSize_390; i++)
+ aop->aopu.aop_str[i] = fReturn[i];
+ return;
+ }
+
+ /* else spill location */
+ sym->aop = op->aop = aop =
+ aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+ aop->size = getSize (sym->type);
+ return;
+ }
+
+ /* must be in a register */
+ sym->aop = op->aop = aop = newAsmop (AOP_REG);
+ aop->size = sym->nRegs;
+ for (i = 0; i < sym->nRegs; i++)
+ aop->aopu.aop_reg[i] = sym->regs[i];
}
/*-----------------------------------------------------------------*/
/* freeAsmop - free up the asmop given to an operand */
/*----------------------------------------------------------------*/
-static void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
+static void
+freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
{
- asmop *aop ;
+ asmop *aop;
- if (!op)
- aop = aaop;
- else
- aop = op->aop;
+ if (!op)
+ aop = aaop;
+ else
+ aop = op->aop;
- if (!aop)
- return ;
+ if (!aop)
+ return;
- if (aop->freed)
- goto dealloc;
+ if (aop->freed)
+ goto dealloc;
- aop->freed = 1;
+ aop->freed = 1;
- /* depending on the asmop type only three cases need work AOP_RO
- , AOP_R1 && AOP_STK */
- switch (aop->type) {
- case AOP_R0 :
- if (_G.r0Pushed ) {
- if (pop) {
- emitcode ("pop","ar0");
- _G.r0Pushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,R0_IDX);
- break;
-
- case AOP_R1 :
- if (_G.r1Pushed ) {
- if (pop) {
- emitcode ("pop","ar1");
- _G.r1Pushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,R1_IDX);
- break;
-
- case AOP_STK :
- {
- int sz = aop->size;
- int stk = aop->aopu.aop_stk + aop->size;
- bitVectUnSetBit(ic->rUsed,R0_IDX);
- bitVectUnSetBit(ic->rUsed,R1_IDX);
-
- getFreePtr(ic,&aop,FALSE);
-
- if (options.stack10bit)
- {
- /* I'm not sure what to do here yet... */
- /* #STUB */
- fprintf(stderr,
- "*** Warning: probably generating bad code for "
- "10 bit stack mode.\n");
- }
-
- if (stk) {
- emitcode ("mov","a,_bp");
- emitcode ("add","a,#0x%02x",((char)stk) & 0xff);
- emitcode ("mov","%s,a",aop->aopu.aop_ptr->name);
- } else {
- emitcode ("mov","%s,_bp",aop->aopu.aop_ptr->name);
- }
-
- while (sz--) {
- emitcode("pop","acc");
- emitcode("mov","@%s,a",aop->aopu.aop_ptr->name);
- if (!sz) break;
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- }
- op->aop = aop;
- freeAsmop(op,NULL,ic,TRUE);
- if (_G.r0Pushed) {
- emitcode("pop","ar0");
- _G.r0Pushed--;
- }
-
- if (_G.r1Pushed) {
- emitcode("pop","ar1");
- _G.r1Pushed--;
- }
- }
+ /* depending on the asmop type only three cases need work AOP_RO
+ , AOP_R1 && AOP_STK */
+ switch (aop->type)
+ {
+ case AOP_R0:
+ if (_G.r0Pushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "ar0");
+ _G.r0Pushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, R0_IDX);
+ break;
+
+ case AOP_R1:
+ if (_G.r1Pushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "ar1");
+ _G.r1Pushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, R1_IDX);
+ break;
+
+ case AOP_STK:
+ {
+ int sz = aop->size;
+ int stk = aop->aopu.aop_stk + aop->size;
+ bitVectUnSetBit (ic->rUsed, R0_IDX);
+ bitVectUnSetBit (ic->rUsed, R1_IDX);
+
+ getFreePtr (ic, &aop, FALSE);
+
+ if (options.stack10bit)
+ {
+ /* I'm not sure what to do here yet... */
+ /* #STUB */
+ fprintf (stderr,
+ "*** Warning: probably generating bad code for "
+ "10 bit stack mode.\n");
+ }
+
+ if (stk)
+ {
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x", ((char) stk) & 0xff);
+ emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name);
+ }
+ else
+ {
+ emitcode ("mov", "%s,_bp", aop->aopu.aop_ptr->name);
+ }
+
+ while (sz--)
+ {
+ emitcode ("pop", "acc");
+ emitcode ("mov", "@%s,a", aop->aopu.aop_ptr->name);
+ if (!sz)
+ break;
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ }
+ op->aop = aop;
+ freeAsmop (op, NULL, ic, TRUE);
+ if (_G.r0Pushed)
+ {
+ emitcode ("pop", "ar0");
+ _G.r0Pushed--;
+ }
+
+ if (_G.r1Pushed)
+ {
+ emitcode ("pop", "ar1");
+ _G.r1Pushed--;
+ }
+ }
}
dealloc:
- /* all other cases just dealloc */
- if (op ) {
- op->aop = NULL;
- if (IS_SYMOP(op)) {
- OP_SYMBOL(op)->aop = NULL;
- /* if the symbol has a spill */
- if (SPIL_LOC(op))
- SPIL_LOC(op)->aop = NULL;
- }
+ /* all other cases just dealloc */
+ if (op)
+ {
+ op->aop = NULL;
+ if (IS_SYMOP (op))
+ {
+ OP_SYMBOL (op)->aop = NULL;
+ /* if the symbol has a spill */
+ if (SPIL_LOC (op))
+ SPIL_LOC (op)->aop = NULL;
+ }
}
}
/* aopGet - for fetching value of the aop */
/* */
/* Set canClobberACC if you are aure it is OK to clobber the value */
-/* in the accumulator. Set it FALSE otherwise; FALSE is always safe,*/
+/* in the accumulator. Set it FALSE otherwise; FALSE is always safe, */
/* just less efficient. */
/*------------------------------------------------------------------*/
-static char *aopGet (asmop *aop,
- int offset,
- bool bit16,
- bool dname,
- bool canClobberACC)
+static char *
+aopGet (asmop * aop,
+ int offset,
+ bool bit16,
+ bool dname,
+ bool canClobberACC)
{
- char *s = buffer ;
- char *rs;
+ char *s = buffer;
+ char *rs;
- /* offset is greater than
- size then zero */
- if (offset > (aop->size - 1) &&
- aop->type != AOP_LIT)
- return zero;
+ /* offset is greater than
+ size then zero */
+ if (offset > (aop->size - 1) &&
+ aop->type != AOP_LIT)
+ return zero;
- /* depending on type */
- switch (aop->type) {
+ /* depending on type */
+ switch (aop->type)
+ {
case AOP_R0:
case AOP_R1:
- /* if we need to increment it */
- while (offset > aop->coff) {
- emitcode ("inc","%s",aop->aopu.aop_ptr->name);
- aop->coff++;
- }
-
- while (offset < aop->coff) {
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- aop->coff--;
- }
-
- aop->coff = offset ;
- if (aop->paged) {
- emitcode("movx","a,@%s",aop->aopu.aop_ptr->name);
- return (dname ? "acc" : "a");
- }
- sprintf(s,"@%s",aop->aopu.aop_ptr->name);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ /* if we need to increment it */
+ while (offset > aop->coff)
+ {
+ emitcode ("inc", "%s", aop->aopu.aop_ptr->name);
+ aop->coff++;
+ }
+
+ while (offset < aop->coff)
+ {
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ aop->coff--;
+ }
+
+ aop->coff = offset;
+ if (aop->paged)
+ {
+ emitcode ("movx", "a,@%s", aop->aopu.aop_ptr->name);
+ return (dname ? "acc" : "a");
+ }
+ sprintf (s, "@%s", aop->aopu.aop_ptr->name);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_DPTR:
case AOP_DPTR2:
if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
-
- if (!canClobberACC)
- {
- emitcode("xch", "a, ap");
- }
- }
-
- _flushLazyDPS();
-
- while (offset > aop->coff) {
- emitcode ("inc","dptr");
- aop->coff++;
- }
-
- while (offset < aop->coff) {
- emitcode("lcall","__decdptr");
- aop->coff--;
- }
-
- aop->coff = offset;
- if (aop->code) {
- emitcode("clr","a");
- emitcode("movc","a,@a+dptr");
- }
- else {
- emitcode("movx","a,@dptr");
- }
+ {
+ genSetDPTR (1);
+
+ if (!canClobberACC)
+ {
+ emitcode ("xch", "a, ap");
+ }
+ }
+
+ _flushLazyDPS ();
+
+ while (offset > aop->coff)
+ {
+ emitcode ("inc", "dptr");
+ aop->coff++;
+ }
+
+ while (offset < aop->coff)
+ {
+ emitcode ("lcall", "__decdptr");
+ aop->coff--;
+ }
+
+ aop->coff = offset;
+ if (aop->code)
+ {
+ emitcode ("clr", "a");
+ emitcode ("movc", "a,@a+dptr");
+ }
+ else
+ {
+ emitcode ("movx", "a,@dptr");
+ }
if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
+ {
+ genSetDPTR (0);
- if (!canClobberACC)
- {
- emitcode("xch", "a, ap");
- return "ap";
- }
- }
+ if (!canClobberACC)
+ {
+ emitcode ("xch", "a, ap");
+ return "ap";
+ }
+ }
return (dname ? "acc" : "a");
case AOP_IMMD:
- if (bit16)
- sprintf (s,"#%s",aop->aopu.aop_immd);
- else
- if (offset)
- sprintf(s,"#(%s >> %d)",
- aop->aopu.aop_immd,
- offset*8);
+ if (bit16)
+ sprintf (s, "#%s", aop->aopu.aop_immd);
+ else if (offset)
+ sprintf (s, "#(%s >> %d)",
+ aop->aopu.aop_immd,
+ offset * 8);
else
- sprintf(s,"#%s",
- aop->aopu.aop_immd);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ sprintf (s, "#%s",
+ aop->aopu.aop_immd);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_DIR:
- if (offset)
- sprintf(s,"(%s + %d)",
- aop->aopu.aop_dir,
- offset);
- else
- sprintf(s,"%s",aop->aopu.aop_dir);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ if (offset)
+ sprintf (s, "(%s + %d)",
+ aop->aopu.aop_dir,
+ offset);
+ else
+ sprintf (s, "%s", aop->aopu.aop_dir);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_REG:
- if (dname)
- return aop->aopu.aop_reg[offset]->dname;
- else
- return aop->aopu.aop_reg[offset]->name;
+ if (dname)
+ return aop->aopu.aop_reg[offset]->dname;
+ else
+ return aop->aopu.aop_reg[offset]->name;
case AOP_CRY:
- emitcode("clr","a");
- emitcode("mov","c,%s",aop->aopu.aop_dir);
- emitcode("rlc","a") ;
- return (dname ? "acc" : "a");
+ emitcode ("clr", "a");
+ emitcode ("mov", "c,%s", aop->aopu.aop_dir);
+ emitcode ("rlc", "a");
+ return (dname ? "acc" : "a");
case AOP_ACC:
- if (!offset && dname)
- return "acc";
- return aop->aopu.aop_str[offset];
+ if (!offset && dname)
+ return "acc";
+ return aop->aopu.aop_str[offset];
case AOP_LIT:
- return aopLiteral (aop->aopu.aop_lit,offset);
+ return aopLiteral (aop->aopu.aop_lit, offset);
case AOP_STR:
- aop->coff = offset ;
- if (strcmp(aop->aopu.aop_str[offset],"a") == 0 &&
- dname)
- return "acc";
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], "a") == 0 &&
+ dname)
+ return "acc";
- return aop->aopu.aop_str[offset];
+ return aop->aopu.aop_str[offset];
}
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopget got unsupported aop->type");
- exit(1);
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopget got unsupported aop->type");
+ exit (1);
}
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop */
/*-----------------------------------------------------------------*/
-static void aopPut (asmop *aop, char *s, int offset)
+static void
+aopPut (asmop * aop, char *s, int offset)
{
- char *d = buffer ;
- symbol *lbl ;
+ char *d = buffer;
+ symbol *lbl;
- if (aop->size && offset > ( aop->size - 1)) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got offset > aop->size");
- exit(1);
+ if (aop->size && offset > (aop->size - 1))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got offset > aop->size");
+ exit (1);
}
- /* will assign value to value */
- /* depending on where it is ofcourse */
- switch (aop->type) {
+ /* will assign value to value */
+ /* depending on where it is ofcourse */
+ switch (aop->type)
+ {
case AOP_DIR:
- if (offset)
- sprintf(d,"(%s + %d)",
- aop->aopu.aop_dir,offset);
- else
- sprintf(d,"%s",aop->aopu.aop_dir);
+ if (offset)
+ sprintf (d, "(%s + %d)",
+ aop->aopu.aop_dir, offset);
+ else
+ sprintf (d, "%s", aop->aopu.aop_dir);
- if (strcmp(d,s))
- emitcode("mov","%s,%s",d,s);
+ if (strcmp (d, s))
+ emitcode ("mov", "%s,%s", d, s);
- break;
+ break;
case AOP_REG:
- if (strcmp(aop->aopu.aop_reg[offset]->name,s) != 0 &&
- strcmp(aop->aopu.aop_reg[offset]->dname,s)!= 0){
- if (*s == '@' ||
- strcmp(s,"r0") == 0 ||
- strcmp(s,"r1") == 0 ||
- strcmp(s,"r2") == 0 ||
- strcmp(s,"r3") == 0 ||
- strcmp(s,"r4") == 0 ||
- strcmp(s,"r5") == 0 ||
- strcmp(s,"r6") == 0 ||
- strcmp(s,"r7") == 0 )
- emitcode("mov","%s,%s",
- aop->aopu.aop_reg[offset]->dname,s);
- else
- emitcode("mov","%s,%s",
- aop->aopu.aop_reg[offset]->name,s);
- }
- break;
+ if (strcmp (aop->aopu.aop_reg[offset]->name, s) != 0 &&
+ strcmp (aop->aopu.aop_reg[offset]->dname, s) != 0)
+ {
+ if (*s == '@' ||
+ strcmp (s, "r0") == 0 ||
+ strcmp (s, "r1") == 0 ||
+ strcmp (s, "r2") == 0 ||
+ strcmp (s, "r3") == 0 ||
+ strcmp (s, "r4") == 0 ||
+ strcmp (s, "r5") == 0 ||
+ strcmp (s, "r6") == 0 ||
+ strcmp (s, "r7") == 0)
+ emitcode ("mov", "%s,%s",
+ aop->aopu.aop_reg[offset]->dname, s);
+ else
+ emitcode ("mov", "%s,%s",
+ aop->aopu.aop_reg[offset]->name, s);
+ }
+ break;
case AOP_DPTR:
case AOP_DPTR2:
if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- }
- _flushLazyDPS();
+ {
+ genSetDPTR (1);
+ }
+ _flushLazyDPS ();
- if (aop->code) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut writting to code space");
- exit(1);
- }
+ if (aop->code)
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut writting to code space");
+ exit (1);
+ }
- while (offset > aop->coff) {
- aop->coff++;
- emitcode ("inc","dptr");
- }
+ while (offset > aop->coff)
+ {
+ aop->coff++;
+ emitcode ("inc", "dptr");
+ }
- while (offset < aop->coff) {
- aop->coff-- ;
- emitcode("lcall","__decdptr");
- }
+ while (offset < aop->coff)
+ {
+ aop->coff--;
+ emitcode ("lcall", "__decdptr");
+ }
- aop->coff = offset;
+ aop->coff = offset;
- /* if not in accumulater */
- MOVA(s);
+ /* if not in accumulater */
+ MOVA (s);
- emitcode ("movx","@dptr,a");
+ emitcode ("movx", "@dptr,a");
if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
- break;
+ {
+ genSetDPTR (0);
+ }
+ break;
case AOP_R0:
case AOP_R1:
- while (offset > aop->coff) {
- aop->coff++;
- emitcode("inc","%s",aop->aopu.aop_ptr->name);
- }
- while (offset < aop->coff) {
- aop->coff-- ;
- emitcode ("dec","%s",aop->aopu.aop_ptr->name);
- }
- aop->coff = offset;
-
- if (aop->paged) {
- MOVA(s);
- emitcode("movx","@%s,a",aop->aopu.aop_ptr->name);
-
- } else
- if (*s == '@') {
- MOVA(s);
- emitcode("mov","@%s,a",aop->aopu.aop_ptr->name);
- } else
- if (strcmp(s,"r0") == 0 ||
- strcmp(s,"r1") == 0 ||
- strcmp(s,"r2") == 0 ||
- strcmp(s,"r3") == 0 ||
- strcmp(s,"r4") == 0 ||
- strcmp(s,"r5") == 0 ||
- strcmp(s,"r6") == 0 ||
- strcmp(s,"r7") == 0 ) {
- char buffer[10];
- sprintf(buffer,"a%s",s);
- emitcode("mov","@%s,%s",
- aop->aopu.aop_ptr->name,buffer);
- } else
- emitcode("mov","@%s,%s",aop->aopu.aop_ptr->name,s);
-
- break;
+ while (offset > aop->coff)
+ {
+ aop->coff++;
+ emitcode ("inc", "%s", aop->aopu.aop_ptr->name);
+ }
+ while (offset < aop->coff)
+ {
+ aop->coff--;
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ }
+ aop->coff = offset;
+
+ if (aop->paged)
+ {
+ MOVA (s);
+ emitcode ("movx", "@%s,a", aop->aopu.aop_ptr->name);
+
+ }
+ else if (*s == '@')
+ {
+ MOVA (s);
+ emitcode ("mov", "@%s,a", aop->aopu.aop_ptr->name);
+ }
+ else if (strcmp (s, "r0") == 0 ||
+ strcmp (s, "r1") == 0 ||
+ strcmp (s, "r2") == 0 ||
+ strcmp (s, "r3") == 0 ||
+ strcmp (s, "r4") == 0 ||
+ strcmp (s, "r5") == 0 ||
+ strcmp (s, "r6") == 0 ||
+ strcmp (s, "r7") == 0)
+ {
+ char buffer[10];
+ sprintf (buffer, "a%s", s);
+ emitcode ("mov", "@%s,%s",
+ aop->aopu.aop_ptr->name, buffer);
+ }
+ else
+ emitcode ("mov", "@%s,%s", aop->aopu.aop_ptr->name, s);
+
+ break;
case AOP_STK:
- if (strcmp(s,"a") == 0)
- emitcode("push","acc");
- else
- emitcode("push","%s",s);
+ if (strcmp (s, "a") == 0)
+ emitcode ("push", "acc");
+ else
+ emitcode ("push", "%s", s);
- break;
+ break;
case AOP_CRY:
- /* if bit variable */
- if (!aop->aopu.aop_dir) {
- emitcode("clr","a");
- emitcode("rlc","a");
- } else {
- if (s == zero)
- emitcode("clr","%s",aop->aopu.aop_dir);
+ /* if bit variable */
+ if (!aop->aopu.aop_dir)
+ {
+ emitcode ("clr", "a");
+ emitcode ("rlc", "a");
+ }
else
- if (s == one)
- emitcode("setb","%s",aop->aopu.aop_dir);
- else
- if (!strcmp(s,"c"))
- emitcode("mov","%s,c",aop->aopu.aop_dir);
- else {
- lbl = newiTempLabel(NULL);
-
- if (strcmp(s,"a")) {
- MOVA(s);
- }
- emitcode("clr","c");
- emitcode("jz","%05d$",lbl->key+100);
- emitcode("cpl","c");
- emitcode("","%05d$:",lbl->key+100);
- emitcode("mov","%s,c",aop->aopu.aop_dir);
- }
- }
- break;
+ {
+ if (s == zero)
+ emitcode ("clr", "%s", aop->aopu.aop_dir);
+ else if (s == one)
+ emitcode ("setb", "%s", aop->aopu.aop_dir);
+ else if (!strcmp (s, "c"))
+ emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+ else
+ {
+ lbl = newiTempLabel (NULL);
+
+ if (strcmp (s, "a"))
+ {
+ MOVA (s);
+ }
+ emitcode ("clr", "c");
+ emitcode ("jz", "%05d$", lbl->key + 100);
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", lbl->key + 100);
+ emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+ }
+ }
+ break;
case AOP_STR:
- aop->coff = offset;
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("mov","%s,%s",aop->aopu.aop_str[offset],s);
- break;
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("mov", "%s,%s", aop->aopu.aop_str[offset], s);
+ break;
case AOP_ACC:
- aop->coff = offset;
- if (!offset && (strcmp(s,"acc") == 0))
- break;
+ aop->coff = offset;
+ if (!offset && (strcmp (s, "acc") == 0))
+ break;
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("mov","%s,%s",aop->aopu.aop_str[offset],s);
- break;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("mov", "%s,%s", aop->aopu.aop_str[offset], s);
+ break;
- default :
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got unsupported aop->type");
- exit(1);
+ default:
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got unsupported aop->type");
+ exit (1);
}
}
/*-----------------------------------------------------------------*/
/* reAdjustPreg - points a register back to where it should */
/*-----------------------------------------------------------------*/
-static void reAdjustPreg (asmop *aop)
+static void
+reAdjustPreg (asmop * aop)
{
- int size ;
+ int size;
- aop->coff = 0;
- if ((size = aop->size) <= 1)
- return ;
- size-- ;
- switch (aop->type) {
- case AOP_R0 :
- case AOP_R1 :
- while (size--)
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- break;
- case AOP_DPTR :
- case AOP_DPTR2:
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- _flushLazyDPS();
- }
- while (size--)
- {
- emitcode("lcall","__decdptr");
- }
+ aop->coff = 0;
+ if ((size = aop->size) <= 1)
+ return;
+ size--;
+ switch (aop->type)
+ {
+ case AOP_R0:
+ case AOP_R1:
+ while (size--)
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ break;
+ case AOP_DPTR:
+ case AOP_DPTR2:
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (1);
+ _flushLazyDPS ();
+ }
+ while (size--)
+ {
+ emitcode ("lcall", "__decdptr");
+ }
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
- break;
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (0);
+ }
+ break;
}
/*-----------------------------------------------------------------*/
/* genNotFloat - generates not for float operations */
/*-----------------------------------------------------------------*/
-static void genNotFloat (operand *op, operand *res)
+static void
+genNotFloat (operand * op, operand * res)
{
- int size, offset;
- char *l;
- symbol *tlbl ;
+ int size, offset;
+ char *l;
+ symbol *tlbl;
- D(emitcode(";", "genNotFloat "););
+ D (emitcode (";", "genNotFloat ");
+ );
- /* we will put 127 in the first byte of
- the result */
- aopPut(AOP(res),"#127",0);
- size = AOP_SIZE(op) - 1;
- offset = 1;
+ /* we will put 127 in the first byte of
+ the result */
+ aopPut (AOP (res), "#127", 0);
+ size = AOP_SIZE (op) - 1;
+ offset = 1;
- _startLazyDPSEvaluation();
- l = aopGet(op->aop,offset++,FALSE,FALSE,TRUE);
- MOVA(l);
+ _startLazyDPSEvaluation ();
+ l = aopGet (op->aop, offset++, FALSE, FALSE, TRUE);
+ MOVA (l);
- while(size--) {
- emitcode("orl","a,%s",
- aopGet(op->aop,
- offset++,FALSE,FALSE,FALSE));
+ while (size--)
+ {
+ emitcode ("orl", "a,%s",
+ aopGet (op->aop,
+ offset++, FALSE, FALSE, FALSE));
}
- _endLazyDPSEvaluation();
- tlbl = newiTempLabel(NULL);
+ _endLazyDPSEvaluation ();
+ tlbl = newiTempLabel (NULL);
- tlbl = newiTempLabel(NULL);
- aopPut(res->aop,one,1);
- emitcode("jz","%05d$",(tlbl->key+100));
- aopPut(res->aop,zero,1);
- emitcode("","%05d$:",(tlbl->key+100));
+ tlbl = newiTempLabel (NULL);
+ aopPut (res->aop, one, 1);
+ emitcode ("jz", "%05d$", (tlbl->key + 100));
+ aopPut (res->aop, zero, 1);
+ emitcode ("", "%05d$:", (tlbl->key + 100));
- size = res->aop->size - 2;
- offset = 2;
- /* put zeros in the rest */
- while (size--)
- aopPut(res->aop,zero,offset++);
+ size = res->aop->size - 2;
+ offset = 2;
+ /* put zeros in the rest */
+ while (size--)
+ aopPut (res->aop, zero, offset++);
}
/*-----------------------------------------------------------------*/
/* opIsGptr: returns non-zero if the passed operand is */
/* a generic pointer type. */
/*-----------------------------------------------------------------*/
-static int opIsGptr(operand *op)
+static int
+opIsGptr (operand * op)
{
- sym_link *type = operandType(op);
+ sym_link *type = operandType (op);
- if ((AOP_SIZE(op) == GPTRSIZE) && IS_GENPTR(type))
+ if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
{
- return 1;
+ return 1;
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* getDataSize - get the operand data size */
/*-----------------------------------------------------------------*/
-static int getDataSize(operand *op)
+static int
+getDataSize (operand * op)
{
- int size;
- size = AOP_SIZE(op);
- if (size == GPTRSIZE)
+ int size;
+ size = AOP_SIZE (op);
+ if (size == GPTRSIZE)
{
- sym_link *type = operandType(op);
- if (IS_GENPTR(type))
- {
- /* generic pointer; arithmetic operations
- * should ignore the high byte (pointer type).
- */
- size--;
- }
+ sym_link *type = operandType (op);
+ if (IS_GENPTR (type))
+ {
+ /* generic pointer; arithmetic operations
+ * should ignore the high byte (pointer type).
+ */
+ size--;
+ }
}
- return size;
+ return size;
}
/*-----------------------------------------------------------------*/
/* outAcc - output Acc */
/*-----------------------------------------------------------------*/
-static void outAcc(operand *result)
+static void
+outAcc (operand * result)
{
- int size, offset;
- size = getDataSize(result);
- if(size)
+ int size, offset;
+ size = getDataSize (result);
+ if (size)
{
- aopPut(AOP(result),"a",0);
- size--;
- offset = 1;
- /* unsigned or positive */
- while(size--){
- aopPut(AOP(result),zero,offset++);
- }
+ aopPut (AOP (result), "a", 0);
+ size--;
+ offset = 1;
+ /* unsigned or positive */
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
}
}
/*-----------------------------------------------------------------*/
/* outBitC - output a bit C */
/*-----------------------------------------------------------------*/
-static void outBitC(operand *result)
+static void
+outBitC (operand * result)
{
- /* if the result is bit */
- if (AOP_TYPE(result) == AOP_CRY)
+ /* if the result is bit */
+ if (AOP_TYPE (result) == AOP_CRY)
{
- aopPut(AOP(result),"c",0);
+ aopPut (AOP (result), "c", 0);
}
- else
+ else
{
- emitcode("clr","a");
- emitcode("rlc","a");
- outAcc(result);
+ emitcode ("clr", "a");
+ emitcode ("rlc", "a");
+ outAcc (result);
}
}
/*-----------------------------------------------------------------*/
/* toBoolean - emit code for orl a,operator(sizeop) */
/*-----------------------------------------------------------------*/
-static void toBoolean(operand *oper)
+static void
+toBoolean (operand * oper)
{
- int size = AOP_SIZE(oper) - 1;
- int offset = 1;
+ int size = AOP_SIZE (oper) - 1;
+ int offset = 1;
- /* The generic part of a generic pointer should
- * not participate in it's truth value.
- *
- * i.e. 0x10000000 is zero.
- */
- if (opIsGptr(oper))
+ /* The generic part of a generic pointer should
+ * not participate in it's truth value.
+ *
+ * i.e. 0x10000000 is zero.
+ */
+ if (opIsGptr (oper))
{
- D(emitcode(";", "toBoolean: generic ptr special case."););
- size--;
+ D (emitcode (";", "toBoolean: generic ptr special case.");
+ );
+ size--;
}
- _startLazyDPSEvaluation();
- if (AOP_NEEDSACC(oper))
+ _startLazyDPSEvaluation ();
+ if (AOP_NEEDSACC (oper))
{
- emitcode("push", "b");
- emitcode("mov", "b, %s", aopGet(AOP(oper),0,FALSE,FALSE,FALSE));
+ emitcode ("push", "b");
+ emitcode ("mov", "b, %s", aopGet (AOP (oper), 0, FALSE, FALSE, FALSE));
}
- else
+ else
{
- MOVA(aopGet(AOP(oper),0,FALSE,FALSE,TRUE));
+ MOVA (aopGet (AOP (oper), 0, FALSE, FALSE, TRUE));
}
- while (size--)
+ while (size--)
{
- if (AOP_NEEDSACC(oper))
- {
- emitcode("orl","b,%s",aopGet(AOP(oper),offset++,FALSE,FALSE,FALSE));
- }
+ if (AOP_NEEDSACC (oper))
+ {
+ emitcode ("orl", "b,%s", aopGet (AOP (oper), offset++, FALSE, FALSE, FALSE));
+ }
else
- {
- emitcode("orl","a,%s",aopGet(AOP(oper),offset++,FALSE,FALSE,FALSE));
- }
+ {
+ emitcode ("orl", "a,%s", aopGet (AOP (oper), offset++, FALSE, FALSE, FALSE));
+ }
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- if (AOP_NEEDSACC(oper))
+ if (AOP_NEEDSACC (oper))
{
- emitcode("mov", "a,b");
- emitcode("pop", "b");
+ emitcode ("mov", "a,b");
+ emitcode ("pop", "b");
}
}
/*-----------------------------------------------------------------*/
/* genNot - generate code for ! operation */
/*-----------------------------------------------------------------*/
-static void genNot (iCode *ic)
+static void
+genNot (iCode * ic)
{
- symbol *tlbl;
- sym_link *optype = operandType(IC_LEFT(ic));
+ symbol *tlbl;
+ sym_link *optype = operandType (IC_LEFT (ic));
- D(emitcode(";", "genNot "););
+ D (emitcode (";", "genNot ");
+ );
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE, AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR);
- /* if in bit space then a special case */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- outBitC(IC_RESULT(ic));
- goto release;
+ /* if in bit space then a special case */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ outBitC (IC_RESULT (ic));
+ goto release;
}
- /* if type float then do float */
- if (IS_FLOAT(optype)) {
- genNotFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
+ /* if type float then do float */
+ if (IS_FLOAT (optype))
+ {
+ genNotFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
}
- toBoolean(IC_LEFT(ic));
+ toBoolean (IC_LEFT (ic));
- tlbl = newiTempLabel(NULL);
- emitcode("cjne","a,#0x01,%05d$",tlbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(IC_RESULT(ic));
+ tlbl = newiTempLabel (NULL);
+ emitcode ("cjne", "a,#0x01,%05d$", tlbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (IC_RESULT (ic));
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCpl - generate code for complement */
/*-----------------------------------------------------------------*/
-static void genCpl (iCode *ic)
+static void
+genCpl (iCode * ic)
{
- int offset = 0;
- int size ;
+ int offset = 0;
+ int size;
- D(emitcode(";", "genCpl "););
+ D (emitcode (";", "genCpl ");
+ );
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE, AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR);
- /* if both are in bit space then
- a special case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
+ /* if both are in bit space then
+ a special case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
- goto release;
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+ goto release;
}
- size = AOP_SIZE(IC_RESULT(ic));
- _startLazyDPSEvaluation();
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("cpl","a");
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ size = AOP_SIZE (IC_RESULT (ic));
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("cpl", "a");
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genUminusFloat - unary minus for floating points */
/*-----------------------------------------------------------------*/
-static void genUminusFloat(operand *op,operand *result)
+static void
+genUminusFloat (operand * op, operand * result)
{
- int size ,offset =0 ;
- char *l;
- /* for this we just need to flip the
- first it then copy the rest in place */
- D(emitcode(";", "genUminusFloat"););
+ int size, offset = 0;
+ char *l;
+ /* for this we just need to flip the
+ first it then copy the rest in place */
+ D (emitcode (";", "genUminusFloat");
+ );
- _startLazyDPSEvaluation();
- size = AOP_SIZE(op) - 1;
- l = aopGet(AOP(op),3,FALSE,FALSE,TRUE);
- MOVA(l);
+ _startLazyDPSEvaluation ();
+ size = AOP_SIZE (op) - 1;
+ l = aopGet (AOP (op), 3, FALSE, FALSE, TRUE);
+ MOVA (l);
- emitcode("cpl","acc.7");
- aopPut(AOP(result),"a",3);
+ emitcode ("cpl", "acc.7");
+ aopPut (AOP (result), "a", 3);
- while(size--) {
- aopPut(AOP(result),
- aopGet(AOP(op),offset,FALSE,FALSE,FALSE),
- offset);
- offset++;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (op), offset, FALSE, FALSE, FALSE),
+ offset);
+ offset++;
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
}
/*-----------------------------------------------------------------*/
/* genUminus - unary minus code generation */
/*-----------------------------------------------------------------*/
-static void genUminus (iCode *ic)
+static void
+genUminus (iCode * ic)
{
- int offset ,size ;
- sym_link *optype, *rtype;
+ int offset, size;
+ sym_link *optype, *rtype;
- D(emitcode(";", "genUminus "););
+ D (emitcode (";", "genUminus ");
+ );
- /* assign asmops */
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp(IC_RESULT(ic),ic,TRUE, AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR);
+ /* assign asmops */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR);
- /* if both in bit space then special
- case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
+ /* if both in bit space then special
+ case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
- goto release;
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+ goto release;
}
- optype = operandType(IC_LEFT(ic));
- rtype = operandType(IC_RESULT(ic));
+ optype = operandType (IC_LEFT (ic));
+ rtype = operandType (IC_RESULT (ic));
- /* if float then do float stuff */
- if (IS_FLOAT(optype)) {
- genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
- }
-
- /* otherwise subtract from zero */
- size = AOP_SIZE(IC_LEFT(ic));
- offset = 0 ;
- _startLazyDPSEvaluation();
- while(size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE);
- if (!strcmp(l,"a")) {
- if (offset==0)
- SETC;
- emitcode("cpl","a");
- emitcode("addc", "a,#0");
- } else {
- if (offset==0)
- CLRC;
- emitcode("clr","a");
- emitcode("subb","a,%s",l);
- }
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* if float then do float stuff */
+ if (IS_FLOAT (optype))
+ {
+ genUminusFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
}
- _endLazyDPSEvaluation();
- /* if any remaining bytes in the result */
- /* we just need to propagate the sign */
- if ((size = (AOP_SIZE(IC_RESULT(ic)) - AOP_SIZE(IC_LEFT(ic))))) {
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- while (size--)
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* otherwise subtract from zero */
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, TRUE);
+ if (!strcmp (l, "a"))
+ {
+ if (offset == 0)
+ SETC;
+ emitcode ("cpl", "a");
+ emitcode ("addc", "a,#0");
+ }
+ else
+ {
+ if (offset == 0)
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,%s", l);
+ }
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
+ }
+ _endLazyDPSEvaluation ();
+
+ /* if any remaining bytes in the result */
+ /* we just need to propagate the sign */
+ if ((size = (AOP_SIZE (IC_RESULT (ic)) - AOP_SIZE (IC_LEFT (ic)))))
+ {
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ while (size--)
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* saveRegisters - will look for a call and save the registers */
/*-----------------------------------------------------------------*/
-static void saveRegisters(iCode *lic)
-{
- int i;
- iCode *ic;
- bitVect *rsave;
- sym_link *detype;
-
- /* look for call */
- for (ic = lic ; ic ; ic = ic->next)
- if (ic->op == CALL || ic->op == PCALL)
- break;
-
- if (!ic) {
- fprintf(stderr,"found parameter push with no function call\n");
- return ;
- }
-
- /* if the registers have been saved already then
- do nothing */
- if (ic->regsSaved || (OP_SYMBOL(IC_LEFT(ic))->calleeSave))
- return ;
-
- /* find the registers in use at this time
- and push them away to safety */
- rsave = bitVectCplAnd(bitVectCopy(ic->rMask),
- ic->rUsed);
-
- ic->regsSaved = 1;
- if (options.useXstack) {
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","b,r0");
- emitcode("mov","r0,%s",spname);
- for (i = 0 ; i < ds390_nRegs ; i++) {
- if (bitVectBitValue(rsave,i)) {
- if (i == R0_IDX)
- emitcode("mov","a,b");
- else
- emitcode("mov","a,%s",ds390_regWithIdx(i)->name);
- emitcode("movx","@r0,a");
- emitcode("inc","r0");
+static void
+saveRegisters (iCode * lic)
+{
+ int i;
+ iCode *ic;
+ bitVect *rsave;
+ sym_link *detype;
+
+ /* look for call */
+ for (ic = lic; ic; ic = ic->next)
+ if (ic->op == CALL || ic->op == PCALL)
+ break;
+
+ if (!ic)
+ {
+ fprintf (stderr, "found parameter push with no function call\n");
+ return;
+ }
+
+ /* if the registers have been saved already then
+ do nothing */
+ if (ic->regsSaved || (OP_SYMBOL (IC_LEFT (ic))->calleeSave))
+ return;
+
+ /* find the registers in use at this time
+ and push them away to safety */
+ rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ic->rUsed);
+
+ ic->regsSaved = 1;
+ if (options.useXstack)
+ {
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "b,r0");
+ emitcode ("mov", "r0,%s", spname);
+ for (i = 0; i < ds390_nRegs; i++)
+ {
+ if (bitVectBitValue (rsave, i))
+ {
+ if (i == R0_IDX)
+ emitcode ("mov", "a,b");
+ else
+ emitcode ("mov", "a,%s", ds390_regWithIdx (i)->name);
+ emitcode ("movx", "@r0,a");
+ emitcode ("inc", "r0");
+ }
+ }
+ emitcode ("mov", "%s,r0", spname);
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "r0,b");
+ }
+ else
+ for (i = 0; i < ds390_nRegs; i++)
+ {
+ if (bitVectBitValue (rsave, i))
+ emitcode ("push", "%s", ds390_regWithIdx (i)->dname);
}
- }
- emitcode("mov","%s,r0",spname);
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","r0,b");
- } else
- for (i = 0 ; i < ds390_nRegs ; i++) {
- if (bitVectBitValue(rsave,i))
- emitcode("push","%s",ds390_regWithIdx(i)->dname);
- }
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) &&
- IS_ISR(currFunc->etype) &&
- !ic->bankSaved)
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) &&
+ IS_ISR (currFunc->etype) &&
+ !ic->bankSaved)
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ saverbank (SPEC_BANK (detype), ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* unsaveRegisters - pop the pushed registers */
/*-----------------------------------------------------------------*/
-static void unsaveRegisters (iCode *ic)
-{
- int i;
- bitVect *rsave;
- /* find the registers in use at this time
- and push them away to safety */
- rsave = bitVectCplAnd(bitVectCopy(ic->rMask),
- ic->rUsed);
-
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- for (i = ds390_nRegs ; i >= 0 ; i--) {
- if (bitVectBitValue(rsave,i)) {
- emitcode("dec","r0");
- emitcode("movx","a,@r0");
- if (i == R0_IDX)
- emitcode("mov","b,a");
- else
- emitcode("mov","%s,a",ds390_regWithIdx(i)->name);
- }
+static void
+unsaveRegisters (iCode * ic)
+{
+ int i;
+ bitVect *rsave;
+ /* find the registers in use at this time
+ and push them away to safety */
+ rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ic->rUsed);
- }
- emitcode("mov","%s,r0",spname);
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","r0,b");
- } else
- for (i = ds390_nRegs ; i >= 0 ; i--) {
- if (bitVectBitValue(rsave,i))
- emitcode("pop","%s",ds390_regWithIdx(i)->dname);
- }
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ for (i = ds390_nRegs; i >= 0; i--)
+ {
+ if (bitVectBitValue (rsave, i))
+ {
+ emitcode ("dec", "r0");
+ emitcode ("movx", "a,@r0");
+ if (i == R0_IDX)
+ emitcode ("mov", "b,a");
+ else
+ emitcode ("mov", "%s,a", ds390_regWithIdx (i)->name);
+ }
+
+ }
+ emitcode ("mov", "%s,r0", spname);
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "r0,b");
+ }
+ else
+ for (i = ds390_nRegs; i >= 0; i--)
+ {
+ if (bitVectBitValue (rsave, i))
+ emitcode ("pop", "%s", ds390_regWithIdx (i)->dname);
+ }
}
/*-----------------------------------------------------------------*/
/* pushSide - */
/*-----------------------------------------------------------------*/
-static void pushSide(operand * oper, int size)
+static void
+pushSide (operand * oper, int size)
{
int offset = 0;
- _startLazyDPSEvaluation();
- while (size--) {
- char *l = aopGet(AOP(oper),offset++,FALSE,TRUE,FALSE);
- if (AOP_TYPE(oper) != AOP_REG &&
- AOP_TYPE(oper) != AOP_DIR &&
- strcmp(l,"a") ) {
- emitcode("mov","a,%s",l);
- emitcode("push","acc");
- } else
- emitcode("push","%s",l);
- }
- _endLazyDPSEvaluation();
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l = aopGet (AOP (oper), offset++, FALSE, TRUE, FALSE);
+ if (AOP_TYPE (oper) != AOP_REG &&
+ AOP_TYPE (oper) != AOP_DIR &&
+ strcmp (l, "a"))
+ {
+ emitcode ("mov", "a,%s", l);
+ emitcode ("push", "acc");
+ }
+ else
+ emitcode ("push", "%s", l);
+ }
+ _endLazyDPSEvaluation ();
}
/*-----------------------------------------------------------------*/
/* assignResultValue - */
/*-----------------------------------------------------------------*/
-static void assignResultValue(operand * oper)
+static void
+assignResultValue (operand * oper)
{
int offset = 0;
- int size = AOP_SIZE(oper);
+ int size = AOP_SIZE (oper);
- _startLazyDPSEvaluation();
- while (size--) {
- aopPut(AOP(oper),fReturn[offset],offset);
- offset++;
- }
- _endLazyDPSEvaluation();
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ aopPut (AOP (oper), fReturn[offset], offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
}
/*-----------------------------------------------------------------*/
/* genXpush - pushes onto the external stack */
/*-----------------------------------------------------------------*/
-static void genXpush (iCode *ic)
+static void
+genXpush (iCode * ic)
{
- asmop *aop = newAsmop(0);
- regs *r ;
- int size,offset = 0;
+ asmop *aop = newAsmop (0);
+ regs *r;
+ int size, offset = 0;
- D(emitcode(";", "genXpush "););
+ D (emitcode (";", "genXpush ");
+ );
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- r = getFreePtr(ic,&aop,FALSE);
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ r = getFreePtr (ic, &aop, FALSE);
- emitcode("mov","%s,_spx",r->name);
+ emitcode ("mov", "%s,_spx", r->name);
- size = AOP_SIZE(IC_LEFT(ic));
- _startLazyDPSEvaluation();
- while(size--) {
+ size = AOP_SIZE (IC_LEFT (ic));
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
- char *l = aopGet(AOP(IC_LEFT(ic)),
- offset++,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("movx","@%s,a",r->name);
- emitcode("inc","%s",r->name);
+ char *l = aopGet (AOP (IC_LEFT (ic)),
+ offset++, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("movx", "@%s,a", r->name);
+ emitcode ("inc", "%s", r->name);
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- emitcode("mov","_spx,%s",r->name);
+ emitcode ("mov", "_spx,%s", r->name);
- freeAsmop(NULL,aop,ic,TRUE);
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (NULL, aop, ic, TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIpush - genrate code for pushing this gets a little complex */
/*-----------------------------------------------------------------*/
-static void genIpush (iCode *ic)
+static void
+genIpush (iCode * ic)
{
- int size, offset = 0 ;
- char *l;
+ int size, offset = 0;
+ char *l;
- D(emitcode(";", "genIpush "););
+ D (emitcode (";", "genIpush ");
+ );
- /* if this is not a parm push : ie. it is spill push
- and spill push is always done on the local stack */
- if (!ic->parmPush) {
-
- /* and the item is spilt then do nothing */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
-
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- /* push it on the stack */
- _startLazyDPSEvaluation();
- while(size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE,TRUE);
- if (*l == '#') {
- MOVA(l);
- l = "acc";
- }
- emitcode("push","%s",l);
- }
- _endLazyDPSEvaluation();
- return ;
- }
+ /* if this is not a parm push : ie. it is spill push
+ and spill push is always done on the local stack */
+ if (!ic->parmPush)
+ {
- /* this is a paramter push: in this case we call
- the routine to find the call and save those
- registers that need to be saved */
- saveRegisters(ic);
+ /* and the item is spilt then do nothing */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- /* if use external stack then call the external
- stack pushing routine */
- if (options.useXstack) {
- genXpush(ic);
- return ;
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ /* push it on the stack */
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE, TRUE);
+ if (*l == '#')
+ {
+ MOVA (l);
+ l = "acc";
+ }
+ emitcode ("push", "%s", l);
+ }
+ _endLazyDPSEvaluation ();
+ return;
+ }
+
+ /* this is a paramter push: in this case we call
+ the routine to find the call and save those
+ registers that need to be saved */
+ saveRegisters (ic);
+
+ /* if use external stack then call the external
+ stack pushing routine */
+ if (options.useXstack)
+ {
+ genXpush (ic);
+ return;
}
- /* then do the push */
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
+ /* then do the push */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
- // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
- size = AOP_SIZE(IC_LEFT(ic));
+ // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
+ size = AOP_SIZE (IC_LEFT (ic));
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE,FALSE);
- if (AOP_TYPE(IC_LEFT(ic)) != AOP_REG &&
- AOP_TYPE(IC_LEFT(ic)) != AOP_DIR &&
- strcmp(l,"a") ) {
- emitcode("mov","a,%s",l);
- emitcode("push","acc");
- } else
- emitcode("push","%s",l);
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE, FALSE);
+ if (AOP_TYPE (IC_LEFT (ic)) != AOP_REG &&
+ AOP_TYPE (IC_LEFT (ic)) != AOP_DIR &&
+ strcmp (l, "a"))
+ {
+ emitcode ("mov", "a,%s", l);
+ emitcode ("push", "acc");
+ }
+ else
+ emitcode ("push", "%s", l);
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIpop - recover the registers: can happen only for spilling */
/*-----------------------------------------------------------------*/
-static void genIpop (iCode *ic)
+static void
+genIpop (iCode * ic)
{
- int size,offset ;
+ int size, offset;
- D(emitcode(";", "genIpop "););
+ D (emitcode (";", "genIpop ");
+ );
- /* if the temp was not pushed then */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
+ /* if the temp was not pushed then */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- offset = (size-1);
- _startLazyDPSEvaluation();
- while (size--)
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = (size - 1);
+ _startLazyDPSEvaluation ();
+ while (size--)
{
- emitcode("pop","%s",aopGet(AOP(IC_LEFT(ic)),offset--,
- FALSE,TRUE,TRUE));
+ emitcode ("pop", "%s", aopGet (AOP (IC_LEFT (ic)), offset--,
+ FALSE, TRUE, TRUE));
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* unsaverbank - restores the resgister bank from stack */
/*-----------------------------------------------------------------*/
-static void unsaverbank (int bank,iCode *ic,bool popPsw)
+static void
+unsaverbank (int bank, iCode * ic, bool popPsw)
{
- int i;
- asmop *aop ;
- regs *r = NULL;
+ int i;
+ asmop *aop;
+ regs *r = NULL;
- if (popPsw) {
- if (options.useXstack) {
- aop = newAsmop(0);
- r = getFreePtr(ic,&aop,FALSE);
+ if (popPsw)
+ {
+ if (options.useXstack)
+ {
+ aop = newAsmop (0);
+ r = getFreePtr (ic, &aop, FALSE);
- emitcode("mov","%s,_spx",r->name);
- emitcode("movx","a,@%s",r->name);
- emitcode("mov","psw,a");
- emitcode("dec","%s",r->name);
+ emitcode ("mov", "%s,_spx", r->name);
+ emitcode ("movx", "a,@%s", r->name);
+ emitcode ("mov", "psw,a");
+ emitcode ("dec", "%s", r->name);
- }else
- emitcode ("pop","psw");
+ }
+ else
+ emitcode ("pop", "psw");
}
- for (i = (ds390_nRegs - 1) ; i >= 0 ;i--) {
- if (options.useXstack) {
- emitcode("movx","a,@%s",r->name);
- emitcode("mov","(%s+%d),a",
- regs390[i].base,8*bank+regs390[i].offset);
- emitcode("dec","%s",r->name);
-
- } else
- emitcode("pop","(%s+%d)",
- regs390[i].base,8*bank+regs390[i].offset);
+ for (i = (ds390_nRegs - 1); i >= 0; i--)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("movx", "a,@%s", r->name);
+ emitcode ("mov", "(%s+%d),a",
+ regs390[i].base, 8 * bank + regs390[i].offset);
+ emitcode ("dec", "%s", r->name);
+
+ }
+ else
+ emitcode ("pop", "(%s+%d)",
+ regs390[i].base, 8 * bank + regs390[i].offset);
}
- if (options.useXstack) {
+ if (options.useXstack)
+ {
- emitcode("mov","_spx,%s",r->name);
- freeAsmop(NULL,aop,ic,TRUE);
+ emitcode ("mov", "_spx,%s", r->name);
+ freeAsmop (NULL, aop, ic, TRUE);
}
}
/*-----------------------------------------------------------------*/
/* saverbank - saves an entire register bank on the stack */
/*-----------------------------------------------------------------*/
-static void saverbank (int bank, iCode *ic, bool pushPsw)
+static void
+saverbank (int bank, iCode * ic, bool pushPsw)
{
- int i;
- asmop *aop ;
- regs *r = NULL;
+ int i;
+ asmop *aop;
+ regs *r = NULL;
- if (options.useXstack) {
+ if (options.useXstack)
+ {
- aop = newAsmop(0);
- r = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,_spx",r->name);
+ aop = newAsmop (0);
+ r = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,_spx", r->name);
}
- for (i = 0 ; i < ds390_nRegs ;i++) {
- if (options.useXstack) {
- emitcode("inc","%s",r->name);
- emitcode("mov","a,(%s+%d)",
- regs390[i].base,8*bank+regs390[i].offset);
- emitcode("movx","@%s,a",r->name);
- } else
- emitcode("push","(%s+%d)",
- regs390[i].base,8*bank+regs390[i].offset);
+ for (i = 0; i < ds390_nRegs; i++)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("inc", "%s", r->name);
+ emitcode ("mov", "a,(%s+%d)",
+ regs390[i].base, 8 * bank + regs390[i].offset);
+ emitcode ("movx", "@%s,a", r->name);
+ }
+ else
+ emitcode ("push", "(%s+%d)",
+ regs390[i].base, 8 * bank + regs390[i].offset);
}
- if (pushPsw) {
- if (options.useXstack) {
- emitcode("mov","a,psw");
- emitcode("movx","@%s,a",r->name);
- emitcode("inc","%s",r->name);
- emitcode("mov","_spx,%s",r->name);
- freeAsmop (NULL,aop,ic,TRUE);
-
- } else
- emitcode("push","psw");
+ if (pushPsw)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("mov", "a,psw");
+ emitcode ("movx", "@%s,a", r->name);
+ emitcode ("inc", "%s", r->name);
+ emitcode ("mov", "_spx,%s", r->name);
+ freeAsmop (NULL, aop, ic, TRUE);
+
+ }
+ else
+ emitcode ("push", "psw");
- emitcode("mov","psw,#0x%02x",(bank << 3)&0x00ff);
+ emitcode ("mov", "psw,#0x%02x", (bank << 3) & 0x00ff);
}
- ic->bankSaved = 1;
+ ic->bankSaved = 1;
}
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
-static void genCall (iCode *ic)
+static void
+genCall (iCode * ic)
{
- sym_link *detype;
+ sym_link *detype;
- D(emitcode(";", "genCall "););
+ D (emitcode (";", "genCall ");
+ );
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
- saveRegisters(ic);
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ saveRegisters (ic);
- /* if we are calling a function that is not using
- the same register bank then we need to save the
- destination registers on the stack */
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) &&
- IS_ISR(currFunc->etype) &&
- !ic->bankSaved)
+ /* if we are calling a function that is not using
+ the same register bank then we need to save the
+ destination registers on the stack */
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) &&
+ IS_ISR (currFunc->etype) &&
+ !ic->bankSaved)
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ saverbank (SPEC_BANK (detype), ic, TRUE);
- /* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
-
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet))
- {
- int size, offset = 0;
-
- aopOp(IC_LEFT(sic),sic,FALSE, TRUE);
- size = AOP_SIZE(IC_LEFT(sic));
-
- _startLazyDPSEvaluation();
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset,
- FALSE, FALSE, TRUE);
- if (strcmp(l,fReturn[offset]))
- emitcode("mov","%s,%s",
- fReturn[offset],
- l);
- offset++;
- }
- _endLazyDPSEvaluation();
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
- }
- _G.sendSet = NULL;
+ /* if send set is not empty the assign */
+ if (_G.sendSet)
+ {
+ iCode *sic;
+
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+
+ aopOp (IC_LEFT (sic), sic, FALSE, TRUE);
+ size = AOP_SIZE (IC_LEFT (sic));
+
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset,
+ FALSE, FALSE, TRUE);
+ if (strcmp (l, fReturn[offset]))
+ emitcode ("mov", "%s,%s",
+ fReturn[offset],
+ l);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
+ _G.sendSet = NULL;
}
- /* make the call */
- emitcode("lcall","%s",(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
- OP_SYMBOL(IC_LEFT(ic))->rname :
- OP_SYMBOL(IC_LEFT(ic))->name));
+ /* make the call */
+ emitcode ("lcall", "%s", (OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
+ OP_SYMBOL (IC_LEFT (ic))->rname :
+ OP_SYMBOL (IC_LEFT (ic))->name));
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) )
+ /* if we need assign a result value */
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
{
- if (isOperandInFarSpace(IC_RESULT(ic))
- && getSize(operandType(IC_RESULT(ic))) <= 2)
- {
- int size = getSize(operandType(IC_RESULT(ic)));
-
- /* Special case for 1 or 2 byte return in far space. */
- emitcode(";", "Kevin function call abuse #1");
-
- MOVA(fReturn[0]);
- if (size > 1)
- {
- emitcode("mov", "b,%s", fReturn[1]);
- }
-
- aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
- aopPut(AOP(IC_RESULT(ic)),"a",0);
-
- if (size > 1)
- {
- aopPut(AOP(IC_RESULT(ic)),"b",1);
- }
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
- }
- else
- {
- _G.accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE, TRUE);
- _G.accInUse--;
+ if (isOperandInFarSpace (IC_RESULT (ic))
+ && getSize (operandType (IC_RESULT (ic))) <= 2)
+ {
+ int size = getSize (operandType (IC_RESULT (ic)));
+
+ /* Special case for 1 or 2 byte return in far space. */
+ emitcode (";", "Kevin function call abuse #1");
+
+ MOVA (fReturn[0]);
+ if (size > 1)
+ {
+ emitcode ("mov", "b,%s", fReturn[1]);
+ }
+
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+
+ if (size > 1)
+ {
+ aopPut (AOP (IC_RESULT (ic)), "b", 1);
+ }
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ }
+ else
+ {
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE, TRUE);
+ _G.accInUse--;
- assignResultValue(IC_RESULT(ic));
+ assignResultValue (IC_RESULT (ic));
- freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
- }
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ }
}
- /* adjust the stack for parameters if
- required */
- if (IC_LEFT(ic)->parmBytes) {
- int i;
- if (IC_LEFT(ic)->parmBytes > 3) {
- emitcode("mov","a,%s",spname);
- emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff);
- emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++)
- emitcode("dec","%s",spname);
+ /* adjust the stack for parameters if
+ required */
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i;
+ if (IC_LEFT (ic)->parmBytes > 3)
+ {
+ emitcode ("mov", "a,%s", spname);
+ emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff);
+ emitcode ("mov", "%s,a", spname);
+ }
+ else
+ for (i = 0; i < IC_LEFT (ic)->parmBytes; i++)
+ emitcode ("dec", "%s", spname);
}
- /* if register bank was saved then pop them */
- if (ic->bankSaved)
- unsaverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if register bank was saved then pop them */
+ if (ic->bankSaved)
+ unsaverbank (SPEC_BANK (detype), ic, TRUE);
- /* if we hade saved some registers then unsave them */
- if (ic->regsSaved && !(OP_SYMBOL(IC_LEFT(ic))->calleeSave))
- unsaveRegisters (ic);
+ /* if we hade saved some registers then unsave them */
+ if (ic->regsSaved && !(OP_SYMBOL (IC_LEFT (ic))->calleeSave))
+ unsaveRegisters (ic);
}
/*-----------------------------------------------------------------*/
/* genPcall - generates a call by pointer statement */
/*-----------------------------------------------------------------*/
-static void genPcall (iCode *ic)
+static void
+genPcall (iCode * ic)
{
- sym_link *detype;
- symbol *rlbl = newiTempLabel(NULL);
+ sym_link *detype;
+ symbol *rlbl = newiTempLabel (NULL);
- D(emitcode(";", "genPcall "););
+ D (emitcode (";", "genPcall ");
+ );
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
- saveRegisters(ic);
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ saveRegisters (ic);
- /* if we are calling a function that is not using
- the same register bank then we need to save the
- destination registers on the stack */
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- IS_ISR(currFunc->etype) &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)))
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if we are calling a function that is not using
+ the same register bank then we need to save the
+ destination registers on the stack */
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ IS_ISR (currFunc->etype) &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)))
+ saverbank (SPEC_BANK (detype), ic, TRUE);
- /* push the return address on to the stack */
- emitcode("mov","a,#%05d$",(rlbl->key+100));
- emitcode("push","acc");
- emitcode("mov","a,#(%05d$ >> 8)",(rlbl->key+100));
- emitcode("push","acc");
+ /* push the return address on to the stack */
+ emitcode ("mov", "a,#%05d$", (rlbl->key + 100));
+ emitcode ("push", "acc");
+ emitcode ("mov", "a,#(%05d$ >> 8)", (rlbl->key + 100));
+ emitcode ("push", "acc");
- if (options.model == MODEL_FLAT24)
+ if (options.model == MODEL_FLAT24)
{
- emitcode("mov","a,#(%05d$ >> 16)",(rlbl->key+100));
- emitcode("push","acc");
+ emitcode ("mov", "a,#(%05d$ >> 16)", (rlbl->key + 100));
+ emitcode ("push", "acc");
}
- /* now push the calling address */
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
+ /* now push the calling address */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
- pushSide(IC_LEFT(ic), FPTRSIZE);
+ pushSide (IC_LEFT (ic), FPTRSIZE);
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
- /* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
-
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet))
- {
- int size, offset = 0;
-
- aopOp(IC_LEFT(sic),sic,FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- _startLazyDPSEvaluation();
- while (size--)
- {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset,
- FALSE,FALSE,TRUE);
- if (strcmp(l,fReturn[offset]))
- {
- emitcode("mov","%s,%s",
- fReturn[offset],
- l);
- }
- offset++;
- }
- _endLazyDPSEvaluation();
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
- }
+ /* if send set is not empty the assign */
+ if (_G.sendSet)
+ {
+ iCode *sic;
+
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+
+ aopOp (IC_LEFT (sic), sic, FALSE, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset,
+ FALSE, FALSE, TRUE);
+ if (strcmp (l, fReturn[offset]))
+ {
+ emitcode ("mov", "%s,%s",
+ fReturn[offset],
+ l);
+ }
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
_G.sendSet = NULL;
}
- emitcode("ret","");
- emitcode("","%05d$:",(rlbl->key+100));
+ emitcode ("ret", "");
+ emitcode ("", "%05d$:", (rlbl->key + 100));
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir)) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+ /* if we need assign a result value */
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
- _G.accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE, TRUE);
- _G.accInUse--;
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE, TRUE);
+ _G.accInUse--;
- assignResultValue(IC_RESULT(ic));
+ assignResultValue (IC_RESULT (ic));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
- /* adjust the stack for parameters if
- required */
- if (IC_LEFT(ic)->parmBytes) {
- int i;
- if (IC_LEFT(ic)->parmBytes > 3) {
- emitcode("mov","a,%s",spname);
- emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff);
- emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++)
- emitcode("dec","%s",spname);
+ /* adjust the stack for parameters if
+ required */
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i;
+ if (IC_LEFT (ic)->parmBytes > 3)
+ {
+ emitcode ("mov", "a,%s", spname);
+ emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff);
+ emitcode ("mov", "%s,a", spname);
+ }
+ else
+ for (i = 0; i < IC_LEFT (ic)->parmBytes; i++)
+ emitcode ("dec", "%s", spname);
}
- /* if register bank was saved then unsave them */
- if (detype &&
- (SPEC_BANK(currFunc->etype) !=
- SPEC_BANK(detype)))
- unsaverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if register bank was saved then unsave them */
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) !=
+ SPEC_BANK (detype)))
+ unsaverbank (SPEC_BANK (detype), ic, TRUE);
- /* if we hade saved some registers then
- unsave them */
- if (ic->regsSaved)
- unsaveRegisters (ic);
+ /* if we hade saved some registers then
+ unsave them */
+ if (ic->regsSaved)
+ unsaveRegisters (ic);
}
/*-----------------------------------------------------------------*/
/* resultRemat - result is rematerializable */
/*-----------------------------------------------------------------*/
-static int resultRemat (iCode *ic)
+static int
+resultRemat (iCode * ic)
{
- if (SKIP_IC(ic) || ic->op == IFX)
- return 0;
+ if (SKIP_IC (ic) || ic->op == IFX)
+ return 0;
- if (IC_RESULT(ic) && IS_ITEMP(IC_RESULT(ic))) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- if (sym->remat && !POINTER_SET(ic))
- return 1;
+ if (IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic)))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ if (sym->remat && !POINTER_SET (ic))
+ return 1;
}
- return 0;
+ return 0;
}
#if defined(__BORLANDC__) || defined(_MSC_VER)
/*-----------------------------------------------------------------*/
/* inExcludeList - return 1 if the string is in exclude Reg list */
/*-----------------------------------------------------------------*/
-static bool inExcludeList(char *s)
+static bool
+inExcludeList (char *s)
{
- int i =0;
-
- if (options.excludeRegs[i] &&
- STRCASECMP(options.excludeRegs[i],"none") == 0)
- return FALSE ;
+ int i = 0;
- for ( i = 0 ; options.excludeRegs[i]; i++) {
if (options.excludeRegs[i] &&
- STRCASECMP(s,options.excludeRegs[i]) == 0)
- return TRUE;
+ 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 ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* genFunction - generated code for function entry */
/*-----------------------------------------------------------------*/
-static void genFunction (iCode *ic)
-{
- symbol *sym;
- sym_link *fetype;
-
- D(emitcode(";", "genFunction "););
-
- _G.nRegsSaved = 0;
- /* create the function header */
- emitcode(";","-----------------------------------------");
- emitcode(";"," function %s",(sym = OP_SYMBOL(IC_LEFT(ic)))->name);
- emitcode(";","-----------------------------------------");
-
- emitcode("","%s:",sym->rname);
- fetype = getSpec(operandType(IC_LEFT(ic)));
-
- /* if critical function then turn interrupts off */
- if (SPEC_CRTCL(fetype))
- emitcode("clr","ea");
-
- /* here we need to generate the equates for the
- register bank if required */
- if (SPEC_BANK(fetype) != rbank) {
- int i ;
-
- rbank = SPEC_BANK(fetype);
- for ( i = 0 ; i < ds390_nRegs ; i++ ) {
- if (strcmp(regs390[i].base,"0") == 0)
- emitcode("","%s = 0x%02x",
- regs390[i].dname,
- 8*rbank+regs390[i].offset);
- else
- emitcode ("","%s = %s + 0x%02x",
- regs390[i].dname,
- regs390[i].base,
- 8*rbank+regs390[i].offset);
- }
- }
-
- /* if this is an interrupt service routine then
- save acc, b, dpl, dph */
- if (IS_ISR(sym->etype)) {
-
- if (!inExcludeList("acc"))
- emitcode ("push","acc");
- if (!inExcludeList("b"))
- emitcode ("push","b");
- if (!inExcludeList("dpl"))
- emitcode ("push","dpl");
- if (!inExcludeList("dph"))
- emitcode ("push","dph");
- if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
- {
- emitcode ("push", "dpx");
- /* Make sure we're using standard DPTR */
- emitcode ("push", "dps");
- emitcode ("mov", "dps, #0x00");
- if (options.stack10bit)
- {
- /* This ISR could conceivably use DPTR2. Better save it. */
- emitcode ("push", "dpl1");
- emitcode ("push", "dph1");
- emitcode ("push", "dpx1");
- emitcode ("push", "ap");
- }
- }
- /* if this isr has no bank i.e. is going to
- run with bank 0 , then we need to save more
- registers :-) */
- if (!SPEC_BANK(sym->etype)) {
-
- /* if this function does not call any other
- function then we can be economical and
- save only those registers that are used */
- if (! sym->hasFcall) {
- int i;
-
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = 0 ; i < sym->regsUsed->size ; i++) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("push","%s",ds390_regWithIdx(i)->dname);
- }
- }
-
- } else {
- /* this function has a function call cannot
- determines register usage so we will have the
- entire bank */
- saverbank(0,ic,FALSE);
- }
- }
- } else {
- /* if callee-save to be used for this function
- then save the registers being used in this function */
- if (sym->calleeSave) {
+static void
+genFunction (iCode * ic)
+{
+ symbol *sym;
+ sym_link *fetype;
+
+ D (emitcode (";", "genFunction ");
+ );
+
+ _G.nRegsSaved = 0;
+ /* create the function header */
+ emitcode (";", "-----------------------------------------");
+ emitcode (";", " function %s", (sym = OP_SYMBOL (IC_LEFT (ic)))->name);
+ emitcode (";", "-----------------------------------------");
+
+ emitcode ("", "%s:", sym->rname);
+ fetype = getSpec (operandType (IC_LEFT (ic)));
+
+ /* if critical function then turn interrupts off */
+ if (SPEC_CRTCL (fetype))
+ emitcode ("clr", "ea");
+
+ /* here we need to generate the equates for the
+ register bank if required */
+ if (SPEC_BANK (fetype) != rbank)
+ {
int i;
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = 0 ; i < sym->regsUsed->size ; i++) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)) ) {
- emitcode("push","%s",ds390_regWithIdx(i)->dname);
- _G.nRegsSaved++;
- }
- }
- }
- }
- }
+ rbank = SPEC_BANK (fetype);
+ for (i = 0; i < ds390_nRegs; i++)
+ {
+ if (strcmp (regs390[i].base, "0") == 0)
+ emitcode ("", "%s = 0x%02x",
+ regs390[i].dname,
+ 8 * rbank + regs390[i].offset);
+ else
+ emitcode ("", "%s = %s + 0x%02x",
+ regs390[i].dname,
+ regs390[i].base,
+ 8 * rbank + regs390[i].offset);
+ }
+ }
+
+ /* if this is an interrupt service routine then
+ save acc, b, dpl, dph */
+ if (IS_ISR (sym->etype))
+ {
- /* set the register bank to the desired value */
- if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype)) {
- emitcode("push","psw");
- emitcode("mov","psw,#0x%02x",(SPEC_BANK(sym->etype) << 3)&0x00ff);
+ if (!inExcludeList ("acc"))
+ emitcode ("push", "acc");
+ if (!inExcludeList ("b"))
+ emitcode ("push", "b");
+ if (!inExcludeList ("dpl"))
+ emitcode ("push", "dpl");
+ if (!inExcludeList ("dph"))
+ emitcode ("push", "dph");
+ if (options.model == MODEL_FLAT24 && !inExcludeList ("dpx"))
+ {
+ emitcode ("push", "dpx");
+ /* Make sure we're using standard DPTR */
+ emitcode ("push", "dps");
+ emitcode ("mov", "dps, #0x00");
+ if (options.stack10bit)
+ {
+ /* This ISR could conceivably use DPTR2. Better save it. */
+ emitcode ("push", "dpl1");
+ emitcode ("push", "dph1");
+ emitcode ("push", "dpx1");
+ emitcode ("push", "ap");
+ }
+ }
+ /* if this isr has no bank i.e. is going to
+ run with bank 0 , then we need to save more
+ registers :-) */
+ if (!SPEC_BANK (sym->etype))
+ {
+
+ /* if this function does not call any other
+ function then we can be economical and
+ save only those registers that are used */
+ if (!sym->hasFcall)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = 0; i < sym->regsUsed->size; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("push", "%s", ds390_regWithIdx (i)->dname);
+ }
+ }
+
+ }
+ else
+ {
+ /* this function has a function call cannot
+ determines register usage so we will have the
+ entire bank */
+ saverbank (0, ic, FALSE);
+ }
+ }
+ }
+ else
+ {
+ /* if callee-save to be used for this function
+ then save the registers being used in this function */
+ if (sym->calleeSave)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = 0; i < sym->regsUsed->size; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ {
+ emitcode ("push", "%s", ds390_regWithIdx (i)->dname);
+ _G.nRegsSaved++;
+ }
+ }
+ }
+ }
+ }
+
+ /* set the register bank to the desired value */
+ if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ {
+ emitcode ("push", "psw");
+ emitcode ("mov", "psw,#0x%02x", (SPEC_BANK (sym->etype) << 3) & 0x00ff);
}
- if (IS_RENT(sym->etype) || options.stackAuto) {
+ if (IS_RENT (sym->etype) || options.stackAuto)
+ {
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- emitcode("mov","a,_bp");
- emitcode("movx","@r0,a");
- emitcode("inc","%s",spname);
- }
- else
- {
- /* set up the stack */
- emitcode ("push","_bp"); /* save the callers stack */
- }
- emitcode ("mov","_bp,%s",spname);
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ emitcode ("mov", "a,_bp");
+ emitcode ("movx", "@r0,a");
+ emitcode ("inc", "%s", spname);
+ }
+ else
+ {
+ /* set up the stack */
+ emitcode ("push", "_bp"); /* save the callers stack */
+ }
+ emitcode ("mov", "_bp,%s", spname);
}
- /* adjust the stack for the function */
- if (sym->stack) {
+ /* adjust the stack for the function */
+ if (sym->stack)
+ {
- int i = sym->stack;
- if (i > 256 )
- werror(W_STACK_OVERFLOW,sym->name);
+ int i = sym->stack;
+ if (i > 256)
+ werror (W_STACK_OVERFLOW, sym->name);
- if (i > 3 && sym->recvSize < 4) {
+ if (i > 3 && sym->recvSize < 4)
+ {
- emitcode ("mov","a,sp");
- emitcode ("add","a,#0x%02x",((char)sym->stack & 0xff));
- emitcode ("mov","sp,a");
+ emitcode ("mov", "a,sp");
+ emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+ emitcode ("mov", "sp,a");
- }
- else
- while(i--)
- emitcode("inc","sp");
+ }
+ else
+ while (i--)
+ emitcode ("inc", "sp");
}
- if (sym->xstack) {
+ if (sym->xstack)
+ {
- emitcode ("mov","a,_spx");
- emitcode ("add","a,#0x%02x",((char)sym->xstack & 0xff));
- emitcode ("mov","_spx,a");
+ emitcode ("mov", "a,_spx");
+ emitcode ("add", "a,#0x%02x", ((char) sym->xstack & 0xff));
+ emitcode ("mov", "_spx,a");
}
}
/*-----------------------------------------------------------------*/
/* genEndFunction - generates epilogue for functions */
/*-----------------------------------------------------------------*/
-static void genEndFunction (iCode *ic)
+static void
+genEndFunction (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
- D(emitcode(";", "genEndFunction "););
+ D (emitcode (";", "genEndFunction ");
+ );
- if (IS_RENT(sym->etype) || options.stackAuto)
+ if (IS_RENT (sym->etype) || options.stackAuto)
{
- emitcode ("mov","%s,_bp",spname);
+ emitcode ("mov", "%s,_bp", spname);
}
- /* if use external stack but some variables were
- added to the local stack then decrement the
- local stack */
- if (options.useXstack && sym->stack) {
- emitcode("mov","a,sp");
- emitcode("add","a,#0x%02x",((char)-sym->stack) & 0xff);
- emitcode("mov","sp,a");
+ /* if use external stack but some variables were
+ added to the local stack then decrement the
+ local stack */
+ if (options.useXstack && sym->stack)
+ {
+ emitcode ("mov", "a,sp");
+ emitcode ("add", "a,#0x%02x", ((char) -sym->stack) & 0xff);
+ emitcode ("mov", "sp,a");
}
- if ((IS_RENT(sym->etype) || options.stackAuto)) {
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- emitcode("movx","a,@r0");
- emitcode("mov","_bp,a");
- emitcode("dec","%s",spname);
- }
- else
- {
- emitcode ("pop","_bp");
- }
+ if ((IS_RENT (sym->etype) || options.stackAuto))
+ {
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ emitcode ("movx", "a,@r0");
+ emitcode ("mov", "_bp,a");
+ emitcode ("dec", "%s", spname);
+ }
+ else
+ {
+ emitcode ("pop", "_bp");
+ }
}
- /* restore the register bank */
- if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype))
- emitcode ("pop","psw");
-
- if (IS_ISR(sym->etype)) {
-
- /* now we need to restore the registers */
- /* if this isr has no bank i.e. is going to
- run with bank 0 , then we need to save more
- registers :-) */
- if (!SPEC_BANK(sym->etype)) {
-
- /* if this function does not call any other
- function then we can be economical and
- save only those registers that are used */
- if (! sym->hasFcall) {
- int i;
-
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",ds390_regWithIdx(i)->dname);
- }
- }
+ /* restore the register bank */
+ if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ emitcode ("pop", "psw");
- } else {
- /* this function has a function call cannot
- determines register usage so we will have the
- entire bank */
- unsaverbank(0,ic,FALSE);
- }
- }
+ if (IS_ISR (sym->etype))
+ {
- if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
- {
- if (options.stack10bit)
- {
- emitcode ("pop", "ap");
- emitcode ("pop", "dpx1");
- emitcode ("pop", "dph1");
- emitcode ("pop", "dpl1");
- }
- emitcode ("pop", "dps");
- emitcode ("pop", "dpx");
- }
- if (!inExcludeList("dph"))
- emitcode ("pop","dph");
- if (!inExcludeList("dpl"))
- emitcode ("pop","dpl");
- if (!inExcludeList("b"))
- emitcode ("pop","b");
- if (!inExcludeList("acc"))
- emitcode ("pop","acc");
-
- if (SPEC_CRTCL(sym->etype))
- emitcode("setb","ea");
-
- /* if debug then send end of function */
+ /* now we need to restore the registers */
+ /* if this isr has no bank i.e. is going to
+ run with bank 0 , then we need to save more
+ registers :-) */
+ if (!SPEC_BANK (sym->etype))
+ {
+
+ /* if this function does not call any other
+ function then we can be economical and
+ save only those registers that are used */
+ if (!sym->hasFcall)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = sym->regsUsed->size; i >= 0; i--)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("pop", "%s", ds390_regWithIdx (i)->dname);
+ }
+ }
+
+ }
+ else
+ {
+ /* this function has a function call cannot
+ determines register usage so we will have the
+ entire bank */
+ unsaverbank (0, ic, FALSE);
+ }
+ }
+
+ if (options.model == MODEL_FLAT24 && !inExcludeList ("dpx"))
+ {
+ if (options.stack10bit)
+ {
+ emitcode ("pop", "ap");
+ emitcode ("pop", "dpx1");
+ emitcode ("pop", "dph1");
+ emitcode ("pop", "dpl1");
+ }
+ emitcode ("pop", "dps");
+ emitcode ("pop", "dpx");
+ }
+ if (!inExcludeList ("dph"))
+ emitcode ("pop", "dph");
+ if (!inExcludeList ("dpl"))
+ emitcode ("pop", "dpl");
+ if (!inExcludeList ("b"))
+ emitcode ("pop", "b");
+ if (!inExcludeList ("acc"))
+ emitcode ("pop", "acc");
+
+ if (SPEC_CRTCL (sym->etype))
+ emitcode ("setb", "ea");
+
+ /* if debug then send end of function */
/* if (options.debug && currFunc) { */
- if (currFunc) {
- _G.debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),currFunc->lastLine,
- ic->level,ic->block);
- if (IS_STATIC(currFunc->etype))
- emitcode("","XF%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","XG$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
-
- emitcode ("reti","");
+ if (currFunc)
+ {
+ _G.debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), currFunc->lastLine,
+ ic->level, ic->block);
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode ("", "XG$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
+
+ emitcode ("reti", "");
}
- else {
- if (SPEC_CRTCL(sym->etype))
- emitcode("setb","ea");
+ else
+ {
+ if (SPEC_CRTCL (sym->etype))
+ emitcode ("setb", "ea");
- if (sym->calleeSave) {
- int i;
+ if (sym->calleeSave)
+ {
+ int i;
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",ds390_regWithIdx(i)->dname);
- }
- }
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = sym->regsUsed->size; i >= 0; i--)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("pop", "%s", ds390_regWithIdx (i)->dname);
+ }
+ }
- }
+ }
- /* if debug then send end of function */
- if (currFunc) {
- _G.debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),currFunc->lastLine,
- ic->level,ic->block);
- if (IS_STATIC(currFunc->etype))
- emitcode("","XF%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","XG$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
+ /* if debug then send end of function */
+ if (currFunc)
+ {
+ _G.debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), currFunc->lastLine,
+ ic->level, ic->block);
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode ("", "XG$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
- emitcode ("ret","");
+ emitcode ("ret", "");
}
}
/*-----------------------------------------------------------------*/
/* genRet - generate code for return statement */
/*-----------------------------------------------------------------*/
-static void genRet (iCode *ic)
-{
- int size,offset = 0 , pushed = 0;
-
- D(emitcode(";", "genRet "););
-
- /* if we have no return value then
- just generate the "ret" */
- if (!IC_LEFT(ic))
- goto jumpret;
-
- /* we have something to return then
- move the return value into place */
- aopOp(IC_LEFT(ic),ic,FALSE, TRUE);
- size = AOP_SIZE(IC_LEFT(ic));
-
- _startLazyDPSEvaluation();
- while (size--) {
- char *l ;
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++,
- FALSE,TRUE,FALSE);
- emitcode("push","%s",l);
- pushed++;
- } else {
- l = aopGet(AOP(IC_LEFT(ic)),offset,
- FALSE,FALSE,FALSE);
- if (strcmp(fReturn[offset],l))
- emitcode("mov","%s,%s",fReturn[offset++],l);
- }
- }
- _endLazyDPSEvaluation();
+static void
+genRet (iCode * ic)
+{
+ int size, offset = 0, pushed = 0;
+
+ D (emitcode (";", "genRet ");
+ );
+
+ /* if we have no return value then
+ just generate the "ret" */
+ if (!IC_LEFT (ic))
+ goto jumpret;
- if (pushed) {
- while(pushed) {
- pushed--;
- if (strcmp(fReturn[pushed],"a"))
- emitcode("pop",fReturn[pushed]);
+ /* we have something to return then
+ move the return value into place */
+ aopOp (IC_LEFT (ic), ic, FALSE, TRUE);
+ size = AOP_SIZE (IC_LEFT (ic));
+
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l;
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++,
+ FALSE, TRUE, FALSE);
+ emitcode ("push", "%s", l);
+ pushed++;
+ }
else
- emitcode("pop","acc");
- }
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset,
+ FALSE, FALSE, FALSE);
+ if (strcmp (fReturn[offset], l))
+ emitcode ("mov", "%s,%s", fReturn[offset++], l);
+ }
}
- freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
+ _endLazyDPSEvaluation ();
- jumpret:
+ if (pushed)
+ {
+ while (pushed)
+ {
+ pushed--;
+ if (strcmp (fReturn[pushed], "a"))
+ emitcode ("pop", fReturn[pushed]);
+ else
+ emitcode ("pop", "acc");
+ }
+ }
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
+
+jumpret:
/* generate a jump to the return label
if the next is not the return statement */
- if (!(ic->next && ic->next->op == LABEL &&
- IC_LABEL(ic->next) == returnLabel))
+ if (!(ic->next && ic->next->op == LABEL &&
+ IC_LABEL (ic->next) == returnLabel))
- emitcode("ljmp","%05d$",(returnLabel->key+100));
+ emitcode ("ljmp", "%05d$", (returnLabel->key + 100));
}
/*-----------------------------------------------------------------*/
/* genLabel - generates a label */
/*-----------------------------------------------------------------*/
-static void genLabel (iCode *ic)
+static void
+genLabel (iCode * ic)
{
- /* special case never generate */
- if (IC_LABEL(ic) == entryLabel)
- return ;
+ /* special case never generate */
+ if (IC_LABEL (ic) == entryLabel)
+ return;
- D(emitcode(";", "genLabel "););
+ D (emitcode (";", "genLabel ");
+ );
- emitcode("","%05d$:",(IC_LABEL(ic)->key+100));
+ emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100));
}
/*-----------------------------------------------------------------*/
/* genGoto - generates a ljmp */
/*-----------------------------------------------------------------*/
-static void genGoto (iCode *ic)
+static void
+genGoto (iCode * ic)
{
- D(emitcode(";", "genGoto "););
- emitcode ("ljmp","%05d$",(IC_LABEL(ic)->key+100));
+ D (emitcode (";", "genGoto ");
+ );
+ emitcode ("ljmp", "%05d$", (IC_LABEL (ic)->key + 100));
}
/*-----------------------------------------------------------------*/
/* between that label and given ic. */
/* Returns zero if label not found. */
/*-----------------------------------------------------------------*/
-static int findLabelBackwards(iCode *ic, int key)
+static int
+findLabelBackwards (iCode * ic, int key)
{
- int count = 0;
+ int count = 0;
- while (ic->prev)
+ while (ic->prev)
{
- ic = ic->prev;
- count++;
+ ic = ic->prev;
+ count++;
- if (ic->op == LABEL && IC_LABEL(ic)->key == key)
- {
- /* printf("findLabelBackwards = %d\n", count); */
- return count;
- }
+ if (ic->op == LABEL && IC_LABEL (ic)->key == key)
+ {
+ /* printf("findLabelBackwards = %d\n", count); */
+ return count;
+ }
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* genPlusIncr :- does addition with increment if possible */
/*-----------------------------------------------------------------*/
-static bool genPlusIncr (iCode *ic)
-{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
-
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
-
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 4)
- return FALSE ;
-
- /* if increment 16 bits in register */
- if (
- AOP_TYPE(IC_LEFT(ic)) == AOP_REG &&
- AOP_TYPE(IC_RESULT(ic)) == AOP_REG &&
- sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) &&
- (icount == 1)) {
- symbol *tlbl;
- int emitTlbl;
- int labelRange;
-
- /* If the next instruction is a goto and the goto target
- * is <= 5 instructions previous to this, we can generate
- * jumps straight to that target.
- */
- if (ic->next && ic->next->op == GOTO
- && (labelRange = findLabelBackwards(ic, IC_LABEL(ic->next)->key)) != 0
- && labelRange <= 5 )
- {
- emitcode(";", "tail increment optimized (range %d)", labelRange);
- tlbl = IC_LABEL(ic->next);
- emitTlbl = 0;
- }
- else
- {
- tlbl = newiTempLabel(NULL);
- emitTlbl = 1;
- }
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0x00,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- else {
- emitcode("clr","a");
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- }
+static bool
+genPlusIncr (iCode * ic)
+{
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
+
+ /* will try to generate an increment */
+ /* if the right side is not a literal
+ we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
+
+ /* if the literal value of the right hand side
+ is greater than 4 then it is not worth it */
+ if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
+ return FALSE;
+
+ /* if increment 16 bits in register */
+ if (
+ AOP_TYPE (IC_LEFT (ic)) == AOP_REG &&
+ AOP_TYPE (IC_RESULT (ic)) == AOP_REG &&
+ sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (size > 1) &&
+ (icount == 1))
+ {
+ symbol *tlbl;
+ int emitTlbl;
+ int labelRange;
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE));
- if (size > 2)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0x00,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
+ /* If the next instruction is a goto and the goto target
+ * is <= 5 instructions previous to this, we can generate
+ * jumps straight to that target.
+ */
+ if (ic->next && ic->next->op == GOTO
+ && (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
+ && labelRange <= 5)
+ {
+ emitcode (";", "tail increment optimized (range %d)", labelRange);
+ tlbl = IC_LABEL (ic->next);
+ emitTlbl = 0;
+ }
else
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
-
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE));
- }
- if (size > 3)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0x00,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE,FALSE));
- }
-
- if (emitTlbl)
- {
- emitcode("","%05d$:",tlbl->key+100);
- }
- return TRUE;
+ {
+ tlbl = newiTempLabel (NULL);
+ emitTlbl = 1;
+ }
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0x00,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("clr", "a");
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE, FALSE));
+ if (size > 2)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0x00,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE, FALSE));
+ }
+ if (size > 3)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0x00,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE, FALSE));
+ }
+
+ if (emitTlbl)
+ {
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* we can if the aops of the left & result match or
- if they are in registers and the registers are the
- same */
- if (
- AOP_TYPE(IC_LEFT(ic)) == AOP_REG &&
- AOP_TYPE(IC_RESULT(ic)) == AOP_REG &&
- sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
+ /* we can if the aops of the left & result match or
+ if they are in registers and the registers are the
+ same */
+ if (
+ AOP_TYPE (IC_LEFT (ic)) == AOP_REG &&
+ AOP_TYPE (IC_RESULT (ic)) == AOP_REG &&
+ sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
- if (icount > 3) {
- MOVA(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE,TRUE));
- emitcode("add","a,#0x%02x",((char) icount) & 0xff);
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- } else {
+ if (icount > 3)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE, TRUE));
+ emitcode ("add", "a,#0x%02x", ((char) icount) & 0xff);
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ }
+ else
+ {
- _startLazyDPSEvaluation();
- while (icount--)
- {
- emitcode ("inc","%s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE,FALSE));
- }
- _endLazyDPSEvaluation();
- }
+ _startLazyDPSEvaluation ();
+ while (icount--)
+ {
+ emitcode ("inc", "%s", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE, FALSE));
+ }
+ _endLazyDPSEvaluation ();
+ }
- return TRUE ;
+ return TRUE;
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* outBitAcc - output a bit in acc */
/*-----------------------------------------------------------------*/
-static void outBitAcc(operand *result)
+static void
+outBitAcc (operand * result)
{
- symbol *tlbl = newiTempLabel(NULL);
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY){
- aopPut(AOP(result),"a",0);
+ symbol *tlbl = newiTempLabel (NULL);
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ aopPut (AOP (result), "a", 0);
}
- else {
- emitcode("jz","%05d$",tlbl->key+100);
- emitcode("mov","a,%s",one);
- emitcode("","%05d$:",tlbl->key+100);
- outAcc(result);
+ else
+ {
+ emitcode ("jz", "%05d$", tlbl->key + 100);
+ emitcode ("mov", "a,%s", one);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outAcc (result);
}
}
/*-----------------------------------------------------------------*/
/* genPlusBits - generates code for addition of two bits */
/*-----------------------------------------------------------------*/
-static void genPlusBits (iCode *ic)
+static void
+genPlusBits (iCode * ic)
{
- D(emitcode(";", "genPlusBits "););
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("jnb","%s,%05d$",AOP(IC_RIGHT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- outBitC(IC_RESULT(ic));
+ D (emitcode (";", "genPlusBits ");
+ );
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("jnb", "%s,%05d$", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ outBitC (IC_RESULT (ic));
}
- else{
- emitcode("clr","a");
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("rlc","a");
- emitcode("mov","c,%s",AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("addc","a,#0x00");
- outAcc(IC_RESULT(ic));
+ else
+ {
+ emitcode ("clr", "a");
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("rlc", "a");
+ emitcode ("mov", "c,%s", AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode ("addc", "a,#0x00");
+ outAcc (IC_RESULT (ic));
}
}
-static void adjustArithmeticResult(iCode *ic)
+static void
+adjustArithmeticResult (iCode * ic)
{
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_LEFT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_LEFT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_LEFT(ic)), GPTRSIZE - 1,FALSE,FALSE,FALSE),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_LEFT (ic)), GPTRSIZE - 1, FALSE, FALSE, FALSE),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_RIGHT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_RIGHT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_RIGHT(ic)),GPTRSIZE - 1,FALSE,FALSE,FALSE),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_RIGHT (ic)), GPTRSIZE - 1, FALSE, FALSE, FALSE),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- AOP_SIZE(IC_LEFT(ic)) < GPTRSIZE &&
- AOP_SIZE(IC_RIGHT(ic)) < GPTRSIZE &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
- char buffer[5];
- sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
- aopPut(AOP(IC_RESULT(ic)),buffer,GPTRSIZE - 1);
- }
+ if (opIsGptr (IC_RESULT (ic)) &&
+ AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+ AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ {
+ char buffer[5];
+ sprintf (buffer, "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic)))));
+ aopPut (AOP (IC_RESULT (ic)), buffer, GPTRSIZE - 1);
+ }
}
#define AOP_OP_3(ic) \
/*-----------------------------------------------------------------*/
/* genPlus - generates code for addition */
/*-----------------------------------------------------------------*/
-static void genPlus (iCode *ic)
+static void
+genPlus (iCode * ic)
{
- int size, offset = 0;
- bool pushResult = FALSE;
- int rSize;
+ int size, offset = 0;
+ bool pushResult = FALSE;
+ int rSize;
- D(emitcode(";", "genPlus "););
+ D (emitcode (";", "genPlus ");
+ );
- /* special cases :- */
+ /* special cases :- */
- AOP_OP_3_NOFATAL(ic, pushResult);
- if (pushResult)
- {
- D(emitcode(";", "genPlus: must push result: 3 ops in far space"););
- }
-
- if (!pushResult)
- {
- /* if literal, literal on the right or
- if left requires ACC or right is already
- in ACC */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT)
- || ((AOP_NEEDSACC(IC_LEFT(ic))) && !(AOP_NEEDSACC(IC_RIGHT(ic))))
- || AOP_TYPE(IC_RIGHT(ic)) == AOP_ACC )
+ AOP_OP_3_NOFATAL (ic, pushResult);
+ if (pushResult)
{
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
- emitcode(";", "Swapped plus args.");
+ D (emitcode (";", "genPlus: must push result: 3 ops in far space");
+ );
}
- /* if both left & right are in bit
- space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- genPlusBits (ic);
- goto release ;
- }
-
- /* if left in bit space & right literal */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- /* if result in bit space */
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- if((unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit) != 0L)
- emitcode("cpl","c");
- outBitC(IC_RESULT(ic));
- } else {
- size = getDataSize(IC_RESULT(ic));
- _startLazyDPSEvaluation();
- while (size--) {
- MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,TRUE));
- emitcode("addc","a,#00");
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
- }
- _endLazyDPSEvaluation();
- }
- goto release ;
- }
-
- /* if I can do an increment instead
- of add then GOOD for ME */
- if (genPlusIncr (ic) == TRUE)
+ if (!pushResult)
{
- emitcode(";", "did genPlusIncr");
- goto release;
- }
-
- }
- size = getDataSize(pushResult ? IC_LEFT(ic) : IC_RESULT(ic));
-
- _startLazyDPSEvaluation();
- while(size--)
+ /* if literal, literal on the right or
+ if left requires ACC or right is already
+ in ACC */
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT)
+ || ((AOP_NEEDSACC (IC_LEFT (ic))) && !(AOP_NEEDSACC (IC_RIGHT (ic))))
+ || AOP_TYPE (IC_RIGHT (ic)) == AOP_ACC)
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
+ emitcode (";", "Swapped plus args.");
+ }
+
+ /* if both left & right are in bit
+ space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ genPlusBits (ic);
+ goto release;
+ }
+
+ /* if left in bit space & right literal */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT)
+ {
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ /* if result in bit space */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ if ((unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) != 0L)
+ emitcode ("cpl", "c");
+ outBitC (IC_RESULT (ic));
+ }
+ else
+ {
+ size = getDataSize (IC_RESULT (ic));
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ MOVA (aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, TRUE));
+ emitcode ("addc", "a,#00");
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
+ }
+ _endLazyDPSEvaluation ();
+ }
+ goto release;
+ }
+
+ /* if I can do an increment instead
+ of add then GOOD for ME */
+ if (genPlusIncr (ic) == TRUE)
+ {
+ emitcode (";", "did genPlusIncr");
+ goto release;
+ }
+
+ }
+ size = getDataSize (pushResult ? IC_LEFT (ic) : IC_RESULT (ic));
+
+ _startLazyDPSEvaluation ();
+ while (size--)
{
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC)
- {
- MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE));
- if(offset == 0)
- emitcode("add","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,FALSE));
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, TRUE));
+ if (offset == 0)
+ emitcode ("add", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, FALSE));
+ else
+ emitcode ("addc", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, FALSE));
+ }
else
- emitcode("addc","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,FALSE));
- } else {
- MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,TRUE));
- if(offset == 0)
- emitcode("add","a,%s",
- aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,FALSE));
+ {
+ MOVA (aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, TRUE));
+ if (offset == 0)
+ emitcode ("add", "a,%s",
+ aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, FALSE));
+ else
+ emitcode ("addc", "a,%s",
+ aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, FALSE));
+ }
+ if (!pushResult)
+ {
+ aopPut (AOP (IC_RESULT (ic)), "a", offset);
+ }
else
- emitcode("addc","a,%s",
- aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,FALSE));
- }
- if (!pushResult)
- {
- aopPut(AOP(IC_RESULT(ic)),"a",offset);
- }
- else
- {
- emitcode("push", "acc");
- }
- offset++;
+ {
+ emitcode ("push", "acc");
+ }
+ offset++;
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- if (pushResult)
+ if (pushResult)
{
- aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
- size = getDataSize(IC_LEFT(ic));
- rSize = getDataSize(IC_RESULT(ic));
+ size = getDataSize (IC_LEFT (ic));
+ rSize = getDataSize (IC_RESULT (ic));
- /* If the pushed data is bigger than the result,
- * simply discard unused bytes. Icky, but works.
- *
- * Should we throw a warning here? We're losing data...
- */
- while (size > rSize)
- {
- D(emitcode(";", "discarding unused result byte."););
- emitcode("pop", "acc");
- size--;
- offset--;
- }
- if (size < rSize)
- {
- emitcode("clr", "a");
- /* Conversly, we haven't pushed enough here.
- * just zero-pad, and all is well.
+ /* If the pushed data is bigger than the result,
+ * simply discard unused bytes. Icky, but works.
+ *
+ * Should we throw a warning here? We're losing data...
*/
- while (size < rSize)
- {
- emitcode("push", "acc");
- size++;
- offset++;
- }
- }
-
- _startLazyDPSEvaluation();
- while(size--)
- {
- emitcode("pop", "acc");
- aopPut(AOP(IC_RESULT(ic)), "a", --offset);
- }
- _endLazyDPSEvaluation();
+ while (size > rSize)
+ {
+ D (emitcode (";", "discarding unused result byte.");
+ );
+ emitcode ("pop", "acc");
+ size--;
+ offset--;
+ }
+ if (size < rSize)
+ {
+ emitcode ("clr", "a");
+ /* Conversly, we haven't pushed enough here.
+ * just zero-pad, and all is well.
+ */
+ while (size < rSize)
+ {
+ emitcode ("push", "acc");
+ size++;
+ offset++;
+ }
+ }
+
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ emitcode ("pop", "acc");
+ aopPut (AOP (IC_RESULT (ic)), "a", --offset);
+ }
+ _endLazyDPSEvaluation ();
}
- adjustArithmeticResult(ic);
+ adjustArithmeticResult (ic);
release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMinusDec :- does subtraction with deccrement if possible */
/*-----------------------------------------------------------------*/
-static bool genMinusDec (iCode *ic)
-{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
-
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
-
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 4)
- return FALSE ;
-
- /* if decrement 16 bits in register */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_REG &&
- AOP_TYPE(IC_RESULT(ic)) == AOP_REG &&
- sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) &&
- (icount == 1)) {
- symbol *tlbl;
- int emitTlbl;
- int labelRange;
+static bool
+genMinusDec (iCode * ic)
+{
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
+
+ /* will try to generate an increment */
+ /* if the right side is not a literal
+ we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
+
+ /* if the literal value of the right hand side
+ is greater than 4 then it is not worth it */
+ if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
+ return FALSE;
+
+ /* if decrement 16 bits in register */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_REG &&
+ AOP_TYPE (IC_RESULT (ic)) == AOP_REG &&
+ sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (size > 1) &&
+ (icount == 1))
+ {
+ symbol *tlbl;
+ int emitTlbl;
+ int labelRange;
/* If the next instruction is a goto and the goto target
* is <= 5 instructions previous to this, we can generate
- * jumps straight to that target.
+ * jumps straight to that target.
*/
- if (ic->next && ic->next->op == GOTO
- && (labelRange = findLabelBackwards(ic, IC_LABEL(ic->next)->key)) != 0
- && labelRange <= 5 )
- {
- emitcode(";", "tail decrement optimized (range %d)", labelRange);
- tlbl = IC_LABEL(ic->next);
- emitTlbl = 0;
- }
- else
- {
- tlbl = newiTempLabel(NULL);
- emitTlbl = 1;
- }
-
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0xff,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("mov","a,#0xff");
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE));
- if (size > 2)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0xff,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE));
- }
- if (size > 3)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- AOP_TYPE(IC_RESULT(ic)) == AOP_DPTR ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0xff,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE,FALSE));
- }
- if (emitTlbl)
- {
- emitcode("","%05d$:",tlbl->key+100);
- }
- return TRUE;
+ if (ic->next && ic->next->op == GOTO
+ && (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
+ && labelRange <= 5)
+ {
+ emitcode (";", "tail decrement optimized (range %d)", labelRange);
+ tlbl = IC_LABEL (ic->next);
+ emitTlbl = 0;
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ emitTlbl = 1;
+ }
+
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0xff,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("mov", "a,#0xff");
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE, FALSE));
+ if (size > 2)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0xff,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE, FALSE));
+ }
+ if (size > 3)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0xff,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE, FALSE));
+ }
+ if (emitTlbl)
+ {
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* we can if the aops of the left & result match or
- if they are in registers and the registers are the
- same */
- if (
- AOP_TYPE(IC_LEFT(ic)) == AOP_REG &&
- AOP_TYPE(IC_RESULT(ic)) == AOP_REG &&
- sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
+ /* we can if the aops of the left & result match or
+ if they are in registers and the registers are the
+ same */
+ if (
+ AOP_TYPE (IC_LEFT (ic)) == AOP_REG &&
+ AOP_TYPE (IC_RESULT (ic)) == AOP_REG &&
+ sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
- _startLazyDPSEvaluation();
- while (icount--)
- {
- emitcode ("dec","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
- }
- _endLazyDPSEvaluation();
+ _startLazyDPSEvaluation ();
+ while (icount--)
+ {
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE, FALSE));
+ }
+ _endLazyDPSEvaluation ();
- return TRUE ;
+ return TRUE;
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* addSign - complete with sign */
/*-----------------------------------------------------------------*/
-static void addSign(operand *result, int offset, int 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++);
+ 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++);
}
}
/*-----------------------------------------------------------------*/
/* genMinusBits - generates code for subtraction of two bits */
/*-----------------------------------------------------------------*/
-static void genMinusBits (iCode *ic)
+static void
+genMinusBits (iCode * ic)
{
- symbol *lbl = newiTempLabel(NULL);
+ symbol *lbl = newiTempLabel (NULL);
- D(emitcode(";", "genMinusBits "););
+ D (emitcode (";", "genMinusBits ");
+ );
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("jnb","%s,%05d$",AOP(IC_RIGHT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- outBitC(IC_RESULT(ic));
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("jnb", "%s,%05d$", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ outBitC (IC_RESULT (ic));
}
- else{
- emitcode("mov","c,%s",AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("subb","a,acc");
- emitcode("jnb","%s,%05d$",AOP(IC_LEFT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- addSign(IC_RESULT(ic), MSB16, SPEC_USIGN(getSpec(operandType(IC_RESULT(ic)))));
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode ("subb", "a,acc");
+ emitcode ("jnb", "%s,%05d$", AOP (IC_LEFT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ addSign (IC_RESULT (ic), MSB16, SPEC_USIGN (getSpec (operandType (IC_RESULT (ic)))));
}
}
/*-----------------------------------------------------------------*/
/* genMinus - generates code for subtraction */
/*-----------------------------------------------------------------*/
-static void genMinus (iCode *ic)
+static void
+genMinus (iCode * ic)
{
- int size, offset = 0;
- int rSize;
- unsigned long lit = 0L;
- bool pushResult = FALSE;
+ int size, offset = 0;
+ int rSize;
+ unsigned long lit = 0L;
+ bool pushResult = FALSE;
- D(emitcode(";", "genMinus "););
+ D (emitcode (";", "genMinus ");
+ );
- aopOp (IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE, TRUE);
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) &&
- (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR2))
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE, TRUE);
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR) &&
+ (AOP_TYPE (IC_RIGHT (ic)) == AOP_DPTR2))
{
- pushResult = TRUE;
+ pushResult = TRUE;
}
- else
+ else
{
- aopOp (IC_RESULT(ic),ic,TRUE, AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR);
+ aopOp (IC_RESULT (ic), ic, TRUE, AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR);
- /* special cases :- */
- /* if both left & right are in bit space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- genMinusBits (ic);
- goto release ;
- }
+ /* special cases :- */
+ /* if both left & right are in bit space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ genMinusBits (ic);
+ goto release;
+ }
- /* if I can do an decrement instead
- of subtract then GOOD for ME */
- if (genMinusDec (ic) == TRUE)
- goto release;
+ /* if I can do an decrement instead
+ of subtract then GOOD for ME */
+ if (genMinusDec (ic) == TRUE)
+ goto release;
}
- size = getDataSize(pushResult ? IC_LEFT(ic) : IC_RESULT(ic));
+ size = getDataSize (pushResult ? IC_LEFT (ic) : IC_RESULT (ic));
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT){
- CLRC;
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ {
+ CLRC;
}
- else{
- lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- lit = - (long)lit;
+ else
+ {
+ lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ lit = -(long) lit;
}
- /* if literal, add a,#-lit, else normal subb */
- _startLazyDPSEvaluation();
- while (size--) {
- MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE));
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- emitcode("subb","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,FALSE));
- else{
- /* first add without previous c */
- if(!offset)
- emitcode("add","a,#0x%02x",
- (unsigned int)(lit & 0x0FFL));
- else
- emitcode("addc","a,#0x%02x",
- (unsigned int)((lit >> (offset*8)) & 0x0FFL));
- }
-
- if (pushResult)
- {
- emitcode("push", "acc");
- }
- else
- {
- aopPut(AOP(IC_RESULT(ic)),"a",offset);
- }
- offset++;
+ /* if literal, add a,#-lit, else normal subb */
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, TRUE));
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ emitcode ("subb", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, FALSE));
+ else
+ {
+ /* first add without previous c */
+ if (!offset)
+ emitcode ("add", "a,#0x%02x",
+ (unsigned int) (lit & 0x0FFL));
+ else
+ emitcode ("addc", "a,#0x%02x",
+ (unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
+ }
+
+ if (pushResult)
+ {
+ emitcode ("push", "acc");
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), "a", offset);
+ }
+ offset++;
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- if (pushResult)
+ if (pushResult)
{
- aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
- size = getDataSize(IC_LEFT(ic));
- rSize = getDataSize(IC_RESULT(ic));
+ size = getDataSize (IC_LEFT (ic));
+ rSize = getDataSize (IC_RESULT (ic));
- /* If the pushed data is bigger than the result,
- * simply discard unused bytes. Icky, but works.
- *
- * Should we throw a warning here? We're losing data...
- */
- while (size > getDataSize(IC_RESULT(ic)))
- {
- emitcode(";", "discarding unused result byte.");
- emitcode("pop", "acc");
- size--;
- offset--;
- }
- if (size < rSize)
- {
- emitcode("clr", "a");
- /* Conversly, we haven't pushed enough here.
- * just zero-pad, and all is well.
+ /* If the pushed data is bigger than the result,
+ * simply discard unused bytes. Icky, but works.
+ *
+ * Should we throw a warning here? We're losing data...
*/
- while (size < rSize)
- {
- emitcode("push", "acc");
- size++;
- offset++;
- }
- }
+ while (size > getDataSize (IC_RESULT (ic)))
+ {
+ emitcode (";", "discarding unused result byte.");
+ emitcode ("pop", "acc");
+ size--;
+ offset--;
+ }
+ if (size < rSize)
+ {
+ emitcode ("clr", "a");
+ /* Conversly, we haven't pushed enough here.
+ * just zero-pad, and all is well.
+ */
+ while (size < rSize)
+ {
+ emitcode ("push", "acc");
+ size++;
+ offset++;
+ }
+ }
- while(size--)
- {
- emitcode("pop", "acc");
- aopPut(AOP(IC_RESULT(ic)), "a", --offset);
- }
+ while (size--)
+ {
+ emitcode ("pop", "acc");
+ aopPut (AOP (IC_RESULT (ic)), "a", --offset);
+ }
}
- adjustArithmeticResult(ic);
+ adjustArithmeticResult (ic);
release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMultbits :- multiplication of bits */
/*-----------------------------------------------------------------*/
-static void genMultbits (operand *left,
- operand *right,
- operand *result)
+static void
+genMultbits (operand * left,
+ operand * right,
+ operand * result)
{
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
}
/*-----------------------------------------------------------------*/
/* genMultOneByte : 8 bit multiplication & division */
/*-----------------------------------------------------------------*/
-static void genMultOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- /* (if two literals, the value is computed before) */
- /* if one literal, literal on the right */
- if (AOP_TYPE(left) == AOP_LIT){
- operand *t = right;
- right = left;
- left = t;
- }
-
- size = AOP_SIZE(result);
- /* signed or unsigned */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("mul","ab");
- /* if result size = 1, mul signed = mul unsigned */
- aopPut(AOP(result),"a",0);
- if (size > 1){
- if (SPEC_USIGN(opetype)){
- aopPut(AOP(result),"b",1);
- if (size > 2)
- /* for filling the MSBs */
- emitcode("clr","a");
- }
- else{
- emitcode("mov","a,b");
-
- /* adjust the MSB if left or right neg */
-
- /* if one literal */
- if (AOP_TYPE(right) == AOP_LIT){
- /* AND literal negative */
- if((int) floatFromVal (AOP(right)->aopu.aop_lit) < 0){
- /* adjust MSB (c==0 after mul) */
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE,FALSE));
- }
- }
- else{
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d$", (lbl->key+100));
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d$",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE,FALSE));
- emitcode("","%05d$:",(lbl->key+100));
- }
-
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d$", (lbl->key+100));
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d$",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- emitcode("","%05d$:",(lbl->key+100));
-
- aopPut(AOP(result),"a",1);
- if(size > 2){
- /* get the sign */
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- }
- }
- size -= 2;
- offset = 2;
- if (size > 0)
- while (size--)
- aopPut(AOP(result),"a",offset++);
+static void
+genMultOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+ int size, offset;
+
+ /* (if two literals, the value is computed before) */
+ /* if one literal, literal on the right */
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
+
+ size = AOP_SIZE (result);
+ /* signed or unsigned */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("mul", "ab");
+ /* if result size = 1, mul signed = mul unsigned */
+ aopPut (AOP (result), "a", 0);
+ if (size > 1)
+ {
+ if (SPEC_USIGN (opetype))
+ {
+ aopPut (AOP (result), "b", 1);
+ if (size > 2)
+ /* for filling the MSBs */
+ emitcode ("clr", "a");
+ }
+ else
+ {
+ emitcode ("mov", "a,b");
+
+ /* adjust the MSB if left or right neg */
+
+ /* if one literal */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ /* AND literal negative */
+ if ((int) floatFromVal (AOP (right)->aopu.aop_lit) < 0)
+ {
+ /* adjust MSB (c==0 after mul) */
+ emitcode ("subb", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE, FALSE));
+ }
+ }
+ else
+ {
+ lbl = newiTempLabel (NULL);
+ emitcode ("xch", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ emitcode ("cjne", "a,#0x80,%05d$", (lbl->key + 100));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("xch", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ lbl = newiTempLabel (NULL);
+ emitcode ("jc", "%05d$", (lbl->key + 100));
+ emitcode ("subb", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE, FALSE));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ }
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("xch", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE, FALSE));
+ emitcode ("cjne", "a,#0x80,%05d$", (lbl->key + 100));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE, FALSE));
+ lbl = newiTempLabel (NULL);
+ emitcode ("jc", "%05d$", (lbl->key + 100));
+ emitcode ("subb", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ aopPut (AOP (result), "a", 1);
+ if (size > 2)
+ {
+ /* get the sign */
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ }
+ }
+ size -= 2;
+ offset = 2;
+ if (size > 0)
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
}
}
/*-----------------------------------------------------------------*/
/* genMult - generates code for multiplication */
/*-----------------------------------------------------------------*/
-static void genMult (iCode *ic)
+static void
+genMult (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- D(emitcode(";", "genMult "););
+ D (emitcode (";", "genMult ");
+ );
- /* assign the amsops */
- AOP_OP_3(ic);
+ /* assign the amsops */
+ AOP_OP_3 (ic);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genMultbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genMultbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genMultOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genMultOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1) ;
+ /* should have been converted to function call */
+ assert (1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDivbits :- division of bits */
/*-----------------------------------------------------------------*/
-static void genDivbits (operand *left,
- operand *right,
- operand *result)
+static void
+genDivbits (operand * left,
+ operand * right,
+ operand * result)
{
- char *l;
+ char *l;
- /* the result must be bit */
- LOAD_AB_FOR_DIV(left, right, l);
- emitcode("div","ab");
- emitcode("rrc","a");
- aopPut(AOP(result),"c",0);
+ /* the result must be bit */
+ LOAD_AB_FOR_DIV (left, right, l);
+ emitcode ("div", "ab");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "c", 0);
}
/*-----------------------------------------------------------------*/
/* genDivOneByte : 8 bit division */
/*-----------------------------------------------------------------*/
-static void genDivOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- size = AOP_SIZE(result) - 1;
- offset = 1;
- /* signed or unsigned */
- if (SPEC_USIGN(opetype)) {
- /* unsigned is easy */
- LOAD_AB_FOR_DIV(left, right, l);
- emitcode("div","ab");
- aopPut(AOP(result),"a",0);
- while (size--)
- aopPut(AOP(result),zero,offset++);
- return ;
- }
-
- /* signed is a little bit more difficult */
-
- /* save the signs of the operands */
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,TRUE,FALSE));
- emitcode("push","acc"); /* save it on the stack */
-
- /* now sign adjust for both left & right */
- l = aopGet(AOP(right),0,FALSE,FALSE,TRUE);
- MOVA(l);
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("mov","b,a");
-
- /* sign adjust left side */
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now the division */
- emitcode("nop", "; workaround for DS80C390 div bug.");
- emitcode("div","ab");
- /* we are interested in the lower order
- only */
- emitcode("mov","b,a");
- lbl = newiTempLabel(NULL);
- emitcode("pop","acc");
- /* if there was an over flow we don't
- adjust the sign of the result */
- emitcode("jb","ov,%05d$",(lbl->key+100));
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- CLRC;
- emitcode("clr","a");
- emitcode("subb","a,b");
- emitcode("mov","b,a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now we are done */
- aopPut(AOP(result),"b",0);
- if(size > 0){
- emitcode("mov","c,b.7");
- emitcode("subb","a,acc");
+static void
+genDivOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+ int size, offset;
+
+ size = AOP_SIZE (result) - 1;
+ offset = 1;
+ /* signed or unsigned */
+ if (SPEC_USIGN (opetype))
+ {
+ /* unsigned is easy */
+ LOAD_AB_FOR_DIV (left, right, l);
+ emitcode ("div", "ab");
+ aopPut (AOP (result), "a", 0);
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ return;
+ }
+
+ /* signed is a little bit more difficult */
+
+ /* save the signs of the operands */
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), 0, FALSE, TRUE, FALSE));
+ emitcode ("push", "acc"); /* save it on the stack */
+
+ /* now sign adjust for both left & right */
+ l = aopGet (AOP (right), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("mov", "b,a");
+
+ /* sign adjust left side */
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now the division */
+ emitcode ("nop", "; workaround for DS80C390 div bug.");
+ emitcode ("div", "ab");
+ /* we are interested in the lower order
+ only */
+ emitcode ("mov", "b,a");
+ lbl = newiTempLabel (NULL);
+ emitcode ("pop", "acc");
+ /* if there was an over flow we don't
+ adjust the sign of the result */
+ emitcode ("jb", "ov,%05d$", (lbl->key + 100));
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,b");
+ emitcode ("mov", "b,a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now we are done */
+ aopPut (AOP (result), "b", 0);
+ if (size > 0)
+ {
+ emitcode ("mov", "c,b.7");
+ emitcode ("subb", "a,acc");
}
- while (size--)
- aopPut(AOP(result),"a",offset++);
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
}
/*-----------------------------------------------------------------*/
/* genDiv - generates code for division */
/*-----------------------------------------------------------------*/
-static void genDiv (iCode *ic)
+static void
+genDiv (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- D(emitcode(";", "genDiv "););
+ D (emitcode (";", "genDiv ");
+ );
- /* assign the amsops */
- AOP_OP_3(ic);
+ /* assign the amsops */
+ AOP_OP_3 (ic);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genDivbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genDivbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genDivOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genDivOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ /* should have been converted to function call */
+ assert (1);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genModbits :- modulus of bits */
/*-----------------------------------------------------------------*/
-static void genModbits (operand *left,
- operand *right,
- operand *result)
+static void
+genModbits (operand * left,
+ operand * right,
+ operand * result)
{
- char *l;
+ char *l;
- /* the result must be bit */
- LOAD_AB_FOR_DIV(left, right, l);
- emitcode("div","ab");
- emitcode("mov","a,b");
- emitcode("rrc","a");
- aopPut(AOP(result),"c",0);
+ /* the result must be bit */
+ LOAD_AB_FOR_DIV (left, right, l);
+ emitcode ("div", "ab");
+ emitcode ("mov", "a,b");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "c", 0);
}
/*-----------------------------------------------------------------*/
/* genModOneByte : 8 bit modulus */
/*-----------------------------------------------------------------*/
-static void genModOneByte (operand *left,
- operand *right,
- operand *result)
+static void
+genModOneByte (operand * left,
+ operand * right,
+ operand * result)
{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
-
- /* signed or unsigned */
- if (SPEC_USIGN(opetype)) {
- /* unsigned is easy */
- LOAD_AB_FOR_DIV(left, right, l);
- emitcode("div","ab");
- aopPut(AOP(result),"b",0);
- return ;
- }
-
- /* signed is a little bit more difficult */
-
- /* save the signs of the operands */
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
-
- emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- emitcode("push","acc"); /* save it on the stack */
-
- /* now sign adjust for both left & right */
- l = aopGet(AOP(right),0,FALSE,FALSE,TRUE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("mov","b,a");
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
- /* sign adjust left side */
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now the multiplication */
- emitcode("nop", "; workaround for DS80C390 div bug.");
- emitcode("div","ab");
- /* we are interested in the lower order
- only */
- lbl = newiTempLabel(NULL);
- emitcode("pop","acc");
- /* if there was an over flow we don't
- adjust the sign of the result */
- emitcode("jb","ov,%05d$",(lbl->key+100));
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- CLRC ;
- emitcode("clr","a");
- emitcode("subb","a,b");
- emitcode("mov","b,a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now we are done */
- aopPut(AOP(result),"b",0);
+ /* signed or unsigned */
+ if (SPEC_USIGN (opetype))
+ {
+ /* unsigned is easy */
+ LOAD_AB_FOR_DIV (left, right, l);
+ emitcode ("div", "ab");
+ aopPut (AOP (result), "b", 0);
+ return;
+ }
+
+ /* signed is a little bit more difficult */
+
+ /* save the signs of the operands */
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ emitcode ("push", "acc"); /* save it on the stack */
+
+ /* now sign adjust for both left & right */
+ l = aopGet (AOP (right), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("mov", "b,a");
+
+ /* sign adjust left side */
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now the multiplication */
+ emitcode ("nop", "; workaround for DS80C390 div bug.");
+ emitcode ("div", "ab");
+ /* we are interested in the lower order
+ only */
+ lbl = newiTempLabel (NULL);
+ emitcode ("pop", "acc");
+ /* if there was an over flow we don't
+ adjust the sign of the result */
+ emitcode ("jb", "ov,%05d$", (lbl->key + 100));
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,b");
+ emitcode ("mov", "b,a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now we are done */
+ aopPut (AOP (result), "b", 0);
}
/*-----------------------------------------------------------------*/
/* genMod - generates code for division */
/*-----------------------------------------------------------------*/
-static void genMod (iCode *ic)
+static void
+genMod (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- D(emitcode(";", "genMod "););
+ D (emitcode (";", "genMod ");
+ );
- /* assign the amsops */
- AOP_OP_3(ic);
+ /* assign the amsops */
+ AOP_OP_3 (ic);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genModbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genModbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genModOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genModOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1);
+ /* should have been converted to function call */
+ assert (1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIfxJump :- will create a jump depending on the ifx */
/*-----------------------------------------------------------------*/
-static void genIfxJump (iCode *ic, char *jval)
+static void
+genIfxJump (iCode * ic, char *jval)
{
- symbol *jlbl ;
- symbol *tlbl = newiTempLabel(NULL);
- char *inst;
+ symbol *jlbl;
+ symbol *tlbl = newiTempLabel (NULL);
+ char *inst;
- D(emitcode(";", "genIfxJump "););
+ D (emitcode (";", "genIfxJump ");
+ );
- /* if true label then we jump if condition
- supplied is true */
- if ( IC_TRUE(ic) ) {
- jlbl = IC_TRUE(ic);
- inst = ((strcmp(jval,"a") == 0 ? "jz" :
- (strcmp(jval,"c") == 0 ? "jnc" : "jnb" )));
+ /* if true label then we jump if condition
+ supplied is true */
+ if (IC_TRUE (ic))
+ {
+ jlbl = IC_TRUE (ic);
+ inst = ((strcmp (jval, "a") == 0 ? "jz" :
+ (strcmp (jval, "c") == 0 ? "jnc" : "jnb")));
}
- else {
- /* false label is present */
- jlbl = IC_FALSE(ic) ;
- inst = ((strcmp(jval,"a") == 0 ? "jnz" :
- (strcmp(jval,"c") == 0 ? "jc" : "jb" )));
+ else
+ {
+ /* false label is present */
+ jlbl = IC_FALSE (ic);
+ inst = ((strcmp (jval, "a") == 0 ? "jnz" :
+ (strcmp (jval, "c") == 0 ? "jc" : "jb")));
}
- if (strcmp(inst,"jb") == 0 || strcmp(inst,"jnb") == 0)
- emitcode(inst,"%s,%05d$",jval,(tlbl->key+100));
- else
- emitcode(inst,"%05d$",tlbl->key+100);
- emitcode("ljmp","%05d$",jlbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
+ if (strcmp (inst, "jb") == 0 || strcmp (inst, "jnb") == 0)
+ emitcode (inst, "%s,%05d$", jval, (tlbl->key + 100));
+ else
+ emitcode (inst, "%05d$", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", jlbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
- /* mark the icode as generated */
- ic->generated = 1;
+ /* mark the icode as generated */
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genCmp :- greater or less than comparison */
/*-----------------------------------------------------------------*/
-static void genCmp (operand *left,operand *right,
- iCode *ic, iCode *ifx, int sign)
+static void
+genCmp (operand * left, operand * right,
+ iCode * ic, iCode * ifx, int sign)
{
- int size, offset = 0 ;
- unsigned long lit = 0L;
- operand *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+ operand *result;
- D(emitcode(";", "genCmp"););
+ D (emitcode (";", "genCmp");
+ );
- result = IC_RESULT(ic);
+ result = IC_RESULT (ic);
- /* if left & right are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
- } else {
- /* subtract right from left if at the
- end the carry flag is set then we know that
- left is greater than right */
- size = max(AOP_SIZE(left),AOP_SIZE(right));
-
- /* if unsigned char cmp with lit, do cjne left,#right,zz */
- if((size == 1) && !sign &&
- (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
- symbol *lbl = newiTempLabel(NULL);
- emitcode("cjne","%s,%s,%05d$",
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
- lbl->key+100);
- emitcode("","%05d$:",lbl->key+100);
- } else {
- if (AOP_TYPE(right) == AOP_LIT)
- {
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- /* optimize if(x < 0) or if(x >= 0) */
- if(lit == 0L)
- {
- if(!sign)
- {
- CLRC;
- }
- else
- {
- MOVA(aopGet(AOP(left),AOP_SIZE(left)-1,FALSE,FALSE,TRUE));
-
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
-
- aopOp(result,ic,FALSE, FALSE);
-
- if(!(AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) && ifx)
- {
- freeAsmop(result,NULL,ic,TRUE);
- genIfxJump (ifx,"acc.7");
- return;
- }
- else
- {
- emitcode("rlc","a");
- }
- goto release_freedLR;
- }
- goto release;
- }
- }
- CLRC;
- while (size--)
- {
- emitcode(";", "genCmp #1: %d/%d/%d", size, sign, offset);
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
- emitcode(";", "genCmp #2");
- if (sign && (size == 0))
- {
- emitcode(";", "genCmp #3");
- emitcode("xrl","a,#0x80");
- if (AOP_TYPE(right) == AOP_LIT)
- {
- unsigned long lit = (unsigned long)
- floatFromVal(AOP(right)->aopu.aop_lit);
- emitcode(";", "genCmp #3.1");
- emitcode("subb","a,#0x%02x",
- 0x80 ^ (unsigned int)((lit >> (offset*8)) & 0x0FFL));
- }
- else
- {
- emitcode(";", "genCmp #3.2");
- if (AOP_NEEDSACC(right))
- {
- emitcode("push", "acc");
- }
- emitcode("mov","b,%s",aopGet(AOP(right),offset++,
- FALSE,FALSE,FALSE));
- emitcode("xrl","b,#0x80");
- if (AOP_NEEDSACC(right))
- {
- emitcode("pop", "acc");
- }
- emitcode("subb","a,b");
- }
- }
- else
- {
- const char *s;
-
- emitcode(";", "genCmp #4");
- if (AOP_NEEDSACC(right))
- {
- /* Yuck!! */
- emitcode(";", "genCmp #4.1");
- emitcode("xch", "a, b");
- MOVA(aopGet(AOP(right),offset++,FALSE,FALSE,TRUE));
- emitcode("xch", "a, b");
- s = "b";
- }
- else
- {
- emitcode(";", "genCmp #4.2");
- s = aopGet(AOP(right),offset++,FALSE,FALSE,FALSE);
- }
-
- emitcode("subb","a,%s",s);
- }
- }
- }
+ /* if left & right are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("anl", "c,/%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ /* subtract right from left if at the
+ end the carry flag is set then we know that
+ left is greater than right */
+ size = max (AOP_SIZE (left), AOP_SIZE (right));
+
+ /* if unsigned char cmp with lit, do cjne left,#right,zz */
+ if ((size == 1) && !sign &&
+ (AOP_TYPE (right) == AOP_LIT && AOP_TYPE (left) != AOP_DIR))
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("cjne", "%s,%s,%05d$",
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE),
+ lbl->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ /* optimize if(x < 0) or if(x >= 0) */
+ if (lit == 0L)
+ {
+ if (!sign)
+ {
+ CLRC;
+ }
+ else
+ {
+ MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE, TRUE));
+
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+
+ aopOp (result, ic, FALSE, FALSE);
+
+ if (!(AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) && ifx)
+ {
+ freeAsmop (result, NULL, ic, TRUE);
+ genIfxJump (ifx, "acc.7");
+ return;
+ }
+ else
+ {
+ emitcode ("rlc", "a");
+ }
+ goto release_freedLR;
+ }
+ goto release;
+ }
+ }
+ CLRC;
+ while (size--)
+ {
+ emitcode (";", "genCmp #1: %d/%d/%d", size, sign, offset);
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE, TRUE));
+ emitcode (";", "genCmp #2");
+ if (sign && (size == 0))
+ {
+ emitcode (";", "genCmp #3");
+ emitcode ("xrl", "a,#0x80");
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long)
+ floatFromVal (AOP (right)->aopu.aop_lit);
+ emitcode (";", "genCmp #3.1");
+ emitcode ("subb", "a,#0x%02x",
+ 0x80 ^ (unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
+ }
+ else
+ {
+ emitcode (";", "genCmp #3.2");
+ if (AOP_NEEDSACC (right))
+ {
+ emitcode ("push", "acc");
+ }
+ emitcode ("mov", "b,%s", aopGet (AOP (right), offset++,
+ FALSE, FALSE, FALSE));
+ emitcode ("xrl", "b,#0x80");
+ if (AOP_NEEDSACC (right))
+ {
+ emitcode ("pop", "acc");
+ }
+ emitcode ("subb", "a,b");
+ }
+ }
+ else
+ {
+ const char *s;
+
+ emitcode (";", "genCmp #4");
+ if (AOP_NEEDSACC (right))
+ {
+ /* Yuck!! */
+ emitcode (";", "genCmp #4.1");
+ emitcode ("xch", "a, b");
+ MOVA (aopGet (AOP (right), offset++, FALSE, FALSE, TRUE));
+ emitcode ("xch", "a, b");
+ s = "b";
+ }
+ else
+ {
+ emitcode (";", "genCmp #4.2");
+ s = aopGet (AOP (right), offset++, FALSE, FALSE, FALSE);
+ }
+
+ emitcode ("subb", "a,%s", s);
+ }
+ }
+ }
}
release:
/* Don't need the left & right operands any more; do need the result. */
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
- aopOp(result,ic,FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
release_freedLR:
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result))
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
{
- outBitC(result);
+ outBitC (result);
}
- else
+ else
{
- /* if the result is used in the next
- ifx conditional branch then generate
- code a little differently */
- if (ifx )
- {
- genIfxJump (ifx,"c");
- }
- else
- {
- outBitC(result);
- }
- /* leave the result in acc */
+ /* if the result is used in the next
+ ifx conditional branch then generate
+ code a little differently */
+ if (ifx)
+ {
+ genIfxJump (ifx, "c");
+ }
+ else
+ {
+ outBitC (result);
+ }
+ /* leave the result in acc */
}
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCmpGt :- greater than comparison */
/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
+static void
+genCmpGt (iCode * ic, iCode * ifx)
{
- operand *left, *right;
- sym_link *letype , *retype;
- int sign ;
+ operand *left, *right;
+ sym_link *letype, *retype;
+ int sign;
- D(emitcode(";", "genCmpGt "););
+ D (emitcode (";", "genCmpGt ");
+ );
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
- /* assign the left & right amsops */
- AOP_OP_2(ic);
+ /* assign the left & right amsops */
+ AOP_OP_2 (ic);
- genCmp(right, left, ic, ifx, sign);
+ genCmp (right, left, ic, ifx, sign);
}
/*-----------------------------------------------------------------*/
/* genCmpLt - less than comparisons */
/*-----------------------------------------------------------------*/
-static void genCmpLt (iCode *ic, iCode *ifx)
+static void
+genCmpLt (iCode * ic, iCode * ifx)
{
- operand *left, *right;
- sym_link *letype , *retype;
- int sign ;
+ operand *left, *right;
+ sym_link *letype, *retype;
+ int sign;
- D(emitcode(";", "genCmpLt "););
+ D (emitcode (";", "genCmpLt ");
+ );
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
- /* assign the left & right amsops */
- AOP_OP_2(ic);
+ /* assign the left & right amsops */
+ AOP_OP_2 (ic);
- genCmp(left, right, ic, ifx, sign);
+ genCmp (left, right, ic, ifx, sign);
}
/*-----------------------------------------------------------------*/
/* gencjneshort - compare and jump if not equal */
/*-----------------------------------------------------------------*/
-static void gencjneshort(operand *left, operand *right, symbol *lbl)
-{
- int size = max(AOP_SIZE(left),AOP_SIZE(right));
- int offset = 0;
- unsigned long lit = 0L;
-
- D(emitcode(";", "gencjneshort"););
-
- /* if the left side is a literal or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(left) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *t = right;
- right = left;
- left = t;
- }
-
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- if (opIsGptr(left) || opIsGptr(right))
- {
- /* We are comparing a generic pointer to something.
- * Exclude the generic type byte from the comparison.
- */
- size--;
- D(emitcode(";", "cjneshort: generic ptr special case.");)
- }
-
-
- /* if the right side is a literal then anything goes */
- if (AOP_TYPE(right) == AOP_LIT &&
- AOP_TYPE(left) != AOP_DIR ) {
- while (size--) {
- char *l = aopGet(AOP(left), offset, FALSE, FALSE,TRUE);
- MOVA(l);
- emitcode("cjne","a,%s,%05d$",
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
- lbl->key+100);
- offset++;
- }
- }
-
- /* if the right side is in a register or in direct space or
- if the left is a pointer register & right is not */
- else if (AOP_TYPE(right) == AOP_REG ||
- AOP_TYPE(right) == AOP_DIR ||
- (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) ||
- (IS_AOP_PREG(left) && !IS_AOP_PREG(right)))
- {
- while (size--)
- {
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
- if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
- ((unsigned int)((lit >> (offset*8)) & 0x0FFL) == 0))
- emitcode("jnz","%05d$",lbl->key+100);
- else
- emitcode("cjne","a,%s,%05d$",
- aopGet(AOP(right),offset,FALSE,TRUE,FALSE),
- lbl->key+100);
- offset++;
- }
- } else {
- /* right is a pointer reg need both a & b */
- while(size--) {
- char *l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
- if(strcmp(l,"b"))
- emitcode("mov","b,%s",l);
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("cjne","a,b,%05d$",lbl->key+100);
- offset++;
- }
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* gencjne - compare and jump if not equal */
-/*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, symbol *lbl)
+static void
+gencjneshort (operand * left, operand * right, symbol * lbl)
{
- symbol *tlbl = newiTempLabel(NULL);
+ int size = max (AOP_SIZE (left), AOP_SIZE (right));
+ int offset = 0;
+ unsigned long lit = 0L;
- D(emitcode(";", "gencjne"););
+ D (emitcode (";", "gencjneshort");
+ );
- gencjneshort(left, right, lbl);
+ /* if the left side is a literal or
+ if the right is in a pointer register and left
+ is not */
+ if ((AOP_TYPE (left) == AOP_LIT) ||
+ (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
+ {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
- emitcode("mov","a,%s",one);
- emitcode("sjmp","%05d$",tlbl->key+100);
- emitcode("","%05d$:",lbl->key+100);
- emitcode("clr","a");
- emitcode("","%05d$:",tlbl->key+100);
-}
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
-/*-----------------------------------------------------------------*/
-/* genCmpEq - generates code for equal to */
-/*-----------------------------------------------------------------*/
-static void genCmpEq (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
-
- D(emitcode(";", "genCmpEq "););
-
- AOP_OP_2(ic);
- AOP_SET_LOCALS(ic);
-
- /* if literal, literal on the right or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
- }
-
- if (ifx && /* !AOP_SIZE(result) */
- OP_SYMBOL(result) &&
- OP_SYMBOL(result)->regType == REG_CND)
- {
- symbol *tlbl;
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- if(lit == 0L){
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- } else if(lit == 1L) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("jb","%s,%05d$",AOP(right)->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- }
- /* if true label then we jump if condition
- supplied is true */
- tlbl = newiTempLabel(NULL);
- if ( IC_TRUE(ifx) ) {
- emitcode("jnc","%05d$",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_TRUE(ifx)->key+100);
- } else {
- emitcode("jc","%05d$",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_FALSE(ifx)->key+100);
- }
- emitcode("","%05d$:",tlbl->key+100);
- } else {
- tlbl = newiTempLabel(NULL);
- gencjneshort(left, right, tlbl);
- if ( IC_TRUE(ifx) ) {
- emitcode("ljmp","%05d$",IC_TRUE(ifx)->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("sjmp","%05d$",lbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_FALSE(ifx)->key+100);
- emitcode("","%05d$:",lbl->key+100);
- }
- }
- /* mark the icode as generated */
- ifx->generated = 1;
-
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- return ;
- }
-
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- if(lit == 0L){
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- } else if(lit == 1L) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("jb","%s,%05d$",AOP(right)->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- }
-
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
-
- aopOp(result,ic,TRUE, FALSE);
-
- /* c = 1 if egal */
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)){
- outBitC(result);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"c");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- outBitC(result);
- } else {
- gencjne(left,right,newiTempLabel(NULL));
-
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
-
- aopOp(result,ic,TRUE, FALSE);
-
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- aopPut(AOP(result),"a",0);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"a");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- if (AOP_TYPE(result) != AOP_CRY)
- outAcc(result);
- /* leave the result in acc */
+ if (opIsGptr (left) || opIsGptr (right))
+ {
+ /* We are comparing a generic pointer to something.
+ * Exclude the generic type byte from the comparison.
+ */
+ size--;
+ D (emitcode (";", "cjneshort: generic ptr special case.");
+ )
+ }
+
+
+ /* if the right side is a literal then anything goes */
+ if (AOP_TYPE (right) == AOP_LIT &&
+ AOP_TYPE (left) != AOP_DIR)
+ {
+ while (size--)
+ {
+ char *l = aopGet (AOP (left), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("cjne", "a,%s,%05d$",
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE),
+ lbl->key + 100);
+ offset++;
+ }
+ }
+
+ /* if the right side is in a register or in direct space or
+ if the left is a pointer register & right is not */
+ else if (AOP_TYPE (right) == AOP_REG ||
+ AOP_TYPE (right) == AOP_DIR ||
+ (AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) ||
+ (IS_AOP_PREG (left) && !IS_AOP_PREG (right)))
+ {
+ while (size--)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE, TRUE));
+ if ((AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) &&
+ ((unsigned int) ((lit >> (offset * 8)) & 0x0FFL) == 0))
+ emitcode ("jnz", "%05d$", lbl->key + 100);
+ else
+ emitcode ("cjne", "a,%s,%05d$",
+ aopGet (AOP (right), offset, FALSE, TRUE, FALSE),
+ lbl->key + 100);
+ offset++;
+ }
+ }
+ else
+ {
+ /* right is a pointer reg need both a & b */
+ while (size--)
+ {
+ char *l = aopGet (AOP (left), offset, FALSE, FALSE, TRUE);
+ if (strcmp (l, "b"))
+ emitcode ("mov", "b,%s", l);
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("cjne", "a,b,%05d$", lbl->key + 100);
+ offset++;
+ }
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* gencjne - compare and jump if not equal */
+/*-----------------------------------------------------------------*/
+static void
+gencjne (operand * left, operand * right, symbol * lbl)
+{
+ symbol *tlbl = newiTempLabel (NULL);
+
+ D (emitcode (";", "gencjne");
+ );
+
+ gencjneshort (left, right, lbl);
+
+ emitcode ("mov", "a,%s", one);
+ emitcode ("sjmp", "%05d$", tlbl->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ emitcode ("clr", "a");
+ emitcode ("", "%05d$:", tlbl->key + 100);
+}
+
+/*-----------------------------------------------------------------*/
+/* genCmpEq - generates code for equal to */
+/*-----------------------------------------------------------------*/
+static void
+genCmpEq (iCode * ic, iCode * ifx)
+{
+ operand *left, *right, *result;
+
+ D (emitcode (";", "genCmpEq ");
+ );
+
+ AOP_OP_2 (ic);
+ AOP_SET_LOCALS (ic);
+
+ /* if literal, literal on the right or
+ if the right is in a pointer register and left
+ is not */
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT) ||
+ (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
+ }
+
+ if (ifx && /* !AOP_SIZE(result) */
+ OP_SYMBOL (result) &&
+ OP_SYMBOL (result)->regType == REG_CND)
+ {
+ symbol *tlbl;
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ if (lit == 0L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ else if (lit == 1L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("clr", "c");
+ }
+ /* AOP_TYPE(right) == AOP_CRY */
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("jb", "%s,%05d$", AOP (right)->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ }
+ /* if true label then we jump if condition
+ supplied is true */
+ tlbl = newiTempLabel (NULL);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("jnc", "%05d$", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
+ }
+ else
+ {
+ emitcode ("jc", "%05d$", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100);
+ }
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ gencjneshort (left, right, tlbl);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("sjmp", "%05d$", lbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ }
+ }
+ /* mark the icode as generated */
+ ifx->generated = 1;
+
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ return;
+ }
+
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ if (lit == 0L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ else if (lit == 1L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("clr", "c");
+ }
+ /* AOP_TYPE(right) == AOP_CRY */
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("jb", "%s,%05d$", AOP (right)->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ }
+
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+
+ aopOp (result, ic, TRUE, FALSE);
+
+ /* c = 1 if egal */
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ outBitC (result);
+ goto release;
+ }
+ if (ifx)
+ {
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+ /* if the result is used in an arithmetic operation
+ then put the result in place */
+ outBitC (result);
+ }
+ else
+ {
+ gencjne (left, right, newiTempLabel (NULL));
+
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+
+ aopOp (result, ic, TRUE, FALSE);
+
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+ if (ifx)
+ {
+ genIfxJump (ifx, "a");
+ goto release;
+ }
+ /* if the result is used in an arithmetic operation
+ then put the result in place */
+ if (AOP_TYPE (result) != AOP_CRY)
+ outAcc (result);
+ /* leave the result in acc */
}
release:
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* ifxForOp - returns the icode containing the ifx for operand */
/*-----------------------------------------------------------------*/
-static iCode *ifxForOp ( operand *op, iCode *ic )
+static iCode *
+ifxForOp (operand * op, iCode * ic)
{
- /* if true symbol then needs to be assigned */
- if (IS_TRUE_SYMOP(op))
- return NULL ;
+ /* if true symbol then needs to be assigned */
+ if (IS_TRUE_SYMOP (op))
+ return NULL;
- /* if this has register type condition and
- the next instruction is ifx with the same operand
- and live to of the operand is upto the ifx only then */
- if (ic->next &&
- ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key &&
- OP_SYMBOL(op)->liveTo <= ic->next->seq )
- return ic->next;
+ /* if this has register type condition and
+ the next instruction is ifx with the same operand
+ and live to of the operand is upto the ifx only then */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ IC_COND (ic->next)->key == op->key &&
+ OP_SYMBOL (op)->liveTo <= ic->next->seq)
+ return ic->next;
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* genAndOp - for && operation */
/*-----------------------------------------------------------------*/
-static void genAndOp (iCode *ic)
+static void
+genAndOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
+ operand *left, *right, *result;
+ symbol *tlbl;
- D(emitcode(";", "genAndOp "););
+ D (emitcode (";", "genAndOp ");
+ );
- /* note here that && operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- AOP_OP_3(ic);
- AOP_SET_LOCALS(ic);
+ /* note here that && operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ AOP_OP_3 (ic);
+ AOP_SET_LOCALS (ic);
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emitcode("jz","%05d$",tlbl->key+100);
- toBoolean(right);
- emitcode("","%05d$:",tlbl->key+100);
- outBitAcc(result);
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emitcode ("jz", "%05d$", tlbl->key + 100);
+ toBoolean (right);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitAcc (result);
}
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genOrOp - for || operation */
/*-----------------------------------------------------------------*/
-static void genOrOp (iCode *ic)
+static void
+genOrOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
+ operand *left, *right, *result;
+ symbol *tlbl;
- D(emitcode(";", "genOrOp "););
+ D (emitcode (";", "genOrOp ");
+ );
- /* note here that || operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- AOP_OP_3(ic);
- AOP_SET_LOCALS(ic);
+ /* note here that || operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ AOP_OP_3 (ic);
+ AOP_SET_LOCALS (ic);
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("orl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emitcode("jnz","%05d$",tlbl->key+100);
- toBoolean(right);
- emitcode("","%05d$:",tlbl->key+100);
- outBitAcc(result);
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("orl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ toBoolean (right);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitAcc (result);
}
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ 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;
+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;
}
/*-----------------------------------------------------------------*/
/* continueIfTrue - */
/*-----------------------------------------------------------------*/
-static void continueIfTrue (iCode *ic)
+static void
+continueIfTrue (iCode * ic)
{
- if(IC_TRUE(ic))
- emitcode("ljmp","%05d$",IC_TRUE(ic)->key+100);
- ic->generated = 1;
+ if (IC_TRUE (ic))
+ emitcode ("ljmp", "%05d$", IC_TRUE (ic)->key + 100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* jmpIfTrue - */
/*-----------------------------------------------------------------*/
-static void jumpIfTrue (iCode *ic)
+static void
+jumpIfTrue (iCode * ic)
{
- if(!IC_TRUE(ic))
- emitcode("ljmp","%05d$",IC_FALSE(ic)->key+100);
- ic->generated = 1;
+ if (!IC_TRUE (ic))
+ emitcode ("ljmp", "%05d$", IC_FALSE (ic)->key + 100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* jmpTrueOrFalse - */
/*-----------------------------------------------------------------*/
-static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
+static void
+jmpTrueOrFalse (iCode * ic, symbol * tlbl)
{
- // ugly but optimized by peephole
- if(IC_TRUE(ic)){
- symbol *nlbl = newiTempLabel(NULL);
- emitcode("sjmp","%05d$",nlbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_TRUE(ic)->key+100);
- emitcode("","%05d$:",nlbl->key+100);
+ // ugly but optimized by peephole
+ if (IC_TRUE (ic))
+ {
+ symbol *nlbl = newiTempLabel (NULL);
+ emitcode ("sjmp", "%05d$", nlbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_TRUE (ic)->key + 100);
+ emitcode ("", "%05d$:", nlbl->key + 100);
}
- else{
- emitcode("ljmp","%05d$",IC_FALSE(ic)->key+100);
- emitcode("","%05d$:",tlbl->key+100);
+ else
+ {
+ emitcode ("ljmp", "%05d$", IC_FALSE (ic)->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
}
- ic->generated = 1;
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAnd - code for and */
/*-----------------------------------------------------------------*/
-static void genAnd (iCode *ic, iCode *ifx)
+static void
+genAnd (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
- int bytelit = 0;
- char buffer[10];
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+ int bytelit = 0;
+ char buffer[10];
- D(emitcode(";", "genAnd "););
+ D (emitcode (";", "genAnd ");
+ );
- AOP_OP_3(ic);
- AOP_SET_LOCALS(ic);
+ AOP_OP_3 (ic);
+ AOP_SET_LOCALS (ic);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit & yy)
- // result = bit & yy;
- if (AOP_TYPE(left) == AOP_CRY){
- // c = bit & literal;
- if(AOP_TYPE(right) == AOP_LIT){
- if(lit & 1) {
- if(size && sameRegs(AOP(result),AOP(left)))
- // no change
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // bit(result) = 0;
- if(size && (AOP_TYPE(result) == AOP_CRY)){
- emitcode("clr","%s",AOP(result)->aopu.aop_dir);
- goto release;
- }
- if((AOP_TYPE(result) == AOP_CRY) && ifx){
- jumpIfTrue(ifx);
- goto release;
- }
- emitcode("clr","c");
- }
- } else {
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit & bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // c = bit & val;
- MOVA(aopGet(AOP(right),0,FALSE,FALSE,TRUE));
- // c = lsb
- emitcode("rrc","a");
- emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- }
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit & ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- // if(val & 0xZZ) - size = 0, ifx != FALSE -
- // bit = val & 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- int posbit = isLiteralBit(lit);
- /* left & 2^n */
- if(posbit){
- posbit--;
- MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE,TRUE));
- // bit = left & 2^n
- if(size)
- emitcode("mov","c,acc.%d",posbit&0x07);
- // if(left & 2^n)
- else{
- if(ifx){
- sprintf(buffer,"acc.%d",posbit&0x07);
- genIfxJump(ifx, buffer);
- }
- goto release;
- }
- } else {
- symbol *tlbl = newiTempLabel(NULL);
- int sizel = AOP_SIZE(left);
- if(size)
- emitcode("setb","c");
- while(sizel--){
- if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
- MOVA( aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
- // byte == 2^n ?
- if((posbit = isLiteralBit(bytelit)) != 0)
- emitcode("jb","acc.%d,%05d$",(posbit-1)&0x07,tlbl->key+100);
- else{
- if(bytelit != 0x0FFL)
- emitcode("anl","a,%s",
- aopGet(AOP(right),offset,FALSE,TRUE,FALSE));
- emitcode("jnz","%05d$",tlbl->key+100);
- }
- }
- offset++;
- }
- // bit = left & literal
- if(size){
- emitcode("clr","c");
- emitcode("","%05d$:",tlbl->key+100);
- }
- // if(left & literal)
- else{
- if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- goto release ;
- }
- }
- outBitC(result);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if((bytelit = (int)((lit >> (offset*8)) & 0x0FFL)) == 0x0FF)
- continue;
- else
- if (bytelit == 0)
- aopPut(AOP(result),zero,offset);
- else
- if (IS_AOP_PREG(result)) {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("anl","%s,%s",
- aopGet(AOP(left),offset,FALSE,TRUE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("anl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- if (IS_AOP_PREG(result)) {
- emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- aopPut(AOP(result),"a",offset);
-
- } else
- emitcode("anl","%s,a",
- aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left & right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = min(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("anl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
- emitcode("jnz","%05d$",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else
- {
- for(;(size--);offset++)
- {
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT)
- {
- if((bytelit = (int)((lit >> (offset*8)) & 0x0FFL)) == 0x0FF)
- {
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
- offset);
- continue;
- }
- else if (bytelit == 0)
- {
- aopPut(AOP(result),zero,offset);
- continue;
- }
- D(emitcode(";", "better literal AND."););
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
- emitcode("anl", "a, %s", aopGet(AOP(right),offset,
- FALSE,FALSE,FALSE));
-
- }
- else
- {
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- {
- emitcode("anl","a,%s",aopGet(AOP(right),offset,
- FALSE,FALSE,FALSE));
- }
- else
- {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("anl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
- }
- }
- aopPut(AOP(result),"a",offset);
- }
- }
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit & yy)
+ // result = bit & yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ // c = bit & literal;
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (lit & 1)
+ {
+ if (size && sameRegs (AOP (result), AOP (left)))
+ // no change
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // bit(result) = 0;
+ if (size && (AOP_TYPE (result) == AOP_CRY))
+ {
+ emitcode ("clr", "%s", AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+ if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ {
+ jumpIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("clr", "c");
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit & bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // c = bit & val;
+ MOVA (aopGet (AOP (right), 0, FALSE, FALSE, TRUE));
+ // c = lsb
+ emitcode ("rrc", "a");
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit & ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+
+ // if(val & 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val & 0xZZ - size = 1, ifx = FALSE -
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ int posbit = isLiteralBit (lit);
+ /* left & 2^n */
+ if (posbit)
+ {
+ posbit--;
+ MOVA (aopGet (AOP (left), posbit >> 3, FALSE, FALSE, TRUE));
+ // bit = left & 2^n
+ if (size)
+ emitcode ("mov", "c,acc.%d", posbit & 0x07);
+ // if(left & 2^n)
+ else
+ {
+ if (ifx)
+ {
+ sprintf (buffer, "acc.%d", posbit & 0x07);
+ genIfxJump (ifx, buffer);
+ }
+ goto release;
+ }
+ }
+ else
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizel = AOP_SIZE (left);
+ if (size)
+ emitcode ("setb", "c");
+ while (sizel--)
+ {
+ if ((bytelit = ((lit >> (offset * 8)) & 0x0FFL)) != 0x0L)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE, TRUE));
+ // byte == 2^n ?
+ if ((posbit = isLiteralBit (bytelit)) != 0)
+ emitcode ("jb", "acc.%d,%05d$", (posbit - 1) & 0x07, tlbl->key + 100);
+ else
+ {
+ if (bytelit != 0x0FFL)
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (right), offset, FALSE, TRUE, FALSE));
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ }
+ }
+ offset++;
+ }
+ // bit = left & literal
+ if (size)
+ {
+ emitcode ("clr", "c");
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ // if(left & literal)
+ else
+ {
+ if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ goto release;
+ }
+ }
+ outBitC (result);
+ goto release;
+ }
+
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if ((bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL)) == 0x0FF)
+ continue;
+ else if (bytelit == 0)
+ aopPut (AOP (result), zero, offset);
+ else if (IS_AOP_PREG (result))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("anl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("anl", "%s,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE, FALSE),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ if (IS_AOP_PREG (result))
+ {
+ emitcode ("anl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ aopPut (AOP (result), "a", offset);
+
+ }
+ else
+ emitcode ("anl", "%s,a",
+ aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left & right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = min (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE));
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ {
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if ((bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL)) == 0x0FF)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE),
+ offset);
+ continue;
+ }
+ else if (bytelit == 0)
+ {
+ aopPut (AOP (result), zero, offset);
+ continue;
+ }
+ D (emitcode (";", "better literal AND.");
+ );
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE, TRUE));
+ emitcode ("anl", "a, %s", aopGet (AOP (right), offset,
+ FALSE, FALSE, FALSE));
+
+ }
+ else
+ {
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ {
+ emitcode ("anl", "a,%s", aopGet (AOP (right), offset,
+ FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE));
+ }
+ }
+ aopPut (AOP (result), "a", offset);
+ }
+ }
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genOr - code for or */
/*-----------------------------------------------------------------*/
-static void genOr (iCode *ic, iCode *ifx)
+static void
+genOr (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
- D(emitcode(";", "genOr "););
+ D (emitcode (";", "genOr ");
+ );
- AOP_OP_3(ic);
- AOP_SET_LOCALS(ic);
+ AOP_OP_3 (ic);
+ AOP_SET_LOCALS (ic);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit | yy)
- // xx = bit | yy;
- if (AOP_TYPE(left) == AOP_CRY){
- if(AOP_TYPE(right) == AOP_LIT){
- // c = bit & literal;
- if(lit){
- // lit != 0 => result = 1
- if(AOP_TYPE(result) == AOP_CRY){
- if(size)
- emitcode("setb","%s",AOP(result)->aopu.aop_dir);
- else if(ifx)
- continueIfTrue(ifx);
- goto release;
- }
- emitcode("setb","c");
- } else {
- // lit == 0 => result = left
- if(size && sameRegs(AOP(result),AOP(left)))
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- }
- } else {
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit | bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("orl","c,%s",AOP(left)->aopu.aop_dir);
- }
- else{
- // c = bit | val;
- symbol *tlbl = newiTempLabel(NULL);
- if(!((AOP_TYPE(result) == AOP_CRY) && ifx))
- emitcode("setb","c");
- emitcode("jb","%s,%05d$",
- AOP(left)->aopu.aop_dir,tlbl->key+100);
- toBoolean(right);
- emitcode("jnz","%05d$",tlbl->key+100);
- if((AOP_TYPE(result) == AOP_CRY) && ifx){
- jmpTrueOrFalse(ifx, tlbl);
- goto release;
- } else {
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- }
- }
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit | ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- // if(val | 0xZZ) - size = 0, ifx != FALSE -
- // bit = val | 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- if(lit){
- // result = 1
- if(size)
- emitcode("setb","%s",AOP(result)->aopu.aop_dir);
- else
- continueIfTrue(ifx);
- goto release;
- } else {
- // lit = 0, result = boolean(left)
- if(size)
- emitcode("setb","c");
- toBoolean(right);
- if(size){
- symbol *tlbl = newiTempLabel(NULL);
- emitcode("jnz","%05d$",tlbl->key+100);
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- } else {
- genIfxJump (ifx,"a");
- goto release;
- }
- }
- outBitC(result);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left)))
- {
- for(;size--; offset++)
- {
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- {
- continue;
- }
- else
- {
- if (IS_AOP_PREG(left))
- {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- aopPut(AOP(result),"a",offset);
- }
- else
- {
- emitcode("orl","%s,%s",
- aopGet(AOP(left),offset,FALSE,TRUE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
- }
- }
- }
- else
- {
- if (AOP_TYPE(left) == AOP_ACC)
- {
- emitcode("orl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
- }
- else
- {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- if (IS_AOP_PREG(left))
- {
- emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- aopPut(AOP(result),"a",offset);
- }
- else
- {
- emitcode("orl","%s,a",
- aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- }
- }
- }
- }
- }
- else
- {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY)
- {
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left | right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("orl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
- emitcode("jnz","%05d$",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- }
- else
- {
- for(;(size--);offset++)
- {
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT)
- {
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- {
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
- offset);
- continue;
- }
- D(emitcode(";", "better literal OR."););
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
- emitcode("orl", "a, %s", aopGet(AOP(right),offset,
- FALSE,FALSE,FALSE));
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
- }
- else
- {
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- {
- emitcode("orl","a,%s",aopGet(AOP(right),offset,
- FALSE,FALSE,FALSE));
- }
- else
- {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("orl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
- }
- }
- aopPut(AOP(result),"a",offset);
- }
- }
- }
-
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit | yy)
+ // xx = bit | yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ // c = bit & literal;
+ if (lit)
+ {
+ // lit != 0 => result = 1
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ if (size)
+ emitcode ("setb", "%s", AOP (result)->aopu.aop_dir);
+ else if (ifx)
+ continueIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("setb", "c");
+ }
+ else
+ {
+ // lit == 0 => result = left
+ if (size && sameRegs (AOP (result), AOP (left)))
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit | bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // c = bit | val;
+ symbol *tlbl = newiTempLabel (NULL);
+ if (!((AOP_TYPE (result) == AOP_CRY) && ifx))
+ emitcode ("setb", "c");
+ emitcode ("jb", "%s,%05d$",
+ AOP (left)->aopu.aop_dir, tlbl->key + 100);
+ toBoolean (right);
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ {
+ jmpTrueOrFalse (ifx, tlbl);
+ goto release;
+ }
+ else
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ }
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit | ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+
+ // if(val | 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val | 0xZZ - size = 1, ifx = FALSE -
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ if (lit)
+ {
+ // result = 1
+ if (size)
+ emitcode ("setb", "%s", AOP (result)->aopu.aop_dir);
+ else
+ continueIfTrue (ifx);
+ goto release;
+ }
+ else
+ {
+ // lit = 0, result = boolean(left)
+ if (size)
+ emitcode ("setb", "c");
+ toBoolean (right);
+ if (size)
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ else
+ {
+ genIfxJump (ifx, "a");
+ goto release;
+ }
+ }
+ outBitC (result);
+ goto release;
+ }
+
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ {
+ continue;
+ }
+ else
+ {
+ if (IS_AOP_PREG (left))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("orl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ {
+ emitcode ("orl", "%s,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE, FALSE),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+ }
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ {
+ emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ if (IS_AOP_PREG (left))
+ {
+ emitcode ("orl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ {
+ emitcode ("orl", "%s,a",
+ aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left | right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = max (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("orl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE));
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ {
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE),
+ offset);
+ continue;
+ }
+ D (emitcode (";", "better literal OR.");
+ );
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE, TRUE));
+ emitcode ("orl", "a, %s", aopGet (AOP (right), offset,
+ FALSE, FALSE, FALSE));
+
+ }
+ else
+ {
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ {
+ emitcode ("orl", "a,%s", aopGet (AOP (right), offset,
+ FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("orl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE));
+ }
+ }
+ aopPut (AOP (result), "a", offset);
+ }
+ }
+ }
+
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genXor - code for xclusive or */
/*-----------------------------------------------------------------*/
-static void genXor (iCode *ic, iCode *ifx)
+static void
+genXor (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
- D(emitcode(";", "genXor "););
+ D (emitcode (";", "genXor ");
+ );
- AOP_OP_3(ic);
- AOP_SET_LOCALS(ic);
+ AOP_OP_3 (ic);
+ AOP_SET_LOCALS (ic);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not ||
- if left needs acc & right does not */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- (AOP_NEEDSACC(left) && !AOP_NEEDSACC(right))) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit ^ yy)
- // xx = bit ^ yy;
- if (AOP_TYPE(left) == AOP_CRY){
- if(AOP_TYPE(right) == AOP_LIT){
- // c = bit & literal;
- if(lit>>1){
- // lit>>1 != 0 => result = 1
- if(AOP_TYPE(result) == AOP_CRY){
- if(size)
- emitcode("setb","%s",AOP(result)->aopu.aop_dir);
- else if(ifx)
- continueIfTrue(ifx);
- goto release;
- }
- emitcode("setb","c");
- } else{
- // lit == (0 or 1)
- if(lit == 0){
- // lit == 0, result = left
- if(size && sameRegs(AOP(result),AOP(left)))
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else{
- // lit == 1, result = not(left)
- if(size && sameRegs(AOP(result),AOP(left))){
- emitcode("cpl","%s",AOP(result)->aopu.aop_dir);
- goto release;
- } else {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- }
- }
- }
-
- } else {
- // right != literal
- symbol *tlbl = newiTempLabel(NULL);
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit ^ bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- }
- else{
- int sizer = AOP_SIZE(right);
- // c = bit ^ val
- // if val>>1 != 0, result = 1
- emitcode("setb","c");
- while(sizer){
- MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE,TRUE));
- if(sizer == 1)
- // test the msb of the lsb
- emitcode("anl","a,#0xfe");
- emitcode("jnz","%05d$",tlbl->key+100);
- sizer--;
- }
- // val = (0,1)
- emitcode("rrc","a");
- }
- emitcode("jnb","%s,%05d$",AOP(left)->aopu.aop_dir,(tlbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(tlbl->key+100));
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit | ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- if(sameRegs(AOP(result),AOP(left))){
- /* if left is same as result */
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- continue;
- else
- if (IS_AOP_PREG(left)) {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("xrl","%s,%s",
- aopGet(AOP(left),offset,FALSE,TRUE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- if (IS_AOP_PREG(left)) {
- emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("xrl","%s,a",
- aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left ^ right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- if((AOP_TYPE(right) == AOP_LIT) &&
- (((lit >> (offset*8)) & 0x0FFL) == 0x00L)){
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
- } else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("xrl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
- }
- emitcode("jnz","%05d$",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else for(;(size--);offset++)
- {
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT)
- {
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- {
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE,FALSE,FALSE),
- offset);
- continue;
- }
- D(emitcode(";", "better literal XOR."););
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE,TRUE));
- emitcode("xrl", "a, %s", aopGet(AOP(right),offset,
- FALSE,FALSE,FALSE));
- }
- else
- {
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- {
- emitcode("xrl","a,%s",aopGet(AOP(right),offset,
- FALSE,FALSE,FALSE));
- }
- else
- {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE,TRUE));
- emitcode("xrl","a,%s",
- aopGet(AOP(left),offset,FALSE,TRUE,FALSE));
- }
- }
- aopPut(AOP(result),"a",offset);
- }
+ /* if left is a literal & right is not ||
+ if left needs acc & right does not */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ (AOP_NEEDSACC (left) && !AOP_NEEDSACC (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit ^ yy)
+ // xx = bit ^ yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ // c = bit & literal;
+ if (lit >> 1)
+ {
+ // lit>>1 != 0 => result = 1
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ if (size)
+ emitcode ("setb", "%s", AOP (result)->aopu.aop_dir);
+ else if (ifx)
+ continueIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("setb", "c");
+ }
+ else
+ {
+ // lit == (0 or 1)
+ if (lit == 0)
+ {
+ // lit == 0, result = left
+ if (size && sameRegs (AOP (result), AOP (left)))
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // lit == 1, result = not(left)
+ if (size && sameRegs (AOP (result), AOP (left)))
+ {
+ emitcode ("cpl", "%s", AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ }
+ }
+
+ }
+ else
+ {
+ // right != literal
+ symbol *tlbl = newiTempLabel (NULL);
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit ^ bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ }
+ else
+ {
+ int sizer = AOP_SIZE (right);
+ // c = bit ^ val
+ // if val>>1 != 0, result = 1
+ emitcode ("setb", "c");
+ while (sizer)
+ {
+ MOVA (aopGet (AOP (right), sizer - 1, FALSE, FALSE, TRUE));
+ if (sizer == 1)
+ // test the msb of the lsb
+ emitcode ("anl", "a,#0xfe");
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ sizer--;
+ }
+ // val = (0,1)
+ emitcode ("rrc", "a");
+ }
+ emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (tlbl->key + 100));
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit | ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ /* if left is same as result */
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ continue;
+ else if (IS_AOP_PREG (left))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("xrl", "%s,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE, FALSE),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ if (IS_AOP_PREG (left))
+ {
+ emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("xrl", "%s,a",
+ aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left ^ right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = max (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (((lit >> (offset * 8)) & 0x0FFL) == 0x00L))
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE, TRUE));
+ }
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("xrl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE));
+ }
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE, FALSE, FALSE),
+ offset);
+ continue;
+ }
+ D (emitcode (";", "better literal XOR.");
+ );
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE, TRUE));
+ emitcode ("xrl", "a, %s", aopGet (AOP (right), offset,
+ FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ {
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), offset,
+ FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE, TRUE));
+ emitcode ("xrl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE, FALSE));
+ }
+ }
+ aopPut (AOP (result), "a", offset);
+ }
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genInline - write the inline code out */
/*-----------------------------------------------------------------*/
-static void genInline (iCode *ic)
+static void
+genInline (iCode * ic)
{
- char buffer[MAX_INLINEASM];
- char *bp = buffer;
- char *bp1= buffer;
+ char buffer[MAX_INLINEASM];
+ char *bp = buffer;
+ char *bp1 = buffer;
- D(emitcode(";", "genInline "););
+ D (emitcode (";", "genInline ");
+ );
- _G.inLine += (!options.asmpeep);
- strcpy(buffer,IC_INLINE(ic));
+ _G.inLine += (!options.asmpeep);
+ strcpy (buffer, IC_INLINE (ic));
- /* emit each line as a code */
- while (*bp) {
- if (*bp == '\n') {
- *bp++ = '\0';
- emitcode(bp1,"");
- bp1 = bp;
- } else {
- if (*bp == ':') {
- bp++;
- *bp = '\0';
- bp++;
- emitcode(bp1,"");
- bp1 = bp;
- } else
- bp++;
- }
- }
- if (bp1 != bp)
- emitcode(bp1,"");
- /* emitcode("",buffer); */
- _G.inLine -= (!options.asmpeep);
+ /* emit each line as a code */
+ while (*bp)
+ {
+ if (*bp == '\n')
+ {
+ *bp++ = '\0';
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ {
+ if (*bp == ':')
+ {
+ bp++;
+ *bp = '\0';
+ bp++;
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ bp++;
+ }
+ }
+ if (bp1 != bp)
+ emitcode (bp1, "");
+ /* emitcode("",buffer); */
+ _G.inLine -= (!options.asmpeep);
}
/*-----------------------------------------------------------------*/
/* genRRC - rotate right with carry */
/*-----------------------------------------------------------------*/
-static void genRRC (iCode *ic)
+static void
+genRRC (iCode * ic)
{
- operand *left , *result ;
- int size, offset = 0;
- char *l;
+ operand *left, *result;
+ int size, offset = 0;
+ char *l;
- D(emitcode(";", "genRRC "););
+ D (emitcode (";", "genRRC ");
+ );
- /* rotate right with carry */
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE, FALSE);
- aopOp (result,ic,FALSE, AOP_TYPE(left) == AOP_DPTR);
+ /* rotate right with carry */
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (left) == AOP_DPTR);
- /* move it to the result */
- size = AOP_SIZE(result);
- offset = size - 1 ;
- CLRC;
+ /* move it to the result */
+ size = AOP_SIZE (result);
+ offset = size - 1;
+ CLRC;
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("rrc","a");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset--);
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset--);
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- /* now we need to put the carry into the
- highest order byte of the result */
- if (AOP_SIZE(result) > 1) {
- l = aopGet(AOP(result),AOP_SIZE(result)-1,FALSE,FALSE,TRUE);
- MOVA(l);
+ /* now we need to put the carry into the
+ highest order byte of the result */
+ if (AOP_SIZE (result) > 1)
+ {
+ l = aopGet (AOP (result), AOP_SIZE (result) - 1, FALSE, FALSE, TRUE);
+ MOVA (l);
}
- emitcode("mov","acc.7,c");
- aopPut(AOP(result),"a",AOP_SIZE(result)-1);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ emitcode ("mov", "acc.7,c");
+ aopPut (AOP (result), "a", AOP_SIZE (result) - 1);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRLC - generate code for rotate left with carry */
/*-----------------------------------------------------------------*/
-static void genRLC (iCode *ic)
-{
- operand *left , *result ;
- int size, offset = 0;
- char *l;
-
- D(emitcode(";", "genRLC "););
-
- /* rotate right with carry */
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE, FALSE);
- aopOp (result,ic,FALSE, AOP_TYPE(left) == AOP_DPTR);
-
- /* move it to the result */
- size = AOP_SIZE(result);
- offset = 0 ;
- if (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("add","a,acc");
- if (AOP_SIZE(result) > 1)
- {
- aopPut(AOP(result),"a",offset++);
- }
-
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("rlc","a");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset++);
- }
- _endLazyDPSEvaluation();
- }
- /* now we need to put the carry into the
- highest order byte of the result */
- if (AOP_SIZE(result) > 1) {
- l = aopGet(AOP(result),0,FALSE,FALSE,TRUE);
- MOVA(l);
- }
- emitcode("mov","acc.0,c");
- aopPut(AOP(result),"a",0);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+static void
+genRLC (iCode * ic)
+{
+ operand *left, *result;
+ int size, offset = 0;
+ char *l;
+
+ D (emitcode (";", "genRLC ");
+ );
+
+ /* rotate right with carry */
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (left) == AOP_DPTR);
+
+ /* move it to the result */
+ size = AOP_SIZE (result);
+ offset = 0;
+ if (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ if (AOP_SIZE (result) > 1)
+ {
+ aopPut (AOP (result), "a", offset++);
+ }
+
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset++);
+ }
+ _endLazyDPSEvaluation ();
+ }
+ /* now we need to put the carry into the
+ highest order byte of the result */
+ if (AOP_SIZE (result) > 1)
+ {
+ l = aopGet (AOP (result), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ }
+ emitcode ("mov", "acc.0,c");
+ aopPut (AOP (result), "a", 0);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGetHbit - generates code get highest order bit */
/*-----------------------------------------------------------------*/
-static void genGetHbit (iCode *ic)
+static void
+genGetHbit (iCode * ic)
{
- operand *left, *result;
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE, FALSE);
- aopOp (result,ic,FALSE, AOP_TYPE(left) == AOP_DPTR);
+ operand *left, *result;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (left) == AOP_DPTR);
- D(emitcode(";", "genGetHbit "););
+ D (emitcode (";", "genGetHbit ");
+ );
- /* get the highest order byte into a */
- MOVA(aopGet(AOP(left),AOP_SIZE(left) - 1,FALSE,FALSE,TRUE));
- if(AOP_TYPE(result) == AOP_CRY){
- emitcode("rlc","a");
- outBitC(result);
+ /* get the highest order byte into a */
+ MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE, TRUE));
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ emitcode ("rlc", "a");
+ outBitC (result);
}
- else{
- emitcode("rl","a");
- emitcode("anl","a,#0x01");
- outAcc(result);
+ else
+ {
+ emitcode ("rl", "a");
+ emitcode ("anl", "a,#0x01");
+ outAcc (result);
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* AccRol - rotate left accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRol (int shCount)
-{
- shCount &= 0x0007; // shCount : 0..7
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("rl","a");
- break;
- case 2 :
- emitcode("rl","a");
- emitcode("rl","a");
- break;
- case 3 :
- emitcode("swap","a");
- emitcode("rr","a");
- break;
- case 4 :
- emitcode("swap","a");
- break;
- case 5 :
- emitcode("swap","a");
- emitcode("rl","a");
- break;
- case 6 :
- emitcode("rr","a");
- emitcode("rr","a");
- break;
- case 7 :
- emitcode("rr","a");
- break;
+static void
+AccRol (int shCount)
+{
+ shCount &= 0x0007; // shCount : 0..7
+
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("rl", "a");
+ break;
+ case 2:
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ break;
+ case 3:
+ emitcode ("swap", "a");
+ emitcode ("rr", "a");
+ break;
+ case 4:
+ emitcode ("swap", "a");
+ break;
+ case 5:
+ emitcode ("swap", "a");
+ emitcode ("rl", "a");
+ break;
+ case 6:
+ emitcode ("rr", "a");
+ emitcode ("rr", "a");
+ break;
+ case 7:
+ emitcode ("rr", "a");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* AccLsh - left shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccLsh (int shCount)
+static void
+AccLsh (int shCount)
{
- if(shCount != 0){
- if(shCount == 1)
- emitcode("add","a,acc");
- else
- if(shCount == 2) {
- emitcode("add","a,acc");
- emitcode("add","a,acc");
- } else {
- /* rotate left accumulator */
- AccRol(shCount);
- /* and kill the lower order bits */
- emitcode("anl","a,#0x%02x", SLMask[shCount]);
- }
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ emitcode ("add", "a,acc");
+ else if (shCount == 2)
+ {
+ emitcode ("add", "a,acc");
+ emitcode ("add", "a,acc");
+ }
+ else
+ {
+ /* rotate left accumulator */
+ AccRol (shCount);
+ /* and kill the lower order bits */
+ emitcode ("anl", "a,#0x%02x", SLMask[shCount]);
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccRsh - right shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRsh (int shCount)
+static void
+AccRsh (int shCount)
{
- if(shCount != 0){
- if(shCount == 1){
- CLRC;
- emitcode("rrc","a");
- } else {
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- emitcode("anl","a,#0x%02x", SRMask[shCount]);
- }
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ {
+ CLRC;
+ emitcode ("rrc", "a");
+ }
+ else
+ {
+ /* rotate right accumulator */
+ AccRol (8 - shCount);
+ /* and kill the higher order bits */
+ emitcode ("anl", "a,#0x%02x", SRMask[shCount]);
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccSRsh - signed right shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccSRsh (int shCount)
-{
- symbol *tlbl ;
- if(shCount != 0){
- if(shCount == 1){
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- } else if(shCount == 2){
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- } else {
- tlbl = newiTempLabel(NULL);
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- emitcode("anl","a,#0x%02x", SRMask[shCount]);
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]);
- emitcode("","%05d$:",tlbl->key+100);
- }
+static void
+AccSRsh (int shCount)
+{
+ symbol *tlbl;
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ {
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ }
+ else if (shCount == 2)
+ {
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ /* rotate right accumulator */
+ AccRol (8 - shCount);
+ /* and kill the higher order bits */
+ emitcode ("anl", "a,#0x%02x", SRMask[shCount]);
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
}
}
#endif
/*-----------------------------------------------------------------*/
/* shiftR1Left2Result - shift right one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR1Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
+static void
+shiftR1Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
{
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
- /* shift right accumulator */
- if(sign)
- AccSRsh(shCount);
- else
- AccRsh(shCount);
- aopPut(AOP(result),"a",offr);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
+ /* shift right accumulator */
+ if (sign)
+ AccSRsh (shCount);
+ else
+ AccRsh (shCount);
+ aopPut (AOP (result), "a", offr);
}
#endif
/*-----------------------------------------------------------------*/
/* shiftL1Left2Result - shift left one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftL1Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftL1Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- char *l;
- l = aopGet(AOP(left),offl,FALSE,FALSE,TRUE);
- MOVA(l);
- /* shift left accumulator */
- AccLsh(shCount);
- aopPut(AOP(result),"a",offr);
+ char *l;
+ l = aopGet (AOP (left), offl, FALSE, FALSE, TRUE);
+ MOVA (l);
+ /* shift left accumulator */
+ AccLsh (shCount);
+ aopPut (AOP (result), "a", offr);
}
#endif
/*-----------------------------------------------------------------*/
/* movLeft2Result - move byte from left to result */
/*-----------------------------------------------------------------*/
-static void movLeft2Result (operand *left, int offl,
- operand *result, int offr, int sign)
-{
- char *l;
- if(!sameRegs(AOP(left),AOP(result)) || (offl != offr)){
- l = aopGet(AOP(left),offl,FALSE,FALSE,FALSE);
-
- if (*l == '@' && (IS_AOP_PREG(result))) {
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- } else {
- if(!sign)
- aopPut(AOP(result),l,offr);
- else{
- /* MSB sign in acc.7 ! */
- if(getDataSize(left) == offl+1){
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- }
- }
- }
+static void
+movLeft2Result (operand * left, int offl,
+ operand * result, int offr, int sign)
+{
+ char *l;
+ if (!sameRegs (AOP (left), AOP (result)) || (offl != offr))
+ {
+ l = aopGet (AOP (left), offl, FALSE, FALSE, FALSE);
+
+ if (*l == '@' && (IS_AOP_PREG (result)))
+ {
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offr);
+ }
+ else
+ {
+ if (!sign)
+ aopPut (AOP (result), l, offr);
+ else
+ {
+ /* MSB sign in acc.7 ! */
+ if (getDataSize (left) == offl + 1)
+ {
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offr);
+ }
+ }
+ }
}
}
#endif
/*-----------------------------------------------------------------*/
/* AccAXRrl1 - right rotate c->a:x->c by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXRrl1 (char *x)
+static void
+AccAXRrl1 (char *x)
{
- emitcode("rrc","a");
- emitcode("xch","a,%s", x);
- emitcode("rrc","a");
- emitcode("xch","a,%s", x);
+ emitcode ("rrc", "a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rrc", "a");
+ emitcode ("xch", "a,%s", x);
}
#endif
/*-----------------------------------------------------------------*/
/* AccAXLrl1 - left rotate c<-a:x<-c by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXLrl1 (char *x)
+static void
+AccAXLrl1 (char *x)
{
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
}
#endif
/*-----------------------------------------------------------------*/
/* AccAXLsh1 - left shift a:x<-0 by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXLsh1 (char *x)
+static void
+AccAXLsh1 (char *x)
{
- emitcode("xch","a,%s",x);
- emitcode("add","a,acc");
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("add", "a,acc");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
}
#endif
/*-----------------------------------------------------------------*/
/* AccAXLsh - left shift a:x by known count (0..7) */
/*-----------------------------------------------------------------*/
-static void AccAXLsh (char *x, int shCount)
-{
- switch(shCount){
- case 0 :
- break;
- case 1 :
- AccAXLsh1(x);
- break;
- case 2 :
- AccAXLsh1(x);
- AccAXLsh1(x);
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD
- AccRol(shCount); // BBBAAAAA:CCCCCDDD
- emitcode("anl","a,#0x%02x",
- SLMask[shCount]); // BBB00000:CCCCCDDD
- emitcode("xch","a,%s",x); // CCCCCDDD:BBB00000
- AccRol(shCount); // DDDCCCCC:BBB00000
- emitcode("xch","a,%s",x); // BBB00000:DDDCCCCC
- emitcode("xrl","a,%s",x); // (BBB^DDD)CCCCC:DDDCCCCC
- emitcode("xch","a,%s",x); // DDDCCCCC:(BBB^DDD)CCCCC
- emitcode("anl","a,#0x%02x",
- SLMask[shCount]); // DDD00000:(BBB^DDD)CCCCC
- emitcode("xch","a,%s",x); // (BBB^DDD)CCCCC:DDD00000
- emitcode("xrl","a,%s",x); // BBBCCCCC:DDD00000
- break;
- case 6 : // AAAAAABB:CCCCCCDD
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000BB:CCCCCCDD
- emitcode("mov","c,acc.0"); // c = B
- emitcode("xch","a,%s",x); // CCCCCCDD:000000BB
- AccAXRrl1(x); // BCCCCCCD:D000000B
- AccAXRrl1(x); // BBCCCCCC:DD000000
- break;
- case 7 : // a:x <<= 7
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000B:CCCCCCCD
- emitcode("mov","c,acc.0"); // c = B
- emitcode("xch","a,%s",x); // CCCCCCCD:0000000B
- AccAXRrl1(x); // BCCCCCCC:D0000000
- break;
- default :
- break;
+static void
+AccAXLsh (char *x, int shCount)
+{
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ AccAXLsh1 (x);
+ break;
+ case 2:
+ AccAXLsh1 (x);
+ AccAXLsh1 (x);
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD
+
+ AccRol (shCount); // BBBAAAAA:CCCCCDDD
+
+ emitcode ("anl", "a,#0x%02x",
+ SLMask[shCount]); // BBB00000:CCCCCDDD
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBB00000
+
+ AccRol (shCount); // DDDCCCCC:BBB00000
+
+ emitcode ("xch", "a,%s", x); // BBB00000:DDDCCCCC
+
+ emitcode ("xrl", "a,%s", x); // (BBB^DDD)CCCCC:DDDCCCCC
+
+ emitcode ("xch", "a,%s", x); // DDDCCCCC:(BBB^DDD)CCCCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SLMask[shCount]); // DDD00000:(BBB^DDD)CCCCC
+
+ emitcode ("xch", "a,%s", x); // (BBB^DDD)CCCCC:DDD00000
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:DDD00000
+
+ break;
+ case 6: // AAAAAABB:CCCCCCDD
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000BB:CCCCCCDD
+
+ emitcode ("mov", "c,acc.0"); // c = B
+
+ emitcode ("xch", "a,%s", x); // CCCCCCDD:000000BB
+
+ AccAXRrl1 (x); // BCCCCCCD:D000000B
+
+ AccAXRrl1 (x); // BBCCCCCC:DD000000
+
+ break;
+ case 7: // a:x <<= 7
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000B:CCCCCCCD
+
+ emitcode ("mov", "c,acc.0"); // c = B
+
+ emitcode ("xch", "a,%s", x); // CCCCCCCD:0000000B
+
+ AccAXRrl1 (x); // BCCCCCCC:D0000000
+
+ break;
+ default:
+ break;
}
}
#endif
/*-----------------------------------------------------------------*/
/* AccAXRsh - right shift a:x known count (0..7) */
/*-----------------------------------------------------------------*/
-static void AccAXRsh (char *x, int shCount)
-{
- switch(shCount){
- case 0 :
- break;
- case 1 :
- CLRC;
- AccAXRrl1(x); // 0->a:x
- break;
- case 2 :
- CLRC;
- AccAXRrl1(x); // 0->a:x
- CLRC;
- AccAXRrl1(x); // 0->a:x
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD = a:x
- AccRol(8 - shCount); // BBBAAAAA:DDDCCCCC
- emitcode("xch","a,%s",x); // CCCCCDDD:BBBAAAAA
- AccRol(8 - shCount); // DDDCCCCC:BBBAAAAA
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000CCCCC:BBBAAAAA
- emitcode("xrl","a,%s",x); // BBB(CCCCC^AAAAA):BBBAAAAA
- emitcode("xch","a,%s",x); // BBBAAAAA:BBB(CCCCC^AAAAA)
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
- emitcode("xch","a,%s",x); // BBB(CCCCC^AAAAA):000AAAAA
- emitcode("xrl","a,%s",x); // BBBCCCCC:000AAAAA
- emitcode("xch","a,%s",x); // 000AAAAA:BBBCCCCC
- break;
- case 6 : // AABBBBBB:CCDDDDDD
- emitcode("mov","c,acc.7");
- AccAXLrl1(x); // ABBBBBBC:CDDDDDDA
- AccAXLrl1(x); // BBBBBBCC:DDDDDDAA
- emitcode("xch","a,%s",x); // DDDDDDAA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000AA:BBBBBBCC
- break;
- case 7 : // ABBBBBBB:CDDDDDDD
- emitcode("mov","c,acc.7"); // c = A
- AccAXLrl1(x); // BBBBBBBC:DDDDDDDA
- emitcode("xch","a,%s",x); // DDDDDDDA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000A:BBBBBBBC
- break;
- default :
- break;
+static void
+AccAXRsh (char *x, int shCount)
+{
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ break;
+ case 2:
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD = a:x
+
+ AccRol (8 - shCount); // BBBAAAAA:DDDCCCCC
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBBAAAAA
+
+ AccRol (8 - shCount); // DDDCCCCC:BBBAAAAA
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000CCCCC:BBBAAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBB(CCCCC^AAAAA):BBBAAAAA
+
+ emitcode ("xch", "a,%s", x); // BBBAAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("xch", "a,%s", x); // BBB(CCCCC^AAAAA):000AAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:000AAAAA
+
+ emitcode ("xch", "a,%s", x); // 000AAAAA:BBBCCCCC
+
+ break;
+ case 6: // AABBBBBB:CCDDDDDD
+
+ emitcode ("mov", "c,acc.7");
+ AccAXLrl1 (x); // ABBBBBBC:CDDDDDDA
+
+ AccAXLrl1 (x); // BBBBBBCC:DDDDDDAA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDAA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000AA:BBBBBBCC
+
+ break;
+ case 7: // ABBBBBBB:CDDDDDDD
+
+ emitcode ("mov", "c,acc.7"); // c = A
+
+ AccAXLrl1 (x); // BBBBBBBC:DDDDDDDA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDDA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000A:BBBBBBBC
+
+ break;
+ default:
+ break;
}
}
#endif
/*-----------------------------------------------------------------*/
/* AccAXRshS - right shift signed a:x known count (0..7) */
/*-----------------------------------------------------------------*/
-static void AccAXRshS (char *x, int shCount)
-{
- symbol *tlbl ;
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- break;
- case 2 :
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD = a:x
- tlbl = newiTempLabel(NULL);
- AccRol(8 - shCount); // BBBAAAAA:CCCCCDDD
- emitcode("xch","a,%s",x); // CCCCCDDD:BBBAAAAA
- AccRol(8 - shCount); // DDDCCCCC:BBBAAAAA
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000CCCCC:BBBAAAAA
- emitcode("xrl","a,%s",x); // BBB(CCCCC^AAAAA):BBBAAAAA
- emitcode("xch","a,%s",x); // BBBAAAAA:BBB(CCCCC^AAAAA)
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
- emitcode("xch","a,%s",x); // BBB(CCCCC^AAAAA):000AAAAA
- emitcode("xrl","a,%s",x); // BBBCCCCC:000AAAAA
- emitcode("xch","a,%s",x); // 000SAAAA:BBBCCCCC
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 111AAAAA:BBBCCCCC
- emitcode("","%05d$:",tlbl->key+100);
- break; // SSSSAAAA:BBBCCCCC
- case 6 : // AABBBBBB:CCDDDDDD
- tlbl = newiTempLabel(NULL);
- emitcode("mov","c,acc.7");
- AccAXLrl1(x); // ABBBBBBC:CDDDDDDA
- AccAXLrl1(x); // BBBBBBCC:DDDDDDAA
- emitcode("xch","a,%s",x); // DDDDDDAA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000AA:BBBBBBCC
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 111111AA:BBBBBBCC
- emitcode("","%05d$:",tlbl->key+100);
- break;
- case 7 : // ABBBBBBB:CDDDDDDD
- tlbl = newiTempLabel(NULL);
- emitcode("mov","c,acc.7"); // c = A
- AccAXLrl1(x); // BBBBBBBC:DDDDDDDA
- emitcode("xch","a,%s",x); // DDDDDDDA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000A:BBBBBBBC
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 1111111A:BBBBBBBC
- emitcode("","%05d$:",tlbl->key+100);
- break;
- default :
- break;
- }
-}
-#endif
+static void
+AccAXRshS (char *x, int shCount)
+{
+ symbol *tlbl;
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
-#if 0
+ break;
+ case 2:
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD = a:x
+
+ tlbl = newiTempLabel (NULL);
+ AccRol (8 - shCount); // BBBAAAAA:CCCCCDDD
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBBAAAAA
+
+ AccRol (8 - shCount); // DDDCCCCC:BBBAAAAA
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000CCCCC:BBBAAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBB(CCCCC^AAAAA):BBBAAAAA
+
+ emitcode ("xch", "a,%s", x); // BBBAAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("xch", "a,%s", x); // BBB(CCCCC^AAAAA):000AAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:000AAAAA
+
+ emitcode ("xch", "a,%s", x); // 000SAAAA:BBBCCCCC
+
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 111AAAAA:BBBCCCCC
+
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ break; // SSSSAAAA:BBBCCCCC
+
+ case 6: // AABBBBBB:CCDDDDDD
+
+ tlbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,acc.7");
+ AccAXLrl1 (x); // ABBBBBBC:CDDDDDDA
+
+ AccAXLrl1 (x); // BBBBBBCC:DDDDDDAA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDAA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000AA:BBBBBBCC
+
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 111111AA:BBBBBBCC
+
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ break;
+ case 7: // ABBBBBBB:CDDDDDDD
+
+ tlbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,acc.7"); // c = A
+
+ AccAXLrl1 (x); // BBBBBBBC:DDDDDDDA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDDA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000A:BBBBBBBC
+
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 1111111A:BBBBBBBC
+
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ break;
+ default:
+ break;
+ }
+}
+#endif
+
+#if 0
//REMOVE ME!!!
/*-----------------------------------------------------------------*/
/* shiftL2Left2Result - shift left two bytes from left to result */
/*-----------------------------------------------------------------*/
-static void shiftL2Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftL2Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- if(sameRegs(AOP(result), AOP(left)) &&
- ((offl + MSB16) == offr)){
- /* don't crash result[offr] */
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
- emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE,FALSE));
- } else {
- movLeft2Result(left,offl, result, offr, 0);
- MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE,TRUE));
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ /* don't crash result[offr] */
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ movLeft2Result (left, offl, result, offr, 0);
+ MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE, TRUE));
}
- /* ax << shCount (x = lsb(result))*/
- AccAXLsh( aopGet(AOP(result),offr,FALSE,FALSE,FALSE), shCount);
- aopPut(AOP(result),"a",offr+MSB16);
+ /* ax << shCount (x = lsb(result)) */
+ AccAXLsh (aopGet (AOP (result), offr, FALSE, FALSE, FALSE), shCount);
+ aopPut (AOP (result), "a", offr + MSB16);
}
#endif
/*-----------------------------------------------------------------*/
/* shiftR2Left2Result - shift right two bytes from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR2Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
-{
- if(sameRegs(AOP(result), AOP(left)) &&
- ((offl + MSB16) == offr)){
- /* don't crash result[offr] */
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
- emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE,FALSE));
- } else {
- movLeft2Result(left,offl, result, offr, 0);
- MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE,TRUE));
- }
- /* a:x >> shCount (x = lsb(result))*/
- if(sign)
- AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE,FALSE) , shCount);
- else
- AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE,FALSE) , shCount);
- if(getDataSize(result) > 1)
- aopPut(AOP(result),"a",offr+MSB16);
+static void
+shiftR2Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
+{
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ /* don't crash result[offr] */
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ movLeft2Result (left, offl, result, offr, 0);
+ MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE, TRUE));
+ }
+ /* a:x >> shCount (x = lsb(result)) */
+ if (sign)
+ AccAXRshS (aopGet (AOP (result), offr, FALSE, FALSE, FALSE), shCount);
+ else
+ AccAXRsh (aopGet (AOP (result), offr, FALSE, FALSE, FALSE), shCount);
+ if (getDataSize (result) > 1)
+ aopPut (AOP (result), "a", offr + MSB16);
}
#endif
#if 0
//REMOVE ME!!!
/*-----------------------------------------------------------------*/
-/* shiftLLeftOrResult - shift left one byte from left, or to result*/
+/* shiftLLeftOrResult - shift left one byte from left, or to result */
/*-----------------------------------------------------------------*/
-static void shiftLLeftOrResult (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftLLeftOrResult (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
- /* shift left accumulator */
- AccLsh(shCount);
- /* or with result */
- emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE,FALSE));
- /* back to result */
- aopPut(AOP(result),"a",offr);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
+ /* shift left accumulator */
+ AccLsh (shCount);
+ /* or with result */
+ emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE, FALSE));
+ /* back to result */
+ aopPut (AOP (result), "a", offr);
}
#endif
#if 0
//REMOVE ME!!!
/*-----------------------------------------------------------------*/
-/* shiftRLeftOrResult - shift right one byte from left,or to result*/
+/* shiftRLeftOrResult - shift right one byte from left,or to result */
/*-----------------------------------------------------------------*/
-static void shiftRLeftOrResult (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftRLeftOrResult (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE,TRUE));
- /* shift right accumulator */
- AccRsh(shCount);
- /* or with result */
- emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE,FALSE));
- /* back to result */
- aopPut(AOP(result),"a",offr);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
+ /* shift right accumulator */
+ AccRsh (shCount);
+ /* or with result */
+ emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE, FALSE));
+ /* back to result */
+ aopPut (AOP (result), "a", offr);
}
#endif
/*-----------------------------------------------------------------*/
/* genlshOne - left shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
-static void genlshOne (operand *result, operand *left, int shCount)
+static void
+genlshOne (operand * result, operand * left, int shCount)
{
- D(emitcode(";", "genlshOne "););
- shiftL1Left2Result(left, LSB, result, LSB, shCount);
+ D (emitcode (";", "genlshOne ");
+ );
+ shiftL1Left2Result (left, LSB, result, LSB, shCount);
}
#endif
/*-----------------------------------------------------------------*/
/* genlshTwo - left shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genlshTwo (operand *result,operand *left, int shCount)
+static void
+genlshTwo (operand * result, operand * left, int shCount)
{
- int size;
+ int size;
- D(emitcode(";", "genlshTwo "););
+ D (emitcode (";", "genlshTwo ");
+ );
- size = getDataSize(result);
+ size = getDataSize (result);
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
- if (size > 1){
- if (shCount)
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- else
- movLeft2Result(left, LSB, result, MSB16, 0);
- }
- aopPut(AOP(result),zero,LSB);
+ if (size > 1)
+ {
+ if (shCount)
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ }
+ aopPut (AOP (result), zero, LSB);
}
- /* 1 <= shCount <= 7 */
- else {
- if(size == 1)
- shiftL1Left2Result(left, LSB, result, LSB, shCount);
- else
- shiftL2Left2Result(left, LSB, result, LSB, shCount);
+ /* 1 <= shCount <= 7 */
+ else
+ {
+ if (size == 1)
+ shiftL1Left2Result (left, LSB, result, LSB, shCount);
+ else
+ shiftL2Left2Result (left, LSB, result, LSB, shCount);
}
}
#endif
/* shiftLLong - shift left one long from left to result */
/* offl = LSB or MSB16 */
/*-----------------------------------------------------------------*/
-static void shiftLLong (operand *left, operand *result, int offr )
+static void
+shiftLLong (operand * left, operand * result, int offr)
{
- char *l;
- int size = AOP_SIZE(result);
+ char *l;
+ int size = AOP_SIZE (result);
- if(size >= LSB+offr){
- l = aopGet(AOP(left),LSB,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("add","a,acc");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB16+offr && offr != LSB )
- emitcode("xch","a,%s",
- aopGet(AOP(left),LSB+offr,FALSE,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",LSB+offr);
+ if (size >= LSB + offr)
+ {
+ l = aopGet (AOP (left), LSB, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB16 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), LSB + offr, FALSE, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", LSB + offr);
}
- if(size >= MSB16+offr){
- if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB16+offr && offr != LSB) ) {
- l = aopGet(AOP(left),MSB16,FALSE,FALSE,TRUE);
- MOVA(l);
- }
- emitcode("rlc","a");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB24+offr && offr != LSB)
- emitcode("xch","a,%s",
- aopGet(AOP(left),MSB16+offr,FALSE,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",MSB16+offr);
+ if (size >= MSB16 + offr)
+ {
+ if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB16 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB16, FALSE, FALSE, TRUE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB24 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), MSB16 + offr, FALSE, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", MSB16 + offr);
}
- if(size >= MSB24+offr){
- if (!(sameRegs(AOP(left),AOP(left)) && size >= MSB24+offr && offr != LSB)) {
- l = aopGet(AOP(left),MSB24,FALSE,FALSE,TRUE);
- MOVA(l);
- }
- emitcode("rlc","a");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB32+offr && offr != LSB )
- emitcode("xch","a,%s",
- aopGet(AOP(left),MSB24+offr,FALSE,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",MSB24+offr);
+ if (size >= MSB24 + offr)
+ {
+ if (!(sameRegs (AOP (left), AOP (left)) && size >= MSB24 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB24, FALSE, FALSE, TRUE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB32 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), MSB24 + offr, FALSE, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", MSB24 + offr);
}
- if(size > MSB32+offr){
- if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB32+offr && offr != LSB)) {
- l = aopGet(AOP(left),MSB32,FALSE,FALSE,TRUE);
- MOVA(l);
- }
- emitcode("rlc","a");
- aopPut(AOP(result),"a",MSB32+offr);
+ if (size > MSB32 + offr)
+ {
+ if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB32 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB32, FALSE, FALSE, TRUE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ aopPut (AOP (result), "a", MSB32 + offr);
}
- if(offr != LSB)
- aopPut(AOP(result),zero,LSB);
+ if (offr != LSB)
+ aopPut (AOP (result), zero, LSB);
}
#endif
/*-----------------------------------------------------------------*/
/* genlshFour - shift four byte by a known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genlshFour (operand *result, operand *left, int shCount)
-{
- int size;
-
- D(emitcode(";", "genlshFour "););
-
- size = AOP_SIZE(result);
-
- /* if shifting more that 3 bytes */
- if (shCount >= 24 ) {
- shCount -= 24;
- if (shCount)
- /* lowest order of left goes to the highest
- order of the destination */
- shiftL1Left2Result(left, LSB, result, MSB32, shCount);
- else
- movLeft2Result(left, LSB, result, MSB32, 0);
- aopPut(AOP(result),zero,LSB);
- aopPut(AOP(result),zero,MSB16);
- aopPut(AOP(result),zero,MSB32);
- return;
- }
-
- /* more than two bytes */
- else if ( shCount >= 16 ) {
- /* lower order two bytes goes to higher order two bytes */
- shCount -= 16;
- /* if some more remaining */
- if (shCount)
- shiftL2Left2Result(left, LSB, result, MSB24, shCount);
- else {
- movLeft2Result(left, MSB16, result, MSB32, 0);
- movLeft2Result(left, LSB, result, MSB24, 0);
- }
- aopPut(AOP(result),zero,MSB16);
- aopPut(AOP(result),zero,LSB);
- return;
- }
-
- /* if more than 1 byte */
- else if ( shCount >= 8 ) {
- /* lower order three bytes goes to higher order three bytes */
- shCount -= 8;
- if(size == 2){
- if(shCount)
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- else
- movLeft2Result(left, LSB, result, MSB16, 0);
- }
- else{ /* size = 4 */
- if(shCount == 0){
- movLeft2Result(left, MSB24, result, MSB32, 0);
- movLeft2Result(left, MSB16, result, MSB24, 0);
- movLeft2Result(left, LSB, result, MSB16, 0);
- aopPut(AOP(result),zero,LSB);
- }
- else if(shCount == 1)
- shiftLLong(left, result, MSB16);
- else{
- shiftL2Left2Result(left, MSB16, result, MSB24, shCount);
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- shiftRLeftOrResult(left, LSB, result, MSB24, 8 - shCount);
- aopPut(AOP(result),zero,LSB);
- }
- }
- }
-
- /* 1 <= shCount <= 7 */
- else if(shCount <= 2){
- shiftLLong(left, result, LSB);
- if(shCount == 2)
- shiftLLong(result, result, LSB);
- }
- /* 3 <= shCount <= 7, optimize */
- else{
- shiftL2Left2Result(left, MSB24, result, MSB24, shCount);
- shiftRLeftOrResult(left, MSB16, result, MSB24, 8 - shCount);
- shiftL2Left2Result(left, LSB, result, LSB, shCount);
+static void
+genlshFour (operand * result, operand * left, int shCount)
+{
+ int size;
+
+ D (emitcode (";", "genlshFour ");
+ );
+
+ size = AOP_SIZE (result);
+
+ /* if shifting more that 3 bytes */
+ if (shCount >= 24)
+ {
+ shCount -= 24;
+ if (shCount)
+ /* lowest order of left goes to the highest
+ order of the destination */
+ shiftL1Left2Result (left, LSB, result, MSB32, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB32, 0);
+ aopPut (AOP (result), zero, LSB);
+ aopPut (AOP (result), zero, MSB16);
+ aopPut (AOP (result), zero, MSB32);
+ return;
+ }
+
+ /* more than two bytes */
+ else if (shCount >= 16)
+ {
+ /* lower order two bytes goes to higher order two bytes */
+ shCount -= 16;
+ /* if some more remaining */
+ if (shCount)
+ shiftL2Left2Result (left, LSB, result, MSB24, shCount);
+ else
+ {
+ movLeft2Result (left, MSB16, result, MSB32, 0);
+ movLeft2Result (left, LSB, result, MSB24, 0);
+ }
+ aopPut (AOP (result), zero, MSB16);
+ aopPut (AOP (result), zero, LSB);
+ return;
+ }
+
+ /* if more than 1 byte */
+ else if (shCount >= 8)
+ {
+ /* lower order three bytes goes to higher order three bytes */
+ shCount -= 8;
+ if (size == 2)
+ {
+ if (shCount)
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ }
+ else
+ { /* size = 4 */
+ if (shCount == 0)
+ {
+ movLeft2Result (left, MSB24, result, MSB32, 0);
+ movLeft2Result (left, MSB16, result, MSB24, 0);
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ aopPut (AOP (result), zero, LSB);
+ }
+ else if (shCount == 1)
+ shiftLLong (left, result, MSB16);
+ else
+ {
+ shiftL2Left2Result (left, MSB16, result, MSB24, shCount);
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ shiftRLeftOrResult (left, LSB, result, MSB24, 8 - shCount);
+ aopPut (AOP (result), zero, LSB);
+ }
+ }
+ }
+
+ /* 1 <= shCount <= 7 */
+ else if (shCount <= 2)
+ {
+ shiftLLong (left, result, LSB);
+ if (shCount == 2)
+ shiftLLong (result, result, LSB);
+ }
+ /* 3 <= shCount <= 7, optimize */
+ else
+ {
+ shiftL2Left2Result (left, MSB24, result, MSB24, shCount);
+ shiftRLeftOrResult (left, MSB16, result, MSB24, 8 - shCount);
+ shiftL2Left2Result (left, LSB, result, LSB, shCount);
}
}
#endif
/*-----------------------------------------------------------------*/
/* genLeftShiftLiteral - left shifting by known count */
/*-----------------------------------------------------------------*/
-static void genLeftShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic)
+static void
+genLeftShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- D(emitcode(";","genLeftShiftLiteral (%d)", shCount););
+ D (emitcode (";", "genLeftShiftLiteral (%d)", shCount);
+ );
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, TRUE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, TRUE);
- size = getSize(operandType(result));
+ size = getSize (operandType (result));
#if VIEW_SIZE
- emitcode("; shift left ","result %d, left %d",size,
- AOP_SIZE(left));
+ emitcode ("; shift left ", "result %d, left %d", size,
+ AOP_SIZE (left));
#endif
- /* I suppose that the left size >= result size */
- if(shCount == 0){
- while(size--){
- movLeft2Result(left, size, result, size, 0);
- }
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ while (size--)
+ {
+ movLeft2Result (left, size, result, size, 0);
+ }
}
- else if(shCount >= (size * 8))
- while(size--)
- aopPut(AOP(result),zero,size);
- else{
- switch (size) {
- case 1:
- genlshOne (result,left,shCount);
- break;
+ else if (shCount >= (size * 8))
+ while (size--)
+ aopPut (AOP (result), zero, size);
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genlshOne (result, left, shCount);
+ break;
- case 2:
- case 3: /* bug: this is for generic pointers, I bet. */
- genlshTwo (result,left,shCount);
- break;
+ case 2:
+ case 3: /* bug: this is for generic pointers, I bet. */
+ genlshTwo (result, left, shCount);
+ break;
- case 4:
- genlshFour (result,left,shCount);
- break;
- }
+ case 4:
+ genlshFour (result, left, shCount);
+ break;
+ }
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
#endif
/*-----------------------------------------------------------------*/
/* genLeftShift - generates code for left shifting */
/*-----------------------------------------------------------------*/
-static void genLeftShift (iCode *ic)
+static void
+genLeftShift (iCode * ic)
{
- operand *left,*right, *result;
- int size, offset;
- char *l;
- symbol *tlbl , *tlbl1;
+ operand *left, *right, *result;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
- D(emitcode(";", "genLeftShift "););
+ D (emitcode (";", "genLeftShift ");
+ );
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- aopOp(right,ic,FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
#if 0
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genLeftShiftLiteral (left,right,result,ic);
- return ;
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genLeftShiftLiteral (left, right, result, ic);
+ return;
}
#endif
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, AOP_TYPE(left) == AOP_DPTR);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
- if (*l == '@' && (IS_AOP_PREG(result))) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- _endLazyDPSEvaluation();
- }
-
- tlbl = newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = 0 ;
- tlbl1 = newiTempLabel(NULL);
-
- /* if it is only one byte then */
- if (size == 1) {
- symbol *tlbl1 = newiTempLabel(NULL);
-
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("add","a,acc");
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
-
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("add","a,acc");
- aopPut(AOP(result),"a",offset++);
- _startLazyDPSEvaluation();
- while (--size) {
- l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("rlc","a");
- aopPut(AOP(result),"a",offset++);
- }
- _endLazyDPSEvaluation();
- reAdjustPreg(AOP(result));
-
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (left) == AOP_DPTR);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE, FALSE);
+ if (*l == '@' && (IS_AOP_PREG (result)))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ }
+
+ tlbl = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = 0;
+ tlbl1 = newiTempLabel (NULL);
+
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ symbol *tlbl1 = newiTempLabel (NULL);
+
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("add", "a,acc");
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ l = aopGet (AOP (result), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ aopPut (AOP (result), "a", offset++);
+ _startLazyDPSEvaluation ();
+ while (--size)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ aopPut (AOP (result), "a", offset++);
+ }
+ _endLazyDPSEvaluation ();
+ reAdjustPreg (AOP (result));
+
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
#if 0
/*-----------------------------------------------------------------*/
/* genrshOne - right shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
-static void genrshOne (operand *result, operand *left,
- int shCount, int sign)
+static void
+genrshOne (operand * result, operand * left,
+ int shCount, int sign)
{
- D(emitcode(";", "genrshOne"););
- shiftR1Left2Result(left, LSB, result, LSB, shCount, sign);
+ D (emitcode (";", "genrshOne");
+ );
+ shiftR1Left2Result (left, LSB, result, LSB, shCount, sign);
}
#endif
/*-----------------------------------------------------------------*/
/* genrshTwo - right shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshTwo (operand *result,operand *left,
- int shCount, int sign)
+static void
+genrshTwo (operand * result, operand * left,
+ int shCount, int sign)
{
- D(emitcode(";", "genrshTwo"););
+ D (emitcode (";", "genrshTwo");
+ );
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
- if (shCount)
- shiftR1Left2Result(left, MSB16, result, LSB,
- shCount, sign);
- else
- movLeft2Result(left, MSB16, result, LSB, sign);
- addSign(result, MSB16, sign);
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (shCount)
+ shiftR1Left2Result (left, MSB16, result, LSB,
+ shCount, sign);
+ else
+ movLeft2Result (left, MSB16, result, LSB, sign);
+ addSign (result, MSB16, sign);
}
- /* 1 <= shCount <= 7 */
- else
- shiftR2Left2Result(left, LSB, result, LSB, shCount, sign);
+ /* 1 <= shCount <= 7 */
+ else
+ shiftR2Left2Result (left, LSB, result, LSB, shCount, sign);
}
#endif
/* shiftRLong - shift right one long from left to result */
/* offl = LSB or MSB16 */
/*-----------------------------------------------------------------*/
-static void shiftRLong (operand *left, int offl,
- operand *result, int sign)
-{
- if(!sign)
- emitcode("clr","c");
- MOVA(aopGet(AOP(left),MSB32,FALSE,FALSE,TRUE));
- if(sign)
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB32-offl);
- if(offl == MSB16)
- /* add sign of "a" */
- addSign(result, MSB32, sign);
-
- MOVA(aopGet(AOP(left),MSB24,FALSE,FALSE,TRUE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB24-offl);
-
- MOVA(aopGet(AOP(left),MSB16,FALSE,FALSE,TRUE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB16-offl);
-
- if(offl == LSB){
- MOVA(aopGet(AOP(left),LSB,FALSE,FALSE,TRUE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",LSB);
+static void
+shiftRLong (operand * left, int offl,
+ operand * result, int sign)
+{
+ if (!sign)
+ emitcode ("clr", "c");
+ MOVA (aopGet (AOP (left), MSB32, FALSE, FALSE, TRUE));
+ if (sign)
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB32 - offl);
+ if (offl == MSB16)
+ /* add sign of "a" */
+ addSign (result, MSB32, sign);
+
+ MOVA (aopGet (AOP (left), MSB24, FALSE, FALSE, TRUE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB24 - offl);
+
+ MOVA (aopGet (AOP (left), MSB16, FALSE, FALSE, TRUE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB16 - offl);
+
+ if (offl == LSB)
+ {
+ MOVA (aopGet (AOP (left), LSB, FALSE, FALSE, TRUE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", LSB);
}
}
#endif
/*-----------------------------------------------------------------*/
/* genrshFour - shift four byte by a known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshFour (operand *result, operand *left,
- int shCount, int sign)
-{
- D(emitcode(";", "genrshFour"););
-
- /* if shifting more that 3 bytes */
- if(shCount >= 24 ) {
- shCount -= 24;
- if(shCount)
- shiftR1Left2Result(left, MSB32, result, LSB, shCount, sign);
- else
- movLeft2Result(left, MSB32, result, LSB, sign);
- addSign(result, MSB16, sign);
- }
- else if(shCount >= 16){
- shCount -= 16;
- if(shCount)
- shiftR2Left2Result(left, MSB24, result, LSB, shCount, sign);
- else{
- movLeft2Result(left, MSB24, result, LSB, 0);
- movLeft2Result(left, MSB32, result, MSB16, sign);
- }
- addSign(result, MSB24, sign);
- }
- else if(shCount >= 8){
- shCount -= 8;
- if(shCount == 1)
- shiftRLong(left, MSB16, result, sign);
- else if(shCount == 0){
- movLeft2Result(left, MSB16, result, LSB, 0);
- movLeft2Result(left, MSB24, result, MSB16, 0);
- movLeft2Result(left, MSB32, result, MSB24, sign);
- addSign(result, MSB32, sign);
- }
- else{
- shiftR2Left2Result(left, MSB16, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB32, result, MSB16, 8 - shCount);
- /* the last shift is signed */
- shiftR1Left2Result(left, MSB32, result, MSB24, shCount, sign);
- addSign(result, MSB32, sign);
- }
- }
- else{ /* 1 <= shCount <= 7 */
- if(shCount <= 2){
- shiftRLong(left, LSB, result, sign);
- if(shCount == 2)
- shiftRLong(result, LSB, result, sign);
- }
- else{
- shiftR2Left2Result(left, LSB, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB24, result, MSB16, 8 - shCount);
- shiftR2Left2Result(left, MSB24, result, MSB24, shCount, sign);
- }
+static void
+genrshFour (operand * result, operand * left,
+ int shCount, int sign)
+{
+ D (emitcode (";", "genrshFour");
+ );
+
+ /* if shifting more that 3 bytes */
+ if (shCount >= 24)
+ {
+ shCount -= 24;
+ if (shCount)
+ shiftR1Left2Result (left, MSB32, result, LSB, shCount, sign);
+ else
+ movLeft2Result (left, MSB32, result, LSB, sign);
+ addSign (result, MSB16, sign);
+ }
+ else if (shCount >= 16)
+ {
+ shCount -= 16;
+ if (shCount)
+ shiftR2Left2Result (left, MSB24, result, LSB, shCount, sign);
+ else
+ {
+ movLeft2Result (left, MSB24, result, LSB, 0);
+ movLeft2Result (left, MSB32, result, MSB16, sign);
+ }
+ addSign (result, MSB24, sign);
+ }
+ else if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (shCount == 1)
+ shiftRLong (left, MSB16, result, sign);
+ else if (shCount == 0)
+ {
+ movLeft2Result (left, MSB16, result, LSB, 0);
+ movLeft2Result (left, MSB24, result, MSB16, 0);
+ movLeft2Result (left, MSB32, result, MSB24, sign);
+ addSign (result, MSB32, sign);
+ }
+ else
+ {
+ shiftR2Left2Result (left, MSB16, result, LSB, shCount, 0);
+ shiftLLeftOrResult (left, MSB32, result, MSB16, 8 - shCount);
+ /* the last shift is signed */
+ shiftR1Left2Result (left, MSB32, result, MSB24, shCount, sign);
+ addSign (result, MSB32, sign);
+ }
+ }
+ else
+ { /* 1 <= shCount <= 7 */
+ if (shCount <= 2)
+ {
+ shiftRLong (left, LSB, result, sign);
+ if (shCount == 2)
+ shiftRLong (result, LSB, result, sign);
+ }
+ else
+ {
+ shiftR2Left2Result (left, LSB, result, LSB, shCount, 0);
+ shiftLLeftOrResult (left, MSB24, result, MSB16, 8 - shCount);
+ shiftR2Left2Result (left, MSB24, result, MSB24, shCount, sign);
+ }
}
}
#endif
/*-----------------------------------------------------------------*/
/* genRightShiftLiteral - right shifting by known count */
/*-----------------------------------------------------------------*/
-static void genRightShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic,
- int sign)
+static void
+genRightShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic,
+ int sign)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- D(emitcode(";", "genRightShiftLiteral"););
+ D (emitcode (";", "genRightShiftLiteral");
+ );
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, AOP_TYPE(left) == AOP_DPTR);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (left) == AOP_DPTR);
#if VIEW_SIZE
- emitcode("; shift right ","result %d, left %d",AOP_SIZE(result),
- AOP_SIZE(left));
+ emitcode ("; shift right ", "result %d, left %d", AOP_SIZE (result),
+ AOP_SIZE (left));
#endif
- size = getDataSize(left);
- /* test the LEFT size !!! */
+ size = getDataSize (left);
+ /* test the LEFT size !!! */
- /* I suppose that the left size >= result size */
- if(shCount == 0){
- size = getDataSize(result);
- while(size--)
- movLeft2Result(left, size, result, size, 0);
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ size = getDataSize (result);
+ while (size--)
+ movLeft2Result (left, size, result, size, 0);
}
- else if(shCount >= (size * 8)){
- if(sign)
- /* get sign in acc.7 */
- MOVA(aopGet(AOP(left),size-1,FALSE,FALSE,TRUE));
- addSign(result, LSB, sign);
- } else{
- switch (size) {
- case 1:
- genrshOne (result,left,shCount,sign);
- break;
+ else if (shCount >= (size * 8))
+ {
+ if (sign)
+ /* get sign in acc.7 */
+ MOVA (aopGet (AOP (left), size - 1, FALSE, FALSE, TRUE));
+ addSign (result, LSB, sign);
+ }
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genrshOne (result, left, shCount, sign);
+ break;
- case 2:
- genrshTwo (result,left,shCount,sign);
- break;
+ case 2:
+ genrshTwo (result, left, shCount, sign);
+ break;
- case 4:
- genrshFour (result,left,shCount,sign);
- break;
- default :
- break;
- }
+ case 4:
+ genrshFour (result, left, shCount, sign);
+ break;
+ default:
+ break;
+ }
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
}
#endif
/*-----------------------------------------------------------------*/
/* genSignedRightShift - right shift of signed number */
/*-----------------------------------------------------------------*/
-static void genSignedRightShift (iCode *ic)
+static void
+genSignedRightShift (iCode * ic)
{
- operand *right, *left, *result;
- int size, offset;
- char *l;
- symbol *tlbl, *tlbl1 ;
+ operand *right, *left, *result;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
- D(emitcode(";", "genSignedRightShift "););
+ D (emitcode (";", "genSignedRightShift ");
+ );
- /* we do it the hard way put the shift count in b
- and loop thru preserving the sign */
+ /* we do it the hard way put the shift count in b
+ and loop thru preserving the sign */
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- aopOp(right,ic,FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
#if 0
- if ( AOP_TYPE(right) == AOP_LIT) {
- genRightShiftLiteral (left,right,result,ic,1);
- return ;
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genRightShiftLiteral (left, right, result, ic, 1);
+ return;
}
#endif
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, AOP_TYPE(left) == AOP_DPTR);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
- if (*l == '@' && IS_AOP_PREG(result)) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- _endLazyDPSEvaluation();
- }
-
- /* mov the highest order bit to OVR */
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
-
- size = AOP_SIZE(result);
- offset = size - 1;
- emitcode("mov","a,%s",aopGet(AOP(left),offset,FALSE,FALSE,FALSE));
- emitcode("rlc","a");
- emitcode("mov","ov,c");
- /* if it is only one byte then */
- if (size == 1) {
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("mov","c,ov");
- emitcode("rrc","a");
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("mov","c,ov");
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("rrc","a");
- aopPut(AOP(result),"a",offset--);
- }
- _endLazyDPSEvaluation();
- reAdjustPreg(AOP(result));
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (left) == AOP_DPTR);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE, FALSE);
+ if (*l == '@' && IS_AOP_PREG (result))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ }
+
+ /* mov the highest order bit to OVR */
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
+
+ size = AOP_SIZE (result);
+ offset = size - 1;
+ emitcode ("mov", "a,%s", aopGet (AOP (left), offset, FALSE, FALSE, FALSE));
+ emitcode ("rlc", "a");
+ emitcode ("mov", "ov,c");
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("mov", "c,ov");
+ emitcode ("rrc", "a");
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("mov", "c,ov");
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", offset--);
+ }
+ _endLazyDPSEvaluation ();
+ reAdjustPreg (AOP (result));
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRightShift - generate code for right shifting */
/*-----------------------------------------------------------------*/
-static void genRightShift (iCode *ic)
+static void
+genRightShift (iCode * ic)
{
- operand *right, *left, *result;
- sym_link *retype ;
- int size, offset;
- char *l;
- symbol *tlbl, *tlbl1 ;
+ operand *right, *left, *result;
+ sym_link *retype;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
- D(emitcode(";", "genRightShift "););
+ D (emitcode (";", "genRightShift ");
+ );
- /* if signed then we do it the hard way preserve the
- sign bit moving it inwards */
- retype = getSpec(operandType(IC_RESULT(ic)));
+ /* if signed then we do it the hard way preserve the
+ sign bit moving it inwards */
+ retype = getSpec (operandType (IC_RESULT (ic)));
- if (!SPEC_USIGN(retype)) {
- genSignedRightShift (ic);
- return ;
+ if (!SPEC_USIGN (retype))
+ {
+ genSignedRightShift (ic);
+ return;
}
- /* signed & unsigned types are treated the same : i.e. the
- signed is NOT propagated inwards : quoting from the
- ANSI - standard : "for E1 >> E2, is equivalent to division
- by 2**E2 if unsigned or if it has a non-negative value,
- otherwise the result is implementation defined ", MY definition
- is that the sign does not get propagated */
+ /* signed & unsigned types are treated the same : i.e. the
+ signed is NOT propagated inwards : quoting from the
+ ANSI - standard : "for E1 >> E2, is equivalent to division
+ by 2**E2 if unsigned or if it has a non-negative value,
+ otherwise the result is implementation defined ", MY definition
+ is that the sign does not get propagated */
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- aopOp(right,ic,FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
#if 0
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genRightShiftLiteral (left,right,result,ic, 0);
- return ;
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genRightShiftLiteral (left, right, result, ic, 0);
+ return;
}
#endif
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, AOP_TYPE(left) == AOP_DPTR);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
- if (*l == '@' && IS_AOP_PREG(result)) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- _endLazyDPSEvaluation();
- }
-
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = size - 1;
-
- /* if it is only one byte then */
- if (size == 1) {
- l = aopGet(AOP(left),0,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- CLRC;
- emitcode("rrc","a");
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- CLRC;
- _startLazyDPSEvaluation();
- while (size--) {
- l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("rrc","a");
- aopPut(AOP(result),"a",offset--);
- }
- _endLazyDPSEvaluation();
- reAdjustPreg(AOP(result));
-
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (left) == AOP_DPTR);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE, FALSE);
+ if (*l == '@' && IS_AOP_PREG (result))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ }
+
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = size - 1;
+
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ l = aopGet (AOP (left), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ CLRC;
+ emitcode ("rrc", "a");
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ CLRC;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", offset--);
+ }
+ _endLazyDPSEvaluation ();
+ reAdjustPreg (AOP (result));
+
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genUnpackBits - generates code for unpacking bits */
/*-----------------------------------------------------------------*/
-static void genUnpackBits (operand *result, char *rname, int ptype)
+static void
+genUnpackBits (operand * result, char *rname, int ptype)
{
- int shCnt ;
- int rlen = 0 ;
- sym_link *etype;
- int offset = 0 ;
+ int shCnt;
+ int rlen = 0;
+ sym_link *etype;
+ int offset = 0;
- D(emitcode(";", "genUnpackBits "););
+ D (emitcode (";", "genUnpackBits ");
+ );
- etype = getSpec(operandType(result));
+ etype = getSpec (operandType (result));
- /* read the first byte */
- switch (ptype) {
+ /* read the first byte */
+ switch (ptype)
+ {
case POINTER:
case IPOINTER:
- emitcode("mov","a,@%s",rname);
- break;
+ emitcode ("mov", "a,@%s", rname);
+ break;
case PPOINTER:
- emitcode("movx","a,@%s",rname);
- break;
+ emitcode ("movx", "a,@%s", rname);
+ break;
case FPOINTER:
- emitcode("movx","a,@dptr");
- break;
+ emitcode ("movx", "a,@dptr");
+ break;
case CPOINTER:
- emitcode("clr","a");
- emitcode("movc","a","@a+dptr");
- break;
+ emitcode ("clr", "a");
+ emitcode ("movc", "a", "@a+dptr");
+ break;
case GPOINTER:
- emitcode("lcall","__gptrget");
- break;
+ emitcode ("lcall", "__gptrget");
+ break;
}
- /* if we have bitdisplacement then it fits */
- /* into this byte completely or if length is */
- /* less than a byte */
- if ((shCnt = SPEC_BSTR(etype)) ||
- (SPEC_BLEN(etype) <= 8)) {
+ /* if we have bitdisplacement then it fits */
+ /* into this byte completely or if length is */
+ /* less than a byte */
+ if ((shCnt = SPEC_BSTR (etype)) ||
+ (SPEC_BLEN (etype) <= 8))
+ {
- /* shift right acc */
- AccRsh(shCnt);
+ /* shift right acc */
+ AccRsh (shCnt);
- emitcode("anl","a,#0x%02x",
- ((unsigned char) -1)>>(8 - SPEC_BLEN(etype)));
- aopPut(AOP(result),"a",offset);
- return ;
+ emitcode ("anl", "a,#0x%02x",
+ ((unsigned char) -1) >> (8 - SPEC_BLEN (etype)));
+ aopPut (AOP (result), "a", offset);
+ return;
}
- /* bit field did not fit in a byte */
- rlen = SPEC_BLEN(etype) - 8;
- aopPut(AOP(result),"a",offset++);
+ /* bit field did not fit in a byte */
+ rlen = SPEC_BLEN (etype) - 8;
+ aopPut (AOP (result), "a", offset++);
- while (1) {
+ while (1)
+ {
- switch (ptype) {
- case POINTER:
- case IPOINTER:
- emitcode("inc","%s",rname);
- emitcode("mov","a,@%s",rname);
- break;
+ switch (ptype)
+ {
+ case POINTER:
+ case IPOINTER:
+ emitcode ("inc", "%s", rname);
+ emitcode ("mov", "a,@%s", rname);
+ break;
- case PPOINTER:
- emitcode("inc","%s",rname);
- emitcode("movx","a,@%s",rname);
- break;
+ case PPOINTER:
+ emitcode ("inc", "%s", rname);
+ emitcode ("movx", "a,@%s", rname);
+ break;
- case FPOINTER:
- emitcode("inc","dptr");
- emitcode("movx","a,@dptr");
- break;
+ case FPOINTER:
+ emitcode ("inc", "dptr");
+ emitcode ("movx", "a,@dptr");
+ break;
- case CPOINTER:
- emitcode("clr","a");
- emitcode("inc","dptr");
- emitcode("movc","a","@a+dptr");
- break;
+ case CPOINTER:
+ emitcode ("clr", "a");
+ emitcode ("inc", "dptr");
+ emitcode ("movc", "a", "@a+dptr");
+ break;
- case GPOINTER:
- emitcode("inc","dptr");
- emitcode("lcall","__gptrget");
- break;
- }
+ case GPOINTER:
+ emitcode ("inc", "dptr");
+ emitcode ("lcall", "__gptrget");
+ break;
+ }
- rlen -= 8;
- /* if we are done */
- if ( rlen < 8 )
- break ;
+ rlen -= 8;
+ /* if we are done */
+ if (rlen < 8)
+ break;
- aopPut(AOP(result),"a",offset++);
+ aopPut (AOP (result), "a", offset++);
}
- if (rlen) {
- emitcode("anl","a,#0x%02x",((unsigned char)-1)>>(rlen));
- aopPut(AOP(result),"a",offset);
+ if (rlen)
+ {
+ emitcode ("anl", "a,#0x%02x", ((unsigned char) -1) >> (rlen));
+ aopPut (AOP (result), "a", offset);
}
- return ;
+ return;
}
/*-----------------------------------------------------------------*/
/* genDataPointerGet - generates code when ptr offset is known */
/*-----------------------------------------------------------------*/
-static void genDataPointerGet (operand *left,
- operand *result,
- iCode *ic)
-{
- char *l;
- char buffer[256];
- int size , offset = 0;
- aopOp(result,ic,TRUE, FALSE);
-
- /* get the string representation of the name */
- l = aopGet(AOP(left),0,FALSE,TRUE,FALSE);
- size = AOP_SIZE(result);
- _startLazyDPSEvaluation();
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l+1,offset);
- else
- sprintf(buffer,"%s",l+1);
- aopPut(AOP(result),buffer,offset++);
+static void
+genDataPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
+{
+ char *l;
+ char buffer[256];
+ int size, offset = 0;
+ aopOp (result, ic, TRUE, FALSE);
+
+ /* get the string representation of the name */
+ l = aopGet (AOP (left), 0, FALSE, TRUE, FALSE);
+ size = AOP_SIZE (result);
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l + 1, offset);
+ else
+ sprintf (buffer, "%s", l + 1);
+ aopPut (AOP (result), buffer, offset++);
}
- _endLazyDPSEvaluation();
+ _endLazyDPSEvaluation ();
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerGet - emitcode for near pointer fetch */
/*-----------------------------------------------------------------*/
-static void genNearPointerGet (operand *left,
- operand *result,
- iCode *ic)
-{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
- sym_link *rtype, *retype, *letype;
- sym_link *ltype = operandType(left);
- char buffer[80];
-
- rtype = operandType(result);
- retype= getSpec(rtype);
- letype= getSpec(ltype);
-
- aopOp(left,ic,FALSE, FALSE);
-
- /* if left is rematerialisable and
- result is not bit variable type and
- the left is pointer to data space i.e
- lower 128 bytes of space */
- if (AOP_TYPE(left) == AOP_IMMD &&
- !IS_BITVAR(retype) &&
- !IS_BITVAR(letype) &&
- DCL_TYPE(ltype) == POINTER) {
- genDataPointerGet (left,result,ic);
- return ;
+static void
+genNearPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
+{
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname;
+ sym_link *rtype, *retype, *letype;
+ sym_link *ltype = operandType (left);
+ char buffer[80];
+
+ rtype = operandType (result);
+ retype = getSpec (rtype);
+ letype = getSpec (ltype);
+
+ aopOp (left, ic, FALSE, FALSE);
+
+ /* if left is rematerialisable and
+ result is not bit variable type and
+ the left is pointer to data space i.e
+ lower 128 bytes of space */
+ if (AOP_TYPE (left) == AOP_IMMD &&
+ !IS_BITVAR (retype) &&
+ !IS_BITVAR (letype) &&
+ DCL_TYPE (ltype) == POINTER)
+ {
+ genDataPointerGet (left, result, ic);
+ return;
}
/* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0,FALSE,TRUE,FALSE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0,FALSE,FALSE,FALSE);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE, FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genUnpackBits (result,rname,POINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
- if (IS_AOP_PREG(result) || AOP_TYPE(result) == AOP_STK ) {
-
- emitcode("mov","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
- } else {
- sprintf(buffer,"@%s",rname);
- aopPut(AOP(result),buffer,offset);
- }
- offset++ ;
- if (size)
- emitcode("inc","%s",rname);
- }
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0, FALSE, TRUE, FALSE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (left), 0, FALSE, FALSE, FALSE);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genUnpackBits (result, rname, POINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+ if (IS_AOP_PREG (result) || AOP_TYPE (result) == AOP_STK)
+ {
+
+ emitcode ("mov", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ {
+ sprintf (buffer, "@%s", rname);
+ aopPut (AOP (result), buffer, offset);
+ }
+ offset++;
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- /* done */
- freeAsmop(result,NULL,ic,TRUE);
+ /* done */
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerGet - emitcode for paged pointer fetch */
/*-----------------------------------------------------------------*/
-static void genPagedPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genPagedPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname;
- sym_link *rtype, *retype, *letype;
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname;
+ sym_link *rtype, *retype, *letype;
- rtype = operandType(result);
- retype= getSpec(rtype);
- letype= getSpec(operandType(left));
- aopOp(left,ic,FALSE, FALSE);
+ rtype = operandType (result);
+ retype = getSpec (rtype);
+ letype = getSpec (operandType (left));
+ aopOp (left, ic, FALSE, FALSE);
/* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0,FALSE,TRUE,FALSE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0,FALSE,FALSE,FALSE);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE, FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genUnpackBits (result,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
-
- emitcode("movx","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
-
- offset++ ;
-
- if (size)
- emitcode("inc","%s",rname);
- }
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0, FALSE, TRUE, FALSE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (left), 0, FALSE, FALSE, FALSE);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genUnpackBits (result, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+
+ emitcode ("movx", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
+
+ offset++;
+
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- /* done */
- freeAsmop(result,NULL,ic,TRUE);
+ /* done */
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerGet - gget value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerGet (operand *left,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
- sym_link *letype = getSpec(operandType(left));
- D(emitcode(";", "genFarPointerGet"););
-
- aopOp(left,ic,FALSE, FALSE);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- {
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE,FALSE));
- }
- else
- {
- /* we need to get it byte by byte */
- _startLazyDPSEvaluation();
- if (AOP_TYPE(left) != AOP_DPTR)
- {
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
- emitcode("mov","dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
- }
- else
- {
- /* We need to generate a load to DPTR indirect through DPTR. */
- D(emitcode(";", "genFarPointerGet -- indirection special case."););
- emitcode("push", "%s", aopGet(AOP(left),0,FALSE,TRUE,TRUE));
- emitcode("push", "%s", aopGet(AOP(left),1,FALSE,TRUE,TRUE));
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
- emitcode("pop", "dph");
- emitcode("pop", "dpl");
- }
- _endLazyDPSEvaluation();
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE, TRUE);
+static void
+genFarPointerGet (operand * left,
+ operand * result, iCode * ic)
+{
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
+ sym_link *letype = getSpec (operandType (left));
+ D (emitcode (";", "genFarPointerGet");
+ );
+
+ aopOp (left, ic, FALSE, FALSE);
- /* if bit then unpack */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genUnpackBits(result,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE, FALSE));
+ }
+ else
+ {
+ /* we need to get it byte by byte */
+ _startLazyDPSEvaluation ();
+ if (AOP_TYPE (left) != AOP_DPTR)
+ {
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE, TRUE));
+ }
+ else
+ {
+ /* We need to generate a load to DPTR indirect through DPTR. */
+ D (emitcode (";", "genFarPointerGet -- indirection special case.");
+ );
+ emitcode ("push", "%s", aopGet (AOP (left), 0, FALSE, TRUE, TRUE));
+ emitcode ("push", "%s", aopGet (AOP (left), 1, FALSE, TRUE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE, TRUE));
+ emitcode ("pop", "dph");
+ emitcode ("pop", "dpl");
+ }
+ _endLazyDPSEvaluation ();
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE, TRUE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genUnpackBits (result, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
- _startLazyDPSEvaluation();
- while (size--) {
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
- genSetDPTR(0);
- _flushLazyDPS();
+ genSetDPTR (0);
+ _flushLazyDPS ();
- emitcode("movx","a,@dptr");
- if (size)
- emitcode("inc","dptr");
+ emitcode ("movx", "a,@dptr");
+ if (size)
+ emitcode ("inc", "dptr");
- aopPut(AOP(result),"a",offset++);
- }
- _endLazyDPSEvaluation();
+ aopPut (AOP (result), "a", offset++);
+ }
+ _endLazyDPSEvaluation ();
}
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* emitcodePointerGet - gget value from code space */
/*-----------------------------------------------------------------*/
-static void emitcodePointerGet (operand *left,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
-
- aopOp(left,ic,FALSE, FALSE);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- {
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE,FALSE));
- }
- else
- { /* we need to get it byte by byte */
- _startLazyDPSEvaluation();
- if (AOP_TYPE(left) != AOP_DPTR)
- {
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
- emitcode("mov","dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
- }
- else
- {
- /* We need to generate a load to DPTR indirect through DPTR. */
- D(emitcode(";", "gencodePointerGet -- indirection special case."););
- emitcode("push", "%s", aopGet(AOP(left),0,FALSE,TRUE,TRUE));
- emitcode("push", "%s", aopGet(AOP(left),1,FALSE,TRUE,TRUE));
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
- emitcode("pop", "dph");
- emitcode("pop", "dpl");
- }
- _endLazyDPSEvaluation();
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE, TRUE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",CPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- _startLazyDPSEvaluation();
- while (size--)
- {
- genSetDPTR(0);
- _flushLazyDPS();
-
- emitcode("clr","a");
- emitcode("movc","a,@a+dptr");
- if (size)
- emitcode("inc","dptr");
- aopPut(AOP(result),"a",offset++);
- }
- _endLazyDPSEvaluation();
- }
-
- freeAsmop(result,NULL,ic,TRUE);
+static void
+emitcodePointerGet (operand * left,
+ operand * result, iCode * ic)
+{
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
+
+ aopOp (left, ic, FALSE, FALSE);
+
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE, FALSE));
+ }
+ else
+ { /* we need to get it byte by byte */
+ _startLazyDPSEvaluation ();
+ if (AOP_TYPE (left) != AOP_DPTR)
+ {
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE, TRUE));
+ }
+ else
+ {
+ /* We need to generate a load to DPTR indirect through DPTR. */
+ D (emitcode (";", "gencodePointerGet -- indirection special case.");
+ );
+ emitcode ("push", "%s", aopGet (AOP (left), 0, FALSE, TRUE, TRUE));
+ emitcode ("push", "%s", aopGet (AOP (left), 1, FALSE, TRUE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE, TRUE));
+ emitcode ("pop", "dph");
+ emitcode ("pop", "dpl");
+ }
+ _endLazyDPSEvaluation ();
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE, TRUE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", CPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
+
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ genSetDPTR (0);
+ _flushLazyDPS ();
+
+ emitcode ("clr", "a");
+ emitcode ("movc", "a,@a+dptr");
+ if (size)
+ emitcode ("inc", "dptr");
+ aopPut (AOP (result), "a", offset++);
+ }
+ _endLazyDPSEvaluation ();
+ }
+
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerGet - gget value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genGenPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
- sym_link *letype = getSpec(operandType(left));
-
- aopOp(left,ic,FALSE, TRUE);
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
+ sym_link *letype = getSpec (operandType (left));
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE,FALSE));
- emitcode("mov","b,#%d",pointerCode(retype));
- }
- else { /* we need to get it byte by byte */
- _startLazyDPSEvaluation();
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
- emitcode("mov","dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
- emitcode("mov","b,%s",aopGet(AOP(left),3,FALSE,FALSE,TRUE));
- _endLazyDPSEvaluation();
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE, TRUE);
+ aopOp (left, ic, FALSE, TRUE);
- /* if bit then unpack */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genUnpackBits(result,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE, FALSE));
+ emitcode ("mov", "b,#%d", pointerCode (retype));
+ }
+ else
+ { /* we need to get it byte by byte */
+ _startLazyDPSEvaluation ();
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE, TRUE));
+ emitcode ("mov", "b,%s", aopGet (AOP (left), 3, FALSE, FALSE, TRUE));
+ _endLazyDPSEvaluation ();
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE, TRUE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genUnpackBits (result, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
- while (size--) {
- emitcode("lcall","__gptrget");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
- }
+ while (size--)
+ {
+ emitcode ("lcall", "__gptrget");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
-static void genPointerGet (iCode *ic)
+static void
+genPointerGet (iCode * ic)
{
- operand *left, *result ;
- sym_link *type, *etype;
- int p_type;
+ operand *left, *result;
+ sym_link *type, *etype;
+ int p_type;
- D(emitcode(";", "genPointerGet "););
+ D (emitcode (";", "genPointerGet ");
+ );
- left = IC_LEFT(ic);
- result = IC_RESULT(ic) ;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(left);
- etype = getSpec(type);
- /* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next))
- p_type = DCL_TYPE(type);
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (left);
+ etype = getSpec (type);
+ /* if left is of type of pointer then it is simple */
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ p_type = DCL_TYPE (type);
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
}
- /* now that we have the pointer type we assign
- the pointer values */
- switch (p_type) {
+ /* now that we have the pointer type we assign
+ the pointer values */
+ switch (p_type)
+ {
case POINTER:
case IPOINTER:
- genNearPointerGet (left,result,ic);
- break;
+ genNearPointerGet (left, result, ic);
+ break;
case PPOINTER:
- genPagedPointerGet(left,result,ic);
- break;
+ genPagedPointerGet (left, result, ic);
+ break;
case FPOINTER:
- genFarPointerGet (left,result,ic);
- break;
+ genFarPointerGet (left, result, ic);
+ break;
case CPOINTER:
- emitcodePointerGet (left,result,ic);
- break;
+ emitcodePointerGet (left, result, ic);
+ break;
case GPOINTER:
- genGenPointerGet (left,result,ic);
- break;
+ genGenPointerGet (left, result, ic);
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genPackBits - generates code for packed bit storage */
/*-----------------------------------------------------------------*/
-static void genPackBits (sym_link *etype ,
- operand *right ,
- char *rname, int p_type)
-{
- int shCount = 0 ;
- int offset = 0 ;
- int rLen = 0 ;
- int blen, bstr ;
- char *l ;
+static void
+genPackBits (sym_link * etype,
+ operand * right,
+ char *rname, int p_type)
+{
+ int shCount = 0;
+ int offset = 0;
+ int rLen = 0;
+ int blen, bstr;
+ char *l;
- blen = SPEC_BLEN(etype);
- bstr = SPEC_BSTR(etype);
+ blen = SPEC_BLEN (etype);
+ bstr = SPEC_BSTR (etype);
- l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
- MOVA(l);
-
- /* if the bit lenth is less than or */
- /* it exactly fits a byte then */
- if (SPEC_BLEN(etype) <= 8 ) {
- shCount = SPEC_BSTR(etype) ;
-
- /* shift left acc */
- AccLsh(shCount);
-
- if (SPEC_BLEN(etype) < 8 ) { /* if smaller than a byte */
-
-
- switch (p_type) {
- case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
- break;
-
- case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
- break;
+ l = aopGet (AOP (right), offset++, FALSE, FALSE, TRUE);
+ MOVA (l);
- case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
- break;
- }
+ /* if the bit lenth is less than or */
+ /* it exactly fits a byte then */
+ if (SPEC_BLEN (etype) <= 8)
+ {
+ shCount = SPEC_BSTR (etype);
- emitcode ("anl","a,#0x%02x",(unsigned char)
- ((unsigned char)(0xFF << (blen+bstr)) |
- (unsigned char)(0xFF >> (8-bstr)) ) );
- emitcode ("orl","a,b");
- if (p_type == GPOINTER)
- emitcode("pop","b");
- }
- }
+ /* shift left acc */
+ AccLsh (shCount);
- switch (p_type) {
- case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
+ if (SPEC_BLEN (etype) < 8)
+ { /* if smaller than a byte */
- case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
- case GPOINTER:
- emitcode("lcall","__gptrput");
- break;
- }
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
- /* if we r done */
- if ( SPEC_BLEN(etype) <= 8 )
- return ;
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
- emitcode("inc","%s",rname);
- rLen = SPEC_BLEN(etype) ;
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
- /* now generate for lengths greater than one byte */
- while (1) {
+ emitcode ("anl", "a,#0x%02x", (unsigned char)
+ ((unsigned char) (0xFF << (blen + bstr)) |
+ (unsigned char) (0xFF >> (8 - bstr))));
+ emitcode ("orl", "a,b");
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+ }
+ }
- l = aopGet(AOP(right),offset++,FALSE,TRUE,FALSE);
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "@%s,a", rname);
+ break;
- rLen -= 8 ;
- if (rLen < 8 )
- break ;
+ case FPOINTER:
+ emitcode ("movx", "@dptr,a");
+ break;
- switch (p_type) {
- case POINTER:
- if (*l == '@') {
- MOVA(l);
- emitcode("mov","@%s,a",rname);
- } else
- emitcode("mov","@%s,%s",rname,l);
- break;
+ case GPOINTER:
+ emitcode ("lcall", "__gptrput");
+ break;
+ }
- case FPOINTER:
- MOVA(l);
- emitcode("movx","@dptr,a");
- break;
-
- case GPOINTER:
- MOVA(l);
- emitcode("lcall","__gptrput");
- break;
- }
- emitcode ("inc","%s",rname);
- }
-
- MOVA(l);
-
- /* last last was not complete */
- if (rLen) {
- /* save the byte & read byte */
- switch (p_type) {
- case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
- break;
+ /* if we r done */
+ if (SPEC_BLEN (etype) <= 8)
+ return;
- case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
- break;
+ emitcode ("inc", "%s", rname);
+ rLen = SPEC_BLEN (etype);
- case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
- break;
- }
-
- emitcode ("anl","a,#0x%02x",((unsigned char)-1 << rLen) );
- emitcode ("orl","a,b");
- }
-
- if (p_type == GPOINTER)
- emitcode("pop","b");
+ /* now generate for lengths greater than one byte */
+ while (1)
+ {
- switch (p_type) {
+ l = aopGet (AOP (right), offset++, FALSE, TRUE, FALSE);
+
+ rLen -= 8;
+ if (rLen < 8)
+ break;
+
+ switch (p_type)
+ {
+ case POINTER:
+ if (*l == '@')
+ {
+ MOVA (l);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, l);
+ break;
+
+ case FPOINTER:
+ MOVA (l);
+ emitcode ("movx", "@dptr,a");
+ break;
+
+ case GPOINTER:
+ MOVA (l);
+ emitcode ("lcall", "__gptrput");
+ break;
+ }
+ emitcode ("inc", "%s", rname);
+ }
+
+ MOVA (l);
+
+ /* last last was not complete */
+ if (rLen)
+ {
+ /* save the byte & read byte */
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
+
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
+
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
+
+ emitcode ("anl", "a,#0x%02x", ((unsigned char) -1 << rLen));
+ emitcode ("orl", "a,b");
+ }
+
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+
+ switch (p_type)
+ {
case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
+ emitcode ("mov", "@%s,a", rname);
+ break;
case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
+ emitcode ("movx", "@dptr,a");
+ break;
case GPOINTER:
- emitcode("lcall","__gptrput");
- break;
+ emitcode ("lcall", "__gptrput");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genDataPointerSet - remat pointer to data space */
/*-----------------------------------------------------------------*/
-static void genDataPointerSet(operand *right,
- operand *result,
- iCode *ic)
+static void
+genDataPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
- int size, offset = 0 ;
- char *l, buffer[256];
+ int size, offset = 0;
+ char *l, buffer[256];
- aopOp(right,ic,FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
- l = aopGet(AOP(result),0,FALSE,TRUE,FALSE);
- size = AOP_SIZE(right);
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l+1,offset);
- else
- sprintf(buffer,"%s",l+1);
- emitcode("mov","%s,%s",buffer,
- aopGet(AOP(right),offset++,FALSE,FALSE,FALSE));
+ l = aopGet (AOP (result), 0, FALSE, TRUE, FALSE);
+ size = AOP_SIZE (right);
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l + 1, offset);
+ else
+ sprintf (buffer, "%s", l + 1);
+ emitcode ("mov", "%s,%s", buffer,
+ aopGet (AOP (right), offset++, FALSE, FALSE, FALSE));
}
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerSet - emitcode for near pointer put */
/*-----------------------------------------------------------------*/
-static void genNearPointerSet (operand *right,
- operand *result,
- iCode *ic)
+static void
+genNearPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname , *l;
- sym_link *retype, *letype;
- sym_link *ptype = operandType(result);
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname, *l;
+ sym_link *retype, *letype;
+ sym_link *ptype = operandType (result);
- retype= getSpec(operandType(right));
- letype= getSpec(ptype);
+ retype = getSpec (operandType (right));
+ letype = getSpec (ptype);
- aopOp(result,ic,FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
- /* if the result is rematerializable &
- in data space & not a bit variable */
- if (AOP_TYPE(result) == AOP_IMMD &&
- DCL_TYPE(ptype) == POINTER &&
- !IS_BITVAR(retype) &&
- !IS_BITVAR(letype)) {
- genDataPointerSet (right,result,ic);
- return;
+ /* if the result is rematerializable &
+ in data space & not a bit variable */
+ if (AOP_TYPE (result) == AOP_IMMD &&
+ DCL_TYPE (ptype) == POINTER &&
+ !IS_BITVAR (retype) &&
+ !IS_BITVAR (letype))
+ {
+ 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))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(result),0,FALSE,TRUE,FALSE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(result),0,FALSE,FALSE,FALSE);
-
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE, FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits ((IS_BITVAR(retype) ? retype : letype),right,rname,POINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
-
- while (size--) {
- l = aopGet(AOP(right),offset,FALSE,TRUE,FALSE);
- if (*l == '@' ) {
- MOVA(l);
- emitcode("mov","@%s,a",rname);
- } else
- emitcode("mov","@%s,%s",rname,l);
- if (size)
- emitcode("inc","%s",rname);
- offset++;
- }
- }
-
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(right) - 1;
- while (size--)
- emitcode("dec","%s",rname);
- }
- }
-
- /* done */
- freeAsmop(right,NULL,ic,TRUE);
+ /* if the value is already in a pointer register
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0, FALSE, TRUE, FALSE));
+ rname = preg->name;
+ }
+ else
+ rname = aopGet (AOP (result), 0, FALSE, FALSE, FALSE);
+
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, rname, POINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
+
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset, FALSE, TRUE, FALSE);
+ if (*l == '@')
+ {
+ MOVA (l);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, l);
+ if (size)
+ emitcode ("inc", "%s", rname);
+ offset++;
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
+ }
+
+ /* done */
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerSet - emitcode for Paged pointer put */
/*-----------------------------------------------------------------*/
-static void genPagedPointerSet (operand *right,
- operand *result,
- iCode *ic)
-{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname , *l;
- sym_link *retype, *letype;
-
- retype= getSpec(operandType(right));
- letype= getSpec(operandType(result));
-
- aopOp(result,ic,FALSE, FALSE);
-
- /* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(result))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(result),0,FALSE,TRUE,FALSE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(result),0,FALSE,FALSE,FALSE);
-
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE, FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits ((IS_BITVAR(retype) ? retype : letype) ,right,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
-
- while (size--) {
- l = aopGet(AOP(right),offset,FALSE,TRUE,TRUE);
-
- MOVA(l);
- emitcode("movx","@%s,a",rname);
+static void
+genPagedPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
+{
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname, *l;
+ sym_link *retype, *letype;
- if (size)
- emitcode("inc","%s",rname);
+ retype = getSpec (operandType (right));
+ letype = getSpec (operandType (result));
- offset++;
- }
+ aopOp (result, ic, FALSE, FALSE);
+
+ /* if the value is already in a pointer register
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0, FALSE, TRUE, FALSE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (result), 0, FALSE, FALSE, FALSE);
+
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(right) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+ l = aopGet (AOP (right), offset, FALSE, TRUE, TRUE);
+
+ MOVA (l);
+ emitcode ("movx", "@%s,a", rname);
+
+ if (size)
+ emitcode ("inc", "%s", rname);
+
+ offset++;
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- /* done */
- freeAsmop(right,NULL,ic,TRUE);
+ /* done */
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerSet - set value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerSet (operand *right,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
- sym_link *letype = getSpec(operandType(result));
-
- aopOp(result,ic,FALSE, FALSE);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE,FALSE));
- else
- {
- /* we need to get it byte by byte */
- _startLazyDPSEvaluation();
- if (AOP_TYPE(result) != AOP_DPTR)
- {
- emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE,TRUE));
- emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE,TRUE));
- emitcode("mov","dpx,%s",aopGet(AOP(result),2,FALSE,FALSE,TRUE));
- }
- else
- {
- /* We need to generate a load to DPTR indirect through DPTR. */
- D(emitcode(";", "genFarPointerSet -- indirection special case."););
- emitcode("push", "%s", aopGet(AOP(result),0,FALSE,TRUE,TRUE));
- emitcode("push", "%s", aopGet(AOP(result),1,FALSE,TRUE,TRUE));
- emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE,TRUE));
- emitcode("pop", "dph");
- emitcode("pop", "dpl");
- }
- _endLazyDPSEvaluation();
- }
- }
- /* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE, TRUE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits((IS_BITVAR(retype)?retype:letype),right,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
-
- _startLazyDPSEvaluation();
- while (size--) {
- char *l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
- MOVA(l);
-
- genSetDPTR(0);
- _flushLazyDPS();
-
- emitcode("movx","@dptr,a");
- if (size)
- emitcode("inc","dptr");
- }
- _endLazyDPSEvaluation();
- }
-
- freeAsmop(right,NULL,ic,TRUE);
+static void
+genFarPointerSet (operand * right,
+ operand * result, iCode * ic)
+{
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
+ sym_link *letype = getSpec (operandType (result));
+
+ aopOp (result, ic, FALSE, FALSE);
+
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0, TRUE, FALSE, FALSE));
+ else
+ {
+ /* we need to get it byte by byte */
+ _startLazyDPSEvaluation ();
+ if (AOP_TYPE (result) != AOP_DPTR)
+ {
+ emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (result), 1, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2, FALSE, FALSE, TRUE));
+ }
+ else
+ {
+ /* We need to generate a load to DPTR indirect through DPTR. */
+ D (emitcode (";", "genFarPointerSet -- indirection special case.");
+ );
+ emitcode ("push", "%s", aopGet (AOP (result), 0, FALSE, TRUE, TRUE));
+ emitcode ("push", "%s", aopGet (AOP (result), 1, FALSE, TRUE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2, FALSE, FALSE, TRUE));
+ emitcode ("pop", "dph");
+ emitcode ("pop", "dpl");
+ }
+ _endLazyDPSEvaluation ();
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE, TRUE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
+
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset++, FALSE, FALSE, TRUE);
+ MOVA (l);
+
+ genSetDPTR (0);
+ _flushLazyDPS ();
+
+ emitcode ("movx", "@dptr,a");
+ if (size)
+ emitcode ("inc", "dptr");
+ }
+ _endLazyDPSEvaluation ();
+ }
+
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerSet - set value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerSet (operand *right,
- operand *result, iCode *ic)
+static void
+genGenPointerSet (operand * right,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
- sym_link *letype = getSpec(operandType(result));
-
- aopOp(result,ic,FALSE, TRUE);
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
+ sym_link *letype = getSpec (operandType (result));
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- _startLazyDPSEvaluation();
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE,FALSE));
- emitcode("mov","b,%s + 1",aopGet(AOP(result),0,TRUE,FALSE,FALSE));
- }
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE,TRUE));
- emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE,TRUE));
- emitcode("mov","dpx,%s",aopGet(AOP(result),2,FALSE,FALSE,TRUE));
- emitcode("mov","b,%s",aopGet(AOP(result),3,FALSE,FALSE,TRUE));
- }
- _endLazyDPSEvaluation();
- }
- /* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE, TRUE);
+ aopOp (result, ic, FALSE, TRUE);
- /* if bit then unpack */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits((IS_BITVAR(retype)?retype:letype),right,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ _startLazyDPSEvaluation ();
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0, TRUE, FALSE, FALSE));
+ emitcode ("mov", "b,%s + 1", aopGet (AOP (result), 0, TRUE, FALSE, FALSE));
+ }
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (result), 1, FALSE, FALSE, TRUE));
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2, FALSE, FALSE, TRUE));
+ emitcode ("mov", "b,%s", aopGet (AOP (result), 3, FALSE, FALSE, TRUE));
+ }
+ _endLazyDPSEvaluation ();
+ }
+ /* so dptr know contains the address */
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE, TRUE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
- _startLazyDPSEvaluation();
- while (size--) {
- char *l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
- MOVA(l);
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset++, FALSE, FALSE, TRUE);
+ MOVA (l);
- genSetDPTR(0);
- _flushLazyDPS();
+ genSetDPTR (0);
+ _flushLazyDPS ();
- emitcode("lcall","__gptrput");
- if (size)
- emitcode("inc","dptr");
- }
- _endLazyDPSEvaluation();
+ emitcode ("lcall", "__gptrput");
+ if (size)
+ emitcode ("inc", "dptr");
+ }
+ _endLazyDPSEvaluation ();
}
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
-static void genPointerSet (iCode *ic)
+static void
+genPointerSet (iCode * ic)
{
- operand *right, *result ;
- sym_link *type, *etype;
- int p_type;
+ operand *right, *result;
+ sym_link *type, *etype;
+ int p_type;
- D(emitcode(";", "genPointerSet "););
+ D (emitcode (";", "genPointerSet ");
+ );
- right = IC_RIGHT(ic);
- result = IC_RESULT(ic) ;
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(result);
- etype = getSpec(type);
- /* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next)) {
- p_type = DCL_TYPE(type);
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (result);
+ etype = getSpec (type);
+ /* if left is of type of pointer then it is simple */
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ {
+ p_type = DCL_TYPE (type);
}
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
}
- /* now that we have the pointer type we assign
- the pointer values */
- switch (p_type) {
+ /* now that we have the pointer type we assign
+ the pointer values */
+ switch (p_type)
+ {
case POINTER:
case IPOINTER:
- genNearPointerSet (right,result,ic);
- break;
+ genNearPointerSet (right, result, ic);
+ break;
case PPOINTER:
- genPagedPointerSet (right,result,ic);
- break;
+ genPagedPointerSet (right, result, ic);
+ break;
case FPOINTER:
- genFarPointerSet (right,result,ic);
- break;
+ genFarPointerSet (right, result, ic);
+ break;
case GPOINTER:
- genGenPointerSet (right,result,ic);
- break;
+ genGenPointerSet (right, result, ic);
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genIfx - generate code for Ifx statement */
/*-----------------------------------------------------------------*/
-static void genIfx (iCode *ic, iCode *popIc)
+static void
+genIfx (iCode * ic, iCode * popIc)
{
- operand *cond = IC_COND(ic);
- int isbit =0;
+ operand *cond = IC_COND (ic);
+ int isbit = 0;
- D(emitcode(";", "genIfx "););
+ D (emitcode (";", "genIfx ");
+ );
- aopOp(cond,ic,FALSE, FALSE);
+ aopOp (cond, ic, FALSE, FALSE);
- /* get the value into acc */
- if (AOP_TYPE(cond) != AOP_CRY)
- toBoolean(cond);
- else
- isbit = 1;
- /* 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);
+ /* get the value into acc */
+ if (AOP_TYPE (cond) != AOP_CRY)
+ toBoolean (cond);
+ else
+ isbit = 1;
+ /* 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");
+ genIfxJump (ic, "a");
- ic->generated = 1;
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAddrOf - generates code for address of */
/*-----------------------------------------------------------------*/
-static void genAddrOf (iCode *ic)
-{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
- int size, offset ;
-
- D(emitcode(";", "genAddrOf "););
-
- aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
-
- /* if the operand is on the stack then we
- need to get the stack offset of this
- variable */
- if (sym->onStack) {
- /* if it has an offset then we need to compute
- it */
- if (sym->stack) {
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",((char) sym->stack & 0xff));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- } else {
- /* we can just move _bp */
- 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;
- while (size--)
- {
- /* Yuck! */
- if (options.stack10bit && offset == 2)
- {
- aopPut(AOP(IC_RESULT(ic)),"#0x40", offset++);
- }
- else
- {
- aopPut(AOP(IC_RESULT(ic)),zero,offset++);
- }
- }
-
- goto release;
- }
-
- /* object not on stack then we need the name */
- size = AOP_SIZE(IC_RESULT(ic));
- offset = 0;
-
- while (size--) {
- char s[SDCC_NAME_MAX];
- if (offset)
- sprintf(s,"#(%s >> %d)",
- sym->rname,
- offset*8);
- else
- sprintf(s,"#%s",sym->rname);
- aopPut(AOP(IC_RESULT(ic)),s,offset++);
+static void
+genAddrOf (iCode * ic)
+{
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+ int size, offset;
+
+ D (emitcode (";", "genAddrOf ");
+ );
+
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+
+ /* if the operand is on the stack then we
+ need to get the stack offset of this
+ variable */
+ if (sym->onStack)
+ {
+ /* if it has an offset then we need to compute
+ it */
+ if (sym->stack)
+ {
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ }
+ else
+ {
+ /* we can just move _bp */
+ 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;
+ while (size--)
+ {
+ /* Yuck! */
+ if (options.stack10bit && offset == 2)
+ {
+ aopPut (AOP (IC_RESULT (ic)), "#0x40", offset++);
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), zero, offset++);
+ }
+ }
+
+ goto release;
+ }
+
+ /* object not on stack then we need the name */
+ size = AOP_SIZE (IC_RESULT (ic));
+ offset = 0;
+
+ while (size--)
+ {
+ char s[SDCC_NAME_MAX];
+ if (offset)
+ sprintf (s, "#(%s >> %d)",
+ sym->rname,
+ offset * 8);
+ else
+ sprintf (s, "#%s", sym->rname);
+ aopPut (AOP (IC_RESULT (ic)), s, offset++);
}
release:
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarFarAssign - assignment when both are in far space */
/*-----------------------------------------------------------------*/
-static void genFarFarAssign (operand *result, operand *right, iCode *ic)
+static void
+genFarFarAssign (operand * result, operand * right, iCode * ic)
{
- int size = AOP_SIZE(right);
- int offset = 0;
- char *l;
+ int size = AOP_SIZE (right);
+ int offset = 0;
+ char *l;
- if (size > 1)
+ if (size > 1)
{
- /* This is a net loss for size == 1, but a big gain
- * otherwise.
- */
- D(emitcode(";", "genFarFarAssign (improved)"););
+ /* This is a net loss for size == 1, but a big gain
+ * otherwise.
+ */
+ D (emitcode (";", "genFarFarAssign (improved)");
+ );
- aopOp(result,ic,TRUE, TRUE);
+ aopOp (result, ic, TRUE, TRUE);
- _startLazyDPSEvaluation();
- while (size--)
- {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE), offset);
- offset++;
- }
- _endLazyDPSEvaluation();
- freeAsmop(result,NULL,ic,FALSE);
- freeAsmop(right,NULL,ic,FALSE);
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE), offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ freeAsmop (result, NULL, ic, FALSE);
+ freeAsmop (right, NULL, ic, FALSE);
}
- else
+ else
{
- D(emitcode(";", "genFarFarAssign "););
+ D (emitcode (";", "genFarFarAssign ");
+ );
- /* first push the right side on to the stack */
- _startLazyDPSEvaluation();
- while (size--)
- {
- l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode ("push","acc");
- }
-
- freeAsmop(right,NULL,ic,FALSE);
- /* now assign DPTR to result */
- aopOp(result,ic,FALSE, FALSE);
- size = AOP_SIZE(result);
- while (size--)
- {
- emitcode ("pop","acc");
- aopPut(AOP(result),"a",--offset);
- }
- freeAsmop(result,NULL,ic,FALSE);
- _endLazyDPSEvaluation();
+ /* first push the right side on to the stack */
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset++, FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("push", "acc");
+ }
+
+ freeAsmop (right, NULL, ic, FALSE);
+ /* now assign DPTR to result */
+ aopOp (result, ic, FALSE, FALSE);
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ emitcode ("pop", "acc");
+ aopPut (AOP (result), "a", --offset);
+ }
+ freeAsmop (result, NULL, ic, FALSE);
+ _endLazyDPSEvaluation ();
}
}
/*-----------------------------------------------------------------*/
/* genAssign - generate code for assignment */
/*-----------------------------------------------------------------*/
-static void genAssign (iCode *ic)
+static void
+genAssign (iCode * ic)
{
- operand *result, *right;
- int size, offset ;
+ operand *result, *right;
+ int size, offset;
unsigned long lit = 0L;
- D(emitcode(";", "genAssign "););
+ D (emitcode (";", "genAssign ");
+ );
- result = IC_RESULT(ic);
- right = IC_RIGHT(ic) ;
-
- /* if they are the same */
- if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
-
- aopOp(right,ic,FALSE, FALSE);
-
- emitcode(";", "genAssign: resultIsFar = %s",
- isOperandInFarSpace(result) ?
- "TRUE" : "FALSE");
-
- /* special case both in far space */
- if ((AOP_TYPE(right) == AOP_DPTR ||
- AOP_TYPE(right) == AOP_DPTR2) &&
- /* IS_TRUE_SYMOP(result) && */
- isOperandInFarSpace(result))
- {
- genFarFarAssign (result,right,ic);
- return ;
- }
-
- aopOp(result,ic,TRUE, FALSE);
-
- /* if they are the same registers */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
-
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
-
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- if (((int) operandLitValue(right)))
- aopPut(AOP(result),one,0);
- else
- aopPut(AOP(result),zero,0);
- goto release;
- }
-
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- aopPut(AOP(result),"c",0);
- goto release ;
- }
-
- /* we need to or */
- toBoolean(right);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- /* bit variables done */
- /* general case */
- size = AOP_SIZE(result);
- offset = 0 ;
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- if((size > 1) &&
- (AOP_TYPE(result) != AOP_REG) &&
- (AOP_TYPE(right) == AOP_LIT) &&
- !IS_FLOAT(operandType(right)))
- {
- D(emitcode(";", "Kevin's better literal load code"););
- _startLazyDPSEvaluation();
- while (size && ((unsigned int)(lit >> (offset*8)) != 0))
- {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE,TRUE),
- offset);
- offset++;
- size--;
- }
- /* And now fill the rest with zeros. */
- if (size)
- {
- emitcode("clr","a");
- }
- while (size--)
- {
- aopPut(AOP(result), "a", offset++);
- }
- _endLazyDPSEvaluation();
- }
- else
- {
- _startLazyDPSEvaluation();
- while (size--)
- {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
- offset);
- offset++;
- }
- _endLazyDPSEvaluation();
+ result = IC_RESULT (ic);
+ right = IC_RIGHT (ic);
+
+ /* if they are the same */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
+
+ aopOp (right, ic, FALSE, FALSE);
+
+ emitcode (";", "genAssign: resultIsFar = %s",
+ isOperandInFarSpace (result) ?
+ "TRUE" : "FALSE");
+
+ /* special case both in far space */
+ if ((AOP_TYPE (right) == AOP_DPTR ||
+ AOP_TYPE (right) == AOP_DPTR2) &&
+ /* IS_TRUE_SYMOP(result) && */
+ isOperandInFarSpace (result))
+ {
+ genFarFarAssign (result, right, ic);
+ return;
+ }
+
+ aopOp (result, ic, TRUE, FALSE);
+
+ /* if they are the same registers */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
+
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((int) operandLitValue (right)))
+ aopPut (AOP (result), one, 0);
+ else
+ aopPut (AOP (result), zero, 0);
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ aopPut (AOP (result), "c", 0);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ /* bit variables done */
+ /* general case */
+ size = AOP_SIZE (result);
+ offset = 0;
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ if ((size > 1) &&
+ (AOP_TYPE (result) != AOP_REG) &&
+ (AOP_TYPE (right) == AOP_LIT) &&
+ !IS_FLOAT (operandType (right)))
+ {
+ D (emitcode (";", "Kevin's better literal load code");
+ );
+ _startLazyDPSEvaluation ();
+ while (size && ((unsigned int) (lit >> (offset * 8)) != 0))
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE, TRUE),
+ offset);
+ offset++;
+ size--;
+ }
+ /* And now fill the rest with zeros. */
+ if (size)
+ {
+ emitcode ("clr", "a");
+ }
+ while (size--)
+ {
+ aopPut (AOP (result), "a", offset++);
+ }
+ _endLazyDPSEvaluation ();
+ }
+ else
+ {
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
}
release:
- freeAsmop (right,NULL,ic,FALSE);
- freeAsmop (result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, FALSE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genJumpTab - generates code for jump table */
/*-----------------------------------------------------------------*/
-static void genJumpTab (iCode *ic)
+static void
+genJumpTab (iCode * ic)
{
- symbol *jtab;
- char *l;
+ symbol *jtab;
+ char *l;
- D(emitcode(";", "genJumpTab "););
+ D (emitcode (";", "genJumpTab ");
+ );
- aopOp(IC_JTCOND(ic),ic,FALSE, FALSE);
- /* get the condition into accumulator */
- l = aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE,TRUE);
- MOVA(l);
- /* multiply by four! */
- emitcode("add","a,acc");
- emitcode("add","a,acc");
- freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
+ aopOp (IC_JTCOND (ic), ic, FALSE, FALSE);
+ /* get the condition into accumulator */
+ l = aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE, TRUE);
+ MOVA (l);
+ /* multiply by four! */
+ emitcode ("add", "a,acc");
+ emitcode ("add", "a,acc");
+ freeAsmop (IC_JTCOND (ic), NULL, ic, TRUE);
- jtab = newiTempLabel(NULL);
- emitcode("mov","dptr,#%05d$",jtab->key+100);
- emitcode("jmp","@a+dptr");
- emitcode("","%05d$:",jtab->key+100);
- /* now generate the jump labels */
- for (jtab = setFirstItem(IC_JTLABELS(ic)) ; jtab;
- jtab = setNextItem(IC_JTLABELS(ic)))
- emitcode("ljmp","%05d$",jtab->key+100);
+ jtab = newiTempLabel (NULL);
+ emitcode ("mov", "dptr,#%05d$", jtab->key + 100);
+ emitcode ("jmp", "@a+dptr");
+ emitcode ("", "%05d$:", jtab->key + 100);
+ /* now generate the jump labels */
+ for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
+ jtab = setNextItem (IC_JTLABELS (ic)))
+ emitcode ("ljmp", "%05d$", jtab->key + 100);
}
/*-----------------------------------------------------------------*/
/* genCast - gen code for casting */
/*-----------------------------------------------------------------*/
-static void genCast (iCode *ic)
+static void
+genCast (iCode * ic)
{
- operand *result = IC_RESULT(ic);
- sym_link *ctype = operandType(IC_LEFT(ic));
- sym_link *rtype = operandType(IC_RIGHT(ic));
- operand *right = IC_RIGHT(ic);
- int size, offset ;
-
- D(emitcode(";", "genCast "););
-
- /* if they are equivalent then do nothing */
- if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
-
- aopOp(right,ic,FALSE, FALSE) ;
- aopOp(result,ic,FALSE, AOP_TYPE(right) == AOP_DPTR);
+ operand *result = IC_RESULT (ic);
+ sym_link *ctype = operandType (IC_LEFT (ic));
+ sym_link *rtype = operandType (IC_RIGHT (ic));
+ operand *right = IC_RIGHT (ic);
+ int size, offset;
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- if (((int) operandLitValue(right)))
- aopPut(AOP(result),one,0);
- else
- aopPut(AOP(result),zero,0);
+ D (emitcode (";", "genCast ");
+ );
- goto release;
- }
-
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- aopPut(AOP(result),"c",0);
- goto release ;
- }
+ /* if they are equivalent then do nothing */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
- /* we need to or */
- toBoolean(right);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
+ aopOp (right, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, AOP_TYPE (right) == AOP_DPTR);
- /* if they are the same size : or less */
- if (AOP_SIZE(result) <= AOP_SIZE(right)) {
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((int) operandLitValue (right)))
+ aopPut (AOP (result), one, 0);
+ else
+ aopPut (AOP (result), zero, 0);
+
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ aopPut (AOP (result), "c", 0);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ /* if they are the same size : or less */
+ if (AOP_SIZE (result) <= AOP_SIZE (right))
+ {
- /* if they are in the same place */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
+ /* if they are in the same place */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
- /* if they in different places then copy */
- size = AOP_SIZE(result);
- offset = 0 ;
- _startLazyDPSEvaluation();
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
- offset);
- offset++;
- }
- _endLazyDPSEvaluation();
- goto release;
+ /* if they in different places then copy */
+ size = AOP_SIZE (result);
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ goto release;
}
- /* if the result is of type pointer */
- if (IS_PTR(ctype)) {
+ /* if the result is of type pointer */
+ if (IS_PTR (ctype))
+ {
- int p_type;
- sym_link *type = operandType(right);
+ int p_type;
+ sym_link *type = operandType (right);
- /* pointer to generic pointer */
- if (IS_GENPTR(ctype)) {
- char *l = zero;
+ /* pointer to generic pointer */
+ if (IS_GENPTR (ctype))
+ {
+ char *l = zero;
- if (IS_PTR(type))
- {
- p_type = DCL_TYPE(type);
- }
- else
- {
+ if (IS_PTR (type))
+ {
+ p_type = DCL_TYPE (type);
+ }
+ else
+ {
#if OLD_CAST_BEHAVIOR
- /* KV: we are converting a non-pointer type to
- * a generic pointer. This (ifdef'd out) code
- * says that the resulting generic pointer
- * should have the same class as the storage
- * location of the non-pointer variable.
- *
- * For example, converting an int (which happens
- * to be stored in DATA space) to a pointer results
- * in a DATA generic pointer; if the original int
- * in XDATA space, so will be the resulting pointer.
- *
- * I don't like that behavior, and thus this change:
- * all such conversions will be forced to XDATA and
- * throw a warning. If you want some non-XDATA
- * type, or you want to suppress the warning, you
- * must go through an intermediate cast, like so:
- *
- * char _generic *gp = (char _xdata *)(intVar);
- */
- sym_link *etype = getSpec(type);
-
- /* we have to go by the storage class */
- if (SPEC_OCLS(etype) != generic)
- {
- p_type = PTR_TYPE(SPEC_OCLS(etype));
- }
- else
+ /* KV: we are converting a non-pointer type to
+ * a generic pointer. This (ifdef'd out) code
+ * says that the resulting generic pointer
+ * should have the same class as the storage
+ * location of the non-pointer variable.
+ *
+ * For example, converting an int (which happens
+ * to be stored in DATA space) to a pointer results
+ * in a DATA generic pointer; if the original int
+ * in XDATA space, so will be the resulting pointer.
+ *
+ * I don't like that behavior, and thus this change:
+ * all such conversions will be forced to XDATA and
+ * throw a warning. If you want some non-XDATA
+ * type, or you want to suppress the warning, you
+ * must go through an intermediate cast, like so:
+ *
+ * char _generic *gp = (char _xdata *)(intVar);
+ */
+ sym_link *etype = getSpec (type);
+
+ /* we have to go by the storage class */
+ if (SPEC_OCLS (etype) != generic)
+ {
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
+ }
+ else
#endif
+ {
+ /* Converting unknown class (i.e. register variable)
+ * to generic pointer. This is not good, but
+ * we'll make a guess (and throw a warning).
+ */
+ p_type = FPOINTER;
+ werror (W_INT_TO_GEN_PTR_CAST);
+ }
+ }
+
+ /* the first two bytes are known */
+ size = GPTRSIZE - 1;
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+
+ /* the last byte depending on type */
+ switch (p_type)
+ {
+ case IPOINTER:
+ case POINTER:
+ l = zero;
+ break;
+ case FPOINTER:
+ l = one;
+ break;
+ case CPOINTER:
+ l = "#0x02";
+ break;
+ case PPOINTER:
+ l = "#0x03";
+ break;
+
+ default:
+ /* this should never happen */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got unknown pointer type");
+ exit (1);
+ }
+ aopPut (AOP (result), l, GPTRSIZE - 1);
+ goto release;
+ }
+
+ /* just copy the pointers */
+ size = AOP_SIZE (result);
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ _endLazyDPSEvaluation ();
+ goto release;
+ }
+
+ /* so we now know that the size of destination is greater
+ than the size of the source */
+ /* we move to result for the size of source */
+ size = AOP_SIZE (right);
+ offset = 0;
+ _startLazyDPSEvaluation ();
+ while (size--)
{
- /* Converting unknown class (i.e. register variable)
- * to generic pointer. This is not good, but
- * we'll make a guess (and throw a warning).
- */
- p_type = FPOINTER;
- werror(W_INT_TO_GEN_PTR_CAST);
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE, FALSE),
+ offset);
+ offset++;
}
- }
+ _endLazyDPSEvaluation ();
- /* the first two bytes are known */
- size = GPTRSIZE - 1;
- offset = 0 ;
- _startLazyDPSEvaluation();
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
- offset);
- offset++;
- }
- _endLazyDPSEvaluation();
-
- /* the last byte depending on type */
- switch (p_type) {
- case IPOINTER:
- case POINTER:
- l = zero;
- break;
- case FPOINTER:
- l = one;
- break;
- case CPOINTER:
- l = "#0x02";
- break;
- case PPOINTER:
- l = "#0x03";
- break;
-
- default:
- /* this should never happen */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got unknown pointer type");
- exit(1);
- }
- aopPut(AOP(result),l, GPTRSIZE - 1);
- goto release ;
- }
+ /* now depending on the sign of the source && destination */
+ size = AOP_SIZE (result) - AOP_SIZE (right);
+ /* if unsigned or not an integral type */
+ /* also, if the source is a bit, we don't need to sign extend, because
+ * it can't possibly have set the sign bit.
+ */
+ if (SPEC_USIGN (rtype) || !IS_SPEC (rtype) || AOP_TYPE (right) == AOP_CRY)
+ {
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
+ }
+ else
+ {
+ /* we need to extend the sign :{ */
+ char *l = aopGet (AOP (right), AOP_SIZE (right) - 1,
+ FALSE, FALSE, TRUE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
+ }
- /* just copy the pointers */
- size = AOP_SIZE(result);
- offset = 0 ;
- _startLazyDPSEvaluation();
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
- offset);
- offset++;
- }
- _endLazyDPSEvaluation();
- goto release ;
- }
-
- /* so we now know that the size of destination is greater
- than the size of the source */
- /* we move to result for the size of source */
- size = AOP_SIZE(right);
- offset = 0 ;
- _startLazyDPSEvaluation();
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
- offset);
- offset++;
- }
- _endLazyDPSEvaluation();
-
- /* now depending on the sign of the source && destination */
- size = AOP_SIZE(result) - AOP_SIZE(right);
- /* if unsigned or not an integral type */
- /* also, if the source is a bit, we don't need to sign extend, because
- * it can't possibly have set the sign bit.
- */
- if (SPEC_USIGN(rtype) || !IS_SPEC(rtype) || AOP_TYPE(right) == AOP_CRY)
- {
- while (size--)
- {
- aopPut(AOP(result),zero,offset++);
- }
- }
- else
- {
- /* we need to extend the sign :{ */
- char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,
- FALSE,FALSE,TRUE);
- MOVA(l);
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- while (size--)
- aopPut(AOP(result),"a",offset++);
- }
-
- /* we are done hurray !!!! */
+ /* we are done hurray !!!! */
release:
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDjnz - generate decrement & jump if not zero instrucion */
/*-----------------------------------------------------------------*/
-static int genDjnz (iCode *ic, iCode *ifx)
+static int
+genDjnz (iCode * ic, iCode * ifx)
{
- symbol *lbl, *lbl1;
- if (!ifx)
- return 0;
+ symbol *lbl, *lbl1;
+ if (!ifx)
+ return 0;
- /* if the if condition has a false label
- then we cannot save */
- if (IC_FALSE(ifx))
- return 0;
+ /* if the if condition has a false label
+ then we cannot save */
+ if (IC_FALSE (ifx))
+ return 0;
- /* if the minus is not of the form
- a = a - 1 */
- if (!isOperandEqual(IC_RESULT(ic),IC_LEFT(ic)) ||
- !IS_OP_LITERAL(IC_RIGHT(ic)))
- return 0;
+ /* if the minus is not of the form
+ a = a - 1 */
+ if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
+ !IS_OP_LITERAL (IC_RIGHT (ic)))
+ return 0;
- if (operandLitValue(IC_RIGHT(ic)) != 1)
- return 0;
+ if (operandLitValue (IC_RIGHT (ic)) != 1)
+ return 0;
- /* if the size of this greater than one then no
- saving */
- if (getSize(operandType(IC_RESULT(ic))) > 1)
- return 0;
+ /* if the size of this greater than one then no
+ saving */
+ if (getSize (operandType (IC_RESULT (ic))) > 1)
+ return 0;
- /* otherwise we can save BIG */
- lbl = newiTempLabel(NULL);
- lbl1= newiTempLabel(NULL);
+ /* otherwise we can save BIG */
+ lbl = newiTempLabel (NULL);
+ lbl1 = newiTempLabel (NULL);
- aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
- if (IS_AOP_PREG(IC_RESULT(ic))) {
- emitcode("dec","%s",
- aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
- emitcode("mov","a,%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
- emitcode("jnz","%05d$",lbl->key+100);
- } else {
- emitcode ("djnz","%s,%05d$",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE),
- lbl->key+100);
+ if (IS_AOP_PREG (IC_RESULT (ic)))
+ {
+ emitcode ("dec", "%s",
+ aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE, FALSE));
+ emitcode ("mov", "a,%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE, FALSE));
+ emitcode ("jnz", "%05d$", lbl->key + 100);
+ }
+ else
+ {
+ emitcode ("djnz", "%s,%05d$", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE, FALSE),
+ lbl->key + 100);
}
- emitcode ("sjmp","%05d$",lbl1->key+100);
- emitcode ("","%05d$:",lbl->key+100);
- emitcode ("ljmp","%05d$",IC_TRUE(ifx)->key+100);
- emitcode ("","%05d$:",lbl1->key+100);
+ emitcode ("sjmp", "%05d$", lbl1->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
+ emitcode ("", "%05d$:", lbl1->key + 100);
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
- ifx->generated = 1;
- return 1;
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ ifx->generated = 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* genReceive - generate code for a receive iCode */
/*-----------------------------------------------------------------*/
-static void genReceive (iCode *ic)
+static void
+genReceive (iCode * ic)
{
- D(emitcode(";", "genReceive "););
+ D (emitcode (";", "genReceive ");
+ );
- if (isOperandInFarSpace(IC_RESULT(ic)) &&
- ( OP_SYMBOL(IC_RESULT(ic))->isspilt ||
- IS_TRUE_SYMOP(IC_RESULT(ic))) ) {
- int size = getSize(operandType(IC_RESULT(ic)));
- int offset = fReturnSize_390 - size;
- while (size--) {
- emitcode ("push","%s", (strcmp(fReturn[fReturnSize_390 - offset - 1],"a") ?
- fReturn[fReturnSize_390 - 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++);
- }
+ if (isOperandInFarSpace (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
+ IS_TRUE_SYMOP (IC_RESULT (ic))))
+ {
+ int size = getSize (operandType (IC_RESULT (ic)));
+ int offset = fReturnSize_390 - size;
+ while (size--)
+ {
+ emitcode ("push", "%s", (strcmp (fReturn[fReturnSize_390 - offset - 1], "a") ?
+ fReturn[fReturnSize_390 - 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
+ {
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+ _G.accInUse--;
+ assignResultValue (IC_RESULT (ic));
}
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* gen390Code - generate code for Dallas 390 based controllers */
/*-----------------------------------------------------------------*/
-void gen390Code (iCode *lic)
+void
+gen390Code (iCode * lic)
{
- iCode *ic;
- int cln = 0;
+ iCode *ic;
+ int cln = 0;
- lineHead = lineCurr = NULL;
+ lineHead = lineCurr = NULL;
#if 0
- //REMOVE ME!!!
- /* print the allocation information */
- if (allocInfo)
- printAllocInfo( currFunc, codeOutFile);
+ //REMOVE ME!!!
+ /* print the allocation information */
+ if (allocInfo)
+ printAllocInfo (currFunc, codeOutFile);
#endif
- /* if debug information required */
- if (options.debug && currFunc) {
- //jwk if (currFunc) {
- cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
- _G.debugLine = 1;
- if (IS_STATIC(currFunc->etype))
- emitcode("","F%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","G$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
- /* stack pointer name */
- if (options.useXstack)
- spname = "_spx";
- else
- spname = "sp";
-
-
- for (ic = lic ; ic ; ic = ic->next ) {
-
- if ( cln != ic->lineno ) {
- if ( options.debug ) {
- _G.debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),ic->lineno,
- ic->level,ic->block);
- _G.debugLine = 0;
- }
- emitcode(";","%s %d",ic->filename,ic->lineno);
- cln = ic->lineno ;
- }
- /* if the result is marked as
- spilt and rematerializable or code for
- this has already been generated then
- do nothing */
- if (resultRemat(ic) || ic->generated )
- continue ;
-
- /* depending on the operation */
- switch (ic->op) {
- case '!' :
- genNot(ic);
- break;
-
- case '~' :
- genCpl(ic);
- break;
-
- case UNARYMINUS:
- genUminus (ic);
- break;
-
- case IPUSH:
- genIpush (ic);
- break;
-
- case IPOP:
- /* IPOP happens only when trying to restore a
- spilt live range, if there is an ifx statement
- following this pop then the if statement might
- be using some of the registers being popped which
- would destory the contents of the register so
- we need to check for this condition and handle it */
- if (ic->next &&
- ic->next->op == IFX &&
- regsInCommon(IC_LEFT(ic),IC_COND(ic->next)))
- genIfx (ic->next,ic);
+ /* if debug information required */
+ if (options.debug && currFunc)
+ {
+ //jwk if (currFunc) {
+ cdbSymbol (currFunc, cdbFile, FALSE, TRUE);
+ _G.debugLine = 1;
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
else
- genIpop (ic);
- break;
-
- case CALL:
- genCall (ic);
- break;
-
- case PCALL:
- genPcall (ic);
- break;
-
- case FUNCTION:
- genFunction (ic);
- break;
-
- case ENDFUNCTION:
- genEndFunction (ic);
- break;
-
- case RETURN:
- genRet (ic);
- break;
-
- case LABEL:
- genLabel (ic);
- break;
-
- case GOTO:
- genGoto (ic);
- break;
-
- case '+' :
- genPlus (ic) ;
- break;
-
- case '-' :
- if ( ! genDjnz (ic,ifxForOp(IC_RESULT(ic),ic)))
- genMinus (ic);
- break;
-
- case '*' :
- genMult (ic);
- break;
-
- case '/' :
- genDiv (ic) ;
- break;
-
- case '%' :
- genMod (ic);
- break;
-
- case '>' :
- genCmpGt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case '<' :
- genCmpLt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case LE_OP:
- case GE_OP:
- case NE_OP:
+ emitcode ("", "G$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
+ /* stack pointer name */
+ if (options.useXstack)
+ spname = "_spx";
+ else
+ spname = "sp";
- /* note these two are xlated by algebraic equivalence
- during parsing SDCC.y */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got '>=' or '<=' shouldn't have come here");
- break;
- case EQ_OP:
- genCmpEq (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ for (ic = lic; ic; ic = ic->next)
+ {
- case AND_OP:
- genAndOp (ic);
- break;
+ if (cln != ic->lineno)
+ {
+ if (options.debug)
+ {
+ _G.debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), ic->lineno,
+ ic->level, ic->block);
+ _G.debugLine = 0;
+ }
+ emitcode (";", "%s %d", ic->filename, ic->lineno);
+ cln = ic->lineno;
+ }
+ /* if the result is marked as
+ spilt and rematerializable or code for
+ this has already been generated then
+ do nothing */
+ if (resultRemat (ic) || ic->generated)
+ continue;
+
+ /* depending on the operation */
+ switch (ic->op)
+ {
+ case '!':
+ genNot (ic);
+ break;
+
+ case '~':
+ genCpl (ic);
+ break;
+
+ case UNARYMINUS:
+ genUminus (ic);
+ break;
+
+ case IPUSH:
+ genIpush (ic);
+ break;
+
+ case IPOP:
+ /* IPOP happens only when trying to restore a
+ spilt live range, if there is an ifx statement
+ following this pop then the if statement might
+ be using some of the registers being popped which
+ would destory the contents of the register so
+ we need to check for this condition and handle it */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
+ genIfx (ic->next, ic);
+ else
+ genIpop (ic);
+ break;
+
+ case CALL:
+ genCall (ic);
+ break;
+
+ case PCALL:
+ genPcall (ic);
+ break;
+
+ case FUNCTION:
+ genFunction (ic);
+ break;
+
+ case ENDFUNCTION:
+ genEndFunction (ic);
+ break;
+
+ case RETURN:
+ genRet (ic);
+ break;
+
+ case LABEL:
+ genLabel (ic);
+ break;
+
+ case GOTO:
+ genGoto (ic);
+ break;
+
+ case '+':
+ genPlus (ic);
+ break;
+
+ case '-':
+ if (!genDjnz (ic, ifxForOp (IC_RESULT (ic), ic)))
+ genMinus (ic);
+ break;
+
+ case '*':
+ genMult (ic);
+ break;
+
+ case '/':
+ genDiv (ic);
+ break;
+
+ case '%':
+ genMod (ic);
+ break;
+
+ case '>':
+ genCmpGt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '<':
+ genCmpLt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case LE_OP:
+ case GE_OP:
+ case NE_OP:
+
+ /* note these two are xlated by algebraic equivalence
+ during parsing SDCC.y */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got '>=' or '<=' shouldn't have come here");
+ break;
+
+ case EQ_OP:
+ genCmpEq (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case AND_OP:
+ genAndOp (ic);
+ break;
+
+ case OR_OP:
+ genOrOp (ic);
+ break;
+
+ case '^':
+ genXor (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '|':
+ genOr (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case BITWISEAND:
+ genAnd (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case INLINEASM:
+ genInline (ic);
+ break;
- case OR_OP:
- genOrOp (ic);
- break;
+ case RRC:
+ genRRC (ic);
+ break;
- case '^' :
- genXor (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ case RLC:
+ genRLC (ic);
+ break;
- case '|' :
- genOr (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ case GETHBIT:
+ genGetHbit (ic);
+ break;
- case BITWISEAND:
- genAnd (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ case LEFT_OP:
+ genLeftShift (ic);
+ break;
- case INLINEASM:
- genInline (ic);
- break;
+ case RIGHT_OP:
+ genRightShift (ic);
+ break;
- case RRC:
- genRRC (ic);
- break;
+ case GET_VALUE_AT_ADDRESS:
+ genPointerGet (ic);
+ break;
- case RLC:
- genRLC (ic);
- break;
+ case '=':
+ if (POINTER_SET (ic))
+ genPointerSet (ic);
+ else
+ genAssign (ic);
+ break;
- case GETHBIT:
- genGetHbit (ic);
- break;
+ case IFX:
+ genIfx (ic, NULL);
+ break;
- case LEFT_OP:
- genLeftShift (ic);
- break;
+ case ADDRESS_OF:
+ genAddrOf (ic);
+ break;
- case RIGHT_OP:
- genRightShift (ic);
- break;
+ case JUMPTABLE:
+ genJumpTab (ic);
+ break;
- case GET_VALUE_AT_ADDRESS:
- genPointerGet(ic);
- break;
-
- case '=' :
- if (POINTER_SET(ic))
- genPointerSet(ic);
- else
- genAssign(ic);
- break;
-
- case IFX:
- genIfx (ic,NULL);
- break;
-
- case ADDRESS_OF:
- genAddrOf (ic);
- break;
+ case CAST:
+ genCast (ic);
+ break;
- case JUMPTABLE:
- genJumpTab (ic);
- break;
-
- case CAST:
- genCast (ic);
- break;
-
- case RECEIVE:
- genReceive(ic);
- break;
+ case RECEIVE:
+ genReceive (ic);
+ break;
- case SEND:
- addSet(&_G.sendSet,ic);
- break;
+ case SEND:
+ addSet (&_G.sendSet, ic);
+ break;
- default :
- ic = ic;
- /* piCode(ic,stdout); */
+ default:
+ ic = ic;
+ /* piCode(ic,stdout); */
- }
+ }
}
- /* now we are ready to call the
- peep hole optimizer */
- if (!options.nopeep)
- peepHole (&lineHead);
+ /* now we are ready to call the
+ peep hole optimizer */
+ if (!options.nopeep)
+ peepHole (&lineHead);
- /* now do the actual printing */
- printLine (lineHead,codeOutFile);
- return;
+ /* now do the actual printing */
+ printLine (lineHead, codeOutFile);
+ return;
}
#ifndef SDCCGEN51_H
#define SDCCGEN51_H
-enum {
+enum
+ {
AOP_LIT = 1,
- AOP_REG, AOP_DIR,
- AOP_DPTR, AOP_DPTR2, AOP_R0,AOP_R1,
- AOP_STK ,AOP_IMMD, AOP_STR,
- AOP_CRY, AOP_ACC };
+ AOP_REG, AOP_DIR,
+ AOP_DPTR, AOP_DPTR2, AOP_R0, AOP_R1,
+ AOP_STK, AOP_IMMD, AOP_STR,
+ AOP_CRY, AOP_ACC
+ };
/* type asmop : a homogenised type for
all the different spaces an operand can be
in */
-typedef struct asmop {
-
- short type ; /* can have values
- AOP_LIT - operand is a literal value
- AOP_REG - is in registers
- AOP_DIR - direct just a name
- AOP_DPTR - dptr contains address of operand
- AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
- AOP_R0/R1 - r0/r1 contains address of operand
- AOP_STK - should be pushed on stack this
- can happen only for the result
- AOP_IMMD - immediate value for eg. remateriazable
- AOP_CRY - carry contains the value of this
- AOP_STR - array of strings
- AOP_ACC - result is in the acc:b pair
- */
- short coff ; /* current offset */
- short size ; /* total size */
- unsigned code :1 ; /* is in Code space */
- unsigned paged:1 ; /* in paged memory */
- unsigned freed:1 ; /* already freed */
- union {
- value *aop_lit ; /* if literal */
- regs *aop_reg[4]; /* array of registers */
- char *aop_dir ; /* if direct */
- regs *aop_ptr ; /* either -> to r0 or r1 */
- char *aop_immd; /* if immediate others are implied */
- int aop_stk ; /* stack offset when AOP_STK */
- char *aop_str[4]; /* just a string array containing the location */
- } aopu;
-} asmop;
+typedef struct asmop
+ {
+
+ short type; /* can have values
+ AOP_LIT - operand is a literal value
+ AOP_REG - is in registers
+ AOP_DIR - direct just a name
+ AOP_DPTR - dptr contains address of operand
+ AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
+ AOP_R0/R1 - r0/r1 contains address of operand
+ AOP_STK - should be pushed on stack this
+ can happen only for the result
+ AOP_IMMD - immediate value for eg. remateriazable
+ AOP_CRY - carry contains the value of this
+ AOP_STR - array of strings
+ AOP_ACC - result is in the acc:b pair
+ */
+ short coff; /* current offset */
+ short size; /* total size */
+ unsigned code:1; /* is in Code space */
+ unsigned paged:1; /* in paged memory */
+ unsigned freed:1; /* already freed */
+ union
+ {
+ value *aop_lit; /* if literal */
+ regs *aop_reg[4]; /* array of registers */
+ char *aop_dir; /* if direct */
+ regs *aop_ptr; /* either -> to r0 or r1 */
+ char *aop_immd; /* if immediate others are implied */
+ int aop_stk; /* stack offset when AOP_STK */
+ char *aop_str[4]; /* just a string array containing the location */
+ }
+ aopu;
+ }
+asmop;
void gen390Code (iCode *);
};
/* list of key words used by msc51 */
-static char *_ds390_keywords[] = {
- "at",
- "bit",
- "code",
- "critical",
- "data",
- "far",
- "idata",
- "interrupt",
- "near",
- "pdata",
- "reentrant",
- "sfr",
- "sbit",
- "using",
- "xdata",
- "_data",
- "_code",
- "_generic",
- "_near",
- "_xdata",
- "_pdata",
- "_idata",
- NULL
+static char *_ds390_keywords[] =
+{
+ "at",
+ "bit",
+ "code",
+ "critical",
+ "data",
+ "far",
+ "idata",
+ "interrupt",
+ "near",
+ "pdata",
+ "reentrant",
+ "sfr",
+ "sbit",
+ "using",
+ "xdata",
+ "_data",
+ "_code",
+ "_generic",
+ "_near",
+ "_xdata",
+ "_pdata",
+ "_idata",
+ NULL
};
-void ds390_assignRegisters (eBBlock **ebbs, int count);
+void ds390_assignRegisters (eBBlock ** ebbs, int count);
-static int regParmFlg = 0; /* determine if we can register a parameter */
+static int regParmFlg = 0; /* determine if we can register a parameter */
-static void _ds390_init(void)
+static void
+_ds390_init (void)
{
- asm_addTree(&asm_asxxxx_mapping);
+ asm_addTree (&asm_asxxxx_mapping);
}
-static void _ds390_reset_regparm()
+static void
+_ds390_reset_regparm ()
{
- regParmFlg = 0;
+ regParmFlg = 0;
}
-static int _ds390_regparm( sym_link *l)
+static int
+_ds390_regparm (sym_link * l)
{
- /* for this processor it is simple
- can pass only the first parameter in a register */
- if (regParmFlg)
- return 0;
+ /* for this processor it is simple
+ can pass only the first parameter in a register */
+ if (regParmFlg)
+ return 0;
- regParmFlg = 1;
- return 1;
+ regParmFlg = 1;
+ return 1;
}
-static bool _ds390_parseOptions(int *pargc, char **argv, int *i)
+static bool
+_ds390_parseOptions (int *pargc, char **argv, int *i)
{
- /* TODO: allow port-specific command line options to specify
- * segment names here.
- */
- return FALSE;
+ /* TODO: allow port-specific command line options to specify
+ * segment names here.
+ */
+ return FALSE;
}
-static void _ds390_finaliseOptions(void)
+static void
+_ds390_finaliseOptions (void)
{
- /* Hack-o-matic: if we are using the flat24 model,
- * adjust pointer sizes.
- */
- if (options.model != MODEL_FLAT24)
+ /* Hack-o-matic: if we are using the flat24 model,
+ * adjust pointer sizes.
+ */
+ if (options.model != MODEL_FLAT24)
{
- fprintf(stderr,
- "*** warning: ds390 port only supports the flat24 model.\n");
- options.model = MODEL_FLAT24;
+ fprintf (stderr,
+ "*** warning: ds390 port only supports the flat24 model.\n");
+ options.model = MODEL_FLAT24;
}
- port->s.fptr_size = 3;
- port->s.gptr_size = 4;
- port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
+ port->s.fptr_size = 3;
+ port->s.gptr_size = 4;
+ port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
#if 1
- port->stack.call_overhead++; /* This acounts for the extra byte
- * of return addres on the stack.
- * but is ugly. There must be a
- * better way.
- */
+ port->stack.call_overhead++; /* This acounts for the extra byte
+ * of return addres on the stack.
+ * but is ugly. There must be a
+ * better way.
+ */
#endif
- if (options.model) {
- port->mem.default_local_map = xdata;
- port->mem.default_globl_map = xdata;
- } else {
- port->mem.default_local_map = data;
- port->mem.default_globl_map = data;
+ if (options.model)
+ {
+ port->mem.default_local_map = xdata;
+ port->mem.default_globl_map = xdata;
}
-
- if (options.stack10bit)
+ else
{
- if (options.model != MODEL_FLAT24)
- {
- fprintf(stderr,
- "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
- fprintf(stderr, "\t10 bit stack mode disabled.\n");
- options.stack10bit = 0;
- }
- else
- {
- /* Fixup the memory map for the stack; it is now in
- * far space and requires a FPOINTER to access it.
- */
- istack->fmap = 1;
- istack->ptrType = FPOINTER;
- }
+ port->mem.default_local_map = data;
+ port->mem.default_globl_map = data;
+ }
+
+ if (options.stack10bit)
+ {
+ if (options.model != MODEL_FLAT24)
+ {
+ fprintf (stderr,
+ "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
+ fprintf (stderr, "\t10 bit stack mode disabled.\n");
+ options.stack10bit = 0;
+ }
+ else
+ {
+ /* Fixup the memory map for the stack; it is now in
+ * far space and requires a FPOINTER to access it.
+ */
+ istack->fmap = 1;
+ istack->ptrType = FPOINTER;
+ }
}
}
-static void _ds390_setDefaultOptions(void)
+static void
+_ds390_setDefaultOptions (void)
{
}
-static const char *_ds390_getRegName(struct regs *reg)
+static const char *
+_ds390_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- return "err";
+ if (reg)
+ return reg->name;
+ return "err";
}
-static void _ds390_genAssemblerPreamble(FILE *of)
+static void
+_ds390_genAssemblerPreamble (FILE * of)
{
- if (options.model == MODEL_FLAT24)
- {
- fputs(".flat24 on\t\t; 24 bit flat addressing\n", of);
- fputs("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
- fputs("dps = 0x86\t\t; dps register unknown to assembler\n", of);
- fputs("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of);
- fputs("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of);
- fputs("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of);
- fputs("ap = 0x9C\t\t; ap register unknown to assembler\n", of);
- }
+ if (options.model == MODEL_FLAT24)
+ {
+ fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
+ fputs ("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
+ fputs ("dps = 0x86\t\t; dps register unknown to assembler\n", of);
+ fputs ("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of);
+ fputs ("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of);
+ fputs ("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of);
+ fputs ("ap = 0x9C\t\t; ap register unknown to assembler\n", of);
+ }
}
/* Generate interrupt vector table. */
-static int _ds390_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
+static int
+_ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
{
- int i;
-
- if (options.model != MODEL_FLAT24)
+ int i;
+
+ if (options.model != MODEL_FLAT24)
{
- /* Let the default code handle it. */
- return FALSE;
+ /* Let the default code handle it. */
+ return FALSE;
}
-
- fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
-
- /* now for the other interrupts */
- for (i = 0; i < maxInterrupts; i++)
+
+ fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
+
+ /* now for the other interrupts */
+ for (i = 0; i < maxInterrupts; i++)
{
- if (interrupts[i])
+ if (interrupts[i])
{
- fprintf(of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
+ fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
}
- else
+ else
{
- fprintf(of, "\treti\n\t.ds\t7\n");
+ fprintf (of, "\treti\n\t.ds\t7\n");
}
}
-
- return TRUE;
+
+ return TRUE;
}
/** $1 is always the basename.
$l is the list of extra options that should be there somewhere...
MUST be terminated with a NULL.
*/
-static const char *_linkCmd[] = {
- "aslink", "-nf", "$1", NULL
+static const char *_linkCmd[] =
+{
+ "aslink", "-nf", "$1", NULL
};
-static const char *_asmCmd[] = {
- "asx8051", "-plosgff", "$1.asm", NULL
+static const char *_asmCmd[] =
+{
+ "asx8051", "-plosgff", "$1.asm", NULL
};
/* Globals */
-PORT ds390_port = {
- "ds390",
- "DS80C390", /* Target name */
- {
- TRUE, /* Emit glue around main */
- MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
- MODEL_SMALL
- },
- {
- _asmCmd,
- "-plosgffc", /* Options with debug */
- "-plosgff", /* Options without debug */
- 0
- },
- {
- _linkCmd,
- NULL,
- ".rel"
- },
- {
- _defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 1, 2, 4, 1, 2, 3, 1, 4, 4
- },
- {
- "XSEG (XDATA)",
- "STACK (DATA)",
- "CSEG (CODE)",
- "DSEG (DATA)",
- "ISEG (DATA)",
- "XSEG (XDATA)",
- "BSEG (BIT)",
- "RSEG (DATA)",
- "GSINIT (CODE)",
- "OSEG (OVR,DATA)",
- "GSFINAL (CODE)",
- "HOME (CODE)",
- NULL,
- NULL,
- 1
- },
- {
- +1, 1, 4, 1, 1, 0
- },
- /* ds390 has an 8 bit mul */
- {
- 1, 0
- },
- "_",
- _ds390_init,
- _ds390_parseOptions,
- _ds390_finaliseOptions,
- _ds390_setDefaultOptions,
- ds390_assignRegisters,
- _ds390_getRegName ,
- _ds390_keywords,
- _ds390_genAssemblerPreamble,
- _ds390_genIVT ,
- _ds390_reset_regparm,
- _ds390_regparm,
+PORT ds390_port =
+{
+ "ds390",
+ "DS80C390", /* Target name */
+ {
+ TRUE, /* Emit glue around main */
+ MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
+ MODEL_SMALL
+ },
+ {
+ _asmCmd,
+ "-plosgffc", /* Options with debug */
+ "-plosgff", /* Options without debug */
+ 0
+ },
+ {
+ _linkCmd,
+ NULL,
+ ".rel"
+ },
+ {
+ _defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 1, 2, 4, 1, 2, 3, 1, 4, 4
+ },
+ {
+ "XSEG (XDATA)",
+ "STACK (DATA)",
+ "CSEG (CODE)",
+ "DSEG (DATA)",
+ "ISEG (DATA)",
+ "XSEG (XDATA)",
+ "BSEG (BIT)",
+ "RSEG (DATA)",
+ "GSINIT (CODE)",
+ "OSEG (OVR,DATA)",
+ "GSFINAL (CODE)",
+ "HOME (CODE)",
NULL,
- FALSE,
- 0, /* leave lt */
- 0, /* leave gt */
- 1, /* transform <= to ! > */
- 1, /* transform >= to ! < */
- 1, /* transform != to !(a == b) */
- 0, /* leave == */
- PORT_MAGIC
+ NULL,
+ 1
+ },
+ {
+ +1, 1, 4, 1, 1, 0
+ },
+ /* ds390 has an 8 bit mul */
+ {
+ 1, 0
+ },
+ "_",
+ _ds390_init,
+ _ds390_parseOptions,
+ _ds390_finaliseOptions,
+ _ds390_setDefaultOptions,
+ ds390_assignRegisters,
+ _ds390_getRegName,
+ _ds390_keywords,
+ _ds390_genAssemblerPreamble,
+ _ds390_genIVT,
+ _ds390_reset_regparm,
+ _ds390_regparm,
+ NULL,
+ FALSE,
+ 0, /* leave lt */
+ 0, /* leave gt */
+ 1, /* transform <= to ! > */
+ 1, /* transform >= to ! < */
+ 1, /* transform != to !(a == b) */
+ 0, /* leave == */
+ PORT_MAGIC
};
-
#ifndef MAIN_INCLUDE
#define MAIN_INCLUDE
-bool x_parseOptions(char **argv, int *pargc);
-void x_setDefaultOptions(void);
-void x_finaliseOptions(void);
+bool x_parseOptions (char **argv, int *pargc);
+void x_setDefaultOptions (void);
+void x_finaliseOptions (void);
#endif
/* some routines are non-processor specific & can be reused when */
/* targetting other processors. The decision for this will have */
/* to be made on a routine by routine basis */
-/* routines used to pack registers are most definitely not reusable*/
+/* routines used to pack registers are most definitely not reusable */
/* since the pack the registers depending strictly on the MCU */
/*-----------------------------------------------------------------*/
/* Global data */
-static struct {
+static struct
+ {
bitVect *spiltSet;
set *stackSpil;
bitVect *regAssigned;
short blockSpil;
int slocNum;
- bitVect *funcrUsed; /* registers used in a function */
+ bitVect *funcrUsed; /* registers used in a function */
int stackExtend;
int dataExtend;
-} _G;
+ }
+_G;
/* Shared with gen.c */
-int ds390_ptrRegReq; /* one byte pointer register required */
+int ds390_ptrRegReq; /* one byte pointer register required */
/* 8051 registers */
-regs regs390[] =
+regs regs390[] =
{
- { REG_GPR ,R2_IDX , REG_GPR , "r2", "ar2", "0", 2, 1 },
- { REG_GPR ,R3_IDX , REG_GPR , "r3", "ar3", "0", 3, 1 },
- { REG_GPR ,R4_IDX , REG_GPR , "r4", "ar4", "0", 4, 1 },
- { REG_GPR ,R5_IDX , REG_GPR , "r5", "ar5", "0", 5, 1 },
- { REG_GPR ,R6_IDX , REG_GPR , "r6", "ar6", "0", 6, 1 },
- { REG_GPR ,R7_IDX , REG_GPR , "r7", "ar7", "0", 7, 1 },
- { REG_PTR ,R0_IDX , REG_PTR , "r0" , "ar0", "0", 0, 1 },
- { REG_PTR ,R1_IDX , REG_PTR , "r1" , "ar1", "0", 1, 1 },
- { REG_GPR ,X8_IDX , REG_GPR , "x8", "x8" , "xreg", 0, 1 },
- { REG_GPR ,X9_IDX , REG_GPR , "x9", "x9" , "xreg", 1, 1 },
- { REG_GPR ,X10_IDX,REG_GPR , "x10", "x10", "xreg", 2, 1 },
- { REG_GPR ,X11_IDX,REG_GPR , "x11", "x11", "xreg", 3, 1 },
- { REG_GPR ,X12_IDX,REG_GPR , "x12", "x12", "xreg", 4, 1 },
- { REG_CND ,CND_IDX,REG_CND , "C" , "C" , "xreg", 0, 1 },
+ {REG_GPR, R2_IDX, REG_GPR, "r2", "ar2", "0", 2, 1},
+ {REG_GPR, R3_IDX, REG_GPR, "r3", "ar3", "0", 3, 1},
+ {REG_GPR, R4_IDX, REG_GPR, "r4", "ar4", "0", 4, 1},
+ {REG_GPR, R5_IDX, REG_GPR, "r5", "ar5", "0", 5, 1},
+ {REG_GPR, R6_IDX, REG_GPR, "r6", "ar6", "0", 6, 1},
+ {REG_GPR, R7_IDX, REG_GPR, "r7", "ar7", "0", 7, 1},
+ {REG_PTR, R0_IDX, REG_PTR, "r0", "ar0", "0", 0, 1},
+ {REG_PTR, R1_IDX, REG_PTR, "r1", "ar1", "0", 1, 1},
+ {REG_GPR, X8_IDX, REG_GPR, "x8", "x8", "xreg", 0, 1},
+ {REG_GPR, X9_IDX, REG_GPR, "x9", "x9", "xreg", 1, 1},
+ {REG_GPR, X10_IDX, REG_GPR, "x10", "x10", "xreg", 2, 1},
+ {REG_GPR, X11_IDX, REG_GPR, "x11", "x11", "xreg", 3, 1},
+ {REG_GPR, X12_IDX, REG_GPR, "x12", "x12", "xreg", 4, 1},
+ {REG_CND, CND_IDX, REG_CND, "C", "C", "xreg", 0, 1},
};
int ds390_nRegs = 13;
static void spillThis (symbol *);
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
-static regs *allocReg (short type)
+static regs *
+allocReg (short type)
{
- int i;
-
- for ( i = 0 ; i < ds390_nRegs ; i++ ) {
-
- /* if type is given as 0 then any
- free register will do */
- if (!type &&
- regs390[i].isFree ) {
- regs390[i].isFree = 0;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- return ®s390[i];
+ int i;
+
+ for (i = 0; i < ds390_nRegs; i++)
+ {
+
+ /* if type is given as 0 then any
+ free register will do */
+ if (!type &&
+ regs390[i].isFree)
+ {
+ regs390[i].isFree = 0;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ return ®s390[i];
}
- /* other wise look for specific type
- of register */
- if (regs390[i].isFree &&
- regs390[i].type == type) {
- regs390[i].isFree = 0;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- return ®s390[i];
+ /* other wise look for specific type
+ of register */
+ if (regs390[i].isFree &&
+ regs390[i].type == type)
+ {
+ regs390[i].isFree = 0;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ return ®s390[i];
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* ds390_regWithIdx - returns pointer to register wit index number */
/*-----------------------------------------------------------------*/
-regs *ds390_regWithIdx (int idx)
+regs *
+ds390_regWithIdx (int idx)
{
- int i ;
-
- for (i=0;i < ds390_nRegs;i++)
- if (regs390[i].rIdx == idx)
- return ®s390[i];
-
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "regWithIdx not found");
- exit(1);
+ int i;
+
+ for (i = 0; i < ds390_nRegs; i++)
+ if (regs390[i].rIdx == idx)
+ return ®s390[i];
+
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "regWithIdx not found");
+ exit (1);
}
/*-----------------------------------------------------------------*/
/* freeReg - frees a register */
/*-----------------------------------------------------------------*/
-static void freeReg (regs *reg)
+static void
+freeReg (regs * reg)
{
- reg->isFree = 1;
+ reg->isFree = 1;
}
/*-----------------------------------------------------------------*/
/* nFreeRegs - returns number of free registers */
/*-----------------------------------------------------------------*/
-static int nFreeRegs (int type)
+static int
+nFreeRegs (int type)
{
- int i;
- int nfr=0;
-
- for (i = 0 ; i < ds390_nRegs; i++ )
- if (regs390[i].isFree && regs390[i].type == type)
- nfr++;
- return nfr;
+ int i;
+ int nfr = 0;
+
+ for (i = 0; i < ds390_nRegs; i++)
+ if (regs390[i].isFree && regs390[i].type == type)
+ nfr++;
+ return nfr;
}
/*-----------------------------------------------------------------*/
/* nfreeRegsType - free registers with type */
/*-----------------------------------------------------------------*/
-static int nfreeRegsType (int type)
+static int
+nfreeRegsType (int type)
{
- int nfr ;
- if (type == REG_PTR) {
- if ((nfr = nFreeRegs(type)) == 0)
- return nFreeRegs(REG_GPR);
- }
-
- return nFreeRegs(type);
+ int nfr;
+ if (type == REG_PTR)
+ {
+ if ((nfr = nFreeRegs (type)) == 0)
+ return nFreeRegs (REG_GPR);
+ }
+
+ return nFreeRegs (type);
}
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
/*-----------------------------------------------------------------*/
-static bool allDefsOutOfRange (bitVect *defs,int fseq, int toseq)
+static bool
+allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
{
- int i ;
+ int i;
- if (!defs)
- return TRUE ;
+ if (!defs)
+ return TRUE;
- for ( i = 0 ;i < defs->size ; i++ ) {
- iCode *ic;
+ for (i = 0; i < defs->size; i++)
+ {
+ iCode *ic;
+
+ if (bitVectBitValue (defs, i) &&
+ (ic = hTabItemWithKey (iCodehTab, i)) &&
+ (ic->seq >= fseq && ic->seq <= toseq))
+
+ return FALSE;
- if (bitVectBitValue(defs,i) &&
- (ic = hTabItemWithKey(iCodehTab,i)) &&
- ( ic->seq >= fseq && ic->seq <= toseq))
-
- return FALSE;
-
}
-
- return TRUE;
+
+ return TRUE;
}
-
+
/*-----------------------------------------------------------------*/
/* computeSpillable - given a point find the spillable live ranges */
/*-----------------------------------------------------------------*/
-static bitVect *computeSpillable (iCode *ic)
+static bitVect *
+computeSpillable (iCode * ic)
{
- bitVect *spillable ;
-
- /* spillable live ranges are those that are live at this
- point . the following categories need to be subtracted
- from this set.
- a) - those that are already spilt
- b) - if being used by this one
- c) - defined by this one */
-
- spillable = bitVectCopy(ic->rlive);
- spillable =
- bitVectCplAnd(spillable,_G.spiltSet); /* those already spilt */
- spillable =
- bitVectCplAnd(spillable,ic->uses); /* used in this one */
- bitVectUnSetBit(spillable,ic->defKey);
- spillable = bitVectIntersect(spillable,_G.regAssigned);
- return spillable;
-
+ bitVect *spillable;
+
+ /* spillable live ranges are those that are live at this
+ point . the following categories need to be subtracted
+ from this set.
+ a) - those that are already spilt
+ b) - if being used by this one
+ c) - defined by this one */
+
+ spillable = bitVectCopy (ic->rlive);
+ spillable =
+ bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
+ spillable =
+ bitVectCplAnd (spillable, ic->uses); /* used in this one */
+ bitVectUnSetBit (spillable, ic->defKey);
+ spillable = bitVectIntersect (spillable, _G.regAssigned);
+ return spillable;
+
}
/*-----------------------------------------------------------------*/
/* noSpilLoc - return true if a variable has no spil location */
/*-----------------------------------------------------------------*/
-static int noSpilLoc (symbol *sym, eBBlock *ebp,iCode *ic)
+static int
+noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 0 : 1);
+ return (sym->usl.spillLoc ? 0 : 1);
}
/*-----------------------------------------------------------------*/
/* hasSpilLoc - will return 1 if the symbol has spil location */
/*-----------------------------------------------------------------*/
-static int hasSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 1 : 0);
+ return (sym->usl.spillLoc ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* directSpilLoc - will return 1 if the splilocation is in direct */
/*-----------------------------------------------------------------*/
-static int directSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- if ( sym->usl.spillLoc &&
- (IN_DIRSPACE(SPEC_OCLS(sym->usl.spillLoc->etype))))
- return 1;
- else
- return 0;
+ if (sym->usl.spillLoc &&
+ (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
+ return 1;
+ else
+ return 0;
}
/*-----------------------------------------------------------------*/
-/* hasSpilLocnoUptr - will return 1 if the symbol has spil location*/
+/* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
/* but is not used as a pointer */
/*-----------------------------------------------------------------*/
-static int hasSpilLocnoUptr (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
+ return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* rematable - will return 1 if the remat flag is set */
/*-----------------------------------------------------------------*/
-static int rematable (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+rematable (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return sym->remat;
+ return sym->remat;
}
/*-----------------------------------------------------------------*/
/* notUsedInBlock - not used in this block */
/*-----------------------------------------------------------------*/
-static int notUsedInBlock (symbol *sym, eBBlock *ebp, iCode *ic)
-{
- return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs) &&
- allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
+static int
+notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
+{
+ return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
+ allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
/* return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs)); */
}
/*-----------------------------------------------------------------*/
/* notUsedInRemaining - not used or defined in remain of the block */
/*-----------------------------------------------------------------*/
-static int notUsedInRemaining (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return ((usedInRemaining (operandFromSymbol(sym),ic) ? 0 : 1) &&
- allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
+ return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
+ allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
}
/*-----------------------------------------------------------------*/
/* allLRs - return true for all */
/*-----------------------------------------------------------------*/
-static int allLRs (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* liveRangesWith - applies function to a given set of live range */
/*-----------------------------------------------------------------*/
-static set *liveRangesWith (bitVect *lrs, int (func)(symbol *,eBBlock *, iCode *),
- eBBlock *ebp, iCode *ic)
+static set *
+liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
+ eBBlock * ebp, iCode * ic)
{
- set *rset = NULL;
- int i;
+ set *rset = NULL;
+ int i;
- if (!lrs || !lrs->size)
- return NULL;
+ if (!lrs || !lrs->size)
+ return NULL;
- for ( i = 1 ; i < lrs->size ; i++ ) {
- symbol *sym;
- if (!bitVectBitValue(lrs,i))
- continue ;
-
- /* if we don't find it in the live range
- hash table we are in serious trouble */
- if (!(sym = hTabItemWithKey(liveRanges,i))) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "liveRangesWith could not find liveRange");
- exit(1);
+ for (i = 1; i < lrs->size; i++)
+ {
+ symbol *sym;
+ if (!bitVectBitValue (lrs, i))
+ continue;
+
+ /* if we don't find it in the live range
+ hash table we are in serious trouble */
+ if (!(sym = hTabItemWithKey (liveRanges, i)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "liveRangesWith could not find liveRange");
+ exit (1);
}
-
- if (func(sym,ebp,ic) && bitVectBitValue(_G.regAssigned,sym->key))
- addSetHead(&rset,sym);
+
+ if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
+ addSetHead (&rset, sym);
}
- return rset;
+ return rset;
}
/*-----------------------------------------------------------------*/
/* leastUsedLR - given a set determines which is the least used */
/*-----------------------------------------------------------------*/
-static symbol *leastUsedLR (set *sset)
+static symbol *
+leastUsedLR (set * sset)
{
- symbol *sym = NULL, *lsym = NULL ;
-
- sym = lsym = setFirstItem(sset);
+ symbol *sym = NULL, *lsym = NULL;
- if (!lsym)
- return NULL;
+ sym = lsym = setFirstItem (sset);
+
+ if (!lsym)
+ return NULL;
+
+ for (; lsym; lsym = setNextItem (sset))
+ {
+
+ /* if usage is the same then prefer
+ the spill the smaller of the two */
+ if (lsym->used == sym->used)
+ if (getSize (lsym->type) < getSize (sym->type))
+ sym = lsym;
- for (; lsym; lsym = setNextItem(sset)) {
-
- /* if usage is the same then prefer
- the spill the smaller of the two */
- if ( lsym->used == sym->used )
- if (getSize(lsym->type) < getSize(sym->type))
- sym = lsym;
-
- /* if less usage */
- if (lsym->used < sym->used )
- sym = lsym;
-
- }
-
- setToNull((void **)&sset);
- sym->blockSpil = 0;
- return sym;
+ /* if less usage */
+ if (lsym->used < sym->used)
+ sym = lsym;
+
+ }
+
+ setToNull ((void **) &sset);
+ sym->blockSpil = 0;
+ return sym;
}
/*-----------------------------------------------------------------*/
/* noOverLap - will iterate through the list looking for over lap */
/*-----------------------------------------------------------------*/
-static int noOverLap (set *itmpStack, symbol *fsym)
+static int
+noOverLap (set * itmpStack, symbol * fsym)
{
- symbol *sym;
-
+ symbol *sym;
+
+
+ for (sym = setFirstItem (itmpStack); sym;
+ sym = setNextItem (itmpStack))
+ {
+ if (sym->liveTo > fsym->liveFrom)
+ return 0;
- for (sym = setFirstItem(itmpStack); sym;
- sym = setNextItem(itmpStack)) {
- if (sym->liveTo > fsym->liveFrom )
- return 0;
-
}
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* isFree - will return 1 if the a free spil location is found */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(isFree)
+static
+DEFSETFUNC (isFree)
{
- symbol *sym = item;
- V_ARG(symbol **,sloc);
- V_ARG(symbol *,fsym);
+ symbol *sym = item;
+ V_ARG (symbol **, sloc);
+ V_ARG (symbol *, fsym);
- /* if already found */
- if (*sloc)
- return 0;
+ /* if already found */
+ if (*sloc)
+ return 0;
- /* if it is free && and the itmp assigned to
- this does not have any overlapping live ranges
- with the one currently being assigned and
- the size can be accomodated */
- if (sym->isFree &&
- noOverLap(sym->usl.itmpStack,fsym) &&
- getSize(sym->type) >= getSize(fsym->type)) {
- *sloc = sym;
- return 1;
+ /* if it is free && and the itmp assigned to
+ this does not have any overlapping live ranges
+ with the one currently being assigned and
+ the size can be accomodated */
+ if (sym->isFree &&
+ noOverLap (sym->usl.itmpStack, fsym) &&
+ getSize (sym->type) >= getSize (fsym->type))
+ {
+ *sloc = sym;
+ return 1;
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* spillLRWithPtrReg :- will spil those live ranges which use PTR */
/*-----------------------------------------------------------------*/
-static void spillLRWithPtrReg (symbol *forSym)
+static void
+spillLRWithPtrReg (symbol * forSym)
{
- symbol *lrsym;
- regs *r0,*r1;
- int k;
-
- if (!_G.regAssigned ||
- bitVectIsZero(_G.regAssigned))
- return;
-
- r0 = ds390_regWithIdx(R0_IDX);
- r1 = ds390_regWithIdx(R1_IDX);
-
- /* for all live ranges */
- for (lrsym = hTabFirstItem(liveRanges,&k) ; lrsym ;
- lrsym = hTabNextItem(liveRanges,&k) ) {
- int j;
-
- /* if no registers assigned to it or
- spilt */
- /* if it does not overlap with this then
- not need to spill it */
-
- if (lrsym->isspilt || !lrsym->nRegs ||
- (lrsym->liveTo < forSym->liveFrom))
- continue ;
-
- /* go thru the registers : if it is either
- r0 or r1 then spil it */
- for (j = 0 ; j < lrsym->nRegs ; j++ )
- if (lrsym->regs[j] == r0 ||
- lrsym->regs[j] == r1 ) {
- spillThis (lrsym);
- break;
- }
+ symbol *lrsym;
+ regs *r0, *r1;
+ int k;
+
+ if (!_G.regAssigned ||
+ bitVectIsZero (_G.regAssigned))
+ return;
+
+ r0 = ds390_regWithIdx (R0_IDX);
+ r1 = ds390_regWithIdx (R1_IDX);
+
+ /* for all live ranges */
+ for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
+ lrsym = hTabNextItem (liveRanges, &k))
+ {
+ int j;
+
+ /* if no registers assigned to it or
+ spilt */
+ /* if it does not overlap with this then
+ not need to spill it */
+
+ if (lrsym->isspilt || !lrsym->nRegs ||
+ (lrsym->liveTo < forSym->liveFrom))
+ continue;
+
+ /* go thru the registers : if it is either
+ r0 or r1 then spil it */
+ for (j = 0; j < lrsym->nRegs; j++)
+ if (lrsym->regs[j] == r0 ||
+ lrsym->regs[j] == r1)
+ {
+ spillThis (lrsym);
+ break;
+ }
}
}
/*-----------------------------------------------------------------*/
/* createStackSpil - create a location on the stack to spil */
/*-----------------------------------------------------------------*/
-static symbol *createStackSpil (symbol *sym)
+static symbol *
+createStackSpil (symbol * sym)
{
- symbol *sloc= NULL;
- int useXstack, model, noOverlay;
-
- char slocBuffer[30];
-
- /* first go try and find a free one that is already
- existing on the stack */
- if (applyToSet(_G.stackSpil,isFree,&sloc, sym)) {
- /* found a free one : just update & return */
- sym->usl.spillLoc = sloc;
- sym->stackSpil= 1;
- sloc->isFree = 0;
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ symbol *sloc = NULL;
+ int useXstack, model, noOverlay;
+
+ char slocBuffer[30];
+
+ /* first go try and find a free one that is already
+ existing on the stack */
+ if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
+ {
+ /* found a free one : just update & return */
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+ sloc->isFree = 0;
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
- /* could not then have to create one , this is the hard part
- we need to allocate this on the stack : this is really a
- hack!! but cannot think of anything better at this time */
-
- if (sprintf(slocBuffer,"sloc%d",_G.slocNum++) >= sizeof(slocBuffer))
+ /* could not then have to create one , this is the hard part
+ we need to allocate this on the stack : this is really a
+ hack!! but cannot think of anything better at this time */
+
+ if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
{
- fprintf(stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
- __FILE__, __LINE__);
- exit(1);
+ fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
+ __FILE__, __LINE__);
+ exit (1);
}
- sloc = newiTemp(slocBuffer);
-
- /* set the type to the spilling symbol */
- sloc->type = copyLinkChain(sym->type);
- sloc->etype = getSpec(sloc->type);
- SPEC_SCLS(sloc->etype) = options.model ? S_XDATA : S_DATA;
- SPEC_EXTR(sloc->etype) = 0;
-
- /* we don't allow it to be allocated`
- onto the external stack since : so we
- temporarily turn it off ; we also
- turn off memory model to prevent
- the spil from going to the external storage
- and turn off overlaying
- */
-
- useXstack = options.useXstack;
- model = options.model;
- noOverlay = options.noOverlay;
- options.noOverlay = 1;
-
- /* options.model = options.useXstack = 0; */
-
- allocLocal(sloc);
-
- options.useXstack = useXstack;
- options.model = model;
- options.noOverlay = noOverlay;
- sloc->isref = 1; /* to prevent compiler warning */
-
- /* if it is on the stack then update the stack */
- if (IN_STACK(sloc->etype)) {
- currFunc->stack += getSize(sloc->type);
- _G.stackExtend += getSize(sloc->type);
- } else
- _G.dataExtend += getSize(sloc->type);
-
- /* add it to the _G.stackSpil set */
- addSetHead(&_G.stackSpil,sloc);
- sym->usl.spillLoc = sloc;
- sym->stackSpil = 1;
-
- /* add it to the set of itempStack set
- of the spill location */
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ sloc = newiTemp (slocBuffer);
+
+ /* set the type to the spilling symbol */
+ sloc->type = copyLinkChain (sym->type);
+ sloc->etype = getSpec (sloc->type);
+ SPEC_SCLS (sloc->etype) = options.model ? S_XDATA : S_DATA;
+ SPEC_EXTR (sloc->etype) = 0;
+
+ /* we don't allow it to be allocated`
+ onto the external stack since : so we
+ temporarily turn it off ; we also
+ turn off memory model to prevent
+ the spil from going to the external storage
+ and turn off overlaying
+ */
+
+ useXstack = options.useXstack;
+ model = options.model;
+ noOverlay = options.noOverlay;
+ options.noOverlay = 1;
+
+ /* options.model = options.useXstack = 0; */
+
+ allocLocal (sloc);
+
+ options.useXstack = useXstack;
+ options.model = model;
+ options.noOverlay = noOverlay;
+ sloc->isref = 1; /* to prevent compiler warning */
+
+ /* if it is on the stack then update the stack */
+ if (IN_STACK (sloc->etype))
+ {
+ currFunc->stack += getSize (sloc->type);
+ _G.stackExtend += getSize (sloc->type);
+ }
+ else
+ _G.dataExtend += getSize (sloc->type);
+
+ /* add it to the _G.stackSpil set */
+ addSetHead (&_G.stackSpil, sloc);
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+
+ /* add it to the set of itempStack set
+ of the spill location */
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
/*-----------------------------------------------------------------*/
/* isSpiltOnStack - returns true if the spil location is on stack */
/*-----------------------------------------------------------------*/
-static bool isSpiltOnStack (symbol *sym)
+static bool
+isSpiltOnStack (symbol * sym)
{
- sym_link *etype;
+ sym_link *etype;
- if (!sym)
- return FALSE ;
-
- if (!sym->isspilt)
- return FALSE ;
+ if (!sym)
+ return FALSE;
+
+ if (!sym->isspilt)
+ return FALSE;
/* if (sym->_G.stackSpil) */
-/* return TRUE; */
-
- if (!sym->usl.spillLoc)
- return FALSE;
+/* return TRUE; */
- etype = getSpec(sym->usl.spillLoc->type);
- if (IN_STACK(etype))
- return TRUE;
+ if (!sym->usl.spillLoc)
+ return FALSE;
+
+ etype = getSpec (sym->usl.spillLoc->type);
+ if (IN_STACK (etype))
+ return TRUE;
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* spillThis - spils a specific operand */
/*-----------------------------------------------------------------*/
-static void spillThis (symbol *sym)
+static void
+spillThis (symbol * sym)
{
- int i;
- /* if this is rematerializable or has a spillLocation
- we are okay, else we need to create a spillLocation
- for it */
- if (!(sym->remat || sym->usl.spillLoc))
- createStackSpil (sym);
-
-
- /* mark it has spilt & put it in the spilt set */
- sym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,sym->key);
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- for (i = 0 ; i < sym->nRegs ; i++)
-
- if (sym->regs[i]) {
- freeReg(sym->regs[i]);
- sym->regs[i] = NULL;
- }
-
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to some
- LIVE ranges */
- if (!ds390_ptrRegReq && isSpiltOnStack(sym)) {
- ds390_ptrRegReq++ ;
- spillLRWithPtrReg(sym);
+ int i;
+ /* if this is rematerializable or has a spillLocation
+ we are okay, else we need to create a spillLocation
+ for it */
+ if (!(sym->remat || sym->usl.spillLoc))
+ createStackSpil (sym);
+
+
+ /* mark it has spilt & put it in the spilt set */
+ sym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ for (i = 0; i < sym->nRegs; i++)
+
+ if (sym->regs[i])
+ {
+ freeReg (sym->regs[i]);
+ sym->regs[i] = NULL;
+ }
+
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to some
+ LIVE ranges */
+ if (!ds390_ptrRegReq && isSpiltOnStack (sym))
+ {
+ ds390_ptrRegReq++;
+ spillLRWithPtrReg (sym);
}
- if (sym->usl.spillLoc && !sym->remat)
- sym->usl.spillLoc->allocreq = 1;
- return;
+ if (sym->usl.spillLoc && !sym->remat)
+ sym->usl.spillLoc->allocreq = 1;
+ return;
}
/*-----------------------------------------------------------------*/
/* selectSpil - select a iTemp to spil : rather a simple procedure */
/*-----------------------------------------------------------------*/
-static symbol *selectSpil (iCode *ic, eBBlock *ebp, symbol *forSym)
+static symbol *
+selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- bitVect *lrcs= NULL ;
- set *selectS ;
- symbol *sym;
+ bitVect *lrcs = NULL;
+ set *selectS;
+ symbol *sym;
- /* get the spillable live ranges */
- lrcs = computeSpillable (ic);
+ /* get the spillable live ranges */
+ lrcs = computeSpillable (ic);
- /* get all live ranges that are rematerizable */
- if ((selectS = liveRangesWith(lrcs,rematable,ebp,ic))) {
+ /* get all live ranges that are rematerizable */
+ if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
+ {
- /* return the least used of these */
- return leastUsedLR(selectS);
+ /* return the least used of these */
+ return leastUsedLR (selectS);
}
- /* get live ranges with spillLocations in direct space */
- if ((selectS = liveRangesWith(lrcs,directSpilLoc,ebp,ic))) {
- sym = leastUsedLR(selectS);
- strcpy(sym->rname,(sym->usl.spillLoc->rname[0] ?
- sym->usl.spillLoc->rname :
- sym->usl.spillLoc->name));
- sym->spildir = 1;
- /* mark it as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* get live ranges with spillLocations in direct space */
+ if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
+ sym->usl.spillLoc->rname :
+ sym->usl.spillLoc->name));
+ sym->spildir = 1;
+ /* mark it as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* if the symbol is local to the block then */
- if (forSym->liveTo < ebp->lSeq) {
-
- /* check if there are any live ranges allocated
- to registers that are not used in this block */
- if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInBlock,ebp,ic))) {
- sym = leastUsedLR(selectS);
- /* if this is not rematerializable */
- if (!sym->remat) {
- _G.blockSpil++;
- sym->blockSpil = 1;
+ /* if the symbol is local to the block then */
+ if (forSym->liveTo < ebp->lSeq)
+ {
+
+ /* check if there are any live ranges allocated
+ to registers that are not used in this block */
+ if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ /* if this is not rematerializable */
+ if (!sym->remat)
+ {
+ _G.blockSpil++;
+ sym->blockSpil = 1;
}
- return sym;
- }
-
- /* check if there are any live ranges that not
- used in the remainder of the block */
- if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInRemaining,ebp,ic))) {
- sym = leastUsedLR (selectS);
- if (sym != forSym) {
- if (!sym->remat) {
- sym->remainSpil = 1;
- _G.blockSpil++;
+ return sym;
+ }
+
+ /* check if there are any live ranges that not
+ used in the remainder of the block */
+ if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ if (sym != forSym)
+ {
+ if (!sym->remat)
+ {
+ sym->remainSpil = 1;
+ _G.blockSpil++;
}
- return sym;
+ return sym;
}
}
- }
-
- /* find live ranges with spillocation && not used as pointers */
- if ((selectS = liveRangesWith(lrcs,hasSpilLocnoUptr,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- /* mark this as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
}
- /* find live ranges with spillocation */
- if ((selectS = liveRangesWith(lrcs,hasSpilLoc,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation && not used as pointers */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ /* mark this as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* couldn't find then we need to create a spil
- location on the stack , for which one? the least
- used ofcourse */
- if ((selectS = liveRangesWith(lrcs,noSpilLoc,ebp,ic))) {
-
- /* return a created spil location */
- sym = createStackSpil(leastUsedLR(selectS));
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
-
- /* this is an extreme situation we will spill
- this one : happens very rarely but it does happen */
- spillThis ( forSym );
- return forSym ;
-
+
+ /* couldn't find then we need to create a spil
+ location on the stack , for which one? the least
+ used ofcourse */
+ if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
+ {
+
+ /* return a created spil location */
+ sym = createStackSpil (leastUsedLR (selectS));
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
+ }
+
+ /* this is an extreme situation we will spill
+ this one : happens very rarely but it does happen */
+ spillThis (forSym);
+ return forSym;
+
}
/*-----------------------------------------------------------------*/
/* spilSomething - spil some variable & mark registers as free */
/*-----------------------------------------------------------------*/
-static bool spilSomething (iCode *ic, eBBlock *ebp, symbol *forSym)
+static bool
+spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- symbol *ssym;
- int i ;
-
- /* get something we can spil */
- ssym = selectSpil(ic,ebp,forSym);
-
- /* mark it as spilt */
- ssym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,ssym->key);
-
- /* mark it as not register assigned &
- take it away from the set */
- bitVectUnSetBit(_G.regAssigned,ssym->key);
-
- /* mark the registers as free */
- for (i = 0 ; i < ssym->nRegs ;i++ )
- if (ssym->regs[i])
- freeReg(ssym->regs[i]);
-
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to as gprs */
- if (!ds390_ptrRegReq && isSpiltOnStack(ssym) ) {
- ds390_ptrRegReq++ ;
- spillLRWithPtrReg(ssym);
+ symbol *ssym;
+ int i;
+
+ /* get something we can spil */
+ ssym = selectSpil (ic, ebp, forSym);
+
+ /* mark it as spilt */
+ ssym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
+
+ /* mark it as not register assigned &
+ take it away from the set */
+ bitVectUnSetBit (_G.regAssigned, ssym->key);
+
+ /* mark the registers as free */
+ for (i = 0; i < ssym->nRegs; i++)
+ if (ssym->regs[i])
+ freeReg (ssym->regs[i]);
+
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to as gprs */
+ if (!ds390_ptrRegReq && isSpiltOnStack (ssym))
+ {
+ ds390_ptrRegReq++;
+ spillLRWithPtrReg (ssym);
}
- /* if this was a block level spil then insert push & pop
- at the start & end of block respectively */
- if (ssym->blockSpil) {
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push to the start of the block */
- addiCodeToeBBlock(ebp,nic,( ebp->sch->op == LABEL ?
+ /* if this was a block level spil then insert push & pop
+ at the start & end of block respectively */
+ if (ssym->blockSpil)
+ {
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push to the start of the block */
+ addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
ebp->sch->next : ebp->sch));
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
- }
-
- /* if spilt because not used in the remainder of the
- block then add a push before this instruction and
- a pop at the end of the block */
- if (ssym->remainSpil) {
-
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push just before this instruction */
- addiCodeToeBBlock(ebp,nic,ic);
-
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
}
- if (ssym == forSym )
- return FALSE ;
- else
- return TRUE ;
+ /* if spilt because not used in the remainder of the
+ block then add a push before this instruction and
+ a pop at the end of the block */
+ if (ssym->remainSpil)
+ {
+
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push just before this instruction */
+ addiCodeToeBBlock (ebp, nic, ic);
+
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
+ }
+
+ if (ssym == forSym)
+ return FALSE;
+ else
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* getRegPtr - will try for PTR if not a GPR type if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegPtr (iCode *ic, eBBlock *ebp, symbol *sym)
+static regs *
+getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
+ regs *reg;
- tryAgain:
- /* try for a ptr type */
- if ((reg = allocReg(REG_PTR)))
- return reg;
+tryAgain:
+ /* try for a ptr type */
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* getRegGpr - will try for GPR if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegGpr (iCode *ic, eBBlock *ebp,symbol *sym)
+static regs *
+getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
-
- tryAgain:
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
-
- if (!ds390_ptrRegReq)
- if ((reg = allocReg(REG_PTR)))
- return reg ;
-
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
-
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ regs *reg;
+
+tryAgain:
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
+
+ if (!ds390_ptrRegReq)
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
+
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
+
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* symHasReg - symbol has a given register */
/*-----------------------------------------------------------------*/
-static bool symHasReg(symbol *sym,regs *reg)
+static bool
+symHasReg (symbol * sym, regs * reg)
{
- int i;
+ int i;
- for ( i = 0 ; i < sym->nRegs ; i++)
- if (sym->regs[i] == reg)
- return TRUE;
-
- return FALSE;
+ for (i = 0; i < sym->nRegs; i++)
+ if (sym->regs[i] == reg)
+ return TRUE;
+
+ return FALSE;
}
/*-----------------------------------------------------------------*/
-/* deassignLRs - check the live to and if they have registers & are*/
+/* deassignLRs - check the live to and if they have registers & are */
/* not spilt then free up the registers */
/*-----------------------------------------------------------------*/
-static void deassignLRs (iCode *ic, eBBlock *ebp)
+static void
+deassignLRs (iCode * ic, eBBlock * ebp)
{
- symbol *sym;
- int k;
- symbol *result;
-
- for (sym = hTabFirstItem(liveRanges,&k); sym;
- sym = hTabNextItem(liveRanges,&k)) {
-
- symbol *psym= NULL;
- /* if it does not end here */
- if (sym->liveTo > ic->seq )
- continue ;
-
- /* if it was spilt on stack then we can
- mark the stack spil location as free */
- if (sym->isspilt ) {
- if (sym->stackSpil) {
- sym->usl.spillLoc->isFree = 1;
- sym->stackSpil = 0;
+ symbol *sym;
+ int k;
+ symbol *result;
+
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
+
+ symbol *psym = NULL;
+ /* if it does not end here */
+ if (sym->liveTo > ic->seq)
+ continue;
+
+ /* if it was spilt on stack then we can
+ mark the stack spil location as free */
+ if (sym->isspilt)
+ {
+ if (sym->stackSpil)
+ {
+ sym->usl.spillLoc->isFree = 1;
+ sym->stackSpil = 0;
}
- continue ;
+ continue;
}
-
- if (!bitVectBitValue(_G.regAssigned,sym->key))
- continue;
-
- /* special case check if this is an IFX &
- the privious one was a pop and the
- previous one was not spilt then keep track
- of the symbol */
- if (ic->op == IFX && ic->prev &&
- ic->prev->op == IPOP &&
- !ic->prev->parmPush &&
- !OP_SYMBOL(IC_LEFT(ic->prev))->isspilt)
- psym = OP_SYMBOL(IC_LEFT(ic->prev));
-
- if (sym->nRegs) {
- int i = 0;
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- /* if the result of this one needs registers
- and does not have it then assign it right
- away */
- if (IC_RESULT(ic) &&
- ! (SKIP_IC2(ic) || /* not a special icode */
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- ic->op == RETURN ||
- POINTER_SET(ic)) &&
- (result = OP_SYMBOL(IC_RESULT(ic))) && /* has a result */
- result->liveTo > ic->seq && /* and will live beyond this */
- result->liveTo <= ebp->lSeq && /* does not go beyond this block */
- result->regType == sym->regType && /* same register types */
- result->nRegs && /* which needs registers */
- ! result->isspilt && /* and does not already have them */
- ! result->remat &&
- ! bitVectBitValue(_G.regAssigned,result->key) &&
- /* the number of free regs + number of regs in this LR
- can accomodate the what result Needs */
- ((nfreeRegsType(result->regType) +
- sym->nRegs) >= result->nRegs)
- ) {
-
- for (i = 0 ; i < result->nRegs ; i++)
- if (i < sym->nRegs )
- result->regs[i] = sym->regs[i] ;
- else
- result->regs[i] = getRegGpr (ic,ebp,result);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,result->key);
-
- }
-
- /* free the remaining */
- for (; i < sym->nRegs ; i++) {
- if (psym) {
- if (!symHasReg(psym,sym->regs[i]))
- freeReg(sym->regs[i]);
- } else
- freeReg(sym->regs[i]);
+
+ if (!bitVectBitValue (_G.regAssigned, sym->key))
+ continue;
+
+ /* special case check if this is an IFX &
+ the privious one was a pop and the
+ previous one was not spilt then keep track
+ of the symbol */
+ if (ic->op == IFX && ic->prev &&
+ ic->prev->op == IPOP &&
+ !ic->prev->parmPush &&
+ !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
+ psym = OP_SYMBOL (IC_LEFT (ic->prev));
+
+ if (sym->nRegs)
+ {
+ int i = 0;
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ /* if the result of this one needs registers
+ and does not have it then assign it right
+ away */
+ if (IC_RESULT (ic) &&
+ !(SKIP_IC2 (ic) || /* not a special icode */
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ ic->op == RETURN ||
+ POINTER_SET (ic)) &&
+ (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
+ result->liveTo > ic->seq && /* and will live beyond this */
+ result->liveTo <= ebp->lSeq && /* does not go beyond this block */
+ result->regType == sym->regType && /* same register types */
+ result->nRegs && /* which needs registers */
+ !result->isspilt && /* and does not already have them */
+ !result->remat &&
+ !bitVectBitValue (_G.regAssigned, result->key) &&
+ /* the number of free regs + number of regs in this LR
+ can accomodate the what result Needs */
+ ((nfreeRegsType (result->regType) +
+ sym->nRegs) >= result->nRegs)
+ )
+ {
+
+ for (i = 0; i < result->nRegs; i++)
+ if (i < sym->nRegs)
+ result->regs[i] = sym->regs[i];
+ else
+ result->regs[i] = getRegGpr (ic, ebp, result);
+
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
+
+ }
+
+ /* free the remaining */
+ for (; i < sym->nRegs; i++)
+ {
+ if (psym)
+ {
+ if (!symHasReg (psym, sym->regs[i]))
+ freeReg (sym->regs[i]);
+ }
+ else
+ freeReg (sym->regs[i]);
}
}
}
/*-----------------------------------------------------------------*/
/* reassignLR - reassign this to registers */
/*-----------------------------------------------------------------*/
-static void reassignLR (operand *op)
+static void
+reassignLR (operand * op)
{
- symbol *sym = OP_SYMBOL(op);
- int i;
+ symbol *sym = OP_SYMBOL (op);
+ int i;
+
+ /* not spilt any more */
+ sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
+ bitVectUnSetBit (_G.spiltSet, sym->key);
- /* not spilt any more */
- sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
- bitVectUnSetBit(_G.spiltSet,sym->key);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- _G.blockSpil--;
+ _G.blockSpil--;
- for (i=0;i<sym->nRegs;i++)
- sym->regs[i]->isFree = 0;
+ for (i = 0; i < sym->nRegs; i++)
+ sym->regs[i]->isFree = 0;
}
/*-----------------------------------------------------------------*/
/* willCauseSpill - determines if allocating will cause a spill */
/*-----------------------------------------------------------------*/
-static int willCauseSpill ( int nr, int rt)
+static int
+willCauseSpill (int nr, int rt)
{
- /* first check if there are any avlb registers
- of te type required */
- if (rt == REG_PTR) {
- /* special case for pointer type
- if pointer type not avlb then
- check for type gpr */
- if (nFreeRegs(rt) >= nr)
+ /* first check if there are any avlb registers
+ of te type required */
+ if (rt == REG_PTR)
+ {
+ /* special case for pointer type
+ if pointer type not avlb then
+ check for type gpr */
+ if (nFreeRegs (rt) >= nr)
+ return 0;
+ if (nFreeRegs (REG_GPR) >= nr)
+ return 0;
+ }
+ else
+ {
+ if (ds390_ptrRegReq)
+ {
+ if (nFreeRegs (rt) >= nr)
return 0;
- if (nFreeRegs(REG_GPR) >= nr)
+ }
+ else
+ {
+ if (nFreeRegs (REG_PTR) +
+ nFreeRegs (REG_GPR) >= nr)
return 0;
- } else {
- if (ds390_ptrRegReq) {
- if (nFreeRegs(rt) >= nr)
- return 0;
- } else {
- if (nFreeRegs(REG_PTR) +
- nFreeRegs(REG_GPR) >= nr)
- return 0;
}
}
- /* it will cause a spil */
- return 1;
+ /* it will cause a spil */
+ return 1;
}
/*-----------------------------------------------------------------*/
-/* positionRegs - the allocator can allocate same registers to res-*/
+/* positionRegs - the allocator can allocate same registers to res- */
/* ult and operand, if this happens make sure they are in the same */
/* position as the operand otherwise chaos results */
/*-----------------------------------------------------------------*/
-static void positionRegs (symbol *result, symbol *opsym, int lineno)
+static void
+positionRegs (symbol * result, symbol * opsym, int lineno)
{
- int count = min(result->nRegs,opsym->nRegs);
- int i , j = 0, shared = 0;
-
- /* if the result has been spilt then cannot share */
- if (opsym->isspilt)
- return ;
- again:
- shared = 0;
- /* first make sure that they actually share */
- for ( i = 0 ; i < count; i++ ) {
- for (j = 0 ; j < count ; j++ ) {
- if (result->regs[i] == opsym->regs[j] && i !=j) {
- shared = 1;
- goto xchgPositions;
- }
- }
- }
- xchgPositions:
- if (shared) {
- regs *tmp = result->regs[i];
- result->regs[i] = result->regs[j];
- result->regs[j] = tmp;
- goto again;
+ int count = min (result->nRegs, opsym->nRegs);
+ int i, j = 0, shared = 0;
+
+ /* if the result has been spilt then cannot share */
+ if (opsym->isspilt)
+ return;
+again:
+ shared = 0;
+ /* first make sure that they actually share */
+ for (i = 0; i < count; i++)
+ {
+ for (j = 0; j < count; j++)
+ {
+ if (result->regs[i] == opsym->regs[j] && i != j)
+ {
+ shared = 1;
+ goto xchgPositions;
+ }
}
+ }
+xchgPositions:
+ if (shared)
+ {
+ regs *tmp = result->regs[i];
+ result->regs[i] = result->regs[j];
+ result->regs[j] = tmp;
+ goto again;
+ }
}
/*-----------------------------------------------------------------*/
/* serialRegAssign - serially allocate registers to the variables */
/*-----------------------------------------------------------------*/
-static void serialRegAssign (eBBlock **ebbs, int count)
+static void
+serialRegAssign (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
-
- iCode *ic;
-
- if (ebbs[i]->noPath &&
- (ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* of all instructions do */
- for (ic = ebbs[i]->sch ; ic ; ic = ic->next) {
-
- /* if this is an ipop that means some live
- range will have to be assigned again */
- if (ic->op == IPOP)
- reassignLR (IC_LEFT(ic));
-
- /* if result is present && is a true symbol */
- if (IC_RESULT(ic) && ic->op != IFX &&
- IS_TRUE_SYMOP(IC_RESULT(ic)))
- OP_SYMBOL(IC_RESULT(ic))->allocreq = 1;
-
- /* take away registers from live
- ranges that end at this instruction */
- deassignLRs (ic, ebbs[i]) ;
-
- /* some don't need registers */
- if (SKIP_IC2(ic) ||
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- (IC_RESULT(ic) &&POINTER_SET(ic)) )
- continue;
-
- /* now we need to allocate registers
- only for the result */
- if (IC_RESULT(ic)) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- bitVect *spillable;
- int willCS ;
- int j;
- int ptrRegSet = 0;
-
- /* if it does not need or is spilt
- or is already assigned to registers
- or will not live beyond this instructions */
- if (!sym->nRegs ||
- sym->isspilt ||
- bitVectBitValue(_G.regAssigned,sym->key) ||
- sym->liveTo <= ic->seq)
- continue ;
-
- /* if some liverange has been spilt at the block level
- and this one live beyond this block then spil this
- to be safe */
- if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq) {
- spillThis (sym);
- continue ;
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* of all instructions do */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an ipop that means some live
+ range will have to be assigned again */
+ if (ic->op == IPOP)
+ reassignLR (IC_LEFT (ic));
+
+ /* if result is present && is a true symbol */
+ if (IC_RESULT (ic) && ic->op != IFX &&
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
+
+ /* take away registers from live
+ ranges that end at this instruction */
+ deassignLRs (ic, ebbs[i]);
+
+ /* some don't need registers */
+ if (SKIP_IC2 (ic) ||
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ (IC_RESULT (ic) && POINTER_SET (ic)))
+ continue;
+
+ /* now we need to allocate registers
+ only for the result */
+ if (IC_RESULT (ic))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ bitVect *spillable;
+ int willCS;
+ int j;
+ int ptrRegSet = 0;
+
+ /* if it does not need or is spilt
+ or is already assigned to registers
+ or will not live beyond this instructions */
+ if (!sym->nRegs ||
+ sym->isspilt ||
+ bitVectBitValue (_G.regAssigned, sym->key) ||
+ sym->liveTo <= ic->seq)
+ continue;
+
+ /* if some liverange has been spilt at the block level
+ and this one live beyond this block then spil this
+ to be safe */
+ if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
+ {
+ spillThis (sym);
+ continue;
}
- /* if trying to allocate this will cause
- a spill and there is nothing to spill
- or this one is rematerializable then
- spill this one */
- willCS = willCauseSpill(sym->nRegs,sym->regType);
- spillable = computeSpillable(ic);
- if ( sym->remat ||
- (willCS && bitVectIsZero(spillable) ) ) {
-
- spillThis (sym) ;
- continue ;
+ /* if trying to allocate this will cause
+ a spill and there is nothing to spill
+ or this one is rematerializable then
+ spill this one */
+ willCS = willCauseSpill (sym->nRegs, sym->regType);
+ spillable = computeSpillable (ic);
+ if (sym->remat ||
+ (willCS && bitVectIsZero (spillable)))
+ {
+
+ spillThis (sym);
+ continue;
}
- /* if it has a spillocation & is used less than
- all other live ranges then spill this */
- if ( willCS && sym->usl.spillLoc ) {
-
- symbol *leastUsed =
- leastUsedLR(liveRangesWith (spillable ,
- allLRs,
- ebbs[i],
- ic));
- if (leastUsed &&
- leastUsed->used > sym->used) {
- spillThis (sym);
- continue;
+ /* if it has a spillocation & is used less than
+ all other live ranges then spill this */
+ if (willCS && sym->usl.spillLoc)
+ {
+
+ symbol *leastUsed =
+ leastUsedLR (liveRangesWith (spillable,
+ allLRs,
+ ebbs[i],
+ ic));
+ if (leastUsed &&
+ leastUsed->used > sym->used)
+ {
+ spillThis (sym);
+ continue;
}
- }
-
- /* if we need ptr regs for the right side
- then mark it */
- if (POINTER_GET(ic) && IS_SYMOP(IC_LEFT(ic))
- && getSize(OP_SYMBOL(IC_LEFT(ic))->type)
- <= PTRSIZE)
+ }
+
+ /* if we need ptr regs for the right side
+ then mark it */
+ if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
+ && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
+ <= PTRSIZE)
{
- ds390_ptrRegReq++;
- ptrRegSet = 1;
+ ds390_ptrRegReq++;
+ ptrRegSet = 1;
}
- /* else we assign registers to it */
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
-
- for (j = 0 ; j < sym->nRegs ;j++ ) {
- if (sym->regType == REG_PTR)
- sym->regs[j] = getRegPtr(ic,ebbs[i],sym);
- else
- sym->regs[j] = getRegGpr(ic,ebbs[i],sym);
-
- /* if the allocation falied which means
- this was spilt then break */
- if (!sym->regs[j])
- break;
+ /* else we assign registers to it */
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ if (sym->regType == REG_PTR)
+ sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
+ else
+ sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
+
+ /* if the allocation falied which means
+ this was spilt then break */
+ if (!sym->regs[j])
+ break;
}
- /* if it shares registers with operands make sure
- that they are in the same position */
- if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->nRegs && ic->op != '=')
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_LEFT(ic)),ic->lineno);
- /* do the same for the right operand */
- if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->nRegs)
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_RIGHT(ic)),ic->lineno);
-
- if (ptrRegSet) {
- ds390_ptrRegReq--;
- ptrRegSet = 0;
+ /* if it shares registers with operands make sure
+ that they are in the same position */
+ if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
+ /* do the same for the right operand */
+ if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->nRegs)
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
+
+ if (ptrRegSet)
+ {
+ ds390_ptrRegReq--;
+ ptrRegSet = 0;
}
-
- }
+
+ }
}
}
}
/*-----------------------------------------------------------------*/
/* rUmaskForOp :- returns register mask for an operand */
/*-----------------------------------------------------------------*/
-static bitVect *rUmaskForOp (operand *op)
+static bitVect *
+rUmaskForOp (operand * op)
{
- bitVect *rumask;
- symbol *sym;
- int j;
-
- /* only temporaries are assigned registers */
- if (!IS_ITEMP(op))
- return NULL;
+ bitVect *rumask;
+ symbol *sym;
+ int j;
- sym = OP_SYMBOL(op);
-
- /* if spilt or no registers assigned to it
- then nothing */
- if (sym->isspilt || !sym->nRegs)
- return NULL;
+ /* only temporaries are assigned registers */
+ if (!IS_ITEMP (op))
+ return NULL;
- rumask = newBitVect(ds390_nRegs);
+ sym = OP_SYMBOL (op);
- for (j = 0; j < sym->nRegs; j++) {
- rumask = bitVectSetBit(rumask,
- sym->regs[j]->rIdx);
+ /* if spilt or no registers assigned to it
+ then nothing */
+ if (sym->isspilt || !sym->nRegs)
+ return NULL;
+
+ rumask = newBitVect (ds390_nRegs);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ rumask = bitVectSetBit (rumask,
+ sym->regs[j]->rIdx);
}
- return rumask;
+ return rumask;
}
/*-----------------------------------------------------------------*/
-/* regsUsedIniCode :- returns bit vector of registers used in iCode*/
+/* regsUsedIniCode :- returns bit vector of registers used in iCode */
/*-----------------------------------------------------------------*/
-static bitVect *regsUsedIniCode (iCode *ic)
+static bitVect *
+regsUsedIniCode (iCode * ic)
{
- bitVect *rmask = newBitVect(ds390_nRegs);
+ bitVect *rmask = newBitVect (ds390_nRegs);
- /* do the special cases first */
- if (ic->op == IFX ) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_COND(ic)));
- goto ret;
+ /* do the special cases first */
+ if (ic->op == IFX)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_COND (ic)));
+ goto ret;
}
- /* for the jumptable */
- if (ic->op == JUMPTABLE) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_JTCOND(ic)));
+ /* for the jumptable */
+ if (ic->op == JUMPTABLE)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_JTCOND (ic)));
- goto ret;
+ goto ret;
}
- /* of all other cases */
- if (IC_LEFT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_LEFT(ic)));
-
-
- if (IC_RIGHT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RIGHT(ic)));
-
- if (IC_RESULT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RESULT(ic)));
-
- ret:
- return rmask;
+ /* of all other cases */
+ if (IC_LEFT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_LEFT (ic)));
+
+
+ if (IC_RIGHT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RIGHT (ic)));
+
+ if (IC_RESULT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RESULT (ic)));
+
+ret:
+ return rmask;
}
/*-----------------------------------------------------------------*/
-/* createRegMask - for each instruction will determine the regsUsed*/
+/* createRegMask - for each instruction will determine the regsUsed */
/*-----------------------------------------------------------------*/
-static void createRegMask (eBBlock **ebbs, int count)
+static void
+createRegMask (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
- iCode *ic ;
-
- if ( ebbs[i]->noPath &&
- ( ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* for all instructions */
- for ( ic = ebbs[i]->sch ; ic ; ic = ic->next ) {
-
- int j;
-
- if (SKIP_IC2(ic) || !ic->rlive)
- continue ;
-
- /* first mark the registers used in this
- instruction */
- ic->rUsed = regsUsedIniCode(ic);
- _G.funcrUsed = bitVectUnion(_G.funcrUsed,ic->rUsed);
-
- /* now create the register mask for those
- registers that are in use : this is a
- super set of ic->rUsed */
- ic->rMask = newBitVect(ds390_nRegs+1);
-
- /* for all live Ranges alive at this point */
- for (j = 1; j < ic->rlive->size; j++ ) {
- symbol *sym;
- int k;
-
- /* if not alive then continue */
- if (!bitVectBitValue(ic->rlive,j))
- continue ;
-
- /* find the live range we are interested in */
- if (!(sym = hTabItemWithKey(liveRanges,j))) {
- werror (E_INTERNAL_ERROR,__FILE__,__LINE__,
- "createRegMask cannot find live range");
- exit(0);
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* for all instructions */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ int j;
+
+ if (SKIP_IC2 (ic) || !ic->rlive)
+ continue;
+
+ /* first mark the registers used in this
+ instruction */
+ ic->rUsed = regsUsedIniCode (ic);
+ _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
+
+ /* now create the register mask for those
+ registers that are in use : this is a
+ super set of ic->rUsed */
+ ic->rMask = newBitVect (ds390_nRegs + 1);
+
+ /* for all live Ranges alive at this point */
+ for (j = 1; j < ic->rlive->size; j++)
+ {
+ symbol *sym;
+ int k;
+
+ /* if not alive then continue */
+ if (!bitVectBitValue (ic->rlive, j))
+ continue;
+
+ /* find the live range we are interested in */
+ if (!(sym = hTabItemWithKey (liveRanges, j)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "createRegMask cannot find live range");
+ exit (0);
}
- /* if no register assigned to it */
- if (!sym->nRegs || sym->isspilt)
- continue ;
+ /* if no register assigned to it */
+ if (!sym->nRegs || sym->isspilt)
+ continue;
- /* for all the registers allocated to it */
- for (k = 0 ; k < sym->nRegs ;k++)
- if (sym->regs[k])
- ic->rMask =
- bitVectSetBit(ic->rMask,sym->regs[k]->rIdx);
+ /* for all the registers allocated to it */
+ for (k = 0; k < sym->nRegs; k++)
+ if (sym->regs[k])
+ ic->rMask =
+ bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
}
}
}
/*-----------------------------------------------------------------*/
/* rematStr - returns the rematerialized string for a remat var */
/*-----------------------------------------------------------------*/
-static char *rematStr (symbol *sym)
+static char *
+rematStr (symbol * sym)
{
- char *s = buffer;
- iCode *ic = sym->rematiCode;
-
- while (1) {
-
- /* if plus or minus print the right hand side */
- if (ic->op == '+' || ic->op == '-') {
- sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
- ic->op );
- s += strlen(s);
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- continue ;
- }
-
- /* we reached the end */
- sprintf(s,"%s",OP_SYMBOL(IC_LEFT(ic))->rname);
- break;
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
+
+ while (1)
+ {
+
+ /* if plus or minus print the right hand side */
+ if (ic->op == '+' || ic->op == '-')
+ {
+ sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+ ic->op);
+ s += strlen (s);
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ continue;
+ }
+
+ /* we reached the end */
+ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ break;
}
- return buffer ;
+ return buffer;
}
/*-----------------------------------------------------------------*/
/* regTypeNum - computes the type & number of registers required */
/*-----------------------------------------------------------------*/
-static void regTypeNum ()
+static void
+regTypeNum ()
{
- symbol *sym;
- int k;
- iCode *ic;
+ symbol *sym;
+ int k;
+ iCode *ic;
- /* for each live range do */
- for ( sym = hTabFirstItem(liveRanges,&k); sym ;
- sym = hTabNextItem(liveRanges,&k)) {
+ /* for each live range do */
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
- /* if used zero times then no registers needed */
- if ((sym->liveTo - sym->liveFrom) == 0)
- continue ;
+ /* if used zero times then no registers needed */
+ if ((sym->liveTo - sym->liveFrom) == 0)
+ continue;
- /* if the live range is a temporary */
- if (sym->isitmp) {
+ /* if the live range is a temporary */
+ if (sym->isitmp)
+ {
- /* if the type is marked as a conditional */
- if (sym->regType == REG_CND)
- continue ;
+ /* if the type is marked as a conditional */
+ if (sym->regType == REG_CND)
+ continue;
- /* if used in return only then we don't
- need registers */
- if (sym->ruonly || sym->accuse) {
- if (IS_AGGREGATE(sym->type) || sym->isptr)
- sym->type = aggrToPtr(sym->type,FALSE);
- continue ;
+ /* if used in return only then we don't
+ need registers */
+ if (sym->ruonly || sym->accuse)
+ {
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ sym->type = aggrToPtr (sym->type, FALSE);
+ continue;
}
-
- /* if the symbol has only one definition &
- that definition is a get_pointer and the
- pointer we are getting is rematerializable and
- in "data" space */
-
- if (bitVectnBitsOn(sym->defs) == 1 &&
- (ic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(sym->defs))) &&
- POINTER_GET(ic) &&
- !IS_BITVAR(sym->etype)) {
-
-
- /* if remat in data space */
- if (OP_SYMBOL(IC_LEFT(ic))->remat &&
- // sym->type &&
- DCL_TYPE(aggrToPtr(sym->type,FALSE)) == POINTER) {
-
- /* create a psuedo symbol & force a spil */
- symbol *psym = newSymbol(rematStr(OP_SYMBOL(IC_LEFT(ic))),1);
- psym->type = sym->type;
- psym->etype = sym->etype;
- strcpy(psym->rname,psym->name);
- sym->isspilt = 1;
- sym->usl.spillLoc = psym;
- continue ;
+
+ /* if the symbol has only one definition &
+ that definition is a get_pointer and the
+ pointer we are getting is rematerializable and
+ in "data" space */
+
+ if (bitVectnBitsOn (sym->defs) == 1 &&
+ (ic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (sym->defs))) &&
+ POINTER_GET (ic) &&
+ !IS_BITVAR (sym->etype))
+ {
+
+
+ /* if remat in data space */
+ if (OP_SYMBOL (IC_LEFT (ic))->remat &&
+ // sym->type &&
+ DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER)
+ {
+
+ /* create a psuedo symbol & force a spil */
+ symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
+ psym->type = sym->type;
+ psym->etype = sym->etype;
+ strcpy (psym->rname, psym->name);
+ sym->isspilt = 1;
+ sym->usl.spillLoc = psym;
+ continue;
}
- /* if in data space or idata space then try to
- allocate pointer register */
-
+ /* if in data space or idata space then try to
+ allocate pointer register */
+
}
-
- /* if not then we require registers */
- sym->nRegs = ((IS_AGGREGATE(sym->type) || sym->isptr ) ?
- getSize(sym->type = aggrToPtr(sym->type,FALSE)) :
- getSize(sym->type));
-
- if (sym->nRegs > 4) {
- fprintf(stderr,"allocated more than 4 or 0 registers for type ");
- printTypeChain(sym->type,stderr);fprintf(stderr,"\n");
- }
-
- /* determine the type of register required */
- if (sym->nRegs == 1 &&
- IS_PTR(sym->type) &&
- sym->uptr)
- sym->regType = REG_PTR ;
- else
- sym->regType = REG_GPR ;
-
- } else
- /* for the first run we don't provide */
- /* registers for true symbols we will */
- /* see how things go */
- sym->nRegs = 0 ;
+
+ /* if not then we require registers */
+ sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
+ getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
+ getSize (sym->type));
+
+ if (sym->nRegs > 4)
+ {
+ fprintf (stderr, "allocated more than 4 or 0 registers for type ");
+ printTypeChain (sym->type, stderr);
+ fprintf (stderr, "\n");
+ }
+
+ /* determine the type of register required */
+ if (sym->nRegs == 1 &&
+ IS_PTR (sym->type) &&
+ sym->uptr)
+ sym->regType = REG_PTR;
+ else
+ sym->regType = REG_GPR;
+
+ }
+ else
+ /* for the first run we don't provide */
+ /* registers for true symbols we will */
+ /* see how things go */
+ sym->nRegs = 0;
}
-
+
}
/*-----------------------------------------------------------------*/
/* freeAllRegs - mark all registers as free */
/*-----------------------------------------------------------------*/
-static void freeAllRegs()
+static void
+freeAllRegs ()
{
- int i;
+ int i;
- for (i=0;i< ds390_nRegs;i++ )
- regs390[i].isFree = 1;
+ for (i = 0; i < ds390_nRegs; i++)
+ regs390[i].isFree = 1;
}
/*-----------------------------------------------------------------*/
/* deallocStackSpil - this will set the stack pointer back */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(deallocStackSpil)
+static
+DEFSETFUNC (deallocStackSpil)
{
- symbol *sym = item;
+ symbol *sym = item;
- deallocLocal(sym);
- return 0;
+ deallocLocal (sym);
+ return 0;
}
/*-----------------------------------------------------------------*/
/* farSpacePackable - returns the packable icode for far variables */
/*-----------------------------------------------------------------*/
-static iCode *farSpacePackable (iCode *ic)
+static iCode *
+farSpacePackable (iCode * ic)
{
- iCode *dic ;
-
- /* go thru till we find a definition for the
- symbol on the right */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if the definition is a call then no */
- if ((dic->op == CALL || dic->op == PCALL) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- return NULL;
+ iCode *dic;
+
+ /* go thru till we find a definition for the
+ symbol on the right */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if the definition is a call then no */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ return NULL;
}
-
- /* if shift by unknown amount then not */
- if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key)
- return NULL;
- /* if pointer get and size > 1 */
- if (POINTER_GET(dic) &&
- getSize(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if shift by unknown amount then not */
+ if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ return NULL;
- if (POINTER_SET(dic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if pointer get and size > 1 */
+ if (POINTER_GET (dic) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
+ return NULL;
- /* if any three is a true symbol in far space */
- if (IC_RESULT(dic) &&
- IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- isOperandInFarSpace(IC_RESULT(dic)))
- return NULL;
+ if (POINTER_SET (dic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
+ return NULL;
- if (IC_RIGHT(dic) &&
- IS_TRUE_SYMOP(IC_RIGHT(dic)) &&
- isOperandInFarSpace(IC_RIGHT(dic)) &&
- !isOperandEqual(IC_RIGHT(dic),IC_RESULT(ic)))
- return NULL;
+ /* if any three is a true symbol in far space */
+ if (IC_RESULT (dic) &&
+ IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ isOperandInFarSpace (IC_RESULT (dic)))
+ return NULL;
+
+ if (IC_RIGHT (dic) &&
+ IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
+ isOperandInFarSpace (IC_RIGHT (dic)) &&
+ !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
+ return NULL;
- if (IC_LEFT(dic) &&
- IS_TRUE_SYMOP(IC_LEFT(dic)) &&
- isOperandInFarSpace(IC_LEFT(dic)) &&
- !isOperandEqual(IC_LEFT(dic),IC_RESULT(ic)))
+ if (IC_LEFT (dic) &&
+ IS_TRUE_SYMOP (IC_LEFT (dic)) &&
+ isOperandInFarSpace (IC_LEFT (dic)) &&
+ !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
+ return NULL;
+
+ if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
+ {
+ if ((dic->op == LEFT_OP ||
+ dic->op == RIGHT_OP ||
+ dic->op == '-') &&
+ IS_OP_LITERAL (IC_RIGHT (dic)))
return NULL;
-
- if (isOperandEqual(IC_RIGHT(ic),IC_RESULT(dic))) {
- if ( (dic->op == LEFT_OP ||
- dic->op == RIGHT_OP ||
- dic->op == '-') &&
- IS_OP_LITERAL(IC_RIGHT(dic)))
- return NULL;
- else
- return dic;
+ else
+ return dic;
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* packRegsForAssign - register reduction for assignment */
/*-----------------------------------------------------------------*/
-static int packRegsForAssign (iCode *ic,eBBlock *ebp)
+static int
+packRegsForAssign (iCode * ic, eBBlock * ebp)
{
- iCode *dic, *sic;
-
- if (!IS_ITEMP(IC_RIGHT(ic)) ||
- OP_SYMBOL(IC_RIGHT(ic))->isind ||
- OP_LIVETO(IC_RIGHT(ic)) > ic->seq) {
- return 0;
+ iCode *dic, *sic;
+
+ if (!IS_ITEMP (IC_RIGHT (ic)) ||
+ OP_SYMBOL (IC_RIGHT (ic))->isind ||
+ OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
+ {
+ return 0;
}
-
- /* if the true symbol is defined in far space or on stack
- then we should not since this will increase register pressure */
- if (isOperandInFarSpace(IC_RESULT(ic))) {
- if ((dic = farSpacePackable(ic)))
- goto pack;
- else
- return 0;
-
+
+ /* if the true symbol is defined in far space or on stack
+ then we should not since this will increase register pressure */
+ if (isOperandInFarSpace (IC_RESULT (ic)))
+ {
+ if ((dic = farSpacePackable (ic)))
+ goto pack;
+ else
+ return 0;
+
}
- /* find the definition of iTempNN scanning backwards if we find a
- a use of the true symbol in before we find the definition then
- we cannot */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if there is a function call and this is
- a parameter & not my parameter then don't pack it */
- if ( (dic->op == CALL || dic->op == PCALL) &&
- (OP_SYMBOL(IC_RESULT(ic))->_isparm &&
- !OP_SYMBOL(IC_RESULT(ic))->ismyparm)) {
- dic = NULL;
- break;
+ /* find the definition of iTempNN scanning backwards if we find a
+ a use of the true symbol in before we find the definition then
+ we cannot */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if there is a function call and this is
+ a parameter & not my parameter then don't pack it */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ (OP_SYMBOL (IC_RESULT (ic))->_isparm &&
+ !OP_SYMBOL (IC_RESULT (ic))->ismyparm))
+ {
+ dic = NULL;
+ break;
}
- if (SKIP_IC2(dic))
- continue;
+ if (SKIP_IC2 (dic))
+ continue;
- if (IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- IS_OP_VOLATILE(IC_RESULT(dic))) {
- dic = NULL;
- break;
+ if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ IS_OP_VOLATILE (IC_RESULT (dic)))
+ {
+ dic = NULL;
+ break;
}
- if (IS_SYMOP(IC_RESULT(dic)) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- if (POINTER_SET(dic))
- dic = NULL;
+ if (IS_SYMOP (IC_RESULT (dic)) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ if (POINTER_SET (dic))
+ dic = NULL;
- break;
+ break;
}
- if (IS_SYMOP(IC_RIGHT(dic)) &&
- (IC_RIGHT(dic)->key == IC_RESULT(ic)->key ||
- IC_RIGHT(dic)->key == IC_RIGHT(ic)->key)) {
- dic = NULL;
- break;
+ if (IS_SYMOP (IC_RIGHT (dic)) &&
+ (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
+ IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
}
-
- if (IS_SYMOP(IC_LEFT(dic)) &&
- (IC_LEFT(dic)->key == IC_RESULT(ic)->key ||
- IC_LEFT(dic)->key == IC_RIGHT(ic)->key)) {
- dic = NULL;
- break;
+
+ if (IS_SYMOP (IC_LEFT (dic)) &&
+ (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
+ IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
}
- if (POINTER_SET(dic) &&
- IC_RESULT(dic)->key == IC_RESULT(ic)->key ) {
- dic = NULL ;
- break;
+ if (POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == IC_RESULT (ic)->key)
+ {
+ dic = NULL;
+ break;
}
}
-
- if (!dic)
- return 0 ; /* did not find */
-
- /* if the result is on stack or iaccess then it must be
- the same atleast one of the operands */
- if (OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess ) {
-
- /* the operation has only one symbol
- operator then we can pack */
- if ((IC_LEFT(dic) && !IS_SYMOP(IC_LEFT(dic))) ||
- (IC_RIGHT(dic) && !IS_SYMOP(IC_RIGHT(dic))))
- goto pack;
-
- if (!((IC_LEFT(dic) &&
- IC_RESULT(ic)->key == IC_LEFT(dic)->key) ||
- (IC_RIGHT(dic) &&
- IC_RESULT(ic)->key == IC_RIGHT(dic)->key)))
- return 0;
+
+ if (!dic)
+ return 0; /* did not find */
+
+ /* if the result is on stack or iaccess then it must be
+ the same atleast one of the operands */
+ if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess)
+ {
+
+ /* the operation has only one symbol
+ operator then we can pack */
+ if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
+ (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
+ goto pack;
+
+ if (!((IC_LEFT (dic) &&
+ IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
+ (IC_RIGHT (dic) &&
+ IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
+ return 0;
}
pack:
- /* found the definition */
- /* replace the result with the result of */
- /* this assignment and remove this assignment */
- IC_RESULT(dic) = IC_RESULT(ic) ;
+ /* found the definition */
+ /* replace the result with the result of */
+ /* this assignment and remove this assignment */
+ IC_RESULT (dic) = IC_RESULT (ic);
- if (IS_ITEMP(IC_RESULT(dic)) && OP_SYMBOL(IC_RESULT(dic))->liveFrom > dic->seq) {
- OP_SYMBOL(IC_RESULT(dic))->liveFrom = dic->seq;
+ if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
+ {
+ OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
}
- /* delete from liverange table also
- delete from all the points inbetween and the new
- one */
- for ( sic = dic; sic != ic ; sic = sic->next ) {
- bitVectUnSetBit(sic->rlive,IC_RESULT(ic)->key);
- if (IS_ITEMP(IC_RESULT(dic)))
- bitVectSetBit(sic->rlive,IC_RESULT(dic)->key);
+ /* delete from liverange table also
+ delete from all the points inbetween and the new
+ one */
+ for (sic = dic; sic != ic; sic = sic->next)
+ {
+ bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
+ if (IS_ITEMP (IC_RESULT (dic)))
+ bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
}
-
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- return 1;
-
+
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ return 1;
+
}
/*-----------------------------------------------------------------*/
-/* findAssignToSym : scanning backwards looks for first assig found*/
+/* findAssignToSym : scanning backwards looks for first assig found */
/*-----------------------------------------------------------------*/
-static iCode *findAssignToSym (operand *op,iCode *ic)
+static iCode *
+findAssignToSym (operand * op, iCode * ic)
{
- iCode *dic;
-
- for (dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if definition by assignment */
- if (dic->op == '=' &&
- !POINTER_SET(dic) &&
- IC_RESULT(dic)->key == op->key
-/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
- ) {
-
- /* we are interested only if defined in far space */
- /* or in stack space in case of + & - */
-
- /* if assigned to a non-symbol then return
- true */
- if (!IS_SYMOP(IC_RIGHT(dic)))
- break ;
-
- /* if the symbol is in far space then
- we should not */
- if (isOperandInFarSpace(IC_RIGHT(dic)))
- return NULL ;
-
- /* for + & - operations make sure that
- if it is on the stack it is the same
- as one of the three operands */
- if ((ic->op == '+' || ic->op == '-') &&
- OP_SYMBOL(IC_RIGHT(dic))->onStack) {
-
- if ( IC_RESULT(ic)->key != IC_RIGHT(dic)->key &&
- IC_LEFT(ic)->key != IC_RIGHT(dic)->key &&
- IC_RIGHT(ic)->key != IC_RIGHT(dic)->key)
- return NULL;
- }
-
- break ;
-
- }
+ iCode *dic;
- /* if we find an usage then we cannot delete it */
- if (IC_LEFT(dic) && IC_LEFT(dic)->key == op->key)
- return NULL;
-
- if (IC_RIGHT(dic) && IC_RIGHT(dic)->key == op->key)
- return NULL;
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
- if (POINTER_SET(dic) && IC_RESULT(dic)->key == op->key)
+ /* if definition by assignment */
+ if (dic->op == '=' &&
+ !POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == op->key
+/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
+ )
+ {
+
+ /* we are interested only if defined in far space */
+ /* or in stack space in case of + & - */
+
+ /* if assigned to a non-symbol then return
+ true */
+ if (!IS_SYMOP (IC_RIGHT (dic)))
+ break;
+
+ /* if the symbol is in far space then
+ we should not */
+ if (isOperandInFarSpace (IC_RIGHT (dic)))
return NULL;
- }
- /* now make sure that the right side of dic
- is not defined between ic & dic */
- if (dic) {
- iCode *sic = dic->next ;
+ /* for + & - operations make sure that
+ if it is on the stack it is the same
+ as one of the three operands */
+ if ((ic->op == '+' || ic->op == '-') &&
+ OP_SYMBOL (IC_RIGHT (dic))->onStack)
+ {
- for (; sic != ic ; sic = sic->next)
- if (IC_RESULT(sic) &&
- IC_RESULT(sic)->key == IC_RIGHT(dic)->key)
+ if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
return NULL;
+ }
+
+ break;
+
+ }
+
+ /* if we find an usage then we cannot delete it */
+ if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
+ return NULL;
+
+ if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
+ return NULL;
+
+ if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
+ return NULL;
+ }
+
+ /* now make sure that the right side of dic
+ is not defined between ic & dic */
+ if (dic)
+ {
+ iCode *sic = dic->next;
+
+ for (; sic != ic; sic = sic->next)
+ if (IC_RESULT (sic) &&
+ IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
+ return NULL;
}
- return dic;
-
-
+ return dic;
+
+
}
/*-----------------------------------------------------------------*/
/* packRegsForSupport :- reduce some registers for support calls */
/*-----------------------------------------------------------------*/
-static int packRegsForSupport (iCode *ic, eBBlock *ebp)
+static int
+packRegsForSupport (iCode * ic, eBBlock * ebp)
{
- int change = 0 ;
- /* for the left & right operand :- look to see if the
- left was assigned a true symbol in far space in that
- case replace them */
- if (IS_ITEMP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_LEFT(ic),ic);
- iCode *sic;
-
- if (!dic)
- goto right ;
-
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_LEFT(ic)->key);
-
- IC_LEFT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_LEFT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change++;
+ int change = 0;
+ /* for the left & right operand :- look to see if the
+ left was assigned a true symbol in far space in that
+ case replace them */
+ if (IS_ITEMP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ goto right;
+
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
+
+ IC_LEFT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- /* do the same for the right operand */
- right:
- if (!change &&
- IS_ITEMP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_RIGHT(ic),ic);
- iCode *sic;
-
- if (!dic)
- return change ;
-
- /* if this is a subtraction & the result
- is a true symbol in far space then don't pack */
- if (ic->op == '-' && IS_TRUE_SYMOP(IC_RESULT(dic))) {
- sym_link *etype =getSpec(operandType(IC_RESULT(dic)));
- if (IN_FARSPACE(SPEC_OCLS(etype)))
- return change ;
+
+ /* do the same for the right operand */
+right:
+ if (!change &&
+ IS_ITEMP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ return change;
+
+ /* if this is a subtraction & the result
+ is a true symbol in far space then don't pack */
+ if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
+ {
+ sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
+ if (IN_FARSPACE (SPEC_OCLS (etype)))
+ return change;
}
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_RIGHT(ic)->key);
-
- IC_RIGHT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_RIGHT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
-
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change ++;
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
+
+ IC_RIGHT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- return change ;
+
+ return change;
}
#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
/*-----------------------------------------------------------------*/
-/* packRegsForOneuse : - will reduce some registers for single Use */
+/* packRegsForOneuse : - will reduce some registers for single Use */
/*-----------------------------------------------------------------*/
-static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp)
+static iCode *
+packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
{
#if 1
-
- /* I can't figure out how to make this safe yet. */
- ic; op; ebp;
- return NULL;
-
-
+
+ /* I can't figure out how to make this safe yet. */
+ if ((int)ic+(int)op+(int)ebp) {
+ return 0;
+ } else {
+ return 0;
+ }
+ return NULL;
+
#else
- bitVect *uses ;
- iCode *dic, *sic;
+ bitVect *uses;
+ iCode *dic, *sic;
- /* if returning a literal then do nothing */
- if (!IS_SYMOP(op))
- return NULL;
-
- /* only upto 2 bytes since we cannot predict
- the usage of b, & acc */
- if (getSize(operandType(op)) > (fReturnSize_390 - 2) &&
- ic->op != RETURN &&
- ic->op != SEND &&
- !POINTER_SET(ic) &&
- !POINTER_GET(ic))
- return NULL;
+ /* if returning a literal then do nothing */
+ if (!IS_SYMOP (op))
+ return NULL;
- /* this routine will mark the a symbol as used in one
- instruction use only && if the defintion is local
- (ie. within the basic block) && has only one definition &&
- that definiion is either a return value from a
- function or does not contain any variables in
- far space */
- uses = bitVectCopy(OP_USES(op));
- bitVectUnSetBit(uses,ic->key); /* take away this iCode */
- if (!bitVectIsZero(uses)) /* has other uses */
- return NULL ;
-
- /* if it has only one defintion */
- if (bitVectnBitsOn(OP_DEFS(op)) > 1)
- return NULL ; /* has more than one definition */
-
- /* get the that definition */
- if (!(dic =
- hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(op)))))
- return NULL ;
-
- /* found the definition now check if it is local */
- if (dic->seq < ebp->fSeq ||
- dic->seq > ebp->lSeq)
- return NULL ; /* non-local */
-
- /* now check if it is the return from
- a function call */
- if (dic->op == CALL || dic->op == PCALL ) {
- if (ic->op != SEND && ic->op != RETURN) {
- OP_SYMBOL(op)->ruonly = 1;
- return dic;
+ /* only upto 2 bytes since we cannot predict
+ the usage of b, & acc */
+ if (getSize (operandType (op)) > (fReturnSize_390 - 2) &&
+ ic->op != RETURN &&
+ ic->op != SEND &&
+ !POINTER_SET (ic) &&
+ !POINTER_GET (ic))
+ return NULL;
+
+ /* this routine will mark the a symbol as used in one
+ instruction use only && if the defintion is local
+ (ie. within the basic block) && has only one definition &&
+ that definiion is either a return value from a
+ function or does not contain any variables in
+ far space */
+ uses = bitVectCopy (OP_USES (op));
+ bitVectUnSetBit (uses, ic->key); /* take away this iCode */
+ if (!bitVectIsZero (uses)) /* has other uses */
+ return NULL;
+
+ /* if it has only one defintion */
+ if (bitVectnBitsOn (OP_DEFS (op)) > 1)
+ return NULL; /* has more than one definition */
+
+ /* get the that definition */
+ if (!(dic =
+ hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (op)))))
+ return NULL;
+
+ /* found the definition now check if it is local */
+ if (dic->seq < ebp->fSeq ||
+ dic->seq > ebp->lSeq)
+ return NULL; /* non-local */
+
+ /* now check if it is the return from
+ a function call */
+ if (dic->op == CALL || dic->op == PCALL)
+ {
+ if (ic->op != SEND && ic->op != RETURN)
+ {
+ OP_SYMBOL (op)->ruonly = 1;
+ return dic;
}
- dic = dic->next ;
+ dic = dic->next;
}
-
-
- /* otherwise check that the definition does
- not contain any symbols in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(ic)) ||
- IS_OP_RUONLY(IC_RIGHT(ic)) ) {
- return NULL;
+
+
+ /* otherwise check that the definition does
+ not contain any symbols in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (ic)) ||
+ IS_OP_RUONLY (IC_RIGHT (ic)))
+ {
+ return NULL;
}
-
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- sic = dic;
-
- /* also make sure the intervenening instructions
- don't have any thing in far space */
- for (dic = dic->next ; dic && dic != ic ; dic = dic->next) {
-
- /* if there is an intervening function call then no */
- if (dic->op == CALL || dic->op == PCALL)
- return NULL;
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- /* if address of & the result is remat the okay */
- if (dic->op == ADDRESS_OF &&
- OP_SYMBOL(IC_RESULT(dic))->remat)
- continue ;
-
- /* if operand has size of three or more & this
- operation is a '*','/' or '%' then 'b' may
- cause a problem */
- if (( dic->op == '%' || dic->op == '/' || dic->op == '*') &&
- getSize(operandType(op)) >= 3)
- return NULL;
- /* if left or right or result is in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- isOperandInFarSpace(IC_RESULT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(dic)) ||
- IS_OP_RUONLY(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_RESULT(dic)) ) {
- return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ sic = dic;
+
+ /* also make sure the intervenening instructions
+ don't have any thing in far space */
+ for (dic = dic->next; dic && dic != ic; dic = dic->next)
+ {
+
+ /* if there is an intervening function call then no */
+ if (dic->op == CALL || dic->op == PCALL)
+ return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ /* if address of & the result is remat the okay */
+ if (dic->op == ADDRESS_OF &&
+ OP_SYMBOL (IC_RESULT (dic))->remat)
+ continue;
+
+ /* if operand has size of three or more & this
+ operation is a '*','/' or '%' then 'b' may
+ cause a problem */
+ if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
+ getSize (operandType (op)) >= 3)
+ return NULL;
+
+ /* if left or right or result is in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ isOperandInFarSpace (IC_RESULT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (dic)) ||
+ IS_OP_RUONLY (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_RESULT (dic)))
+ {
+ return NULL;
}
}
-
- OP_SYMBOL(op)->ruonly = 1;
- return sic;
-#endif
+
+ OP_SYMBOL (op)->ruonly = 1;
+ return sic;
+#endif
}
/*-----------------------------------------------------------------*/
/* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
/*-----------------------------------------------------------------*/
-static bool isBitwiseOptimizable (iCode *ic)
+static bool
+isBitwiseOptimizable (iCode * ic)
{
- sym_link *ltype = getSpec(operandType(IC_LEFT(ic)));
- sym_link *rtype = getSpec(operandType(IC_RIGHT(ic)));
-
- /* bitwise operations are considered optimizable
- under the following conditions (Jean-Louis VERN)
-
- x & lit
- bit & bit
- bit & x
- bit ^ bit
- bit ^ x
- x ^ lit
- x | lit
- bit | bit
- bit | x
- */
- if ( IS_LITERAL(rtype) ||
- (IS_BITVAR(ltype) && IN_BITSPACE(SPEC_OCLS(ltype))))
- return TRUE ;
- else
- return FALSE ;
+ sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
+ sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
+
+ /* bitwise operations are considered optimizable
+ under the following conditions (Jean-Louis VERN)
+
+ x & lit
+ bit & bit
+ bit & x
+ bit ^ bit
+ bit ^ x
+ x ^ lit
+ x | lit
+ bit | bit
+ bit | x
+ */
+ if (IS_LITERAL (rtype) ||
+ (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
+ return TRUE;
+ else
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* packRegsForAccUse - pack registers for acc use */
/*-----------------------------------------------------------------*/
-static void packRegsForAccUse (iCode *ic)
+static void
+packRegsForAccUse (iCode * ic)
{
- iCode *uic;
-
- /* if + or - then it has to be one byte result */
- if ((ic->op == '+' || ic->op == '-')
- && getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (ic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (ic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (IS_BITWISE_OP(ic) &&
- getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
-
- /* has only one definition */
- if (bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) > 1)
- return ;
-
- /* has only one use */
- if (bitVectnBitsOn(OP_USES(IC_RESULT(ic))) > 1)
- return ;
-
- /* and the usage immediately follows this iCode */
- if (!(uic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_USES(IC_RESULT(ic))))))
- return ;
-
- if (ic->next != uic)
- return ;
-
- /* if it is a conditional branch then we definitely can */
- if (uic->op == IFX )
- goto accuse;
-
- if ( uic->op == JUMPTABLE )
- return ;
-
- /* if the usage is not is an assignment
- or an arithmetic / bitwise / shift operation then not */
- if (POINTER_SET(uic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(uic)),FALSE)) > 1)
- return;
-
- if (uic->op != '=' &&
- !IS_ARITHMETIC_OP(uic) &&
- !IS_BITWISE_OP(uic) &&
- uic->op != LEFT_OP &&
- uic->op != RIGHT_OP )
- return;
-
- /* if used in ^ operation then make sure right is not a
- literl */
- if (uic->op == '^' && isOperandLiteral(IC_RIGHT(uic)))
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (uic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- if (uic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- /* make sure that the result of this icode is not on the
- stack, since acc is used to compute stack offset */
- if (IS_TRUE_SYMOP(IC_RESULT(uic)) &&
- OP_SYMBOL(IC_RESULT(uic))->onStack)
- return ;
-
- /* if either one of them in far space then we cannot */
- if ((IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- isOperandInFarSpace(IC_LEFT(uic))) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- isOperandInFarSpace(IC_RIGHT(uic))))
- return ;
-
- /* if the usage has only one operand then we can */
- if (IC_LEFT(uic) == NULL ||
- IC_RIGHT(uic) == NULL)
- goto accuse;
-
- /* make sure this is on the left side if not
- a '+' since '+' is commutative */
- if (ic->op != '+' &&
- IC_LEFT(uic)->key != IC_RESULT(ic)->key)
- return;
-
- /* if one of them is a literal then we can */
- if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) ||
- (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) {
- OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
- return ;
+ iCode *uic;
+
+ /* if + or - then it has to be one byte result */
+ if ((ic->op == '+' || ic->op == '-')
+ && getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (ic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ if (ic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ if (IS_BITWISE_OP (ic) &&
+ getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
+
+
+ /* has only one definition */
+ if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
+ return;
+
+ /* has only one use */
+ if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
+ return;
+
+ /* and the usage immediately follows this iCode */
+ if (!(uic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
+ return;
+
+ if (ic->next != uic)
+ return;
+
+ /* if it is a conditional branch then we definitely can */
+ if (uic->op == IFX)
+ goto accuse;
+
+ if (uic->op == JUMPTABLE)
+ return;
+
+ /* if the usage is not is an assignment
+ or an arithmetic / bitwise / shift operation then not */
+ if (POINTER_SET (uic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
+ return;
+
+ if (uic->op != '=' &&
+ !IS_ARITHMETIC_OP (uic) &&
+ !IS_BITWISE_OP (uic) &&
+ uic->op != LEFT_OP &&
+ uic->op != RIGHT_OP)
+ return;
+
+ /* if used in ^ operation then make sure right is not a
+ literl */
+ if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (uic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ if (uic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ /* make sure that the result of this icode is not on the
+ stack, since acc is used to compute stack offset */
+ if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
+ OP_SYMBOL (IC_RESULT (uic))->onStack)
+ return;
+
+ /* if either one of them in far space then we cannot */
+ if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ isOperandInFarSpace (IC_LEFT (uic))) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ isOperandInFarSpace (IC_RIGHT (uic))))
+ return;
+
+ /* if the usage has only one operand then we can */
+ if (IC_LEFT (uic) == NULL ||
+ IC_RIGHT (uic) == NULL)
+ goto accuse;
+
+ /* make sure this is on the left side if not
+ a '+' since '+' is commutative */
+ if (ic->op != '+' &&
+ IC_LEFT (uic)->key != IC_RESULT (ic)->key)
+ return;
+
+ /* if one of them is a literal then we can */
+ if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
+ (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
+ {
+ OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
+ return;
}
- /* if the other one is not on stack then we can */
- if (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_RIGHT(uic)) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- !OP_SYMBOL(IC_RIGHT(uic))->onStack)))
- goto accuse;
-
- if (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_LEFT(uic)) ||
- (IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- !OP_SYMBOL(IC_LEFT(uic))->onStack)))
- goto accuse ;
-
- return ;
-
- accuse:
- OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
-
-
+ /* if the other one is not on stack then we can */
+ if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_RIGHT (uic)) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
+ goto accuse;
+
+ if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_LEFT (uic)) ||
+ (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ !OP_SYMBOL (IC_LEFT (uic))->onStack)))
+ goto accuse;
+
+ return;
+
+accuse:
+ OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
+
+
}
/*-----------------------------------------------------------------*/
/* packForPush - hueristics to reduce iCode for pushing */
/*-----------------------------------------------------------------*/
-static void packForPush(iCode *ic, eBBlock *ebp)
+static void
+packForPush (iCode * ic, eBBlock * ebp)
{
- iCode *dic;
-
- if (ic->op != IPUSH || !IS_ITEMP(IC_LEFT(ic)))
- return ;
-
- /* must have only definition & one usage */
- if (bitVectnBitsOn(OP_DEFS(IC_LEFT(ic))) != 1 ||
- bitVectnBitsOn(OP_USES(IC_LEFT(ic))) != 1 )
- return ;
-
- /* find the definition */
- if (!(dic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(IC_LEFT(ic))))))
- return ;
-
- if (dic->op != '=' || POINTER_SET(dic))
- return;
-
- /* we now we know that it has one & only one def & use
- and the that the definition is an assignment */
- IC_LEFT(ic) = IC_RIGHT(dic);
-
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
+ iCode *dic;
+
+ if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
+ return;
+
+ /* must have only definition & one usage */
+ if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
+ bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
+ return;
+
+ /* find the definition */
+ if (!(dic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
+ return;
+
+ if (dic->op != '=' || POINTER_SET (dic))
+ return;
+
+ /* we now we know that it has one & only one def & use
+ and the that the definition is an assignment */
+ IC_LEFT (ic) = IC_RIGHT (dic);
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
}
/*-----------------------------------------------------------------*/
/* packRegisters - does some transformations to reduce register */
/* pressure */
/*-----------------------------------------------------------------*/
-static void packRegisters (eBBlock *ebp)
+static void
+packRegisters (eBBlock * ebp)
{
- iCode *ic ;
- int change = 0 ;
-
- while (1) {
-
- change = 0;
-
- /* look for assignments of the form */
- /* iTempNN = TRueSym (someoperation) SomeOperand */
- /* .... */
- /* TrueSym := iTempNN:1 */
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
-
- /* find assignment of the form TrueSym := iTempNN:1 */
- if (ic->op == '=' && !POINTER_SET(ic))
- change += packRegsForAssign(ic,ebp);
+ iCode *ic;
+ int change = 0;
+
+ while (1)
+ {
+
+ change = 0;
+
+ /* look for assignments of the form */
+ /* iTempNN = TRueSym (someoperation) SomeOperand */
+ /* .... */
+ /* TrueSym := iTempNN:1 */
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+
+ /* find assignment of the form TrueSym := iTempNN:1 */
+ if (ic->op == '=' && !POINTER_SET (ic))
+ change += packRegsForAssign (ic, ebp);
}
- if (!change)
- break;
+ if (!change)
+ break;
}
-
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
- /* if this is an itemp & result of a address of a true sym
- then mark this as rematerialisable */
- if (ic->op == ADDRESS_OF &&
- IS_ITEMP(IC_RESULT(ic)) &&
- IS_TRUE_SYMOP(IC_LEFT(ic)) &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- !OP_SYMBOL(IC_LEFT(ic))->onStack ) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an itemp & result of a address of a true sym
+ then mark this as rematerialisable */
+ if (ic->op == ADDRESS_OF &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ IS_TRUE_SYMOP (IC_LEFT (ic)) &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ !OP_SYMBOL (IC_LEFT (ic))->onStack)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
-
- /* if straight assignment then carry remat flag if
- this is the only definition */
- if (ic->op == '=' &&
- !POINTER_SET(ic) &&
- IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->remat &&
- bitVectnBitsOn(OP_SYMBOL(IC_RESULT(ic))->defs) <= 1) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat =
- OP_SYMBOL(IC_RIGHT(ic))->remat;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode =
- OP_SYMBOL(IC_RIGHT(ic))->rematiCode ;
+
+ /* if straight assignment then carry remat flag if
+ this is the only definition */
+ if (ic->op == '=' &&
+ !POINTER_SET (ic) &&
+ IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->remat &&
+ bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat =
+ OP_SYMBOL (IC_RIGHT (ic))->remat;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode =
+ OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
}
- /* if this is a +/- operation with a rematerizable
- then mark this as rematerializable as well */
- if ((ic->op == '+' || ic->op == '-') &&
- (IS_SYMOP(IC_LEFT(ic)) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->remat &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- IS_OP_LITERAL(IC_RIGHT(ic))) ) {
-
- //int i = operandLitValue(IC_RIGHT(ic));
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+ /* if this is a +/- operation with a rematerizable
+ then mark this as rematerializable as well */
+ if ((ic->op == '+' || ic->op == '-') &&
+ (IS_SYMOP (IC_LEFT (ic)) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->remat &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ IS_OP_LITERAL (IC_RIGHT (ic))))
+ {
+
+ //int i = operandLitValue(IC_RIGHT(ic));
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
- /* mark the pointer usages */
- if (POINTER_SET(ic))
- OP_SYMBOL(IC_RESULT(ic))->uptr = 1;
-
- if (POINTER_GET(ic))
- OP_SYMBOL(IC_LEFT(ic))->uptr = 1;
-
- if (!SKIP_IC2(ic)) {
- /* if we are using a symbol on the stack
- then we should say ds390_ptrRegReq */
- if (ic->op == IFX && IS_SYMOP(IC_COND(ic)))
- ds390_ptrRegReq += ((OP_SYMBOL(IC_COND(ic))->onStack ||
- OP_SYMBOL(IC_COND(ic))->iaccess) ? 1 : 0);
- else
- if (ic->op == JUMPTABLE && IS_SYMOP(IC_JTCOND(ic)))
- ds390_ptrRegReq += ((OP_SYMBOL(IC_JTCOND(ic))->onStack ||
- OP_SYMBOL(IC_JTCOND(ic))->iaccess) ? 1 : 0);
- else {
- if (IS_SYMOP(IC_LEFT(ic)))
- ds390_ptrRegReq += ((OP_SYMBOL(IC_LEFT(ic))->onStack ||
- OP_SYMBOL(IC_LEFT(ic))->iaccess) ? 1 : 0);
- if (IS_SYMOP(IC_RIGHT(ic)))
- ds390_ptrRegReq += ((OP_SYMBOL(IC_RIGHT(ic))->onStack ||
- OP_SYMBOL(IC_RIGHT(ic))->iaccess) ? 1 : 0);
- if (IS_SYMOP(IC_RESULT(ic)))
- ds390_ptrRegReq += ((OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess) ? 1 : 0);
- }
+ /* mark the pointer usages */
+ if (POINTER_SET (ic))
+ OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
+
+ if (POINTER_GET (ic))
+ OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
+
+ if (!SKIP_IC2 (ic))
+ {
+ /* if we are using a symbol on the stack
+ then we should say ds390_ptrRegReq */
+ if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
+ ds390_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ||
+ OP_SYMBOL (IC_COND (ic))->iaccess) ? 1 : 0);
+ else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
+ ds390_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ||
+ OP_SYMBOL (IC_JTCOND (ic))->iaccess) ? 1 : 0);
+ else
+ {
+ if (IS_SYMOP (IC_LEFT (ic)))
+ ds390_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ||
+ OP_SYMBOL (IC_LEFT (ic))->iaccess) ? 1 : 0);
+ if (IS_SYMOP (IC_RIGHT (ic)))
+ ds390_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ||
+ OP_SYMBOL (IC_RIGHT (ic))->iaccess) ? 1 : 0);
+ if (IS_SYMOP (IC_RESULT (ic)))
+ ds390_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess) ? 1 : 0);
+ }
}
- /* if the condition of an if instruction
- is defined in the previous instruction then
- mark the itemp as a conditional */
- if ((IS_CONDITIONAL(ic) ||
- ( ( ic->op == BITWISEAND ||
- ic->op == '|' ||
- ic->op == '^' ) &&
- isBitwiseOptimizable(ic))) &&
- ic->next && ic->next->op == IFX &&
- isOperandEqual(IC_RESULT(ic),IC_COND(ic->next)) &&
- OP_SYMBOL(IC_RESULT(ic))->liveTo <= ic->next->seq) {
-
- OP_SYMBOL(IC_RESULT(ic))->regType = REG_CND;
- continue ;
+ /* if the condition of an if instruction
+ is defined in the previous instruction then
+ mark the itemp as a conditional */
+ if ((IS_CONDITIONAL (ic) ||
+ ((ic->op == BITWISEAND ||
+ ic->op == '|' ||
+ ic->op == '^') &&
+ isBitwiseOptimizable (ic))) &&
+ ic->next && ic->next->op == IFX &&
+ isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
+ OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
+ continue;
}
-
- /* reduce for support function calls */
- if (ic->supportRtn || ic->op == '+' || ic->op == '-' )
- packRegsForSupport (ic,ebp);
-
- /* some cases the redundant moves can
- can be eliminated for return statements */
- if ((ic->op == RETURN || ic->op == SEND) &&
- !isOperandInFarSpace(IC_LEFT(ic)) &&
- !options.model)
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
-
- /* if pointer set & left has a size more than
- one and right is not in far space */
- if (POINTER_SET(ic) &&
- !isOperandInFarSpace(IC_RIGHT(ic)) &&
- !OP_SYMBOL(IC_RESULT(ic))->remat &&
- !IS_OP_RUONLY(IC_RIGHT(ic)) &&
- getSize(aggrToPtr(operandType(IC_RESULT(ic)),FALSE)) > 1 )
-
- packRegsForOneuse (ic,IC_RESULT(ic),ebp);
-
- /* if pointer get */
- if (POINTER_GET(ic) &&
- !isOperandInFarSpace(IC_RESULT(ic))&&
- !OP_SYMBOL(IC_LEFT(ic))->remat &&
- !IS_OP_RUONLY(IC_RESULT(ic)) &&
- getSize(aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) > 1 )
-
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
-
-
- /* if this is cast for intergral promotion then
- check if only use of the definition of the
- operand being casted/ if yes then replace
- the result of that arithmetic operation with
- this result and get rid of the cast */
- if (ic->op == CAST) {
- sym_link *fromType = operandType(IC_RIGHT(ic));
- sym_link *toType = operandType(IC_LEFT(ic));
-
- if (IS_INTEGRAL(fromType) && IS_INTEGRAL(toType) &&
- getSize(fromType) != getSize(toType) &&
- SPEC_USIGN(fromType) == SPEC_USIGN(toType)) {
-
- iCode *dic = packRegsForOneuse(ic,IC_RIGHT(ic),ebp);
- if (dic) {
- if (IS_ARITHMETIC_OP(dic)) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- ic = ic->prev;
- } else
- OP_SYMBOL(IC_RIGHT(ic))->ruonly = 0;
- }
- } else {
-
- /* if the type from and type to are the same
- then if this is the only use then packit */
- if (checkType(operandType(IC_RIGHT(ic)),
- operandType(IC_LEFT(ic))) == 1) {
- iCode *dic = packRegsForOneuse (ic,IC_RIGHT(ic),ebp);
- if (dic) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- ic = ic->prev;
+
+ /* reduce for support function calls */
+ if (ic->supportRtn || ic->op == '+' || ic->op == '-')
+ packRegsForSupport (ic, ebp);
+
+ /* some cases the redundant moves can
+ can be eliminated for return statements */
+ if ((ic->op == RETURN || ic->op == SEND) &&
+ !isOperandInFarSpace (IC_LEFT (ic)) &&
+ !options.model)
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+
+ /* if pointer set & left has a size more than
+ one and right is not in far space */
+ if (POINTER_SET (ic) &&
+ !isOperandInFarSpace (IC_RIGHT (ic)) &&
+ !OP_SYMBOL (IC_RESULT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RIGHT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
+
+ packRegsForOneuse (ic, IC_RESULT (ic), ebp);
+
+ /* if pointer get */
+ if (POINTER_GET (ic) &&
+ !isOperandInFarSpace (IC_RESULT (ic)) &&
+ !OP_SYMBOL (IC_LEFT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RESULT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
+
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+
+
+ /* if this is cast for intergral promotion then
+ check if only use of the definition of the
+ operand being casted/ if yes then replace
+ the result of that arithmetic operation with
+ this result and get rid of the cast */
+ if (ic->op == CAST)
+ {
+ sym_link *fromType = operandType (IC_RIGHT (ic));
+ sym_link *toType = operandType (IC_LEFT (ic));
+
+ if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
+ getSize (fromType) != getSize (toType) &&
+ SPEC_USIGN (fromType) == SPEC_USIGN (toType))
+ {
+
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ if (IS_ARITHMETIC_OP (dic))
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ ic = ic->prev;
+ }
+ else
+ OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
+ }
+ }
+ else
+ {
+
+ /* if the type from and type to are the same
+ then if this is the only use then packit */
+ if (checkType (operandType (IC_RIGHT (ic)),
+ operandType (IC_LEFT (ic))) == 1)
+ {
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ ic = ic->prev;
}
}
}
}
-
- /* pack for PUSH
- iTempNN := (some variable in farspace) V1
- push iTempNN ;
- -------------
- push V1
- */
- if (ic->op == IPUSH ) {
- packForPush(ic,ebp);
+
+ /* pack for PUSH
+ iTempNN := (some variable in farspace) V1
+ push iTempNN ;
+ -------------
+ push V1
+ */
+ if (ic->op == IPUSH)
+ {
+ packForPush (ic, ebp);
}
-
-
- /* pack registers for accumulator use, when the
- result of an arithmetic or bit wise operation
- has only one use, that use is immediately following
- the defintion and the using iCode has only one
- operand or has two operands but one is literal &
- the result of that operation is not on stack then
- we can leave the result of this operation in acc:b
- combination */
- if ((IS_ARITHMETIC_OP(ic)
-
- || IS_BITWISE_OP(ic)
-
- || ic->op == LEFT_OP || ic->op == RIGHT_OP
-
- ) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- getSize(operandType(IC_RESULT(ic))) <= 2)
-
- packRegsForAccUse (ic);
+
+
+ /* pack registers for accumulator use, when the
+ result of an arithmetic or bit wise operation
+ has only one use, that use is immediately following
+ the defintion and the using iCode has only one
+ operand or has two operands but one is literal &
+ the result of that operation is not on stack then
+ we can leave the result of this operation in acc:b
+ combination */
+ if ((IS_ARITHMETIC_OP (ic)
+
+ || IS_BITWISE_OP (ic)
+
+ || ic->op == LEFT_OP || ic->op == RIGHT_OP
+
+ ) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ getSize (operandType (IC_RESULT (ic))) <= 2)
+
+ packRegsForAccUse (ic);
}
}
-
+
/*-----------------------------------------------------------------*/
/* assignRegisters - assigns registers to each live range as need */
/*-----------------------------------------------------------------*/
-void ds390_assignRegisters (eBBlock **ebbs, int count)
+void
+ds390_assignRegisters (eBBlock ** ebbs, int count)
{
- iCode *ic;
- int i ;
-
- setToNull((void *)&_G.funcrUsed);
- ds390_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
- /* if not register extentions then reduce number
- of registers */
- if (options.regExtend)
- ds390_nRegs = 13;
- else
- ds390_nRegs = 8;
-
- /* change assignments this will remove some
- live ranges reducing some register pressure */
- for (i = 0 ; i < count ;i++ )
- packRegisters (ebbs[i]);
-
- if (options.dump_pack)
- dumpEbbsToFileExt(".dumppack",ebbs,count);
-
- /* first determine for each live range the number of
- registers & the type of registers required for each */
- regTypeNum ();
-
- /* and serially allocate registers */
- serialRegAssign(ebbs,count);
-
- /* if stack was extended then tell the user */
- if (_G.stackExtend) {
-/* werror(W_TOOMANY_SPILS,"stack", */
-/* _G.stackExtend,currFunc->name,""); */
- _G.stackExtend = 0 ;
+ iCode *ic;
+ int i;
+
+ setToNull ((void *) &_G.funcrUsed);
+ ds390_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
+ /* if not register extentions then reduce number
+ of registers */
+ if (options.regExtend)
+ ds390_nRegs = 13;
+ else
+ ds390_nRegs = 8;
+
+ /* change assignments this will remove some
+ live ranges reducing some register pressure */
+ for (i = 0; i < count; i++)
+ packRegisters (ebbs[i]);
+
+ if (options.dump_pack)
+ dumpEbbsToFileExt (".dumppack", ebbs, count);
+
+ /* first determine for each live range the number of
+ registers & the type of registers required for each */
+ regTypeNum ();
+
+ /* and serially allocate registers */
+ serialRegAssign (ebbs, count);
+
+ /* if stack was extended then tell the user */
+ if (_G.stackExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"stack", */
+/* _G.stackExtend,currFunc->name,""); */
+ _G.stackExtend = 0;
}
- if (_G.dataExtend) {
-/* werror(W_TOOMANY_SPILS,"data space", */
-/* _G.dataExtend,currFunc->name,""); */
- _G.dataExtend = 0 ;
- }
+ if (_G.dataExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"data space", */
+/* _G.dataExtend,currFunc->name,""); */
+ _G.dataExtend = 0;
+ }
- /* after that create the register mask
- for each of the instruction */
- createRegMask (ebbs,count);
+ /* after that create the register mask
+ for each of the instruction */
+ createRegMask (ebbs, count);
- /* redo that offsets for stacked automatic variables */
- redoStackOffsets ();
+ /* redo that offsets for stacked automatic variables */
+ redoStackOffsets ();
- if (options.dump_rassgn)
- dumpEbbsToFileExt(".dumprassgn",ebbs,count);
+ if (options.dump_rassgn)
+ dumpEbbsToFileExt (".dumprassgn", ebbs, count);
- /* do the overlaysegment stuff SDCCmem.c */
- doOverlays(ebbs,count);
+ /* do the overlaysegment stuff SDCCmem.c */
+ doOverlays (ebbs, count);
- /* now get back the chain */
- ic = iCodeLabelOptimize(iCodeFromeBBlock (ebbs,count));
+ /* now get back the chain */
+ ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
- gen390Code(ic);
+ gen390Code (ic);
- /* free up any _G.stackSpil locations allocated */
- applyToSet(_G.stackSpil,deallocStackSpil);
- _G.slocNum = 0;
- setToNull((void **)&_G.stackSpil);
- setToNull((void **)&_G.spiltSet);
- /* mark all registers as free */
- freeAllRegs();
+ /* free up any _G.stackSpil locations allocated */
+ applyToSet (_G.stackSpil, deallocStackSpil);
+ _G.slocNum = 0;
+ setToNull ((void **) &_G.stackSpil);
+ setToNull ((void **) &_G.spiltSet);
+ /* mark all registers as free */
+ freeAllRegs ();
- return ;
+ return;
}
#ifndef SDCCRALLOC_H
#define SDCCRALLOC_H 1
-enum { R2_IDX = 0, R3_IDX , R4_IDX ,
- R5_IDX ,R6_IDX , R7_IDX ,
- R0_IDX ,R1_IDX , X8_IDX ,
- X9_IDX ,X10_IDX , X11_IDX ,
- X12_IDX ,CND_IDX };
+enum
+ {
+ R2_IDX = 0, R3_IDX, R4_IDX,
+ R5_IDX, R6_IDX, R7_IDX,
+ R0_IDX, R1_IDX, X8_IDX,
+ X9_IDX, X10_IDX, X11_IDX,
+ X12_IDX, CND_IDX
+ };
#define REG_PTR 0x01
#define REG_CND 0x04
/* definition for the registers */
typedef struct regs
-{
- short type; /* can have value
- REG_GPR, REG_PTR or REG_CND */
- short rIdx ; /* index into register table */
- short otype;
- char *name ; /* name */
- char *dname; /* name when direct access needed */
- char *base ; /* base address */
- short offset; /* offset from the base */
- unsigned isFree :1; /* is currently unassigned */
-} regs;
+ {
+ short type; /* can have value
+ REG_GPR, REG_PTR or REG_CND */
+ short rIdx; /* index into register table */
+ short otype;
+ char *name; /* name */
+ char *dname; /* name when direct access needed */
+ char *base; /* base address */
+ short offset; /* offset from the base */
+ unsigned isFree:1; /* is currently unassigned */
+ }
+regs;
extern regs regs390[];
-regs *ds390_regWithIdx (int);
+regs *ds390_regWithIdx (int);
extern int ds390_ptrRegReq;
extern int ds390_nRegs;
#include "izt.h"
#include "gen.h"
-static struct {
- struct {
+static struct
+ {
+ struct
+ {
lineNode *head;
lineNode *current;
- } lines;
- struct {
+ }
+ lines;
+ struct
+ {
hTab *base;
hTab *proc;
- } htabs;
-} _G;
+ }
+ htabs;
+ }
+_G;
-static void _tidyUp(char *buf)
+static void
+_tidyUp (char *buf)
{
- // Clean up the line so that it is 'prettier'.
- if (*buf == ';') {
- // If this is a comment line (starts with a ';') then indent it.
- // PENDING: The outputter does its own pretty print. Disable for now.
+ // Clean up the line so that it is 'prettier'.
+ if (*buf == ';')
+ {
+ // If this is a comment line (starts with a ';') then indent it.
+ // PENDING: The outputter does its own pretty print. Disable for now.
}
- else if (strchr(buf, ':')) {
- // Is a label - cant do anything.
+ else if (strchr (buf, ':'))
+ {
+ // Is a label - cant do anything.
}
- else {
- /* Change the first (and probably only) ' ' to a tab so
- everything lines up.
- */
- while (*buf) {
- if (*buf == ' ') {
- *buf = '\t';
- return;
+ else
+ {
+ /* Change the first (and probably only) ' ' to a tab so
+ everything lines up.
+ */
+ while (*buf)
+ {
+ if (*buf == ' ')
+ {
+ *buf = '\t';
+ return;
}
- buf++;
+ buf++;
}
}
}
-void iemit(const char *szFormat, ...)
+void
+iemit (const char *szFormat,...)
{
- char buffer[1024];
- va_list ap;
+ char buffer[1024];
+ va_list ap;
- va_start(ap, szFormat);
+ va_start (ap, szFormat);
- tvsprintf(buffer, szFormat, ap);
+ tvsprintf (buffer, szFormat, ap);
- _tidyUp(buffer);
+ _tidyUp (buffer);
- if (_G.lines.current == NULL) {
- _G.lines.head = newLineNode(buffer);
- _G.lines.current = _G.lines.head;
+ if (_G.lines.current == NULL)
+ {
+ _G.lines.head = newLineNode (buffer);
+ _G.lines.current = _G.lines.head;
}
- else {
- _G.lines.current = connectLine(_G.lines.current, newLineNode(buffer));
+ else
+ {
+ _G.lines.current = connectLine (_G.lines.current, newLineNode (buffer));
}
-
- // PENDING: Inline support.
- // _G.lines.current->isInline = inLine;
+
+ // PENDING: Inline support.
+ // _G.lines.current->isInline = inLine;
}
// Mapping between operand type and a friendly name.
-typedef struct {
- const int op;
- const char *name;
-} OPNAME;
-
-static OPNAME _opnames[] = {
- { '!' , "genNot" },
- { '~' , "genCpl" },
- { UNARYMINUS, "genUminus" },
- { IPUSH, "genIpush" },
- { IPOP, "genIfx" },
- { CALL, "genCall" },
- { PCALL, "genPcall" },
- { FUNCTION, "genFunction" },
- { ENDFUNCTION, "genEndFunction" },
- { RETURN, "genRet" },
- { LABEL, "genLabel" },
- { GOTO, "genGoto" },
- { '+' , "genPlus" },
- { '-' , "genMinus" },
- { '*' , "genMult" },
- { '/' , "genDiv" },
- { '%' , "genMod" },
- { '>' , "genCmpGt" },
- { '<' , "genCmpLt" },
- { EQ_OP, "genCmpEq" },
- { AND_OP, "genAndOp" },
- { OR_OP, "genOrOp" },
- { '^' , "genXor" },
- { '|' , "genOr" },
- { BITWISEAND, "genAnd" },
- { INLINEASM, "genInline" },
- { RRC, "genRRC" },
- { RLC, "genRLC" },
- { GETHBIT, "genHBIT" },
- { LEFT_OP, "genLeftShift" },
- { RIGHT_OP, "genRightShift" },
- { GET_VALUE_AT_ADDRESS, "genPointerGet" },
- { '=', "genAssign" },
- { IFX, "genIfx" },
- { ADDRESS_OF, "genAddrOf" },
- { JUMPTABLE, "genJumpTab" },
- { CAST, "genCast" },
- { RECEIVE, "genReceive" },
- { SEND, "addSet" },
- { 0, NULL }
+typedef struct
+{
+ const int op;
+ const char *name;
+}
+OPNAME;
+
+static OPNAME _opnames[] =
+{
+ {'!', "genNot"},
+ {'~', "genCpl"},
+ {UNARYMINUS, "genUminus"},
+ {IPUSH, "genIpush"},
+ {IPOP, "genIfx"},
+ {CALL, "genCall"},
+ {PCALL, "genPcall"},
+ {FUNCTION, "genFunction"},
+ {ENDFUNCTION, "genEndFunction"},
+ {RETURN, "genRet"},
+ {LABEL, "genLabel"},
+ {GOTO, "genGoto"},
+ {'+', "genPlus"},
+ {'-', "genMinus"},
+ {'*', "genMult"},
+ {'/', "genDiv"},
+ {'%', "genMod"},
+ {'>', "genCmpGt"},
+ {'<', "genCmpLt"},
+ {EQ_OP, "genCmpEq"},
+ {AND_OP, "genAndOp"},
+ {OR_OP, "genOrOp"},
+ {'^', "genXor"},
+ {'|', "genOr"},
+ {BITWISEAND, "genAnd"},
+ {INLINEASM, "genInline"},
+ {RRC, "genRRC"},
+ {RLC, "genRLC"},
+ {GETHBIT, "genHBIT"},
+ {LEFT_OP, "genLeftShift"},
+ {RIGHT_OP, "genRightShift"},
+ {GET_VALUE_AT_ADDRESS, "genPointerGet"},
+ {'=', "genAssign"},
+ {IFX, "genIfx"},
+ {ADDRESS_OF, "genAddrOf"},
+ {JUMPTABLE, "genJumpTab"},
+ {CAST, "genCast"},
+ {RECEIVE, "genReceive"},
+ {SEND, "addSet"},
+ {0, NULL}
};
// Possible return codes for a find matcher.
-enum {
+enum
+ {
FIND_LESS_THAN = -1,
// This element does match.
FIND_MATCH = 0,
FIND_NO_MATCH = FIND_GREATER_THAN,
// This element marks the end of list.
FIND_EOL
-};
+ };
// Limits the given integer to the find result numbers.
-static int _limitToFind(int i)
+static int
+_limitToFind (int i)
{
- if (i < 0) {
- return FIND_LESS_THAN;
+ if (i < 0)
+ {
+ return FIND_LESS_THAN;
}
- else if (i > 0) {
- return FIND_GREATER_THAN;
+ else if (i > 0)
+ {
+ return FIND_GREATER_THAN;
}
- else {
- return FIND_MATCH;
+ else
+ {
+ return FIND_MATCH;
}
}
// Matches an opname id to the given id.
-static int _opnamesMatcher(void *pthis, void *pkey)
+static int
+_opnamesMatcher (void *pthis, void *pkey)
{
- OPNAME *name = pthis;
+ OPNAME *name = pthis;
- if (name->name == NULL) {
- return FIND_EOL;
+ if (name->name == NULL)
+ {
+ return FIND_EOL;
}
- else {
- return _limitToFind(name->op - *(int *)pkey);
+ else
+ {
+ return _limitToFind (name->op - *(int *) pkey);
}
}
// Find an element of an unordered list.
-static void *_find(void *base, size_t elemSize, void *pkey, int (*match)(void *pthis, void *pkey))
+static void *
+_find (void *base, size_t elemSize, void *pkey, int (*match) (void *pthis, void *pkey))
{
- do {
- switch (match(base, pkey)) {
+ do
+ {
+ switch (match (base, pkey))
+ {
case FIND_MATCH:
- return base;
+ return base;
case FIND_EOL:
- return NULL;
+ return NULL;
case FIND_LESS_THAN:
case FIND_GREATER_THAN:
- base = (char *)base + elemSize;
- break;
+ base = (char *) base + elemSize;
+ break;
default:
- wassert(0);
+ wassert (0);
}
- } while (1);
+ }
+ while (1);
}
// Finds the friendly operation name for an op number.
-static const char *_findOpName(int op) {
- OPNAME *name = _find(_opnames, sizeof(*_opnames), &op, _opnamesMatcher);
- if (name) {
- return name->name;
+static const char *
+_findOpName (int op)
+{
+ OPNAME *name = _find (_opnames, sizeof (*_opnames), &op, _opnamesMatcher);
+ if (name)
+ {
+ return name->name;
}
- else {
- return NULL;
+ else
+ {
+ return NULL;
}
}
// PENDING
-static bool _isResultRemat (iCode *ic)
+static bool
+_isResultRemat (iCode * ic)
{
- if (SKIP_IC(ic) || ic->op == IFX)
- return 0;
-
- if (IC_RESULT(ic) && IS_ITEMP(IC_RESULT(ic))) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- if (sym->remat && !POINTER_SET(ic))
- return 1;
- }
-
+ if (SKIP_IC (ic) || ic->op == IFX)
return 0;
+
+ if (IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic)))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ if (sym->remat && !POINTER_SET (ic))
+ return 1;
+ }
+
+ return 0;
}
// Print out the generated lines.
-static void _printLines(void)
+static void
+_printLines (void)
{
- // Currently a holder function. The Z80 needs some special mangling
- // for bank support.
- printLine(_G.lines.head, codeOutFile);
+ // Currently a holder function. The Z80 needs some special mangling
+ // for bank support.
+ printLine (_G.lines.head, codeOutFile);
}
-void izt_initEmitters(void)
+void
+izt_initEmitters (void)
{
- _G.htabs.base = newHashTable(100);
- _G.htabs.proc = newHashTable(100);
+ _G.htabs.base = newHashTable (100);
+ _G.htabs.proc = newHashTable (100);
- izt_initBaseEmitters(&_G.htabs.base);
+ izt_initBaseEmitters (&_G.htabs.base);
}
-static int _emitterCompare(const void *p1, const void *p2)
+static int
+_emitterCompare (const void *p1, const void *p2)
{
- wassert(p1);
- wassert(p2);
- return ((EMITTER *)p1)->op == ((EMITTER *)p2)->op;
+ wassert (p1);
+ wassert (p2);
+ return ((EMITTER *) p1)->op == ((EMITTER *) p2)->op;
}
-static bool _tryEmittingiCode(hTab *h, iCode *ic)
+static bool
+_tryEmittingiCode (hTab * h, iCode * ic)
{
- EMITTER key = { ic->op, NULL };
- EMITTER *found;
+ EMITTER key =
+ {ic->op, NULL};
+ EMITTER *found;
- found = hTabFindByKey(h, ic->op, &key, _emitterCompare);
+ found = hTabFindByKey (h, ic->op, &key, _emitterCompare);
- if (found) {
- found->emit(ic);
- return TRUE;
+ if (found)
+ {
+ found->emit (ic);
+ return TRUE;
}
- else {
- return FALSE;
+ else
+ {
+ return FALSE;
}
}
// Add a NULL terminated array of emitters into the given hash table.
-void izt_addEmittersToHTab(hTab **into, EMITTER _base_emitters[])
+void
+izt_addEmittersToHTab (hTab ** into, EMITTER _base_emitters[])
{
- while (_base_emitters->emit != NULL) {
- hTabAddItemLong(into, _base_emitters->op, _base_emitters, _base_emitters);
- _base_emitters++;
+ while (_base_emitters->emit != NULL)
+ {
+ hTabAddItemLong (into, _base_emitters->op, _base_emitters, _base_emitters);
+ _base_emitters++;
}
}
-void izt_gen(iCode *iic)
+void
+izt_gen (iCode * iic)
{
- iCode *ic = iic;
- int cln = 0;
+ iCode *ic = iic;
+ int cln = 0;
- _G.lines.head = NULL;
- _G.lines.current = NULL;
+ _G.lines.head = NULL;
+ _G.lines.current = NULL;
- // No debug info support.
-
- for (; ic; ic = ic->next) {
- const char *name;
+ // No debug info support.
- // Print out the source file line number.
- if (cln != ic->lineno) {
- iemit("; %s %d", ic->filename, ic->lineno);
- cln = ic->lineno ;
+ for (; ic; ic = ic->next)
+ {
+ const char *name;
+
+ // Print out the source file line number.
+ if (cln != ic->lineno)
+ {
+ iemit ("; %s %d", ic->filename, ic->lineno);
+ cln = ic->lineno;
}
- if (ic->generated) {
- // Code has already been generated. Skip.
- continue;
+ if (ic->generated)
+ {
+ // Code has already been generated. Skip.
+ continue;
}
- if (_isResultRemat(ic)) {
- // The code is spilt and remat. - no need to generate.
- continue;
+ if (_isResultRemat (ic))
+ {
+ // The code is spilt and remat. - no need to generate.
+ continue;
}
-
- // Print the friendly name of the operation, if it has one.
- name = _findOpName(ic->op);
- if (name) {
- iemit("; %s", name);
+
+ // Print the friendly name of the operation, if it has one.
+ name = _findOpName (ic->op);
+ if (name)
+ {
+ iemit ("; %s", name);
}
- else {
- iemit("; warning: unrecognised operation name for %u", ic->op);
+ else
+ {
+ iemit ("; warning: unrecognised operation name for %u", ic->op);
}
- fflush(stdout);
- // Now actually call the code generator.
- // The current processor handler gets first try.
- if (_tryEmittingiCode(_G.htabs.proc, ic)) {
- // Yay.
+ fflush (stdout);
+ // Now actually call the code generator.
+ // The current processor handler gets first try.
+ if (_tryEmittingiCode (_G.htabs.proc, ic))
+ {
+ // Yay.
}
- else if (_tryEmittingiCode(_G.htabs.base, ic)) {
- // Base handler took it.
+ else if (_tryEmittingiCode (_G.htabs.base, ic))
+ {
+ // Base handler took it.
}
- else {
- // None took it. Warn the developer.
- iemit("; warning: no handler for code %u", ic->op);
+ else
+ {
+ // None took it. Warn the developer.
+ iemit ("; warning: no handler for code %u", ic->op);
}
}
- // Pass the code through the peephole optimiser.
- if (!options.nopeep) {
- peepHole(&_G.lines.head);
+ // Pass the code through the peephole optimiser.
+ if (!options.nopeep)
+ {
+ peepHole (&_G.lines.head);
}
- // And emit the remainder.
- _printLines();
+ // And emit the remainder.
+ _printLines ();
}
-
#define IZT_GEN_INCLUDE
// Emit a line of code.
-void iemit(const char *format, ...);
+void iemit (const char *format,...);
// Generic descripter for a function that can emit a type of iCode.
-typedef struct {
+typedef struct
+ {
int op;
- void (*emit)(iCode *ic);
-} EMITTER;
+ void (*emit) (iCode * ic);
+ }
+EMITTER;
// Call the base izt handler to handle this iCode.
-void izt_baseEmitter(iCode *ic);
+void izt_baseEmitter (iCode * ic);
// Initialise the base emitter table.
-void izt_initBaseEmitters(hTab **into);
+void izt_initBaseEmitters (hTab ** into);
// Add a NULL terminated array of emitters into the given hash table.
-void izt_addEmittersToHTab(hTab **into, EMITTER _base_emitters[]);
+void izt_addEmittersToHTab (hTab ** into, EMITTER _base_emitters[]);
// Initialise the emitter tables.
-void izt_initEmitters(void);
+void izt_initEmitters (void);
#endif
-
#include "izt.h"
#include "gen.h"
-static void _genLabel(iCode *ic)
+static void
+_genLabel (iCode * ic)
{
- iemit("!tlabeldef", IC_LABEL(ic)->key + 100);
+ iemit ("!tlabeldef", IC_LABEL (ic)->key + 100);
}
-static void _genGoto(iCode *ic)
+static void
+_genGoto (iCode * ic)
{
- iemit("jp !tlabel", IC_LABEL(ic)->key+100);
+ iemit ("jp !tlabel", IC_LABEL (ic)->key + 100);
}
-static void _genFunction(iCode *ic)
+static void
+_genFunction (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
- // Create the function header
- iemit("!functionheader", sym->name);
- iemit("!functionlabeldef", sym->rname);
+ // Create the function header
+ iemit ("!functionheader", sym->name);
+ iemit ("!functionlabeldef", sym->rname);
- if (sym->stack) {
- iemit("!enterx", sym->stack);
+ if (sym->stack)
+ {
+ iemit ("!enterx", sym->stack);
}
- else {
- iemit("!enter");
+ else
+ {
+ iemit ("!enter");
}
}
-static void _genReturn(iCode *ic)
+static void
+_genReturn (iCode * ic)
{
- if (IC_LEFT(ic)) {
- // Has a return value. Load it up.
- iemit("; PENDING: call the generic loader to setup the return value.");
+ if (IC_LEFT (ic))
+ {
+ // Has a return value. Load it up.
+ iemit ("; PENDING: call the generic loader to setup the return value.");
}
- if (ic->next && ic->next->op == LABEL && IC_LABEL(ic->next) == returnLabel) {
- // The next label is the return label. Dont bother emitting a jump.
+ if (ic->next && ic->next->op == LABEL && IC_LABEL (ic->next) == returnLabel)
+ {
+ // The next label is the return label. Dont bother emitting a jump.
}
- else {
- iemit("jp !tlabel", returnLabel->key+100);
+ else
+ {
+ iemit ("jp !tlabel", returnLabel->key + 100);
}
}
-static EMITTER _base_emitters[] = {
- { LABEL, _genLabel },
- { GOTO, _genGoto },
- { FUNCTION, _genFunction },
- { RETURN, _genReturn },
- { 0, NULL }
+static EMITTER _base_emitters[] =
+{
+ {LABEL, _genLabel},
+ {GOTO, _genGoto},
+ {FUNCTION, _genFunction},
+ {RETURN, _genReturn},
+ {0, NULL}
};
-void izt_initBaseEmitters(hTab **into)
+void
+izt_initBaseEmitters (hTab ** into)
{
- izt_addEmittersToHTab(into, _base_emitters);
+ izt_addEmittersToHTab (into, _base_emitters);
}
*/
#include "izt.h"
-static REG _i186_regs[] = {
- { 1, REG_ID_CL, "cl", 0, { REG_ID_CX, REG_ID_NONE, REG_ID_NONE } },
- { 1, REG_ID_CH, "ch", 0, { REG_ID_CX, REG_ID_NONE, REG_ID_NONE } },
- { 1, REG_ID_DL, "dl", 0, { REG_ID_DX, REG_ID_NONE, REG_ID_NONE } },
- { 1, REG_ID_DH, "dh", 0, { REG_ID_DX, REG_ID_NONE, REG_ID_NONE } },
- { 2, REG_ID_CX, "cx", 0, { REG_ID_CL, REG_ID_CH, REG_ID_NONE } },
- { 2, REG_ID_DX, "dx", 0, { REG_ID_DL, REG_ID_DH, REG_ID_NONE } },
- { 0, REG_ID_NONE,"??", 0, { REG_ID_NONE, REG_ID_NONE, REG_ID_NONE } }
+static REG _i186_regs[] =
+{
+ {1, REG_ID_CL, "cl", 0,
+ {REG_ID_CX, REG_ID_NONE, REG_ID_NONE}},
+ {1, REG_ID_CH, "ch", 0,
+ {REG_ID_CX, REG_ID_NONE, REG_ID_NONE}},
+ {1, REG_ID_DL, "dl", 0,
+ {REG_ID_DX, REG_ID_NONE, REG_ID_NONE}},
+ {1, REG_ID_DH, "dh", 0,
+ {REG_ID_DX, REG_ID_NONE, REG_ID_NONE}},
+ {2, REG_ID_CX, "cx", 0,
+ {REG_ID_CL, REG_ID_CH, REG_ID_NONE}},
+ {2, REG_ID_DX, "dx", 0,
+ {REG_ID_DL, REG_ID_DH, REG_ID_NONE}},
+ {0, REG_ID_NONE, "??", 0,
+ {REG_ID_NONE, REG_ID_NONE, REG_ID_NONE}}
};
-static IZT_PORT _i186_port = {
- _i186_regs
+static IZT_PORT _i186_port =
+{
+ _i186_regs
};
static char _defaultRules[] =
};
/* list of key words used by i186 */
-static char *_i186_keywords[] = {
- NULL
+static char *_i186_keywords[] =
+{
+ NULL
};
// PENDING: A default set of mappings to make asm.c happy.
-static const ASM_MAPPING _asxxxx_z80_mapping[] = {
+static const ASM_MAPPING _asxxxx_z80_mapping[] =
+{
/* We want to prepend the _ */
- { "area", ".area _%s" },
- { "areacode", ".area _%s" },
- { "areadata", ".area _%s" },
- { "areahome", ".area _%s" },
- { "*ixx", "%d(ix)" },
- { "*iyx", "%d(iy)" },
- { "*hl", "(hl)" },
- { "di", "di" },
- { "ldahli",
- "ld a,(hl)\n"
- "\tinc\thl" },
- { "ldahlsp",
- "ld hl,#%d\n"
- "\tadd\thl,sp" },
- { "ldaspsp",
- "ld hl,#%d\n"
- "\tadd\thl,sp\n"
- "\tld\tsp,hl" },
- { "*pair", "(%s)" },
- { "shortjp", "jp" },
- { "enter",
- "push\tix\n"
- "\tld\tix,#0\n"
- "\tadd\tix,sp" },
- { "enterx",
- "push\tix\n"
- "\tld\tix,#0\n"
- "\tadd\tix,sp\n"
- "\tld\thl,#-%d\n"
- "\tadd\thl,sp\n"
- "\tld\tsp,hl" },
- { "leave",
- "pop\tix\n"
- },
- { "leavex",
- "ld sp,ix\n"
- "\tpop\tix\n"
- },
- { "pusha",
- "push af\n"
- "\tpush\tbc\n"
- "\tpush\tde\n"
- "\tpush\thl"
- },
- { "adjustsp", "lda sp,-%d(sp)" },
- { NULL, NULL }
+ {"area", ".area _%s"},
+ {"areacode", ".area _%s"},
+ {"areadata", ".area _%s"},
+ {"areahome", ".area _%s"},
+ {"*ixx", "%d(ix)"},
+ {"*iyx", "%d(iy)"},
+ {"*hl", "(hl)"},
+ {"di", "di"},
+ {"ldahli",
+ "ld a,(hl)\n"
+ "\tinc\thl"},
+ {"ldahlsp",
+ "ld hl,#%d\n"
+ "\tadd\thl,sp"},
+ {"ldaspsp",
+ "ld hl,#%d\n"
+ "\tadd\thl,sp\n"
+ "\tld\tsp,hl"},
+ {"*pair", "(%s)"},
+ {"shortjp", "jp"},
+ {"enter",
+ "push\tix\n"
+ "\tld\tix,#0\n"
+ "\tadd\tix,sp"},
+ {"enterx",
+ "push\tix\n"
+ "\tld\tix,#0\n"
+ "\tadd\tix,sp\n"
+ "\tld\thl,#-%d\n"
+ "\tadd\thl,sp\n"
+ "\tld\tsp,hl"},
+ {"leave",
+ "pop\tix\n"
+ },
+ {"leavex",
+ "ld sp,ix\n"
+ "\tpop\tix\n"
+ },
+ {"pusha",
+ "push af\n"
+ "\tpush\tbc\n"
+ "\tpush\tde\n"
+ "\tpush\thl"
+ },
+ {"adjustsp", "lda sp,-%d(sp)"},
+ {NULL, NULL}
};
-static const ASM_MAPPINGS _asxxxx_z80 = {
- &asm_asxxxx_mapping,
- _asxxxx_z80_mapping
+static const ASM_MAPPINGS _asxxxx_z80 =
+{
+ &asm_asxxxx_mapping,
+ _asxxxx_z80_mapping
};
-static void _i186_init(void)
+static void
+_i186_init (void)
{
- asm_addTree(&asm_asxxxx_mapping);
- asm_addTree(&_asxxxx_z80);
- izt_init(&_i186_port);
+ asm_addTree (&asm_asxxxx_mapping);
+ asm_addTree (&_asxxxx_z80);
+ izt_init (&_i186_port);
}
-static void _i186_reset_regparm()
+static void
+_i186_reset_regparm ()
{
}
-static int _i186_regparm( sym_link *l)
+static int
+_i186_regparm (sym_link * l)
{
- // PENDING: No register parameters.
- return 0;
+ // PENDING: No register parameters.
+ return 0;
}
-static bool _i186_parseOptions(int *pargc, char **argv, int *i)
+static bool
+_i186_parseOptions (int *pargc, char **argv, int *i)
{
- /* TODO: allow port-specific command line options to specify
- * segment names here.
- */
- return FALSE;
+ /* TODO: allow port-specific command line options to specify
+ * segment names here.
+ */
+ return FALSE;
}
-static void _i186_finaliseOptions(void)
+static void
+_i186_finaliseOptions (void)
{
- // No options
+ // No options
}
-static void _i186_setDefaultOptions(void)
+static void
+_i186_setDefaultOptions (void)
{
- // No options
+ // No options
}
-static const char *_i186_getRegName(struct regs *reg)
+static const char *
+_i186_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- wassert(0);
- return "err";
+ if (reg)
+ return reg->name;
+ wassert (0);
+ return "err";
}
-static void _i186_genAssemblerPreamble(FILE *of)
+static void
+_i186_genAssemblerPreamble (FILE * of)
{
- // PENDING
+ // PENDING
}
/* Generate interrupt vector table. */
-static int _i186_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
+static int
+_i186_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
{
- // PENDING
- return 0;
+ // PENDING
+ return 0;
}
/** $1 is always the basename.
MUST be terminated with a NULL.
*/
// PENDING
-static const char *_linkCmd[] = {
- "aslink", "-nf", "$1", NULL
+static const char *_linkCmd[] =
+{
+ "aslink", "-nf", "$1", NULL
};
// PENDING
-static const char *_asmCmd[] = {
- "gpasm", NULL, NULL, NULL
+static const char *_asmCmd[] =
+{
+ "gpasm", NULL, NULL, NULL
};
-void i186_assignRegisters (eBBlock **ebbs, int count)
+void
+i186_assignRegisters (eBBlock ** ebbs, int count)
{
}
/* Globals */
-PORT i186_port = {
- "i186",
- "Intel 8086/80186", /* Target name */
- {
- FALSE, /* Emit glue around main */
- MODEL_SMALL,
- MODEL_SMALL
- },
- {
- _asmCmd,
- NULL,
- NULL,
- 0
- },
- {
- _linkCmd,
- NULL,
- ".o"
- },
- {
- _defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
- },
- {
- "XSEG (XDATA)",
- "STACK (DATA)",
- "CSEG (CODE)",
- "DSEG (DATA)",
- "ISEG (DATA)",
- "XSEG (XDATA)",
- "BSEG (BIT)",
- "RSEG (DATA)",
- "GSINIT (CODE)",
- "OSEG (OVR,DATA)",
- "GSFINAL (CODE)",
- "HOME (CODE)",
- NULL,
- NULL,
- 1
- },
- {
- +1, 1, 4, 1, 1, 0
- },
- /* i186 has an 16 bit mul */
- {
- 2, 0
- },
- "_",
- _i186_init,
- _i186_parseOptions,
- _i186_finaliseOptions,
- _i186_setDefaultOptions,
- izt_assignRegisters,
- _i186_getRegName ,
- _i186_keywords,
- _i186_genAssemblerPreamble,
- _i186_genIVT ,
- _i186_reset_regparm,
- _i186_regparm,
+PORT i186_port =
+{
+ "i186",
+ "Intel 8086/80186", /* Target name */
+ {
+ FALSE, /* Emit glue around main */
+ MODEL_SMALL,
+ MODEL_SMALL
+ },
+ {
+ _asmCmd,
+ NULL,
+ NULL,
+ 0
+ },
+ {
+ _linkCmd,
NULL,
- FALSE,
- 0, /* leave lt */
- 0, /* leave gt */
- 1, /* transform <= to ! > */
- 1, /* transform >= to ! < */
- 1, /* transform != to !(a == b) */
- 0, /* leave == */
- PORT_MAGIC
+ ".o"
+ },
+ {
+ _defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
+ },
+ {
+ "XSEG (XDATA)",
+ "STACK (DATA)",
+ "CSEG (CODE)",
+ "DSEG (DATA)",
+ "ISEG (DATA)",
+ "XSEG (XDATA)",
+ "BSEG (BIT)",
+ "RSEG (DATA)",
+ "GSINIT (CODE)",
+ "OSEG (OVR,DATA)",
+ "GSFINAL (CODE)",
+ "HOME (CODE)",
+ NULL,
+ NULL,
+ 1
+ },
+ {
+ +1, 1, 4, 1, 1, 0
+ },
+ /* i186 has an 16 bit mul */
+ {
+ 2, 0
+ },
+ "_",
+ _i186_init,
+ _i186_parseOptions,
+ _i186_finaliseOptions,
+ _i186_setDefaultOptions,
+ izt_assignRegisters,
+ _i186_getRegName,
+ _i186_keywords,
+ _i186_genAssemblerPreamble,
+ _i186_genIVT,
+ _i186_reset_regparm,
+ _i186_regparm,
+ NULL,
+ FALSE,
+ 0, /* leave lt */
+ 0, /* leave gt */
+ 1, /* transform <= to ! > */
+ 1, /* transform >= to ! < */
+ 1, /* transform != to !(a == b) */
+ 0, /* leave == */
+ PORT_MAGIC
};
#include <common.h>
#include "gen.h"
-typedef enum {
+typedef enum
+ {
REG_ID_NONE,
// Z80
REG_ID_A,
REG_ID_DH,
REG_ID_DX,
REG_ID_MAX
-} REG_ID;
+ }
+REG_ID;
-enum {
+enum
+ {
REG_USED = 1,
REG_USED_HIDDEN = 2
-};
+ };
-enum {
+enum
+ {
REG_TYPE_CND = 1,
REG_TYPE_GPR = 2
-} REG_TYPE;
+ }
+REG_TYPE;
-typedef struct regs {
+typedef struct regs
+ {
int size;
REG_ID id;
const char *name;
int used;
REG_ID hides[3];
-} REG;
+ }
+REG;
#define TEST(_d, _a) \
(_a) ? (void)0 : (failures++, printf("Test %s \"%s\" failed.\n", #_a, _d), _dumpRegs())
#define NUM_OF(_a) (sizeof(_a)/sizeof(*(_a)))
-typedef struct {
+typedef struct
+ {
REG *regs;
-} IZT_PORT;
+ }
+IZT_PORT;
IZT_PORT *izt_port;
-void izt_init(IZT_PORT *port);
-void izt_assignRegisters (eBBlock **ebbs, int count);
-void izt_gen(iCode *ic);
+void izt_init (IZT_PORT * port);
+void izt_assignRegisters (eBBlock ** ebbs, int count);
+void izt_gen (iCode * ic);
#include "izt.h"
/// Static data.
-static struct {
- struct {
+static struct
+ {
+ struct
+ {
/// Used to generate a unique name for the spill location.
int loc;
/// Set of all iTemps spilt onto the stack.
set *set;
/// Similar to stackSpill
bitVect *vect;
- } spill;
+ }
+ spill;
/// Bitvector of all registers used in this function.
bitVect *funcUsedRegs;
/// If a bit is set in this then the iCode at that sequence has had
bitVect *regAssigned;
int blockSpill;
int stackExtend;
-} _G;
+ }
+_G;
-static REG *_findRegById(REG_ID id)
+static REG *
+_findRegById (REG_ID id)
{
- REG *r = izt_port->regs;
-
- while (r->size) {
- if (r->id == id)
- return r;
- r++;
+ REG *r = izt_port->regs;
+
+ while (r->size)
+ {
+ if (r->id == id)
+ return r;
+ r++;
}
- wassert(0);
- return NULL;
+ wassert (0);
+ return NULL;
}
-static REG *_getSubReg(REG *r, int size, int offset)
+static REG *
+_getSubReg (REG * r, int size, int offset)
{
- wassert(r->size >= size);
-
- if (r->size == size) {
- wassert(offset == 0);
- return r;
+ wassert (r->size >= size);
+
+ if (r->size == size)
+ {
+ wassert (offset == 0);
+ return r;
}
- // We use the hiding table to get the parts of the register.
- else if (size == 1) {
- wassert(offset == 0 || offset == 1);
- return _findRegById(r->hides[offset]);
+ // We use the hiding table to get the parts of the register.
+ else if (size == 1)
+ {
+ wassert (offset == 0 || offset == 1);
+ return _findRegById (r->hides[offset]);
}
- else if (size == 2) {
- wassert(offset == 0);
- return _findRegById(r->hides[2]);
+ else if (size == 2)
+ {
+ wassert (offset == 0);
+ return _findRegById (r->hides[2]);
}
- // Cant.
- wassert(0);
- return NULL;
+ // Cant.
+ wassert (0);
+ return NULL;
}
-static int _numRegsAvailable(int size)
+static int
+_numRegsAvailable (int size)
{
- REG *r = izt_port->regs;
- int ret = 0;
+ REG *r = izt_port->regs;
+ int ret = 0;
- while (r->size) {
- if (r->size == size && r->used == 0)
- ret++;
- r++;
+ while (r->size)
+ {
+ if (r->size == size && r->used == 0)
+ ret++;
+ r++;
}
-
- return ret;
+
+ return ret;
}
-static void _setClearUsed(REG_ID id, int clear)
+static void
+_setClearUsed (REG_ID id, int clear)
{
- REG *r = _findRegById(id);
- wassert(r);
+ REG *r = _findRegById (id);
+ wassert (r);
- if (!clear) {
- // The parent shouldnt be able to be allocated if this child
- // is already.
- wassert((r->used & REG_USED_HIDDEN) == 0);
- r->used |= REG_USED_HIDDEN;
+ if (!clear)
+ {
+ // The parent shouldnt be able to be allocated if this child
+ // is already.
+ wassert ((r->used & REG_USED_HIDDEN) == 0);
+ r->used |= REG_USED_HIDDEN;
}
- else {
- wassert((r->used & REG_USED_HIDDEN) != 0);
- r->used &= ~REG_USED_HIDDEN;
+ else
+ {
+ wassert ((r->used & REG_USED_HIDDEN) != 0);
+ r->used &= ~REG_USED_HIDDEN;
}
}
-static void _markAsUsed(REG_ID id)
+static void
+_markAsUsed (REG_ID id)
{
- _setClearUsed(id, FALSE);
+ _setClearUsed (id, FALSE);
}
-static void _markAsFree(REG_ID id)
+static void
+_markAsFree (REG_ID id)
{
- _setClearUsed(id, TRUE);
+ _setClearUsed (id, TRUE);
}
-static REG *_allocateReg(int size)
+static REG *
+_allocateReg (int size)
{
- REG *r = izt_port->regs;
-
- while (r->size) {
- if (r->size == size && r->used == 0) {
- // Now go through the interference table and mark all other
- // registers as used.
- int i;
- for (i=0; i < NUM_OF(r->hides); i++) {
- if (r->hides[i] == REG_ID_NONE) {
- break;
+ REG *r = izt_port->regs;
+
+ while (r->size)
+ {
+ if (r->size == size && r->used == 0)
+ {
+ // Now go through the interference table and mark all other
+ // registers as used.
+ int i;
+ for (i = 0; i < NUM_OF (r->hides); i++)
+ {
+ if (r->hides[i] == REG_ID_NONE)
+ {
+ break;
}
- _markAsUsed(r->hides[i]);
+ _markAsUsed (r->hides[i]);
}
- r->used |= REG_USED;
- return r;
+ r->used |= REG_USED;
+ return r;
}
- r++;
+ r++;
}
- return NULL;
+ return NULL;
}
-static bitVect *_markRegBits(bitVect *v, REG *r)
+static bitVect *
+_markRegBits (bitVect * v, REG * r)
{
- int i;
+ int i;
- // Mark the primary register.
- v = bitVectSetBit(v, r->id);
+ // Mark the primary register.
+ v = bitVectSetBit (v, r->id);
- // Now add all the hidden registers.
- for (i=0; i < NUM_OF(r->hides); i++) {
- if (r->hides[i] == REG_ID_NONE) {
- break;
+ // Now add all the hidden registers.
+ for (i = 0; i < NUM_OF (r->hides); i++)
+ {
+ if (r->hides[i] == REG_ID_NONE)
+ {
+ break;
}
- v = bitVectSetBit(v, r->hides[i]);
+ v = bitVectSetBit (v, r->hides[i]);
}
- return v;
+ return v;
}
-static void _freeReg(REG *r)
+static void
+_freeReg (REG * r)
{
- int i;
- wassert(r->used == REG_USED);
-
- r->used = 0;
+ int i;
+ wassert (r->used == REG_USED);
+
+ r->used = 0;
- for (i=0; i < NUM_OF(r->hides); i++) {
- if (r->hides[i] == REG_ID_NONE) {
- break;
+ for (i = 0; i < NUM_OF (r->hides); i++)
+ {
+ if (r->hides[i] == REG_ID_NONE)
+ {
+ break;
}
- _markAsFree(r->hides[i]);
+ _markAsFree (r->hides[i]);
}
}
-static void _freeAllRegs(viod)
+static void
+_freeAllRegs (viod)
{
- REG *r = izt_port->regs;
+ REG *r = izt_port->regs;
- while (r->size) {
- r->used = 0;
- r++;
+ while (r->size)
+ {
+ r->used = 0;
+ r++;
}
}
-static void _dumpRegs(void)
+static void
+_dumpRegs (void)
{
- REG *r = izt_port->regs;
+ REG *r = izt_port->regs;
- while (r->size) {
- printf("%u\t%u\t%s\t%u\n", r->size, r->id, r->name, r->used);
- r++;
+ while (r->size)
+ {
+ printf ("%u\t%u\t%s\t%u\n", r->size, r->id, r->name, r->used);
+ r++;
}
}
-void izt_init(IZT_PORT *port)
+void
+izt_init (IZT_PORT * port)
{
- wassert(port && port->regs);
- izt_port = port;
- izt_initEmitters();
+ wassert (port && port->regs);
+ izt_port = port;
+ izt_initEmitters ();
}
/// Lower register pressure by packing iTemps where possible.
-static void _packRegisters(eBBlock *ebp)
+static void
+_packRegisters (eBBlock * ebp)
{
- // PENDING: Assignment packing
- // PENDING: Mark address of a true symbol as remat.
- // PENDING: Propagate remat through equals.
- // PENDING: Assign bitwise which is followed by a conditional into carry.
- // PENDING: Pack for one use on pointer get or set. Assumes that the pointer
- // is stored in the scratch register.
- // PENDING: Pack short use iTemps into ACC or the scratch register.
+ // PENDING: Assignment packing
+ // PENDING: Mark address of a true symbol as remat.
+ // PENDING: Propagate remat through equals.
+ // PENDING: Assign bitwise which is followed by a conditional into carry.
+ // PENDING: Pack for one use on pointer get or set. Assumes that the pointer
+ // is stored in the scratch register.
+ // PENDING: Pack short use iTemps into ACC or the scratch register.
}
-static void _computeRequiredRegs(void)
+static void
+_computeRequiredRegs (void)
{
- symbol *sym;
- int k;
+ symbol *sym;
+ int k;
- // Iterate over each live range.
- for (sym = hTabFirstItem(liveRanges, &k); sym ;
- sym = hTabNextItem(liveRanges, &k)) {
+ // Iterate over each live range.
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
- sym->nRegs = 0;
+ sym->nRegs = 0;
- // If the symbol is never used, then next.
- if ((sym->liveTo - sym->liveFrom) == 0)
- continue;
+ // If the symbol is never used, then next.
+ if ((sym->liveTo - sym->liveFrom) == 0)
+ continue;
- // Only temporaries need registers.
- if (!sym->isitmp)
- continue;
+ // Only temporaries need registers.
+ if (!sym->isitmp)
+ continue;
+
+ // Conditionals live in carry and dont need registers.
+ if (sym->regType == REG_TYPE_CND)
+ continue;
- // Conditionals live in carry and dont need registers.
- if (sym->regType == REG_TYPE_CND)
- continue;
-
-#if 0 // PENDING. Currently we dont compute ruonly or accuse.
- if (sym->ruonly || sym->accuse) {
- if (IS_AGGREGATE(sym->type) || sym->isptr)
- sym->type = aggrToPtr(sym->type,FALSE);
- continue ;
+#if 0 // PENDING. Currently we dont compute ruonly or accuse.
+ if (sym->ruonly || sym->accuse)
+ {
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ sym->type = aggrToPtr (sym->type, FALSE);
+ continue;
}
#endif
- // We need registers.
- if (IS_AGGREGATE(sym->type) || sym->isptr) {
- // Turn an aggregate into something real.
- sym->type = aggrToPtr(sym->type, FALSE);
+ // We need registers.
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ {
+ // Turn an aggregate into something real.
+ sym->type = aggrToPtr (sym->type, FALSE);
}
- sym->nRegs = getSize(sym->type);
- wassert(sym->nRegs <= 4);
+ sym->nRegs = getSize (sym->type);
+ wassert (sym->nRegs <= 4);
}
}
-static bool _doesntNeedRegs(iCode *ic)
+static bool
+_doesntNeedRegs (iCode * ic)
{
- // Some types of instructions dont need registers.
- // PENDING: Flush out the types and make processor specific.
- if (SKIP_IC2(ic) ||
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- ic->op == RETURN) {
- return TRUE;
+ // Some types of instructions dont need registers.
+ // PENDING: Flush out the types and make processor specific.
+ if (SKIP_IC2 (ic) ||
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ ic->op == RETURN)
+ {
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
-static bool _willCauseSpill(int size)
+static bool
+_willCauseSpill (int size)
{
- return _numRegsAvailable(size) == 0;
+ return _numRegsAvailable (size) == 0;
}
-static void _deassignLRs(iCode *ic, eBBlock *ebp)
+static void
+_deassignLRs (iCode * ic, eBBlock * ebp)
{
- symbol *sym;
- int ignored;
- symbol *result;
+ symbol *sym;
+ int ignored;
+ symbol *result;
- // For each symbol
- for (sym = hTabFirstItem(liveRanges, &ignored); sym; sym = hTabNextItem(liveRanges, &ignored)) {
-
- // Has this symbol expired yet?
- if (sym->liveTo > ic->seq) {
- // No. Cant deassign.
- continue;
+ // For each symbol
+ for (sym = hTabFirstItem (liveRanges, &ignored); sym; sym = hTabNextItem (liveRanges, &ignored))
+ {
+
+ // Has this symbol expired yet?
+ if (sym->liveTo > ic->seq)
+ {
+ // No. Cant deassign.
+ continue;
}
- // It has expired. Free up the resources.
-
- // If it was spilt, then free up the stack spill location.
- if (sym->isspilt) {
- if (sym->stackSpil) {
- sym->usl.spillLoc->isFree = 1;
- sym->stackSpil = 0;
+ // It has expired. Free up the resources.
+
+ // If it was spilt, then free up the stack spill location.
+ if (sym->isspilt)
+ {
+ if (sym->stackSpil)
+ {
+ sym->usl.spillLoc->isFree = 1;
+ sym->stackSpil = 0;
}
- continue;
+ continue;
}
- // If it currently has no registers assigned, then continue.
- if (bitVectBitValue(_G.regAssigned, sym->key) == 0) {
- continue;
+ // If it currently has no registers assigned, then continue.
+ if (bitVectBitValue (_G.regAssigned, sym->key) == 0)
+ {
+ continue;
}
-
- // If it has no registers assigned to it, then continue.
- if (sym->nRegs == 0) {
- continue;
+
+ // If it has no registers assigned to it, then continue.
+ if (sym->nRegs == 0)
+ {
+ continue;
}
- // Mark this sym as not having registers assigned.
- bitVectUnSetBit(_G.regAssigned, sym->key);
-
- // Free the registers.
- _freeReg(sym->regs[0]);
-
- // If deallocating will free up enough registers for this iCode
- // then steal them immediatly.
- if (IC_RESULT(ic) && !_doesntNeedRegs(ic)) {
- result = OP_SYMBOL(IC_RESULT(ic));
- if (result && // Has a result
- result->liveTo > ic->seq && // and lives past this instruction
- result->liveTo <= ebp->lSeq && // and doesnt go past this block
- result->nRegs && // and actually needs registers
- !result->isspilt && // and doesnt have them yet
- !result->remat && // and wouldnt waste them
- !bitVectBitValue(_G.regAssigned, result->key) && // doesnt have them yet
- !_willCauseSpill(result->nRegs)
- ) {
- result->regs[0] = _allocateReg(result->nRegs);
+ // Mark this sym as not having registers assigned.
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ // Free the registers.
+ _freeReg (sym->regs[0]);
+
+ // If deallocating will free up enough registers for this iCode
+ // then steal them immediatly.
+ if (IC_RESULT (ic) && !_doesntNeedRegs (ic))
+ {
+ result = OP_SYMBOL (IC_RESULT (ic));
+ if (result && // Has a result
+ result->liveTo > ic->seq && // and lives past this instruction
+ result->liveTo <= ebp->lSeq && // and doesnt go past this block
+ result->nRegs && // and actually needs registers
+ !result->isspilt && // and doesnt have them yet
+ !result->remat && // and wouldnt waste them
+ !bitVectBitValue (_G.regAssigned, result->key) && // doesnt have them yet
+ !_willCauseSpill (result->nRegs)
+ )
+ {
+ result->regs[0] = _allocateReg (result->nRegs);
}
}
}
/// Returns true if the live range of the given symbol doesnt overlap
/// with any of the live ranges in the set.
-static bool _noOverlap (set *itmpStack, symbol *fsym)
+static bool
+_noOverlap (set * itmpStack, symbol * fsym)
{
- symbol *sym;
-
- for (sym = setFirstItem(itmpStack); sym; sym = setNextItem(itmpStack)) {
- if (sym->liveTo > fsym->liveFrom) {
- return FALSE;
+ symbol *sym;
+
+ for (sym = setFirstItem (itmpStack); sym; sym = setNextItem (itmpStack))
+ {
+ if (sym->liveTo > fsym->liveFrom)
+ {
+ return FALSE;
}
}
- return TRUE;
+ return TRUE;
}
/// Set operator that returns 1 if a free spill location is found.
-DEFSETFUNC(_stackIsFree)
-{
- symbol *sym = item;
- V_ARG(symbol **,sloc);
- V_ARG(symbol *,fsym);
-
- // Dont bother if one has already been found.
- if (*sloc)
- return 0;
-
- if (sym->isFree && // This location is free...
- _noOverlap(sym->usl.itmpStack, fsym) && // and its usage doesnt overlap with the usage of this sym
- getSize(sym->type) >= getSize(fsym->type) && // and the location is big enough to hold the sym
- 1) {
- // All good. Take this location.
- *sloc = sym;
- return 1;
+DEFSETFUNC (_stackIsFree)
+{
+ symbol *sym = item;
+ V_ARG (symbol **, sloc);
+ V_ARG (symbol *, fsym);
+
+ // Dont bother if one has already been found.
+ if (*sloc)
+ return 0;
+
+ if (sym->isFree && // This location is free...
+ _noOverlap (sym->usl.itmpStack, fsym) && // and its usage doesnt overlap with the usage of this sym
+ getSize (sym->type) >= getSize (fsym->type) && // and the location is big enough to hold the sym
+ 1)
+ {
+ // All good. Take this location.
+ *sloc = sym;
+ return 1;
}
- else {
- // No match.
- return 0;
+ else
+ {
+ // No match.
+ return 0;
}
}
/// Create a new spill location on the stack for this symbol.
-symbol *_createStackSpill(symbol *sym)
-{
- symbol *sloc= NULL;
-
- // Try to reuse an exisiting spill location.
- if (applyToSet(_G.spill.set, _stackIsFree, &sloc, sym)) {
- // Found one. Take it over.
- sym->usl.spillLoc = sloc;
- sym->stackSpil = TRUE;
- sloc->isFree = 0;
- addSetHead(&sloc->usl.itmpStack, sym);
- return sym;
+symbol *
+_createStackSpill (symbol * sym)
+{
+ symbol *sloc = NULL;
+
+ // Try to reuse an exisiting spill location.
+ if (applyToSet (_G.spill.set, _stackIsFree, &sloc, sym))
+ {
+ // Found one. Take it over.
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = TRUE;
+ sloc->isFree = 0;
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
- // No existing location. Time to create one.
- // Give it a pretty name.
- sprintf(buffer, "sloc%d", ++_G.spill.loc);
- // And create.
- sloc = newiTemp(buffer);
-
- // Setup the type.
- sloc->type = copyLinkChain(sym->type);
- sloc->etype = getSpec(sloc->type);
- SPEC_SCLS(sloc->etype) = S_AUTO ;
-
- allocLocal(sloc);
-
- // "To prevent compiler warning"
- sloc->isref = 1;
-
- // Increase the local variable stack size on this function.
- if (IN_STACK(sloc->etype)) {
- currFunc->stack += getSize(sloc->type);
- _G.stackExtend += getSize(sloc->type);
- } else {
- // The IZT port currently doesnt support loading locals into data space.
- wassert(0);
+ // No existing location. Time to create one.
+ // Give it a pretty name.
+ sprintf (buffer, "sloc%d", ++_G.spill.loc);
+ // And create.
+ sloc = newiTemp (buffer);
+
+ // Setup the type.
+ sloc->type = copyLinkChain (sym->type);
+ sloc->etype = getSpec (sloc->type);
+ SPEC_SCLS (sloc->etype) = S_AUTO;
+
+ allocLocal (sloc);
+
+ // "To prevent compiler warning"
+ sloc->isref = 1;
+
+ // Increase the local variable stack size on this function.
+ if (IN_STACK (sloc->etype))
+ {
+ currFunc->stack += getSize (sloc->type);
+ _G.stackExtend += getSize (sloc->type);
}
+ else
+ {
+ // The IZT port currently doesnt support loading locals into data space.
+ wassert (0);
+ }
+
+ // And add it to the spill set.
+ addSetHead (&_G.spill.set, sloc);
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = TRUE;
- // And add it to the spill set.
- addSetHead(&_G.spill.set, sloc);
- sym->usl.spillLoc = sloc;
- sym->stackSpil = TRUE;
-
- // "Add it to the set of itempStack set of the spill location
- addSetHead(&sloc->usl.itmpStack,sym);
+ // "Add it to the set of itempStack set of the spill location
+ addSetHead (&sloc->usl.itmpStack, sym);
- return sym;
+ return sym;
}
-static void _spillThis(symbol *sym)
+static void
+_spillThis (symbol * sym)
{
- // Create a spill location if it needs one and doesnt have one yet.
- if (!(sym->remat || sym->usl.spillLoc)) {
- _createStackSpill(sym);
+ // Create a spill location if it needs one and doesnt have one yet.
+ if (!(sym->remat || sym->usl.spillLoc))
+ {
+ _createStackSpill (sym);
}
- sym->isspilt = TRUE;
- // Add it to the spilt set.
- _G.spill.vect = bitVectSetBit(_G.spill.vect, sym->key);
- // and remove it from the 'has registers' set.
- bitVectUnSetBit(_G.regAssigned, sym->key);
-
- // Free up any registers that were assigned to this.
- if (sym->regs[0]) {
- _freeReg(sym->regs[0]);
- sym->regs[0] = NULL;
+ sym->isspilt = TRUE;
+ // Add it to the spilt set.
+ _G.spill.vect = bitVectSetBit (_G.spill.vect, sym->key);
+ // and remove it from the 'has registers' set.
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ // Free up any registers that were assigned to this.
+ if (sym->regs[0])
+ {
+ _freeReg (sym->regs[0]);
+ sym->regs[0] = NULL;
}
- // CHECK: If this sym now has a spill location, mark it as allocated
- // so that the stack packing later doesnt remove it.
- if (sym->usl.spillLoc && !sym->remat) {
- sym->usl.spillLoc->allocreq = TRUE;
+ // CHECK: If this sym now has a spill location, mark it as allocated
+ // so that the stack packing later doesnt remove it.
+ if (sym->usl.spillLoc && !sym->remat)
+ {
+ sym->usl.spillLoc->allocreq = TRUE;
}
- return;
+ return;
}
-static bitVect *_findSpillable(iCode *ic)
+static bitVect *
+_findSpillable (iCode * ic)
{
- bitVect *spillable;
+ bitVect *spillable;
- // First create a copy of the currently live ranges.
- spillable = bitVectCopy(ic->rlive);
- // Remove those which are already spilt.
- spillable = bitVectCplAnd(spillable, _G.spill.vect);
- // Remove those that this iCode uses.
- spillable = bitVectCplAnd(spillable, ic->uses);
- // Remove those that this iCode defines.
- bitVectUnSetBit(spillable, ic->defKey);
+ // First create a copy of the currently live ranges.
+ spillable = bitVectCopy (ic->rlive);
+ // Remove those which are already spilt.
+ spillable = bitVectCplAnd (spillable, _G.spill.vect);
+ // Remove those that this iCode uses.
+ spillable = bitVectCplAnd (spillable, ic->uses);
+ // Remove those that this iCode defines.
+ bitVectUnSetBit (spillable, ic->defKey);
- // Only those that have registers assigned can actually be spilt :)
- spillable = bitVectIntersect(spillable, _G.regAssigned);
+ // Only those that have registers assigned can actually be spilt :)
+ spillable = bitVectIntersect (spillable, _G.regAssigned);
- return spillable;
+ return spillable;
}
/// Finds the least used live range
-static symbol *_leastUsedLR(set *sset)
-{
- // sym is the currently least used symbol.
- symbol *sym;
- // walk walks the list of symbols in the scan set.
- symbol *walk;
-
- // Use the first as the seed.
- sym = walk = setFirstItem(sset);
-
- while (walk) {
- // Prefer spilling the symbol with the least allocated registers.
- // PENDING: Why?
- if (walk->used == sym->used) {
- if (getSize(walk->type) < getSize(sym->type)) {
- sym = walk;
+static symbol *
+_leastUsedLR (set * sset)
+{
+ // sym is the currently least used symbol.
+ symbol *sym;
+ // walk walks the list of symbols in the scan set.
+ symbol *walk;
+
+ // Use the first as the seed.
+ sym = walk = setFirstItem (sset);
+
+ while (walk)
+ {
+ // Prefer spilling the symbol with the least allocated registers.
+ // PENDING: Why?
+ if (walk->used == sym->used)
+ {
+ if (getSize (walk->type) < getSize (sym->type))
+ {
+ sym = walk;
}
}
- else if (walk->used < sym->used) {
- // This is used less than the current best. It looses.
- sym = walk;
+ else if (walk->used < sym->used)
+ {
+ // This is used less than the current best. It looses.
+ sym = walk;
}
-
- walk = setNextItem(sset);
- }
- setToNull((void **)&sset);
- sym->blockSpil = 0;
+ walk = setNextItem (sset);
+ }
+
+ setToNull ((void **) &sset);
+ sym->blockSpil = 0;
- return sym;
+ return sym;
}
/// Applies a function to a given set of live ranges.
-static set *_liveRangesWith(bitVect *lrs, int (func)(symbol *,eBBlock *, iCode *),
- eBBlock *ebp, iCode *ic)
+static set *
+_liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
+ eBBlock * ebp, iCode * ic)
{
- set *rset = NULL;
- int i;
+ set *rset = NULL;
+ int i;
- // Dont do anything if the bitVect is empty.
- if (!lrs || !lrs->size)
- return NULL;
+ // Dont do anything if the bitVect is empty.
+ if (!lrs || !lrs->size)
+ return NULL;
- for (i = 1; i < lrs->size; i++ ) {
- symbol *sym;
+ for (i = 1; i < lrs->size; i++)
+ {
+ symbol *sym;
- // If this bit isnt turned on, skip.
- if (!bitVectBitValue(lrs, i))
- continue ;
+ // If this bit isnt turned on, skip.
+ if (!bitVectBitValue (lrs, i))
+ continue;
- // If we don't find it in the live range hash table we are in serious trouble.
- if (!(sym = hTabItemWithKey(liveRanges, i))) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "liveRangesWith could not find liveRange");
- exit(1);
+ // If we don't find it in the live range hash table we are in serious trouble.
+ if (!(sym = hTabItemWithKey (liveRanges, i)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "liveRangesWith could not find liveRange");
+ exit (1);
}
-
- // If the function likes it, and it has registers assigned to
- // it, add it to the return set.
- if (func(sym, ebp, ic) && bitVectBitValue(_G.regAssigned, sym->key)) {
- addSetHead(&rset,sym);
+
+ // If the function likes it, and it has registers assigned to
+ // it, add it to the return set.
+ if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
+ {
+ addSetHead (&rset, sym);
}
}
- return rset;
+ return rset;
}
/// Returns TRUE always. Used to fetch all live ranges.
-static int _allLRs(symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+_allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return 1;
+ return 1;
}
-static void _serialRegAssign(eBBlock **ebbs, int count)
+static void
+_serialRegAssign (eBBlock ** ebbs, int count)
{
- int i;
+ int i;
- // For each block, do...
- for (i=0; i<count; i++) {
- iCode *ic;
+ // For each block, do...
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
- if (ebbs[i]->noPath &&
- (ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel )) {
- // PENDING: Dont understand.
- continue;
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ {
+ // PENDING: Dont understand.
+ continue;
}
-
-
- // For each iCode in this block, do...
- for (ic = ebbs[i]->sch; ic; ic = ic->next) {
- symbol *sym;
- bitVect *spillable;
- int willCauseSpill;
-
- // Dont support IPOP
- wassert(ic->op != IPOP);
-
- // if result is present && is a true symbol
- if (IC_RESULT(ic) && ic->op != IFX &&
- IS_TRUE_SYMOP(IC_RESULT(ic)))
- OP_SYMBOL(IC_RESULT(ic))->allocreq = 1;
-
- // Take away registers from live ranges that end at this
- // instruction.
- _deassignLRs(ic, ebbs[i]);
-
- // Some instructions dont need registers.
- if (_doesntNeedRegs(ic)) {
- continue;
+
+
+ // For each iCode in this block, do...
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+ symbol *sym;
+ bitVect *spillable;
+ int willCauseSpill;
+
+ // Dont support IPOP
+ wassert (ic->op != IPOP);
+
+ // if result is present && is a true symbol
+ if (IC_RESULT (ic) && ic->op != IFX &&
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
+
+ // Take away registers from live ranges that end at this
+ // instruction.
+ _deassignLRs (ic, ebbs[i]);
+
+ // Some instructions dont need registers.
+ if (_doesntNeedRegs (ic))
+ {
+ continue;
}
- // If there is no result, then it doesnt need registers.
- if (!IC_RESULT(ic)) {
- continue;
+ // If there is no result, then it doesnt need registers.
+ if (!IC_RESULT (ic))
+ {
+ continue;
}
- sym = OP_SYMBOL(IC_RESULT(ic));
+ sym = OP_SYMBOL (IC_RESULT (ic));
- // Does it need any registers?
- if (sym->nRegs == 0) {
- continue;
+ // Does it need any registers?
+ if (sym->nRegs == 0)
+ {
+ continue;
}
- // Is it already split?
- if (sym->isspilt) {
- continue;
+ // Is it already split?
+ if (sym->isspilt)
+ {
+ continue;
}
- // Does it already have registers assigned?
- if (bitVectBitValue(_G.regAssigned,sym->key)) {
- continue;
+ // Does it already have registers assigned?
+ if (bitVectBitValue (_G.regAssigned, sym->key))
+ {
+ continue;
}
- // Will it live past this instruction?
- if (sym->liveTo <= ic->seq) {
- continue;
+ // Will it live past this instruction?
+ if (sym->liveTo <= ic->seq)
+ {
+ continue;
}
- // MLH Doesnt understand this.
- /* "Iif some liverange has been spilt at the block level
- and this one live beyond this block then spil this
- to be safe" */
- if (_G.blockSpill && sym->liveTo > ebbs[i]->lSeq) {
- _spillThis(sym);
- continue;
+ // MLH Doesnt understand this.
+ /* "Iif some liverange has been spilt at the block level
+ and this one live beyond this block then spil this
+ to be safe" */
+ if (_G.blockSpill && sym->liveTo > ebbs[i]->lSeq)
+ {
+ _spillThis (sym);
+ continue;
}
-
- // Seems that this symbol needs registers. See if
- // allocating will cause a spill.
- willCauseSpill = _willCauseSpill(sym->nRegs);
- spillable = _findSpillable(ic);
-
- // If this is remat., then dont waste any regsiters on it.
- if (sym->remat) {
- _spillThis(sym);
- continue;
+
+ // Seems that this symbol needs registers. See if
+ // allocating will cause a spill.
+ willCauseSpill = _willCauseSpill (sym->nRegs);
+ spillable = _findSpillable (ic);
+
+ // If this is remat., then dont waste any regsiters on it.
+ if (sym->remat)
+ {
+ _spillThis (sym);
+ continue;
}
- // If trying to allocate will cause a spill, and nothing
- // else is spillable then this sym looses.
- if (willCauseSpill && bitVectIsZero(spillable)) {
- _spillThis(sym);
- continue;
+ // If trying to allocate will cause a spill, and nothing
+ // else is spillable then this sym looses.
+ if (willCauseSpill && bitVectIsZero (spillable))
+ {
+ _spillThis (sym);
+ continue;
}
- // If this will cause a spill, and it already has a spill
- // location then spill this if it is the least used.
- if (willCauseSpill && sym->usl.spillLoc) {
- symbol *leastUsed = _leastUsedLR(_liveRangesWith(spillable, _allLRs, ebbs[i], ic));
- if (leastUsed && leastUsed->used > sym->used) {
- _spillThis(sym);
- continue;
+ // If this will cause a spill, and it already has a spill
+ // location then spill this if it is the least used.
+ if (willCauseSpill && sym->usl.spillLoc)
+ {
+ symbol *leastUsed = _leastUsedLR (_liveRangesWith (spillable, _allLRs, ebbs[i], ic));
+ if (leastUsed && leastUsed->used > sym->used)
+ {
+ _spillThis (sym);
+ continue;
}
}
- // Hmm. Here we could have no registers available but
- // we'll still try to allocate. MLH wonders how this will
- // work.
-
- // Mark this iCode as having registers assigned to it.
- _G.regAssigned = bitVectSetBit(_G.regAssigned, sym->key);
+ // Hmm. Here we could have no registers available but
+ // we'll still try to allocate. MLH wonders how this will
+ // work.
+
+ // Mark this iCode as having registers assigned to it.
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- // And do it.
- sym->regs[0] = _allocateReg(sym->nRegs);
+ // And do it.
+ sym->regs[0] = _allocateReg (sym->nRegs);
}
}
}
-static DEFSETFUNC(_deallocStackSpil)
+static
+DEFSETFUNC (_deallocStackSpil)
{
- symbol *sym = item;
+ symbol *sym = item;
- deallocLocal(sym);
- return 0;
+ deallocLocal (sym);
+ return 0;
}
/// Compute the register mask for an operand.
-bitVect *_rUmaskForOp(operand *op)
+bitVect *
+_rUmaskForOp (operand * op)
{
- bitVect *rumask;
- symbol *sym;
-
- // "Only temporaries are assigned registers"
- if (!IS_ITEMP(op))
- return NULL;
+ bitVect *rumask;
+ symbol *sym;
- sym = OP_SYMBOL(op);
-
- // If its spilt or no registers are needed, then no regs are assigned.
- if (sym->isspilt || !sym->nRegs)
- return NULL;
+ // "Only temporaries are assigned registers"
+ if (!IS_ITEMP (op))
+ return NULL;
+
+ sym = OP_SYMBOL (op);
+
+ // If its spilt or no registers are needed, then no regs are assigned.
+ if (sym->isspilt || !sym->nRegs)
+ return NULL;
- rumask = newBitVect(REG_ID_MAX);
+ rumask = newBitVect (REG_ID_MAX);
- if (sym->regs[0]) {
- rumask = _markRegBits(rumask, sym->regs[0]);
+ if (sym->regs[0])
+ {
+ rumask = _markRegBits (rumask, sym->regs[0]);
}
- return rumask;
+ return rumask;
}
/// Returns bit vector of registers used in iCode.
-bitVect *_regsUsedIniCode (iCode *ic)
-{
- bitVect *rmask = newBitVect(REG_ID_MAX);
-
- do {
- // Special cases first.
- if (ic->op == IFX ) {
- rmask = bitVectUnion(rmask, _rUmaskForOp(IC_COND(ic)));
- break;
+bitVect *
+_regsUsedIniCode (iCode * ic)
+{
+ bitVect *rmask = newBitVect (REG_ID_MAX);
+
+ do
+ {
+ // Special cases first.
+ if (ic->op == IFX)
+ {
+ rmask = bitVectUnion (rmask, _rUmaskForOp (IC_COND (ic)));
+ break;
}
- if (ic->op == JUMPTABLE) {
- rmask = bitVectUnion(rmask, _rUmaskForOp(IC_JTCOND(ic)));
- break;
+ if (ic->op == JUMPTABLE)
+ {
+ rmask = bitVectUnion (rmask, _rUmaskForOp (IC_JTCOND (ic)));
+ break;
}
- // Now the good old left, right, and result.
- if (IC_LEFT(ic)) {
- rmask = bitVectUnion(rmask, _rUmaskForOp(IC_LEFT(ic)));
+ // Now the good old left, right, and result.
+ if (IC_LEFT (ic))
+ {
+ rmask = bitVectUnion (rmask, _rUmaskForOp (IC_LEFT (ic)));
}
-
- if (IC_RIGHT(ic)) {
- rmask = bitVectUnion(rmask, _rUmaskForOp(IC_RIGHT(ic)));
+
+ if (IC_RIGHT (ic))
+ {
+ rmask = bitVectUnion (rmask, _rUmaskForOp (IC_RIGHT (ic)));
}
- if (IC_RESULT(ic)) {
- rmask = bitVectUnion(rmask, _rUmaskForOp(IC_RESULT(ic)));
+ if (IC_RESULT (ic))
+ {
+ rmask = bitVectUnion (rmask, _rUmaskForOp (IC_RESULT (ic)));
}
- } while (0);
+ }
+ while (0);
- return rmask;
+ return rmask;
}
/// Compute the helper bitVect that contains the register used mask.
-static void _createRegMask(eBBlock **ebbs, int count)
-{
- int i;
+static void
+_createRegMask (eBBlock ** ebbs, int count)
+{
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+
+ // If this code is unused, skip it.
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ {
+ continue;
+ }
- /* for all blocks */
- for (i = 0; i < count; i++) {
- iCode *ic ;
+ /* for all instructions */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+ int j;
- // If this code is unused, skip it.
- if ( ebbs[i]->noPath &&
- ( ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel )) {
+ if (SKIP_IC2 (ic) || !ic->rlive)
continue;
- }
- /* for all instructions */
- for (ic = ebbs[i]->sch; ic; ic = ic->next) {
- int j;
-
- if (SKIP_IC2(ic) || !ic->rlive)
- continue ;
-
- // Mark the registers used in this instruction.
- ic->rUsed = _regsUsedIniCode(ic);
- // Mark them as used at least once in the function.
- _G.funcUsedRegs = bitVectUnion(_G.funcUsedRegs, ic->rUsed);
-
- /* now create the register mask for those
- registers that are in use : this is a
- super set of ic->rUsed */
- ic->rMask = newBitVect(REG_ID_MAX+1);
-
- // "For all live Ranges alive at this point"
- for (j = 1; j < ic->rlive->size; j++) {
- symbol *sym;
-
- // "If if not alive then continue"
- if (!bitVectBitValue(ic->rlive,j)) {
- continue;
+ // Mark the registers used in this instruction.
+ ic->rUsed = _regsUsedIniCode (ic);
+ // Mark them as used at least once in the function.
+ _G.funcUsedRegs = bitVectUnion (_G.funcUsedRegs, ic->rUsed);
+
+ /* now create the register mask for those
+ registers that are in use : this is a
+ super set of ic->rUsed */
+ ic->rMask = newBitVect (REG_ID_MAX + 1);
+
+ // "For all live Ranges alive at this point"
+ for (j = 1; j < ic->rlive->size; j++)
+ {
+ symbol *sym;
+
+ // "If if not alive then continue"
+ if (!bitVectBitValue (ic->rlive, j))
+ {
+ continue;
}
- // "Find the live range we are interested in"
- if (!(sym = hTabItemWithKey(liveRanges,j))) {
- werror (E_INTERNAL_ERROR,__FILE__,__LINE__,
- "createRegMask cannot find live range");
- exit(0);
+ // "Find the live range we are interested in"
+ if (!(sym = hTabItemWithKey (liveRanges, j)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "createRegMask cannot find live range");
+ exit (0);
}
- // "If no register assigned to it"
- if (!sym->nRegs || sym->isspilt) {
- continue;
+ // "If no register assigned to it"
+ if (!sym->nRegs || sym->isspilt)
+ {
+ continue;
}
- // If this has any registers allocated, mark them as such.
- if (sym->regs[0]) {
- ic->rMask = _markRegBits(ic->rMask, sym->regs[0]);
+ // If this has any registers allocated, mark them as such.
+ if (sym->regs[0])
+ {
+ ic->rMask = _markRegBits (ic->rMask, sym->regs[0]);
}
}
}
}
}
-void izt_assignRegisters(eBBlock **ebbs, int count)
+void
+izt_assignRegisters (eBBlock ** ebbs, int count)
{
- // Contains a flat version of ebbs used in code generation.
- iCode *chain;
+ // Contains a flat version of ebbs used in code generation.
+ iCode *chain;
- // Clear the bit vector of registers used in this function.
- // Assumes that assignRegisters is called once per function.
- setToNull((void *)&_G.funcUsedRegs);
+ // Clear the bit vector of registers used in this function.
+ // Assumes that assignRegisters is called once per function.
+ setToNull ((void *) &_G.funcUsedRegs);
- // First scan each live range, and figure out what registers
- // are required.
- _computeRequiredRegs();
+ // First scan each live range, and figure out what registers
+ // are required.
+ _computeRequiredRegs ();
- // Now allocate the registers.
- _serialRegAssign(ebbs, count);
+ // Now allocate the registers.
+ _serialRegAssign (ebbs, count);
- // And create the helper register used mask.
- _createRegMask(ebbs, count);
+ // And create the helper register used mask.
+ _createRegMask (ebbs, count);
- // Turn the bblock array into an optimised list of iCode entries.
- chain = iCodeLabelOptimize(iCodeFromeBBlock(ebbs,count));
+ // Turn the bblock array into an optimised list of iCode entries.
+ chain = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
- // Redo the stack offsets. This will remove any redundent stack
- // locations ie iTemps that exist only in registers.
- redoStackOffsets();
+ // Redo the stack offsets. This will remove any redundent stack
+ // locations ie iTemps that exist only in registers.
+ redoStackOffsets ();
- izt_gen(chain);
+ izt_gen (chain);
- // Deallocate any stack spill locations.
- applyToSet(_G.spill.set, _deallocStackSpil);
+ // Deallocate any stack spill locations.
+ applyToSet (_G.spill.set, _deallocStackSpil);
- _G.spill.loc = 0;
- setToNull((void **)&_G.spill.set);
- setToNull((void **)&_G.spill.vect);
+ _G.spill.loc = 0;
+ setToNull ((void **) &_G.spill.set);
+ setToNull ((void **) &_G.spill.vect);
- // And free all registers.
- _freeAllRegs();
+ // And free all registers.
+ _freeAllRegs ();
}
-void warningStopper(void)
+void
+warningStopper (void)
{
- // For now references all unused functions.
- _dumpRegs();
- _packRegisters(NULL);
- _getSubReg(NULL, 0, 0);
+ // For now references all unused functions.
+ _dumpRegs ();
+ _packRegisters (NULL);
+ _getSubReg (NULL, 0, 0);
}
*/
#include "izt.h"
-static REG _tlcs900h_regs[] = {
- { 1, REG_ID_C, "c", 0, { REG_ID_BC, REG_ID_NONE, REG_ID_NONE } },
- { 1, REG_ID_B, "b", 0, { REG_ID_BC, REG_ID_NONE, REG_ID_NONE } },
- { 1, REG_ID_E, "e", 0, { REG_ID_DE, REG_ID_NONE, REG_ID_NONE } },
- { 1, REG_ID_D, "d", 0, { REG_ID_DE, REG_ID_NONE, REG_ID_NONE } },
- { 2, REG_ID_BC, "bc", 0, { REG_ID_C, REG_ID_B, REG_ID_NONE } },
- { 2, REG_ID_DE, "de", 0, { REG_ID_E, REG_ID_D, REG_ID_NONE } },
- { 4, REG_ID_XBC, "xbc", 0, { REG_ID_C, REG_ID_B, REG_ID_BC } },
- { 4, REG_ID_XDE, "xde", 0, { REG_ID_E, REG_ID_D, REG_ID_DE } },
- { 0, REG_ID_NONE,"??", 0, { REG_ID_NONE, REG_ID_NONE, REG_ID_NONE } }
+static REG _tlcs900h_regs[] =
+{
+ {1, REG_ID_C, "c", 0,
+ {REG_ID_BC, REG_ID_NONE, REG_ID_NONE}},
+ {1, REG_ID_B, "b", 0,
+ {REG_ID_BC, REG_ID_NONE, REG_ID_NONE}},
+ {1, REG_ID_E, "e", 0,
+ {REG_ID_DE, REG_ID_NONE, REG_ID_NONE}},
+ {1, REG_ID_D, "d", 0,
+ {REG_ID_DE, REG_ID_NONE, REG_ID_NONE}},
+ {2, REG_ID_BC, "bc", 0,
+ {REG_ID_C, REG_ID_B, REG_ID_NONE}},
+ {2, REG_ID_DE, "de", 0,
+ {REG_ID_E, REG_ID_D, REG_ID_NONE}},
+ {4, REG_ID_XBC, "xbc", 0,
+ {REG_ID_C, REG_ID_B, REG_ID_BC}},
+ {4, REG_ID_XDE, "xde", 0,
+ {REG_ID_E, REG_ID_D, REG_ID_DE}},
+ {0, REG_ID_NONE, "??", 0,
+ {REG_ID_NONE, REG_ID_NONE, REG_ID_NONE}}
};
-static IZT_PORT _tlcs900h_port = {
- _tlcs900h_regs
+static IZT_PORT _tlcs900h_port =
+{
+ _tlcs900h_regs
};
static char _defaultRules[] =
//#include "peeph.rul"
};
-static char *_tlcs900h_keywords[] = {
- NULL
+static char *_tlcs900h_keywords[] =
+{
+ NULL
};
-void tlcs900h_assignRegisters (eBBlock **ebbs, int count);
+void tlcs900h_assignRegisters (eBBlock ** ebbs, int count);
-static void _tlcs900h_init(void)
+static void
+_tlcs900h_init (void)
{
- asm_addTree(&asm_asxxxx_mapping);
- izt_init(&_tlcs900h_port);
+ asm_addTree (&asm_asxxxx_mapping);
+ izt_init (&_tlcs900h_port);
}
-static void _tlcs900h_reset_regparm()
+static void
+_tlcs900h_reset_regparm ()
{
}
-static int _tlcs900h_regparm( sym_link *l)
+static int
+_tlcs900h_regparm (sym_link * l)
{
- // PENDING: No register parameters.
- return 0;
+ // PENDING: No register parameters.
+ return 0;
}
-static bool _tlcs900h_parseOptions(int *pargc, char **argv, int *i)
+static bool
+_tlcs900h_parseOptions (int *pargc, char **argv, int *i)
{
- /* TODO: allow port-specific command line options to specify
- * segment names here.
- */
- return FALSE;
+ /* TODO: allow port-specific command line options to specify
+ * segment names here.
+ */
+ return FALSE;
}
-static void _tlcs900h_finaliseOptions(void)
+static void
+_tlcs900h_finaliseOptions (void)
{
- // No options
+ // No options
}
-static void _tlcs900h_setDefaultOptions(void)
+static void
+_tlcs900h_setDefaultOptions (void)
{
- // No options
+ // No options
}
-static const char *_tlcs900h_getRegName(struct regs *reg)
+static const char *
+_tlcs900h_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- wassert(0);
- return "err";
+ if (reg)
+ return reg->name;
+ wassert (0);
+ return "err";
}
-static void _tlcs900h_genAssemblerPreamble(FILE *of)
+static void
+_tlcs900h_genAssemblerPreamble (FILE * of)
{
- // PENDING
+ // PENDING
}
/* Generate interrupt vector table. */
-static int _tlcs900h_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
+static int
+_tlcs900h_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
{
- // PENDING
- return 0;
+ // PENDING
+ return 0;
}
/** $1 is always the basename.
MUST be terminated with a NULL.
*/
// PENDING
-static const char *_linkCmd[] = {
- "aslink", "-nf", "$1", NULL
+static const char *_linkCmd[] =
+{
+ "aslink", "-nf", "$1", NULL
};
// PENDING
-static const char *_asmCmd[] = {
- "gpasm", NULL, NULL, NULL
+static const char *_asmCmd[] =
+{
+ "gpasm", NULL, NULL, NULL
};
-void tlcs900h_assignRegisters (eBBlock **ebbs, int count)
+void
+tlcs900h_assignRegisters (eBBlock ** ebbs, int count)
{
}
/* Globals */
-PORT tlcs900h_port = {
- "tlcs900h",
- "Toshiba TLCS-900H", /* Target name */
- {
- TRUE, /* Emit glue around main */
- MODEL_SMALL,
- MODEL_SMALL
- },
- {
- _asmCmd,
- NULL,
- NULL,
- 0
- },
- {
- _linkCmd,
- NULL,
- ".o"
- },
- {
- _defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
- },
- {
- "XSEG (XDATA)",
- "STACK (DATA)",
- "CSEG (CODE)",
- "DSEG (DATA)",
- "ISEG (DATA)",
- "XSEG (XDATA)",
- "BSEG (BIT)",
- "RSEG (DATA)",
- "GSINIT (CODE)",
- "OSEG (OVR,DATA)",
- "GSFINAL (CODE)",
- "HOME (CODE)",
- NULL,
- NULL,
- 1
- },
- {
- +1, 1, 4, 1, 1, 0
- },
- /* tlcs900h has an 16 bit mul */
- {
- 2, 0
- },
- "_",
- _tlcs900h_init,
- _tlcs900h_parseOptions,
- _tlcs900h_finaliseOptions,
- _tlcs900h_setDefaultOptions,
- tlcs900h_assignRegisters,
- _tlcs900h_getRegName ,
- _tlcs900h_keywords,
- _tlcs900h_genAssemblerPreamble,
- _tlcs900h_genIVT ,
- _tlcs900h_reset_regparm,
- _tlcs900h_regparm,
+PORT tlcs900h_port =
+{
+ "tlcs900h",
+ "Toshiba TLCS-900H", /* Target name */
+ {
+ TRUE, /* Emit glue around main */
+ MODEL_SMALL,
+ MODEL_SMALL
+ },
+ {
+ _asmCmd,
+ NULL,
+ NULL,
+ 0
+ },
+ {
+ _linkCmd,
NULL,
- FALSE,
- 0, /* leave lt */
- 0, /* leave gt */
- 1, /* transform <= to ! > */
- 1, /* transform >= to ! < */
- 1, /* transform != to !(a == b) */
- 0, /* leave == */
- PORT_MAGIC
+ ".o"
+ },
+ {
+ _defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
+ },
+ {
+ "XSEG (XDATA)",
+ "STACK (DATA)",
+ "CSEG (CODE)",
+ "DSEG (DATA)",
+ "ISEG (DATA)",
+ "XSEG (XDATA)",
+ "BSEG (BIT)",
+ "RSEG (DATA)",
+ "GSINIT (CODE)",
+ "OSEG (OVR,DATA)",
+ "GSFINAL (CODE)",
+ "HOME (CODE)",
+ NULL,
+ NULL,
+ 1
+ },
+ {
+ +1, 1, 4, 1, 1, 0
+ },
+ /* tlcs900h has an 16 bit mul */
+ {
+ 2, 0
+ },
+ "_",
+ _tlcs900h_init,
+ _tlcs900h_parseOptions,
+ _tlcs900h_finaliseOptions,
+ _tlcs900h_setDefaultOptions,
+ tlcs900h_assignRegisters,
+ _tlcs900h_getRegName,
+ _tlcs900h_keywords,
+ _tlcs900h_genAssemblerPreamble,
+ _tlcs900h_genIVT,
+ _tlcs900h_reset_regparm,
+ _tlcs900h_regparm,
+ NULL,
+ FALSE,
+ 0, /* leave lt */
+ 0, /* leave gt */
+ 1, /* transform <= to ! > */
+ 1, /* transform >= to ! < */
+ 1, /* transform != to !(a == b) */
+ 0, /* leave == */
+ PORT_MAGIC
};
#include "ralloc.h"
#include "gen.h"
-char *aopLiteral (value *val, int offset);
+char *aopLiteral (value * val, int offset);
extern int allocInfo;
/* this is the down and dirty file with all kinds of
routines may be reusable, will have to see */
static char *zero = "#0x00";
-static char *one = "#0x01";
-static char *spname ;
-
-char *fReturn8051[] = {"dpl","dph","b","a" };
-char *fReturn390[] = {"dpl","dph","dpx", "b","a" };
-unsigned fReturnSize = 4; /* shared with ralloc.c */
+static char *one = "#0x01";
+static char *spname;
+
+char *fReturn8051[] =
+{"dpl", "dph", "b", "a"};
+char *fReturn390[] =
+{"dpl", "dph", "dpx", "b", "a"};
+unsigned fReturnSize = 4; /* shared with ralloc.c */
char **fReturn = fReturn8051;
-static char *accUse[] = {"a","b"};
+static char *accUse[] =
+{"a", "b"};
static short rbank = -1;
-static struct {
+static struct
+ {
short r0Pushed;
short r1Pushed;
short accInUse;
short debugLine;
short nRegsSaved;
set *sendSet;
-} _G;
+ }
+_G;
-extern int mcs51_ptrRegReq ;
+extern int mcs51_ptrRegReq;
extern int mcs51_nRegs;
extern FILE *codeOutFile;
-static void saverbank (int, iCode *,bool);
+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};
+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
/*-----------------------------------------------------------------*/
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
-static void emitcode (char *inst,char *fmt, ...)
+static void
+emitcode (char *inst, char *fmt,...)
{
- va_list ap;
- char lb[MAX_INLINEASM];
- char *lbp = lb;
+ va_list ap;
+ char lb[MAX_INLINEASM];
+ char *lbp = lb;
- va_start(ap,fmt);
+ va_start (ap, fmt);
- if (inst && *inst) {
- if (fmt && *fmt)
- sprintf(lb,"%s\t",inst);
+ if (inst && *inst)
+ {
+ if (fmt && *fmt)
+ sprintf (lb, "%s\t", inst);
+ else
+ sprintf (lb, "%s", inst);
+ vsprintf (lb + (strlen (lb)), fmt, ap);
+ }
else
- sprintf(lb,"%s",inst);
- vsprintf(lb+(strlen(lb)),fmt,ap);
- } else
- vsprintf(lb,fmt,ap);
+ vsprintf (lb, fmt, ap);
- while (isspace(*lbp)) lbp++;
+ while (isspace (*lbp))
+ lbp++;
- if (lbp && *lbp)
- lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(lb)) :
- (lineHead = newLineNode(lb)));
- lineCurr->isInline = _G.inLine;
- lineCurr->isDebug = _G.debugLine;
- va_end(ap);
+ if (lbp && *lbp)
+ lineCurr = (lineCurr ?
+ connectLine (lineCurr, newLineNode (lb)) :
+ (lineHead = newLineNode (lb)));
+ lineCurr->isInline = _G.inLine;
+ lineCurr->isDebug = _G.debugLine;
+ va_end (ap);
}
/*-----------------------------------------------------------------*/
-/* getFreePtr - returns r0 or r1 whichever is free or can be pushed*/
+/* getFreePtr - returns r0 or r1 whichever is free or can be pushed */
/*-----------------------------------------------------------------*/
-static regs *getFreePtr (iCode *ic, asmop **aopp, bool result)
+static regs *
+getFreePtr (iCode * ic, asmop ** aopp, bool result)
{
- bool r0iu = FALSE , r1iu = FALSE;
- bool r0ou = FALSE , r1ou = FALSE;
+ bool r0iu = FALSE, r1iu = FALSE;
+ bool r0ou = FALSE, r1ou = FALSE;
- /* the logic: if r0 & r1 used in the instruction
- then we are in trouble otherwise */
+ /* the logic: if r0 & r1 used in the instruction
+ then we are in trouble otherwise */
- /* 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)))
+ /* 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)))
{
- goto endOfWorld;
+ goto endOfWorld;
}
- r0ou = bitVectBitValue(ic->rMask,R0_IDX);
- r1ou = bitVectBitValue(ic->rMask,R1_IDX);
+ r0ou = bitVectBitValue (ic->rMask, R0_IDX);
+ r1ou = bitVectBitValue (ic->rMask, R1_IDX);
- /* if no usage of r0 then return it */
- if (!r0iu && !r0ou) {
- ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
- (*aopp)->type = AOP_R0;
+ /* if no usage of r0 then return it */
+ if (!r0iu && !r0ou)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
+ (*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx (R0_IDX);
}
- /* if no usage of r1 then return it */
- if (!r1iu && !r1ou) {
- ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
- (*aopp)->type = AOP_R1;
+ /* if no usage of r1 then return it */
+ if (!r1iu && !r1ou)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
+ (*aopp)->type = AOP_R1;
- return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx(R1_IDX);
+ return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx (R1_IDX);
}
- /* now we know they both have usage */
- /* if r0 not used in this instruction */
- if (!r0iu) {
- /* push it if not already pushed */
- if (!_G.r0Pushed) {
- emitcode ("push","%s",
- mcs51_regWithIdx(R0_IDX)->dname);
- _G.r0Pushed++ ;
- }
+ /* now we know they both have usage */
+ /* if r0 not used in this instruction */
+ if (!r0iu)
+ {
+ /* push it if not already pushed */
+ if (!_G.r0Pushed)
+ {
+ emitcode ("push", "%s",
+ mcs51_regWithIdx (R0_IDX)->dname);
+ _G.r0Pushed++;
+ }
- ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
- (*aopp)->type = AOP_R0;
+ ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
+ (*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx (R0_IDX);
}
- /* if r1 not used then */
-
- if (!r1iu) {
- /* push it if not already pushed */
- if (!_G.r1Pushed) {
- emitcode ("push","%s",
- mcs51_regWithIdx(R1_IDX)->dname);
- _G.r1Pushed++ ;
- }
-
- ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
- (*aopp)->type = AOP_R1;
- return mcs51_regWithIdx(R1_IDX);
- }
+ /* if r1 not used then */
-endOfWorld :
- /* I said end of world but not quite end of world yet */
- /* if this is a result then we can push it on the stack*/
- if (result) {
- (*aopp)->type = AOP_STK;
- return NULL;
+ if (!r1iu)
+ {
+ /* push it if not already pushed */
+ if (!_G.r1Pushed)
+ {
+ emitcode ("push", "%s",
+ mcs51_regWithIdx (R1_IDX)->dname);
+ _G.r1Pushed++;
+ }
+
+ ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
+ (*aopp)->type = AOP_R1;
+ return mcs51_regWithIdx (R1_IDX);
+ }
+
+endOfWorld:
+ /* I said end of world but not quite end of world yet */
+ /* if this is a result then we can push it on the stack */
+ if (result)
+ {
+ (*aopp)->type = AOP_STK;
+ 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");
- exit(0);
+ piCode (ic, stdout);
+ /* other wise this is true end of the world */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "getFreePtr should never reach here");
+ exit (0);
}
/*-----------------------------------------------------------------*/
/* newAsmop - creates a new asmOp */
/*-----------------------------------------------------------------*/
-static asmop *newAsmop (short type)
+static asmop *
+newAsmop (short type)
{
- asmop *aop;
+ asmop *aop;
- aop = Safe_calloc(1,sizeof(asmop));
- aop->type = type;
- return aop;
+ aop = Safe_calloc (1, sizeof (asmop));
+ aop->type = type;
+ return aop;
}
-static void genSetDPTR(int n)
+static void
+genSetDPTR (int n)
{
- if (!n)
+ if (!n)
{
- emitcode(";", "Select standard DPTR");
- emitcode("mov", "dps, #0x00");
+ emitcode (";", "Select standard DPTR");
+ emitcode ("mov", "dps, #0x00");
}
- else
+ else
{
- emitcode(";", "Select alternate DPTR");
- emitcode("mov", "dps, #0x01");
+ emitcode (";", "Select alternate DPTR");
+ emitcode ("mov", "dps, #0x01");
}
}
/*-----------------------------------------------------------------*/
/* pointerCode - returns the code for a pointer type */
/*-----------------------------------------------------------------*/
-static int pointerCode (sym_link *etype)
+static int
+pointerCode (sym_link * etype)
{
- return PTR_TYPE(SPEC_OCLS(etype));
+ return PTR_TYPE (SPEC_OCLS (etype));
}
/*-----------------------------------------------------------------*/
/* aopForSym - for a true symbol */
/*-----------------------------------------------------------------*/
-static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
-{
- asmop *aop;
- memmap *space= SPEC_OCLS(sym->etype);
-
- /* if already has one */
- if (sym->aop)
- return sym->aop;
-
- /* assign depending on the storage class */
- /* if it is on the stack or indirectly addressable */
- /* space we need to assign either r0 or r1 to it */
- if ((sym->onStack && !options.stack10bit) || sym->iaccess) {
- sym->aop = aop = newAsmop(0);
- aop->aopu.aop_ptr = getFreePtr(ic,&aop,result);
- aop->size = getSize(sym->type);
-
- /* now assign the address of the variable to
- the pointer register */
- if (aop->type != AOP_STK) {
-
- if (sym->onStack) {
- if ( _G.accInUse )
- emitcode("push","acc");
-
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",
- ((sym->stack < 0) ?
- ((char)(sym->stack - _G.nRegsSaved )) :
- ((char)sym->stack)) & 0xff);
- emitcode("mov","%s,a",
- aop->aopu.aop_ptr->name);
-
- if ( _G.accInUse )
- emitcode("pop","acc");
- } else
- emitcode("mov","%s,#%s",
- aop->aopu.aop_ptr->name,
- sym->rname);
- aop->paged = space->paged;
- } else
- aop->aopu.aop_stk = sym->stack;
- return aop;
- }
-
- if (sym->onStack && options.stack10bit)
- {
- /* It's on the 10 bit stack, which is located in
- * far data space.
- */
-
- if ( _G.accInUse )
- emitcode("push","acc");
-
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",
- ((sym->stack < 0) ?
- ((char)(sym->stack - _G.nRegsSaved )) :
- ((char)sym->stack)) & 0xff);
-
- genSetDPTR(1);
- emitcode ("mov","dpx1,#0x40");
- emitcode ("mov","dph1,#0x00");
- emitcode ("mov","dpl1, a");
- genSetDPTR(0);
-
- if ( _G.accInUse )
- emitcode("pop","acc");
-
- sym->aop = aop = newAsmop(AOP_DPTR2);
- aop->size = getSize(sym->type);
+static asmop *
+aopForSym (iCode * ic, symbol * sym, bool result)
+{
+ asmop *aop;
+ memmap *space = SPEC_OCLS (sym->etype);
+
+ /* if already has one */
+ if (sym->aop)
+ return sym->aop;
+
+ /* assign depending on the storage class */
+ /* if it is on the stack or indirectly addressable */
+ /* space we need to assign either r0 or r1 to it */
+ if ((sym->onStack && !options.stack10bit) || sym->iaccess)
+ {
+ sym->aop = aop = newAsmop (0);
+ aop->aopu.aop_ptr = getFreePtr (ic, &aop, result);
+ aop->size = getSize (sym->type);
+
+ /* now assign the address of the variable to
+ the pointer register */
+ if (aop->type != AOP_STK)
+ {
+
+ if (sym->onStack)
+ {
+ if (_G.accInUse)
+ emitcode ("push", "acc");
+
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x",
+ ((sym->stack < 0) ?
+ ((char) (sym->stack - _G.nRegsSaved)) :
+ ((char) sym->stack)) & 0xff);
+ emitcode ("mov", "%s,a",
+ aop->aopu.aop_ptr->name);
+
+ if (_G.accInUse)
+ emitcode ("pop", "acc");
+ }
+ else
+ emitcode ("mov", "%s,#%s",
+ aop->aopu.aop_ptr->name,
+ sym->rname);
+ aop->paged = space->paged;
+ }
+ else
+ aop->aopu.aop_stk = sym->stack;
+ return aop;
+ }
+
+ if (sym->onStack && options.stack10bit)
+ {
+ /* It's on the 10 bit stack, which is located in
+ * far data space.
+ */
+
+ if (_G.accInUse)
+ emitcode ("push", "acc");
+
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x",
+ ((sym->stack < 0) ?
+ ((char) (sym->stack - _G.nRegsSaved)) :
+ ((char) sym->stack)) & 0xff);
+
+ genSetDPTR (1);
+ emitcode ("mov", "dpx1,#0x40");
+ emitcode ("mov", "dph1,#0x00");
+ emitcode ("mov", "dpl1, a");
+ genSetDPTR (0);
+
+ if (_G.accInUse)
+ emitcode ("pop", "acc");
+
+ sym->aop = aop = newAsmop (AOP_DPTR2);
+ aop->size = getSize (sym->type);
return aop;
}
- /* if in bit space */
- if (IN_BITSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_CRY);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- return aop;
+ /* if in bit space */
+ if (IN_BITSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_CRY);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ return aop;
}
- /* if it is in direct space */
- if (IN_DIRSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_DIR);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- return aop;
+ /* if it is in direct space */
+ if (IN_DIRSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_DIR);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ return aop;
}
- /* special case for a function */
- if (IS_FUNC(sym->type)) {
- sym->aop = aop = newAsmop(AOP_IMMD);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(sym->rname)+1);
- strcpy(aop->aopu.aop_immd,sym->rname);
- aop->size = FPTRSIZE;
- return aop;
+ /* special case for a function */
+ if (IS_FUNC (sym->type))
+ {
+ sym->aop = aop = newAsmop (AOP_IMMD);
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (sym->rname) + 1);
+ strcpy (aop->aopu.aop_immd, sym->rname);
+ aop->size = FPTRSIZE;
+ return aop;
}
- /* only remaining is far space */
- /* in which case DPTR gets the address */
- sym->aop = aop = newAsmop(AOP_DPTR);
- emitcode ("mov","dptr,#%s", sym->rname);
- aop->size = getSize(sym->type);
+ /* only remaining is far space */
+ /* in which case DPTR gets the address */
+ sym->aop = aop = newAsmop (AOP_DPTR);
+ emitcode ("mov", "dptr,#%s", sym->rname);
+ aop->size = getSize (sym->type);
- /* if it is in code space */
- if (IN_CODESPACE(space))
- aop->code = 1;
+ /* if it is in code space */
+ if (IN_CODESPACE (space))
+ aop->code = 1;
- return aop;
+ return aop;
}
/*-----------------------------------------------------------------*/
/* aopForRemat - rematerialzes an object */
/*-----------------------------------------------------------------*/
-static asmop *aopForRemat (symbol *sym)
+static asmop *
+aopForRemat (symbol * sym)
{
- iCode *ic = sym->rematiCode;
- asmop *aop = newAsmop(AOP_IMMD);
- int val = 0;
+ iCode *ic = sym->rematiCode;
+ asmop *aop = newAsmop (AOP_IMMD);
+ int val = 0;
- for (;;) {
+ for (;;)
+ {
if (ic->op == '+')
- val += operandLitValue(IC_RIGHT(ic));
- else if (ic->op == '-')
- val -= operandLitValue(IC_RIGHT(ic));
- else
- break;
+ val += operandLitValue (IC_RIGHT (ic));
+ else if (ic->op == '-')
+ val -= operandLitValue (IC_RIGHT (ic));
+ else
+ break;
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
}
- if (val)
- sprintf(buffer,"(%s %c 0x%04x)",
- OP_SYMBOL(IC_LEFT(ic))->rname,
- val >= 0 ? '+' : '-',
- abs(val) & 0xffff);
- else
- strcpy(buffer,OP_SYMBOL(IC_LEFT(ic))->rname);
+ if (val)
+ sprintf (buffer, "(%s %c 0x%04x)",
+ OP_SYMBOL (IC_LEFT (ic))->rname,
+ val >= 0 ? '+' : '-',
+ abs (val) & 0xffff);
+ else
+ strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(buffer)+1);
- strcpy(aop->aopu.aop_immd,buffer);
- return aop;
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (buffer) + 1);
+ strcpy (aop->aopu.aop_immd, buffer);
+ return aop;
}
/*-----------------------------------------------------------------*/
/* regsInCommon - two operands have some registers in common */
/*-----------------------------------------------------------------*/
-static bool regsInCommon (operand *op1, operand *op2)
+static bool
+regsInCommon (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
- int i;
+ symbol *sym1, *sym2;
+ int i;
- /* if they have registers in common */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE ;
+ /* if they have registers in common */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- if (sym1->nRegs == 0 || sym2->nRegs == 0)
- return FALSE ;
+ if (sym1->nRegs == 0 || sym2->nRegs == 0)
+ return FALSE;
- for (i = 0 ; i < sym1->nRegs ; i++) {
- int j;
- if (!sym1->regs[i])
- continue ;
+ for (i = 0; i < sym1->nRegs; i++)
+ {
+ int j;
+ if (!sym1->regs[i])
+ continue;
- for (j = 0 ; j < sym2->nRegs ;j++ ) {
- if (!sym2->regs[j])
- continue ;
+ for (j = 0; j < sym2->nRegs; j++)
+ {
+ if (!sym2->regs[j])
+ continue;
- if (sym2->regs[j] == sym1->regs[i])
- return TRUE ;
- }
+ if (sym2->regs[j] == sym1->regs[i])
+ return TRUE;
+ }
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* operandsEqu - equivalent */
/*-----------------------------------------------------------------*/
-static bool operandsEqu ( operand *op1, operand *op2)
+static bool
+operandsEqu (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
+ symbol *sym1, *sym2;
- /* if they not symbols */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE;
+ /* if they not symbols */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- /* if both are itemps & one is spilt
- and the other is not then false */
- if (IS_ITEMP(op1) && IS_ITEMP(op2) &&
- sym1->isspilt != sym2->isspilt )
- return FALSE ;
+ /* if both are itemps & one is spilt
+ and the other is not then false */
+ if (IS_ITEMP (op1) && IS_ITEMP (op2) &&
+ sym1->isspilt != sym2->isspilt)
+ return FALSE;
- /* if they are the same */
- if (sym1 == sym2)
- return TRUE ;
+ /* if they are the same */
+ if (sym1 == sym2)
+ return TRUE;
- if (strcmp(sym1->rname,sym2->rname) == 0)
- return TRUE;
+ if (strcmp (sym1->rname, sym2->rname) == 0)
+ return TRUE;
- /* if left is a tmp & right is not */
- if (IS_ITEMP(op1) &&
- !IS_ITEMP(op2) &&
- sym1->isspilt &&
- (sym1->usl.spillLoc == sym2))
- return TRUE;
+ /* if left is a tmp & right is not */
+ if (IS_ITEMP (op1) &&
+ !IS_ITEMP (op2) &&
+ sym1->isspilt &&
+ (sym1->usl.spillLoc == sym2))
+ return TRUE;
- if (IS_ITEMP(op2) &&
- !IS_ITEMP(op1) &&
- sym2->isspilt &&
- sym1->level > 0 &&
- (sym2->usl.spillLoc == sym1))
- return TRUE ;
+ if (IS_ITEMP (op2) &&
+ !IS_ITEMP (op1) &&
+ sym2->isspilt &&
+ sym1->level > 0 &&
+ (sym2->usl.spillLoc == sym1))
+ return TRUE;
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* sameRegs - two asmops have the same registers */
/*-----------------------------------------------------------------*/
-static bool sameRegs (asmop *aop1, asmop *aop2 )
+static bool
+sameRegs (asmop * aop1, asmop * aop2)
{
- int i;
+ int i;
- if (aop1 == aop2)
- return TRUE ;
+ if (aop1 == aop2)
+ return TRUE;
- if (aop1->type != AOP_REG ||
- aop2->type != AOP_REG )
- return FALSE ;
+ if (aop1->type != AOP_REG ||
+ aop2->type != AOP_REG)
+ return FALSE;
- if (aop1->size != aop2->size )
- return FALSE ;
+ if (aop1->size != aop2->size)
+ return FALSE;
- for (i = 0 ; i < aop1->size ; i++ )
- if (aop1->aopu.aop_reg[i] !=
- aop2->aopu.aop_reg[i] )
- return FALSE ;
+ for (i = 0; i < aop1->size; i++)
+ if (aop1->aopu.aop_reg[i] !=
+ aop2->aopu.aop_reg[i])
+ return FALSE;
- return TRUE ;
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* aopOp - allocates an asmop for an operand : */
/*-----------------------------------------------------------------*/
-static void aopOp (operand *op, iCode *ic, bool result)
+static void
+aopOp (operand * op, iCode * ic, bool result)
{
- asmop *aop;
- symbol *sym;
- int i;
+ asmop *aop;
+ symbol *sym;
+ int i;
- if (!op)
- return ;
+ if (!op)
+ return;
- /* if this a literal */
- if (IS_OP_LITERAL(op)) {
- op->aop = aop = newAsmop(AOP_LIT);
- aop->aopu.aop_lit = op->operand.valOperand;
- aop->size = getSize(operandType(op));
- return;
+ /* if this a literal */
+ if (IS_OP_LITERAL (op))
+ {
+ op->aop = aop = newAsmop (AOP_LIT);
+ aop->aopu.aop_lit = op->operand.valOperand;
+ aop->size = getSize (operandType (op));
+ return;
}
- /* if already has a asmop then continue */
- if (op->aop)
- return ;
+ /* if already has a asmop then continue */
+ if (op->aop)
+ return;
- /* if the underlying symbol has a aop */
- if (IS_SYMOP(op) && OP_SYMBOL(op)->aop) {
- op->aop = OP_SYMBOL(op)->aop;
- return;
+ /* if the underlying symbol has a aop */
+ if (IS_SYMOP (op) && OP_SYMBOL (op)->aop)
+ {
+ op->aop = OP_SYMBOL (op)->aop;
+ return;
}
- /* if this is a true symbol */
- if (IS_TRUE_SYMOP(op)) {
- op->aop = aopForSym(ic,OP_SYMBOL(op),result);
- return ;
+ /* if this is a true symbol */
+ if (IS_TRUE_SYMOP (op))
+ {
+ op->aop = aopForSym (ic, OP_SYMBOL (op), result);
+ return;
}
- /* this is a temporary : this has
- only four choices :
- a) register
- b) spillocation
- c) rematerialize
- d) conditional
- e) can be a return use only */
+ /* this is a temporary : this has
+ only four choices :
+ a) register
+ b) spillocation
+ c) rematerialize
+ d) conditional
+ e) can be a return use only */
- sym = OP_SYMBOL(op);
+ sym = OP_SYMBOL (op);
- /* if the type is a conditional */
- if (sym->regType == REG_CND) {
- aop = op->aop = sym->aop = newAsmop(AOP_CRY);
- aop->size = 0;
- return;
+ /* if the type is a conditional */
+ if (sym->regType == REG_CND)
+ {
+ aop = op->aop = sym->aop = newAsmop (AOP_CRY);
+ aop->size = 0;
+ return;
}
- /* if it is spilt then two situations
- a) is rematerialize
- b) has a spill location */
- if (sym->isspilt || sym->nRegs == 0) {
-
- /* rematerialize it NOW */
- if (sym->remat) {
- sym->aop = op->aop = aop =
- aopForRemat (sym);
- aop->size = getSize(sym->type);
- return;
- }
-
- if (sym->accuse) {
- int i;
- aop = op->aop = sym->aop = newAsmop(AOP_ACC);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < 2 ; i++ )
- aop->aopu.aop_str[i] = accUse[i];
- return;
- }
-
- if (sym->ruonly ) {
- int i;
- aop = op->aop = sym->aop = newAsmop(AOP_STR);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < fReturnSize ; i++ )
- aop->aopu.aop_str[i] = fReturn[i];
- return;
- }
-
- /* else spill location */
- sym->aop = op->aop = aop =
- aopForSym(ic,sym->usl.spillLoc,result);
- aop->size = getSize(sym->type);
- return;
- }
+ /* if it is spilt then two situations
+ a) is rematerialize
+ b) has a spill location */
+ if (sym->isspilt || sym->nRegs == 0)
+ {
- /* must be in a register */
- sym->aop = op->aop = aop = newAsmop(AOP_REG);
- aop->size = sym->nRegs;
- for ( i = 0 ; i < sym->nRegs ;i++)
- aop->aopu.aop_reg[i] = sym->regs[i];
+ /* rematerialize it NOW */
+ if (sym->remat)
+ {
+ sym->aop = op->aop = aop =
+ aopForRemat (sym);
+ aop->size = getSize (sym->type);
+ return;
+ }
+
+ if (sym->accuse)
+ {
+ int i;
+ aop = op->aop = sym->aop = newAsmop (AOP_ACC);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < 2; i++)
+ aop->aopu.aop_str[i] = accUse[i];
+ return;
+ }
+
+ if (sym->ruonly)
+ {
+ int i;
+ aop = op->aop = sym->aop = newAsmop (AOP_STR);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < fReturnSize; i++)
+ aop->aopu.aop_str[i] = fReturn[i];
+ return;
+ }
+
+ /* else spill location */
+ sym->aop = op->aop = aop =
+ aopForSym (ic, sym->usl.spillLoc, result);
+ aop->size = getSize (sym->type);
+ return;
+ }
+
+ /* must be in a register */
+ sym->aop = op->aop = aop = newAsmop (AOP_REG);
+ aop->size = sym->nRegs;
+ for (i = 0; i < sym->nRegs; i++)
+ aop->aopu.aop_reg[i] = sym->regs[i];
}
/*-----------------------------------------------------------------*/
/* freeAsmop - free up the asmop given to an operand */
/*----------------------------------------------------------------*/
-static void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
-{
- asmop *aop ;
-
- if (!op)
- aop = aaop;
- else
- aop = op->aop;
-
- if (!aop)
- return ;
-
- if (aop->freed)
- goto dealloc;
-
- aop->freed = 1;
-
- /* depending on the asmop type only three cases need work AOP_RO
- , AOP_R1 && AOP_STK */
- switch (aop->type) {
- case AOP_R0 :
- if (_G.r0Pushed ) {
- if (pop) {
- emitcode ("pop","ar0");
- _G.r0Pushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,R0_IDX);
- break;
-
- case AOP_R1 :
- if (_G.r1Pushed ) {
- if (pop) {
- emitcode ("pop","ar1");
- _G.r1Pushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,R1_IDX);
- break;
-
- case AOP_STK :
- {
- int sz = aop->size;
- int stk = aop->aopu.aop_stk + aop->size;
- bitVectUnSetBit(ic->rUsed,R0_IDX);
- bitVectUnSetBit(ic->rUsed,R1_IDX);
-
- getFreePtr(ic,&aop,FALSE);
-
- if (options.stack10bit)
- {
- /* I'm not sure what to do here yet... */
- /* #STUB */
- fprintf(stderr,
- "*** Warning: probably generating bad code for "
- "10 bit stack mode.\n");
- }
-
- if (stk) {
- emitcode ("mov","a,_bp");
- emitcode ("add","a,#0x%02x",((char)stk) & 0xff);
- emitcode ("mov","%s,a",aop->aopu.aop_ptr->name);
- } else {
- emitcode ("mov","%s,_bp",aop->aopu.aop_ptr->name);
- }
-
- while (sz--) {
- emitcode("pop","acc");
- emitcode("mov","@%s,a",aop->aopu.aop_ptr->name);
- if (!sz) break;
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- }
- op->aop = aop;
- freeAsmop(op,NULL,ic,TRUE);
- if (_G.r0Pushed) {
- emitcode("pop","ar0");
- _G.r0Pushed--;
- }
-
- if (_G.r1Pushed) {
- emitcode("pop","ar1");
- _G.r1Pushed--;
- }
- }
+static void
+freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
+{
+ asmop *aop;
+
+ if (!op)
+ aop = aaop;
+ else
+ aop = op->aop;
+
+ if (!aop)
+ return;
+
+ if (aop->freed)
+ goto dealloc;
+
+ aop->freed = 1;
+
+ /* depending on the asmop type only three cases need work AOP_RO
+ , AOP_R1 && AOP_STK */
+ switch (aop->type)
+ {
+ case AOP_R0:
+ if (_G.r0Pushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "ar0");
+ _G.r0Pushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, R0_IDX);
+ break;
+
+ case AOP_R1:
+ if (_G.r1Pushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "ar1");
+ _G.r1Pushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, R1_IDX);
+ break;
+
+ case AOP_STK:
+ {
+ int sz = aop->size;
+ int stk = aop->aopu.aop_stk + aop->size;
+ bitVectUnSetBit (ic->rUsed, R0_IDX);
+ bitVectUnSetBit (ic->rUsed, R1_IDX);
+
+ getFreePtr (ic, &aop, FALSE);
+
+ if (options.stack10bit)
+ {
+ /* I'm not sure what to do here yet... */
+ /* #STUB */
+ fprintf (stderr,
+ "*** Warning: probably generating bad code for "
+ "10 bit stack mode.\n");
+ }
+
+ if (stk)
+ {
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x", ((char) stk) & 0xff);
+ emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name);
+ }
+ else
+ {
+ emitcode ("mov", "%s,_bp", aop->aopu.aop_ptr->name);
+ }
+
+ while (sz--)
+ {
+ emitcode ("pop", "acc");
+ emitcode ("mov", "@%s,a", aop->aopu.aop_ptr->name);
+ if (!sz)
+ break;
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ }
+ op->aop = aop;
+ freeAsmop (op, NULL, ic, TRUE);
+ if (_G.r0Pushed)
+ {
+ emitcode ("pop", "ar0");
+ _G.r0Pushed--;
+ }
+
+ if (_G.r1Pushed)
+ {
+ emitcode ("pop", "ar1");
+ _G.r1Pushed--;
+ }
+ }
}
dealloc:
- /* all other cases just dealloc */
- if (op ) {
- op->aop = NULL;
- if (IS_SYMOP(op)) {
- OP_SYMBOL(op)->aop = NULL;
- /* if the symbol has a spill */
- if (SPIL_LOC(op))
- SPIL_LOC(op)->aop = NULL;
- }
+ /* all other cases just dealloc */
+ if (op)
+ {
+ op->aop = NULL;
+ if (IS_SYMOP (op))
+ {
+ OP_SYMBOL (op)->aop = NULL;
+ /* if the symbol has a spill */
+ if (SPIL_LOC (op))
+ SPIL_LOC (op)->aop = NULL;
+ }
}
}
/*-----------------------------------------------------------------*/
/* aopGet - for fetching value of the aop */
/*-----------------------------------------------------------------*/
-static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
+static char *
+aopGet (asmop * aop, int offset, bool bit16, bool dname)
{
- char *s = buffer ;
- char *rs;
+ char *s = buffer;
+ char *rs;
- /* offset is greater than
- size then zero */
- if (offset > (aop->size - 1) &&
- aop->type != AOP_LIT)
- return zero;
+ /* offset is greater than
+ size then zero */
+ if (offset > (aop->size - 1) &&
+ aop->type != AOP_LIT)
+ return zero;
- /* depending on type */
- switch (aop->type) {
+ /* depending on type */
+ switch (aop->type)
+ {
case AOP_R0:
case AOP_R1:
- /* if we need to increment it */
- while (offset > aop->coff) {
- emitcode ("inc","%s",aop->aopu.aop_ptr->name);
- aop->coff++;
- }
-
- while (offset < aop->coff) {
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- aop->coff--;
- }
-
- aop->coff = offset ;
- if (aop->paged) {
- emitcode("movx","a,@%s",aop->aopu.aop_ptr->name);
- return (dname ? "acc" : "a");
- }
- sprintf(s,"@%s",aop->aopu.aop_ptr->name);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ /* if we need to increment it */
+ while (offset > aop->coff)
+ {
+ emitcode ("inc", "%s", aop->aopu.aop_ptr->name);
+ aop->coff++;
+ }
+
+ while (offset < aop->coff)
+ {
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ aop->coff--;
+ }
+
+ aop->coff = offset;
+ if (aop->paged)
+ {
+ emitcode ("movx", "a,@%s", aop->aopu.aop_ptr->name);
+ return (dname ? "acc" : "a");
+ }
+ sprintf (s, "@%s", aop->aopu.aop_ptr->name);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_DPTR:
case AOP_DPTR2:
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- }
-
- while (offset > aop->coff) {
- emitcode ("inc","dptr");
- aop->coff++;
- }
-
- while (offset < aop->coff) {
- emitcode("lcall","__decdptr");
- aop->coff--;
- }
-
- aop->coff = offset;
- if (aop->code) {
- emitcode("clr","a");
- emitcode("movc","a,@a+dptr");
- }
- else {
- emitcode("movx","a,@dptr");
- }
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (1);
+ }
+
+ while (offset > aop->coff)
+ {
+ emitcode ("inc", "dptr");
+ aop->coff++;
+ }
+
+ while (offset < aop->coff)
+ {
+ emitcode ("lcall", "__decdptr");
+ aop->coff--;
+ }
+
+ aop->coff = offset;
+ if (aop->code)
+ {
+ emitcode ("clr", "a");
+ emitcode ("movc", "a,@a+dptr");
+ }
+ else
+ {
+ emitcode ("movx", "a,@dptr");
+ }
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (0);
+ }
- return (dname ? "acc" : "a");
+ return (dname ? "acc" : "a");
case AOP_IMMD:
- if (bit16)
- sprintf (s,"#%s",aop->aopu.aop_immd);
- else
- if (offset)
- sprintf(s,"#(%s >> %d)",
- aop->aopu.aop_immd,
- offset*8);
+ if (bit16)
+ sprintf (s, "#%s", aop->aopu.aop_immd);
+ else if (offset)
+ sprintf (s, "#(%s >> %d)",
+ aop->aopu.aop_immd,
+ offset * 8);
else
- sprintf(s,"#%s",
- aop->aopu.aop_immd);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ sprintf (s, "#%s",
+ aop->aopu.aop_immd);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_DIR:
- if (offset)
- sprintf(s,"(%s + %d)",
- aop->aopu.aop_dir,
- offset);
- else
- sprintf(s,"%s",aop->aopu.aop_dir);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ if (offset)
+ sprintf (s, "(%s + %d)",
+ aop->aopu.aop_dir,
+ offset);
+ else
+ sprintf (s, "%s", aop->aopu.aop_dir);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_REG:
- if (dname)
- return aop->aopu.aop_reg[offset]->dname;
- else
- return aop->aopu.aop_reg[offset]->name;
+ if (dname)
+ return aop->aopu.aop_reg[offset]->dname;
+ else
+ return aop->aopu.aop_reg[offset]->name;
case AOP_CRY:
- emitcode("clr","a");
- emitcode("mov","c,%s",aop->aopu.aop_dir);
- emitcode("rlc","a") ;
- return (dname ? "acc" : "a");
+ emitcode ("clr", "a");
+ emitcode ("mov", "c,%s", aop->aopu.aop_dir);
+ emitcode ("rlc", "a");
+ return (dname ? "acc" : "a");
case AOP_ACC:
- if (!offset && dname)
- return "acc";
- return aop->aopu.aop_str[offset];
+ if (!offset && dname)
+ return "acc";
+ return aop->aopu.aop_str[offset];
case AOP_LIT:
- return aopLiteral (aop->aopu.aop_lit,offset);
+ return aopLiteral (aop->aopu.aop_lit, offset);
case AOP_STR:
- aop->coff = offset ;
- if (strcmp(aop->aopu.aop_str[offset],"a") == 0 &&
- dname)
- return "acc";
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], "a") == 0 &&
+ dname)
+ return "acc";
- return aop->aopu.aop_str[offset];
+ return aop->aopu.aop_str[offset];
}
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopget got unsupported aop->type");
- exit(0);
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopget got unsupported aop->type");
+ exit (0);
}
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop */
/*-----------------------------------------------------------------*/
-static void aopPut (asmop *aop, char *s, int offset)
+static void
+aopPut (asmop * aop, char *s, int offset)
{
- char *d = buffer ;
- symbol *lbl ;
+ char *d = buffer;
+ symbol *lbl;
- if (aop->size && offset > ( aop->size - 1)) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got offset > aop->size");
- exit(0);
+ if (aop->size && offset > (aop->size - 1))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got offset > aop->size");
+ exit (0);
}
- /* will assign value to value */
- /* depending on where it is ofcourse */
- switch (aop->type) {
+ /* will assign value to value */
+ /* depending on where it is ofcourse */
+ switch (aop->type)
+ {
case AOP_DIR:
- if (offset)
- sprintf(d,"(%s + %d)",
- aop->aopu.aop_dir,offset);
- else
- sprintf(d,"%s",aop->aopu.aop_dir);
+ if (offset)
+ sprintf (d, "(%s + %d)",
+ aop->aopu.aop_dir, offset);
+ else
+ sprintf (d, "%s", aop->aopu.aop_dir);
- if (strcmp(d,s))
- emitcode("mov","%s,%s",d,s);
+ if (strcmp (d, s))
+ emitcode ("mov", "%s,%s", d, s);
- break;
+ break;
case AOP_REG:
- if (strcmp(aop->aopu.aop_reg[offset]->name,s) != 0 &&
- strcmp(aop->aopu.aop_reg[offset]->dname,s)!= 0){
- if (*s == '@' ||
- strcmp(s,"r0") == 0 ||
- strcmp(s,"r1") == 0 ||
- strcmp(s,"r2") == 0 ||
- strcmp(s,"r3") == 0 ||
- strcmp(s,"r4") == 0 ||
- strcmp(s,"r5") == 0 ||
- strcmp(s,"r6") == 0 ||
- strcmp(s,"r7") == 0 )
- emitcode("mov","%s,%s",
- aop->aopu.aop_reg[offset]->dname,s);
- else
- emitcode("mov","%s,%s",
- aop->aopu.aop_reg[offset]->name,s);
- }
- break;
+ if (strcmp (aop->aopu.aop_reg[offset]->name, s) != 0 &&
+ strcmp (aop->aopu.aop_reg[offset]->dname, s) != 0)
+ {
+ if (*s == '@' ||
+ strcmp (s, "r0") == 0 ||
+ strcmp (s, "r1") == 0 ||
+ strcmp (s, "r2") == 0 ||
+ strcmp (s, "r3") == 0 ||
+ strcmp (s, "r4") == 0 ||
+ strcmp (s, "r5") == 0 ||
+ strcmp (s, "r6") == 0 ||
+ strcmp (s, "r7") == 0)
+ emitcode ("mov", "%s,%s",
+ aop->aopu.aop_reg[offset]->dname, s);
+ else
+ emitcode ("mov", "%s,%s",
+ aop->aopu.aop_reg[offset]->name, s);
+ }
+ break;
case AOP_DPTR:
case AOP_DPTR2:
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- }
-
- if (aop->code) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut writting to code space");
- exit(0);
- }
-
- while (offset > aop->coff) {
- aop->coff++;
- emitcode ("inc","dptr");
- }
-
- while (offset < aop->coff) {
- aop->coff-- ;
- emitcode("lcall","__decdptr");
- }
-
- aop->coff = offset;
-
- /* if not in accumulater */
- MOVA(s);
-
- emitcode ("movx","@dptr,a");
-
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
- break;
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (1);
+ }
+
+ if (aop->code)
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut writting to code space");
+ exit (0);
+ }
+
+ while (offset > aop->coff)
+ {
+ aop->coff++;
+ emitcode ("inc", "dptr");
+ }
+
+ while (offset < aop->coff)
+ {
+ aop->coff--;
+ emitcode ("lcall", "__decdptr");
+ }
+
+ aop->coff = offset;
+
+ /* if not in accumulater */
+ MOVA (s);
+
+ emitcode ("movx", "@dptr,a");
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (0);
+ }
+ break;
case AOP_R0:
case AOP_R1:
- while (offset > aop->coff) {
- aop->coff++;
- emitcode("inc","%s",aop->aopu.aop_ptr->name);
- }
- while (offset < aop->coff) {
- aop->coff-- ;
- emitcode ("dec","%s",aop->aopu.aop_ptr->name);
- }
- aop->coff = offset;
-
- if (aop->paged) {
- MOVA(s);
- emitcode("movx","@%s,a",aop->aopu.aop_ptr->name);
-
- } else
- if (*s == '@') {
- MOVA(s);
- emitcode("mov","@%s,a",aop->aopu.aop_ptr->name);
- } else
- if (strcmp(s,"r0") == 0 ||
- strcmp(s,"r1") == 0 ||
- strcmp(s,"r2") == 0 ||
- strcmp(s,"r3") == 0 ||
- strcmp(s,"r4") == 0 ||
- strcmp(s,"r5") == 0 ||
- strcmp(s,"r6") == 0 ||
- strcmp(s,"r7") == 0 ) {
- char buffer[10];
- sprintf(buffer,"a%s",s);
- emitcode("mov","@%s,%s",
- aop->aopu.aop_ptr->name,buffer);
- } else
- emitcode("mov","@%s,%s",aop->aopu.aop_ptr->name,s);
-
- break;
+ while (offset > aop->coff)
+ {
+ aop->coff++;
+ emitcode ("inc", "%s", aop->aopu.aop_ptr->name);
+ }
+ while (offset < aop->coff)
+ {
+ aop->coff--;
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ }
+ aop->coff = offset;
+
+ if (aop->paged)
+ {
+ MOVA (s);
+ emitcode ("movx", "@%s,a", aop->aopu.aop_ptr->name);
+
+ }
+ else if (*s == '@')
+ {
+ MOVA (s);
+ emitcode ("mov", "@%s,a", aop->aopu.aop_ptr->name);
+ }
+ else if (strcmp (s, "r0") == 0 ||
+ strcmp (s, "r1") == 0 ||
+ strcmp (s, "r2") == 0 ||
+ strcmp (s, "r3") == 0 ||
+ strcmp (s, "r4") == 0 ||
+ strcmp (s, "r5") == 0 ||
+ strcmp (s, "r6") == 0 ||
+ strcmp (s, "r7") == 0)
+ {
+ char buffer[10];
+ sprintf (buffer, "a%s", s);
+ emitcode ("mov", "@%s,%s",
+ aop->aopu.aop_ptr->name, buffer);
+ }
+ else
+ emitcode ("mov", "@%s,%s", aop->aopu.aop_ptr->name, s);
+
+ break;
case AOP_STK:
- if (strcmp(s,"a") == 0)
- emitcode("push","acc");
- else
- emitcode("push","%s",s);
+ if (strcmp (s, "a") == 0)
+ emitcode ("push", "acc");
+ else
+ emitcode ("push", "%s", s);
- break;
+ break;
case AOP_CRY:
- /* if bit variable */
- if (!aop->aopu.aop_dir) {
- emitcode("clr","a");
- emitcode("rlc","a");
- } else {
- if (s == zero)
- emitcode("clr","%s",aop->aopu.aop_dir);
+ /* if bit variable */
+ if (!aop->aopu.aop_dir)
+ {
+ emitcode ("clr", "a");
+ emitcode ("rlc", "a");
+ }
else
- if (s == one)
- emitcode("setb","%s",aop->aopu.aop_dir);
- else
- if (!strcmp(s,"c"))
- emitcode("mov","%s,c",aop->aopu.aop_dir);
- else {
- lbl = newiTempLabel(NULL);
-
- if (strcmp(s,"a")) {
- MOVA(s);
- }
- emitcode("clr","c");
- emitcode("jz","%05d$",lbl->key+100);
- emitcode("cpl","c");
- emitcode("","%05d$:",lbl->key+100);
- emitcode("mov","%s,c",aop->aopu.aop_dir);
- }
- }
- break;
+ {
+ if (s == zero)
+ emitcode ("clr", "%s", aop->aopu.aop_dir);
+ else if (s == one)
+ emitcode ("setb", "%s", aop->aopu.aop_dir);
+ else if (!strcmp (s, "c"))
+ emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+ else
+ {
+ lbl = newiTempLabel (NULL);
+
+ if (strcmp (s, "a"))
+ {
+ MOVA (s);
+ }
+ emitcode ("clr", "c");
+ emitcode ("jz", "%05d$", lbl->key + 100);
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", lbl->key + 100);
+ emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+ }
+ }
+ break;
case AOP_STR:
- aop->coff = offset;
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("mov","%s,%s",aop->aopu.aop_str[offset],s);
- break;
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("mov", "%s,%s", aop->aopu.aop_str[offset], s);
+ break;
case AOP_ACC:
- aop->coff = offset;
- if (!offset && (strcmp(s,"acc") == 0))
- break;
+ aop->coff = offset;
+ if (!offset && (strcmp (s, "acc") == 0))
+ break;
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("mov","%s,%s",aop->aopu.aop_str[offset],s);
- break;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("mov", "%s,%s", aop->aopu.aop_str[offset], s);
+ break;
- default :
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got unsupported aop->type");
- exit(0);
+ default:
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got unsupported aop->type");
+ exit (0);
}
}
/*-----------------------------------------------------------------*/
/* pointToEnd :- points to the last byte of the operand */
/*-----------------------------------------------------------------*/
-static void pointToEnd (asmop *aop)
+static void
+pointToEnd (asmop * aop)
{
- int count ;
- if (!aop)
- return ;
+ int count;
+ if (!aop)
+ return;
- aop->coff = count = (aop->size - 1);
- switch (aop->type) {
- case AOP_R0 :
- case AOP_R1 :
- while (count--)
- emitcode("inc","%s",aop->aopu.aop_ptr->name);
- break;
- case AOP_DPTR :
- while (count--)
- emitcode("inc","dptr");
- break;
+ aop->coff = count = (aop->size - 1);
+ switch (aop->type)
+ {
+ case AOP_R0:
+ case AOP_R1:
+ while (count--)
+ emitcode ("inc", "%s", aop->aopu.aop_ptr->name);
+ break;
+ case AOP_DPTR:
+ while (count--)
+ emitcode ("inc", "dptr");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* reAdjustPreg - points a register back to where it should */
/*-----------------------------------------------------------------*/
-static void reAdjustPreg (asmop *aop)
+static void
+reAdjustPreg (asmop * aop)
{
- int size ;
+ int size;
- aop->coff = 0;
- if ((size = aop->size) <= 1)
- return ;
- size-- ;
- switch (aop->type) {
- case AOP_R0 :
- case AOP_R1 :
- while (size--)
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- break;
- case AOP_DPTR :
- case AOP_DPTR2:
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- }
- while (size--)
- {
- emitcode("lcall","__decdptr");
- }
-
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
- break;
+ aop->coff = 0;
+ if ((size = aop->size) <= 1)
+ return;
+ size--;
+ switch (aop->type)
+ {
+ case AOP_R0:
+ case AOP_R1:
+ while (size--)
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ break;
+ case AOP_DPTR:
+ case AOP_DPTR2:
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (1);
+ }
+ while (size--)
+ {
+ emitcode ("lcall", "__decdptr");
+ }
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (0);
+ }
+ break;
}
/*-----------------------------------------------------------------*/
/* genNotFloat - generates not for float operations */
/*-----------------------------------------------------------------*/
-static void genNotFloat (operand *op, operand *res)
+static void
+genNotFloat (operand * op, operand * res)
{
- int size, offset;
- char *l;
- symbol *tlbl ;
+ int size, offset;
+ char *l;
+ symbol *tlbl;
- /* we will put 127 in the first byte of
- the result */
- aopPut(AOP(res),"#127",0);
- size = AOP_SIZE(op) - 1;
- offset = 1;
+ /* we will put 127 in the first byte of
+ the result */
+ aopPut (AOP (res), "#127", 0);
+ size = AOP_SIZE (op) - 1;
+ offset = 1;
- l = aopGet(op->aop,offset++,FALSE,FALSE);
- MOVA(l);
+ l = aopGet (op->aop, offset++, FALSE, FALSE);
+ MOVA (l);
- while(size--) {
- emitcode("orl","a,%s",
- aopGet(op->aop,
- offset++,FALSE,FALSE));
+ while (size--)
+ {
+ emitcode ("orl", "a,%s",
+ aopGet (op->aop,
+ offset++, FALSE, FALSE));
}
- tlbl = newiTempLabel(NULL);
+ tlbl = newiTempLabel (NULL);
- tlbl = newiTempLabel(NULL);
- aopPut(res->aop,one,1);
- emitcode("jz","%05d$",(tlbl->key+100));
- aopPut(res->aop,zero,1);
- emitcode("","%05d$:",(tlbl->key+100));
+ tlbl = newiTempLabel (NULL);
+ aopPut (res->aop, one, 1);
+ emitcode ("jz", "%05d$", (tlbl->key + 100));
+ aopPut (res->aop, zero, 1);
+ emitcode ("", "%05d$:", (tlbl->key + 100));
- size = res->aop->size - 2;
- offset = 2;
- /* put zeros in the rest */
- while (size--)
- aopPut(res->aop,zero,offset++);
+ size = res->aop->size - 2;
+ offset = 2;
+ /* put zeros in the rest */
+ while (size--)
+ aopPut (res->aop, zero, offset++);
}
/*-----------------------------------------------------------------*/
/* opIsGptr: returns non-zero if the passed operand is */
/* a generic pointer type. */
/*-----------------------------------------------------------------*/
-static int opIsGptr(operand *op)
+static int
+opIsGptr (operand * op)
{
- sym_link *type = operandType(op);
+ sym_link *type = operandType (op);
- if ((AOP_SIZE(op) == GPTRSIZE) && IS_GENPTR(type))
+ if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
{
- return 1;
+ return 1;
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* getDataSize - get the operand data size */
/*-----------------------------------------------------------------*/
-static int getDataSize(operand *op)
+static int
+getDataSize (operand * op)
{
- int size;
- size = AOP_SIZE(op);
- if (size == GPTRSIZE)
+ int size;
+ size = AOP_SIZE (op);
+ if (size == GPTRSIZE)
{
- sym_link *type = operandType(op);
- if (IS_GENPTR(type))
- {
- /* generic pointer; arithmetic operations
- * should ignore the high byte (pointer type).
- */
- size--;
- }
+ sym_link *type = operandType (op);
+ if (IS_GENPTR (type))
+ {
+ /* generic pointer; arithmetic operations
+ * should ignore the high byte (pointer type).
+ */
+ size--;
+ }
}
- return size;
+ return size;
}
/*-----------------------------------------------------------------*/
/* outAcc - output Acc */
/*-----------------------------------------------------------------*/
-static void outAcc(operand *result)
+static void
+outAcc (operand * result)
{
- int size, offset;
- size = getDataSize(result);
- if(size){
- aopPut(AOP(result),"a",0);
- size--;
- offset = 1;
- /* unsigned or positive */
- while(size--){
- aopPut(AOP(result),zero,offset++);
- }
+ int size, offset;
+ size = getDataSize (result);
+ if (size)
+ {
+ aopPut (AOP (result), "a", 0);
+ size--;
+ offset = 1;
+ /* unsigned or positive */
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
}
}
/*-----------------------------------------------------------------*/
/* outBitC - output a bit C */
/*-----------------------------------------------------------------*/
-static void outBitC(operand *result)
+static void
+outBitC (operand * result)
{
- /* if the result is bit */
- if (AOP_TYPE(result) == AOP_CRY)
- aopPut(AOP(result),"c",0);
- else {
- emitcode("clr","a");
- emitcode("rlc","a");
- outAcc(result);
+ /* if the result is bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ aopPut (AOP (result), "c", 0);
+ else
+ {
+ emitcode ("clr", "a");
+ emitcode ("rlc", "a");
+ outAcc (result);
}
}
/*-----------------------------------------------------------------*/
/* toBoolean - emit code for orl a,operator(sizeop) */
/*-----------------------------------------------------------------*/
-static void toBoolean(operand *oper)
+static void
+toBoolean (operand * oper)
{
- int size = AOP_SIZE(oper) - 1;
- int offset = 1;
- MOVA(aopGet(AOP(oper),0,FALSE,FALSE));
- while (size--)
- emitcode("orl","a,%s",aopGet(AOP(oper),offset++,FALSE,FALSE));
+ int size = AOP_SIZE (oper) - 1;
+ int offset = 1;
+ MOVA (aopGet (AOP (oper), 0, FALSE, FALSE));
+ while (size--)
+ emitcode ("orl", "a,%s", aopGet (AOP (oper), offset++, FALSE, FALSE));
}
/*-----------------------------------------------------------------*/
/* genNot - generate code for ! operation */
/*-----------------------------------------------------------------*/
-static void genNot (iCode *ic)
+static void
+genNot (iCode * ic)
{
- symbol *tlbl;
- sym_link *optype = operandType(IC_LEFT(ic));
+ symbol *tlbl;
+ sym_link *optype = operandType (IC_LEFT (ic));
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* if in bit space then a special case */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- outBitC(IC_RESULT(ic));
- goto release;
+ /* if in bit space then a special case */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ outBitC (IC_RESULT (ic));
+ goto release;
}
- /* if type float then do float */
- if (IS_FLOAT(optype)) {
- genNotFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
+ /* if type float then do float */
+ if (IS_FLOAT (optype))
+ {
+ genNotFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
}
- toBoolean(IC_LEFT(ic));
+ toBoolean (IC_LEFT (ic));
- tlbl = newiTempLabel(NULL);
- emitcode("cjne","a,#0x01,%05d$",tlbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(IC_RESULT(ic));
+ tlbl = newiTempLabel (NULL);
+ emitcode ("cjne", "a,#0x01,%05d$", tlbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (IC_RESULT (ic));
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCpl - generate code for complement */
/*-----------------------------------------------------------------*/
-static void genCpl (iCode *ic)
+static void
+genCpl (iCode * ic)
{
- int offset = 0;
- int size ;
+ int offset = 0;
+ int size;
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* if both are in bit space then
- a special case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
+ /* if both are in bit space then
+ a special case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
- goto release;
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+ goto release;
}
- size = AOP_SIZE(IC_RESULT(ic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("cpl","a");
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ size = AOP_SIZE (IC_RESULT (ic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("cpl", "a");
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genUminusFloat - unary minus for floating points */
/*-----------------------------------------------------------------*/
-static void genUminusFloat(operand *op,operand *result)
+static void
+genUminusFloat (operand * op, operand * result)
{
- int size ,offset =0 ;
- char *l;
- /* for this we just need to flip the
- first it then copy the rest in place */
- size = AOP_SIZE(op) - 1;
- l = aopGet(AOP(op),3,FALSE,FALSE);
+ int size, offset = 0;
+ char *l;
+ /* for this we just need to flip the
+ first it then copy the rest in place */
+ size = AOP_SIZE (op) - 1;
+ l = aopGet (AOP (op), 3, FALSE, FALSE);
- MOVA(l);
+ MOVA (l);
- emitcode("cpl","acc.7");
- aopPut(AOP(result),"a",3);
+ emitcode ("cpl", "acc.7");
+ aopPut (AOP (result), "a", 3);
- while(size--) {
- aopPut(AOP(result),
- aopGet(AOP(op),offset,FALSE,FALSE),
- offset);
- offset++;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (op), offset, FALSE, FALSE),
+ offset);
+ offset++;
}
}
/*-----------------------------------------------------------------*/
/* genUminus - unary minus code generation */
/*-----------------------------------------------------------------*/
-static void genUminus (iCode *ic)
+static void
+genUminus (iCode * ic)
{
- int offset ,size ;
- sym_link *optype, *rtype;
+ int offset, size;
+ sym_link *optype, *rtype;
- /* assign asmops */
- aopOp(IC_LEFT(ic),ic,FALSE);
- aopOp(IC_RESULT(ic),ic,TRUE);
+ /* assign asmops */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* if both in bit space then special
- case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
+ /* if both in bit space then special
+ case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
- goto release;
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+ goto release;
}
- optype = operandType(IC_LEFT(ic));
- rtype = operandType(IC_RESULT(ic));
+ optype = operandType (IC_LEFT (ic));
+ rtype = operandType (IC_RESULT (ic));
- /* if float then do float stuff */
- if (IS_FLOAT(optype)) {
- genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
- }
-
- /* otherwise subtract from zero */
- size = AOP_SIZE(IC_LEFT(ic));
- offset = 0 ;
- //CLRC ;
- while(size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE);
- if (!strcmp(l,"a")) {
- if (offset==0)
- SETC;
- emitcode("cpl","a");
- emitcode("addc","a,#0");
- } else {
- if (offset==0)
- CLRC;
- emitcode("clr","a");
- emitcode("subb","a,%s",l);
- }
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* if float then do float stuff */
+ if (IS_FLOAT (optype))
+ {
+ genUminusFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
}
- /* if any remaining bytes in the result */
- /* we just need to propagate the sign */
- if ((size = (AOP_SIZE(IC_RESULT(ic)) - AOP_SIZE(IC_LEFT(ic))))) {
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- while (size--)
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* otherwise subtract from zero */
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = 0;
+ //CLRC ;
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE);
+ if (!strcmp (l, "a"))
+ {
+ if (offset == 0)
+ SETC;
+ emitcode ("cpl", "a");
+ emitcode ("addc", "a,#0");
+ }
+ else
+ {
+ if (offset == 0)
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,%s", l);
+ }
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
+ }
+
+ /* if any remaining bytes in the result */
+ /* we just need to propagate the sign */
+ if ((size = (AOP_SIZE (IC_RESULT (ic)) - AOP_SIZE (IC_LEFT (ic)))))
+ {
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ while (size--)
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* saveRegisters - will look for a call and save the registers */
/*-----------------------------------------------------------------*/
-static void saveRegisters(iCode *lic)
-{
- int i;
- iCode *ic;
- bitVect *rsave;
- sym_link *detype;
-
- /* look for call */
- for (ic = lic ; ic ; ic = ic->next)
- if (ic->op == CALL || ic->op == PCALL)
- break;
-
- if (!ic) {
- fprintf(stderr,"found parameter push with no function call\n");
- return ;
- }
-
- /* if the registers have been saved already then
- do nothing */
- if (ic->regsSaved || (OP_SYMBOL(IC_LEFT(ic))->calleeSave))
- return ;
-
- /* find the registers in use at this time
- and push them away to safety */
- rsave = bitVectCplAnd(bitVectCopy(ic->rMask),
- ic->rUsed);
-
- ic->regsSaved = 1;
- if (options.useXstack) {
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","b,r0");
- emitcode("mov","r0,%s",spname);
- for (i = 0 ; i < mcs51_nRegs ; i++) {
- if (bitVectBitValue(rsave,i)) {
- if (i == R0_IDX)
- emitcode("mov","a,b");
- else
- emitcode("mov","a,%s",mcs51_regWithIdx(i)->name);
- emitcode("movx","@r0,a");
- emitcode("inc","r0");
+static void
+saveRegisters (iCode * lic)
+{
+ int i;
+ iCode *ic;
+ bitVect *rsave;
+ sym_link *detype;
+
+ /* look for call */
+ for (ic = lic; ic; ic = ic->next)
+ if (ic->op == CALL || ic->op == PCALL)
+ break;
+
+ if (!ic)
+ {
+ fprintf (stderr, "found parameter push with no function call\n");
+ return;
+ }
+
+ /* if the registers have been saved already then
+ do nothing */
+ if (ic->regsSaved || (OP_SYMBOL (IC_LEFT (ic))->calleeSave))
+ return;
+
+ /* find the registers in use at this time
+ and push them away to safety */
+ rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ic->rUsed);
+
+ ic->regsSaved = 1;
+ if (options.useXstack)
+ {
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "b,r0");
+ emitcode ("mov", "r0,%s", spname);
+ for (i = 0; i < mcs51_nRegs; i++)
+ {
+ if (bitVectBitValue (rsave, i))
+ {
+ if (i == R0_IDX)
+ emitcode ("mov", "a,b");
+ else
+ emitcode ("mov", "a,%s", mcs51_regWithIdx (i)->name);
+ emitcode ("movx", "@r0,a");
+ emitcode ("inc", "r0");
+ }
+ }
+ emitcode ("mov", "%s,r0", spname);
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "r0,b");
+ }
+ else
+ for (i = 0; i < mcs51_nRegs; i++)
+ {
+ if (bitVectBitValue (rsave, i))
+ emitcode ("push", "%s", mcs51_regWithIdx (i)->dname);
}
- }
- emitcode("mov","%s,r0",spname);
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","r0,b");
- } else
- for (i = 0 ; i < mcs51_nRegs ; i++) {
- if (bitVectBitValue(rsave,i))
- emitcode("push","%s",mcs51_regWithIdx(i)->dname);
- }
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) &&
- IS_ISR(currFunc->etype) &&
- !ic->bankSaved)
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) &&
+ IS_ISR (currFunc->etype) &&
+ !ic->bankSaved)
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ saverbank (SPEC_BANK (detype), ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* unsaveRegisters - pop the pushed registers */
/*-----------------------------------------------------------------*/
-static void unsaveRegisters (iCode *ic)
-{
- int i;
- bitVect *rsave;
- /* find the registers in use at this time
- and push them away to safety */
- rsave = bitVectCplAnd(bitVectCopy(ic->rMask),
- ic->rUsed);
-
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- for (i = mcs51_nRegs ; i >= 0 ; i--) {
- if (bitVectBitValue(rsave,i)) {
- emitcode("dec","r0");
- emitcode("movx","a,@r0");
- if (i == R0_IDX)
- emitcode("mov","b,a");
- else
- emitcode("mov","%s,a",mcs51_regWithIdx(i)->name);
- }
+static void
+unsaveRegisters (iCode * ic)
+{
+ int i;
+ bitVect *rsave;
+ /* find the registers in use at this time
+ and push them away to safety */
+ rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ic->rUsed);
- }
- emitcode("mov","%s,r0",spname);
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","r0,b");
- } else
- for (i = mcs51_nRegs ; i >= 0 ; i--) {
- if (bitVectBitValue(rsave,i))
- emitcode("pop","%s",mcs51_regWithIdx(i)->dname);
- }
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ for (i = mcs51_nRegs; i >= 0; i--)
+ {
+ if (bitVectBitValue (rsave, i))
+ {
+ emitcode ("dec", "r0");
+ emitcode ("movx", "a,@r0");
+ if (i == R0_IDX)
+ emitcode ("mov", "b,a");
+ else
+ emitcode ("mov", "%s,a", mcs51_regWithIdx (i)->name);
+ }
+
+ }
+ emitcode ("mov", "%s,r0", spname);
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "r0,b");
+ }
+ else
+ for (i = mcs51_nRegs; i >= 0; i--)
+ {
+ if (bitVectBitValue (rsave, i))
+ emitcode ("pop", "%s", mcs51_regWithIdx (i)->dname);
+ }
}
/*-----------------------------------------------------------------*/
/* pushSide - */
/*-----------------------------------------------------------------*/
-static void pushSide(operand * oper, int size)
+static void
+pushSide (operand * oper, int size)
{
int offset = 0;
- while (size--) {
- char *l = aopGet(AOP(oper),offset++,FALSE,TRUE);
- if (AOP_TYPE(oper) != AOP_REG &&
- AOP_TYPE(oper) != AOP_DIR &&
- strcmp(l,"a") ) {
- emitcode("mov","a,%s",l);
- emitcode("push","acc");
- } else
- emitcode("push","%s",l);
- }
+ while (size--)
+ {
+ char *l = aopGet (AOP (oper), offset++, FALSE, TRUE);
+ if (AOP_TYPE (oper) != AOP_REG &&
+ AOP_TYPE (oper) != AOP_DIR &&
+ strcmp (l, "a"))
+ {
+ emitcode ("mov", "a,%s", l);
+ emitcode ("push", "acc");
+ }
+ else
+ emitcode ("push", "%s", l);
+ }
}
/*-----------------------------------------------------------------*/
/* assignResultValue - */
/*-----------------------------------------------------------------*/
-static void assignResultValue(operand * oper)
+static void
+assignResultValue (operand * oper)
{
int offset = 0;
- int size = AOP_SIZE(oper);
- while (size--) {
- aopPut(AOP(oper),fReturn[offset],offset);
- offset++;
- }
+ int size = AOP_SIZE (oper);
+ while (size--)
+ {
+ aopPut (AOP (oper), fReturn[offset], offset);
+ offset++;
+ }
}
/*-----------------------------------------------------------------*/
/* genXpush - pushes onto the external stack */
/*-----------------------------------------------------------------*/
-static void genXpush (iCode *ic)
+static void
+genXpush (iCode * ic)
{
- asmop *aop = newAsmop(0);
- regs *r ;
- int size,offset = 0;
+ asmop *aop = newAsmop (0);
+ regs *r;
+ int size, offset = 0;
- aopOp(IC_LEFT(ic),ic,FALSE);
- r = getFreePtr(ic,&aop,FALSE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ r = getFreePtr (ic, &aop, FALSE);
- emitcode("mov","%s,_spx",r->name);
+ emitcode ("mov", "%s,_spx", r->name);
- size = AOP_SIZE(IC_LEFT(ic));
- while(size--) {
+ size = AOP_SIZE (IC_LEFT (ic));
+ while (size--)
+ {
- char *l = aopGet(AOP(IC_LEFT(ic)),
- offset++,FALSE,FALSE);
- MOVA(l);
- emitcode("movx","@%s,a",r->name);
- emitcode("inc","%s",r->name);
+ char *l = aopGet (AOP (IC_LEFT (ic)),
+ offset++, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("movx", "@%s,a", r->name);
+ emitcode ("inc", "%s", r->name);
}
- emitcode("mov","_spx,%s",r->name);
+ emitcode ("mov", "_spx,%s", r->name);
- freeAsmop(NULL,aop,ic,TRUE);
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (NULL, aop, ic, TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIpush - genrate code for pushing this gets a little complex */
/*-----------------------------------------------------------------*/
-static void genIpush (iCode *ic)
+static void
+genIpush (iCode * ic)
{
- int size, offset = 0 ;
- char *l;
+ int size, offset = 0;
+ char *l;
- /* if this is not a parm push : ie. it is spill push
- and spill push is always done on the local stack */
- if (!ic->parmPush) {
-
- /* and the item is spilt then do nothing */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
-
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- /* push it on the stack */
- while(size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE);
- if (*l == '#') {
- MOVA(l);
- l = "acc";
- }
- emitcode("push","%s",l);
- }
- return ;
- }
+ /* if this is not a parm push : ie. it is spill push
+ and spill push is always done on the local stack */
+ if (!ic->parmPush)
+ {
- /* this is a paramter push: in this case we call
- the routine to find the call and save those
- registers that need to be saved */
- saveRegisters(ic);
+ /* and the item is spilt then do nothing */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- /* if use external stack then call the external
- stack pushing routine */
- if (options.useXstack) {
- genXpush(ic);
- return ;
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ /* push it on the stack */
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE);
+ if (*l == '#')
+ {
+ MOVA (l);
+ l = "acc";
+ }
+ emitcode ("push", "%s", l);
+ }
+ return;
+ }
+
+ /* this is a paramter push: in this case we call
+ the routine to find the call and save those
+ registers that need to be saved */
+ saveRegisters (ic);
+
+ /* if use external stack then call the external
+ stack pushing routine */
+ if (options.useXstack)
+ {
+ genXpush (ic);
+ return;
}
- /* then do the push */
- aopOp(IC_LEFT(ic),ic,FALSE);
+ /* then do the push */
+ aopOp (IC_LEFT (ic), ic, FALSE);
// pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
- size = AOP_SIZE(IC_LEFT(ic));
+ size = AOP_SIZE (IC_LEFT (ic));
- while (size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE);
- if (AOP_TYPE(IC_LEFT(ic)) != AOP_REG &&
- AOP_TYPE(IC_LEFT(ic)) != AOP_DIR &&
- strcmp(l,"a") ) {
- emitcode("mov","a,%s",l);
- emitcode("push","acc");
- } else
- emitcode("push","%s",l);
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE);
+ if (AOP_TYPE (IC_LEFT (ic)) != AOP_REG &&
+ AOP_TYPE (IC_LEFT (ic)) != AOP_DIR &&
+ strcmp (l, "a"))
+ {
+ emitcode ("mov", "a,%s", l);
+ emitcode ("push", "acc");
+ }
+ else
+ emitcode ("push", "%s", l);
}
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIpop - recover the registers: can happen only for spilling */
/*-----------------------------------------------------------------*/
-static void genIpop (iCode *ic)
+static void
+genIpop (iCode * ic)
{
- int size,offset ;
+ int size, offset;
- /* if the temp was not pushed then */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
+ /* if the temp was not pushed then */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- offset = (size-1);
- while (size--)
- emitcode("pop","%s",aopGet(AOP(IC_LEFT(ic)),offset--,
- FALSE,TRUE));
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = (size - 1);
+ while (size--)
+ emitcode ("pop", "%s", aopGet (AOP (IC_LEFT (ic)), offset--,
+ FALSE, TRUE));
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* unsaverbank - restores the resgister bank from stack */
/*-----------------------------------------------------------------*/
-static void unsaverbank (int bank,iCode *ic,bool popPsw)
+static void
+unsaverbank (int bank, iCode * ic, bool popPsw)
{
- int i;
- asmop *aop ;
- regs *r = NULL;
+ int i;
+ asmop *aop;
+ regs *r = NULL;
- if (popPsw) {
- if (options.useXstack) {
- aop = newAsmop(0);
- r = getFreePtr(ic,&aop,FALSE);
+ if (popPsw)
+ {
+ if (options.useXstack)
+ {
+ aop = newAsmop (0);
+ r = getFreePtr (ic, &aop, FALSE);
- emitcode("mov","%s,_spx",r->name);
- emitcode("movx","a,@%s",r->name);
- emitcode("mov","psw,a");
- emitcode("dec","%s",r->name);
+ emitcode ("mov", "%s,_spx", r->name);
+ emitcode ("movx", "a,@%s", r->name);
+ emitcode ("mov", "psw,a");
+ emitcode ("dec", "%s", r->name);
- }else
- emitcode ("pop","psw");
+ }
+ else
+ emitcode ("pop", "psw");
}
- for (i = (mcs51_nRegs - 1) ; i >= 0 ;i--) {
- if (options.useXstack) {
- emitcode("movx","a,@%s",r->name);
- emitcode("mov","(%s+%d),a",
- regs8051[i].base,8*bank+regs8051[i].offset);
- emitcode("dec","%s",r->name);
-
- } else
- emitcode("pop","(%s+%d)",
- regs8051[i].base,8*bank+regs8051[i].offset);
+ for (i = (mcs51_nRegs - 1); i >= 0; i--)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("movx", "a,@%s", r->name);
+ emitcode ("mov", "(%s+%d),a",
+ regs8051[i].base, 8 * bank + regs8051[i].offset);
+ emitcode ("dec", "%s", r->name);
+
+ }
+ else
+ emitcode ("pop", "(%s+%d)",
+ regs8051[i].base, 8 * bank + regs8051[i].offset);
}
- if (options.useXstack) {
+ if (options.useXstack)
+ {
- emitcode("mov","_spx,%s",r->name);
- freeAsmop(NULL,aop,ic,TRUE);
+ emitcode ("mov", "_spx,%s", r->name);
+ freeAsmop (NULL, aop, ic, TRUE);
}
}
/*-----------------------------------------------------------------*/
/* saverbank - saves an entire register bank on the stack */
/*-----------------------------------------------------------------*/
-static void saverbank (int bank, iCode *ic, bool pushPsw)
+static void
+saverbank (int bank, iCode * ic, bool pushPsw)
{
- int i;
- asmop *aop ;
- regs *r = NULL;
+ int i;
+ asmop *aop;
+ regs *r = NULL;
- if (options.useXstack) {
+ if (options.useXstack)
+ {
- aop = newAsmop(0);
- r = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,_spx",r->name);
+ aop = newAsmop (0);
+ r = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,_spx", r->name);
}
- for (i = 0 ; i < mcs51_nRegs ;i++) {
- if (options.useXstack) {
- emitcode("inc","%s",r->name);
- emitcode("mov","a,(%s+%d)",
- regs8051[i].base,8*bank+regs8051[i].offset);
- emitcode("movx","@%s,a",r->name);
- } else
- emitcode("push","(%s+%d)",
- regs8051[i].base,8*bank+regs8051[i].offset);
+ for (i = 0; i < mcs51_nRegs; i++)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("inc", "%s", r->name);
+ emitcode ("mov", "a,(%s+%d)",
+ regs8051[i].base, 8 * bank + regs8051[i].offset);
+ emitcode ("movx", "@%s,a", r->name);
+ }
+ else
+ emitcode ("push", "(%s+%d)",
+ regs8051[i].base, 8 * bank + regs8051[i].offset);
}
- if (pushPsw) {
- if (options.useXstack) {
- emitcode("mov","a,psw");
- emitcode("movx","@%s,a",r->name);
- emitcode("inc","%s",r->name);
- emitcode("mov","_spx,%s",r->name);
- freeAsmop (NULL,aop,ic,TRUE);
-
- } else
- emitcode("push","psw");
+ if (pushPsw)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("mov", "a,psw");
+ emitcode ("movx", "@%s,a", r->name);
+ emitcode ("inc", "%s", r->name);
+ emitcode ("mov", "_spx,%s", r->name);
+ freeAsmop (NULL, aop, ic, TRUE);
+
+ }
+ else
+ emitcode ("push", "psw");
- emitcode("mov","psw,#0x%02x",(bank << 3)&0x00ff);
+ emitcode ("mov", "psw,#0x%02x", (bank << 3) & 0x00ff);
}
- ic->bankSaved = 1;
+ ic->bankSaved = 1;
}
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
-static void genCall (iCode *ic)
-{
- sym_link *detype;
-
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
- saveRegisters(ic);
-
- /* if we are calling a function that is not using
- the same register bank then we need to save the
- destination registers on the stack */
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) &&
- IS_ISR(currFunc->etype) &&
- !ic->bankSaved)
-
- saverbank(SPEC_BANK(detype),ic,TRUE);
-
- /* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
-
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
- aopOp(IC_LEFT(sic),sic,FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset,
- FALSE,FALSE);
- if (strcmp(l,fReturn[offset]))
- emitcode("mov","%s,%s",
- fReturn[offset],
- l);
- offset++;
- }
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
- }
- _G.sendSet = NULL;
- }
- /* make the call */
- emitcode("lcall","%s",(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
- OP_SYMBOL(IC_LEFT(ic))->rname :
- OP_SYMBOL(IC_LEFT(ic))->name));
+static void
+genCall (iCode * ic)
+{
+ sym_link *detype;
+
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ saveRegisters (ic);
+
+ /* if we are calling a function that is not using
+ the same register bank then we need to save the
+ destination registers on the stack */
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) &&
+ IS_ISR (currFunc->etype) &&
+ !ic->bankSaved)
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+ saverbank (SPEC_BANK (detype), ic, TRUE);
- _G.accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE);
- _G.accInUse--;
+ /* if send set is not empty the assign */
+ if (_G.sendSet)
+ {
+ iCode *sic;
+
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+ aopOp (IC_LEFT (sic), sic, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset,
+ FALSE, FALSE);
+ if (strcmp (l, fReturn[offset]))
+ emitcode ("mov", "%s,%s",
+ fReturn[offset],
+ l);
+ offset++;
+ }
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
+ _G.sendSet = NULL;
+ }
+ /* make the call */
+ emitcode ("lcall", "%s", (OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
+ OP_SYMBOL (IC_LEFT (ic))->rname :
+ OP_SYMBOL (IC_LEFT (ic))->name));
+
+ /* if we need assign a result value */
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
- assignResultValue(IC_RESULT(ic));
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ _G.accInUse--;
- freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
+ assignResultValue (IC_RESULT (ic));
+
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
- /* adjust the stack for parameters if
- required */
- if (IC_LEFT(ic)->parmBytes) {
- int i;
- if (IC_LEFT(ic)->parmBytes > 3) {
- emitcode("mov","a,%s",spname);
- emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff);
- emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++)
- emitcode("dec","%s",spname);
+ /* adjust the stack for parameters if
+ required */
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i;
+ if (IC_LEFT (ic)->parmBytes > 3)
+ {
+ emitcode ("mov", "a,%s", spname);
+ emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff);
+ emitcode ("mov", "%s,a", spname);
+ }
+ else
+ for (i = 0; i < IC_LEFT (ic)->parmBytes; i++)
+ emitcode ("dec", "%s", spname);
}
- /* if register bank was saved then pop them */
- if (ic->bankSaved)
- unsaverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if register bank was saved then pop them */
+ if (ic->bankSaved)
+ unsaverbank (SPEC_BANK (detype), ic, TRUE);
- /* if we hade saved some registers then unsave them */
- if (ic->regsSaved && !(OP_SYMBOL(IC_LEFT(ic))->calleeSave))
- unsaveRegisters (ic);
+ /* if we hade saved some registers then unsave them */
+ if (ic->regsSaved && !(OP_SYMBOL (IC_LEFT (ic))->calleeSave))
+ unsaveRegisters (ic);
}
/*-----------------------------------------------------------------*/
/* genPcall - generates a call by pointer statement */
/*-----------------------------------------------------------------*/
-static void genPcall (iCode *ic)
+static void
+genPcall (iCode * ic)
{
- sym_link *detype;
- symbol *rlbl = newiTempLabel(NULL);
+ sym_link *detype;
+ symbol *rlbl = newiTempLabel (NULL);
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
- saveRegisters(ic);
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ saveRegisters (ic);
- /* if we are calling a function that is not using
- the same register bank then we need to save the
- destination registers on the stack */
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- IS_ISR(currFunc->etype) &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)))
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if we are calling a function that is not using
+ the same register bank then we need to save the
+ destination registers on the stack */
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ IS_ISR (currFunc->etype) &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)))
+ saverbank (SPEC_BANK (detype), ic, TRUE);
- /* push the return address on to the stack */
- emitcode("mov","a,#%05d$",(rlbl->key+100));
- emitcode("push","acc");
- emitcode("mov","a,#(%05d$ >> 8)",(rlbl->key+100));
- emitcode("push","acc");
+ /* push the return address on to the stack */
+ emitcode ("mov", "a,#%05d$", (rlbl->key + 100));
+ emitcode ("push", "acc");
+ emitcode ("mov", "a,#(%05d$ >> 8)", (rlbl->key + 100));
+ emitcode ("push", "acc");
- if (options.model == MODEL_FLAT24)
+ if (options.model == MODEL_FLAT24)
{
- emitcode("mov","a,#(%05d$ >> 16)",(rlbl->key+100));
- emitcode("push","acc");
+ emitcode ("mov", "a,#(%05d$ >> 16)", (rlbl->key + 100));
+ emitcode ("push", "acc");
}
- /* now push the calling address */
- aopOp(IC_LEFT(ic),ic,FALSE);
+ /* now push the calling address */
+ aopOp (IC_LEFT (ic), ic, FALSE);
- pushSide(IC_LEFT(ic), FPTRSIZE);
+ pushSide (IC_LEFT (ic), FPTRSIZE);
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
- /* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
+ /* if send set is not empty the assign */
+ if (_G.sendSet)
+ {
+ iCode *sic;
+
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+ aopOp (IC_LEFT (sic), sic, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset,
+ FALSE, FALSE);
+ if (strcmp (l, fReturn[offset]))
+ emitcode ("mov", "%s,%s",
+ fReturn[offset],
+ l);
+ offset++;
+ }
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
+ _G.sendSet = NULL;
+ }
+
+ emitcode ("ret", "");
+ emitcode ("", "%05d$:", (rlbl->key + 100));
+
+
+ /* if we need assign a result value */
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
- aopOp(IC_LEFT(sic),sic,FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset,
- FALSE,FALSE);
- if (strcmp(l,fReturn[offset]))
- emitcode("mov","%s,%s",
- fReturn[offset],
- l);
- offset++;
- }
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
- }
- _G.sendSet = NULL;
- }
-
- emitcode("ret","");
- emitcode("","%05d$:",(rlbl->key+100));
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ _G.accInUse--;
+ assignResultValue (IC_RESULT (ic));
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir)) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
-
- _G.accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE);
- _G.accInUse--;
-
- assignResultValue(IC_RESULT(ic));
-
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
- /* adjust the stack for parameters if
- required */
- if (IC_LEFT(ic)->parmBytes) {
- int i;
- if (IC_LEFT(ic)->parmBytes > 3) {
- emitcode("mov","a,%s",spname);
- emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff);
- emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++)
- emitcode("dec","%s",spname);
+ /* adjust the stack for parameters if
+ required */
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i;
+ if (IC_LEFT (ic)->parmBytes > 3)
+ {
+ emitcode ("mov", "a,%s", spname);
+ emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff);
+ emitcode ("mov", "%s,a", spname);
+ }
+ else
+ for (i = 0; i < IC_LEFT (ic)->parmBytes; i++)
+ emitcode ("dec", "%s", spname);
}
- /* if register bank was saved then unsave them */
- if (detype &&
- (SPEC_BANK(currFunc->etype) !=
- SPEC_BANK(detype)))
- unsaverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if register bank was saved then unsave them */
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) !=
+ SPEC_BANK (detype)))
+ unsaverbank (SPEC_BANK (detype), ic, TRUE);
- /* if we hade saved some registers then
- unsave them */
- if (ic->regsSaved)
- unsaveRegisters (ic);
+ /* if we hade saved some registers then
+ unsave them */
+ if (ic->regsSaved)
+ unsaveRegisters (ic);
}
/*-----------------------------------------------------------------*/
/* resultRemat - result is rematerializable */
/*-----------------------------------------------------------------*/
-static int resultRemat (iCode *ic)
+static int
+resultRemat (iCode * ic)
{
- if (SKIP_IC(ic) || ic->op == IFX)
- return 0;
+ if (SKIP_IC (ic) || ic->op == IFX)
+ return 0;
- if (IC_RESULT(ic) && IS_ITEMP(IC_RESULT(ic))) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- if (sym->remat && !POINTER_SET(ic))
- return 1;
+ if (IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic)))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ if (sym->remat && !POINTER_SET (ic))
+ return 1;
}
- return 0;
+ return 0;
}
#if defined(__BORLANDC__) || defined(_MSC_VER)
/*-----------------------------------------------------------------*/
/* inExcludeList - return 1 if the string is in exclude Reg list */
/*-----------------------------------------------------------------*/
-static bool inExcludeList(char *s)
+static bool
+inExcludeList (char *s)
{
- int i =0;
+ 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;
+ 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 ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* genFunction - generated code for function entry */
/*-----------------------------------------------------------------*/
-static void genFunction (iCode *ic)
-{
- symbol *sym;
- sym_link *fetype;
-
- _G.nRegsSaved = 0;
- /* create the function header */
- emitcode(";","-----------------------------------------");
- emitcode(";"," function %s",(sym = OP_SYMBOL(IC_LEFT(ic)))->name);
- emitcode(";","-----------------------------------------");
-
- emitcode("","%s:",sym->rname);
- fetype = getSpec(operandType(IC_LEFT(ic)));
-
- /* if critical function then turn interrupts off */
- if (SPEC_CRTCL(fetype))
- emitcode("clr","ea");
-
- /* here we need to generate the equates for the
- register bank if required */
- if (SPEC_BANK(fetype) != rbank) {
- int i ;
-
- rbank = SPEC_BANK(fetype);
- for ( i = 0 ; i < mcs51_nRegs ; i++ ) {
- if (strcmp(regs8051[i].base,"0") == 0)
- emitcode("","%s = 0x%02x",
- regs8051[i].dname,
- 8*rbank+regs8051[i].offset);
- else
- emitcode ("","%s = %s + 0x%02x",
- regs8051[i].dname,
- regs8051[i].base,
- 8*rbank+regs8051[i].offset);
- }
- }
-
- /* if this is an interrupt service routine then
- save acc, b, dpl, dph */
- if (IS_ISR(sym->etype)) {
-
- if (!inExcludeList("acc"))
- emitcode ("push","acc");
- if (!inExcludeList("b"))
- emitcode ("push","b");
- if (!inExcludeList("dpl"))
- emitcode ("push","dpl");
- if (!inExcludeList("dph"))
- emitcode ("push","dph");
- if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
- {
- emitcode ("push", "dpx");
- /* Make sure we're using standard DPTR */
- emitcode ("push", "dps");
- emitcode ("mov", "dps, #0x00");
- if (options.stack10bit)
- {
- /* This ISR could conceivably use DPTR2. Better save it. */
- emitcode ("push", "dpl1");
- emitcode ("push", "dph1");
- emitcode ("push", "dpx1");
- }
- }
- /* if this isr has no bank i.e. is going to
- run with bank 0 , then we need to save more
- registers :-) */
- if (!SPEC_BANK(sym->etype)) {
-
- /* if this function does not call any other
- function then we can be economical and
- save only those registers that are used */
- if (! sym->hasFcall) {
- int i;
-
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = 0 ; i < sym->regsUsed->size ; i++) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("push","%s",mcs51_regWithIdx(i)->dname);
- }
- }
-
- } else {
- /* this function has a function call cannot
- determines register usage so we will have the
- entire bank */
- saverbank(0,ic,FALSE);
- }
- }
- } else {
- /* if callee-save to be used for this function
- then save the registers being used in this function */
- if (sym->calleeSave) {
+static void
+genFunction (iCode * ic)
+{
+ symbol *sym;
+ sym_link *fetype;
+
+ _G.nRegsSaved = 0;
+ /* create the function header */
+ emitcode (";", "-----------------------------------------");
+ emitcode (";", " function %s", (sym = OP_SYMBOL (IC_LEFT (ic)))->name);
+ emitcode (";", "-----------------------------------------");
+
+ emitcode ("", "%s:", sym->rname);
+ fetype = getSpec (operandType (IC_LEFT (ic)));
+
+ /* if critical function then turn interrupts off */
+ if (SPEC_CRTCL (fetype))
+ emitcode ("clr", "ea");
+
+ /* here we need to generate the equates for the
+ register bank if required */
+ if (SPEC_BANK (fetype) != rbank)
+ {
int i;
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = 0 ; i < sym->regsUsed->size ; i++) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) ) {
- emitcode("push","%s",mcs51_regWithIdx(i)->dname);
- _G.nRegsSaved++;
- }
- }
- }
- }
- }
+ rbank = SPEC_BANK (fetype);
+ for (i = 0; i < mcs51_nRegs; i++)
+ {
+ if (strcmp (regs8051[i].base, "0") == 0)
+ emitcode ("", "%s = 0x%02x",
+ regs8051[i].dname,
+ 8 * rbank + regs8051[i].offset);
+ else
+ emitcode ("", "%s = %s + 0x%02x",
+ regs8051[i].dname,
+ regs8051[i].base,
+ 8 * rbank + regs8051[i].offset);
+ }
+ }
+
+ /* if this is an interrupt service routine then
+ save acc, b, dpl, dph */
+ if (IS_ISR (sym->etype))
+ {
- /* set the register bank to the desired value */
- if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype)) {
- emitcode("push","psw");
- emitcode("mov","psw,#0x%02x",(SPEC_BANK(sym->etype) << 3)&0x00ff);
+ if (!inExcludeList ("acc"))
+ emitcode ("push", "acc");
+ if (!inExcludeList ("b"))
+ emitcode ("push", "b");
+ if (!inExcludeList ("dpl"))
+ emitcode ("push", "dpl");
+ if (!inExcludeList ("dph"))
+ emitcode ("push", "dph");
+ if (options.model == MODEL_FLAT24 && !inExcludeList ("dpx"))
+ {
+ emitcode ("push", "dpx");
+ /* Make sure we're using standard DPTR */
+ emitcode ("push", "dps");
+ emitcode ("mov", "dps, #0x00");
+ if (options.stack10bit)
+ {
+ /* This ISR could conceivably use DPTR2. Better save it. */
+ emitcode ("push", "dpl1");
+ emitcode ("push", "dph1");
+ emitcode ("push", "dpx1");
+ }
+ }
+ /* if this isr has no bank i.e. is going to
+ run with bank 0 , then we need to save more
+ registers :-) */
+ if (!SPEC_BANK (sym->etype))
+ {
+
+ /* if this function does not call any other
+ function then we can be economical and
+ save only those registers that are used */
+ if (!sym->hasFcall)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = 0; i < sym->regsUsed->size; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("push", "%s", mcs51_regWithIdx (i)->dname);
+ }
+ }
+
+ }
+ else
+ {
+ /* this function has a function call cannot
+ determines register usage so we will have the
+ entire bank */
+ saverbank (0, ic, FALSE);
+ }
+ }
+ }
+ else
+ {
+ /* if callee-save to be used for this function
+ then save the registers being used in this function */
+ if (sym->calleeSave)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = 0; i < sym->regsUsed->size; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ {
+ emitcode ("push", "%s", mcs51_regWithIdx (i)->dname);
+ _G.nRegsSaved++;
+ }
+ }
+ }
+ }
+ }
+
+ /* set the register bank to the desired value */
+ if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ {
+ emitcode ("push", "psw");
+ emitcode ("mov", "psw,#0x%02x", (SPEC_BANK (sym->etype) << 3) & 0x00ff);
}
- if (IS_RENT(sym->etype) || options.stackAuto) {
+ if (IS_RENT (sym->etype) || options.stackAuto)
+ {
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- emitcode("mov","a,_bp");
- emitcode("movx","@r0,a");
- emitcode("inc","%s",spname);
- }
- else
- {
- /* set up the stack */
- emitcode ("push","_bp"); /* save the callers stack */
- }
- emitcode ("mov","_bp,%s",spname);
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ emitcode ("mov", "a,_bp");
+ emitcode ("movx", "@r0,a");
+ emitcode ("inc", "%s", spname);
+ }
+ else
+ {
+ /* set up the stack */
+ emitcode ("push", "_bp"); /* save the callers stack */
+ }
+ emitcode ("mov", "_bp,%s", spname);
}
- /* adjust the stack for the function */
- if (sym->stack) {
+ /* adjust the stack for the function */
+ if (sym->stack)
+ {
- int i = sym->stack;
- if (i > 256 )
- werror(W_STACK_OVERFLOW,sym->name);
+ int i = sym->stack;
+ if (i > 256)
+ werror (W_STACK_OVERFLOW, sym->name);
- if (i > 3 && sym->recvSize < 4) {
+ if (i > 3 && sym->recvSize < 4)
+ {
- emitcode ("mov","a,sp");
- emitcode ("add","a,#0x%02x",((char)sym->stack & 0xff));
- emitcode ("mov","sp,a");
+ emitcode ("mov", "a,sp");
+ emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+ emitcode ("mov", "sp,a");
- }
- else
- while(i--)
- emitcode("inc","sp");
+ }
+ else
+ while (i--)
+ emitcode ("inc", "sp");
}
- if (sym->xstack) {
+ if (sym->xstack)
+ {
- emitcode ("mov","a,_spx");
- emitcode ("add","a,#0x%02x",((char)sym->xstack & 0xff));
- emitcode ("mov","_spx,a");
+ emitcode ("mov", "a,_spx");
+ emitcode ("add", "a,#0x%02x", ((char) sym->xstack & 0xff));
+ emitcode ("mov", "_spx,a");
}
}
/*-----------------------------------------------------------------*/
/* genEndFunction - generates epilogue for functions */
/*-----------------------------------------------------------------*/
-static void genEndFunction (iCode *ic)
+static void
+genEndFunction (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
- if (IS_RENT(sym->etype) || options.stackAuto)
+ if (IS_RENT (sym->etype) || options.stackAuto)
{
- emitcode ("mov","%s,_bp",spname);
+ emitcode ("mov", "%s,_bp", spname);
}
- /* if use external stack but some variables were
- added to the local stack then decrement the
- local stack */
- if (options.useXstack && sym->stack) {
- emitcode("mov","a,sp");
- emitcode("add","a,#0x%02x",((char)-sym->stack) & 0xff);
- emitcode("mov","sp,a");
+ /* if use external stack but some variables were
+ added to the local stack then decrement the
+ local stack */
+ if (options.useXstack && sym->stack)
+ {
+ emitcode ("mov", "a,sp");
+ emitcode ("add", "a,#0x%02x", ((char) -sym->stack) & 0xff);
+ emitcode ("mov", "sp,a");
}
- if ((IS_RENT(sym->etype) || options.stackAuto)) {
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- emitcode("movx","a,@r0");
- emitcode("mov","_bp,a");
- emitcode("dec","%s",spname);
- }
- else
- {
- emitcode ("pop","_bp");
- }
+ if ((IS_RENT (sym->etype) || options.stackAuto))
+ {
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ emitcode ("movx", "a,@r0");
+ emitcode ("mov", "_bp,a");
+ emitcode ("dec", "%s", spname);
+ }
+ else
+ {
+ emitcode ("pop", "_bp");
+ }
}
- /* restore the register bank */
- if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype))
- emitcode ("pop","psw");
-
- if (IS_ISR(sym->etype)) {
-
- /* now we need to restore the registers */
- /* if this isr has no bank i.e. is going to
- run with bank 0 , then we need to save more
- registers :-) */
- if (!SPEC_BANK(sym->etype)) {
+ /* restore the register bank */
+ if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ emitcode ("pop", "psw");
- /* if this function does not call any other
- function then we can be economical and
- save only those registers that are used */
- if (! sym->hasFcall) {
- int i;
-
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",mcs51_regWithIdx(i)->dname);
- }
- }
-
- } else {
- /* this function has a function call cannot
- determines register usage so we will have the
- entire bank */
- unsaverbank(0,ic,FALSE);
- }
- }
+ if (IS_ISR (sym->etype))
+ {
- if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
- {
- if (options.stack10bit)
- {
- emitcode ("pop", "dpx1");
- emitcode ("pop", "dph1");
- emitcode ("pop", "dpl1");
- }
- emitcode ("pop", "dps");
- emitcode ("pop", "dpx");
- }
- if (!inExcludeList("dph"))
- emitcode ("pop","dph");
- if (!inExcludeList("dpl"))
- emitcode ("pop","dpl");
- if (!inExcludeList("b"))
- emitcode ("pop","b");
- if (!inExcludeList("acc"))
- emitcode ("pop","acc");
-
- if (SPEC_CRTCL(sym->etype))
- emitcode("setb","ea");
-
- /* if debug then send end of function */
+ /* now we need to restore the registers */
+ /* if this isr has no bank i.e. is going to
+ run with bank 0 , then we need to save more
+ registers :-) */
+ if (!SPEC_BANK (sym->etype))
+ {
+
+ /* if this function does not call any other
+ function then we can be economical and
+ save only those registers that are used */
+ if (!sym->hasFcall)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = sym->regsUsed->size; i >= 0; i--)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("pop", "%s", mcs51_regWithIdx (i)->dname);
+ }
+ }
+
+ }
+ else
+ {
+ /* this function has a function call cannot
+ determines register usage so we will have the
+ entire bank */
+ unsaverbank (0, ic, FALSE);
+ }
+ }
+
+ if (options.model == MODEL_FLAT24 && !inExcludeList ("dpx"))
+ {
+ if (options.stack10bit)
+ {
+ emitcode ("pop", "dpx1");
+ emitcode ("pop", "dph1");
+ emitcode ("pop", "dpl1");
+ }
+ emitcode ("pop", "dps");
+ emitcode ("pop", "dpx");
+ }
+ if (!inExcludeList ("dph"))
+ emitcode ("pop", "dph");
+ if (!inExcludeList ("dpl"))
+ emitcode ("pop", "dpl");
+ if (!inExcludeList ("b"))
+ emitcode ("pop", "b");
+ if (!inExcludeList ("acc"))
+ emitcode ("pop", "acc");
+
+ if (SPEC_CRTCL (sym->etype))
+ emitcode ("setb", "ea");
+
+ /* if debug then send end of function */
/* if (options.debug && currFunc) { */
- if (currFunc) {
- _G.debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),currFunc->lastLine,
- ic->level,ic->block);
- if (IS_STATIC(currFunc->etype))
- emitcode("","XF%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","XG$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
-
- emitcode ("reti","");
+ if (currFunc)
+ {
+ _G.debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), currFunc->lastLine,
+ ic->level, ic->block);
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode ("", "XG$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
+
+ emitcode ("reti", "");
}
- else {
- if (SPEC_CRTCL(sym->etype))
- emitcode("setb","ea");
+ else
+ {
+ if (SPEC_CRTCL (sym->etype))
+ emitcode ("setb", "ea");
- if (sym->calleeSave) {
- int i;
+ if (sym->calleeSave)
+ {
+ int i;
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",mcs51_regWithIdx(i)->dname);
- }
- }
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = sym->regsUsed->size; i >= 0; i--)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("pop", "%s", mcs51_regWithIdx (i)->dname);
+ }
+ }
- }
+ }
- /* if debug then send end of function */
- if (currFunc) {
- _G.debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),currFunc->lastLine,
- ic->level,ic->block);
- if (IS_STATIC(currFunc->etype))
- emitcode("","XF%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","XG$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
+ /* if debug then send end of function */
+ if (currFunc)
+ {
+ _G.debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), currFunc->lastLine,
+ ic->level, ic->block);
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode ("", "XG$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
- emitcode ("ret","");
+ emitcode ("ret", "");
}
}
/*-----------------------------------------------------------------*/
/* genRet - generate code for return statement */
/*-----------------------------------------------------------------*/
-static void genRet (iCode *ic)
-{
- int size,offset = 0 , pushed = 0;
-
- /* if we have no return value then
- just generate the "ret" */
- if (!IC_LEFT(ic))
- goto jumpret;
-
- /* we have something to return then
- move the return value into place */
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
-
- while (size--) {
- char *l ;
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
- /* #NOCHANGE */
- l = aopGet(AOP(IC_LEFT(ic)),offset++,
- FALSE,TRUE);
- emitcode("push","%s",l);
- pushed++;
- } else {
- l = aopGet(AOP(IC_LEFT(ic)),offset,
- FALSE,FALSE);
- if (strcmp(fReturn[offset],l))
- emitcode("mov","%s,%s",fReturn[offset++],l);
- }
- }
+static void
+genRet (iCode * ic)
+{
+ int size, offset = 0, pushed = 0;
- if (pushed) {
- while(pushed) {
- pushed--;
- if (strcmp(fReturn[pushed],"a"))
- emitcode("pop",fReturn[pushed]);
+ /* if we have no return value then
+ just generate the "ret" */
+ if (!IC_LEFT (ic))
+ goto jumpret;
+
+ /* we have something to return then
+ move the return value into place */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+
+ while (size--)
+ {
+ char *l;
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR)
+ {
+ /* #NOCHANGE */
+ l = aopGet (AOP (IC_LEFT (ic)), offset++,
+ FALSE, TRUE);
+ emitcode ("push", "%s", l);
+ pushed++;
+ }
else
- emitcode("pop","acc");
- }
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset,
+ FALSE, FALSE);
+ if (strcmp (fReturn[offset], l))
+ emitcode ("mov", "%s,%s", fReturn[offset++], l);
+ }
}
- freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
- jumpret:
+ if (pushed)
+ {
+ while (pushed)
+ {
+ pushed--;
+ if (strcmp (fReturn[pushed], "a"))
+ emitcode ("pop", fReturn[pushed]);
+ else
+ emitcode ("pop", "acc");
+ }
+ }
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
+
+jumpret:
/* generate a jump to the return label
if the next is not the return statement */
- if (!(ic->next && ic->next->op == LABEL &&
- IC_LABEL(ic->next) == returnLabel))
+ if (!(ic->next && ic->next->op == LABEL &&
+ IC_LABEL (ic->next) == returnLabel))
- emitcode("ljmp","%05d$",(returnLabel->key+100));
+ emitcode ("ljmp", "%05d$", (returnLabel->key + 100));
}
/*-----------------------------------------------------------------*/
/* genLabel - generates a label */
/*-----------------------------------------------------------------*/
-static void genLabel (iCode *ic)
+static void
+genLabel (iCode * ic)
{
- /* special case never generate */
- if (IC_LABEL(ic) == entryLabel)
- return ;
+ /* special case never generate */
+ if (IC_LABEL (ic) == entryLabel)
+ return;
- emitcode("","%05d$:",(IC_LABEL(ic)->key+100));
+ emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100));
}
/*-----------------------------------------------------------------*/
/* genGoto - generates a ljmp */
/*-----------------------------------------------------------------*/
-static void genGoto (iCode *ic)
+static void
+genGoto (iCode * ic)
{
- emitcode ("ljmp","%05d$",(IC_LABEL(ic)->key+100));
+ emitcode ("ljmp", "%05d$", (IC_LABEL (ic)->key + 100));
}
/*-----------------------------------------------------------------*/
/* between that label and given ic. */
/* Returns zero if label not found. */
/*-----------------------------------------------------------------*/
-static int findLabelBackwards(iCode *ic, int key)
+static int
+findLabelBackwards (iCode * ic, int key)
{
- int count = 0;
+ int count = 0;
- while (ic->prev)
+ while (ic->prev)
{
- ic = ic->prev;
- count++;
+ ic = ic->prev;
+ count++;
- if (ic->op == LABEL && IC_LABEL(ic)->key == key)
- {
- /* printf("findLabelBackwards = %d\n", count); */
- return count;
- }
+ if (ic->op == LABEL && IC_LABEL (ic)->key == key)
+ {
+ /* printf("findLabelBackwards = %d\n", count); */
+ return count;
+ }
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* genPlusIncr :- does addition with increment if possible */
/*-----------------------------------------------------------------*/
-static bool genPlusIncr (iCode *ic)
-{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
-
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
-
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if ((icount = floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 4)
- return FALSE ;
-
- /* if increment 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) &&
- (icount == 1)) {
- symbol *tlbl;
- int emitTlbl;
- int labelRange;
-
- /* If the next instruction is a goto and the goto target
- * is < 10 instructions previous to this, we can generate
- * jumps straight to that target.
- */
- if (ic->next && ic->next->op == GOTO
- && (labelRange = findLabelBackwards(ic, IC_LABEL(ic->next)->key)) != 0
- && labelRange <= 10 )
- {
- emitcode(";", "tail increment optimized");
- tlbl = IC_LABEL(ic->next);
- emitTlbl = 0;
- }
- else
- {
- tlbl = newiTempLabel(NULL);
- emitTlbl = 1;
- }
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0x00,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
- ,tlbl->key+100);
- else {
- emitcode("clr","a");
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
- ,tlbl->key+100);
- }
+static bool
+genPlusIncr (iCode * ic)
+{
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
- if (size > 2)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0x00,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
- ,tlbl->key+100);
- else
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
- ,tlbl->key+100);
-
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
- }
- if (size > 3)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0x00,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
- }
+ /* will try to generate an increment */
+ /* if the right side is not a literal
+ we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
- if (emitTlbl)
- {
- emitcode("","%05d$:",tlbl->key+100);
- }
- return TRUE;
+ /* if the literal value of the right hand side
+ is greater than 4 then it is not worth it */
+ if ((icount = floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
+ return FALSE;
+
+ /* if increment 16 bits in register */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (size > 1) &&
+ (icount == 1))
+ {
+ symbol *tlbl;
+ int emitTlbl;
+ int labelRange;
+
+ /* If the next instruction is a goto and the goto target
+ * is < 10 instructions previous to this, we can generate
+ * jumps straight to that target.
+ */
+ if (ic->next && ic->next->op == GOTO
+ && (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
+ && labelRange <= 10)
+ {
+ emitcode (";", "tail increment optimized");
+ tlbl = IC_LABEL (ic->next);
+ emitTlbl = 0;
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ emitTlbl = 1;
+ }
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0x00,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("clr", "a");
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE));
+ if (size > 2)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0x00,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE)
+ ,tlbl->key + 100);
+
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE));
+ }
+ if (size > 3)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0x00,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE));
+ }
+
+ if (emitTlbl)
+ {
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* we can if the aops of the left & result match or
- if they are in registers and the registers are the
- same */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
+ /* we can if the aops of the left & result match or
+ if they are in registers and the registers are the
+ same */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
- if (icount > 3) {
- MOVA(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("add","a,#0x%02x",((char) icount) & 0xff);
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- } else {
+ if (icount > 3)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ emitcode ("add", "a,#0x%02x", ((char) icount) & 0xff);
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ }
+ else
+ {
- while (icount--)
- emitcode ("inc","%s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- }
+ while (icount--)
+ emitcode ("inc", "%s", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ }
- return TRUE ;
+ return TRUE;
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* outBitAcc - output a bit in acc */
/*-----------------------------------------------------------------*/
-static void outBitAcc(operand *result)
+static void
+outBitAcc (operand * result)
{
- symbol *tlbl = newiTempLabel(NULL);
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY){
- aopPut(AOP(result),"a",0);
+ symbol *tlbl = newiTempLabel (NULL);
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ aopPut (AOP (result), "a", 0);
}
- else {
- emitcode("jz","%05d$",tlbl->key+100);
- emitcode("mov","a,%s",one);
- emitcode("","%05d$:",tlbl->key+100);
- outAcc(result);
+ else
+ {
+ emitcode ("jz", "%05d$", tlbl->key + 100);
+ emitcode ("mov", "a,%s", one);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outAcc (result);
}
}
/*-----------------------------------------------------------------*/
/* genPlusBits - generates code for addition of two bits */
/*-----------------------------------------------------------------*/
-static void genPlusBits (iCode *ic)
+static void
+genPlusBits (iCode * ic)
{
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("jnb","%s,%05d$",AOP(IC_RIGHT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- outBitC(IC_RESULT(ic));
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("jnb", "%s,%05d$", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ outBitC (IC_RESULT (ic));
}
- else{
- emitcode("clr","a");
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("rlc","a");
- emitcode("mov","c,%s",AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("addc","a,#0x00");
- outAcc(IC_RESULT(ic));
+ else
+ {
+ emitcode ("clr", "a");
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("rlc", "a");
+ emitcode ("mov", "c,%s", AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode ("addc", "a,#0x00");
+ outAcc (IC_RESULT (ic));
}
}
#if 0
/* This is the original version of this code.
- *
+
* This is being kept around for reference,
* because I am not entirely sure I got it right...
*/
-static void adjustArithmeticResult(iCode *ic)
-{
- if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
- AOP_SIZE(IC_LEFT(ic)) == 3 &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_LEFT(ic)),2,FALSE,FALSE),
- 2);
-
- if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
- AOP_SIZE(IC_RIGHT(ic)) == 3 &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_RIGHT(ic)),2,FALSE,FALSE),
- 2);
-
- if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
- AOP_SIZE(IC_LEFT(ic)) < 3 &&
- AOP_SIZE(IC_RIGHT(ic)) < 3 &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
- char buffer[5];
- sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
- aopPut(AOP(IC_RESULT(ic)),buffer,2);
+static void
+adjustArithmeticResult (iCode * ic)
+{
+ if (AOP_SIZE (IC_RESULT (ic)) == 3 &&
+ AOP_SIZE (IC_LEFT (ic)) == 3 &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_LEFT (ic)), 2, FALSE, FALSE),
+ 2);
+
+ if (AOP_SIZE (IC_RESULT (ic)) == 3 &&
+ AOP_SIZE (IC_RIGHT (ic)) == 3 &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_RIGHT (ic)), 2, FALSE, FALSE),
+ 2);
+
+ if (AOP_SIZE (IC_RESULT (ic)) == 3 &&
+ AOP_SIZE (IC_LEFT (ic)) < 3 &&
+ AOP_SIZE (IC_RIGHT (ic)) < 3 &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ {
+ char buffer[5];
+ sprintf (buffer, "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic)))));
+ aopPut (AOP (IC_RESULT (ic)), buffer, 2);
}
}
#else
* I'm pretty certain it's right, but not enough to toss the old
* code just yet...
*/
-static void adjustArithmeticResult(iCode *ic)
+static void
+adjustArithmeticResult (iCode * ic)
{
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_LEFT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_LEFT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_LEFT(ic)), GPTRSIZE - 1,FALSE,FALSE),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_LEFT (ic)), GPTRSIZE - 1, FALSE, FALSE),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_RIGHT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_RIGHT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_RIGHT(ic)),GPTRSIZE - 1,FALSE,FALSE),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_RIGHT (ic)), GPTRSIZE - 1, FALSE, FALSE),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- AOP_SIZE(IC_LEFT(ic)) < GPTRSIZE &&
- AOP_SIZE(IC_RIGHT(ic)) < GPTRSIZE &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
- char buffer[5];
- sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
- aopPut(AOP(IC_RESULT(ic)),buffer,GPTRSIZE - 1);
- }
+ if (opIsGptr (IC_RESULT (ic)) &&
+ AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+ AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ {
+ char buffer[5];
+ sprintf (buffer, "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic)))));
+ aopPut (AOP (IC_RESULT (ic)), buffer, GPTRSIZE - 1);
+ }
}
#endif
/*-----------------------------------------------------------------*/
/* genPlus - generates code for addition */
/*-----------------------------------------------------------------*/
-static void genPlus (iCode *ic)
-{
- int size, offset = 0;
-
- /* special cases :- */
-
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
-
- /* if literal, literal on the right or
- if left requires ACC or right is already
- in ACC */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (AOP_NEEDSACC(IC_LEFT(ic))) ||
- AOP_TYPE(IC_RIGHT(ic)) == AOP_ACC ){
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
- }
-
- /* if both left & right are in bit
- space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- genPlusBits (ic);
- goto release ;
- }
-
- /* if left in bit space & right literal */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- /* if result in bit space */
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- if((unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit) != 0L)
- emitcode("cpl","c");
- outBitC(IC_RESULT(ic));
- } else {
- size = getDataSize(IC_RESULT(ic));
- while (size--) {
- MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitcode("addc","a,#00");
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
- }
- }
- goto release ;
- }
-
- /* if I can do an increment instead
- of add then GOOD for ME */
- if (genPlusIncr (ic) == TRUE)
- goto release;
-
- size = getDataSize(IC_RESULT(ic));
-
- while(size--){
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
- MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- if(offset == 0)
- emitcode("add","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
+static void
+genPlus (iCode * ic)
+{
+ int size, offset = 0;
+
+ /* special cases :- */
+
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
+
+ /* if literal, literal on the right or
+ if left requires ACC or right is already
+ in ACC */
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT) ||
+ (AOP_NEEDSACC (IC_LEFT (ic))) ||
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_ACC)
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
+ }
+
+ /* if both left & right are in bit
+ space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ genPlusBits (ic);
+ goto release;
+ }
+
+ /* if left in bit space & right literal */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT)
+ {
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ /* if result in bit space */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ if ((unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) != 0L)
+ emitcode ("cpl", "c");
+ outBitC (IC_RESULT (ic));
+ }
else
- emitcode("addc","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- } else {
- MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- if(offset == 0)
- emitcode("add","a,%s",
- aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+ {
+ size = getDataSize (IC_RESULT (ic));
+ while (size--)
+ {
+ MOVA (aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ emitcode ("addc", "a,#00");
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
+ }
+ }
+ goto release;
+ }
+
+ /* if I can do an increment instead
+ of add then GOOD for ME */
+ if (genPlusIncr (ic) == TRUE)
+ goto release;
+
+ size = getDataSize (IC_RESULT (ic));
+
+ while (size--)
+ {
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ if (offset == 0)
+ emitcode ("add", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ else
+ emitcode ("addc", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ }
else
- emitcode("addc","a,%s",
- aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- }
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ {
+ MOVA (aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ if (offset == 0)
+ emitcode ("add", "a,%s",
+ aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ else
+ emitcode ("addc", "a,%s",
+ aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ }
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
- adjustArithmeticResult(ic);
+ adjustArithmeticResult (ic);
release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMinusDec :- does subtraction with deccrement if possible */
/*-----------------------------------------------------------------*/
-static bool genMinusDec (iCode *ic)
+static bool
+genMinusDec (iCode * ic)
{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
+ /* will try to generate an increment */
+ /* if the right side is not a literal
+ we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 4)
- return FALSE ;
+ /* if the literal value of the right hand side
+ is greater than 4 then it is not worth it */
+ if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
+ return FALSE;
- /* if decrement 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) &&
- (icount == 1)) {
- symbol *tlbl;
- int emitTlbl;
- int labelRange;
+ /* if decrement 16 bits in register */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (size > 1) &&
+ (icount == 1))
+ {
+ symbol *tlbl;
+ int emitTlbl;
+ int labelRange;
/* If the next instruction is a goto and the goto target
* is <= 10 instructions previous to this, we can generate
* jumps straight to that target.
*/
- if (ic->next && ic->next->op == GOTO
- && (labelRange = findLabelBackwards(ic, IC_LABEL(ic->next)->key)) != 0
- && labelRange <= 10 )
- {
- emitcode(";", "tail decrement optimized");
- tlbl = IC_LABEL(ic->next);
- emitTlbl = 0;
- }
- else
- {
- tlbl = newiTempLabel(NULL);
- emitTlbl = 1;
- }
-
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0xff,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("mov","a,#0xff");
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
- if (size > 2)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0xff,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
- }
- if (size > 3)
- {
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_REG ||
- IS_AOP_PREG(IC_RESULT(ic)))
- emitcode("cjne","%s,#0xff,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
- ,tlbl->key+100);
- else{
- emitcode("cjne","a,%s,%05d$"
- ,aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE)
- ,tlbl->key+100);
- }
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
- }
- if (emitTlbl)
- {
- emitcode("","%05d$:",tlbl->key+100);
- }
- return TRUE;
+ if (ic->next && ic->next->op == GOTO
+ && (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
+ && labelRange <= 10)
+ {
+ emitcode (";", "tail decrement optimized");
+ tlbl = IC_LABEL (ic->next);
+ emitTlbl = 0;
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ emitTlbl = 1;
+ }
+
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0xff,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("mov", "a,#0xff");
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE));
+ if (size > 2)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0xff,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE));
+ }
+ if (size > 3)
+ {
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+ IS_AOP_PREG (IC_RESULT (ic)))
+ emitcode ("cjne", "%s,#0xff,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE)
+ ,tlbl->key + 100);
+ else
+ {
+ emitcode ("cjne", "a,%s,%05d$"
+ ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE)
+ ,tlbl->key + 100);
+ }
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE));
+ }
+ if (emitTlbl)
+ {
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* we can if the aops of the left & result match or
- if they are in registers and the registers are the
- same */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
+ /* we can if the aops of the left & result match or
+ if they are in registers and the registers are the
+ same */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
- while (icount--)
- emitcode ("dec","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+ while (icount--)
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
- return TRUE ;
+ return TRUE;
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* addSign - complete with sign */
/*-----------------------------------------------------------------*/
-static void addSign(operand *result, int offset, int 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++);
+ 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++);
}
}
/*-----------------------------------------------------------------*/
/* genMinusBits - generates code for subtraction of two bits */
/*-----------------------------------------------------------------*/
-static void genMinusBits (iCode *ic)
+static void
+genMinusBits (iCode * ic)
{
- symbol *lbl = newiTempLabel(NULL);
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("jnb","%s,%05d$",AOP(IC_RIGHT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- outBitC(IC_RESULT(ic));
+ symbol *lbl = newiTempLabel (NULL);
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("jnb", "%s,%05d$", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ outBitC (IC_RESULT (ic));
}
- else{
- emitcode("mov","c,%s",AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("subb","a,acc");
- emitcode("jnb","%s,%05d$",AOP(IC_LEFT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- addSign(IC_RESULT(ic), MSB16, SPEC_USIGN(getSpec(operandType(IC_RESULT(ic)))));
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode ("subb", "a,acc");
+ emitcode ("jnb", "%s,%05d$", AOP (IC_LEFT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ addSign (IC_RESULT (ic), MSB16, SPEC_USIGN (getSpec (operandType (IC_RESULT (ic)))));
}
}
/*-----------------------------------------------------------------*/
/* genMinus - generates code for subtraction */
/*-----------------------------------------------------------------*/
-static void genMinus (iCode *ic)
+static void
+genMinus (iCode * ic)
{
- int size, offset = 0;
- unsigned long lit = 0L;
+ int size, offset = 0;
+ unsigned long lit = 0L;
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* special cases :- */
- /* if both left & right are in bit space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- genMinusBits (ic);
- goto release ;
+ /* special cases :- */
+ /* if both left & right are in bit space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ genMinusBits (ic);
+ goto release;
}
- /* if I can do an decrement instead
- of subtract then GOOD for ME */
- if (genMinusDec (ic) == TRUE)
- goto release;
+ /* if I can do an decrement instead
+ of subtract then GOOD for ME */
+ if (genMinusDec (ic) == TRUE)
+ goto release;
- size = getDataSize(IC_RESULT(ic));
+ size = getDataSize (IC_RESULT (ic));
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT){
- CLRC;
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ {
+ CLRC;
}
- else{
- lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- lit = - (long)lit;
+ else
+ {
+ lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ lit = -(long) lit;
}
- /* if literal, add a,#-lit, else normal subb */
- while (size--) {
- MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- emitcode("subb","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- else{
- /* first add without previous c */
- if(!offset)
- 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++);
+ /* if literal, add a,#-lit, else normal subb */
+ while (size--)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ emitcode ("subb", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ else
+ {
+ /* first add without previous c */
+ if (!offset)
+ 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++);
}
- adjustArithmeticResult(ic);
+ adjustArithmeticResult (ic);
release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMultbits :- multiplication of bits */
/*-----------------------------------------------------------------*/
-static void genMultbits (operand *left,
- operand *right,
- operand *result)
+static void
+genMultbits (operand * left,
+ operand * right,
+ operand * result)
{
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
}
/*-----------------------------------------------------------------*/
/* genMultOneByte : 8 bit multiplication & division */
/*-----------------------------------------------------------------*/
-static void genMultOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- /* (if two literals, the value is computed before) */
- /* if one literal, literal on the right */
- if (AOP_TYPE(left) == AOP_LIT){
- operand *t = right;
- right = left;
- left = t;
- }
-
- size = AOP_SIZE(result);
- /* signed or unsigned */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("mul","ab");
- /* if result size = 1, mul signed = mul unsigned */
- aopPut(AOP(result),"a",0);
- if (size > 1){
- if (SPEC_USIGN(opetype)){
- aopPut(AOP(result),"b",1);
- if (size > 2)
- /* for filling the MSBs */
- emitcode("clr","a");
- }
- else{
- emitcode("mov","a,b");
-
- /* adjust the MSB if left or right neg */
-
- /* if one literal */
- if (AOP_TYPE(right) == AOP_LIT){
- /* AND literal negative */
- if((int) floatFromVal (AOP(right)->aopu.aop_lit) < 0){
- /* adjust MSB (c==0 after mul) */
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
- }
- }
- else{
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d$", (lbl->key+100));
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d$",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("","%05d$:",(lbl->key+100));
- }
-
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d$", (lbl->key+100));
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d$",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("","%05d$:",(lbl->key+100));
-
- aopPut(AOP(result),"a",1);
- if(size > 2){
- /* get the sign */
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- }
- }
- size -= 2;
- offset = 2;
- if (size > 0)
- while (size--)
- aopPut(AOP(result),"a",offset++);
+static void
+genMultOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+ int size, offset;
+
+ /* (if two literals, the value is computed before) */
+ /* if one literal, literal on the right */
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
+
+ size = AOP_SIZE (result);
+ /* signed or unsigned */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("mul", "ab");
+ /* if result size = 1, mul signed = mul unsigned */
+ aopPut (AOP (result), "a", 0);
+ if (size > 1)
+ {
+ if (SPEC_USIGN (opetype))
+ {
+ aopPut (AOP (result), "b", 1);
+ if (size > 2)
+ /* for filling the MSBs */
+ emitcode ("clr", "a");
+ }
+ else
+ {
+ emitcode ("mov", "a,b");
+
+ /* adjust the MSB if left or right neg */
+
+ /* if one literal */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ /* AND literal negative */
+ if ((int) floatFromVal (AOP (right)->aopu.aop_lit) < 0)
+ {
+ /* adjust MSB (c==0 after mul) */
+ emitcode ("subb", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ }
+ }
+ else
+ {
+ lbl = newiTempLabel (NULL);
+ emitcode ("xch", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("cjne", "a,#0x80,%05d$", (lbl->key + 100));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("xch", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ lbl = newiTempLabel (NULL);
+ emitcode ("jc", "%05d$", (lbl->key + 100));
+ emitcode ("subb", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ }
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("xch", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("cjne", "a,#0x80,%05d$", (lbl->key + 100));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ lbl = newiTempLabel (NULL);
+ emitcode ("jc", "%05d$", (lbl->key + 100));
+ emitcode ("subb", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ aopPut (AOP (result), "a", 1);
+ if (size > 2)
+ {
+ /* get the sign */
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ }
+ }
+ size -= 2;
+ offset = 2;
+ if (size > 0)
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
}
}
/*-----------------------------------------------------------------*/
/* genMult - generates code for multiplication */
/*-----------------------------------------------------------------*/
-static void genMult (iCode *ic)
+static void
+genMult (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genMultbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genMultbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genMultOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genMultOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1) ;
+ /* should have been converted to function call */
+ assert (1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDivbits :- division of bits */
/*-----------------------------------------------------------------*/
-static void genDivbits (operand *left,
- operand *right,
- operand *result)
+static void
+genDivbits (operand * left,
+ operand * right,
+ operand * result)
{
- char *l;
+ char *l;
- /* the result must be bit */
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
+ /* the result must be bit */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
- MOVA(l);
+ MOVA (l);
- emitcode("div","ab");
- emitcode("rrc","a");
- aopPut(AOP(result),"c",0);
+ emitcode ("div", "ab");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "c", 0);
}
/*-----------------------------------------------------------------*/
/* genDivOneByte : 8 bit division */
/*-----------------------------------------------------------------*/
-static void genDivOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- size = AOP_SIZE(result) - 1;
- offset = 1;
- /* signed or unsigned */
- if (SPEC_USIGN(opetype)) {
- /* unsigned is easy */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("div","ab");
- aopPut(AOP(result),"a",0);
- while (size--)
- aopPut(AOP(result),zero,offset++);
- return ;
- }
-
- /* signed is a little bit more difficult */
-
- /* save the signs of the operands */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,TRUE));
- emitcode("push","acc"); /* save it on the stack */
-
- /* now sign adjust for both left & right */
- l = aopGet(AOP(right),0,FALSE,FALSE);
- MOVA(l);
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("mov","b,a");
-
- /* sign adjust left side */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now the division */
- emitcode("div","ab");
- /* we are interested in the lower order
- only */
- emitcode("mov","b,a");
- lbl = newiTempLabel(NULL);
- emitcode("pop","acc");
- /* if there was an over flow we don't
- adjust the sign of the result */
- emitcode("jb","ov,%05d$",(lbl->key+100));
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- CLRC;
- emitcode("clr","a");
- emitcode("subb","a,b");
- emitcode("mov","b,a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now we are done */
- aopPut(AOP(result),"b",0);
- if(size > 0){
- emitcode("mov","c,b.7");
- emitcode("subb","a,acc");
+static void
+genDivOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+ int size, offset;
+
+ size = AOP_SIZE (result) - 1;
+ offset = 1;
+ /* signed or unsigned */
+ if (SPEC_USIGN (opetype))
+ {
+ /* unsigned is easy */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("div", "ab");
+ aopPut (AOP (result), "a", 0);
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ return;
+ }
+
+ /* signed is a little bit more difficult */
+
+ /* save the signs of the operands */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), 0, FALSE, TRUE));
+ emitcode ("push", "acc"); /* save it on the stack */
+
+ /* now sign adjust for both left & right */
+ l = aopGet (AOP (right), 0, FALSE, FALSE);
+ MOVA (l);
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("mov", "b,a");
+
+ /* sign adjust left side */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now the division */
+ emitcode ("div", "ab");
+ /* we are interested in the lower order
+ only */
+ emitcode ("mov", "b,a");
+ lbl = newiTempLabel (NULL);
+ emitcode ("pop", "acc");
+ /* if there was an over flow we don't
+ adjust the sign of the result */
+ emitcode ("jb", "ov,%05d$", (lbl->key + 100));
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,b");
+ emitcode ("mov", "b,a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now we are done */
+ aopPut (AOP (result), "b", 0);
+ if (size > 0)
+ {
+ emitcode ("mov", "c,b.7");
+ emitcode ("subb", "a,acc");
}
- while (size--)
- aopPut(AOP(result),"a",offset++);
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
}
/*-----------------------------------------------------------------*/
/* genDiv - generates code for division */
/*-----------------------------------------------------------------*/
-static void genDiv (iCode *ic)
+static void
+genDiv (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genDivbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genDivbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genDivOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genDivOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ /* should have been converted to function call */
+ assert (1);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genModbits :- modulus of bits */
/*-----------------------------------------------------------------*/
-static void genModbits (operand *left,
- operand *right,
- operand *result)
+static void
+genModbits (operand * left,
+ operand * right,
+ operand * result)
{
- char *l;
+ char *l;
- /* the result must be bit */
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
+ /* the result must be bit */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
- MOVA(l);
+ MOVA (l);
- emitcode("div","ab");
- emitcode("mov","a,b");
- emitcode("rrc","a");
- aopPut(AOP(result),"c",0);
+ emitcode ("div", "ab");
+ emitcode ("mov", "a,b");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "c", 0);
}
/*-----------------------------------------------------------------*/
/* genModOneByte : 8 bit modulus */
/*-----------------------------------------------------------------*/
-static void genModOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
-
- /* signed or unsigned */
- if (SPEC_USIGN(opetype)) {
- /* unsigned is easy */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("div","ab");
- aopPut(AOP(result),"b",0);
- return ;
- }
-
- /* signed is a little bit more difficult */
-
- /* save the signs of the operands */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
-
- emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("push","acc"); /* save it on the stack */
-
- /* now sign adjust for both left & right */
- l = aopGet(AOP(right),0,FALSE,FALSE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
- emitcode("mov","b,a");
-
- /* sign adjust left side */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now the multiplication */
- emitcode("div","ab");
- /* we are interested in the lower order
- only */
- lbl = newiTempLabel(NULL);
- emitcode("pop","acc");
- /* if there was an over flow we don't
- adjust the sign of the result */
- emitcode("jb","ov,%05d$",(lbl->key+100));
- emitcode("jnb","acc.7,%05d$",(lbl->key+100));
- CLRC ;
- emitcode("clr","a");
- emitcode("subb","a,b");
- emitcode("mov","b,a");
- emitcode("","%05d$:",(lbl->key+100));
-
- /* now we are done */
- aopPut(AOP(result),"b",0);
+static void
+genModOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+
+ /* signed or unsigned */
+ if (SPEC_USIGN (opetype))
+ {
+ /* unsigned is easy */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("div", "ab");
+ aopPut (AOP (result), "b", 0);
+ return;
+ }
+
+ /* signed is a little bit more difficult */
+
+ /* save the signs of the operands */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("push", "acc"); /* save it on the stack */
+
+ /* now sign adjust for both left & right */
+ l = aopGet (AOP (right), 0, FALSE, FALSE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ emitcode ("mov", "b,a");
+
+ /* sign adjust left side */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now the multiplication */
+ emitcode ("div", "ab");
+ /* we are interested in the lower order
+ only */
+ lbl = newiTempLabel (NULL);
+ emitcode ("pop", "acc");
+ /* if there was an over flow we don't
+ adjust the sign of the result */
+ emitcode ("jb", "ov,%05d$", (lbl->key + 100));
+ emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100));
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,b");
+ emitcode ("mov", "b,a");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+
+ /* now we are done */
+ aopPut (AOP (result), "b", 0);
}
/*-----------------------------------------------------------------*/
/* genMod - generates code for division */
/*-----------------------------------------------------------------*/
-static void genMod (iCode *ic)
+static void
+genMod (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genModbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genModbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genModOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genModOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1);
+ /* should have been converted to function call */
+ assert (1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIfxJump :- will create a jump depending on the ifx */
/*-----------------------------------------------------------------*/
-static void genIfxJump (iCode *ic, char *jval)
+static void
+genIfxJump (iCode * ic, char *jval)
{
- symbol *jlbl ;
- symbol *tlbl = newiTempLabel(NULL);
- char *inst;
+ symbol *jlbl;
+ symbol *tlbl = newiTempLabel (NULL);
+ char *inst;
- /* if true label then we jump if condition
- supplied is true */
- if ( IC_TRUE(ic) ) {
- jlbl = IC_TRUE(ic);
- inst = ((strcmp(jval,"a") == 0 ? "jz" :
- (strcmp(jval,"c") == 0 ? "jnc" : "jnb" )));
+ /* if true label then we jump if condition
+ supplied is true */
+ if (IC_TRUE (ic))
+ {
+ jlbl = IC_TRUE (ic);
+ inst = ((strcmp (jval, "a") == 0 ? "jz" :
+ (strcmp (jval, "c") == 0 ? "jnc" : "jnb")));
}
- else {
- /* false label is present */
- jlbl = IC_FALSE(ic) ;
- inst = ((strcmp(jval,"a") == 0 ? "jnz" :
- (strcmp(jval,"c") == 0 ? "jc" : "jb" )));
+ else
+ {
+ /* false label is present */
+ jlbl = IC_FALSE (ic);
+ inst = ((strcmp (jval, "a") == 0 ? "jnz" :
+ (strcmp (jval, "c") == 0 ? "jc" : "jb")));
}
- if (strcmp(inst,"jb") == 0 || strcmp(inst,"jnb") == 0)
- emitcode(inst,"%s,%05d$",jval,(tlbl->key+100));
- else
- emitcode(inst,"%05d$",tlbl->key+100);
- emitcode("ljmp","%05d$",jlbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
+ if (strcmp (inst, "jb") == 0 || strcmp (inst, "jnb") == 0)
+ emitcode (inst, "%s,%05d$", jval, (tlbl->key + 100));
+ else
+ emitcode (inst, "%05d$", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", jlbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
- /* mark the icode as generated */
- ic->generated = 1;
+ /* mark the icode as generated */
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genCmp :- greater or less than comparison */
/*-----------------------------------------------------------------*/
-static void genCmp (operand *left,operand *right,
- operand *result, iCode *ifx, int sign)
-{
- int size, offset = 0 ;
- unsigned long lit = 0L;
-
- /* if left & right are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
- } else {
- /* subtract right from left if at the
- end the carry flag is set then we know that
- left is greater than right */
- size = max(AOP_SIZE(left),AOP_SIZE(right));
-
- /* if unsigned char cmp with lit, do cjne left,#right,zz */
- if((size == 1) && !sign &&
- (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
- symbol *lbl = newiTempLabel(NULL);
- emitcode("cjne","%s,%s,%05d$",
- aopGet(AOP(left),offset,FALSE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE),
- lbl->key+100);
- emitcode("","%05d$:",lbl->key+100);
- } else {
- if(AOP_TYPE(right) == AOP_LIT){
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- /* optimize if(x < 0) or if(x >= 0) */
- if(lit == 0L){
- if(!sign){
- CLRC;
- }
- else{
- MOVA(aopGet(AOP(left),AOP_SIZE(left)-1,FALSE,FALSE));
- if(!(AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) && ifx){
- genIfxJump (ifx,"acc.7");
- return;
- }
- else
- emitcode("rlc","a");
- }
- goto release;
- }
- }
- CLRC;
- while (size--) {
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
- if (sign && size == 0) {
- emitcode("xrl","a,#0x80");
- if (AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)
- floatFromVal(AOP(right)->aopu.aop_lit);
- emitcode("subb","a,#0x%02x",
- 0x80 ^ (unsigned int)((lit >> (offset*8)) & 0x0FFL));
- } else {
- emitcode("mov","b,%s",aopGet(AOP(right),offset++,FALSE,FALSE));
- emitcode("xrl","b,#0x80");
- emitcode("subb","a,b");
- }
- } else
- emitcode("subb","a,%s",aopGet(AOP(right),offset++,FALSE,FALSE));
- }
- }
+static void
+genCmp (operand * left, operand * right,
+ operand * result, iCode * ifx, int sign)
+{
+ int size, offset = 0;
+ unsigned long lit = 0L;
+
+ /* if left & right are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("anl", "c,/%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ /* subtract right from left if at the
+ end the carry flag is set then we know that
+ left is greater than right */
+ size = max (AOP_SIZE (left), AOP_SIZE (right));
+
+ /* if unsigned char cmp with lit, do cjne left,#right,zz */
+ if ((size == 1) && !sign &&
+ (AOP_TYPE (right) == AOP_LIT && AOP_TYPE (left) != AOP_DIR))
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("cjne", "%s,%s,%05d$",
+ aopGet (AOP (left), offset, FALSE, FALSE),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ lbl->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ /* optimize if(x < 0) or if(x >= 0) */
+ if (lit == 0L)
+ {
+ if (!sign)
+ {
+ CLRC;
+ }
+ else
+ {
+ MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE));
+ if (!(AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) && ifx)
+ {
+ genIfxJump (ifx, "acc.7");
+ return;
+ }
+ else
+ emitcode ("rlc", "a");
+ }
+ goto release;
+ }
+ }
+ CLRC;
+ while (size--)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE));
+ if (sign && size == 0)
+ {
+ emitcode ("xrl", "a,#0x80");
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long)
+ floatFromVal (AOP (right)->aopu.aop_lit);
+ emitcode ("subb", "a,#0x%02x",
+ 0x80 ^ (unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
+ }
+ else
+ {
+ emitcode ("mov", "b,%s", aopGet (AOP (right), offset++, FALSE, FALSE));
+ emitcode ("xrl", "b,#0x80");
+ emitcode ("subb", "a,b");
+ }
+ }
+ else
+ emitcode ("subb", "a,%s", aopGet (AOP (right), offset++, FALSE, FALSE));
+ }
+ }
}
release:
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- outBitC(result);
- } else {
- /* if the result is used in the next
- ifx conditional branch then generate
- code a little differently */
- if (ifx )
- genIfxJump (ifx,"c");
- else
- outBitC(result);
- /* leave the result in acc */
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ outBitC (result);
+ }
+ else
+ {
+ /* if the result is used in the next
+ ifx conditional branch then generate
+ code a little differently */
+ if (ifx)
+ genIfxJump (ifx, "c");
+ else
+ outBitC (result);
+ /* leave the result in acc */
}
}
/*-----------------------------------------------------------------*/
/* genCmpGt :- greater than comparison */
/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
+static void
+genCmpGt (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
+ operand *left, *right, *result;
+ sym_link *letype, *retype;
+ int sign;
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- genCmp(right, left, result, ifx, sign);
+ genCmp (right, left, result, ifx, sign);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCmpLt - less than comparisons */
/*-----------------------------------------------------------------*/
-static void genCmpLt (iCode *ic, iCode *ifx)
+static void
+genCmpLt (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
+ operand *left, *right, *result;
+ sym_link *letype, *retype;
+ int sign;
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- genCmp(left, right, result, ifx, sign);
+ genCmp (left, right, result, ifx, sign);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* gencjneshort - compare and jump if not equal */
/*-----------------------------------------------------------------*/
-static void gencjneshort(operand *left, operand *right, symbol *lbl)
-{
- int size = max(AOP_SIZE(left),AOP_SIZE(right));
- int offset = 0;
- unsigned long lit = 0L;
-
- /* if the left side is a literal or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(left) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *t = right;
- right = left;
- left = t;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- /* if the right side is a literal then anything goes */
- if (AOP_TYPE(right) == AOP_LIT &&
- AOP_TYPE(left) != AOP_DIR ) {
- while (size--) {
- emitcode("cjne","%s,%s,%05d$",
- aopGet(AOP(left),offset,FALSE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE),
- lbl->key+100);
- offset++;
- }
- }
-
- /* if the right side is in a register or in direct space or
- if the left is a pointer register & right is not */
- else if (AOP_TYPE(right) == AOP_REG ||
- AOP_TYPE(right) == AOP_DIR ||
- (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) ||
- (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) {
- while (size--) {
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
- if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
- ((unsigned int)((lit >> (offset*8)) & 0x0FFL) == 0))
- emitcode("jnz","%05d$",lbl->key+100);
- else
- emitcode("cjne","a,%s,%05d$",
- aopGet(AOP(right),offset,FALSE,TRUE),
- lbl->key+100);
- offset++;
- }
- } else {
- /* right is a pointer reg need both a & b */
- while(size--) {
- char *l = aopGet(AOP(left),offset,FALSE,FALSE);
- if(strcmp(l,"b"))
- emitcode("mov","b,%s",l);
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("cjne","a,b,%05d$",lbl->key+100);
- offset++;
- }
+static void
+gencjneshort (operand * left, operand * right, symbol * lbl)
+{
+ int size = max (AOP_SIZE (left), AOP_SIZE (right));
+ int offset = 0;
+ unsigned long lit = 0L;
+
+ /* if the left side is a literal or
+ if the right is in a pointer register and left
+ is not */
+ if ((AOP_TYPE (left) == AOP_LIT) ||
+ (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
+ {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ /* if the right side is a literal then anything goes */
+ if (AOP_TYPE (right) == AOP_LIT &&
+ AOP_TYPE (left) != AOP_DIR)
+ {
+ while (size--)
+ {
+ emitcode ("cjne", "%s,%s,%05d$",
+ aopGet (AOP (left), offset, FALSE, FALSE),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ lbl->key + 100);
+ offset++;
+ }
+ }
+
+ /* if the right side is in a register or in direct space or
+ if the left is a pointer register & right is not */
+ else if (AOP_TYPE (right) == AOP_REG ||
+ AOP_TYPE (right) == AOP_DIR ||
+ (AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) ||
+ (IS_AOP_PREG (left) && !IS_AOP_PREG (right)))
+ {
+ while (size--)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE));
+ if ((AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) &&
+ ((unsigned int) ((lit >> (offset * 8)) & 0x0FFL) == 0))
+ emitcode ("jnz", "%05d$", lbl->key + 100);
+ else
+ emitcode ("cjne", "a,%s,%05d$",
+ aopGet (AOP (right), offset, FALSE, TRUE),
+ lbl->key + 100);
+ offset++;
+ }
+ }
+ else
+ {
+ /* right is a pointer reg need both a & b */
+ while (size--)
+ {
+ char *l = aopGet (AOP (left), offset, FALSE, FALSE);
+ if (strcmp (l, "b"))
+ emitcode ("mov", "b,%s", l);
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("cjne", "a,b,%05d$", lbl->key + 100);
+ offset++;
+ }
}
}
/*-----------------------------------------------------------------*/
/* gencjne - compare and jump if not equal */
/*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, symbol *lbl)
+static void
+gencjne (operand * left, operand * right, symbol * lbl)
{
- symbol *tlbl = newiTempLabel(NULL);
+ symbol *tlbl = newiTempLabel (NULL);
- gencjneshort(left, right, lbl);
+ gencjneshort (left, right, lbl);
- emitcode("mov","a,%s",one);
- emitcode("sjmp","%05d$",tlbl->key+100);
- emitcode("","%05d$:",lbl->key+100);
- emitcode("clr","a");
- emitcode("","%05d$:",tlbl->key+100);
+ emitcode ("mov", "a,%s", one);
+ emitcode ("sjmp", "%05d$", tlbl->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ emitcode ("clr", "a");
+ emitcode ("", "%05d$:", tlbl->key + 100);
}
/*-----------------------------------------------------------------*/
/* genCmpEq - generates code for equal to */
/*-----------------------------------------------------------------*/
-static void genCmpEq (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
-
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
-
- /* if literal, literal on the right or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
- }
-
- if(ifx && !AOP_SIZE(result)){
- symbol *tlbl;
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- if(lit == 0L){
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- } else if(lit == 1L) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("jb","%s,%05d$",AOP(right)->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- }
- /* if true label then we jump if condition
- supplied is true */
- tlbl = newiTempLabel(NULL);
- if ( IC_TRUE(ifx) ) {
- emitcode("jnc","%05d$",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_TRUE(ifx)->key+100);
- } else {
- emitcode("jc","%05d$",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_FALSE(ifx)->key+100);
- }
- emitcode("","%05d$:",tlbl->key+100);
- } else {
- tlbl = newiTempLabel(NULL);
- gencjneshort(left, right, tlbl);
- if ( IC_TRUE(ifx) ) {
- emitcode("ljmp","%05d$",IC_TRUE(ifx)->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("sjmp","%05d$",lbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_FALSE(ifx)->key+100);
- emitcode("","%05d$:",lbl->key+100);
- }
- }
- /* mark the icode as generated */
- ifx->generated = 1;
- goto release ;
- }
-
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- if(lit == 0L){
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- } else if(lit == 1L) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("jb","%s,%05d$",AOP(right)->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(lbl->key+100));
- }
- /* c = 1 if egal */
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)){
- outBitC(result);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"c");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- outBitC(result);
- } else {
- gencjne(left,right,newiTempLabel(NULL));
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- aopPut(AOP(result),"a",0);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"a");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- if (AOP_TYPE(result) != AOP_CRY)
- outAcc(result);
- /* leave the result in acc */
+static void
+genCmpEq (iCode * ic, iCode * ifx)
+{
+ operand *left, *right, *result;
+
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
+
+ /* if literal, literal on the right or
+ if the right is in a pointer register and left
+ is not */
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT) ||
+ (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
+ }
+
+ if (ifx && !AOP_SIZE (result))
+ {
+ symbol *tlbl;
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ if (lit == 0L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ else if (lit == 1L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("clr", "c");
+ }
+ /* AOP_TYPE(right) == AOP_CRY */
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("jb", "%s,%05d$", AOP (right)->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ }
+ /* if true label then we jump if condition
+ supplied is true */
+ tlbl = newiTempLabel (NULL);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("jnc", "%05d$", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
+ }
+ else
+ {
+ emitcode ("jc", "%05d$", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100);
+ }
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ gencjneshort (left, right, tlbl);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("sjmp", "%05d$", lbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ }
+ }
+ /* mark the icode as generated */
+ ifx->generated = 1;
+ goto release;
+ }
+
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ if (lit == 0L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ else if (lit == 1L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("clr", "c");
+ }
+ /* AOP_TYPE(right) == AOP_CRY */
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("jb", "%s,%05d$", AOP (right)->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (lbl->key + 100));
+ }
+ /* c = 1 if egal */
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ outBitC (result);
+ goto release;
+ }
+ if (ifx)
+ {
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+ /* if the result is used in an arithmetic operation
+ then put the result in place */
+ outBitC (result);
+ }
+ else
+ {
+ gencjne (left, right, newiTempLabel (NULL));
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+ if (ifx)
+ {
+ genIfxJump (ifx, "a");
+ goto release;
+ }
+ /* if the result is used in an arithmetic operation
+ then put the result in place */
+ if (AOP_TYPE (result) != AOP_CRY)
+ outAcc (result);
+ /* leave the result in acc */
}
release:
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* ifxForOp - returns the icode containing the ifx for operand */
/*-----------------------------------------------------------------*/
-static iCode *ifxForOp ( operand *op, iCode *ic )
+static iCode *
+ifxForOp (operand * op, iCode * ic)
{
- /* if true symbol then needs to be assigned */
- if (IS_TRUE_SYMOP(op))
- return NULL ;
+ /* if true symbol then needs to be assigned */
+ if (IS_TRUE_SYMOP (op))
+ return NULL;
- /* if this has register type condition and
- the next instruction is ifx with the same operand
- and live to of the operand is upto the ifx only then */
- if (ic->next &&
- ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key &&
- OP_SYMBOL(op)->liveTo <= ic->next->seq )
- return ic->next;
+ /* if this has register type condition and
+ the next instruction is ifx with the same operand
+ and live to of the operand is upto the ifx only then */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ IC_COND (ic->next)->key == op->key &&
+ OP_SYMBOL (op)->liveTo <= ic->next->seq)
+ return ic->next;
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* genAndOp - for && operation */
/*-----------------------------------------------------------------*/
-static void genAndOp (iCode *ic)
+static void
+genAndOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
+ operand *left, *right, *result;
+ symbol *tlbl;
- /* note here that && operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE);
+ /* note here that && operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE);
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emitcode("jz","%05d$",tlbl->key+100);
- toBoolean(right);
- emitcode("","%05d$:",tlbl->key+100);
- outBitAcc(result);
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emitcode ("jz", "%05d$", tlbl->key + 100);
+ toBoolean (right);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitAcc (result);
}
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genOrOp - for || operation */
/*-----------------------------------------------------------------*/
-static void genOrOp (iCode *ic)
+static void
+genOrOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
+ operand *left, *right, *result;
+ symbol *tlbl;
- /* note here that || operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE);
+ /* note here that || operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE);
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("orl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emitcode("jnz","%05d$",tlbl->key+100);
- toBoolean(right);
- emitcode("","%05d$:",tlbl->key+100);
- outBitAcc(result);
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("orl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ toBoolean (right);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitAcc (result);
}
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ 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;
+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;
}
/*-----------------------------------------------------------------*/
/* continueIfTrue - */
/*-----------------------------------------------------------------*/
-static void continueIfTrue (iCode *ic)
+static void
+continueIfTrue (iCode * ic)
{
- if(IC_TRUE(ic))
- emitcode("ljmp","%05d$",IC_TRUE(ic)->key+100);
- ic->generated = 1;
+ if (IC_TRUE (ic))
+ emitcode ("ljmp", "%05d$", IC_TRUE (ic)->key + 100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* jmpIfTrue - */
/*-----------------------------------------------------------------*/
-static void jumpIfTrue (iCode *ic)
+static void
+jumpIfTrue (iCode * ic)
{
- if(!IC_TRUE(ic))
- emitcode("ljmp","%05d$",IC_FALSE(ic)->key+100);
- ic->generated = 1;
+ if (!IC_TRUE (ic))
+ emitcode ("ljmp", "%05d$", IC_FALSE (ic)->key + 100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* jmpTrueOrFalse - */
/*-----------------------------------------------------------------*/
-static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
+static void
+jmpTrueOrFalse (iCode * ic, symbol * tlbl)
{
- // ugly but optimized by peephole
- if(IC_TRUE(ic)){
- symbol *nlbl = newiTempLabel(NULL);
- emitcode("sjmp","%05d$",nlbl->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("ljmp","%05d$",IC_TRUE(ic)->key+100);
- emitcode("","%05d$:",nlbl->key+100);
+ // ugly but optimized by peephole
+ if (IC_TRUE (ic))
+ {
+ symbol *nlbl = newiTempLabel (NULL);
+ emitcode ("sjmp", "%05d$", nlbl->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_TRUE (ic)->key + 100);
+ emitcode ("", "%05d$:", nlbl->key + 100);
}
- else{
- emitcode("ljmp","%05d$",IC_FALSE(ic)->key+100);
- emitcode("","%05d$:",tlbl->key+100);
+ else
+ {
+ emitcode ("ljmp", "%05d$", IC_FALSE (ic)->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
}
- ic->generated = 1;
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAnd - code for and */
/*-----------------------------------------------------------------*/
-static void genAnd (iCode *ic, iCode *ifx)
+static void
+genAnd (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
- int bytelit = 0;
- char buffer[10];
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+ int bytelit = 0;
+ char buffer[10];
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit & yy)
- // result = bit & yy;
- if (AOP_TYPE(left) == AOP_CRY){
- // c = bit & literal;
- if(AOP_TYPE(right) == AOP_LIT){
- if(lit & 1) {
- if(size && sameRegs(AOP(result),AOP(left)))
- // no change
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // bit(result) = 0;
- if(size && (AOP_TYPE(result) == AOP_CRY)){
- emitcode("clr","%s",AOP(result)->aopu.aop_dir);
- goto release;
- }
- if((AOP_TYPE(result) == AOP_CRY) && ifx){
- jumpIfTrue(ifx);
- goto release;
- }
- emitcode("clr","c");
- }
- } else {
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit & bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // c = bit & val;
- MOVA(aopGet(AOP(right),0,FALSE,FALSE));
- // c = lsb
- emitcode("rrc","a");
- emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- }
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit & ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- // if(val & 0xZZ) - size = 0, ifx != FALSE -
- // bit = val & 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- int posbit = isLiteralBit(lit);
- /* left & 2^n */
- if(posbit){
- posbit--;
- MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE));
- // bit = left & 2^n
- if(size)
- emitcode("mov","c,acc.%d",posbit&0x07);
- // if(left & 2^n)
- else{
- if(ifx){
- sprintf(buffer,"acc.%d",posbit&0x07);
- genIfxJump(ifx, buffer);
- }
- goto release;
- }
- } else {
- symbol *tlbl = newiTempLabel(NULL);
- int sizel = AOP_SIZE(left);
- if(size)
- emitcode("setb","c");
- while(sizel--){
- if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
- MOVA( aopGet(AOP(left),offset,FALSE,FALSE));
- // byte == 2^n ?
- if((posbit = isLiteralBit(bytelit)) != 0)
- emitcode("jb","acc.%d,%05d$",(posbit-1)&0x07,tlbl->key+100);
- else{
- if(bytelit != 0x0FFL)
- emitcode("anl","a,%s",
- aopGet(AOP(right),offset,FALSE,TRUE));
- emitcode("jnz","%05d$",tlbl->key+100);
- }
- }
- offset++;
- }
- // bit = left & literal
- if(size){
- emitcode("clr","c");
- emitcode("","%05d$:",tlbl->key+100);
- }
- // if(left & literal)
- else{
- if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- goto release ;
- }
- }
- outBitC(result);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if((bytelit = (int)((lit >> (offset*8)) & 0x0FFL)) == 0x0FF)
- continue;
- else
- if (bytelit == 0)
- aopPut(AOP(result),zero,offset);
- else
- if (IS_AOP_PREG(result)) {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("anl","%s,%s",
- aopGet(AOP(left),offset,FALSE,TRUE),
- aopGet(AOP(right),offset,FALSE,FALSE));
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("anl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- if (IS_AOP_PREG(result)) {
- emitcode("anl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
-
- } else
- emitcode("anl","%s,a",
- aopGet(AOP(left),offset,FALSE,TRUE));
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left & right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = min(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("anl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("jnz","%05d$",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else {
- for(;(size--);offset++) {
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- if((bytelit = (int)((lit >> (offset*8)) & 0x0FFL)) == 0x0FF){
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE,FALSE),
- offset);
- continue;
- } else if(bytelit == 0){
- aopPut(AOP(result),zero,offset);
- continue;
- }
- }
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("anl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("anl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- }
- aopPut(AOP(result),"a",offset);
- }
- }
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
-}
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
-/*-----------------------------------------------------------------*/
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit & yy)
+ // result = bit & yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ // c = bit & literal;
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (lit & 1)
+ {
+ if (size && sameRegs (AOP (result), AOP (left)))
+ // no change
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // bit(result) = 0;
+ if (size && (AOP_TYPE (result) == AOP_CRY))
+ {
+ emitcode ("clr", "%s", AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+ if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ {
+ jumpIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("clr", "c");
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit & bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // c = bit & val;
+ MOVA (aopGet (AOP (right), 0, FALSE, FALSE));
+ // c = lsb
+ emitcode ("rrc", "a");
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit & ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+
+ // if(val & 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val & 0xZZ - size = 1, ifx = FALSE -
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ int posbit = isLiteralBit (lit);
+ /* left & 2^n */
+ if (posbit)
+ {
+ posbit--;
+ MOVA (aopGet (AOP (left), posbit >> 3, FALSE, FALSE));
+ // bit = left & 2^n
+ if (size)
+ emitcode ("mov", "c,acc.%d", posbit & 0x07);
+ // if(left & 2^n)
+ else
+ {
+ if (ifx)
+ {
+ sprintf (buffer, "acc.%d", posbit & 0x07);
+ genIfxJump (ifx, buffer);
+ }
+ goto release;
+ }
+ }
+ else
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizel = AOP_SIZE (left);
+ if (size)
+ emitcode ("setb", "c");
+ while (sizel--)
+ {
+ if ((bytelit = ((lit >> (offset * 8)) & 0x0FFL)) != 0x0L)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE));
+ // byte == 2^n ?
+ if ((posbit = isLiteralBit (bytelit)) != 0)
+ emitcode ("jb", "acc.%d,%05d$", (posbit - 1) & 0x07, tlbl->key + 100);
+ else
+ {
+ if (bytelit != 0x0FFL)
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (right), offset, FALSE, TRUE));
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ }
+ }
+ offset++;
+ }
+ // bit = left & literal
+ if (size)
+ {
+ emitcode ("clr", "c");
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ // if(left & literal)
+ else
+ {
+ if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ goto release;
+ }
+ }
+ outBitC (result);
+ goto release;
+ }
+
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if ((bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL)) == 0x0FF)
+ continue;
+ else if (bytelit == 0)
+ aopPut (AOP (result), zero, offset);
+ else if (IS_AOP_PREG (result))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("anl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("anl", "%s,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE),
+ aopGet (AOP (right), offset, FALSE, FALSE));
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ if (IS_AOP_PREG (result))
+ {
+ emitcode ("anl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+
+ }
+ else
+ emitcode ("anl", "%s,a",
+ aopGet (AOP (left), offset, FALSE, TRUE));
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left & right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = min (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ {
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if ((bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL)) == 0x0FF)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE, FALSE),
+ offset);
+ continue;
+ }
+ else if (bytelit == 0)
+ {
+ aopPut (AOP (result), zero, offset);
+ continue;
+ }
+ }
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ aopPut (AOP (result), "a", offset);
+ }
+ }
+ }
+
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
+}
+
+/*-----------------------------------------------------------------*/
/* genOr - code for or */
/*-----------------------------------------------------------------*/
-static void genOr (iCode *ic, iCode *ifx)
+static void
+genOr (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit | yy)
- // xx = bit | yy;
- if (AOP_TYPE(left) == AOP_CRY){
- if(AOP_TYPE(right) == AOP_LIT){
- // c = bit & literal;
- if(lit){
- // lit != 0 => result = 1
- if(AOP_TYPE(result) == AOP_CRY){
- if(size)
- emitcode("setb","%s",AOP(result)->aopu.aop_dir);
- else if(ifx)
- continueIfTrue(ifx);
- goto release;
- }
- emitcode("setb","c");
- } else {
- // lit == 0 => result = left
- if(size && sameRegs(AOP(result),AOP(left)))
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- }
- } else {
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit | bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("orl","c,%s",AOP(left)->aopu.aop_dir);
- }
- else{
- // c = bit | val;
- symbol *tlbl = newiTempLabel(NULL);
- if(!((AOP_TYPE(result) == AOP_CRY) && ifx))
- emitcode("setb","c");
- emitcode("jb","%s,%05d$",
- AOP(left)->aopu.aop_dir,tlbl->key+100);
- toBoolean(right);
- emitcode("jnz","%05d$",tlbl->key+100);
- if((AOP_TYPE(result) == AOP_CRY) && ifx){
- jmpTrueOrFalse(ifx, tlbl);
- goto release;
- } else {
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- }
- }
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit | ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- // if(val | 0xZZ) - size = 0, ifx != FALSE -
- // bit = val | 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- if(lit){
- // result = 1
- if(size)
- emitcode("setb","%s",AOP(result)->aopu.aop_dir);
- else
- continueIfTrue(ifx);
- goto release;
- } else {
- // lit = 0, result = boolean(left)
- if(size)
- emitcode("setb","c");
- toBoolean(right);
- if(size){
- symbol *tlbl = newiTempLabel(NULL);
- emitcode("jnz","%05d$",tlbl->key+100);
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- } else {
- genIfxJump (ifx,"a");
- goto release;
- }
- }
- outBitC(result);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- continue;
- else
- if (IS_AOP_PREG(left)) {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("orl","%s,%s",
- aopGet(AOP(left),offset,FALSE,TRUE),
- aopGet(AOP(right),offset,FALSE,FALSE));
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("orl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- if (IS_AOP_PREG(left)) {
- emitcode("orl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("orl","%s,a",
- aopGet(AOP(left),offset,FALSE,TRUE));
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left | right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("orl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("jnz","%05d$",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else for(;(size--);offset++){
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L){
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE,FALSE),
- offset);
- continue;
- }
- }
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("orl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("orl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- }
- aopPut(AOP(result),"a",offset);
- }
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit | yy)
+ // xx = bit | yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ // c = bit & literal;
+ if (lit)
+ {
+ // lit != 0 => result = 1
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ if (size)
+ emitcode ("setb", "%s", AOP (result)->aopu.aop_dir);
+ else if (ifx)
+ continueIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("setb", "c");
+ }
+ else
+ {
+ // lit == 0 => result = left
+ if (size && sameRegs (AOP (result), AOP (left)))
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit | bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // c = bit | val;
+ symbol *tlbl = newiTempLabel (NULL);
+ if (!((AOP_TYPE (result) == AOP_CRY) && ifx))
+ emitcode ("setb", "c");
+ emitcode ("jb", "%s,%05d$",
+ AOP (left)->aopu.aop_dir, tlbl->key + 100);
+ toBoolean (right);
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ {
+ jmpTrueOrFalse (ifx, tlbl);
+ goto release;
+ }
+ else
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ }
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit | ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+
+ // if(val | 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val | 0xZZ - size = 1, ifx = FALSE -
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ if (lit)
+ {
+ // result = 1
+ if (size)
+ emitcode ("setb", "%s", AOP (result)->aopu.aop_dir);
+ else
+ continueIfTrue (ifx);
+ goto release;
+ }
+ else
+ {
+ // lit = 0, result = boolean(left)
+ if (size)
+ emitcode ("setb", "c");
+ toBoolean (right);
+ if (size)
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
+ else
+ {
+ genIfxJump (ifx, "a");
+ goto release;
+ }
+ }
+ outBitC (result);
+ goto release;
+ }
+
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ continue;
+ else if (IS_AOP_PREG (left))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("orl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("orl", "%s,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE),
+ aopGet (AOP (right), offset, FALSE, FALSE));
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ if (IS_AOP_PREG (left))
+ {
+ emitcode ("orl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("orl", "%s,a",
+ aopGet (AOP (left), offset, FALSE, TRUE));
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left | right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = max (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("orl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE, FALSE),
+ offset);
+ continue;
+ }
+ }
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("orl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ aopPut (AOP (result), "a", offset);
+ }
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genXor - code for xclusive or */
/*-----------------------------------------------------------------*/
-static void genXor (iCode *ic, iCode *ifx)
+static void
+genXor (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not ||
- if left needs acc & right does not */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- (AOP_NEEDSACC(left) && !AOP_NEEDSACC(right))) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit ^ yy)
- // xx = bit ^ yy;
- if (AOP_TYPE(left) == AOP_CRY){
- if(AOP_TYPE(right) == AOP_LIT){
- // c = bit & literal;
- if(lit>>1){
- // lit>>1 != 0 => result = 1
- if(AOP_TYPE(result) == AOP_CRY){
- if(size)
- emitcode("setb","%s",AOP(result)->aopu.aop_dir);
- else if(ifx)
- continueIfTrue(ifx);
- goto release;
- }
- emitcode("setb","c");
- } else{
- // lit == (0 or 1)
- if(lit == 0){
- // lit == 0, result = left
- if(size && sameRegs(AOP(result),AOP(left)))
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else{
- // lit == 1, result = not(left)
- if(size && sameRegs(AOP(result),AOP(left))){
- emitcode("cpl","%s",AOP(result)->aopu.aop_dir);
- goto release;
- } else {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- }
- }
- }
-
- } else {
- // right != literal
- symbol *tlbl = newiTempLabel(NULL);
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit ^ bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- }
- else{
- int sizer = AOP_SIZE(right);
- // c = bit ^ val
- // if val>>1 != 0, result = 1
- emitcode("setb","c");
- while(sizer){
- MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE));
- if(sizer == 1)
- // test the msb of the lsb
- emitcode("anl","a,#0xfe");
- emitcode("jnz","%05d$",tlbl->key+100);
- sizer--;
- }
- // val = (0,1)
- emitcode("rrc","a");
- }
- emitcode("jnb","%s,%05d$",AOP(left)->aopu.aop_dir,(tlbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d$:",(tlbl->key+100));
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit | ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- if(sameRegs(AOP(result),AOP(left))){
- /* if left is same as result */
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- continue;
- else
- if (IS_AOP_PREG(left)) {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("xrl","%s,%s",
- aopGet(AOP(left),offset,FALSE,TRUE),
- aopGet(AOP(right),offset,FALSE,FALSE));
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- if (IS_AOP_PREG(left)) {
- emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("xrl","%s,a",
- aopGet(AOP(left),offset,FALSE,TRUE));
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left ^ right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- if((AOP_TYPE(right) == AOP_LIT) &&
- (((lit >> (offset*8)) & 0x0FFL) == 0x00L)){
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
- } else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("xrl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- }
- emitcode("jnz","%05d$",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d$:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else for(;(size--);offset++){
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L){
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE,FALSE),
- offset);
- continue;
- }
- }
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("xrl","a,%s",
- aopGet(AOP(left),offset,FALSE,TRUE));
- }
- aopPut(AOP(result),"a",offset);
- }
+ /* if left is a literal & right is not ||
+ if left needs acc & right does not */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ (AOP_NEEDSACC (left) && !AOP_NEEDSACC (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit ^ yy)
+ // xx = bit ^ yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ // c = bit & literal;
+ if (lit >> 1)
+ {
+ // lit>>1 != 0 => result = 1
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ if (size)
+ emitcode ("setb", "%s", AOP (result)->aopu.aop_dir);
+ else if (ifx)
+ continueIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("setb", "c");
+ }
+ else
+ {
+ // lit == (0 or 1)
+ if (lit == 0)
+ {
+ // lit == 0, result = left
+ if (size && sameRegs (AOP (result), AOP (left)))
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // lit == 1, result = not(left)
+ if (size && sameRegs (AOP (result), AOP (left)))
+ {
+ emitcode ("cpl", "%s", AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ }
+ }
+
+ }
+ else
+ {
+ // right != literal
+ symbol *tlbl = newiTempLabel (NULL);
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit ^ bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ }
+ else
+ {
+ int sizer = AOP_SIZE (right);
+ // c = bit ^ val
+ // if val>>1 != 0, result = 1
+ emitcode ("setb", "c");
+ while (sizer)
+ {
+ MOVA (aopGet (AOP (right), sizer - 1, FALSE, FALSE));
+ if (sizer == 1)
+ // test the msb of the lsb
+ emitcode ("anl", "a,#0xfe");
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ sizer--;
+ }
+ // val = (0,1)
+ emitcode ("rrc", "a");
+ }
+ emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d$:", (tlbl->key + 100));
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit | ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ /* if left is same as result */
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ continue;
+ else if (IS_AOP_PREG (left))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("xrl", "%s,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE),
+ aopGet (AOP (right), offset, FALSE, FALSE));
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ if (IS_AOP_PREG (left))
+ {
+ emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("xrl", "%s,a",
+ aopGet (AOP (left), offset, FALSE, TRUE));
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left ^ right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = max (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (((lit >> (offset * 8)) & 0x0FFL) == 0x00L))
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("xrl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ emitcode ("jnz", "%05d$", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE, FALSE),
+ offset);
+ continue;
+ }
+ }
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("xrl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE));
+ }
+ aopPut (AOP (result), "a", offset);
+ }
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genInline - write the inline code out */
/*-----------------------------------------------------------------*/
-static void genInline (iCode *ic)
+static void
+genInline (iCode * ic)
{
- char buffer[MAX_INLINEASM];
- char *bp = buffer;
- char *bp1= buffer;
+ char buffer[MAX_INLINEASM];
+ char *bp = buffer;
+ char *bp1 = buffer;
- _G.inLine += (!options.asmpeep);
- strcpy(buffer,IC_INLINE(ic));
+ _G.inLine += (!options.asmpeep);
+ strcpy (buffer, IC_INLINE (ic));
- /* emit each line as a code */
- while (*bp) {
- if (*bp == '\n') {
- *bp++ = '\0';
- emitcode(bp1,"");
- bp1 = bp;
- } else {
- if (*bp == ':') {
- bp++;
- *bp = '\0';
- bp++;
- emitcode(bp1,"");
- bp1 = bp;
- } else
- bp++;
- }
- }
- if (bp1 != bp)
- emitcode(bp1,"");
- /* emitcode("",buffer); */
- _G.inLine -= (!options.asmpeep);
+ /* emit each line as a code */
+ while (*bp)
+ {
+ if (*bp == '\n')
+ {
+ *bp++ = '\0';
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ {
+ if (*bp == ':')
+ {
+ bp++;
+ *bp = '\0';
+ bp++;
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ bp++;
+ }
+ }
+ if (bp1 != bp)
+ emitcode (bp1, "");
+ /* emitcode("",buffer); */
+ _G.inLine -= (!options.asmpeep);
}
/*-----------------------------------------------------------------*/
/* genRRC - rotate right with carry */
/*-----------------------------------------------------------------*/
-static void genRRC (iCode *ic)
+static void
+genRRC (iCode * ic)
{
- operand *left , *result ;
- int size, offset = 0;
- char *l;
+ operand *left, *result;
+ int size, offset = 0;
+ char *l;
- /* rotate right with carry */
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
+ /* rotate right with carry */
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
- /* move it to the result */
- size = AOP_SIZE(result);
- offset = size - 1 ;
- CLRC;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rrc","a");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset--);
- }
- /* now we need to put the carry into the
- highest order byte of the result */
- if (AOP_SIZE(result) > 1) {
- l = aopGet(AOP(result),AOP_SIZE(result)-1,FALSE,FALSE);
- MOVA(l);
+ /* move it to the result */
+ size = AOP_SIZE (result);
+ offset = size - 1;
+ CLRC;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset--);
+ }
+ /* now we need to put the carry into the
+ highest order byte of the result */
+ if (AOP_SIZE (result) > 1)
+ {
+ l = aopGet (AOP (result), AOP_SIZE (result) - 1, FALSE, FALSE);
+ MOVA (l);
}
- emitcode("mov","acc.7,c");
- aopPut(AOP(result),"a",AOP_SIZE(result)-1);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ emitcode ("mov", "acc.7,c");
+ aopPut (AOP (result), "a", AOP_SIZE (result) - 1);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRLC - generate code for rotate left with carry */
/*-----------------------------------------------------------------*/
-static void genRLC (iCode *ic)
-{
- operand *left , *result ;
- int size, offset = 0;
- char *l;
-
- /* rotate right with carry */
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
-
- /* move it to the result */
- size = AOP_SIZE(result);
- offset = 0 ;
- if (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("add","a,acc");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset++);
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rlc","a");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset++);
- }
- }
- /* now we need to put the carry into the
- highest order byte of the result */
- if (AOP_SIZE(result) > 1) {
- l = aopGet(AOP(result),0,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("mov","acc.0,c");
- aopPut(AOP(result),"a",0);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+static void
+genRLC (iCode * ic)
+{
+ operand *left, *result;
+ int size, offset = 0;
+ char *l;
+
+ /* rotate right with carry */
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* move it to the result */
+ size = AOP_SIZE (result);
+ offset = 0;
+ if (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset++);
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset++);
+ }
+ }
+ /* now we need to put the carry into the
+ highest order byte of the result */
+ if (AOP_SIZE (result) > 1)
+ {
+ l = aopGet (AOP (result), 0, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("mov", "acc.0,c");
+ aopPut (AOP (result), "a", 0);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGetHbit - generates code get highest order bit */
/*-----------------------------------------------------------------*/
-static void genGetHbit (iCode *ic)
+static void
+genGetHbit (iCode * ic)
{
- operand *left, *result;
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
+ operand *left, *result;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
- /* get the highest order byte into a */
- MOVA(aopGet(AOP(left),AOP_SIZE(left) - 1,FALSE,FALSE));
- if(AOP_TYPE(result) == AOP_CRY){
- emitcode("rlc","a");
- outBitC(result);
+ /* get the highest order byte into a */
+ MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE));
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ emitcode ("rlc", "a");
+ outBitC (result);
}
- else{
- emitcode("rl","a");
- emitcode("anl","a,#0x01");
- outAcc(result);
+ else
+ {
+ emitcode ("rl", "a");
+ emitcode ("anl", "a,#0x01");
+ outAcc (result);
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* AccRol - rotate left accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRol (int shCount)
-{
- shCount &= 0x0007; // shCount : 0..7
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("rl","a");
- break;
- case 2 :
- emitcode("rl","a");
- emitcode("rl","a");
- break;
- case 3 :
- emitcode("swap","a");
- emitcode("rr","a");
- break;
- case 4 :
- emitcode("swap","a");
- break;
- case 5 :
- emitcode("swap","a");
- emitcode("rl","a");
- break;
- case 6 :
- emitcode("rr","a");
- emitcode("rr","a");
- break;
- case 7 :
- emitcode("rr","a");
- break;
+static void
+AccRol (int shCount)
+{
+ shCount &= 0x0007; // shCount : 0..7
+
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("rl", "a");
+ break;
+ case 2:
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ break;
+ case 3:
+ emitcode ("swap", "a");
+ emitcode ("rr", "a");
+ break;
+ case 4:
+ emitcode ("swap", "a");
+ break;
+ case 5:
+ emitcode ("swap", "a");
+ emitcode ("rl", "a");
+ break;
+ case 6:
+ emitcode ("rr", "a");
+ emitcode ("rr", "a");
+ break;
+ case 7:
+ emitcode ("rr", "a");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* AccLsh - left shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccLsh (int shCount)
+static void
+AccLsh (int shCount)
{
- if(shCount != 0){
- if(shCount == 1)
- emitcode("add","a,acc");
- else
- if(shCount == 2) {
- emitcode("add","a,acc");
- emitcode("add","a,acc");
- } else {
- /* rotate left accumulator */
- AccRol(shCount);
- /* and kill the lower order bits */
- emitcode("anl","a,#0x%02x", SLMask[shCount]);
- }
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ emitcode ("add", "a,acc");
+ else if (shCount == 2)
+ {
+ emitcode ("add", "a,acc");
+ emitcode ("add", "a,acc");
+ }
+ else
+ {
+ /* rotate left accumulator */
+ AccRol (shCount);
+ /* and kill the lower order bits */
+ emitcode ("anl", "a,#0x%02x", SLMask[shCount]);
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccRsh - right shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRsh (int shCount)
+static void
+AccRsh (int shCount)
{
- if(shCount != 0){
- if(shCount == 1){
- CLRC;
- emitcode("rrc","a");
- } else {
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- emitcode("anl","a,#0x%02x", SRMask[shCount]);
- }
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ {
+ CLRC;
+ emitcode ("rrc", "a");
+ }
+ else
+ {
+ /* rotate right accumulator */
+ AccRol (8 - shCount);
+ /* and kill the higher order bits */
+ emitcode ("anl", "a,#0x%02x", SRMask[shCount]);
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccSRsh - signed right shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccSRsh (int shCount)
-{
- symbol *tlbl ;
- if(shCount != 0){
- if(shCount == 1){
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- } else if(shCount == 2){
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- } else {
- tlbl = newiTempLabel(NULL);
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- emitcode("anl","a,#0x%02x", SRMask[shCount]);
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]);
- emitcode("","%05d$:",tlbl->key+100);
- }
+static void
+AccSRsh (int shCount)
+{
+ symbol *tlbl;
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ {
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ }
+ else if (shCount == 2)
+ {
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ /* rotate right accumulator */
+ AccRol (8 - shCount);
+ /* and kill the higher order bits */
+ emitcode ("anl", "a,#0x%02x", SRMask[shCount]);
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ }
}
}
/*-----------------------------------------------------------------*/
/* shiftR1Left2Result - shift right one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR1Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
+static void
+shiftR1Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
{
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- /* shift right accumulator */
- if(sign)
- AccSRsh(shCount);
- else
- AccRsh(shCount);
- aopPut(AOP(result),"a",offr);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ /* shift right accumulator */
+ if (sign)
+ AccSRsh (shCount);
+ else
+ AccRsh (shCount);
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* shiftL1Left2Result - shift left one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftL1Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftL1Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- char *l;
- l = aopGet(AOP(left),offl,FALSE,FALSE);
- MOVA(l);
- /* shift left accumulator */
- AccLsh(shCount);
- aopPut(AOP(result),"a",offr);
+ char *l;
+ l = aopGet (AOP (left), offl, FALSE, FALSE);
+ MOVA (l);
+ /* shift left accumulator */
+ AccLsh (shCount);
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* movLeft2Result - move byte from left to result */
/*-----------------------------------------------------------------*/
-static void movLeft2Result (operand *left, int offl,
- operand *result, int offr, int sign)
+static void
+movLeft2Result (operand * left, int offl,
+ operand * result, int offr, int sign)
{
- char *l;
- if(!sameRegs(AOP(left),AOP(result)) || (offl != offr)){
- l = aopGet(AOP(left),offl,FALSE,FALSE);
+ char *l;
+ if (!sameRegs (AOP (left), AOP (result)) || (offl != offr))
+ {
+ l = aopGet (AOP (left), offl, FALSE, FALSE);
- if (*l == '@' && (IS_AOP_PREG(result))) {
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- } else {
- if(!sign)
- aopPut(AOP(result),l,offr);
- else{
- /* MSB sign in acc.7 ! */
- if(getDataSize(left) == offl+1){
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- }
- }
- }
+ if (*l == '@' && (IS_AOP_PREG (result)))
+ {
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offr);
+ }
+ else
+ {
+ if (!sign)
+ aopPut (AOP (result), l, offr);
+ else
+ {
+ /* MSB sign in acc.7 ! */
+ if (getDataSize (left) == offl + 1)
+ {
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offr);
+ }
+ }
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccAXRrl1 - right rotate c->a:x->c by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXRrl1 (char *x)
+static void
+AccAXRrl1 (char *x)
{
- emitcode("rrc","a");
- emitcode("xch","a,%s", x);
- emitcode("rrc","a");
- emitcode("xch","a,%s", x);
+ emitcode ("rrc", "a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rrc", "a");
+ emitcode ("xch", "a,%s", x);
}
/*-----------------------------------------------------------------*/
/* AccAXLrl1 - left rotate c<-a:x<-c by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXLrl1 (char *x)
+static void
+AccAXLrl1 (char *x)
{
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
}
/*-----------------------------------------------------------------*/
/* AccAXLsh1 - left shift a:x<-0 by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXLsh1 (char *x)
+static void
+AccAXLsh1 (char *x)
{
- emitcode("xch","a,%s",x);
- emitcode("add","a,acc");
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("add", "a,acc");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
}
/*-----------------------------------------------------------------*/
/* AccAXLsh - left shift a:x by known count (0..7) */
/*-----------------------------------------------------------------*/
-static void AccAXLsh (char *x, int shCount)
-{
- switch(shCount){
- case 0 :
- break;
- case 1 :
- AccAXLsh1(x);
- break;
- case 2 :
- AccAXLsh1(x);
- AccAXLsh1(x);
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD
- AccRol(shCount); // BBBAAAAA:CCCCCDDD
- emitcode("anl","a,#0x%02x",
- SLMask[shCount]); // BBB00000:CCCCCDDD
- emitcode("xch","a,%s",x); // CCCCCDDD:BBB00000
- AccRol(shCount); // DDDCCCCC:BBB00000
- emitcode("xch","a,%s",x); // BBB00000:DDDCCCCC
- emitcode("xrl","a,%s",x); // (BBB^DDD)CCCCC:DDDCCCCC
- emitcode("xch","a,%s",x); // DDDCCCCC:(BBB^DDD)CCCCC
- emitcode("anl","a,#0x%02x",
- SLMask[shCount]); // DDD00000:(BBB^DDD)CCCCC
- emitcode("xch","a,%s",x); // (BBB^DDD)CCCCC:DDD00000
- emitcode("xrl","a,%s",x); // BBBCCCCC:DDD00000
- break;
- case 6 : // AAAAAABB:CCCCCCDD
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000BB:CCCCCCDD
- emitcode("mov","c,acc.0"); // c = B
- emitcode("xch","a,%s",x); // CCCCCCDD:000000BB
- AccAXRrl1(x); // BCCCCCCD:D000000B
- AccAXRrl1(x); // BBCCCCCC:DD000000
- break;
- case 7 : // a:x <<= 7
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000B:CCCCCCCD
- emitcode("mov","c,acc.0"); // c = B
- emitcode("xch","a,%s",x); // CCCCCCCD:0000000B
- AccAXRrl1(x); // BCCCCCCC:D0000000
- break;
- default :
- break;
+static void
+AccAXLsh (char *x, int shCount)
+{
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ AccAXLsh1 (x);
+ break;
+ case 2:
+ AccAXLsh1 (x);
+ AccAXLsh1 (x);
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD
+
+ AccRol (shCount); // BBBAAAAA:CCCCCDDD
+
+ emitcode ("anl", "a,#0x%02x",
+ SLMask[shCount]); // BBB00000:CCCCCDDD
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBB00000
+
+ AccRol (shCount); // DDDCCCCC:BBB00000
+
+ emitcode ("xch", "a,%s", x); // BBB00000:DDDCCCCC
+
+ emitcode ("xrl", "a,%s", x); // (BBB^DDD)CCCCC:DDDCCCCC
+
+ emitcode ("xch", "a,%s", x); // DDDCCCCC:(BBB^DDD)CCCCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SLMask[shCount]); // DDD00000:(BBB^DDD)CCCCC
+
+ emitcode ("xch", "a,%s", x); // (BBB^DDD)CCCCC:DDD00000
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:DDD00000
+
+ break;
+ case 6: // AAAAAABB:CCCCCCDD
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000BB:CCCCCCDD
+
+ emitcode ("mov", "c,acc.0"); // c = B
+
+ emitcode ("xch", "a,%s", x); // CCCCCCDD:000000BB
+
+ AccAXRrl1 (x); // BCCCCCCD:D000000B
+
+ AccAXRrl1 (x); // BBCCCCCC:DD000000
+
+ break;
+ case 7: // a:x <<= 7
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000B:CCCCCCCD
+
+ emitcode ("mov", "c,acc.0"); // c = B
+
+ emitcode ("xch", "a,%s", x); // CCCCCCCD:0000000B
+
+ AccAXRrl1 (x); // BCCCCCCC:D0000000
+
+ break;
+ default:
+ break;
}
}
/*-----------------------------------------------------------------*/
/* AccAXRsh - right shift a:x known count (0..7) */
/*-----------------------------------------------------------------*/
-static void AccAXRsh (char *x, int shCount)
-{
- switch(shCount){
- case 0 :
- break;
- case 1 :
- CLRC;
- AccAXRrl1(x); // 0->a:x
- break;
- case 2 :
- CLRC;
- AccAXRrl1(x); // 0->a:x
- CLRC;
- AccAXRrl1(x); // 0->a:x
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD = a:x
- AccRol(8 - shCount); // BBBAAAAA:DDDCCCCC
- emitcode("xch","a,%s",x); // CCCCCDDD:BBBAAAAA
- AccRol(8 - shCount); // DDDCCCCC:BBBAAAAA
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000CCCCC:BBBAAAAA
- emitcode("xrl","a,%s",x); // BBB(CCCCC^AAAAA):BBBAAAAA
- emitcode("xch","a,%s",x); // BBBAAAAA:BBB(CCCCC^AAAAA)
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
- emitcode("xch","a,%s",x); // BBB(CCCCC^AAAAA):000AAAAA
- emitcode("xrl","a,%s",x); // BBBCCCCC:000AAAAA
- emitcode("xch","a,%s",x); // 000AAAAA:BBBCCCCC
- break;
- case 6 : // AABBBBBB:CCDDDDDD
- emitcode("mov","c,acc.7");
- AccAXLrl1(x); // ABBBBBBC:CDDDDDDA
- AccAXLrl1(x); // BBBBBBCC:DDDDDDAA
- emitcode("xch","a,%s",x); // DDDDDDAA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000AA:BBBBBBCC
- break;
- case 7 : // ABBBBBBB:CDDDDDDD
- emitcode("mov","c,acc.7"); // c = A
- AccAXLrl1(x); // BBBBBBBC:DDDDDDDA
- emitcode("xch","a,%s",x); // DDDDDDDA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000A:BBBBBBBC
- break;
- default :
- break;
+static void
+AccAXRsh (char *x, int shCount)
+{
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ break;
+ case 2:
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD = a:x
+
+ AccRol (8 - shCount); // BBBAAAAA:DDDCCCCC
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBBAAAAA
+
+ AccRol (8 - shCount); // DDDCCCCC:BBBAAAAA
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000CCCCC:BBBAAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBB(CCCCC^AAAAA):BBBAAAAA
+
+ emitcode ("xch", "a,%s", x); // BBBAAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("xch", "a,%s", x); // BBB(CCCCC^AAAAA):000AAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:000AAAAA
+
+ emitcode ("xch", "a,%s", x); // 000AAAAA:BBBCCCCC
+
+ break;
+ case 6: // AABBBBBB:CCDDDDDD
+
+ emitcode ("mov", "c,acc.7");
+ AccAXLrl1 (x); // ABBBBBBC:CDDDDDDA
+
+ AccAXLrl1 (x); // BBBBBBCC:DDDDDDAA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDAA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000AA:BBBBBBCC
+
+ break;
+ case 7: // ABBBBBBB:CDDDDDDD
+
+ emitcode ("mov", "c,acc.7"); // c = A
+
+ AccAXLrl1 (x); // BBBBBBBC:DDDDDDDA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDDA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000A:BBBBBBBC
+
+ break;
+ default:
+ break;
}
}
/*-----------------------------------------------------------------*/
/* AccAXRshS - right shift signed a:x known count (0..7) */
/*-----------------------------------------------------------------*/
-static void AccAXRshS (char *x, int shCount)
-{
- symbol *tlbl ;
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- break;
- case 2 :
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD = a:x
- tlbl = newiTempLabel(NULL);
- AccRol(8 - shCount); // BBBAAAAA:CCCCCDDD
- emitcode("xch","a,%s",x); // CCCCCDDD:BBBAAAAA
- AccRol(8 - shCount); // DDDCCCCC:BBBAAAAA
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000CCCCC:BBBAAAAA
- emitcode("xrl","a,%s",x); // BBB(CCCCC^AAAAA):BBBAAAAA
- emitcode("xch","a,%s",x); // BBBAAAAA:BBB(CCCCC^AAAAA)
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
- emitcode("xch","a,%s",x); // BBB(CCCCC^AAAAA):000AAAAA
- emitcode("xrl","a,%s",x); // BBBCCCCC:000AAAAA
- emitcode("xch","a,%s",x); // 000SAAAA:BBBCCCCC
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 111AAAAA:BBBCCCCC
- emitcode("","%05d$:",tlbl->key+100);
- break; // SSSSAAAA:BBBCCCCC
- case 6 : // AABBBBBB:CCDDDDDD
- tlbl = newiTempLabel(NULL);
- emitcode("mov","c,acc.7");
- AccAXLrl1(x); // ABBBBBBC:CDDDDDDA
- AccAXLrl1(x); // BBBBBBCC:DDDDDDAA
- emitcode("xch","a,%s",x); // DDDDDDAA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000AA:BBBBBBCC
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 111111AA:BBBBBBCC
- emitcode("","%05d$:",tlbl->key+100);
- break;
- case 7 : // ABBBBBBB:CDDDDDDD
- tlbl = newiTempLabel(NULL);
- emitcode("mov","c,acc.7"); // c = A
- AccAXLrl1(x); // BBBBBBBC:DDDDDDDA
- emitcode("xch","a,%s",x); // DDDDDDDA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000A:BBBBBBBC
- emitcode("jnb","acc.%d,%05d$",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 1111111A:BBBBBBBC
- emitcode("","%05d$:",tlbl->key+100);
- break;
- default :
- break;
+static void
+AccAXRshS (char *x, int shCount)
+{
+ symbol *tlbl;
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ break;
+ case 2:
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD = a:x
+
+ tlbl = newiTempLabel (NULL);
+ AccRol (8 - shCount); // BBBAAAAA:CCCCCDDD
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBBAAAAA
+
+ AccRol (8 - shCount); // DDDCCCCC:BBBAAAAA
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000CCCCC:BBBAAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBB(CCCCC^AAAAA):BBBAAAAA
+
+ emitcode ("xch", "a,%s", x); // BBBAAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("xch", "a,%s", x); // BBB(CCCCC^AAAAA):000AAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:000AAAAA
+
+ emitcode ("xch", "a,%s", x); // 000SAAAA:BBBCCCCC
+
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 111AAAAA:BBBCCCCC
+
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ break; // SSSSAAAA:BBBCCCCC
+
+ case 6: // AABBBBBB:CCDDDDDD
+
+ tlbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,acc.7");
+ AccAXLrl1 (x); // ABBBBBBC:CDDDDDDA
+
+ AccAXLrl1 (x); // BBBBBBCC:DDDDDDAA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDAA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000AA:BBBBBBCC
+
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 111111AA:BBBBBBCC
+
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ break;
+ case 7: // ABBBBBBB:CDDDDDDD
+
+ tlbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,acc.7"); // c = A
+
+ AccAXLrl1 (x); // BBBBBBBC:DDDDDDDA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDDA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000A:BBBBBBBC
+
+ emitcode ("jnb", "acc.%d,%05d$", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 1111111A:BBBBBBBC
+
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ break;
+ default:
+ break;
}
}
/*-----------------------------------------------------------------*/
/* shiftL2Left2Result - shift left two bytes from left to result */
/*-----------------------------------------------------------------*/
-static void shiftL2Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftL2Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- if(sameRegs(AOP(result), AOP(left)) &&
- ((offl + MSB16) == offr)){
- /* don't crash result[offr] */
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
- } else {
- movLeft2Result(left,offl, result, offr, 0);
- MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ /* don't crash result[offr] */
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
}
- /* ax << shCount (x = lsb(result))*/
- AccAXLsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- aopPut(AOP(result),"a",offr+MSB16);
+ else
+ {
+ movLeft2Result (left, offl, result, offr, 0);
+ MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
+ }
+ /* ax << shCount (x = lsb(result)) */
+ AccAXLsh (aopGet (AOP (result), offr, FALSE, FALSE), shCount);
+ aopPut (AOP (result), "a", offr + MSB16);
}
/*-----------------------------------------------------------------*/
/* shiftR2Left2Result - shift right two bytes from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR2Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
+static void
+shiftR2Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
{
- if(sameRegs(AOP(result), AOP(left)) &&
- ((offl + MSB16) == offr)){
- /* don't crash result[offr] */
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
- } else {
- movLeft2Result(left,offl, result, offr, 0);
- MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ /* don't crash result[offr] */
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
}
- /* a:x >> shCount (x = lsb(result))*/
- if(sign)
- AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- else
- AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- if(getDataSize(result) > 1)
- aopPut(AOP(result),"a",offr+MSB16);
+ else
+ {
+ movLeft2Result (left, offl, result, offr, 0);
+ MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
+ }
+ /* a:x >> shCount (x = lsb(result)) */
+ if (sign)
+ AccAXRshS (aopGet (AOP (result), offr, FALSE, FALSE), shCount);
+ else
+ AccAXRsh (aopGet (AOP (result), offr, FALSE, FALSE), shCount);
+ if (getDataSize (result) > 1)
+ aopPut (AOP (result), "a", offr + MSB16);
}
/*-----------------------------------------------------------------*/
-/* shiftLLeftOrResult - shift left one byte from left, or to result*/
+/* shiftLLeftOrResult - shift left one byte from left, or to result */
/*-----------------------------------------------------------------*/
-static void shiftLLeftOrResult (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftLLeftOrResult (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- /* shift left accumulator */
- AccLsh(shCount);
- /* or with result */
- emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE));
- /* back to result */
- aopPut(AOP(result),"a",offr);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ /* shift left accumulator */
+ AccLsh (shCount);
+ /* or with result */
+ emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE));
+ /* back to result */
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
-/* shiftRLeftOrResult - shift right one byte from left,or to result*/
+/* shiftRLeftOrResult - shift right one byte from left,or to result */
/*-----------------------------------------------------------------*/
-static void shiftRLeftOrResult (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftRLeftOrResult (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- /* shift right accumulator */
- AccRsh(shCount);
- /* or with result */
- emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE));
- /* back to result */
- aopPut(AOP(result),"a",offr);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ /* shift right accumulator */
+ AccRsh (shCount);
+ /* or with result */
+ emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE));
+ /* back to result */
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* genlshOne - left shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
-static void genlshOne (operand *result, operand *left, int shCount)
+static void
+genlshOne (operand * result, operand * left, int shCount)
{
- shiftL1Left2Result(left, LSB, result, LSB, shCount);
+ shiftL1Left2Result (left, LSB, result, LSB, shCount);
}
/*-----------------------------------------------------------------*/
/* genlshTwo - left shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genlshTwo (operand *result,operand *left, int shCount)
+static void
+genlshTwo (operand * result, operand * left, int shCount)
{
- int size;
+ int size;
- size = getDataSize(result);
+ size = getDataSize (result);
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
- if (size > 1){
- if (shCount)
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- else
- movLeft2Result(left, LSB, result, MSB16, 0);
- }
- aopPut(AOP(result),zero,LSB);
+ if (size > 1)
+ {
+ if (shCount)
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ }
+ aopPut (AOP (result), zero, LSB);
}
- /* 1 <= shCount <= 7 */
- else {
- if(size == 1)
- shiftL1Left2Result(left, LSB, result, LSB, shCount);
- else
- shiftL2Left2Result(left, LSB, result, LSB, shCount);
+ /* 1 <= shCount <= 7 */
+ else
+ {
+ if (size == 1)
+ shiftL1Left2Result (left, LSB, result, LSB, shCount);
+ else
+ shiftL2Left2Result (left, LSB, result, LSB, shCount);
}
}
/* shiftLLong - shift left one long from left to result */
/* offl = LSB or MSB16 */
/*-----------------------------------------------------------------*/
-static void shiftLLong (operand *left, operand *result, int offr )
+static void
+shiftLLong (operand * left, operand * result, int offr)
{
- char *l;
- int size = AOP_SIZE(result);
+ char *l;
+ int size = AOP_SIZE (result);
- if(size >= LSB+offr){
- l = aopGet(AOP(left),LSB,FALSE,FALSE);
- MOVA(l);
- emitcode("add","a,acc");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB16+offr && offr != LSB )
- emitcode("xch","a,%s",
- aopGet(AOP(left),LSB+offr,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",LSB+offr);
+ if (size >= LSB + offr)
+ {
+ l = aopGet (AOP (left), LSB, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB16 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), LSB + offr, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", LSB + offr);
}
- if(size >= MSB16+offr){
- if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB16+offr && offr != LSB) ) {
- l = aopGet(AOP(left),MSB16,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("rlc","a");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB24+offr && offr != LSB)
- emitcode("xch","a,%s",
- aopGet(AOP(left),MSB16+offr,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",MSB16+offr);
+ if (size >= MSB16 + offr)
+ {
+ if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB16 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB16, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB24 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), MSB16 + offr, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", MSB16 + offr);
}
- if(size >= MSB24+offr){
- if (!(sameRegs(AOP(left),AOP(left)) && size >= MSB24+offr && offr != LSB)) {
- l = aopGet(AOP(left),MSB24,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("rlc","a");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB32+offr && offr != LSB )
- emitcode("xch","a,%s",
- aopGet(AOP(left),MSB24+offr,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",MSB24+offr);
+ if (size >= MSB24 + offr)
+ {
+ if (!(sameRegs (AOP (left), AOP (left)) && size >= MSB24 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB24, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB32 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), MSB24 + offr, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", MSB24 + offr);
}
- if(size > MSB32+offr){
- if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB32+offr && offr != LSB)) {
- l = aopGet(AOP(left),MSB32,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("rlc","a");
- aopPut(AOP(result),"a",MSB32+offr);
+ if (size > MSB32 + offr)
+ {
+ if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB32 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB32, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ aopPut (AOP (result), "a", MSB32 + offr);
}
- if(offr != LSB)
- aopPut(AOP(result),zero,LSB);
+ if (offr != LSB)
+ aopPut (AOP (result), zero, LSB);
}
/*-----------------------------------------------------------------*/
/* genlshFour - shift four byte by a known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genlshFour (operand *result, operand *left, int shCount)
-{
- int size;
-
- size = AOP_SIZE(result);
-
- /* if shifting more that 3 bytes */
- if (shCount >= 24 ) {
- shCount -= 24;
- if (shCount)
- /* lowest order of left goes to the highest
- order of the destination */
- shiftL1Left2Result(left, LSB, result, MSB32, shCount);
- else
- movLeft2Result(left, LSB, result, MSB32, 0);
- aopPut(AOP(result),zero,LSB);
- aopPut(AOP(result),zero,MSB16);
- aopPut(AOP(result),zero,MSB32);
- return;
- }
-
- /* more than two bytes */
- else if ( shCount >= 16 ) {
- /* lower order two bytes goes to higher order two bytes */
- shCount -= 16;
- /* if some more remaining */
- if (shCount)
- shiftL2Left2Result(left, LSB, result, MSB24, shCount);
- else {
- movLeft2Result(left, MSB16, result, MSB32, 0);
- movLeft2Result(left, LSB, result, MSB24, 0);
- }
- aopPut(AOP(result),zero,MSB16);
- aopPut(AOP(result),zero,LSB);
- return;
- }
-
- /* if more than 1 byte */
- else if ( shCount >= 8 ) {
- /* lower order three bytes goes to higher order three bytes */
- shCount -= 8;
- if(size == 2){
- if(shCount)
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- else
- movLeft2Result(left, LSB, result, MSB16, 0);
- }
- else{ /* size = 4 */
- if(shCount == 0){
- movLeft2Result(left, MSB24, result, MSB32, 0);
- movLeft2Result(left, MSB16, result, MSB24, 0);
- movLeft2Result(left, LSB, result, MSB16, 0);
- aopPut(AOP(result),zero,LSB);
- }
- else if(shCount == 1)
- shiftLLong(left, result, MSB16);
- else{
- shiftL2Left2Result(left, MSB16, result, MSB24, shCount);
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- shiftRLeftOrResult(left, LSB, result, MSB24, 8 - shCount);
- aopPut(AOP(result),zero,LSB);
- }
- }
- }
-
- /* 1 <= shCount <= 7 */
- else if(shCount <= 2){
- shiftLLong(left, result, LSB);
- if(shCount == 2)
- shiftLLong(result, result, LSB);
- }
- /* 3 <= shCount <= 7, optimize */
- else{
- shiftL2Left2Result(left, MSB24, result, MSB24, shCount);
- shiftRLeftOrResult(left, MSB16, result, MSB24, 8 - shCount);
- shiftL2Left2Result(left, LSB, result, LSB, shCount);
+static void
+genlshFour (operand * result, operand * left, int shCount)
+{
+ int size;
+
+ size = AOP_SIZE (result);
+
+ /* if shifting more that 3 bytes */
+ if (shCount >= 24)
+ {
+ shCount -= 24;
+ if (shCount)
+ /* lowest order of left goes to the highest
+ order of the destination */
+ shiftL1Left2Result (left, LSB, result, MSB32, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB32, 0);
+ aopPut (AOP (result), zero, LSB);
+ aopPut (AOP (result), zero, MSB16);
+ aopPut (AOP (result), zero, MSB32);
+ return;
+ }
+
+ /* more than two bytes */
+ else if (shCount >= 16)
+ {
+ /* lower order two bytes goes to higher order two bytes */
+ shCount -= 16;
+ /* if some more remaining */
+ if (shCount)
+ shiftL2Left2Result (left, LSB, result, MSB24, shCount);
+ else
+ {
+ movLeft2Result (left, MSB16, result, MSB32, 0);
+ movLeft2Result (left, LSB, result, MSB24, 0);
+ }
+ aopPut (AOP (result), zero, MSB16);
+ aopPut (AOP (result), zero, LSB);
+ return;
+ }
+
+ /* if more than 1 byte */
+ else if (shCount >= 8)
+ {
+ /* lower order three bytes goes to higher order three bytes */
+ shCount -= 8;
+ if (size == 2)
+ {
+ if (shCount)
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ }
+ else
+ { /* size = 4 */
+ if (shCount == 0)
+ {
+ movLeft2Result (left, MSB24, result, MSB32, 0);
+ movLeft2Result (left, MSB16, result, MSB24, 0);
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ aopPut (AOP (result), zero, LSB);
+ }
+ else if (shCount == 1)
+ shiftLLong (left, result, MSB16);
+ else
+ {
+ shiftL2Left2Result (left, MSB16, result, MSB24, shCount);
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ shiftRLeftOrResult (left, LSB, result, MSB24, 8 - shCount);
+ aopPut (AOP (result), zero, LSB);
+ }
+ }
+ }
+
+ /* 1 <= shCount <= 7 */
+ else if (shCount <= 2)
+ {
+ shiftLLong (left, result, LSB);
+ if (shCount == 2)
+ shiftLLong (result, result, LSB);
+ }
+ /* 3 <= shCount <= 7, optimize */
+ else
+ {
+ shiftL2Left2Result (left, MSB24, result, MSB24, shCount);
+ shiftRLeftOrResult (left, MSB16, result, MSB24, 8 - shCount);
+ shiftL2Left2Result (left, LSB, result, LSB, shCount);
}
}
/*-----------------------------------------------------------------*/
/* genLeftShiftLiteral - left shifting by known count */
/*-----------------------------------------------------------------*/
-static void genLeftShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic)
+static void
+genLeftShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
- size = getSize(operandType(result));
+ size = getSize (operandType (result));
#if VIEW_SIZE
- emitcode("; shift left ","result %d, left %d",size,
- AOP_SIZE(left));
+ emitcode ("; shift left ", "result %d, left %d", size,
+ AOP_SIZE (left));
#endif
- /* I suppose that the left size >= result size */
- if(shCount == 0){
- while(size--){
- movLeft2Result(left, size, result, size, 0);
- }
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ while (size--)
+ {
+ movLeft2Result (left, size, result, size, 0);
+ }
}
- else if(shCount >= (size * 8))
- while(size--)
- aopPut(AOP(result),zero,size);
- else{
- switch (size) {
- case 1:
- genlshOne (result,left,shCount);
- break;
+ else if (shCount >= (size * 8))
+ while (size--)
+ aopPut (AOP (result), zero, size);
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genlshOne (result, left, shCount);
+ break;
- case 2:
- case 3:
- genlshTwo (result,left,shCount);
- break;
+ case 2:
+ case 3:
+ genlshTwo (result, left, shCount);
+ break;
- case 4:
- genlshFour (result,left,shCount);
- break;
- }
+ case 4:
+ genlshFour (result, left, shCount);
+ break;
+ }
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genLeftShift - generates code for left shifting */
/*-----------------------------------------------------------------*/
-static void genLeftShift (iCode *ic)
-{
- operand *left,*right, *result;
- int size, offset;
- char *l;
- symbol *tlbl , *tlbl1;
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
-
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genLeftShiftLiteral (left,right,result,ic);
- return ;
- }
-
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && (IS_AOP_PREG(result))) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- }
-
- tlbl = newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = 0 ;
- tlbl1 = newiTempLabel(NULL);
-
- /* if it is only one byte then */
- if (size == 1) {
- symbol *tlbl1 = newiTempLabel(NULL);
-
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("add","a,acc");
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
-
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("add","a,acc");
- aopPut(AOP(result),"a",offset++);
- while (--size) {
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rlc","a");
- aopPut(AOP(result),"a",offset++);
- }
- reAdjustPreg(AOP(result));
-
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
-release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+static void
+genLeftShift (iCode * ic)
+{
+ operand *left, *right, *result;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (right, ic, FALSE);
+
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genLeftShiftLiteral (left, right, result, ic);
+ return;
+ }
+
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE);
+ if (*l == '@' && (IS_AOP_PREG (result)))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ }
+
+ tlbl = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = 0;
+ tlbl1 = newiTempLabel (NULL);
+
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ symbol *tlbl1 = newiTempLabel (NULL);
+
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("add", "a,acc");
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ aopPut (AOP (result), "a", offset++);
+ while (--size)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ aopPut (AOP (result), "a", offset++);
+ }
+ reAdjustPreg (AOP (result));
+
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
+release:
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genrshOne - right shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
-static void genrshOne (operand *result, operand *left,
- int shCount, int sign)
+static void
+genrshOne (operand * result, operand * left,
+ int shCount, int sign)
{
- shiftR1Left2Result(left, LSB, result, LSB, shCount, sign);
+ shiftR1Left2Result (left, LSB, result, LSB, shCount, sign);
}
/*-----------------------------------------------------------------*/
/* genrshTwo - right shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshTwo (operand *result,operand *left,
- int shCount, int sign)
+static void
+genrshTwo (operand * result, operand * left,
+ int shCount, int sign)
{
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
- if (shCount)
- shiftR1Left2Result(left, MSB16, result, LSB,
- shCount, sign);
- else
- movLeft2Result(left, MSB16, result, LSB, sign);
- addSign(result, MSB16, sign);
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (shCount)
+ shiftR1Left2Result (left, MSB16, result, LSB,
+ shCount, sign);
+ else
+ movLeft2Result (left, MSB16, result, LSB, sign);
+ addSign (result, MSB16, sign);
}
- /* 1 <= shCount <= 7 */
- else
- shiftR2Left2Result(left, LSB, result, LSB, shCount, sign);
+ /* 1 <= shCount <= 7 */
+ else
+ shiftR2Left2Result (left, LSB, result, LSB, shCount, sign);
}
/*-----------------------------------------------------------------*/
/* shiftRLong - shift right one long from left to result */
/* offl = LSB or MSB16 */
/*-----------------------------------------------------------------*/
-static void shiftRLong (operand *left, int offl,
- operand *result, int sign)
-{
- if(!sign)
- emitcode("clr","c");
- MOVA(aopGet(AOP(left),MSB32,FALSE,FALSE));
- if(sign)
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB32-offl);
- if(offl == MSB16)
- /* add sign of "a" */
- addSign(result, MSB32, sign);
-
- MOVA(aopGet(AOP(left),MSB24,FALSE,FALSE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB24-offl);
-
- MOVA(aopGet(AOP(left),MSB16,FALSE,FALSE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB16-offl);
-
- if(offl == LSB){
- MOVA(aopGet(AOP(left),LSB,FALSE,FALSE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",LSB);
+static void
+shiftRLong (operand * left, int offl,
+ operand * result, int sign)
+{
+ if (!sign)
+ emitcode ("clr", "c");
+ MOVA (aopGet (AOP (left), MSB32, FALSE, FALSE));
+ if (sign)
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB32 - offl);
+ if (offl == MSB16)
+ /* add sign of "a" */
+ addSign (result, MSB32, sign);
+
+ MOVA (aopGet (AOP (left), MSB24, FALSE, FALSE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB24 - offl);
+
+ MOVA (aopGet (AOP (left), MSB16, FALSE, FALSE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB16 - offl);
+
+ if (offl == LSB)
+ {
+ MOVA (aopGet (AOP (left), LSB, FALSE, FALSE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", LSB);
}
}
/*-----------------------------------------------------------------*/
/* genrshFour - shift four byte by a known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshFour (operand *result, operand *left,
- int shCount, int sign)
-{
- /* if shifting more that 3 bytes */
- if(shCount >= 24 ) {
- shCount -= 24;
- if(shCount)
- shiftR1Left2Result(left, MSB32, result, LSB, shCount, sign);
- else
- movLeft2Result(left, MSB32, result, LSB, sign);
- addSign(result, MSB16, sign);
- }
- else if(shCount >= 16){
- shCount -= 16;
- if(shCount)
- shiftR2Left2Result(left, MSB24, result, LSB, shCount, sign);
- else{
- movLeft2Result(left, MSB24, result, LSB, 0);
- movLeft2Result(left, MSB32, result, MSB16, sign);
- }
- addSign(result, MSB24, sign);
- }
- else if(shCount >= 8){
- shCount -= 8;
- if(shCount == 1)
- shiftRLong(left, MSB16, result, sign);
- else if(shCount == 0){
- movLeft2Result(left, MSB16, result, LSB, 0);
- movLeft2Result(left, MSB24, result, MSB16, 0);
- movLeft2Result(left, MSB32, result, MSB24, sign);
- addSign(result, MSB32, sign);
- }
- else{
- shiftR2Left2Result(left, MSB16, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB32, result, MSB16, 8 - shCount);
- /* the last shift is signed */
- shiftR1Left2Result(left, MSB32, result, MSB24, shCount, sign);
- addSign(result, MSB32, sign);
- }
- }
- else{ /* 1 <= shCount <= 7 */
- if(shCount <= 2){
- shiftRLong(left, LSB, result, sign);
- if(shCount == 2)
- shiftRLong(result, LSB, result, sign);
- }
- else{
- shiftR2Left2Result(left, LSB, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB24, result, MSB16, 8 - shCount);
- shiftR2Left2Result(left, MSB24, result, MSB24, shCount, sign);
- }
+static void
+genrshFour (operand * result, operand * left,
+ int shCount, int sign)
+{
+ /* if shifting more that 3 bytes */
+ if (shCount >= 24)
+ {
+ shCount -= 24;
+ if (shCount)
+ shiftR1Left2Result (left, MSB32, result, LSB, shCount, sign);
+ else
+ movLeft2Result (left, MSB32, result, LSB, sign);
+ addSign (result, MSB16, sign);
+ }
+ else if (shCount >= 16)
+ {
+ shCount -= 16;
+ if (shCount)
+ shiftR2Left2Result (left, MSB24, result, LSB, shCount, sign);
+ else
+ {
+ movLeft2Result (left, MSB24, result, LSB, 0);
+ movLeft2Result (left, MSB32, result, MSB16, sign);
+ }
+ addSign (result, MSB24, sign);
+ }
+ else if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (shCount == 1)
+ shiftRLong (left, MSB16, result, sign);
+ else if (shCount == 0)
+ {
+ movLeft2Result (left, MSB16, result, LSB, 0);
+ movLeft2Result (left, MSB24, result, MSB16, 0);
+ movLeft2Result (left, MSB32, result, MSB24, sign);
+ addSign (result, MSB32, sign);
+ }
+ else
+ {
+ shiftR2Left2Result (left, MSB16, result, LSB, shCount, 0);
+ shiftLLeftOrResult (left, MSB32, result, MSB16, 8 - shCount);
+ /* the last shift is signed */
+ shiftR1Left2Result (left, MSB32, result, MSB24, shCount, sign);
+ addSign (result, MSB32, sign);
+ }
+ }
+ else
+ { /* 1 <= shCount <= 7 */
+ if (shCount <= 2)
+ {
+ shiftRLong (left, LSB, result, sign);
+ if (shCount == 2)
+ shiftRLong (result, LSB, result, sign);
+ }
+ else
+ {
+ shiftR2Left2Result (left, LSB, result, LSB, shCount, 0);
+ shiftLLeftOrResult (left, MSB24, result, MSB16, 8 - shCount);
+ shiftR2Left2Result (left, MSB24, result, MSB24, shCount, sign);
+ }
}
}
/*-----------------------------------------------------------------*/
/* genRightShiftLiteral - right shifting by known count */
/*-----------------------------------------------------------------*/
-static void genRightShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic,
- int sign)
+static void
+genRightShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic,
+ int sign)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
#if VIEW_SIZE
- emitcode("; shift right ","result %d, left %d",AOP_SIZE(result),
- AOP_SIZE(left));
+ emitcode ("; shift right ", "result %d, left %d", AOP_SIZE (result),
+ AOP_SIZE (left));
#endif
- size = getDataSize(left);
- /* test the LEFT size !!! */
+ size = getDataSize (left);
+ /* test the LEFT size !!! */
- /* I suppose that the left size >= result size */
- if(shCount == 0){
- size = getDataSize(result);
- while(size--)
- movLeft2Result(left, size, result, size, 0);
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ size = getDataSize (result);
+ while (size--)
+ movLeft2Result (left, size, result, size, 0);
}
- else if(shCount >= (size * 8)){
- if(sign)
- /* get sign in acc.7 */
- MOVA(aopGet(AOP(left),size-1,FALSE,FALSE));
- addSign(result, LSB, sign);
- } else{
- switch (size) {
- case 1:
- genrshOne (result,left,shCount,sign);
- break;
+ else if (shCount >= (size * 8))
+ {
+ if (sign)
+ /* get sign in acc.7 */
+ MOVA (aopGet (AOP (left), size - 1, FALSE, FALSE));
+ addSign (result, LSB, sign);
+ }
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genrshOne (result, left, shCount, sign);
+ break;
- case 2:
- genrshTwo (result,left,shCount,sign);
- break;
+ case 2:
+ genrshTwo (result, left, shCount, sign);
+ break;
- case 4:
- genrshFour (result,left,shCount,sign);
- break;
- default :
- break;
- }
+ case 4:
+ genrshFour (result, left, shCount, sign);
+ break;
+ default:
+ break;
+ }
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
}
/*-----------------------------------------------------------------*/
/* genSignedRightShift - right shift of signed number */
/*-----------------------------------------------------------------*/
-static void genSignedRightShift (iCode *ic)
-{
- operand *right, *left, *result;
- int size, offset;
- char *l;
- symbol *tlbl, *tlbl1 ;
-
- /* we do it the hard way put the shift count in b
- and loop thru preserving the sign */
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
-
-
- if ( AOP_TYPE(right) == AOP_LIT) {
- genRightShiftLiteral (left,right,result,ic,1);
- return ;
- }
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && IS_AOP_PREG(result)) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- }
-
- /* mov the highest order bit to OVR */
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
-
- size = AOP_SIZE(result);
- offset = size - 1;
- emitcode("mov","a,%s",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("rlc","a");
- emitcode("mov","ov,c");
- /* if it is only one byte then */
- if (size == 1) {
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("mov","c,ov");
- emitcode("rrc","a");
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- emitcode("mov","c,ov");
- while (size--) {
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rrc","a");
- aopPut(AOP(result),"a",offset--);
- }
- reAdjustPreg(AOP(result));
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
+static void
+genSignedRightShift (iCode * ic)
+{
+ operand *right, *left, *result;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
+
+ /* we do it the hard way put the shift count in b
+ and loop thru preserving the sign */
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (right, ic, FALSE);
+
+
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genRightShiftLiteral (left, right, result, ic, 1);
+ return;
+ }
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE);
+ if (*l == '@' && IS_AOP_PREG (result))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ }
+
+ /* mov the highest order bit to OVR */
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
+
+ size = AOP_SIZE (result);
+ offset = size - 1;
+ emitcode ("mov", "a,%s", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("rlc", "a");
+ emitcode ("mov", "ov,c");
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("mov", "c,ov");
+ emitcode ("rrc", "a");
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ emitcode ("mov", "c,ov");
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", offset--);
+ }
+ reAdjustPreg (AOP (result));
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRightShift - generate code for right shifting */
/*-----------------------------------------------------------------*/
-static void genRightShift (iCode *ic)
-{
- operand *right, *left, *result;
- sym_link *retype ;
- int size, offset;
- char *l;
- symbol *tlbl, *tlbl1 ;
-
- /* if signed then we do it the hard way preserve the
- sign bit moving it inwards */
- retype = getSpec(operandType(IC_RESULT(ic)));
-
- if (!SPEC_USIGN(retype)) {
- genSignedRightShift (ic);
- return ;
- }
-
- /* signed & unsigned types are treated the same : i.e. the
- signed is NOT propagated inwards : quoting from the
- ANSI - standard : "for E1 >> E2, is equivalent to division
- by 2**E2 if unsigned or if it has a non-negative value,
- otherwise the result is implementation defined ", MY definition
- is that the sign does not get propagated */
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
-
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genRightShiftLiteral (left,right,result,ic, 0);
- return ;
- }
-
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && IS_AOP_PREG(result)) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- }
-
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = size - 1;
-
- /* if it is only one byte then */
- if (size == 1) {
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- CLRC;
- emitcode("rrc","a");
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
- emitcode("sjmp","%05d$",tlbl1->key+100);
- emitcode("","%05d$:",tlbl->key+100);
- CLRC;
- while (size--) {
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rrc","a");
- aopPut(AOP(result),"a",offset--);
- }
- reAdjustPreg(AOP(result));
-
- emitcode("","%05d$:",tlbl1->key+100);
- emitcode("djnz","b,%05d$",tlbl->key+100);
+static void
+genRightShift (iCode * ic)
+{
+ operand *right, *left, *result;
+ sym_link *retype;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
+
+ /* if signed then we do it the hard way preserve the
+ sign bit moving it inwards */
+ retype = getSpec (operandType (IC_RESULT (ic)));
+
+ if (!SPEC_USIGN (retype))
+ {
+ genSignedRightShift (ic);
+ return;
+ }
+
+ /* signed & unsigned types are treated the same : i.e. the
+ signed is NOT propagated inwards : quoting from the
+ ANSI - standard : "for E1 >> E2, is equivalent to division
+ by 2**E2 if unsigned or if it has a non-negative value,
+ otherwise the result is implementation defined ", MY definition
+ is that the sign does not get propagated */
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (right, ic, FALSE);
+
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genRightShiftLiteral (left, right, result, ic, 0);
+ return;
+ }
+
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE);
+ if (*l == '@' && IS_AOP_PREG (result))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ }
+
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = size - 1;
+
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ CLRC;
+ emitcode ("rrc", "a");
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+ emitcode ("sjmp", "%05d$", tlbl1->key + 100);
+ emitcode ("", "%05d$:", tlbl->key + 100);
+ CLRC;
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", offset--);
+ }
+ reAdjustPreg (AOP (result));
+
+ emitcode ("", "%05d$:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d$", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genUnpackBits - generates code for unpacking bits */
/*-----------------------------------------------------------------*/
-static void genUnpackBits (operand *result, char *rname, int ptype)
+static void
+genUnpackBits (operand * result, char *rname, int ptype)
{
- int shCnt ;
- int rlen = 0 ;
- sym_link *etype;
- int offset = 0 ;
- int rsize ;
+ int shCnt;
+ int rlen = 0;
+ sym_link *etype;
+ int offset = 0;
+ int rsize;
- etype = getSpec(operandType(result));
- rsize = getSize(operandType(result));
- /* read the first byte */
- switch (ptype) {
+ etype = getSpec (operandType (result));
+ rsize = getSize (operandType (result));
+ /* read the first byte */
+ switch (ptype)
+ {
case POINTER:
case IPOINTER:
- emitcode("mov","a,@%s",rname);
- break;
+ emitcode ("mov", "a,@%s", rname);
+ break;
case PPOINTER:
- emitcode("movx","a,@%s",rname);
- break;
+ emitcode ("movx", "a,@%s", rname);
+ break;
case FPOINTER:
- emitcode("movx","a,@dptr");
- break;
+ emitcode ("movx", "a,@dptr");
+ break;
case CPOINTER:
- emitcode("clr","a");
- emitcode("movc","a","@a+dptr");
- break;
+ emitcode ("clr", "a");
+ emitcode ("movc", "a", "@a+dptr");
+ break;
case GPOINTER:
- emitcode("lcall","__gptrget");
- break;
+ emitcode ("lcall", "__gptrget");
+ break;
}
- rlen = SPEC_BLEN(etype) ;
+ rlen = SPEC_BLEN (etype);
- /* if we have bitdisplacement then it fits */
- /* into this byte completely or if length is */
- /* less than a byte */
- if ((shCnt = SPEC_BSTR(etype)) ||
- (SPEC_BLEN(etype) <= 8)) {
+ /* if we have bitdisplacement then it fits */
+ /* into this byte completely or if length is */
+ /* less than a byte */
+ if ((shCnt = SPEC_BSTR (etype)) ||
+ (SPEC_BLEN (etype) <= 8))
+ {
- /* shift right acc */
- AccRsh(shCnt);
+ /* shift right acc */
+ AccRsh (shCnt);
- emitcode("anl","a,#0x%02x",
- ((unsigned char) -1)>>(8 - SPEC_BLEN(etype)));
- aopPut(AOP(result),"a",offset++);
- goto finish;
+ emitcode ("anl", "a,#0x%02x",
+ ((unsigned char) -1) >> (8 - SPEC_BLEN (etype)));
+ aopPut (AOP (result), "a", offset++);
+ goto finish;
}
- /* bit field did not fit in a byte */
- aopPut(AOP(result),"a",offset++);
+ /* bit field did not fit in a byte */
+ aopPut (AOP (result), "a", offset++);
- while (1) {
+ while (1)
+ {
- switch (ptype) {
- case POINTER:
- case IPOINTER:
- emitcode("inc","%s",rname);
- emitcode("mov","a,@%s",rname);
- break;
+ switch (ptype)
+ {
+ case POINTER:
+ case IPOINTER:
+ emitcode ("inc", "%s", rname);
+ emitcode ("mov", "a,@%s", rname);
+ break;
- case PPOINTER:
- emitcode("inc","%s",rname);
- emitcode("movx","a,@%s",rname);
- break;
+ case PPOINTER:
+ emitcode ("inc", "%s", rname);
+ emitcode ("movx", "a,@%s", rname);
+ break;
- case FPOINTER:
- emitcode("inc","dptr");
- emitcode("movx","a,@dptr");
- break;
+ case FPOINTER:
+ emitcode ("inc", "dptr");
+ emitcode ("movx", "a,@dptr");
+ break;
- case CPOINTER:
- emitcode("clr","a");
- emitcode("inc","dptr");
- emitcode("movc","a","@a+dptr");
- break;
+ case CPOINTER:
+ emitcode ("clr", "a");
+ emitcode ("inc", "dptr");
+ emitcode ("movc", "a", "@a+dptr");
+ break;
- case GPOINTER:
- emitcode("inc","dptr");
- emitcode("lcall","__gptrget");
- break;
- }
+ case GPOINTER:
+ emitcode ("inc", "dptr");
+ emitcode ("lcall", "__gptrget");
+ break;
+ }
- rlen -= 8;
- /* if we are done */
- if ( rlen < 8 )
- break ;
+ rlen -= 8;
+ /* if we are done */
+ if (rlen < 8)
+ break;
- aopPut(AOP(result),"a",offset++);
+ aopPut (AOP (result), "a", offset++);
}
- if (rlen) {
+ if (rlen)
+ {
// emitcode("anl","a,#0x%02x",((unsigned char)-1)>>(rlen));
- AccLsh(8-rlen);
- aopPut(AOP(result),"a",offset++);
+ AccLsh (8 - rlen);
+ aopPut (AOP (result), "a", offset++);
}
- finish:
- if (offset < rsize) {
+finish:
+ if (offset < rsize)
+ {
rsize -= offset;
- while (rsize--) aopPut(AOP(result),zero,offset++);
+ while (rsize--)
+ aopPut (AOP (result), zero, offset++);
}
- return ;
+ return;
}
/*-----------------------------------------------------------------*/
/* genDataPointerGet - generates code when ptr offset is known */
/*-----------------------------------------------------------------*/
-static void genDataPointerGet (operand *left,
- operand *result,
- iCode *ic)
-{
- char *l;
- char buffer[256];
- int size , offset = 0;
- aopOp(result,ic,TRUE);
-
- /* get the string representation of the name */
- l = aopGet(AOP(left),0,FALSE,TRUE);
- size = AOP_SIZE(result);
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l+1,offset);
- else
- sprintf(buffer,"%s",l+1);
- aopPut(AOP(result),buffer,offset++);
+static void
+genDataPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
+{
+ char *l;
+ char buffer[256];
+ int size, offset = 0;
+ aopOp (result, ic, TRUE);
+
+ /* get the string representation of the name */
+ l = aopGet (AOP (left), 0, FALSE, TRUE);
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l + 1, offset);
+ else
+ sprintf (buffer, "%s", l + 1);
+ aopPut (AOP (result), buffer, offset++);
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerGet - emitcode for near pointer fetch */
/*-----------------------------------------------------------------*/
-static void genNearPointerGet (operand *left,
- operand *result,
- iCode *ic)
-{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
- sym_link *rtype, *retype;
- sym_link *ltype = operandType(left);
- char buffer[80];
-
- rtype = operandType(result);
- retype= getSpec(rtype);
-
- aopOp(left,ic,FALSE);
-
- /* if left is rematerialisable and
- result is not bit variable type and
- the left is pointer to data space i.e
- lower 128 bytes of space */
- if (AOP_TYPE(left) == AOP_IMMD &&
- !IS_BITVAR(retype) &&
- DCL_TYPE(ltype) == POINTER) {
- genDataPointerGet (left,result,ic);
- return ;
+static void
+genNearPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
+{
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname;
+ sym_link *rtype, *retype;
+ sym_link *ltype = operandType (left);
+ char buffer[80];
+
+ rtype = operandType (result);
+ retype = getSpec (rtype);
+
+ aopOp (left, ic, FALSE);
+
+ /* if left is rematerialisable and
+ result is not bit variable type and
+ the left is pointer to data space i.e
+ lower 128 bytes of space */
+ if (AOP_TYPE (left) == AOP_IMMD &&
+ !IS_BITVAR (retype) &&
+ DCL_TYPE (ltype) == POINTER)
+ {
+ genDataPointerGet (left, result, ic);
+ return;
}
/* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0,FALSE,FALSE);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genUnpackBits (result,rname,POINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
- if (IS_AOP_PREG(result) || AOP_TYPE(result) == AOP_STK ) {
-
- emitcode("mov","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
- } else {
- sprintf(buffer,"@%s",rname);
- aopPut(AOP(result),buffer,offset);
- }
- offset++ ;
- if (size)
- emitcode("inc","%s",rname);
- }
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0, FALSE, TRUE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (left), 0, FALSE, FALSE);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, rname, POINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+ if (IS_AOP_PREG (result) || AOP_TYPE (result) == AOP_STK)
+ {
+
+ emitcode ("mov", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ {
+ sprintf (buffer, "@%s", rname);
+ aopPut (AOP (result), buffer, offset);
+ }
+ offset++;
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- /* done */
- freeAsmop(result,NULL,ic,TRUE);
+ /* done */
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerGet - emitcode for paged pointer fetch */
/*-----------------------------------------------------------------*/
-static void genPagedPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genPagedPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
- sym_link *rtype, *retype;
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname;
+ sym_link *rtype, *retype;
- rtype = operandType(result);
- retype= getSpec(rtype);
+ rtype = operandType (result);
+ retype = getSpec (rtype);
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
/* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0,FALSE,FALSE);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genUnpackBits (result,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
-
- emitcode("movx","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
-
- offset++ ;
-
- if (size)
- emitcode("inc","%s",rname);
- }
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0, FALSE, TRUE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (left), 0, FALSE, FALSE);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+
+ emitcode ("movx", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
+
+ offset++;
+
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- /* done */
- freeAsmop(result,NULL,ic,TRUE);
+ /* done */
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerGet - gget value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genFarPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
- while (size--) {
- emitcode("movx","a,@dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
- }
+ while (size--)
+ {
+ emitcode ("movx", "a,@dptr");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* emitcodePointerGet - gget value from code space */
/*-----------------------------------------------------------------*/
-static void emitcodePointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+emitcodePointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",CPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", CPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
- while (size--) {
- emitcode("clr","a");
- emitcode("movc","a,@a+dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
- }
+ while (size--)
+ {
+ emitcode ("clr", "a");
+ emitcode ("movc", "a,@a+dptr");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerGet - gget value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genGenPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- emitcode("mov","b,#%d",pointerCode(retype));
- }
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- emitcode("mov","b,%s",aopGet(AOP(left),3,FALSE,FALSE));
- }
- else
- {
- emitcode("mov","b,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- emitcode("lcall","__gptrget");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
- }
- }
-
- freeAsmop(result,NULL,ic,TRUE);
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE));
+ emitcode ("mov", "b,#%d", pointerCode (retype));
+ }
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE));
+ emitcode ("mov", "b,%s", aopGet (AOP (left), 3, FALSE, FALSE));
+ }
+ else
+ {
+ emitcode ("mov", "b,%s", aopGet (AOP (left), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
+
+ while (size--)
+ {
+ emitcode ("lcall", "__gptrget");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
+ }
+
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
-static void genPointerGet (iCode *ic)
+static void
+genPointerGet (iCode * ic)
{
- operand *left, *result ;
- sym_link *type, *etype;
- int p_type;
+ operand *left, *result;
+ sym_link *type, *etype;
+ int p_type;
- left = IC_LEFT(ic);
- result = IC_RESULT(ic) ;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(left);
- etype = getSpec(type);
- /* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next))
- p_type = DCL_TYPE(type);
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (left);
+ etype = getSpec (type);
+ /* if left is of type of pointer then it is simple */
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ p_type = DCL_TYPE (type);
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
/* if (SPEC_OCLS(etype)->codesp ) { */
/* p_type = CPOINTER ; */
/* p_type = POINTER ; */
}
- /* now that we have the pointer type we assign
- the pointer values */
- switch (p_type) {
+ /* now that we have the pointer type we assign
+ the pointer values */
+ switch (p_type)
+ {
case POINTER:
case IPOINTER:
- genNearPointerGet (left,result,ic);
- break;
+ genNearPointerGet (left, result, ic);
+ break;
case PPOINTER:
- genPagedPointerGet(left,result,ic);
- break;
+ genPagedPointerGet (left, result, ic);
+ break;
case FPOINTER:
- genFarPointerGet (left,result,ic);
- break;
+ genFarPointerGet (left, result, ic);
+ break;
case CPOINTER:
- emitcodePointerGet (left,result,ic);
- break;
+ emitcodePointerGet (left, result, ic);
+ break;
case GPOINTER:
- genGenPointerGet (left,result,ic);
- break;
+ genGenPointerGet (left, result, ic);
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genPackBits - generates code for packed bit storage */
/*-----------------------------------------------------------------*/
-static void genPackBits (sym_link *etype ,
- operand *right ,
- char *rname, int p_type)
-{
- int shCount = 0 ;
- int offset = 0 ;
- int rLen = 0 ;
- int blen, bstr ;
- char *l ;
-
- blen = SPEC_BLEN(etype);
- bstr = SPEC_BSTR(etype);
-
- l = aopGet(AOP(right),offset++,FALSE,FALSE);
- MOVA(l);
-
- /* if the bit lenth is less than or */
- /* it exactly fits a byte then */
- if (SPEC_BLEN(etype) <= 8 ) {
- shCount = SPEC_BSTR(etype) ;
-
- /* shift left acc */
- AccLsh(shCount);
-
- if (SPEC_BLEN(etype) < 8 ) { /* if smaller than a byte */
-
-
- switch (p_type) {
- case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
- break;
-
- case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
- break;
+static void
+genPackBits (sym_link * etype,
+ operand * right,
+ char *rname, int p_type)
+{
+ int shCount = 0;
+ int offset = 0;
+ int rLen = 0;
+ int blen, bstr;
+ char *l;
- case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
- break;
- }
+ blen = SPEC_BLEN (etype);
+ bstr = SPEC_BSTR (etype);
- emitcode ("anl","a,#0x%02x",(unsigned char)
- ((unsigned char)(0xFF << (blen+bstr)) |
- (unsigned char)(0xFF >> (8-bstr)) ) );
- emitcode ("orl","a,b");
- if (p_type == GPOINTER)
- emitcode("pop","b");
- }
- }
+ l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ MOVA (l);
- switch (p_type) {
- case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
+ /* if the bit lenth is less than or */
+ /* it exactly fits a byte then */
+ if (SPEC_BLEN (etype) <= 8)
+ {
+ shCount = SPEC_BSTR (etype);
- case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
+ /* shift left acc */
+ AccLsh (shCount);
- case GPOINTER:
- emitcode("lcall","__gptrput");
- break;
- }
+ if (SPEC_BLEN (etype) < 8)
+ { /* if smaller than a byte */
- /* if we r done */
- if ( SPEC_BLEN(etype) <= 8 )
- return ;
- emitcode("inc","%s",rname);
- rLen = SPEC_BLEN(etype) ;
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
- /* now generate for lengths greater than one byte */
- while (1) {
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
- l = aopGet(AOP(right),offset++,FALSE,TRUE);
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
- rLen -= 8 ;
- if (rLen < 8 )
- break ;
+ emitcode ("anl", "a,#0x%02x", (unsigned char)
+ ((unsigned char) (0xFF << (blen + bstr)) |
+ (unsigned char) (0xFF >> (8 - bstr))));
+ emitcode ("orl", "a,b");
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+ }
+ }
- switch (p_type) {
- case POINTER:
- if (*l == '@') {
- MOVA(l);
- emitcode("mov","@%s,a",rname);
- } else
- emitcode("mov","@%s,%s",rname,l);
- break;
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "@%s,a", rname);
+ break;
- case FPOINTER:
- MOVA(l);
- emitcode("movx","@dptr,a");
- break;
+ case FPOINTER:
+ emitcode ("movx", "@dptr,a");
+ break;
- case GPOINTER:
- MOVA(l);
- emitcode("lcall","__gptrput");
- break;
- }
- emitcode ("inc","%s",rname);
+ case GPOINTER:
+ emitcode ("lcall", "__gptrput");
+ break;
}
- MOVA(l);
-
- /* last last was not complete */
- if (rLen) {
- /* save the byte & read byte */
- switch (p_type) {
- case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
- break;
+ /* if we r done */
+ if (SPEC_BLEN (etype) <= 8)
+ return;
- case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
- break;
+ emitcode ("inc", "%s", rname);
+ rLen = SPEC_BLEN (etype);
- case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
- break;
- }
-
- emitcode ("anl","a,#0x%02x",(((unsigned char)-1 << rLen) & 0xff) );
- emitcode ("orl","a,b");
- }
-
- if (p_type == GPOINTER)
- emitcode("pop","b");
+ /* now generate for lengths greater than one byte */
+ while (1)
+ {
- switch (p_type) {
+ l = aopGet (AOP (right), offset++, FALSE, TRUE);
+
+ rLen -= 8;
+ if (rLen < 8)
+ break;
+
+ switch (p_type)
+ {
+ case POINTER:
+ if (*l == '@')
+ {
+ MOVA (l);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, l);
+ break;
+
+ case FPOINTER:
+ MOVA (l);
+ emitcode ("movx", "@dptr,a");
+ break;
+
+ case GPOINTER:
+ MOVA (l);
+ emitcode ("lcall", "__gptrput");
+ break;
+ }
+ emitcode ("inc", "%s", rname);
+ }
+
+ MOVA (l);
+
+ /* last last was not complete */
+ if (rLen)
+ {
+ /* save the byte & read byte */
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
+
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
+
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
+
+ emitcode ("anl", "a,#0x%02x", (((unsigned char) -1 << rLen) & 0xff));
+ emitcode ("orl", "a,b");
+ }
+
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+
+ switch (p_type)
+ {
case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
+ emitcode ("mov", "@%s,a", rname);
+ break;
case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
+ emitcode ("movx", "@dptr,a");
+ break;
case GPOINTER:
- emitcode("lcall","__gptrput");
- break;
+ emitcode ("lcall", "__gptrput");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genDataPointerSet - remat pointer to data space */
/*-----------------------------------------------------------------*/
-static void genDataPointerSet(operand *right,
- operand *result,
- iCode *ic)
+static void
+genDataPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
- int size, offset = 0 ;
- char *l, buffer[256];
+ int size, offset = 0;
+ char *l, buffer[256];
- aopOp(right,ic,FALSE);
+ aopOp (right, ic, FALSE);
- l = aopGet(AOP(result),0,FALSE,TRUE);
- size = AOP_SIZE(right);
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l+1,offset);
- else
- sprintf(buffer,"%s",l+1);
- emitcode("mov","%s,%s",buffer,
- aopGet(AOP(right),offset++,FALSE,FALSE));
+ l = aopGet (AOP (result), 0, FALSE, TRUE);
+ size = AOP_SIZE (right);
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l + 1, offset);
+ else
+ sprintf (buffer, "%s", l + 1);
+ emitcode ("mov", "%s,%s", buffer,
+ aopGet (AOP (right), offset++, FALSE, FALSE));
}
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerSet - emitcode for near pointer put */
/*-----------------------------------------------------------------*/
-static void genNearPointerSet (operand *right,
- operand *result,
- iCode *ic)
-{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname , *l;
- sym_link *retype, *letype;
- sym_link *ptype = operandType(result);
-
- retype= getSpec(operandType(right));
- letype= getSpec(ptype);
- aopOp(result,ic,FALSE);
-
- /* if the result is rematerializable &
- in data space & not a bit variable */
- if (AOP_TYPE(result) == AOP_IMMD &&
- DCL_TYPE(ptype) == POINTER &&
- !IS_BITVAR(retype) &&
- !IS_BITVAR(letype)) {
- genDataPointerSet (right,result,ic);
- return;
+static void
+genNearPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
+{
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname, *l;
+ sym_link *retype, *letype;
+ sym_link *ptype = operandType (result);
+
+ retype = getSpec (operandType (right));
+ letype = getSpec (ptype);
+ aopOp (result, ic, FALSE);
+
+ /* if the result is rematerializable &
+ in data space & not a bit variable */
+ if (AOP_TYPE (result) == AOP_IMMD &&
+ DCL_TYPE (ptype) == POINTER &&
+ !IS_BITVAR (retype) &&
+ !IS_BITVAR (letype))
+ {
+ 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))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(result),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(result),0,FALSE,FALSE);
-
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits ((IS_BITVAR(retype) ? retype : letype),right,rname,POINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
-
- while (size--) {
- l = aopGet(AOP(right),offset,FALSE,TRUE);
- if (*l == '@' ) {
- MOVA(l);
- emitcode("mov","@%s,a",rname);
- } else
- emitcode("mov","@%s,%s",rname,l);
- if (size)
- emitcode("inc","%s",rname);
- offset++;
- }
- }
-
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(right) - 1;
- while (size--)
- emitcode("dec","%s",rname);
- }
- }
-
- /* done */
- freeAsmop(right,NULL,ic,TRUE);
+ /* if the value is already in a pointer register
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0, FALSE, TRUE));
+ rname = preg->name;
+ }
+ else
+ rname = aopGet (AOP (result), 0, FALSE, FALSE);
+
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, rname, POINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
+
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset, FALSE, TRUE);
+ if (*l == '@')
+ {
+ MOVA (l);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, l);
+ if (size)
+ emitcode ("inc", "%s", rname);
+ offset++;
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
+ }
+
+ /* done */
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerSet - emitcode for Paged pointer put */
/*-----------------------------------------------------------------*/
-static void genPagedPointerSet (operand *right,
- operand *result,
- iCode *ic)
-{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname , *l;
- sym_link *retype, *letype;
-
- retype= getSpec(operandType(right));
- letype= getSpec(operandType(result));
-
- aopOp(result,ic,FALSE);
-
- /* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(result))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(result),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(result),0,FALSE,FALSE);
-
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits ((IS_BITVAR(retype) ? retype : letype),right,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
-
- while (size--) {
- l = aopGet(AOP(right),offset,FALSE,TRUE);
-
- MOVA(l);
- emitcode("movx","@%s,a",rname);
+static void
+genPagedPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
+{
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname, *l;
+ sym_link *retype, *letype;
- if (size)
- emitcode("inc","%s",rname);
+ retype = getSpec (operandType (right));
+ letype = getSpec (operandType (result));
- offset++;
- }
+ aopOp (result, ic, FALSE);
+
+ /* if the value is already in a pointer register
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0, FALSE, TRUE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (result), 0, FALSE, FALSE);
+
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(right) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+ l = aopGet (AOP (right), offset, FALSE, TRUE);
+
+ MOVA (l);
+ emitcode ("movx", "@%s,a", rname);
+
+ if (size)
+ emitcode ("inc", "%s", rname);
+
+ offset++;
+ }
}
- /* done */
- freeAsmop(right,NULL,ic,TRUE);
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
+ }
+
+ /* done */
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerSet - set value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerSet (operand *right,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
- sym_link *letype = getSpec(operandType(result));
- aopOp(result,ic,FALSE);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits((IS_BITVAR(retype) ? retype : letype),right,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
-
- while (size--) {
- char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
- MOVA(l);
- emitcode("movx","@dptr,a");
- if (size)
- emitcode("inc","dptr");
- }
- }
-
- freeAsmop(right,NULL,ic,TRUE);
+static void
+genFarPointerSet (operand * right,
+ operand * result, iCode * ic)
+{
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
+ sym_link *letype = getSpec (operandType (result));
+ aopOp (result, ic, FALSE);
+
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0, TRUE, FALSE));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (result), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
+
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("movx", "@dptr,a");
+ if (size)
+ emitcode ("inc", "dptr");
+ }
+ }
+
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerSet - set value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerSet (operand *right,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
- sym_link *letype = getSpec(operandType(result));
-
- aopOp(result,ic,FALSE);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE));
- emitcode("mov","b,%s + 1",aopGet(AOP(result),0,TRUE,FALSE));
- }
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
- emitcode("mov","b,%s",aopGet(AOP(result),3,FALSE,FALSE));
- }
- else
- {
- emitcode("mov","b,%s",aopGet(AOP(result),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype) || IS_BITVAR(letype))
- genPackBits((IS_BITVAR(retype) ? retype : letype),right,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
-
- while (size--) {
- char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
- MOVA(l);
- emitcode("lcall","__gptrput");
- if (size)
- emitcode("inc","dptr");
- }
- }
-
- freeAsmop(right,NULL,ic,TRUE);
+static void
+genGenPointerSet (operand * right,
+ operand * result, iCode * ic)
+{
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
+ sym_link *letype = getSpec (operandType (result));
+
+ aopOp (result, ic, FALSE);
+
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0, TRUE, FALSE));
+ emitcode ("mov", "b,%s + 1", aopGet (AOP (result), 0, TRUE, FALSE));
+ }
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (result), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2, FALSE, FALSE));
+ emitcode ("mov", "b,%s", aopGet (AOP (result), 3, FALSE, FALSE));
+ }
+ else
+ {
+ emitcode ("mov", "b,%s", aopGet (AOP (result), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype) || IS_BITVAR (letype))
+ genPackBits ((IS_BITVAR (retype) ? retype : letype), right, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
+
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("lcall", "__gptrput");
+ if (size)
+ emitcode ("inc", "dptr");
+ }
+ }
+
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
-static void genPointerSet (iCode *ic)
+static void
+genPointerSet (iCode * ic)
{
- operand *right, *result ;
- sym_link *type, *etype;
- int p_type;
+ operand *right, *result;
+ sym_link *type, *etype;
+ int p_type;
- right = IC_RIGHT(ic);
- result = IC_RESULT(ic) ;
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(result);
- etype = getSpec(type);
- /* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next)) {
- p_type = DCL_TYPE(type);
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (result);
+ etype = getSpec (type);
+ /* if left is of type of pointer then it is simple */
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ {
+ p_type = DCL_TYPE (type);
}
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
}
- /* now that we have the pointer type we assign
- the pointer values */
- switch (p_type) {
+ /* now that we have the pointer type we assign
+ the pointer values */
+ switch (p_type)
+ {
case POINTER:
case IPOINTER:
- genNearPointerSet (right,result,ic);
- break;
+ genNearPointerSet (right, result, ic);
+ break;
case PPOINTER:
- genPagedPointerSet (right,result,ic);
- break;
+ genPagedPointerSet (right, result, ic);
+ break;
case FPOINTER:
- genFarPointerSet (right,result,ic);
- break;
+ genFarPointerSet (right, result, ic);
+ break;
case GPOINTER:
- genGenPointerSet (right,result,ic);
- break;
+ genGenPointerSet (right, result, ic);
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genIfx - generate code for Ifx statement */
/*-----------------------------------------------------------------*/
-static void genIfx (iCode *ic, iCode *popIc)
+static void
+genIfx (iCode * ic, iCode * popIc)
{
- operand *cond = IC_COND(ic);
- int isbit =0;
-
- aopOp(cond,ic,FALSE);
+ operand *cond = IC_COND (ic);
+ int isbit = 0;
- /* get the value into acc */
- if (AOP_TYPE(cond) != AOP_CRY)
- toBoolean(cond);
- else
- isbit = 1;
- /* the result is now in the accumulator */
- freeAsmop(cond,NULL,ic,TRUE);
+ aopOp (cond, ic, FALSE);
- /* 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);
+ /* get the value into acc */
+ if (AOP_TYPE (cond) != AOP_CRY)
+ toBoolean (cond);
+ else
+ isbit = 1;
+ /* 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");
+ genIfxJump (ic, "a");
- ic->generated = 1;
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAddrOf - generates code for address of */
/*-----------------------------------------------------------------*/
-static void genAddrOf (iCode *ic)
-{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
- int size, offset ;
-
- aopOp(IC_RESULT(ic),ic,FALSE);
-
- /* if the operand is on the stack then we
- need to get the stack offset of this
- variable */
- if (sym->onStack) {
- /* if it has an offset then we need to compute
- it */
- if (sym->stack) {
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",((char) sym->stack & 0xff));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- } else {
- /* we can just move _bp */
- 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;
- while (size--)
- {
- /* Yuck! */
- if (options.stack10bit && offset == 2)
- {
- aopPut(AOP(IC_RESULT(ic)),"#0x40", offset++);
- }
- else
- {
- aopPut(AOP(IC_RESULT(ic)),zero,offset++);
- }
- }
-
- goto release;
- }
-
- /* object not on stack then we need the name */
- size = AOP_SIZE(IC_RESULT(ic));
- offset = 0;
-
- while (size--) {
- char s[SDCC_NAME_MAX];
- if (offset)
- sprintf(s,"#(%s >> %d)",
- sym->rname,
- offset*8);
- else
- sprintf(s,"#%s",sym->rname);
- aopPut(AOP(IC_RESULT(ic)),s,offset++);
+static void
+genAddrOf (iCode * ic)
+{
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+ int size, offset;
+
+ aopOp (IC_RESULT (ic), ic, FALSE);
+
+ /* if the operand is on the stack then we
+ need to get the stack offset of this
+ variable */
+ if (sym->onStack)
+ {
+ /* if it has an offset then we need to compute
+ it */
+ if (sym->stack)
+ {
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ }
+ else
+ {
+ /* we can just move _bp */
+ 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;
+ while (size--)
+ {
+ /* Yuck! */
+ if (options.stack10bit && offset == 2)
+ {
+ aopPut (AOP (IC_RESULT (ic)), "#0x40", offset++);
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), zero, offset++);
+ }
+ }
+
+ goto release;
+ }
+
+ /* object not on stack then we need the name */
+ size = AOP_SIZE (IC_RESULT (ic));
+ offset = 0;
+
+ while (size--)
+ {
+ char s[SDCC_NAME_MAX];
+ if (offset)
+ sprintf (s, "#(%s >> %d)",
+ sym->rname,
+ offset * 8);
+ else
+ sprintf (s, "#%s", sym->rname);
+ aopPut (AOP (IC_RESULT (ic)), s, offset++);
}
release:
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarFarAssign - assignment when both are in far space */
/*-----------------------------------------------------------------*/
-static void genFarFarAssign (operand *result, operand *right, iCode *ic)
+static void
+genFarFarAssign (operand * result, operand * right, iCode * ic)
{
- int size = AOP_SIZE(right);
- int offset = 0;
- char *l ;
- /* first push the right side on to the stack */
- while (size--) {
- l = aopGet(AOP(right),offset++,FALSE,FALSE);
- MOVA(l);
- emitcode ("push","acc");
+ int size = AOP_SIZE (right);
+ int offset = 0;
+ char *l;
+ /* first push the right side on to the stack */
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("push", "acc");
}
- freeAsmop(right,NULL,ic,FALSE);
- /* now assign DPTR to result */
- aopOp(result,ic,FALSE);
- size = AOP_SIZE(result);
- while (size--) {
- emitcode ("pop","acc");
- aopPut(AOP(result),"a",--offset);
+ freeAsmop (right, NULL, ic, FALSE);
+ /* now assign DPTR to result */
+ aopOp (result, ic, FALSE);
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ emitcode ("pop", "acc");
+ aopPut (AOP (result), "a", --offset);
}
- freeAsmop(result,NULL,ic,FALSE);
+ freeAsmop (result, NULL, ic, FALSE);
}
/*-----------------------------------------------------------------*/
/* genAssign - generate code for assignment */
/*-----------------------------------------------------------------*/
-static void genAssign (iCode *ic)
+static void
+genAssign (iCode * ic)
{
- operand *result, *right;
- int size, offset ;
+ operand *result, *right;
+ int size, offset;
unsigned long lit = 0L;
- result = IC_RESULT(ic);
- right = IC_RIGHT(ic) ;
-
- /* if they are the same */
- if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
-
- aopOp(right,ic,FALSE);
-
- /* special case both in far space */
- if ((AOP_TYPE(right) == AOP_DPTR ||
- AOP_TYPE(right) == AOP_DPTR2) &&
- IS_TRUE_SYMOP(result) &&
- isOperandInFarSpace(result)) {
-
- genFarFarAssign (result,right,ic);
- return ;
- }
-
- aopOp(result,ic,TRUE);
-
- /* if they are the same registers */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
-
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
-
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- if (((int) operandLitValue(right)))
- aopPut(AOP(result),one,0);
- else
- aopPut(AOP(result),zero,0);
- goto release;
- }
-
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- aopPut(AOP(result),"c",0);
- goto release ;
- }
-
- /* we need to or */
- toBoolean(right);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- /* bit variables done */
- /* general case */
- size = AOP_SIZE(result);
- offset = 0 ;
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if((size > 1) &&
- (AOP_TYPE(result) != AOP_REG) &&
- (AOP_TYPE(right) == AOP_LIT) &&
- !IS_FLOAT(operandType(right)) &&
- (lit < 256L)){
- emitcode("clr","a");
- while (size--) {
- if((unsigned int)((lit >> (size*8)) & 0x0FFL)== 0)
- aopPut(AOP(result),"a",size);
- else
- aopPut(AOP(result),
- aopGet(AOP(right),size,FALSE,FALSE),
- size);
- }
- } else {
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
+ result = IC_RESULT (ic);
+ right = IC_RIGHT (ic);
+
+ /* if they are the same */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
+
+ aopOp (right, ic, FALSE);
+
+ /* special case both in far space */
+ if ((AOP_TYPE (right) == AOP_DPTR ||
+ AOP_TYPE (right) == AOP_DPTR2) &&
+ IS_TRUE_SYMOP (result) &&
+ isOperandInFarSpace (result))
+ {
+
+ genFarFarAssign (result, right, ic);
+ return;
+ }
+
+ aopOp (result, ic, TRUE);
+
+ /* if they are the same registers */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
+
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((int) operandLitValue (right)))
+ aopPut (AOP (result), one, 0);
+ else
+ aopPut (AOP (result), zero, 0);
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ aopPut (AOP (result), "c", 0);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ /* bit variables done */
+ /* general case */
+ size = AOP_SIZE (result);
+ offset = 0;
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ if ((size > 1) &&
+ (AOP_TYPE (result) != AOP_REG) &&
+ (AOP_TYPE (right) == AOP_LIT) &&
+ !IS_FLOAT (operandType (right)) &&
+ (lit < 256L))
+ {
+ emitcode ("clr", "a");
+ while (size--)
+ {
+ if ((unsigned int) ((lit >> (size * 8)) & 0x0FFL) == 0)
+ aopPut (AOP (result), "a", size);
+ else
+ aopPut (AOP (result),
+ aopGet (AOP (right), size, FALSE, FALSE),
+ size);
+ }
+ }
+ else
+ {
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
}
release:
- freeAsmop (right,NULL,ic,TRUE);
- freeAsmop (result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genJumpTab - genrates code for jump table */
/*-----------------------------------------------------------------*/
-static void genJumpTab (iCode *ic)
+static void
+genJumpTab (iCode * ic)
{
- symbol *jtab;
- char *l;
+ symbol *jtab;
+ char *l;
- aopOp(IC_JTCOND(ic),ic,FALSE);
- /* get the condition into accumulator */
- l = aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE);
- MOVA(l);
- /* multiply by three */
- emitcode("add","a,acc");
- emitcode("add","a,%s",aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE));
- freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
+ aopOp (IC_JTCOND (ic), ic, FALSE);
+ /* get the condition into accumulator */
+ l = aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE);
+ MOVA (l);
+ /* multiply by three */
+ emitcode ("add", "a,acc");
+ emitcode ("add", "a,%s", aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE));
+ freeAsmop (IC_JTCOND (ic), NULL, ic, TRUE);
- jtab = newiTempLabel(NULL);
- emitcode("mov","dptr,#%05d$",jtab->key+100);
- emitcode("jmp","@a+dptr");
- emitcode("","%05d$:",jtab->key+100);
- /* now generate the jump labels */
- for (jtab = setFirstItem(IC_JTLABELS(ic)) ; jtab;
- jtab = setNextItem(IC_JTLABELS(ic)))
- emitcode("ljmp","%05d$",jtab->key+100);
+ jtab = newiTempLabel (NULL);
+ emitcode ("mov", "dptr,#%05d$", jtab->key + 100);
+ emitcode ("jmp", "@a+dptr");
+ emitcode ("", "%05d$:", jtab->key + 100);
+ /* now generate the jump labels */
+ for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
+ jtab = setNextItem (IC_JTLABELS (ic)))
+ emitcode ("ljmp", "%05d$", jtab->key + 100);
}
/*-----------------------------------------------------------------*/
/* genCast - gen code for casting */
/*-----------------------------------------------------------------*/
-static void genCast (iCode *ic)
+static void
+genCast (iCode * ic)
{
- operand *result = IC_RESULT(ic);
- sym_link *ctype = operandType(IC_LEFT(ic));
- sym_link *rtype = operandType(IC_RIGHT(ic));
- operand *right = IC_RIGHT(ic);
- int size, offset ;
-
- /* if they are equivalent then do nothing */
- if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
+ operand *result = IC_RESULT (ic);
+ sym_link *ctype = operandType (IC_LEFT (ic));
+ sym_link *rtype = operandType (IC_RIGHT (ic));
+ operand *right = IC_RIGHT (ic);
+ int size, offset;
- aopOp(right,ic,FALSE) ;
- aopOp(result,ic,FALSE);
+ /* if they are equivalent then do nothing */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- if (((int) operandLitValue(right)))
- aopPut(AOP(result),one,0);
- else
- aopPut(AOP(result),zero,0);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, FALSE);
- goto release;
- }
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((int) operandLitValue (right)))
+ aopPut (AOP (result), one, 0);
+ else
+ aopPut (AOP (result), zero, 0);
+
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ aopPut (AOP (result), "c", 0);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ /* if they are the same size : or less */
+ if (AOP_SIZE (result) <= AOP_SIZE (right))
+ {
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- aopPut(AOP(result),"c",0);
- goto release ;
- }
+ /* if they are in the same place */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
- /* we need to or */
- toBoolean(right);
- aopPut(AOP(result),"a",0);
- goto release ;
+ /* if they in different places then copy */
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ goto release;
}
- /* if they are the same size : or less */
- if (AOP_SIZE(result) <= AOP_SIZE(right)) {
- /* if they are in the same place */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
+ /* if the result is of type pointer */
+ if (IS_PTR (ctype))
+ {
- /* if they in different places then copy */
- size = AOP_SIZE(result);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
- goto release;
+ int p_type;
+ sym_link *type = operandType (right);
+ sym_link *etype = getSpec (type);
+
+ /* pointer to generic pointer */
+ if (IS_GENPTR (ctype))
+ {
+ char *l = zero;
+
+ if (IS_PTR (type))
+ p_type = DCL_TYPE (type);
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
+ }
+
+ /* the first two bytes are known */
+ size = GPTRSIZE - 1;
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ /* the last byte depending on type */
+ switch (p_type)
+ {
+ case IPOINTER:
+ case POINTER:
+ l = zero;
+ break;
+ case FPOINTER:
+ l = one;
+ break;
+ case CPOINTER:
+ l = "#0x02";
+ break;
+ case PPOINTER:
+ l = "#0x03";
+ break;
+
+ default:
+ /* this should never happen */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got unknown pointer type");
+ exit (1);
+ }
+ aopPut (AOP (result), l, GPTRSIZE - 1);
+ goto release;
+ }
+
+ /* just copy the pointers */
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ goto release;
+ }
+
+ /* so we now know that the size of destination is greater
+ than the size of the source */
+ /* we move to result for the size of source */
+ size = AOP_SIZE (right);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
}
+ /* now depending on the sign of the source && destination */
+ size = AOP_SIZE (result) - AOP_SIZE (right);
+ /* if unsigned or not an integral type */
+ if (SPEC_USIGN (rtype) || !IS_SPEC (rtype))
+ {
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ }
+ else
+ {
+ /* we need to extend the sign :{ */
+ char *l = aopGet (AOP (right), AOP_SIZE (right) - 1,
+ FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
+ }
- /* if the result is of type pointer */
- if (IS_PTR(ctype)) {
-
- int p_type;
- sym_link *type = operandType(right);
- sym_link *etype = getSpec(type);
-
- /* pointer to generic pointer */
- if (IS_GENPTR(ctype)) {
- char *l = zero;
-
- if (IS_PTR(type))
- p_type = DCL_TYPE(type);
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
- }
-
- /* the first two bytes are known */
- size = GPTRSIZE - 1;
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
- /* the last byte depending on type */
- switch (p_type) {
- case IPOINTER:
- case POINTER:
- l = zero;
- break;
- case FPOINTER:
- l = one;
- break;
- case CPOINTER:
- l = "#0x02";
- break;
- case PPOINTER:
- l = "#0x03";
- break;
-
- default:
- /* this should never happen */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got unknown pointer type");
- exit(1);
- }
- aopPut(AOP(result),l, GPTRSIZE - 1);
- goto release ;
- }
-
- /* just copy the pointers */
- size = AOP_SIZE(result);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
- goto release ;
- }
-
- /* so we now know that the size of destination is greater
- than the size of the source */
- /* we move to result for the size of source */
- size = AOP_SIZE(right);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
-
- /* now depending on the sign of the source && destination */
- size = AOP_SIZE(result) - AOP_SIZE(right);
- /* if unsigned or not an integral type */
- if (SPEC_USIGN(rtype) || !IS_SPEC(rtype)) {
- while (size--)
- aopPut(AOP(result),zero,offset++);
- } else {
- /* we need to extend the sign :{ */
- char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,
- FALSE,FALSE);
- MOVA(l);
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- while (size--)
- aopPut(AOP(result),"a",offset++);
- }
-
- /* we are done hurray !!!! */
+ /* we are done hurray !!!! */
release:
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDjnz - generate decrement & jump if not zero instrucion */
/*-----------------------------------------------------------------*/
-static int genDjnz (iCode *ic, iCode *ifx)
+static int
+genDjnz (iCode * ic, iCode * ifx)
{
- symbol *lbl, *lbl1;
- if (!ifx)
- return 0;
+ symbol *lbl, *lbl1;
+ if (!ifx)
+ return 0;
- /* if the if condition has a false label
- then we cannot save */
- if (IC_FALSE(ifx))
- return 0;
+ /* if the if condition has a false label
+ then we cannot save */
+ if (IC_FALSE (ifx))
+ return 0;
- /* if the minus is not of the form
- a = a - 1 */
- if (!isOperandEqual(IC_RESULT(ic),IC_LEFT(ic)) ||
- !IS_OP_LITERAL(IC_RIGHT(ic)))
- return 0;
+ /* if the minus is not of the form
+ a = a - 1 */
+ if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
+ !IS_OP_LITERAL (IC_RIGHT (ic)))
+ return 0;
- if (operandLitValue(IC_RIGHT(ic)) != 1)
- return 0;
+ if (operandLitValue (IC_RIGHT (ic)) != 1)
+ return 0;
- /* if the size of this greater than one then no
- saving */
- if (getSize(operandType(IC_RESULT(ic))) > 1)
- return 0;
+ /* if the size of this greater than one then no
+ saving */
+ if (getSize (operandType (IC_RESULT (ic))) > 1)
+ return 0;
- /* otherwise we can save BIG */
- lbl = newiTempLabel(NULL);
- lbl1= newiTempLabel(NULL);
+ /* otherwise we can save BIG */
+ lbl = newiTempLabel (NULL);
+ lbl1 = newiTempLabel (NULL);
- aopOp(IC_RESULT(ic),ic,FALSE);
+ aopOp (IC_RESULT (ic), ic, FALSE);
- if (IS_AOP_PREG(IC_RESULT(ic))) {
- emitcode("dec","%s",
- aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- emitcode("mov","a,%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- emitcode("jnz","%05d$",lbl->key+100);
- } else {
- emitcode ("djnz","%s,%05d$",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
- lbl->key+100);
+ if (IS_AOP_PREG (IC_RESULT (ic)))
+ {
+ emitcode ("dec", "%s",
+ aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ emitcode ("mov", "a,%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ emitcode ("jnz", "%05d$", lbl->key + 100);
}
- emitcode ("sjmp","%05d$",lbl1->key+100);
- emitcode ("","%05d$:",lbl->key+100);
- emitcode ("ljmp","%05d$",IC_TRUE(ifx)->key+100);
- emitcode ("","%05d$:",lbl1->key+100);
+ else
+ {
+ emitcode ("djnz", "%s,%05d$", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE),
+ lbl->key + 100);
+ }
+ emitcode ("sjmp", "%05d$", lbl1->key + 100);
+ emitcode ("", "%05d$:", lbl->key + 100);
+ emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100);
+ emitcode ("", "%05d$:", lbl1->key + 100);
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
- ifx->generated = 1;
- return 1;
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ ifx->generated = 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* genReceive - generate code for a receive iCode */
/*-----------------------------------------------------------------*/
-static void genReceive (iCode *ic)
+static void
+genReceive (iCode * ic)
{
- if (isOperandInFarSpace(IC_RESULT(ic)) &&
- ( OP_SYMBOL(IC_RESULT(ic))->isspilt ||
- IS_TRUE_SYMOP(IC_RESULT(ic))) ) {
+ if (isOperandInFarSpace (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
+ IS_TRUE_SYMOP (IC_RESULT (ic))))
+ {
- int size = getSize(operandType(IC_RESULT(ic)));
- int offset = fReturnSize - size;
- while (size--) {
- emitcode ("push","%s", (strcmp(fReturn[fReturnSize - offset - 1],"a") ?
- fReturn[fReturnSize - offset - 1] : "acc"));
- offset++;
- }
- aopOp(IC_RESULT(ic),ic,FALSE);
- size = AOP_SIZE(IC_RESULT(ic));
- offset = 0;
- while (size--) {
- emitcode ("pop","acc");
- aopPut (AOP(IC_RESULT(ic)),"a",offset++);
- }
+ int size = getSize (operandType (IC_RESULT (ic)));
+ int offset = fReturnSize - size;
+ while (size--)
+ {
+ emitcode ("push", "%s", (strcmp (fReturn[fReturnSize - offset - 1], "a") ?
+ fReturn[fReturnSize - offset - 1] : "acc"));
+ offset++;
+ }
+ aopOp (IC_RESULT (ic), ic, 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);
- _G.accInUse--;
- assignResultValue(IC_RESULT(ic));
+ }
+ else
+ {
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ _G.accInUse--;
+ assignResultValue (IC_RESULT (ic));
}
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* gen51Code - generate code for 8051 based controllers */
/*-----------------------------------------------------------------*/
-void gen51Code (iCode *lic)
+void
+gen51Code (iCode * lic)
{
- iCode *ic;
- int cln = 0;
+ iCode *ic;
+ int cln = 0;
- lineHead = lineCurr = NULL;
+ lineHead = lineCurr = NULL;
- /* print the allocation information */
- if (allocInfo)
- printAllocInfo( currFunc, codeOutFile);
- /* if debug information required */
+ /* print the allocation information */
+ if (allocInfo)
+ printAllocInfo (currFunc, codeOutFile);
+ /* if debug information required */
/* if (options.debug && currFunc) { */
- if (currFunc) {
- cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
- _G.debugLine = 1;
- if (IS_STATIC(currFunc->etype))
- emitcode("","F%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","G$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
- /* stack pointer name */
- if (options.useXstack)
- spname = "_spx";
- else
- spname = "sp";
-
-
- for (ic = lic ; ic ; ic = ic->next ) {
-
- if ( cln != ic->lineno ) {
- if ( options.debug ) {
- _G.debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),ic->lineno,
- ic->level,ic->block);
- _G.debugLine = 0;
- }
- emitcode(";","%s %d",ic->filename,ic->lineno);
- cln = ic->lineno ;
- }
- /* if the result is marked as
- spilt and rematerializable or code for
- this has already been generated then
- do nothing */
- if (resultRemat(ic) || ic->generated )
- continue ;
-
- /* depending on the operation */
- switch (ic->op) {
- case '!' :
- genNot(ic);
- break;
-
- case '~' :
- genCpl(ic);
- break;
-
- case UNARYMINUS:
- genUminus (ic);
- break;
-
- case IPUSH:
- genIpush (ic);
- break;
-
- case IPOP:
- /* IPOP happens only when trying to restore a
- spilt live range, if there is an ifx statement
- following this pop then the if statement might
- be using some of the registers being popped which
- would destory the contents of the register so
- we need to check for this condition and handle it */
- if (ic->next &&
- ic->next->op == IFX &&
- regsInCommon(IC_LEFT(ic),IC_COND(ic->next)))
- genIfx (ic->next,ic);
+ if (currFunc)
+ {
+ cdbSymbol (currFunc, cdbFile, FALSE, TRUE);
+ _G.debugLine = 1;
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
else
- genIpop (ic);
- break;
-
- case CALL:
- genCall (ic);
- break;
-
- case PCALL:
- genPcall (ic);
- break;
-
- case FUNCTION:
- genFunction (ic);
- break;
-
- case ENDFUNCTION:
- genEndFunction (ic);
- break;
-
- case RETURN:
- genRet (ic);
- break;
-
- case LABEL:
- genLabel (ic);
- break;
-
- case GOTO:
- genGoto (ic);
- break;
-
- case '+' :
- genPlus (ic) ;
- break;
-
- case '-' :
- if ( ! genDjnz (ic,ifxForOp(IC_RESULT(ic),ic)))
- genMinus (ic);
- break;
-
- case '*' :
- genMult (ic);
- break;
-
- case '/' :
- genDiv (ic) ;
- break;
-
- case '%' :
- genMod (ic);
- break;
-
- case '>' :
- genCmpGt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case '<' :
- genCmpLt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case LE_OP:
- case GE_OP:
- case NE_OP:
-
- /* note these two are xlated by algebraic equivalence
- during parsing SDCC.y */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got '>=' or '<=' shouldn't have come here");
- break;
-
- case EQ_OP:
- genCmpEq (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case AND_OP:
- genAndOp (ic);
- break;
+ emitcode ("", "G$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
+ /* stack pointer name */
+ if (options.useXstack)
+ spname = "_spx";
+ else
+ spname = "sp";
- case OR_OP:
- genOrOp (ic);
- break;
- case '^' :
- genXor (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ for (ic = lic; ic; ic = ic->next)
+ {
- case '|' :
- genOr (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ if (cln != ic->lineno)
+ {
+ if (options.debug)
+ {
+ _G.debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), ic->lineno,
+ ic->level, ic->block);
+ _G.debugLine = 0;
+ }
+ emitcode (";", "%s %d", ic->filename, ic->lineno);
+ cln = ic->lineno;
+ }
+ /* if the result is marked as
+ spilt and rematerializable or code for
+ this has already been generated then
+ do nothing */
+ if (resultRemat (ic) || ic->generated)
+ continue;
+
+ /* depending on the operation */
+ switch (ic->op)
+ {
+ case '!':
+ genNot (ic);
+ break;
+
+ case '~':
+ genCpl (ic);
+ break;
+
+ case UNARYMINUS:
+ genUminus (ic);
+ break;
+
+ case IPUSH:
+ genIpush (ic);
+ break;
+
+ case IPOP:
+ /* IPOP happens only when trying to restore a
+ spilt live range, if there is an ifx statement
+ following this pop then the if statement might
+ be using some of the registers being popped which
+ would destory the contents of the register so
+ we need to check for this condition and handle it */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
+ genIfx (ic->next, ic);
+ else
+ genIpop (ic);
+ break;
+
+ case CALL:
+ genCall (ic);
+ break;
+
+ case PCALL:
+ genPcall (ic);
+ break;
+
+ case FUNCTION:
+ genFunction (ic);
+ break;
+
+ case ENDFUNCTION:
+ genEndFunction (ic);
+ break;
+
+ case RETURN:
+ genRet (ic);
+ break;
+
+ case LABEL:
+ genLabel (ic);
+ break;
+
+ case GOTO:
+ genGoto (ic);
+ break;
+
+ case '+':
+ genPlus (ic);
+ break;
+
+ case '-':
+ if (!genDjnz (ic, ifxForOp (IC_RESULT (ic), ic)))
+ genMinus (ic);
+ break;
+
+ case '*':
+ genMult (ic);
+ break;
+
+ case '/':
+ genDiv (ic);
+ break;
+
+ case '%':
+ genMod (ic);
+ break;
+
+ case '>':
+ genCmpGt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '<':
+ genCmpLt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case LE_OP:
+ case GE_OP:
+ case NE_OP:
+
+ /* note these two are xlated by algebraic equivalence
+ during parsing SDCC.y */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got '>=' or '<=' shouldn't have come here");
+ break;
+
+ case EQ_OP:
+ genCmpEq (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case AND_OP:
+ genAndOp (ic);
+ break;
+
+ case OR_OP:
+ genOrOp (ic);
+ break;
+
+ case '^':
+ genXor (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '|':
+ genOr (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case BITWISEAND:
+ genAnd (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case INLINEASM:
+ genInline (ic);
+ break;
- case BITWISEAND:
- genAnd (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ case RRC:
+ genRRC (ic);
+ break;
- case INLINEASM:
- genInline (ic);
- break;
+ case RLC:
+ genRLC (ic);
+ break;
- case RRC:
- genRRC (ic);
- break;
+ case GETHBIT:
+ genGetHbit (ic);
+ break;
- case RLC:
- genRLC (ic);
- break;
+ case LEFT_OP:
+ genLeftShift (ic);
+ break;
- case GETHBIT:
- genGetHbit (ic);
- break;
+ case RIGHT_OP:
+ genRightShift (ic);
+ break;
- case LEFT_OP:
- genLeftShift (ic);
- break;
+ case GET_VALUE_AT_ADDRESS:
+ genPointerGet (ic);
+ break;
- case RIGHT_OP:
- genRightShift (ic);
- break;
+ case '=':
+ if (POINTER_SET (ic))
+ genPointerSet (ic);
+ else
+ genAssign (ic);
+ break;
- case GET_VALUE_AT_ADDRESS:
- genPointerGet(ic);
- break;
+ case IFX:
+ genIfx (ic, NULL);
+ break;
- case '=' :
- if (POINTER_SET(ic))
- genPointerSet(ic);
- else
- genAssign(ic);
- break;
+ case ADDRESS_OF:
+ genAddrOf (ic);
+ break;
- case IFX:
- genIfx (ic,NULL);
- break;
+ case JUMPTABLE:
+ genJumpTab (ic);
+ break;
- case ADDRESS_OF:
- genAddrOf (ic);
- break;
+ case CAST:
+ genCast (ic);
+ break;
- case JUMPTABLE:
- genJumpTab (ic);
- break;
+ case RECEIVE:
+ genReceive (ic);
+ break;
- case CAST:
- genCast (ic);
- break;
+ case SEND:
+ addSet (&_G.sendSet, ic);
+ break;
- case RECEIVE:
- genReceive(ic);
- break;
-
- case SEND:
- addSet(&_G.sendSet,ic);
- break;
+ default:
+ ic = ic;
+ /* piCode(ic,stdout); */
- default :
- ic = ic;
- /* piCode(ic,stdout); */
-
- }
+ }
}
- /* now we are ready to call the
- peep hole optimizer */
- if (!options.nopeep)
- peepHole (&lineHead);
+ /* now we are ready to call the
+ peep hole optimizer */
+ if (!options.nopeep)
+ peepHole (&lineHead);
- /* now do the actual printing */
- printLine (lineHead,codeOutFile);
- return;
+ /* now do the actual printing */
+ printLine (lineHead, codeOutFile);
+ return;
}
#ifndef SDCCGEN51_H
#define SDCCGEN51_H
-enum {
+enum
+ {
AOP_LIT = 1,
- AOP_REG, AOP_DIR,
- AOP_DPTR, AOP_DPTR2, AOP_R0,AOP_R1,
- AOP_STK ,AOP_IMMD, AOP_STR,
- AOP_CRY, AOP_ACC };
+ AOP_REG, AOP_DIR,
+ AOP_DPTR, AOP_DPTR2, AOP_R0, AOP_R1,
+ AOP_STK, AOP_IMMD, AOP_STR,
+ AOP_CRY, AOP_ACC
+ };
/* type asmop : a homogenised type for
all the different spaces an operand can be
in */
-typedef struct asmop {
-
- short type ; /* can have values
- AOP_LIT - operand is a literal value
- AOP_REG - is in registers
- AOP_DIR - direct just a name
- AOP_DPTR - dptr contains address of operand
- AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
- AOP_R0/R1 - r0/r1 contains address of operand
- AOP_STK - should be pushed on stack this
- can happen only for the result
- AOP_IMMD - immediate value for eg. remateriazable
- AOP_CRY - carry contains the value of this
- AOP_STR - array of strings
- AOP_ACC - result is in the acc:b pair
- */
- short coff ; /* current offset */
- short size ; /* total size */
- unsigned code :1 ; /* is in Code space */
- unsigned paged:1 ; /* in paged memory */
- unsigned freed:1 ; /* already freed */
- union {
- value *aop_lit ; /* if literal */
- regs *aop_reg[4]; /* array of registers */
- char *aop_dir ; /* if direct */
- regs *aop_ptr ; /* either -> to r0 or r1 */
- char *aop_immd; /* if immediate others are implied */
- int aop_stk ; /* stack offset when AOP_STK */
- char *aop_str[4]; /* just a string array containing the location */
- } aopu;
-} asmop;
+typedef struct asmop
+ {
+
+ short type; /* can have values
+ AOP_LIT - operand is a literal value
+ AOP_REG - is in registers
+ AOP_DIR - direct just a name
+ AOP_DPTR - dptr contains address of operand
+ AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
+ AOP_R0/R1 - r0/r1 contains address of operand
+ AOP_STK - should be pushed on stack this
+ can happen only for the result
+ AOP_IMMD - immediate value for eg. remateriazable
+ AOP_CRY - carry contains the value of this
+ AOP_STR - array of strings
+ AOP_ACC - result is in the acc:b pair
+ */
+ short coff; /* current offset */
+ short size; /* total size */
+ unsigned code:1; /* is in Code space */
+ unsigned paged:1; /* in paged memory */
+ unsigned freed:1; /* already freed */
+ union
+ {
+ value *aop_lit; /* if literal */
+ regs *aop_reg[4]; /* array of registers */
+ char *aop_dir; /* if direct */
+ regs *aop_ptr; /* either -> to r0 or r1 */
+ char *aop_immd; /* if immediate others are implied */
+ int aop_stk; /* stack offset when AOP_STK */
+ char *aop_str[4]; /* just a string array containing the location */
+ }
+ aopu;
+ }
+asmop;
void gen51Code (iCode *);
};
/* list of key words used by msc51 */
-static char *_mcs51_keywords[] = {
- "at",
- "bit",
- "code",
- "critical",
- "data",
- "far",
- "idata",
- "interrupt",
- "near",
- "pdata",
- "reentrant",
- "sfr",
- "sbit",
- "using",
- "xdata",
- "_data",
- "_code",
- "_generic",
- "_near",
- "_xdata",
- "_pdata",
- "_idata",
- NULL
+static char *_mcs51_keywords[] =
+{
+ "at",
+ "bit",
+ "code",
+ "critical",
+ "data",
+ "far",
+ "idata",
+ "interrupt",
+ "near",
+ "pdata",
+ "reentrant",
+ "sfr",
+ "sbit",
+ "using",
+ "xdata",
+ "_data",
+ "_code",
+ "_generic",
+ "_near",
+ "_xdata",
+ "_pdata",
+ "_idata",
+ NULL
};
-void mcs51_assignRegisters (eBBlock **ebbs, int count);
+void mcs51_assignRegisters (eBBlock ** ebbs, int count);
-static int regParmFlg = 0; /* determine if we can register a parameter */
+static int regParmFlg = 0; /* determine if we can register a parameter */
-static void _mcs51_init(void)
+static void
+_mcs51_init (void)
{
- asm_addTree(&asm_asxxxx_mapping);
+ asm_addTree (&asm_asxxxx_mapping);
}
-static void _mcs51_reset_regparm()
+static void
+_mcs51_reset_regparm ()
{
- regParmFlg = 0;
+ regParmFlg = 0;
}
-static int _mcs51_regparm( sym_link *l)
+static int
+_mcs51_regparm (sym_link * l)
{
- /* for this processor it is simple
- can pass only the first parameter in a register */
- if (regParmFlg)
- return 0;
+ /* for this processor it is simple
+ can pass only the first parameter in a register */
+ if (regParmFlg)
+ return 0;
- regParmFlg = 1;
- return 1;
+ regParmFlg = 1;
+ return 1;
}
-static bool _mcs51_parseOptions(int *pargc, char **argv, int *i)
+static bool
+_mcs51_parseOptions (int *pargc, char **argv, int *i)
{
- /* TODO: allow port-specific command line options to specify
- * segment names here.
- */
- return FALSE;
+ /* TODO: allow port-specific command line options to specify
+ * segment names here.
+ */
+ return FALSE;
}
-static void _mcs51_finaliseOptions(void)
+static void
+_mcs51_finaliseOptions (void)
{
- /* Hack-o-matic: if we are using the flat24 model,
- * adjust pointer sizes.
- */
- if (options.model == MODEL_FLAT24)
+ /* Hack-o-matic: if we are using the flat24 model,
+ * adjust pointer sizes.
+ */
+ if (options.model == MODEL_FLAT24)
{
-
- fprintf(stderr, "*** WARNING: you should use the '-mds390' option "
- "for DS80C390 support. This code generator is "
- "badly out of date and probably broken.\n");
-
- port->s.fptr_size = 3;
- port->s.gptr_size = 4;
- port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
- #if 1
- port->stack.call_overhead++; /* This acounts for the extra byte
- * of return addres on the stack.
- * but is ugly. There must be a
- * better way.
- */
- #endif
- fReturn = fReturn390;
- fReturnSize = 5;
- }
- if (options.model == MODEL_LARGE) {
- port->mem.default_local_map = xdata;
- port->mem.default_globl_map = xdata;
- } else {
- port->mem.default_local_map = data;
- port->mem.default_globl_map = data;
+ fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
+ "for DS80C390 support. This code generator is "
+ "badly out of date and probably broken.\n");
+
+ port->s.fptr_size = 3;
+ port->s.gptr_size = 4;
+ port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
+#if 1
+ port->stack.call_overhead++; /* This acounts for the extra byte
+ * of return addres on the stack.
+ * but is ugly. There must be a
+ * better way.
+ */
+#endif
+ fReturn = fReturn390;
+ fReturnSize = 5;
+ }
+
+ if (options.model == MODEL_LARGE)
+ {
+ port->mem.default_local_map = xdata;
+ port->mem.default_globl_map = xdata;
+ }
+ else
+ {
+ port->mem.default_local_map = data;
+ port->mem.default_globl_map = data;
}
-
- if (options.stack10bit)
+
+ if (options.stack10bit)
{
- if (options.model != MODEL_FLAT24)
- {
- fprintf(stderr,
- "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
- fprintf(stderr, "\t10 bit stack mode disabled.\n");
- options.stack10bit = 0;
- }
- else
- {
- /* Fixup the memory map for the stack; it is now in
- * far space and requires a FPOINTER to access it.
- */
- istack->fmap = 1;
- istack->ptrType = FPOINTER;
- }
+ if (options.model != MODEL_FLAT24)
+ {
+ fprintf (stderr,
+ "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
+ fprintf (stderr, "\t10 bit stack mode disabled.\n");
+ options.stack10bit = 0;
+ }
+ else
+ {
+ /* Fixup the memory map for the stack; it is now in
+ * far space and requires a FPOINTER to access it.
+ */
+ istack->fmap = 1;
+ istack->ptrType = FPOINTER;
+ }
}
}
-static void _mcs51_setDefaultOptions(void)
+static void
+_mcs51_setDefaultOptions (void)
{
}
-static const char *_mcs51_getRegName(struct regs *reg)
+static const char *
+_mcs51_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- return "err";
+ if (reg)
+ return reg->name;
+ return "err";
}
-static void _mcs51_genAssemblerPreamble(FILE *of)
+static void
+_mcs51_genAssemblerPreamble (FILE * of)
{
- if (options.model == MODEL_FLAT24)
- {
- fputs(".flat24 on\t\t; 24 bit flat addressing\n", of);
- fputs("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
- fputs("dps = 0x86\t\t; dps register unknown to assembler\n", of);
- fputs("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of);
- fputs("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of);
- fputs("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of);
- }
+ if (options.model == MODEL_FLAT24)
+ {
+ fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
+ fputs ("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
+ fputs ("dps = 0x86\t\t; dps register unknown to assembler\n", of);
+ fputs ("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of);
+ fputs ("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of);
+ fputs ("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of);
+ }
}
/* Generate interrupt vector table. */
-static int _mcs51_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
+static int
+_mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
{
- int i;
-
- if (options.model != MODEL_FLAT24)
+ int i;
+
+ if (options.model != MODEL_FLAT24)
{
- /* Let the default code handle it. */
- return FALSE;
+ /* Let the default code handle it. */
+ return FALSE;
}
-
- fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
-
- /* now for the other interrupts */
- for (i = 0; i < maxInterrupts; i++)
+
+ fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
+
+ /* now for the other interrupts */
+ for (i = 0; i < maxInterrupts; i++)
{
- if (interrupts[i])
+ if (interrupts[i])
{
- fprintf(of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
+ fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
}
- else
+ else
{
- fprintf(of, "\treti\n\t.ds\t7\n");
+ fprintf (of, "\treti\n\t.ds\t7\n");
}
}
-
- return TRUE;
+
+ return TRUE;
}
/** $1 is always the basename.
$l is the list of extra options that should be there somewhere...
MUST be terminated with a NULL.
*/
-static const char *_linkCmd[] = {
- "aslink", "-nf", "$1", NULL
+static const char *_linkCmd[] =
+{
+ "aslink", "-nf", "$1", NULL
};
-static const char *_asmCmd[] = {
- "asx8051", "-plosgffc", "$1.asm", NULL
+static const char *_asmCmd[] =
+{
+ "asx8051", "-plosgffc", "$1.asm", NULL
};
/* Globals */
-PORT mcs51_port = {
- "mcs51",
- "MCU 8051", /* Target name */
- {
- TRUE, /* Emit glue around main */
- MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
- MODEL_SMALL
- },
- {
- _asmCmd,
- "-plosgffc", /* Options with debug */
- "-plosgff", /* Options without debug */
- 0
- },
- {
- _linkCmd,
- NULL,
- ".rel"
- },
- {
- _defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 1, 2, 4, 1, 2, 3, 1, 4, 4
- },
- {
- "XSEG (XDATA)",
- "STACK (DATA)",
- "CSEG (CODE)",
- "DSEG (DATA)",
- "ISEG (DATA)",
- "XSEG (XDATA)",
- "BSEG (BIT)",
- "RSEG (DATA)",
- "GSINIT (CODE)",
- "OSEG (OVR,DATA)",
- "GSFINAL (CODE)",
- "HOME (CODE)",
- NULL,
- NULL,
- 1
- },
- {
- +1, 1, 4, 1, 1, 0
- },
- /* mcs51 has an 8 bit mul */
- {
- 1, 0
- },
- "_",
- _mcs51_init,
- _mcs51_parseOptions,
- _mcs51_finaliseOptions,
- _mcs51_setDefaultOptions,
- mcs51_assignRegisters,
- _mcs51_getRegName ,
- _mcs51_keywords,
- _mcs51_genAssemblerPreamble,
- _mcs51_genIVT ,
- _mcs51_reset_regparm,
- _mcs51_regparm,
+PORT mcs51_port =
+{
+ "mcs51",
+ "MCU 8051", /* Target name */
+ {
+ TRUE, /* Emit glue around main */
+ MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
+ MODEL_SMALL
+ },
+ {
+ _asmCmd,
+ "-plosgffc", /* Options with debug */
+ "-plosgff", /* Options without debug */
+ 0
+ },
+ {
+ _linkCmd,
NULL,
- FALSE,
- 0, /* leave lt */
- 0, /* leave gt */
- 1, /* transform <= to ! > */
- 1, /* transform >= to ! < */
- 1, /* transform != to !(a == b) */
- 0, /* leave == */
- PORT_MAGIC
+ ".rel"
+ },
+ {
+ _defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 1, 2, 4, 1, 2, 3, 1, 4, 4
+ },
+ {
+ "XSEG (XDATA)",
+ "STACK (DATA)",
+ "CSEG (CODE)",
+ "DSEG (DATA)",
+ "ISEG (DATA)",
+ "XSEG (XDATA)",
+ "BSEG (BIT)",
+ "RSEG (DATA)",
+ "GSINIT (CODE)",
+ "OSEG (OVR,DATA)",
+ "GSFINAL (CODE)",
+ "HOME (CODE)",
+ NULL,
+ NULL,
+ 1
+ },
+ {
+ +1, 1, 4, 1, 1, 0
+ },
+ /* mcs51 has an 8 bit mul */
+ {
+ 1, 0
+ },
+ "_",
+ _mcs51_init,
+ _mcs51_parseOptions,
+ _mcs51_finaliseOptions,
+ _mcs51_setDefaultOptions,
+ mcs51_assignRegisters,
+ _mcs51_getRegName,
+ _mcs51_keywords,
+ _mcs51_genAssemblerPreamble,
+ _mcs51_genIVT,
+ _mcs51_reset_regparm,
+ _mcs51_regparm,
+ NULL,
+ FALSE,
+ 0, /* leave lt */
+ 0, /* leave gt */
+ 1, /* transform <= to ! > */
+ 1, /* transform >= to ! < */
+ 1, /* transform != to !(a == b) */
+ 0, /* leave == */
+ PORT_MAGIC
};
-
#ifndef MAIN_INCLUDE
#define MAIN_INCLUDE
-bool x_parseOptions(char **argv, int *pargc);
-void x_setDefaultOptions(void);
-void x_finaliseOptions(void);
+bool x_parseOptions (char **argv, int *pargc);
+void x_setDefaultOptions (void);
+void x_finaliseOptions (void);
#endif
/* some routines are non-processor specific & can be reused when */
/* targetting other processors. The decision for this will have */
/* to be made on a routine by routine basis */
-/* routines used to pack registers are most definitely not reusable*/
+/* routines used to pack registers are most definitely not reusable */
/* since the pack the registers depending strictly on the MCU */
/*-----------------------------------------------------------------*/
-extern void gen51Code(iCode *);
+extern void gen51Code (iCode *);
/* Global data */
-static struct {
+static struct
+ {
bitVect *spiltSet;
set *stackSpil;
bitVect *regAssigned;
short blockSpil;
int slocNum;
- bitVect *funcrUsed; /* registers used in a function */
+ bitVect *funcrUsed; /* registers used in a function */
int stackExtend;
int dataExtend;
-} _G;
+ }
+_G;
/* Shared with gen.c */
-int mcs51_ptrRegReq; /* one byte pointer register required */
+int mcs51_ptrRegReq; /* one byte pointer register required */
/* 8051 registers */
-regs regs8051[] =
+regs regs8051[] =
{
- { REG_GPR ,R2_IDX , REG_GPR , "r2", "ar2", "0", 2, 1 },
- { REG_GPR ,R3_IDX , REG_GPR , "r3", "ar3", "0", 3, 1 },
- { REG_GPR ,R4_IDX , REG_GPR , "r4", "ar4", "0", 4, 1 },
- { REG_GPR ,R5_IDX , REG_GPR , "r5", "ar5", "0", 5, 1 },
- { REG_GPR ,R6_IDX , REG_GPR , "r6", "ar6", "0", 6, 1 },
- { REG_GPR ,R7_IDX , REG_GPR , "r7", "ar7", "0", 7, 1 },
- { REG_PTR ,R0_IDX , REG_PTR , "r0" , "ar0", "0", 0, 1 },
- { REG_PTR ,R1_IDX , REG_PTR , "r1" , "ar1", "0", 1, 1 },
- { REG_GPR ,X8_IDX , REG_GPR , "x8", "x8" , "xreg", 0, 1 },
- { REG_GPR ,X9_IDX , REG_GPR , "x9", "x9" , "xreg", 1, 1 },
- { REG_GPR ,X10_IDX,REG_GPR , "x10", "x10", "xreg", 2, 1 },
- { REG_GPR ,X11_IDX,REG_GPR , "x11", "x11", "xreg", 3, 1 },
- { REG_GPR ,X12_IDX,REG_GPR , "x12", "x12", "xreg", 4, 1 },
- { REG_CND ,CND_IDX,REG_CND , "C" , "C" , "xreg", 0, 1 },
+ {REG_GPR, R2_IDX, REG_GPR, "r2", "ar2", "0", 2, 1},
+ {REG_GPR, R3_IDX, REG_GPR, "r3", "ar3", "0", 3, 1},
+ {REG_GPR, R4_IDX, REG_GPR, "r4", "ar4", "0", 4, 1},
+ {REG_GPR, R5_IDX, REG_GPR, "r5", "ar5", "0", 5, 1},
+ {REG_GPR, R6_IDX, REG_GPR, "r6", "ar6", "0", 6, 1},
+ {REG_GPR, R7_IDX, REG_GPR, "r7", "ar7", "0", 7, 1},
+ {REG_PTR, R0_IDX, REG_PTR, "r0", "ar0", "0", 0, 1},
+ {REG_PTR, R1_IDX, REG_PTR, "r1", "ar1", "0", 1, 1},
+ {REG_GPR, X8_IDX, REG_GPR, "x8", "x8", "xreg", 0, 1},
+ {REG_GPR, X9_IDX, REG_GPR, "x9", "x9", "xreg", 1, 1},
+ {REG_GPR, X10_IDX, REG_GPR, "x10", "x10", "xreg", 2, 1},
+ {REG_GPR, X11_IDX, REG_GPR, "x11", "x11", "xreg", 3, 1},
+ {REG_GPR, X12_IDX, REG_GPR, "x12", "x12", "xreg", 4, 1},
+ {REG_CND, CND_IDX, REG_CND, "C", "C", "xreg", 0, 1},
};
int mcs51_nRegs = 13;
static void spillThis (symbol *);
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
-static regs *allocReg (short type)
+static regs *
+allocReg (short type)
{
- int i;
-
- for ( i = 0 ; i < mcs51_nRegs ; i++ ) {
-
- /* if type is given as 0 then any
- free register will do */
- if (!type &&
- regs8051[i].isFree ) {
- regs8051[i].isFree = 0;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- return ®s8051[i];
+ int i;
+
+ for (i = 0; i < mcs51_nRegs; i++)
+ {
+
+ /* if type is given as 0 then any
+ free register will do */
+ if (!type &&
+ regs8051[i].isFree)
+ {
+ regs8051[i].isFree = 0;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ return ®s8051[i];
}
- /* other wise look for specific type
- of register */
- if (regs8051[i].isFree &&
- regs8051[i].type == type) {
- regs8051[i].isFree = 0;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- return ®s8051[i];
+ /* other wise look for specific type
+ of register */
+ if (regs8051[i].isFree &&
+ regs8051[i].type == type)
+ {
+ regs8051[i].isFree = 0;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ return ®s8051[i];
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* mcs51_regWithIdx - returns pointer to register wit index number */
/*-----------------------------------------------------------------*/
-regs *mcs51_regWithIdx (int idx)
+regs *
+mcs51_regWithIdx (int idx)
{
- int i ;
-
- for (i=0;i < mcs51_nRegs;i++)
- if (regs8051[i].rIdx == idx)
- return ®s8051[i];
-
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "regWithIdx not found");
- exit(1);
+ int i;
+
+ for (i = 0; i < mcs51_nRegs; i++)
+ if (regs8051[i].rIdx == idx)
+ return ®s8051[i];
+
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "regWithIdx not found");
+ exit (1);
}
/*-----------------------------------------------------------------*/
/* freeReg - frees a register */
/*-----------------------------------------------------------------*/
-static void freeReg (regs *reg)
+static void
+freeReg (regs * reg)
{
if (!reg)
- {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "freeReg - Freeing NULL register");
- exit(1);
- }
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "freeReg - Freeing NULL register");
+ exit (1);
+ }
reg->isFree = 1;
}
/*-----------------------------------------------------------------*/
/* nFreeRegs - returns number of free registers */
/*-----------------------------------------------------------------*/
-static int nFreeRegs (int type)
+static int
+nFreeRegs (int type)
{
- int i;
- int nfr=0;
-
- for (i = 0 ; i < mcs51_nRegs; i++ )
- if (regs8051[i].isFree && regs8051[i].type == type)
- nfr++;
- return nfr;
+ int i;
+ int nfr = 0;
+
+ for (i = 0; i < mcs51_nRegs; i++)
+ if (regs8051[i].isFree && regs8051[i].type == type)
+ nfr++;
+ return nfr;
}
/*-----------------------------------------------------------------*/
/* nfreeRegsType - free registers with type */
/*-----------------------------------------------------------------*/
-static int nfreeRegsType (int type)
+static int
+nfreeRegsType (int type)
{
- int nfr ;
- if (type == REG_PTR) {
- if ((nfr = nFreeRegs(type)) == 0)
- return nFreeRegs(REG_GPR);
- }
-
- return nFreeRegs(type);
+ int nfr;
+ if (type == REG_PTR)
+ {
+ if ((nfr = nFreeRegs (type)) == 0)
+ return nFreeRegs (REG_GPR);
+ }
+
+ return nFreeRegs (type);
}
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
/*-----------------------------------------------------------------*/
-static bool allDefsOutOfRange (bitVect *defs,int fseq, int toseq)
+static bool
+allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
{
- int i ;
+ int i;
- if (!defs)
- return TRUE ;
+ if (!defs)
+ return TRUE;
- for ( i = 0 ;i < defs->size ; i++ ) {
- iCode *ic;
+ for (i = 0; i < defs->size; i++)
+ {
+ iCode *ic;
+
+ if (bitVectBitValue (defs, i) &&
+ (ic = hTabItemWithKey (iCodehTab, i)) &&
+ (ic->seq >= fseq && ic->seq <= toseq))
+
+ return FALSE;
- if (bitVectBitValue(defs,i) &&
- (ic = hTabItemWithKey(iCodehTab,i)) &&
- ( ic->seq >= fseq && ic->seq <= toseq))
-
- return FALSE;
-
}
-
- return TRUE;
+
+ return TRUE;
}
-
+
/*-----------------------------------------------------------------*/
/* computeSpillable - given a point find the spillable live ranges */
/*-----------------------------------------------------------------*/
-static bitVect *computeSpillable (iCode *ic)
+static bitVect *
+computeSpillable (iCode * ic)
{
- bitVect *spillable ;
-
- /* spillable live ranges are those that are live at this
- point . the following categories need to be subtracted
- from this set.
- a) - those that are already spilt
- b) - if being used by this one
- c) - defined by this one */
-
- spillable = bitVectCopy(ic->rlive);
- spillable =
- bitVectCplAnd(spillable,_G.spiltSet); /* those already spilt */
- spillable =
- bitVectCplAnd(spillable,ic->uses); /* used in this one */
- bitVectUnSetBit(spillable,ic->defKey);
- spillable = bitVectIntersect(spillable,_G.regAssigned);
- return spillable;
-
+ bitVect *spillable;
+
+ /* spillable live ranges are those that are live at this
+ point . the following categories need to be subtracted
+ from this set.
+ a) - those that are already spilt
+ b) - if being used by this one
+ c) - defined by this one */
+
+ spillable = bitVectCopy (ic->rlive);
+ spillable =
+ bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
+ spillable =
+ bitVectCplAnd (spillable, ic->uses); /* used in this one */
+ bitVectUnSetBit (spillable, ic->defKey);
+ spillable = bitVectIntersect (spillable, _G.regAssigned);
+ return spillable;
+
}
/*-----------------------------------------------------------------*/
/* noSpilLoc - return true if a variable has no spil location */
/*-----------------------------------------------------------------*/
-static int noSpilLoc (symbol *sym, eBBlock *ebp,iCode *ic)
+static int
+noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 0 : 1);
+ return (sym->usl.spillLoc ? 0 : 1);
}
/*-----------------------------------------------------------------*/
/* hasSpilLoc - will return 1 if the symbol has spil location */
/*-----------------------------------------------------------------*/
-static int hasSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 1 : 0);
+ return (sym->usl.spillLoc ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* directSpilLoc - will return 1 if the splilocation is in direct */
/*-----------------------------------------------------------------*/
-static int directSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- if ( sym->usl.spillLoc &&
- (IN_DIRSPACE(SPEC_OCLS(sym->usl.spillLoc->etype))))
- return 1;
- else
- return 0;
+ if (sym->usl.spillLoc &&
+ (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
+ return 1;
+ else
+ return 0;
}
/*-----------------------------------------------------------------*/
-/* hasSpilLocnoUptr - will return 1 if the symbol has spil location*/
+/* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
/* but is not used as a pointer */
/*-----------------------------------------------------------------*/
-static int hasSpilLocnoUptr (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
+ return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* rematable - will return 1 if the remat flag is set */
/*-----------------------------------------------------------------*/
-static int rematable (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+rematable (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return sym->remat;
+ return sym->remat;
}
/*-----------------------------------------------------------------*/
/* notUsedInBlock - not used in this block */
/*-----------------------------------------------------------------*/
-static int notUsedInBlock (symbol *sym, eBBlock *ebp, iCode *ic)
-{
- return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs) &&
- allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
+static int
+notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
+{
+ return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
+ allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
/* return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs)); */
}
/*-----------------------------------------------------------------*/
/* notUsedInRemaining - not used or defined in remain of the block */
/*-----------------------------------------------------------------*/
-static int notUsedInRemaining (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return ((usedInRemaining (operandFromSymbol(sym),ic) ? 0 : 1) &&
- allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
+ return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
+ allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
}
/*-----------------------------------------------------------------*/
/* allLRs - return true for all */
/*-----------------------------------------------------------------*/
-static int allLRs (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* liveRangesWith - applies function to a given set of live range */
/*-----------------------------------------------------------------*/
-static set *liveRangesWith (bitVect *lrs, int (func)(symbol *,eBBlock *, iCode *),
- eBBlock *ebp, iCode *ic)
+static set *
+liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
+ eBBlock * ebp, iCode * ic)
{
- set *rset = NULL;
- int i;
+ set *rset = NULL;
+ int i;
- if (!lrs || !lrs->size)
- return NULL;
+ if (!lrs || !lrs->size)
+ return NULL;
- for ( i = 1 ; i < lrs->size ; i++ ) {
- symbol *sym;
- if (!bitVectBitValue(lrs,i))
- continue ;
-
- /* if we don't find it in the live range
- hash table we are in serious trouble */
- if (!(sym = hTabItemWithKey(liveRanges,i))) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "liveRangesWith could not find liveRange");
- exit(1);
+ for (i = 1; i < lrs->size; i++)
+ {
+ symbol *sym;
+ if (!bitVectBitValue (lrs, i))
+ continue;
+
+ /* if we don't find it in the live range
+ hash table we are in serious trouble */
+ if (!(sym = hTabItemWithKey (liveRanges, i)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "liveRangesWith could not find liveRange");
+ exit (1);
}
-
- if (func(sym,ebp,ic) && bitVectBitValue(_G.regAssigned,sym->key))
- addSetHead(&rset,sym);
+
+ if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
+ addSetHead (&rset, sym);
}
- return rset;
+ return rset;
}
/*-----------------------------------------------------------------*/
/* leastUsedLR - given a set determines which is the least used */
/*-----------------------------------------------------------------*/
-static symbol *leastUsedLR (set *sset)
+static symbol *
+leastUsedLR (set * sset)
{
- symbol *sym = NULL, *lsym = NULL ;
-
- sym = lsym = setFirstItem(sset);
+ symbol *sym = NULL, *lsym = NULL;
- if (!lsym)
- return NULL;
+ sym = lsym = setFirstItem (sset);
+
+ if (!lsym)
+ return NULL;
+
+ for (; lsym; lsym = setNextItem (sset))
+ {
+
+ /* if usage is the same then prefer
+ the spill the smaller of the two */
+ if (lsym->used == sym->used)
+ if (getSize (lsym->type) < getSize (sym->type))
+ sym = lsym;
+
+ /* if less usage */
+ if (lsym->used < sym->used)
+ sym = lsym;
- for (; lsym; lsym = setNextItem(sset)) {
-
- /* if usage is the same then prefer
- the spill the smaller of the two */
- if ( lsym->used == sym->used )
- if (getSize(lsym->type) < getSize(sym->type))
- sym = lsym;
-
- /* if less usage */
- if (lsym->used < sym->used )
- sym = lsym;
-
- }
-
- setToNull((void **)&sset);
- sym->blockSpil = 0;
- return sym;
+ }
+
+ setToNull ((void **) &sset);
+ sym->blockSpil = 0;
+ return sym;
}
/*-----------------------------------------------------------------*/
/* noOverLap - will iterate through the list looking for over lap */
/*-----------------------------------------------------------------*/
-static int noOverLap (set *itmpStack, symbol *fsym)
+static int
+noOverLap (set * itmpStack, symbol * fsym)
{
- symbol *sym;
-
+ symbol *sym;
+
+
+ for (sym = setFirstItem (itmpStack); sym;
+ sym = setNextItem (itmpStack))
+ {
+ if (sym->liveTo > fsym->liveFrom)
+ return 0;
- for (sym = setFirstItem(itmpStack); sym;
- sym = setNextItem(itmpStack)) {
- if (sym->liveTo > fsym->liveFrom )
- return 0;
-
}
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* isFree - will return 1 if the a free spil location is found */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(isFree)
+static
+DEFSETFUNC (isFree)
{
- symbol *sym = item;
- V_ARG(symbol **,sloc);
- V_ARG(symbol *,fsym);
+ symbol *sym = item;
+ V_ARG (symbol **, sloc);
+ V_ARG (symbol *, fsym);
- /* if already found */
- if (*sloc)
- return 0;
+ /* if already found */
+ if (*sloc)
+ return 0;
- /* if it is free && and the itmp assigned to
- this does not have any overlapping live ranges
- with the one currently being assigned and
- the size can be accomodated */
- if (sym->isFree &&
- noOverLap(sym->usl.itmpStack,fsym) &&
- getSize(sym->type) >= getSize(fsym->type)) {
- *sloc = sym;
- return 1;
+ /* if it is free && and the itmp assigned to
+ this does not have any overlapping live ranges
+ with the one currently being assigned and
+ the size can be accomodated */
+ if (sym->isFree &&
+ noOverLap (sym->usl.itmpStack, fsym) &&
+ getSize (sym->type) >= getSize (fsym->type))
+ {
+ *sloc = sym;
+ return 1;
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* spillLRWithPtrReg :- will spil those live ranges which use PTR */
/*-----------------------------------------------------------------*/
-static void spillLRWithPtrReg (symbol *forSym)
+static void
+spillLRWithPtrReg (symbol * forSym)
{
- symbol *lrsym;
- regs *r0,*r1;
- int k;
-
- if (!_G.regAssigned ||
- bitVectIsZero(_G.regAssigned))
- return;
-
- r0 = mcs51_regWithIdx(R0_IDX);
- r1 = mcs51_regWithIdx(R1_IDX);
-
- /* for all live ranges */
- for (lrsym = hTabFirstItem(liveRanges,&k) ; lrsym ;
- lrsym = hTabNextItem(liveRanges,&k) ) {
- int j;
-
- /* if no registers assigned to it or
- spilt */
- /* if it does not overlap with this then
- not need to spill it */
-
- if (lrsym->isspilt || !lrsym->nRegs ||
- (lrsym->liveTo < forSym->liveFrom))
- continue ;
-
- /* go thru the registers : if it is either
- r0 or r1 then spil it */
- for (j = 0 ; j < lrsym->nRegs ; j++ )
- if (lrsym->regs[j] == r0 ||
- lrsym->regs[j] == r1 ) {
- spillThis (lrsym);
- break;
- }
+ symbol *lrsym;
+ regs *r0, *r1;
+ int k;
+
+ if (!_G.regAssigned ||
+ bitVectIsZero (_G.regAssigned))
+ return;
+
+ r0 = mcs51_regWithIdx (R0_IDX);
+ r1 = mcs51_regWithIdx (R1_IDX);
+
+ /* for all live ranges */
+ for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
+ lrsym = hTabNextItem (liveRanges, &k))
+ {
+ int j;
+
+ /* if no registers assigned to it or
+ spilt */
+ /* if it does not overlap with this then
+ not need to spill it */
+
+ if (lrsym->isspilt || !lrsym->nRegs ||
+ (lrsym->liveTo < forSym->liveFrom))
+ continue;
+
+ /* go thru the registers : if it is either
+ r0 or r1 then spil it */
+ for (j = 0; j < lrsym->nRegs; j++)
+ if (lrsym->regs[j] == r0 ||
+ lrsym->regs[j] == r1)
+ {
+ spillThis (lrsym);
+ break;
+ }
}
}
/*-----------------------------------------------------------------*/
/* createStackSpil - create a location on the stack to spil */
/*-----------------------------------------------------------------*/
-static symbol *createStackSpil (symbol *sym)
+static symbol *
+createStackSpil (symbol * sym)
{
- symbol *sloc= NULL;
- int useXstack, model, noOverlay;
-
- char slocBuffer[30];
-
- /* first go try and find a free one that is already
- existing on the stack */
- if (applyToSet(_G.stackSpil,isFree,&sloc, sym)) {
- /* found a free one : just update & return */
- sym->usl.spillLoc = sloc;
- sym->stackSpil= 1;
- sloc->isFree = 0;
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ symbol *sloc = NULL;
+ int useXstack, model;
+
+ char slocBuffer[30];
+
+ /* first go try and find a free one that is already
+ existing on the stack */
+ if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
+ {
+ /* found a free one : just update & return */
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+ sloc->isFree = 0;
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
- /* could not then have to create one , this is the hard part
- we need to allocate this on the stack : this is really a
- hack!! but cannot think of anything better at this time */
-
- if (sprintf(slocBuffer,"sloc%d",_G.slocNum++) >= sizeof(slocBuffer))
+ /* could not then have to create one , this is the hard part
+ we need to allocate this on the stack : this is really a
+ hack!! but cannot think of anything better at this time */
+
+ if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
{
- fprintf(stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
- __FILE__, __LINE__);
- exit(1);
+ fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
+ __FILE__, __LINE__);
+ exit (1);
}
- sloc = newiTemp(slocBuffer);
-
- /* set the type to the spilling symbol */
- sloc->type = copyLinkChain(sym->type);
- sloc->etype = getSpec(sloc->type);
- SPEC_SCLS(sloc->etype) = S_DATA ;
- SPEC_EXTR(sloc->etype) = 0;
-
- /* we don't allow it to be allocated`
- onto the external stack since : so we
- temporarily turn it off ; we also
- turn off memory model to prevent
- the spil from going to the external storage
- */
-
- useXstack = options.useXstack;
- model = options.model;
+ sloc = newiTemp (slocBuffer);
+
+ /* set the type to the spilling symbol */
+ sloc->type = copyLinkChain (sym->type);
+ sloc->etype = getSpec (sloc->type);
+ SPEC_SCLS (sloc->etype) = S_DATA;
+ SPEC_EXTR (sloc->etype) = 0;
+
+ /* we don't allow it to be allocated`
+ onto the external stack since : so we
+ temporarily turn it off ; we also
+ turn off memory model to prevent
+ the spil from going to the external storage
+ */
+
+ useXstack = options.useXstack;
+ model = options.model;
/* noOverlay = options.noOverlay; */
/* options.noOverlay = 1; */
- options.model = options.useXstack = 0;
+ options.model = options.useXstack = 0;
- allocLocal(sloc);
+ allocLocal (sloc);
- options.useXstack = useXstack;
- options.model = model;
+ options.useXstack = useXstack;
+ options.model = model;
/* options.noOverlay = noOverlay; */
- sloc->isref = 1; /* to prevent compiler warning */
-
- /* if it is on the stack then update the stack */
- if (IN_STACK(sloc->etype)) {
- currFunc->stack += getSize(sloc->type);
- _G.stackExtend += getSize(sloc->type);
- } else
- _G.dataExtend += getSize(sloc->type);
-
- /* add it to the _G.stackSpil set */
- addSetHead(&_G.stackSpil,sloc);
- sym->usl.spillLoc = sloc;
- sym->stackSpil = 1;
-
- /* add it to the set of itempStack set
- of the spill location */
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ sloc->isref = 1; /* to prevent compiler warning */
+
+ /* if it is on the stack then update the stack */
+ if (IN_STACK (sloc->etype))
+ {
+ currFunc->stack += getSize (sloc->type);
+ _G.stackExtend += getSize (sloc->type);
+ }
+ else
+ _G.dataExtend += getSize (sloc->type);
+
+ /* add it to the _G.stackSpil set */
+ addSetHead (&_G.stackSpil, sloc);
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+
+ /* add it to the set of itempStack set
+ of the spill location */
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
/*-----------------------------------------------------------------*/
/* isSpiltOnStack - returns true if the spil location is on stack */
/*-----------------------------------------------------------------*/
-static bool isSpiltOnStack (symbol *sym)
+static bool
+isSpiltOnStack (symbol * sym)
{
- sym_link *etype;
+ sym_link *etype;
- if (!sym)
- return FALSE ;
-
- if (!sym->isspilt)
- return FALSE ;
+ if (!sym)
+ return FALSE;
+
+ if (!sym->isspilt)
+ return FALSE;
/* if (sym->_G.stackSpil) */
-/* return TRUE; */
-
- if (!sym->usl.spillLoc)
- return FALSE;
+/* return TRUE; */
- etype = getSpec(sym->usl.spillLoc->type);
- if (IN_STACK(etype))
- return TRUE;
+ if (!sym->usl.spillLoc)
+ return FALSE;
+
+ etype = getSpec (sym->usl.spillLoc->type);
+ if (IN_STACK (etype))
+ return TRUE;
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* spillThis - spils a specific operand */
/*-----------------------------------------------------------------*/
-static void spillThis (symbol *sym)
+static void
+spillThis (symbol * sym)
{
- int i;
- /* if this is rematerializable or has a spillLocation
- we are okay, else we need to create a spillLocation
- for it */
- if (!(sym->remat || sym->usl.spillLoc))
- createStackSpil (sym);
-
-
- /* mark it has spilt & put it in the spilt set */
- sym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,sym->key);
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- for (i = 0 ; i < sym->nRegs ; i++)
-
- if (sym->regs[i]) {
- freeReg(sym->regs[i]);
- sym->regs[i] = NULL;
- }
-
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to some
- LIVE ranges */
- if (!mcs51_ptrRegReq && isSpiltOnStack(sym)) {
- mcs51_ptrRegReq++ ;
- spillLRWithPtrReg(sym);
+ int i;
+ /* if this is rematerializable or has a spillLocation
+ we are okay, else we need to create a spillLocation
+ for it */
+ if (!(sym->remat || sym->usl.spillLoc))
+ createStackSpil (sym);
+
+
+ /* mark it has spilt & put it in the spilt set */
+ sym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ for (i = 0; i < sym->nRegs; i++)
+
+ if (sym->regs[i])
+ {
+ freeReg (sym->regs[i]);
+ sym->regs[i] = NULL;
+ }
+
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to some
+ LIVE ranges */
+ if (!mcs51_ptrRegReq && isSpiltOnStack (sym))
+ {
+ mcs51_ptrRegReq++;
+ spillLRWithPtrReg (sym);
}
- if (sym->usl.spillLoc && !sym->remat)
- sym->usl.spillLoc->allocreq = 1;
- return;
+ if (sym->usl.spillLoc && !sym->remat)
+ sym->usl.spillLoc->allocreq = 1;
+ return;
}
/*-----------------------------------------------------------------*/
/* selectSpil - select a iTemp to spil : rather a simple procedure */
/*-----------------------------------------------------------------*/
-static symbol *selectSpil (iCode *ic, eBBlock *ebp, symbol *forSym)
+static symbol *
+selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- bitVect *lrcs= NULL ;
- set *selectS ;
- symbol *sym;
+ bitVect *lrcs = NULL;
+ set *selectS;
+ symbol *sym;
- /* get the spillable live ranges */
- lrcs = computeSpillable (ic);
+ /* get the spillable live ranges */
+ lrcs = computeSpillable (ic);
- /* get all live ranges that are rematerizable */
- if ((selectS = liveRangesWith(lrcs,rematable,ebp,ic))) {
+ /* get all live ranges that are rematerizable */
+ if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
+ {
- /* return the least used of these */
- return leastUsedLR(selectS);
+ /* return the least used of these */
+ return leastUsedLR (selectS);
}
- /* get live ranges with spillLocations in direct space */
- if ((selectS = liveRangesWith(lrcs,directSpilLoc,ebp,ic))) {
- sym = leastUsedLR(selectS);
- strcpy(sym->rname,(sym->usl.spillLoc->rname[0] ?
- sym->usl.spillLoc->rname :
- sym->usl.spillLoc->name));
- sym->spildir = 1;
- /* mark it as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* get live ranges with spillLocations in direct space */
+ if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
+ sym->usl.spillLoc->rname :
+ sym->usl.spillLoc->name));
+ sym->spildir = 1;
+ /* mark it as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* if the symbol is local to the block then */
- if (forSym->liveTo < ebp->lSeq) {
-
- /* check if there are any live ranges allocated
- to registers that are not used in this block */
- if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInBlock,ebp,ic))) {
- sym = leastUsedLR(selectS);
- /* if this is not rematerializable */
- if (!sym->remat) {
- _G.blockSpil++;
- sym->blockSpil = 1;
+ /* if the symbol is local to the block then */
+ if (forSym->liveTo < ebp->lSeq)
+ {
+
+ /* check if there are any live ranges allocated
+ to registers that are not used in this block */
+ if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ /* if this is not rematerializable */
+ if (!sym->remat)
+ {
+ _G.blockSpil++;
+ sym->blockSpil = 1;
}
- return sym;
- }
-
- /* check if there are any live ranges that not
- used in the remainder of the block */
- if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInRemaining,ebp,ic))) {
- sym = leastUsedLR (selectS);
- if (sym != forSym) {
- if (!sym->remat) {
- sym->remainSpil = 1;
- _G.blockSpil++;
+ return sym;
+ }
+
+ /* check if there are any live ranges that not
+ used in the remainder of the block */
+ if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ if (sym != forSym)
+ {
+ if (!sym->remat)
+ {
+ sym->remainSpil = 1;
+ _G.blockSpil++;
}
- return sym;
+ return sym;
}
}
- }
-
- /* find live ranges with spillocation && not used as pointers */
- if ((selectS = liveRangesWith(lrcs,hasSpilLocnoUptr,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- /* mark this as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
}
- /* find live ranges with spillocation */
- if ((selectS = liveRangesWith(lrcs,hasSpilLoc,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation && not used as pointers */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ /* mark this as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* couldn't find then we need to create a spil
- location on the stack , for which one? the least
- used ofcourse */
- if ((selectS = liveRangesWith(lrcs,noSpilLoc,ebp,ic))) {
-
- /* return a created spil location */
- sym = createStackSpil(leastUsedLR(selectS));
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
-
- /* this is an extreme situation we will spill
- this one : happens very rarely but it does happen */
- spillThis ( forSym );
- return forSym ;
-
+
+ /* couldn't find then we need to create a spil
+ location on the stack , for which one? the least
+ used ofcourse */
+ if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
+ {
+
+ /* return a created spil location */
+ sym = createStackSpil (leastUsedLR (selectS));
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
+ }
+
+ /* this is an extreme situation we will spill
+ this one : happens very rarely but it does happen */
+ spillThis (forSym);
+ return forSym;
+
}
/*-----------------------------------------------------------------*/
/* spilSomething - spil some variable & mark registers as free */
/*-----------------------------------------------------------------*/
-static bool spilSomething (iCode *ic, eBBlock *ebp, symbol *forSym)
+static bool
+spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- symbol *ssym;
- int i ;
-
- /* get something we can spil */
- ssym = selectSpil(ic,ebp,forSym);
-
- /* mark it as spilt */
- ssym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,ssym->key);
-
- /* mark it as not register assigned &
- take it away from the set */
- bitVectUnSetBit(_G.regAssigned,ssym->key);
-
- /* mark the registers as free */
- for (i = 0 ; i < ssym->nRegs ;i++ )
- if (ssym->regs[i])
- freeReg(ssym->regs[i]);
-
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to as gprs */
- if (!mcs51_ptrRegReq && isSpiltOnStack(ssym) ) {
- mcs51_ptrRegReq++ ;
- spillLRWithPtrReg(ssym);
+ symbol *ssym;
+ int i;
+
+ /* get something we can spil */
+ ssym = selectSpil (ic, ebp, forSym);
+
+ /* mark it as spilt */
+ ssym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
+
+ /* mark it as not register assigned &
+ take it away from the set */
+ bitVectUnSetBit (_G.regAssigned, ssym->key);
+
+ /* mark the registers as free */
+ for (i = 0; i < ssym->nRegs; i++)
+ if (ssym->regs[i])
+ freeReg (ssym->regs[i]);
+
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to as gprs */
+ if (!mcs51_ptrRegReq && isSpiltOnStack (ssym))
+ {
+ mcs51_ptrRegReq++;
+ spillLRWithPtrReg (ssym);
}
- /* if this was a block level spil then insert push & pop
- at the start & end of block respectively */
- if (ssym->blockSpil) {
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push to the start of the block */
- addiCodeToeBBlock(ebp,nic,( ebp->sch->op == LABEL ?
+ /* if this was a block level spil then insert push & pop
+ at the start & end of block respectively */
+ if (ssym->blockSpil)
+ {
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push to the start of the block */
+ addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
ebp->sch->next : ebp->sch));
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
- }
-
- /* if spilt because not used in the remainder of the
- block then add a push before this instruction and
- a pop at the end of the block */
- if (ssym->remainSpil) {
-
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push just before this instruction */
- addiCodeToeBBlock(ebp,nic,ic);
-
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
+ }
+
+ /* if spilt because not used in the remainder of the
+ block then add a push before this instruction and
+ a pop at the end of the block */
+ if (ssym->remainSpil)
+ {
+
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push just before this instruction */
+ addiCodeToeBBlock (ebp, nic, ic);
+
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
}
- if (ssym == forSym )
- return FALSE ;
- else
- return TRUE ;
+ if (ssym == forSym)
+ return FALSE;
+ else
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* getRegPtr - will try for PTR if not a GPR type if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegPtr (iCode *ic, eBBlock *ebp, symbol *sym)
+static regs *
+getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
+ regs *reg;
- tryAgain:
- /* try for a ptr type */
- if ((reg = allocReg(REG_PTR)))
- return reg;
+tryAgain:
+ /* try for a ptr type */
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* getRegGpr - will try for GPR if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegGpr (iCode *ic, eBBlock *ebp,symbol *sym)
+static regs *
+getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
-
- tryAgain:
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
-
- if (!mcs51_ptrRegReq)
- if ((reg = allocReg(REG_PTR)))
- return reg ;
-
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
-
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ regs *reg;
+
+tryAgain:
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
+
+ if (!mcs51_ptrRegReq)
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
+
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
+
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* symHasReg - symbol has a given register */
/*-----------------------------------------------------------------*/
-static bool symHasReg(symbol *sym,regs *reg)
+static bool
+symHasReg (symbol * sym, regs * reg)
{
- int i;
+ int i;
- for ( i = 0 ; i < sym->nRegs ; i++)
- if (sym->regs[i] == reg)
- return TRUE;
-
- return FALSE;
+ for (i = 0; i < sym->nRegs; i++)
+ if (sym->regs[i] == reg)
+ return TRUE;
+
+ return FALSE;
}
/*-----------------------------------------------------------------*/
-/* deassignLRs - check the live to and if they have registers & are*/
+/* deassignLRs - check the live to and if they have registers & are */
/* not spilt then free up the registers */
/*-----------------------------------------------------------------*/
-static void deassignLRs (iCode *ic, eBBlock *ebp)
+static void
+deassignLRs (iCode * ic, eBBlock * ebp)
{
- symbol *sym;
- int k;
- symbol *result;
-
- for (sym = hTabFirstItem(liveRanges,&k); sym;
- sym = hTabNextItem(liveRanges,&k)) {
-
- symbol *psym= NULL;
- /* if it does not end here */
- if (sym->liveTo > ic->seq )
- continue ;
-
- /* if it was spilt on stack then we can
- mark the stack spil location as free */
- if (sym->isspilt ) {
- if (sym->stackSpil) {
- sym->usl.spillLoc->isFree = 1;
- sym->stackSpil = 0;
+ symbol *sym;
+ int k;
+ symbol *result;
+
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
+
+ symbol *psym = NULL;
+ /* if it does not end here */
+ if (sym->liveTo > ic->seq)
+ continue;
+
+ /* if it was spilt on stack then we can
+ mark the stack spil location as free */
+ if (sym->isspilt)
+ {
+ if (sym->stackSpil)
+ {
+ sym->usl.spillLoc->isFree = 1;
+ sym->stackSpil = 0;
}
- continue ;
+ continue;
}
-
- if (!bitVectBitValue(_G.regAssigned,sym->key))
- continue;
-
- /* special case check if this is an IFX &
- the privious one was a pop and the
- previous one was not spilt then keep track
- of the symbol */
- if (ic->op == IFX && ic->prev &&
- ic->prev->op == IPOP &&
- !ic->prev->parmPush &&
- !OP_SYMBOL(IC_LEFT(ic->prev))->isspilt)
- psym = OP_SYMBOL(IC_LEFT(ic->prev));
-
- if (sym->nRegs) {
- int i = 0;
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- /* if the result of this one needs registers
- and does not have it then assign it right
- away */
- if (IC_RESULT(ic) &&
- ! (SKIP_IC2(ic) || /* not a special icode */
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- ic->op == RETURN ||
- POINTER_SET(ic)) &&
- (result = OP_SYMBOL(IC_RESULT(ic))) && /* has a result */
- result->liveTo > ic->seq && /* and will live beyond this */
- result->liveTo <= ebp->lSeq && /* does not go beyond this block */
- result->regType == sym->regType && /* same register types */
- result->nRegs && /* which needs registers */
- ! result->isspilt && /* and does not already have them */
- ! result->remat &&
- ! bitVectBitValue(_G.regAssigned,result->key) &&
- /* the number of free regs + number of regs in this LR
- can accomodate the what result Needs */
- ((nfreeRegsType(result->regType) +
- sym->nRegs) >= result->nRegs)
- ) {
-
- for (i = 0 ; i < result->nRegs ; i++)
- if (i < sym->nRegs )
- result->regs[i] = sym->regs[i] ;
- else
- result->regs[i] = getRegGpr (ic,ebp,result);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,result->key);
-
- }
-
- /* free the remaining */
- for (; i < sym->nRegs ; i++) {
- if (psym) {
- if (!symHasReg(psym,sym->regs[i]))
- freeReg(sym->regs[i]);
- } else
- freeReg(sym->regs[i]);
+
+ if (!bitVectBitValue (_G.regAssigned, sym->key))
+ continue;
+
+ /* special case check if this is an IFX &
+ the privious one was a pop and the
+ previous one was not spilt then keep track
+ of the symbol */
+ if (ic->op == IFX && ic->prev &&
+ ic->prev->op == IPOP &&
+ !ic->prev->parmPush &&
+ !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
+ psym = OP_SYMBOL (IC_LEFT (ic->prev));
+
+ if (sym->nRegs)
+ {
+ int i = 0;
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ /* if the result of this one needs registers
+ and does not have it then assign it right
+ away */
+ if (IC_RESULT (ic) &&
+ !(SKIP_IC2 (ic) || /* not a special icode */
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ ic->op == RETURN ||
+ POINTER_SET (ic)) &&
+ (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
+ result->liveTo > ic->seq && /* and will live beyond this */
+ result->liveTo <= ebp->lSeq && /* does not go beyond this block */
+ result->regType == sym->regType && /* same register types */
+ result->nRegs && /* which needs registers */
+ !result->isspilt && /* and does not already have them */
+ !result->remat &&
+ !bitVectBitValue (_G.regAssigned, result->key) &&
+ /* the number of free regs + number of regs in this LR
+ can accomodate the what result Needs */
+ ((nfreeRegsType (result->regType) +
+ sym->nRegs) >= result->nRegs)
+ )
+ {
+
+ for (i = 0; i < result->nRegs; i++)
+ if (i < sym->nRegs)
+ result->regs[i] = sym->regs[i];
+ else
+ result->regs[i] = getRegGpr (ic, ebp, result);
+
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
+
+ }
+
+ /* free the remaining */
+ for (; i < sym->nRegs; i++)
+ {
+ if (psym)
+ {
+ if (!symHasReg (psym, sym->regs[i]))
+ freeReg (sym->regs[i]);
+ }
+ else
+ freeReg (sym->regs[i]);
}
}
}
/*-----------------------------------------------------------------*/
/* reassignLR - reassign this to registers */
/*-----------------------------------------------------------------*/
-static void reassignLR (operand *op)
+static void
+reassignLR (operand * op)
{
- symbol *sym = OP_SYMBOL(op);
- int i;
+ symbol *sym = OP_SYMBOL (op);
+ int i;
+
+ /* not spilt any more */
+ sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
+ bitVectUnSetBit (_G.spiltSet, sym->key);
- /* not spilt any more */
- sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
- bitVectUnSetBit(_G.spiltSet,sym->key);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- _G.blockSpil--;
+ _G.blockSpil--;
- for (i=0;i<sym->nRegs;i++)
- sym->regs[i]->isFree = 0;
+ for (i = 0; i < sym->nRegs; i++)
+ sym->regs[i]->isFree = 0;
}
/*-----------------------------------------------------------------*/
/* willCauseSpill - determines if allocating will cause a spill */
/*-----------------------------------------------------------------*/
-static int willCauseSpill ( int nr, int rt)
+static int
+willCauseSpill (int nr, int rt)
{
- /* first check if there are any avlb registers
- of te type required */
- if (rt == REG_PTR) {
- /* special case for pointer type
- if pointer type not avlb then
- check for type gpr */
- if (nFreeRegs(rt) >= nr)
+ /* first check if there are any avlb registers
+ of te type required */
+ if (rt == REG_PTR)
+ {
+ /* special case for pointer type
+ if pointer type not avlb then
+ check for type gpr */
+ if (nFreeRegs (rt) >= nr)
+ return 0;
+ if (nFreeRegs (REG_GPR) >= nr)
+ return 0;
+ }
+ else
+ {
+ if (mcs51_ptrRegReq)
+ {
+ if (nFreeRegs (rt) >= nr)
return 0;
- if (nFreeRegs(REG_GPR) >= nr)
+ }
+ else
+ {
+ if (nFreeRegs (REG_PTR) +
+ nFreeRegs (REG_GPR) >= nr)
return 0;
- } else {
- if (mcs51_ptrRegReq) {
- if (nFreeRegs(rt) >= nr)
- return 0;
- } else {
- if (nFreeRegs(REG_PTR) +
- nFreeRegs(REG_GPR) >= nr)
- return 0;
}
}
- /* it will cause a spil */
- return 1;
+ /* it will cause a spil */
+ return 1;
}
/*-----------------------------------------------------------------*/
-/* positionRegs - the allocator can allocate same registers to res-*/
+/* positionRegs - the allocator can allocate same registers to res- */
/* ult and operand, if this happens make sure they are in the same */
/* position as the operand otherwise chaos results */
/*-----------------------------------------------------------------*/
-static void positionRegs (symbol *result, symbol *opsym, int lineno)
+static void
+positionRegs (symbol * result, symbol * opsym, int lineno)
{
- int count = min(result->nRegs,opsym->nRegs);
- int i , j = 0, shared = 0;
-
- /* if the result has been spilt then cannot share */
- if (opsym->isspilt)
- return ;
- again:
- shared = 0;
- /* first make sure that they actually share */
- for ( i = 0 ; i < count; i++ ) {
- for (j = 0 ; j < count ; j++ ) {
- if (result->regs[i] == opsym->regs[j] && i !=j) {
- shared = 1;
- goto xchgPositions;
- }
- }
- }
- xchgPositions:
- if (shared) {
- regs *tmp = result->regs[i];
- result->regs[i] = result->regs[j];
- result->regs[j] = tmp;
- goto again;
+ int count = min (result->nRegs, opsym->nRegs);
+ int i, j = 0, shared = 0;
+
+ /* if the result has been spilt then cannot share */
+ if (opsym->isspilt)
+ return;
+again:
+ shared = 0;
+ /* first make sure that they actually share */
+ for (i = 0; i < count; i++)
+ {
+ for (j = 0; j < count; j++)
+ {
+ if (result->regs[i] == opsym->regs[j] && i != j)
+ {
+ shared = 1;
+ goto xchgPositions;
+ }
}
+ }
+xchgPositions:
+ if (shared)
+ {
+ regs *tmp = result->regs[i];
+ result->regs[i] = result->regs[j];
+ result->regs[j] = tmp;
+ goto again;
+ }
}
/*-----------------------------------------------------------------*/
/* serialRegAssign - serially allocate registers to the variables */
/*-----------------------------------------------------------------*/
-static void serialRegAssign (eBBlock **ebbs, int count)
+static void
+serialRegAssign (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
-
- iCode *ic;
-
- if (ebbs[i]->noPath &&
- (ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* of all instructions do */
- for (ic = ebbs[i]->sch ; ic ; ic = ic->next) {
-
- /* if this is an ipop that means some live
- range will have to be assigned again */
- if (ic->op == IPOP)
- reassignLR (IC_LEFT(ic));
-
- /* if result is present && is a true symbol */
- if (IC_RESULT(ic) && ic->op != IFX &&
- IS_TRUE_SYMOP(IC_RESULT(ic)))
- OP_SYMBOL(IC_RESULT(ic))->allocreq = 1;
-
- /* take away registers from live
- ranges that end at this instruction */
- deassignLRs (ic, ebbs[i]) ;
-
- /* some don't need registers */
- if (SKIP_IC2(ic) ||
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- (IC_RESULT(ic) &&POINTER_SET(ic)) )
- continue;
-
- /* now we need to allocate registers
- only for the result */
- if (IC_RESULT(ic)) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- bitVect *spillable;
- int willCS ;
- int j;
- int ptrRegSet = 0;
-
- /* if it does not need or is spilt
- or is already assigned to registers
- or will not live beyond this instructions */
- if (!sym->nRegs ||
- sym->isspilt ||
- bitVectBitValue(_G.regAssigned,sym->key) ||
- sym->liveTo <= ic->seq)
- continue ;
-
- /* if some liverange has been spilt at the block level
- and this one live beyond this block then spil this
- to be safe */
- if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq) {
- spillThis (sym);
- continue ;
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* of all instructions do */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an ipop that means some live
+ range will have to be assigned again */
+ if (ic->op == IPOP)
+ reassignLR (IC_LEFT (ic));
+
+ /* if result is present && is a true symbol */
+ if (IC_RESULT (ic) && ic->op != IFX &&
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
+
+ /* take away registers from live
+ ranges that end at this instruction */
+ deassignLRs (ic, ebbs[i]);
+
+ /* some don't need registers */
+ if (SKIP_IC2 (ic) ||
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ (IC_RESULT (ic) && POINTER_SET (ic)))
+ continue;
+
+ /* now we need to allocate registers
+ only for the result */
+ if (IC_RESULT (ic))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ bitVect *spillable;
+ int willCS;
+ int j;
+ int ptrRegSet = 0;
+
+ /* if it does not need or is spilt
+ or is already assigned to registers
+ or will not live beyond this instructions */
+ if (!sym->nRegs ||
+ sym->isspilt ||
+ bitVectBitValue (_G.regAssigned, sym->key) ||
+ sym->liveTo <= ic->seq)
+ continue;
+
+ /* if some liverange has been spilt at the block level
+ and this one live beyond this block then spil this
+ to be safe */
+ if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
+ {
+ spillThis (sym);
+ continue;
}
- /* if trying to allocate this will cause
- a spill and there is nothing to spill
- or this one is rematerializable then
- spill this one */
- willCS = willCauseSpill(sym->nRegs,sym->regType);
- spillable = computeSpillable(ic);
- if ( sym->remat ||
- (willCS && bitVectIsZero(spillable) ) ) {
-
- spillThis (sym) ;
- continue ;
+ /* if trying to allocate this will cause
+ a spill and there is nothing to spill
+ or this one is rematerializable then
+ spill this one */
+ willCS = willCauseSpill (sym->nRegs, sym->regType);
+ spillable = computeSpillable (ic);
+ if (sym->remat ||
+ (willCS && bitVectIsZero (spillable)))
+ {
+
+ spillThis (sym);
+ continue;
}
- /* if it has a spillocation & is used less than
- all other live ranges then spill this */
- if ( willCS && sym->usl.spillLoc ) {
-
- symbol *leastUsed =
- leastUsedLR(liveRangesWith (spillable ,
- allLRs,
- ebbs[i],
- ic));
- if (leastUsed &&
- leastUsed->used > sym->used) {
- spillThis (sym);
- continue;
+ /* if it has a spillocation & is used less than
+ all other live ranges then spill this */
+ if (willCS && sym->usl.spillLoc)
+ {
+
+ symbol *leastUsed =
+ leastUsedLR (liveRangesWith (spillable,
+ allLRs,
+ ebbs[i],
+ ic));
+ if (leastUsed &&
+ leastUsed->used > sym->used)
+ {
+ spillThis (sym);
+ continue;
}
- }
-
- /* if we need ptr regs for the right side
- then mark it */
- if (POINTER_GET(ic) && IS_SYMOP(IC_LEFT(ic))
- && getSize(OP_SYMBOL(IC_LEFT(ic))->type)
- <= PTRSIZE)
+ }
+
+ /* if we need ptr regs for the right side
+ then mark it */
+ if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
+ && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
+ <= PTRSIZE)
{
- mcs51_ptrRegReq++;
- ptrRegSet = 1;
+ mcs51_ptrRegReq++;
+ ptrRegSet = 1;
}
- /* else we assign registers to it */
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
-
- for (j = 0 ; j < sym->nRegs ;j++ ) {
- if (sym->regType == REG_PTR)
- sym->regs[j] = getRegPtr(ic,ebbs[i],sym);
- else
- sym->regs[j] = getRegGpr(ic,ebbs[i],sym);
-
- /* if the allocation falied which means
- this was spilt then break */
- if (!sym->regs[j])
- break;
+ /* else we assign registers to it */
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ if (sym->regType == REG_PTR)
+ sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
+ else
+ sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
+
+ /* if the allocation falied which means
+ this was spilt then break */
+ if (!sym->regs[j])
+ break;
}
- /* if it shares registers with operands make sure
- that they are in the same position */
- if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->nRegs && ic->op != '=')
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_LEFT(ic)),ic->lineno);
- /* do the same for the right operand */
- if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->nRegs)
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_RIGHT(ic)),ic->lineno);
-
- if (ptrRegSet) {
- mcs51_ptrRegReq--;
- ptrRegSet = 0;
+ /* if it shares registers with operands make sure
+ that they are in the same position */
+ if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
+ /* do the same for the right operand */
+ if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->nRegs)
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
+
+ if (ptrRegSet)
+ {
+ mcs51_ptrRegReq--;
+ ptrRegSet = 0;
}
-
- }
+
+ }
}
}
}
/*-----------------------------------------------------------------*/
/* rUmaskForOp :- returns register mask for an operand */
/*-----------------------------------------------------------------*/
-static bitVect *rUmaskForOp (operand *op)
+static bitVect *
+rUmaskForOp (operand * op)
{
- bitVect *rumask;
- symbol *sym;
- int j;
-
- /* only temporaries are assigned registers */
- if (!IS_ITEMP(op))
- return NULL;
+ bitVect *rumask;
+ symbol *sym;
+ int j;
- sym = OP_SYMBOL(op);
-
- /* if spilt or no registers assigned to it
- then nothing */
- if (sym->isspilt || !sym->nRegs)
- return NULL;
+ /* only temporaries are assigned registers */
+ if (!IS_ITEMP (op))
+ return NULL;
- rumask = newBitVect(mcs51_nRegs);
+ sym = OP_SYMBOL (op);
- for (j = 0; j < sym->nRegs; j++) {
- rumask = bitVectSetBit(rumask,
- sym->regs[j]->rIdx);
+ /* if spilt or no registers assigned to it
+ then nothing */
+ if (sym->isspilt || !sym->nRegs)
+ return NULL;
+
+ rumask = newBitVect (mcs51_nRegs);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ rumask = bitVectSetBit (rumask,
+ sym->regs[j]->rIdx);
}
- return rumask;
+ return rumask;
}
/*-----------------------------------------------------------------*/
-/* regsUsedIniCode :- returns bit vector of registers used in iCode*/
+/* regsUsedIniCode :- returns bit vector of registers used in iCode */
/*-----------------------------------------------------------------*/
-static bitVect *regsUsedIniCode (iCode *ic)
+static bitVect *
+regsUsedIniCode (iCode * ic)
{
- bitVect *rmask = newBitVect(mcs51_nRegs);
+ bitVect *rmask = newBitVect (mcs51_nRegs);
- /* do the special cases first */
- if (ic->op == IFX ) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_COND(ic)));
- goto ret;
+ /* do the special cases first */
+ if (ic->op == IFX)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_COND (ic)));
+ goto ret;
}
- /* for the jumptable */
- if (ic->op == JUMPTABLE) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_JTCOND(ic)));
+ /* for the jumptable */
+ if (ic->op == JUMPTABLE)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_JTCOND (ic)));
- goto ret;
+ goto ret;
}
- /* of all other cases */
- if (IC_LEFT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_LEFT(ic)));
-
-
- if (IC_RIGHT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RIGHT(ic)));
-
- if (IC_RESULT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RESULT(ic)));
-
- ret:
- return rmask;
+ /* of all other cases */
+ if (IC_LEFT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_LEFT (ic)));
+
+
+ if (IC_RIGHT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RIGHT (ic)));
+
+ if (IC_RESULT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RESULT (ic)));
+
+ret:
+ return rmask;
}
/*-----------------------------------------------------------------*/
-/* createRegMask - for each instruction will determine the regsUsed*/
+/* createRegMask - for each instruction will determine the regsUsed */
/*-----------------------------------------------------------------*/
-static void createRegMask (eBBlock **ebbs, int count)
+static void
+createRegMask (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
- iCode *ic ;
-
- if ( ebbs[i]->noPath &&
- ( ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* for all instructions */
- for ( ic = ebbs[i]->sch ; ic ; ic = ic->next ) {
-
- int j;
-
- if (SKIP_IC2(ic) || !ic->rlive)
- continue ;
-
- /* first mark the registers used in this
- instruction */
- ic->rUsed = regsUsedIniCode(ic);
- _G.funcrUsed = bitVectUnion(_G.funcrUsed,ic->rUsed);
-
- /* now create the register mask for those
- registers that are in use : this is a
- super set of ic->rUsed */
- ic->rMask = newBitVect(mcs51_nRegs+1);
-
- /* for all live Ranges alive at this point */
- for (j = 1; j < ic->rlive->size; j++ ) {
- symbol *sym;
- int k;
-
- /* if not alive then continue */
- if (!bitVectBitValue(ic->rlive,j))
- continue ;
-
- /* find the live range we are interested in */
- if (!(sym = hTabItemWithKey(liveRanges,j))) {
- werror (E_INTERNAL_ERROR,__FILE__,__LINE__,
- "createRegMask cannot find live range");
- exit(0);
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* for all instructions */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ int j;
+
+ if (SKIP_IC2 (ic) || !ic->rlive)
+ continue;
+
+ /* first mark the registers used in this
+ instruction */
+ ic->rUsed = regsUsedIniCode (ic);
+ _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
+
+ /* now create the register mask for those
+ registers that are in use : this is a
+ super set of ic->rUsed */
+ ic->rMask = newBitVect (mcs51_nRegs + 1);
+
+ /* for all live Ranges alive at this point */
+ for (j = 1; j < ic->rlive->size; j++)
+ {
+ symbol *sym;
+ int k;
+
+ /* if not alive then continue */
+ if (!bitVectBitValue (ic->rlive, j))
+ continue;
+
+ /* find the live range we are interested in */
+ if (!(sym = hTabItemWithKey (liveRanges, j)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "createRegMask cannot find live range");
+ exit (0);
}
- /* if no register assigned to it */
- if (!sym->nRegs || sym->isspilt)
- continue ;
+ /* if no register assigned to it */
+ if (!sym->nRegs || sym->isspilt)
+ continue;
- /* for all the registers allocated to it */
- for (k = 0 ; k < sym->nRegs ;k++)
- if (sym->regs[k])
- ic->rMask =
- bitVectSetBit(ic->rMask,sym->regs[k]->rIdx);
+ /* for all the registers allocated to it */
+ for (k = 0; k < sym->nRegs; k++)
+ if (sym->regs[k])
+ ic->rMask =
+ bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
}
}
}
/*-----------------------------------------------------------------*/
/* rematStr - returns the rematerialized string for a remat var */
/*-----------------------------------------------------------------*/
-static char *rematStr (symbol *sym)
+static char *
+rematStr (symbol * sym)
{
- char *s = buffer;
- iCode *ic = sym->rematiCode;
-
- while (1) {
-
- /* if plus or minus print the right hand side */
- if (ic->op == '+' || ic->op == '-') {
- sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
- ic->op );
- s += strlen(s);
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- continue ;
- }
-
- /* we reached the end */
- sprintf(s,"%s",OP_SYMBOL(IC_LEFT(ic))->rname);
- break;
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
+
+ while (1)
+ {
+
+ /* if plus or minus print the right hand side */
+ if (ic->op == '+' || ic->op == '-')
+ {
+ sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+ ic->op);
+ s += strlen (s);
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ continue;
+ }
+
+ /* we reached the end */
+ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ break;
}
- return buffer ;
+ return buffer;
}
/*-----------------------------------------------------------------*/
/* regTypeNum - computes the type & number of registers required */
/*-----------------------------------------------------------------*/
-static void regTypeNum ()
+static void
+regTypeNum ()
{
- symbol *sym;
- int k;
- iCode *ic;
+ symbol *sym;
+ int k;
+ iCode *ic;
- /* for each live range do */
- for ( sym = hTabFirstItem(liveRanges,&k); sym ;
- sym = hTabNextItem(liveRanges,&k)) {
+ /* for each live range do */
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
- /* if used zero times then no registers needed */
- if ((sym->liveTo - sym->liveFrom) == 0)
- continue ;
+ /* if used zero times then no registers needed */
+ if ((sym->liveTo - sym->liveFrom) == 0)
+ continue;
- /* if the live range is a temporary */
- if (sym->isitmp) {
+ /* if the live range is a temporary */
+ if (sym->isitmp)
+ {
- /* if the type is marked as a conditional */
- if (sym->regType == REG_CND)
- continue ;
+ /* if the type is marked as a conditional */
+ if (sym->regType == REG_CND)
+ continue;
- /* if used in return only then we don't
- need registers */
- if (sym->ruonly || sym->accuse) {
- if (IS_AGGREGATE(sym->type) || sym->isptr)
- sym->type = aggrToPtr(sym->type,FALSE);
- continue ;
+ /* if used in return only then we don't
+ need registers */
+ if (sym->ruonly || sym->accuse)
+ {
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ sym->type = aggrToPtr (sym->type, FALSE);
+ continue;
}
-
- /* if the symbol has only one definition &
- that definition is a get_pointer and the
- pointer we are getting is rematerializable and
- in "data" space */
-
- if (bitVectnBitsOn(sym->defs) == 1 &&
- (ic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(sym->defs))) &&
- POINTER_GET(ic) &&
- !IS_BITVAR(sym->etype)) {
-
-
- /* if remat in data space */
- if (OP_SYMBOL(IC_LEFT(ic))->remat &&
- DCL_TYPE(aggrToPtr(sym->type,FALSE)) == POINTER) {
-
- /* create a psuedo symbol & force a spil */
- symbol *psym = newSymbol(rematStr(OP_SYMBOL(IC_LEFT(ic))),1);
- psym->type = sym->type;
- psym->etype = sym->etype;
- strcpy(psym->rname,psym->name);
- sym->isspilt = 1;
- sym->usl.spillLoc = psym;
- continue ;
+
+ /* if the symbol has only one definition &
+ that definition is a get_pointer and the
+ pointer we are getting is rematerializable and
+ in "data" space */
+
+ if (bitVectnBitsOn (sym->defs) == 1 &&
+ (ic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (sym->defs))) &&
+ POINTER_GET (ic) &&
+ !IS_BITVAR (sym->etype))
+ {
+
+
+ /* if remat in data space */
+ if (OP_SYMBOL (IC_LEFT (ic))->remat &&
+ DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER)
+ {
+
+ /* create a psuedo symbol & force a spil */
+ symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
+ psym->type = sym->type;
+ psym->etype = sym->etype;
+ strcpy (psym->rname, psym->name);
+ sym->isspilt = 1;
+ sym->usl.spillLoc = psym;
+ continue;
}
- /* if in data space or idata space then try to
- allocate pointer register */
-
+ /* if in data space or idata space then try to
+ allocate pointer register */
+
}
-
- /* if not then we require registers */
- sym->nRegs = ((IS_AGGREGATE(sym->type) || sym->isptr ) ?
- getSize(sym->type = aggrToPtr(sym->type,FALSE)) :
- getSize(sym->type));
-
- if (sym->nRegs > 4) {
- fprintf(stderr,"allocated more than 4 or 0 registers for type ");
- printTypeChain(sym->type,stderr);fprintf(stderr,"\n");
- }
-
- /* determine the type of register required */
- if (sym->nRegs == 1 &&
- IS_PTR(sym->type) &&
- sym->uptr)
- sym->regType = REG_PTR ;
- else
- sym->regType = REG_GPR ;
-
- } else
- /* for the first run we don't provide */
- /* registers for true symbols we will */
- /* see how things go */
- sym->nRegs = 0 ;
+
+ /* if not then we require registers */
+ sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
+ getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
+ getSize (sym->type));
+
+ if (sym->nRegs > 4)
+ {
+ fprintf (stderr, "allocated more than 4 or 0 registers for type ");
+ printTypeChain (sym->type, stderr);
+ fprintf (stderr, "\n");
+ }
+
+ /* determine the type of register required */
+ if (sym->nRegs == 1 &&
+ IS_PTR (sym->type) &&
+ sym->uptr)
+ sym->regType = REG_PTR;
+ else
+ sym->regType = REG_GPR;
+
+ }
+ else
+ /* for the first run we don't provide */
+ /* registers for true symbols we will */
+ /* see how things go */
+ sym->nRegs = 0;
}
-
+
}
/*-----------------------------------------------------------------*/
/* freeAllRegs - mark all registers as free */
/*-----------------------------------------------------------------*/
-static void freeAllRegs()
+static void
+freeAllRegs ()
{
- int i;
+ int i;
- for (i=0;i< mcs51_nRegs;i++ )
- regs8051[i].isFree = 1;
+ for (i = 0; i < mcs51_nRegs; i++)
+ regs8051[i].isFree = 1;
}
/*-----------------------------------------------------------------*/
/* deallocStackSpil - this will set the stack pointer back */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(deallocStackSpil)
+static
+DEFSETFUNC (deallocStackSpil)
{
- symbol *sym = item;
+ symbol *sym = item;
- deallocLocal(sym);
- return 0;
+ deallocLocal (sym);
+ return 0;
}
/*-----------------------------------------------------------------*/
/* farSpacePackable - returns the packable icode for far variables */
/*-----------------------------------------------------------------*/
-static iCode *farSpacePackable (iCode *ic)
+static iCode *
+farSpacePackable (iCode * ic)
{
- iCode *dic ;
-
- /* go thru till we find a definition for the
- symbol on the right */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if the definition is a call then no */
- if ((dic->op == CALL || dic->op == PCALL) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- return NULL;
+ iCode *dic;
+
+ /* go thru till we find a definition for the
+ symbol on the right */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if the definition is a call then no */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ return NULL;
}
-
- /* if shift by unknown amount then not */
- if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key)
- return NULL;
- /* if pointer get and size > 1 */
- if (POINTER_GET(dic) &&
- getSize(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if shift by unknown amount then not */
+ if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ return NULL;
- if (POINTER_SET(dic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if pointer get and size > 1 */
+ if (POINTER_GET (dic) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
+ return NULL;
- /* if any three is a true symbol in far space */
- if (IC_RESULT(dic) &&
- IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- isOperandInFarSpace(IC_RESULT(dic)))
- return NULL;
+ if (POINTER_SET (dic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
+ return NULL;
- if (IC_RIGHT(dic) &&
- IS_TRUE_SYMOP(IC_RIGHT(dic)) &&
- isOperandInFarSpace(IC_RIGHT(dic)) &&
- !isOperandEqual(IC_RIGHT(dic),IC_RESULT(ic)))
- return NULL;
+ /* if any three is a true symbol in far space */
+ if (IC_RESULT (dic) &&
+ IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ isOperandInFarSpace (IC_RESULT (dic)))
+ return NULL;
+
+ if (IC_RIGHT (dic) &&
+ IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
+ isOperandInFarSpace (IC_RIGHT (dic)) &&
+ !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
+ return NULL;
- if (IC_LEFT(dic) &&
- IS_TRUE_SYMOP(IC_LEFT(dic)) &&
- isOperandInFarSpace(IC_LEFT(dic)) &&
- !isOperandEqual(IC_LEFT(dic),IC_RESULT(ic)))
+ if (IC_LEFT (dic) &&
+ IS_TRUE_SYMOP (IC_LEFT (dic)) &&
+ isOperandInFarSpace (IC_LEFT (dic)) &&
+ !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
+ return NULL;
+
+ if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
+ {
+ if ((dic->op == LEFT_OP ||
+ dic->op == RIGHT_OP ||
+ dic->op == '-') &&
+ IS_OP_LITERAL (IC_RIGHT (dic)))
return NULL;
-
- if (isOperandEqual(IC_RIGHT(ic),IC_RESULT(dic))) {
- if ( (dic->op == LEFT_OP ||
- dic->op == RIGHT_OP ||
- dic->op == '-') &&
- IS_OP_LITERAL(IC_RIGHT(dic)))
- return NULL;
- else
- return dic;
+ else
+ return dic;
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* packRegsForAssign - register reduction for assignment */
/*-----------------------------------------------------------------*/
-static int packRegsForAssign (iCode *ic,eBBlock *ebp)
+static int
+packRegsForAssign (iCode * ic, eBBlock * ebp)
{
- iCode *dic, *sic;
- sym_link *etype = operandType(IC_RIGHT(ic));
-
- if (!IS_ITEMP(IC_RIGHT(ic)) ||
- OP_SYMBOL(IC_RIGHT(ic))->isind ||
- OP_LIVETO(IC_RIGHT(ic)) > ic->seq ||
- IS_BITFIELD(etype)) {
- return 0;
+ iCode *dic, *sic;
+ sym_link *etype = operandType (IC_RIGHT (ic));
+
+ if (!IS_ITEMP (IC_RIGHT (ic)) ||
+ OP_SYMBOL (IC_RIGHT (ic))->isind ||
+ OP_LIVETO (IC_RIGHT (ic)) > ic->seq ||
+ IS_BITFIELD (etype))
+ {
+ return 0;
}
-
- /* if the true symbol is defined in far space or on stack
- then we should not since this will increase register pressure */
- if (isOperandInFarSpace(IC_RESULT(ic))) {
- if ((dic = farSpacePackable(ic)))
- goto pack;
- else
- return 0;
-
+
+ /* if the true symbol is defined in far space or on stack
+ then we should not since this will increase register pressure */
+ if (isOperandInFarSpace (IC_RESULT (ic)))
+ {
+ if ((dic = farSpacePackable (ic)))
+ goto pack;
+ else
+ return 0;
+
}
- /* find the definition of iTempNN scanning backwards if we find a
- a use of the true symbol in before we find the definition then
- we cannot */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if there is a function call and this is
- a parameter & not my parameter then don't pack it */
- if ( (dic->op == CALL || dic->op == PCALL) &&
- (OP_SYMBOL(IC_RESULT(ic))->_isparm &&
- !OP_SYMBOL(IC_RESULT(ic))->ismyparm)) {
- dic = NULL;
- break;
+ /* find the definition of iTempNN scanning backwards if we find a
+ a use of the true symbol in before we find the definition then
+ we cannot */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if there is a function call and this is
+ a parameter & not my parameter then don't pack it */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ (OP_SYMBOL (IC_RESULT (ic))->_isparm &&
+ !OP_SYMBOL (IC_RESULT (ic))->ismyparm))
+ {
+ dic = NULL;
+ break;
}
- if (SKIP_IC2(dic))
- continue;
+ if (SKIP_IC2 (dic))
+ continue;
- if (IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- IS_OP_VOLATILE(IC_RESULT(dic))) {
- dic = NULL;
- break;
+ if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ IS_OP_VOLATILE (IC_RESULT (dic)))
+ {
+ dic = NULL;
+ break;
}
- if (IS_SYMOP(IC_RESULT(dic)) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- if (POINTER_SET(dic))
- dic = NULL;
+ if (IS_SYMOP (IC_RESULT (dic)) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ if (POINTER_SET (dic))
+ dic = NULL;
- break;
+ break;
}
- if (IS_SYMOP(IC_RIGHT(dic)) &&
- (IC_RIGHT(dic)->key == IC_RESULT(ic)->key ||
- IC_RIGHT(dic)->key == IC_RIGHT(ic)->key)) {
- dic = NULL;
- break;
+ if (IS_SYMOP (IC_RIGHT (dic)) &&
+ (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
+ IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
}
-
- if (IS_SYMOP(IC_LEFT(dic)) &&
- (IC_LEFT(dic)->key == IC_RESULT(ic)->key ||
- IC_LEFT(dic)->key == IC_RIGHT(ic)->key)) {
- dic = NULL;
- break;
+
+ if (IS_SYMOP (IC_LEFT (dic)) &&
+ (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
+ IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
}
- if (POINTER_SET(dic) &&
- IC_RESULT(dic)->key == IC_RESULT(ic)->key ) {
- dic = NULL ;
- break;
+ if (POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == IC_RESULT (ic)->key)
+ {
+ dic = NULL;
+ break;
}
}
-
- if (!dic)
- return 0 ; /* did not find */
-
- /* if assignment then check that right is not a bit */
- if (ASSIGNMENT(dic) && !POINTER_SET(dic)) {
- sym_link *etype = operandType(IC_RIGHT(dic));
- if (IS_BITFIELD(etype)) return 0;
+
+ if (!dic)
+ return 0; /* did not find */
+
+ /* if assignment then check that right is not a bit */
+ if (ASSIGNMENT (dic) && !POINTER_SET (dic))
+ {
+ sym_link *etype = operandType (IC_RIGHT (dic));
+ if (IS_BITFIELD (etype))
+ return 0;
+ }
+ /* if the result is on stack or iaccess then it must be
+ the same atleast one of the operands */
+ if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess)
+ {
+
+ /* the operation has only one symbol
+ operator then we can pack */
+ if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
+ (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
+ goto pack;
+
+ if (!((IC_LEFT (dic) &&
+ IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
+ (IC_RIGHT (dic) &&
+ IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
+ return 0;
}
- /* if the result is on stack or iaccess then it must be
- the same atleast one of the operands */
- if (OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess ) {
-
- /* the operation has only one symbol
- operator then we can pack */
- if ((IC_LEFT(dic) && !IS_SYMOP(IC_LEFT(dic))) ||
- (IC_RIGHT(dic) && !IS_SYMOP(IC_RIGHT(dic))))
- goto pack;
-
- if (!((IC_LEFT(dic) &&
- IC_RESULT(ic)->key == IC_LEFT(dic)->key) ||
- (IC_RIGHT(dic) &&
- IC_RESULT(ic)->key == IC_RIGHT(dic)->key)))
- return 0;
- }
pack:
- /* found the definition */
- /* replace the result with the result of */
- /* this assignment and remove this assignment */
- IC_RESULT(dic) = IC_RESULT(ic) ;
+ /* found the definition */
+ /* replace the result with the result of */
+ /* this assignment and remove this assignment */
+ IC_RESULT (dic) = IC_RESULT (ic);
- if (IS_ITEMP(IC_RESULT(dic)) && OP_SYMBOL(IC_RESULT(dic))->liveFrom > dic->seq) {
- OP_SYMBOL(IC_RESULT(dic))->liveFrom = dic->seq;
+ if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
+ {
+ OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
}
- /* delete from liverange table also
- delete from all the points inbetween and the new
- one */
- for ( sic = dic; sic != ic ; sic = sic->next ) {
- bitVectUnSetBit(sic->rlive,IC_RESULT(ic)->key);
- if (IS_ITEMP(IC_RESULT(dic)))
- bitVectSetBit(sic->rlive,IC_RESULT(dic)->key);
+ /* delete from liverange table also
+ delete from all the points inbetween and the new
+ one */
+ for (sic = dic; sic != ic; sic = sic->next)
+ {
+ bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
+ if (IS_ITEMP (IC_RESULT (dic)))
+ bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
}
-
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- return 1;
-
+
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ return 1;
+
}
/*-----------------------------------------------------------------*/
-/* findAssignToSym : scanning backwards looks for first assig found*/
+/* findAssignToSym : scanning backwards looks for first assig found */
/*-----------------------------------------------------------------*/
-static iCode *findAssignToSym (operand *op,iCode *ic)
+static iCode *
+findAssignToSym (operand * op, iCode * ic)
{
- iCode *dic;
-
- for (dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if definition by assignment */
- if (dic->op == '=' &&
- !POINTER_SET(dic) &&
- IC_RESULT(dic)->key == op->key
-/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
- ) {
-
- /* we are interested only if defined in far space */
- /* or in stack space in case of + & - */
-
- /* if assigned to a non-symbol then return
- true */
- if (!IS_SYMOP(IC_RIGHT(dic)))
- break ;
-
- /* if the symbol is in far space then
- we should not */
- if (isOperandInFarSpace(IC_RIGHT(dic)))
- return NULL ;
-
- /* for + & - operations make sure that
- if it is on the stack it is the same
- as one of the three operands */
- if ((ic->op == '+' || ic->op == '-') &&
- OP_SYMBOL(IC_RIGHT(dic))->onStack) {
-
- if ( IC_RESULT(ic)->key != IC_RIGHT(dic)->key &&
- IC_LEFT(ic)->key != IC_RIGHT(dic)->key &&
- IC_RIGHT(ic)->key != IC_RIGHT(dic)->key)
- return NULL;
- }
-
- break ;
-
- }
+ iCode *dic;
- /* if we find an usage then we cannot delete it */
- if (IC_LEFT(dic) && IC_LEFT(dic)->key == op->key)
- return NULL;
-
- if (IC_RIGHT(dic) && IC_RIGHT(dic)->key == op->key)
- return NULL;
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if definition by assignment */
+ if (dic->op == '=' &&
+ !POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == op->key
+/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
+ )
+ {
- if (POINTER_SET(dic) && IC_RESULT(dic)->key == op->key)
+ /* we are interested only if defined in far space */
+ /* or in stack space in case of + & - */
+
+ /* if assigned to a non-symbol then return
+ true */
+ if (!IS_SYMOP (IC_RIGHT (dic)))
+ break;
+
+ /* if the symbol is in far space then
+ we should not */
+ if (isOperandInFarSpace (IC_RIGHT (dic)))
return NULL;
- }
- /* now make sure that the right side of dic
- is not defined between ic & dic */
- if (dic) {
- iCode *sic = dic->next ;
+ /* for + & - operations make sure that
+ if it is on the stack it is the same
+ as one of the three operands */
+ if ((ic->op == '+' || ic->op == '-') &&
+ OP_SYMBOL (IC_RIGHT (dic))->onStack)
+ {
- for (; sic != ic ; sic = sic->next)
- if (IC_RESULT(sic) &&
- IC_RESULT(sic)->key == IC_RIGHT(dic)->key)
+ if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
return NULL;
+ }
+
+ break;
+
+ }
+
+ /* if we find an usage then we cannot delete it */
+ if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
+ return NULL;
+
+ if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
+ return NULL;
+
+ if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
+ return NULL;
}
- return dic;
-
-
+ /* now make sure that the right side of dic
+ is not defined between ic & dic */
+ if (dic)
+ {
+ iCode *sic = dic->next;
+
+ for (; sic != ic; sic = sic->next)
+ if (IC_RESULT (sic) &&
+ IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
+ return NULL;
+ }
+
+ return dic;
+
+
}
/*-----------------------------------------------------------------*/
/* packRegsForSupport :- reduce some registers for support calls */
/*-----------------------------------------------------------------*/
-static int packRegsForSupport (iCode *ic, eBBlock *ebp)
+static int
+packRegsForSupport (iCode * ic, eBBlock * ebp)
{
- int change = 0 ;
- /* for the left & right operand :- look to see if the
- left was assigned a true symbol in far space in that
- case replace them */
- if (IS_ITEMP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_LEFT(ic),ic);
- iCode *sic;
-
- if (!dic)
- goto right ;
-
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_LEFT(ic)->key);
-
- IC_LEFT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_LEFT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change++;
+ int change = 0;
+ /* for the left & right operand :- look to see if the
+ left was assigned a true symbol in far space in that
+ case replace them */
+ if (IS_ITEMP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ goto right;
+
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
+
+ IC_LEFT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- /* do the same for the right operand */
- right:
- if (!change &&
- IS_ITEMP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_RIGHT(ic),ic);
- iCode *sic;
-
- if (!dic)
- return change ;
-
- /* if this is a subtraction & the result
- is a true symbol in far space then don't pack */
- if (ic->op == '-' && IS_TRUE_SYMOP(IC_RESULT(dic))) {
- sym_link *etype =getSpec(operandType(IC_RESULT(dic)));
- if (IN_FARSPACE(SPEC_OCLS(etype)))
- return change ;
+
+ /* do the same for the right operand */
+right:
+ if (!change &&
+ IS_ITEMP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ return change;
+
+ /* if this is a subtraction & the result
+ is a true symbol in far space then don't pack */
+ if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
+ {
+ sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
+ if (IN_FARSPACE (SPEC_OCLS (etype)))
+ return change;
}
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_RIGHT(ic)->key);
-
- IC_RIGHT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_RIGHT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
-
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change ++;
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
+
+ IC_RIGHT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- return change ;
+
+ return change;
}
#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
/*-----------------------------------------------------------------*/
-/* packRegsForOneuse : - will reduce some registers for single Use */
+/* packRegsForOneuse : - will reduce some registers for single Use */
/*-----------------------------------------------------------------*/
-static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp)
+static iCode *
+packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
{
- bitVect *uses ;
- iCode *dic, *sic;
+ bitVect *uses;
+ iCode *dic, *sic;
- /* if returning a literal then do nothing */
- if (!IS_SYMOP(op))
- return NULL;
-
- /* only upto 2 bytes since we cannot predict
- the usage of b, & acc */
- if (getSize(operandType(op)) > (fReturnSize - 2) &&
- ic->op != RETURN &&
- ic->op != SEND &&
- !POINTER_SET(ic) &&
- !POINTER_GET(ic))
- return NULL;
+ /* if returning a literal then do nothing */
+ if (!IS_SYMOP (op))
+ return NULL;
- /* this routine will mark the a symbol as used in one
- instruction use only && if the defintion is local
- (ie. within the basic block) && has only one definition &&
- that definiion is either a return value from a
- function or does not contain any variables in
- far space */
- uses = bitVectCopy(OP_USES(op));
- bitVectUnSetBit(uses,ic->key); /* take away this iCode */
- if (!bitVectIsZero(uses)) /* has other uses */
- return NULL ;
-
- /* if it has only one defintion */
- if (bitVectnBitsOn(OP_DEFS(op)) > 1)
- return NULL ; /* has more than one definition */
-
- /* get the that definition */
- if (!(dic =
- hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(op)))))
- return NULL ;
-
- /* found the definition now check if it is local */
- if (dic->seq < ebp->fSeq ||
- dic->seq > ebp->lSeq)
- return NULL ; /* non-local */
-
- /* now check if it is the return from
- a function call */
- if (dic->op == CALL || dic->op == PCALL ) {
- if (ic->op != SEND && ic->op != RETURN) {
- OP_SYMBOL(op)->ruonly = 1;
- return dic;
+ /* only upto 2 bytes since we cannot predict
+ the usage of b, & acc */
+ if (getSize (operandType (op)) > (fReturnSize - 2) &&
+ ic->op != RETURN &&
+ ic->op != SEND &&
+ !POINTER_SET (ic) &&
+ !POINTER_GET (ic))
+ return NULL;
+
+ /* this routine will mark the a symbol as used in one
+ instruction use only && if the defintion is local
+ (ie. within the basic block) && has only one definition &&
+ that definiion is either a return value from a
+ function or does not contain any variables in
+ far space */
+ uses = bitVectCopy (OP_USES (op));
+ bitVectUnSetBit (uses, ic->key); /* take away this iCode */
+ if (!bitVectIsZero (uses)) /* has other uses */
+ return NULL;
+
+ /* if it has only one defintion */
+ if (bitVectnBitsOn (OP_DEFS (op)) > 1)
+ return NULL; /* has more than one definition */
+
+ /* get the that definition */
+ if (!(dic =
+ hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (op)))))
+ return NULL;
+
+ /* found the definition now check if it is local */
+ if (dic->seq < ebp->fSeq ||
+ dic->seq > ebp->lSeq)
+ return NULL; /* non-local */
+
+ /* now check if it is the return from
+ a function call */
+ if (dic->op == CALL || dic->op == PCALL)
+ {
+ if (ic->op != SEND && ic->op != RETURN)
+ {
+ OP_SYMBOL (op)->ruonly = 1;
+ return dic;
}
- dic = dic->next ;
+ dic = dic->next;
}
-
-
- /* otherwise check that the definition does
- not contain any symbols in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(ic)) ||
- IS_OP_RUONLY(IC_RIGHT(ic)) ) {
- return NULL;
+
+
+ /* otherwise check that the definition does
+ not contain any symbols in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (ic)) ||
+ IS_OP_RUONLY (IC_RIGHT (ic)))
+ {
+ return NULL;
}
-
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- sic = dic;
-
- /* also make sure the intervenening instructions
- don't have any thing in far space */
- for (dic = dic->next ; dic && dic != ic && sic != ic; dic = dic->next) {
-
- /* if there is an intervening function call then no */
- if (dic->op == CALL || dic->op == PCALL)
- return NULL;
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- /* if address of & the result is remat the okay */
- if (dic->op == ADDRESS_OF &&
- OP_SYMBOL(IC_RESULT(dic))->remat)
- continue ;
-
- /* if operand has size of three or more & this
- operation is a '*','/' or '%' then 'b' may
- cause a problem */
- if (( dic->op == '%' || dic->op == '/' || dic->op == '*') &&
- getSize(operandType(op)) >= 3)
- return NULL;
- /* if left or right or result is in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- isOperandInFarSpace(IC_RESULT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(dic)) ||
- IS_OP_RUONLY(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_RESULT(dic)) ) {
- return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ sic = dic;
+
+ /* also make sure the intervenening instructions
+ don't have any thing in far space */
+ for (dic = dic->next; dic && dic != ic && sic != ic; dic = dic->next)
+ {
+
+ /* if there is an intervening function call then no */
+ if (dic->op == CALL || dic->op == PCALL)
+ return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ /* if address of & the result is remat the okay */
+ if (dic->op == ADDRESS_OF &&
+ OP_SYMBOL (IC_RESULT (dic))->remat)
+ continue;
+
+ /* if operand has size of three or more & this
+ operation is a '*','/' or '%' then 'b' may
+ cause a problem */
+ if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
+ getSize (operandType (op)) >= 3)
+ return NULL;
+
+ /* if left or right or result is in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ isOperandInFarSpace (IC_RESULT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (dic)) ||
+ IS_OP_RUONLY (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_RESULT (dic)))
+ {
+ return NULL;
}
}
-
- OP_SYMBOL(op)->ruonly = 1;
- return sic;
-
+
+ OP_SYMBOL (op)->ruonly = 1;
+ return sic;
+
}
/*-----------------------------------------------------------------*/
/* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
/*-----------------------------------------------------------------*/
-static bool isBitwiseOptimizable (iCode *ic)
+static bool
+isBitwiseOptimizable (iCode * ic)
{
- sym_link *ltype = getSpec(operandType(IC_LEFT(ic)));
- sym_link *rtype = getSpec(operandType(IC_RIGHT(ic)));
-
- /* bitwise operations are considered optimizable
- under the following conditions (Jean-Louis VERN)
-
- x & lit
- bit & bit
- bit & x
- bit ^ bit
- bit ^ x
- x ^ lit
- x | lit
- bit | bit
- bit | x
- */
- if ( IS_LITERAL(rtype) ||
- (IS_BITVAR(ltype) && IN_BITSPACE(SPEC_OCLS(ltype))))
- return TRUE ;
- else
- return FALSE ;
+ sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
+ sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
+
+ /* bitwise operations are considered optimizable
+ under the following conditions (Jean-Louis VERN)
+
+ x & lit
+ bit & bit
+ bit & x
+ bit ^ bit
+ bit ^ x
+ x ^ lit
+ x | lit
+ bit | bit
+ bit | x
+ */
+ if (IS_LITERAL (rtype) ||
+ (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
+ return TRUE;
+ else
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* packRegsForAccUse - pack registers for acc use */
/*-----------------------------------------------------------------*/
-static void packRegsForAccUse (iCode *ic)
+static void
+packRegsForAccUse (iCode * ic)
{
- iCode *uic;
-
- /* if + or - then it has to be one byte result */
- if ((ic->op == '+' || ic->op == '-')
- && getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (ic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (ic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (IS_BITWISE_OP(ic) &&
- getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
-
- /* has only one definition */
- if (bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) > 1)
- return ;
-
- /* has only one use */
- if (bitVectnBitsOn(OP_USES(IC_RESULT(ic))) > 1)
- return ;
-
- /* and the usage immediately follows this iCode */
- if (!(uic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_USES(IC_RESULT(ic))))))
- return ;
-
- if (ic->next != uic)
- return ;
-
- /* if it is a conditional branch then we definitely can */
- if (uic->op == IFX )
- goto accuse;
-
- if ( uic->op == JUMPTABLE )
- return ;
-
- /* if the usage is not is an assignment
- or an arithmetic / bitwise / shift operation then not */
- if (POINTER_SET(uic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(uic)),FALSE)) > 1)
- return;
-
- if (uic->op != '=' &&
- !IS_ARITHMETIC_OP(uic) &&
- !IS_BITWISE_OP(uic) &&
- uic->op != LEFT_OP &&
- uic->op != RIGHT_OP )
- return;
-
- /* if used in ^ operation then make sure right is not a
- literl */
- if (uic->op == '^' && isOperandLiteral(IC_RIGHT(uic)))
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (uic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- if (uic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- /* make sure that the result of this icode is not on the
- stack, since acc is used to compute stack offset */
- if (IS_TRUE_SYMOP(IC_RESULT(uic)) &&
- OP_SYMBOL(IC_RESULT(uic))->onStack)
- return ;
-
- /* if either one of them in far space then we cannot */
- if ((IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- isOperandInFarSpace(IC_LEFT(uic))) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- isOperandInFarSpace(IC_RIGHT(uic))))
- return ;
-
- /* if the usage has only one operand then we can */
- if (IC_LEFT(uic) == NULL ||
- IC_RIGHT(uic) == NULL)
- goto accuse;
-
- /* make sure this is on the left side if not
- a '+' since '+' is commutative */
- if (ic->op != '+' &&
- IC_LEFT(uic)->key != IC_RESULT(ic)->key)
- return;
-
- /* if one of them is a literal then we can */
- if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) ||
- (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) {
- OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
- return ;
+ iCode *uic;
+
+ /* if + or - then it has to be one byte result */
+ if ((ic->op == '+' || ic->op == '-')
+ && getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (ic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ if (ic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ if (IS_BITWISE_OP (ic) &&
+ getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
+
+
+ /* has only one definition */
+ if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
+ return;
+
+ /* has only one use */
+ if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
+ return;
+
+ /* and the usage immediately follows this iCode */
+ if (!(uic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
+ return;
+
+ if (ic->next != uic)
+ return;
+
+ /* if it is a conditional branch then we definitely can */
+ if (uic->op == IFX)
+ goto accuse;
+
+ if (uic->op == JUMPTABLE)
+ return;
+
+ /* if the usage is not is an assignment
+ or an arithmetic / bitwise / shift operation then not */
+ if (POINTER_SET (uic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
+ return;
+
+ if (uic->op != '=' &&
+ !IS_ARITHMETIC_OP (uic) &&
+ !IS_BITWISE_OP (uic) &&
+ uic->op != LEFT_OP &&
+ uic->op != RIGHT_OP)
+ return;
+
+ /* if used in ^ operation then make sure right is not a
+ literl */
+ if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (uic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ if (uic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ /* make sure that the result of this icode is not on the
+ stack, since acc is used to compute stack offset */
+ if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
+ OP_SYMBOL (IC_RESULT (uic))->onStack)
+ return;
+
+ /* if either one of them in far space then we cannot */
+ if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ isOperandInFarSpace (IC_LEFT (uic))) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ isOperandInFarSpace (IC_RIGHT (uic))))
+ return;
+
+ /* if the usage has only one operand then we can */
+ if (IC_LEFT (uic) == NULL ||
+ IC_RIGHT (uic) == NULL)
+ goto accuse;
+
+ /* make sure this is on the left side if not
+ a '+' since '+' is commutative */
+ if (ic->op != '+' &&
+ IC_LEFT (uic)->key != IC_RESULT (ic)->key)
+ return;
+
+ /* if one of them is a literal then we can */
+ if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
+ (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
+ {
+ OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
+ return;
}
- /* if the other one is not on stack then we can */
- if (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_RIGHT(uic)) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- !OP_SYMBOL(IC_RIGHT(uic))->onStack)))
- goto accuse;
-
- if (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_LEFT(uic)) ||
- (IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- !OP_SYMBOL(IC_LEFT(uic))->onStack)))
- goto accuse ;
-
- return ;
-
- accuse:
- OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
-
-
+ /* if the other one is not on stack then we can */
+ if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_RIGHT (uic)) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
+ goto accuse;
+
+ if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_LEFT (uic)) ||
+ (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ !OP_SYMBOL (IC_LEFT (uic))->onStack)))
+ goto accuse;
+
+ return;
+
+accuse:
+ OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
+
+
}
/*-----------------------------------------------------------------*/
/* packForPush - hueristics to reduce iCode for pushing */
/*-----------------------------------------------------------------*/
-static void packForPush(iCode *ic, eBBlock *ebp)
+static void
+packForPush (iCode * ic, eBBlock * ebp)
{
- iCode *dic;
-
- if (ic->op != IPUSH || !IS_ITEMP(IC_LEFT(ic)))
- return ;
-
- /* must have only definition & one usage */
- if (bitVectnBitsOn(OP_DEFS(IC_LEFT(ic))) != 1 ||
- bitVectnBitsOn(OP_USES(IC_LEFT(ic))) != 1 )
- return ;
-
- /* find the definition */
- if (!(dic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(IC_LEFT(ic))))))
- return ;
-
- if (dic->op != '=' || POINTER_SET(dic))
- return;
-
- /* we now we know that it has one & only one def & use
- and the that the definition is an assignment */
- IC_LEFT(ic) = IC_RIGHT(dic);
-
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
+ iCode *dic;
+
+ if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
+ return;
+
+ /* must have only definition & one usage */
+ if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
+ bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
+ return;
+
+ /* find the definition */
+ if (!(dic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
+ return;
+
+ if (dic->op != '=' || POINTER_SET (dic))
+ return;
+
+ /* we now we know that it has one & only one def & use
+ and the that the definition is an assignment */
+ IC_LEFT (ic) = IC_RIGHT (dic);
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
}
/*-----------------------------------------------------------------*/
/* packRegisters - does some transformations to reduce register */
/* pressure */
/*-----------------------------------------------------------------*/
-static void packRegisters (eBBlock *ebp)
+static void
+packRegisters (eBBlock * ebp)
{
- iCode *ic ;
- int change = 0 ;
-
- while (1) {
-
- change = 0;
-
- /* look for assignments of the form */
- /* iTempNN = TRueSym (someoperation) SomeOperand */
- /* .... */
- /* TrueSym := iTempNN:1 */
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
-
- /* find assignment of the form TrueSym := iTempNN:1 */
- if (ic->op == '=' && !POINTER_SET(ic))
- change += packRegsForAssign(ic,ebp);
+ iCode *ic;
+ int change = 0;
+
+ while (1)
+ {
+
+ change = 0;
+
+ /* look for assignments of the form */
+ /* iTempNN = TRueSym (someoperation) SomeOperand */
+ /* .... */
+ /* TrueSym := iTempNN:1 */
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+
+ /* find assignment of the form TrueSym := iTempNN:1 */
+ if (ic->op == '=' && !POINTER_SET (ic))
+ change += packRegsForAssign (ic, ebp);
}
- if (!change)
- break;
+ if (!change)
+ break;
}
-
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
- /* if this is an itemp & result of a address of a true sym
- then mark this as rematerialisable */
- if (ic->op == ADDRESS_OF &&
- IS_ITEMP(IC_RESULT(ic)) &&
- IS_TRUE_SYMOP(IC_LEFT(ic)) &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- !OP_SYMBOL(IC_LEFT(ic))->onStack ) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an itemp & result of a address of a true sym
+ then mark this as rematerialisable */
+ if (ic->op == ADDRESS_OF &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ IS_TRUE_SYMOP (IC_LEFT (ic)) &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ !OP_SYMBOL (IC_LEFT (ic))->onStack)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
-
- /* if straight assignment then carry remat flag if
- this is the only definition */
- if (ic->op == '=' &&
- !POINTER_SET(ic) &&
- IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->remat &&
- bitVectnBitsOn(OP_SYMBOL(IC_RESULT(ic))->defs) <= 1) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat =
- OP_SYMBOL(IC_RIGHT(ic))->remat;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode =
- OP_SYMBOL(IC_RIGHT(ic))->rematiCode ;
+
+ /* if straight assignment then carry remat flag if
+ this is the only definition */
+ if (ic->op == '=' &&
+ !POINTER_SET (ic) &&
+ IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->remat &&
+ bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat =
+ OP_SYMBOL (IC_RIGHT (ic))->remat;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode =
+ OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
}
- /* if this is a +/- operation with a rematerizable
- then mark this as rematerializable as well */
- if ((ic->op == '+' || ic->op == '-') &&
- (IS_SYMOP(IC_LEFT(ic)) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->remat &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- IS_OP_LITERAL(IC_RIGHT(ic))) ) {
-
- int i = operandLitValue(IC_RIGHT(ic));
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+ /* if this is a +/- operation with a rematerizable
+ then mark this as rematerializable as well */
+ if ((ic->op == '+' || ic->op == '-') &&
+ (IS_SYMOP (IC_LEFT (ic)) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->remat &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ IS_OP_LITERAL (IC_RIGHT (ic))))
+ {
+
+ //int i = operandLitValue (IC_RIGHT (ic));
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
- /* mark the pointer usages */
- if (POINTER_SET(ic))
- OP_SYMBOL(IC_RESULT(ic))->uptr = 1;
-
- if (POINTER_GET(ic))
- OP_SYMBOL(IC_LEFT(ic))->uptr = 1;
-
- if (!SKIP_IC2(ic)) {
- /* if we are using a symbol on the stack
- then we should say mcs51_ptrRegReq */
- if (ic->op == IFX && IS_SYMOP(IC_COND(ic)))
- mcs51_ptrRegReq += ((OP_SYMBOL(IC_COND(ic))->onStack ||
- OP_SYMBOL(IC_COND(ic))->iaccess) ? 1 : 0);
- else
- if (ic->op == JUMPTABLE && IS_SYMOP(IC_JTCOND(ic)))
- mcs51_ptrRegReq += ((OP_SYMBOL(IC_JTCOND(ic))->onStack ||
- OP_SYMBOL(IC_JTCOND(ic))->iaccess) ? 1 : 0);
- else {
- if (IS_SYMOP(IC_LEFT(ic)))
- mcs51_ptrRegReq += ((OP_SYMBOL(IC_LEFT(ic))->onStack ||
- OP_SYMBOL(IC_LEFT(ic))->iaccess) ? 1 : 0);
- if (IS_SYMOP(IC_RIGHT(ic)))
- mcs51_ptrRegReq += ((OP_SYMBOL(IC_RIGHT(ic))->onStack ||
- OP_SYMBOL(IC_RIGHT(ic))->iaccess) ? 1 : 0);
- if (IS_SYMOP(IC_RESULT(ic)))
- mcs51_ptrRegReq += ((OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess) ? 1 : 0);
- }
+ /* mark the pointer usages */
+ if (POINTER_SET (ic))
+ OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
+
+ if (POINTER_GET (ic))
+ OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
+
+ if (!SKIP_IC2 (ic))
+ {
+ /* if we are using a symbol on the stack
+ then we should say mcs51_ptrRegReq */
+ if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
+ mcs51_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ||
+ OP_SYMBOL (IC_COND (ic))->iaccess) ? 1 : 0);
+ else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
+ mcs51_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ||
+ OP_SYMBOL (IC_JTCOND (ic))->iaccess) ? 1 : 0);
+ else
+ {
+ if (IS_SYMOP (IC_LEFT (ic)))
+ mcs51_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ||
+ OP_SYMBOL (IC_LEFT (ic))->iaccess) ? 1 : 0);
+ if (IS_SYMOP (IC_RIGHT (ic)))
+ mcs51_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ||
+ OP_SYMBOL (IC_RIGHT (ic))->iaccess) ? 1 : 0);
+ if (IS_SYMOP (IC_RESULT (ic)))
+ mcs51_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess) ? 1 : 0);
+ }
}
- /* if the condition of an if instruction
- is defined in the previous instruction then
- mark the itemp as a conditional */
- if ((IS_CONDITIONAL(ic) ||
- ( ( ic->op == BITWISEAND ||
- ic->op == '|' ||
- ic->op == '^' ) &&
- isBitwiseOptimizable(ic))) &&
- ic->next && ic->next->op == IFX &&
- isOperandEqual(IC_RESULT(ic),IC_COND(ic->next)) &&
- OP_SYMBOL(IC_RESULT(ic))->liveTo <= ic->next->seq) {
-
- OP_SYMBOL(IC_RESULT(ic))->regType = REG_CND;
- continue ;
+ /* if the condition of an if instruction
+ is defined in the previous instruction then
+ mark the itemp as a conditional */
+ if ((IS_CONDITIONAL (ic) ||
+ ((ic->op == BITWISEAND ||
+ ic->op == '|' ||
+ ic->op == '^') &&
+ isBitwiseOptimizable (ic))) &&
+ ic->next && ic->next->op == IFX &&
+ isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
+ OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
+ continue;
}
-
- /* reduce for support function calls */
- if (ic->supportRtn || ic->op == '+' || ic->op == '-' )
- packRegsForSupport (ic,ebp);
-
- /* some cases the redundant moves can
- can be eliminated for return statements */
- if ((ic->op == RETURN || ic->op == SEND) &&
- !isOperandInFarSpace(IC_LEFT(ic)) &&
- options.model == MODEL_SMALL)
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
-
- /* if pointer set & left has a size more than
- one and right is not in far space */
- if (POINTER_SET(ic) &&
- !isOperandInFarSpace(IC_RIGHT(ic)) &&
- !OP_SYMBOL(IC_RESULT(ic))->remat &&
- !IS_OP_RUONLY(IC_RIGHT(ic)) &&
- getSize(aggrToPtr(operandType(IC_RESULT(ic)),FALSE)) > 1 )
-
- packRegsForOneuse (ic,IC_RESULT(ic),ebp);
-
- /* if pointer get */
- if (POINTER_GET(ic) &&
- !isOperandInFarSpace(IC_RESULT(ic))&&
- !OP_SYMBOL(IC_LEFT(ic))->remat &&
- !IS_OP_RUONLY(IC_RESULT(ic)) &&
- getSize(aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) > 1 )
-
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
-
-
- /* if this is cast for intergral promotion then
- check if only use of the definition of the
- operand being casted/ if yes then replace
- the result of that arithmetic operation with
- this result and get rid of the cast */
- if (ic->op == CAST) {
- sym_link *fromType = operandType(IC_RIGHT(ic));
- sym_link *toType = operandType(IC_LEFT(ic));
-
- if (IS_INTEGRAL(fromType) && IS_INTEGRAL(toType) &&
- getSize(fromType) != getSize(toType) &&
- SPEC_USIGN(fromType) == SPEC_USIGN(toType)) {
-
- iCode *dic = packRegsForOneuse(ic,IC_RIGHT(ic),ebp);
- if (dic) {
- if (IS_ARITHMETIC_OP(dic)) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- ic = ic->prev;
- } else
- OP_SYMBOL(IC_RIGHT(ic))->ruonly = 0;
- }
- } else {
-
- /* if the type from and type to are the same
- then if this is the only use then packit */
- if (checkType(operandType(IC_RIGHT(ic)),
- operandType(IC_LEFT(ic))) == 1) {
- iCode *dic = packRegsForOneuse (ic,IC_RIGHT(ic),ebp);
- if (dic) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- ic = ic->prev;
+
+ /* reduce for support function calls */
+ if (ic->supportRtn || ic->op == '+' || ic->op == '-')
+ packRegsForSupport (ic, ebp);
+
+ /* some cases the redundant moves can
+ can be eliminated for return statements */
+ if ((ic->op == RETURN || ic->op == SEND) &&
+ !isOperandInFarSpace (IC_LEFT (ic)) &&
+ options.model == MODEL_SMALL)
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+
+ /* if pointer set & left has a size more than
+ one and right is not in far space */
+ if (POINTER_SET (ic) &&
+ !isOperandInFarSpace (IC_RIGHT (ic)) &&
+ !OP_SYMBOL (IC_RESULT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RIGHT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
+
+ packRegsForOneuse (ic, IC_RESULT (ic), ebp);
+
+ /* if pointer get */
+ if (POINTER_GET (ic) &&
+ !isOperandInFarSpace (IC_RESULT (ic)) &&
+ !OP_SYMBOL (IC_LEFT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RESULT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
+
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+
+
+ /* if this is cast for intergral promotion then
+ check if only use of the definition of the
+ operand being casted/ if yes then replace
+ the result of that arithmetic operation with
+ this result and get rid of the cast */
+ if (ic->op == CAST)
+ {
+ sym_link *fromType = operandType (IC_RIGHT (ic));
+ sym_link *toType = operandType (IC_LEFT (ic));
+
+ if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
+ getSize (fromType) != getSize (toType) &&
+ SPEC_USIGN (fromType) == SPEC_USIGN (toType))
+ {
+
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ if (IS_ARITHMETIC_OP (dic))
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ ic = ic->prev;
+ }
+ else
+ OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
+ }
+ }
+ else
+ {
+
+ /* if the type from and type to are the same
+ then if this is the only use then packit */
+ if (checkType (operandType (IC_RIGHT (ic)),
+ operandType (IC_LEFT (ic))) == 1)
+ {
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ ic = ic->prev;
}
}
}
}
-
- /* pack for PUSH
- iTempNN := (some variable in farspace) V1
- push iTempNN ;
- -------------
- push V1
- */
- if (ic->op == IPUSH ) {
- packForPush(ic,ebp);
+
+ /* pack for PUSH
+ iTempNN := (some variable in farspace) V1
+ push iTempNN ;
+ -------------
+ push V1
+ */
+ if (ic->op == IPUSH)
+ {
+ packForPush (ic, ebp);
}
-
-
- /* pack registers for accumulator use, when the
- result of an arithmetic or bit wise operation
- has only one use, that use is immediately following
- the defintion and the using iCode has only one
- operand or has two operands but one is literal &
- the result of that operation is not on stack then
- we can leave the result of this operation in acc:b
- combination */
- if ((IS_ARITHMETIC_OP(ic)
- || IS_BITWISE_OP(ic)
- || ic->op == LEFT_OP || ic->op == RIGHT_OP
- || (ic->op == ADDRESS_OF && isOperandOnStack(IC_LEFT(ic)))
- ) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- getSize(operandType(IC_RESULT(ic))) <= 2)
-
- packRegsForAccUse (ic);
+
+
+ /* pack registers for accumulator use, when the
+ result of an arithmetic or bit wise operation
+ has only one use, that use is immediately following
+ the defintion and the using iCode has only one
+ operand or has two operands but one is literal &
+ the result of that operation is not on stack then
+ we can leave the result of this operation in acc:b
+ combination */
+ if ((IS_ARITHMETIC_OP (ic)
+ || IS_BITWISE_OP (ic)
+ || ic->op == LEFT_OP || ic->op == RIGHT_OP
+ || (ic->op == ADDRESS_OF && isOperandOnStack (IC_LEFT (ic)))
+ ) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ getSize (operandType (IC_RESULT (ic))) <= 2)
+
+ packRegsForAccUse (ic);
}
}
-
+
/*-----------------------------------------------------------------*/
/* assignRegisters - assigns registers to each live range as need */
/*-----------------------------------------------------------------*/
-void mcs51_assignRegisters (eBBlock **ebbs, int count)
+void
+mcs51_assignRegisters (eBBlock ** ebbs, int count)
{
- iCode *ic;
- int i ;
-
- setToNull((void *)&_G.funcrUsed);
- mcs51_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
- /* if not register extentions then reduce number
- of registers */
- if (options.regExtend)
- mcs51_nRegs = 13;
- else
- mcs51_nRegs = 8;
-
- /* change assignments this will remove some
- live ranges reducing some register pressure */
- for (i = 0 ; i < count ;i++ )
- packRegisters (ebbs[i]);
-
- if (options.dump_pack)
- dumpEbbsToFileExt(".dumppack",ebbs,count);
-
- /* first determine for each live range the number of
- registers & the type of registers required for each */
- regTypeNum ();
-
- /* and serially allocate registers */
- serialRegAssign(ebbs,count);
-
- /* if stack was extended then tell the user */
- if (_G.stackExtend) {
-/* werror(W_TOOMANY_SPILS,"stack", */
-/* _G.stackExtend,currFunc->name,""); */
- _G.stackExtend = 0 ;
+ iCode *ic;
+ int i;
+
+ setToNull ((void *) &_G.funcrUsed);
+ mcs51_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
+ /* if not register extentions then reduce number
+ of registers */
+ if (options.regExtend)
+ mcs51_nRegs = 13;
+ else
+ mcs51_nRegs = 8;
+
+ /* change assignments this will remove some
+ live ranges reducing some register pressure */
+ for (i = 0; i < count; i++)
+ packRegisters (ebbs[i]);
+
+ if (options.dump_pack)
+ dumpEbbsToFileExt (".dumppack", ebbs, count);
+
+ /* first determine for each live range the number of
+ registers & the type of registers required for each */
+ regTypeNum ();
+
+ /* and serially allocate registers */
+ serialRegAssign (ebbs, count);
+
+ /* if stack was extended then tell the user */
+ if (_G.stackExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"stack", */
+/* _G.stackExtend,currFunc->name,""); */
+ _G.stackExtend = 0;
}
- if (_G.dataExtend) {
-/* werror(W_TOOMANY_SPILS,"data space", */
-/* _G.dataExtend,currFunc->name,""); */
- _G.dataExtend = 0 ;
- }
+ if (_G.dataExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"data space", */
+/* _G.dataExtend,currFunc->name,""); */
+ _G.dataExtend = 0;
+ }
- /* after that create the register mask
- for each of the instruction */
- createRegMask (ebbs,count);
+ /* after that create the register mask
+ for each of the instruction */
+ createRegMask (ebbs, count);
- /* redo that offsets for stacked automatic variables */
- redoStackOffsets ();
+ /* redo that offsets for stacked automatic variables */
+ redoStackOffsets ();
- if (options.dump_rassgn) {
- dumpEbbsToFileExt(".dumprassgn",ebbs,count);
- dumpLiveRanges(".lrange",liveRanges);
+ if (options.dump_rassgn)
+ {
+ dumpEbbsToFileExt (".dumprassgn", ebbs, count);
+ dumpLiveRanges (".lrange", liveRanges);
}
- /* do the overlaysegment stuff SDCCmem.c */
- doOverlays(ebbs,count);
+ /* do the overlaysegment stuff SDCCmem.c */
+ doOverlays (ebbs, count);
- /* now get back the chain */
- ic = iCodeLabelOptimize(iCodeFromeBBlock (ebbs,count));
+ /* now get back the chain */
+ ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
- gen51Code(ic);
+ gen51Code (ic);
- /* free up any _G.stackSpil locations allocated */
- applyToSet(_G.stackSpil,deallocStackSpil);
- _G.slocNum = 0;
- setToNull((void **)&_G.stackSpil);
- setToNull((void **)&_G.spiltSet);
- /* mark all registers as free */
- freeAllRegs();
+ /* free up any _G.stackSpil locations allocated */
+ applyToSet (_G.stackSpil, deallocStackSpil);
+ _G.slocNum = 0;
+ setToNull ((void **) &_G.stackSpil);
+ setToNull ((void **) &_G.spiltSet);
+ /* mark all registers as free */
+ freeAllRegs ();
- return ;
+ return;
}
#ifndef SDCCRALLOC_H
#define SDCCRALLOC_H 1
-enum { R2_IDX = 0, R3_IDX , R4_IDX ,
- R5_IDX ,R6_IDX , R7_IDX ,
- R0_IDX ,R1_IDX , X8_IDX ,
- X9_IDX ,X10_IDX , X11_IDX ,
- X12_IDX ,CND_IDX };
+enum
+ {
+ R2_IDX = 0, R3_IDX, R4_IDX,
+ R5_IDX, R6_IDX, R7_IDX,
+ R0_IDX, R1_IDX, X8_IDX,
+ X9_IDX, X10_IDX, X11_IDX,
+ X12_IDX, CND_IDX
+ };
#define REG_PTR 0x01
#define REG_CND 0x04
/* definition for the registers */
typedef struct regs
-{
- short type; /* can have value
- REG_GPR, REG_PTR or REG_CND */
- short rIdx ; /* index into register table */
- short otype;
- char *name ; /* name */
- char *dname; /* name when direct access needed */
- char *base ; /* base address */
- short offset; /* offset from the base */
- unsigned isFree :1; /* is currently unassigned */
-} regs;
+ {
+ short type; /* can have value
+ REG_GPR, REG_PTR or REG_CND */
+ short rIdx; /* index into register table */
+ short otype;
+ char *name; /* name */
+ char *dname; /* name when direct access needed */
+ char *base; /* base address */
+ short offset; /* offset from the base */
+ unsigned isFree:1; /* is currently unassigned */
+ }
+regs;
extern regs regs8051[];
-regs *mcs51_regWithIdx (int);
+regs *mcs51_regWithIdx (int);
#endif
#include "gen.h"
//char *aopLiteral (value *val, int offset);
-char *pic14aopLiteral (value *val, int offset);
+char *pic14aopLiteral (value * val, int offset);
/* this is the down and dirty file with all kinds of
kludgy & hacky stuff. This is what it is all about
routines may be reusable, will have to see */
static char *zero = "#0x00";
-static char *one = "#0x01";
+static char *one = "#0x01";
static char *spname = "sp";
-char *fReturnpic14[] = {"fsr","dph","b","a" };
+char *fReturnpic14[] =
+{"fsr", "dph", "b", "a"};
//char *fReturn390[] = {"dpl","dph","dpx", "b","a" };
-static unsigned fReturnSize = 4; /* shared with ralloc.c */
+static unsigned fReturnSize = 4; /* shared with ralloc.c */
static char **fReturn = fReturnpic14;
-static char *accUse[] = {"a","b"};
+static char *accUse[] =
+{"a", "b"};
//static short rbank = -1;
-static struct {
+static struct
+ {
short r0Pushed;
short r1Pushed;
short accInUse;
short debugLine;
short nRegsSaved;
set *sendSet;
-} _G;
+ }
+_G;
-extern int pic14_ptrRegReq ;
+extern int pic14_ptrRegReq;
extern int pic14_nRegs;
extern FILE *codeOutFile;
-static void saverbank (int, iCode *,bool);
+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};
+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 FUNCTION_LABEL_INC 20
-static int labelOffset=0;
-static int debug_verbose=0;
+static int labelOffset = 0;
+static int debug_verbose = 0;
/*-----------------------------------------------------------------*/
/* return y; */
/* return -1; */
/*-----------------------------------------------------------------*/
-static int my_powof2 (unsigned long num)
+static int
+my_powof2 (unsigned long num)
{
- if(num) {
- if( (num & (num-1)) == 0) {
- int nshifts = -1;
- while(num) {
- num>>=1;
- nshifts++;
- }
- return nshifts;
+ if (num)
+ {
+ if ((num & (num - 1)) == 0)
+ {
+ int nshifts = -1;
+ while (num)
+ {
+ num >>= 1;
+ nshifts++;
+ }
+ return nshifts;
+ }
}
- }
return -1;
}
/*-----------------------------------------------------------------*/
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
-static void emitcode (char *inst,char *fmt, ...)
+static void
+emitcode (char *inst, char *fmt,...)
{
- va_list ap;
- char lb[MAX_INLINEASM];
- char *lbp = lb;
+ va_list ap;
+ char lb[MAX_INLINEASM];
+ char *lbp = lb;
- va_start(ap,fmt);
+ va_start (ap, fmt);
- if (inst && *inst) {
- if (fmt && *fmt)
- sprintf(lb,"%s\t",inst);
+ if (inst && *inst)
+ {
+ if (fmt && *fmt)
+ sprintf (lb, "%s\t", inst);
+ else
+ sprintf (lb, "%s", inst);
+ vsprintf (lb + (strlen (lb)), fmt, ap);
+ }
else
- sprintf(lb,"%s",inst);
- vsprintf(lb+(strlen(lb)),fmt,ap);
- } else
- vsprintf(lb,fmt,ap);
+ vsprintf (lb, fmt, ap);
- while (isspace(*lbp)) lbp++;
+ while (isspace (*lbp))
+ lbp++;
- if (lbp && *lbp)
- lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(lb)) :
- (lineHead = newLineNode(lb)));
- lineCurr->isInline = _G.inLine;
- lineCurr->isDebug = _G.debugLine;
- va_end(ap);
+ if (lbp && *lbp)
+ lineCurr = (lineCurr ?
+ connectLine (lineCurr, newLineNode (lb)) :
+ (lineHead = newLineNode (lb)));
+ lineCurr->isInline = _G.inLine;
+ lineCurr->isDebug = _G.debugLine;
+ va_end (ap);
}
-static void DEBUGemitcode (char *inst,char *fmt, ...)
+static void
+DEBUGemitcode (char *inst, char *fmt,...)
{
- va_list ap;
- char lb[MAX_INLINEASM];
- char *lbp = lb;
+ va_list ap;
+ char lb[MAX_INLINEASM];
+ char *lbp = lb;
- if(!debug_verbose)
- return;
+ if (!debug_verbose)
+ return;
- va_start(ap,fmt);
+ va_start (ap, fmt);
- if (inst && *inst) {
- if (fmt && *fmt)
- sprintf(lb,"%s\t",inst);
+ if (inst && *inst)
+ {
+ if (fmt && *fmt)
+ sprintf (lb, "%s\t", inst);
+ else
+ sprintf (lb, "%s", inst);
+ vsprintf (lb + (strlen (lb)), fmt, ap);
+ }
else
- sprintf(lb,"%s",inst);
- vsprintf(lb+(strlen(lb)),fmt,ap);
- } else
- vsprintf(lb,fmt,ap);
+ vsprintf (lb, fmt, ap);
- while (isspace(*lbp)) lbp++;
+ while (isspace (*lbp))
+ lbp++;
- if (lbp && *lbp)
- lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(lb)) :
- (lineHead = newLineNode(lb)));
- lineCurr->isInline = _G.inLine;
- lineCurr->isDebug = _G.debugLine;
- va_end(ap);
+ if (lbp && *lbp)
+ lineCurr = (lineCurr ?
+ connectLine (lineCurr, newLineNode (lb)) :
+ (lineHead = newLineNode (lb)));
+ lineCurr->isInline = _G.inLine;
+ lineCurr->isDebug = _G.debugLine;
+ va_end (ap);
}
/*-----------------------------------------------------------------*/
-/* getFreePtr - returns r0 or r1 whichever is free or can be pushed*/
+/* getFreePtr - returns r0 or r1 whichever is free or can be pushed */
/*-----------------------------------------------------------------*/
-static regs *getFreePtr (iCode *ic, asmop **aopp, bool result)
+static regs *
+getFreePtr (iCode * ic, asmop ** aopp, bool result)
{
- bool r0iu = FALSE , r1iu = FALSE;
- bool r0ou = FALSE , r1ou = FALSE;
+ bool r0iu = FALSE, r1iu = FALSE;
+ bool r0ou = FALSE, r1ou = FALSE;
- /* the logic: if r0 & r1 used in the instruction
- then we are in trouble otherwise */
+ /* the logic: if r0 & r1 used in the instruction
+ then we are in trouble otherwise */
- /* 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)))
+ /* 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)))
{
- goto endOfWorld;
+ goto endOfWorld;
}
- r0ou = bitVectBitValue(ic->rMask,R0_IDX);
- r1ou = bitVectBitValue(ic->rMask,R1_IDX);
+ r0ou = bitVectBitValue (ic->rMask, R0_IDX);
+ r1ou = bitVectBitValue (ic->rMask, R1_IDX);
- /* if no usage of r0 then return it */
- if (!r0iu && !r0ou) {
- ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
- (*aopp)->type = AOP_R0;
+ /* if no usage of r0 then return it */
+ if (!r0iu && !r0ou)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
+ (*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = pic14_regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = pic14_regWithIdx (R0_IDX);
}
- /* if no usage of r1 then return it */
- if (!r1iu && !r1ou) {
- ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
- (*aopp)->type = AOP_R1;
+ /* if no usage of r1 then return it */
+ if (!r1iu && !r1ou)
+ {
+ ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
+ (*aopp)->type = AOP_R1;
- return (*aopp)->aopu.aop_ptr = pic14_regWithIdx(R1_IDX);
+ return (*aopp)->aopu.aop_ptr = pic14_regWithIdx (R1_IDX);
}
- /* now we know they both have usage */
- /* if r0 not used in this instruction */
- if (!r0iu) {
- /* push it if not already pushed */
- if (!_G.r0Pushed) {
- emitcode ("push","%s",
- pic14_regWithIdx(R0_IDX)->dname);
- _G.r0Pushed++ ;
- }
+ /* now we know they both have usage */
+ /* if r0 not used in this instruction */
+ if (!r0iu)
+ {
+ /* push it if not already pushed */
+ if (!_G.r0Pushed)
+ {
+ emitcode ("push", "%s",
+ pic14_regWithIdx (R0_IDX)->dname);
+ _G.r0Pushed++;
+ }
- ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
- (*aopp)->type = AOP_R0;
+ ic->rUsed = bitVectSetBit (ic->rUsed, R0_IDX);
+ (*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = pic14_regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = pic14_regWithIdx (R0_IDX);
}
- /* if r1 not used then */
+ /* if r1 not used then */
- if (!r1iu) {
- /* push it if not already pushed */
- if (!_G.r1Pushed) {
- emitcode ("push","%s",
- pic14_regWithIdx(R1_IDX)->dname);
- _G.r1Pushed++ ;
- }
-
- ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
- (*aopp)->type = AOP_R1;
- return pic14_regWithIdx(R1_IDX);
- }
-
-endOfWorld :
- /* I said end of world but not quite end of world yet */
- /* if this is a result then we can push it on the stack*/
- if (result) {
- (*aopp)->type = AOP_STK;
- return NULL;
+ if (!r1iu)
+ {
+ /* push it if not already pushed */
+ if (!_G.r1Pushed)
+ {
+ emitcode ("push", "%s",
+ pic14_regWithIdx (R1_IDX)->dname);
+ _G.r1Pushed++;
+ }
+
+ ic->rUsed = bitVectSetBit (ic->rUsed, R1_IDX);
+ (*aopp)->type = AOP_R1;
+ return pic14_regWithIdx (R1_IDX);
+ }
+
+endOfWorld:
+ /* I said end of world but not quite end of world yet */
+ /* if this is a result then we can push it on the stack */
+ if (result)
+ {
+ (*aopp)->type = AOP_STK;
+ 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");
- exit(0);
+ piCode (ic, stdout);
+ /* other wise this is true end of the world */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "getFreePtr should never reach here");
+ exit (0);
}
/*-----------------------------------------------------------------*/
/* newAsmop - creates a new asmOp */
/*-----------------------------------------------------------------*/
-static asmop *newAsmop (short type)
+static asmop *
+newAsmop (short type)
{
- asmop *aop;
+ asmop *aop;
- aop = Safe_calloc(1,sizeof(asmop));
- aop->type = type;
- return aop;
+ aop = Safe_calloc (1, sizeof (asmop));
+ aop->type = type;
+ return aop;
}
-static void genSetDPTR(int n)
+static void
+genSetDPTR (int n)
{
- if (!n)
+ if (!n)
{
- emitcode(";", "Select standard DPTR");
- emitcode("mov", "dps, #0x00");
+ emitcode (";", "Select standard DPTR");
+ emitcode ("mov", "dps, #0x00");
}
- else
+ else
{
- emitcode(";", "Select alternate DPTR");
- emitcode("mov", "dps, #0x01");
+ emitcode (";", "Select alternate DPTR");
+ emitcode ("mov", "dps, #0x01");
}
}
/*-----------------------------------------------------------------*/
/* pointerCode - returns the code for a pointer type */
/*-----------------------------------------------------------------*/
-static int pointerCode (sym_link *etype)
+static int
+pointerCode (sym_link * etype)
{
- return PTR_TYPE(SPEC_OCLS(etype));
+ return PTR_TYPE (SPEC_OCLS (etype));
}
/*-----------------------------------------------------------------*/
/* aopForSym - for a true symbol */
/*-----------------------------------------------------------------*/
-static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
-{
- asmop *aop;
- memmap *space= SPEC_OCLS(sym->etype);
-
- DEBUGemitcode("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if already has one */
- if (sym->aop)
- return sym->aop;
-
- /* assign depending on the storage class */
- /* if it is on the stack or indirectly addressable */
- /* space we need to assign either r0 or r1 to it */
- if ((sym->onStack && !options.stack10bit) || sym->iaccess) {
- sym->aop = aop = newAsmop(0);
- aop->aopu.aop_ptr = getFreePtr(ic,&aop,result);
- aop->size = getSize(sym->type);
-
- /* now assign the address of the variable to
- the pointer register */
- if (aop->type != AOP_STK) {
-
- if (sym->onStack) {
- if ( _G.accInUse )
- emitcode("push","acc");
-
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",
- ((sym->stack < 0) ?
- ((char)(sym->stack - _G.nRegsSaved )) :
- ((char)sym->stack)) & 0xff);
- emitcode("mov","%s,a",
- aop->aopu.aop_ptr->name);
-
- if ( _G.accInUse )
- emitcode("pop","acc");
- } else
- emitcode("mov","%s,#%s",
- aop->aopu.aop_ptr->name,
- sym->rname);
- aop->paged = space->paged;
- } else
- aop->aopu.aop_stk = sym->stack;
- return aop;
- }
-
- if (sym->onStack && options.stack10bit)
- {
- /* It's on the 10 bit stack, which is located in
- * far data space.
- */
+static asmop *
+aopForSym (iCode * ic, symbol * sym, bool result)
+{
+ asmop *aop;
+ memmap *space = SPEC_OCLS (sym->etype);
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if already has one */
+ if (sym->aop)
+ return sym->aop;
+
+ /* assign depending on the storage class */
+ /* if it is on the stack or indirectly addressable */
+ /* space we need to assign either r0 or r1 to it */
+ if ((sym->onStack && !options.stack10bit) || sym->iaccess)
+ {
+ sym->aop = aop = newAsmop (0);
+ aop->aopu.aop_ptr = getFreePtr (ic, &aop, result);
+ aop->size = getSize (sym->type);
+
+ /* now assign the address of the variable to
+ the pointer register */
+ if (aop->type != AOP_STK)
+ {
+
+ if (sym->onStack)
+ {
+ if (_G.accInUse)
+ emitcode ("push", "acc");
+
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x",
+ ((sym->stack < 0) ?
+ ((char) (sym->stack - _G.nRegsSaved)) :
+ ((char) sym->stack)) & 0xff);
+ emitcode ("mov", "%s,a",
+ aop->aopu.aop_ptr->name);
+
+ if (_G.accInUse)
+ emitcode ("pop", "acc");
+ }
+ else
+ emitcode ("mov", "%s,#%s",
+ aop->aopu.aop_ptr->name,
+ sym->rname);
+ aop->paged = space->paged;
+ }
+ else
+ aop->aopu.aop_stk = sym->stack;
+ return aop;
+ }
+
+ if (sym->onStack && options.stack10bit)
+ {
+ /* It's on the 10 bit stack, which is located in
+ * far data space.
+ */
//DEBUGemitcode(";","%d",__LINE__);
- if ( _G.accInUse )
- emitcode("push","acc");
+ if (_G.accInUse)
+ emitcode ("push", "acc");
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",
- ((sym->stack < 0) ?
- ((char)(sym->stack - _G.nRegsSaved )) :
- ((char)sym->stack)) & 0xff);
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x",
+ ((sym->stack < 0) ?
+ ((char) (sym->stack - _G.nRegsSaved)) :
+ ((char) sym->stack)) & 0xff);
- genSetDPTR(1);
- emitcode ("mov","dpx1,#0x40");
- emitcode ("mov","dph1,#0x00");
- emitcode ("mov","dpl1, a");
- genSetDPTR(0);
+ genSetDPTR (1);
+ emitcode ("mov", "dpx1,#0x40");
+ emitcode ("mov", "dph1,#0x00");
+ emitcode ("mov", "dpl1, a");
+ genSetDPTR (0);
- if ( _G.accInUse )
- emitcode("pop","acc");
+ if (_G.accInUse)
+ emitcode ("pop", "acc");
- sym->aop = aop = newAsmop(AOP_DPTR2);
- aop->size = getSize(sym->type);
+ sym->aop = aop = newAsmop (AOP_DPTR2);
+ aop->size = getSize (sym->type);
return aop;
}
- //DEBUGemitcode(";","%d",__LINE__);
- /* if in bit space */
- if (IN_BITSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_CRY);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- DEBUGemitcode(";","%d sym->rname = %s, size = %d",__LINE__,sym->rname,aop->size);
- return aop;
+ //DEBUGemitcode(";","%d",__LINE__);
+ /* if in bit space */
+ if (IN_BITSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_CRY);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ DEBUGemitcode (";", "%d sym->rname = %s, size = %d", __LINE__, sym->rname, aop->size);
+ return aop;
}
- /* if it is in direct space */
- if (IN_DIRSPACE(space)) {
- sym->aop = aop = newAsmop (AOP_DIR);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- DEBUGemitcode(";","%d sym->rname = %s, size = %d",__LINE__,sym->rname,aop->size);
- return aop;
+ /* if it is in direct space */
+ if (IN_DIRSPACE (space))
+ {
+ sym->aop = aop = newAsmop (AOP_DIR);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ DEBUGemitcode (";", "%d sym->rname = %s, size = %d", __LINE__, sym->rname, aop->size);
+ return aop;
}
- /* special case for a function */
- if (IS_FUNC(sym->type)) {
- sym->aop = aop = newAsmop(AOP_IMMD);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(sym->rname)+1);
- strcpy(aop->aopu.aop_immd,sym->rname);
- aop->size = FPTRSIZE;
- return aop;
+ /* special case for a function */
+ if (IS_FUNC (sym->type))
+ {
+ sym->aop = aop = newAsmop (AOP_IMMD);
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (sym->rname) + 1);
+ strcpy (aop->aopu.aop_immd, sym->rname);
+ aop->size = FPTRSIZE;
+ return aop;
}
- /* only remaining is far space */
- /* in which case DPTR gets the address */
- sym->aop = aop = newAsmop(AOP_DPTR);
- emitcode ("mov","dptr,#%s", sym->rname);
- aop->size = getSize(sym->type);
+ /* only remaining is far space */
+ /* in which case DPTR gets the address */
+ sym->aop = aop = newAsmop (AOP_DPTR);
+ emitcode ("mov", "dptr,#%s", sym->rname);
+ aop->size = getSize (sym->type);
- DEBUGemitcode(";","%d size = %d",__LINE__,aop->size);
- /* if it is in code space */
- if (IN_CODESPACE(space))
- aop->code = 1;
+ DEBUGemitcode (";", "%d size = %d", __LINE__, aop->size);
+ /* if it is in code space */
+ if (IN_CODESPACE (space))
+ aop->code = 1;
- return aop;
+ return aop;
}
/*-----------------------------------------------------------------*/
/* aopForRemat - rematerialzes an object */
/*-----------------------------------------------------------------*/
-static asmop *aopForRemat (symbol *sym)
+static asmop *
+aopForRemat (symbol * sym)
{
- iCode *ic = sym->rematiCode;
- asmop *aop = newAsmop(AOP_IMMD);
- int val = 0;
- DEBUGemitcode(";","%s %d",__FUNCTION__,__LINE__);
- for (;;) {
+ iCode *ic = sym->rematiCode;
+ asmop *aop = newAsmop (AOP_IMMD);
+ int val = 0;
+ DEBUGemitcode (";", "%s %d", __FUNCTION__, __LINE__);
+ for (;;)
+ {
if (ic->op == '+')
- val += operandLitValue(IC_RIGHT(ic));
- else if (ic->op == '-')
- val -= operandLitValue(IC_RIGHT(ic));
- else
- break;
+ val += operandLitValue (IC_RIGHT (ic));
+ else if (ic->op == '-')
+ val -= operandLitValue (IC_RIGHT (ic));
+ else
+ break;
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
}
- if (val)
- sprintf(buffer,"(%s %c 0x%04x)",
- OP_SYMBOL(IC_LEFT(ic))->rname,
- val >= 0 ? '+' : '-',
- abs(val) & 0xffff);
- else
- strcpy(buffer,OP_SYMBOL(IC_LEFT(ic))->rname);
+ if (val)
+ sprintf (buffer, "(%s %c 0x%04x)",
+ OP_SYMBOL (IC_LEFT (ic))->rname,
+ val >= 0 ? '+' : '-',
+ abs (val) & 0xffff);
+ else
+ strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname);
- //DEBUGemitcode(";","%s",buffer);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(buffer)+1);
- strcpy(aop->aopu.aop_immd,buffer);
- return aop;
+ //DEBUGemitcode(";","%s",buffer);
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (buffer) + 1);
+ strcpy (aop->aopu.aop_immd, buffer);
+ return aop;
}
/*-----------------------------------------------------------------*/
/* regsInCommon - two operands have some registers in common */
/*-----------------------------------------------------------------*/
-static bool regsInCommon (operand *op1, operand *op2)
+static bool
+regsInCommon (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
- int i;
+ symbol *sym1, *sym2;
+ int i;
- /* if they have registers in common */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE ;
+ /* if they have registers in common */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- if (sym1->nRegs == 0 || sym2->nRegs == 0)
- return FALSE ;
+ if (sym1->nRegs == 0 || sym2->nRegs == 0)
+ return FALSE;
- for (i = 0 ; i < sym1->nRegs ; i++) {
- int j;
- if (!sym1->regs[i])
- continue ;
+ for (i = 0; i < sym1->nRegs; i++)
+ {
+ int j;
+ if (!sym1->regs[i])
+ continue;
- for (j = 0 ; j < sym2->nRegs ;j++ ) {
- if (!sym2->regs[j])
- continue ;
+ for (j = 0; j < sym2->nRegs; j++)
+ {
+ if (!sym2->regs[j])
+ continue;
- if (sym2->regs[j] == sym1->regs[i])
- return TRUE ;
- }
+ if (sym2->regs[j] == sym1->regs[i])
+ return TRUE;
+ }
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* operandsEqu - equivalent */
/*-----------------------------------------------------------------*/
-static bool operandsEqu ( operand *op1, operand *op2)
+static bool
+operandsEqu (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
+ symbol *sym1, *sym2;
- /* if they not symbols */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE;
+ /* if they not symbols */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- /* if both are itemps & one is spilt
- and the other is not then false */
- if (IS_ITEMP(op1) && IS_ITEMP(op2) &&
- sym1->isspilt != sym2->isspilt )
- return FALSE ;
+ /* if both are itemps & one is spilt
+ and the other is not then false */
+ if (IS_ITEMP (op1) && IS_ITEMP (op2) &&
+ sym1->isspilt != sym2->isspilt)
+ return FALSE;
- /* if they are the same */
- if (sym1 == sym2)
- return TRUE ;
+ /* if they are the same */
+ if (sym1 == sym2)
+ return TRUE;
- if (strcmp(sym1->rname,sym2->rname) == 0)
- return TRUE;
+ if (strcmp (sym1->rname, sym2->rname) == 0)
+ return TRUE;
- /* if left is a tmp & right is not */
- if (IS_ITEMP(op1) &&
- !IS_ITEMP(op2) &&
- sym1->isspilt &&
- (sym1->usl.spillLoc == sym2))
- return TRUE;
+ /* if left is a tmp & right is not */
+ if (IS_ITEMP (op1) &&
+ !IS_ITEMP (op2) &&
+ sym1->isspilt &&
+ (sym1->usl.spillLoc == sym2))
+ return TRUE;
- if (IS_ITEMP(op2) &&
- !IS_ITEMP(op1) &&
- sym2->isspilt &&
- sym1->level > 0 &&
- (sym2->usl.spillLoc == sym1))
- return TRUE ;
+ if (IS_ITEMP (op2) &&
+ !IS_ITEMP (op1) &&
+ sym2->isspilt &&
+ sym1->level > 0 &&
+ (sym2->usl.spillLoc == sym1))
+ return TRUE;
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* sameRegs - two asmops have the same registers */
/*-----------------------------------------------------------------*/
-static bool sameRegs (asmop *aop1, asmop *aop2 )
+static bool
+sameRegs (asmop * aop1, asmop * aop2)
{
- int i;
+ int i;
- if (aop1 == aop2)
- return TRUE ;
+ if (aop1 == aop2)
+ return TRUE;
- if (aop1->type != AOP_REG ||
- aop2->type != AOP_REG )
- return FALSE ;
+ if (aop1->type != AOP_REG ||
+ aop2->type != AOP_REG)
+ return FALSE;
- if (aop1->size != aop2->size )
- return FALSE ;
+ if (aop1->size != aop2->size)
+ return FALSE;
- for (i = 0 ; i < aop1->size ; i++ )
- if (aop1->aopu.aop_reg[i] !=
- aop2->aopu.aop_reg[i] )
- return FALSE ;
+ for (i = 0; i < aop1->size; i++)
+ if (aop1->aopu.aop_reg[i] !=
+ aop2->aopu.aop_reg[i])
+ return FALSE;
- return TRUE ;
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* aopOp - allocates an asmop for an operand : */
/*-----------------------------------------------------------------*/
-static void aopOp (operand *op, iCode *ic, bool result)
+static void
+aopOp (operand * op, iCode * ic, bool result)
{
- asmop *aop;
- symbol *sym;
- int i;
+ asmop *aop;
+ symbol *sym;
+ int i;
- if (!op)
- return ;
+ if (!op)
+ return;
- DEBUGemitcode(";","%d",__LINE__);
- /* if this a literal */
- if (IS_OP_LITERAL(op)) {
- DEBUGemitcode(";","%d",__LINE__);
- op->aop = aop = newAsmop(AOP_LIT);
- aop->aopu.aop_lit = op->operand.valOperand;
- aop->size = getSize(operandType(op));
- return;
+ DEBUGemitcode (";", "%d", __LINE__);
+ /* if this a literal */
+ if (IS_OP_LITERAL (op))
+ {
+ DEBUGemitcode (";", "%d", __LINE__);
+ op->aop = aop = newAsmop (AOP_LIT);
+ aop->aopu.aop_lit = op->operand.valOperand;
+ aop->size = getSize (operandType (op));
+ return;
}
- /* if already has a asmop then continue */
- if (op->aop)
- return ;
+ /* if already has a asmop then continue */
+ if (op->aop)
+ return;
- /* if the underlying symbol has a aop */
- if (IS_SYMOP(op) && OP_SYMBOL(op)->aop) {
- DEBUGemitcode(";","%d",__LINE__);
- op->aop = OP_SYMBOL(op)->aop;
- return;
+ /* if the underlying symbol has a aop */
+ if (IS_SYMOP (op) && OP_SYMBOL (op)->aop)
+ {
+ DEBUGemitcode (";", "%d", __LINE__);
+ op->aop = OP_SYMBOL (op)->aop;
+ return;
}
- /* if this is a true symbol */
- if (IS_TRUE_SYMOP(op)) {
- DEBUGemitcode(";","%d",__LINE__);
- op->aop = aopForSym(ic,OP_SYMBOL(op),result);
- return ;
+ /* if this is a true symbol */
+ if (IS_TRUE_SYMOP (op))
+ {
+ DEBUGemitcode (";", "%d", __LINE__);
+ op->aop = aopForSym (ic, OP_SYMBOL (op), result);
+ return;
}
- /* this is a temporary : this has
- only four choices :
- a) register
- b) spillocation
- c) rematerialize
- d) conditional
- e) can be a return use only */
+ /* this is a temporary : this has
+ only four choices :
+ a) register
+ b) spillocation
+ c) rematerialize
+ d) conditional
+ e) can be a return use only */
- sym = OP_SYMBOL(op);
+ sym = OP_SYMBOL (op);
- /* if the type is a conditional */
- if (sym->regType == REG_CND) {
- DEBUGemitcode(";","%d",__LINE__);
- aop = op->aop = sym->aop = newAsmop(AOP_CRY);
- aop->size = 0;
- return;
+ /* if the type is a conditional */
+ if (sym->regType == REG_CND)
+ {
+ DEBUGemitcode (";", "%d", __LINE__);
+ aop = op->aop = sym->aop = newAsmop (AOP_CRY);
+ aop->size = 0;
+ return;
}
- /* if it is spilt then two situations
- a) is rematerialize
- b) has a spill location */
- if (sym->isspilt || sym->nRegs == 0) {
-
- DEBUGemitcode(";","%d",__LINE__);
- /* rematerialize it NOW */
- if (sym->remat) {
- sym->aop = op->aop = aop =
- aopForRemat (sym);
- aop->size = getSize(sym->type);
- DEBUGemitcode(";","%d",__LINE__);
- return;
- }
-
- if (sym->accuse) {
- int i;
- aop = op->aop = sym->aop = newAsmop(AOP_ACC);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < 2 ; i++ )
- aop->aopu.aop_str[i] = accUse[i];
- DEBUGemitcode(";","%d",__LINE__);
- return;
- }
-
- if (sym->ruonly ) {
- int i;
- aop = op->aop = sym->aop = newAsmop(AOP_STR);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < fReturnSize ; i++ )
- aop->aopu.aop_str[i] = fReturn[i];
- DEBUGemitcode(";","%d",__LINE__);
- return;
- }
+ /* if it is spilt then two situations
+ a) is rematerialize
+ b) has a spill location */
+ if (sym->isspilt || sym->nRegs == 0)
+ {
- /* else spill location */
- DEBUGemitcode(";","%s %d %s",__FUNCTION__,__LINE__,sym->usl.spillLoc->rname);
- sym->aop = op->aop = aop =
- aopForSym(ic,sym->usl.spillLoc,result);
- aop->size = getSize(sym->type);
- return;
+ DEBUGemitcode (";", "%d", __LINE__);
+ /* rematerialize it NOW */
+ if (sym->remat)
+ {
+ sym->aop = op->aop = aop =
+ aopForRemat (sym);
+ aop->size = getSize (sym->type);
+ DEBUGemitcode (";", "%d", __LINE__);
+ return;
+ }
+
+ if (sym->accuse)
+ {
+ int i;
+ aop = op->aop = sym->aop = newAsmop (AOP_ACC);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < 2; i++)
+ aop->aopu.aop_str[i] = accUse[i];
+ DEBUGemitcode (";", "%d", __LINE__);
+ return;
+ }
+
+ if (sym->ruonly)
+ {
+ int i;
+ aop = op->aop = sym->aop = newAsmop (AOP_STR);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < fReturnSize; i++)
+ aop->aopu.aop_str[i] = fReturn[i];
+ DEBUGemitcode (";", "%d", __LINE__);
+ return;
+ }
+
+ /* else spill location */
+ DEBUGemitcode (";", "%s %d %s", __FUNCTION__, __LINE__, sym->usl.spillLoc->rname);
+ sym->aop = op->aop = aop =
+ aopForSym (ic, sym->usl.spillLoc, result);
+ aop->size = getSize (sym->type);
+ return;
}
- /* must be in a register */
- sym->aop = op->aop = aop = newAsmop(AOP_REG);
- aop->size = sym->nRegs;
- for ( i = 0 ; i < sym->nRegs ;i++)
- aop->aopu.aop_reg[i] = sym->regs[i];
+ /* must be in a register */
+ sym->aop = op->aop = aop = newAsmop (AOP_REG);
+ aop->size = sym->nRegs;
+ for (i = 0; i < sym->nRegs; i++)
+ aop->aopu.aop_reg[i] = sym->regs[i];
}
/*-----------------------------------------------------------------*/
/* freeAsmop - free up the asmop given to an operand */
/*----------------------------------------------------------------*/
-static void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
-{
- asmop *aop ;
-
- if (!op)
- aop = aaop;
- else
- aop = op->aop;
-
- if (!aop)
- return ;
-
- if (aop->freed)
- goto dealloc;
-
- aop->freed = 1;
-
- /* depending on the asmop type only three cases need work AOP_RO
- , AOP_R1 && AOP_STK */
- switch (aop->type) {
- case AOP_R0 :
- if (_G.r0Pushed ) {
- if (pop) {
- emitcode ("pop","ar0");
- _G.r0Pushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,R0_IDX);
- break;
-
- case AOP_R1 :
- if (_G.r1Pushed ) {
- if (pop) {
- emitcode ("pop","ar1");
- _G.r1Pushed--;
- }
- }
- bitVectUnSetBit(ic->rUsed,R1_IDX);
- break;
-
- case AOP_STK :
- {
- int sz = aop->size;
- int stk = aop->aopu.aop_stk + aop->size;
- bitVectUnSetBit(ic->rUsed,R0_IDX);
- bitVectUnSetBit(ic->rUsed,R1_IDX);
-
- getFreePtr(ic,&aop,FALSE);
-
- if (options.stack10bit)
- {
- /* I'm not sure what to do here yet... */
- /* #STUB */
- fprintf(stderr,
- "*** Warning: probably generating bad code for "
- "10 bit stack mode.\n");
- }
-
- if (stk) {
- emitcode ("mov","a,_bp");
- emitcode ("add","a,#0x%02x",((char)stk) & 0xff);
- emitcode ("mov","%s,a",aop->aopu.aop_ptr->name);
- } else {
- emitcode ("mov","%s,_bp",aop->aopu.aop_ptr->name);
- }
-
- while (sz--) {
- emitcode("pop","acc");
- emitcode("mov","@%s,a",aop->aopu.aop_ptr->name);
- if (!sz) break;
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- }
- op->aop = aop;
- freeAsmop(op,NULL,ic,TRUE);
- if (_G.r0Pushed) {
- emitcode("pop","ar0");
- _G.r0Pushed--;
- }
-
- if (_G.r1Pushed) {
- emitcode("pop","ar1");
- _G.r1Pushed--;
- }
- }
+static void
+freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
+{
+ asmop *aop;
+
+ if (!op)
+ aop = aaop;
+ else
+ aop = op->aop;
+
+ if (!aop)
+ return;
+
+ if (aop->freed)
+ goto dealloc;
+
+ aop->freed = 1;
+
+ /* depending on the asmop type only three cases need work AOP_RO
+ , AOP_R1 && AOP_STK */
+ switch (aop->type)
+ {
+ case AOP_R0:
+ if (_G.r0Pushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "ar0");
+ _G.r0Pushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, R0_IDX);
+ break;
+
+ case AOP_R1:
+ if (_G.r1Pushed)
+ {
+ if (pop)
+ {
+ emitcode ("pop", "ar1");
+ _G.r1Pushed--;
+ }
+ }
+ bitVectUnSetBit (ic->rUsed, R1_IDX);
+ break;
+
+ case AOP_STK:
+ {
+ int sz = aop->size;
+ int stk = aop->aopu.aop_stk + aop->size;
+ bitVectUnSetBit (ic->rUsed, R0_IDX);
+ bitVectUnSetBit (ic->rUsed, R1_IDX);
+
+ getFreePtr (ic, &aop, FALSE);
+
+ if (options.stack10bit)
+ {
+ /* I'm not sure what to do here yet... */
+ /* #STUB */
+ fprintf (stderr,
+ "*** Warning: probably generating bad code for "
+ "10 bit stack mode.\n");
+ }
+
+ if (stk)
+ {
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x", ((char) stk) & 0xff);
+ emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name);
+ }
+ else
+ {
+ emitcode ("mov", "%s,_bp", aop->aopu.aop_ptr->name);
+ }
+
+ while (sz--)
+ {
+ emitcode ("pop", "acc");
+ emitcode ("mov", "@%s,a", aop->aopu.aop_ptr->name);
+ if (!sz)
+ break;
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ }
+ op->aop = aop;
+ freeAsmop (op, NULL, ic, TRUE);
+ if (_G.r0Pushed)
+ {
+ emitcode ("pop", "ar0");
+ _G.r0Pushed--;
+ }
+
+ if (_G.r1Pushed)
+ {
+ emitcode ("pop", "ar1");
+ _G.r1Pushed--;
+ }
+ }
}
dealloc:
- /* all other cases just dealloc */
- if (op ) {
- op->aop = NULL;
- if (IS_SYMOP(op)) {
- OP_SYMBOL(op)->aop = NULL;
- /* if the symbol has a spill */
- if (SPIL_LOC(op))
- SPIL_LOC(op)->aop = NULL;
- }
+ /* all other cases just dealloc */
+ if (op)
+ {
+ op->aop = NULL;
+ if (IS_SYMOP (op))
+ {
+ OP_SYMBOL (op)->aop = NULL;
+ /* if the symbol has a spill */
+ if (SPIL_LOC (op))
+ SPIL_LOC (op)->aop = NULL;
+ }
}
}
/*-----------------------------------------------------------------*/
/* aopGet - for fetching value of the aop */
/*-----------------------------------------------------------------*/
-static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
+static char *
+aopGet (asmop * aop, int offset, bool bit16, bool dname)
{
- char *s = buffer ;
- char *rs;
+ char *s = buffer;
+ char *rs;
- //DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* offset is greater than
- size then zero */
- if (offset > (aop->size - 1) &&
- aop->type != AOP_LIT)
- return zero;
+ //DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* offset is greater than
+ size then zero */
+ if (offset > (aop->size - 1) &&
+ aop->type != AOP_LIT)
+ return zero;
- /* depending on type */
- switch (aop->type) {
+ /* depending on type */
+ switch (aop->type)
+ {
case AOP_R0:
case AOP_R1:
- DEBUGemitcode(";","%d",__LINE__);
- /* if we need to increment it */
- while (offset > aop->coff) {
- emitcode ("inc","%s",aop->aopu.aop_ptr->name);
- aop->coff++;
- }
-
- while (offset < aop->coff) {
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- aop->coff--;
- }
-
- aop->coff = offset ;
- if (aop->paged) {
- emitcode("movx","a,@%s",aop->aopu.aop_ptr->name);
- return (dname ? "acc" : "a");
- }
- sprintf(s,"@%s",aop->aopu.aop_ptr->name);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ DEBUGemitcode (";", "%d", __LINE__);
+ /* if we need to increment it */
+ while (offset > aop->coff)
+ {
+ emitcode ("inc", "%s", aop->aopu.aop_ptr->name);
+ aop->coff++;
+ }
+
+ while (offset < aop->coff)
+ {
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ aop->coff--;
+ }
+
+ aop->coff = offset;
+ if (aop->paged)
+ {
+ emitcode ("movx", "a,@%s", aop->aopu.aop_ptr->name);
+ return (dname ? "acc" : "a");
+ }
+ sprintf (s, "@%s", aop->aopu.aop_ptr->name);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_DPTR:
case AOP_DPTR2:
- DEBUGemitcode(";","%d",__LINE__);
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- }
-
- while (offset > aop->coff) {
- emitcode ("inc","dptr");
- aop->coff++;
- }
-
- while (offset < aop->coff) {
- emitcode("lcall","__decdptr");
- aop->coff--;
- }
-
- aop->coff = offset;
- if (aop->code) {
- emitcode("clr","a");
- emitcode("movc","a,@a+dptr");
- }
- else {
- emitcode("movx","a,@dptr");
- }
+ DEBUGemitcode (";", "%d", __LINE__);
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (1);
+ }
+
+ while (offset > aop->coff)
+ {
+ emitcode ("inc", "dptr");
+ aop->coff++;
+ }
+
+ while (offset < aop->coff)
+ {
+ emitcode ("lcall", "__decdptr");
+ aop->coff--;
+ }
+
+ aop->coff = offset;
+ if (aop->code)
+ {
+ emitcode ("clr", "a");
+ emitcode ("movc", "a,@a+dptr");
+ }
+ else
+ {
+ emitcode ("movx", "a,@dptr");
+ }
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (0);
+ }
- return (dname ? "acc" : "a");
+ return (dname ? "acc" : "a");
case AOP_IMMD:
- DEBUGemitcode(";","%d",__LINE__);
- if (bit16)
- sprintf (s,"%s",aop->aopu.aop_immd);
- else
- if (offset)
- sprintf(s,"(%s >> %d)",
- aop->aopu.aop_immd,
- offset*8);
+ DEBUGemitcode (";", "%d", __LINE__);
+ if (bit16)
+ sprintf (s, "%s", aop->aopu.aop_immd);
+ else if (offset)
+ sprintf (s, "(%s >> %d)",
+ aop->aopu.aop_immd,
+ offset * 8);
else
- sprintf(s,"%s",
- aop->aopu.aop_immd);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ sprintf (s, "%s",
+ aop->aopu.aop_immd);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_DIR:
- if (offset)
- sprintf(s,"(%s + %d)",
- aop->aopu.aop_dir,
- offset);
- else
- sprintf(s,"%s",aop->aopu.aop_dir);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ if (offset)
+ sprintf (s, "(%s + %d)",
+ aop->aopu.aop_dir,
+ offset);
+ else
+ sprintf (s, "%s", aop->aopu.aop_dir);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_REG:
- DEBUGemitcode(";","%d",__LINE__);
- if (dname)
- return aop->aopu.aop_reg[offset]->dname;
- else
- return aop->aopu.aop_reg[offset]->name;
+ DEBUGemitcode (";", "%d", __LINE__);
+ if (dname)
+ return aop->aopu.aop_reg[offset]->dname;
+ else
+ return aop->aopu.aop_reg[offset]->name;
case AOP_CRY:
- emitcode(";","%d",__LINE__);
+ emitcode (";", "%d", __LINE__);
//emitcode("clr","a");
//emitcode("mov","c,%s",aop->aopu.aop_dir);
//emitcode("rlc","a") ;
return aop->aopu.aop_dir;
case AOP_ACC:
- DEBUGemitcode(";Warning -pic port ignoring get(AOP_ACC)","%d",__LINE__);
- //if (!offset && dname)
- // return "acc";
- //return aop->aopu.aop_str[offset];
- return "AOP_accumulator_bug";
+ DEBUGemitcode (";Warning -pic port ignoring get(AOP_ACC)", "%d", __LINE__);
+ //if (!offset && dname)
+ // return "acc";
+ //return aop->aopu.aop_str[offset];
+ return "AOP_accumulator_bug";
case AOP_LIT:
- DEBUGemitcode(";","%d",__LINE__);
- return pic14aopLiteral (aop->aopu.aop_lit,offset);
+ DEBUGemitcode (";", "%d", __LINE__);
+ return pic14aopLiteral (aop->aopu.aop_lit, offset);
case AOP_STR:
- DEBUGemitcode(";","%d",__LINE__);
- aop->coff = offset ;
- if (strcmp(aop->aopu.aop_str[offset],"a") == 0 &&
- dname)
- return "acc";
+ DEBUGemitcode (";", "%d", __LINE__);
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], "a") == 0 &&
+ dname)
+ return "acc";
- return aop->aopu.aop_str[offset];
+ return aop->aopu.aop_str[offset];
}
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopget got unsupported aop->type");
- exit(0);
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopget got unsupported aop->type");
+ exit (0);
}
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop */
/*-----------------------------------------------------------------*/
-static void aopPut (asmop *aop, char *s, int offset)
+static void
+aopPut (asmop * aop, char *s, int offset)
{
- char *d = buffer ;
- symbol *lbl ;
+ char *d = buffer;
+ symbol *lbl;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- if (aop->size && offset > ( aop->size - 1)) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got offset > aop->size");
- exit(0);
+ if (aop->size && offset > (aop->size - 1))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got offset > aop->size");
+ exit (0);
}
- /* will assign value to value */
- /* depending on where it is ofcourse */
- switch (aop->type) {
+ /* will assign value to value */
+ /* depending on where it is ofcourse */
+ switch (aop->type)
+ {
case AOP_DIR:
- if (offset)
- sprintf(d,"(%s + %d)",
- aop->aopu.aop_dir,offset);
- else
- sprintf(d,"%s",aop->aopu.aop_dir);
-
- if (strcmp(d,s)) {
- DEBUGemitcode(";","%d",__LINE__);
- if(strcmp(s,"W"))
- emitcode("movf","%s,w",s);
- emitcode("movwf","%s",d);
- }
- break;
-
- case AOP_REG:
- if (strcmp(aop->aopu.aop_reg[offset]->name,s) != 0 &&
- strcmp(aop->aopu.aop_reg[offset]->dname,s)!= 0){
- /*
- if (*s == '@' ||
- strcmp(s,"r0") == 0 ||
- strcmp(s,"r1") == 0 ||
- strcmp(s,"r2") == 0 ||
- strcmp(s,"r3") == 0 ||
- strcmp(s,"r4") == 0 ||
- strcmp(s,"r5") == 0 ||
- strcmp(s,"r6") == 0 ||
- strcmp(s,"r7") == 0 )
- emitcode("mov","%s,%s ; %d",
- aop->aopu.aop_reg[offset]->dname,s,__LINE__);
+ if (offset)
+ sprintf (d, "(%s + %d)",
+ aop->aopu.aop_dir, offset);
else
- */
-
- if(strcmp(s,"W"))
- emitcode("movf","%s,w ; %d",s,__LINE__);
-
- emitcode("movwf","%s",
- aop->aopu.aop_reg[offset]->name);
+ sprintf (d, "%s", aop->aopu.aop_dir);
+
+ if (strcmp (d, s))
+ {
+ DEBUGemitcode (";", "%d", __LINE__);
+ if (strcmp (s, "W"))
+ emitcode ("movf", "%s,w", s);
+ emitcode ("movwf", "%s", d);
+ }
+ break;
- }
- break;
+ case AOP_REG:
+ if (strcmp (aop->aopu.aop_reg[offset]->name, s) != 0 &&
+ strcmp (aop->aopu.aop_reg[offset]->dname, s) != 0)
+ {
+ /*
+ if (*s == '@' ||
+ strcmp(s,"r0") == 0 ||
+ strcmp(s,"r1") == 0 ||
+ strcmp(s,"r2") == 0 ||
+ strcmp(s,"r3") == 0 ||
+ strcmp(s,"r4") == 0 ||
+ strcmp(s,"r5") == 0 ||
+ strcmp(s,"r6") == 0 ||
+ strcmp(s,"r7") == 0 )
+ emitcode("mov","%s,%s ; %d",
+ aop->aopu.aop_reg[offset]->dname,s,__LINE__);
+ else
+ */
+
+ if (strcmp (s, "W"))
+ emitcode ("movf", "%s,w ; %d", s, __LINE__);
+
+ emitcode ("movwf", "%s",
+ aop->aopu.aop_reg[offset]->name);
+
+ }
+ break;
case AOP_DPTR:
case AOP_DPTR2:
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- }
-
- if (aop->code) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut writting to code space");
- exit(0);
- }
-
- while (offset > aop->coff) {
- aop->coff++;
- emitcode ("inc","dptr");
- }
-
- while (offset < aop->coff) {
- aop->coff-- ;
- emitcode("lcall","__decdptr");
- }
-
- aop->coff = offset;
-
- /* if not in accumulater */
- MOVA(s);
-
- emitcode ("movx","@dptr,a");
-
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
- break;
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (1);
+ }
+
+ if (aop->code)
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut writting to code space");
+ exit (0);
+ }
+
+ while (offset > aop->coff)
+ {
+ aop->coff++;
+ emitcode ("inc", "dptr");
+ }
+
+ while (offset < aop->coff)
+ {
+ aop->coff--;
+ emitcode ("lcall", "__decdptr");
+ }
+
+ aop->coff = offset;
+
+ /* if not in accumulater */
+ MOVA (s);
+
+ emitcode ("movx", "@dptr,a");
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (0);
+ }
+ break;
case AOP_R0:
case AOP_R1:
- while (offset > aop->coff) {
- aop->coff++;
- emitcode("inc","%s",aop->aopu.aop_ptr->name);
- }
- while (offset < aop->coff) {
- aop->coff-- ;
- emitcode ("dec","%s",aop->aopu.aop_ptr->name);
- }
- aop->coff = offset;
-
- if (aop->paged) {
- MOVA(s);
- emitcode("movx","@%s,a",aop->aopu.aop_ptr->name);
-
- } else
- if (*s == '@') {
- MOVA(s);
- emitcode("mov","@%s,a ; %d",aop->aopu.aop_ptr->name,__LINE__);
- } else
- if (strcmp(s,"r0") == 0 ||
- strcmp(s,"r1") == 0 ||
- strcmp(s,"r2") == 0 ||
- strcmp(s,"r3") == 0 ||
- strcmp(s,"r4") == 0 ||
- strcmp(s,"r5") == 0 ||
- strcmp(s,"r6") == 0 ||
- strcmp(s,"r7") == 0 ) {
- char buffer[10];
- sprintf(buffer,"a%s",s);
- emitcode("mov","@%s,%s",
- aop->aopu.aop_ptr->name,buffer);
- } else
- emitcode("mov","@%s,%s",aop->aopu.aop_ptr->name,s);
-
- break;
+ while (offset > aop->coff)
+ {
+ aop->coff++;
+ emitcode ("inc", "%s", aop->aopu.aop_ptr->name);
+ }
+ while (offset < aop->coff)
+ {
+ aop->coff--;
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ }
+ aop->coff = offset;
+
+ if (aop->paged)
+ {
+ MOVA (s);
+ emitcode ("movx", "@%s,a", aop->aopu.aop_ptr->name);
+
+ }
+ else if (*s == '@')
+ {
+ MOVA (s);
+ emitcode ("mov", "@%s,a ; %d", aop->aopu.aop_ptr->name, __LINE__);
+ }
+ else if (strcmp (s, "r0") == 0 ||
+ strcmp (s, "r1") == 0 ||
+ strcmp (s, "r2") == 0 ||
+ strcmp (s, "r3") == 0 ||
+ strcmp (s, "r4") == 0 ||
+ strcmp (s, "r5") == 0 ||
+ strcmp (s, "r6") == 0 ||
+ strcmp (s, "r7") == 0)
+ {
+ char buffer[10];
+ sprintf (buffer, "a%s", s);
+ emitcode ("mov", "@%s,%s",
+ aop->aopu.aop_ptr->name, buffer);
+ }
+ else
+ emitcode ("mov", "@%s,%s", aop->aopu.aop_ptr->name, s);
+
+ break;
case AOP_STK:
- if (strcmp(s,"a") == 0)
- emitcode("push","acc");
- else
- emitcode("push","%s",s);
+ if (strcmp (s, "a") == 0)
+ emitcode ("push", "acc");
+ else
+ emitcode ("push", "%s", s);
- break;
+ break;
case AOP_CRY:
- /* if bit variable */
- if (!aop->aopu.aop_dir) {
- emitcode("clr","a");
- emitcode("rlc","a");
- } else {
- if (s == zero)
- emitcode("clr","%s",aop->aopu.aop_dir);
+ /* if bit variable */
+ if (!aop->aopu.aop_dir)
+ {
+ emitcode ("clr", "a");
+ emitcode ("rlc", "a");
+ }
else
- if (s == one)
- emitcode("setb","%s",aop->aopu.aop_dir);
- else
- if (!strcmp(s,"c"))
- emitcode("mov","%s,c",aop->aopu.aop_dir);
- else {
- lbl = newiTempLabel(NULL);
-
- if (strcmp(s,"a")) {
- MOVA(s);
- }
- emitcode("clr","c");
- emitcode("jz","%05d_DS_",lbl->key+100);
- emitcode("cpl","c");
- emitcode("","%05d_DS_:",lbl->key+100);
- emitcode("mov","%s,c",aop->aopu.aop_dir);
- }
- }
- break;
+ {
+ if (s == zero)
+ emitcode ("clr", "%s", aop->aopu.aop_dir);
+ else if (s == one)
+ emitcode ("setb", "%s", aop->aopu.aop_dir);
+ else if (!strcmp (s, "c"))
+ emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+ else
+ {
+ lbl = newiTempLabel (NULL);
+
+ if (strcmp (s, "a"))
+ {
+ MOVA (s);
+ }
+ emitcode ("clr", "c");
+ emitcode ("jz", "%05d_DS_", lbl->key + 100);
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d_DS_:", lbl->key + 100);
+ emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+ }
+ }
+ break;
case AOP_STR:
- aop->coff = offset;
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("mov","%s,%s ; %d",aop->aopu.aop_str[offset],s,__LINE__);
- break;
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("mov", "%s,%s ; %d", aop->aopu.aop_str[offset], s, __LINE__);
+ break;
case AOP_ACC:
- aop->coff = offset;
- if (!offset && (strcmp(s,"acc") == 0))
- break;
+ aop->coff = offset;
+ if (!offset && (strcmp (s, "acc") == 0))
+ break;
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("mov","%s,%s ; %d",aop->aopu.aop_str[offset],s, __LINE__);
- break;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("mov", "%s,%s ; %d", aop->aopu.aop_str[offset], s, __LINE__);
+ break;
- default :
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got unsupported aop->type");
- exit(0);
+ default:
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got unsupported aop->type");
+ exit (0);
}
}
/*-----------------------------------------------------------------*/
/* reAdjustPreg - points a register back to where it should */
/*-----------------------------------------------------------------*/
-static void reAdjustPreg (asmop *aop)
+static void
+reAdjustPreg (asmop * aop)
{
- int size ;
+ int size;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aop->coff = 0;
- if ((size = aop->size) <= 1)
- return ;
- size-- ;
- switch (aop->type) {
- case AOP_R0 :
- case AOP_R1 :
- while (size--)
- emitcode("dec","%s",aop->aopu.aop_ptr->name);
- break;
- case AOP_DPTR :
- case AOP_DPTR2:
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(1);
- }
- while (size--)
- {
- emitcode("lcall","__decdptr");
- }
-
- if (aop->type == AOP_DPTR2)
- {
- genSetDPTR(0);
- }
- break;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aop->coff = 0;
+ if ((size = aop->size) <= 1)
+ return;
+ size--;
+ switch (aop->type)
+ {
+ case AOP_R0:
+ case AOP_R1:
+ while (size--)
+ emitcode ("dec", "%s", aop->aopu.aop_ptr->name);
+ break;
+ case AOP_DPTR:
+ case AOP_DPTR2:
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (1);
+ }
+ while (size--)
+ {
+ emitcode ("lcall", "__decdptr");
+ }
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR (0);
+ }
+ break;
}
/*-----------------------------------------------------------------*/
/* genNotFloat - generates not for float operations */
/*-----------------------------------------------------------------*/
-static void genNotFloat (operand *op, operand *res)
+static void
+genNotFloat (operand * op, operand * res)
{
- int size, offset;
- char *l;
- symbol *tlbl ;
+ int size, offset;
+ char *l;
+ symbol *tlbl;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* we will put 127 in the first byte of
- the result */
- aopPut(AOP(res),"#127",0);
- size = AOP_SIZE(op) - 1;
- offset = 1;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* we will put 127 in the first byte of
+ the result */
+ aopPut (AOP (res), "#127", 0);
+ size = AOP_SIZE (op) - 1;
+ offset = 1;
- l = aopGet(op->aop,offset++,FALSE,FALSE);
- MOVA(l);
+ l = aopGet (op->aop, offset++, FALSE, FALSE);
+ MOVA (l);
- while(size--) {
- emitcode("orl","a,%s",
- aopGet(op->aop,
- offset++,FALSE,FALSE));
+ while (size--)
+ {
+ emitcode ("orl", "a,%s",
+ aopGet (op->aop,
+ offset++, FALSE, FALSE));
}
- tlbl = newiTempLabel(NULL);
+ tlbl = newiTempLabel (NULL);
- tlbl = newiTempLabel(NULL);
- aopPut(res->aop,one,1);
- emitcode("jz","%05d_DS_",(tlbl->key+100));
- aopPut(res->aop,zero,1);
- emitcode("","%05d_DS_:",(tlbl->key+100));
+ tlbl = newiTempLabel (NULL);
+ aopPut (res->aop, one, 1);
+ emitcode ("jz", "%05d_DS_", (tlbl->key + 100));
+ aopPut (res->aop, zero, 1);
+ emitcode ("", "%05d_DS_:", (tlbl->key + 100));
- size = res->aop->size - 2;
- offset = 2;
- /* put zeros in the rest */
- while (size--)
- aopPut(res->aop,zero,offset++);
+ size = res->aop->size - 2;
+ offset = 2;
+ /* put zeros in the rest */
+ while (size--)
+ aopPut (res->aop, zero, offset++);
}
#if 0
/* opIsGptr: returns non-zero if the passed operand is */
/* a generic pointer type. */
/*-----------------------------------------------------------------*/
-static int opIsGptr(operand *op)
+static int
+opIsGptr (operand * op)
{
- sym_link *type = operandType(op);
+ sym_link *type = operandType (op);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if ((AOP_SIZE(op) == GPTRSIZE) && IS_GENPTR(type))
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
{
- return 1;
+ return 1;
}
- return 0;
+ return 0;
}
#endif
/*-----------------------------------------------------------------*/
/* getDataSize - get the operand data size */
/*-----------------------------------------------------------------*/
-static int getDataSize(operand *op)
+static int
+getDataSize (operand * op)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- return AOP_SIZE(op);
+ return AOP_SIZE (op);
- // tsd- in the pic port, the genptr size is 1, so this code here
- // fails. ( in the 8051 port, the size was 4).
+ // tsd- in the pic port, the genptr size is 1, so this code here
+ // fails. ( in the 8051 port, the size was 4).
#if 0
- int size;
- size = AOP_SIZE(op);
- if (size == GPTRSIZE)
- {
- sym_link *type = operandType(op);
- if (IS_GENPTR(type))
- {
- /* generic pointer; arithmetic operations
- * should ignore the high byte (pointer type).
- */
- size--;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- }
- }
- return size;
+ int size;
+ size = AOP_SIZE (op);
+ if (size == GPTRSIZE)
+ {
+ sym_link *type = operandType (op);
+ if (IS_GENPTR (type))
+ {
+ /* generic pointer; arithmetic operations
+ * should ignore the high byte (pointer type).
+ */
+ size--;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ }
+ }
+ return size;
#endif
}
/*-----------------------------------------------------------------*/
/* outAcc - output Acc */
/*-----------------------------------------------------------------*/
-static void outAcc(operand *result)
+static void
+outAcc (operand * result)
{
- int size, offset;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- size = getDataSize(result);
- if(size){
- aopPut(AOP(result),"a",0);
- size--;
- offset = 1;
- /* unsigned or positive */
- while(size--){
- aopPut(AOP(result),zero,offset++);
- }
+ int size, offset;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ size = getDataSize (result);
+ if (size)
+ {
+ aopPut (AOP (result), "a", 0);
+ size--;
+ offset = 1;
+ /* unsigned or positive */
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
}
}
/*-----------------------------------------------------------------*/
/* outBitC - output a bit C */
/*-----------------------------------------------------------------*/
-static void outBitC(operand *result)
+static void
+outBitC (operand * result)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if the result is bit */
- if (AOP_TYPE(result) == AOP_CRY)
- aopPut(AOP(result),"c",0);
- else {
- emitcode("clr","a ; %d", __LINE__);
- emitcode("rlc","a");
- outAcc(result);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if the result is bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ aopPut (AOP (result), "c", 0);
+ else
+ {
+ emitcode ("clr", "a ; %d", __LINE__);
+ emitcode ("rlc", "a");
+ outAcc (result);
}
}
/*-----------------------------------------------------------------*/
/* toBoolean - emit code for orl a,operator(sizeop) */
/*-----------------------------------------------------------------*/
-static void toBoolean(operand *oper)
+static void
+toBoolean (operand * oper)
{
- int size = AOP_SIZE(oper) - 1;
- int offset = 1;
+ int size = AOP_SIZE (oper) - 1;
+ int offset = 1;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- if ( AOP_TYPE(oper) != AOP_ACC)
- emitcode("movf","%s,w",aopGet(AOP(oper),0,FALSE,FALSE));
+ if (AOP_TYPE (oper) != AOP_ACC)
+ emitcode ("movf", "%s,w", aopGet (AOP (oper), 0, FALSE, FALSE));
- while (size--)
- emitcode("iorwf","%s,w",aopGet(AOP(oper),offset++,FALSE,FALSE));
+ while (size--)
+ emitcode ("iorwf", "%s,w", aopGet (AOP (oper), offset++, FALSE, FALSE));
}
/*-----------------------------------------------------------------*/
/* genNot - generate code for ! operation */
/*-----------------------------------------------------------------*/
-static void genNot (iCode *ic)
+static void
+genNot (iCode * ic)
{
- symbol *tlbl;
- sym_link *optype = operandType(IC_LEFT(ic));
+ symbol *tlbl;
+ sym_link *optype = operandType (IC_LEFT (ic));
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* if in bit space then a special case */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
- emitcode("movlw","1<<%s");
+ /* if in bit space then a special case */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
+ emitcode ("movlw", "1<<%s");
//emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
//emitcode("cpl","c");
//outBitC(IC_RESULT(ic));
goto release;
}
- /* if type float then do float */
- if (IS_FLOAT(optype)) {
- genNotFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
+ /* if type float then do float */
+ if (IS_FLOAT (optype))
+ {
+ genNotFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
}
- toBoolean(IC_LEFT(ic));
+ toBoolean (IC_LEFT (ic));
- tlbl = newiTempLabel(NULL);
- emitcode("cjne","a,#0x01,%05d_DS_",tlbl->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- outBitC(IC_RESULT(ic));
+ tlbl = newiTempLabel (NULL);
+ emitcode ("cjne", "a,#0x01,%05d_DS_", tlbl->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ outBitC (IC_RESULT (ic));
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCpl - generate code for complement */
/*-----------------------------------------------------------------*/
-static void genCpl (iCode *ic)
+static void
+genCpl (iCode * ic)
{
- int offset = 0;
- int size ;
+ int offset = 0;
+ int size;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* if both are in bit space then
- a special case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
+ /* if both are in bit space then
+ a special case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
- goto release;
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+ goto release;
}
- size = AOP_SIZE(IC_RESULT(ic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("cpl","a");
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ size = AOP_SIZE (IC_RESULT (ic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("cpl", "a");
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genUminusFloat - unary minus for floating points */
/*-----------------------------------------------------------------*/
-static void genUminusFloat(operand *op,operand *result)
+static void
+genUminusFloat (operand * op, operand * result)
{
- int size ,offset =0 ;
- char *l;
+ int size, offset = 0;
+ char *l;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* for this we just need to flip the
- first it then copy the rest in place */
- size = AOP_SIZE(op) - 1;
- l = aopGet(AOP(op),3,FALSE,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* for this we just need to flip the
+ first it then copy the rest in place */
+ size = AOP_SIZE (op) - 1;
+ l = aopGet (AOP (op), 3, FALSE, FALSE);
- MOVA(l);
+ MOVA (l);
- emitcode("cpl","acc.7");
- aopPut(AOP(result),"a",3);
+ emitcode ("cpl", "acc.7");
+ aopPut (AOP (result), "a", 3);
- while(size--) {
- aopPut(AOP(result),
- aopGet(AOP(op),offset,FALSE,FALSE),
- offset);
- offset++;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (op), offset, FALSE, FALSE),
+ offset);
+ offset++;
}
}
/*-----------------------------------------------------------------*/
/* genUminus - unary minus code generation */
/*-----------------------------------------------------------------*/
-static void genUminus (iCode *ic)
+static void
+genUminus (iCode * ic)
{
- int offset ,size ;
- sym_link *optype, *rtype;
+ int offset, size;
+ sym_link *optype, *rtype;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* assign asmops */
- aopOp(IC_LEFT(ic),ic,FALSE);
- aopOp(IC_RESULT(ic),ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* assign asmops */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* if both in bit space then special
- case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
+ /* if both in bit space then special
+ case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
- emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
- emitcode("cpl","c");
- emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
- goto release;
+ emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+ goto release;
}
- optype = operandType(IC_LEFT(ic));
- rtype = operandType(IC_RESULT(ic));
+ optype = operandType (IC_LEFT (ic));
+ rtype = operandType (IC_RESULT (ic));
- /* if float then do float stuff */
- if (IS_FLOAT(optype)) {
- genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
- goto release;
+ /* if float then do float stuff */
+ if (IS_FLOAT (optype))
+ {
+ genUminusFloat (IC_LEFT (ic), IC_RESULT (ic));
+ goto release;
}
- /* otherwise subtract from zero */
- size = AOP_SIZE(IC_LEFT(ic));
- offset = 0 ;
- CLRC ;
- while(size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE);
- if (!strcmp(l,"a")) {
- emitcode("cpl","a");
- emitcode("inc","a");
- } else {
- emitcode("clr","a");
- emitcode("subb","a,%s",l);
- }
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* otherwise subtract from zero */
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = 0;
+ CLRC;
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE);
+ if (!strcmp (l, "a"))
+ {
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ }
+ else
+ {
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,%s", l);
+ }
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
- /* if any remaining bytes in the result */
- /* we just need to propagate the sign */
- if ((size = (AOP_SIZE(IC_RESULT(ic)) - AOP_SIZE(IC_LEFT(ic))))) {
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- while (size--)
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* if any remaining bytes in the result */
+ /* we just need to propagate the sign */
+ if ((size = (AOP_SIZE (IC_RESULT (ic)) - AOP_SIZE (IC_LEFT (ic)))))
+ {
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ while (size--)
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? 0 : 1));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* saveRegisters - will look for a call and save the registers */
/*-----------------------------------------------------------------*/
-static void saveRegisters(iCode *lic)
-{
- int i;
- iCode *ic;
- bitVect *rsave;
- sym_link *detype;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* look for call */
- for (ic = lic ; ic ; ic = ic->next)
- if (ic->op == CALL || ic->op == PCALL)
- break;
-
- if (!ic) {
- fprintf(stderr,"found parameter push with no function call\n");
- return ;
- }
-
- /* if the registers have been saved already then
- do nothing */
- if (ic->regsSaved || (OP_SYMBOL(IC_LEFT(ic))->calleeSave))
- return ;
-
- /* find the registers in use at this time
- and push them away to safety */
- rsave = bitVectCplAnd(bitVectCopy(ic->rMask),
- ic->rUsed);
-
- ic->regsSaved = 1;
- if (options.useXstack) {
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","b,r0");
- emitcode("mov","r0,%s",spname);
- for (i = 0 ; i < pic14_nRegs ; i++) {
- if (bitVectBitValue(rsave,i)) {
- if (i == R0_IDX)
- emitcode("mov","a,b");
- else
- emitcode("mov","a,%s",pic14_regWithIdx(i)->name);
- emitcode("movx","@r0,a");
- emitcode("inc","r0");
+static void
+saveRegisters (iCode * lic)
+{
+ int i;
+ iCode *ic;
+ bitVect *rsave;
+ sym_link *detype;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* look for call */
+ for (ic = lic; ic; ic = ic->next)
+ if (ic->op == CALL || ic->op == PCALL)
+ break;
+
+ if (!ic)
+ {
+ fprintf (stderr, "found parameter push with no function call\n");
+ return;
+ }
+
+ /* if the registers have been saved already then
+ do nothing */
+ if (ic->regsSaved || (OP_SYMBOL (IC_LEFT (ic))->calleeSave))
+ return;
+
+ /* find the registers in use at this time
+ and push them away to safety */
+ rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ic->rUsed);
+
+ ic->regsSaved = 1;
+ if (options.useXstack)
+ {
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "b,r0");
+ emitcode ("mov", "r0,%s", spname);
+ for (i = 0; i < pic14_nRegs; i++)
+ {
+ if (bitVectBitValue (rsave, i))
+ {
+ if (i == R0_IDX)
+ emitcode ("mov", "a,b");
+ else
+ emitcode ("mov", "a,%s", pic14_regWithIdx (i)->name);
+ emitcode ("movx", "@r0,a");
+ emitcode ("inc", "r0");
+ }
+ }
+ emitcode ("mov", "%s,r0", spname);
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "r0,b");
+ }
+ else
+ for (i = 0; i < pic14_nRegs; i++)
+ {
+ if (bitVectBitValue (rsave, i))
+ emitcode ("push", "%s", pic14_regWithIdx (i)->dname);
}
- }
- emitcode("mov","%s,r0",spname);
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","r0,b");
- } else
- for (i = 0 ; i < pic14_nRegs ; i++) {
- if (bitVectBitValue(rsave,i))
- emitcode("push","%s",pic14_regWithIdx(i)->dname);
- }
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) &&
- IS_ISR(currFunc->etype) &&
- !ic->bankSaved)
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) &&
+ IS_ISR (currFunc->etype) &&
+ !ic->bankSaved)
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ saverbank (SPEC_BANK (detype), ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* unsaveRegisters - pop the pushed registers */
/*-----------------------------------------------------------------*/
-static void unsaveRegisters (iCode *ic)
-{
- int i;
- bitVect *rsave;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* find the registers in use at this time
- and push them away to safety */
- rsave = bitVectCplAnd(bitVectCopy(ic->rMask),
- ic->rUsed);
-
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- for (i = pic14_nRegs ; i >= 0 ; i--) {
- if (bitVectBitValue(rsave,i)) {
- emitcode("dec","r0");
- emitcode("movx","a,@r0");
- if (i == R0_IDX)
- emitcode("mov","b,a");
- else
- emitcode("mov","%s,a",pic14_regWithIdx(i)->name);
- }
+static void
+unsaveRegisters (iCode * ic)
+{
+ int i;
+ bitVect *rsave;
- }
- emitcode("mov","%s,r0",spname);
- if (bitVectBitValue(rsave,R0_IDX))
- emitcode("mov","r0,b");
- } else
- for (i = pic14_nRegs ; i >= 0 ; i--) {
- if (bitVectBitValue(rsave,i))
- emitcode("pop","%s",pic14_regWithIdx(i)->dname);
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* find the registers in use at this time
+ and push them away to safety */
+ rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ic->rUsed);
+
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ for (i = pic14_nRegs; i >= 0; i--)
+ {
+ if (bitVectBitValue (rsave, i))
+ {
+ emitcode ("dec", "r0");
+ emitcode ("movx", "a,@r0");
+ if (i == R0_IDX)
+ emitcode ("mov", "b,a");
+ else
+ emitcode ("mov", "%s,a", pic14_regWithIdx (i)->name);
+ }
+
+ }
+ emitcode ("mov", "%s,r0", spname);
+ if (bitVectBitValue (rsave, R0_IDX))
+ emitcode ("mov", "r0,b");
+ }
+ else
+ for (i = pic14_nRegs; i >= 0; i--)
+ {
+ if (bitVectBitValue (rsave, i))
+ emitcode ("pop", "%s", pic14_regWithIdx (i)->dname);
+ }
}
/*-----------------------------------------------------------------*/
/* pushSide - */
/*-----------------------------------------------------------------*/
-static void pushSide(operand * oper, int size)
+static void
+pushSide (operand * oper, int size)
{
int offset = 0;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- while (size--) {
- char *l = aopGet(AOP(oper),offset++,FALSE,TRUE);
- if (AOP_TYPE(oper) != AOP_REG &&
- AOP_TYPE(oper) != AOP_DIR &&
- strcmp(l,"a") ) {
- emitcode("mov","a,%s",l);
- emitcode("push","acc");
- } else
- emitcode("push","%s",l);
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ while (size--)
+ {
+ char *l = aopGet (AOP (oper), offset++, FALSE, TRUE);
+ if (AOP_TYPE (oper) != AOP_REG &&
+ AOP_TYPE (oper) != AOP_DIR &&
+ strcmp (l, "a"))
+ {
+ emitcode ("mov", "a,%s", l);
+ emitcode ("push", "acc");
+ }
+ else
+ emitcode ("push", "%s", l);
+ }
}
/*-----------------------------------------------------------------*/
/* assignResultValue - */
/*-----------------------------------------------------------------*/
-static void assignResultValue(operand * oper)
+static void
+assignResultValue (operand * oper)
{
int offset = 0;
- int size = AOP_SIZE(oper);
+ int size = AOP_SIZE (oper);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- // The last byte in the assignment is in W
- aopPut(AOP(oper),"W",size-1);
+ // The last byte in the assignment is in W
+ aopPut (AOP (oper), "W", size - 1);
- if(size>1) {
- while (--size) {
- aopPut(AOP(oper),fReturn[offset],offset);
- offset++;
+ if (size > 1)
+ {
+ while (--size)
+ {
+ aopPut (AOP (oper), fReturn[offset], offset);
+ offset++;
- }
+ }
}
}
/*-----------------------------------------------------------------*/
/* genXpush - pushes onto the external stack */
/*-----------------------------------------------------------------*/
-static void genXpush (iCode *ic)
+static void
+genXpush (iCode * ic)
{
- asmop *aop = newAsmop(0);
- regs *r ;
- int size,offset = 0;
+ asmop *aop = newAsmop (0);
+ regs *r;
+ int size, offset = 0;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp(IC_LEFT(ic),ic,FALSE);
- r = getFreePtr(ic,&aop,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ r = getFreePtr (ic, &aop, FALSE);
- emitcode("mov","%s,_spx",r->name);
+ emitcode ("mov", "%s,_spx", r->name);
- size = AOP_SIZE(IC_LEFT(ic));
- while(size--) {
+ size = AOP_SIZE (IC_LEFT (ic));
+ while (size--)
+ {
- char *l = aopGet(AOP(IC_LEFT(ic)),
- offset++,FALSE,FALSE);
- MOVA(l);
- emitcode("movx","@%s,a",r->name);
- emitcode("inc","%s",r->name);
+ char *l = aopGet (AOP (IC_LEFT (ic)),
+ offset++, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("movx", "@%s,a", r->name);
+ emitcode ("inc", "%s", r->name);
}
- emitcode("mov","_spx,%s",r->name);
+ emitcode ("mov", "_spx,%s", r->name);
- freeAsmop(NULL,aop,ic,TRUE);
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (NULL, aop, ic, TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIpush - genrate code for pushing this gets a little complex */
/*-----------------------------------------------------------------*/
-static void genIpush (iCode *ic)
+static void
+genIpush (iCode * ic)
{
- int size, offset = 0 ;
- char *l;
+ int size, offset = 0;
+ char *l;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if this is not a parm push : ie. it is spill push
- and spill push is always done on the local stack */
- if (!ic->parmPush) {
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if this is not a parm push : ie. it is spill push
+ and spill push is always done on the local stack */
+ if (!ic->parmPush)
+ {
- /* and the item is spilt then do nothing */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
+ /* and the item is spilt then do nothing */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- /* push it on the stack */
- while(size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE);
- if (*l == '#') {
- MOVA(l);
- l = "acc";
- }
- emitcode("push","%s",l);
- }
- return ;
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ /* push it on the stack */
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE);
+ if (*l == '#')
+ {
+ MOVA (l);
+ l = "acc";
+ }
+ emitcode ("push", "%s", l);
+ }
+ return;
}
- /* this is a paramter push: in this case we call
- the routine to find the call and save those
- registers that need to be saved */
- saveRegisters(ic);
+ /* this is a paramter push: in this case we call
+ the routine to find the call and save those
+ registers that need to be saved */
+ saveRegisters (ic);
- /* if use external stack then call the external
- stack pushing routine */
- if (options.useXstack) {
- genXpush(ic);
- return ;
+ /* if use external stack then call the external
+ stack pushing routine */
+ if (options.useXstack)
+ {
+ genXpush (ic);
+ return;
}
- /* then do the push */
- aopOp(IC_LEFT(ic),ic,FALSE);
+ /* then do the push */
+ aopOp (IC_LEFT (ic), ic, FALSE);
// pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
- size = AOP_SIZE(IC_LEFT(ic));
+ size = AOP_SIZE (IC_LEFT (ic));
- while (size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE);
- if (AOP_TYPE(IC_LEFT(ic)) != AOP_REG &&
- AOP_TYPE(IC_LEFT(ic)) != AOP_DIR &&
- strcmp(l,"a") ) {
- emitcode("mov","a,%s",l);
- emitcode("push","acc");
- } else
- emitcode("push","%s",l);
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE);
+ if (AOP_TYPE (IC_LEFT (ic)) != AOP_REG &&
+ AOP_TYPE (IC_LEFT (ic)) != AOP_DIR &&
+ strcmp (l, "a"))
+ {
+ emitcode ("mov", "a,%s", l);
+ emitcode ("push", "acc");
+ }
+ else
+ emitcode ("push", "%s", l);
}
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIpop - recover the registers: can happen only for spilling */
/*-----------------------------------------------------------------*/
-static void genIpop (iCode *ic)
+static void
+genIpop (iCode * ic)
{
- int size,offset ;
+ int size, offset;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if the temp was not pushed then */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if the temp was not pushed then */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- offset = (size-1);
- while (size--)
- emitcode("pop","%s",aopGet(AOP(IC_LEFT(ic)),offset--,
- FALSE,TRUE));
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = (size - 1);
+ while (size--)
+ emitcode ("pop", "%s", aopGet (AOP (IC_LEFT (ic)), offset--,
+ FALSE, TRUE));
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* unsaverbank - restores the resgister bank from stack */
/*-----------------------------------------------------------------*/
-static void unsaverbank (int bank,iCode *ic,bool popPsw)
+static void
+unsaverbank (int bank, iCode * ic, bool popPsw)
{
- int i;
- asmop *aop ;
- regs *r = NULL;
+ int i;
+ asmop *aop;
+ regs *r = NULL;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (popPsw) {
- if (options.useXstack) {
- aop = newAsmop(0);
- r = getFreePtr(ic,&aop,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (popPsw)
+ {
+ if (options.useXstack)
+ {
+ aop = newAsmop (0);
+ r = getFreePtr (ic, &aop, FALSE);
- emitcode("mov","%s,_spx",r->name);
- emitcode("movx","a,@%s",r->name);
- emitcode("mov","psw,a");
- emitcode("dec","%s",r->name);
+ emitcode ("mov", "%s,_spx", r->name);
+ emitcode ("movx", "a,@%s", r->name);
+ emitcode ("mov", "psw,a");
+ emitcode ("dec", "%s", r->name);
- }else
- emitcode ("pop","psw");
+ }
+ else
+ emitcode ("pop", "psw");
}
- for (i = (pic14_nRegs - 1) ; i >= 0 ;i--) {
- if (options.useXstack) {
- emitcode("movx","a,@%s",r->name);
- //emitcode("mov","(%s+%d),a",
- // regspic14[i].base,8*bank+regspic14[i].offset);
- emitcode("dec","%s",r->name);
+ for (i = (pic14_nRegs - 1); i >= 0; i--)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("movx", "a,@%s", r->name);
+ //emitcode("mov","(%s+%d),a",
+ // regspic14[i].base,8*bank+regspic14[i].offset);
+ emitcode ("dec", "%s", r->name);
+
+ }
+ else
+ emitcode ("pop", ""); //"(%s+%d)",
+ //regspic14[i].base,8*bank); //+regspic14[i].offset);
- } else
- emitcode("pop",""); //"(%s+%d)",
- //regspic14[i].base,8*bank); //+regspic14[i].offset);
}
- if (options.useXstack) {
+ if (options.useXstack)
+ {
- emitcode("mov","_spx,%s",r->name);
- freeAsmop(NULL,aop,ic,TRUE);
+ emitcode ("mov", "_spx,%s", r->name);
+ freeAsmop (NULL, aop, ic, TRUE);
}
}
/*-----------------------------------------------------------------*/
/* saverbank - saves an entire register bank on the stack */
/*-----------------------------------------------------------------*/
-static void saverbank (int bank, iCode *ic, bool pushPsw)
+static void
+saverbank (int bank, iCode * ic, bool pushPsw)
{
- int i;
- asmop *aop ;
- regs *r = NULL;
+ int i;
+ asmop *aop;
+ regs *r = NULL;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (options.useXstack) {
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (options.useXstack)
+ {
- aop = newAsmop(0);
- r = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,_spx",r->name);
+ aop = newAsmop (0);
+ r = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,_spx", r->name);
}
- for (i = 0 ; i < pic14_nRegs ;i++) {
- if (options.useXstack) {
- emitcode("inc","%s",r->name);
- //emitcode("mov","a,(%s+%d)",
- // regspic14[i].base,8*bank+regspic14[i].offset);
- emitcode("movx","@%s,a",r->name);
- } else
- emitcode("push","");// "(%s+%d)",
- //regspic14[i].base,8*bank+regspic14[i].offset);
- }
+ for (i = 0; i < pic14_nRegs; i++)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("inc", "%s", r->name);
+ //emitcode("mov","a,(%s+%d)",
+ // regspic14[i].base,8*bank+regspic14[i].offset);
+ emitcode ("movx", "@%s,a", r->name);
+ }
+ else
+ emitcode ("push", ""); // "(%s+%d)",
+ //regspic14[i].base,8*bank+regspic14[i].offset);
- if (pushPsw) {
- if (options.useXstack) {
- emitcode("mov","a,psw");
- emitcode("movx","@%s,a",r->name);
- emitcode("inc","%s",r->name);
- emitcode("mov","_spx,%s",r->name);
- freeAsmop (NULL,aop,ic,TRUE);
+ }
- } else
- emitcode("push","psw");
+ if (pushPsw)
+ {
+ if (options.useXstack)
+ {
+ emitcode ("mov", "a,psw");
+ emitcode ("movx", "@%s,a", r->name);
+ emitcode ("inc", "%s", r->name);
+ emitcode ("mov", "_spx,%s", r->name);
+ freeAsmop (NULL, aop, ic, TRUE);
+
+ }
+ else
+ emitcode ("push", "psw");
- emitcode("mov","psw,#0x%02x",(bank << 3)&0x00ff);
+ emitcode ("mov", "psw,#0x%02x", (bank << 3) & 0x00ff);
}
- ic->bankSaved = 1;
+ ic->bankSaved = 1;
}
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
-static void genCall (iCode *ic)
+static void
+genCall (iCode * ic)
{
- sym_link *detype;
+ sym_link *detype;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
- saveRegisters(ic);
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ saveRegisters (ic);
- /* if we are calling a function that is not using
- the same register bank then we need to save the
- destination registers on the stack */
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) &&
- IS_ISR(currFunc->etype) &&
- !ic->bankSaved)
+ /* if we are calling a function that is not using
+ the same register bank then we need to save the
+ destination registers on the stack */
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) &&
+ IS_ISR (currFunc->etype) &&
+ !ic->bankSaved)
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ saverbank (SPEC_BANK (detype), ic, TRUE);
- /* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
+ /* if send set is not empty the assign */
+ if (_G.sendSet)
+ {
+ iCode *sic;
+
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+
+ aopOp (IC_LEFT (sic), sic, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset,
+ FALSE, FALSE);
+ DEBUGemitcode (";", "%d - left type %d", __LINE__, AOP (IC_LEFT (sic))->type);
+
+ if (strcmp (l, fReturn[offset]))
+ {
+
+ if (((AOP (IC_LEFT (sic))->type) == AOP_IMMD) ||
+ ((AOP (IC_LEFT (sic))->type) == AOP_LIT))
+ emitcode ("movlw", "%s", l);
+ else
+ emitcode ("movf", "%s,w", l);
+ // The last one is past in W
+ if (size)
+ emitcode ("movwf", "%s", fReturn[offset]);
+ }
+ offset++;
+ }
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
+ _G.sendSet = NULL;
+ }
+ /* make the call */
+ emitcode ("call", "%s", (OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
+ OP_SYMBOL (IC_LEFT (ic))->rname :
+ OP_SYMBOL (IC_LEFT (ic))->name));
+
+ /* if we need assign a result value */
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ _G.accInUse--;
- aopOp(IC_LEFT(sic),sic,FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset,
- FALSE,FALSE);
- DEBUGemitcode(";","%d - left type %d",__LINE__,AOP(IC_LEFT(sic))->type);
+ assignResultValue (IC_RESULT (ic));
- if (strcmp(l,fReturn[offset])) {
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ }
- if ( ((AOP(IC_LEFT(sic))->type) == AOP_IMMD) ||
- ((AOP(IC_LEFT(sic))->type) == AOP_LIT) )
- emitcode("movlw","%s",l);
+ /* adjust the stack for parameters if
+ required */
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i;
+ if (IC_LEFT (ic)->parmBytes > 3)
+ {
+ emitcode ("mov", "a,%s", spname);
+ emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff);
+ emitcode ("mov", "%s,a", spname);
+ }
else
- emitcode("movf","%s,w",l);
- // The last one is past in W
- if(size)
- emitcode("movwf","%s",fReturn[offset]);
- }
- offset++;
- }
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
- }
- _G.sendSet = NULL;
- }
- /* make the call */
- emitcode("call","%s",(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
- OP_SYMBOL(IC_LEFT(ic))->rname :
- OP_SYMBOL(IC_LEFT(ic))->name));
-
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
-
- _G.accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE);
- _G.accInUse--;
-
- assignResultValue(IC_RESULT(ic));
-
- freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
- }
-
- /* adjust the stack for parameters if
- required */
- if (IC_LEFT(ic)->parmBytes) {
- int i;
- if (IC_LEFT(ic)->parmBytes > 3) {
- emitcode("mov","a,%s",spname);
- emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff);
- emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++)
- emitcode("dec","%s",spname);
-
+ for (i = 0; i < IC_LEFT (ic)->parmBytes; i++)
+ emitcode ("dec", "%s", spname);
+
}
- /* if register bank was saved then pop them */
- if (ic->bankSaved)
- unsaverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if register bank was saved then pop them */
+ if (ic->bankSaved)
+ unsaverbank (SPEC_BANK (detype), ic, TRUE);
- /* if we hade saved some registers then unsave them */
- if (ic->regsSaved && !(OP_SYMBOL(IC_LEFT(ic))->calleeSave))
- unsaveRegisters (ic);
+ /* if we hade saved some registers then unsave them */
+ if (ic->regsSaved && !(OP_SYMBOL (IC_LEFT (ic))->calleeSave))
+ unsaveRegisters (ic);
}
/*-----------------------------------------------------------------*/
/* genPcall - generates a call by pointer statement */
/*-----------------------------------------------------------------*/
-static void genPcall (iCode *ic)
+static void
+genPcall (iCode * ic)
{
- sym_link *detype;
- symbol *rlbl = newiTempLabel(NULL);
+ sym_link *detype;
+ symbol *rlbl = newiTempLabel (NULL);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved)
- saveRegisters(ic);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ saveRegisters (ic);
- /* if we are calling a function that is not using
- the same register bank then we need to save the
- destination registers on the stack */
- detype = getSpec(operandType(IC_LEFT(ic)));
- if (detype &&
- IS_ISR(currFunc->etype) &&
- (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)))
- saverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if we are calling a function that is not using
+ the same register bank then we need to save the
+ destination registers on the stack */
+ detype = getSpec (operandType (IC_LEFT (ic)));
+ if (detype &&
+ IS_ISR (currFunc->etype) &&
+ (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)))
+ saverbank (SPEC_BANK (detype), ic, TRUE);
- /* push the return address on to the stack */
- emitcode("mov","a,#%05d_DS_",(rlbl->key+100));
- emitcode("push","acc");
- emitcode("mov","a,#(%05d_DS_ >> 8)",(rlbl->key+100));
- emitcode("push","acc");
+ /* push the return address on to the stack */
+ emitcode ("mov", "a,#%05d_DS_", (rlbl->key + 100));
+ emitcode ("push", "acc");
+ emitcode ("mov", "a,#(%05d_DS_ >> 8)", (rlbl->key + 100));
+ emitcode ("push", "acc");
- if (options.model == MODEL_FLAT24)
+ if (options.model == MODEL_FLAT24)
{
- emitcode("mov","a,#(%05d_DS_ >> 16)",(rlbl->key+100));
- emitcode("push","acc");
+ emitcode ("mov", "a,#(%05d_DS_ >> 16)", (rlbl->key + 100));
+ emitcode ("push", "acc");
}
- /* now push the calling address */
- aopOp(IC_LEFT(ic),ic,FALSE);
-
- pushSide(IC_LEFT(ic), FPTRSIZE);
-
- freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
-
- /* if send set is not empty the assign */
- if (_G.sendSet) {
- iCode *sic ;
-
- for (sic = setFirstItem(_G.sendSet) ; sic ;
- sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
- aopOp(IC_LEFT(sic),sic,FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(sic)),offset,
- FALSE,FALSE);
- if (strcmp(l,fReturn[offset]))
- emitcode("mov","%s,%s",
- fReturn[offset],
- l);
- offset++;
- }
- freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
- }
- _G.sendSet = NULL;
- }
+ /* now push the calling address */
+ aopOp (IC_LEFT (ic), ic, FALSE);
- emitcode("ret","");
- emitcode("","%05d_DS_:",(rlbl->key+100));
+ pushSide (IC_LEFT (ic), FPTRSIZE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir)) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+ /* if send set is not empty the assign */
+ if (_G.sendSet)
+ {
+ iCode *sic;
+
+ for (sic = setFirstItem (_G.sendSet); sic;
+ sic = setNextItem (_G.sendSet))
+ {
+ int size, offset = 0;
+ aopOp (IC_LEFT (sic), sic, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (sic)), offset,
+ FALSE, FALSE);
+ if (strcmp (l, fReturn[offset]))
+ emitcode ("mov", "%s,%s",
+ fReturn[offset],
+ l);
+ offset++;
+ }
+ freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+ }
+ _G.sendSet = NULL;
+ }
+
+ emitcode ("ret", "");
+ emitcode ("", "%05d_DS_:", (rlbl->key + 100));
+
+
+ /* if we need assign a result value */
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
- _G.accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE);
- _G.accInUse--;
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ _G.accInUse--;
- assignResultValue(IC_RESULT(ic));
+ assignResultValue (IC_RESULT (ic));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
- /* adjust the stack for parameters if
- required */
- if (IC_LEFT(ic)->parmBytes) {
- int i;
- if (IC_LEFT(ic)->parmBytes > 3) {
- emitcode("mov","a,%s",spname);
- emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff);
- emitcode("mov","%s,a",spname);
- } else
- for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++)
- emitcode("dec","%s",spname);
+ /* adjust the stack for parameters if
+ required */
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i;
+ if (IC_LEFT (ic)->parmBytes > 3)
+ {
+ emitcode ("mov", "a,%s", spname);
+ emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff);
+ emitcode ("mov", "%s,a", spname);
+ }
+ else
+ for (i = 0; i < IC_LEFT (ic)->parmBytes; i++)
+ emitcode ("dec", "%s", spname);
}
- /* if register bank was saved then unsave them */
- if (detype &&
- (SPEC_BANK(currFunc->etype) !=
- SPEC_BANK(detype)))
- unsaverbank(SPEC_BANK(detype),ic,TRUE);
+ /* if register bank was saved then unsave them */
+ if (detype &&
+ (SPEC_BANK (currFunc->etype) !=
+ SPEC_BANK (detype)))
+ unsaverbank (SPEC_BANK (detype), ic, TRUE);
- /* if we hade saved some registers then
- unsave them */
- if (ic->regsSaved)
- unsaveRegisters (ic);
+ /* if we hade saved some registers then
+ unsave them */
+ if (ic->regsSaved)
+ unsaveRegisters (ic);
}
/*-----------------------------------------------------------------*/
/* resultRemat - result is rematerializable */
/*-----------------------------------------------------------------*/
-static int resultRemat (iCode *ic)
+static int
+resultRemat (iCode * ic)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (SKIP_IC(ic) || ic->op == IFX)
- return 0;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (SKIP_IC (ic) || ic->op == IFX)
+ return 0;
- if (IC_RESULT(ic) && IS_ITEMP(IC_RESULT(ic))) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- if (sym->remat && !POINTER_SET(ic))
- return 1;
+ if (IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic)))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ if (sym->remat && !POINTER_SET (ic))
+ return 1;
}
- return 0;
+ return 0;
}
#if defined(__BORLANDC__) || defined(_MSC_VER)
/*-----------------------------------------------------------------*/
/* inExcludeList - return 1 if the string is in exclude Reg list */
/*-----------------------------------------------------------------*/
-static bool inExcludeList(char *s)
+static bool
+inExcludeList (char *s)
{
- int i =0;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (options.excludeRegs[i] &&
- STRCASECMP(options.excludeRegs[i],"none") == 0)
- return FALSE ;
+ int i = 0;
- for ( i = 0 ; options.excludeRegs[i]; i++) {
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
if (options.excludeRegs[i] &&
- STRCASECMP(s,options.excludeRegs[i]) == 0)
- return TRUE;
+ 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 ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* genFunction - generated code for function entry */
/*-----------------------------------------------------------------*/
-static void genFunction (iCode *ic)
+static void
+genFunction (iCode * ic)
{
- symbol *sym;
- sym_link *fetype;
+ symbol *sym;
+ sym_link *fetype;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- labelOffset += FUNCTION_LABEL_INC;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ labelOffset += FUNCTION_LABEL_INC;
- _G.nRegsSaved = 0;
- /* create the function header */
- emitcode(";","-----------------------------------------");
- emitcode(";"," function %s",(sym = OP_SYMBOL(IC_LEFT(ic)))->name);
- emitcode(";","-----------------------------------------");
+ _G.nRegsSaved = 0;
+ /* create the function header */
+ emitcode (";", "-----------------------------------------");
+ emitcode (";", " function %s", (sym = OP_SYMBOL (IC_LEFT (ic)))->name);
+ emitcode (";", "-----------------------------------------");
- emitcode("","%s:",sym->rname);
- fetype = getSpec(operandType(IC_LEFT(ic)));
+ emitcode ("", "%s:", sym->rname);
+ fetype = getSpec (operandType (IC_LEFT (ic)));
- /* if critical function then turn interrupts off */
- if (SPEC_CRTCL(fetype))
- emitcode("clr","ea");
+ /* if critical function then turn interrupts off */
+ if (SPEC_CRTCL (fetype))
+ emitcode ("clr", "ea");
- /* here we need to generate the equates for the
- register bank if required */
+ /* here we need to generate the equates for the
+ register bank if required */
#if 0
- if (SPEC_BANK(fetype) != rbank) {
- int i ;
-
- rbank = SPEC_BANK(fetype);
- for ( i = 0 ; i < pic14_nRegs ; i++ ) {
- if (strcmp(regspic14[i].base,"0") == 0)
- emitcode("","%s = 0x%02x",
- regspic14[i].dname,
- 8*rbank+regspic14[i].offset);
- else
- emitcode ("","%s = %s + 0x%02x",
- regspic14[i].dname,
- regspic14[i].base,
- 8*rbank+regspic14[i].offset);
- }
+ if (SPEC_BANK (fetype) != rbank)
+ {
+ int i;
+
+ rbank = SPEC_BANK (fetype);
+ for (i = 0; i < pic14_nRegs; i++)
+ {
+ if (strcmp (regspic14[i].base, "0") == 0)
+ emitcode ("", "%s = 0x%02x",
+ regspic14[i].dname,
+ 8 * rbank + regspic14[i].offset);
+ else
+ emitcode ("", "%s = %s + 0x%02x",
+ regspic14[i].dname,
+ regspic14[i].base,
+ 8 * rbank + regspic14[i].offset);
+ }
}
#endif
- /* if this is an interrupt service routine then
- save acc, b, dpl, dph */
- if (IS_ISR(sym->etype)) {
-
- if (!inExcludeList("acc"))
- emitcode ("push","acc");
- if (!inExcludeList("b"))
- emitcode ("push","b");
- if (!inExcludeList("dpl"))
- emitcode ("push","dpl");
- if (!inExcludeList("dph"))
- emitcode ("push","dph");
- if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
- {
- emitcode ("push", "dpx");
- /* Make sure we're using standard DPTR */
- emitcode ("push", "dps");
- emitcode ("mov", "dps, #0x00");
- if (options.stack10bit)
- {
- /* This ISR could conceivably use DPTR2. Better save it. */
- emitcode ("push", "dpl1");
- emitcode ("push", "dph1");
- emitcode ("push", "dpx1");
- }
- }
- /* if this isr has no bank i.e. is going to
- run with bank 0 , then we need to save more
- registers :-) */
- if (!SPEC_BANK(sym->etype)) {
-
- /* if this function does not call any other
- function then we can be economical and
- save only those registers that are used */
- if (! sym->hasFcall) {
- int i;
-
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = 0 ; i < sym->regsUsed->size ; i++) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("push","%s",pic14_regWithIdx(i)->dname);
- }
- }
-
- } else {
- /* this function has a function call cannot
- determines register usage so we will have the
- entire bank */
- saverbank(0,ic,FALSE);
- }
- }
- } else {
- /* if callee-save to be used for this function
- then save the registers being used in this function */
- if (sym->calleeSave) {
- int i;
+ /* if this is an interrupt service routine then
+ save acc, b, dpl, dph */
+ if (IS_ISR (sym->etype))
+ {
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = 0 ; i < sym->regsUsed->size ; i++) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)) ) {
- emitcode("push","%s",pic14_regWithIdx(i)->dname);
- _G.nRegsSaved++;
- }
- }
- }
- }
+ if (!inExcludeList ("acc"))
+ emitcode ("push", "acc");
+ if (!inExcludeList ("b"))
+ emitcode ("push", "b");
+ if (!inExcludeList ("dpl"))
+ emitcode ("push", "dpl");
+ if (!inExcludeList ("dph"))
+ emitcode ("push", "dph");
+ if (options.model == MODEL_FLAT24 && !inExcludeList ("dpx"))
+ {
+ emitcode ("push", "dpx");
+ /* Make sure we're using standard DPTR */
+ emitcode ("push", "dps");
+ emitcode ("mov", "dps, #0x00");
+ if (options.stack10bit)
+ {
+ /* This ISR could conceivably use DPTR2. Better save it. */
+ emitcode ("push", "dpl1");
+ emitcode ("push", "dph1");
+ emitcode ("push", "dpx1");
+ }
+ }
+ /* if this isr has no bank i.e. is going to
+ run with bank 0 , then we need to save more
+ registers :-) */
+ if (!SPEC_BANK (sym->etype))
+ {
+
+ /* if this function does not call any other
+ function then we can be economical and
+ save only those registers that are used */
+ if (!sym->hasFcall)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = 0; i < sym->regsUsed->size; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("push", "%s", pic14_regWithIdx (i)->dname);
+ }
+ }
+
+ }
+ else
+ {
+ /* this function has a function call cannot
+ determines register usage so we will have the
+ entire bank */
+ saverbank (0, ic, FALSE);
+ }
+ }
}
-
- /* set the register bank to the desired value */
- if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype)) {
- emitcode("push","psw");
- emitcode("mov","psw,#0x%02x",(SPEC_BANK(sym->etype) << 3)&0x00ff);
+ else
+ {
+ /* if callee-save to be used for this function
+ then save the registers being used in this function */
+ if (sym->calleeSave)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = 0; i < sym->regsUsed->size; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ {
+ emitcode ("push", "%s", pic14_regWithIdx (i)->dname);
+ _G.nRegsSaved++;
+ }
+ }
+ }
+ }
+ }
+
+ /* set the register bank to the desired value */
+ if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ {
+ emitcode ("push", "psw");
+ emitcode ("mov", "psw,#0x%02x", (SPEC_BANK (sym->etype) << 3) & 0x00ff);
}
- if (IS_RENT(sym->etype) || options.stackAuto) {
+ if (IS_RENT (sym->etype) || options.stackAuto)
+ {
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- emitcode("mov","a,_bp");
- emitcode("movx","@r0,a");
- emitcode("inc","%s",spname);
- }
- else
- {
- /* set up the stack */
- emitcode ("push","_bp"); /* save the callers stack */
- }
- emitcode ("mov","_bp,%s",spname);
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ emitcode ("mov", "a,_bp");
+ emitcode ("movx", "@r0,a");
+ emitcode ("inc", "%s", spname);
+ }
+ else
+ {
+ /* set up the stack */
+ emitcode ("push", "_bp"); /* save the callers stack */
+ }
+ emitcode ("mov", "_bp,%s", spname);
}
- /* adjust the stack for the function */
- if (sym->stack) {
+ /* adjust the stack for the function */
+ if (sym->stack)
+ {
- int i = sym->stack;
- if (i > 256 )
- werror(W_STACK_OVERFLOW,sym->name);
+ int i = sym->stack;
+ if (i > 256)
+ werror (W_STACK_OVERFLOW, sym->name);
- if (i > 3 && sym->recvSize < 4) {
+ if (i > 3 && sym->recvSize < 4)
+ {
- emitcode ("mov","a,sp");
- emitcode ("add","a,#0x%02x",((char)sym->stack & 0xff));
- emitcode ("mov","sp,a");
+ emitcode ("mov", "a,sp");
+ emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+ emitcode ("mov", "sp,a");
- }
- else
- while(i--)
- emitcode("inc","sp");
+ }
+ else
+ while (i--)
+ emitcode ("inc", "sp");
}
- if (sym->xstack) {
+ if (sym->xstack)
+ {
- emitcode ("mov","a,_spx");
- emitcode ("add","a,#0x%02x",((char)sym->xstack & 0xff));
- emitcode ("mov","_spx,a");
+ emitcode ("mov", "a,_spx");
+ emitcode ("add", "a,#0x%02x", ((char) sym->xstack & 0xff));
+ emitcode ("mov", "_spx,a");
}
}
/*-----------------------------------------------------------------*/
/* genEndFunction - generates epilogue for functions */
/*-----------------------------------------------------------------*/
-static void genEndFunction (iCode *ic)
+static void
+genEndFunction (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- if (IS_RENT(sym->etype) || options.stackAuto)
+ if (IS_RENT (sym->etype) || options.stackAuto)
{
- emitcode ("mov","%s,_bp",spname);
+ emitcode ("mov", "%s,_bp", spname);
}
- /* if use external stack but some variables were
- added to the local stack then decrement the
- local stack */
- if (options.useXstack && sym->stack) {
- emitcode("mov","a,sp");
- emitcode("add","a,#0x%02x",((char)-sym->stack) & 0xff);
- emitcode("mov","sp,a");
+ /* if use external stack but some variables were
+ added to the local stack then decrement the
+ local stack */
+ if (options.useXstack && sym->stack)
+ {
+ emitcode ("mov", "a,sp");
+ emitcode ("add", "a,#0x%02x", ((char) -sym->stack) & 0xff);
+ emitcode ("mov", "sp,a");
}
- if ((IS_RENT(sym->etype) || options.stackAuto)) {
- if (options.useXstack) {
- emitcode("mov","r0,%s",spname);
- emitcode("movx","a,@r0");
- emitcode("mov","_bp,a");
- emitcode("dec","%s",spname);
- }
- else
- {
- emitcode ("pop","_bp");
- }
+ if ((IS_RENT (sym->etype) || options.stackAuto))
+ {
+ if (options.useXstack)
+ {
+ emitcode ("mov", "r0,%s", spname);
+ emitcode ("movx", "a,@r0");
+ emitcode ("mov", "_bp,a");
+ emitcode ("dec", "%s", spname);
+ }
+ else
+ {
+ emitcode ("pop", "_bp");
+ }
}
- /* restore the register bank */
- if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype))
- emitcode ("pop","psw");
-
- if (IS_ISR(sym->etype)) {
-
- /* now we need to restore the registers */
- /* if this isr has no bank i.e. is going to
- run with bank 0 , then we need to save more
- registers :-) */
- if (!SPEC_BANK(sym->etype)) {
+ /* restore the register bank */
+ if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ emitcode ("pop", "psw");
- /* if this function does not call any other
- function then we can be economical and
- save only those registers that are used */
- if (! sym->hasFcall) {
- int i;
-
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",pic14_regWithIdx(i)->dname);
- }
- }
-
- } else {
- /* this function has a function call cannot
- determines register usage so we will have the
- entire bank */
- unsaverbank(0,ic,FALSE);
- }
- }
+ if (IS_ISR (sym->etype))
+ {
- if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
- {
- if (options.stack10bit)
- {
- emitcode ("pop", "dpx1");
- emitcode ("pop", "dph1");
- emitcode ("pop", "dpl1");
- }
- emitcode ("pop", "dps");
- emitcode ("pop", "dpx");
- }
- if (!inExcludeList("dph"))
- emitcode ("pop","dph");
- if (!inExcludeList("dpl"))
- emitcode ("pop","dpl");
- if (!inExcludeList("b"))
- emitcode ("pop","b");
- if (!inExcludeList("acc"))
- emitcode ("pop","acc");
-
- if (SPEC_CRTCL(sym->etype))
- emitcode("setb","ea");
-
- /* if debug then send end of function */
+ /* now we need to restore the registers */
+ /* if this isr has no bank i.e. is going to
+ run with bank 0 , then we need to save more
+ registers :-) */
+ if (!SPEC_BANK (sym->etype))
+ {
+
+ /* if this function does not call any other
+ function then we can be economical and
+ save only those registers that are used */
+ if (!sym->hasFcall)
+ {
+ int i;
+
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = sym->regsUsed->size; i >= 0; i--)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("pop", "%s", pic14_regWithIdx (i)->dname);
+ }
+ }
+
+ }
+ else
+ {
+ /* this function has a function call cannot
+ determines register usage so we will have the
+ entire bank */
+ unsaverbank (0, ic, FALSE);
+ }
+ }
+
+ if (options.model == MODEL_FLAT24 && !inExcludeList ("dpx"))
+ {
+ if (options.stack10bit)
+ {
+ emitcode ("pop", "dpx1");
+ emitcode ("pop", "dph1");
+ emitcode ("pop", "dpl1");
+ }
+ emitcode ("pop", "dps");
+ emitcode ("pop", "dpx");
+ }
+ if (!inExcludeList ("dph"))
+ emitcode ("pop", "dph");
+ if (!inExcludeList ("dpl"))
+ emitcode ("pop", "dpl");
+ if (!inExcludeList ("b"))
+ emitcode ("pop", "b");
+ if (!inExcludeList ("acc"))
+ emitcode ("pop", "acc");
+
+ if (SPEC_CRTCL (sym->etype))
+ emitcode ("setb", "ea");
+
+ /* if debug then send end of function */
/* if (options.debug && currFunc) { */
- if (currFunc) {
- _G.debugLine = 1;
- emitcode(";","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),currFunc->lastLine,
- ic->level,ic->block);
- if (IS_STATIC(currFunc->etype))
- emitcode(";","XF%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode(";","XG$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
-
- emitcode ("reti","");
+ if (currFunc)
+ {
+ _G.debugLine = 1;
+ emitcode (";", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), currFunc->lastLine,
+ ic->level, ic->block);
+ if (IS_STATIC (currFunc->etype))
+ emitcode (";", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode (";", "XG$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
+
+ emitcode ("reti", "");
}
- else {
- if (SPEC_CRTCL(sym->etype))
- emitcode("setb","ea");
+ else
+ {
+ if (SPEC_CRTCL (sym->etype))
+ emitcode ("setb", "ea");
- if (sym->calleeSave) {
- int i;
+ if (sym->calleeSave)
+ {
+ int i;
- /* if any registers used */
- if (sym->regsUsed) {
- /* save the registers used */
- for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
- if (bitVectBitValue(sym->regsUsed,i) ||
- (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",pic14_regWithIdx(i)->dname);
- }
- }
+ /* if any registers used */
+ if (sym->regsUsed)
+ {
+ /* save the registers used */
+ for (i = sym->regsUsed->size; i >= 0; i--)
+ {
+ if (bitVectBitValue (sym->regsUsed, i) ||
+ (pic14_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+ emitcode ("pop", "%s", pic14_regWithIdx (i)->dname);
+ }
+ }
- }
+ }
- /* if debug then send end of function */
- if (currFunc) {
- _G.debugLine = 1;
- emitcode(";","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),currFunc->lastLine,
- ic->level,ic->block);
- if (IS_STATIC(currFunc->etype))
- emitcode(";","XF%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode(";","XG$%s$0$0 ==.",currFunc->name);
- _G.debugLine = 0;
- }
+ /* if debug then send end of function */
+ if (currFunc)
+ {
+ _G.debugLine = 1;
+ emitcode (";", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), currFunc->lastLine,
+ ic->level, ic->block);
+ if (IS_STATIC (currFunc->etype))
+ emitcode (";", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode (";", "XG$%s$0$0 ==.", currFunc->name);
+ _G.debugLine = 0;
+ }
- emitcode ("return","");
+ emitcode ("return", "");
}
}
/*-----------------------------------------------------------------*/
/* genRet - generate code for return statement */
/*-----------------------------------------------------------------*/
-static void genRet (iCode *ic)
-{
- int size,offset = 0 , pushed = 0;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if we have no return value then
- just generate the "ret" */
- if (!IC_LEFT(ic))
- goto jumpret;
-
- /* we have something to return then
- move the return value into place */
- aopOp(IC_LEFT(ic),ic,FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
-
- while (size--) {
- char *l ;
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
- /* #NOCHANGE */
- l = aopGet(AOP(IC_LEFT(ic)),offset++,
- FALSE,TRUE);
- emitcode("push","%s",l);
- pushed++;
- } else {
- l = aopGet(AOP(IC_LEFT(ic)),offset,
- FALSE,FALSE);
- if (strcmp(fReturn[offset],l)) {
- if( ( (AOP(IC_LEFT(ic))->type) == AOP_IMMD) ||
- ((AOP(IC_LEFT(ic))->type) == AOP_LIT) )
- emitcode("movlw","%s",l);
- else
- emitcode("movf","%s,w",l);
- if(size)
- emitcode("movwf","%s",fReturn[offset]);
- offset++;
- }
- }
- }
+static void
+genRet (iCode * ic)
+{
+ int size, offset = 0, pushed = 0;
- if (pushed) {
- while(pushed) {
- pushed--;
- if (strcmp(fReturn[pushed],"a"))
- emitcode("pop",fReturn[pushed]);
- else
- emitcode("pop","acc");
- }
- }
- freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if we have no return value then
+ just generate the "ret" */
+ if (!IC_LEFT (ic))
+ goto jumpret;
+
+ /* we have something to return then
+ move the return value into place */
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
- jumpret:
+ while (size--)
+ {
+ char *l;
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR)
+ {
+ /* #NOCHANGE */
+ l = aopGet (AOP (IC_LEFT (ic)), offset++,
+ FALSE, TRUE);
+ emitcode ("push", "%s", l);
+ pushed++;
+ }
+ else
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset,
+ FALSE, FALSE);
+ if (strcmp (fReturn[offset], l))
+ {
+ if (((AOP (IC_LEFT (ic))->type) == AOP_IMMD) ||
+ ((AOP (IC_LEFT (ic))->type) == AOP_LIT))
+ emitcode ("movlw", "%s", l);
+ else
+ emitcode ("movf", "%s,w", l);
+ if (size)
+ emitcode ("movwf", "%s", fReturn[offset]);
+ offset++;
+ }
+ }
+ }
+
+ if (pushed)
+ {
+ while (pushed)
+ {
+ pushed--;
+ if (strcmp (fReturn[pushed], "a"))
+ emitcode ("pop", fReturn[pushed]);
+ else
+ emitcode ("pop", "acc");
+ }
+ }
+ freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
+
+jumpret:
/* generate a jump to the return label
if the next is not the return statement */
- if (!(ic->next && ic->next->op == LABEL &&
- IC_LABEL(ic->next) == returnLabel))
+ if (!(ic->next && ic->next->op == LABEL &&
+ IC_LABEL (ic->next) == returnLabel))
- emitcode("goto","_%05d_DS_",returnLabel->key+100 + labelOffset);
+ emitcode ("goto", "_%05d_DS_", returnLabel->key + 100 + labelOffset);
}
/*-----------------------------------------------------------------*/
/* genLabel - generates a label */
/*-----------------------------------------------------------------*/
-static void genLabel (iCode *ic)
+static void
+genLabel (iCode * ic)
{
- /* special case never generate */
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (IC_LABEL(ic) == entryLabel)
- return ;
+ /* special case never generate */
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (IC_LABEL (ic) == entryLabel)
+ return;
- emitcode("","_%05d_DS_:",(IC_LABEL(ic)->key+100 + labelOffset));
+ emitcode ("", "_%05d_DS_:", (IC_LABEL (ic)->key + 100 + labelOffset));
}
/*-----------------------------------------------------------------*/
/* genGoto - generates a goto */
/*-----------------------------------------------------------------*/
//tsd
-static void genGoto (iCode *ic)
+static void
+genGoto (iCode * ic)
{
- emitcode ("goto","_%05d_DS_",(IC_LABEL(ic)->key+100)+labelOffset);
+ emitcode ("goto", "_%05d_DS_", (IC_LABEL (ic)->key + 100) + labelOffset);
}
/*-----------------------------------------------------------------*/
/* Returns zero if label not found. */
/*-----------------------------------------------------------------*/
#if 0
-static int findLabelBackwards(iCode *ic, int key)
+static int
+findLabelBackwards (iCode * ic, int key)
{
- int count = 0;
+ int count = 0;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- while (ic->prev)
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ while (ic->prev)
{
- ic = ic->prev;
- count++;
+ ic = ic->prev;
+ count++;
- if (ic->op == LABEL && IC_LABEL(ic)->key == key)
- {
- /* printf("findLabelBackwards = %d\n", count); */
- return count;
- }
+ if (ic->op == LABEL && IC_LABEL (ic)->key == key)
+ {
+ /* printf("findLabelBackwards = %d\n", count); */
+ return count;
+ }
}
- return 0;
+ return 0;
}
#endif
/*-----------------------------------------------------------------*/
/* genPlusIncr :- does addition with increment if possible */
/*-----------------------------------------------------------------*/
-static bool genPlusIncr (iCode *ic)
-{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- DEBUGemitcode ("; ","result %d, left %d, right %d",
- AOP_TYPE(IC_RESULT(ic)),
- AOP_TYPE(IC_LEFT(ic)),
- AOP_TYPE(IC_RIGHT(ic)));
-
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
-
- DEBUGemitcode ("; ","%s %d",__FUNCTION__,__LINE__);
- /* if the literal value of the right hand side
- is greater than 1 then it is faster to add */
- if ((icount = floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
- return FALSE ;
-
- /* if increment 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (icount == 1)) {
+static bool
+genPlusIncr (iCode * ic)
+{
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ DEBUGemitcode ("; ", "result %d, left %d, right %d",
+ AOP_TYPE (IC_RESULT (ic)),
+ AOP_TYPE (IC_LEFT (ic)),
+ AOP_TYPE (IC_RIGHT (ic)));
+
+ /* will try to generate an increment */
+ /* if the right side is not a literal
+ we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
+
+ DEBUGemitcode ("; ", "%s %d", __FUNCTION__, __LINE__);
+ /* if the literal value of the right hand side
+ is greater than 1 then it is faster to add */
+ if ((icount = floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 2)
+ return FALSE;
+
+ /* if increment 16 bits in register */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (icount == 1))
+ {
int offset = MSB16;
- emitcode("incf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
+ emitcode ("incf", "%s,f", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE));
- while(--size) {
- emitSKPNZ;
- emitcode(" incf","%s,f",aopGet(AOP(IC_RESULT(ic)),offset++,FALSE,FALSE));
- }
+ while (--size)
+ {
+ emitSKPNZ;
+ emitcode (" incf", "%s,f", aopGet (AOP (IC_RESULT (ic)), offset++, FALSE, FALSE));
+ }
return TRUE;
}
- DEBUGemitcode ("; ","%s %d",__FUNCTION__,__LINE__);
- /* if left is in accumulator - probably a bit operation*/
- if( strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a") &&
- (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) ) {
+ DEBUGemitcode ("; ", "%s %d", __FUNCTION__, __LINE__);
+ /* if left is in accumulator - probably a bit operation */
+ if (strcmp (aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE), "a") &&
+ (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY))
+ {
- emitcode("bcf","(%s >> 3), (%s & 7)",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
- if(icount)
- emitcode("xorlw","1");
+ emitcode ("bcf", "(%s >> 3), (%s & 7)",
+ AOP (IC_RESULT (ic))->aopu.aop_dir,
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
+ if (icount)
+ emitcode ("xorlw", "1");
else
- emitcode("andlw","1");
+ emitcode ("andlw", "1");
emitSKPZ;
- emitcode("bsf","(%s >> 3), (%s & 7)",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
+ emitcode ("bsf", "(%s >> 3), (%s & 7)",
+ AOP (IC_RESULT (ic))->aopu.aop_dir,
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* If we are incrementing the same register by two: */
+ /* If we are incrementing the same register by two: */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
while (icount--)
- emitcode("incf","%s,f",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+ emitcode ("incf", "%s,f", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
- return TRUE ;
+ return TRUE;
}
- DEBUGemitcode ("; ","couldn't increment result-%s left-%s",
- aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
- aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- return FALSE ;
+ DEBUGemitcode ("; ", "couldn't increment result-%s left-%s",
+ aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE),
+ aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* outBitAcc - output a bit in acc */
/*-----------------------------------------------------------------*/
-static void outBitAcc(operand *result)
+static void
+outBitAcc (operand * result)
{
- symbol *tlbl = newiTempLabel(NULL);
- /* if the result is a bit */
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ symbol *tlbl = newiTempLabel (NULL);
+ /* if the result is a bit */
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- if (AOP_TYPE(result) == AOP_CRY){
- aopPut(AOP(result),"a",0);
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ aopPut (AOP (result), "a", 0);
}
- else {
- emitcode("jz","%05d_DS_",tlbl->key+100);
- emitcode("mov","a,%s",one);
- emitcode("","%05d_DS_:",tlbl->key+100);
- outAcc(result);
+ else
+ {
+ emitcode ("jz", "%05d_DS_", tlbl->key + 100);
+ emitcode ("mov", "a,%s", one);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ outAcc (result);
}
}
/*-----------------------------------------------------------------*/
/* genPlusBits - generates code for addition of two bits */
/*-----------------------------------------------------------------*/
-static void genPlusBits (iCode *ic)
-{
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /*
- The following block of code will add two bits.
- Note that it'll even work if the destination is
- the carry (C in the status register).
- It won't work if the 'Z' bit is a source or destination.
- */
-
- /* If the result is stored in the accumulator (w) */
- if(strcmp(aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),"a") == 0 ) {
- emitcode("movlw","(1 << (%s & 7))",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
- emitcode("bcf","(%s >> 3), (%s & 7)",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("xorwf","(%s >>3),f",
- AOP(IC_RESULT(ic))->aopu.aop_dir);
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_LEFT(ic))->aopu.aop_dir,
- AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("xorwf","(%s>>3),f",
- AOP(IC_RESULT(ic))->aopu.aop_dir);
- } else {
-
- emitcode("clrw","");
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("xorlw","1");
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_LEFT(ic))->aopu.aop_dir,
- AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("xorlw","1");
+static void
+genPlusBits (iCode * ic)
+{
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /*
+ The following block of code will add two bits.
+ Note that it'll even work if the destination is
+ the carry (C in the status register).
+ It won't work if the 'Z' bit is a source or destination.
+ */
+
+ /* If the result is stored in the accumulator (w) */
+ if (strcmp (aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE), "a") == 0)
+ {
+ emitcode ("movlw", "(1 << (%s & 7))",
+ AOP (IC_RESULT (ic))->aopu.aop_dir,
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
+ emitcode ("bcf", "(%s >> 3), (%s & 7)",
+ AOP (IC_RESULT (ic))->aopu.aop_dir,
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (ic))->aopu.aop_dir,
+ AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode ("xorwf", "(%s >>3),f",
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_LEFT (ic))->aopu.aop_dir,
+ AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("xorwf", "(%s>>3),f",
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
+ }
+ else
+ {
+
+ emitcode ("clrw", "");
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (ic))->aopu.aop_dir,
+ AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode ("xorlw", "1");
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_LEFT (ic))->aopu.aop_dir,
+ AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("xorlw", "1");
}
}
#if 0
/* This is the original version of this code.
- *
+
* This is being kept around for reference,
* because I am not entirely sure I got it right...
*/
-static void adjustArithmeticResult(iCode *ic)
-{
- if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
- AOP_SIZE(IC_LEFT(ic)) == 3 &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_LEFT(ic)),2,FALSE,FALSE),
- 2);
-
- if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
- AOP_SIZE(IC_RIGHT(ic)) == 3 &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_RIGHT(ic)),2,FALSE,FALSE),
- 2);
-
- if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
- AOP_SIZE(IC_LEFT(ic)) < 3 &&
- AOP_SIZE(IC_RIGHT(ic)) < 3 &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
- char buffer[5];
- sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
- aopPut(AOP(IC_RESULT(ic)),buffer,2);
+static void
+adjustArithmeticResult (iCode * ic)
+{
+ if (AOP_SIZE (IC_RESULT (ic)) == 3 &&
+ AOP_SIZE (IC_LEFT (ic)) == 3 &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_LEFT (ic)), 2, FALSE, FALSE),
+ 2);
+
+ if (AOP_SIZE (IC_RESULT (ic)) == 3 &&
+ AOP_SIZE (IC_RIGHT (ic)) == 3 &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_RIGHT (ic)), 2, FALSE, FALSE),
+ 2);
+
+ if (AOP_SIZE (IC_RESULT (ic)) == 3 &&
+ AOP_SIZE (IC_LEFT (ic)) < 3 &&
+ AOP_SIZE (IC_RIGHT (ic)) < 3 &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ {
+ char buffer[5];
+ sprintf (buffer, "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic)))));
+ aopPut (AOP (IC_RESULT (ic)), buffer, 2);
}
}
//#else
* I'm pretty certain it's right, but not enough to toss the old
* code just yet...
*/
-static void adjustArithmeticResult(iCode *ic)
+static void
+adjustArithmeticResult (iCode * ic)
{
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_LEFT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_LEFT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_LEFT(ic)), GPTRSIZE - 1,FALSE,FALSE),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_LEFT (ic)), GPTRSIZE - 1, FALSE, FALSE),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- opIsGptr(IC_RIGHT(ic)) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
+ if (opIsGptr (IC_RESULT (ic)) &&
+ opIsGptr (IC_RIGHT (ic)) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
{
- aopPut(AOP(IC_RESULT(ic)),
- aopGet(AOP(IC_RIGHT(ic)),GPTRSIZE - 1,FALSE,FALSE),
- GPTRSIZE - 1);
+ aopPut (AOP (IC_RESULT (ic)),
+ aopGet (AOP (IC_RIGHT (ic)), GPTRSIZE - 1, FALSE, FALSE),
+ GPTRSIZE - 1);
}
- if (opIsGptr(IC_RESULT(ic)) &&
- AOP_SIZE(IC_LEFT(ic)) < GPTRSIZE &&
- AOP_SIZE(IC_RIGHT(ic)) < GPTRSIZE &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
- char buffer[5];
- sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
- aopPut(AOP(IC_RESULT(ic)),buffer,GPTRSIZE - 1);
- }
+ if (opIsGptr (IC_RESULT (ic)) &&
+ AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+ AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
+ {
+ char buffer[5];
+ sprintf (buffer, "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic)))));
+ aopPut (AOP (IC_RESULT (ic)), buffer, GPTRSIZE - 1);
+ }
}
#endif
/*-----------------------------------------------------------------*/
/* genPlus - generates code for addition */
/*-----------------------------------------------------------------*/
-static void genPlus (iCode *ic)
+static void
+genPlus (iCode * ic)
{
- int size, offset = 0;
+ int size, offset = 0;
- /* special cases :- */
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* special cases :- */
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* if literal, literal on the right or
- if left requires ACC or right is already
- in ACC */
+ /* if literal, literal on the right or
+ if left requires ACC or right is already
+ in ACC */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) {
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_LIT)
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
}
- /* if both left & right are in bit space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- genPlusBits (ic);
- goto release ;
+ /* if both left & right are in bit space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ genPlusBits (ic);
+ goto release;
}
- /* if left in bit space & right literal */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
- /* if result in bit space */
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- if((unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit) != 0L) {
- emitcode("movlw","(1 << (%s & 7)) ;%d",AOP(IC_RESULT(ic))->aopu.aop_dir,__LINE__);
- if (!sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_LEFT(ic))->aopu.aop_dir,
- AOP(IC_LEFT(ic))->aopu.aop_dir);
-
- emitcode("xorwf","(%s>>3),f",AOP(IC_RESULT(ic))->aopu.aop_dir);
- }
- } else {
- size = getDataSize(IC_RESULT(ic));
- while (size--) {
- MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitcode("addc","a,#00 ;%d",__LINE__);
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
- }
- }
- goto release ;
+ /* if left in bit space & right literal */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT)
+ {
+ /* if result in bit space */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ if ((unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) != 0L)
+ {
+ emitcode ("movlw", "(1 << (%s & 7)) ;%d", AOP (IC_RESULT (ic))->aopu.aop_dir, __LINE__);
+ if (!sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_LEFT (ic))->aopu.aop_dir,
+ AOP (IC_LEFT (ic))->aopu.aop_dir);
+
+ emitcode ("xorwf", "(%s>>3),f", AOP (IC_RESULT (ic))->aopu.aop_dir);
+ }
+ }
+ else
+ {
+ size = getDataSize (IC_RESULT (ic));
+ while (size--)
+ {
+ MOVA (aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ emitcode ("addc", "a,#00 ;%d", __LINE__);
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
+ }
+ }
+ goto release;
}
- /* if I can do an increment instead
- of add then GOOD for ME */
- if (genPlusIncr (ic) == TRUE)
- goto release;
+ /* if I can do an increment instead
+ of add then GOOD for ME */
+ if (genPlusIncr (ic) == TRUE)
+ goto release;
- size = getDataSize(IC_RESULT(ic));
+ size = getDataSize (IC_RESULT (ic));
- if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
+ if (AOP (IC_RIGHT (ic))->type == AOP_LIT)
+ {
/* Add a literal to something else */
- bool know_W=0;
- unsigned lit = floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- unsigned l1=0;
+ bool know_W = 0;
+ unsigned lit = floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ unsigned l1 = 0;
offset = 0;
- DEBUGemitcode(";","adding lit to something. size %d",size);
- while(size--){
-
- DEBUGemitcode(";","size %d",size);
-
- switch (lit & 0xff) {
- case 0:
- break;
- case 1:
- if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
- emitcode("incf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- else {
- know_W = 0;
- emitcode("incf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- }
- break;
- case 0xff:
- if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
- emitcode("decf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- else {
- know_W = 0;
- emitcode("decf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- }
- break;
- default:
- if( !know_W || ( (lit&0xff) != l1) ) {
- know_W = 1;
- emitcode("movlw","0x%x", lit&0xff);
- }
- if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- else {
- know_W = 0;
- emitcode("addwf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- if(size) {
- emitSKPNC;
- emitcode("incf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset+1,FALSE,FALSE));
- }
- }
- }
-
- l1 = lit & 0xff;
- lit >>= 8;
- offset++;
- }
-
- } else if(AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
+ DEBUGemitcode (";", "adding lit to something. size %d", size);
+ while (size--)
+ {
+
+ DEBUGemitcode (";", "size %d", size);
+
+ switch (lit & 0xff)
+ {
+ case 0:
+ break;
+ case 1:
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ emitcode ("incf", "%s,f", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ else
+ {
+ know_W = 0;
+ emitcode ("incf", "%s,w", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) != AOP_ACC)
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), offset, FALSE, FALSE));
+ }
+ break;
+ case 0xff:
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ emitcode ("decf", "%s,f", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ else
+ {
+ know_W = 0;
+ emitcode ("decf", "%s,w", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) != AOP_ACC)
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), offset, FALSE, FALSE));
+ }
+ break;
+ default:
+ if (!know_W || ((lit & 0xff) != l1))
+ {
+ know_W = 1;
+ emitcode ("movlw", "0x%x", lit & 0xff);
+ }
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ else
+ {
+ know_W = 0;
+ emitcode ("addwf", "%s,w", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), offset, FALSE, FALSE));
+ if (size)
+ {
+ emitSKPNC;
+ emitcode ("incf", "%s,f", aopGet (AOP (IC_LEFT (ic)), offset + 1, FALSE, FALSE));
+ }
+ }
+ }
+
+ l1 = lit & 0xff;
+ lit >>= 8;
+ offset++;
+ }
+
+ }
+ else if (AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
- emitcode(";bitadd","right is bit: %s",aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitcode(";bitadd","left is bit: %s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode(";bitadd","result is bit: %s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+ emitcode (";bitadd", "right is bit: %s", aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE));
+ emitcode (";bitadd", "left is bit: %s", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ emitcode (";bitadd", "result is bit: %s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
/* here we are adding a bit to a char or int */
- if(size == 1) {
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
-
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- } else {
-
- if(AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" xorlw","1");
- } else {
- emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- }
-
- if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
-
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
- emitcode("andlw","1");
- emitcode("bcf","(%s >> 3), (%s & 7)",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
- emitSKPZ;
- emitcode("bsf","(%s >> 3), (%s & 7)",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
-
- } else
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- }
- }
-
- } else {
- int offset = 1;
+ if (size == 1)
+ {
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
+
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (ic))->aopu.aop_dir,
+ AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode (" incf", "%s,f", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ }
+ else
+ {
+
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC)
+ {
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (ic))->aopu.aop_dir,
+ AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode (" xorlw", "1");
+ }
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (ic))->aopu.aop_dir,
+ AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode (" incf", "%s,w", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ }
+
+ if (AOP_TYPE (IC_RESULT (ic)) != AOP_ACC)
+ {
+
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ emitcode ("andlw", "1");
+ emitcode ("bcf", "(%s >> 3), (%s & 7)",
+ AOP (IC_RESULT (ic))->aopu.aop_dir,
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
+ emitSKPZ;
+ emitcode ("bsf", "(%s >> 3), (%s & 7)",
+ AOP (IC_RESULT (ic))->aopu.aop_dir,
+ AOP (IC_RESULT (ic))->aopu.aop_dir);
+
+ }
+ else
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ }
+ }
+
+ }
+ else
+ {
+ int offset = 1;
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
- emitcode("clrz","");
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
+ emitcode ("clrz", "");
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (ic))->aopu.aop_dir,
+ AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode (" incf", "%s,f", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
- } else {
+ }
+ else
+ {
- emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (ic))->aopu.aop_dir,
+ AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode (" incf", "%s,w", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
- }
+ }
- while(--size){
- emitSKPZ;
- emitcode(" incf","%s,f", aopGet(AOP(IC_RIGHT(ic)),offset++,FALSE,FALSE));
- }
+ while (--size)
+ {
+ emitSKPZ;
+ emitcode (" incf", "%s,f", aopGet (AOP (IC_RIGHT (ic)), offset++, FALSE, FALSE));
+ }
- }
+ }
- } else {
-
- if(strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a") == 0 ) {
- emitcode("addwf","%s,w", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- } else {
- //if ( (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) || (AOP_TYPE(IC_RESULT(ic)) == AOP_ACC) )
- if ( AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
- emitcode("addwf","%s,w", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- } else {
-
- emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
-
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- else {
- if( (AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) ||
- (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ) {
- emitcode("addlw","%s", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- } else {
- emitcode("addwf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- }
}
- }
- }
+ else
+ {
+
+ if (strcmp (aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE), "a") == 0)
+ {
+ emitcode ("addwf", "%s,w", aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE));
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ }
+ else
+ {
+ //if ( (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) || (AOP_TYPE(IC_RESULT(ic)) == AOP_ACC) )
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC)
+ {
+ emitcode ("addwf", "%s,w", aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) != AOP_ACC)
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ }
+ else
+ {
+
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE));
+
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ else
+ {
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_IMMD) ||
+ (AOP_TYPE (IC_LEFT (ic)) == AOP_LIT))
+ {
+ emitcode ("addlw", "%s", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ }
+ else
+ {
+ emitcode ("addwf", "%s,w", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ if (AOP_TYPE (IC_RESULT (ic)) != AOP_ACC)
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ }
+ }
+ }
+ }
offset = 1;
size--;
- while(size--){
- if (!sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
- emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- }
- emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitSKPNC;
- emitcode("incfsz","%s,w",aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitcode("addwf","%s,f", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
+ while (size--)
+ {
+ if (!sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), offset, FALSE, FALSE));
+ }
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ emitSKPNC;
+ emitcode ("incfsz", "%s,w", aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_RESULT (ic)), offset, FALSE, FALSE));
- }
+ }
}
- //adjustArithmeticResult(ic);
+ //adjustArithmeticResult(ic);
- release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+release:
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMinusDec :- does subtraction with decrement if possible */
/*-----------------------------------------------------------------*/
-static bool genMinusDec (iCode *ic)
-{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
-
- DEBUGemitcode ("; lit val","%d",(unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
-
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
- return FALSE ;
-
- /* if decrement 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) &&
- (icount == 1)) {
-
- if(size == 2) {
- emitcode("decf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
- emitcode("incfsz","%s,w",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
- emitcode(" decf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
- } else {
- /* size is 3 or 4 */
- emitcode("movlw","0xff");
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
-
- emitSKPNC;
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
- emitSKPNC;
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
-
- if(size > 3) {
- emitcode("skpnc","");
- emitSKPNC;
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
- }
+static bool
+genMinusDec (iCode * ic)
+{
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* will try to generate an increment */
+ /* if the right side is not a literal
+ we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
+
+ DEBUGemitcode ("; lit val", "%d", (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit));
+
+ /* if the literal value of the right hand side
+ is greater than 4 then it is not worth it */
+ if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 2)
+ return FALSE;
+
+ /* if decrement 16 bits in register */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (size > 1) &&
+ (icount == 1))
+ {
+
+ if (size == 2)
+ {
+ emitcode ("decf", "%s,f", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE));
+ emitcode ("incfsz", "%s,w", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE));
+ emitcode (" decf", "%s,f", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE));
+ }
+ else
+ {
+ /* size is 3 or 4 */
+ emitcode ("movlw", "0xff");
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE));
+
+ emitSKPNC;
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE));
+ emitSKPNC;
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE));
+
+ if (size > 3)
+ {
+ emitcode ("skpnc", "");
+ emitSKPNC;
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE));
+ }
+
+ }
return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* we can if the aops of the left & result match or
- if they are in registers and the registers are the
- same */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
+ /* we can if the aops of the left & result match or
+ if they are in registers and the registers are the
+ same */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
- while (icount--)
- emitcode ("decf","%s,f",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+ while (icount--)
+ emitcode ("decf", "%s,f", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
- return TRUE ;
+ return TRUE;
}
- DEBUGemitcode ("; returning"," result=%s, left=%s",
- aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
- aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- if(size==1) {
- emitcode("decf","%s,w",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("movwf","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+ DEBUGemitcode ("; returning", " result=%s, left=%s",
+ aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE),
+ aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ if (size == 1)
+ {
+ emitcode ("decf", "%s,w", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
return TRUE;
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* addSign - complete with sign */
/*-----------------------------------------------------------------*/
-static void addSign(operand *result, int offset, int sign)
+static void
+addSign (operand * result, int offset, int sign)
{
- int size = (getDataSize(result) - offset);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- 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++);
+ int size = (getDataSize (result) - offset);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ 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++);
}
}
/*-----------------------------------------------------------------*/
/* genMinusBits - generates code for subtraction of two bits */
/*-----------------------------------------------------------------*/
-static void genMinusBits (iCode *ic)
+static void
+genMinusBits (iCode * ic)
{
- symbol *lbl = newiTempLabel(NULL);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("jnb","%s,%05d_DS_",AOP(IC_RIGHT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d_DS_:",(lbl->key+100));
- outBitC(IC_RESULT(ic));
+ symbol *lbl = newiTempLabel (NULL);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
+ emitcode ("jnb", "%s,%05d_DS_", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ outBitC (IC_RESULT (ic));
}
- else{
- emitcode("mov","c,%s",AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("subb","a,acc");
- emitcode("jnb","%s,%05d_DS_",AOP(IC_LEFT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- addSign(IC_RESULT(ic), MSB16, SPEC_USIGN(getSpec(operandType(IC_RESULT(ic)))));
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (IC_RIGHT (ic))->aopu.aop_dir);
+ emitcode ("subb", "a,acc");
+ emitcode ("jnb", "%s,%05d_DS_", AOP (IC_LEFT (ic))->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("inc", "a");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ addSign (IC_RESULT (ic), MSB16, SPEC_USIGN (getSpec (operandType (IC_RESULT (ic)))));
}
}
/*-----------------------------------------------------------------*/
/* genMinus - generates code for subtraction */
/*-----------------------------------------------------------------*/
-static void genMinus (iCode *ic)
+static void
+genMinus (iCode * ic)
{
- int size, offset = 0;
- unsigned long lit = 0L;
+ int size, offset = 0;
+ unsigned long lit = 0L;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp (IC_LEFT (ic), ic, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE);
- /* special cases :- */
- /* if both left & right are in bit space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- genMinusBits (ic);
- goto release ;
+ /* special cases :- */
+ /* if both left & right are in bit space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ genMinusBits (ic);
+ goto release;
}
- /* if I can do an decrement instead
- of subtract then GOOD for ME */
- if (genMinusDec (ic) == TRUE)
- goto release;
+ /* if I can do an decrement instead
+ of subtract then GOOD for ME */
+ if (genMinusDec (ic) == TRUE)
+ goto release;
- size = getDataSize(IC_RESULT(ic));
+ size = getDataSize (IC_RESULT (ic));
- if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
+ if (AOP (IC_RIGHT (ic))->type == AOP_LIT)
+ {
/* Add a literal to something else */
- lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- lit = - (long)lit;
+ lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ lit = -(long) lit;
/* add the first byte: */
- emitcode("movlw","0x%x", lit & 0xff);
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+ emitcode ("movlw", "0x%x", lit & 0xff);
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
offset = 1;
size--;
- while(size--){
+ while (size--)
+ {
- emitcode("rlf","_known_zero,w");
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+ emitcode ("rlf", "_known_zero,w");
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
- lit >>= 8;
- if(lit & 0xff) {
- emitcode("movlw","0x%x", lit & 0xff);
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+ lit >>= 8;
+ if (lit & 0xff)
+ {
+ emitcode ("movlw", "0x%x", lit & 0xff);
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
- }
- offset++;
- }
+ }
+ offset++;
+ }
- } else {
+ }
+ else
+ {
- emitcode("movf","%s", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitcode("subwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+ emitcode ("movf", "%s", aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE));
+ emitcode ("subwf", "%s,f", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE));
offset = 1;
size--;
- while(size--){
- emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitSKPNC;
- emitcode("incfsz","%s,w",aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitcode("subwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+ while (size--)
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ emitSKPNC;
+ emitcode ("incfsz", "%s,w", aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE));
+ emitcode ("subwf", "%s,f", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE));
- }
+ }
}
- // adjustArithmeticResult(ic);
+ // adjustArithmeticResult(ic);
release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_LEFT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RIGHT (ic), NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genMultbits :- multiplication of bits */
/*-----------------------------------------------------------------*/
-static void genMultbits (operand *left,
- operand *right,
- operand *result)
+static void
+genMultbits (operand * left,
+ operand * right,
+ operand * result)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
}
/*-----------------------------------------------------------------*/
/* genMultOneByte : 8 bit multiplication & division */
/*-----------------------------------------------------------------*/
-static void genMultOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* (if two literals, the value is computed before) */
- /* if one literal, literal on the right */
- if (AOP_TYPE(left) == AOP_LIT){
- operand *t = right;
- right = left;
- left = t;
- }
-
- size = AOP_SIZE(result);
- /* signed or unsigned */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("mul","ab");
- /* if result size = 1, mul signed = mul unsigned */
- aopPut(AOP(result),"a",0);
- if (size > 1){
- if (SPEC_USIGN(opetype)){
- aopPut(AOP(result),"b",1);
- if (size > 2)
- /* for filling the MSBs */
- emitcode("clr","a");
- }
- else{
- emitcode("mov","a,b");
-
- /* adjust the MSB if left or right neg */
-
- /* if one literal */
- if (AOP_TYPE(right) == AOP_LIT){
- /* AND literal negative */
- if((int) floatFromVal (AOP(right)->aopu.aop_lit) < 0){
- /* adjust MSB (c==0 after mul) */
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
- }
- }
- else{
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d_DS_", (lbl->key+100));
- emitcode("","%05d_DS_:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d_DS_",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("","%05d_DS_:",(lbl->key+100));
- }
-
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d_DS_", (lbl->key+100));
- emitcode("","%05d_DS_:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d_DS_",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("","%05d_DS_:",(lbl->key+100));
-
- aopPut(AOP(result),"a",1);
- if(size > 2){
- /* get the sign */
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- }
- }
- size -= 2;
- offset = 2;
- if (size > 0)
- while (size--)
- aopPut(AOP(result),"a",offset++);
+static void
+genMultOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+ int size, offset;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* (if two literals, the value is computed before) */
+ /* if one literal, literal on the right */
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
+
+ size = AOP_SIZE (result);
+ /* signed or unsigned */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("mul", "ab");
+ /* if result size = 1, mul signed = mul unsigned */
+ aopPut (AOP (result), "a", 0);
+ if (size > 1)
+ {
+ if (SPEC_USIGN (opetype))
+ {
+ aopPut (AOP (result), "b", 1);
+ if (size > 2)
+ /* for filling the MSBs */
+ emitcode ("clr", "a");
+ }
+ else
+ {
+ emitcode ("mov", "a,b");
+
+ /* adjust the MSB if left or right neg */
+
+ /* if one literal */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ /* AND literal negative */
+ if ((int) floatFromVal (AOP (right)->aopu.aop_lit) < 0)
+ {
+ /* adjust MSB (c==0 after mul) */
+ emitcode ("subb", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ }
+ }
+ else
+ {
+ lbl = newiTempLabel (NULL);
+ emitcode ("xch", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("cjne", "a,#0x80,%05d_DS_", (lbl->key + 100));
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ emitcode ("xch", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ lbl = newiTempLabel (NULL);
+ emitcode ("jc", "%05d_DS_", (lbl->key + 100));
+ emitcode ("subb", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ }
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("xch", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("cjne", "a,#0x80,%05d_DS_", (lbl->key + 100));
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ lbl = newiTempLabel (NULL);
+ emitcode ("jc", "%05d_DS_", (lbl->key + 100));
+ emitcode ("subb", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+
+ aopPut (AOP (result), "a", 1);
+ if (size > 2)
+ {
+ /* get the sign */
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ }
+ }
+ size -= 2;
+ offset = 2;
+ if (size > 0)
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
}
}
/*-----------------------------------------------------------------*/
/* genMult - generates code for multiplication */
/*-----------------------------------------------------------------*/
-static void genMult (iCode *ic)
+static void
+genMult (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genMultbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genMultbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genMultOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genMultOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1) ;
+ /* should have been converted to function call */
+ assert (1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDivbits :- division of bits */
/*-----------------------------------------------------------------*/
-static void genDivbits (operand *left,
- operand *right,
- operand *result)
+static void
+genDivbits (operand * left,
+ operand * right,
+ operand * result)
{
- char *l;
+ char *l;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* the result must be bit */
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* the result must be bit */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
- MOVA(l);
+ MOVA (l);
- emitcode("div","ab");
- emitcode("rrc","a");
- aopPut(AOP(result),"c",0);
+ emitcode ("div", "ab");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "c", 0);
}
/*-----------------------------------------------------------------*/
/* genDivOneByte : 8 bit division */
/*-----------------------------------------------------------------*/
-static void genDivOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- size = AOP_SIZE(result) - 1;
- offset = 1;
- /* signed or unsigned */
- if (SPEC_USIGN(opetype)) {
- /* unsigned is easy */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("div","ab");
- aopPut(AOP(result),"a",0);
- while (size--)
- aopPut(AOP(result),zero,offset++);
- return ;
- }
-
- /* signed is a little bit more difficult */
-
- /* save the signs of the operands */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,TRUE));
- emitcode("push","acc"); /* save it on the stack */
-
- /* now sign adjust for both left & right */
- l = aopGet(AOP(right),0,FALSE,FALSE);
- MOVA(l);
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));
- emitcode("mov","b,a");
-
- /* sign adjust left side */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));
-
- /* now the division */
- emitcode("div","ab");
- /* we are interested in the lower order
- only */
- emitcode("mov","b,a");
- lbl = newiTempLabel(NULL);
- emitcode("pop","acc");
- /* if there was an over flow we don't
- adjust the sign of the result */
- emitcode("jb","ov,%05d_DS_",(lbl->key+100));
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- CLRC;
- emitcode("clr","a");
- emitcode("subb","a,b");
- emitcode("mov","b,a");
- emitcode("","%05d_DS_:",(lbl->key+100));
-
- /* now we are done */
- aopPut(AOP(result),"b",0);
- if(size > 0){
- emitcode("mov","c,b.7");
- emitcode("subb","a,acc");
+static void
+genDivOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+ int size, offset;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ size = AOP_SIZE (result) - 1;
+ offset = 1;
+ /* signed or unsigned */
+ if (SPEC_USIGN (opetype))
+ {
+ /* unsigned is easy */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("div", "ab");
+ aopPut (AOP (result), "a", 0);
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ return;
}
- while (size--)
- aopPut(AOP(result),"a",offset++);
+
+ /* signed is a little bit more difficult */
+
+ /* save the signs of the operands */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), 0, FALSE, TRUE));
+ emitcode ("push", "acc"); /* save it on the stack */
+
+ /* now sign adjust for both left & right */
+ l = aopGet (AOP (right), 0, FALSE, FALSE);
+ MOVA (l);
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d_DS_", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ emitcode ("mov", "b,a");
+
+ /* sign adjust left side */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d_DS_", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+
+ /* now the division */
+ emitcode ("div", "ab");
+ /* we are interested in the lower order
+ only */
+ emitcode ("mov", "b,a");
+ lbl = newiTempLabel (NULL);
+ emitcode ("pop", "acc");
+ /* if there was an over flow we don't
+ adjust the sign of the result */
+ emitcode ("jb", "ov,%05d_DS_", (lbl->key + 100));
+ emitcode ("jnb", "acc.7,%05d_DS_", (lbl->key + 100));
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,b");
+ emitcode ("mov", "b,a");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+
+ /* now we are done */
+ aopPut (AOP (result), "b", 0);
+ if (size > 0)
+ {
+ emitcode ("mov", "c,b.7");
+ emitcode ("subb", "a,acc");
+ }
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
}
/*-----------------------------------------------------------------*/
/* genDiv - generates code for division */
/*-----------------------------------------------------------------*/
-static void genDiv (iCode *ic)
+static void
+genDiv (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genDivbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genDivbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genDivOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genDivOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ /* should have been converted to function call */
+ assert (1);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genModbits :- modulus of bits */
/*-----------------------------------------------------------------*/
-static void genModbits (operand *left,
- operand *right,
- operand *result)
+static void
+genModbits (operand * left,
+ operand * right,
+ operand * result)
{
- char *l;
+ char *l;
- /* the result must be bit */
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
+ /* the result must be bit */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
- MOVA(l);
+ MOVA (l);
- emitcode("div","ab");
- emitcode("mov","a,b");
- emitcode("rrc","a");
- aopPut(AOP(result),"c",0);
+ emitcode ("div", "ab");
+ emitcode ("mov", "a,b");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "c", 0);
}
/*-----------------------------------------------------------------*/
/* genModOneByte : 8 bit modulus */
/*-----------------------------------------------------------------*/
-static void genModOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* signed or unsigned */
- if (SPEC_USIGN(opetype)) {
- /* unsigned is easy */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("div","ab");
- aopPut(AOP(result),"b",0);
- return ;
- }
-
- /* signed is a little bit more difficult */
-
- /* save the signs of the operands */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
-
- emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("push","acc"); /* save it on the stack */
-
- /* now sign adjust for both left & right */
- l = aopGet(AOP(right),0,FALSE,FALSE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));
- emitcode("mov","b,a");
-
- /* sign adjust left side */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));
-
- /* now the multiplication */
- emitcode("div","ab");
- /* we are interested in the lower order
- only */
- lbl = newiTempLabel(NULL);
- emitcode("pop","acc");
- /* if there was an over flow we don't
- adjust the sign of the result */
- emitcode("jb","ov,%05d_DS_",(lbl->key+100));
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- CLRC ;
- emitcode("clr","a");
- emitcode("subb","a,b");
- emitcode("mov","b,a");
- emitcode("","%05d_DS_:",(lbl->key+100));
-
- /* now we are done */
- aopPut(AOP(result),"b",0);
+static void
+genModOneByte (operand * left,
+ operand * right,
+ operand * result)
+{
+ sym_link *opetype = operandType (result);
+ char *l;
+ symbol *lbl;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* signed or unsigned */
+ if (SPEC_USIGN (opetype))
+ {
+ /* unsigned is easy */
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("div", "ab");
+ aopPut (AOP (result), "b", 0);
+ return;
+ }
+
+ /* signed is a little bit more difficult */
+
+ /* save the signs of the operands */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("push", "acc"); /* save it on the stack */
+
+ /* now sign adjust for both left & right */
+ l = aopGet (AOP (right), 0, FALSE, FALSE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d_DS_", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ emitcode ("mov", "b,a");
+
+ /* sign adjust left side */
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,%05d_DS_", (lbl->key + 100));
+ emitcode ("cpl", "a");
+ emitcode ("inc", "a");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+
+ /* now the multiplication */
+ emitcode ("div", "ab");
+ /* we are interested in the lower order
+ only */
+ lbl = newiTempLabel (NULL);
+ emitcode ("pop", "acc");
+ /* if there was an over flow we don't
+ adjust the sign of the result */
+ emitcode ("jb", "ov,%05d_DS_", (lbl->key + 100));
+ emitcode ("jnb", "acc.7,%05d_DS_", (lbl->key + 100));
+ CLRC;
+ emitcode ("clr", "a");
+ emitcode ("subb", "a,b");
+ emitcode ("mov", "b,a");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+
+ /* now we are done */
+ aopPut (AOP (result), "b", 0);
}
/*-----------------------------------------------------------------*/
/* genMod - generates code for division */
/*-----------------------------------------------------------------*/
-static void genMod (iCode *ic)
+static void
+genMod (iCode * ic)
{
- operand *left = IC_LEFT(ic);
- operand *right = IC_RIGHT(ic);
- operand *result= IC_RESULT(ic);
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genModbits(left,right,result);
- goto release ;
+ /* special cases first */
+ /* both are bits */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ genModbits (left, right, result);
+ goto release;
}
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genModOneByte(left,right,result);
- goto release ;
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genModOneByte (left, right, result);
+ goto release;
}
- /* should have been converted to function call */
- assert(1);
+ /* should have been converted to function call */
+ assert (1);
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genIfxJump :- will create a jump depending on the ifx */
/*-----------------------------------------------------------------*/
-static void genIfxJump (iCode *ic, char *jval)
+static void
+genIfxJump (iCode * ic, char *jval)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if true label then we jump if condition
- supplied is true */
- if ( IC_TRUE(ic) ) {
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if true label then we jump if condition
+ supplied is true */
+ if (IC_TRUE (ic))
+ {
- if(strcmp(jval,"a") == 0)
- emitSKPZ;
- else if (strcmp(jval,"c") == 0)
- emitSKPC;
- else
- emitcode("btfsc","(%s >> 3),(%s & 7)",jval,jval);
+ if (strcmp (jval, "a") == 0)
+ emitSKPZ;
+ else if (strcmp (jval, "c") == 0)
+ emitSKPC;
+ else
+ emitcode ("btfsc", "(%s >> 3),(%s & 7)", jval, jval);
- emitcode(" goto","_%05d_DS_",IC_TRUE(ic)->key+100 + labelOffset);
+ emitcode (" goto", "_%05d_DS_", IC_TRUE (ic)->key + 100 + labelOffset);
}
- else {
- /* false label is present */
- if(strcmp(jval,"a") == 0)
- emitSKPNZ;
- else if (strcmp(jval,"c") == 0)
- emitSKPNC;
else
- emitcode("btfss","(%s >> 3),(%s & 7)",jval,jval);
+ {
+ /* false label is present */
+ if (strcmp (jval, "a") == 0)
+ emitSKPNZ;
+ else if (strcmp (jval, "c") == 0)
+ emitSKPNC;
+ else
+ emitcode ("btfss", "(%s >> 3),(%s & 7)", jval, jval);
- emitcode(" goto","_%05d_DS_",IC_FALSE(ic)->key+100 + labelOffset);
+ emitcode (" goto", "_%05d_DS_", IC_FALSE (ic)->key + 100 + labelOffset);
}
- /* mark the icode as generated */
- ic->generated = 1;
+ /* mark the icode as generated */
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genSkip */
/*-----------------------------------------------------------------*/
-static void genSkip(iCode *ifx,int status_bit)
+static void
+genSkip (iCode * ifx, int status_bit)
{
- if(!ifx)
+ if (!ifx)
return;
- if ( IC_TRUE(ifx) ) {
- switch(status_bit) {
- case 'z':
- emitSKPNZ;
- break;
+ if (IC_TRUE (ifx))
+ {
+ switch (status_bit)
+ {
+ case 'z':
+ emitSKPNZ;
+ break;
- case 'c':
- emitSKPNC;
- break;
+ case 'c':
+ emitSKPNC;
+ break;
- case 'd':
- emitcode("skpndc","");
- break;
+ case 'd':
+ emitcode ("skpndc", "");
+ break;
- }
+ }
- emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
+ emitcode ("goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
- } else {
+ }
+ else
+ {
- switch(status_bit) {
+ switch (status_bit)
+ {
- case 'z':
- emitSKPZ;
- break;
+ case 'z':
+ emitSKPZ;
+ break;
- case 'c':
- emitSKPC;
- break;
+ case 'c':
+ emitSKPC;
+ break;
- case 'd':
- emitcode("skpdc","");
- break;
- }
- emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
+ case 'd':
+ emitcode ("skpdc", "");
+ break;
+ }
+ emitcode ("goto", "_%05d_DS_", IC_FALSE (ifx)->key + 100 + labelOffset);
- }
+ }
}
/*-----------------------------------------------------------------*/
/* genSkipc */
/*-----------------------------------------------------------------*/
-static void genSkipc(iCode *ifx, int condition)
+static void
+genSkipc (iCode * ifx, int condition)
{
- if(!ifx)
+ if (!ifx)
return;
- if(condition)
+ if (condition)
emitSKPNC;
else
emitSKPC;
- if ( IC_TRUE(ifx) )
- emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
+ if (IC_TRUE (ifx))
+ emitcode ("goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
else
- emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
+ emitcode ("goto", "_%05d_DS_", IC_FALSE (ifx)->key + 100 + labelOffset);
}
/*-----------------------------------------------------------------*/
/* genSkipz */
/*-----------------------------------------------------------------*/
-static void genSkipz(iCode *ifx, int condition)
+static void
+genSkipz (iCode * ifx, int condition)
{
- if(!ifx)
+ if (!ifx)
return;
- if(condition)
+ if (condition)
emitSKPNZ;
else
emitSKPZ;
- if ( IC_TRUE(ifx) )
- emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
+ if (IC_TRUE (ifx))
+ emitcode ("goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
else
- emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
+ emitcode ("goto", "_%05d_DS_", IC_FALSE (ifx)->key + 100 + labelOffset);
}
/*-----------------------------------------------------------------*/
/* genCmp :- greater or less than comparison */
/*-----------------------------------------------------------------*/
-static void genCmp (operand *left,operand *right,
- operand *result, iCode *ifx, int sign)
+static void
+genCmp (operand * left, operand * right,
+ operand * result, iCode * ifx, int sign)
{
- int size, offset = 0 ;
- unsigned long lit = 0L,i = 0;
+ int size, offset = 0;
+ unsigned long lit = 0L, i = 0;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
/* if left & right are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
- } else {
- /* subtract right from left if at the
- end the carry flag is set then we know that
- left is greater than right */
- size = max(AOP_SIZE(left),AOP_SIZE(right));
-
- /* if unsigned char cmp with lit, do cjne left,#right,zz */
- if((size == 1) && !sign &&
- (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
- symbol *lbl = newiTempLabel(NULL);
- emitcode("cjne","%s,%s,%05d_DS_",
- aopGet(AOP(left),offset,FALSE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE),
- lbl->key+100);
- emitcode("","%05d_DS_:",lbl->key+100);
- } else {
-
- if(AOP_TYPE(right) == AOP_LIT) {
-
- DEBUGemitcode(";right lit","%d",sign);
-
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- //default:
- while(size--) {
- i = (lit >> (size*8)) & 0xff;
- if(i == 0) {
- emitcode("movf","%s,w",aopGet(AOP(left),size,FALSE,FALSE));
- genSkipz(ifx,IC_TRUE(ifx) == NULL);
- } else {
- emitcode("movlw","0x%x",i);
- emitcode("subwf","%s,w",aopGet(AOP(left),size,FALSE,FALSE));
- genSkipc(ifx,IC_TRUE(ifx) == NULL);
- }
-
- }
- ifx->generated = 1;
- return;
- }
- if(AOP_TYPE(left) == AOP_LIT) {
-
- DEBUGemitcode(";left lit","%d",sign);
-
- lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit))+1;
-
- //default:
- while(size--) {
- i = (lit >> (size*8)) & 0xff;
- if(i == 0) {
- emitcode("movf","%s,w",aopGet(AOP(right),size,FALSE,FALSE));
- genSkipz(ifx,IC_TRUE(ifx) != NULL);
- } else if( i == 1 ) {
- emitcode("decf","%s,w",aopGet(AOP(right),size,FALSE,FALSE));
- genSkipz(ifx,IC_TRUE(ifx) != NULL);
-
- } else {
- emitcode("movlw","0x%x",i);
- emitcode("subwf","%s,w",aopGet(AOP(right),size,FALSE,FALSE));
- genSkipc(ifx,IC_TRUE(ifx) != NULL);
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("anl", "c,/%s", AOP (left)->aopu.aop_dir);
}
- }
- ifx->generated = 1;
- return;
- }
-
-
- // CLRC;
- DEBUGemitcode(";sign","%d",sign);
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("subwf","%s,w",aopGet(AOP(left),offset++,FALSE,FALSE));
- size--;
- while (size--) {
-
- /*if (AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)
- floatFromVal(AOP(right)->aopu.aop_lit);
- emitcode("subb","a,#0x%02x",
- 0x80 ^ (unsigned int)((lit >> (offset*8)) & 0x0FFL));
- } else {
- emitcode("mov","b,%s",aopGet(AOP(right),offset++,FALSE,FALSE));
- emitcode("xrl","b,#0x80");
- emitcode("subb","a,b");
- }
- } else
- emitcode("subb","a,%s",aopGet(AOP(right),offset++,FALSE,FALSE));
- */
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitSKPC;
- emitcode("incfsz","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("subwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- offset++;
- }
+ else
+ {
+ /* subtract right from left if at the
+ end the carry flag is set then we know that
+ left is greater than right */
+ size = max (AOP_SIZE (left), AOP_SIZE (right));
+
+ /* if unsigned char cmp with lit, do cjne left,#right,zz */
+ if ((size == 1) && !sign &&
+ (AOP_TYPE (right) == AOP_LIT && AOP_TYPE (left) != AOP_DIR))
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("cjne", "%s,%s,%05d_DS_",
+ aopGet (AOP (left), offset, FALSE, FALSE),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ lbl->key + 100);
+ emitcode ("", "%05d_DS_:", lbl->key + 100);
+ }
+ else
+ {
+
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+
+ DEBUGemitcode (";right lit", "%d", sign);
+
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ //default:
+ while (size--)
+ {
+ i = (lit >> (size * 8)) & 0xff;
+ if (i == 0)
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (left), size, FALSE, FALSE));
+ genSkipz (ifx, IC_TRUE (ifx) == NULL);
+ }
+ else
+ {
+ emitcode ("movlw", "0x%x", i);
+ emitcode ("subwf", "%s,w", aopGet (AOP (left), size, FALSE, FALSE));
+ genSkipc (ifx, IC_TRUE (ifx) == NULL);
+ }
+
+ }
+ ifx->generated = 1;
+ return;
+ }
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+
+ DEBUGemitcode (";left lit", "%d", sign);
+
+ lit = (unsigned long) (floatFromVal (AOP (left)->aopu.aop_lit)) + 1;
+
+ //default:
+ while (size--)
+ {
+ i = (lit >> (size * 8)) & 0xff;
+ if (i == 0)
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (right), size, FALSE, FALSE));
+ genSkipz (ifx, IC_TRUE (ifx) != NULL);
+ }
+ else if (i == 1)
+ {
+ emitcode ("decf", "%s,w", aopGet (AOP (right), size, FALSE, FALSE));
+ genSkipz (ifx, IC_TRUE (ifx) != NULL);
+
+ }
+ else
+ {
+ emitcode ("movlw", "0x%x", i);
+ emitcode ("subwf", "%s,w", aopGet (AOP (right), size, FALSE, FALSE));
+ genSkipc (ifx, IC_TRUE (ifx) != NULL);
+ }
+ }
+ ifx->generated = 1;
+ return;
+ }
+
+
+ // CLRC;
+ DEBUGemitcode (";sign", "%d", sign);
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("subwf", "%s,w", aopGet (AOP (left), offset++, FALSE, FALSE));
+ size--;
+ while (size--)
+ {
+
+ /*if (AOP_TYPE(right) == AOP_LIT){
+ unsigned long lit = (unsigned long)
+ floatFromVal(AOP(right)->aopu.aop_lit);
+ emitcode("subb","a,#0x%02x",
+ 0x80 ^ (unsigned int)((lit >> (offset*8)) & 0x0FFL));
+ } else {
+ emitcode("mov","b,%s",aopGet(AOP(right),offset++,FALSE,FALSE));
+ emitcode("xrl","b,#0x80");
+ emitcode("subb","a,b");
+ }
+ } else
+ emitcode("subb","a,%s",aopGet(AOP(right),offset++,FALSE,FALSE));
+ */
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitSKPC;
+ emitcode ("incfsz", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("subwf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ offset++;
+ }
+ }
}
- }
//release:
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- outBitC(result);
- } else {
- /* if the result is used in the next
- ifx conditional branch then generate
- code a little differently */
- if (ifx )
- genIfxJump (ifx,"c");
- else
- outBitC(result);
- /* leave the result in acc */
- }
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ outBitC (result);
+ }
+ else
+ {
+ /* if the result is used in the next
+ ifx conditional branch then generate
+ code a little differently */
+ if (ifx)
+ genIfxJump (ifx, "c");
+ else
+ outBitC (result);
+ /* leave the result in acc */
+ }
}
/*-----------------------------------------------------------------*/
/* genCmpGt :- greater than comparison */
/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
+static void
+genCmpGt (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
+ operand *left, *right, *result;
+ sym_link *letype, *retype;
+ int sign;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- genCmp(right, left, result, ifx, sign);
+ genCmp (right, left, result, ifx, sign);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genCmpLt - less than comparisons */
/*-----------------------------------------------------------------*/
-static void genCmpLt (iCode *ic, iCode *ifx)
+static void
+genCmpLt (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
+ operand *left, *right, *result;
+ sym_link *letype, *retype;
+ int sign;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
- genCmp(left, right, result, ifx, sign);
+ genCmp (left, right, result, ifx, sign);
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* gencjneshort - compare and jump if not equal */
/*-----------------------------------------------------------------*/
-static void gencjneshort(operand *left, operand *right, symbol *lbl)
-{
- int size = max(AOP_SIZE(left),AOP_SIZE(right));
- int offset = 0;
- unsigned long lit = 0L;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if the left side is a literal or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(left) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *t = right;
- right = left;
- left = t;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- /* if the right side is a literal then anything goes */
- if (AOP_TYPE(right) == AOP_LIT &&
- AOP_TYPE(left) != AOP_DIR ) {
- while (size--) {
- if(lit & 0xff) {
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("xorlw","0x%x",lit & 0xff);
- } else
- emitcode("movf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
+static void
+gencjneshort (operand * left, operand * right, symbol * lbl)
+{
+ int size = max (AOP_SIZE (left), AOP_SIZE (right));
+ int offset = 0;
+ unsigned long lit = 0L;
- emitSKPNZ;
- emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
- offset++;
- lit >>= 8;
- }
- }
-
- /* if the right side is in a register or in direct space or
- if the left is a pointer register & right is not */
- else if (AOP_TYPE(right) == AOP_REG ||
- AOP_TYPE(right) == AOP_DIR ||
- (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) ||
- (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) {
- while (size--) {
- if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
- ( (lit & 0xff) != 0)) {
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("xorlw","0x%x",lit & 0xff);
- lit >>= 8;
- } else
- emitcode("movf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if the left side is a literal or
+ if the right is in a pointer register and left
+ is not */
+ if ((AOP_TYPE (left) == AOP_LIT) ||
+ (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
+ {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
- emitSKPZ;
- emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
- offset++;
+ /* if the right side is a literal then anything goes */
+ if (AOP_TYPE (right) == AOP_LIT &&
+ AOP_TYPE (left) != AOP_DIR)
+ {
+ while (size--)
+ {
+ if (lit & 0xff)
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("xorlw", "0x%x", lit & 0xff);
+ }
+ else
+ emitcode ("movf", "%s,f", aopGet (AOP (left), offset, FALSE, FALSE));
+
+ emitSKPNZ;
+ emitcode ("goto", "_%05d_DS_", lbl->key + 100 + labelOffset);
+ offset++;
+ lit >>= 8;
+ }
+ }
+
+ /* if the right side is in a register or in direct space or
+ if the left is a pointer register & right is not */
+ else if (AOP_TYPE (right) == AOP_REG ||
+ AOP_TYPE (right) == AOP_DIR ||
+ (AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) ||
+ (IS_AOP_PREG (left) && !IS_AOP_PREG (right)))
+ {
+ while (size--)
+ {
+ if ((AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) &&
+ ((lit & 0xff) != 0))
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("xorlw", "0x%x", lit & 0xff);
+ lit >>= 8;
+ }
+ else
+ emitcode ("movf", "%s,f", aopGet (AOP (left), offset, FALSE, FALSE));
+
+ emitSKPZ;
+ emitcode ("goto", "_%05d_DS_", lbl->key + 100 + labelOffset);
+ offset++;
/*
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
- if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
- ((unsigned int)((lit >> (offset*8)) & 0x0FFL) == 0))
- emitcode("jnz","%05d_DS_",lbl->key+100);
- else
- emitcode("cjne","a,%s,%05d_DS_",
- aopGet(AOP(right),offset,FALSE,TRUE),
- lbl->key+100);
- offset++;
-*/
- }
- } else {
- /* right is a pointer reg need both a & b */
- while(size--) {
- char *l = aopGet(AOP(left),offset,FALSE,FALSE);
- if(strcmp(l,"b"))
- emitcode("mov","b,%s",l);
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("cjne","a,b,%05d_DS_",lbl->key+100);
- offset++;
- }
+ MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
+ if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
+ ((unsigned int)((lit >> (offset*8)) & 0x0FFL) == 0))
+ emitcode("jnz","%05d_DS_",lbl->key+100);
+ else
+ emitcode("cjne","a,%s,%05d_DS_",
+ aopGet(AOP(right),offset,FALSE,TRUE),
+ lbl->key+100);
+ offset++;
+ */
+ }
+ }
+ else
+ {
+ /* right is a pointer reg need both a & b */
+ while (size--)
+ {
+ char *l = aopGet (AOP (left), offset, FALSE, FALSE);
+ if (strcmp (l, "b"))
+ emitcode ("mov", "b,%s", l);
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("cjne", "a,b,%05d_DS_", lbl->key + 100);
+ offset++;
+ }
}
}
/*-----------------------------------------------------------------*/
/* gencjne - compare and jump if not equal */
/*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, symbol *lbl)
+static void
+gencjne (operand * left, operand * right, symbol * lbl)
{
- symbol *tlbl = newiTempLabel(NULL);
+ symbol *tlbl = newiTempLabel (NULL);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- gencjneshort(left, right, lbl);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ gencjneshort (left, right, lbl);
- emitcode("mov","a,%s",one);
- emitcode("sjmp","%05d_DS_",tlbl->key+100);
- emitcode("","%05d_DS_:",lbl->key+100);
- emitcode("clr","a");
- emitcode("","%05d_DS_:",tlbl->key+100);
+ emitcode ("mov", "a,%s", one);
+ emitcode ("sjmp", "%05d_DS_", tlbl->key + 100);
+ emitcode ("", "%05d_DS_:", lbl->key + 100);
+ emitcode ("clr", "a");
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
}
/*-----------------------------------------------------------------*/
/* genCmpEq - generates code for equal to */
/*-----------------------------------------------------------------*/
-static void genCmpEq (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
- unsigned long lit = 0L;
- int size,offset=0;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(ifx)
- DEBUGemitcode ("; ifx is non-null","");
- else
- DEBUGemitcode ("; ifx is null","");
-
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
-
- size = max(AOP_SIZE(left),AOP_SIZE(right));
-
- /* if literal, literal on the right or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
- }
-
- if(ifx && !AOP_SIZE(result)){
- symbol *tlbl;
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- if(lit == 0L){
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- } else if(lit == 1L) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("jb","%s,%05d_DS_",AOP(right)->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d_DS_:",(lbl->key+100));
- }
- /* if true label then we jump if condition
- supplied is true */
- tlbl = newiTempLabel(NULL);
- if ( IC_TRUE(ifx) ) {
- emitcode("jnc","%05d_DS_",tlbl->key+100);
- emitcode("ljmp","%05d_DS_",IC_TRUE(ifx)->key+100);
- } else {
- emitcode("jc","%05d_DS_",tlbl->key+100);
- emitcode("ljmp","%05d_DS_",IC_FALSE(ifx)->key+100);
- }
- emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
- } else {
-
- /* They're not both bit variables. Is the right a literal? */
- if(AOP_TYPE(right) == AOP_LIT) {
-
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- while (size--) {
-
- if(size >= 1) {
- int l = lit & 0xff;
- int h = (lit>>8) & 0xff;
- int optimized=0;
-
- /* Check special cases for integers */
- switch(lit & 0xffff) {
- case 0x0000:
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- genSkip(ifx,'z');
- optimized++;
- break;
- case 0x0001:
- emitcode("decf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- genSkip(ifx,'z');
- optimized++;
- break;
- case 0x0100:
- emitcode("decf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- genSkip(ifx,'z');
- optimized++;
- break;
- case 0x00ff:
- emitcode("incf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- genSkip(ifx,'z');
- optimized++;
- break;
- case 0xff00:
- emitcode("incf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- genSkip(ifx,'z');
- optimized++;
- break;
- default:
- if(h == 0) {
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("xorlw","0x%x",l);
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- optimized++;
- genSkip(ifx,'z');
- } else if (l == 0) {
- emitcode("movf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- emitcode("xorlw","0x%x",h);
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- optimized++;
- genSkip(ifx,'z');
- } else {
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("xorlw","0x%x",l);
- emitcode("movlw","0x%x",h);
- emitSKPZ;
- emitcode("xorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
- optimized++;
- genSkip(ifx,'z');
- }
-
- }
- if(optimized) {
- size--;
- offset+=2;
- lit>>=16;
-
- continue;
- }
-
- }
-
- switch(lit & 0xff) {
- case 1:
- if ( IC_TRUE(ifx) ) {
- emitcode("decf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitSKPNZ;
- emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
- } else {
- emitcode("decfsz","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
- break;
- case 0xff:
- if ( IC_TRUE(ifx) ) {
- emitcode("incf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitSKPNZ;
- emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
- } else {
- emitcode("incfsz","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
- break;
- default:
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- if(lit)
- emitcode("xorlw","0x%x",lit & 0xff);
- genSkip(ifx,'z');
- }
-
-
- // emitcode("goto","_%05d_DS_",tlbl->key+100+labelOffset);
- //emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);
- offset++;
- lit >>= 8;
- }
-
- } else if(AOP_TYPE(right) == AOP_CRY ) {
- /* we know the left is not a bit, but that the right is */
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- if ( IC_TRUE(ifx) )
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- else
- emitcode("btfss","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
-
- emitcode("xorlw","1");
-
- /* if the two are equal, then W will be 0 and the Z bit is set
- * we could test Z now, or go ahead and check the high order bytes if
- * the variable we're comparing is larger than a byte. */
-
- while(--size)
- emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
+static void
+genCmpEq (iCode * ic, iCode * ifx)
+{
+ operand *left, *right, *result;
+ unsigned long lit = 0L;
+ int size, offset = 0;
- if ( IC_TRUE(ifx) ) {
- emitSKPNZ;
- emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
- } else {
- emitSKPZ;
- emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (ifx)
+ DEBUGemitcode ("; ifx is non-null", "");
+ else
+ DEBUGemitcode ("; ifx is null", "");
- } else {
- /* They're both variables that are larger than bits */
- int s = size;
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
- tlbl = newiTempLabel(NULL);
+ size = max (AOP_SIZE (left), AOP_SIZE (right));
- while(size--) {
+ /* if literal, literal on the right or
+ if the right is in a pointer register and left
+ is not */
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT) ||
+ (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
+ }
- emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("xorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
+ if (ifx && !AOP_SIZE (result))
+ {
+ symbol *tlbl;
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ if (lit == 0L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ else if (lit == 1L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("clr", "c");
+ }
+ /* AOP_TYPE(right) == AOP_CRY */
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("jb", "%s,%05d_DS_", AOP (right)->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ }
+ /* if true label then we jump if condition
+ supplied is true */
+ tlbl = newiTempLabel (NULL);
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("jnc", "%05d_DS_", tlbl->key + 100);
+ emitcode ("ljmp", "%05d_DS_", IC_TRUE (ifx)->key + 100);
+ }
+ else
+ {
+ emitcode ("jc", "%05d_DS_", tlbl->key + 100);
+ emitcode ("ljmp", "%05d_DS_", IC_FALSE (ifx)->key + 100);
+ }
+ emitcode ("", "%05d_DS_:", tlbl->key + 100 + labelOffset);
+ }
+ else
+ {
+
+ /* They're not both bit variables. Is the right a literal? */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ while (size--)
+ {
+
+ if (size >= 1)
+ {
+ int l = lit & 0xff;
+ int h = (lit >> 8) & 0xff;
+ int optimized = 0;
+
+ /* Check special cases for integers */
+ switch (lit & 0xffff)
+ {
+ case 0x0000:
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ genSkip (ifx, 'z');
+ optimized++;
+ break;
+ case 0x0001:
+ emitcode ("decf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ genSkip (ifx, 'z');
+ optimized++;
+ break;
+ case 0x0100:
+ emitcode ("decf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ genSkip (ifx, 'z');
+ optimized++;
+ break;
+ case 0x00ff:
+ emitcode ("incf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ genSkip (ifx, 'z');
+ optimized++;
+ break;
+ case 0xff00:
+ emitcode ("incf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ genSkip (ifx, 'z');
+ optimized++;
+ break;
+ default:
+ if (h == 0)
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("xorlw", "0x%x", l);
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ optimized++;
+ genSkip (ifx, 'z');
+ }
+ else if (l == 0)
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ emitcode ("xorlw", "0x%x", h);
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ optimized++;
+ genSkip (ifx, 'z');
+ }
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("xorlw", "0x%x", l);
+ emitcode ("movlw", "0x%x", h);
+ emitSKPZ;
+ emitcode ("xorwf", "%s,w", aopGet (AOP (left), offset + 1, FALSE, FALSE));
+ optimized++;
+ genSkip (ifx, 'z');
+ }
+
+ }
+ if (optimized)
+ {
+ size--;
+ offset += 2;
+ lit >>= 16;
+
+ continue;
+ }
+
+ }
+
+ switch (lit & 0xff)
+ {
+ case 1:
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("decf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitSKPNZ;
+ emitcode ("goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
+ }
+ else
+ {
+ emitcode ("decfsz", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("goto", "_%05d_DS_", IC_FALSE (ifx)->key + 100 + labelOffset);
+ }
+ break;
+ case 0xff:
+ if (IC_TRUE (ifx))
+ {
+ emitcode ("incf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitSKPNZ;
+ emitcode ("goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
+ }
+ else
+ {
+ emitcode ("incfsz", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("goto", "_%05d_DS_", IC_FALSE (ifx)->key + 100 + labelOffset);
+ }
+ break;
+ default:
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ if (lit)
+ emitcode ("xorlw", "0x%x", lit & 0xff);
+ genSkip (ifx, 'z');
+ }
+
+
+ // emitcode("goto","_%05d_DS_",tlbl->key+100+labelOffset);
+ //emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);
+ offset++;
+ lit >>= 8;
+ }
+
+ }
+ else if (AOP_TYPE (right) == AOP_CRY)
+ {
+ /* we know the left is not a bit, but that the right is */
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ if (IC_TRUE (ifx))
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ else
+ emitcode ("btfss", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+
+ emitcode ("xorlw", "1");
+
+ /* if the two are equal, then W will be 0 and the Z bit is set
+ * we could test Z now, or go ahead and check the high order bytes if
+ * the variable we're comparing is larger than a byte. */
+
+ while (--size)
+ emitcode ("iorwf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+
+ if (IC_TRUE (ifx))
+ {
+ emitSKPNZ;
+ emitcode (" goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
+ }
+ else
+ {
+ emitSKPZ;
+ emitcode (" goto", "_%05d_DS_", IC_FALSE (ifx)->key + 100 + labelOffset);
+ }
+
+ }
+ else
+ {
+ /* They're both variables that are larger than bits */
+ int s = size;
+
+ tlbl = newiTempLabel (NULL);
+
+ while (size--)
+ {
+
+ emitcode ("movf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("xorwf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+
+ if (IC_TRUE (ifx))
+ {
+ if (size)
+ {
+ emitSKPZ;
+ emitcode (" goto", "_%05d_DS_", tlbl->key + 100 + labelOffset);
+ }
+ else
+ {
+ emitSKPNZ;
+ emitcode (" goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
+ }
+ }
+ else
+ {
+ emitSKPZ;
+ emitcode (" goto", "_%05d_DS_", IC_FALSE (ifx)->key + 100 + labelOffset);
+ }
+ offset++;
+ }
+ if (s > 1 && IC_TRUE (ifx))
+ emitcode ("", "_%05d_DS_:", tlbl->key + 100 + labelOffset);
+ }
+ }
+ /* mark the icode as generated */
+ ifx->generated = 1;
+ goto release;
+ }
- if ( IC_TRUE(ifx) ) {
- if(size) {
- emitSKPZ;
- emitcode(" goto","_%05d_DS_",tlbl->key+100+labelOffset);
- } else {
- emitSKPNZ;
- emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ if (lit == 0L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ else if (lit == 1L)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ emitcode ("clr", "c");
+ }
+ /* AOP_TYPE(right) == AOP_CRY */
+ }
+ else
+ {
+ symbol *lbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("jb", "%s,%05d_DS_", AOP (right)->aopu.aop_dir, (lbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d_DS_:", (lbl->key + 100));
+ }
+ /* c = 1 if egal */
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ outBitC (result);
+ goto release;
+ }
+ if (ifx)
+ {
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+ /* if the result is used in an arithmetic operation
+ then put the result in place */
+ outBitC (result);
}
- } else {
- emitSKPZ;
- emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
- offset++;
- }
- if(s>1 && IC_TRUE(ifx))
- emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);
- }
- }
- /* mark the icode as generated */
- ifx->generated = 1;
- goto release ;
- }
-
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- if(lit == 0L){
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- } else if(lit == 1L) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("jb","%s,%05d_DS_",AOP(right)->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d_DS_:",(lbl->key+100));
- }
- /* c = 1 if egal */
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)){
- outBitC(result);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"c");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- outBitC(result);
- } else {
- gencjne(left,right,newiTempLabel(NULL));
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- aopPut(AOP(result),"a",0);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"a");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- if (AOP_TYPE(result) != AOP_CRY)
- outAcc(result);
- /* leave the result in acc */
+ else
+ {
+ gencjne (left, right, newiTempLabel (NULL));
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+ if (ifx)
+ {
+ genIfxJump (ifx, "a");
+ goto release;
+ }
+ /* if the result is used in an arithmetic operation
+ then put the result in place */
+ if (AOP_TYPE (result) != AOP_CRY)
+ outAcc (result);
+ /* leave the result in acc */
}
release:
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* ifxForOp - returns the icode containing the ifx for operand */
/*-----------------------------------------------------------------*/
-static iCode *ifxForOp ( operand *op, iCode *ic )
+static iCode *
+ifxForOp (operand * op, iCode * ic)
{
- /* if true symbol then needs to be assigned */
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (IS_TRUE_SYMOP(op))
- return NULL ;
+ /* if true symbol then needs to be assigned */
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (IS_TRUE_SYMOP (op))
+ return NULL;
- /* if this has register type condition and
- the next instruction is ifx with the same operand
- and live to of the operand is upto the ifx only then */
- if (ic->next &&
- ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key &&
- OP_SYMBOL(op)->liveTo <= ic->next->seq )
- return ic->next;
+ /* if this has register type condition and
+ the next instruction is ifx with the same operand
+ and live to of the operand is upto the ifx only then */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ IC_COND (ic->next)->key == op->key &&
+ OP_SYMBOL (op)->liveTo <= ic->next->seq)
+ return ic->next;
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* genAndOp - for && operation */
/*-----------------------------------------------------------------*/
-static void genAndOp (iCode *ic)
+static void
+genAndOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
+ operand *left, *right, *result;
+ symbol *tlbl;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* note here that && operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* note here that && operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE);
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emitcode("jz","%05d_DS_",tlbl->key+100);
- toBoolean(right);
- emitcode("","%05d_DS_:",tlbl->key+100);
- outBitAcc(result);
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ outBitC (result);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emitcode ("jz", "%05d_DS_", tlbl->key + 100);
+ toBoolean (right);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ outBitAcc (result);
}
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/* genOrOp - for || operation */
/*-----------------------------------------------------------------*/
/*
- tsd pic port -
- modified this code, but it doesn't appear to ever get called
-*/
+ tsd pic port -
+ modified this code, but it doesn't appear to ever get called
+ */
-static void genOrOp (iCode *ic)
+static void
+genOrOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
+ operand *left, *right, *result;
+ symbol *tlbl;
- /* note here that || operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE);
+ /* note here that || operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE);
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- emitcode("clrc","");
- emitcode("btfss","(%s >> 3), (%s & 7)",
- AOP(left)->aopu.aop_dir,
- AOP(left)->aopu.aop_dir);
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- emitcode("setc","");
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("clrc", "");
+ emitcode ("btfss", "(%s >> 3), (%s & 7)",
+ AOP (left)->aopu.aop_dir,
+ AOP (left)->aopu.aop_dir);
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ emitcode ("setc", "");
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emitSKPZ;
- emitcode("goto","%05d_DS_",tlbl->key+100+labelOffset);
- toBoolean(right);
- emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emitSKPZ;
+ emitcode ("goto", "%05d_DS_", tlbl->key + 100 + labelOffset);
+ toBoolean (right);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100 + labelOffset);
- outBitAcc(result);
+ outBitAcc (result);
}
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ 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;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- for(idx = 0; idx < 32; idx++)
- if(lit == pw[idx])
- return idx+1;
- return 0;
+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;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ for (idx = 0; idx < 32; idx++)
+ if (lit == pw[idx])
+ return idx + 1;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* continueIfTrue - */
/*-----------------------------------------------------------------*/
-static void continueIfTrue (iCode *ic)
+static void
+continueIfTrue (iCode * ic)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(IC_TRUE(ic))
- emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
- ic->generated = 1;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (IC_TRUE (ic))
+ emitcode ("ljmp", "%05d_DS_", IC_TRUE (ic)->key + 100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* jmpIfTrue - */
/*-----------------------------------------------------------------*/
-static void jumpIfTrue (iCode *ic)
+static void
+jumpIfTrue (iCode * ic)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!IC_TRUE(ic))
- emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
- ic->generated = 1;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (!IC_TRUE (ic))
+ emitcode ("ljmp", "%05d_DS_", IC_FALSE (ic)->key + 100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* jmpTrueOrFalse - */
/*-----------------------------------------------------------------*/
-static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
+static void
+jmpTrueOrFalse (iCode * ic, symbol * tlbl)
{
- // ugly but optimized by peephole
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(IC_TRUE(ic)){
- symbol *nlbl = newiTempLabel(NULL);
- emitcode("sjmp","%05d_DS_",nlbl->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
- emitcode("","%05d_DS_:",nlbl->key+100);
+ // ugly but optimized by peephole
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (IC_TRUE (ic))
+ {
+ symbol *nlbl = newiTempLabel (NULL);
+ emitcode ("sjmp", "%05d_DS_", nlbl->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ emitcode ("ljmp", "%05d_DS_", IC_TRUE (ic)->key + 100);
+ emitcode ("", "%05d_DS_:", nlbl->key + 100);
}
- else{
- emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
+ else
+ {
+ emitcode ("ljmp", "%05d_DS_", IC_FALSE (ic)->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
}
- ic->generated = 1;
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAnd - code for and */
/*-----------------------------------------------------------------*/
-static void genAnd (iCode *ic, iCode *ifx)
+static void
+genAnd (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
- int bytelit = 0;
- char buffer[10];
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+ int bytelit = 0;
+ char buffer[10];
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit & yy)
- // result = bit & yy;
- if (AOP_TYPE(left) == AOP_CRY){
- // c = bit & literal;
- if(AOP_TYPE(right) == AOP_LIT){
- if(lit & 1) {
- if(size && sameRegs(AOP(result),AOP(left)))
- // no change
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // bit(result) = 0;
- if(size && (AOP_TYPE(result) == AOP_CRY)){
- emitcode("clr","%s",AOP(result)->aopu.aop_dir);
- goto release;
- }
- if((AOP_TYPE(result) == AOP_CRY) && ifx){
- jumpIfTrue(ifx);
- goto release;
- }
- emitcode("clr","c");
- }
- } else {
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit & bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // c = bit & val;
- MOVA(aopGet(AOP(right),0,FALSE,FALSE));
- // c = lsb
- emitcode("rrc","a");
- emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- }
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit & ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- // if(val & 0xZZ) - size = 0, ifx != FALSE -
- // bit = val & 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- int posbit = isLiteralBit(lit);
- /* left & 2^n */
- if(posbit){
- posbit--;
- MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE));
- // bit = left & 2^n
- if(size)
- emitcode("mov","c,acc.%d",posbit&0x07);
- // if(left & 2^n)
- else{
- if(ifx){
- sprintf(buffer,"acc.%d",posbit&0x07);
- genIfxJump(ifx, buffer);
- }
- goto release;
- }
- } else {
- symbol *tlbl = newiTempLabel(NULL);
- int sizel = AOP_SIZE(left);
- if(size)
- emitcode("setb","c");
- while(sizel--){
- if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
- MOVA( aopGet(AOP(left),offset,FALSE,FALSE));
- // byte == 2^n ?
- if((posbit = isLiteralBit(bytelit)) != 0)
- emitcode("jb","acc.%d,%05d_DS_",(posbit-1)&0x07,tlbl->key+100);
- else{
- if(bytelit != 0x0FFL)
- emitcode("anl","a,%s",
- aopGet(AOP(right),offset,FALSE,TRUE));
- emitcode("jnz","%05d_DS_",tlbl->key+100);
- }
- }
- offset++;
- }
- // bit = left & literal
- if(size){
- emitcode("clr","c");
- emitcode("","%05d_DS_:",tlbl->key+100);
- }
- // if(left & literal)
- else{
- if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- goto release ;
- }
- }
- outBitC(result);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++,lit>>=8) {
- if(AOP_TYPE(right) == AOP_LIT){
- switch(lit & 0xff) {
- case 0x00:
- /* and'ing with 0 has clears the result */
- emitcode("clrf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- case 0xff:
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- break;
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
- default:
- {
- int p = my_powof2( (~lit) & 0xff );
- if(p>=0) {
- /* only one bit is set in the literal, so use a bcf instruction */
- emitcode("bcf","%s,%d",aopGet(AOP(left),offset,FALSE,TRUE),p);
- } else {
- emitcode("movlw","0x%x", (lit & 0xff));
- emitcode("andwf","%s,f",aopGet(AOP(left),offset,FALSE,TRUE),p);
- }
- }
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
}
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("iorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("iorwf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
}
- }
- }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left & right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = min(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("anl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("jnz","%05d_DS_",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d_DS_:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else {
- for(;(size--);offset++) {
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- int t = (lit >> (offset*8)) & 0x0FFL;
- switch(t) {
- case 0x00:
- emitcode("clrf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- case 0xff:
- emitcode("movf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- default:
- emitcode("movlw","0x%x",t);
- emitcode("andwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
-
- }
- continue;
- }
+ size = AOP_SIZE (result);
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("andwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("andwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- }
- emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
+ // if(bit & yy)
+ // result = bit & yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ // c = bit & literal;
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (lit & 1)
+ {
+ if (size && sameRegs (AOP (result), AOP (left)))
+ // no change
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // bit(result) = 0;
+ if (size && (AOP_TYPE (result) == AOP_CRY))
+ {
+ emitcode ("clr", "%s", AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+ if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ {
+ jumpIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("clr", "c");
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit & bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // c = bit & val;
+ MOVA (aopGet (AOP (right), 0, FALSE, FALSE));
+ // c = lsb
+ emitcode ("rrc", "a");
+ emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit & ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
}
- }
+
+ // if(val & 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val & 0xZZ - size = 1, ifx = FALSE -
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ int posbit = isLiteralBit (lit);
+ /* left & 2^n */
+ if (posbit)
+ {
+ posbit--;
+ MOVA (aopGet (AOP (left), posbit >> 3, FALSE, FALSE));
+ // bit = left & 2^n
+ if (size)
+ emitcode ("mov", "c,acc.%d", posbit & 0x07);
+ // if(left & 2^n)
+ else
+ {
+ if (ifx)
+ {
+ sprintf (buffer, "acc.%d", posbit & 0x07);
+ genIfxJump (ifx, buffer);
+ }
+ goto release;
+ }
+ }
+ else
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizel = AOP_SIZE (left);
+ if (size)
+ emitcode ("setb", "c");
+ while (sizel--)
+ {
+ if ((bytelit = ((lit >> (offset * 8)) & 0x0FFL)) != 0x0L)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE));
+ // byte == 2^n ?
+ if ((posbit = isLiteralBit (bytelit)) != 0)
+ emitcode ("jb", "acc.%d,%05d_DS_", (posbit - 1) & 0x07, tlbl->key + 100);
+ else
+ {
+ if (bytelit != 0x0FFL)
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (right), offset, FALSE, TRUE));
+ emitcode ("jnz", "%05d_DS_", tlbl->key + 100);
+ }
+ }
+ offset++;
+ }
+ // bit = left & literal
+ if (size)
+ {
+ emitcode ("clr", "c");
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ }
+ // if(left & literal)
+ else
+ {
+ if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ goto release;
+ }
+ }
+ outBitC (result);
+ goto release;
+ }
+
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++, lit >>= 8)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ switch (lit & 0xff)
+ {
+ case 0x00:
+ /* and'ing with 0 has clears the result */
+ emitcode ("clrf", "%s", aopGet (AOP (result), offset, FALSE, FALSE));
+ break;
+ case 0xff:
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ break;
+
+ default:
+ {
+ int p = my_powof2 ((~lit) & 0xff);
+ if (p >= 0)
+ {
+ /* only one bit is set in the literal, so use a bcf instruction */
+ emitcode ("bcf", "%s,%d", aopGet (AOP (left), offset, FALSE, TRUE), p);
+ }
+ else
+ {
+ emitcode ("movlw", "0x%x", (lit & 0xff));
+ emitcode ("andwf", "%s,f", aopGet (AOP (left), offset, FALSE, TRUE), p);
+ }
+ }
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("iorwf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("iorwf", "%s,f", aopGet (AOP (left), offset, FALSE, FALSE));
+
+ }
+ }
+ }
+
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left & right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = min (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("anl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("jnz", "%05d_DS_", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ {
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ int t = (lit >> (offset * 8)) & 0x0FFL;
+ switch (t)
+ {
+ case 0x00:
+ emitcode ("clrf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+ break;
+ case 0xff:
+ emitcode ("movf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+ break;
+ default:
+ emitcode ("movlw", "0x%x", t);
+ emitcode ("andwf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+
+ }
+ continue;
+ }
+
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("andwf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("andwf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ emitcode ("movwf", "%s", aopGet (AOP (result), offset, FALSE, FALSE));
+ }
+ }
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genOr - code for or */
/*-----------------------------------------------------------------*/
-static void genOr (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
-
-
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit | yy)
- // xx = bit | yy;
- if (AOP_TYPE(left) == AOP_CRY){
- if(AOP_TYPE(right) == AOP_LIT){
- // c = bit & literal;
- if(lit){
- // lit != 0 => result = 1
- if(AOP_TYPE(result) == AOP_CRY){
- if(size)
- emitcode("bsf","(%s >> 3), (%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- else if(ifx)
- continueIfTrue(ifx);
- goto release;
- }
- emitcode(";XXXsetb","c %s,%d",__FILE__,__LINE__);
- } else {
- // lit == 0 => result = left
- if(size && sameRegs(AOP(result),AOP(left)))
- goto release;
- emitcode(";XXX mov","c,%s %s,%d",AOP(left)->aopu.aop_dir,__FILE__,__LINE__);
- }
- } else {
- if (AOP_TYPE(right) == AOP_CRY){
- if(sameRegs(AOP(result),AOP(left))){
- // c = bit | bit;
- emitcode("bcf","(%s >> 3), (%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- emitcode("bsf","(%s >> 3), (%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- } else {
-
- emitcode("bcf","(%s >> 3), (%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- emitcode("btfss","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(left)->aopu.aop_dir,
- AOP(left)->aopu.aop_dir);
- emitcode("bsf","(%s >> 3), (%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- }
- }
- else{
- // c = bit | val;
- symbol *tlbl = newiTempLabel(NULL);
- emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
- if(!((AOP_TYPE(result) == AOP_CRY) && ifx))
- emitcode(";XXX setb","c");
- emitcode(";XXX jb","%s,%05d_DS_",
- AOP(left)->aopu.aop_dir,tlbl->key+100);
- toBoolean(right);
- emitcode(";XXX jnz","%05d_DS_",tlbl->key+100);
- if((AOP_TYPE(result) == AOP_CRY) && ifx){
- jmpTrueOrFalse(ifx, tlbl);
- goto release;
- } else {
- CLRC;
- emitcode("","%05d_DS_:",tlbl->key+100);
- }
- }
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit | ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- // if(val | 0xZZ) - size = 0, ifx != FALSE -
- // bit = val | 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- if(lit){
- emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
- // result = 1
- if(size)
- emitcode(";XXX setb","%s",AOP(result)->aopu.aop_dir);
- else
- continueIfTrue(ifx);
- goto release;
- } else {
- emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
- // lit = 0, result = boolean(left)
- if(size)
- emitcode(";XXX setb","c");
- toBoolean(right);
- if(size){
- symbol *tlbl = newiTempLabel(NULL);
- emitcode(";XXX jnz","%05d_DS_",tlbl->key+100);
- CLRC;
- emitcode("","%05d_DS_:",tlbl->key+100);
- } else {
- genIfxJump (ifx,"a");
- goto release;
- }
- }
- outBitC(result);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++,lit>>=8) {
- if(AOP_TYPE(right) == AOP_LIT){
- if((lit & 0xff) == 0)
- /* or'ing with 0 has no effect */
- continue;
- else {
- int p = my_powof2(lit & 0xff);
- if(p>=0) {
- /* only one bit is set in the literal, so use a bsf instruction */
- emitcode("bsf","%s,%d",aopGet(AOP(left),offset,FALSE,TRUE),p);
- } else {
- emitcode("movlw","0x%x", (lit & 0xff));
- emitcode("iorwf","%s,f",aopGet(AOP(left),offset,FALSE,TRUE),p);
- }
+static void
+genOr (iCode * ic, iCode * ifx)
+{
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
+
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
}
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("iorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("iorwf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
}
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left | right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
- emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
-
- if(size)
- emitcode(";XXX setb","c");
- while(sizer--){
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode(";XXX orl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode(";XXX jnz","%05d_DS_",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d_DS_:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else for(;(size--);offset++){
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- int t = (lit >> (offset*8)) & 0x0FFL;
- switch(t) {
- case 0x00:
- emitcode("movf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- default:
- emitcode("movlw","0x%x",t);
- emitcode("iorwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- }
- continue;
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
}
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("iorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("iorwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit | yy)
+ // xx = bit | yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ // c = bit & literal;
+ if (lit)
+ {
+ // lit != 0 => result = 1
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ if (size)
+ emitcode ("bsf", "(%s >> 3), (%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ else if (ifx)
+ continueIfTrue (ifx);
+ goto release;
+ }
+ emitcode (";XXXsetb", "c %s,%d", __FILE__, __LINE__);
+ }
+ else
+ {
+ // lit == 0 => result = left
+ if (size && sameRegs (AOP (result), AOP (left)))
+ goto release;
+ emitcode (";XXX mov", "c,%s %s,%d", AOP (left)->aopu.aop_dir, __FILE__, __LINE__);
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ // c = bit | bit;
+ emitcode ("bcf", "(%s >> 3), (%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ emitcode ("bsf", "(%s >> 3), (%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ }
+ else
+ {
+
+ emitcode ("bcf", "(%s >> 3), (%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ emitcode ("btfss", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (left)->aopu.aop_dir,
+ AOP (left)->aopu.aop_dir);
+ emitcode ("bsf", "(%s >> 3), (%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ }
+ }
+ else
+ {
+ // c = bit | val;
+ symbol *tlbl = newiTempLabel (NULL);
+ emitcode (";XXX ", " %s,%d", __FILE__, __LINE__);
+ if (!((AOP_TYPE (result) == AOP_CRY) && ifx))
+ emitcode (";XXX setb", "c");
+ emitcode (";XXX jb", "%s,%05d_DS_",
+ AOP (left)->aopu.aop_dir, tlbl->key + 100);
+ toBoolean (right);
+ emitcode (";XXX jnz", "%05d_DS_", tlbl->key + 100);
+ if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ {
+ jmpTrueOrFalse (ifx, tlbl);
+ goto release;
+ }
+ else
+ {
+ CLRC;
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ }
+ }
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit | ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
}
- emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- }
+
+ // if(val | 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val | 0xZZ - size = 1, ifx = FALSE -
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ if (lit)
+ {
+ emitcode (";XXX ", " %s,%d", __FILE__, __LINE__);
+ // result = 1
+ if (size)
+ emitcode (";XXX setb", "%s", AOP (result)->aopu.aop_dir);
+ else
+ continueIfTrue (ifx);
+ goto release;
+ }
+ else
+ {
+ emitcode (";XXX ", " %s,%d", __FILE__, __LINE__);
+ // lit = 0, result = boolean(left)
+ if (size)
+ emitcode (";XXX setb", "c");
+ toBoolean (right);
+ if (size)
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ emitcode (";XXX jnz", "%05d_DS_", tlbl->key + 100);
+ CLRC;
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ }
+ else
+ {
+ genIfxJump (ifx, "a");
+ goto release;
+ }
+ }
+ outBitC (result);
+ goto release;
+ }
+
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++, lit >>= 8)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if ((lit & 0xff) == 0)
+ /* or'ing with 0 has no effect */
+ continue;
+ else
+ {
+ int p = my_powof2 (lit & 0xff);
+ if (p >= 0)
+ {
+ /* only one bit is set in the literal, so use a bsf instruction */
+ emitcode ("bsf", "%s,%d", aopGet (AOP (left), offset, FALSE, TRUE), p);
+ }
+ else
+ {
+ emitcode ("movlw", "0x%x", (lit & 0xff));
+ emitcode ("iorwf", "%s,f", aopGet (AOP (left), offset, FALSE, TRUE), p);
+ }
+
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("iorwf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("iorwf", "%s,f", aopGet (AOP (left), offset, FALSE, FALSE));
+
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left | right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = max (AOP_SIZE (left), AOP_SIZE (right));
+ emitcode (";XXX ", " %s,%d", __FILE__, __LINE__);
+
+ if (size)
+ emitcode (";XXX setb", "c");
+ while (sizer--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode (";XXX orl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode (";XXX jnz", "%05d_DS_", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ int t = (lit >> (offset * 8)) & 0x0FFL;
+ switch (t)
+ {
+ case 0x00:
+ emitcode ("movf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+ break;
+ default:
+ emitcode ("movlw", "0x%x", t);
+ emitcode ("iorwf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+
+ }
+ continue;
+ }
+
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("iorwf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("iorwf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ emitcode ("movwf", "%s", aopGet (AOP (result), offset, FALSE, FALSE));
+ }
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genXor - code for xclusive or */
/*-----------------------------------------------------------------*/
-static void genXor (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
-
- /* if left is a literal & right is not ||
- if left needs acc & right does not */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- (AOP_NEEDSACC(left) && !AOP_NEEDSACC(right))) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- // if(bit ^ yy)
- // xx = bit ^ yy;
- if (AOP_TYPE(left) == AOP_CRY){
- if(AOP_TYPE(right) == AOP_LIT){
- // c = bit & literal;
- if(lit>>1){
- // lit>>1 != 0 => result = 1
- if(AOP_TYPE(result) == AOP_CRY){
- if(size)
- emitcode("setb","%s",AOP(result)->aopu.aop_dir);
- else if(ifx)
- continueIfTrue(ifx);
- goto release;
- }
- emitcode("setb","c");
- } else{
- // lit == (0 or 1)
- if(lit == 0){
- // lit == 0, result = left
- if(size && sameRegs(AOP(result),AOP(left)))
- goto release;
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else{
- // lit == 1, result = not(left)
- if(size && sameRegs(AOP(result),AOP(left))){
- emitcode("cpl","%s",AOP(result)->aopu.aop_dir);
- goto release;
- } else {
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("cpl","c");
- }
- }
- }
-
- } else {
- // right != literal
- symbol *tlbl = newiTempLabel(NULL);
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit ^ bit;
- emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- }
- else{
- int sizer = AOP_SIZE(right);
- // c = bit ^ val
- // if val>>1 != 0, result = 1
- emitcode("setb","c");
- while(sizer){
- MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE));
- if(sizer == 1)
- // test the msb of the lsb
- emitcode("anl","a,#0xfe");
- emitcode("jnz","%05d_DS_",tlbl->key+100);
- sizer--;
- }
- // val = (0,1)
- emitcode("rrc","a");
- }
- emitcode("jnb","%s,%05d_DS_",AOP(left)->aopu.aop_dir,(tlbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d_DS_:",(tlbl->key+100));
- }
- // bit = c
- // val = c
- if(size)
- outBitC(result);
- // if(bit | ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
- }
-
- if(sameRegs(AOP(result),AOP(left))){
- /* if left is same as result */
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- continue;
- else
- if (IS_AOP_PREG(left)) {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("xrl","%s,%s",
- aopGet(AOP(left),offset,FALSE,TRUE),
- aopGet(AOP(right),offset,FALSE,FALSE));
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- if (IS_AOP_PREG(left)) {
- emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
- aopPut(AOP(result),"a",offset);
- } else
- emitcode("xrl","%s,a",
- aopGet(AOP(left),offset,FALSE,TRUE));
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left ^ right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- emitcode("setb","c");
- while(sizer--){
- if((AOP_TYPE(right) == AOP_LIT) &&
- (((lit >> (offset*8)) & 0x0FFL) == 0x00L)){
- MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
- } else {
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("xrl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- }
- emitcode("jnz","%05d_DS_",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- emitcode("","%05d_DS_:",tlbl->key+100);
- outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else for(;(size--);offset++){
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- int t = (lit >> (offset*8)) & 0x0FFL;
- switch(t) {
- case 0x00:
- emitcode("movf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- case 0xff:
- emitcode("comf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- default:
- emitcode("movlw","0x%x",t);
- emitcode("xorwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
-
- }
- continue;
- }
-
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("xorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- else {
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("xorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- }
- if ( AOP_TYPE(result) != AOP_ACC)
- emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- }
+static void
+genXor (iCode * ic, iCode * ifx)
+{
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE);
+
+ /* if left is a literal & right is not ||
+ if left needs acc & right does not */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ (AOP_NEEDSACC (left) && !AOP_NEEDSACC (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ // if(bit ^ yy)
+ // xx = bit ^ yy;
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ // c = bit & literal;
+ if (lit >> 1)
+ {
+ // lit>>1 != 0 => result = 1
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ if (size)
+ emitcode ("setb", "%s", AOP (result)->aopu.aop_dir);
+ else if (ifx)
+ continueIfTrue (ifx);
+ goto release;
+ }
+ emitcode ("setb", "c");
+ }
+ else
+ {
+ // lit == (0 or 1)
+ if (lit == 0)
+ {
+ // lit == 0, result = left
+ if (size && sameRegs (AOP (result), AOP (left)))
+ goto release;
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ }
+ else
+ {
+ // lit == 1, result = not(left)
+ if (size && sameRegs (AOP (result), AOP (left)))
+ {
+ emitcode ("cpl", "%s", AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+ else
+ {
+ emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
+ emitcode ("cpl", "c");
+ }
+ }
+ }
+
+ }
+ else
+ {
+ // right != literal
+ symbol *tlbl = newiTempLabel (NULL);
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ // c = bit ^ bit;
+ emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+ }
+ else
+ {
+ int sizer = AOP_SIZE (right);
+ // c = bit ^ val
+ // if val>>1 != 0, result = 1
+ emitcode ("setb", "c");
+ while (sizer)
+ {
+ MOVA (aopGet (AOP (right), sizer - 1, FALSE, FALSE));
+ if (sizer == 1)
+ // test the msb of the lsb
+ emitcode ("anl", "a,#0xfe");
+ emitcode ("jnz", "%05d_DS_", tlbl->key + 100);
+ sizer--;
+ }
+ // val = (0,1)
+ emitcode ("rrc", "a");
+ }
+ emitcode ("jnb", "%s,%05d_DS_", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
+ emitcode ("cpl", "c");
+ emitcode ("", "%05d_DS_:", (tlbl->key + 100));
+ }
+ // bit = c
+ // val = c
+ if (size)
+ outBitC (result);
+ // if(bit | ...)
+ else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
+ genIfxJump (ifx, "c");
+ goto release;
+ }
+
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ /* if left is same as result */
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ continue;
+ else if (IS_AOP_PREG (left))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("xrl", "%s,%s",
+ aopGet (AOP (left), offset, FALSE, TRUE),
+ aopGet (AOP (right), offset, FALSE, FALSE));
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ if (IS_AOP_PREG (left))
+ {
+ emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ emitcode ("xrl", "%s,a",
+ aopGet (AOP (left), offset, FALSE, TRUE));
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left ^ right)
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizer = max (AOP_SIZE (left), AOP_SIZE (right));
+ if (size)
+ emitcode ("setb", "c");
+ while (sizer--)
+ {
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (((lit >> (offset * 8)) & 0x0FFL) == 0x00L))
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("xrl", "a,%s",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ emitcode ("jnz", "%05d_DS_", tlbl->key + 100);
+ offset++;
+ }
+ if (size)
+ {
+ CLRC;
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ outBitC (result);
+ }
+ else if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ }
+ else
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ int t = (lit >> (offset * 8)) & 0x0FFL;
+ switch (t)
+ {
+ case 0x00:
+ emitcode ("movf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+ break;
+ case 0xff:
+ emitcode ("comf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+ break;
+ default:
+ emitcode ("movlw", "0x%x", t);
+ emitcode ("xorwf", "%s,w",
+ aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset, FALSE, FALSE));
+
+ }
+ continue;
+ }
+
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("xorwf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("xorwf", "%s,w", aopGet (AOP (left), offset, FALSE, FALSE));
+ }
+ if (AOP_TYPE (result) != AOP_ACC)
+ emitcode ("movwf", "%s", aopGet (AOP (result), offset, FALSE, FALSE));
+ }
}
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+release:
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genInline - write the inline code out */
/*-----------------------------------------------------------------*/
-static void genInline (iCode *ic)
+static void
+genInline (iCode * ic)
{
- char buffer[MAX_INLINEASM];
- char *bp = buffer;
- char *bp1= buffer;
+ char buffer[MAX_INLINEASM];
+ char *bp = buffer;
+ char *bp1 = buffer;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- _G.inLine += (!options.asmpeep);
- strcpy(buffer,IC_INLINE(ic));
+ _G.inLine += (!options.asmpeep);
+ strcpy (buffer, IC_INLINE (ic));
- /* emit each line as a code */
- while (*bp) {
- if (*bp == '\n') {
- *bp++ = '\0';
- emitcode(bp1,"");
- bp1 = bp;
- } else {
- if (*bp == ':') {
- bp++;
- *bp = '\0';
- bp++;
- emitcode(bp1,"");
- bp1 = bp;
- } else
- bp++;
- }
- }
- if (bp1 != bp)
- emitcode(bp1,"");
- /* emitcode("",buffer); */
- _G.inLine -= (!options.asmpeep);
+ /* emit each line as a code */
+ while (*bp)
+ {
+ if (*bp == '\n')
+ {
+ *bp++ = '\0';
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ {
+ if (*bp == ':')
+ {
+ bp++;
+ *bp = '\0';
+ bp++;
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ bp++;
+ }
+ }
+ if (bp1 != bp)
+ emitcode (bp1, "");
+ /* emitcode("",buffer); */
+ _G.inLine -= (!options.asmpeep);
}
/*-----------------------------------------------------------------*/
/* genRRC - rotate right with carry */
/*-----------------------------------------------------------------*/
-static void genRRC (iCode *ic)
+static void
+genRRC (iCode * ic)
{
- operand *left , *result ;
- int size, offset = 0;
- char *l;
+ operand *left, *result;
+ int size, offset = 0;
+ char *l;
- /* rotate right with carry */
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
+ /* rotate right with carry */
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
- /* move it to the result */
- size = AOP_SIZE(result);
- offset = size - 1 ;
- CLRC;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rrc","a");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset--);
- }
- /* now we need to put the carry into the
- highest order byte of the result */
- if (AOP_SIZE(result) > 1) {
- l = aopGet(AOP(result),AOP_SIZE(result)-1,FALSE,FALSE);
- MOVA(l);
+ /* move it to the result */
+ size = AOP_SIZE (result);
+ offset = size - 1;
+ CLRC;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset--);
+ }
+ /* now we need to put the carry into the
+ highest order byte of the result */
+ if (AOP_SIZE (result) > 1)
+ {
+ l = aopGet (AOP (result), AOP_SIZE (result) - 1, FALSE, FALSE);
+ MOVA (l);
}
- emitcode("mov","acc.7,c");
- aopPut(AOP(result),"a",AOP_SIZE(result)-1);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ emitcode ("mov", "acc.7,c");
+ aopPut (AOP (result), "a", AOP_SIZE (result) - 1);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRLC - generate code for rotate left with carry */
/*-----------------------------------------------------------------*/
-static void genRLC (iCode *ic)
-{
- operand *left , *result ;
- int size, offset = 0;
- char *l;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* rotate right with carry */
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
-
- /* move it to the result */
- size = AOP_SIZE(result);
- offset = 0 ;
- if (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("add","a,acc");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset++);
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rlc","a");
- if (AOP_SIZE(result) > 1)
- aopPut(AOP(result),"a",offset++);
- }
- }
- /* now we need to put the carry into the
- highest order byte of the result */
- if (AOP_SIZE(result) > 1) {
- l = aopGet(AOP(result),0,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("mov","acc.0,c");
- aopPut(AOP(result),"a",0);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+static void
+genRLC (iCode * ic)
+{
+ operand *left, *result;
+ int size, offset = 0;
+ char *l;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* rotate right with carry */
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* move it to the result */
+ size = AOP_SIZE (result);
+ offset = 0;
+ if (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset++);
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ if (AOP_SIZE (result) > 1)
+ aopPut (AOP (result), "a", offset++);
+ }
+ }
+ /* now we need to put the carry into the
+ highest order byte of the result */
+ if (AOP_SIZE (result) > 1)
+ {
+ l = aopGet (AOP (result), 0, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("mov", "acc.0,c");
+ aopPut (AOP (result), "a", 0);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGetHbit - generates code get highest order bit */
/*-----------------------------------------------------------------*/
-static void genGetHbit (iCode *ic)
+static void
+genGetHbit (iCode * ic)
{
- operand *left, *result;
- left = IC_LEFT(ic);
- result=IC_RESULT(ic);
- aopOp (left,ic,FALSE);
- aopOp (result,ic,FALSE);
+ operand *left, *result;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* get the highest order byte into a */
- MOVA(aopGet(AOP(left),AOP_SIZE(left) - 1,FALSE,FALSE));
- if(AOP_TYPE(result) == AOP_CRY){
- emitcode("rlc","a");
- outBitC(result);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* get the highest order byte into a */
+ MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE));
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ emitcode ("rlc", "a");
+ outBitC (result);
}
- else{
- emitcode("rl","a");
- emitcode("anl","a,#0x01");
- outAcc(result);
+ else
+ {
+ emitcode ("rl", "a");
+ emitcode ("anl", "a,#0x01");
+ outAcc (result);
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* AccRol - rotate left accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRol (int shCount)
-{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- shCount &= 0x0007; // shCount : 0..7
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("rl","a");
- break;
- case 2 :
- emitcode("rl","a");
- emitcode("rl","a");
- break;
- case 3 :
- emitcode("swap","a");
- emitcode("rr","a");
- break;
- case 4 :
- emitcode("swap","a");
- break;
- case 5 :
- emitcode("swap","a");
- emitcode("rl","a");
- break;
- case 6 :
- emitcode("rr","a");
- emitcode("rr","a");
- break;
- case 7 :
- emitcode("rr","a");
- break;
+static void
+AccRol (int shCount)
+{
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ shCount &= 0x0007; // shCount : 0..7
+
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("rl", "a");
+ break;
+ case 2:
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ break;
+ case 3:
+ emitcode ("swap", "a");
+ emitcode ("rr", "a");
+ break;
+ case 4:
+ emitcode ("swap", "a");
+ break;
+ case 5:
+ emitcode ("swap", "a");
+ emitcode ("rl", "a");
+ break;
+ case 6:
+ emitcode ("rr", "a");
+ emitcode ("rr", "a");
+ break;
+ case 7:
+ emitcode ("rr", "a");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* AccLsh - left shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccLsh (int shCount)
+static void
+AccLsh (int shCount)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1)
- emitcode("add","a,acc");
- else
- if(shCount == 2) {
- emitcode("add","a,acc");
- emitcode("add","a,acc");
- } else {
- /* rotate left accumulator */
- AccRol(shCount);
- /* and kill the lower order bits */
- emitcode("anl","a,#0x%02x", SLMask[shCount]);
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ emitcode ("add", "a,acc");
+ else if (shCount == 2)
+ {
+ emitcode ("add", "a,acc");
+ emitcode ("add", "a,acc");
+ }
+ else
+ {
+ /* rotate left accumulator */
+ AccRol (shCount);
+ /* and kill the lower order bits */
+ emitcode ("anl", "a,#0x%02x", SLMask[shCount]);
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccRsh - right shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRsh (int shCount)
+static void
+AccRsh (int shCount)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1){
- CLRC;
- emitcode("rrc","a");
- } else {
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- emitcode("anl","a,#0x%02x", SRMask[shCount]);
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ {
+ CLRC;
+ emitcode ("rrc", "a");
+ }
+ else
+ {
+ /* rotate right accumulator */
+ AccRol (8 - shCount);
+ /* and kill the higher order bits */
+ emitcode ("anl", "a,#0x%02x", SRMask[shCount]);
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccSRsh - signed right shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccSRsh (int shCount)
-{
- symbol *tlbl ;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1){
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- } else if(shCount == 2){
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- } else {
- tlbl = newiTempLabel(NULL);
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- emitcode("anl","a,#0x%02x", SRMask[shCount]);
- emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]);
- emitcode("","%05d_DS_:",tlbl->key+100);
- }
+static void
+AccSRsh (int shCount)
+{
+ symbol *tlbl;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ {
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ }
+ else if (shCount == 2)
+ {
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ /* rotate right accumulator */
+ AccRol (8 - shCount);
+ /* and kill the higher order bits */
+ emitcode ("anl", "a,#0x%02x", SRMask[shCount]);
+ emitcode ("jnb", "acc.%d,%05d_DS_", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ }
}
}
/*-----------------------------------------------------------------*/
/* shiftR1Left2Result - shift right one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR1Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
+static void
+shiftR1Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- /* shift right accumulator */
- if(sign)
- AccSRsh(shCount);
- else
- AccRsh(shCount);
- aopPut(AOP(result),"a",offr);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ /* shift right accumulator */
+ if (sign)
+ AccSRsh (shCount);
+ else
+ AccRsh (shCount);
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* shiftL1Left2Result - shift left one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftL1Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftL1Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- char *l;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- l = aopGet(AOP(left),offl,FALSE,FALSE);
- MOVA(l);
- /* shift left accumulator */
- AccLsh(shCount);
- aopPut(AOP(result),"a",offr);
+ char *l;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ l = aopGet (AOP (left), offl, FALSE, FALSE);
+ MOVA (l);
+ /* shift left accumulator */
+ AccLsh (shCount);
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* movLeft2Result - move byte from left to result */
/*-----------------------------------------------------------------*/
-static void movLeft2Result (operand *left, int offl,
- operand *result, int offr, int sign)
+static void
+movLeft2Result (operand * left, int offl,
+ operand * result, int offr, int sign)
{
- char *l;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!sameRegs(AOP(left),AOP(result)) || (offl != offr)){
- l = aopGet(AOP(left),offl,FALSE,FALSE);
+ char *l;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (!sameRegs (AOP (left), AOP (result)) || (offl != offr))
+ {
+ l = aopGet (AOP (left), offl, FALSE, FALSE);
- if (*l == '@' && (IS_AOP_PREG(result))) {
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- } else {
- if(!sign)
- aopPut(AOP(result),l,offr);
- else{
- /* MSB sign in acc.7 ! */
- if(getDataSize(left) == offl+1){
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- }
- }
- }
+ if (*l == '@' && (IS_AOP_PREG (result)))
+ {
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offr);
+ }
+ else
+ {
+ if (!sign)
+ aopPut (AOP (result), l, offr);
+ else
+ {
+ /* MSB sign in acc.7 ! */
+ if (getDataSize (left) == offl + 1)
+ {
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offr);
+ }
+ }
+ }
}
}
/*-----------------------------------------------------------------*/
/* AccAXRrl1 - right rotate c->a:x->c by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXRrl1 (char *x)
+static void
+AccAXRrl1 (char *x)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- emitcode("rrc","a");
- emitcode("xch","a,%s", x);
- emitcode("rrc","a");
- emitcode("xch","a,%s", x);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ emitcode ("rrc", "a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rrc", "a");
+ emitcode ("xch", "a,%s", x);
}
/*-----------------------------------------------------------------*/
/* AccAXLrl1 - left rotate c<-a:x<-c by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXLrl1 (char *x)
+static void
+AccAXLrl1 (char *x)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
}
/*-----------------------------------------------------------------*/
/* AccAXLsh1 - left shift a:x<-0 by 1 */
/*-----------------------------------------------------------------*/
-static void AccAXLsh1 (char *x)
+static void
+AccAXLsh1 (char *x)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- emitcode("xch","a,%s",x);
- emitcode("add","a,acc");
- emitcode("xch","a,%s",x);
- emitcode("rlc","a");
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ emitcode ("xch", "a,%s", x);
+ emitcode ("add", "a,acc");
+ emitcode ("xch", "a,%s", x);
+ emitcode ("rlc", "a");
}
/*-----------------------------------------------------------------*/
/* AccAXLsh - left shift a:x by known count (0..7) */
/*-----------------------------------------------------------------*/
-static void AccAXLsh (char *x, int shCount)
-{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- switch(shCount){
- case 0 :
- break;
- case 1 :
- AccAXLsh1(x);
- break;
- case 2 :
- AccAXLsh1(x);
- AccAXLsh1(x);
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD
- AccRol(shCount); // BBBAAAAA:CCCCCDDD
- emitcode("anl","a,#0x%02x",
- SLMask[shCount]); // BBB00000:CCCCCDDD
- emitcode("xch","a,%s",x); // CCCCCDDD:BBB00000
- AccRol(shCount); // DDDCCCCC:BBB00000
- emitcode("xch","a,%s",x); // BBB00000:DDDCCCCC
- emitcode("xrl","a,%s",x); // (BBB^DDD)CCCCC:DDDCCCCC
- emitcode("xch","a,%s",x); // DDDCCCCC:(BBB^DDD)CCCCC
- emitcode("anl","a,#0x%02x",
- SLMask[shCount]); // DDD00000:(BBB^DDD)CCCCC
- emitcode("xch","a,%s",x); // (BBB^DDD)CCCCC:DDD00000
- emitcode("xrl","a,%s",x); // BBBCCCCC:DDD00000
- break;
- case 6 : // AAAAAABB:CCCCCCDD
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000BB:CCCCCCDD
- emitcode("mov","c,acc.0"); // c = B
- emitcode("xch","a,%s",x); // CCCCCCDD:000000BB
- AccAXRrl1(x); // BCCCCCCD:D000000B
- AccAXRrl1(x); // BBCCCCCC:DD000000
- break;
- case 7 : // a:x <<= 7
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000B:CCCCCCCD
- emitcode("mov","c,acc.0"); // c = B
- emitcode("xch","a,%s",x); // CCCCCCCD:0000000B
- AccAXRrl1(x); // BCCCCCCC:D0000000
- break;
- default :
- break;
- }
-}
+static void
+AccAXLsh (char *x, int shCount)
+{
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ AccAXLsh1 (x);
+ break;
+ case 2:
+ AccAXLsh1 (x);
+ AccAXLsh1 (x);
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD
-/*-----------------------------------------------------------------*/
-/* AccAXRsh - right shift a:x known count (0..7) */
-/*-----------------------------------------------------------------*/
-static void AccAXRsh (char *x, int shCount)
-{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- switch(shCount){
- case 0 :
- break;
- case 1 :
- CLRC;
- AccAXRrl1(x); // 0->a:x
- break;
- case 2 :
- CLRC;
- AccAXRrl1(x); // 0->a:x
- CLRC;
- AccAXRrl1(x); // 0->a:x
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD = a:x
- AccRol(8 - shCount); // BBBAAAAA:DDDCCCCC
- emitcode("xch","a,%s",x); // CCCCCDDD:BBBAAAAA
- AccRol(8 - shCount); // DDDCCCCC:BBBAAAAA
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000CCCCC:BBBAAAAA
- emitcode("xrl","a,%s",x); // BBB(CCCCC^AAAAA):BBBAAAAA
- emitcode("xch","a,%s",x); // BBBAAAAA:BBB(CCCCC^AAAAA)
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
- emitcode("xch","a,%s",x); // BBB(CCCCC^AAAAA):000AAAAA
- emitcode("xrl","a,%s",x); // BBBCCCCC:000AAAAA
- emitcode("xch","a,%s",x); // 000AAAAA:BBBCCCCC
- break;
- case 6 : // AABBBBBB:CCDDDDDD
- emitcode("mov","c,acc.7");
- AccAXLrl1(x); // ABBBBBBC:CDDDDDDA
- AccAXLrl1(x); // BBBBBBCC:DDDDDDAA
- emitcode("xch","a,%s",x); // DDDDDDAA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000AA:BBBBBBCC
- break;
- case 7 : // ABBBBBBB:CDDDDDDD
- emitcode("mov","c,acc.7"); // c = A
- AccAXLrl1(x); // BBBBBBBC:DDDDDDDA
- emitcode("xch","a,%s",x); // DDDDDDDA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000A:BBBBBBBC
- break;
- default :
- break;
- }
-}
+ AccRol (shCount); // BBBAAAAA:CCCCCDDD
-/*-----------------------------------------------------------------*/
-/* AccAXRshS - right shift signed a:x known count (0..7) */
-/*-----------------------------------------------------------------*/
-static void AccAXRshS (char *x, int shCount)
-{
- symbol *tlbl ;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- break;
- case 2 :
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- emitcode("mov","c,acc.7");
- AccAXRrl1(x); // s->a:x
- break;
- case 3 :
- case 4 :
- case 5 : // AAAAABBB:CCCCCDDD = a:x
- tlbl = newiTempLabel(NULL);
- AccRol(8 - shCount); // BBBAAAAA:CCCCCDDD
- emitcode("xch","a,%s",x); // CCCCCDDD:BBBAAAAA
- AccRol(8 - shCount); // DDDCCCCC:BBBAAAAA
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000CCCCC:BBBAAAAA
- emitcode("xrl","a,%s",x); // BBB(CCCCC^AAAAA):BBBAAAAA
- emitcode("xch","a,%s",x); // BBBAAAAA:BBB(CCCCC^AAAAA)
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
- emitcode("xch","a,%s",x); // BBB(CCCCC^AAAAA):000AAAAA
- emitcode("xrl","a,%s",x); // BBBCCCCC:000AAAAA
- emitcode("xch","a,%s",x); // 000SAAAA:BBBCCCCC
- emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 111AAAAA:BBBCCCCC
- emitcode("","%05d_DS_:",tlbl->key+100);
- break; // SSSSAAAA:BBBCCCCC
- case 6 : // AABBBBBB:CCDDDDDD
- tlbl = newiTempLabel(NULL);
- emitcode("mov","c,acc.7");
- AccAXLrl1(x); // ABBBBBBC:CDDDDDDA
- AccAXLrl1(x); // BBBBBBCC:DDDDDDAA
- emitcode("xch","a,%s",x); // DDDDDDAA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 000000AA:BBBBBBCC
- emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 111111AA:BBBBBBCC
- emitcode("","%05d_DS_:",tlbl->key+100);
- break;
- case 7 : // ABBBBBBB:CDDDDDDD
- tlbl = newiTempLabel(NULL);
- emitcode("mov","c,acc.7"); // c = A
- AccAXLrl1(x); // BBBBBBBC:DDDDDDDA
- emitcode("xch","a,%s",x); // DDDDDDDA:BBBBBBCC
- emitcode("anl","a,#0x%02x",
- SRMask[shCount]); // 0000000A:BBBBBBBC
- emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100);
- emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]); // 1111111A:BBBBBBBC
- emitcode("","%05d_DS_:",tlbl->key+100);
- break;
- default :
- break;
- }
-}
+ emitcode ("anl", "a,#0x%02x",
+ SLMask[shCount]); // BBB00000:CCCCCDDD
-/*-----------------------------------------------------------------*/
-/* shiftL2Left2Result - shift left two bytes from left to result */
-/*-----------------------------------------------------------------*/
-static void shiftL2Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBB00000
+
+ AccRol (shCount); // DDDCCCCC:BBB00000
+
+ emitcode ("xch", "a,%s", x); // BBB00000:DDDCCCCC
+
+ emitcode ("xrl", "a,%s", x); // (BBB^DDD)CCCCC:DDDCCCCC
+
+ emitcode ("xch", "a,%s", x); // DDDCCCCC:(BBB^DDD)CCCCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SLMask[shCount]); // DDD00000:(BBB^DDD)CCCCC
+
+ emitcode ("xch", "a,%s", x); // (BBB^DDD)CCCCC:DDD00000
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:DDD00000
+
+ break;
+ case 6: // AAAAAABB:CCCCCCDD
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000BB:CCCCCCDD
+
+ emitcode ("mov", "c,acc.0"); // c = B
+
+ emitcode ("xch", "a,%s", x); // CCCCCCDD:000000BB
+
+ AccAXRrl1 (x); // BCCCCCCD:D000000B
+
+ AccAXRrl1 (x); // BBCCCCCC:DD000000
+
+ break;
+ case 7: // a:x <<= 7
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000B:CCCCCCCD
+
+ emitcode ("mov", "c,acc.0"); // c = B
+
+ emitcode ("xch", "a,%s", x); // CCCCCCCD:0000000B
+
+ AccAXRrl1 (x); // BCCCCCCC:D0000000
+
+ break;
+ default:
+ break;
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* AccAXRsh - right shift a:x known count (0..7) */
+/*-----------------------------------------------------------------*/
+static void
+AccAXRsh (char *x, int shCount)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(sameRegs(AOP(result), AOP(left)) &&
- ((offl + MSB16) == offr)){
- /* don't crash result[offr] */
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
- } else {
- movLeft2Result(left,offl, result, offr, 0);
- MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ break;
+ case 2:
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ CLRC;
+ AccAXRrl1 (x); // 0->a:x
+
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD = a:x
+
+ AccRol (8 - shCount); // BBBAAAAA:DDDCCCCC
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBBAAAAA
+
+ AccRol (8 - shCount); // DDDCCCCC:BBBAAAAA
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000CCCCC:BBBAAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBB(CCCCC^AAAAA):BBBAAAAA
+
+ emitcode ("xch", "a,%s", x); // BBBAAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("xch", "a,%s", x); // BBB(CCCCC^AAAAA):000AAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:000AAAAA
+
+ emitcode ("xch", "a,%s", x); // 000AAAAA:BBBCCCCC
+
+ break;
+ case 6: // AABBBBBB:CCDDDDDD
+
+ emitcode ("mov", "c,acc.7");
+ AccAXLrl1 (x); // ABBBBBBC:CDDDDDDA
+
+ AccAXLrl1 (x); // BBBBBBCC:DDDDDDAA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDAA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000AA:BBBBBBCC
+
+ break;
+ case 7: // ABBBBBBB:CDDDDDDD
+
+ emitcode ("mov", "c,acc.7"); // c = A
+
+ AccAXLrl1 (x); // BBBBBBBC:DDDDDDDA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDDA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000A:BBBBBBBC
+
+ break;
+ default:
+ break;
}
- /* ax << shCount (x = lsb(result))*/
- AccAXLsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- aopPut(AOP(result),"a",offr+MSB16);
+}
+
+/*-----------------------------------------------------------------*/
+/* AccAXRshS - right shift signed a:x known count (0..7) */
+/*-----------------------------------------------------------------*/
+static void
+AccAXRshS (char *x, int shCount)
+{
+ symbol *tlbl;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ break;
+ case 2:
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ emitcode ("mov", "c,acc.7");
+ AccAXRrl1 (x); // s->a:x
+
+ break;
+ case 3:
+ case 4:
+ case 5: // AAAAABBB:CCCCCDDD = a:x
+
+ tlbl = newiTempLabel (NULL);
+ AccRol (8 - shCount); // BBBAAAAA:CCCCCDDD
+
+ emitcode ("xch", "a,%s", x); // CCCCCDDD:BBBAAAAA
+
+ AccRol (8 - shCount); // DDDCCCCC:BBBAAAAA
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000CCCCC:BBBAAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBB(CCCCC^AAAAA):BBBAAAAA
+
+ emitcode ("xch", "a,%s", x); // BBBAAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000AAAAA:BBB(CCCCC^AAAAA)
+
+ emitcode ("xch", "a,%s", x); // BBB(CCCCC^AAAAA):000AAAAA
+
+ emitcode ("xrl", "a,%s", x); // BBBCCCCC:000AAAAA
+
+ emitcode ("xch", "a,%s", x); // 000SAAAA:BBBCCCCC
+
+ emitcode ("jnb", "acc.%d,%05d_DS_", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 111AAAAA:BBBCCCCC
+
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ break; // SSSSAAAA:BBBCCCCC
+
+ case 6: // AABBBBBB:CCDDDDDD
+
+ tlbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,acc.7");
+ AccAXLrl1 (x); // ABBBBBBC:CDDDDDDA
+
+ AccAXLrl1 (x); // BBBBBBCC:DDDDDDAA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDAA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 000000AA:BBBBBBCC
+
+ emitcode ("jnb", "acc.%d,%05d_DS_", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 111111AA:BBBBBBCC
+
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ break;
+ case 7: // ABBBBBBB:CDDDDDDD
+
+ tlbl = newiTempLabel (NULL);
+ emitcode ("mov", "c,acc.7"); // c = A
+
+ AccAXLrl1 (x); // BBBBBBBC:DDDDDDDA
+
+ emitcode ("xch", "a,%s", x); // DDDDDDDA:BBBBBBCC
+
+ emitcode ("anl", "a,#0x%02x",
+ SRMask[shCount]); // 0000000A:BBBBBBBC
+
+ emitcode ("jnb", "acc.%d,%05d_DS_", 7 - shCount, tlbl->key + 100);
+ emitcode ("orl", "a,#0x%02x",
+ (unsigned char) ~SRMask[shCount]); // 1111111A:BBBBBBBC
+
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ break;
+ default:
+ break;
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* shiftL2Left2Result - shift left two bytes from left to result */
+/*-----------------------------------------------------------------*/
+static void
+shiftL2Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
+{
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ /* don't crash result[offr] */
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
+ }
+ else
+ {
+ movLeft2Result (left, offl, result, offr, 0);
+ MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
+ }
+ /* ax << shCount (x = lsb(result)) */
+ AccAXLsh (aopGet (AOP (result), offr, FALSE, FALSE), shCount);
+ aopPut (AOP (result), "a", offr + MSB16);
}
/*-----------------------------------------------------------------*/
/* shiftR2Left2Result - shift right two bytes from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR2Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
+static void
+shiftR2Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(sameRegs(AOP(result), AOP(left)) &&
- ((offl + MSB16) == offr)){
- /* don't crash result[offr] */
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
- } else {
- movLeft2Result(left,offl, result, offr, 0);
- MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ /* don't crash result[offr] */
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
}
- /* a:x >> shCount (x = lsb(result))*/
- if(sign)
- AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- else
- AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- if(getDataSize(result) > 1)
- aopPut(AOP(result),"a",offr+MSB16);
+ else
+ {
+ movLeft2Result (left, offl, result, offr, 0);
+ MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE));
+ }
+ /* a:x >> shCount (x = lsb(result)) */
+ if (sign)
+ AccAXRshS (aopGet (AOP (result), offr, FALSE, FALSE), shCount);
+ else
+ AccAXRsh (aopGet (AOP (result), offr, FALSE, FALSE), shCount);
+ if (getDataSize (result) > 1)
+ aopPut (AOP (result), "a", offr + MSB16);
}
/*-----------------------------------------------------------------*/
-/* shiftLLeftOrResult - shift left one byte from left, or to result*/
+/* shiftLLeftOrResult - shift left one byte from left, or to result */
/*-----------------------------------------------------------------*/
-static void shiftLLeftOrResult (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftLLeftOrResult (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- /* shift left accumulator */
- AccLsh(shCount);
- /* or with result */
- emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE));
- /* back to result */
- aopPut(AOP(result),"a",offr);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ /* shift left accumulator */
+ AccLsh (shCount);
+ /* or with result */
+ emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE));
+ /* back to result */
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
-/* shiftRLeftOrResult - shift right one byte from left,or to result*/
+/* shiftRLeftOrResult - shift right one byte from left,or to result */
/*-----------------------------------------------------------------*/
-static void shiftRLeftOrResult (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftRLeftOrResult (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- /* shift right accumulator */
- AccRsh(shCount);
- /* or with result */
- emitcode("orl","a,%s", aopGet(AOP(result),offr,FALSE,FALSE));
- /* back to result */
- aopPut(AOP(result),"a",offr);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ MOVA (aopGet (AOP (left), offl, FALSE, FALSE));
+ /* shift right accumulator */
+ AccRsh (shCount);
+ /* or with result */
+ emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE));
+ /* back to result */
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* genlshOne - left shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
-static void genlshOne (operand *result, operand *left, int shCount)
+static void
+genlshOne (operand * result, operand * left, int shCount)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- shiftL1Left2Result(left, LSB, result, LSB, shCount);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ shiftL1Left2Result (left, LSB, result, LSB, shCount);
}
/*-----------------------------------------------------------------*/
/* genlshTwo - left shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genlshTwo (operand *result,operand *left, int shCount)
+static void
+genlshTwo (operand * result, operand * left, int shCount)
{
- int size;
+ int size;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- size = getDataSize(result);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ size = getDataSize (result);
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
- if (size > 1){
- if (shCount)
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- else
- movLeft2Result(left, LSB, result, MSB16, 0);
- }
- aopPut(AOP(result),zero,LSB);
+ if (size > 1)
+ {
+ if (shCount)
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ }
+ aopPut (AOP (result), zero, LSB);
}
- /* 1 <= shCount <= 7 */
- else {
- if(size == 1)
- shiftL1Left2Result(left, LSB, result, LSB, shCount);
- else
- shiftL2Left2Result(left, LSB, result, LSB, shCount);
+ /* 1 <= shCount <= 7 */
+ else
+ {
+ if (size == 1)
+ shiftL1Left2Result (left, LSB, result, LSB, shCount);
+ else
+ shiftL2Left2Result (left, LSB, result, LSB, shCount);
}
}
/* shiftLLong - shift left one long from left to result */
/* offl = LSB or MSB16 */
/*-----------------------------------------------------------------*/
-static void shiftLLong (operand *left, operand *result, int offr )
+static void
+shiftLLong (operand * left, operand * result, int offr)
{
- char *l;
- int size = AOP_SIZE(result);
+ char *l;
+ int size = AOP_SIZE (result);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(size >= LSB+offr){
- l = aopGet(AOP(left),LSB,FALSE,FALSE);
- MOVA(l);
- emitcode("add","a,acc");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB16+offr && offr != LSB )
- emitcode("xch","a,%s",
- aopGet(AOP(left),LSB+offr,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",LSB+offr);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (size >= LSB + offr)
+ {
+ l = aopGet (AOP (left), LSB, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB16 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), LSB + offr, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", LSB + offr);
}
- if(size >= MSB16+offr){
- if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB16+offr && offr != LSB) ) {
- l = aopGet(AOP(left),MSB16,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("rlc","a");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB24+offr && offr != LSB)
- emitcode("xch","a,%s",
- aopGet(AOP(left),MSB16+offr,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",MSB16+offr);
+ if (size >= MSB16 + offr)
+ {
+ if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB16 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB16, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB24 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), MSB16 + offr, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", MSB16 + offr);
}
- if(size >= MSB24+offr){
- if (!(sameRegs(AOP(left),AOP(left)) && size >= MSB24+offr && offr != LSB)) {
- l = aopGet(AOP(left),MSB24,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("rlc","a");
- if (sameRegs(AOP(left),AOP(result)) &&
- size >= MSB32+offr && offr != LSB )
- emitcode("xch","a,%s",
- aopGet(AOP(left),MSB24+offr,FALSE,FALSE));
- else
- aopPut(AOP(result),"a",MSB24+offr);
+ if (size >= MSB24 + offr)
+ {
+ if (!(sameRegs (AOP (left), AOP (left)) && size >= MSB24 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB24, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ if (sameRegs (AOP (left), AOP (result)) &&
+ size >= MSB32 + offr && offr != LSB)
+ emitcode ("xch", "a,%s",
+ aopGet (AOP (left), MSB24 + offr, FALSE, FALSE));
+ else
+ aopPut (AOP (result), "a", MSB24 + offr);
}
- if(size > MSB32+offr){
- if (!(sameRegs(AOP(result),AOP(left)) && size >= MSB32+offr && offr != LSB)) {
- l = aopGet(AOP(left),MSB32,FALSE,FALSE);
- MOVA(l);
- }
- emitcode("rlc","a");
- aopPut(AOP(result),"a",MSB32+offr);
+ if (size > MSB32 + offr)
+ {
+ if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB32 + offr && offr != LSB))
+ {
+ l = aopGet (AOP (left), MSB32, FALSE, FALSE);
+ MOVA (l);
+ }
+ emitcode ("rlc", "a");
+ aopPut (AOP (result), "a", MSB32 + offr);
}
- if(offr != LSB)
- aopPut(AOP(result),zero,LSB);
+ if (offr != LSB)
+ aopPut (AOP (result), zero, LSB);
}
/*-----------------------------------------------------------------*/
/* genlshFour - shift four byte by a known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genlshFour (operand *result, operand *left, int shCount)
-{
- int size;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- size = AOP_SIZE(result);
-
- /* if shifting more that 3 bytes */
- if (shCount >= 24 ) {
- shCount -= 24;
- if (shCount)
- /* lowest order of left goes to the highest
- order of the destination */
- shiftL1Left2Result(left, LSB, result, MSB32, shCount);
- else
- movLeft2Result(left, LSB, result, MSB32, 0);
- aopPut(AOP(result),zero,LSB);
- aopPut(AOP(result),zero,MSB16);
- aopPut(AOP(result),zero,MSB32);
- return;
- }
-
- /* more than two bytes */
- else if ( shCount >= 16 ) {
- /* lower order two bytes goes to higher order two bytes */
- shCount -= 16;
- /* if some more remaining */
- if (shCount)
- shiftL2Left2Result(left, LSB, result, MSB24, shCount);
- else {
- movLeft2Result(left, MSB16, result, MSB32, 0);
- movLeft2Result(left, LSB, result, MSB24, 0);
- }
- aopPut(AOP(result),zero,MSB16);
- aopPut(AOP(result),zero,LSB);
- return;
- }
-
- /* if more than 1 byte */
- else if ( shCount >= 8 ) {
- /* lower order three bytes goes to higher order three bytes */
- shCount -= 8;
- if(size == 2){
- if(shCount)
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- else
- movLeft2Result(left, LSB, result, MSB16, 0);
- }
- else{ /* size = 4 */
- if(shCount == 0){
- movLeft2Result(left, MSB24, result, MSB32, 0);
- movLeft2Result(left, MSB16, result, MSB24, 0);
- movLeft2Result(left, LSB, result, MSB16, 0);
- aopPut(AOP(result),zero,LSB);
- }
- else if(shCount == 1)
- shiftLLong(left, result, MSB16);
- else{
- shiftL2Left2Result(left, MSB16, result, MSB24, shCount);
- shiftL1Left2Result(left, LSB, result, MSB16, shCount);
- shiftRLeftOrResult(left, LSB, result, MSB24, 8 - shCount);
- aopPut(AOP(result),zero,LSB);
- }
- }
- }
-
- /* 1 <= shCount <= 7 */
- else if(shCount <= 2){
- shiftLLong(left, result, LSB);
- if(shCount == 2)
- shiftLLong(result, result, LSB);
- }
- /* 3 <= shCount <= 7, optimize */
- else{
- shiftL2Left2Result(left, MSB24, result, MSB24, shCount);
- shiftRLeftOrResult(left, MSB16, result, MSB24, 8 - shCount);
- shiftL2Left2Result(left, LSB, result, LSB, shCount);
+static void
+genlshFour (operand * result, operand * left, int shCount)
+{
+ int size;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ size = AOP_SIZE (result);
+
+ /* if shifting more that 3 bytes */
+ if (shCount >= 24)
+ {
+ shCount -= 24;
+ if (shCount)
+ /* lowest order of left goes to the highest
+ order of the destination */
+ shiftL1Left2Result (left, LSB, result, MSB32, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB32, 0);
+ aopPut (AOP (result), zero, LSB);
+ aopPut (AOP (result), zero, MSB16);
+ aopPut (AOP (result), zero, MSB32);
+ return;
+ }
+
+ /* more than two bytes */
+ else if (shCount >= 16)
+ {
+ /* lower order two bytes goes to higher order two bytes */
+ shCount -= 16;
+ /* if some more remaining */
+ if (shCount)
+ shiftL2Left2Result (left, LSB, result, MSB24, shCount);
+ else
+ {
+ movLeft2Result (left, MSB16, result, MSB32, 0);
+ movLeft2Result (left, LSB, result, MSB24, 0);
+ }
+ aopPut (AOP (result), zero, MSB16);
+ aopPut (AOP (result), zero, LSB);
+ return;
+ }
+
+ /* if more than 1 byte */
+ else if (shCount >= 8)
+ {
+ /* lower order three bytes goes to higher order three bytes */
+ shCount -= 8;
+ if (size == 2)
+ {
+ if (shCount)
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ else
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ }
+ else
+ { /* size = 4 */
+ if (shCount == 0)
+ {
+ movLeft2Result (left, MSB24, result, MSB32, 0);
+ movLeft2Result (left, MSB16, result, MSB24, 0);
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ aopPut (AOP (result), zero, LSB);
+ }
+ else if (shCount == 1)
+ shiftLLong (left, result, MSB16);
+ else
+ {
+ shiftL2Left2Result (left, MSB16, result, MSB24, shCount);
+ shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ shiftRLeftOrResult (left, LSB, result, MSB24, 8 - shCount);
+ aopPut (AOP (result), zero, LSB);
+ }
+ }
+ }
+
+ /* 1 <= shCount <= 7 */
+ else if (shCount <= 2)
+ {
+ shiftLLong (left, result, LSB);
+ if (shCount == 2)
+ shiftLLong (result, result, LSB);
+ }
+ /* 3 <= shCount <= 7, optimize */
+ else
+ {
+ shiftL2Left2Result (left, MSB24, result, MSB24, shCount);
+ shiftRLeftOrResult (left, MSB16, result, MSB24, 8 - shCount);
+ shiftL2Left2Result (left, LSB, result, LSB, shCount);
}
}
/*-----------------------------------------------------------------*/
/* genLeftShiftLiteral - left shifting by known count */
/*-----------------------------------------------------------------*/
-static void genLeftShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic)
+static void
+genLeftShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- freeAsmop(right,NULL,ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ freeAsmop (right, NULL, ic, TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
- size = getSize(operandType(result));
+ size = getSize (operandType (result));
#if VIEW_SIZE
- emitcode("; shift left ","result %d, left %d",size,
- AOP_SIZE(left));
+ emitcode ("; shift left ", "result %d, left %d", size,
+ AOP_SIZE (left));
#endif
- /* I suppose that the left size >= result size */
- if(shCount == 0){
- while(size--){
- movLeft2Result(left, size, result, size, 0);
- }
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ while (size--)
+ {
+ movLeft2Result (left, size, result, size, 0);
+ }
}
- else if(shCount >= (size * 8))
- while(size--)
- aopPut(AOP(result),zero,size);
- else{
- switch (size) {
- case 1:
- genlshOne (result,left,shCount);
- break;
+ else if (shCount >= (size * 8))
+ while (size--)
+ aopPut (AOP (result), zero, size);
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genlshOne (result, left, shCount);
+ break;
- case 2:
- case 3:
- genlshTwo (result,left,shCount);
- break;
+ case 2:
+ case 3:
+ genlshTwo (result, left, shCount);
+ break;
- case 4:
- genlshFour (result,left,shCount);
- break;
- }
+ case 4:
+ genlshFour (result, left, shCount);
+ break;
+ }
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genLeftShift - generates code for left shifting */
/*-----------------------------------------------------------------*/
-static void genLeftShift (iCode *ic)
-{
- operand *left,*right, *result;
- int size, offset;
- char *l;
- symbol *tlbl , *tlbl1;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
-
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genLeftShiftLiteral (left,right,result,ic);
- return ;
- }
-
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && (IS_AOP_PREG(result))) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- }
-
- tlbl = newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = 0 ;
- tlbl1 = newiTempLabel(NULL);
-
- /* if it is only one byte then */
- if (size == 1) {
- symbol *tlbl1 = newiTempLabel(NULL);
-
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- emitcode("add","a,acc");
- emitcode("","%05d_DS_:",tlbl1->key+100);
- emitcode("djnz","b,%05d_DS_",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
-
- emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("add","a,acc");
- aopPut(AOP(result),"a",offset++);
- while (--size) {
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rlc","a");
- aopPut(AOP(result),"a",offset++);
- }
- reAdjustPreg(AOP(result));
-
- emitcode("","%05d_DS_:",tlbl1->key+100);
- emitcode("djnz","b,%05d_DS_",tlbl->key+100);
+static void
+genLeftShift (iCode * ic)
+{
+ operand *left, *right, *result;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (right, ic, FALSE);
+
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genLeftShiftLiteral (left, right, result, ic);
+ return;
+ }
+
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE);
+ if (*l == '@' && (IS_AOP_PREG (result)))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ }
+
+ tlbl = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = 0;
+ tlbl1 = newiTempLabel (NULL);
+
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ symbol *tlbl1 = newiTempLabel (NULL);
+
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d_DS_", tlbl1->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ emitcode ("add", "a,acc");
+ emitcode ("", "%05d_DS_:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d_DS_", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+
+ emitcode ("sjmp", "%05d_DS_", tlbl1->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("add", "a,acc");
+ aopPut (AOP (result), "a", offset++);
+ while (--size)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rlc", "a");
+ aopPut (AOP (result), "a", offset++);
+ }
+ reAdjustPreg (AOP (result));
+
+ emitcode ("", "%05d_DS_:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d_DS_", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genrshOne - right shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
-static void genrshOne (operand *result, operand *left,
- int shCount, int sign)
+static void
+genrshOne (operand * result, operand * left,
+ int shCount, int sign)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- shiftR1Left2Result(left, LSB, result, LSB, shCount, sign);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ shiftR1Left2Result (left, LSB, result, LSB, shCount, sign);
}
/*-----------------------------------------------------------------*/
/* genrshTwo - right shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshTwo (operand *result,operand *left,
- int shCount, int sign)
+static void
+genrshTwo (operand * result, operand * left,
+ int shCount, int sign)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
- if (shCount)
- shiftR1Left2Result(left, MSB16, result, LSB,
- shCount, sign);
- else
- movLeft2Result(left, MSB16, result, LSB, sign);
- addSign(result, MSB16, sign);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (shCount)
+ shiftR1Left2Result (left, MSB16, result, LSB,
+ shCount, sign);
+ else
+ movLeft2Result (left, MSB16, result, LSB, sign);
+ addSign (result, MSB16, sign);
}
- /* 1 <= shCount <= 7 */
- else
- shiftR2Left2Result(left, LSB, result, LSB, shCount, sign);
+ /* 1 <= shCount <= 7 */
+ else
+ shiftR2Left2Result (left, LSB, result, LSB, shCount, sign);
}
/*-----------------------------------------------------------------*/
/* shiftRLong - shift right one long from left to result */
/* offl = LSB or MSB16 */
/*-----------------------------------------------------------------*/
-static void shiftRLong (operand *left, int offl,
- operand *result, int sign)
-{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!sign)
- emitcode("clr","c");
- MOVA(aopGet(AOP(left),MSB32,FALSE,FALSE));
- if(sign)
- emitcode("mov","c,acc.7");
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB32-offl);
- if(offl == MSB16)
- /* add sign of "a" */
- addSign(result, MSB32, sign);
-
- MOVA(aopGet(AOP(left),MSB24,FALSE,FALSE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB24-offl);
-
- MOVA(aopGet(AOP(left),MSB16,FALSE,FALSE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB16-offl);
-
- if(offl == LSB){
- MOVA(aopGet(AOP(left),LSB,FALSE,FALSE));
- emitcode("rrc","a");
- aopPut(AOP(result),"a",LSB);
+static void
+shiftRLong (operand * left, int offl,
+ operand * result, int sign)
+{
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (!sign)
+ emitcode ("clr", "c");
+ MOVA (aopGet (AOP (left), MSB32, FALSE, FALSE));
+ if (sign)
+ emitcode ("mov", "c,acc.7");
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB32 - offl);
+ if (offl == MSB16)
+ /* add sign of "a" */
+ addSign (result, MSB32, sign);
+
+ MOVA (aopGet (AOP (left), MSB24, FALSE, FALSE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB24 - offl);
+
+ MOVA (aopGet (AOP (left), MSB16, FALSE, FALSE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", MSB16 - offl);
+
+ if (offl == LSB)
+ {
+ MOVA (aopGet (AOP (left), LSB, FALSE, FALSE));
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", LSB);
}
}
/*-----------------------------------------------------------------*/
/* genrshFour - shift four byte by a known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshFour (operand *result, operand *left,
- int shCount, int sign)
-{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if shifting more that 3 bytes */
- if(shCount >= 24 ) {
- shCount -= 24;
- if(shCount)
- shiftR1Left2Result(left, MSB32, result, LSB, shCount, sign);
- else
- movLeft2Result(left, MSB32, result, LSB, sign);
- addSign(result, MSB16, sign);
- }
- else if(shCount >= 16){
- shCount -= 16;
- if(shCount)
- shiftR2Left2Result(left, MSB24, result, LSB, shCount, sign);
- else{
- movLeft2Result(left, MSB24, result, LSB, 0);
- movLeft2Result(left, MSB32, result, MSB16, sign);
- }
- addSign(result, MSB24, sign);
- }
- else if(shCount >= 8){
- shCount -= 8;
- if(shCount == 1)
- shiftRLong(left, MSB16, result, sign);
- else if(shCount == 0){
- movLeft2Result(left, MSB16, result, LSB, 0);
- movLeft2Result(left, MSB24, result, MSB16, 0);
- movLeft2Result(left, MSB32, result, MSB24, sign);
- addSign(result, MSB32, sign);
- }
- else{
- shiftR2Left2Result(left, MSB16, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB32, result, MSB16, 8 - shCount);
- /* the last shift is signed */
- shiftR1Left2Result(left, MSB32, result, MSB24, shCount, sign);
- addSign(result, MSB32, sign);
- }
- }
- else{ /* 1 <= shCount <= 7 */
- if(shCount <= 2){
- shiftRLong(left, LSB, result, sign);
- if(shCount == 2)
- shiftRLong(result, LSB, result, sign);
- }
- else{
- shiftR2Left2Result(left, LSB, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB24, result, MSB16, 8 - shCount);
- shiftR2Left2Result(left, MSB24, result, MSB24, shCount, sign);
- }
+static void
+genrshFour (operand * result, operand * left,
+ int shCount, int sign)
+{
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if shifting more that 3 bytes */
+ if (shCount >= 24)
+ {
+ shCount -= 24;
+ if (shCount)
+ shiftR1Left2Result (left, MSB32, result, LSB, shCount, sign);
+ else
+ movLeft2Result (left, MSB32, result, LSB, sign);
+ addSign (result, MSB16, sign);
+ }
+ else if (shCount >= 16)
+ {
+ shCount -= 16;
+ if (shCount)
+ shiftR2Left2Result (left, MSB24, result, LSB, shCount, sign);
+ else
+ {
+ movLeft2Result (left, MSB24, result, LSB, 0);
+ movLeft2Result (left, MSB32, result, MSB16, sign);
+ }
+ addSign (result, MSB24, sign);
+ }
+ else if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (shCount == 1)
+ shiftRLong (left, MSB16, result, sign);
+ else if (shCount == 0)
+ {
+ movLeft2Result (left, MSB16, result, LSB, 0);
+ movLeft2Result (left, MSB24, result, MSB16, 0);
+ movLeft2Result (left, MSB32, result, MSB24, sign);
+ addSign (result, MSB32, sign);
+ }
+ else
+ {
+ shiftR2Left2Result (left, MSB16, result, LSB, shCount, 0);
+ shiftLLeftOrResult (left, MSB32, result, MSB16, 8 - shCount);
+ /* the last shift is signed */
+ shiftR1Left2Result (left, MSB32, result, MSB24, shCount, sign);
+ addSign (result, MSB32, sign);
+ }
+ }
+ else
+ { /* 1 <= shCount <= 7 */
+ if (shCount <= 2)
+ {
+ shiftRLong (left, LSB, result, sign);
+ if (shCount == 2)
+ shiftRLong (result, LSB, result, sign);
+ }
+ else
+ {
+ shiftR2Left2Result (left, LSB, result, LSB, shCount, 0);
+ shiftLLeftOrResult (left, MSB24, result, MSB16, 8 - shCount);
+ shiftR2Left2Result (left, MSB24, result, MSB24, shCount, sign);
+ }
}
}
/*-----------------------------------------------------------------*/
/* genRightShiftLiteral - right shifting by known count */
/*-----------------------------------------------------------------*/
-static void genRightShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic,
- int sign)
+static void
+genRightShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic,
+ int sign)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- freeAsmop(right,NULL,ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ freeAsmop (right, NULL, ic, TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
#if VIEW_SIZE
- emitcode("; shift right ","result %d, left %d",AOP_SIZE(result),
- AOP_SIZE(left));
+ emitcode ("; shift right ", "result %d, left %d", AOP_SIZE (result),
+ AOP_SIZE (left));
#endif
- size = getDataSize(left);
- /* test the LEFT size !!! */
+ size = getDataSize (left);
+ /* test the LEFT size !!! */
- /* I suppose that the left size >= result size */
- if(shCount == 0){
- size = getDataSize(result);
- while(size--)
- movLeft2Result(left, size, result, size, 0);
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ size = getDataSize (result);
+ while (size--)
+ movLeft2Result (left, size, result, size, 0);
}
- else if(shCount >= (size * 8)){
- if(sign)
- /* get sign in acc.7 */
- MOVA(aopGet(AOP(left),size-1,FALSE,FALSE));
- addSign(result, LSB, sign);
- } else{
- switch (size) {
- case 1:
- genrshOne (result,left,shCount,sign);
- break;
+ else if (shCount >= (size * 8))
+ {
+ if (sign)
+ /* get sign in acc.7 */
+ MOVA (aopGet (AOP (left), size - 1, FALSE, FALSE));
+ addSign (result, LSB, sign);
+ }
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genrshOne (result, left, shCount, sign);
+ break;
- case 2:
- genrshTwo (result,left,shCount,sign);
- break;
+ case 2:
+ genrshTwo (result, left, shCount, sign);
+ break;
- case 4:
- genrshFour (result,left,shCount,sign);
- break;
- default :
- break;
- }
+ case 4:
+ genrshFour (result, left, shCount, sign);
+ break;
+ default:
+ break;
+ }
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
}
/*-----------------------------------------------------------------*/
/* genSignedRightShift - right shift of signed number */
/*-----------------------------------------------------------------*/
-static void genSignedRightShift (iCode *ic)
-{
- operand *right, *left, *result;
- int size, offset;
- char *l;
- symbol *tlbl, *tlbl1 ;
-
- /* we do it the hard way put the shift count in b
- and loop thru preserving the sign */
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
-
-
- if ( AOP_TYPE(right) == AOP_LIT) {
- genRightShiftLiteral (left,right,result,ic,1);
- return ;
- }
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && IS_AOP_PREG(result)) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- }
-
- /* mov the highest order bit to OVR */
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
-
- size = AOP_SIZE(result);
- offset = size - 1;
- emitcode("mov","a,%s",aopGet(AOP(left),offset,FALSE,FALSE));
- emitcode("rlc","a");
- emitcode("mov","ov,c");
- /* if it is only one byte then */
- if (size == 1) {
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- emitcode("mov","c,ov");
- emitcode("rrc","a");
- emitcode("","%05d_DS_:",tlbl1->key+100);
- emitcode("djnz","b,%05d_DS_",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
- emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- emitcode("mov","c,ov");
- while (size--) {
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rrc","a");
- aopPut(AOP(result),"a",offset--);
- }
- reAdjustPreg(AOP(result));
- emitcode("","%05d_DS_:",tlbl1->key+100);
- emitcode("djnz","b,%05d_DS_",tlbl->key+100);
+static void
+genSignedRightShift (iCode * ic)
+{
+ operand *right, *left, *result;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
+
+ /* we do it the hard way put the shift count in b
+ and loop thru preserving the sign */
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (right, ic, FALSE);
+
+
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genRightShiftLiteral (left, right, result, ic, 1);
+ return;
+ }
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE);
+ if (*l == '@' && IS_AOP_PREG (result))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ }
+
+ /* mov the highest order bit to OVR */
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
+
+ size = AOP_SIZE (result);
+ offset = size - 1;
+ emitcode ("mov", "a,%s", aopGet (AOP (left), offset, FALSE, FALSE));
+ emitcode ("rlc", "a");
+ emitcode ("mov", "ov,c");
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d_DS_", tlbl1->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ emitcode ("mov", "c,ov");
+ emitcode ("rrc", "a");
+ emitcode ("", "%05d_DS_:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d_DS_", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+ emitcode ("sjmp", "%05d_DS_", tlbl1->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ emitcode ("mov", "c,ov");
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", offset--);
+ }
+ reAdjustPreg (AOP (result));
+ emitcode ("", "%05d_DS_:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d_DS_", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genRightShift - generate code for right shifting */
/*-----------------------------------------------------------------*/
-static void genRightShift (iCode *ic)
-{
- operand *right, *left, *result;
- sym_link *retype ;
- int size, offset;
- char *l;
- symbol *tlbl, *tlbl1 ;
-
- /* if signed then we do it the hard way preserve the
- sign bit moving it inwards */
- retype = getSpec(operandType(IC_RESULT(ic)));
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- if (!SPEC_USIGN(retype)) {
- genSignedRightShift (ic);
- return ;
- }
-
- /* signed & unsigned types are treated the same : i.e. the
- signed is NOT propagated inwards : quoting from the
- ANSI - standard : "for E1 >> E2, is equivalent to division
- by 2**E2 if unsigned or if it has a non-negative value,
- otherwise the result is implementation defined ", MY definition
- is that the sign does not get propagated */
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
-
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genRightShiftLiteral (left,right,result,ic, 0);
- return ;
- }
-
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("inc","b");
- freeAsmop (right,NULL,ic,TRUE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && IS_AOP_PREG(result)) {
-
- emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- offset++;
- }
- }
-
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = size - 1;
-
- /* if it is only one byte then */
- if (size == 1) {
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- CLRC;
- emitcode("rrc","a");
- emitcode("","%05d_DS_:",tlbl1->key+100);
- emitcode("djnz","b,%05d_DS_",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
- emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- emitcode("","%05d_DS_:",tlbl->key+100);
- CLRC;
- while (size--) {
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- emitcode("rrc","a");
- aopPut(AOP(result),"a",offset--);
- }
- reAdjustPreg(AOP(result));
-
- emitcode("","%05d_DS_:",tlbl1->key+100);
- emitcode("djnz","b,%05d_DS_",tlbl->key+100);
+static void
+genRightShift (iCode * ic)
+{
+ operand *right, *left, *result;
+ sym_link *retype;
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
+
+ /* if signed then we do it the hard way preserve the
+ sign bit moving it inwards */
+ retype = getSpec (operandType (IC_RESULT (ic)));
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ if (!SPEC_USIGN (retype))
+ {
+ genSignedRightShift (ic);
+ return;
+ }
+
+ /* signed & unsigned types are treated the same : i.e. the
+ signed is NOT propagated inwards : quoting from the
+ ANSI - standard : "for E1 >> E2, is equivalent to division
+ by 2**E2 if unsigned or if it has a non-negative value,
+ otherwise the result is implementation defined ", MY definition
+ is that the sign does not get propagated */
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (right, ic, FALSE);
+
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genRightShiftLiteral (left, right, result, ic, 0);
+ return;
+ }
+
+ /* shift count is unknown then we have to form
+ a loop get the loop count in B : Note: we take
+ only the lower order byte since shifting
+ more that 32 bits make no sense anyway, ( the
+ largest size of an object can be only 32 bits ) */
+
+ emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE));
+ emitcode ("inc", "b");
+ freeAsmop (right, NULL, ic, TRUE);
+ aopOp (left, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
+
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE, TRUE);
+ if (*l == '@' && IS_AOP_PREG (result))
+ {
+
+ emitcode ("mov", "a,%s", l);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
+ }
+
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = size - 1;
+
+ /* if it is only one byte then */
+ if (size == 1)
+ {
+ l = aopGet (AOP (left), 0, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("sjmp", "%05d_DS_", tlbl1->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ CLRC;
+ emitcode ("rrc", "a");
+ emitcode ("", "%05d_DS_:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d_DS_", tlbl->key + 100);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ reAdjustPreg (AOP (result));
+ emitcode ("sjmp", "%05d_DS_", tlbl1->key + 100);
+ emitcode ("", "%05d_DS_:", tlbl->key + 100);
+ CLRC;
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rrc", "a");
+ aopPut (AOP (result), "a", offset--);
+ }
+ reAdjustPreg (AOP (result));
+
+ emitcode ("", "%05d_DS_:", tlbl1->key + 100);
+ emitcode ("djnz", "b,%05d_DS_", tlbl->key + 100);
release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genUnpackBits - generates code for unpacking bits */
/*-----------------------------------------------------------------*/
-static void genUnpackBits (operand *result, char *rname, int ptype)
+static void
+genUnpackBits (operand * result, char *rname, int ptype)
{
- int shCnt ;
- int rlen = 0 ;
- sym_link *etype;
- int offset = 0 ;
+ int shCnt;
+ int rlen = 0;
+ sym_link *etype;
+ int offset = 0;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- etype = getSpec(operandType(result));
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ etype = getSpec (operandType (result));
- /* read the first byte */
- switch (ptype) {
+ /* read the first byte */
+ switch (ptype)
+ {
case POINTER:
case IPOINTER:
- emitcode("mov","a,@%s",rname);
- break;
+ emitcode ("mov", "a,@%s", rname);
+ break;
case PPOINTER:
- emitcode("movx","a,@%s",rname);
- break;
+ emitcode ("movx", "a,@%s", rname);
+ break;
case FPOINTER:
- emitcode("movx","a,@dptr");
- break;
+ emitcode ("movx", "a,@dptr");
+ break;
case CPOINTER:
- emitcode("clr","a");
- emitcode("movc","a","@a+dptr");
- break;
+ emitcode ("clr", "a");
+ emitcode ("movc", "a", "@a+dptr");
+ break;
case GPOINTER:
- emitcode("lcall","__gptrget");
- break;
+ emitcode ("lcall", "__gptrget");
+ break;
}
- /* if we have bitdisplacement then it fits */
- /* into this byte completely or if length is */
- /* less than a byte */
- if ((shCnt = SPEC_BSTR(etype)) ||
- (SPEC_BLEN(etype) <= 8)) {
+ /* if we have bitdisplacement then it fits */
+ /* into this byte completely or if length is */
+ /* less than a byte */
+ if ((shCnt = SPEC_BSTR (etype)) ||
+ (SPEC_BLEN (etype) <= 8))
+ {
- /* shift right acc */
- AccRsh(shCnt);
+ /* shift right acc */
+ AccRsh (shCnt);
- emitcode("anl","a,#0x%02x",
- ((unsigned char) -1)>>(8 - SPEC_BLEN(etype)));
- aopPut(AOP(result),"a",offset);
- return ;
+ emitcode ("anl", "a,#0x%02x",
+ ((unsigned char) -1) >> (8 - SPEC_BLEN (etype)));
+ aopPut (AOP (result), "a", offset);
+ return;
}
- /* bit field did not fit in a byte */
- rlen = SPEC_BLEN(etype) - 8;
- aopPut(AOP(result),"a",offset++);
+ /* bit field did not fit in a byte */
+ rlen = SPEC_BLEN (etype) - 8;
+ aopPut (AOP (result), "a", offset++);
- while (1) {
+ while (1)
+ {
- switch (ptype) {
- case POINTER:
- case IPOINTER:
- emitcode("inc","%s",rname);
- emitcode("mov","a,@%s",rname);
- break;
+ switch (ptype)
+ {
+ case POINTER:
+ case IPOINTER:
+ emitcode ("inc", "%s", rname);
+ emitcode ("mov", "a,@%s", rname);
+ break;
- case PPOINTER:
- emitcode("inc","%s",rname);
- emitcode("movx","a,@%s",rname);
- break;
+ case PPOINTER:
+ emitcode ("inc", "%s", rname);
+ emitcode ("movx", "a,@%s", rname);
+ break;
- case FPOINTER:
- emitcode("inc","dptr");
- emitcode("movx","a,@dptr");
- break;
+ case FPOINTER:
+ emitcode ("inc", "dptr");
+ emitcode ("movx", "a,@dptr");
+ break;
- case CPOINTER:
- emitcode("clr","a");
- emitcode("inc","dptr");
- emitcode("movc","a","@a+dptr");
- break;
+ case CPOINTER:
+ emitcode ("clr", "a");
+ emitcode ("inc", "dptr");
+ emitcode ("movc", "a", "@a+dptr");
+ break;
- case GPOINTER:
- emitcode("inc","dptr");
- emitcode("lcall","__gptrget");
- break;
- }
+ case GPOINTER:
+ emitcode ("inc", "dptr");
+ emitcode ("lcall", "__gptrget");
+ break;
+ }
- rlen -= 8;
- /* if we are done */
- if ( rlen <= 0 )
- break ;
+ rlen -= 8;
+ /* if we are done */
+ if (rlen <= 0)
+ break;
- aopPut(AOP(result),"a",offset++);
+ aopPut (AOP (result), "a", offset++);
}
- if (rlen) {
- emitcode("anl","a,#0x%02x",((unsigned char)-1)>>(-rlen));
- aopPut(AOP(result),"a",offset);
+ if (rlen)
+ {
+ emitcode ("anl", "a,#0x%02x", ((unsigned char) -1) >> (-rlen));
+ aopPut (AOP (result), "a", offset);
}
- return ;
+ return;
}
/*-----------------------------------------------------------------*/
/* genDataPointerGet - generates code when ptr offset is known */
/*-----------------------------------------------------------------*/
-static void genDataPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genDataPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
- char *l;
- char buffer[256];
- int size , offset = 0;
- aopOp(result,ic,TRUE);
+ char *l;
+ char buffer[256];
+ int size, offset = 0;
+ aopOp (result, ic, TRUE);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- /* get the string representation of the name */
- l = aopGet(AOP(left),0,FALSE,TRUE);
- size = AOP_SIZE(result);
- // tsd, was l+1 - the underline `_' prefix was being stripped
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l,offset);
- else
- sprintf(buffer,"%s",l);
- aopPut(AOP(result),buffer,offset++);
+ /* get the string representation of the name */
+ l = aopGet (AOP (left), 0, FALSE, TRUE);
+ size = AOP_SIZE (result);
+ // tsd, was l+1 - the underline `_' prefix was being stripped
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l, offset);
+ else
+ sprintf (buffer, "%s", l);
+ aopPut (AOP (result), buffer, offset++);
}
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerGet - emitcode for near pointer fetch */
/*-----------------------------------------------------------------*/
-static void genNearPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genNearPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
- sym_link *rtype, *retype;
- sym_link *ltype = operandType(left);
- char buffer[80];
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname;
+ sym_link *rtype, *retype;
+ sym_link *ltype = operandType (left);
+ char buffer[80];
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- rtype = operandType(result);
- retype= getSpec(rtype);
+ rtype = operandType (result);
+ retype = getSpec (rtype);
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
- /* if left is rematerialisable and
- result is not bit variable type and
- the left is pointer to data space i.e
- lower 128 bytes of space */
- if (AOP_TYPE(left) == AOP_IMMD &&
- !IS_BITVAR(retype) &&
- DCL_TYPE(ltype) == POINTER) {
- genDataPointerGet (left,result,ic);
- return ;
+ /* if left is rematerialisable and
+ result is not bit variable type and
+ the left is pointer to data space i.e
+ lower 128 bytes of space */
+ if (AOP_TYPE (left) == AOP_IMMD &&
+ !IS_BITVAR (retype) &&
+ DCL_TYPE (ltype) == POINTER)
+ {
+ genDataPointerGet (left, result, ic);
+ return;
}
/* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0,FALSE,FALSE);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genUnpackBits (result,rname,POINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
- if (IS_AOP_PREG(result) || AOP_TYPE(result) == AOP_STK ) {
-
- emitcode("mov","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
- } else {
- sprintf(buffer,"@%s",rname);
- aopPut(AOP(result),buffer,offset);
- }
- offset++ ;
- if (size)
- emitcode("inc","%s",rname);
- }
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0, FALSE, TRUE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (left), 0, FALSE, FALSE);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, rname, POINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+ if (IS_AOP_PREG (result) || AOP_TYPE (result) == AOP_STK)
+ {
+
+ emitcode ("mov", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ {
+ sprintf (buffer, "@%s", rname);
+ aopPut (AOP (result), buffer, offset);
+ }
+ offset++;
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
+ }
+
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- /* done */
- freeAsmop(result,NULL,ic,TRUE);
+ /* done */
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerGet - emitcode for paged pointer fetch */
/*-----------------------------------------------------------------*/
-static void genPagedPointerGet (operand *left,
- operand *result,
- iCode *ic)
+static void
+genPagedPointerGet (operand * left,
+ operand * result,
+ iCode * ic)
{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
- sym_link *rtype, *retype;
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname;
+ sym_link *rtype, *retype;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- rtype = operandType(result);
- retype= getSpec(rtype);
+ rtype = operandType (result);
+ retype = getSpec (rtype);
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
/* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0,FALSE,FALSE);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genUnpackBits (result,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
-
- emitcode("movx","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
-
- offset++ ;
-
- if (size)
- emitcode("inc","%s",rname);
- }
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (left)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (left), 0, FALSE, TRUE));
+ rname = preg->name;
}
+ else
+ rname = aopGet (AOP (left), 0, FALSE, FALSE);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (result);
+ int offset = 0;
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(result) - 1;
while (size--)
- emitcode("dec","%s",rname);
- }
+ {
+
+ emitcode ("movx", "a,@%s", rname);
+ aopPut (AOP (result), "a", offset);
+
+ offset++;
+
+ if (size)
+ emitcode ("inc", "%s", rname);
+ }
}
- /* done */
- freeAsmop(result,NULL,ic,TRUE);
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (result) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
+ }
+
+ /* done */
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerGet - gget value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genFarPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- aopOp(left,ic,FALSE);
+ aopOp (left, ic, FALSE);
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
- while (size--) {
- emitcode("movx","a,@dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
- }
+ while (size--)
+ {
+ emitcode ("movx", "a,@dptr");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* emitcodePointerGet - gget value from code space */
/*-----------------------------------------------------------------*/
-static void emitcodePointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+emitcodePointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- aopOp(left,ic,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
+ aopOp (left, ic, FALSE);
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",CPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (left), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (left), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", CPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
- while (size--) {
- emitcode("clr","a");
- emitcode("movc","a,@a+dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- emitcode("inc","dptr");
- }
+ while (size--)
+ {
+ emitcode ("clr", "a");
+ emitcode ("movc", "a,@a+dptr");
+ aopPut (AOP (result), "a", offset++);
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerGet - gget value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genGenPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp(left,ic,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp (left, ic, FALSE);
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- emitcode("mov","b,#%d",pointerCode(retype));
- }
- else { /* we need to get it byte by byte */
-
- emitcode("movf","%s,w",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("movwf","FSR");
- /*
- emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- emitcode("mov","b,%s",aopGet(AOP(left),3,FALSE,FALSE));
- }
- else
- {
- emitcode("mov","b,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- */
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genUnpackBits(result,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- //emitcode("lcall","__gptrget");
- emitcode("movf","indf,w");
- //aopPut(AOP(result),"a",offset++);
- emitcode("movwf","%s",
- aopGet(AOP(result),offset++,FALSE,FALSE));
- if (size)
- emitcode("incf","fsr,f");
- }
- }
-
- freeAsmop(result,NULL,ic,TRUE);
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (left) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (left) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (left), 0, TRUE, FALSE));
+ emitcode ("mov", "b,#%d", pointerCode (retype));
+ }
+ else
+ { /* we need to get it byte by byte */
+
+ emitcode ("movf", "%s,w", aopGet (AOP (left), 0, FALSE, FALSE));
+ emitcode ("movwf", "FSR");
+ /*
+ emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
+ emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
+ emitcode("mov","b,%s",aopGet(AOP(left),3,FALSE,FALSE));
+ }
+ else
+ {
+ emitcode("mov","b,%s",aopGet(AOP(left),2,FALSE,FALSE));
+ }
+ */
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (left, NULL, ic, TRUE);
+ aopOp (result, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genUnpackBits (result, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
+
+ while (size--)
+ {
+ //emitcode("lcall","__gptrget");
+ emitcode ("movf", "indf,w");
+ //aopPut(AOP(result),"a",offset++);
+ emitcode ("movwf", "%s",
+ aopGet (AOP (result), offset++, FALSE, FALSE));
+ if (size)
+ emitcode ("incf", "fsr,f");
+ }
+ }
+
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
-static void genPointerGet (iCode *ic)
+static void
+genPointerGet (iCode * ic)
{
- operand *left, *result ;
- sym_link *type, *etype;
- int p_type;
+ operand *left, *result;
+ sym_link *type, *etype;
+ int p_type;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic) ;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(left);
- etype = getSpec(type);
- /* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next))
- p_type = DCL_TYPE(type);
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (left);
+ etype = getSpec (type);
+ /* if left is of type of pointer then it is simple */
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ p_type = DCL_TYPE (type);
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
/* if (SPEC_OCLS(etype)->codesp ) { */
/* p_type = CPOINTER ; */
/* p_type = POINTER ; */
}
- /* now that we have the pointer type we assign
- the pointer values */
- switch (p_type) {
+ /* now that we have the pointer type we assign
+ the pointer values */
+ switch (p_type)
+ {
case POINTER:
case IPOINTER:
- genNearPointerGet (left,result,ic);
- break;
+ genNearPointerGet (left, result, ic);
+ break;
case PPOINTER:
- genPagedPointerGet(left,result,ic);
- break;
+ genPagedPointerGet (left, result, ic);
+ break;
case FPOINTER:
- genFarPointerGet (left,result,ic);
- break;
+ genFarPointerGet (left, result, ic);
+ break;
case CPOINTER:
- emitcodePointerGet (left,result,ic);
- break;
+ emitcodePointerGet (left, result, ic);
+ break;
case GPOINTER:
- genGenPointerGet (left,result,ic);
- break;
+ genGenPointerGet (left, result, ic);
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genPackBits - generates code for packed bit storage */
/*-----------------------------------------------------------------*/
-static void genPackBits (sym_link *etype ,
- operand *right ,
- char *rname, int p_type)
-{
- int shCount = 0 ;
- int offset = 0 ;
- int rLen = 0 ;
- int blen, bstr ;
- char *l ;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- blen = SPEC_BLEN(etype);
- bstr = SPEC_BSTR(etype);
+static void
+genPackBits (sym_link * etype,
+ operand * right,
+ char *rname, int p_type)
+{
+ int shCount = 0;
+ int offset = 0;
+ int rLen = 0;
+ int blen, bstr;
+ char *l;
- l = aopGet(AOP(right),offset++,FALSE,FALSE);
- MOVA(l);
-
- /* if the bit lenth is less than or */
- /* it exactly fits a byte then */
- if (SPEC_BLEN(etype) <= 8 ) {
- shCount = SPEC_BSTR(etype) ;
-
- /* shift left acc */
- AccLsh(shCount);
-
- if (SPEC_BLEN(etype) < 8 ) { /* if smaller than a byte */
-
-
- switch (p_type) {
- case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
- break;
-
- case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
- break;
-
- case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
- break;
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ blen = SPEC_BLEN (etype);
+ bstr = SPEC_BSTR (etype);
- emitcode ("anl","a,#0x%02x",(unsigned char)
- ((unsigned char)(0xFF << (blen+bstr)) |
- (unsigned char)(0xFF >> (8-bstr)) ) );
- emitcode ("orl","a,b");
- if (p_type == GPOINTER)
- emitcode("pop","b");
- }
- }
+ l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ MOVA (l);
- switch (p_type) {
- case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
+ /* if the bit lenth is less than or */
+ /* it exactly fits a byte then */
+ if (SPEC_BLEN (etype) <= 8)
+ {
+ shCount = SPEC_BSTR (etype);
- case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
+ /* shift left acc */
+ AccLsh (shCount);
- case GPOINTER:
- DEBUGemitcode(";lcall","__gptrput");
- break;
- }
+ if (SPEC_BLEN (etype) < 8)
+ { /* if smaller than a byte */
- /* if we r done */
- if ( SPEC_BLEN(etype) <= 8 )
- return ;
- emitcode("inc","%s",rname);
- rLen = SPEC_BLEN(etype) ;
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
- /* now generate for lengths greater than one byte */
- while (1) {
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
- l = aopGet(AOP(right),offset++,FALSE,TRUE);
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
- rLen -= 8 ;
- if (rLen <= 0 )
- break ;
+ emitcode ("anl", "a,#0x%02x", (unsigned char)
+ ((unsigned char) (0xFF << (blen + bstr)) |
+ (unsigned char) (0xFF >> (8 - bstr))));
+ emitcode ("orl", "a,b");
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+ }
+ }
- switch (p_type) {
- case POINTER:
- if (*l == '@') {
- MOVA(l);
- emitcode("mov","@%s,a",rname);
- } else
- emitcode("mov","@%s,%s",rname,l);
- break;
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "@%s,a", rname);
+ break;
- case FPOINTER:
- MOVA(l);
- emitcode("movx","@dptr,a");
- break;
+ case FPOINTER:
+ emitcode ("movx", "@dptr,a");
+ break;
- case GPOINTER:
- MOVA(l);
- DEBUGemitcode(";lcall","__gptrput");
- break;
- }
- emitcode ("inc","%s",rname);
+ case GPOINTER:
+ DEBUGemitcode (";lcall", "__gptrput");
+ break;
}
- MOVA(l);
-
- /* last last was not complete */
- if (rLen) {
- /* save the byte & read byte */
- switch (p_type) {
- case POINTER:
- emitcode ("mov","b,a");
- emitcode("mov","a,@%s",rname);
- break;
+ /* if we r done */
+ if (SPEC_BLEN (etype) <= 8)
+ return;
- case FPOINTER:
- emitcode ("mov","b,a");
- emitcode("movx","a,@dptr");
- break;
+ emitcode ("inc", "%s", rname);
+ rLen = SPEC_BLEN (etype);
- case GPOINTER:
- emitcode ("push","b");
- emitcode ("push","acc");
- emitcode ("lcall","__gptrget");
- emitcode ("pop","b");
- break;
- }
-
- emitcode ("anl","a,#0x%02x",((unsigned char)-1 << -rLen) );
- emitcode ("orl","a,b");
- }
-
- if (p_type == GPOINTER)
- emitcode("pop","b");
+ /* now generate for lengths greater than one byte */
+ while (1)
+ {
- switch (p_type) {
+ l = aopGet (AOP (right), offset++, FALSE, TRUE);
+
+ rLen -= 8;
+ if (rLen <= 0)
+ break;
+
+ switch (p_type)
+ {
+ case POINTER:
+ if (*l == '@')
+ {
+ MOVA (l);
+ emitcode ("mov", "@%s,a", rname);
+ }
+ else
+ emitcode ("mov", "@%s,%s", rname, l);
+ break;
+
+ case FPOINTER:
+ MOVA (l);
+ emitcode ("movx", "@dptr,a");
+ break;
+
+ case GPOINTER:
+ MOVA (l);
+ DEBUGemitcode (";lcall", "__gptrput");
+ break;
+ }
+ emitcode ("inc", "%s", rname);
+ }
+
+ MOVA (l);
+
+ /* last last was not complete */
+ if (rLen)
+ {
+ /* save the byte & read byte */
+ switch (p_type)
+ {
+ case POINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("mov", "a,@%s", rname);
+ break;
+
+ case FPOINTER:
+ emitcode ("mov", "b,a");
+ emitcode ("movx", "a,@dptr");
+ break;
+
+ case GPOINTER:
+ emitcode ("push", "b");
+ emitcode ("push", "acc");
+ emitcode ("lcall", "__gptrget");
+ emitcode ("pop", "b");
+ break;
+ }
+
+ emitcode ("anl", "a,#0x%02x", ((unsigned char) -1 << -rLen));
+ emitcode ("orl", "a,b");
+ }
+
+ if (p_type == GPOINTER)
+ emitcode ("pop", "b");
+
+ switch (p_type)
+ {
case POINTER:
- emitcode("mov","@%s,a",rname);
- break;
+ emitcode ("mov", "@%s,a", rname);
+ break;
case FPOINTER:
- emitcode("movx","@dptr,a");
- break;
+ emitcode ("movx", "@dptr,a");
+ break;
case GPOINTER:
- DEBUGemitcode(";lcall","__gptrput");
- break;
+ DEBUGemitcode (";lcall", "__gptrput");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genDataPointerSet - remat pointer to data space */
/*-----------------------------------------------------------------*/
-static void genDataPointerSet(operand *right,
- operand *result,
- iCode *ic)
+static void
+genDataPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
- int size, offset = 0 ;
- char *l, buffer[256];
+ int size, offset = 0;
+ char *l, buffer[256];
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp(right,ic,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp (right, ic, FALSE);
- l = aopGet(AOP(result),0,FALSE,TRUE);
- size = AOP_SIZE(right);
- // tsd, was l+1 - the underline `_' prefix was being stripped
- while (size--) {
- if (offset)
- sprintf(buffer,"(%s + %d)",l,offset);
- else
- sprintf(buffer,"%s",l);
-
- if (AOP_TYPE(right) == AOP_LIT) {
- unsigned int lit = floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit);
- lit = lit >> (8*offset);
- if(lit) {
- emitcode("movlw","%s",lit);
- emitcode("movwf","%s",buffer);
- } else
- emitcode("clrf","%s",buffer);
- }else {
- emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitcode("movwf","%s",buffer);
- }
+ l = aopGet (AOP (result), 0, FALSE, TRUE);
+ size = AOP_SIZE (right);
+ // tsd, was l+1 - the underline `_' prefix was being stripped
+ while (size--)
+ {
+ if (offset)
+ sprintf (buffer, "(%s + %d)", l, offset);
+ else
+ sprintf (buffer, "%s", l);
+
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned int lit = floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ lit = lit >> (8 * offset);
+ if (lit)
+ {
+ emitcode ("movlw", "%s", lit);
+ emitcode ("movwf", "%s", buffer);
+ }
+ else
+ emitcode ("clrf", "%s", buffer);
+ }
+ else
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s", buffer);
+ }
- offset++;
+ offset++;
}
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genNearPointerSet - emitcode for near pointer put */
/*-----------------------------------------------------------------*/
-static void genNearPointerSet (operand *right,
- operand *result,
- iCode *ic)
+static void
+genNearPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
- asmop *aop = NULL;
- char *l;
- sym_link *retype;
- sym_link *ptype = operandType(result);
+ asmop *aop = NULL;
+ char *l;
+ sym_link *retype;
+ sym_link *ptype = operandType (result);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- retype= getSpec(operandType(right));
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ retype = getSpec (operandType (right));
- aopOp(result,ic,FALSE);
+ aopOp (result, ic, FALSE);
- /* if the result is rematerializable &
- in data space & not a bit variable */
- if (AOP_TYPE(result) == AOP_IMMD &&
- DCL_TYPE(ptype) == POINTER &&
- !IS_BITVAR(retype)) {
- genDataPointerSet (right,result,ic);
- return;
+ /* if the result is rematerializable &
+ in data space & not a bit variable */
+ if (AOP_TYPE (result) == AOP_IMMD &&
+ DCL_TYPE (ptype) == POINTER &&
+ !IS_BITVAR (retype))
+ {
+ genDataPointerSet (right, result, ic);
+ return;
}
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- /* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(result))) {
- /* otherwise get a free pointer register */
- //aop = newAsmop(0);
- //preg = getFreePtr(ic,&aop,FALSE);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- //emitcode("mov","%s,%s",
- // preg->name,
- // aopGet(AOP(result),0,FALSE,TRUE));
- //rname = preg->name ;
- emitcode("movwf","fsr");
- }// else
- // rname = aopGet(AOP(result),0,FALSE,FALSE);
-
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype)) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "The programmer is obviously confused");
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ /* if the value is already in a pointer register
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ //aop = newAsmop(0);
+ //preg = getFreePtr(ic,&aop,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ //emitcode("mov","%s,%s",
+ // preg->name,
+ // aopGet(AOP(result),0,FALSE,TRUE));
+ //rname = preg->name ;
+ emitcode ("movwf", "fsr");
+ } // else
+ // rname = aopGet(AOP(result),0,FALSE,FALSE);
+
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "The programmer is obviously confused");
//genPackBits (retype,right,rname,POINTER);
- exit(1);
- }
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- while (size--) {
- l = aopGet(AOP(right),offset,FALSE,TRUE);
- if (*l == '@' ) {
- //MOVA(l);
- //emitcode("mov","@%s,a",rname);
- emitcode("movf","indf,w ;1");
- } else {
-
- if (AOP_TYPE(right) == AOP_LIT) {
- unsigned int lit = floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit);
- if(lit) {
- emitcode("movlw","%s",l);
- emitcode("movwf","indf ;2");
- } else
- emitcode("clrf","indf");
- }else {
- emitcode("movf","%s,w",l);
- emitcode("movwf","indf ;2");
- }
- //emitcode("mov","@%s,%s",rname,l);
- }
- if (size)
- emitcode("incf","fsr,f ;3");
- //emitcode("inc","%s",rname);
- offset++;
- }
+ exit (1);
}
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- if size > 0 && this could be used again
- we have to point it back to where it
- belongs */
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (AOP_SIZE(right) > 1 &&
- !OP_SYMBOL(result)->remat &&
- ( OP_SYMBOL(result)->liveTo > ic->seq ||
- ic->depth )) {
- int size = AOP_SIZE(right) - 1;
- while (size--)
- emitcode("decf","fsr,f");
- //emitcode("dec","%s",rname);
- }
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset, FALSE, TRUE);
+ if (*l == '@')
+ {
+ //MOVA(l);
+ //emitcode("mov","@%s,a",rname);
+ emitcode ("movf", "indf,w ;1");
+ }
+ else
+ {
+
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned int lit = floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ if (lit)
+ {
+ emitcode ("movlw", "%s", l);
+ emitcode ("movwf", "indf ;2");
+ }
+ else
+ emitcode ("clrf", "indf");
+ }
+ else
+ {
+ emitcode ("movf", "%s,w", l);
+ emitcode ("movwf", "indf ;2");
+ }
+ //emitcode("mov","@%s,%s",rname,l);
+ }
+ if (size)
+ emitcode ("incf", "fsr,f ;3");
+ //emitcode("inc","%s",rname);
+ offset++;
+ }
+ }
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ if size > 0 && this could be used again
+ we have to point it back to where it
+ belongs */
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ if (AOP_SIZE (right) > 1 &&
+ !OP_SYMBOL (result)->remat &&
+ (OP_SYMBOL (result)->liveTo > ic->seq ||
+ ic->depth))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("decf", "fsr,f");
+ //emitcode("dec","%s",rname);
+ }
}
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* done */
- freeAsmop(right,NULL,ic,TRUE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* done */
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPagedPointerSet - emitcode for Paged pointer put */
/*-----------------------------------------------------------------*/
-static void genPagedPointerSet (operand *right,
- operand *result,
- iCode *ic)
+static void
+genPagedPointerSet (operand * right,
+ operand * result,
+ iCode * ic)
{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname , *l;
- sym_link *retype;
+ asmop *aop = NULL;
+ regs *preg = NULL;
+ char *rname, *l;
+ sym_link *retype;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- retype= getSpec(operandType(right));
+ retype = getSpec (operandType (right));
- aopOp(result,ic,FALSE);
+ aopOp (result, ic, FALSE);
- /* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(result))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(result),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(result),0,FALSE,FALSE);
+ /* if the value is already in a pointer register
+ then don't need anything more */
+ if (!AOP_INPREG (AOP (result)))
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0, FALSE, TRUE));
+ rname = preg->name;
+ }
+ else
+ rname = aopGet (AOP (result), 0, FALSE, FALSE);
- freeAsmop(result,NULL,ic,TRUE);
- aopOp (right,ic,FALSE);
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
- /* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
- genPackBits (retype,right,rname,PPOINTER);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(right);
- int offset = 0 ;
+ /* if bitfield then unpack the bits */
+ if (IS_BITVAR (retype))
+ genPackBits (retype, right, rname, PPOINTER);
+ else
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE (right);
+ int offset = 0;
- while (size--) {
- l = aopGet(AOP(right),offset,FALSE,TRUE);
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset, FALSE, TRUE);
- MOVA(l);
- emitcode("movx","@%s,a",rname);
+ MOVA (l);
+ emitcode ("movx", "@%s,a", rname);
- if (size)
- emitcode("inc","%s",rname);
+ if (size)
+ emitcode ("inc", "%s", rname);
- offset++;
- }
+ offset++;
+ }
}
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- 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 )) {
- int size = AOP_SIZE(right) - 1;
- while (size--)
- emitcode("dec","%s",rname);
- }
+ /* now some housekeeping stuff */
+ if (aop)
+ {
+ /* we had to allocate for this iCode */
+ freeAsmop (NULL, aop, ic, TRUE);
+ }
+ else
+ {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ 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))
+ {
+ int size = AOP_SIZE (right) - 1;
+ while (size--)
+ emitcode ("dec", "%s", rname);
+ }
}
- /* done */
- freeAsmop(right,NULL,ic,TRUE);
+ /* done */
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarPointerSet - set value from far space */
/*-----------------------------------------------------------------*/
-static void genFarPointerSet (operand *right,
- operand *result, iCode *ic)
+static void
+genFarPointerSet (operand * right,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp(result,ic,FALSE);
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD)
- emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
- emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp (result, ic, FALSE);
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genPackBits(retype,right,"dptr",FPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0, TRUE, FALSE));
+ else
+ { /* we need to get it byte by byte */
+ emitcode ("mov", "dpl,%s", aopGet (AOP (result), 0, FALSE, FALSE));
+ emitcode ("mov", "dph,%s", aopGet (AOP (result), 1, FALSE, FALSE));
+ if (options.model == MODEL_FLAT24)
+ {
+ emitcode ("mov", "dpx,%s", aopGet (AOP (result), 2, FALSE, FALSE));
+ }
+ }
+ }
+ /* so dptr know contains the address */
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
+
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genPackBits (retype, right, "dptr", FPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
- while (size--) {
- char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
- MOVA(l);
- emitcode("movx","@dptr,a");
- if (size)
- emitcode("inc","dptr");
- }
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("movx", "@dptr,a");
+ if (size)
+ emitcode ("inc", "dptr");
+ }
}
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genGenPointerSet - set value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerSet (operand *right,
- operand *result, iCode *ic)
+static void
+genGenPointerSet (operand * right,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- aopOp(result,ic,FALSE);
+ aopOp (result, ic, FALSE);
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(result) == AOP_IMMD) {
- emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE));
- emitcode("mov","b,%s + 1",aopGet(AOP(result),0,TRUE,FALSE));
- }
- else { /* we need to get it byte by byte */
- char *l = aopGet(AOP(result),0,FALSE,FALSE);
- if(strcmp("FSR",l))
- emitcode("movlw","%s",aopGet(AOP(result),0,FALSE,FALSE));
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ /* if this is remateriazable */
+ if (AOP_TYPE (result) == AOP_IMMD)
+ {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (result), 0, TRUE, FALSE));
+ emitcode ("mov", "b,%s + 1", aopGet (AOP (result), 0, TRUE, FALSE));
+ }
+ else
+ { /* we need to get it byte by byte */
+ char *l = aopGet (AOP (result), 0, FALSE, FALSE);
+ if (strcmp ("FSR", l))
+ emitcode ("movlw", "%s", aopGet (AOP (result), 0, FALSE, FALSE));
- emitcode("movwf","INDF");
- }
+ emitcode ("movwf", "INDF");
+ }
}
- /* so dptr know contains the address */
- freeAsmop(result,NULL,ic,TRUE);
- aopOp(right,ic,FALSE);
+ /* so dptr know contains the address */
+ freeAsmop (result, NULL, ic, TRUE);
+ aopOp (right, ic, FALSE);
- /* if bit then unpack */
- if (IS_BITVAR(retype))
- genPackBits(retype,right,"dptr",GPOINTER);
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ genPackBits (retype, right, "dptr", GPOINTER);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
- while (--size) {
- char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
- if(size)
- emitcode("incf","fsr,f");
- emitcode("movf","%s,w",aopGet(AOP(right),offset++,FALSE,FALSE));
- emitcode("movwf","indf");
- //MOVA(l);
- //DEBUGemitcode(";lcall","__gptrput");
- //if (size)
- // emitcode("inc","dptr");
- }
+ while (--size)
+ {
+ char *l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ if (size)
+ emitcode ("incf", "fsr,f");
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset++, FALSE, FALSE));
+ emitcode ("movwf", "indf");
+ //MOVA(l);
+ //DEBUGemitcode(";lcall","__gptrput");
+ //if (size)
+ // emitcode("inc","dptr");
+ }
}
- freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
-static void genPointerSet (iCode *ic)
+static void
+genPointerSet (iCode * ic)
{
- operand *right, *result ;
- sym_link *type, *etype;
- int p_type;
+ operand *right, *result;
+ sym_link *type, *etype;
+ int p_type;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- right = IC_RIGHT(ic);
- result = IC_RESULT(ic) ;
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(result);
- etype = getSpec(type);
- /* if left is of type of pointer then it is simple */
- if (IS_PTR(type) && !IS_FUNC(type->next)) {
- p_type = DCL_TYPE(type);
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (result);
+ etype = getSpec (type);
+ /* if left is of type of pointer then it is simple */
+ if (IS_PTR (type) && !IS_FUNC (type->next))
+ {
+ p_type = DCL_TYPE (type);
}
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
/* if (SPEC_OCLS(etype)->codesp ) { */
/* p_type = CPOINTER ; */
/* p_type = POINTER ; */
}
- /* now that we have the pointer type we assign
- the pointer values */
- switch (p_type) {
+ /* now that we have the pointer type we assign
+ the pointer values */
+ switch (p_type)
+ {
case POINTER:
case IPOINTER:
- genNearPointerSet (right,result,ic);
- break;
+ genNearPointerSet (right, result, ic);
+ break;
case PPOINTER:
- genPagedPointerSet (right,result,ic);
- break;
+ genPagedPointerSet (right, result, ic);
+ break;
case FPOINTER:
- genFarPointerSet (right,result,ic);
- break;
+ genFarPointerSet (right, result, ic);
+ break;
case GPOINTER:
- genGenPointerSet (right,result,ic);
- break;
+ genGenPointerSet (right, result, ic);
+ break;
}
}
/*-----------------------------------------------------------------*/
/* genIfx - generate code for Ifx statement */
/*-----------------------------------------------------------------*/
-static void genIfx (iCode *ic, iCode *popIc)
+static void
+genIfx (iCode * ic, iCode * popIc)
{
- operand *cond = IC_COND(ic);
- int isbit =0;
+ operand *cond = IC_COND (ic);
+ int isbit = 0;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp(cond,ic,FALSE);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ aopOp (cond, ic, FALSE);
- /* get the value into acc */
- if (AOP_TYPE(cond) != AOP_CRY)
- toBoolean(cond);
- else
- isbit = 1;
- /* the result is now in the accumulator */
- freeAsmop(cond,NULL,ic,TRUE);
+ /* get the value into acc */
+ if (AOP_TYPE (cond) != AOP_CRY)
+ toBoolean (cond);
+ else
+ isbit = 1;
+ /* 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 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);
- DEBUGemitcode ("; isbit SPIL_LOC","%s",SPIL_LOC(cond)->rname);
+ /* if the condition is a bit variable */
+ if (isbit && IS_ITEMP (cond) &&
+ SPIL_LOC (cond))
+ {
+ genIfxJump (ic, SPIL_LOC (cond)->rname);
+ DEBUGemitcode ("; isbit SPIL_LOC", "%s", SPIL_LOC (cond)->rname);
}
- else {
- /*
- if (isbit && !IS_ITEMP(cond))
- DEBUGemitcode ("; isbit OP_SYM","%s",OP_SYMBOL(cond)->rname);
else
- DEBUGemitcode ("; isbit","a");
- */
-
- if (isbit && !IS_ITEMP(cond))
- genIfxJump(ic,OP_SYMBOL(cond)->rname);
- else
- genIfxJump(ic,"a");
+ {
+ /*
+ if (isbit && !IS_ITEMP(cond))
+ DEBUGemitcode ("; isbit OP_SYM","%s",OP_SYMBOL(cond)->rname);
+ else
+ DEBUGemitcode ("; isbit","a");
+ */
+
+ if (isbit && !IS_ITEMP (cond))
+ genIfxJump (ic, OP_SYMBOL (cond)->rname);
+ else
+ genIfxJump (ic, "a");
}
- ic->generated = 1;
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAddrOf - generates code for address of */
/*-----------------------------------------------------------------*/
-static void genAddrOf (iCode *ic)
-{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
- int size, offset ;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- aopOp(IC_RESULT(ic),ic,FALSE);
-
- /* if the operand is on the stack then we
- need to get the stack offset of this
- variable */
- if (sym->onStack) {
- /* if it has an offset then we need to compute
- it */
- if (sym->stack) {
- emitcode("mov","a,_bp");
- emitcode("add","a,#0x%02x",((char) sym->stack & 0xff));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- } else {
- /* we can just move _bp */
- 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;
- while (size--)
- {
- /* Yuck! */
- if (options.stack10bit && offset == 2)
- {
- aopPut(AOP(IC_RESULT(ic)),"#0x40", offset++);
- }
- else
- {
- aopPut(AOP(IC_RESULT(ic)),zero,offset++);
- }
- }
-
- goto release;
- }
-
- /* object not on stack then we need the name */
- size = AOP_SIZE(IC_RESULT(ic));
- offset = 0;
-
- while (size--) {
- char s[SDCC_NAME_MAX];
- if (offset)
- sprintf(s,"#(%s >> %d)",
- sym->rname,
- offset*8);
- else
- sprintf(s,"#%s",sym->rname);
- aopPut(AOP(IC_RESULT(ic)),s,offset++);
+static void
+genAddrOf (iCode * ic)
+{
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+ int size, offset;
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ aopOp (IC_RESULT (ic), ic, FALSE);
+
+ /* if the operand is on the stack then we
+ need to get the stack offset of this
+ variable */
+ if (sym->onStack)
+ {
+ /* if it has an offset then we need to compute
+ it */
+ if (sym->stack)
+ {
+ emitcode ("mov", "a,_bp");
+ emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+ aopPut (AOP (IC_RESULT (ic)), "a", 0);
+ }
+ else
+ {
+ /* we can just move _bp */
+ 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;
+ while (size--)
+ {
+ /* Yuck! */
+ if (options.stack10bit && offset == 2)
+ {
+ aopPut (AOP (IC_RESULT (ic)), "#0x40", offset++);
+ }
+ else
+ {
+ aopPut (AOP (IC_RESULT (ic)), zero, offset++);
+ }
+ }
+
+ goto release;
+ }
+
+ /* object not on stack then we need the name */
+ size = AOP_SIZE (IC_RESULT (ic));
+ offset = 0;
+
+ while (size--)
+ {
+ char s[SDCC_NAME_MAX];
+ if (offset)
+ sprintf (s, "#(%s >> %d)",
+ sym->rname,
+ offset * 8);
+ else
+ sprintf (s, "#%s", sym->rname);
+ aopPut (AOP (IC_RESULT (ic)), s, offset++);
}
release:
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genFarFarAssign - assignment when both are in far space */
/*-----------------------------------------------------------------*/
-static void genFarFarAssign (operand *result, operand *right, iCode *ic)
+static void
+genFarFarAssign (operand * result, operand * right, iCode * ic)
{
- int size = AOP_SIZE(right);
- int offset = 0;
- char *l ;
- /* first push the right side on to the stack */
- while (size--) {
- l = aopGet(AOP(right),offset++,FALSE,FALSE);
- MOVA(l);
- emitcode ("push","acc");
+ int size = AOP_SIZE (right);
+ int offset = 0;
+ char *l;
+ /* first push the right side on to the stack */
+ while (size--)
+ {
+ l = aopGet (AOP (right), offset++, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("push", "acc");
}
- freeAsmop(right,NULL,ic,FALSE);
- /* now assign DPTR to result */
- aopOp(result,ic,FALSE);
- size = AOP_SIZE(result);
- while (size--) {
- emitcode ("pop","acc");
- aopPut(AOP(result),"a",--offset);
+ freeAsmop (right, NULL, ic, FALSE);
+ /* now assign DPTR to result */
+ aopOp (result, ic, FALSE);
+ size = AOP_SIZE (result);
+ while (size--)
+ {
+ emitcode ("pop", "acc");
+ aopPut (AOP (result), "a", --offset);
}
- freeAsmop(result,NULL,ic,FALSE);
+ freeAsmop (result, NULL, ic, FALSE);
}
#endif
/*-----------------------------------------------------------------*/
/* genAssign - generate code for assignment */
/*-----------------------------------------------------------------*/
-static void genAssign (iCode *ic)
+static void
+genAssign (iCode * ic)
{
- operand *result, *right;
- int size, offset ;
+ operand *result, *right;
+ int size, offset;
unsigned long lit = 0L;
- result = IC_RESULT(ic);
- right = IC_RIGHT(ic) ;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- /* if they are the same */
- if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
-
- aopOp(right,ic,FALSE);
- aopOp(result,ic,TRUE);
-
- /* if they are the same registers */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
-
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
-
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- if (((int) operandLitValue(right)))
- emitcode("bsf","(%s >> 3),(%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- else
- emitcode("bcf","(%s >> 3),(%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- goto release;
- }
-
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("bcf","(%s >> 3),(%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- emitcode("btfsc","(%s >> 3),(%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- emitcode("bsf","(%s >> 3),(%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- goto release ;
- }
-
- /* we need to or */
- toBoolean(right);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- /* bit variables done */
- /* general case */
- size = AOP_SIZE(result);
- offset = 0 ;
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if((AOP_TYPE(result) != AOP_REG) &&
- (AOP_TYPE(right) == AOP_LIT) &&
- !IS_FLOAT(operandType(right)) &&
- (lit < 256L)){
-
- while (size--) {
- if((unsigned int)((lit >> (size*8)) & 0x0FFL)== 0)
- emitcode("clrf","%s", aopGet(AOP(result),size,FALSE,FALSE));
- else {
- emitcode("movlw","%s", aopGet(AOP(right),size,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(result),size,FALSE,FALSE));
- }
- }
- } else {
- while (size--) {
- if(AOP_TYPE(right) == AOP_LIT)
- emitcode("movlw","%s", aopGet(AOP(right),offset,FALSE,FALSE));
- else
- emitcode("movf","%s,w", aopGet(AOP(right),offset,FALSE,FALSE));
-
- emitcode("movwf","%s", aopGet(AOP(result),offset,FALSE,FALSE));
- offset++;
- }
+ result = IC_RESULT (ic);
+ right = IC_RIGHT (ic);
+
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+
+ /* if they are the same */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
+
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, TRUE);
+
+ /* if they are the same registers */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
+
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((int) operandLitValue (right)))
+ emitcode ("bsf", "(%s >> 3),(%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ else
+ emitcode ("bcf", "(%s >> 3),(%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("bcf", "(%s >> 3),(%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ emitcode ("btfsc", "(%s >> 3),(%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ emitcode ("bsf", "(%s >> 3),(%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ /* bit variables done */
+ /* general case */
+ size = AOP_SIZE (result);
+ offset = 0;
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ if ((AOP_TYPE (result) != AOP_REG) &&
+ (AOP_TYPE (right) == AOP_LIT) &&
+ !IS_FLOAT (operandType (right)) &&
+ (lit < 256L))
+ {
+
+ while (size--)
+ {
+ if ((unsigned int) ((lit >> (size * 8)) & 0x0FFL) == 0)
+ emitcode ("clrf", "%s", aopGet (AOP (result), size, FALSE, FALSE));
+ else
+ {
+ emitcode ("movlw", "%s", aopGet (AOP (right), size, FALSE, FALSE));
+ emitcode ("movwf", "%s", aopGet (AOP (result), size, FALSE, FALSE));
+ }
+ }
+ }
+ else
+ {
+ while (size--)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ emitcode ("movlw", "%s", aopGet (AOP (right), offset, FALSE, FALSE));
+ else
+ emitcode ("movf", "%s,w", aopGet (AOP (right), offset, FALSE, FALSE));
+
+ emitcode ("movwf", "%s", aopGet (AOP (result), offset, FALSE, FALSE));
+ offset++;
+ }
}
release:
- freeAsmop (right,NULL,ic,FALSE);
- freeAsmop (result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, FALSE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genJumpTab - genrates code for jump table */
/*-----------------------------------------------------------------*/
-static void genJumpTab (iCode *ic)
+static void
+genJumpTab (iCode * ic)
{
- symbol *jtab;
- char *l;
+ symbol *jtab;
+ char *l;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- aopOp(IC_JTCOND(ic),ic,FALSE);
- /* get the condition into accumulator */
- l = aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE);
- MOVA(l);
- /* multiply by three */
- emitcode("add","a,acc");
- emitcode("add","a,%s",aopGet(AOP(IC_JTCOND(ic)),0,FALSE,FALSE));
- freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
+ aopOp (IC_JTCOND (ic), ic, FALSE);
+ /* get the condition into accumulator */
+ l = aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE);
+ MOVA (l);
+ /* multiply by three */
+ emitcode ("add", "a,acc");
+ emitcode ("add", "a,%s", aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE));
+ freeAsmop (IC_JTCOND (ic), NULL, ic, TRUE);
- jtab = newiTempLabel(NULL);
- emitcode("mov","dptr,#%05d_DS_",jtab->key+100);
- emitcode("jmp","@a+dptr");
- emitcode("","%05d_DS_:",jtab->key+100);
- /* now generate the jump labels */
- for (jtab = setFirstItem(IC_JTLABELS(ic)) ; jtab;
- jtab = setNextItem(IC_JTLABELS(ic)))
- emitcode("ljmp","%05d_DS_",jtab->key+100);
+ jtab = newiTempLabel (NULL);
+ emitcode ("mov", "dptr,#%05d_DS_", jtab->key + 100);
+ emitcode ("jmp", "@a+dptr");
+ emitcode ("", "%05d_DS_:", jtab->key + 100);
+ /* now generate the jump labels */
+ for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
+ jtab = setNextItem (IC_JTLABELS (ic)))
+ emitcode ("ljmp", "%05d_DS_", jtab->key + 100);
}
/* genMixedOperation - gen code for operators between mixed types */
/*-----------------------------------------------------------------*/
/*
- TSD - Written for the PIC port - but this unfortunately is buggy.
- This routine is good in that it is able to efficiently promote
- types to different (larger) sizes. Unfortunately, the temporary
- variables that are optimized out by this routine are sometimes
- used in other places. So until I know how to really parse the
- iCode tree, I'm going to not be using this routine :(.
-*/
-static int genMixedOperation (iCode *ic)
+ TSD - Written for the PIC port - but this unfortunately is buggy.
+ This routine is good in that it is able to efficiently promote
+ types to different (larger) sizes. Unfortunately, the temporary
+ variables that are optimized out by this routine are sometimes
+ used in other places. So until I know how to really parse the
+ iCode tree, I'm going to not be using this routine :(.
+ */
+static int
+genMixedOperation (iCode * ic)
{
#if 0
- operand *result = IC_RESULT(ic);
- sym_link *ctype = operandType(IC_LEFT(ic));
- operand *right = IC_RIGHT(ic);
+ operand *result = IC_RESULT (ic);
+ sym_link *ctype = operandType (IC_LEFT (ic));
+ operand *right = IC_RIGHT (ic);
int ret = 0;
- int big,small;
+ int big, small;
int offset;
iCode *nextic;
- operand *nextright=NULL,*nextleft=NULL,*nextresult=NULL;
+ operand *nextright = NULL, *nextleft = NULL, *nextresult = NULL;
- emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
+ emitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
nextic = ic->next;
- if(!nextic)
+ if (!nextic)
return 0;
- nextright = IC_RIGHT(nextic);
- nextleft = IC_LEFT(nextic);
- nextresult = IC_RESULT(nextic);
+ nextright = IC_RIGHT (nextic);
+ nextleft = IC_LEFT (nextic);
+ nextresult = IC_RESULT (nextic);
- aopOp(right,ic,FALSE);
- aopOp(result,ic,FALSE);
- aopOp(nextright, nextic, FALSE);
- aopOp(nextleft, nextic, FALSE);
- aopOp(nextresult, nextic, FALSE);
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, FALSE);
+ aopOp (nextright, nextic, FALSE);
+ aopOp (nextleft, nextic, FALSE);
+ aopOp (nextresult, nextic, FALSE);
- if (sameRegs(AOP(IC_RESULT(ic)), AOP(IC_RIGHT(nextic)))) {
+ if (sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (nextic))))
+ {
- operand *t = right;
- right = nextright;
- nextright = t;
+ operand *t = right;
+ right = nextright;
+ nextright = t;
- emitcode(";remove right +","");
+ emitcode (";remove right +", "");
- } else if (sameRegs(AOP(IC_RESULT(ic)), AOP(IC_LEFT(nextic)))) {
+ }
+ else if (sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (nextic))))
+ {
/*
- operand *t = right;
- right = nextleft;
- nextleft = t;
-*/
- emitcode(";remove left +","");
- } else
+ operand *t = right;
+ right = nextleft;
+ nextleft = t;
+ */
+ emitcode (";remove left +", "");
+ }
+ else
return 0;
- big = AOP_SIZE(nextleft);
- small = AOP_SIZE(nextright);
-
- switch(nextic->op) {
-
- case '+':
- emitcode(";optimize a +","");
- /* if unsigned or not an integral type */
- if (AOP_TYPE(IC_LEFT(nextic)) == AOP_CRY) {
- emitcode(";add a bit to something","");
- } else {
+ big = AOP_SIZE (nextleft);
+ small = AOP_SIZE (nextright);
- emitcode("movf","%s,w",AOP(nextright)->aopu.aop_dir);
-
- if (!sameRegs(AOP(IC_LEFT(nextic)), AOP(IC_RESULT(nextic))) ) {
- emitcode("addwf","%s,w",AOP(nextleft)->aopu.aop_dir);
- emitcode("movwf","%s",aopGet(AOP(IC_RESULT(nextic)),0,FALSE,FALSE));
- } else
- emitcode("addwf","%s,f",AOP(nextleft)->aopu.aop_dir);
-
- offset = 0;
- while(--big) {
-
- offset++;
-
- if(--small) {
- if (!sameRegs(AOP(IC_LEFT(nextic)), AOP(IC_RESULT(nextic))) ){
- emitcode("movf","%s,w",aopGet(AOP(IC_LEFT(nextic)),offset,FALSE,FALSE));
- emitcode("movwf","%s,f",aopGet(AOP(IC_RESULT(nextic)),offset,FALSE,FALSE) );
- }
+ switch (nextic->op)
+ {
- emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(nextic)),offset,FALSE,FALSE));
- emitSKPNC;
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(nextic))->aopu.aop_dir,
- AOP(IC_RIGHT(nextic))->aopu.aop_dir);
- emitcode(" incf","%s,w", aopGet(AOP(IC_LEFT(nextic)),offset,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(nextic)),offset,FALSE,FALSE));
-
- } else {
- emitcode("rlf","known_zero,w");
-
- /*
- if right is signed
- btfsc right,7
- addlw ff
- */
- if (!sameRegs(AOP(IC_LEFT(nextic)), AOP(IC_RESULT(nextic))) ){
- emitcode("addwf","%s,w",aopGet(AOP(IC_LEFT(nextic)),offset,FALSE,FALSE));
- emitcode("movwf","%s,f",aopGet(AOP(IC_RESULT(nextic)),offset,FALSE,FALSE) );
- } else {
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(nextic)),offset,FALSE,FALSE) );
- }
- }
- }
- ret = 1;
+ case '+':
+ emitcode (";optimize a +", "");
+ /* if unsigned or not an integral type */
+ if (AOP_TYPE (IC_LEFT (nextic)) == AOP_CRY)
+ {
+ emitcode (";add a bit to something", "");
+ }
+ else
+ {
+
+ emitcode ("movf", "%s,w", AOP (nextright)->aopu.aop_dir);
+
+ if (!sameRegs (AOP (IC_LEFT (nextic)), AOP (IC_RESULT (nextic))))
+ {
+ emitcode ("addwf", "%s,w", AOP (nextleft)->aopu.aop_dir);
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (nextic)), 0, FALSE, FALSE));
+ }
+ else
+ emitcode ("addwf", "%s,f", AOP (nextleft)->aopu.aop_dir);
+
+ offset = 0;
+ while (--big)
+ {
+
+ offset++;
+
+ if (--small)
+ {
+ if (!sameRegs (AOP (IC_LEFT (nextic)), AOP (IC_RESULT (nextic))))
+ {
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_LEFT (nextic)), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s,f", aopGet (AOP (IC_RESULT (nextic)), offset, FALSE, FALSE));
+ }
+
+ emitcode ("movf", "%s,w", aopGet (AOP (IC_LEFT (nextic)), offset, FALSE, FALSE));
+ emitSKPNC;
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (IC_RIGHT (nextic))->aopu.aop_dir,
+ AOP (IC_RIGHT (nextic))->aopu.aop_dir);
+ emitcode (" incf", "%s,w", aopGet (AOP (IC_LEFT (nextic)), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s", aopGet (AOP (IC_RESULT (nextic)), offset, FALSE, FALSE));
+
+ }
+ else
+ {
+ emitcode ("rlf", "known_zero,w");
+
+ /*
+ if right is signed
+ btfsc right,7
+ addlw ff
+ */
+ if (!sameRegs (AOP (IC_LEFT (nextic)), AOP (IC_RESULT (nextic))))
+ {
+ emitcode ("addwf", "%s,w", aopGet (AOP (IC_LEFT (nextic)), offset, FALSE, FALSE));
+ emitcode ("movwf", "%s,f", aopGet (AOP (IC_RESULT (nextic)), offset, FALSE, FALSE));
+ }
+ else
+ {
+ emitcode ("addwf", "%s,f", aopGet (AOP (IC_RESULT (nextic)), offset, FALSE, FALSE));
+ }
+ }
+ }
+ ret = 1;
+ }
}
- }
ret = 1;
release:
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
- freeAsmop(nextright,NULL,ic,TRUE);
- freeAsmop(nextleft,NULL,ic,TRUE);
- if(ret)
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
+ freeAsmop (nextright, NULL, ic, TRUE);
+ freeAsmop (nextleft, NULL, ic, TRUE);
+ if (ret)
nextic->generated = 1;
return ret;
/*-----------------------------------------------------------------*/
/* genCast - gen code for casting */
/*-----------------------------------------------------------------*/
-static void genCast (iCode *ic)
-{
- operand *result = IC_RESULT(ic);
- sym_link *ctype = operandType(IC_LEFT(ic));
- operand *right = IC_RIGHT(ic);
- int size, offset ;
-
- emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if they are equivalent then do nothing */
- if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
-
- aopOp(right,ic,FALSE) ;
- aopOp(result,ic,FALSE);
-
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
- /* if the right size is a literal then
- we know what the value is */
- if (AOP_TYPE(right) == AOP_LIT) {
- emitcode("; *** right is a lit","%s %d",__FUNCTION__,__LINE__);
- if (((int) operandLitValue(right)))
- emitcode("bsf","(%s >> 3), (%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
- else
- emitcode("bcf","(%s >> 3), (%s & 7)",
- AOP(result)->aopu.aop_dir,
- AOP(result)->aopu.aop_dir);
-
- goto release;
- }
-
- /* the right is also a bit variable */
- if (AOP_TYPE(right) == AOP_CRY) {
- emitcode("clrc","");
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- aopPut(AOP(result),"c",0);
- goto release ;
- }
-
- /* we need to or */
- toBoolean(right);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- /* if they are the same size : or less */
- if (AOP_SIZE(result) <= AOP_SIZE(right)) {
-
- /* if they are in the same place */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
-
- /* if they in different places then copy */
- size = AOP_SIZE(result);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
- goto release;
- }
-
-
- /* if the result is of type pointer */
- if (IS_PTR(ctype)) {
+static void
+genCast (iCode * ic)
+{
+ operand *result = IC_RESULT (ic);
+ sym_link *ctype = operandType (IC_LEFT (ic));
+ operand *right = IC_RIGHT (ic);
+ int size, offset;
- int p_type;
- sym_link *type = operandType(right);
- sym_link *etype = getSpec(type);
+ emitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
+ /* if they are equivalent then do nothing */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
+
+ aopOp (right, ic, FALSE);
+ aopOp (result, ic, FALSE);
+
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ /* if the right size is a literal then
+ we know what the value is */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ emitcode ("; *** right is a lit", "%s %d", __FUNCTION__, __LINE__);
+ if (((int) operandLitValue (right)))
+ emitcode ("bsf", "(%s >> 3), (%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+ else
+ emitcode ("bcf", "(%s >> 3), (%s & 7)",
+ AOP (result)->aopu.aop_dir,
+ AOP (result)->aopu.aop_dir);
+
+ goto release;
+ }
+
+ /* the right is also a bit variable */
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
+ emitcode ("clrc", "");
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ aopPut (AOP (result), "c", 0);
+ goto release;
+ }
+
+ /* we need to or */
+ toBoolean (right);
+ aopPut (AOP (result), "a", 0);
+ goto release;
+ }
+
+ /* if they are the same size : or less */
+ if (AOP_SIZE (result) <= AOP_SIZE (right))
+ {
+
+ /* if they are in the same place */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
- /* pointer to generic pointer */
- if (IS_GENPTR(ctype)) {
- char *l = zero;
+ /* if they in different places then copy */
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ goto release;
+ }
+
+
+ /* if the result is of type pointer */
+ if (IS_PTR (ctype))
+ {
+
+ int p_type;
+ sym_link *type = operandType (right);
+ sym_link *etype = getSpec (type);
- if (IS_PTR(type))
- p_type = DCL_TYPE(type);
- else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ /* pointer to generic pointer */
+ if (IS_GENPTR (ctype))
+ {
+ char *l = zero;
+
+ if (IS_PTR (type))
+ p_type = DCL_TYPE (type);
+ else
+ {
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE (SPEC_OCLS (etype));
/* if (SPEC_OCLS(etype)->codesp ) */
/* p_type = CPOINTER ; */
/* p_type = IPOINTER ; */
/* else */
/* p_type = POINTER ; */
- }
-
- /* the first two bytes are known */
- size = GPTRSIZE - 1;
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
- /* the last byte depending on type */
- switch (p_type) {
- case IPOINTER:
- case POINTER:
- l = zero;
- break;
- case FPOINTER:
- l = one;
- break;
- case CPOINTER:
- l = "#0x02";
- break;
- case PPOINTER:
- l = "#0x03";
- break;
-
- default:
- /* this should never happen */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got unknown pointer type");
- exit(1);\v }
- aopPut(AOP(result),l, GPTRSIZE - 1);
- goto release ;
- }
-
- /* just copy the pointers */
- size = AOP_SIZE(result);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
- goto release ;
+ }
+
+ /* the first two bytes are known */
+ size = GPTRSIZE - 1;
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ /* the last byte depending on type */
+ switch (p_type)
+ {
+ case IPOINTER:
+ case POINTER:
+ l = zero;
+ break;
+ case FPOINTER:
+ l = one;
+ break;
+ case CPOINTER:
+ l = "#0x02";
+ break;
+ case PPOINTER:
+ l = "#0x03";
+ break;
+
+ default:
+ /* this should never happen */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got unknown pointer type");
+ exit (1);
+ \v
+ }
+ aopPut (AOP (result), l, GPTRSIZE - 1);
+ goto release;
+ }
+
+ /* just copy the pointers */
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+ goto release;
}
- if (AOP_TYPE(right) == AOP_CRY) {
+ if (AOP_TYPE (right) == AOP_CRY)
+ {
int offset = 1;
- size = AOP_SIZE(right);
-
- emitcode("clrf","%s ; %d", aopGet(AOP(result),0,FALSE,FALSE),__LINE__);
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- emitcode("incf","%s,f", aopGet(AOP(result),0,FALSE,FALSE),__LINE__);
- while (size--) {
- emitcode("clrf","%s", aopGet(AOP(result),offset++,FALSE,FALSE),__LINE__);
- }
+ size = AOP_SIZE (right);
+
+ emitcode ("clrf", "%s ; %d", aopGet (AOP (result), 0, FALSE, FALSE), __LINE__);
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ emitcode ("incf", "%s,f", aopGet (AOP (result), 0, FALSE, FALSE), __LINE__);
+ while (size--)
+ {
+ emitcode ("clrf", "%s", aopGet (AOP (result), offset++, FALSE, FALSE), __LINE__);
+ }
goto release;
}
- /* so we now know that the size of destination is greater
- than the size of the source.
- Now, if the next iCode is an operator then we might be
- able to optimize the operation without performing a cast.
- */
- if(genMixedOperation(ic))
- goto release;
+ /* so we now know that the size of destination is greater
+ than the size of the source.
+ Now, if the next iCode is an operator then we might be
+ able to optimize the operation without performing a cast.
+ */
+ if (genMixedOperation (ic))
+ goto release;
- /* we move to result for the size of source */
- size = AOP_SIZE(right);
- offset = 0 ;
- while (size--) {
- emitcode(";","%d",__LINE__);
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
- }
-
- /* now depending on the sign of the destination */
- size = AOP_SIZE(result) - AOP_SIZE(right);
- /* if unsigned or not an integral type */
- if (SPEC_USIGN(ctype) || !IS_SPEC(ctype)) {
- while (size--)
- emitcode("clrf","%s",aopGet(AOP(result),offset++,FALSE,FALSE));
- } else {
+ /* we move to result for the size of source */
+ size = AOP_SIZE (right);
+ offset = 0;
+ while (size--)
+ {
+ emitcode (";", "%d", __LINE__);
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE, FALSE),
+ offset);
+ offset++;
+ }
+
+ /* now depending on the sign of the destination */
+ size = AOP_SIZE (result) - AOP_SIZE (right);
+ /* if unsigned or not an integral type */
+ if (SPEC_USIGN (ctype) || !IS_SPEC (ctype))
+ {
+ while (size--)
+ emitcode ("clrf", "%s", aopGet (AOP (result), offset++, FALSE, FALSE));
+ }
+ else
+ {
/* we need to extend the sign :{ */
//char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,FALSE,FALSE);
//MOVA(l);
- emitcode("clrw","");
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- emitcode("movlw","0xff");
- while (size--) {
- emitcode("movwf","%s",aopGet(AOP(result),offset++,FALSE,FALSE));
- // aopPut(AOP(result),"a",offset++);
- }
+ emitcode ("clrw", "");
+ emitcode ("btfsc", "(%s >> 3), (%s & 7)",
+ AOP (right)->aopu.aop_dir,
+ AOP (right)->aopu.aop_dir);
+ emitcode ("movlw", "0xff");
+ while (size--)
+ {
+ emitcode ("movwf", "%s", aopGet (AOP (result), offset++, FALSE, FALSE));
+ // aopPut(AOP(result),"a",offset++);
+ }
}
- /* we are done hurray !!!! */
+ /* we are done hurray !!!! */
release:
- freeAsmop(right,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop (right, NULL, ic, TRUE);
+ freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genDjnz - generate decrement & jump if not zero instrucion */
/*-----------------------------------------------------------------*/
-static int genDjnz (iCode *ic, iCode *ifx)
+static int
+genDjnz (iCode * ic, iCode * ifx)
{
- symbol *lbl, *lbl1;
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ symbol *lbl, *lbl1;
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- if (!ifx)
- return 0;
+ if (!ifx)
+ return 0;
- /* if the if condition has a false label
- then we cannot save */
- if (IC_FALSE(ifx))
- return 0;
+ /* if the if condition has a false label
+ then we cannot save */
+ if (IC_FALSE (ifx))
+ return 0;
- /* if the minus is not of the form
- a = a - 1 */
- if (!isOperandEqual(IC_RESULT(ic),IC_LEFT(ic)) ||
- !IS_OP_LITERAL(IC_RIGHT(ic)))
- return 0;
+ /* if the minus is not of the form
+ a = a - 1 */
+ if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
+ !IS_OP_LITERAL (IC_RIGHT (ic)))
+ return 0;
- if (operandLitValue(IC_RIGHT(ic)) != 1)
- return 0;
+ if (operandLitValue (IC_RIGHT (ic)) != 1)
+ return 0;
- /* if the size of this greater than one then no
- saving */
- if (getSize(operandType(IC_RESULT(ic))) > 1)
- return 0;
+ /* if the size of this greater than one then no
+ saving */
+ if (getSize (operandType (IC_RESULT (ic))) > 1)
+ return 0;
- /* otherwise we can save BIG */
- lbl = newiTempLabel(NULL);
- lbl1= newiTempLabel(NULL);
+ /* otherwise we can save BIG */
+ lbl = newiTempLabel (NULL);
+ lbl1 = newiTempLabel (NULL);
- aopOp(IC_RESULT(ic),ic,FALSE);
+ aopOp (IC_RESULT (ic), ic, FALSE);
- if (IS_AOP_PREG(IC_RESULT(ic))) {
- emitcode("dec","%s",
- aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- emitcode("mov","a,%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- emitcode("jnz","%05d_DS_",lbl->key+100);
- } else {
- emitcode("decfsz","%s,f",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- emitcode ("goto","_%05d_DS_",IC_TRUE(ifx)->key+100 + labelOffset);
+ if (IS_AOP_PREG (IC_RESULT (ic)))
+ {
+ emitcode ("dec", "%s",
+ aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ emitcode ("mov", "a,%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ emitcode ("jnz", "%05d_DS_", lbl->key + 100);
+ }
+ else
+ {
+ emitcode ("decfsz", "%s,f", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE));
+ emitcode ("goto", "_%05d_DS_", IC_TRUE (ifx)->key + 100 + labelOffset);
}
/* emitcode ("sjmp","%05d_DS_",lbl1->key+100); */
/* emitcode ("","%05d_DS_:",lbl1->key+100); */
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
- ifx->generated = 1;
- return 1;
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ ifx->generated = 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* genReceive - generate code for a receive iCode */
/*-----------------------------------------------------------------*/
-static void genReceive (iCode *ic)
+static void
+genReceive (iCode * ic)
{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGemitcode ("; ***", "%s %d", __FUNCTION__, __LINE__);
- if (isOperandInFarSpace(IC_RESULT(ic)) &&
- ( OP_SYMBOL(IC_RESULT(ic))->isspilt ||
- IS_TRUE_SYMOP(IC_RESULT(ic))) ) {
+ if (isOperandInFarSpace (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
+ IS_TRUE_SYMOP (IC_RESULT (ic))))
+ {
- int size = getSize(operandType(IC_RESULT(ic)));
- int offset = fReturnSize - size;
- while (size--) {
- emitcode ("push","%s", (strcmp(fReturn[fReturnSize - offset - 1],"a") ?
- fReturn[fReturnSize - offset - 1] : "acc"));
- offset++;
- }
- aopOp(IC_RESULT(ic),ic,FALSE);
- size = AOP_SIZE(IC_RESULT(ic));
- offset = 0;
- while (size--) {
- emitcode ("pop","acc");
- aopPut (AOP(IC_RESULT(ic)),"a",offset++);
- }
+ int size = getSize (operandType (IC_RESULT (ic)));
+ int offset = fReturnSize - size;
+ while (size--)
+ {
+ emitcode ("push", "%s", (strcmp (fReturn[fReturnSize - offset - 1], "a") ?
+ fReturn[fReturnSize - offset - 1] : "acc"));
+ offset++;
+ }
+ aopOp (IC_RESULT (ic), ic, 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);
- _G.accInUse--;
- assignResultValue(IC_RESULT(ic));
+ }
+ else
+ {
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE);
+ _G.accInUse--;
+ assignResultValue (IC_RESULT (ic));
}
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* genpic14Code - generate code for pic14 based controllers */
/*-----------------------------------------------------------------*/
-void genpic14Code (iCode *lic)
+void
+genpic14Code (iCode * lic)
{
- iCode *ic;
- int cln = 0;
+ iCode *ic;
+ int cln = 0;
- lineHead = lineCurr = NULL;
+ lineHead = lineCurr = NULL;
- /* if debug information required */
+ /* if debug information required */
/* if (options.debug && currFunc) { */
- if (currFunc) {
- cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
- _G.debugLine = 1;
- if (IS_STATIC(currFunc->etype))
- emitcode("",";F%s$%s$0$0 %d",moduleName,currFunc->name,__LINE__);
- else
- emitcode("",";G$%s$0$0 %d",currFunc->name,__LINE__);
- _G.debugLine = 0;
- }
-
-
- for (ic = lic ; ic ; ic = ic->next ) {
-
- DEBUGemitcode(";ic","");
- if ( cln != ic->lineno ) {
- if ( options.debug ) {
- _G.debugLine = 1;
- emitcode("",";C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),ic->lineno,
- ic->level,ic->block);
- _G.debugLine = 0;
- }
- emitcode(";","%s %d",ic->filename,ic->lineno);
- cln = ic->lineno ;
- }
- /* if the result is marked as
- spilt and rematerializable or code for
- this has already been generated then
- do nothing */
- if (resultRemat(ic) || ic->generated )
- continue ;
-
- /* depending on the operation */
- switch (ic->op) {
- case '!' :
- genNot(ic);
- break;
-
- case '~' :
- genCpl(ic);
- break;
-
- case UNARYMINUS:
- genUminus (ic);
- break;
-
- case IPUSH:
- genIpush (ic);
- break;
-
- case IPOP:
- /* IPOP happens only when trying to restore a
- spilt live range, if there is an ifx statement
- following this pop then the if statement might
- be using some of the registers being popped which
- would destory the contents of the register so
- we need to check for this condition and handle it */
- if (ic->next &&
- ic->next->op == IFX &&
- regsInCommon(IC_LEFT(ic),IC_COND(ic->next)))
- genIfx (ic->next,ic);
+ if (currFunc)
+ {
+ cdbSymbol (currFunc, cdbFile, FALSE, TRUE);
+ _G.debugLine = 1;
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", ";F%s$%s$0$0 %d", moduleName, currFunc->name, __LINE__);
else
- genIpop (ic);
- break;
-
- case CALL:
- genCall (ic);
- break;
-
- case PCALL:
- genPcall (ic);
- break;
-
- case FUNCTION:
- genFunction (ic);
- break;
-
- case ENDFUNCTION:
- genEndFunction (ic);
- break;
-
- case RETURN:
- genRet (ic);
- break;
-
- case LABEL:
- genLabel (ic);
- break;
-
- case GOTO:
- genGoto (ic);
- break;
-
- case '+' :
- genPlus (ic) ;
- break;
-
- case '-' :
- if ( ! genDjnz (ic,ifxForOp(IC_RESULT(ic),ic)))
- genMinus (ic);
- break;
-
- case '*' :
- genMult (ic);
- break;
-
- case '/' :
- genDiv (ic) ;
- break;
-
- case '%' :
- genMod (ic);
- break;
-
- case '>' :
- genCmpGt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case '<' :
- genCmpLt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case LE_OP:
- case GE_OP:
- case NE_OP:
-
- /* note these two are xlated by algebraic equivalence
- during parsing SDCC.y */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got '>=' or '<=' shouldn't have come here");
- break;
-
- case EQ_OP:
- genCmpEq (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case AND_OP:
- genAndOp (ic);
- break;
-
- case OR_OP:
- genOrOp (ic);
- break;
-
- case '^' :
- genXor (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ emitcode ("", ";G$%s$0$0 %d", currFunc->name, __LINE__);
+ _G.debugLine = 0;
+ }
- case '|' :
- genOr (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
- case BITWISEAND:
- genAnd (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ for (ic = lic; ic; ic = ic->next)
+ {
- case INLINEASM:
- genInline (ic);
- break;
+ DEBUGemitcode (";ic", "");
+ if (cln != ic->lineno)
+ {
+ if (options.debug)
+ {
+ _G.debugLine = 1;
+ emitcode ("", ";C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), ic->lineno,
+ ic->level, ic->block);
+ _G.debugLine = 0;
+ }
+ emitcode (";", "%s %d", ic->filename, ic->lineno);
+ cln = ic->lineno;
+ }
+ /* if the result is marked as
+ spilt and rematerializable or code for
+ this has already been generated then
+ do nothing */
+ if (resultRemat (ic) || ic->generated)
+ continue;
+
+ /* depending on the operation */
+ switch (ic->op)
+ {
+ case '!':
+ genNot (ic);
+ break;
+
+ case '~':
+ genCpl (ic);
+ break;
+
+ case UNARYMINUS:
+ genUminus (ic);
+ break;
+
+ case IPUSH:
+ genIpush (ic);
+ break;
+
+ case IPOP:
+ /* IPOP happens only when trying to restore a
+ spilt live range, if there is an ifx statement
+ following this pop then the if statement might
+ be using some of the registers being popped which
+ would destory the contents of the register so
+ we need to check for this condition and handle it */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
+ genIfx (ic->next, ic);
+ else
+ genIpop (ic);
+ break;
+
+ case CALL:
+ genCall (ic);
+ break;
+
+ case PCALL:
+ genPcall (ic);
+ break;
+
+ case FUNCTION:
+ genFunction (ic);
+ break;
+
+ case ENDFUNCTION:
+ genEndFunction (ic);
+ break;
+
+ case RETURN:
+ genRet (ic);
+ break;
+
+ case LABEL:
+ genLabel (ic);
+ break;
+
+ case GOTO:
+ genGoto (ic);
+ break;
+
+ case '+':
+ genPlus (ic);
+ break;
+
+ case '-':
+ if (!genDjnz (ic, ifxForOp (IC_RESULT (ic), ic)))
+ genMinus (ic);
+ break;
+
+ case '*':
+ genMult (ic);
+ break;
+
+ case '/':
+ genDiv (ic);
+ break;
+
+ case '%':
+ genMod (ic);
+ break;
+
+ case '>':
+ genCmpGt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '<':
+ genCmpLt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case LE_OP:
+ case GE_OP:
+ case NE_OP:
+
+ /* note these two are xlated by algebraic equivalence
+ during parsing SDCC.y */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got '>=' or '<=' shouldn't have come here");
+ break;
+
+ case EQ_OP:
+ genCmpEq (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case AND_OP:
+ genAndOp (ic);
+ break;
+
+ case OR_OP:
+ genOrOp (ic);
+ break;
+
+ case '^':
+ genXor (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '|':
+ genOr (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case BITWISEAND:
+ genAnd (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case INLINEASM:
+ genInline (ic);
+ break;
- case RRC:
- genRRC (ic);
- break;
+ case RRC:
+ genRRC (ic);
+ break;
- case RLC:
- genRLC (ic);
- break;
+ case RLC:
+ genRLC (ic);
+ break;
- case GETHBIT:
- genGetHbit (ic);
- break;
+ case GETHBIT:
+ genGetHbit (ic);
+ break;
- case LEFT_OP:
- genLeftShift (ic);
- break;
+ case LEFT_OP:
+ genLeftShift (ic);
+ break;
- case RIGHT_OP:
- genRightShift (ic);
- break;
+ case RIGHT_OP:
+ genRightShift (ic);
+ break;
- case GET_VALUE_AT_ADDRESS:
- genPointerGet(ic);
- break;
+ case GET_VALUE_AT_ADDRESS:
+ genPointerGet (ic);
+ break;
- case '=' :
- if (POINTER_SET(ic))
- genPointerSet(ic);
- else
- genAssign(ic);
- break;
+ case '=':
+ if (POINTER_SET (ic))
+ genPointerSet (ic);
+ else
+ genAssign (ic);
+ break;
- case IFX:
- genIfx (ic,NULL);
- break;
+ case IFX:
+ genIfx (ic, NULL);
+ break;
- case ADDRESS_OF:
- genAddrOf (ic);
- break;
+ case ADDRESS_OF:
+ genAddrOf (ic);
+ break;
- case JUMPTABLE:
- genJumpTab (ic);
- break;
+ case JUMPTABLE:
+ genJumpTab (ic);
+ break;
- case CAST:
- genCast (ic);
- break;
+ case CAST:
+ genCast (ic);
+ break;
- case RECEIVE:
- genReceive(ic);
- break;
+ case RECEIVE:
+ genReceive (ic);
+ break;
- case SEND:
- addSet(&_G.sendSet,ic);
- break;
+ case SEND:
+ addSet (&_G.sendSet, ic);
+ break;
- default :
- ic = ic;
- /* piCode(ic,stdout); */
+ default:
+ ic = ic;
+ /* piCode(ic,stdout); */
- }
+ }
}
- /* now we are ready to call the
- peep hole optimizer */
- if (!options.nopeep) {
- printf("peep hole optimizing\n");
- peepHole (&lineHead);
+ /* now we are ready to call the
+ peep hole optimizer */
+ if (!options.nopeep)
+ {
+ printf ("peep hole optimizing\n");
+ peepHole (&lineHead);
}
- /* now do the actual printing */
- printLine (lineHead,codeOutFile);
- return;
+ /* now do the actual printing */
+ printLine (lineHead, codeOutFile);
+ return;
}
#ifndef SDCCGENPIC14_H
#define SDCCGENPIC14_H
-enum {
+enum
+ {
AOP_LIT = 1,
- AOP_REG, AOP_DIR,
- AOP_DPTR, AOP_DPTR2, AOP_R0,AOP_R1,
- AOP_STK ,AOP_IMMD, AOP_STR,
- AOP_CRY, AOP_ACC };
+ AOP_REG, AOP_DIR,
+ AOP_DPTR, AOP_DPTR2, AOP_R0, AOP_R1,
+ AOP_STK, AOP_IMMD, AOP_STR,
+ AOP_CRY, AOP_ACC
+ };
/* type asmop : a homogenised type for
all the different spaces an operand can be
in */
-typedef struct asmop {
-
- short type ; /* can have values
- AOP_LIT - operand is a literal value
- AOP_REG - is in registers
- AOP_DIR - direct just a name
- AOP_DPTR - dptr contains address of operand
- AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
- AOP_R0/R1 - r0/r1 contains address of operand
- AOP_STK - should be pushed on stack this
- can happen only for the result
- AOP_IMMD - immediate value for eg. remateriazable
- AOP_CRY - carry contains the value of this
- AOP_STR - array of strings
- AOP_ACC - result is in the acc:b pair
- */
- short coff ; /* current offset */
- short size ; /* total size */
- unsigned code :1 ; /* is in Code space */
- unsigned paged:1 ; /* in paged memory */
- unsigned freed:1 ; /* already freed */
- union {
- value *aop_lit ; /* if literal */
- regs *aop_reg[4]; /* array of registers */
- char *aop_dir ; /* if direct */
- regs *aop_ptr ; /* either -> to r0 or r1 */
- char *aop_immd; /* if immediate others are implied */
- int aop_stk ; /* stack offset when AOP_STK */
- char *aop_str[4]; /* just a string array containing the location */
- } aopu;
-} asmop;
+typedef struct asmop
+ {
+
+ short type; /* can have values
+ AOP_LIT - operand is a literal value
+ AOP_REG - is in registers
+ AOP_DIR - direct just a name
+ AOP_DPTR - dptr contains address of operand
+ AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
+ AOP_R0/R1 - r0/r1 contains address of operand
+ AOP_STK - should be pushed on stack this
+ can happen only for the result
+ AOP_IMMD - immediate value for eg. remateriazable
+ AOP_CRY - carry contains the value of this
+ AOP_STR - array of strings
+ AOP_ACC - result is in the acc:b pair
+ */
+ short coff; /* current offset */
+ short size; /* total size */
+ unsigned code:1; /* is in Code space */
+ unsigned paged:1; /* in paged memory */
+ unsigned freed:1; /* already freed */
+ union
+ {
+ value *aop_lit; /* if literal */
+ regs *aop_reg[4]; /* array of registers */
+ char *aop_dir; /* if direct */
+ regs *aop_ptr; /* either -> to r0 or r1 */
+ char *aop_immd; /* if immediate others are implied */
+ int aop_stk; /* stack offset when AOP_STK */
+ char *aop_str[4]; /* just a string array containing the location */
+ }
+ aopu;
+ }
+asmop;
void genpic14Code (iCode *);
extern int noAlloc;
extern set *publics;
extern int maxInterrupts;
-extern int maxRegBank ;
+extern int maxRegBank;
extern symbol *mainf;
extern char *VersionString;
extern FILE *codeOutFile;
extern char *iComments2;
//extern void emitStaticSeg (memmap * map);
-extern DEFSETFUNC(closeTmpFiles);
-extern DEFSETFUNC(rmTmpFiles);
+extern DEFSETFUNC (closeTmpFiles);
+extern DEFSETFUNC (rmTmpFiles);
extern void copyFile (FILE * dest, FILE * src);
extern void printChar (FILE * ofile, char *s, int plen);
#if 0
-char *aopLiteral (value *val, int offset)
-static void emitRegularMap (memmap * map, bool addPublics, bool arFlag)
-value *initPointer (initList *ilist)
-void printIvalType (sym_link * type, initList * ilist, FILE * oFile)
-void printIvalStruct (symbol * sym,sym_link * type,
- initList * ilist, FILE * oFile)
-int printIvalChar (sym_link * type, initList * ilist, FILE * oFile, char *s)
-void printIvalArray (symbol * sym, sym_link * type, initList * ilist,
- FILE * oFile)
-void printIvalFuncPtr (sym_link * type, initList * ilist, FILE * oFile)
-int printIvalCharPtr (symbol * sym, sym_link * type, value * val, FILE * oFile)
-void printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
+char *
+aopLiteral (value * val, int offset)
+ static void emitRegularMap (memmap * map, bool addPublics, bool arFlag)
+ value *initPointer (initList * ilist)
+ void printIvalType (sym_link * type, initList * ilist, FILE * oFile)
+ void printIvalStruct (symbol * sym, sym_link * type,
+ initList * ilist, FILE * oFile)
+ int printIvalChar (sym_link * type, initList * ilist, FILE * oFile, char *s)
+ void printIvalArray (symbol * sym, sym_link * type, initList * ilist,
+ FILE * oFile)
+ void printIvalFuncPtr (sym_link * type, initList * ilist, FILE * oFile)
+ int printIvalCharPtr (symbol * sym, sym_link * type, value * val, FILE * oFile)
+ void printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
#endif
/*-----------------------------------------------------------------*/
/* aopLiteral - string from a literal value */
/*-----------------------------------------------------------------*/
-char *pic14aopLiteral (value *val, int offset)
+ char *pic14aopLiteral (value * val, int offset)
{
- char *rs;
- union {
- float f;
- unsigned char c[4];
- } fl;
-
- /* if it is a float then it gets tricky */
- /* otherwise it is fairly simple */
- if (!IS_FLOAT(val->type)) {
- unsigned long v = floatFromVal(val);
-
- v >>= (offset * 8);
- sprintf(buffer,"0x%02x",((char) v) & 0xff);
- rs = Safe_calloc(1,strlen(buffer)+1);
- return strcpy (rs,buffer);
+ char *rs;
+ union
+ {
+ float f;
+ unsigned char c[4];
}
+ fl;
+
+ /* if it is a float then it gets tricky */
+ /* otherwise it is fairly simple */
+ if (!IS_FLOAT (val->type))
+ {
+ unsigned long v = floatFromVal (val);
- /* it is type float */
- fl.f = (float) floatFromVal(val);
+ v >>= (offset * 8);
+ sprintf (buffer, "0x%02x", ((char) v) & 0xff);
+ rs = Safe_calloc (1, strlen (buffer) + 1);
+ return strcpy (rs, buffer);
+ }
+
+ /* it is type float */
+ fl.f = (float) floatFromVal (val);
#ifdef _BIG_ENDIAN
- sprintf(buffer,"0x%02x",fl.c[3-offset]);
+ sprintf (buffer, "0x%02x", fl.c[3 - offset]);
#else
- sprintf(buffer,"0x%02x",fl.c[offset]);
+ sprintf (buffer, "0x%02x", fl.c[offset]);
#endif
- rs = Safe_calloc(1,strlen(buffer)+1);
- return strcpy (rs,buffer);
+ rs = Safe_calloc (1, strlen (buffer) + 1);
+ return strcpy (rs, buffer);
}
/*-----------------------------------------------------------------*/
/* emitRegularMap - emit code for maps with no special cases */
/*-----------------------------------------------------------------*/
-static void pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
+static void
+pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
{
- symbol *sym;
- int i,size,bitvars=0;;
-
- if (addPublics)
- fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
-
- /* print the area name */
- for (sym = setFirstItem (map->syms); sym;
- sym = setNextItem (map->syms)) {
-
- /* if extern then do nothing */
- if (IS_EXTERN (sym->etype))
- continue;
-
- /* if allocation required check is needed
- then check if the symbol really requires
- allocation only for local variables */
- if (arFlag && !IS_AGGREGATE(sym->type) &&
- !(sym->_isparm && !IS_REGPARM(sym->etype)) &&
- !sym->allocreq && sym->level)
- continue ;
-
- /* if global variable & not static or extern
- and addPublics allowed then add it to the public set */
- if ((sym->level == 0 ||
- (sym->_isparm && !IS_REGPARM(sym->etype))) &&
- addPublics &&
- !IS_STATIC (sym->etype))
- addSetHead (&publics, sym);
-
- /* if extern then do nothing or is a function
- then do nothing */
- if (IS_FUNC (sym->type))
- continue;
-#if 0
- /* print extra debug info if required */
- if (options.debug || sym->level == 0) {
+ symbol *sym;
+ int i, size, bitvars = 0;;
- cdbSymbol(sym,cdbFile,FALSE,FALSE);
+ if (addPublics)
+ fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
- if (!sym->level) /* global */
- if (IS_STATIC(sym->etype))
- fprintf(map->oFile,"F%s_",moduleName); /* scope is file */
- else
- fprintf(map->oFile,"G_"); /* scope is global */
- else
- /* symbol is local */
- fprintf(map->oFile,"L%s_",(sym->localof ? sym->localof->name : "-null-"));
- fprintf(map->oFile,"%s_%d_%d",sym->name,sym->level,sym->block);
- }
-#endif
+ /* print the area name */
+ for (sym = setFirstItem (map->syms); sym;
+ sym = setNextItem (map->syms))
+ {
- /* if is has an absolute address then generate
- an equate for this no need to allocate space */
- if (SPEC_ABSA (sym->etype)) {
- //if (options.debug || sym->level == 0)
- //fprintf (map->oFile,"; == 0x%04x\n",SPEC_ADDR (sym->etype));
-
- fprintf (map->oFile, "%s\tEQU\t0x%04x\n",
- sym->rname,
- SPEC_ADDR (sym->etype));
- }
- else {
- /* allocate space */
-
- /* If this is a bit variable, then allocate storage after 8 bits have been declared */
- /* unlike the 8051, the pic does not have a separate bit area. So we emulate bit ram */
- /* by grouping the bits together into groups of 8 and storing them in the normal ram.*/
- if(IS_BITVAR(sym->etype)) {
- if((bitvars % 8) == 0) {
- fprintf (map->oFile, " cblock\n");
- fprintf (map->oFile, "\tbitfield%d\n", bitvars);
- fprintf (map->oFile, " endc\n");
- }
-
- fprintf (map->oFile, "%s\tEQU\t( (bitfield%d<<3)+%d)\n",
- sym->rname,
- bitvars & 0xfff8,
- bitvars & 0x0007);
-
- bitvars++;
- } else {
- fprintf (map->oFile, "\t%s\n", sym->rname);
- if( (size = (unsigned int)getSize (sym->type) & 0xffff)>1) {
- for(i=1; i<size; i++)
- fprintf (map->oFile, "\t%s_%d\n", sym->rname,i);
- }
- }
- //fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
- }
+ /* if extern then do nothing */
+ if (IS_EXTERN (sym->etype))
+ continue;
- /* if it has a initial value then do it only if
- it is a global variable */
- if (sym->ival && sym->level == 0) {
- ast *ival = NULL;
+ /* if allocation required check is needed
+ then check if the symbol really requires
+ allocation only for local variables */
+ if (arFlag && !IS_AGGREGATE (sym->type) &&
+ !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
+ !sym->allocreq && sym->level)
+ continue;
+
+ /* if global variable & not static or extern
+ and addPublics allowed then add it to the public set */
+ if ((sym->level == 0 ||
+ (sym->_isparm && !IS_REGPARM (sym->etype))) &&
+ addPublics &&
+ !IS_STATIC (sym->etype))
+ addSetHead (&publics, sym);
+
+ /* if extern then do nothing or is a function
+ then do nothing */
+ if (IS_FUNC (sym->type))
+ continue;
+#if 0
+ /* print extra debug info if required */
+ if (options.debug || sym->level == 0)
+ {
+
+ cdbSymbol (sym, cdbFile, FALSE, FALSE);
+
+ if (!sym->level) /* global */
+ if (IS_STATIC (sym->etype))
+ fprintf (map->oFile, "F%s_", moduleName); /* scope is file */
+ else
+ fprintf (map->oFile, "G_"); /* scope is global */
+ else
+ /* symbol is local */
+ fprintf (map->oFile, "L%s_", (sym->localof ? sym->localof->name : "-null-"));
+ fprintf (map->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
+ }
+#endif
- if (IS_AGGREGATE (sym->type))
- ival = initAggregates (sym, sym->ival, NULL);
+ /* if is has an absolute address then generate
+ an equate for this no need to allocate space */
+ if (SPEC_ABSA (sym->etype))
+ {
+ //if (options.debug || sym->level == 0)
+ //fprintf (map->oFile,"; == 0x%04x\n",SPEC_ADDR (sym->etype));
+
+ fprintf (map->oFile, "%s\tEQU\t0x%04x\n",
+ sym->rname,
+ SPEC_ADDR (sym->etype));
+ }
else
- ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
- decorateType (resolveSymbols (list2expr (sym->ival))));
- codeOutFile = statsg->oFile;
- eBBlockFromiCode (iCodeFromAst (ival));
- sym->ival = NULL;
- }
+ {
+ /* allocate space */
+
+ /* If this is a bit variable, then allocate storage after 8 bits have been declared */
+ /* unlike the 8051, the pic does not have a separate bit area. So we emulate bit ram */
+ /* by grouping the bits together into groups of 8 and storing them in the normal ram. */
+ if (IS_BITVAR (sym->etype))
+ {
+ if ((bitvars % 8) == 0)
+ {
+ fprintf (map->oFile, " cblock\n");
+ fprintf (map->oFile, "\tbitfield%d\n", bitvars);
+ fprintf (map->oFile, " endc\n");
+ }
+
+ fprintf (map->oFile, "%s\tEQU\t( (bitfield%d<<3)+%d)\n",
+ sym->rname,
+ bitvars & 0xfff8,
+ bitvars & 0x0007);
+
+ bitvars++;
+ }
+ else
+ {
+ fprintf (map->oFile, "\t%s\n", sym->rname);
+ if ((size = (unsigned int) getSize (sym->type) & 0xffff) > 1)
+ {
+ for (i = 1; i < size; i++)
+ fprintf (map->oFile, "\t%s_%d\n", sym->rname, i);
+ }
+ }
+ //fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
+ }
+
+ /* if it has a initial value then do it only if
+ it is a global variable */
+ if (sym->ival && sym->level == 0)
+ {
+ ast *ival = NULL;
+
+ if (IS_AGGREGATE (sym->type))
+ ival = initAggregates (sym, sym->ival, NULL);
+ else
+ ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
+ decorateType (resolveSymbols (list2expr (sym->ival))));
+ codeOutFile = statsg->oFile;
+ eBBlockFromiCode (iCodeFromAst (ival));
+ sym->ival = NULL;
+ }
}
}
/*-----------------------------------------------------------------*/
/* initPointer - pointer initialization code massaging */
/*-----------------------------------------------------------------*/
-value *initPointer (initList *ilist)
+value *
+initPointer (initList * ilist)
{
- value *val;
- ast *expr = list2expr(ilist);
-
- if (!expr)
- goto wrong;
-
- /* try it the oldway first */
- if ((val = constExprValue(expr,FALSE)))
- return val;
-
- /* no then we have to do these cludgy checks */
- /* pointers can be initialized with address of
- a variable or address of an array element */
- if (IS_AST_OP(expr) && expr->opval.op == '&') {
- /* address of symbol */
- if (IS_AST_SYM_VALUE(expr->left)) {
- val = copyValue(AST_VALUE(expr->left));
- val->type = newLink();
- if (SPEC_SCLS(expr->left->etype) == S_CODE) {
- DCL_TYPE(val->type) = CPOINTER ;
- DCL_PTR_CONST(val->type) = port->mem.code_ro;
- }
- else
- if (SPEC_SCLS(expr->left->etype) == S_XDATA)
- DCL_TYPE(val->type) = FPOINTER;
- else
- if (SPEC_SCLS(expr->left->etype) == S_XSTACK )
- DCL_TYPE(val->type) = PPOINTER ;
- else
- if (SPEC_SCLS(expr->left->etype) == S_IDATA)
- DCL_TYPE(val->type) = IPOINTER ;
- else
- if (SPEC_SCLS(expr->left->etype) == S_EEPROM)
- DCL_TYPE(val->type) = EEPPOINTER ;
- else
- DCL_TYPE(val->type) = POINTER ;
- val->type->next = expr->left->ftype;
- val->etype = getSpec(val->type);
- return val;
- }
-
- /* if address of indexed array */
- if (IS_AST_OP(expr->left) && expr->left->opval.op == '[')
- return valForArray(expr->left);
-
- /* if address of structure element then
- case 1. a.b ; */
- if (IS_AST_OP(expr->left) &&
- expr->left->opval.op == '.' ) {
- return valForStructElem(expr->left->left,
- expr->left->right);
- }
-
- /* case 2. (&a)->b ;
- (&some_struct)->element */
- if (IS_AST_OP(expr->left) &&
- expr->left->opval.op == PTR_OP &&
- IS_ADDRESS_OF_OP(expr->left->left))
- return valForStructElem(expr->left->left->left,
- expr->left->right);
+ value *val;
+ ast *expr = list2expr (ilist);
+
+ if (!expr)
+ goto wrong;
+
+ /* try it the oldway first */
+ if ((val = constExprValue (expr, FALSE)))
+ return val;
+
+ /* no then we have to do these cludgy checks */
+ /* pointers can be initialized with address of
+ a variable or address of an array element */
+ if (IS_AST_OP (expr) && expr->opval.op == '&')
+ {
+ /* address of symbol */
+ if (IS_AST_SYM_VALUE (expr->left))
+ {
+ val = copyValue (AST_VALUE (expr->left));
+ val->type = newLink ();
+ if (SPEC_SCLS (expr->left->etype) == S_CODE)
+ {
+ DCL_TYPE (val->type) = CPOINTER;
+ DCL_PTR_CONST (val->type) = port->mem.code_ro;
+ }
+ else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
+ DCL_TYPE (val->type) = FPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
+ DCL_TYPE (val->type) = PPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_IDATA)
+ DCL_TYPE (val->type) = IPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_EEPROM)
+ DCL_TYPE (val->type) = EEPPOINTER;
+ else
+ DCL_TYPE (val->type) = POINTER;
+ val->type->next = expr->left->ftype;
+ val->etype = getSpec (val->type);
+ return val;
+ }
+
+ /* if address of indexed array */
+ if (IS_AST_OP (expr->left) && expr->left->opval.op == '[')
+ return valForArray (expr->left);
+
+ /* if address of structure element then
+ case 1. a.b ; */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == '.')
+ {
+ return valForStructElem (expr->left->left,
+ expr->left->right);
+ }
+
+ /* case 2. (&a)->b ;
+ (&some_struct)->element */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == PTR_OP &&
+ IS_ADDRESS_OF_OP (expr->left->left))
+ return valForStructElem (expr->left->left->left,
+ expr->left->right);
}
- wrong:
- werror(E_INIT_WRONG);
- return NULL;
+wrong:
+ werror (E_INIT_WRONG);
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* printChar - formats and prints a characater string with DB */
/*-----------------------------------------------------------------*/
-void printChar (FILE * ofile, char *s, int plen)
+void
+printChar (FILE * ofile, char *s, int plen)
{
- int i;
- int len = strlen (s);
- int pplen = 0;
-
- while (len && pplen < plen) {
-
- fprintf (ofile, "\t.ascii /");
- i = 60;
- while (i && *s && pplen < plen) {
- if (*s < ' ' || *s == '/') {
- fprintf (ofile, "/\n\t.byte 0x%02x\n\t.ascii /", *s++);
- }
+ int i;
+ int len = strlen (s);
+ int pplen = 0;
+
+ while (len && pplen < plen)
+ {
+
+ fprintf (ofile, "\t.ascii /");
+ i = 60;
+ while (i && *s && pplen < plen)
+ {
+ if (*s < ' ' || *s == '/')
+ {
+ fprintf (ofile, "/\n\t.byte 0x%02x\n\t.ascii /", *s++);
+ }
+ else
+ fprintf (ofile, "%c", *s++);
+ pplen++;
+ i--;
+ }
+ fprintf (ofile, "/\n");
+
+ if (len > 60)
+ len -= 60;
else
- fprintf (ofile, "%c", *s++);
- pplen++;
- i--;
- }
- fprintf (ofile, "/\n");
-
- if (len > 60)
- len -= 60;
- else
- len = 0;
+ len = 0;
}
- if (pplen < plen)
- fprintf(ofile,"\t.byte\t0\n");
+ if (pplen < plen)
+ fprintf (ofile, "\t.byte\t0\n");
}
/*-----------------------------------------------------------------*/
/* printIvalType - generates ival for int/char */
/*-----------------------------------------------------------------*/
-void printIvalType (sym_link * type, initList * ilist, FILE * oFile)
+void
+printIvalType (sym_link * type, initList * ilist, FILE * oFile)
{
- value *val;
+ value *val;
- /* if initList is deep */
- if (ilist->type == INIT_DEEP)
- ilist = ilist->init.deep;
+ /* if initList is deep */
+ if (ilist->type == INIT_DEEP)
+ ilist = ilist->init.deep;
- val = list2val (ilist);
- switch (getSize (type)) {
+ val = list2val (ilist);
+ switch (getSize (type))
+ {
case 1:
- if (!val)
- fprintf (oFile, "\t.byte 0\n");
- else
- fprintf (oFile, "\t.byte %s\n",
- aopLiteral (val, 0));
- break;
+ if (!val)
+ fprintf (oFile, "\t.byte 0\n");
+ else
+ fprintf (oFile, "\t.byte %s\n",
+ aopLiteral (val, 0));
+ break;
case 2:
- if (!val)
- fprintf (oFile, "\t.word 0\n");
- else
- fprintf (oFile, "\t.byte %s,%s\n",
- aopLiteral (val, 0), aopLiteral (val, 1));
- break;
+ if (!val)
+ fprintf (oFile, "\t.word 0\n");
+ else
+ fprintf (oFile, "\t.byte %s,%s\n",
+ aopLiteral (val, 0), aopLiteral (val, 1));
+ break;
case 4:
- if (!val)
- fprintf (oFile, "\t.word 0,0\n");
- else
- fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
- aopLiteral (val, 0), aopLiteral (val, 1),
- aopLiteral (val, 2), aopLiteral (val, 3));
- break;
+ if (!val)
+ fprintf (oFile, "\t.word 0,0\n");
+ else
+ fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+ aopLiteral (val, 0), aopLiteral (val, 1),
+ aopLiteral (val, 2), aopLiteral (val, 3));
+ break;
}
- return;
+ return;
}
/*-----------------------------------------------------------------*/
/* printIvalStruct - generates initial value for structures */
/*-----------------------------------------------------------------*/
-void printIvalStruct (symbol * sym,sym_link * type,
- initList * ilist, FILE * oFile)
+void
+printIvalStruct (symbol * sym, sym_link * type,
+ initList * ilist, FILE * oFile)
{
- symbol *sflds;
- initList *iloop;
+ symbol *sflds;
+ initList *iloop;
- sflds = SPEC_STRUCT (type)->fields;
- if (ilist->type != INIT_DEEP) {
- werror (E_INIT_STRUCT, sym->name);
- return;
+ sflds = SPEC_STRUCT (type)->fields;
+ if (ilist->type != INIT_DEEP)
+ {
+ werror (E_INIT_STRUCT, sym->name);
+ return;
}
- iloop = ilist->init.deep;
+ iloop = ilist->init.deep;
- for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL))
- printIval (sflds, sflds->type, iloop, oFile);
+ for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL))
+ printIval (sflds, sflds->type, iloop, oFile);
- return;
+ return;
}
/*-----------------------------------------------------------------*/
/* printIvalChar - generates initital value for character array */
/*-----------------------------------------------------------------*/
-int printIvalChar (sym_link * type, initList * ilist, FILE * oFile, char *s)
+int
+printIvalChar (sym_link * type, initList * ilist, FILE * oFile, char *s)
{
- value *val;
- int remain;
+ value *val;
+ int remain;
- if (!s) {
+ if (!s)
+ {
- val = list2val (ilist);
- /* if the value is a character string */
- if (IS_ARRAY (val->type) && IS_CHAR (val->etype)) {
- if (!DCL_ELEM (type))
- DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
+ val = list2val (ilist);
+ /* if the value is a character string */
+ if (IS_ARRAY (val->type) && IS_CHAR (val->etype))
+ {
+ if (!DCL_ELEM (type))
+ DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
- /* if size mismatch */
+ /* if size mismatch */
/* if (DCL_ELEM (type) < ((int) strlen (SPEC_CVAL (val->etype).v_char) + 1)) */
/* werror (E_ARRAY_BOUND); */
- printChar (oFile, SPEC_CVAL (val->etype).v_char,DCL_ELEM(type));
+ printChar (oFile, SPEC_CVAL (val->etype).v_char, DCL_ELEM (type));
- if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) -1))>0)
- while (remain--)
- fprintf (oFile, "\t.byte 0\n");
+ if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0)
+ while (remain--)
+ fprintf (oFile, "\t.byte 0\n");
- return 1;
- }
- else
- return 0;
+ return 1;
+ }
+ else
+ return 0;
}
- else
- printChar (oFile, s,strlen(s)+1);
- return 1;
+ else
+ printChar (oFile, s, strlen (s) + 1);
+ return 1;
}
/*-----------------------------------------------------------------*/
/* printIvalArray - generates code for array initialization */
/*-----------------------------------------------------------------*/
-void printIvalArray (symbol * sym, sym_link * type, initList * ilist,
- FILE * oFile)
+void
+printIvalArray (symbol * sym, sym_link * type, initList * ilist,
+ FILE * oFile)
{
- initList *iloop;
- int lcnt = 0, size = 0;
-
- /* take care of the special case */
- /* array of characters can be init */
- /* by a string */
- if (IS_CHAR (type->next))
- if (printIvalChar (type,
- (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
- oFile, SPEC_CVAL (sym->etype).v_char))
+ initList *iloop;
+ int lcnt = 0, size = 0;
+
+ /* take care of the special case */
+ /* array of characters can be init */
+ /* by a string */
+ if (IS_CHAR (type->next))
+ if (printIvalChar (type,
+ (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
+ oFile, SPEC_CVAL (sym->etype).v_char))
return;
- /* not the special case */
- if (ilist->type != INIT_DEEP) {
- werror (E_INIT_STRUCT, sym->name);
- return;
+ /* not the special case */
+ if (ilist->type != INIT_DEEP)
+ {
+ werror (E_INIT_STRUCT, sym->name);
+ return;
}
- iloop = ilist->init.deep;
- lcnt = DCL_ELEM (type);
+ iloop = ilist->init.deep;
+ lcnt = DCL_ELEM (type);
- for (;;) {
- size++;
- printIval (sym, type->next, iloop, oFile);
- iloop = (iloop ? iloop->next : NULL);
+ for (;;)
+ {
+ size++;
+ printIval (sym, type->next, iloop, oFile);
+ iloop = (iloop ? iloop->next : NULL);
- /* if not array limits given & we */
- /* are out of initialisers then */
- if (!DCL_ELEM (type) && !iloop)
- break;
+ /* if not array limits given & we */
+ /* are out of initialisers then */
+ if (!DCL_ELEM (type) && !iloop)
+ break;
- /* no of elements given and we */
- /* have generated for all of them */
- if (!--lcnt)
- break;
+ /* no of elements given and we */
+ /* have generated for all of them */
+ if (!--lcnt)
+ break;
}
- /* if we have not been given a size */
- if (!DCL_ELEM (type))
- DCL_ELEM (type) = size;
+ /* if we have not been given a size */
+ if (!DCL_ELEM (type))
+ DCL_ELEM (type) = size;
- return;
+ return;
}
/*-----------------------------------------------------------------*/
/* printIvalFuncPtr - generate initial value for function pointers */
/*-----------------------------------------------------------------*/
-void printIvalFuncPtr (sym_link * type, initList * ilist, FILE * oFile)
+void
+printIvalFuncPtr (sym_link * type, initList * ilist, FILE * oFile)
{
- value *val;
- int dLvl = 0;
+ value *val;
+ int dLvl = 0;
- val = list2val (ilist);
- /* check the types */
- if ((dLvl = checkType (val->type, type->next)) <= 0) {
+ val = list2val (ilist);
+ /* check the types */
+ if ((dLvl = checkType (val->type, type->next)) <= 0)
+ {
- fprintf (oFile, "\t.word 0\n");
- return;
+ fprintf (oFile, "\t.word 0\n");
+ return;
}
- /* now generate the name */
- if (!val->sym) {
- if (IS_LITERAL (val->etype))
- fprintf (oFile, "\t.byte %s,%s\n",
- aopLiteral (val, 0), aopLiteral (val, 1));
- else
- fprintf (oFile, "\t.byte %s,(%s >> 8)\n",
- val->name, val->name);
+ /* now generate the name */
+ if (!val->sym)
+ {
+ if (IS_LITERAL (val->etype))
+ fprintf (oFile, "\t.byte %s,%s\n",
+ aopLiteral (val, 0), aopLiteral (val, 1));
+ else
+ fprintf (oFile, "\t.byte %s,(%s >> 8)\n",
+ val->name, val->name);
}
- else
- fprintf (oFile, "\t.byte %s,(%s >> 8)\n",
- val->sym->rname, val->sym->rname);
+ else
+ fprintf (oFile, "\t.byte %s,(%s >> 8)\n",
+ val->sym->rname, val->sym->rname);
- return;
+ return;
}
/*-----------------------------------------------------------------*/
/* printIvalCharPtr - generates initial values for character pointers */
/*-----------------------------------------------------------------*/
-int printIvalCharPtr (symbol * sym, sym_link * type, value * val, FILE * oFile)
+int
+printIvalCharPtr (symbol * sym, sym_link * type, value * val, FILE * oFile)
{
- int size = 0;
+ int size = 0;
- size = getSize (type);
+ size = getSize (type);
- if (size == 1)
- fprintf(oFile,
- "\t.byte %s", val->name) ;
- else
- fprintf (oFile,
- "\t.byte %s,(%s >> 8)",
- val->name, val->name);
+ if (size == 1)
+ fprintf (oFile,
+ "\t.byte %s", val->name);
+ else
+ fprintf (oFile,
+ "\t.byte %s,(%s >> 8)",
+ val->name, val->name);
- if (size > 2)
- fprintf (oFile, ",#0x02\n");
- else
- fprintf (oFile, "\n");
+ if (size > 2)
+ fprintf (oFile, ",#0x02\n");
+ else
+ fprintf (oFile, "\n");
- if (val->sym && val->sym->isstrlit)
- addSet (&statsg->syms, val->sym);
+ if (val->sym && val->sym->isstrlit)
+ addSet (&statsg->syms, val->sym);
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* printIvalPtr - generates initial value for pointers */
/*-----------------------------------------------------------------*/
-void printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
+void
+printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
{
- value *val;
+ value *val;
- /* if deep then */
- if (ilist->type == INIT_DEEP)
- ilist = ilist->init.deep;
+ /* if deep then */
+ if (ilist->type == INIT_DEEP)
+ ilist = ilist->init.deep;
- /* function pointer */
- if (IS_FUNC (type->next)) {
- printIvalFuncPtr (type, ilist, oFile);
- return;
+ /* function pointer */
+ if (IS_FUNC (type->next))
+ {
+ printIvalFuncPtr (type, ilist, oFile);
+ return;
}
- if (!(val = initPointer (ilist)))
- return ;
+ if (!(val = initPointer (ilist)))
+ return;
- /* if character pointer */
- if (IS_CHAR (type->next))
- if (printIvalCharPtr (sym, type, val, oFile))
+ /* if character pointer */
+ if (IS_CHAR (type->next))
+ if (printIvalCharPtr (sym, type, val, oFile))
return;
- /* check the type */
- if (checkType (type, val->type) != 1)
- werror (E_INIT_WRONG);
-
- /* if val is literal */
- if (IS_LITERAL (val->etype)) {
- switch (getSize (type)) {
- case 1:
- fprintf (oFile, "\t.byte 0x%02x\n", ((char) floatFromVal (val)) & 0xff);
- break;
- case 2:
- fprintf (oFile, "\t.byte %s,%s\n",
- aopLiteral (val, 0), aopLiteral (val, 1));
+ /* check the type */
+ if (checkType (type, val->type) != 1)
+ werror (E_INIT_WRONG);
- break;
- case 3:
- fprintf (oFile, "\t.byte %s,%s,0x%02x\n",
- aopLiteral (val, 0), aopLiteral (val, 1), CPOINTER);
- }
- return;
+ /* if val is literal */
+ if (IS_LITERAL (val->etype))
+ {
+ switch (getSize (type))
+ {
+ case 1:
+ fprintf (oFile, "\t.byte 0x%02x\n", ((char) floatFromVal (val)) & 0xff);
+ break;
+ case 2:
+ fprintf (oFile, "\t.byte %s,%s\n",
+ aopLiteral (val, 0), aopLiteral (val, 1));
+
+ break;
+ case 3:
+ fprintf (oFile, "\t.byte %s,%s,0x%02x\n",
+ aopLiteral (val, 0), aopLiteral (val, 1), CPOINTER);
+ }
+ return;
}
- switch (getSize (type)) {
+ switch (getSize (type))
+ {
case 1:
- fprintf (oFile, "\t.byte %s\n", val->name);
- break;
+ fprintf (oFile, "\t.byte %s\n", val->name);
+ break;
case 2:
- fprintf (oFile, "\t.byte %s,(%s >> 8)\n", val->name, val->name);
- break;
+ fprintf (oFile, "\t.byte %s,(%s >> 8)\n", val->name, val->name);
+ break;
case 3:
- fprintf (oFile, "\t.byte %s,(%s >> 8),0x%02x\n",
- val->name, val->name, DCL_TYPE(val->type));
+ fprintf (oFile, "\t.byte %s,(%s >> 8),0x%02x\n",
+ val->name, val->name, DCL_TYPE (val->type));
}
- return;
+ return;
}
/*-----------------------------------------------------------------*/
/* printIval - generates code for initial value */
/*-----------------------------------------------------------------*/
-void printIval (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
+void
+printIval (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
{
- if (!ilist)
- return;
+ if (!ilist)
+ return;
- /* if structure then */
- if (IS_STRUCT (type)) {
- printIvalStruct (sym, type, ilist, oFile);
- return;
+ /* if structure then */
+ if (IS_STRUCT (type))
+ {
+ printIvalStruct (sym, type, ilist, oFile);
+ return;
}
- /* if this is a pointer */
- if (IS_PTR (type)) {
- printIvalPtr (sym, type, ilist, oFile);
- return;
+ /* if this is a pointer */
+ if (IS_PTR (type))
+ {
+ printIvalPtr (sym, type, ilist, oFile);
+ return;
}
- /* if this is an array */
- if (IS_ARRAY (type)) {
- printIvalArray (sym, type, ilist, oFile);
- return;
+ /* if this is an array */
+ if (IS_ARRAY (type))
+ {
+ printIvalArray (sym, type, ilist, oFile);
+ return;
}
- /* if type is SPECIFIER */
- if (IS_SPEC (type)) {
- printIvalType (type, ilist, oFile);
- return;
+ /* if type is SPECIFIER */
+ if (IS_SPEC (type))
+ {
+ printIvalType (type, ilist, oFile);
+ return;
}
}
/*-----------------------------------------------------------------*/
/* emitStaticSeg - emitcode for the static segment */
/*-----------------------------------------------------------------*/
-static void pic14emitStaticSeg (memmap * map)
+static void
+pic14emitStaticSeg (memmap * map)
{
- symbol *sym;
-
- fprintf(map->oFile,";\t.area\t%s\n",map->sname);
-
+ symbol *sym;
- /* for all variables in this segment do */
- for (sym = setFirstItem (map->syms); sym;
- sym = setNextItem (map->syms)) {
+ fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
- /* if it is "extern" then do nothing */
- if (IS_EXTERN (sym->etype))
- continue;
- /* if it is not static add it to the public
- table */
- if (!IS_STATIC (sym->etype))
- addSetHead (&publics, sym);
-
- /* print extra debug info if required */
- if (options.debug || sym->level == 0) {
+ /* for all variables in this segment do */
+ for (sym = setFirstItem (map->syms); sym;
+ sym = setNextItem (map->syms))
+ {
- cdbSymbol(sym,cdbFile,FALSE,FALSE);
+ /* if it is "extern" then do nothing */
+ if (IS_EXTERN (sym->etype))
+ continue;
- if (!sym->level) { /* global */
- if (IS_STATIC(sym->etype))
- fprintf(code->oFile,"F%s_",moduleName); /* scope is file */
- else
- fprintf(code->oFile,"G_"); /* scope is global */
- }
- else
- /* symbol is local */
- fprintf(code->oFile,"L%s_",
- (sym->localof ? sym->localof->name : "-null-"));
- fprintf(code->oFile,"%s_%d_%d",sym->name,sym->level,sym->block);
- }
-
- /* if it has an absolute address */
- if (SPEC_ABSA (sym->etype)) {
- if (options.debug || sym->level == 0)
- fprintf(code->oFile," == 0x%04x\n", SPEC_ADDR (sym->etype));
+ /* if it is not static add it to the public
+ table */
+ if (!IS_STATIC (sym->etype))
+ addSetHead (&publics, sym);
- fprintf (code->oFile, "%s\t=\t0x%04x\n",
- sym->rname,
- SPEC_ADDR (sym->etype));
- }
- else {
+ /* print extra debug info if required */
if (options.debug || sym->level == 0)
- fprintf(code->oFile," == .\n");
-
- /* if it has an initial value */
- if (sym->ival) {
- fprintf (code->oFile, "%s:\n", sym->rname);
- noAlloc++;
- resolveIvalSym (sym->ival);
- printIval (sym, sym->type, sym->ival, code->oFile);
- noAlloc--;
- }
- else {
- /* allocate space */
- fprintf (code->oFile, "%s:\n", sym->rname);
- /* special case for character strings */
- if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
- SPEC_CVAL (sym->etype).v_char)
- printChar (code->oFile,
- SPEC_CVAL (sym->etype).v_char,
- strlen(SPEC_CVAL (sym->etype).v_char)+1);
- else
- fprintf (code->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type)& 0xffff);
- }
- }
+ {
+
+ cdbSymbol (sym, cdbFile, FALSE, FALSE);
+
+ if (!sym->level)
+ { /* global */
+ if (IS_STATIC (sym->etype))
+ fprintf (code->oFile, "F%s_", moduleName); /* scope is file */
+ else
+ fprintf (code->oFile, "G_"); /* scope is global */
+ }
+ else
+ /* symbol is local */
+ fprintf (code->oFile, "L%s_",
+ (sym->localof ? sym->localof->name : "-null-"));
+ fprintf (code->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
+ }
+
+ /* if it has an absolute address */
+ if (SPEC_ABSA (sym->etype))
+ {
+ if (options.debug || sym->level == 0)
+ fprintf (code->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+
+ fprintf (code->oFile, "%s\t=\t0x%04x\n",
+ sym->rname,
+ SPEC_ADDR (sym->etype));
+ }
+ else
+ {
+ if (options.debug || sym->level == 0)
+ fprintf (code->oFile, " == .\n");
+
+ /* if it has an initial value */
+ if (sym->ival)
+ {
+ fprintf (code->oFile, "%s:\n", sym->rname);
+ noAlloc++;
+ resolveIvalSym (sym->ival);
+ printIval (sym, sym->type, sym->ival, code->oFile);
+ noAlloc--;
+ }
+ else
+ {
+ /* allocate space */
+ fprintf (code->oFile, "%s:\n", sym->rname);
+ /* special case for character strings */
+ if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
+ SPEC_CVAL (sym->etype).v_char)
+ printChar (code->oFile,
+ SPEC_CVAL (sym->etype).v_char,
+ strlen (SPEC_CVAL (sym->etype).v_char) + 1);
+ else
+ fprintf (code->oFile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+ }
+ }
}
}
/*-----------------------------------------------------------------*/
/* emitMaps - emits the code for the data portion the code */
/*-----------------------------------------------------------------*/
-static void pic14emitMaps ()
+static void
+pic14emitMaps ()
{
- /* no special considerations for the following
- data, idata & bit & xdata */
- pic14emitRegularMap (data, TRUE, TRUE);
- pic14emitRegularMap (idata, TRUE,TRUE);
- pic14emitRegularMap (bit, TRUE,FALSE);
- pic14emitRegularMap (xdata, TRUE,TRUE);
- pic14emitRegularMap (sfr, FALSE,FALSE);
- pic14emitRegularMap (sfrbit, FALSE,FALSE);
- pic14emitRegularMap (code, TRUE,FALSE);
- pic14emitStaticSeg (statsg);
+ /* no special considerations for the following
+ data, idata & bit & xdata */
+ pic14emitRegularMap (data, TRUE, TRUE);
+ pic14emitRegularMap (idata, TRUE, TRUE);
+ pic14emitRegularMap (bit, TRUE, FALSE);
+ pic14emitRegularMap (xdata, TRUE, TRUE);
+ pic14emitRegularMap (sfr, FALSE, FALSE);
+ pic14emitRegularMap (sfrbit, FALSE, FALSE);
+ pic14emitRegularMap (code, TRUE, FALSE);
+ pic14emitStaticSeg (statsg);
}
/*-----------------------------------------------------------------*/
/* createInterruptVect - creates the interrupt vector */
/*-----------------------------------------------------------------*/
-static void pic14createInterruptVect (FILE * vFile)
+static void
+pic14createInterruptVect (FILE * vFile)
{
- int i = 0;
- mainf = newSymbol ("main", 0);
- mainf->block = 0;
-
- /* only if the main function exists */
- if (!(mainf = findSymWithLevel (SymbolTab, mainf))) {
- if (!options.cc_only)
- werror(E_NO_MAIN);
- return;
+ int i = 0;
+ mainf = newSymbol ("main", 0);
+ mainf->block = 0;
+
+ /* only if the main function exists */
+ if (!(mainf = findSymWithLevel (SymbolTab, mainf)))
+ {
+ if (!options.cc_only)
+ werror (E_NO_MAIN);
+ return;
}
- /* if the main is only a prototype ie. no body then do nothing */
- if (!mainf->fbody) {
- /* if ! compile only then main function should be present */
- if (!options.cc_only)
- werror(E_NO_MAIN);
- return;
+ /* if the main is only a prototype ie. no body then do nothing */
+ if (!mainf->fbody)
+ {
+ /* if ! compile only then main function should be present */
+ if (!options.cc_only)
+ werror (E_NO_MAIN);
+ return;
}
- fprintf (vFile, ";\t.area\t%s\n", CODE_NAME);
- fprintf (vFile, ";__interrupt_vect:\n");
+ fprintf (vFile, ";\t.area\t%s\n", CODE_NAME);
+ fprintf (vFile, ";__interrupt_vect:\n");
- if (!port->genIVT || ! (port->genIVT(vFile, interrupts, maxInterrupts)))
+ if (!port->genIVT || !(port->genIVT (vFile, interrupts, maxInterrupts)))
{
- /* "generic" interrupt table header (if port doesn't specify one).
- *
- * Look suspiciously like 8051 code to me...
- */
+ /* "generic" interrupt table header (if port doesn't specify one).
+
+ * Look suspiciously like 8051 code to me...
+ */
fprintf (vFile, ";\tljmp\t__sdcc_gsinit_startup\n");
/* now for the other interrupts */
- for (; i < maxInterrupts; i++) {
- if (interrupts[i])
- fprintf (vFile, ";\tljmp\t%s\n\t.ds\t5\n", interrupts[i]->rname);
- else
- fprintf (vFile, ";\treti\n;\t.ds\t7\n");
- }
+ for (; i < maxInterrupts; i++)
+ {
+ if (interrupts[i])
+ fprintf (vFile, ";\tljmp\t%s\n\t.ds\t5\n", interrupts[i]->rname);
+ else
+ fprintf (vFile, ";\treti\n;\t.ds\t7\n");
+ }
}
}
/*-----------------------------------------------------------------*/
/* initialComments - puts in some initial comments */
/*-----------------------------------------------------------------*/
-static void pic14initialComments (FILE * afile)
+static void
+pic14initialComments (FILE * afile)
{
- initialComments(afile);
- fprintf (afile, "; PIC port for the 14-bit core\n" );
+ initialComments (afile);
+ fprintf (afile, "; PIC port for the 14-bit core\n");
fprintf (afile, iComments2);
}
/*-----------------------------------------------------------------*/
/* printPublics - generates .global for publics */
/*-----------------------------------------------------------------*/
-static void pic14printPublics (FILE * afile)
+static void
+pic14printPublics (FILE * afile)
{
- symbol *sym;
+ symbol *sym;
- fprintf (afile, "%s", iComments2);
- fprintf (afile, "; publics variables in this module\n");
- fprintf (afile, "%s", iComments2);
+ fprintf (afile, "%s", iComments2);
+ fprintf (afile, "; publics variables in this module\n");
+ fprintf (afile, "%s", iComments2);
- for (sym = setFirstItem (publics); sym;
- sym = setNextItem (publics))
- fprintf (afile, ";\t.globl %s\n", sym->rname);
+ for (sym = setFirstItem (publics); sym;
+ sym = setNextItem (publics))
+ fprintf (afile, ";\t.globl %s\n", sym->rname);
}
/*-----------------------------------------------------------------*/
/* emitOverlay - will emit code for the overlay stuff */
/*-----------------------------------------------------------------*/
-static void pic14emitOverlay(FILE *afile)
+static void
+pic14emitOverlay (FILE * afile)
{
- set *ovrset;
-
- if (!elementsInSet(ovrSetSets))
- fprintf(afile,";\t.area\t%s\n", port->mem.overlay_name);
-
- /* for each of the sets in the overlay segment do */
- for (ovrset = setFirstItem(ovrSetSets); ovrset;
- ovrset = setNextItem(ovrSetSets)) {
-
- symbol *sym ;
-
- if (elementsInSet(ovrset)) {
- /* this dummy area is used to fool the assembler
- otherwise the assembler will append each of these
- declarations into one chunk and will not overlay
- sad but true */
- fprintf(afile,";\t.area _DUMMY\n");
- /* output the area informtion */
- fprintf(afile,";\t.area\t%s\n", port->mem.overlay_name); /* MOF */
- }
-
- for (sym = setFirstItem(ovrset); sym;
- sym = setNextItem(ovrset)) {
-
- /* if extern then do nothing */
- if (IS_EXTERN (sym->etype))
- continue;
-
- /* if allocation required check is needed
- then check if the symbol really requires
- allocation only for local variables */
- if (!IS_AGGREGATE(sym->type) &&
- !(sym->_isparm && !IS_REGPARM(sym->etype))
- && !sym->allocreq && sym->level)
- continue ;
-
- /* if global variable & not static or extern
- and addPublics allowed then add it to the public set */
- if ((sym->_isparm && !IS_REGPARM(sym->etype))
- && !IS_STATIC (sym->etype))
- addSetHead (&publics, sym);
+ set *ovrset;
- /* if extern then do nothing or is a function
- then do nothing */
- if (IS_FUNC (sym->type))
- continue;
-
- /* print extra debug info if required */
- if (options.debug || sym->level == 0) {
-
- cdbSymbol(sym,cdbFile,FALSE,FALSE);
-
- if (!sym->level) { /* global */
- if (IS_STATIC(sym->etype))
- fprintf(afile,"F%s_",moduleName); /* scope is file */
- else
- fprintf(afile,"G_"); /* scope is global */
- }
- else
- /* symbol is local */
- fprintf(afile,"L%s_",
- (sym->localof ? sym->localof->name : "-null-"));
- fprintf(afile,"%s_%d_%d",sym->name,sym->level,sym->block);
- }
-
- /* if is has an absolute address then generate
- an equate for this no need to allocate space */
- if (SPEC_ABSA (sym->etype)) {
-
- if (options.debug || sym->level == 0)
- fprintf (afile," == 0x%04x\n",SPEC_ADDR (sym->etype));
-
- fprintf (afile, "%s\t=\t0x%04x\n",
- sym->rname,
- SPEC_ADDR (sym->etype));
- }
- else {
- if (options.debug || sym->level == 0)
- fprintf(afile,"==.\n");
+ if (!elementsInSet (ovrSetSets))
+ fprintf (afile, ";\t.area\t%s\n", port->mem.overlay_name);
- /* allocate space */
- fprintf (afile, "%s:\n", sym->rname);
- fprintf (afile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
- }
+ /* for each of the sets in the overlay segment do */
+ for (ovrset = setFirstItem (ovrSetSets); ovrset;
+ ovrset = setNextItem (ovrSetSets))
+ {
- }
+ symbol *sym;
+
+ if (elementsInSet (ovrset))
+ {
+ /* this dummy area is used to fool the assembler
+ otherwise the assembler will append each of these
+ declarations into one chunk and will not overlay
+ sad but true */
+ fprintf (afile, ";\t.area _DUMMY\n");
+ /* output the area informtion */
+ fprintf (afile, ";\t.area\t%s\n", port->mem.overlay_name); /* MOF */
+ }
+
+ for (sym = setFirstItem (ovrset); sym;
+ sym = setNextItem (ovrset))
+ {
+
+ /* if extern then do nothing */
+ if (IS_EXTERN (sym->etype))
+ continue;
+
+ /* if allocation required check is needed
+ then check if the symbol really requires
+ allocation only for local variables */
+ if (!IS_AGGREGATE (sym->type) &&
+ !(sym->_isparm && !IS_REGPARM (sym->etype))
+ && !sym->allocreq && sym->level)
+ continue;
+
+ /* if global variable & not static or extern
+ and addPublics allowed then add it to the public set */
+ if ((sym->_isparm && !IS_REGPARM (sym->etype))
+ && !IS_STATIC (sym->etype))
+ addSetHead (&publics, sym);
+
+ /* if extern then do nothing or is a function
+ then do nothing */
+ if (IS_FUNC (sym->type))
+ continue;
+
+ /* print extra debug info if required */
+ if (options.debug || sym->level == 0)
+ {
+
+ cdbSymbol (sym, cdbFile, FALSE, FALSE);
+
+ if (!sym->level)
+ { /* global */
+ if (IS_STATIC (sym->etype))
+ fprintf (afile, "F%s_", moduleName); /* scope is file */
+ else
+ fprintf (afile, "G_"); /* scope is global */
+ }
+ else
+ /* symbol is local */
+ fprintf (afile, "L%s_",
+ (sym->localof ? sym->localof->name : "-null-"));
+ fprintf (afile, "%s_%d_%d", sym->name, sym->level, sym->block);
+ }
+
+ /* if is has an absolute address then generate
+ an equate for this no need to allocate space */
+ if (SPEC_ABSA (sym->etype))
+ {
+
+ if (options.debug || sym->level == 0)
+ fprintf (afile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+
+ fprintf (afile, "%s\t=\t0x%04x\n",
+ sym->rname,
+ SPEC_ADDR (sym->etype));
+ }
+ else
+ {
+ if (options.debug || sym->level == 0)
+ fprintf (afile, "==.\n");
+
+ /* allocate space */
+ fprintf (afile, "%s:\n", sym->rname);
+ fprintf (afile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+ }
+
+ }
}
}
/*-----------------------------------------------------------------*/
/* glue - the final glue that hold the whole thing together */
/*-----------------------------------------------------------------*/
-void pic14glue ()
+void
+pic14glue ()
{
- FILE *vFile;
- FILE *asmFile;
- FILE *ovrFile = tempfile();
- int i;
-
- addSetHead(&tmpfileSet,ovrFile);
- /* print the global struct definitions */
- if (options.debug)
- cdbStructBlock (0,cdbFile);
-
- vFile = tempfile();
- /* PENDING: this isnt the best place but it will do */
- if (port->general.glue_up_main) {
- /* create the interrupt vector table */
- pic14createInterruptVect (vFile);
+ FILE *vFile;
+ FILE *asmFile;
+ FILE *ovrFile = tempfile ();
+ int i;
+
+ addSetHead (&tmpfileSet, ovrFile);
+ /* print the global struct definitions */
+ if (options.debug)
+ cdbStructBlock (0, cdbFile);
+
+ vFile = tempfile ();
+ /* PENDING: this isnt the best place but it will do */
+ if (port->general.glue_up_main)
+ {
+ /* create the interrupt vector table */
+ pic14createInterruptVect (vFile);
}
- addSetHead(&tmpfileSet,vFile);
+ addSetHead (&tmpfileSet, vFile);
- /* emit code for the all the variables declared */
- pic14emitMaps ();
- /* do the overlay segments */
- pic14emitOverlay(ovrFile);
+ /* emit code for the all the variables declared */
+ pic14emitMaps ();
+ /* do the overlay segments */
+ pic14emitOverlay (ovrFile);
- /* now put it all together into the assembler file */
- /* create the assembler file name */
+ /* now put it all together into the assembler file */
+ /* create the assembler file name */
- if (!options.c1mode) {
- sprintf (buffer, srcFileName);
- strcat (buffer, ".asm");
+ if (!options.c1mode)
+ {
+ sprintf (buffer, srcFileName);
+ strcat (buffer, ".asm");
}
- else {
- strcpy(buffer, options.out_name);
+ else
+ {
+ strcpy (buffer, options.out_name);
}
- if (!(asmFile = fopen (buffer, "w"))) {
- werror (E_FILE_OPEN_ERR, buffer);
- exit (1);
+ if (!(asmFile = fopen (buffer, "w")))
+ {
+ werror (E_FILE_OPEN_ERR, buffer);
+ exit (1);
}
- /* initial comments */
- pic14initialComments (asmFile);
+ /* initial comments */
+ pic14initialComments (asmFile);
- /* print module name */
- fprintf (asmFile, ";\t.module %s\n", moduleName);
+ /* print module name */
+ fprintf (asmFile, ";\t.module %s\n", moduleName);
- /* Let the port generate any global directives, etc. */
- if (port->genAssemblerPreamble)
+ /* Let the port generate any global directives, etc. */
+ if (port->genAssemblerPreamble)
{
- port->genAssemblerPreamble(asmFile);
+ port->genAssemblerPreamble (asmFile);
}
- /* print the global variables in this module */
- pic14printPublics (asmFile);
+ /* print the global variables in this module */
+ pic14printPublics (asmFile);
- /* copy the sfr segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; special function registers\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfr->oFile);
+ /* copy the sfr segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; special function registers\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, sfr->oFile);
- /* Put all variables into a cblock */
- fprintf (asmFile, "\n\n\tcblock 0x13\n\n");
+ /* Put all variables into a cblock */
+ fprintf (asmFile, "\n\n\tcblock 0x13\n\n");
- for(i=0; i<pic14_nRegs; i++) {
- if(regspic14[i].wasUsed && (regspic14[i].offset>=0x0c) )
- fprintf (asmFile, "\t%s\n",regspic14[i].name);
+ for (i = 0; i < pic14_nRegs; i++)
+ {
+ if (regspic14[i].wasUsed && (regspic14[i].offset >= 0x0c))
+ fprintf (asmFile, "\t%s\n", regspic14[i].name);
}
- //fprintf (asmFile, "\tr0x0C\n");
- //fprintf (asmFile, "\tr0x0D\n");
+ //fprintf (asmFile, "\tr0x0C\n");
+ //fprintf (asmFile, "\tr0x0D\n");
- /* For now, create a "dpl" and a "dph" in the register space */
- /* of the pic so that we can use the same calling mechanism */
- /* as the 8051 port */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; dpl and dph to emulate the 8051 calling mechanism \n");
- fprintf (asmFile, "%s", iComments2);
-
- fprintf (asmFile, "\tdph\n");
+ /* For now, create a "dpl" and a "dph" in the register space */
+ /* of the pic so that we can use the same calling mechanism */
+ /* as the 8051 port */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; dpl and dph to emulate the 8051 calling mechanism \n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "\tdph\n");
- /* copy the sbit segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; special function bits \n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, sfrbit->oFile);
- /* copy the data segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; internal ram data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, data->oFile);
+ /* copy the sbit segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; special function bits \n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, sfrbit->oFile);
+ /* copy the data segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; internal ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, data->oFile);
- /* create the overlay segments */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; overlayable items in internal ram \n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, ovrFile);
- /* create the stack segment MOF */
- if (mainf && mainf->fbody) {
+ /* create the overlay segments */
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; Stack segment in internal ram \n");
+ fprintf (asmFile, "; overlayable items in internal ram \n");
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, ";\t.area\tSSEG\t(DATA)\n"
- ";__start__stack:\n;\t.ds\t1\n\n");
- }
+ copyFile (asmFile, ovrFile);
- /* create the idata segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; indirectly addressable internal ram data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, idata->oFile);
+ /* create the stack segment MOF */
+ if (mainf && mainf->fbody)
+ {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; Stack segment in internal ram \n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, ";\t.area\tSSEG\t(DATA)\n"
+ ";__start__stack:\n;\t.ds\t1\n\n");
+ }
- /* if external stack then reserve space of it */
- if (mainf && mainf->fbody && options.useXstack ) {
+ /* create the idata segment */
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; external stack \n");
+ fprintf (asmFile, "; indirectly addressable internal ram data\n");
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile,";\t.area XSEG (XDATA)\n"); /* MOF */
- fprintf (asmFile,";\t.ds 256\n");
+ copyFile (asmFile, idata->oFile);
+
+ /* if external stack then reserve space of it */
+ if (mainf && mainf->fbody && options.useXstack)
+ {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; external stack \n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, ";\t.area XSEG (XDATA)\n"); /* MOF */
+ fprintf (asmFile, ";\t.ds 256\n");
}
- /* copy xtern ram data */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; external ram data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, xdata->oFile);
+ /* copy xtern ram data */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; external ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, xdata->oFile);
+
+ fprintf (asmFile, "\tendc\n");
- fprintf (asmFile, "\tendc\n");
+ /* copy the bit segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; bit data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, bit->oFile);
- /* copy the bit segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; bit data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, bit->oFile);
+ fprintf (asmFile, "\tORG 0\n");
- fprintf (asmFile, "\tORG 0\n");
+ /* copy the interrupt vector table */
+ if (mainf && mainf->fbody)
+ {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; interrupt vector \n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, vFile);
+ }
- /* copy the interrupt vector table */
- if (mainf && mainf->fbody) {
+ /* copy global & static initialisations */
fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; interrupt vector \n");
+ fprintf (asmFile, "; global & static initialisations\n");
fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, vFile);
- }
- /* copy global & static initialisations */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; global & static initialisations\n");
- fprintf (asmFile, "%s", iComments2);
-
- /* Everywhere we generate a reference to the static_name area,
- * (which is currently only here), we immediately follow it with a
- * definition of the post_static_name area. This guarantees that
- * the post_static_name area will immediately follow the static_name
- * area.
- */
- fprintf (asmFile, ";\t.area %s\n", port->mem.static_name); /* MOF */
- fprintf (asmFile, ";\t.area %s\n", port->mem.post_static_name);
- fprintf (asmFile, ";\t.area %s\n", port->mem.static_name);
-
- if (mainf && mainf->fbody) {
- fprintf (asmFile,"__sdcc_gsinit_startup:\n");
- /* if external stack is specified then the
- higher order byte of the xdatalocation is
- going into P2 and the lower order going into
- spx */
- if (options.useXstack) {
- fprintf(asmFile,";\tmov\tP2,#0x%02x\n",
- (((unsigned int)options.xdata_loc) >> 8) & 0xff);
- fprintf(asmFile,";\tmov\t_spx,#0x%02x\n",
- (unsigned int)options.xdata_loc & 0xff);
- }
-
- /* initialise the stack pointer */
- /* if the user specified a value then use it */
- if (options.stack_loc)
- fprintf(asmFile,";\tmov\tsp,#%d\n",options.stack_loc);
- else
- /* no: we have to compute it */
+ /* Everywhere we generate a reference to the static_name area,
+ * (which is currently only here), we immediately follow it with a
+ * definition of the post_static_name area. This guarantees that
+ * the post_static_name area will immediately follow the static_name
+ * area.
+ */
+ fprintf (asmFile, ";\t.area %s\n", port->mem.static_name); /* MOF */
+ fprintf (asmFile, ";\t.area %s\n", port->mem.post_static_name);
+ fprintf (asmFile, ";\t.area %s\n", port->mem.static_name);
+
+ if (mainf && mainf->fbody)
+ {
+ fprintf (asmFile, "__sdcc_gsinit_startup:\n");
+ /* if external stack is specified then the
+ higher order byte of the xdatalocation is
+ going into P2 and the lower order going into
+ spx */
+ if (options.useXstack)
+ {
+ fprintf (asmFile, ";\tmov\tP2,#0x%02x\n",
+ (((unsigned int) options.xdata_loc) >> 8) & 0xff);
+ fprintf (asmFile, ";\tmov\t_spx,#0x%02x\n",
+ (unsigned int) options.xdata_loc & 0xff);
+ }
+
+ /* initialise the stack pointer */
+ /* if the user specified a value then use it */
+ if (options.stack_loc)
+ fprintf (asmFile, ";\tmov\tsp,#%d\n", options.stack_loc);
+ else
+ /* no: we have to compute it */
if (!options.stackOnData && maxRegBank <= 3)
- fprintf(asmFile,";\tmov\tsp,#%d\n",((maxRegBank + 1) * 8) -1);
+ fprintf (asmFile, ";\tmov\tsp,#%d\n", ((maxRegBank + 1) * 8) - 1);
else
- fprintf(asmFile,";\tmov\tsp,#__start__stack\n"); /* MOF */
+ fprintf (asmFile, ";\tmov\tsp,#__start__stack\n"); /* MOF */
- fprintf (asmFile,";\tlcall\t__sdcc_external_startup\n");
- fprintf (asmFile,";\tmov\ta,dpl\n");
- fprintf (asmFile,";\tjz\t__sdcc_init_data\n");
- fprintf (asmFile,";\tljmp\t__sdcc_program_startup\n");
- fprintf (asmFile,";__sdcc_init_data:\n");
+ fprintf (asmFile, ";\tlcall\t__sdcc_external_startup\n");
+ fprintf (asmFile, ";\tmov\ta,dpl\n");
+ fprintf (asmFile, ";\tjz\t__sdcc_init_data\n");
+ fprintf (asmFile, ";\tljmp\t__sdcc_program_startup\n");
+ fprintf (asmFile, ";__sdcc_init_data:\n");
}
- copyFile (asmFile, statsg->oFile);
+ copyFile (asmFile, statsg->oFile);
- if (port->general.glue_up_main && mainf && mainf->fbody)
+ if (port->general.glue_up_main && mainf && mainf->fbody)
{
- /* This code is generated in the post-static area.
- * This area is guaranteed to follow the static area
- * by the ugly shucking and jiving about 20 lines ago.
- */
- fprintf(asmFile, ";\t.area %s\n", port->mem.post_static_name);
- fprintf (asmFile,";\tljmp\t__sdcc_program_startup\n");
+ /* This code is generated in the post-static area.
+ * This area is guaranteed to follow the static area
+ * by the ugly shucking and jiving about 20 lines ago.
+ */
+ fprintf (asmFile, ";\t.area %s\n", port->mem.post_static_name);
+ fprintf (asmFile, ";\tljmp\t__sdcc_program_startup\n");
}
- /* copy over code */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; code\n");
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, ";\t.area %s\n", port->mem.code_name);
- if (mainf && mainf->fbody) {
+ /* copy over code */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; code\n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, ";\t.area %s\n", port->mem.code_name);
+ if (mainf && mainf->fbody)
+ {
- /* entry point @ start of CSEG */
- fprintf (asmFile,"__sdcc_program_startup:\n");
+ /* entry point @ start of CSEG */
+ fprintf (asmFile, "__sdcc_program_startup:\n");
- /* put in the call to main */
- fprintf(asmFile,"\tcall\t_main\n");
- if (options.mainreturn) {
+ /* put in the call to main */
+ fprintf (asmFile, "\tcall\t_main\n");
+ if (options.mainreturn)
+ {
- fprintf(asmFile,";\treturn from main ; will return to caller\n");
- fprintf(asmFile,"\treturn\n");
+ fprintf (asmFile, ";\treturn from main ; will return to caller\n");
+ fprintf (asmFile, "\treturn\n");
- } else {
+ }
+ else
+ {
- fprintf(asmFile,";\treturn from main will lock up\n");
- fprintf(asmFile,"\tgoto\t$\n");
- }
+ fprintf (asmFile, ";\treturn from main will lock up\n");
+ fprintf (asmFile, "\tgoto\t$\n");
+ }
}
- copyFile (asmFile, code->oFile);
+ copyFile (asmFile, code->oFile);
- fprintf (asmFile,"\tend\n");
+ fprintf (asmFile, "\tend\n");
- fclose (asmFile);
- applyToSet(tmpfileSet,closeTmpFiles);
- applyToSet(tmpfileNameSet, rmTmpFiles);
+ fclose (asmFile);
+ applyToSet (tmpfileSet, closeTmpFiles);
+ applyToSet (tmpfileNameSet, rmTmpFiles);
}
#ifndef SDCCGLUE_H
#define SDCCGLUE_H 1
-void glue();
+void glue ();
/* drdani Jan 30 2000
- This is needed in gen.c of z80 port */
+ This is needed in gen.c of z80 port */
char *aopLiteral (value *, int);
#endif
};
/* list of key words used by msc51 */
-static char *_pic14_keywords[] = {
- "at",
- "bit",
- "code",
- "critical",
- "data",
- "far",
- "idata",
- "interrupt",
- "near",
- "pdata",
- "reentrant",
- "sfr",
- "sbit",
- "using",
- "xdata",
- "_data",
- "_code",
- "_generic",
- "_near",
- "_xdata",
- "_pdata",
- "_idata",
- NULL
+static char *_pic14_keywords[] =
+{
+ "at",
+ "bit",
+ "code",
+ "critical",
+ "data",
+ "far",
+ "idata",
+ "interrupt",
+ "near",
+ "pdata",
+ "reentrant",
+ "sfr",
+ "sbit",
+ "using",
+ "xdata",
+ "_data",
+ "_code",
+ "_generic",
+ "_near",
+ "_xdata",
+ "_pdata",
+ "_idata",
+ NULL
};
-void pic14_assignRegisters (eBBlock **ebbs, int count);
+void pic14_assignRegisters (eBBlock ** ebbs, int count);
-static int regParmFlg = 0; /* determine if we can register a parameter */
+static int regParmFlg = 0; /* determine if we can register a parameter */
-static void _pic14_init(void)
+static void
+_pic14_init (void)
{
- asm_addTree(&asm_asxxxx_mapping);
+ asm_addTree (&asm_asxxxx_mapping);
}
-static void _pic14_reset_regparm()
+static void
+_pic14_reset_regparm ()
{
- regParmFlg = 0;
+ regParmFlg = 0;
}
-static int _pic14_regparm( sym_link *l)
+static int
+_pic14_regparm (sym_link * l)
{
- /* for this processor it is simple
- can pass only the first parameter in a register */
- if (regParmFlg)
- return 0;
+ /* for this processor it is simple
+ can pass only the first parameter in a register */
+ if (regParmFlg)
+ return 0;
- regParmFlg = 1;
- return 1;
+ regParmFlg = 1;
+ return 1;
}
-static bool _pic14_parseOptions(int *pargc, char **argv, int *i)
+static bool
+_pic14_parseOptions (int *pargc, char **argv, int *i)
{
- /* TODO: allow port-specific command line options to specify
- * segment names here.
- */
- return FALSE;
+ /* TODO: allow port-specific command line options to specify
+ * segment names here.
+ */
+ return FALSE;
}
-static void _pic14_finaliseOptions(void)
+static void
+_pic14_finaliseOptions (void)
{
- /* Hack-o-matic: if we are using the flat24 model,
- * adjust pointer sizes.
- */
- if (options.model == MODEL_FLAT24)
+ /* Hack-o-matic: if we are using the flat24 model,
+ * adjust pointer sizes.
+ */
+ if (options.model == MODEL_FLAT24)
{
-
- fprintf(stderr, "*** WARNING: you should use the '-mds390' option "
- "for DS80C390 support. This code generator is "
- "badly out of date and probably broken.\n");
-
- port->s.fptr_size = 3;
- port->s.gptr_size = 4;
- port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
- #if 1
- port->stack.call_overhead++; /* This acounts for the extra byte
- * of return addres on the stack.
- * but is ugly. There must be a
- * better way.
- */
- #endif
- fReturn = fReturn390;
- fReturnSize = 5;
- }
- if (options.model == MODEL_LARGE) {
- port->mem.default_local_map = xdata;
- port->mem.default_globl_map = xdata;
- } else {
- port->mem.default_local_map = data;
- port->mem.default_globl_map = data;
+ fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
+ "for DS80C390 support. This code generator is "
+ "badly out of date and probably broken.\n");
+
+ port->s.fptr_size = 3;
+ port->s.gptr_size = 4;
+ port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
+#if 1
+ port->stack.call_overhead++; /* This acounts for the extra byte
+ * of return addres on the stack.
+ * but is ugly. There must be a
+ * better way.
+ */
+#endif
+ fReturn = fReturn390;
+ fReturnSize = 5;
+ }
+
+ if (options.model == MODEL_LARGE)
+ {
+ port->mem.default_local_map = xdata;
+ port->mem.default_globl_map = xdata;
+ }
+ else
+ {
+ port->mem.default_local_map = data;
+ port->mem.default_globl_map = data;
}
-
- if (options.stack10bit)
+
+ if (options.stack10bit)
{
- if (options.model != MODEL_FLAT24)
- {
- fprintf(stderr,
- "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
- fprintf(stderr, "\t10 bit stack mode disabled.\n");
- options.stack10bit = 0;
- }
- else
- {
- /* Fixup the memory map for the stack; it is now in
- * far space and requires a FPOINTER to access it.
- */
- istack->fmap = 1;
- istack->ptrType = FPOINTER;
- }
+ if (options.model != MODEL_FLAT24)
+ {
+ fprintf (stderr,
+ "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
+ fprintf (stderr, "\t10 bit stack mode disabled.\n");
+ options.stack10bit = 0;
+ }
+ else
+ {
+ /* Fixup the memory map for the stack; it is now in
+ * far space and requires a FPOINTER to access it.
+ */
+ istack->fmap = 1;
+ istack->ptrType = FPOINTER;
+ }
}
}
-static void _pic14_setDefaultOptions(void)
+static void
+_pic14_setDefaultOptions (void)
{
}
-static const char *_pic14_getRegName(struct regs *reg)
+static const char *
+_pic14_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- return "err";
+ if (reg)
+ return reg->name;
+ return "err";
}
-static void _pic14_genAssemblerPreamble(FILE *of)
+static void
+_pic14_genAssemblerPreamble (FILE * of)
{
- fprintf(of,"\tlist\tp=16c84\n");
- fprintf(of,"\t__config _wdt_off\n");
- fprintf(of,"\ninclude \"p16c84.inc\"\n");
+ fprintf (of, "\tlist\tp=16c84\n");
+ fprintf (of, "\t__config _wdt_off\n");
+ fprintf (of, "\ninclude \"p16c84.inc\"\n");
}
/* Generate interrupt vector table. */
-static int _pic14_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
+static int
+_pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
{
- int i;
-
- if (options.model != MODEL_FLAT24)
+ int i;
+
+ if (options.model != MODEL_FLAT24)
{
- /* Let the default code handle it. */
- return FALSE;
+ /* Let the default code handle it. */
+ return FALSE;
}
-
- fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
-
- /* now for the other interrupts */
- for (i = 0; i < maxInterrupts; i++)
+
+ fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
+
+ /* now for the other interrupts */
+ for (i = 0; i < maxInterrupts; i++)
{
- if (interrupts[i])
+ if (interrupts[i])
{
- fprintf(of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
+ fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
}
- else
+ else
{
- fprintf(of, "\t;reti\n\t.ds\t7\n");
+ fprintf (of, "\t;reti\n\t.ds\t7\n");
}
}
-
- return TRUE;
+
+ return TRUE;
}
/** $1 is always the basename.
$l is the list of extra options that should be there somewhere...
MUST be terminated with a NULL.
*/
-static const char *_linkCmd[] = {
- "aslink", "-nf", "$1", NULL
+static const char *_linkCmd[] =
+{
+ "aslink", "-nf", "$1", NULL
};
-static const char *_asmCmd[] = {
- "gpasm", NULL, NULL, NULL
+static const char *_asmCmd[] =
+{
+ "gpasm", NULL, NULL, NULL
};
/* Globals */
-PORT pic14_port = {
- "pic14",
- "MCU pic", /* Target name */
- {
- TRUE, /* Emit glue around main */
- MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
- MODEL_SMALL
- },
- {
- _asmCmd,
- NULL,
- NULL,
- //"-plosgffc", /* Options with debug */
- //"-plosgff", /* Options without debug */
- 0
- },
- {
- _linkCmd,
- NULL,
- ".rel"
- },
- {
- _defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 1, 2, 4, 1, 2, 1, 1, 4, 4
+PORT pic14_port =
+{
+ "pic14",
+ "MCU pic", /* Target name */
+ {
+ TRUE, /* Emit glue around main */
+ MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
+ MODEL_SMALL
+ },
+ {
+ _asmCmd,
+ NULL,
+ NULL,
+ //"-plosgffc", /* Options with debug */
+ //"-plosgff", /* Options without debug */
+ 0
+ },
+ {
+ _linkCmd,
+ NULL,
+ ".rel"
+ },
+ {
+ _defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 1, 2, 4, 1, 2, 1, 1, 4, 4
/* TSD - I changed the size of gptr from 3 to 1. However, it should be
2 so that we can accomodate the PIC's with 4 register banks (like the
16f877)
- */
- },
- {
- "XSEG (XDATA)",
- "STACK (DATA)",
- "CSEG (CODE)",
- "DSEG (DATA)",
- "ISEG (DATA)",
- "XSEG (XDATA)",
- "BSEG (BIT)",
- "RSEG (DATA)",
- "GSINIT (CODE)",
- "OSEG (OVR,DATA)",
- "GSFINAL (CODE)",
- "HOME (CODE)",
- NULL,
- NULL,
- 1
- },
- {
- +1, 1, 4, 1, 1, 0
- },
- /* pic14 has an 8 bit mul */
- {
- 1, 0
- },
- "_",
- _pic14_init,
- _pic14_parseOptions,
- _pic14_finaliseOptions,
- _pic14_setDefaultOptions,
- pic14_assignRegisters,
- _pic14_getRegName ,
- _pic14_keywords,
- _pic14_genAssemblerPreamble,
- _pic14_genIVT ,
- _pic14_reset_regparm,
- _pic14_regparm,
+ */
+ },
+ {
+ "XSEG (XDATA)",
+ "STACK (DATA)",
+ "CSEG (CODE)",
+ "DSEG (DATA)",
+ "ISEG (DATA)",
+ "XSEG (XDATA)",
+ "BSEG (BIT)",
+ "RSEG (DATA)",
+ "GSINIT (CODE)",
+ "OSEG (OVR,DATA)",
+ "GSFINAL (CODE)",
+ "HOME (CODE)",
+ NULL,
NULL,
- FALSE,
- 0, /* leave lt */
- 0, /* leave gt */
- 1, /* transform <= to ! > */
- 1, /* transform >= to ! < */
- 1, /* transform != to !(a == b) */
- 0, /* leave == */
- PORT_MAGIC
+ 1
+ },
+ {
+ +1, 1, 4, 1, 1, 0
+ },
+ /* pic14 has an 8 bit mul */
+ {
+ 1, 0
+ },
+ "_",
+ _pic14_init,
+ _pic14_parseOptions,
+ _pic14_finaliseOptions,
+ _pic14_setDefaultOptions,
+ pic14_assignRegisters,
+ _pic14_getRegName,
+ _pic14_keywords,
+ _pic14_genAssemblerPreamble,
+ _pic14_genIVT,
+ _pic14_reset_regparm,
+ _pic14_regparm,
+ NULL,
+ FALSE,
+ 0, /* leave lt */
+ 0, /* leave gt */
+ 1, /* transform <= to ! > */
+ 1, /* transform >= to ! < */
+ 1, /* transform != to !(a == b) */
+ 0, /* leave == */
+ PORT_MAGIC
};
-
#ifndef MAIN_INCLUDE
#define MAIN_INCLUDE
-bool x_parseOptions(char **argv, int *pargc);
-void x_setDefaultOptions(void);
-void x_finaliseOptions(void);
+bool x_parseOptions (char **argv, int *pargc);
+void x_setDefaultOptions (void);
+void x_finaliseOptions (void);
#endif
/* some routines are non-processor specific & can be reused when */
/* targetting other processors. The decision for this will have */
/* to be made on a routine by routine basis */
-/* routines used to pack registers are most definitely not reusable*/
+/* routines used to pack registers are most definitely not reusable */
/* since the pack the registers depending strictly on the MCU */
/*-----------------------------------------------------------------*/
-extern void genpic14Code(iCode *);
+extern void genpic14Code (iCode *);
/* Global data */
-static struct {
+static struct
+ {
bitVect *spiltSet;
set *stackSpil;
bitVect *regAssigned;
short blockSpil;
int slocNum;
- bitVect *funcrUsed; /* registers used in a function */
+ bitVect *funcrUsed; /* registers used in a function */
int stackExtend;
int dataExtend;
-} _G;
+ }
+_G;
/* Shared with gen.c */
-int pic14_ptrRegReq; /* one byte pointer register required */
+int pic14_ptrRegReq; /* one byte pointer register required */
/* pic14 registers */
-regs regspic14[] =
+regs regspic14[] =
{
- {REG_GPR, 0x0C, "r0x0C", "r0x0C", 0x0C, 1, 0},
- {REG_GPR, 0x0D, "r0x0D", "r0x0C", 0x0D, 1, 0},
- {REG_GPR, 0x0E, "r0x0E", "r0x0C", 0x0E, 1, 0},
- {REG_GPR, 0x0F, "r0x0F", "r0x0C", 0x0F, 1, 0},
- {REG_GPR, 0x10, "r0x10", "r0x10", 0x10, 1, 0},
- {REG_GPR, 0x11, "r0x11", "r0x11", 0x11, 1, 0},
- {REG_GPR, 0x12, "r0x12", "r0x12", 0x12, 1, 0},
- {REG_GPR, 0x13, "r0x13", "r0x13", 0x13, 1, 0},
- {REG_GPR, 0x14, "r0x14", "r0x14", 0x14, 1, 0},
- {REG_GPR, 0x15, "r0x15", "r0x15", 0x15, 1, 0},
- {REG_GPR, 0x16, "r0x16", "r0x16", 0x16, 1, 0},
- {REG_GPR, 0x17, "r0x17", "r0x17", 0x17, 1, 0},
- {REG_GPR, 0x18, "r0x18", "r0x18", 0x18, 1, 0},
- {REG_GPR, 0x19, "r0x19", "r0x19", 0x19, 1, 0},
- {REG_GPR, 0x1A, "r0x1A", "r0x1A", 0x1A, 1, 0},
- {REG_GPR, 0x1B, "r0x1B", "r0x1B", 0x1B, 1, 0},
- {REG_GPR, 0x1C, "r0x1C", "r0x1C", 0x1C, 1, 0},
- {REG_GPR, 0x1D, "r0x1D", "r0x1D", 0x1D, 1, 0},
- {REG_GPR, 0x1E, "r0x1E", "r0x1E", 0x1E, 1, 0},
- {REG_GPR, 0x1F, "r0x1F", "r0x1F", 0x1F, 1, 0},
- {REG_PTR, 4, "FSR", "FSR", 4, 1,0},
+ {REG_GPR, 0x0C, "r0x0C", "r0x0C", 0x0C, 1, 0},
+ {REG_GPR, 0x0D, "r0x0D", "r0x0C", 0x0D, 1, 0},
+ {REG_GPR, 0x0E, "r0x0E", "r0x0C", 0x0E, 1, 0},
+ {REG_GPR, 0x0F, "r0x0F", "r0x0C", 0x0F, 1, 0},
+ {REG_GPR, 0x10, "r0x10", "r0x10", 0x10, 1, 0},
+ {REG_GPR, 0x11, "r0x11", "r0x11", 0x11, 1, 0},
+ {REG_GPR, 0x12, "r0x12", "r0x12", 0x12, 1, 0},
+ {REG_GPR, 0x13, "r0x13", "r0x13", 0x13, 1, 0},
+ {REG_GPR, 0x14, "r0x14", "r0x14", 0x14, 1, 0},
+ {REG_GPR, 0x15, "r0x15", "r0x15", 0x15, 1, 0},
+ {REG_GPR, 0x16, "r0x16", "r0x16", 0x16, 1, 0},
+ {REG_GPR, 0x17, "r0x17", "r0x17", 0x17, 1, 0},
+ {REG_GPR, 0x18, "r0x18", "r0x18", 0x18, 1, 0},
+ {REG_GPR, 0x19, "r0x19", "r0x19", 0x19, 1, 0},
+ {REG_GPR, 0x1A, "r0x1A", "r0x1A", 0x1A, 1, 0},
+ {REG_GPR, 0x1B, "r0x1B", "r0x1B", 0x1B, 1, 0},
+ {REG_GPR, 0x1C, "r0x1C", "r0x1C", 0x1C, 1, 0},
+ {REG_GPR, 0x1D, "r0x1D", "r0x1D", 0x1D, 1, 0},
+ {REG_GPR, 0x1E, "r0x1E", "r0x1E", 0x1E, 1, 0},
+ {REG_GPR, 0x1F, "r0x1F", "r0x1F", 0x1F, 1, 0},
+ {REG_PTR, 4, "FSR", "FSR", 4, 1, 0},
};
-int pic14_nRegs = sizeof(regspic14) / sizeof(regs);
+int pic14_nRegs = sizeof (regspic14) / sizeof (regs);
static void spillThis (symbol *);
-static int debug=1;
-static FILE *debugF=NULL;
+static int debug = 1;
+static FILE *debugF = NULL;
/*-----------------------------------------------------------------*/
/* debugLog - open a file for debugging information */
/*-----------------------------------------------------------------*/
//static void debugLog(char *inst,char *fmt, ...)
-static void debugLog(char *fmt, ...)
+static void
+debugLog (char *fmt,...)
{
- static int append = 0; // First time through, open the file without append.
+ static int append = 0; // First time through, open the file without append.
+
char buffer[256];
//char *bufferP=buffer;
va_list ap;
- if(!debug)
+ if (!debug)
return;
- if (!debugF) {
- /* create the file name */
- strcpy(buffer,srcFileName);
- strcat(buffer,".d");
+ if (!debugF)
+ {
+ /* create the file name */
+ strcpy (buffer, srcFileName);
+ strcat (buffer, ".d");
+
+ if (!(debugF = fopen (buffer, (append ? "a+" : "w"))))
+ {
+ werror (E_FILE_OPEN_ERR, buffer);
+ exit (1);
+ }
+ append = 1; // Next time debubLog is called, we'll append the debug info
- if( !(debugF = fopen(buffer, (append ? "a+" : "w") ))) {
- werror(E_FILE_OPEN_ERR,buffer);
- exit(1);
}
- append = 1; // Next time debubLog is called, we'll append the debug info
- }
- va_start(ap,fmt);
+ va_start (ap, fmt);
- vsprintf(buffer,fmt,ap);
+ vsprintf (buffer, fmt, ap);
- fprintf(debugF,"%s",buffer);
+ fprintf (debugF, "%s", buffer);
/*
- while (isspace(*bufferP)) bufferP++;
+ while (isspace(*bufferP)) bufferP++;
- if (bufferP && *bufferP)
- lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(lb)) :
- (lineHead = newLineNode(lb)));
- lineCurr->isInline = _G.inLine;
- lineCurr->isDebug = _G.debugLine;
-*/
- va_end(ap);
+ if (bufferP && *bufferP)
+ lineCurr = (lineCurr ?
+ connectLine(lineCurr,newLineNode(lb)) :
+ (lineHead = newLineNode(lb)));
+ lineCurr->isInline = _G.inLine;
+ lineCurr->isDebug = _G.debugLine;
+ */
+ va_end (ap);
}
-static void debugNewLine(void)
+static void
+debugNewLine (void)
{
- if(debugF)
- fputc('\n',debugF);
+ if (debugF)
+ fputc ('\n', debugF);
}
/*-----------------------------------------------------------------*/
/* debugLogClose - closes the debug log file (if opened) */
/*-----------------------------------------------------------------*/
-static void debugLogClose(void)
+static void
+debugLogClose (void)
{
- if(debugF) {
- fclose(debugF);
- debugF = NULL;
- }
+ if (debugF)
+ {
+ fclose (debugF);
+ debugF = NULL;
+ }
}
#define AOP(op) op->aop
-static char *debugAopGet(char *str,operand *op)
+static char *
+debugAopGet (char *str, operand * op)
{
- if(str)
- debugLog(str);
+ if (str)
+ debugLog (str);
- printOperand(op,debugF);debugNewLine();
+ printOperand (op, debugF);
+ debugNewLine ();
return NULL;
}
-static char * decodeOp(unsigned int op)
+static char *
+decodeOp (unsigned int op)
{
- if(op<128 && op>' ') {
- buffer[0] = (op & 0xff);
- buffer[1] = 0;
- return buffer;
- }
+ if (op < 128 && op > ' ')
+ {
+ buffer[0] = (op & 0xff);
+ buffer[1] = 0;
+ return buffer;
+ }
- switch(op) {
- case IDENTIFIER:
- return "IDENTIFIER";
- case TYPE_NAME:
- return "TYPE_NAME";
- case CONSTANT:
- return "CONSTANT";
- case STRING_LITERAL:
- return "STRING_LITERAL";
- case SIZEOF:
- return "SIZEOF";
- case PTR_OP:
- return "PTR_OP";
- case INC_OP:
- return "INC_OP";
- case DEC_OP:
- return "DEC_OP";
- case LEFT_OP:
- return "LEFT_OP";
- case RIGHT_OP:
- return "RIGHT_OP";
- case LE_OP:
- return "LE_OP";
- case GE_OP:
- return "GE_OP";
- case EQ_OP:
- return "EQ_OP";
- case NE_OP:
- return "NE_OP";
- case AND_OP:
- return "AND_OP";
- case OR_OP:
- return "OR_OP";
- case MUL_ASSIGN:
- return "MUL_ASSIGN";
- case DIV_ASSIGN:
- return "DIV_ASSIGN";
- case MOD_ASSIGN:
- return "MOD_ASSIGN";
- case ADD_ASSIGN:
- return "ADD_ASSIGN";
- case SUB_ASSIGN:
- return "SUB_ASSIGN";
- case LEFT_ASSIGN:
- return "LEFT_ASSIGN";
- case RIGHT_ASSIGN:
- return "RIGHT_ASSIGN";
- case AND_ASSIGN:
- return "AND_ASSIGN";
- case XOR_ASSIGN:
- return "XOR_ASSIGN";
- case OR_ASSIGN:
- return "OR_ASSIGN";
- case TYPEDEF:
- return "TYPEDEF";
- case EXTERN:
- return "EXTERN";
- case STATIC:
- return "STATIC";
- case AUTO:
- return "AUTO";
- case REGISTER:
- return "REGISTER";
- case CODE:
- return "CODE";
- case EEPROM:
- return "EEPROM";
- case INTERRUPT:
- return "INTERRUPT";
- case SFR:
- return "SFR";
- case AT:
- return "AT";
- case SBIT:
- return "SBIT";
- case REENTRANT:
- return "REENTRANT";
- case USING:
- return "USING";
- case XDATA:
- return "XDATA";
- case DATA:
- return "DATA";
- case IDATA:
- return "IDATA";
- case PDATA:
- return "PDATA";
- case VAR_ARGS:
- return "VAR_ARGS";
- case CRITICAL:
- return "CRITICAL";
- case NONBANKED:
- return "NONBANKED";
- case BANKED:
- return "BANKED";
- case CHAR:
- return "CHAR";
- case SHORT:
- return "SHORT";
- case INT:
- return "INT";
- case LONG:
- return "LONG";
- case SIGNED:
- return "SIGNED";
- case UNSIGNED:
- return "UNSIGNED";
- case FLOAT:
- return "FLOAT";
- case DOUBLE:
- return "DOUBLE";
- case CONST:
- return "CONST";
- case VOLATILE:
- return "VOLATILE";
- case VOID:
- return "VOID";
- case BIT:
- return "BIT";
- case STRUCT:
- return "STRUCT";
- case UNION:
- return "UNION";
- case ENUM:
- return "ENUM";
- case ELIPSIS:
- return "ELIPSIS";
- case RANGE:
- return "RANGE";
- case FAR:
- return "FAR";
- case _XDATA:
- return "_XDATA";
- case _CODE:
- return "_CODE";
- case _GENERIC:
- return "_GENERIC";
- case _NEAR:
- return "_NEAR";
- case _PDATA:
- return "_PDATA";
- case _IDATA:
- return "_IDATA";
- case _EEPROM:
- return "_EEPROM";
- case CASE:
- return "CASE";
- case DEFAULT:
- return "DEFAULT";
- case IF:
- return "IF";
- case ELSE:
- return "ELSE";
- case SWITCH:
- return "SWITCH";
- case WHILE:
- return "WHILE";
- case DO:
- return "DO";
- case FOR:
- return "FOR";
- case GOTO:
- return "GOTO";
- case CONTINUE:
- return "CONTINUE";
- case BREAK:
- return "BREAK";
- case RETURN:
- return "RETURN";
- case INLINEASM:
- return "INLINEASM";
- case IFX:
- return "IFX";
- case ADDRESS_OF:
- return "ADDRESS_OF";
- case GET_VALUE_AT_ADDRESS:
- return "GET_VALUE_AT_ADDRESS";
- case SPIL:
- return "SPIL";
- case UNSPIL:
- return "UNSPIL";
- case GETHBIT:
- return "GETHBIT";
- case BITWISEAND:
- return "BITWISEAND";
- case UNARYMINUS:
- return "UNARYMINUS";
- case IPUSH:
- return "IPUSH";
- case IPOP:
- return "IPOP";
- case PCALL:
- return "PCALL";
- case ENDFUNCTION:
- return "ENDFUNCTION";
- case JUMPTABLE:
- return "JUMPTABLE";
- case RRC:
- return "RRC";
- case RLC:
- return "RLC";
- case CAST:
- return "CAST";
- case CALL:
- return "CALL";
- case PARAM:
- return "PARAM ";
- case NULLOP:
- return "NULLOP";
- case BLOCK:
- return "BLOCK";
- case LABEL:
- return "LABEL";
- case RECEIVE:
- return "RECEIVE";
- case SEND:
- return "SEND";
- }
- sprintf(buffer,"unkown op %d %c",op, op&0xff);
+ switch (op)
+ {
+ case IDENTIFIER:
+ return "IDENTIFIER";
+ case TYPE_NAME:
+ return "TYPE_NAME";
+ case CONSTANT:
+ return "CONSTANT";
+ case STRING_LITERAL:
+ return "STRING_LITERAL";
+ case SIZEOF:
+ return "SIZEOF";
+ case PTR_OP:
+ return "PTR_OP";
+ case INC_OP:
+ return "INC_OP";
+ case DEC_OP:
+ return "DEC_OP";
+ case LEFT_OP:
+ return "LEFT_OP";
+ case RIGHT_OP:
+ return "RIGHT_OP";
+ case LE_OP:
+ return "LE_OP";
+ case GE_OP:
+ return "GE_OP";
+ case EQ_OP:
+ return "EQ_OP";
+ case NE_OP:
+ return "NE_OP";
+ case AND_OP:
+ return "AND_OP";
+ case OR_OP:
+ return "OR_OP";
+ case MUL_ASSIGN:
+ return "MUL_ASSIGN";
+ case DIV_ASSIGN:
+ return "DIV_ASSIGN";
+ case MOD_ASSIGN:
+ return "MOD_ASSIGN";
+ case ADD_ASSIGN:
+ return "ADD_ASSIGN";
+ case SUB_ASSIGN:
+ return "SUB_ASSIGN";
+ case LEFT_ASSIGN:
+ return "LEFT_ASSIGN";
+ case RIGHT_ASSIGN:
+ return "RIGHT_ASSIGN";
+ case AND_ASSIGN:
+ return "AND_ASSIGN";
+ case XOR_ASSIGN:
+ return "XOR_ASSIGN";
+ case OR_ASSIGN:
+ return "OR_ASSIGN";
+ case TYPEDEF:
+ return "TYPEDEF";
+ case EXTERN:
+ return "EXTERN";
+ case STATIC:
+ return "STATIC";
+ case AUTO:
+ return "AUTO";
+ case REGISTER:
+ return "REGISTER";
+ case CODE:
+ return "CODE";
+ case EEPROM:
+ return "EEPROM";
+ case INTERRUPT:
+ return "INTERRUPT";
+ case SFR:
+ return "SFR";
+ case AT:
+ return "AT";
+ case SBIT:
+ return "SBIT";
+ case REENTRANT:
+ return "REENTRANT";
+ case USING:
+ return "USING";
+ case XDATA:
+ return "XDATA";
+ case DATA:
+ return "DATA";
+ case IDATA:
+ return "IDATA";
+ case PDATA:
+ return "PDATA";
+ case VAR_ARGS:
+ return "VAR_ARGS";
+ case CRITICAL:
+ return "CRITICAL";
+ case NONBANKED:
+ return "NONBANKED";
+ case BANKED:
+ return "BANKED";
+ case CHAR:
+ return "CHAR";
+ case SHORT:
+ return "SHORT";
+ case INT:
+ return "INT";
+ case LONG:
+ return "LONG";
+ case SIGNED:
+ return "SIGNED";
+ case UNSIGNED:
+ return "UNSIGNED";
+ case FLOAT:
+ return "FLOAT";
+ case DOUBLE:
+ return "DOUBLE";
+ case CONST:
+ return "CONST";
+ case VOLATILE:
+ return "VOLATILE";
+ case VOID:
+ return "VOID";
+ case BIT:
+ return "BIT";
+ case STRUCT:
+ return "STRUCT";
+ case UNION:
+ return "UNION";
+ case ENUM:
+ return "ENUM";
+ case ELIPSIS:
+ return "ELIPSIS";
+ case RANGE:
+ return "RANGE";
+ case FAR:
+ return "FAR";
+ case _XDATA:
+ return "_XDATA";
+ case _CODE:
+ return "_CODE";
+ case _GENERIC:
+ return "_GENERIC";
+ case _NEAR:
+ return "_NEAR";
+ case _PDATA:
+ return "_PDATA";
+ case _IDATA:
+ return "_IDATA";
+ case _EEPROM:
+ return "_EEPROM";
+ case CASE:
+ return "CASE";
+ case DEFAULT:
+ return "DEFAULT";
+ case IF:
+ return "IF";
+ case ELSE:
+ return "ELSE";
+ case SWITCH:
+ return "SWITCH";
+ case WHILE:
+ return "WHILE";
+ case DO:
+ return "DO";
+ case FOR:
+ return "FOR";
+ case GOTO:
+ return "GOTO";
+ case CONTINUE:
+ return "CONTINUE";
+ case BREAK:
+ return "BREAK";
+ case RETURN:
+ return "RETURN";
+ case INLINEASM:
+ return "INLINEASM";
+ case IFX:
+ return "IFX";
+ case ADDRESS_OF:
+ return "ADDRESS_OF";
+ case GET_VALUE_AT_ADDRESS:
+ return "GET_VALUE_AT_ADDRESS";
+ case SPIL:
+ return "SPIL";
+ case UNSPIL:
+ return "UNSPIL";
+ case GETHBIT:
+ return "GETHBIT";
+ case BITWISEAND:
+ return "BITWISEAND";
+ case UNARYMINUS:
+ return "UNARYMINUS";
+ case IPUSH:
+ return "IPUSH";
+ case IPOP:
+ return "IPOP";
+ case PCALL:
+ return "PCALL";
+ case ENDFUNCTION:
+ return "ENDFUNCTION";
+ case JUMPTABLE:
+ return "JUMPTABLE";
+ case RRC:
+ return "RRC";
+ case RLC:
+ return "RLC";
+ case CAST:
+ return "CAST";
+ case CALL:
+ return "CALL";
+ case PARAM:
+ return "PARAM ";
+ case NULLOP:
+ return "NULLOP";
+ case BLOCK:
+ return "BLOCK";
+ case LABEL:
+ return "LABEL";
+ case RECEIVE:
+ return "RECEIVE";
+ case SEND:
+ return "SEND";
+ }
+ sprintf (buffer, "unkown op %d %c", op, op & 0xff);
return buffer;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-static char * debugLogRegType(short type)
+static char *
+debugLogRegType (short type)
{
- switch(type) {
- case REG_GPR:
- return "REG_GPR";
- case REG_PTR:
- return "REG_PTR";
- case REG_CND:
- return "REG_CND";
- }
+ switch (type)
+ {
+ case REG_GPR:
+ return "REG_GPR";
+ case REG_PTR:
+ return "REG_PTR";
+ case REG_CND:
+ return "REG_CND";
+ }
- sprintf(buffer,"unkown reg type %d",type);
+ sprintf (buffer, "unkown reg type %d", type);
return buffer;
}
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
-static regs *allocReg (short type)
+static regs *
+allocReg (short type)
{
- int i;
-
- debugLog("%s of type %s\n",__FUNCTION__,debugLogRegType(type));
-
- for ( i = 0 ; i < pic14_nRegs ; i++ ) {
-
- /* if type is given as 0 then any
- free register will do */
- if (!type &&
- regspic14[i].isFree ) {
- regspic14[i].isFree = 0;
- regspic14[i].wasUsed = 1;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- debugLog(" returning %s\n",regspic14[i].name);
- return ®spic14[i];
+ int i;
+
+ debugLog ("%s of type %s\n", __FUNCTION__, debugLogRegType (type));
+
+ for (i = 0; i < pic14_nRegs; i++)
+ {
+
+ /* if type is given as 0 then any
+ free register will do */
+ if (!type &&
+ regspic14[i].isFree)
+ {
+ regspic14[i].isFree = 0;
+ regspic14[i].wasUsed = 1;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ debugLog (" returning %s\n", regspic14[i].name);
+ return ®spic14[i];
}
- /* other wise look for specific type
- of register */
- if (regspic14[i].isFree &&
- regspic14[i].type == type) {
- regspic14[i].isFree = 0;
- regspic14[i].wasUsed = 1;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- debugLog(" returning %s\n",regspic14[i].name);
- return ®spic14[i];
+ /* other wise look for specific type
+ of register */
+ if (regspic14[i].isFree &&
+ regspic14[i].type == type)
+ {
+ regspic14[i].isFree = 0;
+ regspic14[i].wasUsed = 1;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ debugLog (" returning %s\n", regspic14[i].name);
+ return ®spic14[i];
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* pic14_regWithIdx - returns pointer to register wit index number */
/*-----------------------------------------------------------------*/
-regs *pic14_regWithIdx (int idx)
+regs *
+pic14_regWithIdx (int idx)
{
- int i ;
-
- debugLog("%s\n",__FUNCTION__);
+ int i;
+
+ debugLog ("%s\n", __FUNCTION__);
- for (i=0;i < pic14_nRegs;i++)
- if (regspic14[i].rIdx == idx)
- return ®spic14[i];
+ for (i = 0; i < pic14_nRegs; i++)
+ if (regspic14[i].rIdx == idx)
+ return ®spic14[i];
- return ®spic14[0];
+ return ®spic14[0];
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "regWithIdx not found");
- exit(1);
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "regWithIdx not found");
+ exit (1);
}
/*-----------------------------------------------------------------*/
/* freeReg - frees a register */
/*-----------------------------------------------------------------*/
-static void freeReg (regs *reg)
+static void
+freeReg (regs * reg)
{
- debugLog("%s\n",__FUNCTION__);
- reg->isFree = 1;
+ debugLog ("%s\n", __FUNCTION__);
+ reg->isFree = 1;
}
/*-----------------------------------------------------------------*/
/* nFreeRegs - returns number of free registers */
/*-----------------------------------------------------------------*/
-static int nFreeRegs (int type)
+static int
+nFreeRegs (int type)
{
- int i;
- int nfr=0;
-
- debugLog("%s\n",__FUNCTION__);
- for (i = 0 ; i < pic14_nRegs; i++ )
- if (regspic14[i].isFree && regspic14[i].type == type)
- nfr++;
- return nfr;
+ int i;
+ int nfr = 0;
+
+ debugLog ("%s\n", __FUNCTION__);
+ for (i = 0; i < pic14_nRegs; i++)
+ if (regspic14[i].isFree && regspic14[i].type == type)
+ nfr++;
+ return nfr;
}
/*-----------------------------------------------------------------*/
/* nfreeRegsType - free registers with type */
/*-----------------------------------------------------------------*/
-static int nfreeRegsType (int type)
+static int
+nfreeRegsType (int type)
{
- int nfr ;
- debugLog("%s\n",__FUNCTION__);
- if (type == REG_PTR) {
- if ((nfr = nFreeRegs(type)) == 0)
- return nFreeRegs(REG_GPR);
- }
-
- return nFreeRegs(type);
+ int nfr;
+ debugLog ("%s\n", __FUNCTION__);
+ if (type == REG_PTR)
+ {
+ if ((nfr = nFreeRegs (type)) == 0)
+ return nFreeRegs (REG_GPR);
+ }
+
+ return nFreeRegs (type);
}
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
/*-----------------------------------------------------------------*/
-static bool allDefsOutOfRange (bitVect *defs,int fseq, int toseq)
+static bool
+allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
{
- int i ;
+ int i;
+
+ debugLog ("%s\n", __FUNCTION__);
+ if (!defs)
+ return TRUE;
+
+ for (i = 0; i < defs->size; i++)
+ {
+ iCode *ic;
- debugLog("%s\n",__FUNCTION__);
- if (!defs)
- return TRUE ;
+ if (bitVectBitValue (defs, i) &&
+ (ic = hTabItemWithKey (iCodehTab, i)) &&
+ (ic->seq >= fseq && ic->seq <= toseq))
- for ( i = 0 ;i < defs->size ; i++ ) {
- iCode *ic;
+ return FALSE;
- if (bitVectBitValue(defs,i) &&
- (ic = hTabItemWithKey(iCodehTab,i)) &&
- ( ic->seq >= fseq && ic->seq <= toseq))
-
- return FALSE;
-
}
-
- return TRUE;
+
+ return TRUE;
}
-
+
/*-----------------------------------------------------------------*/
/* computeSpillable - given a point find the spillable live ranges */
/*-----------------------------------------------------------------*/
-static bitVect *computeSpillable (iCode *ic)
+static bitVect *
+computeSpillable (iCode * ic)
{
- bitVect *spillable ;
-
- debugLog("%s\n",__FUNCTION__);
- /* spillable live ranges are those that are live at this
- point . the following categories need to be subtracted
- from this set.
- a) - those that are already spilt
- b) - if being used by this one
- c) - defined by this one */
-
- spillable = bitVectCopy(ic->rlive);
- spillable =
- bitVectCplAnd(spillable,_G.spiltSet); /* those already spilt */
- spillable =
- bitVectCplAnd(spillable,ic->uses); /* used in this one */
- bitVectUnSetBit(spillable,ic->defKey);
- spillable = bitVectIntersect(spillable,_G.regAssigned);
- return spillable;
-
+ bitVect *spillable;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* spillable live ranges are those that are live at this
+ point . the following categories need to be subtracted
+ from this set.
+ a) - those that are already spilt
+ b) - if being used by this one
+ c) - defined by this one */
+
+ spillable = bitVectCopy (ic->rlive);
+ spillable =
+ bitVectCplAnd (spillable, _G.spiltSet); /* those already spilt */
+ spillable =
+ bitVectCplAnd (spillable, ic->uses); /* used in this one */
+ bitVectUnSetBit (spillable, ic->defKey);
+ spillable = bitVectIntersect (spillable, _G.regAssigned);
+ return spillable;
+
}
/*-----------------------------------------------------------------*/
/* noSpilLoc - return true if a variable has no spil location */
/*-----------------------------------------------------------------*/
-static int noSpilLoc (symbol *sym, eBBlock *ebp,iCode *ic)
+static int
+noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- debugLog("%s\n",__FUNCTION__);
- return (sym->usl.spillLoc ? 0 : 1);
+ debugLog ("%s\n", __FUNCTION__);
+ return (sym->usl.spillLoc ? 0 : 1);
}
/*-----------------------------------------------------------------*/
/* hasSpilLoc - will return 1 if the symbol has spil location */
/*-----------------------------------------------------------------*/
-static int hasSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- debugLog("%s\n",__FUNCTION__);
- return (sym->usl.spillLoc ? 1 : 0);
+ debugLog ("%s\n", __FUNCTION__);
+ return (sym->usl.spillLoc ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* directSpilLoc - will return 1 if the splilocation is in direct */
/*-----------------------------------------------------------------*/
-static int directSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- debugLog("%s\n",__FUNCTION__);
- if ( sym->usl.spillLoc &&
- (IN_DIRSPACE(SPEC_OCLS(sym->usl.spillLoc->etype))))
- return 1;
- else
- return 0;
+ debugLog ("%s\n", __FUNCTION__);
+ if (sym->usl.spillLoc &&
+ (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
+ return 1;
+ else
+ return 0;
}
/*-----------------------------------------------------------------*/
-/* hasSpilLocnoUptr - will return 1 if the symbol has spil location*/
+/* hasSpilLocnoUptr - will return 1 if the symbol has spil location */
/* but is not used as a pointer */
/*-----------------------------------------------------------------*/
-static int hasSpilLocnoUptr (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLocnoUptr (symbol * sym, eBBlock * ebp, iCode * ic)
{
- debugLog("%s\n",__FUNCTION__);
- return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
+ debugLog ("%s\n", __FUNCTION__);
+ return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* rematable - will return 1 if the remat flag is set */
/*-----------------------------------------------------------------*/
-static int rematable (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+rematable (symbol * sym, eBBlock * ebp, iCode * ic)
{
- debugLog("%s\n",__FUNCTION__);
- return sym->remat;
+ debugLog ("%s\n", __FUNCTION__);
+ return sym->remat;
}
/*-----------------------------------------------------------------*/
/* notUsedInBlock - not used in this block */
/*-----------------------------------------------------------------*/
-static int notUsedInBlock (symbol *sym, eBBlock *ebp, iCode *ic)
-{
- debugLog("%s\n",__FUNCTION__);
- return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs) &&
- allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
+static int
+notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
+{
+ debugLog ("%s\n", __FUNCTION__);
+ return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
+ allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
/* return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs)); */
}
/*-----------------------------------------------------------------*/
/* notUsedInRemaining - not used or defined in remain of the block */
/*-----------------------------------------------------------------*/
-static int notUsedInRemaining (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+notUsedInRemaining (symbol * sym, eBBlock * ebp, iCode * ic)
{
- debugLog("%s\n",__FUNCTION__);
- return ((usedInRemaining (operandFromSymbol(sym),ic) ? 0 : 1) &&
- allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
+ debugLog ("%s\n", __FUNCTION__);
+ return ((usedInRemaining (operandFromSymbol (sym), ic) ? 0 : 1) &&
+ allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq));
}
/*-----------------------------------------------------------------*/
/* allLRs - return true for all */
/*-----------------------------------------------------------------*/
-static int allLRs (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
{
- debugLog("%s\n",__FUNCTION__);
- return 1;
+ debugLog ("%s\n", __FUNCTION__);
+ return 1;
}
/*-----------------------------------------------------------------*/
/* liveRangesWith - applies function to a given set of live range */
/*-----------------------------------------------------------------*/
-static set *liveRangesWith (bitVect *lrs, int (func)(symbol *,eBBlock *, iCode *),
- eBBlock *ebp, iCode *ic)
+static set *
+liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
+ eBBlock * ebp, iCode * ic)
{
- set *rset = NULL;
- int i;
+ set *rset = NULL;
+ int i;
- debugLog("%s\n",__FUNCTION__);
- if (!lrs || !lrs->size)
- return NULL;
+ debugLog ("%s\n", __FUNCTION__);
+ if (!lrs || !lrs->size)
+ return NULL;
- for ( i = 1 ; i < lrs->size ; i++ ) {
- symbol *sym;
- if (!bitVectBitValue(lrs,i))
- continue ;
-
- /* if we don't find it in the live range
- hash table we are in serious trouble */
- if (!(sym = hTabItemWithKey(liveRanges,i))) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "liveRangesWith could not find liveRange");
- exit(1);
+ for (i = 1; i < lrs->size; i++)
+ {
+ symbol *sym;
+ if (!bitVectBitValue (lrs, i))
+ continue;
+
+ /* if we don't find it in the live range
+ hash table we are in serious trouble */
+ if (!(sym = hTabItemWithKey (liveRanges, i)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "liveRangesWith could not find liveRange");
+ exit (1);
}
-
- if (func(sym,ebp,ic) && bitVectBitValue(_G.regAssigned,sym->key))
- addSetHead(&rset,sym);
+
+ if (func (sym, ebp, ic) && bitVectBitValue (_G.regAssigned, sym->key))
+ addSetHead (&rset, sym);
}
- return rset;
+ return rset;
}
/*-----------------------------------------------------------------*/
/* leastUsedLR - given a set determines which is the least used */
/*-----------------------------------------------------------------*/
-static symbol *leastUsedLR (set *sset)
+static symbol *
+leastUsedLR (set * sset)
{
- symbol *sym = NULL, *lsym = NULL ;
-
- debugLog("%s\n",__FUNCTION__);
- sym = lsym = setFirstItem(sset);
+ symbol *sym = NULL, *lsym = NULL;
- if (!lsym)
- return NULL;
+ debugLog ("%s\n", __FUNCTION__);
+ sym = lsym = setFirstItem (sset);
- for (; lsym; lsym = setNextItem(sset)) {
-
- /* if usage is the same then prefer
- the spill the smaller of the two */
- if ( lsym->used == sym->used )
- if (getSize(lsym->type) < getSize(sym->type))
- sym = lsym;
-
- /* if less usage */
- if (lsym->used < sym->used )
- sym = lsym;
-
- }
+ if (!lsym)
+ return NULL;
- setToNull((void **)&sset);
- sym->blockSpil = 0;
- return sym;
+ for (; lsym; lsym = setNextItem (sset))
+ {
+
+ /* if usage is the same then prefer
+ the spill the smaller of the two */
+ if (lsym->used == sym->used)
+ if (getSize (lsym->type) < getSize (sym->type))
+ sym = lsym;
+
+ /* if less usage */
+ if (lsym->used < sym->used)
+ sym = lsym;
+
+ }
+
+ setToNull ((void **) &sset);
+ sym->blockSpil = 0;
+ return sym;
}
/*-----------------------------------------------------------------*/
/* noOverLap - will iterate through the list looking for over lap */
/*-----------------------------------------------------------------*/
-static int noOverLap (set *itmpStack, symbol *fsym)
+static int
+noOverLap (set * itmpStack, symbol * fsym)
{
- symbol *sym;
- debugLog("%s\n",__FUNCTION__);
-
+ symbol *sym;
+ debugLog ("%s\n", __FUNCTION__);
+
+
+ for (sym = setFirstItem (itmpStack); sym;
+ sym = setNextItem (itmpStack))
+ {
+ if (sym->liveTo > fsym->liveFrom)
+ return 0;
- for (sym = setFirstItem(itmpStack); sym;
- sym = setNextItem(itmpStack)) {
- if (sym->liveTo > fsym->liveFrom )
- return 0;
-
}
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* isFree - will return 1 if the a free spil location is found */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(isFree)
+static
+DEFSETFUNC (isFree)
{
- symbol *sym = item;
- V_ARG(symbol **,sloc);
- V_ARG(symbol *,fsym);
+ symbol *sym = item;
+ V_ARG (symbol **, sloc);
+ V_ARG (symbol *, fsym);
- debugLog("%s\n",__FUNCTION__);
- /* if already found */
- if (*sloc)
- return 0;
+ debugLog ("%s\n", __FUNCTION__);
+ /* if already found */
+ if (*sloc)
+ return 0;
- /* if it is free && and the itmp assigned to
- this does not have any overlapping live ranges
- with the one currently being assigned and
- the size can be accomodated */
- if (sym->isFree &&
- noOverLap(sym->usl.itmpStack,fsym) &&
- getSize(sym->type) >= getSize(fsym->type)) {
- *sloc = sym;
- return 1;
+ /* if it is free && and the itmp assigned to
+ this does not have any overlapping live ranges
+ with the one currently being assigned and
+ the size can be accomodated */
+ if (sym->isFree &&
+ noOverLap (sym->usl.itmpStack, fsym) &&
+ getSize (sym->type) >= getSize (fsym->type))
+ {
+ *sloc = sym;
+ return 1;
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* spillLRWithPtrReg :- will spil those live ranges which use PTR */
/*-----------------------------------------------------------------*/
-static void spillLRWithPtrReg (symbol *forSym)
+static void
+spillLRWithPtrReg (symbol * forSym)
{
- symbol *lrsym;
- regs *r0,*r1;
- int k;
+ symbol *lrsym;
+ regs *r0, *r1;
+ int k;
- debugLog("%s\n",__FUNCTION__);
- if (!_G.regAssigned ||
- bitVectIsZero(_G.regAssigned))
- return;
+ debugLog ("%s\n", __FUNCTION__);
+ if (!_G.regAssigned ||
+ bitVectIsZero (_G.regAssigned))
+ return;
- r0 = pic14_regWithIdx(R0_IDX);
- r1 = pic14_regWithIdx(R1_IDX);
-
- /* for all live ranges */
- for (lrsym = hTabFirstItem(liveRanges,&k) ; lrsym ;
- lrsym = hTabNextItem(liveRanges,&k) ) {
- int j;
-
- /* if no registers assigned to it or
- spilt */
- /* if it does not overlap with this then
- not need to spill it */
-
- if (lrsym->isspilt || !lrsym->nRegs ||
- (lrsym->liveTo < forSym->liveFrom))
- continue ;
-
- /* go thru the registers : if it is either
- r0 or r1 then spil it */
- for (j = 0 ; j < lrsym->nRegs ; j++ )
- if (lrsym->regs[j] == r0 ||
- lrsym->regs[j] == r1 ) {
- spillThis (lrsym);
- break;
- }
+ r0 = pic14_regWithIdx (R0_IDX);
+ r1 = pic14_regWithIdx (R1_IDX);
+
+ /* for all live ranges */
+ for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
+ lrsym = hTabNextItem (liveRanges, &k))
+ {
+ int j;
+
+ /* if no registers assigned to it or
+ spilt */
+ /* if it does not overlap with this then
+ not need to spill it */
+
+ if (lrsym->isspilt || !lrsym->nRegs ||
+ (lrsym->liveTo < forSym->liveFrom))
+ continue;
+
+ /* go thru the registers : if it is either
+ r0 or r1 then spil it */
+ for (j = 0; j < lrsym->nRegs; j++)
+ if (lrsym->regs[j] == r0 ||
+ lrsym->regs[j] == r1)
+ {
+ spillThis (lrsym);
+ break;
+ }
}
}
/*-----------------------------------------------------------------*/
/* createStackSpil - create a location on the stack to spil */
/*-----------------------------------------------------------------*/
-static symbol *createStackSpil (symbol *sym)
+static symbol *
+createStackSpil (symbol * sym)
{
- symbol *sloc= NULL;
- int useXstack, model, noOverlay;
-
- char slocBuffer[30];
- debugLog("%s\n",__FUNCTION__);
-
- /* first go try and find a free one that is already
- existing on the stack */
- if (applyToSet(_G.stackSpil,isFree,&sloc, sym)) {
- /* found a free one : just update & return */
- sym->usl.spillLoc = sloc;
- sym->stackSpil= 1;
- sloc->isFree = 0;
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ symbol *sloc = NULL;
+ int useXstack, model, noOverlay;
+
+ char slocBuffer[30];
+ debugLog ("%s\n", __FUNCTION__);
+
+ /* first go try and find a free one that is already
+ existing on the stack */
+ if (applyToSet (_G.stackSpil, isFree, &sloc, sym))
+ {
+ /* found a free one : just update & return */
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+ sloc->isFree = 0;
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
- /* could not then have to create one , this is the hard part
- we need to allocate this on the stack : this is really a
- hack!! but cannot think of anything better at this time */
-
- if (sprintf(slocBuffer,"sloc%d",_G.slocNum++) >= sizeof(slocBuffer))
+ /* could not then have to create one , this is the hard part
+ we need to allocate this on the stack : this is really a
+ hack!! but cannot think of anything better at this time */
+
+ if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
{
- fprintf(stderr, "kkkInternal error: slocBuffer overflowed: %s:%d\n",
- __FILE__, __LINE__);
- exit(1);
+ fprintf (stderr, "kkkInternal error: slocBuffer overflowed: %s:%d\n",
+ __FILE__, __LINE__);
+ exit (1);
}
- sloc = newiTemp(slocBuffer);
-
- /* set the type to the spilling symbol */
- sloc->type = copyLinkChain(sym->type);
- sloc->etype = getSpec(sloc->type);
- SPEC_SCLS(sloc->etype) = S_DATA ;
- SPEC_EXTR(sloc->etype) = 0;
-
- /* we don't allow it to be allocated`
- onto the external stack since : so we
- temporarily turn it off ; we also
- turn off memory model to prevent
- the spil from going to the external storage
- and turn off overlaying
- */
-
- useXstack = options.useXstack;
- model = options.model;
- noOverlay = options.noOverlay;
- options.noOverlay = 1;
- options.model = options.useXstack = 0;
-
- allocLocal(sloc);
-
- options.useXstack = useXstack;
- options.model = model;
- options.noOverlay = noOverlay;
- sloc->isref = 1; /* to prevent compiler warning */
-
- /* if it is on the stack then update the stack */
- if (IN_STACK(sloc->etype)) {
- currFunc->stack += getSize(sloc->type);
- _G.stackExtend += getSize(sloc->type);
- } else
- _G.dataExtend += getSize(sloc->type);
-
- /* add it to the _G.stackSpil set */
- addSetHead(&_G.stackSpil,sloc);
- sym->usl.spillLoc = sloc;
- sym->stackSpil = 1;
-
- /* add it to the set of itempStack set
- of the spill location */
- addSetHead(&sloc->usl.itmpStack,sym);
- return sym;
+ sloc = newiTemp (slocBuffer);
+
+ /* set the type to the spilling symbol */
+ sloc->type = copyLinkChain (sym->type);
+ sloc->etype = getSpec (sloc->type);
+ SPEC_SCLS (sloc->etype) = S_DATA;
+ SPEC_EXTR (sloc->etype) = 0;
+
+ /* we don't allow it to be allocated`
+ onto the external stack since : so we
+ temporarily turn it off ; we also
+ turn off memory model to prevent
+ the spil from going to the external storage
+ and turn off overlaying
+ */
+
+ useXstack = options.useXstack;
+ model = options.model;
+ noOverlay = options.noOverlay;
+ options.noOverlay = 1;
+ options.model = options.useXstack = 0;
+
+ allocLocal (sloc);
+
+ options.useXstack = useXstack;
+ options.model = model;
+ options.noOverlay = noOverlay;
+ sloc->isref = 1; /* to prevent compiler warning */
+
+ /* if it is on the stack then update the stack */
+ if (IN_STACK (sloc->etype))
+ {
+ currFunc->stack += getSize (sloc->type);
+ _G.stackExtend += getSize (sloc->type);
+ }
+ else
+ _G.dataExtend += getSize (sloc->type);
+
+ /* add it to the _G.stackSpil set */
+ addSetHead (&_G.stackSpil, sloc);
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+
+ /* add it to the set of itempStack set
+ of the spill location */
+ addSetHead (&sloc->usl.itmpStack, sym);
+ return sym;
}
/*-----------------------------------------------------------------*/
/* isSpiltOnStack - returns true if the spil location is on stack */
/*-----------------------------------------------------------------*/
-static bool isSpiltOnStack (symbol *sym)
+static bool
+isSpiltOnStack (symbol * sym)
{
- sym_link *etype;
+ sym_link *etype;
- debugLog("%s\n",__FUNCTION__);
- if (!sym)
- return FALSE ;
-
- if (!sym->isspilt)
- return FALSE ;
+ debugLog ("%s\n", __FUNCTION__);
+ if (!sym)
+ return FALSE;
+
+ if (!sym->isspilt)
+ return FALSE;
/* if (sym->_G.stackSpil) */
-/* return TRUE; */
-
- if (!sym->usl.spillLoc)
- return FALSE;
+/* return TRUE; */
- etype = getSpec(sym->usl.spillLoc->type);
- if (IN_STACK(etype))
- return TRUE;
+ if (!sym->usl.spillLoc)
+ return FALSE;
- return FALSE ;
+ etype = getSpec (sym->usl.spillLoc->type);
+ if (IN_STACK (etype))
+ return TRUE;
+
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* spillThis - spils a specific operand */
/*-----------------------------------------------------------------*/
-static void spillThis (symbol *sym)
+static void
+spillThis (symbol * sym)
{
- int i;
- debugLog("%s : %s\n",__FUNCTION__, sym->rname);
-
- /* if this is rematerializable or has a spillLocation
- we are okay, else we need to create a spillLocation
- for it */
- if (!(sym->remat || sym->usl.spillLoc))
- createStackSpil (sym);
-
-
- /* mark it has spilt & put it in the spilt set */
- sym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,sym->key);
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- for (i = 0 ; i < sym->nRegs ; i++)
-
- if (sym->regs[i]) {
- freeReg(sym->regs[i]);
- sym->regs[i] = NULL;
- }
-
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to some
- LIVE ranges */
- if (!pic14_ptrRegReq && isSpiltOnStack(sym)) {
- pic14_ptrRegReq++ ;
- spillLRWithPtrReg(sym);
+ int i;
+ debugLog ("%s : %s\n", __FUNCTION__, sym->rname);
+
+ /* if this is rematerializable or has a spillLocation
+ we are okay, else we need to create a spillLocation
+ for it */
+ if (!(sym->remat || sym->usl.spillLoc))
+ createStackSpil (sym);
+
+
+ /* mark it has spilt & put it in the spilt set */
+ sym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key);
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ for (i = 0; i < sym->nRegs; i++)
+
+ if (sym->regs[i])
+ {
+ freeReg (sym->regs[i]);
+ sym->regs[i] = NULL;
+ }
+
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to some
+ LIVE ranges */
+ if (!pic14_ptrRegReq && isSpiltOnStack (sym))
+ {
+ pic14_ptrRegReq++;
+ spillLRWithPtrReg (sym);
}
- if (sym->usl.spillLoc && !sym->remat)
- sym->usl.spillLoc->allocreq = 1;
- return;
+ if (sym->usl.spillLoc && !sym->remat)
+ sym->usl.spillLoc->allocreq = 1;
+ return;
}
/*-----------------------------------------------------------------*/
/* selectSpil - select a iTemp to spil : rather a simple procedure */
/*-----------------------------------------------------------------*/
-static symbol *selectSpil (iCode *ic, eBBlock *ebp, symbol *forSym)
+static symbol *
+selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- bitVect *lrcs= NULL ;
- set *selectS ;
- symbol *sym;
+ bitVect *lrcs = NULL;
+ set *selectS;
+ symbol *sym;
- debugLog("%s\n",__FUNCTION__);
- /* get the spillable live ranges */
- lrcs = computeSpillable (ic);
+ debugLog ("%s\n", __FUNCTION__);
+ /* get the spillable live ranges */
+ lrcs = computeSpillable (ic);
- /* get all live ranges that are rematerizable */
- if ((selectS = liveRangesWith(lrcs,rematable,ebp,ic))) {
+ /* get all live ranges that are rematerizable */
+ if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
+ {
- /* return the least used of these */
- return leastUsedLR(selectS);
+ /* return the least used of these */
+ return leastUsedLR (selectS);
}
- /* get live ranges with spillLocations in direct space */
- if ((selectS = liveRangesWith(lrcs,directSpilLoc,ebp,ic))) {
- sym = leastUsedLR(selectS);
- strcpy(sym->rname,(sym->usl.spillLoc->rname[0] ?
- sym->usl.spillLoc->rname :
- sym->usl.spillLoc->name));
- sym->spildir = 1;
- /* mark it as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* get live ranges with spillLocations in direct space */
+ if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
+ sym->usl.spillLoc->rname :
+ sym->usl.spillLoc->name));
+ sym->spildir = 1;
+ /* mark it as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* if the symbol is local to the block then */
- if (forSym->liveTo < ebp->lSeq) {
-
- /* check if there are any live ranges allocated
- to registers that are not used in this block */
- if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInBlock,ebp,ic))) {
- sym = leastUsedLR(selectS);
- /* if this is not rematerializable */
- if (!sym->remat) {
- _G.blockSpil++;
- sym->blockSpil = 1;
+ /* if the symbol is local to the block then */
+ if (forSym->liveTo < ebp->lSeq)
+ {
+
+ /* check if there are any live ranges allocated
+ to registers that are not used in this block */
+ if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ /* if this is not rematerializable */
+ if (!sym->remat)
+ {
+ _G.blockSpil++;
+ sym->blockSpil = 1;
}
- return sym;
- }
-
- /* check if there are any live ranges that not
- used in the remainder of the block */
- if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInRemaining,ebp,ic))) {
- sym = leastUsedLR (selectS);
- if (!sym->remat) {
- sym->remainSpil = 1;
- _G.blockSpil++;
+ return sym;
+ }
+
+ /* check if there are any live ranges that not
+ used in the remainder of the block */
+ if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ if (!sym->remat)
+ {
+ sym->remainSpil = 1;
+ _G.blockSpil++;
}
- return sym;
+ return sym;
}
- }
-
- /* find live ranges with spillocation && not used as pointers */
- if ((selectS = liveRangesWith(lrcs,hasSpilLocnoUptr,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- /* mark this as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
}
- /* find live ranges with spillocation */
- if ((selectS = liveRangesWith(lrcs,hasSpilLoc,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation && not used as pointers */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ /* mark this as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* couldn't find then we need to create a spil
- location on the stack , for which one? the least
- used ofcourse */
- if ((selectS = liveRangesWith(lrcs,noSpilLoc,ebp,ic))) {
-
- /* return a created spil location */
- sym = createStackSpil(leastUsedLR(selectS));
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
-
- /* this is an extreme situation we will spill
- this one : happens very rarely but it does happen */
- spillThis ( forSym );
- return forSym ;
-
+
+ /* couldn't find then we need to create a spil
+ location on the stack , for which one? the least
+ used ofcourse */
+ if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
+ {
+
+ /* return a created spil location */
+ sym = createStackSpil (leastUsedLR (selectS));
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
+ }
+
+ /* this is an extreme situation we will spill
+ this one : happens very rarely but it does happen */
+ spillThis (forSym);
+ return forSym;
+
}
/*-----------------------------------------------------------------*/
/* spilSomething - spil some variable & mark registers as free */
/*-----------------------------------------------------------------*/
-static bool spilSomething (iCode *ic, eBBlock *ebp, symbol *forSym)
+static bool
+spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- symbol *ssym;
- int i ;
-
- debugLog("%s\n",__FUNCTION__);
- /* get something we can spil */
- ssym = selectSpil(ic,ebp,forSym);
-
- /* mark it as spilt */
- ssym->isspilt = 1;
- _G.spiltSet = bitVectSetBit(_G.spiltSet,ssym->key);
-
- /* mark it as not register assigned &
- take it away from the set */
- bitVectUnSetBit(_G.regAssigned,ssym->key);
-
- /* mark the registers as free */
- for (i = 0 ; i < ssym->nRegs ;i++ )
- if (ssym->regs[i])
- freeReg(ssym->regs[i]);
-
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to as gprs */
- if (!pic14_ptrRegReq && isSpiltOnStack(ssym) ) {
- pic14_ptrRegReq++ ;
- spillLRWithPtrReg(ssym);
+ symbol *ssym;
+ int i;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* get something we can spil */
+ ssym = selectSpil (ic, ebp, forSym);
+
+ /* mark it as spilt */
+ ssym->isspilt = 1;
+ _G.spiltSet = bitVectSetBit (_G.spiltSet, ssym->key);
+
+ /* mark it as not register assigned &
+ take it away from the set */
+ bitVectUnSetBit (_G.regAssigned, ssym->key);
+
+ /* mark the registers as free */
+ for (i = 0; i < ssym->nRegs; i++)
+ if (ssym->regs[i])
+ freeReg (ssym->regs[i]);
+
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to as gprs */
+ if (!pic14_ptrRegReq && isSpiltOnStack (ssym))
+ {
+ pic14_ptrRegReq++;
+ spillLRWithPtrReg (ssym);
}
- /* if this was a block level spil then insert push & pop
- at the start & end of block respectively */
- if (ssym->blockSpil) {
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push to the start of the block */
- addiCodeToeBBlock(ebp,nic,( ebp->sch->op == LABEL ?
+ /* if this was a block level spil then insert push & pop
+ at the start & end of block respectively */
+ if (ssym->blockSpil)
+ {
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push to the start of the block */
+ addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
ebp->sch->next : ebp->sch));
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
- }
-
- /* if spilt because not used in the remainder of the
- block then add a push before this instruction and
- a pop at the end of the block */
- if (ssym->remainSpil) {
-
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push just before this instruction */
- addiCodeToeBBlock(ebp,nic,ic);
-
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
+ }
+
+ /* if spilt because not used in the remainder of the
+ block then add a push before this instruction and
+ a pop at the end of the block */
+ if (ssym->remainSpil)
+ {
+
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push just before this instruction */
+ addiCodeToeBBlock (ebp, nic, ic);
+
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
}
- if (ssym == forSym )
- return FALSE ;
- else
- return TRUE ;
+ if (ssym == forSym)
+ return FALSE;
+ else
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* getRegPtr - will try for PTR if not a GPR type if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegPtr (iCode *ic, eBBlock *ebp, symbol *sym)
+static regs *
+getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
+ regs *reg;
- debugLog("%s\n",__FUNCTION__);
- tryAgain:
- /* try for a ptr type */
- if ((reg = allocReg(REG_PTR)))
- return reg;
+ debugLog ("%s\n", __FUNCTION__);
+tryAgain:
+ /* try for a ptr type */
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* getRegGpr - will try for GPR if not spil */
/*-----------------------------------------------------------------*/
-static regs *getRegGpr (iCode *ic, eBBlock *ebp,symbol *sym)
+static regs *
+getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
-
- debugLog("%s\n",__FUNCTION__);
- tryAgain:
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR)))
- return reg;
-
- if (!pic14_ptrRegReq)
- if ((reg = allocReg(REG_PTR)))
- return reg ;
-
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym))
- return NULL ;
-
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ regs *reg;
+
+ debugLog ("%s\n", __FUNCTION__);
+tryAgain:
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ return reg;
+
+ if (!pic14_ptrRegReq)
+ if ((reg = allocReg (REG_PTR)))
+ return reg;
+
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ return NULL;
+
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/*-----------------------------------------------------------------*/
/* symHasReg - symbol has a given register */
/*-----------------------------------------------------------------*/
-static bool symHasReg(symbol *sym,regs *reg)
+static bool
+symHasReg (symbol * sym, regs * reg)
{
- int i;
+ int i;
- debugLog("%s\n",__FUNCTION__);
- for ( i = 0 ; i < sym->nRegs ; i++)
- if (sym->regs[i] == reg)
- return TRUE;
-
- return FALSE;
+ debugLog ("%s\n", __FUNCTION__);
+ for (i = 0; i < sym->nRegs; i++)
+ if (sym->regs[i] == reg)
+ return TRUE;
+
+ return FALSE;
}
/*-----------------------------------------------------------------*/
-/* deassignLRs - check the live to and if they have registers & are*/
+/* deassignLRs - check the live to and if they have registers & are */
/* not spilt then free up the registers */
/*-----------------------------------------------------------------*/
-static void deassignLRs (iCode *ic, eBBlock *ebp)
+static void
+deassignLRs (iCode * ic, eBBlock * ebp)
{
- symbol *sym;
- int k;
- symbol *result;
-
- debugLog("%s\n",__FUNCTION__);
- for (sym = hTabFirstItem(liveRanges,&k); sym;
- sym = hTabNextItem(liveRanges,&k)) {
-
- symbol *psym= NULL;
- /* if it does not end here */
- if (sym->liveTo > ic->seq )
- continue ;
-
- /* if it was spilt on stack then we can
- mark the stack spil location as free */
- if (sym->isspilt ) {
- if (sym->stackSpil) {
- sym->usl.spillLoc->isFree = 1;
- sym->stackSpil = 0;
+ symbol *sym;
+ int k;
+ symbol *result;
+
+ debugLog ("%s\n", __FUNCTION__);
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
+
+ symbol *psym = NULL;
+ /* if it does not end here */
+ if (sym->liveTo > ic->seq)
+ continue;
+
+ /* if it was spilt on stack then we can
+ mark the stack spil location as free */
+ if (sym->isspilt)
+ {
+ if (sym->stackSpil)
+ {
+ sym->usl.spillLoc->isFree = 1;
+ sym->stackSpil = 0;
}
- continue ;
+ continue;
}
-
- if (!bitVectBitValue(_G.regAssigned,sym->key))
- continue;
-
- /* special case check if this is an IFX &
- the privious one was a pop and the
- previous one was not spilt then keep track
- of the symbol */
- if (ic->op == IFX && ic->prev &&
- ic->prev->op == IPOP &&
- !ic->prev->parmPush &&
- !OP_SYMBOL(IC_LEFT(ic->prev))->isspilt)
- psym = OP_SYMBOL(IC_LEFT(ic->prev));
-
- if (sym->nRegs) {
- int i = 0;
-
- bitVectUnSetBit(_G.regAssigned,sym->key);
-
- /* if the result of this one needs registers
- and does not have it then assign it right
- away */
- if (IC_RESULT(ic) &&
- ! (SKIP_IC2(ic) || /* not a special icode */
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- ic->op == RETURN ||
- POINTER_SET(ic)) &&
- (result = OP_SYMBOL(IC_RESULT(ic))) && /* has a result */
- result->liveTo > ic->seq && /* and will live beyond this */
- result->liveTo <= ebp->lSeq && /* does not go beyond this block */
- result->regType == sym->regType && /* same register types */
- result->nRegs && /* which needs registers */
- ! result->isspilt && /* and does not already have them */
- ! result->remat &&
- ! bitVectBitValue(_G.regAssigned,result->key) &&
- /* the number of free regs + number of regs in this LR
- can accomodate the what result Needs */
- ((nfreeRegsType(result->regType) +
- sym->nRegs) >= result->nRegs)
- ) {
-
- for (i = 0 ; i < max(sym->nRegs,result->nRegs) ; i++)
- if (i < sym->nRegs )
- result->regs[i] = sym->regs[i] ;
- else
- result->regs[i] = getRegGpr (ic,ebp,result);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,result->key);
-
- }
-
- /* free the remaining */
- for (; i < sym->nRegs ; i++) {
- if (psym) {
- if (!symHasReg(psym,sym->regs[i]))
- freeReg(sym->regs[i]);
- } else
- freeReg(sym->regs[i]);
+
+ if (!bitVectBitValue (_G.regAssigned, sym->key))
+ continue;
+
+ /* special case check if this is an IFX &
+ the privious one was a pop and the
+ previous one was not spilt then keep track
+ of the symbol */
+ if (ic->op == IFX && ic->prev &&
+ ic->prev->op == IPOP &&
+ !ic->prev->parmPush &&
+ !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
+ psym = OP_SYMBOL (IC_LEFT (ic->prev));
+
+ if (sym->nRegs)
+ {
+ int i = 0;
+
+ bitVectUnSetBit (_G.regAssigned, sym->key);
+
+ /* if the result of this one needs registers
+ and does not have it then assign it right
+ away */
+ if (IC_RESULT (ic) &&
+ !(SKIP_IC2 (ic) || /* not a special icode */
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ ic->op == RETURN ||
+ POINTER_SET (ic)) &&
+ (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
+ result->liveTo > ic->seq && /* and will live beyond this */
+ result->liveTo <= ebp->lSeq && /* does not go beyond this block */
+ result->regType == sym->regType && /* same register types */
+ result->nRegs && /* which needs registers */
+ !result->isspilt && /* and does not already have them */
+ !result->remat &&
+ !bitVectBitValue (_G.regAssigned, result->key) &&
+ /* the number of free regs + number of regs in this LR
+ can accomodate the what result Needs */
+ ((nfreeRegsType (result->regType) +
+ sym->nRegs) >= result->nRegs)
+ )
+ {
+
+ for (i = 0; i < max (sym->nRegs, result->nRegs); i++)
+ if (i < sym->nRegs)
+ result->regs[i] = sym->regs[i];
+ else
+ result->regs[i] = getRegGpr (ic, ebp, result);
+
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key);
+
+ }
+
+ /* free the remaining */
+ for (; i < sym->nRegs; i++)
+ {
+ if (psym)
+ {
+ if (!symHasReg (psym, sym->regs[i]))
+ freeReg (sym->regs[i]);
+ }
+ else
+ freeReg (sym->regs[i]);
}
}
}
/*-----------------------------------------------------------------*/
/* reassignLR - reassign this to registers */
/*-----------------------------------------------------------------*/
-static void reassignLR (operand *op)
+static void
+reassignLR (operand * op)
{
- symbol *sym = OP_SYMBOL(op);
- int i;
+ symbol *sym = OP_SYMBOL (op);
+ int i;
- debugLog("%s\n",__FUNCTION__);
- /* not spilt any more */
- sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
- bitVectUnSetBit(_G.spiltSet,sym->key);
-
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
+ debugLog ("%s\n", __FUNCTION__);
+ /* not spilt any more */
+ sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
+ bitVectUnSetBit (_G.spiltSet, sym->key);
- _G.blockSpil--;
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- for (i=0;i<sym->nRegs;i++)
- sym->regs[i]->isFree = 0;
+ _G.blockSpil--;
+
+ for (i = 0; i < sym->nRegs; i++)
+ sym->regs[i]->isFree = 0;
}
/*-----------------------------------------------------------------*/
/* willCauseSpill - determines if allocating will cause a spill */
/*-----------------------------------------------------------------*/
-static int willCauseSpill ( int nr, int rt)
+static int
+willCauseSpill (int nr, int rt)
{
- debugLog("%s\n",__FUNCTION__);
- /* first check if there are any avlb registers
- of te type required */
- if (rt == REG_PTR) {
- /* special case for pointer type
- if pointer type not avlb then
- check for type gpr */
- if (nFreeRegs(rt) >= nr)
+ debugLog ("%s\n", __FUNCTION__);
+ /* first check if there are any avlb registers
+ of te type required */
+ if (rt == REG_PTR)
+ {
+ /* special case for pointer type
+ if pointer type not avlb then
+ check for type gpr */
+ if (nFreeRegs (rt) >= nr)
+ return 0;
+ if (nFreeRegs (REG_GPR) >= nr)
+ return 0;
+ }
+ else
+ {
+ if (pic14_ptrRegReq)
+ {
+ if (nFreeRegs (rt) >= nr)
return 0;
- if (nFreeRegs(REG_GPR) >= nr)
+ }
+ else
+ {
+ if (nFreeRegs (REG_PTR) +
+ nFreeRegs (REG_GPR) >= nr)
return 0;
- } else {
- if (pic14_ptrRegReq) {
- if (nFreeRegs(rt) >= nr)
- return 0;
- } else {
- if (nFreeRegs(REG_PTR) +
- nFreeRegs(REG_GPR) >= nr)
- return 0;
}
}
- debugLog(" ... yep it will (cause a spill)\n");
- /* it will cause a spil */
- return 1;
+ debugLog (" ... yep it will (cause a spill)\n");
+ /* it will cause a spil */
+ return 1;
}
/*-----------------------------------------------------------------*/
-/* positionRegs - the allocator can allocate same registers to res-*/
+/* positionRegs - the allocator can allocate same registers to res- */
/* ult and operand, if this happens make sure they are in the same */
/* position as the operand otherwise chaos results */
/*-----------------------------------------------------------------*/
-static void positionRegs (symbol *result, symbol *opsym, int lineno)
+static void
+positionRegs (symbol * result, symbol * opsym, int lineno)
{
- int count = min(result->nRegs,opsym->nRegs);
- int i , j = 0, shared = 0;
-
- debugLog("%s\n",__FUNCTION__);
- /* if the result has been spilt then cannot share */
- if (opsym->isspilt)
- return ;
- again:
- shared = 0;
- /* first make sure that they actually share */
- for ( i = 0 ; i < count; i++ ) {
- for (j = 0 ; j < count ; j++ ) {
- if (result->regs[i] == opsym->regs[j] && i !=j) {
- shared = 1;
- goto xchgPositions;
- }
- }
- }
- xchgPositions:
- if (shared) {
- regs *tmp = result->regs[i];
- result->regs[i] = result->regs[j];
- result->regs[j] = tmp;
- goto again;
+ int count = min (result->nRegs, opsym->nRegs);
+ int i, j = 0, shared = 0;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* if the result has been spilt then cannot share */
+ if (opsym->isspilt)
+ return;
+again:
+ shared = 0;
+ /* first make sure that they actually share */
+ for (i = 0; i < count; i++)
+ {
+ for (j = 0; j < count; j++)
+ {
+ if (result->regs[i] == opsym->regs[j] && i != j)
+ {
+ shared = 1;
+ goto xchgPositions;
+ }
}
+ }
+xchgPositions:
+ if (shared)
+ {
+ regs *tmp = result->regs[i];
+ result->regs[i] = result->regs[j];
+ result->regs[j] = tmp;
+ goto again;
+ }
}
/*-----------------------------------------------------------------*/
/* serialRegAssign - serially allocate registers to the variables */
/*-----------------------------------------------------------------*/
-static void serialRegAssign (eBBlock **ebbs, int count)
+static void
+serialRegAssign (eBBlock ** ebbs, int count)
{
- int i;
-
- debugLog("%s\n",__FUNCTION__);
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
-
- iCode *ic;
-
- if (ebbs[i]->noPath &&
- (ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* of all instructions do */
- for (ic = ebbs[i]->sch ; ic ; ic = ic->next) {
-
- debugLog(" op: %s\n", decodeOp(ic->op));
-
- /* if this is an ipop that means some live
- range will have to be assigned again */
- if (ic->op == IPOP)
- reassignLR (IC_LEFT(ic));
-
- /* if result is present && is a true symbol */
- if (IC_RESULT(ic) && ic->op != IFX &&
- IS_TRUE_SYMOP(IC_RESULT(ic)))
- OP_SYMBOL(IC_RESULT(ic))->allocreq = 1;
-
- /* take away registers from live
- ranges that end at this instruction */
- deassignLRs (ic, ebbs[i]) ;
-
- /* some don't need registers */
- if (SKIP_IC2(ic) ||
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- (IC_RESULT(ic) &&POINTER_SET(ic)) )
- continue;
-
- /* now we need to allocate registers
- only for the result */
- if (IC_RESULT(ic)) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- bitVect *spillable;
- int willCS ;
- int j;
- int ptrRegSet = 0;
-
- /* if it does not need or is spilt
- or is already assigned to registers
- or will not live beyond this instructions */
- if (!sym->nRegs ||
- sym->isspilt ||
- bitVectBitValue(_G.regAssigned,sym->key) ||
- sym->liveTo <= ic->seq)
- continue ;
-
- /* if some liverange has been spilt at the block level
- and this one live beyond this block then spil this
- to be safe */
- if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq) {
- spillThis (sym);
- continue ;
+ int i;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* of all instructions do */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ debugLog (" op: %s\n", decodeOp (ic->op));
+
+ /* if this is an ipop that means some live
+ range will have to be assigned again */
+ if (ic->op == IPOP)
+ reassignLR (IC_LEFT (ic));
+
+ /* if result is present && is a true symbol */
+ if (IC_RESULT (ic) && ic->op != IFX &&
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
+
+ /* take away registers from live
+ ranges that end at this instruction */
+ deassignLRs (ic, ebbs[i]);
+
+ /* some don't need registers */
+ if (SKIP_IC2 (ic) ||
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ (IC_RESULT (ic) && POINTER_SET (ic)))
+ continue;
+
+ /* now we need to allocate registers
+ only for the result */
+ if (IC_RESULT (ic))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ bitVect *spillable;
+ int willCS;
+ int j;
+ int ptrRegSet = 0;
+
+ /* if it does not need or is spilt
+ or is already assigned to registers
+ or will not live beyond this instructions */
+ if (!sym->nRegs ||
+ sym->isspilt ||
+ bitVectBitValue (_G.regAssigned, sym->key) ||
+ sym->liveTo <= ic->seq)
+ continue;
+
+ /* if some liverange has been spilt at the block level
+ and this one live beyond this block then spil this
+ to be safe */
+ if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
+ {
+ spillThis (sym);
+ continue;
}
- /* if trying to allocate this will cause
- a spill and there is nothing to spill
- or this one is rematerializable then
- spill this one */
- willCS = willCauseSpill(sym->nRegs,sym->regType);
- spillable = computeSpillable(ic);
- if ( sym->remat ||
- (willCS && bitVectIsZero(spillable) ) ) {
-
- spillThis (sym) ;
- continue ;
+ /* if trying to allocate this will cause
+ a spill and there is nothing to spill
+ or this one is rematerializable then
+ spill this one */
+ willCS = willCauseSpill (sym->nRegs, sym->regType);
+ spillable = computeSpillable (ic);
+ if (sym->remat ||
+ (willCS && bitVectIsZero (spillable)))
+ {
+
+ spillThis (sym);
+ continue;
}
- /* if it has a spillocation & is used less than
- all other live ranges then spill this */
- if ( willCS && sym->usl.spillLoc ) {
-
- symbol *leastUsed =
- leastUsedLR(liveRangesWith (spillable ,
- allLRs,
- ebbs[i],
- ic));
- if (leastUsed &&
- leastUsed->used > sym->used) {
- spillThis (sym);
- continue;
- }
- }
-
- if(ic->op == RECEIVE)
- debugLog("When I get clever, I'll optimize the receive logic\n");
-
- /* if we need ptr regs for the right side
- then mark it */
- if (POINTER_GET(ic) && getSize(OP_SYMBOL(IC_LEFT(ic))->type)
- <= PTRSIZE)
+ /* if it has a spillocation & is used less than
+ all other live ranges then spill this */
+ if (willCS && sym->usl.spillLoc)
{
- pic14_ptrRegReq++;
- ptrRegSet = 1;
+
+ symbol *leastUsed =
+ leastUsedLR (liveRangesWith (spillable,
+ allLRs,
+ ebbs[i],
+ ic));
+ if (leastUsed &&
+ leastUsed->used > sym->used)
+ {
+ spillThis (sym);
+ continue;
+ }
}
- /* else we assign registers to it */
- _G.regAssigned = bitVectSetBit(_G.regAssigned,sym->key);
- debugLog(" %d - \n",__LINE__);
+ if (ic->op == RECEIVE)
+ debugLog ("When I get clever, I'll optimize the receive logic\n");
- for (j = 0 ; j < sym->nRegs ;j++ ) {
- if (sym->regType == REG_PTR)
- sym->regs[j] = getRegPtr(ic,ebbs[i],sym);
- else
- sym->regs[j] = getRegGpr(ic,ebbs[i],sym);
+ /* if we need ptr regs for the right side
+ then mark it */
+ if (POINTER_GET (ic) && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
+ <= PTRSIZE)
+ {
+ pic14_ptrRegReq++;
+ ptrRegSet = 1;
+ }
+ /* else we assign registers to it */
+ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- /* if the allocation falied which means
- this was spilt then break */
- if (!sym->regs[j])
- break;
+ debugLog (" %d - \n", __LINE__);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ if (sym->regType == REG_PTR)
+ sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
+ else
+ sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
+
+ /* if the allocation falied which means
+ this was spilt then break */
+ if (!sym->regs[j])
+ break;
}
- debugLog(" %d - \n",__LINE__);
-
- /* if it shares registers with operands make sure
- that they are in the same position */
- if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->nRegs && ic->op != '=')
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_LEFT(ic)),ic->lineno);
- /* do the same for the right operand */
- if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->nRegs && ic->op != '=')
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_RIGHT(ic)),ic->lineno);
-
- debugLog(" %d - \n",__LINE__);
- if (ptrRegSet) {
- debugLog(" %d - \n",__LINE__);
- pic14_ptrRegReq--;
- ptrRegSet = 0;
+ debugLog (" %d - \n", __LINE__);
+
+ /* if it shares registers with operands make sure
+ that they are in the same position */
+ if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
+ /* do the same for the right operand */
+ if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->nRegs && ic->op != '=')
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
+
+ debugLog (" %d - \n", __LINE__);
+ if (ptrRegSet)
+ {
+ debugLog (" %d - \n", __LINE__);
+ pic14_ptrRegReq--;
+ ptrRegSet = 0;
}
-
- }
+
+ }
}
}
}
/*-----------------------------------------------------------------*/
/* rUmaskForOp :- returns register mask for an operand */
/*-----------------------------------------------------------------*/
-static bitVect *rUmaskForOp (operand *op)
+static bitVect *
+rUmaskForOp (operand * op)
{
- bitVect *rumask;
- symbol *sym;
- int j;
-
- debugLog("%s\n",__FUNCTION__);
- /* only temporaries are assigned registers */
- if (!IS_ITEMP(op))
- return NULL;
+ bitVect *rumask;
+ symbol *sym;
+ int j;
- sym = OP_SYMBOL(op);
-
- /* if spilt or no registers assigned to it
- then nothing */
- if (sym->isspilt || !sym->nRegs)
- return NULL;
+ debugLog ("%s\n", __FUNCTION__);
+ /* only temporaries are assigned registers */
+ if (!IS_ITEMP (op))
+ return NULL;
- rumask = newBitVect(pic14_nRegs);
+ sym = OP_SYMBOL (op);
- for (j = 0; j < sym->nRegs; j++) {
- rumask = bitVectSetBit(rumask,
- sym->regs[j]->rIdx);
+ /* if spilt or no registers assigned to it
+ then nothing */
+ if (sym->isspilt || !sym->nRegs)
+ return NULL;
+
+ rumask = newBitVect (pic14_nRegs);
+
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ rumask = bitVectSetBit (rumask,
+ sym->regs[j]->rIdx);
}
- return rumask;
+ return rumask;
}
/*-----------------------------------------------------------------*/
-/* regsUsedIniCode :- returns bit vector of registers used in iCode*/
+/* regsUsedIniCode :- returns bit vector of registers used in iCode */
/*-----------------------------------------------------------------*/
-static bitVect *regsUsedIniCode (iCode *ic)
+static bitVect *
+regsUsedIniCode (iCode * ic)
{
- bitVect *rmask = newBitVect(pic14_nRegs);
-
- debugLog("%s\n",__FUNCTION__);
- /* do the special cases first */
- if (ic->op == IFX ) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_COND(ic)));
- goto ret;
+ bitVect *rmask = newBitVect (pic14_nRegs);
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* do the special cases first */
+ if (ic->op == IFX)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_COND (ic)));
+ goto ret;
}
- /* for the jumptable */
- if (ic->op == JUMPTABLE) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_JTCOND(ic)));
+ /* for the jumptable */
+ if (ic->op == JUMPTABLE)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_JTCOND (ic)));
- goto ret;
+ goto ret;
}
- /* of all other cases */
- if (IC_LEFT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_LEFT(ic)));
-
-
- if (IC_RIGHT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RIGHT(ic)));
-
- if (IC_RESULT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RESULT(ic)));
-
- ret:
- return rmask;
+ /* of all other cases */
+ if (IC_LEFT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_LEFT (ic)));
+
+
+ if (IC_RIGHT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RIGHT (ic)));
+
+ if (IC_RESULT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RESULT (ic)));
+
+ret:
+ return rmask;
}
/*-----------------------------------------------------------------*/
-/* createRegMask - for each instruction will determine the regsUsed*/
+/* createRegMask - for each instruction will determine the regsUsed */
/*-----------------------------------------------------------------*/
-static void createRegMask (eBBlock **ebbs, int count)
+static void
+createRegMask (eBBlock ** ebbs, int count)
{
- int i;
-
- debugLog("%s\n",__FUNCTION__);
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
- iCode *ic ;
-
- if ( ebbs[i]->noPath &&
- ( ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* for all instructions */
- for ( ic = ebbs[i]->sch ; ic ; ic = ic->next ) {
-
- int j;
-
- if (SKIP_IC2(ic) || !ic->rlive)
- continue ;
-
- /* first mark the registers used in this
- instruction */
- ic->rUsed = regsUsedIniCode(ic);
- _G.funcrUsed = bitVectUnion(_G.funcrUsed,ic->rUsed);
-
- /* now create the register mask for those
- registers that are in use : this is a
- super set of ic->rUsed */
- ic->rMask = newBitVect(pic14_nRegs+1);
-
- /* for all live Ranges alive at this point */
- for (j = 1; j < ic->rlive->size; j++ ) {
- symbol *sym;
- int k;
-
- /* if not alive then continue */
- if (!bitVectBitValue(ic->rlive,j))
- continue ;
-
- /* find the live range we are interested in */
- if (!(sym = hTabItemWithKey(liveRanges,j))) {
- werror (E_INTERNAL_ERROR,__FILE__,__LINE__,
- "createRegMask cannot find live range");
- exit(0);
+ int i;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* for all instructions */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ int j;
+
+ if (SKIP_IC2 (ic) || !ic->rlive)
+ continue;
+
+ /* first mark the registers used in this
+ instruction */
+ ic->rUsed = regsUsedIniCode (ic);
+ _G.funcrUsed = bitVectUnion (_G.funcrUsed, ic->rUsed);
+
+ /* now create the register mask for those
+ registers that are in use : this is a
+ super set of ic->rUsed */
+ ic->rMask = newBitVect (pic14_nRegs + 1);
+
+ /* for all live Ranges alive at this point */
+ for (j = 1; j < ic->rlive->size; j++)
+ {
+ symbol *sym;
+ int k;
+
+ /* if not alive then continue */
+ if (!bitVectBitValue (ic->rlive, j))
+ continue;
+
+ /* find the live range we are interested in */
+ if (!(sym = hTabItemWithKey (liveRanges, j)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "createRegMask cannot find live range");
+ exit (0);
}
- /* if no register assigned to it */
- if (!sym->nRegs || sym->isspilt)
- continue ;
+ /* if no register assigned to it */
+ if (!sym->nRegs || sym->isspilt)
+ continue;
- /* for all the registers allocated to it */
- for (k = 0 ; k < sym->nRegs ;k++)
- if (sym->regs[k])
- ic->rMask =
- bitVectSetBit(ic->rMask,sym->regs[k]->rIdx);
+ /* for all the registers allocated to it */
+ for (k = 0; k < sym->nRegs; k++)
+ if (sym->regs[k])
+ ic->rMask =
+ bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
}
}
}
/*-----------------------------------------------------------------*/
/* rematStr - returns the rematerialized string for a remat var */
/*-----------------------------------------------------------------*/
-static char *rematStr (symbol *sym)
+static char *
+rematStr (symbol * sym)
{
- char *s = buffer;
- iCode *ic = sym->rematiCode;
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
- debugLog("%s\n",__FUNCTION__);
- while (1) {
+ debugLog ("%s\n", __FUNCTION__);
+ while (1)
+ {
- printf("%s\n",s);
- /* if plus or minus print the right hand side */
+ printf ("%s\n", s);
+ /* if plus or minus print the right hand side */
/*
- if (ic->op == '+' || ic->op == '-') {
- sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
- ic->op );
- s += strlen(s);
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- continue ;
- }
-*/
- if (ic->op == '+' || ic->op == '-') {
- iCode *ric = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- sprintf(s,"(%s %c 0x%04x)",
- OP_SYMBOL(IC_LEFT(ric))->rname,
- ic->op,
- (int) operandLitValue(IC_RIGHT(ic)));
-
- //s += strlen(s);
- //ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- //continue ;
- return buffer;
- }
-
- /* we reached the end */
- sprintf(s,"%s\n",OP_SYMBOL(IC_LEFT(ic))->rname);
- break;
+ if (ic->op == '+' || ic->op == '-') {
+ sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
+ ic->op );
+ s += strlen(s);
+ ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
+ continue ;
+ }
+ */
+ if (ic->op == '+' || ic->op == '-')
+ {
+ iCode *ric = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ sprintf (s, "(%s %c 0x%04x)",
+ OP_SYMBOL (IC_LEFT (ric))->rname,
+ ic->op,
+ (int) operandLitValue (IC_RIGHT (ic)));
+
+ //s += strlen(s);
+ //ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
+ //continue ;
+ return buffer;
+ }
+
+ /* we reached the end */
+ sprintf (s, "%s\n", OP_SYMBOL (IC_LEFT (ic))->rname);
+ break;
}
- printf("%s\n",buffer);
- return buffer ;
+ printf ("%s\n", buffer);
+ return buffer;
}
/*-----------------------------------------------------------------*/
/* regTypeNum - computes the type & number of registers required */
/*-----------------------------------------------------------------*/
-static void regTypeNum ()
+static void
+regTypeNum ()
{
- symbol *sym;
- int k;
- iCode *ic;
-
- debugLog("%s\n",__FUNCTION__);
- /* for each live range do */
- for ( sym = hTabFirstItem(liveRanges,&k); sym ;
- sym = hTabNextItem(liveRanges,&k)) {
+ symbol *sym;
+ int k;
+ iCode *ic;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* for each live range do */
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
- debugLog(" %d - %s\n",__LINE__ , sym->rname);
+ debugLog (" %d - %s\n", __LINE__, sym->rname);
- /* if used zero times then no registers needed */
- if ((sym->liveTo - sym->liveFrom) == 0)
- continue ;
+ /* if used zero times then no registers needed */
+ if ((sym->liveTo - sym->liveFrom) == 0)
+ continue;
- /* if the live range is a temporary */
- if (sym->isitmp) {
+ /* if the live range is a temporary */
+ if (sym->isitmp)
+ {
- debugLog(" %d - \n",__LINE__);
+ debugLog (" %d - \n", __LINE__);
- /* if the type is marked as a conditional */
- if (sym->regType == REG_CND)
- continue ;
+ /* if the type is marked as a conditional */
+ if (sym->regType == REG_CND)
+ continue;
- /* if used in return only then we don't
- need registers */
- if (sym->ruonly || sym->accuse) {
- if (IS_AGGREGATE(sym->type) || sym->isptr)
- sym->type = aggrToPtr(sym->type,FALSE);
- debugLog(" %d - \n",__LINE__);
+ /* if used in return only then we don't
+ need registers */
+ if (sym->ruonly || sym->accuse)
+ {
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ sym->type = aggrToPtr (sym->type, FALSE);
+ debugLog (" %d - \n", __LINE__);
- continue ;
+ continue;
}
-
- /* if the symbol has only one definition &
- that definition is a get_pointer and the
- pointer we are getting is rematerializable and
- in "data" space */
-
- if (bitVectnBitsOn(sym->defs) == 1 &&
- (ic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(sym->defs))) &&
- POINTER_GET(ic) &&
- !IS_BITVAR(sym->etype)) {
-
- debugLog(" %d - \n",__LINE__);
-
- /* if remat in data space */
- if (OP_SYMBOL(IC_LEFT(ic))->remat &&
- DCL_TYPE(aggrToPtr(sym->type,FALSE)) == POINTER) {
-
- /* create a psuedo symbol & force a spil */
- symbol *psym = newSymbol(rematStr(OP_SYMBOL(IC_LEFT(ic))),1);
- psym->type = sym->type;
- psym->etype = sym->etype;
- strcpy(psym->rname,psym->name);
- sym->isspilt = 1;
- sym->usl.spillLoc = psym;
- continue ;
+
+ /* if the symbol has only one definition &
+ that definition is a get_pointer and the
+ pointer we are getting is rematerializable and
+ in "data" space */
+
+ if (bitVectnBitsOn (sym->defs) == 1 &&
+ (ic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (sym->defs))) &&
+ POINTER_GET (ic) &&
+ !IS_BITVAR (sym->etype))
+ {
+
+ debugLog (" %d - \n", __LINE__);
+
+ /* if remat in data space */
+ if (OP_SYMBOL (IC_LEFT (ic))->remat &&
+ DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER)
+ {
+
+ /* create a psuedo symbol & force a spil */
+ symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
+ psym->type = sym->type;
+ psym->etype = sym->etype;
+ strcpy (psym->rname, psym->name);
+ sym->isspilt = 1;
+ sym->usl.spillLoc = psym;
+ continue;
}
- /* if in data space or idata space then try to
- allocate pointer register */
-
+ /* if in data space or idata space then try to
+ allocate pointer register */
+
+ }
+
+ /* if not then we require registers */
+ sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
+ getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
+ getSize (sym->type));
+
+ if (sym->nRegs > 4)
+ {
+ fprintf (stderr, "allocated more than 4 or 0 registers for type ");
+ printTypeChain (sym->type, stderr);
+ fprintf (stderr, "\n");
}
-
- /* if not then we require registers */
- sym->nRegs = ((IS_AGGREGATE(sym->type) || sym->isptr ) ?
- getSize(sym->type = aggrToPtr(sym->type,FALSE)) :
- getSize(sym->type));
-
- if (sym->nRegs > 4) {
- fprintf(stderr,"allocated more than 4 or 0 registers for type ");
- printTypeChain(sym->type,stderr);fprintf(stderr,"\n");
- }
-
- debugLog(" %d - \n",__LINE__);
-
- /* determine the type of register required */
- if (sym->nRegs == 1 &&
- IS_PTR(sym->type) &&
- sym->uptr)
- sym->regType = REG_PTR ;
- else
- sym->regType = REG_GPR ;
- debugLog(" reg type %s\n",debugLogRegType(sym->regType));
-
- } else
- /* for the first run we don't provide */
- /* registers for true symbols we will */
- /* see how things go */
- sym->nRegs = 0 ;
+
+ debugLog (" %d - \n", __LINE__);
+
+ /* determine the type of register required */
+ if (sym->nRegs == 1 &&
+ IS_PTR (sym->type) &&
+ sym->uptr)
+ sym->regType = REG_PTR;
+ else
+ sym->regType = REG_GPR;
+ debugLog (" reg type %s\n", debugLogRegType (sym->regType));
+
+ }
+ else
+ /* for the first run we don't provide */
+ /* registers for true symbols we will */
+ /* see how things go */
+ sym->nRegs = 0;
}
-
+
}
/*-----------------------------------------------------------------*/
/* freeAllRegs - mark all registers as free */
/*-----------------------------------------------------------------*/
-static void freeAllRegs()
+static void
+freeAllRegs ()
{
- int i;
+ int i;
- debugLog("%s\n",__FUNCTION__);
- for (i=0;i< pic14_nRegs;i++ )
- regspic14[i].isFree = 1;
+ debugLog ("%s\n", __FUNCTION__);
+ for (i = 0; i < pic14_nRegs; i++)
+ regspic14[i].isFree = 1;
}
/*-----------------------------------------------------------------*/
/* deallocStackSpil - this will set the stack pointer back */
/*-----------------------------------------------------------------*/
-static DEFSETFUNC(deallocStackSpil)
+static
+DEFSETFUNC (deallocStackSpil)
{
- symbol *sym = item;
+ symbol *sym = item;
- debugLog("%s\n",__FUNCTION__);
- deallocLocal(sym);
- return 0;
+ debugLog ("%s\n", __FUNCTION__);
+ deallocLocal (sym);
+ return 0;
}
/*-----------------------------------------------------------------*/
/* farSpacePackable - returns the packable icode for far variables */
/*-----------------------------------------------------------------*/
-static iCode *farSpacePackable (iCode *ic)
+static iCode *
+farSpacePackable (iCode * ic)
{
- iCode *dic ;
-
- debugLog("%s\n",__FUNCTION__);
- /* go thru till we find a definition for the
- symbol on the right */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if the definition is a call then no */
- if ((dic->op == CALL || dic->op == PCALL) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- return NULL;
+ iCode *dic;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* go thru till we find a definition for the
+ symbol on the right */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if the definition is a call then no */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ return NULL;
}
-
- /* if shift by unknown amount then not */
- if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key)
- return NULL;
- /* if pointer get and size > 1 */
- if (POINTER_GET(dic) &&
- getSize(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if shift by unknown amount then not */
+ if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ return NULL;
- if (POINTER_SET(dic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)) > 1)
- return NULL ;
+ /* if pointer get and size > 1 */
+ if (POINTER_GET (dic) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) > 1)
+ return NULL;
- /* if any three is a true symbol in far space */
- if (IC_RESULT(dic) &&
- IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- isOperandInFarSpace(IC_RESULT(dic)))
- return NULL;
+ if (POINTER_SET (dic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)) > 1)
+ return NULL;
- if (IC_RIGHT(dic) &&
- IS_TRUE_SYMOP(IC_RIGHT(dic)) &&
- isOperandInFarSpace(IC_RIGHT(dic)) &&
- !isOperandEqual(IC_RIGHT(dic),IC_RESULT(ic)))
- return NULL;
+ /* if any three is a true symbol in far space */
+ if (IC_RESULT (dic) &&
+ IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ isOperandInFarSpace (IC_RESULT (dic)))
+ return NULL;
+
+ if (IC_RIGHT (dic) &&
+ IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
+ isOperandInFarSpace (IC_RIGHT (dic)) &&
+ !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
+ return NULL;
- if (IC_LEFT(dic) &&
- IS_TRUE_SYMOP(IC_LEFT(dic)) &&
- isOperandInFarSpace(IC_LEFT(dic)) &&
- !isOperandEqual(IC_LEFT(dic),IC_RESULT(ic)))
+ if (IC_LEFT (dic) &&
+ IS_TRUE_SYMOP (IC_LEFT (dic)) &&
+ isOperandInFarSpace (IC_LEFT (dic)) &&
+ !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
+ return NULL;
+
+ if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic)))
+ {
+ if ((dic->op == LEFT_OP ||
+ dic->op == RIGHT_OP ||
+ dic->op == '-') &&
+ IS_OP_LITERAL (IC_RIGHT (dic)))
return NULL;
-
- if (isOperandEqual(IC_RIGHT(ic),IC_RESULT(dic))) {
- if ( (dic->op == LEFT_OP ||
- dic->op == RIGHT_OP ||
- dic->op == '-') &&
- IS_OP_LITERAL(IC_RIGHT(dic)))
- return NULL;
- else
- return dic;
+ else
+ return dic;
}
}
- return NULL;
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* packRegsForAssign - register reduction for assignment */
/*-----------------------------------------------------------------*/
-static int packRegsForAssign (iCode *ic,eBBlock *ebp)
+static int
+packRegsForAssign (iCode * ic, eBBlock * ebp)
{
- iCode *dic, *sic;
-
- debugLog("%s\n",__FUNCTION__);
+ iCode *dic, *sic;
- debugAopGet(" result:",IC_RESULT(ic));
- debugAopGet(" left:",IC_LEFT(ic));
- debugAopGet(" right:",IC_RIGHT(ic));
+ debugLog ("%s\n", __FUNCTION__);
- if (!IS_ITEMP(IC_RIGHT(ic)) ||
- OP_SYMBOL(IC_RIGHT(ic))->isind ||
- OP_LIVETO(IC_RIGHT(ic)) > ic->seq) {
- return 0;
+ debugAopGet (" result:", IC_RESULT (ic));
+ debugAopGet (" left:", IC_LEFT (ic));
+ debugAopGet (" right:", IC_RIGHT (ic));
+
+ if (!IS_ITEMP (IC_RIGHT (ic)) ||
+ OP_SYMBOL (IC_RIGHT (ic))->isind ||
+ OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
+ {
+ return 0;
}
-
- /* if the true symbol is defined in far space or on stack
- then we should not since this will increase register pressure */
- if (isOperandInFarSpace(IC_RESULT(ic))) {
- if ((dic = farSpacePackable(ic)))
- goto pack;
- else
- return 0;
-
+
+ /* if the true symbol is defined in far space or on stack
+ then we should not since this will increase register pressure */
+ if (isOperandInFarSpace (IC_RESULT (ic)))
+ {
+ if ((dic = farSpacePackable (ic)))
+ goto pack;
+ else
+ return 0;
+
}
- /* find the definition of iTempNN scanning backwards if we find a
- a use of the true symbol before we find the definition then
- we cannot pack */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if there is a function call and this is
- a parameter & not my parameter then don't pack it */
- if ( (dic->op == CALL || dic->op == PCALL) &&
- (OP_SYMBOL(IC_RESULT(ic))->_isparm &&
- !OP_SYMBOL(IC_RESULT(ic))->ismyparm)) {
- debugLog(" %d - \n",__LINE__);
- dic = NULL;
- break;
+ /* find the definition of iTempNN scanning backwards if we find a
+ a use of the true symbol before we find the definition then
+ we cannot pack */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if there is a function call and this is
+ a parameter & not my parameter then don't pack it */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ (OP_SYMBOL (IC_RESULT (ic))->_isparm &&
+ !OP_SYMBOL (IC_RESULT (ic))->ismyparm))
+ {
+ debugLog (" %d - \n", __LINE__);
+ dic = NULL;
+ break;
}
- if (SKIP_IC2(dic))
- continue;
+ if (SKIP_IC2 (dic))
+ continue;
- if (IS_TRUE_SYMOP(IC_RESULT(dic)) &&
- IS_OP_VOLATILE(IC_RESULT(dic))) {
- debugLog(" %d - \n",__LINE__);
- dic = NULL;
- break;
+ if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ IS_OP_VOLATILE (IC_RESULT (dic)))
+ {
+ debugLog (" %d - \n", __LINE__);
+ dic = NULL;
+ break;
}
- if (IS_SYMOP(IC_RESULT(dic)) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- debugLog(" %d - dic key == ic key -- pointer set=%c\n",__LINE__,((POINTER_SET(dic)) ? 'Y' :'N') );
- if (POINTER_SET(dic))
- dic = NULL;
+ if (IS_SYMOP (IC_RESULT (dic)) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ debugLog (" %d - dic key == ic key -- pointer set=%c\n", __LINE__, ((POINTER_SET (dic)) ? 'Y' : 'N'));
+ if (POINTER_SET (dic))
+ dic = NULL;
- break;
+ break;
}
- if (IS_SYMOP(IC_RIGHT(dic)) &&
- (IC_RIGHT(dic)->key == IC_RESULT(ic)->key ||
- IC_RIGHT(dic)->key == IC_RIGHT(ic)->key)) {
- debugLog(" %d - \n",__LINE__);
- dic = NULL;
- break;
+ if (IS_SYMOP (IC_RIGHT (dic)) &&
+ (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
+ IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ debugLog (" %d - \n", __LINE__);
+ dic = NULL;
+ break;
}
-
- if (IS_SYMOP(IC_LEFT(dic)) &&
- (IC_LEFT(dic)->key == IC_RESULT(ic)->key ||
- IC_LEFT(dic)->key == IC_RIGHT(ic)->key)) {
- debugLog(" %d - \n",__LINE__);
- dic = NULL;
- break;
+
+ if (IS_SYMOP (IC_LEFT (dic)) &&
+ (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
+ IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ debugLog (" %d - \n", __LINE__);
+ dic = NULL;
+ break;
}
- if (POINTER_SET(dic) &&
- IC_RESULT(dic)->key == IC_RESULT(ic)->key ) {
- debugLog(" %d - \n",__LINE__);
- dic = NULL ;
- break;
+ if (POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == IC_RESULT (ic)->key)
+ {
+ debugLog (" %d - \n", __LINE__);
+ dic = NULL;
+ break;
}
}
-
- if (!dic)
- return 0 ; /* did not find */
-
- /* if the result is on stack or iaccess then it must be
- the same atleast one of the operands */
- if (OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess ) {
-
- /* the operation has only one symbol
- operator then we can pack */
- if ((IC_LEFT(dic) && !IS_SYMOP(IC_LEFT(dic))) ||
- (IC_RIGHT(dic) && !IS_SYMOP(IC_RIGHT(dic))))
- goto pack;
-
- if (!((IC_LEFT(dic) &&
- IC_RESULT(ic)->key == IC_LEFT(dic)->key) ||
- (IC_RIGHT(dic) &&
- IC_RESULT(ic)->key == IC_RIGHT(dic)->key)))
- return 0;
+
+ if (!dic)
+ return 0; /* did not find */
+
+ /* if the result is on stack or iaccess then it must be
+ the same atleast one of the operands */
+ if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess)
+ {
+
+ /* the operation has only one symbol
+ operator then we can pack */
+ if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
+ (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
+ goto pack;
+
+ if (!((IC_LEFT (dic) &&
+ IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
+ (IC_RIGHT (dic) &&
+ IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
+ return 0;
}
pack:
- debugLog(" packing. removing %s\n",OP_SYMBOL(IC_RIGHT(ic))->rname);
- /* found the definition */
- /* replace the result with the result of */
- /* this assignment and remove this assignment */
- IC_RESULT(dic) = IC_RESULT(ic) ;
-
- if (IS_ITEMP(IC_RESULT(dic)) && OP_SYMBOL(IC_RESULT(dic))->liveFrom > dic->seq) {
- OP_SYMBOL(IC_RESULT(dic))->liveFrom = dic->seq;
+ debugLog (" packing. removing %s\n", OP_SYMBOL (IC_RIGHT (ic))->rname);
+ /* found the definition */
+ /* replace the result with the result of */
+ /* this assignment and remove this assignment */
+ IC_RESULT (dic) = IC_RESULT (ic);
+
+ if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
+ {
+ OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
}
- /* delete from liverange table also
- delete from all the points inbetween and the new
- one */
- for ( sic = dic; sic != ic ; sic = sic->next ) {
- bitVectUnSetBit(sic->rlive,IC_RESULT(ic)->key);
- if (IS_ITEMP(IC_RESULT(dic)))
- bitVectSetBit(sic->rlive,IC_RESULT(dic)->key);
+ /* delete from liverange table also
+ delete from all the points inbetween and the new
+ one */
+ for (sic = dic; sic != ic; sic = sic->next)
+ {
+ bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
+ if (IS_ITEMP (IC_RESULT (dic)))
+ bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
}
-
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- return 1;
-
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ return 1;
+
+
}
/*-----------------------------------------------------------------*/
-/* findAssignToSym : scanning backwards looks for first assig found*/
+/* findAssignToSym : scanning backwards looks for first assig found */
/*-----------------------------------------------------------------*/
-static iCode *findAssignToSym (operand *op,iCode *ic)
+static iCode *
+findAssignToSym (operand * op, iCode * ic)
{
- iCode *dic;
-
- debugLog("%s\n",__FUNCTION__);
- for (dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if definition by assignment */
- if (dic->op == '=' &&
- !POINTER_SET(dic) &&
- IC_RESULT(dic)->key == op->key
-/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
- ) {
-
- /* we are interested only if defined in far space */
- /* or in stack space in case of + & - */
-
- /* if assigned to a non-symbol then return
- true */
- if (!IS_SYMOP(IC_RIGHT(dic)))
- break ;
-
- /* if the symbol is in far space then
- we should not */
- if (isOperandInFarSpace(IC_RIGHT(dic)))
- return NULL ;
-
- /* for + & - operations make sure that
- if it is on the stack it is the same
- as one of the three operands */
- if ((ic->op == '+' || ic->op == '-') &&
- OP_SYMBOL(IC_RIGHT(dic))->onStack) {
-
- if ( IC_RESULT(ic)->key != IC_RIGHT(dic)->key &&
- IC_LEFT(ic)->key != IC_RIGHT(dic)->key &&
- IC_RIGHT(ic)->key != IC_RIGHT(dic)->key)
- return NULL;
- }
-
- break ;
-
- }
+ iCode *dic;
- /* if we find an usage then we cannot delete it */
- if (IC_LEFT(dic) && IC_LEFT(dic)->key == op->key)
- return NULL;
-
- if (IC_RIGHT(dic) && IC_RIGHT(dic)->key == op->key)
- return NULL;
+ debugLog ("%s\n", __FUNCTION__);
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+
+ /* if definition by assignment */
+ if (dic->op == '=' &&
+ !POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == op->key
+/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
+ )
+ {
+
+ /* we are interested only if defined in far space */
+ /* or in stack space in case of + & - */
+
+ /* if assigned to a non-symbol then return
+ true */
+ if (!IS_SYMOP (IC_RIGHT (dic)))
+ break;
- if (POINTER_SET(dic) && IC_RESULT(dic)->key == op->key)
+ /* if the symbol is in far space then
+ we should not */
+ if (isOperandInFarSpace (IC_RIGHT (dic)))
return NULL;
- }
- /* now make sure that the right side of dic
- is not defined between ic & dic */
- if (dic) {
- iCode *sic = dic->next ;
+ /* for + & - operations make sure that
+ if it is on the stack it is the same
+ as one of the three operands */
+ if ((ic->op == '+' || ic->op == '-') &&
+ OP_SYMBOL (IC_RIGHT (dic))->onStack)
+ {
- for (; sic != ic ; sic = sic->next)
- if (IC_RESULT(sic) &&
- IC_RESULT(sic)->key == IC_RIGHT(dic)->key)
+ if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
return NULL;
+ }
+
+ break;
+
+ }
+
+ /* if we find an usage then we cannot delete it */
+ if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
+ return NULL;
+
+ if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
+ return NULL;
+
+ if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
+ return NULL;
}
- return dic;
-
-
+ /* now make sure that the right side of dic
+ is not defined between ic & dic */
+ if (dic)
+ {
+ iCode *sic = dic->next;
+
+ for (; sic != ic; sic = sic->next)
+ if (IC_RESULT (sic) &&
+ IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
+ return NULL;
+ }
+
+ return dic;
+
+
}
/*-----------------------------------------------------------------*/
/* packRegsForSupport :- reduce some registers for support calls */
/*-----------------------------------------------------------------*/
-static int packRegsForSupport (iCode *ic, eBBlock *ebp)
+static int
+packRegsForSupport (iCode * ic, eBBlock * ebp)
{
- int change = 0 ;
-
- debugLog("%s\n",__FUNCTION__);
- /* for the left & right operand :- look to see if the
- left was assigned a true symbol in far space in that
- case replace them */
- if (IS_ITEMP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_LEFT(ic),ic);
- iCode *sic;
-
- if (!dic)
- goto right ;
-
- debugAopGet("removing left:",IC_LEFT(ic));
-
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_LEFT(ic)->key);
-
- IC_LEFT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_LEFT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change++;
+ int change = 0;
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* for the left & right operand :- look to see if the
+ left was assigned a true symbol in far space in that
+ case replace them */
+ if (IS_ITEMP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ goto right;
+
+ debugAopGet ("removing left:", IC_LEFT (ic));
+
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
+
+ IC_LEFT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- /* do the same for the right operand */
- right:
- if (!change &&
- IS_ITEMP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_RIGHT(ic),ic);
- iCode *sic;
-
- if (!dic)
- return change ;
-
- /* if this is a subtraction & the result
- is a true symbol in far space then don't pack */
- if (ic->op == '-' && IS_TRUE_SYMOP(IC_RESULT(dic))) {
- sym_link *etype =getSpec(operandType(IC_RESULT(dic)));
- if (IN_FARSPACE(SPEC_OCLS(etype)))
- return change ;
+
+ /* do the same for the right operand */
+right:
+ if (!change &&
+ IS_ITEMP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ return change;
+
+ /* if this is a subtraction & the result
+ is a true symbol in far space then don't pack */
+ if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic)))
+ {
+ sym_link *etype = getSpec (operandType (IC_RESULT (dic)));
+ if (IN_FARSPACE (SPEC_OCLS (etype)))
+ return change;
}
- debugAopGet("removing right:",IC_RIGHT(ic));
-
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_RIGHT(ic)->key);
-
- IC_RIGHT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_RIGHT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
-
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
- change ++;
+ debugAopGet ("removing right:", IC_RIGHT (ic));
+
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
+
+ IC_RIGHT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
}
-
- return change ;
+
+ return change;
}
#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
/*-----------------------------------------------------------------*/
-/* packRegsForOneuse : - will reduce some registers for single Use */
+/* packRegsForOneuse : - will reduce some registers for single Use */
/*-----------------------------------------------------------------*/
-static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp)
+static iCode *
+packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
{
- bitVect *uses ;
- iCode *dic, *sic;
+ bitVect *uses;
+ iCode *dic, *sic;
- debugLog("%s\n",__FUNCTION__);
- /* if returning a literal then do nothing */
- if (!IS_SYMOP(op))
- return NULL;
-
- /* only upto 2 bytes since we cannot predict
- the usage of b, & acc */
- if (getSize(operandType(op)) > (fReturnSize - 2) &&
- ic->op != RETURN &&
- ic->op != SEND)
- return NULL;
+ debugLog ("%s\n", __FUNCTION__);
+ /* if returning a literal then do nothing */
+ if (!IS_SYMOP (op))
+ return NULL;
- /* this routine will mark the a symbol as used in one
- instruction use only && if the definition is local
- (ie. within the basic block) && has only one definition &&
- that definition is either a return value from a
- function or does not contain any variables in
- far space */
- uses = bitVectCopy(OP_USES(op));
- bitVectUnSetBit(uses,ic->key); /* take away this iCode */
- if (!bitVectIsZero(uses)) /* has other uses */
- return NULL ;
-
- /* if it has only one defintion */
- if (bitVectnBitsOn(OP_DEFS(op)) > 1)
- return NULL ; /* has more than one definition */
-
- /* get that definition */
- if (!(dic =
- hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(op)))))
- return NULL ;
-
- /* found the definition now check if it is local */
- if (dic->seq < ebp->fSeq ||
- dic->seq > ebp->lSeq)
- return NULL ; /* non-local */
-
- /* now check if it is the return from
- a function call */
- if (dic->op == CALL || dic->op == PCALL ) {
- if (ic->op != SEND && ic->op != RETURN) {
- OP_SYMBOL(op)->ruonly = 1;
- return dic;
+ /* only upto 2 bytes since we cannot predict
+ the usage of b, & acc */
+ if (getSize (operandType (op)) > (fReturnSize - 2) &&
+ ic->op != RETURN &&
+ ic->op != SEND)
+ return NULL;
+
+ /* this routine will mark the a symbol as used in one
+ instruction use only && if the definition is local
+ (ie. within the basic block) && has only one definition &&
+ that definition is either a return value from a
+ function or does not contain any variables in
+ far space */
+ uses = bitVectCopy (OP_USES (op));
+ bitVectUnSetBit (uses, ic->key); /* take away this iCode */
+ if (!bitVectIsZero (uses)) /* has other uses */
+ return NULL;
+
+ /* if it has only one defintion */
+ if (bitVectnBitsOn (OP_DEFS (op)) > 1)
+ return NULL; /* has more than one definition */
+
+ /* get that definition */
+ if (!(dic =
+ hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (op)))))
+ return NULL;
+
+ /* found the definition now check if it is local */
+ if (dic->seq < ebp->fSeq ||
+ dic->seq > ebp->lSeq)
+ return NULL; /* non-local */
+
+ /* now check if it is the return from
+ a function call */
+ if (dic->op == CALL || dic->op == PCALL)
+ {
+ if (ic->op != SEND && ic->op != RETURN)
+ {
+ OP_SYMBOL (op)->ruonly = 1;
+ return dic;
}
- dic = dic->next ;
+ dic = dic->next;
}
-
-
- /* otherwise check that the definition does
- not contain any symbols in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(ic)) ||
- IS_OP_RUONLY(IC_RIGHT(ic)) ) {
- return NULL;
+
+
+ /* otherwise check that the definition does
+ not contain any symbols in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (ic)) ||
+ IS_OP_RUONLY (IC_RIGHT (ic)))
+ {
+ return NULL;
}
-
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- sic = dic;
-
- /* also make sure the intervenening instructions
- don't have any thing in far space */
- for (dic = dic->next ; dic && dic != ic ; dic = dic->next) {
-
- /* if there is an intervening function call then no */
- if (dic->op == CALL || dic->op == PCALL)
- return NULL;
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_RESULT(dic)),FALSE)))
- return NULL ;
-
- if (POINTER_GET(dic) &&
- !IS_DATA_PTR(aggrToPtr(operandType(IC_LEFT(dic)),FALSE)))
- return NULL ;
-
- /* if address of & the result is remat then okay */
- if (dic->op == ADDRESS_OF &&
- OP_SYMBOL(IC_RESULT(dic))->remat)
- continue ;
-
- /* if operand has size of three or more & this
- operation is a '*','/' or '%' then 'b' may
- cause a problem */
- if (( dic->op == '%' || dic->op == '/' || dic->op == '*') &&
- getSize(operandType(op)) >= 3)
- return NULL;
- /* if left or right or result is in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- isOperandInFarSpace(IC_RESULT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(dic)) ||
- IS_OP_RUONLY(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_RESULT(dic)) ) {
- return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ sic = dic;
+
+ /* also make sure the intervenening instructions
+ don't have any thing in far space */
+ for (dic = dic->next; dic && dic != ic; dic = dic->next)
+ {
+
+ /* if there is an intervening function call then no */
+ if (dic->op == CALL || dic->op == PCALL)
+ return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+ return NULL;
+
+ if (POINTER_GET (dic) &&
+ !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+ return NULL;
+
+ /* if address of & the result is remat then okay */
+ if (dic->op == ADDRESS_OF &&
+ OP_SYMBOL (IC_RESULT (dic))->remat)
+ continue;
+
+ /* if operand has size of three or more & this
+ operation is a '*','/' or '%' then 'b' may
+ cause a problem */
+ if ((dic->op == '%' || dic->op == '/' || dic->op == '*') &&
+ getSize (operandType (op)) >= 3)
+ return NULL;
+
+ /* if left or right or result is in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ isOperandInFarSpace (IC_RESULT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (dic)) ||
+ IS_OP_RUONLY (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_RESULT (dic)))
+ {
+ return NULL;
}
}
-
- OP_SYMBOL(op)->ruonly = 1;
- return sic;
-
+
+ OP_SYMBOL (op)->ruonly = 1;
+ return sic;
+
}
/*-----------------------------------------------------------------*/
/* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
/*-----------------------------------------------------------------*/
-static bool isBitwiseOptimizable (iCode *ic)
+static bool
+isBitwiseOptimizable (iCode * ic)
{
- sym_link *ltype = getSpec(operandType(IC_LEFT(ic)));
- sym_link *rtype = getSpec(operandType(IC_RIGHT(ic)));
-
- debugLog("%s\n",__FUNCTION__);
- /* bitwise operations are considered optimizable
- under the following conditions (Jean-Louis VERN)
-
- x & lit
- bit & bit
- bit & x
- bit ^ bit
- bit ^ x
- x ^ lit
- x | lit
- bit | bit
- bit | x
- */
- if ( IS_LITERAL(rtype) ||
- (IS_BITVAR(ltype) && IN_BITSPACE(SPEC_OCLS(ltype))))
- return TRUE ;
- else
- return FALSE ;
+ sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
+ sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
+
+ debugLog ("%s\n", __FUNCTION__);
+ /* bitwise operations are considered optimizable
+ under the following conditions (Jean-Louis VERN)
+
+ x & lit
+ bit & bit
+ bit & x
+ bit ^ bit
+ bit ^ x
+ x ^ lit
+ x | lit
+ bit | bit
+ bit | x
+ */
+ if (IS_LITERAL (rtype) ||
+ (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
+ return TRUE;
+ else
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* packRegsForAccUse - pack registers for acc use */
/*-----------------------------------------------------------------*/
-static void packRegsForAccUse (iCode *ic)
+static void
+packRegsForAccUse (iCode * ic)
{
- iCode *uic;
-
- debugLog("%s\n",__FUNCTION__);
- /* if + or - then it has to be one byte result */
- if ((ic->op == '+' || ic->op == '-')
- && getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (ic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (ic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (IS_BITWISE_OP(ic) &&
- getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
-
- /* has only one definition */
- if (bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) > 1)
- return ;
-
- /* has only one use */
- if (bitVectnBitsOn(OP_USES(IC_RESULT(ic))) > 1)
- return ;
-
- /* and the usage immediately follows this iCode */
- if (!(uic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_USES(IC_RESULT(ic))))))
- return ;
-
- if (ic->next != uic)
- return ;
-
- /* if it is a conditional branch then we definitely can */
- if (uic->op == IFX )
- goto accuse;
-
- if ( uic->op == JUMPTABLE )
- return ;
-
- /* if the usage is not is an assignment
- or an arithmetic / bitwise / shift operation then not */
- if (POINTER_SET(uic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(uic)),FALSE)) > 1)
- return;
+ iCode *uic;
- if (uic->op != '=' &&
- !IS_ARITHMETIC_OP(uic) &&
- !IS_BITWISE_OP(uic) &&
- uic->op != LEFT_OP &&
- uic->op != RIGHT_OP )
- return;
+ debugLog ("%s\n", __FUNCTION__);
+ /* if + or - then it has to be one byte result */
+ if ((ic->op == '+' || ic->op == '-')
+ && getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
- /* if used in ^ operation then make sure right is not a
- literl */
- if (uic->op == '^' && isOperandLiteral(IC_RIGHT(uic)))
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (uic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- if (uic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- /* make sure that the result of this icode is not on the
- stack, since acc is used to compute stack offset */
- if (IS_TRUE_SYMOP(IC_RESULT(uic)) &&
- OP_SYMBOL(IC_RESULT(uic))->onStack)
- return ;
-
- /* if either one of them in far space then we cannot */
- if ((IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- isOperandInFarSpace(IC_LEFT(uic))) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- isOperandInFarSpace(IC_RIGHT(uic))))
- return ;
-
- /* if the usage has only one operand then we can */
- if (IC_LEFT(uic) == NULL ||
- IC_RIGHT(uic) == NULL)
- goto accuse;
-
- /* make sure this is on the left side if not
- a '+' since '+' is commutative */
- if (ic->op != '+' &&
- IC_LEFT(uic)->key != IC_RESULT(ic)->key)
- return;
+ /* if shift operation make sure right side is not a literal */
+ if (ic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ if (ic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
- /* if one of them is a literal then we can */
- if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) ||
- (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) {
- OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
- return ;
+ if (IS_BITWISE_OP (ic) &&
+ getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
+
+
+ /* has only one definition */
+ if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
+ return;
+
+ /* has only one use */
+ if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
+ return;
+
+ /* and the usage immediately follows this iCode */
+ if (!(uic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
+ return;
+
+ if (ic->next != uic)
+ return;
+
+ /* if it is a conditional branch then we definitely can */
+ if (uic->op == IFX)
+ goto accuse;
+
+ if (uic->op == JUMPTABLE)
+ return;
+
+ /* if the usage is not is an assignment
+ or an arithmetic / bitwise / shift operation then not */
+ if (POINTER_SET (uic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
+ return;
+
+ if (uic->op != '=' &&
+ !IS_ARITHMETIC_OP (uic) &&
+ !IS_BITWISE_OP (uic) &&
+ uic->op != LEFT_OP &&
+ uic->op != RIGHT_OP)
+ return;
+
+ /* if used in ^ operation then make sure right is not a
+ literl */
+ if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (uic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ if (uic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ /* make sure that the result of this icode is not on the
+ stack, since acc is used to compute stack offset */
+ if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
+ OP_SYMBOL (IC_RESULT (uic))->onStack)
+ return;
+
+ /* if either one of them in far space then we cannot */
+ if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ isOperandInFarSpace (IC_LEFT (uic))) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ isOperandInFarSpace (IC_RIGHT (uic))))
+ return;
+
+ /* if the usage has only one operand then we can */
+ if (IC_LEFT (uic) == NULL ||
+ IC_RIGHT (uic) == NULL)
+ goto accuse;
+
+ /* make sure this is on the left side if not
+ a '+' since '+' is commutative */
+ if (ic->op != '+' &&
+ IC_LEFT (uic)->key != IC_RESULT (ic)->key)
+ return;
+
+ /* if one of them is a literal then we can */
+ if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
+ (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
+ {
+ OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
+ return;
}
- /* if the other one is not on stack then we can */
- if (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_RIGHT(uic)) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- !OP_SYMBOL(IC_RIGHT(uic))->onStack)))
- goto accuse;
-
- if (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_LEFT(uic)) ||
- (IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- !OP_SYMBOL(IC_LEFT(uic))->onStack)))
- goto accuse ;
-
- return ;
-
- accuse:
- OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
-
-
+ /* if the other one is not on stack then we can */
+ if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_RIGHT (uic)) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ !OP_SYMBOL (IC_RIGHT (uic))->onStack)))
+ goto accuse;
+
+ if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_LEFT (uic)) ||
+ (IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ !OP_SYMBOL (IC_LEFT (uic))->onStack)))
+ goto accuse;
+
+ return;
+
+accuse:
+ OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
+
+
}
/*-----------------------------------------------------------------*/
/* packForPush - hueristics to reduce iCode for pushing */
/*-----------------------------------------------------------------*/
-static void packForReceive(iCode *ic, eBBlock *ebp)
+static void
+packForReceive (iCode * ic, eBBlock * ebp)
{
iCode *dic;
- bool can_remove=1; // assume that we can remove temporary
+ bool can_remove = 1; // assume that we can remove temporary
- debugLog("%s\n",__FUNCTION__);
- debugAopGet(" result:",IC_RESULT(ic));
- debugAopGet(" left:",IC_LEFT(ic));
- debugAopGet(" right:",IC_RIGHT(ic));
+ debugLog ("%s\n", __FUNCTION__);
+ debugAopGet (" result:", IC_RESULT (ic));
+ debugAopGet (" left:", IC_LEFT (ic));
+ debugAopGet (" right:", IC_RIGHT (ic));
- if(!ic->next)
+ if (!ic->next)
return;
- for ( dic = ic->next ; dic ; dic = dic->next ) {
+ for (dic = ic->next; dic; dic = dic->next)
+ {
- if(IC_LEFT(dic) && (IC_RESULT(ic)->key == IC_LEFT(dic)->key) )
- debugLog(" used on left\n");
- if(IC_RIGHT(dic) && IC_RESULT(ic)->key == IC_RIGHT(dic)->key)
- debugLog(" used on right\n");
- if(IC_RESULT(dic) && IC_RESULT(ic)->key == IC_RESULT(dic)->key)
- debugLog(" used on result\n");
+ if (IC_LEFT (dic) && (IC_RESULT (ic)->key == IC_LEFT (dic)->key))
+ debugLog (" used on left\n");
+ if (IC_RIGHT (dic) && IC_RESULT (ic)->key == IC_RIGHT (dic)->key)
+ debugLog (" used on right\n");
+ if (IC_RESULT (dic) && IC_RESULT (ic)->key == IC_RESULT (dic)->key)
+ debugLog (" used on result\n");
- if( (IC_LEFT(dic) && (IC_RESULT(ic)->key == IC_LEFT(dic)->key) ) ||
- (IC_RESULT(dic) && IC_RESULT(ic)->key == IC_RESULT(dic)->key) )
- return;
+ if ((IC_LEFT (dic) && (IC_RESULT (ic)->key == IC_LEFT (dic)->key)) ||
+ (IC_RESULT (dic) && IC_RESULT (ic)->key == IC_RESULT (dic)->key))
+ return;
- }
+ }
- debugLog(" hey we can remove this unnecessary assign\n");
+ debugLog (" hey we can remove this unnecessary assign\n");
}
/*-----------------------------------------------------------------*/
/* packForPush - hueristics to reduce iCode for pushing */
/*-----------------------------------------------------------------*/
-static void packForPush(iCode *ic, eBBlock *ebp)
+static void
+packForPush (iCode * ic, eBBlock * ebp)
{
- iCode *dic;
-
- debugLog("%s\n",__FUNCTION__);
- if (ic->op != IPUSH || !IS_ITEMP(IC_LEFT(ic)))
- return ;
-
- /* must have only definition & one usage */
- if (bitVectnBitsOn(OP_DEFS(IC_LEFT(ic))) != 1 ||
- bitVectnBitsOn(OP_USES(IC_LEFT(ic))) != 1 )
- return ;
-
- /* find the definition */
- if (!(dic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(IC_LEFT(ic))))))
- return ;
-
- if (dic->op != '=' || POINTER_SET(dic))
- return;
+ iCode *dic;
+
+ debugLog ("%s\n", __FUNCTION__);
+ if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
+ return;
+
+ /* must have only definition & one usage */
+ if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
+ bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
+ return;
- /* we now we know that it has one & only one def & use
- and the that the definition is an assignment */
- IC_LEFT(ic) = IC_RIGHT(dic);
+ /* find the definition */
+ if (!(dic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (IC_LEFT (ic))))))
+ return;
+
+ if (dic->op != '=' || POINTER_SET (dic))
+ return;
+
+ /* we now we know that it has one & only one def & use
+ and the that the definition is an assignment */
+ IC_LEFT (ic) = IC_RIGHT (dic);
- remiCodeFromeBBlock(ebp,dic);
- hTabDeleteItem (&iCodehTab,dic->key,dic,DELETE_ITEM,NULL);
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
}
/*-----------------------------------------------------------------*/
/* packRegisters - does some transformations to reduce register */
/* pressure */
/*-----------------------------------------------------------------*/
-static void packRegisters (eBBlock *ebp)
+static void
+packRegisters (eBBlock * ebp)
{
- iCode *ic ;
- int change = 0 ;
-
- debugLog("%s\n",__FUNCTION__);
-
- while (1) {
-
- change = 0;
-
- /* look for assignments of the form */
- /* iTempNN = TRueSym (someoperation) SomeOperand */
- /* .... */
- /* TrueSym := iTempNN:1 */
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
- /* find assignment of the form TrueSym := iTempNN:1 */
- if (ic->op == '=' && !POINTER_SET(ic))
- change += packRegsForAssign(ic,ebp);
- /* debug stuff */
- if (ic->op == '=') {
- if(POINTER_SET(ic))
- debugLog("pointer is set\n");
- debugAopGet(" result:",IC_RESULT(ic));
- debugAopGet(" left:",IC_LEFT(ic));
- debugAopGet(" right:",IC_RIGHT(ic));
+ iCode *ic;
+ int change = 0;
+
+ debugLog ("%s\n", __FUNCTION__);
+
+ while (1)
+ {
+
+ change = 0;
+
+ /* look for assignments of the form */
+ /* iTempNN = TRueSym (someoperation) SomeOperand */
+ /* .... */
+ /* TrueSym := iTempNN:1 */
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+ /* find assignment of the form TrueSym := iTempNN:1 */
+ if (ic->op == '=' && !POINTER_SET (ic))
+ change += packRegsForAssign (ic, ebp);
+ /* debug stuff */
+ if (ic->op == '=')
+ {
+ if (POINTER_SET (ic))
+ debugLog ("pointer is set\n");
+ debugAopGet (" result:", IC_RESULT (ic));
+ debugAopGet (" left:", IC_LEFT (ic));
+ debugAopGet (" right:", IC_RIGHT (ic));
}
}
- if (!change)
- break;
+ if (!change)
+ break;
}
-
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
-
- /* if this is an itemp & result of a address of a true sym
- then mark this as rematerialisable */
- if (ic->op == ADDRESS_OF &&
- IS_ITEMP(IC_RESULT(ic)) &&
- IS_TRUE_SYMOP(IC_LEFT(ic)) &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- !OP_SYMBOL(IC_LEFT(ic))->onStack ) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an itemp & result of a address of a true sym
+ then mark this as rematerialisable */
+ if (ic->op == ADDRESS_OF &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ IS_TRUE_SYMOP (IC_LEFT (ic)) &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ !OP_SYMBOL (IC_LEFT (ic))->onStack)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
-
- /* if straight assignment then carry remat flag if
- this is the only definition */
- if (ic->op == '=' &&
- !POINTER_SET(ic) &&
- IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->remat &&
- bitVectnBitsOn(OP_SYMBOL(IC_RESULT(ic))->defs) <= 1) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat =
- OP_SYMBOL(IC_RIGHT(ic))->remat;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode =
- OP_SYMBOL(IC_RIGHT(ic))->rematiCode ;
+
+ /* if straight assignment then carry remat flag if
+ this is the only definition */
+ if (ic->op == '=' &&
+ !POINTER_SET (ic) &&
+ IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->remat &&
+ bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat =
+ OP_SYMBOL (IC_RIGHT (ic))->remat;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode =
+ OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
}
- /* if this is a +/- operation with a rematerizable
- then mark this as rematerializable as well */
- if ((ic->op == '+' || ic->op == '-') &&
- (IS_SYMOP(IC_LEFT(ic)) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->remat &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- IS_OP_LITERAL(IC_RIGHT(ic))) ) {
+ /* if this is a +/- operation with a rematerizable
+ then mark this as rematerializable as well */
+ if ((ic->op == '+' || ic->op == '-') &&
+ (IS_SYMOP (IC_LEFT (ic)) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->remat &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ IS_OP_LITERAL (IC_RIGHT (ic))))
+ {
//int i =
- operandLitValue(IC_RIGHT(ic));
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+ operandLitValue (IC_RIGHT (ic));
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
- /* mark the pointer usages */
- if (POINTER_SET(ic)) {
- OP_SYMBOL(IC_RESULT(ic))->uptr = 1;
- debugLog(" marking as a pointer (set)\n");
+ /* mark the pointer usages */
+ if (POINTER_SET (ic))
+ {
+ OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
+ debugLog (" marking as a pointer (set)\n");
}
- if (POINTER_GET(ic)) {
- OP_SYMBOL(IC_LEFT(ic))->uptr = 1;
- debugLog(" marking as a pointer (get)\n");
+ if (POINTER_GET (ic))
+ {
+ OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
+ debugLog (" marking as a pointer (get)\n");
}
- if (!SKIP_IC2(ic)) {
- /* if we are using a symbol on the stack
- then we should say pic14_ptrRegReq */
- if (ic->op == IFX && IS_SYMOP(IC_COND(ic)))
- pic14_ptrRegReq += ((OP_SYMBOL(IC_COND(ic))->onStack ||
- OP_SYMBOL(IC_COND(ic))->iaccess) ? 1 : 0);
- else
- if (ic->op == JUMPTABLE && IS_SYMOP(IC_JTCOND(ic)))
- pic14_ptrRegReq += ((OP_SYMBOL(IC_JTCOND(ic))->onStack ||
- OP_SYMBOL(IC_JTCOND(ic))->iaccess) ? 1 : 0);
- else {
- if (IS_SYMOP(IC_LEFT(ic)))
- pic14_ptrRegReq += ((OP_SYMBOL(IC_LEFT(ic))->onStack ||
- OP_SYMBOL(IC_LEFT(ic))->iaccess) ? 1 : 0);
- if (IS_SYMOP(IC_RIGHT(ic)))
- pic14_ptrRegReq += ((OP_SYMBOL(IC_RIGHT(ic))->onStack ||
- OP_SYMBOL(IC_RIGHT(ic))->iaccess) ? 1 : 0);
- if (IS_SYMOP(IC_RESULT(ic)))
- pic14_ptrRegReq += ((OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess) ? 1 : 0);
- }
+ if (!SKIP_IC2 (ic))
+ {
+ /* if we are using a symbol on the stack
+ then we should say pic14_ptrRegReq */
+ if (ic->op == IFX && IS_SYMOP (IC_COND (ic)))
+ pic14_ptrRegReq += ((OP_SYMBOL (IC_COND (ic))->onStack ||
+ OP_SYMBOL (IC_COND (ic))->iaccess) ? 1 : 0);
+ else if (ic->op == JUMPTABLE && IS_SYMOP (IC_JTCOND (ic)))
+ pic14_ptrRegReq += ((OP_SYMBOL (IC_JTCOND (ic))->onStack ||
+ OP_SYMBOL (IC_JTCOND (ic))->iaccess) ? 1 : 0);
+ else
+ {
+ if (IS_SYMOP (IC_LEFT (ic)))
+ pic14_ptrRegReq += ((OP_SYMBOL (IC_LEFT (ic))->onStack ||
+ OP_SYMBOL (IC_LEFT (ic))->iaccess) ? 1 : 0);
+ if (IS_SYMOP (IC_RIGHT (ic)))
+ pic14_ptrRegReq += ((OP_SYMBOL (IC_RIGHT (ic))->onStack ||
+ OP_SYMBOL (IC_RIGHT (ic))->iaccess) ? 1 : 0);
+ if (IS_SYMOP (IC_RESULT (ic)))
+ pic14_ptrRegReq += ((OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess) ? 1 : 0);
+ }
}
- /* if the condition of an if instruction
- is defined in the previous instruction then
- mark the itemp as a conditional */
- if ((IS_CONDITIONAL(ic) ||
- ( ( ic->op == BITWISEAND ||
- ic->op == '|' ||
- ic->op == '^' ) &&
- isBitwiseOptimizable(ic))) &&
- ic->next && ic->next->op == IFX &&
- isOperandEqual(IC_RESULT(ic),IC_COND(ic->next)) &&
- OP_SYMBOL(IC_RESULT(ic))->liveTo <= ic->next->seq) {
-
- OP_SYMBOL(IC_RESULT(ic))->regType = REG_CND;
- continue ;
+ /* if the condition of an if instruction
+ is defined in the previous instruction then
+ mark the itemp as a conditional */
+ if ((IS_CONDITIONAL (ic) ||
+ ((ic->op == BITWISEAND ||
+ ic->op == '|' ||
+ ic->op == '^') &&
+ isBitwiseOptimizable (ic))) &&
+ ic->next && ic->next->op == IFX &&
+ isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
+ OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
+ continue;
}
-
- /* reduce for support function calls */
- if (ic->supportRtn || ic->op == '+' || ic->op == '-' )
- packRegsForSupport (ic,ebp);
-
- /* if a parameter is passed, it's in W, so we may not
- need to place a copy in a register */
- if(ic->op == RECEIVE)
- packForReceive(ic,ebp);
-
- /* some cases the redundant moves can
- can be eliminated for return statements */
- if ((ic->op == RETURN || ic->op == SEND) &&
- !isOperandInFarSpace(IC_LEFT(ic)) &&
- !options.model)
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
-
- /* if pointer set & left has a size more than
- one and right is not in far space */
- if (POINTER_SET(ic) &&
- !isOperandInFarSpace(IC_RIGHT(ic)) &&
- !OP_SYMBOL(IC_RESULT(ic))->remat &&
- !IS_OP_RUONLY(IC_RIGHT(ic)) &&
- getSize(aggrToPtr(operandType(IC_RESULT(ic)),FALSE)) > 1 )
-
- packRegsForOneuse (ic,IC_RESULT(ic),ebp);
-
- /* if pointer get */
- if (POINTER_GET(ic) &&
- !isOperandInFarSpace(IC_RESULT(ic))&&
- !OP_SYMBOL(IC_LEFT(ic))->remat &&
- !IS_OP_RUONLY(IC_RESULT(ic)) &&
- getSize(aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) > 1 )
-
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
-
-
- /* if this is cast for intergral promotion then
- check if only use of the definition of the
- operand being casted/ if yes then replace
- the result of that arithmetic operation with
- this result and get rid of the cast */
- if (ic->op == CAST) {
- sym_link *fromType = operandType(IC_RIGHT(ic));
- sym_link *toType = operandType(IC_LEFT(ic));
-
- if (IS_INTEGRAL(fromType) && IS_INTEGRAL(toType) &&
- getSize(fromType) != getSize(toType) ) {
-
- iCode *dic = packRegsForOneuse(ic,IC_RIGHT(ic),ebp);
- if (dic) {
- if (IS_ARITHMETIC_OP(dic)) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- ic = ic->prev;
- } else
- OP_SYMBOL(IC_RIGHT(ic))->ruonly = 0;
- }
- } else {
-
- /* if the type from and type to are the same
- then if this is the only use then packit */
- if (checkType(operandType(IC_RIGHT(ic)),
- operandType(IC_LEFT(ic))) == 1) {
- iCode *dic = packRegsForOneuse (ic,IC_RIGHT(ic),ebp);
- if (dic) {
- IC_RESULT(dic) = IC_RESULT(ic);
- remiCodeFromeBBlock(ebp,ic);
- hTabDeleteItem (&iCodehTab,ic->key,ic,DELETE_ITEM,NULL);
- OP_DEFS(IC_RESULT(dic)) = bitVectSetBit(OP_DEFS(IC_RESULT(dic)),dic->key);
- ic = ic->prev;
+
+ /* reduce for support function calls */
+ if (ic->supportRtn || ic->op == '+' || ic->op == '-')
+ packRegsForSupport (ic, ebp);
+
+ /* if a parameter is passed, it's in W, so we may not
+ need to place a copy in a register */
+ if (ic->op == RECEIVE)
+ packForReceive (ic, ebp);
+
+ /* some cases the redundant moves can
+ can be eliminated for return statements */
+ if ((ic->op == RETURN || ic->op == SEND) &&
+ !isOperandInFarSpace (IC_LEFT (ic)) &&
+ !options.model)
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+
+ /* if pointer set & left has a size more than
+ one and right is not in far space */
+ if (POINTER_SET (ic) &&
+ !isOperandInFarSpace (IC_RIGHT (ic)) &&
+ !OP_SYMBOL (IC_RESULT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RIGHT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
+
+ packRegsForOneuse (ic, IC_RESULT (ic), ebp);
+
+ /* if pointer get */
+ if (POINTER_GET (ic) &&
+ !isOperandInFarSpace (IC_RESULT (ic)) &&
+ !OP_SYMBOL (IC_LEFT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RESULT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
+
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+
+
+ /* if this is cast for intergral promotion then
+ check if only use of the definition of the
+ operand being casted/ if yes then replace
+ the result of that arithmetic operation with
+ this result and get rid of the cast */
+ if (ic->op == CAST)
+ {
+ sym_link *fromType = operandType (IC_RIGHT (ic));
+ sym_link *toType = operandType (IC_LEFT (ic));
+
+ if (IS_INTEGRAL (fromType) && IS_INTEGRAL (toType) &&
+ getSize (fromType) != getSize (toType))
+ {
+
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ if (IS_ARITHMETIC_OP (dic))
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ ic = ic->prev;
+ }
+ else
+ OP_SYMBOL (IC_RIGHT (ic))->ruonly = 0;
+ }
+ }
+ else
+ {
+
+ /* if the type from and type to are the same
+ then if this is the only use then packit */
+ if (checkType (operandType (IC_RIGHT (ic)),
+ operandType (IC_LEFT (ic))) == 1)
+ {
+ iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
+ if (dic)
+ {
+ IC_RESULT (dic) = IC_RESULT (ic);
+ remiCodeFromeBBlock (ebp, ic);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+ OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ ic = ic->prev;
}
}
}
}
-
- /* pack for PUSH
- iTempNN := (some variable in farspace) V1
- push iTempNN ;
- -------------
- push V1
- */
- if (ic->op == IPUSH ) {
- packForPush(ic,ebp);
+
+ /* pack for PUSH
+ iTempNN := (some variable in farspace) V1
+ push iTempNN ;
+ -------------
+ push V1
+ */
+ if (ic->op == IPUSH)
+ {
+ packForPush (ic, ebp);
}
-
-
- /* pack registers for accumulator use, when the
- result of an arithmetic or bit wise operation
- has only one use, that use is immediately following
- the defintion and the using iCode has only one
- operand or has two operands but one is literal &
- the result of that operation is not on stack then
- we can leave the result of this operation in acc:b
- combination */
- if ((IS_ARITHMETIC_OP(ic)
-
- || IS_BITWISE_OP(ic)
-
- || ic->op == LEFT_OP || ic->op == RIGHT_OP
-
- ) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- getSize(operandType(IC_RESULT(ic))) <= 2)
-
- packRegsForAccUse (ic);
+
+
+ /* pack registers for accumulator use, when the
+ result of an arithmetic or bit wise operation
+ has only one use, that use is immediately following
+ the defintion and the using iCode has only one
+ operand or has two operands but one is literal &
+ the result of that operation is not on stack then
+ we can leave the result of this operation in acc:b
+ combination */
+ if ((IS_ARITHMETIC_OP (ic)
+
+ || IS_BITWISE_OP (ic)
+
+ || ic->op == LEFT_OP || ic->op == RIGHT_OP
+
+ ) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ getSize (operandType (IC_RESULT (ic))) <= 2)
+
+ packRegsForAccUse (ic);
}
}
-static void dumpEbbsToDebug(eBBlock **ebbs, int count)
+static void
+dumpEbbsToDebug (eBBlock ** ebbs, int count)
{
int i;
- if(!debug || !debugF)
+ if (!debug || !debugF)
return;
- for (i=0; i < count ; i++ ) {
- fprintf(debugF,"\n----------------------------------------------------------------\n");
- fprintf(debugF,"Basic Block %s : loop Depth = %d noPath = %d , lastinLoop = %d\n",
- ebbs[i]->entryLabel->name,
- ebbs[i]->depth,
- ebbs[i]->noPath,
- ebbs[i]->isLastInLoop);
- fprintf(debugF,"depth 1st num %d : bbnum = %d 1st iCode = %d , last iCode = %d\n",
- ebbs[i]->dfnum,
- ebbs[i]->bbnum,
- ebbs[i]->fSeq,
- ebbs[i]->lSeq);
- fprintf(debugF,"visited %d : hasFcall = %d\n",
- ebbs[i]->visited,
- ebbs[i]->hasFcall);
-
- fprintf(debugF,"\ndefines bitVector :");
- bitVectDebugOn(ebbs[i]->defSet,debugF);
- fprintf(debugF,"\nlocal defines bitVector :");
- bitVectDebugOn(ebbs[i]->ldefs,debugF);
- fprintf(debugF,"\npointers Set bitvector :");
- bitVectDebugOn(ebbs[i]->ptrsSet,debugF);
- fprintf(debugF,"\nin pointers Set bitvector :");
- bitVectDebugOn(ebbs[i]->inPtrsSet,debugF);
- fprintf(debugF,"\ninDefs Set bitvector :");
- bitVectDebugOn(ebbs[i]->inDefs,debugF);
- fprintf(debugF,"\noutDefs Set bitvector :");
- bitVectDebugOn(ebbs[i]->outDefs,debugF);
- fprintf(debugF,"\nusesDefs Set bitvector :");
- bitVectDebugOn(ebbs[i]->usesDefs,debugF);
- fprintf(debugF,"\n----------------------------------------------------------------\n");
- printiCChain(ebbs[i]->sch,debugF);
- }
+ for (i = 0; i < count; i++)
+ {
+ fprintf (debugF, "\n----------------------------------------------------------------\n");
+ fprintf (debugF, "Basic Block %s : loop Depth = %d noPath = %d , lastinLoop = %d\n",
+ ebbs[i]->entryLabel->name,
+ ebbs[i]->depth,
+ ebbs[i]->noPath,
+ ebbs[i]->isLastInLoop);
+ fprintf (debugF, "depth 1st num %d : bbnum = %d 1st iCode = %d , last iCode = %d\n",
+ ebbs[i]->dfnum,
+ ebbs[i]->bbnum,
+ ebbs[i]->fSeq,
+ ebbs[i]->lSeq);
+ fprintf (debugF, "visited %d : hasFcall = %d\n",
+ ebbs[i]->visited,
+ ebbs[i]->hasFcall);
+
+ fprintf (debugF, "\ndefines bitVector :");
+ bitVectDebugOn (ebbs[i]->defSet, debugF);
+ fprintf (debugF, "\nlocal defines bitVector :");
+ bitVectDebugOn (ebbs[i]->ldefs, debugF);
+ fprintf (debugF, "\npointers Set bitvector :");
+ bitVectDebugOn (ebbs[i]->ptrsSet, debugF);
+ fprintf (debugF, "\nin pointers Set bitvector :");
+ bitVectDebugOn (ebbs[i]->inPtrsSet, debugF);
+ fprintf (debugF, "\ninDefs Set bitvector :");
+ bitVectDebugOn (ebbs[i]->inDefs, debugF);
+ fprintf (debugF, "\noutDefs Set bitvector :");
+ bitVectDebugOn (ebbs[i]->outDefs, debugF);
+ fprintf (debugF, "\nusesDefs Set bitvector :");
+ bitVectDebugOn (ebbs[i]->usesDefs, debugF);
+ fprintf (debugF, "\n----------------------------------------------------------------\n");
+ printiCChain (ebbs[i]->sch, debugF);
+ }
}
/*-----------------------------------------------------------------*/
/* assignRegisters - assigns registers to each live range as need */
/*-----------------------------------------------------------------*/
-void pic14_assignRegisters (eBBlock **ebbs, int count)
+void
+pic14_assignRegisters (eBBlock ** ebbs, int count)
{
- iCode *ic;
- int i ;
-
- debugLog("<><><><><><><><><><><><><><><><><>\nstarting\t%s:%s",__FILE__,__FUNCTION__);
- debugLog("ebbs before optimizing:\n");
- dumpEbbsToDebug(ebbs,count);
-
- setToNull((void *)&_G.funcrUsed);
- pic14_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
-
-
- /* change assignments this will remove some
- live ranges reducing some register pressure */
- for (i = 0 ; i < count ;i++ )
- packRegisters (ebbs[i]);
-
- if (options.dump_pack)
- dumpEbbsToFileExt(".dumppack",ebbs,count);
-
- /* first determine for each live range the number of
- registers & the type of registers required for each */
- regTypeNum ();
-
- /* and serially allocate registers */
- serialRegAssign(ebbs,count);
-
- /* if stack was extended then tell the user */
- if (_G.stackExtend) {
-/* werror(W_TOOMANY_SPILS,"stack", */
-/* _G.stackExtend,currFunc->name,""); */
- _G.stackExtend = 0 ;
+ iCode *ic;
+ int i;
+
+ debugLog ("<><><><><><><><><><><><><><><><><>\nstarting\t%s:%s", __FILE__, __FUNCTION__);
+ debugLog ("ebbs before optimizing:\n");
+ dumpEbbsToDebug (ebbs, count);
+
+ setToNull ((void *) &_G.funcrUsed);
+ pic14_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
+
+
+ /* change assignments this will remove some
+ live ranges reducing some register pressure */
+ for (i = 0; i < count; i++)
+ packRegisters (ebbs[i]);
+
+ if (options.dump_pack)
+ dumpEbbsToFileExt (".dumppack", ebbs, count);
+
+ /* first determine for each live range the number of
+ registers & the type of registers required for each */
+ regTypeNum ();
+
+ /* and serially allocate registers */
+ serialRegAssign (ebbs, count);
+
+ /* if stack was extended then tell the user */
+ if (_G.stackExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"stack", */
+/* _G.stackExtend,currFunc->name,""); */
+ _G.stackExtend = 0;
}
- if (_G.dataExtend) {
-/* werror(W_TOOMANY_SPILS,"data space", */
-/* _G.dataExtend,currFunc->name,""); */
- _G.dataExtend = 0 ;
- }
+ if (_G.dataExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"data space", */
+/* _G.dataExtend,currFunc->name,""); */
+ _G.dataExtend = 0;
+ }
- /* after that create the register mask
- for each of the instruction */
- createRegMask (ebbs,count);
+ /* after that create the register mask
+ for each of the instruction */
+ createRegMask (ebbs, count);
- /* redo that offsets for stacked automatic variables */
- redoStackOffsets ();
+ /* redo that offsets for stacked automatic variables */
+ redoStackOffsets ();
- if (options.dump_rassgn)
- dumpEbbsToFileExt(".dumprassgn",ebbs,count);
+ if (options.dump_rassgn)
+ dumpEbbsToFileExt (".dumprassgn", ebbs, count);
- /* now get back the chain */
- ic = iCodeLabelOptimize(iCodeFromeBBlock (ebbs,count));
+ /* now get back the chain */
+ ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
- debugLog("ebbs after optimizing:\n");
- dumpEbbsToDebug(ebbs,count);
+ debugLog ("ebbs after optimizing:\n");
+ dumpEbbsToDebug (ebbs, count);
- genpic14Code(ic);
+ genpic14Code (ic);
- /* free up any _G.stackSpil locations allocated */
- applyToSet(_G.stackSpil,deallocStackSpil);
- _G.slocNum = 0;
- setToNull((void **)&_G.stackSpil);
- setToNull((void **)&_G.spiltSet);
- /* mark all registers as free */
- freeAllRegs();
+ /* free up any _G.stackSpil locations allocated */
+ applyToSet (_G.stackSpil, deallocStackSpil);
+ _G.slocNum = 0;
+ setToNull ((void **) &_G.stackSpil);
+ setToNull ((void **) &_G.spiltSet);
+ /* mark all registers as free */
+ freeAllRegs ();
- debugLog("leaving\n<><><><><><><><><><><><><><><><><>\n");
- debugLogClose();
- return ;
+ debugLog ("leaving\n<><><><><><><><><><><><><><><><><>\n");
+ debugLogClose ();
+ return;
}
#ifndef SDCCRALLOC_H
#define SDCCRALLOC_H 1
-enum { R2_IDX = 0, R3_IDX , R4_IDX ,
- R5_IDX ,R6_IDX , R7_IDX ,
- R0_IDX ,R1_IDX , X8_IDX ,
- X9_IDX ,X10_IDX , X11_IDX ,
- X12_IDX ,CND_IDX };
+enum
+ {
+ R2_IDX = 0, R3_IDX, R4_IDX,
+ R5_IDX, R6_IDX, R7_IDX,
+ R0_IDX, R1_IDX, X8_IDX,
+ X9_IDX, X10_IDX, X11_IDX,
+ X12_IDX, CND_IDX
+ };
#define REG_PTR 0x01
#define REG_CND 0x04
/* definition for the registers */
typedef struct regs
-{
- short type; /* can have value
- REG_GPR, REG_PTR or REG_CND */
- short rIdx ; /* index into register table */
- // short otype;
- char *name ; /* name */
- char *dname; /* name when direct access needed */
- // char *base ; /* base address */
- short offset; /* offset from the base */
- unsigned isFree :1; /* is currently unassigned */
- unsigned wasUsed :1; /* becomes true if register has been used */
-} regs;
+ {
+ short type; /* can have value
+ REG_GPR, REG_PTR or REG_CND */
+ short rIdx; /* index into register table */
+ // short otype;
+ char *name; /* name */
+ char *dname; /* name when direct access needed */
+ // char *base ; /* base address */
+ short offset; /* offset from the base */
+ unsigned isFree:1; /* is currently unassigned */
+ unsigned wasUsed:1; /* becomes true if register has been used */
+ }
+regs;
extern regs regspic14[];
extern int pic14_nRegs;
-regs *pic14_regWithIdx (int);
+regs *pic14_regWithIdx (int);
-enum PIC_register_types {
- PIC_INDF,
- PIC_TMR0,
- PIC_FSR,
- PIC_STATUS,
- PIC_IOPORT,
- PIC_IOTRIS,
- PIC_GPR, /* A general purpose file register */
- PIC_SFR /* A special function register */
-};
+enum PIC_register_types
+ {
+ PIC_INDF,
+ PIC_TMR0,
+ PIC_FSR,
+ PIC_STATUS,
+ PIC_IOPORT,
+ PIC_IOTRIS,
+ PIC_GPR, /* A general purpose file register */
+ PIC_SFR /* A special function register */
+ };
#endif
* (like bitx = bity + bitz;) */
#define SUPPORT_BIT_ARITHMETIC 1
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
#if SUPPORT_BIT_TYPES
unsigned char achar3 = 0;
unsigned char *acharP = 0;
-void done()
+void
+done ()
{
dummy++;
}
-void add_lit2uchar(void)
+void
+add_lit2uchar (void)
{
achar0 = achar0 + 5;
- if(achar0 != 5)
+ if (achar0 != 5)
failures++;
achar0 += 10;
- if(achar0 != 15)
+ if (achar0 != 15)
failures++;
- achar0 = achar0 +1; // Should be an increment
- if(achar0 != 16)
+ achar0 = achar0 + 1; // Should be an increment
+
+ if (achar0 != 16)
failures++;
- for(achar1 = 0; achar1 < 100; achar1++)
+ for (achar1 = 0; achar1 < 100; achar1++)
achar0 += 2;
- if(achar0 != 216)
+ if (achar0 != 216)
failures++;
}
-void add_uchar2uchar(void)
+void
+add_uchar2uchar (void)
{
achar1 = achar1 + achar0;
- if(achar1 != 16)
+ if (achar1 != 16)
failures++;
- for(achar2 = 0; achar2<7; achar2++)
+ for (achar2 = 0; achar2 < 7; achar2++)
achar1 += achar0;
- if(achar1 != 128)
+ if (achar1 != 128)
failures++;
}
// achar1 = 32
// achar2, achar3 can be anything.
-void add_uchar2uchar2(void)
+void
+add_uchar2uchar2 (void)
{
achar0 = achar0 + 1;
achar0 = achar0 + 2;
achar0 = achar0 + 3;
- if(achar0 != 7)
+ if (achar0 != 7)
failures++;
achar1 += achar0;
- if(achar1 != 39)
+ if (achar1 != 39)
failures++;
achar2 = achar1 + achar0;
- if(achar2 != 46)
+ if (achar2 != 46)
failures++;
achar3 = achar2 + achar1 + achar0;
- if(achar3 != 92)
+ if (achar3 != 92)
failures++;
}
#if SUPPORT_BIT_TYPES
-void add_bits(void)
+void
+add_bits (void)
{
bit1 = bit0;
bit0 = 1;
- if(bit1 != 0)
+ if (bit1 != 0)
failures++;
- bit1 = bit1+bit0;
- if(bit1 != 1)
+ bit1 = bit1 + bit0;
+ if (bit1 != 1)
failures++;
#if SUPPORT_BIT_ARITHMETIC
- bit2 = bit1+bit3;
- if(bit2)
+ bit2 = bit1 + bit3;
+ if (bit2)
failures++;
- bit3 = bit4+bit5+bit6+bit7+bit0;
- if(!bit3)
+ bit3 = bit4 + bit5 + bit6 + bit7 + bit0;
+ if (!bit3)
failures++;
#endif
}
/* add_bit2uchar(void) - assumes bit0 = 1, achar0 = 7 */
-void add_bit2uchar(void)
+void
+add_bit2uchar (void)
{
achar0 += bit0;
- if(achar0 != 8)
+ if (achar0 != 8)
failures++;
- if(achar0 == bit0)
+ if (achar0 == bit0)
failures++;
}
-void add_bit2uint(void)
+void
+add_bit2uint (void)
{
- if(aint0 != bit11)
+ if (aint0 != bit11)
failures++;
aint0 += bit0;
- if(aint0!=1)
+ if (aint0 != 1)
failures++;
}
-void main(void)
+void
+main (void)
{
- add_lit2uchar();
+ add_lit2uchar ();
- achar0=16;
- achar1=0;
- add_uchar2uchar();
+ achar0 = 16;
+ achar1 = 0;
+ add_uchar2uchar ();
achar0 = 0;
achar1 = 32;
- add_uchar2uchar2();
+ add_uchar2uchar2 ();
#if SUPPORT_BIT_TYPES
- add_bits();
+ add_bits ();
- add_bit2uchar();
- add_bit2uint();
+ add_bit2uchar ();
+ add_bit2uint ();
#endif
success = failures;
- done();
+ done ();
}
//#include "p16c84.h"
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
bit bit0 = 0;
unsigned int aint0 = 0;
unsigned char achar0 = 0;
unsigned char achar1 = 0;
-void done()
+void
+done ()
{
dummy++;
}
-void bool_or1(void)
+void
+bool_or1 (void)
{
- if( (achar0 >0) || (achar1 >0 ))
+ if ((achar0 > 0) || (achar1 > 0))
failures++;
}
-void bool_or2(void)
+void
+bool_or2 (void)
{
- if( achar0 || achar1)
+ if (achar0 || achar1)
failures++;
}
-void bool_test1(void)
+void
+bool_test1 (void)
{
- if( (achar0==0) || achar1)
+ if ((achar0 == 0) || achar1)
failures++;
}
-void bool_test2(void)
+void
+bool_test2 (void)
{
- if( (achar0==0) || aint0)
+ if ((achar0 == 0) || aint0)
failures++;
}
-void bool_and1(void)
+void
+bool_and1 (void)
{
- if( achar0 && achar1)
+ if (achar0 && achar1)
failures++;
}
-void bin_or1(void)
+void
+bin_or1 (void)
{
char t;
t = achar0 | achar1;
- if(t)
+ if (t)
failures++;
}
-void bin_xor1(void)
+void
+bin_xor1 (void)
{
- if(achar0 ^ achar1)
+ if (achar0 ^ achar1)
failures++;
}
-void bool_test3(void)
+void
+bool_test3 (void)
{
- if((achar0 == 0x42) || (achar1 == 42))
+ if ((achar0 == 0x42) || (achar1 == 42))
failures++;
}
-void bool_or_lit1(void)
+void
+bool_or_lit1 (void)
{
achar0 |= 0x0f;
- if(achar0 > 0x10)
+ if (achar0 > 0x10)
failures++;
- if( (achar0 | 0x10) > 0xf0)
+ if ((achar0 | 0x10) > 0xf0)
failures++;
}
-void bool_and_lit1(void)
+void
+bool_and_lit1 (void)
{
achar0 &= 0xf0;
- if(achar0 > 0x10)
+ if (achar0 > 0x10)
failures++;
- if( (achar0 & 0x10) > 0xf0)
+ if ((achar0 & 0x10) > 0xf0)
failures++;
achar0 &= 0xef;
}
-void main(void)
+void
+main (void)
{
- bool_or1();
- bool_or2();
- bool_and1();
- bin_or1();
- bin_xor1();
+ bool_or1 ();
+ bool_or2 ();
+ bool_and1 ();
+ bin_or1 ();
+ bin_xor1 ();
achar0++;
- bool_and1();
- bool_test1();
- bool_test2();
- bool_test3();
+ bool_and1 ();
+ bool_test1 ();
+ bool_test2 ();
+ bool_test3 ();
- achar0--; achar1++;
- bool_and1();
+ achar0--;
+ achar1++;
+ bool_and1 ();
- achar0=0;
- achar1=0;
+ achar0 = 0;
+ achar1 = 0;
- bool_or_lit1();
- bool_and_lit1();
+ bool_or_lit1 ();
+ bool_and_lit1 ();
success = failures;
- done();
+ done ();
}
unsigned char success = 0;
-unsigned char uchar0=0;
-unsigned char uchar1=0;
-unsigned char uchar2=0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
+unsigned char uchar2 = 0;
-void done(void)
+void
+done (void)
{
success++;
}
-void incptr(unsigned char *ucP)
+void
+incptr (unsigned char *ucP)
{
*ucP = *ucP + 1;
}
-void inc(unsigned char k)
+void
+inc (unsigned char k)
{
uchar0 = uchar0 + k;
uchar1 = uchar1 + uchar0;
uchar2 = uchar1 + k;
}
-void main(void)
+void
+main (void)
{
- uchar0=1;
+ uchar0 = 1;
//incptr(&uchar0);
- inc(uchar0);
- if(uchar0 !=2)
+ inc (uchar0);
+ if (uchar0 != 2)
success++;
- done();
+ done ();
}
//#include "p16c84.h"
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
bit bit0 = 0;
unsigned int aint0 = 0;
unsigned char achar0 = 0;
unsigned char achar1 = 0;
-void done()
+void
+done ()
{
dummy++;
}
-void bool_or1(void)
+void
+bool_or1 (void)
{
- if( (achar0 >0) || (achar1 >0 ))
+ if ((achar0 > 0) || (achar1 > 0))
failures++;
}
-void bool_or2(void)
+void
+bool_or2 (void)
{
- if( achar0 || achar1)
+ if (achar0 || achar1)
failures++;
}
-void bool_test1(void)
+void
+bool_test1 (void)
{
- if( (achar0==0) || achar1)
+ if ((achar0 == 0) || achar1)
failures++;
}
-void bool_test2(void)
+void
+bool_test2 (void)
{
- if( (achar0==0) || aint0)
+ if ((achar0 == 0) || aint0)
failures++;
}
-void bool_and1(void)
+void
+bool_and1 (void)
{
- if( achar0 && achar1)
+ if (achar0 && achar1)
failures++;
}
-void bin_or1(void)
+void
+bin_or1 (void)
{
char t;
t = achar0 | achar1;
- if(t)
+ if (t)
failures++;
}
-void bin_xor1(void)
+void
+bin_xor1 (void)
{
- if(achar0 ^ achar1)
+ if (achar0 ^ achar1)
failures++;
}
-void bool_test3(void)
+void
+bool_test3 (void)
{
- if((achar0 == 0x42) || (achar1 == 42))
+ if ((achar0 == 0x42) || (achar1 == 42))
failures++;
}
-void bool_or_lit1(void)
+void
+bool_or_lit1 (void)
{
achar0 |= 0x0f;
- if(achar0 > 0x10)
+ if (achar0 > 0x10)
failures++;
- if( (achar0 | 0x10) > 0xf0)
+ if ((achar0 | 0x10) > 0xf0)
failures++;
}
-void bool_and_lit1(void)
+void
+bool_and_lit1 (void)
{
achar0 &= 0xf0;
- if(achar0 > 0x10)
+ if (achar0 > 0x10)
failures++;
- if( (achar0 & 0x10) > 0xf0)
+ if ((achar0 & 0x10) > 0xf0)
failures++;
achar0 &= 0xef;
}
-void main(void)
+void
+main (void)
{
- bool_or1();
- bool_or2();
- bool_and1();
- bin_or1();
- bin_xor1();
+ bool_or1 ();
+ bool_or2 ();
+ bool_and1 ();
+ bin_or1 ();
+ bin_xor1 ();
achar0++;
- bool_and1();
- bool_test1();
- bool_test2();
- bool_test3();
+ bool_and1 ();
+ bool_test1 ();
+ bool_test2 ();
+ bool_test3 ();
- achar0--; achar1++;
- bool_and1();
+ achar0--;
+ achar1++;
+ bool_and1 ();
- achar0=0;
- achar1=0;
+ achar0 = 0;
+ achar1 = 0;
- bool_or_lit1();
- bool_and_lit1();
+ bool_or_lit1 ();
+ bool_and_lit1 ();
success = failures;
- done();
+ done ();
}
//#include "p16c84.h"
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
bit bit0 = 0;
unsigned int aint0 = 0;
unsigned char achar0 = 0;
unsigned char achar1 = 0;
-unsigned char call3(void);
+unsigned char call3 (void);
-void done()
+void
+done ()
{
dummy++;
}
-void call1(unsigned char uc0)
+void
+call1 (unsigned char uc0)
{
- if(uc0)
+ if (uc0)
failures++;
}
-void call2(unsigned int ui0)
+void
+call2 (unsigned int ui0)
{
- if(ui0)
+ if (ui0)
failures++;
}
-unsigned char call3(void)
+unsigned char
+call3 (void)
{
- if(achar0)
+ if (achar0)
failures++;
- return(failures);
+ return (failures);
}
-unsigned int call4(void)
+unsigned int
+call4 (void)
{
- unsigned int i=0;
+ unsigned int i = 0;
- if(aint0)
+ if (aint0)
i++;
- return(i);
+ return (i);
}
-unsigned int call5(unsigned int k)
+unsigned int
+call5 (unsigned int k)
{
- if(k)
+ if (k)
failures++;
- return(k);
+ return (k);
}
-void main(void)
+void
+main (void)
{
- call1(achar0);
- call2(aint0);
- achar1 = call3();
- aint1 = call4();
- if(aint1)
+ call1 (achar0);
+ call2 (aint0);
+ achar1 = call3 ();
+ aint1 = call4 ();
+ if (aint1)
failures++;
- aint1 = call5(aint0);
- if(aint1)
+ aint1 = call5 (aint0);
+ if (aint1)
failures++;
success = failures;
- done();
+ done ();
}
/*
- PIC PORT Test code
+ PIC PORT Test code
-*/
+ */
/*
- compare.c test compare
+ compare.c test compare
-*/
+ */
-bit bit0=0;
-bit bit1=0;
+bit bit0 = 0;
+bit bit1 = 0;
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
unsigned char achar0 = 0;
unsigned char achar1 = 0;
unsigned int aint0 = 0;
unsigned int aint1 = 0;
-char schar0=0;
-char schar1=0;
+char schar0 = 0;
+char schar1 = 0;
-void done()
+void
+done ()
{
dummy++;
/* achar0 should be zero */
-void compare_char_to_lits1(void)
+void
+compare_char_to_lits1 (void)
{
- if(achar0)
+ if (achar0)
failures++;
- if(achar0 == 1)
+ if (achar0 == 1)
failures++;
- if(achar0 == 7)
+ if (achar0 == 7)
failures++;
- if(achar0 != 0)
+ if (achar0 != 0)
failures++;
}
/* achar0 should be `5' */
-void compare_char_to_lits2(void)
+void
+compare_char_to_lits2 (void)
{
- if(!achar0)
+ if (!achar0)
failures++;
- if(achar0 == 1)
+ if (achar0 == 1)
failures++;
- if(achar0 == 7)
+ if (achar0 == 7)
failures++;
- if(achar0 != 5)
+ if (achar0 != 5)
failures++;
}
/* achar0 should equal achar1 */
-void compare_char_to_char1(void)
+void
+compare_char_to_char1 (void)
{
- if(achar0 != achar1)
+ if (achar0 != achar1)
failures++;
- if(schar0 != schar1)
+ if (schar0 != schar1)
failures++;
}
/* achar0 should be different than achar1 */
-void compare_char_to_char2(void)
+void
+compare_char_to_char2 (void)
{
- if(achar0 == achar1)
+ if (achar0 == achar1)
failures++;
}
/* aint0 should be zero */
-void compare_int_to_lits1(void)
+void
+compare_int_to_lits1 (void)
{
- if(aint0)
+ if (aint0)
failures++;
- if(aint0 == 1)
+ if (aint0 == 1)
failures++;
- if(aint0 == 7)
+ if (aint0 == 7)
failures++;
- if(aint0 != 0)
+ if (aint0 != 0)
failures++;
}
/* aint0 should be `5' */
-void compare_int_to_lits2(void)
+void
+compare_int_to_lits2 (void)
{
- if(!aint0)
+ if (!aint0)
failures++;
- if(aint0 == 1)
+ if (aint0 == 1)
failures++;
- if(aint0 == 7)
+ if (aint0 == 7)
failures++;
- if(aint0 != 5)
+ if (aint0 != 5)
failures++;
}
/* aint0 should be `0x1234' */
-void compare_int_to_lits3(void)
+void
+compare_int_to_lits3 (void)
{
- if(!aint0)
+ if (!aint0)
failures++;
- if(aint0 == 1)
+ if (aint0 == 1)
failures++;
- if(aint0 == 7)
+ if (aint0 == 7)
failures++;
- if(aint0 != 0x1234)
+ if (aint0 != 0x1234)
failures++;
}
/* aint0 should equal aint1 */
-void compare_int_to_int1(void)
+void
+compare_int_to_int1 (void)
{
- if(aint0 != aint1)
+ if (aint0 != aint1)
failures++;
}
/* aint0 should be different than aint1 */
-void compare_int_to_int2(void)
+void
+compare_int_to_int2 (void)
{
- if(aint0 == aint1)
+ if (aint0 == aint1)
failures++;
}
-void main(void)
+void
+main (void)
{
- compare_char_to_lits1();
- compare_char_to_char1();
+ compare_char_to_lits1 ();
+ compare_char_to_char1 ();
achar0 = 5;
- compare_char_to_lits2();
- compare_char_to_char2();
+ compare_char_to_lits2 ();
+ compare_char_to_char2 ();
- compare_int_to_lits1();
+ compare_int_to_lits1 ();
aint0 = 5;
- compare_int_to_lits2();
+ compare_int_to_lits2 ();
aint0 = 0x1234;
- compare_int_to_lits3();
- compare_int_to_int2();
+ compare_int_to_lits3 ();
+ compare_int_to_int2 ();
aint0 = 0;
- compare_int_to_int1();
+ compare_int_to_int1 ();
success = failures;
- done();
+ done ();
}
//#include "p16c84.h"
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
bit bit0 = 0;
unsigned int aint0 = 0;
unsigned char achar0 = 0;
unsigned char achar1 = 0;
-void done()
+void
+done ()
{
dummy++;
-void char_lt_char(void)
+void
+char_lt_char (void)
{
- if(achar0 < achar1)
+ if (achar0 < achar1)
failures++;
}
-void char_gt_char(void)
+void
+char_gt_char (void)
{
- if(achar1 > achar0)
+ if (achar1 > achar0)
failures++;
}
-void char_lte_char(void)
+void
+char_lte_char (void)
{
- if(achar0 <= achar1)
+ if (achar0 <= achar1)
failures++;
}
-void char_gte_char(void)
+void
+char_gte_char (void)
{
- if(achar1 >= achar0)
+ if (achar1 >= achar0)
failures++;
}
-void char_lt_lit(void)
+void
+char_lt_lit (void)
{
- if(achar1 < 0x10)
+ if (achar1 < 0x10)
failures++;
}
-void char_gt_lit(void)
+void
+char_gt_lit (void)
{
- if(achar1 > 0x10)
+ if (achar1 > 0x10)
failures++;
}
-void char_lte_lit(void)
+void
+char_lte_lit (void)
{
- if(achar1 <= 0x0f)
+ if (achar1 <= 0x0f)
failures++;
}
-void char_gte_lit(void)
+void
+char_gte_lit (void)
{
- if(achar1 >= 0x11)
+ if (achar1 >= 0x11)
failures++;
}
/* ints */
-void int_lt_int(void)
+void
+int_lt_int (void)
{
- if(aint0 < aint1)
+ if (aint0 < aint1)
failures++;
}
-void int_gt_int(void)
+void
+int_gt_int (void)
{
- if(aint1 > aint0)
+ if (aint1 > aint0)
failures++;
}
-void int_lte_int(void)
+void
+int_lte_int (void)
{
- if(aint0 <= aint1)
+ if (aint0 <= aint1)
failures++;
}
-void int_gte_int(void)
+void
+int_gte_int (void)
{
- if(aint1 >= aint0)
+ if (aint1 >= aint0)
failures++;
}
-void int_lt_lit(void)
+void
+int_lt_lit (void)
{
- if(aint1 < 0x10)
+ if (aint1 < 0x10)
failures++;
}
-void int_gt_lit(void)
+void
+int_gt_lit (void)
{
- if(aint1 > 0x10)
+ if (aint1 > 0x10)
failures++;
}
-void int_lte_lit(void)
+void
+int_lte_lit (void)
{
- if(aint1 <= 0x0f)
+ if (aint1 <= 0x0f)
failures++;
}
-void int_gte_lit(void)
+void
+int_gte_lit (void)
{
- if(aint1 >= 0x11)
+ if (aint1 >= 0x11)
failures++;
}
-void main(void)
+void
+main (void)
{
- char_lt_char();
- char_gt_char();
+ char_lt_char ();
+ char_gt_char ();
achar0++;
- char_lt_char();
- char_gt_char();
- char_gte_char();
- char_lte_char();
+ char_lt_char ();
+ char_gt_char ();
+ char_gte_char ();
+ char_lte_char ();
achar1 = 0x10;
- char_lt_lit();
- char_gt_lit();
- char_lte_lit();
- char_gte_lit();
+ char_lt_lit ();
+ char_gt_lit ();
+ char_lte_lit ();
+ char_gte_lit ();
- int_lt_int();
- int_gt_int();
+ int_lt_int ();
+ int_gt_int ();
aint0++;
- int_lt_int();
- int_gt_int();
- int_gte_int();
- int_lte_int();
+ int_lt_int ();
+ int_gt_int ();
+ int_gte_int ();
+ int_lte_int ();
aint1 = 0x10;
- int_lt_lit();
- int_gt_lit();
+ int_lt_lit ();
+ int_gt_lit ();
success = failures;
- done();
+ done ();
}
//#include "p16c84.h"
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
bit bit0 = 0;
unsigned int aint0 = 0;
unsigned char achar0 = 0;
unsigned char achar1 = 0;
-unsigned char call3(void);
+unsigned char call3 (void);
-void done()
+void
+done ()
{
dummy++;
}
-void for1(void)
+void
+for1 (void)
{
- unsigned char i=0;
+ unsigned char i = 0;
- for(i=0; i<10; i++)
+ for (i = 0; i < 10; i++)
achar0++;
- if(achar0 != 10)
+ if (achar0 != 10)
failures++;
}
-void for2(void)
+void
+for2 (void)
{
- unsigned char i=0;
+ unsigned char i = 0;
- for(i=0; i<10; i++)
+ for (i = 0; i < 10; i++)
achar0++;
- if(i < 10)
+ if (i < 10)
failures++;
}
-void main(void)
+void
+main (void)
{
- for1();
- for2();
+ for1 ();
+ for2 ();
success = failures;
- done();
+ done ();
}
//#include "p16c84.h"
// Pointer tests
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
bit bit0 = 0;
unsigned int aint0 = 0;
unsigned char achar1 = 0;
unsigned char *acharP = 0;
-void done()
+void
+done ()
{
dummy++;
}
-void f1(unsigned char *ucP)
+void
+f1 (unsigned char *ucP)
{
- if(ucP==0) {
- failures++;
- return;
- }
-
- if(*ucP)
+ if (ucP == 0)
+ {
failures++;
+ return;
+ }
+
+ if (*ucP)
+ failures++;
}
-void f2(unsigned int *uiP)
+void
+f2 (unsigned int *uiP)
{
- if(uiP==0) {
- failures++;
- return;
- }
+ if (uiP == 0)
+ {
+ failures++;
+ return;
+ }
- if(*uiP)
+ if (*uiP)
failures++;
}
-unsigned char *f3(void)
+unsigned char *
+f3 (void)
{
return &achar0;
}
-void main(void)
+void
+main (void)
{
- f1(&achar0);
- f2(&aint0);
+ f1 (&achar0);
+ f2 (&aint0);
- acharP = f3();
- if( (acharP == 0) || (*acharP))
- failures++;
+ acharP = f3 ();
+ if ((acharP == 0) || (*acharP))
+ failures++;
success = failures;
- done();
+ done ();
}
* (like bitx = bity + bitz;) */
#define SUPPORT_BIT_ARITHMETIC 1
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
#if SUPPORT_BIT_TYPES
unsigned char achar1 = 0;
unsigned char *acharP = 0;
-struct chars {
- unsigned char c0,c1;
-};
+struct chars
+ {
+ unsigned char c0, c1;
+ };
struct chars char_struct;
-void done()
+void
+done ()
{
dummy++;
}
-void struct_test(void)
+void
+struct_test (void)
{
- if(char_struct.c0 || char_struct.c1)
+ if (char_struct.c0 || char_struct.c1)
failures++;
char_struct.c0++;
- if(char_struct.c0 != 1)
+ if (char_struct.c0 != 1)
failures++;
}
-void ptr_to_struct(struct chars *p)
+void
+ptr_to_struct (struct chars *p)
{
- if(p->c1)
+ if (p->c1)
failures++;
p->c1++;
- if(p->c1 != 1)
+ if (p->c1 != 1)
failures++;
}
-void main(void)
+void
+main (void)
{
char_struct.c0 = 0;
char_struct.c1 = 0;
- struct_test();
- ptr_to_struct(&char_struct);
+ struct_test ();
+ ptr_to_struct (&char_struct);
success = failures;
- done();
+ done ();
}
//#include "p16c84.h"
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
bit bit0 = 0;
unsigned int aint0 = 0;
unsigned char achar1 = 0;
-void done()
+void
+done ()
{
dummy++;
}
-void while1(void)
+void
+while1 (void)
{
- unsigned char i=10;
+ unsigned char i = 10;
- do {
- achar0++;
- } while(--i);
+ do
+ {
+ achar0++;
+ }
+ while (--i);
- if(achar0 != 10)
+ if (achar0 != 10)
failures++;
}
-void main(void)
+void
+main (void)
{
- while1();
+ while1 ();
success = failures;
- done();
+ done ();
}
#include "peeph-gbz80.rul"
};
-static char *_gbz80_keywords[] = { NULL };
+static char *_gbz80_keywords[] =
+{NULL};
-static bool _gbz80_parseOptions(int *pargc, char **argv, int *i)
+static bool
+_gbz80_parseOptions (int *pargc, char **argv, int *i)
{
- return FALSE;
+ return FALSE;
}
-static void _gbz80_init(void)
+static void
+_gbz80_init (void)
{
- z80_opts.sub = SUB_GBZ80;
+ z80_opts.sub = SUB_GBZ80;
}
-static void _gbz80_finaliseOptions(void)
+static void
+_gbz80_finaliseOptions (void)
{
- port->mem.default_local_map = data;
- port->mem.default_globl_map = data;
+ port->mem.default_local_map = data;
+ port->mem.default_globl_map = data;
}
-static void _gbz80_setDefaultOptions(void)
-{
- options.genericPtr = 1; /* default on */
- options.nopeep = 0;
- options.stackAuto = 1;
- options.mainreturn = 1;
- options.noregparms = 1;
- /* first the options part */
- options.intlong_rent = 1;
+static void
+_gbz80_setDefaultOptions (void)
+{
+ options.genericPtr = 1; /* default on */
+ options.nopeep = 0;
+ options.stackAuto = 1;
+ options.mainreturn = 1;
+ options.noregparms = 1;
+ /* first the options part */
+ options.intlong_rent = 1;
- optimize.global_cse = 1;
- optimize.label1 = 1;
- optimize.label2 = 1;
- optimize.label3 = 1;
- optimize.label4 = 1;
- optimize.loopInvariant = 1;
- optimize.loopInduction = 0;
+ optimize.global_cse = 1;
+ optimize.label1 = 1;
+ optimize.label2 = 1;
+ optimize.label3 = 1;
+ optimize.label4 = 1;
+ optimize.loopInvariant = 1;
+ optimize.loopInduction = 0;
}
-static const char *_gbz80_getRegName(struct regs *reg)
+static const char *
+_gbz80_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- assert(0);
- return "err";
+ if (reg)
+ return reg->name;
+ assert (0);
+ return "err";
}
/** $1 is always the basename.
$l is the list of extra options that should be there somewhere...
MUST be terminated with a NULL.
*/
-static const char *_linkCmd[] = {
- "link-gbz80", "-nf", "$1", NULL
+static const char *_linkCmd[] =
+{
+ "link-gbz80", "-nf", "$1", NULL
};
-static const char *_asmCmd[] = {
- "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
+static const char *_asmCmd[] =
+{
+ "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
};
/* Globals */
-PORT gbz80_port = {
- "gbz80",
- "Gameboy Z80-like", /* Target name */
- {
- FALSE,
- },
- {
- _asmCmd,
- "-plosgff", /* Options with debug */
- "-plosgff", /* Options without debug */
- },
- {
- _linkCmd
- },
- {
- _defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
- },
- {
- "_XSEG",
- "_STACK",
- "_CODE",
- "_DATA",
- "_ISEG",
- "_XSEG",
- "_BSEG",
- "_RSEG",
- "_GSINIT",
- "_OVERLAY",
- "_GSFINAL",
- NULL,
- NULL
- },
- {
- -1, 0, 0, 4, 0
- },
+PORT gbz80_port =
+{
+ "gbz80",
+ "Gameboy Z80-like", /* Target name */
+ {
+ FALSE,
+ },
+ {
+ _asmCmd,
+ "-plosgff", /* Options with debug */
+ "-plosgff", /* Options without debug */
+ },
+ {
+ _linkCmd
+ },
+ {
+ _defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
+ },
+ {
+ "_XSEG",
+ "_STACK",
+ "_CODE",
+ "_DATA",
+ "_ISEG",
+ "_XSEG",
+ "_BSEG",
+ "_RSEG",
+ "_GSINIT",
+ "_OVERLAY",
+ "_GSFINAL",
+ NULL,
+ NULL
+ },
+ {
+ -1, 0, 0, 4, 0
+ },
/* Z80 has no native mul/div commands */
- {
- 0
- },
- _gbz80_init,
- _gbz80_parseOptions,
- _gbz80_finaliseOptions,
- _gbz80_setDefaultOptions,
- z80_assignRegisters,
- _gbz80_getRegName,
- _gbz80_keywords,
- 0, /* no assembler preamble */
- 0, /* no local IVT generation code */
+ {
+ 0
+ },
+ _gbz80_init,
+ _gbz80_parseOptions,
+ _gbz80_finaliseOptions,
+ _gbz80_setDefaultOptions,
+ z80_assignRegisters,
+ _gbz80_getRegName,
+ _gbz80_keywords,
+ 0, /* no assembler preamble */
+ 0, /* no local IVT generation code */
};
stuff. This is what it is all about CODE GENERATION for a specific MCU.
Some of the routines may be reusable, will have to see */
-static char *spname ;
-static char *_z80_return[] = {"l", "h", "e", "d" };
-static char *_gbz80_return[] = { "e", "d", "l", "h" };
+static char *spname;
+static char *_z80_return[] =
+{"l", "h", "e", "d"};
+static char *_gbz80_return[] =
+{"e", "d", "l", "h"};
static char **_fReturn;
static char **_fTmp;
/* PENDING: messy */
static char zero[20];
-static char *accUse[] = {"a" };
-static char *hlUse[] = { "l", "h" };
+static char *accUse[] =
+{"a"};
+static char *hlUse[] =
+{"l", "h"};
short rbank = -1;
-short accInUse = 0 ;
+short accInUse = 0;
short inLine = 0;
short debugLine = 0;
short nregssaved = 0;
-extern int ptrRegReq ;
+extern int ptrRegReq;
extern int nRegs;
extern FILE *codeOutFile;
set *sendSet = NULL;
-typedef enum {
+typedef enum
+ {
PAIR_INVALID,
PAIR_BC,
PAIR_DE,
PAIR_IY,
PAIR_IX,
NUM_PAIRS
-} PAIR_ID;
+ }
+PAIR_ID;
-static struct {
+static struct
+ {
const char *name;
const char *l;
const char *h;
-} _pairs[NUM_PAIRS] = {
- { "??", "?", "?" },
- { "bc", "c", "b" },
- { "de", "e", "d" },
- { "hl", "l", "h" },
- { "iy", "iy.l?", "iy.h?" },
- { "ix", "ix.l?", "ix.h?" }
+ }
+_pairs[NUM_PAIRS] =
+{
+ {
+ "??", "?", "?"
+ }
+ ,
+ {
+ "bc", "c", "b"
+ }
+ ,
+ {
+ "de", "e", "d"
+ }
+ ,
+ {
+ "hl", "l", "h"
+ }
+ ,
+ {
+ "iy", "iy.l?", "iy.h?"
+ }
+ ,
+ {
+ "ix", "ix.l?", "ix.h?"
+ }
};
#define RESULTONSTACK(x) \
lineNode *lineCurr = NULL;
static const unsigned char SLMask[] =
-{0xFF ,0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00};
+{0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00};
static const unsigned char SRMask[] =
{0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00};
IX+2 ret LH
IX+0 ix LH
IX-2 temp0 LH
-*/
-
-static struct {
- struct {
- AOP_TYPE last_type;
- const char *lit;
- int offset;
- } pairs[NUM_PAIRS];
- struct {
- int last;
- int pushed;
- int param_offset;
- int offset;
- int pushed_bc;
- int pushed_de;
- } stack;
+ */
+
+static struct
+ {
+ struct
+ {
+ AOP_TYPE last_type;
+ const char *lit;
+ int offset;
+ }
+ pairs[NUM_PAIRS];
+ struct
+ {
+ int last;
+ int pushed;
+ int param_offset;
+ int offset;
+ int pushed_bc;
+ int pushed_de;
+ }
+ stack;
int frameId;
bool flush_statics;
bool in_home;
-} _G;
+ }
+_G;
-static char *aopGet(asmop *aop, int offset, bool bit16);
+static char *aopGet (asmop * aop, int offset, bool bit16);
-static void _tidyUp(char *buf)
+static void
+_tidyUp (char *buf)
{
- /* Clean up the line so that it is 'prettier' */
- if (strchr(buf, ':')) {
- /* Is a label - cant do anything */
- return;
- }
- /* Change the first (and probably only) ' ' to a tab so
- everything lines up.
- */
- while (*buf) {
- if (*buf == ' ') {
- *buf = '\t';
+ /* Clean up the line so that it is 'prettier' */
+ if (strchr (buf, ':'))
+ {
+ /* Is a label - cant do anything */
return;
- }
- buf++;
+ }
+ /* Change the first (and probably only) ' ' to a tab so
+ everything lines up.
+ */
+ while (*buf)
+ {
+ if (*buf == ' ')
+ {
+ *buf = '\t';
+ return;
+ }
+ buf++;
}
}
-static void emit2(const char *szFormat, ...)
+static void
+emit2 (const char *szFormat,...)
{
- char buffer[256];
- va_list ap;
+ char buffer[256];
+ va_list ap;
- va_start(ap, szFormat);
+ va_start (ap, szFormat);
- tvsprintf(buffer, szFormat, ap);
+ tvsprintf (buffer, szFormat, ap);
- _tidyUp(buffer);
- lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(buffer)) :
- (lineHead = newLineNode(buffer)));
+ _tidyUp (buffer);
+ lineCurr = (lineCurr ?
+ connectLine (lineCurr, newLineNode (buffer)) :
+ (lineHead = newLineNode (buffer)));
- lineCurr->isInline = inLine;
- lineCurr->isDebug = debugLine;
+ lineCurr->isInline = inLine;
+ lineCurr->isDebug = debugLine;
}
/*-----------------------------------------------------------------*/
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
-void emitcode (const char *inst, const char *fmt, ...)
+void
+emitcode (const char *inst, const char *fmt,...)
{
- va_list ap;
- char lb[MAX_INLINEASM];
- char *lbp = lb;
-
- va_start(ap,fmt);
-
- if (*inst != '\0') {
- sprintf(lb,"%s\t",inst);
- vsprintf(lb+(strlen(lb)),fmt,ap);
- } else
- vsprintf(lb,fmt,ap);
-
- while (isspace(*lbp)) lbp++;
-
- if (lbp && *lbp)
- lineCurr = (lineCurr ?
- connectLine(lineCurr,newLineNode(lb)) :
- (lineHead = newLineNode(lb)));
- lineCurr->isInline = inLine;
- lineCurr->isDebug = debugLine;
- va_end(ap);
-}
+ va_list ap;
+ char lb[MAX_INLINEASM];
+ char *lbp = lb;
-/* Z80:
- { "adjustsp",
- "\tld hl,#-%d\n"
- "\tadd hl,sp\n"
- "\tld sp,hl"
- }
- { "prelude",
- "push bc"
- "push de"
- "push ix"
- "ld ix,#0"
- "add ix,sp"
- { "leave"
- emitcode("ld", "sp,ix");
- emitcode("pop", "ix");
- emitcode("pop", "de");
+ va_start (ap, fmt);
+
+ if (*inst != '\0')
+ {
+ sprintf (lb, "%s\t", inst);
+ vsprintf (lb + (strlen (lb)), fmt, ap);
}
+ else
+ vsprintf (lb, fmt, ap);
+
+ while (isspace (*lbp))
+ lbp++;
+
+ if (lbp && *lbp)
+ lineCurr = (lineCurr ?
+ connectLine (lineCurr, newLineNode (lb)) :
+ (lineHead = newLineNode (lb)));
+ lineCurr->isInline = inLine;
+ lineCurr->isDebug = debugLine;
+ va_end (ap);
}
-*/
-const char *getPairName(asmop *aop)
+/* Z80:
+ { "adjustsp",
+ "\tld hl,#-%d\n"
+ "\tadd hl,sp\n"
+ "\tld sp,hl"
+ }
+ { "prelude",
+ "push bc"
+ "push de"
+ "push ix"
+ "ld ix,#0"
+ "add ix,sp"
+ { "leave"
+ emitcode("ld", "sp,ix");
+ emitcode("pop", "ix");
+ emitcode("pop", "de");
+ }
+ }
+ */
+
+const char *
+getPairName (asmop * aop)
{
- if (aop->type == AOP_REG) {
- switch (aop->aopu.aop_reg[0]->rIdx) {
- case C_IDX:
- return "bc";
- break;
- case E_IDX:
- return "de";
- break;
- case L_IDX:
- return "hl";
- break;
- }
- }
- else if (aop->type == AOP_STR) {
- switch (*aop->aopu.aop_str[0]) {
- case 'c':
- return "bc";
- break;
- case 'e':
- return "de";
- break;
- case 'l':
- return "hl";
- break;
- }
- }
- wassert(0);
- return NULL;
+ if (aop->type == AOP_REG)
+ {
+ switch (aop->aopu.aop_reg[0]->rIdx)
+ {
+ case C_IDX:
+ return "bc";
+ break;
+ case E_IDX:
+ return "de";
+ break;
+ case L_IDX:
+ return "hl";
+ break;
+ }
+ }
+ else if (aop->type == AOP_STR)
+ {
+ switch (*aop->aopu.aop_str[0])
+ {
+ case 'c':
+ return "bc";
+ break;
+ case 'e':
+ return "de";
+ break;
+ case 'l':
+ return "hl";
+ break;
+ }
+ }
+ wassert (0);
+ return NULL;
}
-static PAIR_ID getPairId(asmop *aop)
+static PAIR_ID
+getPairId (asmop * aop)
{
- if (aop->size == 2) {
- if (aop->type == AOP_REG) {
- if ((aop->aopu.aop_reg[0]->rIdx == C_IDX)&&(aop->aopu.aop_reg[1]->rIdx == B_IDX)) {
- return PAIR_BC;
- }
- if ((aop->aopu.aop_reg[0]->rIdx == E_IDX)&&(aop->aopu.aop_reg[1]->rIdx == D_IDX)) {
- return PAIR_DE;
- }
- if ((aop->aopu.aop_reg[0]->rIdx == L_IDX)&&(aop->aopu.aop_reg[1]->rIdx == H_IDX)) {
- return PAIR_HL;
- }
- }
- if (aop->type == AOP_STR) {
- if (!strcmp(aop->aopu.aop_str[0], "c")&&!strcmp(aop->aopu.aop_str[1], "b")) {
- return PAIR_BC;
- }
- if (!strcmp(aop->aopu.aop_str[0], "e")&&!strcmp(aop->aopu.aop_str[1], "d")) {
- return PAIR_DE;
- }
- if (!strcmp(aop->aopu.aop_str[0], "l")&&!strcmp(aop->aopu.aop_str[1], "h")) {
- return PAIR_HL;
- }
- }
- }
- return PAIR_INVALID;
+ if (aop->size == 2)
+ {
+ if (aop->type == AOP_REG)
+ {
+ if ((aop->aopu.aop_reg[0]->rIdx == C_IDX) && (aop->aopu.aop_reg[1]->rIdx == B_IDX))
+ {
+ return PAIR_BC;
+ }
+ if ((aop->aopu.aop_reg[0]->rIdx == E_IDX) && (aop->aopu.aop_reg[1]->rIdx == D_IDX))
+ {
+ return PAIR_DE;
+ }
+ if ((aop->aopu.aop_reg[0]->rIdx == L_IDX) && (aop->aopu.aop_reg[1]->rIdx == H_IDX))
+ {
+ return PAIR_HL;
+ }
+ }
+ if (aop->type == AOP_STR)
+ {
+ if (!strcmp (aop->aopu.aop_str[0], "c") && !strcmp (aop->aopu.aop_str[1], "b"))
+ {
+ return PAIR_BC;
+ }
+ if (!strcmp (aop->aopu.aop_str[0], "e") && !strcmp (aop->aopu.aop_str[1], "d"))
+ {
+ return PAIR_DE;
+ }
+ if (!strcmp (aop->aopu.aop_str[0], "l") && !strcmp (aop->aopu.aop_str[1], "h"))
+ {
+ return PAIR_HL;
+ }
+ }
+ }
+ return PAIR_INVALID;
}
/** Returns TRUE if the registers used in aop form a pair (BC, DE, HL) */
-bool isPair(asmop *aop)
+bool
+isPair (asmop * aop)
{
- return (getPairId(aop) != PAIR_INVALID);
+ return (getPairId (aop) != PAIR_INVALID);
}
-bool isPtrPair(asmop *aop)
+bool
+isPtrPair (asmop * aop)
{
- PAIR_ID pairId = getPairId(aop);
- switch (pairId) {
+ PAIR_ID pairId = getPairId (aop);
+ switch (pairId)
+ {
case PAIR_HL:
case PAIR_IY:
case PAIR_IX:
- return TRUE;
+ return TRUE;
default:
- return FALSE;
+ return FALSE;
}
}
/** Push a register pair onto the stack */
-void genPairPush(asmop *aop)
+void
+genPairPush (asmop * aop)
{
- emitcode("push", "%s", getPairName(aop));
+ emitcode ("push", "%s", getPairName (aop));
}
/*-----------------------------------------------------------------*/
/* newAsmop - creates a new asmOp */
/*-----------------------------------------------------------------*/
-static asmop *newAsmop (short type)
+static asmop *
+newAsmop (short type)
{
- asmop *aop;
+ asmop *aop;
- aop = Safe_calloc(1,sizeof(asmop));
- aop->type = type;
- return aop;
+ aop = Safe_calloc (1, sizeof (asmop));
+ aop->type = type;
+ return aop;
}
/*-----------------------------------------------------------------*/
/* aopForSym - for a true symbol */
/*-----------------------------------------------------------------*/
-static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool requires_a)
+static asmop *
+aopForSym (iCode * ic, symbol * sym, bool result, bool requires_a)
{
- asmop *aop;
- memmap *space;
-
- wassert(ic);
- wassert(sym);
- wassert(sym->etype);
-
- space = SPEC_OCLS(sym->etype);
-
- /* if already has one */
- if (sym->aop)
- return sym->aop;
-
- /* Assign depending on the storage class */
- if (sym->onStack || sym->iaccess) {
- emitcode("", "; AOP_STK for %s", sym->rname);
- sym->aop = aop = newAsmop(AOP_STK);
- aop->size = getSize(sym->type);
- aop->aopu.aop_stk = sym->stack;
- return aop;
- }
-
- /* special case for a function */
- if (IS_FUNC(sym->type)) {
- sym->aop = aop = newAsmop(AOP_IMMD);
- aop->aopu.aop_immd = Safe_calloc(1,strlen(sym->rname)+1);
- strcpy(aop->aopu.aop_immd,sym->rname);
- aop->size = 2;
- return aop;
- }
-
- if (IS_GB) {
- /* if it is in direct space */
- if (IN_REGSP(space) && !requires_a) {
- sym->aop = aop = newAsmop (AOP_SFR);
- aop->aopu.aop_dir = sym->rname ;
- aop->size = getSize(sym->type);
- emitcode("", "; AOP_SFR for %s", sym->rname);
+ asmop *aop;
+ memmap *space;
+
+ wassert (ic);
+ wassert (sym);
+ wassert (sym->etype);
+
+ space = SPEC_OCLS (sym->etype);
+
+ /* if already has one */
+ if (sym->aop)
+ return sym->aop;
+
+ /* Assign depending on the storage class */
+ if (sym->onStack || sym->iaccess)
+ {
+ emitcode ("", "; AOP_STK for %s", sym->rname);
+ sym->aop = aop = newAsmop (AOP_STK);
+ aop->size = getSize (sym->type);
+ aop->aopu.aop_stk = sym->stack;
+ return aop;
+ }
+
+ /* special case for a function */
+ if (IS_FUNC (sym->type))
+ {
+ sym->aop = aop = newAsmop (AOP_IMMD);
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (sym->rname) + 1);
+ strcpy (aop->aopu.aop_immd, sym->rname);
+ aop->size = 2;
return aop;
- }
}
- /* only remaining is far space */
- /* in which case DPTR gets the address */
- if (IS_GB) {
- emitcode("", "; AOP_HL for %s", sym->rname);
- sym->aop = aop = newAsmop(AOP_HL);
+ if (IS_GB)
+ {
+ /* if it is in direct space */
+ if (IN_REGSP (space) && !requires_a)
+ {
+ sym->aop = aop = newAsmop (AOP_SFR);
+ aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ emitcode ("", "; AOP_SFR for %s", sym->rname);
+ return aop;
+ }
+ }
+
+ /* only remaining is far space */
+ /* in which case DPTR gets the address */
+ if (IS_GB)
+ {
+ emitcode ("", "; AOP_HL for %s", sym->rname);
+ sym->aop = aop = newAsmop (AOP_HL);
}
- else {
- sym->aop = aop = newAsmop(AOP_IY);
+ else
+ {
+ sym->aop = aop = newAsmop (AOP_IY);
}
- aop->size = getSize(sym->type);
- aop->aopu.aop_dir = sym->rname;
+ aop->size = getSize (sym->type);
+ aop->aopu.aop_dir = sym->rname;
- /* if it is in code space */
- if (IN_CODESPACE(space))
- aop->code = 1;
+ /* if it is in code space */
+ if (IN_CODESPACE (space))
+ aop->code = 1;
- return aop;
+ return aop;
}
/*-----------------------------------------------------------------*/
/* aopForRemat - rematerialzes an object */
/*-----------------------------------------------------------------*/
-static asmop *aopForRemat (symbol *sym)
+static asmop *
+aopForRemat (symbol * sym)
{
- char *s = buffer;
- iCode *ic = sym->rematiCode;
- asmop *aop = newAsmop(AOP_IMMD);
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
+ asmop *aop = newAsmop (AOP_IMMD);
- while (1) {
- /* if plus or minus print the right hand side */
- if (ic->op == '+' || ic->op == '-') {
- /* PENDING: for re-target */
- sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
- ic->op );
- s += strlen(s);
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- continue ;
- }
- /* we reached the end */
- sprintf(s,"%s",OP_SYMBOL(IC_LEFT(ic))->rname);
- break;
- }
-
- aop->aopu.aop_immd = Safe_calloc(1,strlen(buffer)+1);
- strcpy(aop->aopu.aop_immd,buffer);
- return aop;
+ while (1)
+ {
+ /* if plus or minus print the right hand side */
+ if (ic->op == '+' || ic->op == '-')
+ {
+ /* PENDING: for re-target */
+ sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+ ic->op);
+ s += strlen (s);
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ continue;
+ }
+ /* we reached the end */
+ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ break;
+ }
+
+ aop->aopu.aop_immd = Safe_calloc (1, strlen (buffer) + 1);
+ strcpy (aop->aopu.aop_immd, buffer);
+ return aop;
}
/*-----------------------------------------------------------------*/
/* regsInCommon - two operands have some registers in common */
/*-----------------------------------------------------------------*/
-bool regsInCommon (operand *op1, operand *op2)
+bool
+regsInCommon (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
- int i;
+ symbol *sym1, *sym2;
+ int i;
- /* if they have registers in common */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE ;
+ /* if they have registers in common */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- if (sym1->nRegs == 0 || sym2->nRegs == 0)
- return FALSE ;
+ if (sym1->nRegs == 0 || sym2->nRegs == 0)
+ return FALSE;
- for (i = 0 ; i < sym1->nRegs ; i++) {
- int j;
- if (!sym1->regs[i])
- continue ;
+ for (i = 0; i < sym1->nRegs; i++)
+ {
+ int j;
+ if (!sym1->regs[i])
+ continue;
- for (j = 0 ; j < sym2->nRegs ;j++ ) {
- if (!sym2->regs[j])
- continue ;
+ for (j = 0; j < sym2->nRegs; j++)
+ {
+ if (!sym2->regs[j])
+ continue;
- if (sym2->regs[j] == sym1->regs[i])
- return TRUE ;
- }
+ if (sym2->regs[j] == sym1->regs[i])
+ return TRUE;
+ }
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* operandsEqu - equivalent */
/*-----------------------------------------------------------------*/
-bool operandsEqu ( operand *op1, operand *op2)
+bool
+operandsEqu (operand * op1, operand * op2)
{
- symbol *sym1, *sym2;
+ symbol *sym1, *sym2;
- /* if they not symbols */
- if (!IS_SYMOP(op1) || !IS_SYMOP(op2))
- return FALSE;
+ /* if they not symbols */
+ if (!IS_SYMOP (op1) || !IS_SYMOP (op2))
+ return FALSE;
- sym1 = OP_SYMBOL(op1);
- sym2 = OP_SYMBOL(op2);
+ sym1 = OP_SYMBOL (op1);
+ sym2 = OP_SYMBOL (op2);
- /* if both are itemps & one is spilt
- and the other is not then false */
- if (IS_ITEMP(op1) && IS_ITEMP(op2) &&
- sym1->isspilt != sym2->isspilt )
- return FALSE ;
+ /* if both are itemps & one is spilt
+ and the other is not then false */
+ if (IS_ITEMP (op1) && IS_ITEMP (op2) &&
+ sym1->isspilt != sym2->isspilt)
+ return FALSE;
- /* if they are the same */
- if (sym1 == sym2)
- return 1;
+ /* if they are the same */
+ if (sym1 == sym2)
+ return 1;
- if (strcmp(sym1->rname,sym2->rname) == 0)
- return 2;
+ if (strcmp (sym1->rname, sym2->rname) == 0)
+ return 2;
- /* if left is a tmp & right is not */
- if (IS_ITEMP(op1) &&
- !IS_ITEMP(op2) &&
- sym1->isspilt &&
- (sym1->usl.spillLoc == sym2))
- return 3;
+ /* if left is a tmp & right is not */
+ if (IS_ITEMP (op1) &&
+ !IS_ITEMP (op2) &&
+ sym1->isspilt &&
+ (sym1->usl.spillLoc == sym2))
+ return 3;
- if (IS_ITEMP(op2) &&
- !IS_ITEMP(op1) &&
- sym2->isspilt &&
- sym1->level > 0 &&
- (sym2->usl.spillLoc == sym1))
- return 4;
+ if (IS_ITEMP (op2) &&
+ !IS_ITEMP (op1) &&
+ sym2->isspilt &&
+ sym1->level > 0 &&
+ (sym2->usl.spillLoc == sym1))
+ return 4;
- return FALSE;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* sameRegs - two asmops have the same registers */
/*-----------------------------------------------------------------*/
-bool sameRegs (asmop *aop1, asmop *aop2 )
+bool
+sameRegs (asmop * aop1, asmop * aop2)
{
- int i;
+ int i;
- if (aop1->type == AOP_SFR ||
- aop2->type == AOP_SFR)
- return FALSE;
+ if (aop1->type == AOP_SFR ||
+ aop2->type == AOP_SFR)
+ return FALSE;
- if (aop1 == aop2)
- return TRUE;
+ if (aop1 == aop2)
+ return TRUE;
- if (aop1->type != AOP_REG ||
- aop2->type != AOP_REG )
- return FALSE;
+ if (aop1->type != AOP_REG ||
+ aop2->type != AOP_REG)
+ return FALSE;
- if (aop1->size != aop2->size)
- return FALSE ;
+ if (aop1->size != aop2->size)
+ return FALSE;
- for (i = 0 ; i < aop1->size ; i++ )
- if (aop1->aopu.aop_reg[i] !=
- aop2->aopu.aop_reg[i] )
- return FALSE ;
+ for (i = 0; i < aop1->size; i++)
+ if (aop1->aopu.aop_reg[i] !=
+ aop2->aopu.aop_reg[i])
+ return FALSE;
- return TRUE ;
+ return TRUE;
}
/*-----------------------------------------------------------------*/
/* aopOp - allocates an asmop for an operand : */
/*-----------------------------------------------------------------*/
-static void aopOp (operand *op, iCode *ic, bool result, bool requires_a)
+static void
+aopOp (operand * op, iCode * ic, bool result, bool requires_a)
{
- asmop *aop;
- symbol *sym;
- int i;
-
- if (!op)
- return ;
-
- /* if this a literal */
- if (IS_OP_LITERAL(op)) {
- op->aop = aop = newAsmop(AOP_LIT);
- aop->aopu.aop_lit = op->operand.valOperand;
- aop->size = getSize(operandType(op));
- return;
- }
-
- /* if already has a asmop then continue */
- if (op->aop)
- return ;
-
- /* if the underlying symbol has a aop */
- if (IS_SYMOP(op) && OP_SYMBOL(op)->aop) {
- op->aop = OP_SYMBOL(op)->aop;
- return;
- }
-
- /* if this is a true symbol */
- if (IS_TRUE_SYMOP(op)) {
- op->aop = aopForSym(ic, OP_SYMBOL(op), result, requires_a);
- return ;
- }
-
- /* this is a temporary : this has
- only four choices :
- a) register
- b) spillocation
- c) rematerialize
- d) conditional
- e) can be a return use only */
-
- sym = OP_SYMBOL(op);
-
- /* if the type is a conditional */
- if (sym->regType == REG_CND) {
- aop = op->aop = sym->aop = newAsmop(AOP_CRY);
- aop->size = 0;
- return;
- }
-
- /* if it is spilt then two situations
- a) is rematerialize
- b) has a spill location */
- if (sym->isspilt || sym->nRegs == 0) {
- /* rematerialize it NOW */
- if (sym->remat) {
- sym->aop = op->aop = aop =
- aopForRemat (sym);
- aop->size = getSize(sym->type);
- return;
- }
-
- if (sym->accuse) {
- int i;
- if (sym->accuse == ACCUSE_A) {
- aop = op->aop = sym->aop = newAsmop(AOP_ACC);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < 2 ; i++ )
- aop->aopu.aop_str[i] = accUse[i];
- }
- else if (sym->accuse == ACCUSE_HL) {
- wassert(!IS_GB);
- aop = op->aop = sym->aop = newAsmop(AOP_HLREG);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < 2 ; i++ )
- aop->aopu.aop_str[i] = hlUse[i];
- }
- else
- wassert(0);
+ asmop *aop;
+ symbol *sym;
+ int i;
+
+ if (!op)
+ return;
+
+ /* if this a literal */
+ if (IS_OP_LITERAL (op))
+ {
+ op->aop = aop = newAsmop (AOP_LIT);
+ aop->aopu.aop_lit = op->operand.valOperand;
+ aop->size = getSize (operandType (op));
return;
- }
+ }
+
+ /* if already has a asmop then continue */
+ if (op->aop)
+ return;
+
+ /* if the underlying symbol has a aop */
+ if (IS_SYMOP (op) && OP_SYMBOL (op)->aop)
+ {
+ op->aop = OP_SYMBOL (op)->aop;
+ return;
+ }
+
+ /* if this is a true symbol */
+ if (IS_TRUE_SYMOP (op))
+ {
+ op->aop = aopForSym (ic, OP_SYMBOL (op), result, requires_a);
+ return;
+ }
+
+ /* this is a temporary : this has
+ only four choices :
+ a) register
+ b) spillocation
+ c) rematerialize
+ d) conditional
+ e) can be a return use only */
+
+ sym = OP_SYMBOL (op);
+
+ /* if the type is a conditional */
+ if (sym->regType == REG_CND)
+ {
+ aop = op->aop = sym->aop = newAsmop (AOP_CRY);
+ aop->size = 0;
+ return;
+ }
+
+ /* if it is spilt then two situations
+ a) is rematerialize
+ b) has a spill location */
+ if (sym->isspilt || sym->nRegs == 0)
+ {
+ /* rematerialize it NOW */
+ if (sym->remat)
+ {
+ sym->aop = op->aop = aop =
+ aopForRemat (sym);
+ aop->size = getSize (sym->type);
+ return;
+ }
+
+ if (sym->accuse)
+ {
+ int i;
+ if (sym->accuse == ACCUSE_A)
+ {
+ aop = op->aop = sym->aop = newAsmop (AOP_ACC);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < 2; i++)
+ aop->aopu.aop_str[i] = accUse[i];
+ }
+ else if (sym->accuse == ACCUSE_HL)
+ {
+ wassert (!IS_GB);
+ aop = op->aop = sym->aop = newAsmop (AOP_HLREG);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < 2; i++)
+ aop->aopu.aop_str[i] = hlUse[i];
+ }
+ else
+ wassert (0);
+ return;
+ }
+
+ if (sym->ruonly)
+ {
+ int i;
+ aop = op->aop = sym->aop = newAsmop (AOP_STR);
+ aop->size = getSize (sym->type);
+ for (i = 0; i < 4; i++)
+ aop->aopu.aop_str[i] = _fReturn[i];
+ return;
+ }
+
+ /* else spill location */
+ sym->aop = op->aop = aop =
+ aopForSym (ic, sym->usl.spillLoc, result, requires_a);
+ aop->size = getSize (sym->type);
+ return;
+ }
- if (sym->ruonly ) {
- int i;
- aop = op->aop = sym->aop = newAsmop(AOP_STR);
- aop->size = getSize(sym->type);
- for ( i = 0 ; i < 4 ; i++ )
- aop->aopu.aop_str[i] = _fReturn[i];
- return;
- }
-
- /* else spill location */
- sym->aop = op->aop = aop =
- aopForSym(ic,sym->usl.spillLoc,result, requires_a);
- aop->size = getSize(sym->type);
- return;
- }
-
- /* must be in a register */
- sym->aop = op->aop = aop = newAsmop(AOP_REG);
- aop->size = sym->nRegs;
- for ( i = 0 ; i < sym->nRegs ;i++)
- aop->aopu.aop_reg[i] = sym->regs[i];
+ /* must be in a register */
+ sym->aop = op->aop = aop = newAsmop (AOP_REG);
+ aop->size = sym->nRegs;
+ for (i = 0; i < sym->nRegs; i++)
+ aop->aopu.aop_reg[i] = sym->regs[i];
}
/*-----------------------------------------------------------------*/
/* freeAsmop - free up the asmop given to an operand */
/*----------------------------------------------------------------*/
-static void freeAsmop (operand *op, asmop *aaop, iCode *ic)
+static void
+freeAsmop (operand * op, asmop * aaop, iCode * ic)
{
- asmop *aop ;
+ asmop *aop;
- if (!op)
- aop = aaop;
- else
- aop = op->aop;
+ if (!op)
+ aop = aaop;
+ else
+ aop = op->aop;
- if (!aop)
- return ;
+ if (!aop)
+ return;
- if (aop->freed)
- goto dealloc;
+ if (aop->freed)
+ goto dealloc;
- aop->freed = 1;
+ aop->freed = 1;
dealloc:
- /* all other cases just dealloc */
- if (op ) {
- op->aop = NULL;
- if (IS_SYMOP(op)) {
- OP_SYMBOL(op)->aop = NULL;
- /* if the symbol has a spill */
- if (SPIL_LOC(op))
- SPIL_LOC(op)->aop = NULL;
- }
+ /* all other cases just dealloc */
+ if (op)
+ {
+ op->aop = NULL;
+ if (IS_SYMOP (op))
+ {
+ OP_SYMBOL (op)->aop = NULL;
+ /* if the symbol has a spill */
+ if (SPIL_LOC (op))
+ SPIL_LOC (op)->aop = NULL;
+ }
}
}
-bool isLitWord(asmop *aop)
+bool
+isLitWord (asmop * aop)
{
- /* if (aop->size != 2)
- return FALSE;*/
- switch (aop->type) {
+ /* if (aop->size != 2)
+ return FALSE; */
+ switch (aop->type)
+ {
case AOP_IMMD:
case AOP_LIT:
- return TRUE;
+ return TRUE;
default:
- return FALSE;
+ return FALSE;
}
}
-char *aopGetLitWordLong(asmop *aop, int offset, bool with_hash)
+char *
+aopGetLitWordLong (asmop * aop, int offset, bool with_hash)
{
- char *s = buffer ;
- char *rs;
+ char *s = buffer;
+ char *rs;
#if 0
- if (aop->size != 2 && aop->type != AOP_HL)
- return NULL;
+ if (aop->size != 2 && aop->type != AOP_HL)
+ return NULL;
#endif
- /* depending on type */
- switch (aop->type) {
+ /* depending on type */
+ switch (aop->type)
+ {
case AOP_HL:
case AOP_IY:
case AOP_IMMD:
- /* PENDING: for re-target */
- if (with_hash)
- tsprintf(s, "!hashedstr + %d", aop->aopu.aop_immd, offset);
- else
- tsprintf(s, "%s + %d", aop->aopu.aop_immd, offset);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
- case AOP_LIT: {
- value * val = aop->aopu.aop_lit;
- /* if it is a float then it gets tricky */
- /* otherwise it is fairly simple */
- if (!IS_FLOAT(val->type)) {
- unsigned long v = floatFromVal(val);
-
- if (offset == 2)
- v >>= 16;
-
- if (with_hash)
- tsprintf(buffer, "!immedword", v);
- else
- tsprintf(buffer, "!constword", v);
- rs = Safe_calloc(1,strlen(buffer)+1);
- return strcpy (rs,buffer);
- }
- else {
- /* A float */
- Z80_FLOAT f;
- convertFloat(&f, floatFromVal(val));
+ /* PENDING: for re-target */
if (with_hash)
- tsprintf(buffer, "!immedword", f.w[offset/2]);
+ tsprintf (s, "!hashedstr + %d", aop->aopu.aop_immd, offset);
else
- tsprintf(buffer, "!constword", f.w[offset/2]);
- rs = Safe_calloc(1,strlen(buffer)+1);
- return strcpy (rs,buffer);
- }
- }
+ tsprintf (s, "%s + %d", aop->aopu.aop_immd, offset);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
+ case AOP_LIT:
+ {
+ value *val = aop->aopu.aop_lit;
+ /* if it is a float then it gets tricky */
+ /* otherwise it is fairly simple */
+ if (!IS_FLOAT (val->type))
+ {
+ unsigned long v = floatFromVal (val);
+
+ if (offset == 2)
+ v >>= 16;
+
+ if (with_hash)
+ tsprintf (buffer, "!immedword", v);
+ else
+ tsprintf (buffer, "!constword", v);
+ rs = Safe_calloc (1, strlen (buffer) + 1);
+ return strcpy (rs, buffer);
+ }
+ else
+ {
+ /* A float */
+ Z80_FLOAT f;
+ convertFloat (&f, floatFromVal (val));
+ if (with_hash)
+ tsprintf (buffer, "!immedword", f.w[offset / 2]);
+ else
+ tsprintf (buffer, "!constword", f.w[offset / 2]);
+ rs = Safe_calloc (1, strlen (buffer) + 1);
+ return strcpy (rs, buffer);
+ }
+ }
default:
- return NULL;
+ return NULL;
}
}
-char *aopGetWord(asmop *aop, int offset)
+char *
+aopGetWord (asmop * aop, int offset)
{
- return aopGetLitWordLong(aop, offset, TRUE);
+ return aopGetLitWordLong (aop, offset, TRUE);
}
-bool isPtr(const char *s)
+bool
+isPtr (const char *s)
{
- if (!strcmp(s, "hl"))
- return TRUE;
- if (!strcmp(s, "ix"))
- return TRUE;
- if (!strcmp(s, "iy"))
- return TRUE;
- return FALSE;
+ if (!strcmp (s, "hl"))
+ return TRUE;
+ if (!strcmp (s, "ix"))
+ return TRUE;
+ if (!strcmp (s, "iy"))
+ return TRUE;
+ return FALSE;
}
-static void adjustPair(const char *pair, int *pold, int new)
+static void
+adjustPair (const char *pair, int *pold, int new)
{
- wassert(pair);
+ wassert (pair);
- while (*pold < new) {
- emitcode("inc", "%s", pair);
- (*pold)++;
+ while (*pold < new)
+ {
+ emitcode ("inc", "%s", pair);
+ (*pold)++;
}
- while (*pold > new) {
- emitcode("dec", "%s", pair);
- (*pold)--;
+ while (*pold > new)
+ {
+ emitcode ("dec", "%s", pair);
+ (*pold)--;
}
}
-static void spillPair(PAIR_ID pairId)
+static void
+spillPair (PAIR_ID pairId)
{
- _G.pairs[pairId].last_type = AOP_INVALID;
- _G.pairs[pairId].lit = NULL;
+ _G.pairs[pairId].last_type = AOP_INVALID;
+ _G.pairs[pairId].lit = NULL;
}
-static void spillCached(void)
+static void
+spillCached (void)
{
- spillPair(PAIR_HL);
- spillPair(PAIR_IY);
+ spillPair (PAIR_HL);
+ spillPair (PAIR_IY);
}
-static bool requiresHL(asmop *aop)
+static bool
+requiresHL (asmop * aop)
{
- switch (aop->type) {
+ switch (aop->type)
+ {
case AOP_HL:
case AOP_STK:
- return TRUE;
+ return TRUE;
default:
- return FALSE;
+ return FALSE;
}
}
-static char *fetchLitSpecial(asmop *aop, bool negate, bool xor)
+static char *
+fetchLitSpecial (asmop * aop, bool negate, bool xor)
{
- unsigned long v;
- value * val = aop->aopu.aop_lit;
+ unsigned long v;
+ value *val = aop->aopu.aop_lit;
- wassert(aop->type == AOP_LIT);
- wassert(!IS_FLOAT(val->type));
+ wassert (aop->type == AOP_LIT);
+ wassert (!IS_FLOAT (val->type));
- v = floatFromVal(val);
+ v = floatFromVal (val);
- if (xor)
- v ^= 0x8000;
- if (negate)
- v = -v;
- v &= 0xFFFF;
+ if (xor)
+ v ^= 0x8000;
+ if (negate)
+ v = -v;
+ v &= 0xFFFF;
- tsprintf(buffer, "!immedword", v);
- return gc_strdup(buffer);
+ tsprintf (buffer, "!immedword", v);
+ return gc_strdup (buffer);
}
-static void fetchLitPair(PAIR_ID pairId, asmop *left, int offset)
+static void
+fetchLitPair (PAIR_ID pairId, asmop * left, int offset)
{
- const char *l;
- const char *pair = _pairs[pairId].name;
- l = aopGetLitWordLong(left, 0, FALSE);
- wassert(l && pair);
-
- if (isPtr(pair)) {
- if (pairId == PAIR_HL || pairId == PAIR_IY) {
- if (_G.pairs[pairId].last_type == left->type) {
- if (_G.pairs[pairId].lit && !strcmp(_G.pairs[pairId].lit, l)) {
- if (pairId == PAIR_HL && abs(_G.pairs[pairId].offset - offset) < 3) {
- adjustPair(pair, &_G.pairs[pairId].offset, offset);
- return;
- }
- if (pairId == PAIR_IY && abs(offset)<127) {
- return;
- }
- }
- }
- }
- _G.pairs[pairId].last_type = left->type;
- _G.pairs[pairId].lit = gc_strdup(l);
- _G.pairs[pairId].offset = offset;
- }
- if (IS_GB && pairId == PAIR_DE && 0) {
- if (_G.pairs[pairId].lit && !strcmp(_G.pairs[pairId].lit, l)) {
- if (abs(_G.pairs[pairId].offset - offset) < 3) {
- adjustPair(pair, &_G.pairs[pairId].offset, offset);
- return;
- }
- }
- _G.pairs[pairId].last_type = left->type;
- _G.pairs[pairId].lit = gc_strdup(l);
- _G.pairs[pairId].offset = offset;
- }
- /* Both a lit on the right and a true symbol on the left */
- if (offset)
- emit2("ld %s,!hashedstr + %u", pair, l, offset);
- else
- emit2("ld %s,!hashedstr", pair, l);
+ const char *l;
+ const char *pair = _pairs[pairId].name;
+ l = aopGetLitWordLong (left, 0, FALSE);
+ wassert (l && pair);
+
+ if (isPtr (pair))
+ {
+ if (pairId == PAIR_HL || pairId == PAIR_IY)
+ {
+ if (_G.pairs[pairId].last_type == left->type)
+ {
+ if (_G.pairs[pairId].lit && !strcmp (_G.pairs[pairId].lit, l))
+ {
+ if (pairId == PAIR_HL && abs (_G.pairs[pairId].offset - offset) < 3)
+ {
+ adjustPair (pair, &_G.pairs[pairId].offset, offset);
+ return;
+ }
+ if (pairId == PAIR_IY && abs (offset) < 127)
+ {
+ return;
+ }
+ }
+ }
+ }
+ _G.pairs[pairId].last_type = left->type;
+ _G.pairs[pairId].lit = gc_strdup (l);
+ _G.pairs[pairId].offset = offset;
+ }
+ if (IS_GB && pairId == PAIR_DE && 0)
+ {
+ if (_G.pairs[pairId].lit && !strcmp (_G.pairs[pairId].lit, l))
+ {
+ if (abs (_G.pairs[pairId].offset - offset) < 3)
+ {
+ adjustPair (pair, &_G.pairs[pairId].offset, offset);
+ return;
+ }
+ }
+ _G.pairs[pairId].last_type = left->type;
+ _G.pairs[pairId].lit = gc_strdup (l);
+ _G.pairs[pairId].offset = offset;
+ }
+ /* Both a lit on the right and a true symbol on the left */
+ if (offset)
+ emit2 ("ld %s,!hashedstr + %u", pair, l, offset);
+ else
+ emit2 ("ld %s,!hashedstr", pair, l);
}
-static void fetchPairLong(PAIR_ID pairId, asmop *aop, int offset)
+static void
+fetchPairLong (PAIR_ID pairId, asmop * aop, int offset)
{
- /* if this is remateriazable */
- if (isLitWord(aop)) {
- fetchLitPair(pairId, aop, offset);
- }
- else { /* we need to get it byte by byte */
- if (pairId == PAIR_HL && IS_GB && requiresHL(aop)) {
- aopGet(aop, offset, FALSE);
- switch (aop->size) {
- case 1:
- emit2("ld l,!*hl");
- emit2("ld h,!immedbyte", 0);
- break;
- case 2:
- emit2("!ldahli");
- emit2("ld h,!*hl");
- emit2("ld l,a");
- break;
- default:
- emit2("; WARNING: mlh woosed out. This code is invalid.");
- }
- }
- else if (IS_Z80 && aop->type == AOP_IY) {
- /* Instead of fetching relative to IY, just grab directly
- from the address IY refers to */
- char *l = aopGetLitWordLong(aop, offset, FALSE);
- wassert(l);
- emit2("ld %s,(%s)", _pairs[pairId].name, l);
- }
- else {
- emitcode("ld", "%s,%s", _pairs[pairId].l, aopGet(aop, offset, FALSE));
- emitcode("ld", "%s,%s", _pairs[pairId].h, aopGet(aop, offset+1, FALSE));
- }
- /* PENDING: check? */
- if (pairId == PAIR_HL)
- spillPair(PAIR_HL);
+ /* if this is remateriazable */
+ if (isLitWord (aop))
+ {
+ fetchLitPair (pairId, aop, offset);
+ }
+ else
+ { /* we need to get it byte by byte */
+ if (pairId == PAIR_HL && IS_GB && requiresHL (aop))
+ {
+ aopGet (aop, offset, FALSE);
+ switch (aop->size)
+ {
+ case 1:
+ emit2 ("ld l,!*hl");
+ emit2 ("ld h,!immedbyte", 0);
+ break;
+ case 2:
+ emit2 ("!ldahli");
+ emit2 ("ld h,!*hl");
+ emit2 ("ld l,a");
+ break;
+ default:
+ emit2 ("; WARNING: mlh woosed out. This code is invalid.");
+ }
+ }
+ else if (IS_Z80 && aop->type == AOP_IY)
+ {
+ /* Instead of fetching relative to IY, just grab directly
+ from the address IY refers to */
+ char *l = aopGetLitWordLong (aop, offset, FALSE);
+ wassert (l);
+ emit2 ("ld %s,(%s)", _pairs[pairId].name, l);
+ }
+ else
+ {
+ emitcode ("ld", "%s,%s", _pairs[pairId].l, aopGet (aop, offset, FALSE));
+ emitcode ("ld", "%s,%s", _pairs[pairId].h, aopGet (aop, offset + 1, FALSE));
+ }
+ /* PENDING: check? */
+ if (pairId == PAIR_HL)
+ spillPair (PAIR_HL);
}
}
-static void fetchPair(PAIR_ID pairId, asmop *aop)
+static void
+fetchPair (PAIR_ID pairId, asmop * aop)
{
- fetchPairLong(pairId, aop, 0);
+ fetchPairLong (pairId, aop, 0);
}
-static void fetchHL(asmop *aop)
+static void
+fetchHL (asmop * aop)
{
- fetchPair(PAIR_HL, aop);
+ fetchPair (PAIR_HL, aop);
}
-static void setupPair(PAIR_ID pairId, asmop *aop, int offset)
+static void
+setupPair (PAIR_ID pairId, asmop * aop, int offset)
{
- assert(pairId == PAIR_HL || pairId == PAIR_IY);
+ assert (pairId == PAIR_HL || pairId == PAIR_IY);
- switch (aop->type) {
+ switch (aop->type)
+ {
case AOP_IY:
- fetchLitPair(pairId, aop, 0);
- break;
+ fetchLitPair (pairId, aop, 0);
+ break;
case AOP_HL:
- fetchLitPair(pairId, aop, offset);
- _G.pairs[pairId].offset = offset;
- break;
- case AOP_STK: {
- /* Doesnt include _G.stack.pushed */
- int abso = aop->aopu.aop_stk + offset + _G.stack.offset;
- if (aop->aopu.aop_stk > 0) {
- abso += _G.stack.param_offset;
- }
- assert(pairId == PAIR_HL);
- /* In some cases we can still inc or dec hl */
- if (_G.pairs[pairId].last_type == AOP_STK && abs(_G.pairs[pairId].offset - abso) < 3) {
- adjustPair(_pairs[pairId].name, &_G.pairs[pairId].offset, abso);
- }
- else {
- emit2("!ldahlsp", abso +_G.stack.pushed);
- }
- _G.pairs[pairId].offset = abso;
- break;
- }
+ fetchLitPair (pairId, aop, offset);
+ _G.pairs[pairId].offset = offset;
+ break;
+ case AOP_STK:
+ {
+ /* Doesnt include _G.stack.pushed */
+ int abso = aop->aopu.aop_stk + offset + _G.stack.offset;
+ if (aop->aopu.aop_stk > 0)
+ {
+ abso += _G.stack.param_offset;
+ }
+ assert (pairId == PAIR_HL);
+ /* In some cases we can still inc or dec hl */
+ if (_G.pairs[pairId].last_type == AOP_STK && abs (_G.pairs[pairId].offset - abso) < 3)
+ {
+ adjustPair (_pairs[pairId].name, &_G.pairs[pairId].offset, abso);
+ }
+ else
+ {
+ emit2 ("!ldahlsp", abso + _G.stack.pushed);
+ }
+ _G.pairs[pairId].offset = abso;
+ break;
+ }
default:
- wassert(0);
+ wassert (0);
}
- _G.pairs[pairId].last_type = aop->type;
+ _G.pairs[pairId].last_type = aop->type;
}
-static void emitLabel(int key)
+static void
+emitLabel (int key)
{
- emit2("!tlabeldef", key);
- spillCached();
+ emit2 ("!tlabeldef", key);
+ spillCached ();
}
/*-----------------------------------------------------------------*/
/* aopGet - for fetching value of the aop */
/*-----------------------------------------------------------------*/
-static char *aopGet(asmop *aop, int offset, bool bit16)
+static char *
+aopGet (asmop * aop, int offset, bool bit16)
{
- char *s = buffer ;
- char *rs;
+ char *s = buffer;
+ char *rs;
- /* offset is greater than size then zero */
- /* PENDING: this seems a bit screwed in some pointer cases. */
- if (offset > (aop->size - 1) &&
- aop->type != AOP_LIT)
- return zero;
+ /* offset is greater than size then zero */
+ /* PENDING: this seems a bit screwed in some pointer cases. */
+ if (offset > (aop->size - 1) &&
+ aop->type != AOP_LIT)
+ return zero;
- /* depending on type */
- switch (aop->type) {
+ /* depending on type */
+ switch (aop->type)
+ {
case AOP_IMMD:
- /* PENDING: re-target */
- if (bit16)
- tsprintf (s,"!immedwords", aop->aopu.aop_immd);
- else
- switch (offset) {
- case 2:
- tsprintf(s, "!bankimmeds", aop->aopu.aop_immd);
- break;
- case 1:
- tsprintf(s, "!msbimmeds", aop->aopu.aop_immd);
- break;
- case 0:
- tsprintf(s, "!lsbimmeds", aop->aopu.aop_immd);
- break;
- default:
- wassert(0);
- }
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ /* PENDING: re-target */
+ if (bit16)
+ tsprintf (s, "!immedwords", aop->aopu.aop_immd);
+ else
+ switch (offset)
+ {
+ case 2:
+ tsprintf (s, "!bankimmeds", aop->aopu.aop_immd);
+ break;
+ case 1:
+ tsprintf (s, "!msbimmeds", aop->aopu.aop_immd);
+ break;
+ case 0:
+ tsprintf (s, "!lsbimmeds", aop->aopu.aop_immd);
+ break;
+ default:
+ wassert (0);
+ }
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_DIR:
- wassert(IS_GB);
- emitcode("ld", "a,(%s+%d) ; x", aop->aopu.aop_dir, offset);
- sprintf(s, "a");
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ wassert (IS_GB);
+ emitcode ("ld", "a,(%s+%d) ; x", aop->aopu.aop_dir, offset);
+ sprintf (s, "a");
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_SFR:
- wassert(IS_GB);
- emitcode("ldh", "a,(%s+%d) ; x", aop->aopu.aop_dir, offset);
- sprintf(s, "a");
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ wassert (IS_GB);
+ emitcode ("ldh", "a,(%s+%d) ; x", aop->aopu.aop_dir, offset);
+ sprintf (s, "a");
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_REG:
- return aop->aopu.aop_reg[offset]->name;
+ return aop->aopu.aop_reg[offset]->name;
case AOP_HL:
- wassert(IS_GB);
- setupPair(PAIR_HL, aop, offset);
- tsprintf(s, "!*hl");
- return gc_strdup(s);
+ wassert (IS_GB);
+ setupPair (PAIR_HL, aop, offset);
+ tsprintf (s, "!*hl");
+ return gc_strdup (s);
case AOP_IY:
- wassert(IS_Z80);
- setupPair(PAIR_IY, aop, offset);
- tsprintf(s,"!*iyx", offset);
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ wassert (IS_Z80);
+ setupPair (PAIR_IY, aop, offset);
+ tsprintf (s, "!*iyx", offset);
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_STK:
- if (IS_GB) {
- setupPair(PAIR_HL, aop, offset);
- tsprintf(s, "!*hl");
- }
- else {
- if (aop->aopu.aop_stk >= 0)
- offset += _G.stack.param_offset;
- tsprintf(s,"!*ixx ; x", aop->aopu.aop_stk+offset);
- }
- rs = Safe_calloc(1,strlen(s)+1);
- strcpy(rs,s);
- return rs;
+ if (IS_GB)
+ {
+ setupPair (PAIR_HL, aop, offset);
+ tsprintf (s, "!*hl");
+ }
+ else
+ {
+ if (aop->aopu.aop_stk >= 0)
+ offset += _G.stack.param_offset;
+ tsprintf (s, "!*ixx ; x", aop->aopu.aop_stk + offset);
+ }
+ rs = Safe_calloc (1, strlen (s) + 1);
+ strcpy (rs, s);
+ return rs;
case AOP_CRY:
- wassert(0);
+ wassert (0);
case AOP_ACC:
- if (!offset) {
- return "a";
- }
- return "!zero";
+ if (!offset)
+ {
+ return "a";
+ }
+ return "!zero";
case AOP_HLREG:
- wassert(offset < 2);
- return aop->aopu.aop_str[offset];
+ wassert (offset < 2);
+ return aop->aopu.aop_str[offset];
case AOP_LIT:
- return aopLiteral (aop->aopu.aop_lit,offset);
+ return aopLiteral (aop->aopu.aop_lit, offset);
case AOP_STR:
- aop->coff = offset;
- return aop->aopu.aop_str[offset];
+ aop->coff = offset;
+ return aop->aopu.aop_str[offset];
default:
- break;
+ break;
}
- wassertl(0, "aopget got unsupported aop->type");
- exit(0);
+ wassertl (0, "aopget got unsupported aop->type");
+ exit (0);
}
-bool isRegString(const char *s)
+bool
+isRegString (const char *s)
{
- if (!strcmp(s, "b") ||
- !strcmp(s, "c") ||
- !strcmp(s, "d") ||
- !strcmp(s, "e") ||
- !strcmp(s, "a") ||
- !strcmp(s, "h") ||
- !strcmp(s, "l"))
- return TRUE;
- return FALSE;
+ if (!strcmp (s, "b") ||
+ !strcmp (s, "c") ||
+ !strcmp (s, "d") ||
+ !strcmp (s, "e") ||
+ !strcmp (s, "a") ||
+ !strcmp (s, "h") ||
+ !strcmp (s, "l"))
+ return TRUE;
+ return FALSE;
}
-bool isConstant(const char *s)
+bool
+isConstant (const char *s)
{
- /* This is a bit of a hack... */
- return (*s == '#' || *s == '$');
+ /* This is a bit of a hack... */
+ return (*s == '#' || *s == '$');
}
-bool canAssignToPtr(const char *s)
+bool
+canAssignToPtr (const char *s)
{
- if (isRegString(s))
- return TRUE;
- if (isConstant(s))
- return TRUE;
- return FALSE;
+ if (isRegString (s))
+ return TRUE;
+ if (isConstant (s))
+ return TRUE;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop */
/*-----------------------------------------------------------------*/
-static void aopPut (asmop *aop, const char *s, int offset)
+static void
+aopPut (asmop * aop, const char *s, int offset)
{
- if (aop->size && offset > ( aop->size - 1)) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got offset > aop->size");
- exit(0);
+ if (aop->size && offset > (aop->size - 1))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got offset > aop->size");
+ exit (0);
}
- /* will assign value to value */
- /* depending on where it is ofcourse */
- switch (aop->type) {
+ /* will assign value to value */
+ /* depending on where it is ofcourse */
+ switch (aop->type)
+ {
case AOP_DIR:
- /* Direct. Hmmm. */
- wassert(IS_GB);
- if (strcmp(s, "a"))
- emitcode("ld", "a,%s", s);
- emitcode("ld", "(%s+%d),a", aop->aopu.aop_dir, offset);
- break;
+ /* Direct. Hmmm. */
+ wassert (IS_GB);
+ if (strcmp (s, "a"))
+ emitcode ("ld", "a,%s", s);
+ emitcode ("ld", "(%s+%d),a", aop->aopu.aop_dir, offset);
+ break;
case AOP_SFR:
- wassert(IS_GB);
- if (strcmp(s, "a"))
- emitcode("ld", "a,%s", s);
- emitcode("ldh", "(%s+%d),a", aop->aopu.aop_dir, offset);
- break;
+ wassert (IS_GB);
+ if (strcmp (s, "a"))
+ emitcode ("ld", "a,%s", s);
+ emitcode ("ldh", "(%s+%d),a", aop->aopu.aop_dir, offset);
+ break;
case AOP_REG:
- if (!strcmp(s, "!*hl"))
- emit2("ld %s,!*hl", aop->aopu.aop_reg[offset]->name);
- else
- emit2("ld %s,%s",
- aop->aopu.aop_reg[offset]->name, s);
- break;
+ if (!strcmp (s, "!*hl"))
+ emit2 ("ld %s,!*hl", aop->aopu.aop_reg[offset]->name);
+ else
+ emit2 ("ld %s,%s",
+ aop->aopu.aop_reg[offset]->name, s);
+ break;
case AOP_IY:
- wassert(!IS_GB);
- setupPair(PAIR_IY, aop, offset);
- if (!canAssignToPtr(s)) {
- emit2("ld a,%s", s);
- emit2("ld !*iyx,a", offset);
- }
- else
- emit2("ld !*iyx,%s", offset, s);
- break;
+ wassert (!IS_GB);
+ setupPair (PAIR_IY, aop, offset);
+ if (!canAssignToPtr (s))
+ {
+ emit2 ("ld a,%s", s);
+ emit2 ("ld !*iyx,a", offset);
+ }
+ else
+ emit2 ("ld !*iyx,%s", offset, s);
+ break;
case AOP_HL:
- wassert(IS_GB);
- /* PENDING: for re-target */
- if (!strcmp(s, "!*hl") || !strcmp(s, "(hl)") || !strcmp(s, "[hl]")) {
- emit2("ld a,!*hl");
- s = "a";
- }
- setupPair(PAIR_HL, aop, offset);
-
- emit2("ld !*hl,%s", s);
- break;
+ wassert (IS_GB);
+ /* PENDING: for re-target */
+ if (!strcmp (s, "!*hl") || !strcmp (s, "(hl)") || !strcmp (s, "[hl]"))
+ {
+ emit2 ("ld a,!*hl");
+ s = "a";
+ }
+ setupPair (PAIR_HL, aop, offset);
+
+ emit2 ("ld !*hl,%s", s);
+ break;
case AOP_STK:
- if (IS_GB) {
- /* PENDING: re-target */
- if (!strcmp(s, "!*hl") || !strcmp(s, "(hl)") || !strcmp(s, "[hl]")) {
- emit2("ld a,!*hl");
- s = "a";
- }
- setupPair(PAIR_HL, aop, offset);
- if (!canAssignToPtr(s)) {
- emit2("ld a,%s", s);
- emit2("ld !*hl,a");
- }
- else
- emit2("ld !*hl,%s", s);
- }
- else {
- if (aop->aopu.aop_stk >= 0)
- offset += _G.stack.param_offset;
- if (!canAssignToPtr(s)) {
- emit2("ld a,%s", s);
- emit2("ld !*ixx,a", aop->aopu.aop_stk+offset);
- }
+ if (IS_GB)
+ {
+ /* PENDING: re-target */
+ if (!strcmp (s, "!*hl") || !strcmp (s, "(hl)") || !strcmp (s, "[hl]"))
+ {
+ emit2 ("ld a,!*hl");
+ s = "a";
+ }
+ setupPair (PAIR_HL, aop, offset);
+ if (!canAssignToPtr (s))
+ {
+ emit2 ("ld a,%s", s);
+ emit2 ("ld !*hl,a");
+ }
+ else
+ emit2 ("ld !*hl,%s", s);
+ }
else
- emit2("ld !*ixx,%s", aop->aopu.aop_stk+offset, s);
- }
- break;
+ {
+ if (aop->aopu.aop_stk >= 0)
+ offset += _G.stack.param_offset;
+ if (!canAssignToPtr (s))
+ {
+ emit2 ("ld a,%s", s);
+ emit2 ("ld !*ixx,a", aop->aopu.aop_stk + offset);
+ }
+ else
+ emit2 ("ld !*ixx,%s", aop->aopu.aop_stk + offset, s);
+ }
+ break;
case AOP_CRY:
- /* if bit variable */
- if (!aop->aopu.aop_dir) {
- emit2("ld a,#0");
- emit2("rla");
- } else {
- /* In bit space but not in C - cant happen */
- wassert(0);
- }
- break;
+ /* if bit variable */
+ if (!aop->aopu.aop_dir)
+ {
+ emit2 ("ld a,#0");
+ emit2 ("rla");
+ }
+ else
+ {
+ /* In bit space but not in C - cant happen */
+ wassert (0);
+ }
+ break;
case AOP_STR:
- aop->coff = offset;
- if (strcmp(aop->aopu.aop_str[offset],s)) {
- emitcode ("ld","%s,%s",aop->aopu.aop_str[offset],s);
- }
- break;
+ aop->coff = offset;
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ {
+ emitcode ("ld", "%s,%s", aop->aopu.aop_str[offset], s);
+ }
+ break;
case AOP_ACC:
- aop->coff = offset;
- if (!offset && (strcmp(s,"acc") == 0))
+ aop->coff = offset;
+ if (!offset && (strcmp (s, "acc") == 0))
+ break;
+ if (offset > 0)
+ {
+
+ emitcode ("", "; Error aopPut AOP_ACC");
+ }
+ else
+ {
+ if (strcmp (aop->aopu.aop_str[offset], s))
+ emitcode ("ld", "%s,%s", aop->aopu.aop_str[offset], s);
+ }
break;
- if (offset>0) {
-
- emitcode("", "; Error aopPut AOP_ACC");
- }
- else {
- if (strcmp(aop->aopu.aop_str[offset],s))
- emitcode ("ld","%s,%s",aop->aopu.aop_str[offset],s);
- }
- break;
case AOP_HLREG:
- wassert(offset < 2);
- emit2("ld %s,%s", aop->aopu.aop_str[offset], s);
- break;
+ wassert (offset < 2);
+ emit2 ("ld %s,%s", aop->aopu.aop_str[offset], s);
+ break;
- default :
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "aopPut got unsupported aop->type");
- exit(0);
+ default:
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "aopPut got unsupported aop->type");
+ exit (0);
}
}
#define AOP_SIZE(op) AOP(op)->size
#define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY))
-static void commitPair(asmop *aop, PAIR_ID id)
+static void
+commitPair (asmop * aop, PAIR_ID id)
{
- if (id == PAIR_HL && requiresHL(aop)) {
- emit2("ld a,l");
- emit2("ld d,h");
- aopPut(aop, "a", 0);
- aopPut(aop, "d", 1);
+ if (id == PAIR_HL && requiresHL (aop))
+ {
+ emit2 ("ld a,l");
+ emit2 ("ld d,h");
+ aopPut (aop, "a", 0);
+ aopPut (aop, "d", 1);
}
- else {
- aopPut(aop, _pairs[id].l, 0);
- aopPut(aop, _pairs[id].h, 1);
+ else
+ {
+ aopPut (aop, _pairs[id].l, 0);
+ aopPut (aop, _pairs[id].h, 1);
}
}
/*-----------------------------------------------------------------*/
/* getDataSize - get the operand data size */
/*-----------------------------------------------------------------*/
-int getDataSize(operand *op)
+int
+getDataSize (operand * op)
{
- int size;
- size = AOP_SIZE(op);
- if(size == 3) {
- /* pointer */
- wassert(0);
+ int size;
+ size = AOP_SIZE (op);
+ if (size == 3)
+ {
+ /* pointer */
+ wassert (0);
}
- return size;
+ return size;
}
/*-----------------------------------------------------------------*/
/* movLeft2Result - move byte from left to result */
/*-----------------------------------------------------------------*/
-static void movLeft2Result (operand *left, int offl,
- operand *result, int offr, int sign)
+static void
+movLeft2Result (operand * left, int offl,
+ operand * result, int offr, int sign)
{
- char *l;
- if(!sameRegs(AOP(left),AOP(result)) || (offl != offr)){
- l = aopGet(AOP(left),offl,FALSE);
+ char *l;
+ if (!sameRegs (AOP (left), AOP (result)) || (offl != offr))
+ {
+ l = aopGet (AOP (left), offl, FALSE);
- if (!sign) {
- aopPut(AOP(result),l,offr);
- }
- else {
- wassert(0);
- }
+ if (!sign)
+ {
+ aopPut (AOP (result), l, offr);
+ }
+ else
+ {
+ wassert (0);
+ }
}
}
/** Put Acc into a register set
*/
-void outAcc(operand *result)
+void
+outAcc (operand * result)
{
- int size, offset;
- size = getDataSize(result);
- if (size){
- aopPut(AOP(result),"a",0);
- size--;
- offset = 1;
- /* unsigned or positive */
- while (size--){
- aopPut(AOP(result), zero, offset++);
- }
+ int size, offset;
+ size = getDataSize (result);
+ if (size)
+ {
+ aopPut (AOP (result), "a", 0);
+ size--;
+ offset = 1;
+ /* unsigned or positive */
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
}
}
/** Take the value in carry and put it into a register
*/
-void outBitCLong(operand *result, bool swap_sense)
+void
+outBitCLong (operand * result, bool swap_sense)
{
- /* if the result is bit */
- if (AOP_TYPE(result) == AOP_CRY) {
- emitcode("", "; Note: outBitC form 1");
- aopPut(AOP(result),"blah",0);
- }
- else {
- emit2("ld a,!zero");
- emit2("rla");
- if (swap_sense)
- emit2("xor a,!immedbyte", 1);
- outAcc(result);
+ /* if the result is bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ emitcode ("", "; Note: outBitC form 1");
+ aopPut (AOP (result), "blah", 0);
+ }
+ else
+ {
+ emit2 ("ld a,!zero");
+ emit2 ("rla");
+ if (swap_sense)
+ emit2 ("xor a,!immedbyte", 1);
+ outAcc (result);
}
}
-void outBitC(operand *result)
+void
+outBitC (operand * result)
{
- outBitCLong(result, FALSE);
+ outBitCLong (result, FALSE);
}
/*-----------------------------------------------------------------*/
/* toBoolean - emit code for orl a,operator(sizeop) */
/*-----------------------------------------------------------------*/
-void toBoolean(operand *oper)
+void
+toBoolean (operand * oper)
{
- int size = AOP_SIZE(oper);
- int offset = 0;
- if (size>1) {
- emitcode("ld", "a,%s", aopGet(AOP(oper), offset++, FALSE));
- size--;
- while (size--)
- emitcode("or","a,%s",aopGet(AOP(oper),offset++,FALSE));
+ int size = AOP_SIZE (oper);
+ int offset = 0;
+ if (size > 1)
+ {
+ emitcode ("ld", "a,%s", aopGet (AOP (oper), offset++, FALSE));
+ size--;
+ while (size--)
+ emitcode ("or", "a,%s", aopGet (AOP (oper), offset++, FALSE));
}
- else {
- if (AOP(oper)->type != AOP_ACC) {
- CLRC;
- emitcode("or","a,%s",aopGet(AOP(oper),0,FALSE));
- }
+ else
+ {
+ if (AOP (oper)->type != AOP_ACC)
+ {
+ CLRC;
+ emitcode ("or", "a,%s", aopGet (AOP (oper), 0, FALSE));
+ }
}
}
/*-----------------------------------------------------------------*/
/* genNot - generate code for ! operation */
/*-----------------------------------------------------------------*/
-static void genNot (iCode *ic)
+static void
+genNot (iCode * ic)
{
- sym_link *optype = operandType(IC_LEFT(ic));
+ sym_link *optype = operandType (IC_LEFT (ic));
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE, TRUE);
- aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE, TRUE);
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
- /* if in bit space then a special case */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
- wassert(0);
+ /* if in bit space then a special case */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
+ wassert (0);
}
- /* if type float then do float */
- if (IS_FLOAT(optype)) {
- wassert(0);
+ /* if type float then do float */
+ if (IS_FLOAT (optype))
+ {
+ wassert (0);
}
- toBoolean(IC_LEFT(ic));
+ toBoolean (IC_LEFT (ic));
- /* Not of A:
- If A == 0, !A = 1
- else A = 0
- So if A = 0, A-1 = 0xFF and C is set, rotate C into reg. */
- emit2("sub a,!one");
- outBitC(IC_RESULT(ic));
+ /* Not of A:
+ If A == 0, !A = 1
+ else A = 0
+ So if A = 0, A-1 = 0xFF and C is set, rotate C into reg. */
+ emit2 ("sub a,!one");
+ outBitC (IC_RESULT (ic));
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic);
- freeAsmop(IC_RESULT(ic),NULL,ic);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genCpl - generate code for complement */
/*-----------------------------------------------------------------*/
-static void genCpl (iCode *ic)
+static void
+genCpl (iCode * ic)
{
- int offset = 0;
- int size ;
+ int offset = 0;
+ int size;
- /* assign asmOps to operand & result */
- aopOp (IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
+ /* assign asmOps to operand & result */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
- /* if both are in bit space then
- a special case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
- wassert(0);
+ /* if both are in bit space then
+ a special case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
+ wassert (0);
}
- size = AOP_SIZE(IC_RESULT(ic));
- while (size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE);
- MOVA(l);
- emitcode("cpl","");
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ size = AOP_SIZE (IC_RESULT (ic));
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE);
+ MOVA (l);
+ emitcode ("cpl", "");
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic);
- freeAsmop(IC_RESULT(ic),NULL,ic);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genUminus - unary minus code generation */
/*-----------------------------------------------------------------*/
-static void genUminus (iCode *ic)
+static void
+genUminus (iCode * ic)
{
- int offset ,size ;
- sym_link *optype, *rtype;
+ int offset, size;
+ sym_link *optype, *rtype;
- /* assign asmops */
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp(IC_RESULT(ic),ic,TRUE, FALSE);
+ /* assign asmops */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
- /* if both in bit space then special
- case */
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
- wassert(0);
- goto release;
+ /* if both in bit space then special
+ case */
+ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
+ {
+ wassert (0);
+ goto release;
}
- optype = operandType(IC_LEFT(ic));
- rtype = operandType(IC_RESULT(ic));
+ optype = operandType (IC_LEFT (ic));
+ rtype = operandType (IC_RESULT (ic));
- /* if float then do float stuff */
- if (IS_FLOAT(optype)) {
- wassert(0);
- goto release;
+ /* if float then do float stuff */
+ if (IS_FLOAT (optype))
+ {
+ wassert (0);
+ goto release;
}
- /* otherwise subtract from zero */
- size = AOP_SIZE(IC_LEFT(ic));
- offset = 0 ;
- CLRC ;
- while(size--) {
- char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE);
- emit2("ld a,!zero");
- emit2("sbc a,%s",l);
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* otherwise subtract from zero */
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = 0;
+ CLRC;
+ while (size--)
+ {
+ char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE);
+ emit2 ("ld a,!zero");
+ emit2 ("sbc a,%s", l);
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
- /* if any remaining bytes in the result */
- /* we just need to propagate the sign */
- if ((size = (AOP_SIZE(IC_RESULT(ic)) - AOP_SIZE(IC_LEFT(ic))))) {
- emit2("rlc a");
- emit2("sbc a,a");
- while (size--)
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ /* if any remaining bytes in the result */
+ /* we just need to propagate the sign */
+ if ((size = (AOP_SIZE (IC_RESULT (ic)) - AOP_SIZE (IC_LEFT (ic)))))
+ {
+ emit2 ("rlc a");
+ emit2 ("sbc a,a");
+ while (size--)
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
release:
- /* release the aops */
- freeAsmop(IC_LEFT(ic),NULL,ic);
- freeAsmop(IC_RESULT(ic),NULL,ic);
+ /* release the aops */
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
-static void _push(PAIR_ID pairId)
+static void
+_push (PAIR_ID pairId)
{
- emit2("push %s", _pairs[pairId].name);
- _G.stack.pushed += 2;
+ emit2 ("push %s", _pairs[pairId].name);
+ _G.stack.pushed += 2;
}
-static void _pop(PAIR_ID pairId)
+static void
+_pop (PAIR_ID pairId)
{
- emit2("pop %s", _pairs[pairId].name);
- _G.stack.pushed -= 2;
+ emit2 ("pop %s", _pairs[pairId].name);
+ _G.stack.pushed -= 2;
}
/*-----------------------------------------------------------------*/
/* assignResultValue - */
/*-----------------------------------------------------------------*/
-void assignResultValue(operand * oper)
+void
+assignResultValue (operand * oper)
{
- int size = AOP_SIZE(oper);
- bool topInA = 0;
+ int size = AOP_SIZE (oper);
+ bool topInA = 0;
- wassert(size <= 4);
- topInA = requiresHL(AOP(oper));
+ wassert (size <= 4);
+ topInA = requiresHL (AOP (oper));
#if 0
- if (!IS_GB)
- wassert(size <= 2);
+ if (!IS_GB)
+ wassert (size <= 2);
#endif
- if (IS_GB && size == 4 && requiresHL(AOP(oper))) {
- /* We do it the hard way here. */
- _push(PAIR_HL);
- aopPut(AOP(oper), _fReturn[0], 0);
- aopPut(AOP(oper), _fReturn[1], 1);
- emitcode("pop", "de");
- _G.stack.pushed -= 2;
- aopPut(AOP(oper), _fReturn[0], 2);
- aopPut(AOP(oper), _fReturn[1], 3);
+ if (IS_GB && size == 4 && requiresHL (AOP (oper)))
+ {
+ /* We do it the hard way here. */
+ _push (PAIR_HL);
+ aopPut (AOP (oper), _fReturn[0], 0);
+ aopPut (AOP (oper), _fReturn[1], 1);
+ emitcode ("pop", "de");
+ _G.stack.pushed -= 2;
+ aopPut (AOP (oper), _fReturn[0], 2);
+ aopPut (AOP (oper), _fReturn[1], 3);
}
- else {
- while (size--) {
- aopPut(AOP(oper), _fReturn[size], size);
- }
+ else
+ {
+ while (size--)
+ {
+ aopPut (AOP (oper), _fReturn[size], size);
+ }
}
}
/*-----------------------------------------------------------------*/
/* genIpush - genrate code for pushing this gets a little complex */
/*-----------------------------------------------------------------*/
-static void genIpush (iCode *ic)
+static void
+genIpush (iCode * ic)
{
- int size, offset = 0 ;
- char *l;
+ int size, offset = 0;
+ char *l;
- /* if this is not a parm push : ie. it is spill push
- and spill push is always done on the local stack */
- if (!ic->parmPush) {
- /* and the item is spilt then do nothing */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
-
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- /* push it on the stack */
- if (isPair(AOP(IC_LEFT(ic)))) {
- emitcode("push", getPairName(AOP(IC_LEFT(ic))));
- _G.stack.pushed += 2;
- }
- else {
- offset = size;
- while (size--) {
- /* Simple for now - load into A and PUSH AF */
- if (AOP(IC_LEFT(ic))->type == AOP_IY) {
- char *l = aopGetLitWordLong(AOP(IC_LEFT(ic)), --offset, FALSE);
- wassert(l);
- emit2("ld a,(%s)", l);
- }
- else {
- l = aopGet(AOP(IC_LEFT(ic)), --offset, FALSE);
- emit2("ld a,%s", l);
- }
- emit2("push af");
- emit2("inc sp");
- _G.stack.pushed++;
- }
- }
- return ;
+ /* if this is not a parm push : ie. it is spill push
+ and spill push is always done on the local stack */
+ if (!ic->parmPush)
+ {
+ /* and the item is spilt then do nothing */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
+
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ /* push it on the stack */
+ if (isPair (AOP (IC_LEFT (ic))))
+ {
+ emitcode ("push", getPairName (AOP (IC_LEFT (ic))));
+ _G.stack.pushed += 2;
+ }
+ else
+ {
+ offset = size;
+ while (size--)
+ {
+ /* Simple for now - load into A and PUSH AF */
+ if (AOP (IC_LEFT (ic))->type == AOP_IY)
+ {
+ char *l = aopGetLitWordLong (AOP (IC_LEFT (ic)), --offset, FALSE);
+ wassert (l);
+ emit2 ("ld a,(%s)", l);
+ }
+ else
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), --offset, FALSE);
+ emit2 ("ld a,%s", l);
+ }
+ emit2 ("push af");
+ emit2 ("inc sp");
+ _G.stack.pushed++;
+ }
+ }
+ return;
}
- /* Hmmm... what about saving the currently used registers
- at this point? */
+ /* Hmmm... what about saving the currently used registers
+ at this point? */
- /* then do the push */
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
+ /* then do the push */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
+ size = AOP_SIZE (IC_LEFT (ic));
- if (isPair(AOP(IC_LEFT(ic)))) {
- _G.stack.pushed+=2;
- emitcode("push", "%s", getPairName(AOP(IC_LEFT(ic))));
- }
- else {
- if (size == 2) {
- fetchHL(AOP(IC_LEFT(ic)));
- emitcode("push", "hl");
- spillPair(PAIR_HL);
- _G.stack.pushed += 2;
- goto release;
- }
- if (size == 4) {
- fetchPairLong(PAIR_HL, AOP(IC_LEFT(ic)), 2);
- emitcode("push", "hl");
- spillPair(PAIR_HL);
- _G.stack.pushed += 2;
- fetchPairLong(PAIR_HL, AOP(IC_LEFT(ic)), 0);
- emitcode("push", "hl");
- spillPair(PAIR_HL);
+ if (isPair (AOP (IC_LEFT (ic))))
+ {
_G.stack.pushed += 2;
- goto release;
- }
- offset = size;
- while (size--) {
- if (AOP(IC_LEFT(ic))->type == AOP_IY) {
- char *l = aopGetLitWordLong(AOP(IC_LEFT(ic)), --offset, FALSE);
- wassert(l);
- emit2("ld a,(%s)", l);
- }
- else {
- l = aopGet(AOP(IC_LEFT(ic)), --offset, FALSE);
- emit2("ld a,%s", l);
- }
- emitcode("push", "af");
- emitcode("inc", "sp");
- _G.stack.pushed++;
- }
+ emitcode ("push", "%s", getPairName (AOP (IC_LEFT (ic))));
+ }
+ else
+ {
+ if (size == 2)
+ {
+ fetchHL (AOP (IC_LEFT (ic)));
+ emitcode ("push", "hl");
+ spillPair (PAIR_HL);
+ _G.stack.pushed += 2;
+ goto release;
+ }
+ if (size == 4)
+ {
+ fetchPairLong (PAIR_HL, AOP (IC_LEFT (ic)), 2);
+ emitcode ("push", "hl");
+ spillPair (PAIR_HL);
+ _G.stack.pushed += 2;
+ fetchPairLong (PAIR_HL, AOP (IC_LEFT (ic)), 0);
+ emitcode ("push", "hl");
+ spillPair (PAIR_HL);
+ _G.stack.pushed += 2;
+ goto release;
+ }
+ offset = size;
+ while (size--)
+ {
+ if (AOP (IC_LEFT (ic))->type == AOP_IY)
+ {
+ char *l = aopGetLitWordLong (AOP (IC_LEFT (ic)), --offset, FALSE);
+ wassert (l);
+ emit2 ("ld a,(%s)", l);
+ }
+ else
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), --offset, FALSE);
+ emit2 ("ld a,%s", l);
+ }
+ emitcode ("push", "af");
+ emitcode ("inc", "sp");
+ _G.stack.pushed++;
+ }
}
- release:
- freeAsmop(IC_LEFT(ic),NULL,ic);
+release:
+ freeAsmop (IC_LEFT (ic), NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genIpop - recover the registers: can happen only for spilling */
/*-----------------------------------------------------------------*/
-static void genIpop (iCode *ic)
+static void
+genIpop (iCode * ic)
{
- int size,offset ;
+ int size, offset;
- /* if the temp was not pushed then */
- if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
- return ;
+ /* if the temp was not pushed then */
+ if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
+ return;
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
- offset = (size-1);
- if (isPair(AOP(IC_LEFT(ic)))) {
- emitcode("pop", getPairName(AOP(IC_LEFT(ic))));
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
+ offset = (size - 1);
+ if (isPair (AOP (IC_LEFT (ic))))
+ {
+ emitcode ("pop", getPairName (AOP (IC_LEFT (ic))));
}
- else {
- while (size--) {
- emitcode("dec", "sp");
- emitcode("pop", "hl");
- spillPair(PAIR_HL);
- aopPut(AOP(IC_LEFT(ic)), "l", offset--);
- }
+ else
+ {
+ while (size--)
+ {
+ emitcode ("dec", "sp");
+ emitcode ("pop", "hl");
+ spillPair (PAIR_HL);
+ aopPut (AOP (IC_LEFT (ic)), "l", offset--);
+ }
}
- freeAsmop(IC_LEFT(ic),NULL,ic);
+ freeAsmop (IC_LEFT (ic), NULL, ic);
}
-static int _isPairUsed(iCode *ic, PAIR_ID pairId)
+static int
+_isPairUsed (iCode * ic, PAIR_ID pairId)
{
- int ret = 0;
- switch (pairId) {
+ int ret = 0;
+ switch (pairId)
+ {
case PAIR_DE:
- if (bitVectBitValue(ic->rUsed, D_IDX))
- ret++;
- if (bitVectBitValue(ic->rUsed, E_IDX))
- ret++;
- break;
+ if (bitVectBitValue (ic->rUsed, D_IDX))
+ ret++;
+ if (bitVectBitValue (ic->rUsed, E_IDX))
+ ret++;
+ break;
default:
- wassert(0);
+ wassert (0);
}
- return ret;
+ return ret;
}
-static int _opUsesPair(operand *op, iCode *ic, PAIR_ID pairId)
+static int
+_opUsesPair (operand * op, iCode * ic, PAIR_ID pairId)
{
- int ret = 0;
- asmop *aop;
- symbol *sym = OP_SYMBOL(op);
-
- if (sym->isspilt || sym->nRegs == 0)
- return 0;
+ int ret = 0;
+ asmop *aop;
+ symbol *sym = OP_SYMBOL (op);
- aopOp(op, ic, FALSE, FALSE);
+ if (sym->isspilt || sym->nRegs == 0)
+ return 0;
- aop = AOP(op);
- if (aop->type == AOP_REG) {
- int i;
- for (i=0; i < aop->size; i++) {
- if (pairId == PAIR_DE) {
- emit2("; name %s", aop->aopu.aop_reg[i]->name);
- if (!strcmp(aop->aopu.aop_reg[i]->name, "e"))
- ret++;
- if (!strcmp(aop->aopu.aop_reg[i]->name, "d"))
- ret++;
- }
- else {
- wassert(0);
- }
- }
- }
+ aopOp (op, ic, FALSE, FALSE);
- freeAsmop(IC_LEFT(ic),NULL,ic);
- return ret;
+ aop = AOP (op);
+ if (aop->type == AOP_REG)
+ {
+ int i;
+ for (i = 0; i < aop->size; i++)
+ {
+ if (pairId == PAIR_DE)
+ {
+ emit2 ("; name %s", aop->aopu.aop_reg[i]->name);
+ if (!strcmp (aop->aopu.aop_reg[i]->name, "e"))
+ ret++;
+ if (!strcmp (aop->aopu.aop_reg[i]->name, "d"))
+ ret++;
+ }
+ else
+ {
+ wassert (0);
+ }
+ }
+ }
+
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ return ret;
}
/* This is quite unfortunate */
-static void setArea(int inHome)
+static void
+setArea (int inHome)
{
- static int lastArea = 0;
-
- /*
- if (_G.in_home != inHome) {
- if (inHome) {
- const char *sz = port->mem.code_name;
- port->mem.code_name = "HOME";
- emit2("!area", CODE_NAME);
- port->mem.code_name = sz;
- }
- else
- emit2("!area", CODE_NAME);*/
+ static int lastArea = 0;
+
+ /*
+ if (_G.in_home != inHome) {
+ if (inHome) {
+ const char *sz = port->mem.code_name;
+ port->mem.code_name = "HOME";
+ emit2("!area", CODE_NAME);
+ port->mem.code_name = sz;
+ }
+ else
+ emit2("!area", CODE_NAME); */
_G.in_home = inHome;
// }
}
-static bool isInHome(void)
+static bool
+isInHome (void)
{
- return _G.in_home;
+ return _G.in_home;
}
/** Emit the code for a call statement
*/
-static void emitCall(iCode *ic, bool ispcall)
+static void
+emitCall (iCode * ic, bool ispcall)
{
- int pushed_de = 0;
- sym_link *detype = getSpec(operandType(IC_LEFT(ic)));
-
- /* if caller saves & we have not saved then */
- if (!ic->regsSaved) {
- /* PENDING */
- }
-
- /* if send set is not empty then assign */
- if (sendSet) {
- iCode *sic;
- int send = 0;
- int n = elementsInSet(sendSet);
- if (IS_Z80 && n == 2 && _isPairUsed(ic, PAIR_DE)) {
- /* Only push de if it is used and if it's not used
- in the return value */
- /* Panic if partly used */
- if (_opUsesPair(IC_RESULT(ic), ic, PAIR_DE) == 1) {
- emit2("; Warning: de crossover");
- }
- else if (!_opUsesPair(IC_RESULT(ic), ic, PAIR_DE)) {
- /* Store away de */
- _push(PAIR_DE);
- pushed_de = 1;
- }
- }
- /* PENDING: HACK */
- if (IS_Z80 && n == 2 ) {
- /* Want to load HL first, then DE as HL may = DE */
- sic = setFirstItem(sendSet);
- sic = setNextItem(sendSet);
- aopOp(IC_LEFT(sic),sic,FALSE, FALSE);
- fetchPair(PAIR_HL, AOP(IC_LEFT(sic)));
- send++;
- freeAsmop (IC_LEFT(sic),NULL,sic);
- sic = setFirstItem(sendSet);
- aopOp(IC_LEFT(sic),sic,FALSE, FALSE);
- fetchPair(PAIR_DE, AOP(IC_LEFT(sic)));
- send++;
- freeAsmop (IC_LEFT(sic),NULL,sic);
- }
- else {
- for (sic = setFirstItem(sendSet) ; sic ;
- sic = setNextItem(sendSet)) {
- int size;
- aopOp(IC_LEFT(sic),sic,FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(sic));
- wassert(size <= 2);
- /* Always send in pairs */
- switch (send) {
- case 0:
- if (IS_Z80 && n == 1)
- fetchPair(PAIR_HL, AOP(IC_LEFT(sic)));
- else
- fetchPair(PAIR_DE, AOP(IC_LEFT(sic)));
- break;
- case 1:
- fetchPair(PAIR_HL, AOP(IC_LEFT(sic)));
- break;
- default:
- /* Send set too big */
- wassert(0);
- }
- send++;
- freeAsmop (IC_LEFT(sic),NULL,sic);
- }
- }
- sendSet = NULL;
- if (pushed_de) {
- }
- }
-
- if (ispcall) {
- if (IS_BANKEDCALL(detype)) {
- werror(W_INDIR_BANKED);
- }
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
-
- if (isLitWord(AOP(IC_LEFT(ic)))) {
- emitcode("", "; Special case where the pCall is to a constant");
- emitcode("call", aopGetLitWordLong(AOP(IC_LEFT(ic)), 0, FALSE));
- }
- else {
- symbol *rlbl = newiTempLabel(NULL);
- spillPair(PAIR_HL);
- emit2("ld hl,!immed!tlabel", (rlbl->key+100));
- emitcode("push", "hl");
- _G.stack.pushed += 2;
+ int pushed_de = 0;
+ sym_link *detype = getSpec (operandType (IC_LEFT (ic)));
- fetchHL(AOP(IC_LEFT(ic)));
- emit2("jp !*hl");
- emit2("!tlabeldef", (rlbl->key+100));
- _G.stack.pushed -= 2;
- }
- freeAsmop(IC_LEFT(ic),NULL,ic);
- }
- else {
- char *name = OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
- OP_SYMBOL(IC_LEFT(ic))->rname :
- OP_SYMBOL(IC_LEFT(ic))->name;
- if (IS_BANKEDCALL(detype)) {
- emit2("call banked_call");
- emit2("!dws", name);
- emit2("!dw !bankimmeds", name);
- }
- else {
- /* make the call */
- emit2("call %s", name);
- }
+ /* if caller saves & we have not saved then */
+ if (!ic->regsSaved)
+ {
+ /* PENDING */
}
- spillCached();
- /* if we need assign a result value */
- if ((IS_ITEMP(IC_RESULT(ic)) &&
- (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
- OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
- IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+ /* if send set is not empty then assign */
+ if (sendSet)
+ {
+ iCode *sic;
+ int send = 0;
+ int n = elementsInSet (sendSet);
+ if (IS_Z80 && n == 2 && _isPairUsed (ic, PAIR_DE))
+ {
+ /* Only push de if it is used and if it's not used
+ in the return value */
+ /* Panic if partly used */
+ if (_opUsesPair (IC_RESULT (ic), ic, PAIR_DE) == 1)
+ {
+ emit2 ("; Warning: de crossover");
+ }
+ else if (!_opUsesPair (IC_RESULT (ic), ic, PAIR_DE))
+ {
+ /* Store away de */
+ _push (PAIR_DE);
+ pushed_de = 1;
+ }
+ }
+ /* PENDING: HACK */
+ if (IS_Z80 && n == 2)
+ {
+ /* Want to load HL first, then DE as HL may = DE */
+ sic = setFirstItem (sendSet);
+ sic = setNextItem (sendSet);
+ aopOp (IC_LEFT (sic), sic, FALSE, FALSE);
+ fetchPair (PAIR_HL, AOP (IC_LEFT (sic)));
+ send++;
+ freeAsmop (IC_LEFT (sic), NULL, sic);
+ sic = setFirstItem (sendSet);
+ aopOp (IC_LEFT (sic), sic, FALSE, FALSE);
+ fetchPair (PAIR_DE, AOP (IC_LEFT (sic)));
+ send++;
+ freeAsmop (IC_LEFT (sic), NULL, sic);
+ }
+ else
+ {
+ for (sic = setFirstItem (sendSet); sic;
+ sic = setNextItem (sendSet))
+ {
+ int size;
+ aopOp (IC_LEFT (sic), sic, FALSE, FALSE);
+ size = AOP_SIZE (IC_LEFT (sic));
+ wassert (size <= 2);
+ /* Always send in pairs */
+ switch (send)
+ {
+ case 0:
+ if (IS_Z80 && n == 1)
+ fetchPair (PAIR_HL, AOP (IC_LEFT (sic)));
+ else
+ fetchPair (PAIR_DE, AOP (IC_LEFT (sic)));
+ break;
+ case 1:
+ fetchPair (PAIR_HL, AOP (IC_LEFT (sic)));
+ break;
+ default:
+ /* Send set too big */
+ wassert (0);
+ }
+ send++;
+ freeAsmop (IC_LEFT (sic), NULL, sic);
+ }
+ }
+ sendSet = NULL;
+ if (pushed_de)
+ {
+ }
+ }
+
+ if (ispcall)
+ {
+ if (IS_BANKEDCALL (detype))
+ {
+ werror (W_INDIR_BANKED);
+ }
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+
+ if (isLitWord (AOP (IC_LEFT (ic))))
+ {
+ emitcode ("", "; Special case where the pCall is to a constant");
+ emitcode ("call", aopGetLitWordLong (AOP (IC_LEFT (ic)), 0, FALSE));
+ }
+ else
+ {
+ symbol *rlbl = newiTempLabel (NULL);
+ spillPair (PAIR_HL);
+ emit2 ("ld hl,!immed!tlabel", (rlbl->key + 100));
+ emitcode ("push", "hl");
+ _G.stack.pushed += 2;
+
+ fetchHL (AOP (IC_LEFT (ic)));
+ emit2 ("jp !*hl");
+ emit2 ("!tlabeldef", (rlbl->key + 100));
+ _G.stack.pushed -= 2;
+ }
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ }
+ else
+ {
+ char *name = OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
+ OP_SYMBOL (IC_LEFT (ic))->rname :
+ OP_SYMBOL (IC_LEFT (ic))->name;
+ if (IS_BANKEDCALL (detype))
+ {
+ emit2 ("call banked_call");
+ emit2 ("!dws", name);
+ emit2 ("!dw !bankimmeds", name);
+ }
+ else
+ {
+ /* make the call */
+ emit2 ("call %s", name);
+ }
+ }
+ spillCached ();
+
+ /* if we need assign a result value */
+ if ((IS_ITEMP (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
+ OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ {
- accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
- accInUse--;
+ accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+ accInUse--;
- assignResultValue(IC_RESULT(ic));
+ assignResultValue (IC_RESULT (ic));
- freeAsmop(IC_RESULT(ic),NULL, ic);
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
- /* adjust the stack for parameters if required */
- if (IC_LEFT(ic)->parmBytes) {
- int i = IC_LEFT(ic)->parmBytes;
- _G.stack.pushed -= i;
- if (IS_GB) {
- emit2("!ldaspsp", i);
- }
- else {
- spillCached();
- if (i>6) {
- emitcode("ld", "hl,#%d", i);
- emitcode("add", "hl,sp");
- emitcode("ld", "sp,hl");
- }
- else {
- while (i>1) {
- emitcode("pop", "hl");
- i-=2;
- }
- if (i)
- emitcode("inc", "sp");
- }
- spillCached();
- }
- }
- if (pushed_de)
- _pop(PAIR_DE);
+ /* adjust the stack for parameters if required */
+ if (IC_LEFT (ic)->parmBytes)
+ {
+ int i = IC_LEFT (ic)->parmBytes;
+ _G.stack.pushed -= i;
+ if (IS_GB)
+ {
+ emit2 ("!ldaspsp", i);
+ }
+ else
+ {
+ spillCached ();
+ if (i > 6)
+ {
+ emitcode ("ld", "hl,#%d", i);
+ emitcode ("add", "hl,sp");
+ emitcode ("ld", "sp,hl");
+ }
+ else
+ {
+ while (i > 1)
+ {
+ emitcode ("pop", "hl");
+ i -= 2;
+ }
+ if (i)
+ emitcode ("inc", "sp");
+ }
+ spillCached ();
+ }
+ }
+ if (pushed_de)
+ _pop (PAIR_DE);
}
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
-static void genCall (iCode *ic)
+static void
+genCall (iCode * ic)
{
- sym_link *detype = getSpec(operandType(IC_LEFT(ic)));
- emitCall(ic, FALSE);
+ sym_link *detype = getSpec (operandType (IC_LEFT (ic)));
+ emitCall (ic, FALSE);
}
/*-----------------------------------------------------------------*/
/* genPcall - generates a call by pointer statement */
/*-----------------------------------------------------------------*/
-static void genPcall (iCode *ic)
+static void
+genPcall (iCode * ic)
{
- emitCall(ic, TRUE);
+ emitCall (ic, TRUE);
}
/*-----------------------------------------------------------------*/
/* resultRemat - result is rematerializable */
/*-----------------------------------------------------------------*/
-static int resultRemat (iCode *ic)
+static int
+resultRemat (iCode * ic)
{
- if (SKIP_IC(ic) || ic->op == IFX)
- return 0;
+ if (SKIP_IC (ic) || ic->op == IFX)
+ return 0;
- if (IC_RESULT(ic) && IS_ITEMP(IC_RESULT(ic))) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- if (sym->remat && !POINTER_SET(ic))
- return 1;
+ if (IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic)))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ if (sym->remat && !POINTER_SET (ic))
+ return 1;
}
- return 0;
+ return 0;
}
extern set *publics;
/*-----------------------------------------------------------------*/
/* genFunction - generated code for function entry */
/*-----------------------------------------------------------------*/
-static void genFunction (iCode *ic)
+static void
+genFunction (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
- sym_link *fetype;
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+ sym_link *fetype;
- nregssaved = 0;
- setArea(IS_NONBANKED(sym->etype));
+ nregssaved = 0;
+ setArea (IS_NONBANKED (sym->etype));
- /* PENDING: hack */
- if (!IS_STATIC(sym->etype)) {
- addSetIfnotP(&publics, sym);
+ /* PENDING: hack */
+ if (!IS_STATIC (sym->etype))
+ {
+ addSetIfnotP (&publics, sym);
}
- /* create the function header */
- emit2("!functionheader", sym->name);
- /* PENDING: portability. */
- emit2("__%s_start:", sym->rname);
- emit2("!functionlabeldef", sym->rname);
-
- fetype = getSpec(operandType(IC_LEFT(ic)));
+ /* create the function header */
+ emit2 ("!functionheader", sym->name);
+ /* PENDING: portability. */
+ emit2 ("__%s_start:", sym->rname);
+ emit2 ("!functionlabeldef", sym->rname);
- /* if critical function then turn interrupts off */
- if (SPEC_CRTCL(fetype))
- emit2("!di");
+ fetype = getSpec (operandType (IC_LEFT (ic)));
- /* if this is an interrupt service routine then
- save acc, b, dpl, dph */
- if (IS_ISR(sym->etype)) {
- emit2("!pusha");
- }
- /* PENDING: callee-save etc */
+ /* if critical function then turn interrupts off */
+ if (SPEC_CRTCL (fetype))
+ emit2 ("!di");
- /* If BC or DE are used, then push */
- _G.stack.pushed_bc = 0;
- _G.stack.pushed_de = 0;
- _G.stack.param_offset = 0;
- if (sym->regsUsed) {
- int i;
- for ( i = 0 ; i < sym->regsUsed->size ; i++) {
- if (bitVectBitValue(sym->regsUsed, i)) {
- switch (i) {
- case C_IDX:
- case B_IDX:
- _G.stack.pushed_bc = 1;
- break;
- case D_IDX:
- case E_IDX:
- if (IS_Z80)
- _G.stack.pushed_de = 1;
- break;
- }
- }
- }
- if (_G.stack.pushed_bc) {
- emit2("push bc");
- _G.stack.param_offset += 2;
- }
- if (_G.stack.pushed_de) {
- emit2("push de");
- _G.stack.param_offset += 2;
- }
+ /* if this is an interrupt service routine then
+ save acc, b, dpl, dph */
+ if (IS_ISR (sym->etype))
+ {
+ emit2 ("!pusha");
}
+ /* PENDING: callee-save etc */
- /* adjust the stack for the function */
- _G.stack.last = sym->stack;
-
- if (sym->stack)
- emit2("!enterx", sym->stack);
- else
- emit2("!enter");
- _G.stack.offset = sym->stack;
+ /* If BC or DE are used, then push */
+ _G.stack.pushed_bc = 0;
+ _G.stack.pushed_de = 0;
+ _G.stack.param_offset = 0;
+ if (sym->regsUsed)
+ {
+ int i;
+ for (i = 0; i < sym->regsUsed->size; i++)
+ {
+ if (bitVectBitValue (sym->regsUsed, i))
+ {
+ switch (i)
+ {
+ case C_IDX:
+ case B_IDX:
+ _G.stack.pushed_bc = 1;
+ break;
+ case D_IDX:
+ case E_IDX:
+ if (IS_Z80)
+ _G.stack.pushed_de = 1;
+ break;
+ }
+ }
+ }
+ if (_G.stack.pushed_bc)
+ {
+ emit2 ("push bc");
+ _G.stack.param_offset += 2;
+ }
+ if (_G.stack.pushed_de)
+ {
+ emit2 ("push de");
+ _G.stack.param_offset += 2;
+ }
+ }
+
+ /* adjust the stack for the function */
+ _G.stack.last = sym->stack;
+
+ if (sym->stack)
+ emit2 ("!enterx", sym->stack);
+ else
+ emit2 ("!enter");
+ _G.stack.offset = sym->stack;
}
/*-----------------------------------------------------------------*/
/* genEndFunction - generates epilogue for functions */
/*-----------------------------------------------------------------*/
-static void genEndFunction (iCode *ic)
+static void
+genEndFunction (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
- if (IS_ISR(sym->etype)) {
- wassert(0);
+ if (IS_ISR (sym->etype))
+ {
+ wassert (0);
}
- else {
- if (SPEC_CRTCL(sym->etype))
- emit2("!ei");
-
- /* PENDING: calleeSave */
-
- /* if debug then send end of function */
- if (options.debug && currFunc) {
- debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),currFunc->lastLine,
- ic->level,ic->block);
- if (IS_STATIC(currFunc->etype))
- emitcode("","XF%s$%s$0$0 ==.",moduleName,currFunc->name);
- else
- emitcode("","XG$%s$0$0 ==.",currFunc->name);
- debugLine = 0;
- }
- if (_G.stack.offset)
- emit2("!leavex", _G.stack.offset);
else
- emit2("!leave");
+ {
+ if (SPEC_CRTCL (sym->etype))
+ emit2 ("!ei");
+
+ /* PENDING: calleeSave */
+
+ /* if debug then send end of function */
+ if (options.debug && currFunc)
+ {
+ debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), currFunc->lastLine,
+ ic->level, ic->block);
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode ("", "XG$%s$0$0 ==.", currFunc->name);
+ debugLine = 0;
+ }
+ if (_G.stack.offset)
+ emit2 ("!leavex", _G.stack.offset);
+ else
+ emit2 ("!leave");
- if (_G.stack.pushed_de)
- emit2("pop de");
- if (_G.stack.pushed_bc)
- emit2("pop bc");
- /* Both baned and non-banked just ret */
- emit2("ret");
+ if (_G.stack.pushed_de)
+ emit2 ("pop de");
+ if (_G.stack.pushed_bc)
+ emit2 ("pop bc");
+ /* Both baned and non-banked just ret */
+ emit2 ("ret");
- /* PENDING: portability. */
- emit2("__%s_end:", sym->rname);
+ /* PENDING: portability. */
+ emit2 ("__%s_end:", sym->rname);
}
- _G.flush_statics = 1;
- _G.stack.pushed = 0;
- _G.stack.offset = 0;
+ _G.flush_statics = 1;
+ _G.stack.pushed = 0;
+ _G.stack.offset = 0;
}
/*-----------------------------------------------------------------*/
/* genRet - generate code for return statement */
/*-----------------------------------------------------------------*/
-static void genRet (iCode *ic)
+static void
+genRet (iCode * ic)
{
- char *l;
- /* Errk. This is a hack until I can figure out how
- to cause dehl to spill on a call */
- int size,offset = 0;
-
- /* if we have no return value then
- just generate the "ret" */
- if (!IC_LEFT(ic))
- goto jumpret;
-
- /* we have something to return then
- move the return value into place */
- aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
- size = AOP_SIZE(IC_LEFT(ic));
-
- if ((size == 2) && ((l = aopGetWord(AOP(IC_LEFT(ic)), 0)))) {
- if (IS_GB) {
- emitcode("ld", "de,%s", l);
- }
- else {
- emitcode("ld", "hl,%s", l);
- }
- }
- else {
- if (IS_GB && size == 4 && requiresHL(AOP(IC_LEFT(ic)))) {
- fetchPair(PAIR_DE, AOP(IC_LEFT(ic)));
- fetchPairLong(PAIR_HL, AOP(IC_LEFT(ic)), 2);
- }
- else {
- while (size--) {
- l = aopGet(AOP(IC_LEFT(ic)),offset,
- FALSE);
- if (strcmp(_fReturn[offset],l))
- emitcode("ld","%s,%s", _fReturn[offset++],l);
- }
- }
- }
- freeAsmop (IC_LEFT(ic),NULL,ic);
+ char *l;
+ /* Errk. This is a hack until I can figure out how
+ to cause dehl to spill on a call */
+ int size, offset = 0;
+
+ /* if we have no return value then
+ just generate the "ret" */
+ if (!IC_LEFT (ic))
+ goto jumpret;
+
+ /* we have something to return then
+ move the return value into place */
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ size = AOP_SIZE (IC_LEFT (ic));
- jumpret:
+ if ((size == 2) && ((l = aopGetWord (AOP (IC_LEFT (ic)), 0))))
+ {
+ if (IS_GB)
+ {
+ emitcode ("ld", "de,%s", l);
+ }
+ else
+ {
+ emitcode ("ld", "hl,%s", l);
+ }
+ }
+ else
+ {
+ if (IS_GB && size == 4 && requiresHL (AOP (IC_LEFT (ic))))
+ {
+ fetchPair (PAIR_DE, AOP (IC_LEFT (ic)));
+ fetchPairLong (PAIR_HL, AOP (IC_LEFT (ic)), 2);
+ }
+ else
+ {
+ while (size--)
+ {
+ l = aopGet (AOP (IC_LEFT (ic)), offset,
+ FALSE);
+ if (strcmp (_fReturn[offset], l))
+ emitcode ("ld", "%s,%s", _fReturn[offset++], l);
+ }
+ }
+ }
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+
+jumpret:
/* generate a jump to the return label
if the next is not the return statement */
- if (!(ic->next && ic->next->op == LABEL &&
- IC_LABEL(ic->next) == returnLabel))
+ if (!(ic->next && ic->next->op == LABEL &&
+ IC_LABEL (ic->next) == returnLabel))
- emit2("jp !tlabel", returnLabel->key+100);
+ emit2 ("jp !tlabel", returnLabel->key + 100);
}
/*-----------------------------------------------------------------*/
/* genLabel - generates a label */
/*-----------------------------------------------------------------*/
-static void genLabel (iCode *ic)
+static void
+genLabel (iCode * ic)
{
- /* special case never generate */
- if (IC_LABEL(ic) == entryLabel)
- return ;
+ /* special case never generate */
+ if (IC_LABEL (ic) == entryLabel)
+ return;
- emitLabel(IC_LABEL(ic)->key+100);
+ emitLabel (IC_LABEL (ic)->key + 100);
}
/*-----------------------------------------------------------------*/
/* genGoto - generates a ljmp */
/*-----------------------------------------------------------------*/
-static void genGoto (iCode *ic)
+static void
+genGoto (iCode * ic)
{
- emit2("jp !tlabel", IC_LABEL(ic)->key+100);
+ emit2 ("jp !tlabel", IC_LABEL (ic)->key + 100);
}
/*-----------------------------------------------------------------*/
/* genPlusIncr :- does addition with increment if possible */
/*-----------------------------------------------------------------*/
-static bool genPlusIncr (iCode *ic)
+static bool
+genPlusIncr (iCode * ic)
{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
- PAIR_ID resultId = getPairId(AOP(IC_RESULT(ic)));
-
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE;
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
+ PAIR_ID resultId = getPairId (AOP (IC_RESULT (ic)));
+
+ /* will try to generate an increment */
+ /* if the right side is not a literal
+ we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
- emitcode("", "; genPlusIncr");
+ emitcode ("", "; genPlusIncr");
- icount = floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
+ icount = floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
- /* If result is a pair */
- if (resultId != PAIR_INVALID) {
- if (isLitWord(AOP(IC_LEFT(ic)))) {
- fetchLitPair(getPairId(AOP(IC_RESULT(ic))), AOP(IC_LEFT(ic)), icount);
- return TRUE;
- }
- if (isPair(AOP(IC_LEFT(ic))) && resultId == PAIR_HL && icount > 2) {
- fetchPair(resultId, AOP(IC_RIGHT(ic)));
- emitcode("add", "hl,%s", getPairName(AOP(IC_LEFT(ic))));
+ /* If result is a pair */
+ if (resultId != PAIR_INVALID)
+ {
+ if (isLitWord (AOP (IC_LEFT (ic))))
+ {
+ fetchLitPair (getPairId (AOP (IC_RESULT (ic))), AOP (IC_LEFT (ic)), icount);
+ return TRUE;
+ }
+ if (isPair (AOP (IC_LEFT (ic))) && resultId == PAIR_HL && icount > 2)
+ {
+ fetchPair (resultId, AOP (IC_RIGHT (ic)));
+ emitcode ("add", "hl,%s", getPairName (AOP (IC_LEFT (ic))));
+ return TRUE;
+ }
+ if (icount > 5)
+ return FALSE;
+ /* Inc a pair */
+ if (!sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
+ if (icount > 2)
+ return FALSE;
+ movLeft2Result (IC_LEFT (ic), 0, IC_RESULT (ic), 0, 0);
+ movLeft2Result (IC_LEFT (ic), 1, IC_RESULT (ic), 1, 0);
+ }
+ while (icount--)
+ {
+ emitcode ("inc", "%s", getPairName (AOP (IC_RESULT (ic))));
+ }
return TRUE;
- }
- if (icount > 5)
- return FALSE;
- /* Inc a pair */
- if (!sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
- if (icount > 2)
- return FALSE;
- movLeft2Result(IC_LEFT(ic), 0, IC_RESULT(ic), 0, 0);
- movLeft2Result(IC_LEFT(ic), 1, IC_RESULT(ic), 1, 0);
- }
- while (icount--) {
- emitcode("inc", "%s", getPairName(AOP(IC_RESULT(ic))));
- }
- return TRUE;
}
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if (icount > 4)
- return FALSE;
+ /* if the literal value of the right hand side
+ is greater than 4 then it is not worth it */
+ if (icount > 4)
+ return FALSE;
- /* if increment 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- size > 1 &&
- icount == 1
- ) {
- int offset = 0;
- symbol *tlbl = NULL;
- tlbl = newiTempLabel(NULL);
- while (size--) {
- emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)), offset++, FALSE));
- if (size) {
- emit2("!shortjp nz,!tlabel", tlbl->key+100);
- }
- }
- emitLabel(tlbl->key+100);
- return TRUE;
+ /* if increment 16 bits in register */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ size > 1 &&
+ icount == 1
+ )
+ {
+ int offset = 0;
+ symbol *tlbl = NULL;
+ tlbl = newiTempLabel (NULL);
+ while (size--)
+ {
+ emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), offset++, FALSE));
+ if (size)
+ {
+ emit2 ("!shortjp nz,!tlabel", tlbl->key + 100);
+ }
+ }
+ emitLabel (tlbl->key + 100);
+ return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* we can if the aops of the left & result match or
- if they are in registers and the registers are the
- same */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
- while (icount--)
- emitcode ("inc","%s",aopGet(AOP(IC_LEFT(ic)),0, FALSE));
- return TRUE ;
+ /* we can if the aops of the left & result match or
+ if they are in registers and the registers are the
+ same */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
+ while (icount--)
+ emitcode ("inc", "%s", aopGet (AOP (IC_LEFT (ic)), 0, FALSE));
+ return TRUE;
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* outBitAcc - output a bit in acc */
/*-----------------------------------------------------------------*/
-void outBitAcc(operand *result)
+void
+outBitAcc (operand * result)
{
- symbol *tlbl = newiTempLabel(NULL);
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY){
- wassert(0);
+ symbol *tlbl = newiTempLabel (NULL);
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ wassert (0);
}
- else {
- emit2("!shortjp z,!tlabel", tlbl->key+100);
- emit2("ld a,!one");
- emitLabel(tlbl->key+100);
- outAcc(result);
+ else
+ {
+ emit2 ("!shortjp z,!tlabel", tlbl->key + 100);
+ emit2 ("ld a,!one");
+ emitLabel (tlbl->key + 100);
+ outAcc (result);
}
}
/*-----------------------------------------------------------------*/
/* genPlus - generates code for addition */
/*-----------------------------------------------------------------*/
-static void genPlus (iCode *ic)
+static void
+genPlus (iCode * ic)
{
- int size, offset = 0;
+ int size, offset = 0;
- /* special cases :- */
+ /* special cases :- */
- aopOp (IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
- /* Swap the left and right operands if:
+ /* Swap the left and right operands if:
- if literal, literal on the right or
- if left requires ACC or right is already
- in ACC */
+ if literal, literal on the right or
+ if left requires ACC or right is already
+ in ACC */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (AOP_NEEDSACC(IC_LEFT(ic))) ||
- AOP_TYPE(IC_RIGHT(ic)) == AOP_ACC ){
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
+ if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT) ||
+ (AOP_NEEDSACC (IC_LEFT (ic))) ||
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_ACC)
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
}
- /* if both left & right are in bit
- space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- /* Cant happen */
- wassert(0);
+ /* if both left & right are in bit
+ space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ /* Cant happen */
+ wassert (0);
}
- /* if left in bit space & right literal */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
- /* Can happen I guess */
- wassert(0);
+ /* if left in bit space & right literal */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT)
+ {
+ /* Can happen I guess */
+ wassert (0);
}
- /* if I can do an increment instead
- of add then GOOD for ME */
- if (genPlusIncr (ic) == TRUE)
- goto release;
-
- emit2("; genPlusIncr failed");
+ /* if I can do an increment instead
+ of add then GOOD for ME */
+ if (genPlusIncr (ic) == TRUE)
+ goto release;
- size = getDataSize(IC_RESULT(ic));
+ emit2 ("; genPlusIncr failed");
- /* Special case when left and right are constant */
- if (isPair(AOP(IC_RESULT(ic)))) {
- char *left, *right;
+ size = getDataSize (IC_RESULT (ic));
- left = aopGetLitWordLong(AOP(IC_LEFT(ic)), 0, FALSE);
- right = aopGetLitWordLong(AOP(IC_RIGHT(ic)), 0, FALSE);
- if (left && right) {
- /* It's a pair */
- /* PENDING: fix */
- char buffer[100];
- sprintf(buffer, "#(%s + %s)", left, right);
- emitcode("ld", "%s,%s", getPairName(AOP(IC_RESULT(ic))), buffer);
+ /* Special case when left and right are constant */
+ if (isPair (AOP (IC_RESULT (ic))))
+ {
+ char *left, *right;
+
+ left = aopGetLitWordLong (AOP (IC_LEFT (ic)), 0, FALSE);
+ right = aopGetLitWordLong (AOP (IC_RIGHT (ic)), 0, FALSE);
+ if (left && right)
+ {
+ /* It's a pair */
+ /* PENDING: fix */
+ char buffer[100];
+ sprintf (buffer, "#(%s + %s)", left, right);
+ emitcode ("ld", "%s,%s", getPairName (AOP (IC_RESULT (ic))), buffer);
+ goto release;
+ }
+ }
+
+ if (isPair (AOP (IC_RIGHT (ic))) && getPairId (AOP (IC_RESULT (ic))) == PAIR_HL)
+ {
+ /* Fetch into HL then do the add */
+ spillPair (PAIR_HL);
+ fetchPair (PAIR_HL, AOP (IC_LEFT (ic)));
+ emitcode ("add", "hl,%s", getPairName (AOP (IC_RIGHT (ic))));
goto release;
- }
}
- if (isPair(AOP(IC_RIGHT(ic))) && getPairId(AOP(IC_RESULT(ic))) == PAIR_HL) {
- /* Fetch into HL then do the add */
- spillPair(PAIR_HL);
- fetchPair(PAIR_HL, AOP(IC_LEFT(ic)));
- emitcode("add", "hl,%s", getPairName(AOP(IC_RIGHT(ic))));
- goto release;
- }
-
- /* Special case:
- ld hl,sp+n trashes C so we cant afford to do it during an
- add with stack based varibles. Worst case is:
- ld hl,sp+left
- ld a,(hl)
- ld hl,sp+right
- add (hl)
- ld hl,sp+result
- ld (hl),a
- ld hl,sp+left+1
- ld a,(hl)
- ld hl,sp+right+1
- adc (hl)
- ld hl,sp+result+1
- ld (hl),a
- So you cant afford to load up hl if either left, right, or result
- is on the stack (*sigh*) The alt is:
- ld hl,sp+left
- ld de,(hl)
- ld hl,sp+right
- ld hl,(hl)
- add hl,de
- ld hl,sp+result
- ld (hl),hl
- Combinations in here are:
- * If left or right are in bc then the loss is small - trap later
- * If the result is in bc then the loss is also small
- */
- if (IS_GB) {
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_STK ||
- AOP_TYPE(IC_RIGHT(ic)) == AOP_STK ||
- AOP_TYPE(IC_RESULT(ic)) == AOP_STK) {
- if ((AOP_SIZE(IC_LEFT(ic)) == 2 ||
- AOP_SIZE(IC_RIGHT(ic)) == 2) &&
- (AOP_SIZE(IC_LEFT(ic)) <= 2 &&
- AOP_SIZE(IC_RIGHT(ic)) <= 2)) {
- if (getPairId(AOP(IC_RIGHT(ic))) == PAIR_BC) {
- /* Swap left and right */
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
- }
- if (getPairId(AOP(IC_LEFT(ic))) == PAIR_BC) {
- fetchPair(PAIR_HL, AOP(IC_RIGHT(ic)));
- emit2("add hl,bc");
- }
- else {
- fetchPair(PAIR_DE, AOP(IC_LEFT(ic)));
- fetchPair(PAIR_HL, AOP(IC_RIGHT(ic)));
- emit2("add hl,de");
- }
- commitPair(AOP(IC_RESULT(ic)), PAIR_HL);
- goto release;
- }
- else if (size == 4) {
- emit2("; WARNING: This add is probably broken.\n");
- }
- }
+ /* Special case:
+ ld hl,sp+n trashes C so we cant afford to do it during an
+ add with stack based varibles. Worst case is:
+ ld hl,sp+left
+ ld a,(hl)
+ ld hl,sp+right
+ add (hl)
+ ld hl,sp+result
+ ld (hl),a
+ ld hl,sp+left+1
+ ld a,(hl)
+ ld hl,sp+right+1
+ adc (hl)
+ ld hl,sp+result+1
+ ld (hl),a
+ So you cant afford to load up hl if either left, right, or result
+ is on the stack (*sigh*) The alt is:
+ ld hl,sp+left
+ ld de,(hl)
+ ld hl,sp+right
+ ld hl,(hl)
+ add hl,de
+ ld hl,sp+result
+ ld (hl),hl
+ Combinations in here are:
+ * If left or right are in bc then the loss is small - trap later
+ * If the result is in bc then the loss is also small
+ */
+ if (IS_GB)
+ {
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_STK ||
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_STK ||
+ AOP_TYPE (IC_RESULT (ic)) == AOP_STK)
+ {
+ if ((AOP_SIZE (IC_LEFT (ic)) == 2 ||
+ AOP_SIZE (IC_RIGHT (ic)) == 2) &&
+ (AOP_SIZE (IC_LEFT (ic)) <= 2 &&
+ AOP_SIZE (IC_RIGHT (ic)) <= 2))
+ {
+ if (getPairId (AOP (IC_RIGHT (ic))) == PAIR_BC)
+ {
+ /* Swap left and right */
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
+ }
+ if (getPairId (AOP (IC_LEFT (ic))) == PAIR_BC)
+ {
+ fetchPair (PAIR_HL, AOP (IC_RIGHT (ic)));
+ emit2 ("add hl,bc");
+ }
+ else
+ {
+ fetchPair (PAIR_DE, AOP (IC_LEFT (ic)));
+ fetchPair (PAIR_HL, AOP (IC_RIGHT (ic)));
+ emit2 ("add hl,de");
+ }
+ commitPair (AOP (IC_RESULT (ic)), PAIR_HL);
+ goto release;
+ }
+ else if (size == 4)
+ {
+ emit2 ("; WARNING: This add is probably broken.\n");
+ }
+ }
}
- while(size--) {
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
- MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE));
- if(offset == 0)
- emit2("add a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE));
- else
- emit2("adc a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE));
- } else {
- MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE));
- if(offset == 0)
- emit2("add a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE));
+ while (size--)
+ {
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE));
+ if (offset == 0)
+ emit2 ("add a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE));
+ else
+ emit2 ("adc a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE));
+ }
else
- emit2("adc a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE));
- }
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE));
+ if (offset == 0)
+ emit2 ("add a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE));
+ else
+ emit2 ("adc a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE));
+ }
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
release:
- freeAsmop(IC_LEFT(ic),NULL,ic);
- freeAsmop(IC_RIGHT(ic),NULL,ic);
- freeAsmop(IC_RESULT(ic),NULL,ic);
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ freeAsmop (IC_RIGHT (ic), NULL, ic);
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genMinusDec :- does subtraction with deccrement if possible */
/*-----------------------------------------------------------------*/
-static bool genMinusDec (iCode *ic)
+static bool
+genMinusDec (iCode * ic)
{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
+ unsigned int icount;
+ unsigned int size = getDataSize (IC_RESULT (ic));
- /* will try to generate an increment */
- /* if the right side is not a literal we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
+ /* will try to generate an increment */
+ /* if the right side is not a literal we cannot */
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ return FALSE;
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
- return FALSE;
+ /* if the literal value of the right hand side
+ is greater than 4 then it is not worth it */
+ if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 2)
+ return FALSE;
- size = getDataSize(IC_RESULT(ic));
+ size = getDataSize (IC_RESULT (ic));
#if 0
- /* if increment 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) &&
- (icount == 1)) {
- symbol *tlbl = newiTempLabel(NULL);
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE));
- emitcode("jp", "np," LABEL_STR ,tlbl->key+100);
-
- emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE));
- if(size == 4) {
- wassert(0);
- }
- emitLabel(tlbl->key+100);
- return TRUE;
+ /* if increment 16 bits in register */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (size > 1) &&
+ (icount == 1))
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE));
+ emitcode ("jp", "np," LABEL_STR, tlbl->key + 100);
+
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE));
+ if (size == 4)
+ {
+ wassert (0);
+ }
+ emitLabel (tlbl->key + 100);
+ return TRUE;
}
#endif
- /* if decrement 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) && isPair(AOP(IC_RESULT(ic)))) {
- while (icount--)
- emitcode("dec", "%s", getPairName(AOP(IC_RESULT(ic))));
- return TRUE;
+ /* if decrement 16 bits in register */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
+ (size > 1) && isPair (AOP (IC_RESULT (ic))))
+ {
+ while (icount--)
+ emitcode ("dec", "%s", getPairName (AOP (IC_RESULT (ic))));
+ return TRUE;
}
- /* If result is a pair */
- if (isPair(AOP(IC_RESULT(ic)))) {
- movLeft2Result(IC_LEFT(ic), 0, IC_RESULT(ic), 0, 0);
- movLeft2Result(IC_LEFT(ic), 1, IC_RESULT(ic), 1, 0);
- while (icount--)
- emitcode("dec", "%s", getPairName(AOP(IC_RESULT(ic))));
- return TRUE;
+ /* If result is a pair */
+ if (isPair (AOP (IC_RESULT (ic))))
+ {
+ movLeft2Result (IC_LEFT (ic), 0, IC_RESULT (ic), 0, 0);
+ movLeft2Result (IC_LEFT (ic), 1, IC_RESULT (ic), 1, 0);
+ while (icount--)
+ emitcode ("dec", "%s", getPairName (AOP (IC_RESULT (ic))));
+ return TRUE;
}
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
+ /* if the sizes are greater than 1 then we cannot */
+ if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
+ AOP_SIZE (IC_LEFT (ic)) > 1)
+ return FALSE;
- /* we can if the aops of the left & result match or if they are in
- registers and the registers are the same */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
- while (icount--)
- emitcode ("dec","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE));
- return TRUE ;
+ /* we can if the aops of the left & result match or if they are in
+ registers and the registers are the same */
+ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))))
+ {
+ while (icount--)
+ emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE));
+ return TRUE;
}
- return FALSE ;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* genMinus - generates code for subtraction */
/*-----------------------------------------------------------------*/
-static void genMinus (iCode *ic)
+static void
+genMinus (iCode * ic)
{
- int size, offset = 0;
- unsigned long lit = 0L;
-
- aopOp (IC_LEFT(ic),ic,FALSE, FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
-
- /* special cases :- */
- /* if both left & right are in bit space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- wassert(0);
- goto release ;
- }
-
- /* if I can do an decrement instead of subtract then GOOD for ME */
- if (genMinusDec (ic) == TRUE)
- goto release;
-
- size = getDataSize(IC_RESULT(ic));
-
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT){
- }
- else{
- lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- lit = - (long)lit;
- }
-
- /* Same logic as genPlus */
- if (IS_GB) {
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_STK ||
- AOP_TYPE(IC_RIGHT(ic)) == AOP_STK ||
- AOP_TYPE(IC_RESULT(ic)) == AOP_STK) {
- if ((AOP_SIZE(IC_LEFT(ic)) == 2 ||
- AOP_SIZE(IC_RIGHT(ic)) == 2) &&
- (AOP_SIZE(IC_LEFT(ic)) <= 2 &&
- AOP_SIZE(IC_RIGHT(ic)) <= 2)) {
- PAIR_ID left = getPairId(AOP(IC_LEFT(ic)));
- PAIR_ID right = getPairId(AOP(IC_RIGHT(ic)));
-
- if (left == PAIR_INVALID && right == PAIR_INVALID) {
- left = PAIR_DE;
- right = PAIR_HL;
- }
- else if (right == PAIR_INVALID)
- right = PAIR_DE;
- else if (left == PAIR_INVALID)
- left = PAIR_DE;
-
- fetchPair(left, AOP(IC_LEFT(ic)));
- /* Order is important. Right may be HL */
- fetchPair(right, AOP(IC_RIGHT(ic)));
-
- emit2("ld a,%s", _pairs[left].l);
- emit2("sub a,%s", _pairs[right].l);
- emit2("ld e,a");
- emit2("ld a,%s", _pairs[left].h);
- emit2("sbc a,%s", _pairs[right].h);
-
- aopPut(AOP(IC_RESULT(ic)), "a", 1);
- aopPut(AOP(IC_RESULT(ic)), "e", 0);
+ int size, offset = 0;
+ unsigned long lit = 0L;
+
+ aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RIGHT (ic), ic, FALSE, FALSE);
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
+
+ /* special cases :- */
+ /* if both left & right are in bit space */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY &&
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ wassert (0);
+ goto release;
+ }
+
+ /* if I can do an decrement instead of subtract then GOOD for ME */
+ if (genMinusDec (ic) == TRUE)
goto release;
- }
- else if (size == 4) {
- emit2("; WARNING: This sub is probably broken.\n");
- }
- }
+
+ size = getDataSize (IC_RESULT (ic));
+
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ {
+ }
+ else
+ {
+ lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+ lit = -(long) lit;
}
- /* if literal, add a,#-lit, else normal subb */
- while (size--) {
- MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE));
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT) {
- if (!offset)
- emitcode("sub","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE));
- else
- emitcode("sbc","a,%s",
- aopGet(AOP(IC_RIGHT(ic)),offset,FALSE));
- }
- else{
- /* first add without previous c */
- if (!offset)
- emit2("add a,!immedbyte", (unsigned int)(lit & 0x0FFL));
+ /* Same logic as genPlus */
+ if (IS_GB)
+ {
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_STK ||
+ AOP_TYPE (IC_RIGHT (ic)) == AOP_STK ||
+ AOP_TYPE (IC_RESULT (ic)) == AOP_STK)
+ {
+ if ((AOP_SIZE (IC_LEFT (ic)) == 2 ||
+ AOP_SIZE (IC_RIGHT (ic)) == 2) &&
+ (AOP_SIZE (IC_LEFT (ic)) <= 2 &&
+ AOP_SIZE (IC_RIGHT (ic)) <= 2))
+ {
+ PAIR_ID left = getPairId (AOP (IC_LEFT (ic)));
+ PAIR_ID right = getPairId (AOP (IC_RIGHT (ic)));
+
+ if (left == PAIR_INVALID && right == PAIR_INVALID)
+ {
+ left = PAIR_DE;
+ right = PAIR_HL;
+ }
+ else if (right == PAIR_INVALID)
+ right = PAIR_DE;
+ else if (left == PAIR_INVALID)
+ left = PAIR_DE;
+
+ fetchPair (left, AOP (IC_LEFT (ic)));
+ /* Order is important. Right may be HL */
+ fetchPair (right, AOP (IC_RIGHT (ic)));
+
+ emit2 ("ld a,%s", _pairs[left].l);
+ emit2 ("sub a,%s", _pairs[right].l);
+ emit2 ("ld e,a");
+ emit2 ("ld a,%s", _pairs[left].h);
+ emit2 ("sbc a,%s", _pairs[right].h);
+
+ aopPut (AOP (IC_RESULT (ic)), "a", 1);
+ aopPut (AOP (IC_RESULT (ic)), "e", 0);
+ goto release;
+ }
+ else if (size == 4)
+ {
+ emit2 ("; WARNING: This sub is probably broken.\n");
+ }
+ }
+ }
+
+ /* if literal, add a,#-lit, else normal subb */
+ while (size--)
+ {
+ MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE));
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ {
+ if (!offset)
+ emitcode ("sub", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE));
+ else
+ emitcode ("sbc", "a,%s",
+ aopGet (AOP (IC_RIGHT (ic)), offset, FALSE));
+ }
else
- emit2("adc a,!immedbyte", (unsigned int)((lit >> (offset*8)) & 0x0FFL));
- }
- aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+ {
+ /* first add without previous c */
+ if (!offset)
+ emit2 ("add a,!immedbyte", (unsigned int) (lit & 0x0FFL));
+ else
+ emit2 ("adc a,!immedbyte", (unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
+ }
+ aopPut (AOP (IC_RESULT (ic)), "a", offset++);
}
- if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
- AOP_SIZE(IC_LEFT(ic)) == 3 &&
- !sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
- wassert(0);
+ if (AOP_SIZE (IC_RESULT (ic)) == 3 &&
+ AOP_SIZE (IC_LEFT (ic)) == 3 &&
+ !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))))
+ wassert (0);
release:
- freeAsmop(IC_LEFT(ic),NULL,ic);
- freeAsmop(IC_RIGHT(ic),NULL,ic);
- freeAsmop(IC_RESULT(ic),NULL,ic);
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ freeAsmop (IC_RIGHT (ic), NULL, ic);
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genMult - generates code for multiplication */
/*-----------------------------------------------------------------*/
-static void genMult (iCode *ic)
+static void
+genMult (iCode * ic)
{
- /* Shouldn't occur - all done through function calls */
- wassert(0);
+ /* Shouldn't occur - all done through function calls */
+ wassert (0);
}
/*-----------------------------------------------------------------*/
/* genDiv - generates code for division */
/*-----------------------------------------------------------------*/
-static void genDiv (iCode *ic)
+static void
+genDiv (iCode * ic)
{
- /* Shouldn't occur - all done through function calls */
- wassert(0);
+ /* Shouldn't occur - all done through function calls */
+ wassert (0);
}
/*-----------------------------------------------------------------*/
/* genMod - generates code for division */
/*-----------------------------------------------------------------*/
-static void genMod (iCode *ic)
+static void
+genMod (iCode * ic)
{
- /* Shouldn't occur - all done through function calls */
- wassert(0);
+ /* Shouldn't occur - all done through function calls */
+ wassert (0);
}
/*-----------------------------------------------------------------*/
/* genIfxJump :- will create a jump depending on the ifx */
/*-----------------------------------------------------------------*/
-static void genIfxJump (iCode *ic, char *jval)
+static void
+genIfxJump (iCode * ic, char *jval)
{
- symbol *jlbl ;
- const char *inst;
-
- /* if true label then we jump if condition
- supplied is true */
- if (IC_TRUE(ic)) {
- jlbl = IC_TRUE(ic);
- if (!strcmp(jval, "a")) {
- inst = "nz";
- }
- else if (!strcmp(jval, "c")) {
- inst = "c";
- }
- else if (!strcmp(jval, "nc")) {
- inst = "nc";
- }
- else {
- /* The buffer contains the bit on A that we should test */
- inst = "nz";
- }
+ symbol *jlbl;
+ const char *inst;
+
+ /* if true label then we jump if condition
+ supplied is true */
+ if (IC_TRUE (ic))
+ {
+ jlbl = IC_TRUE (ic);
+ if (!strcmp (jval, "a"))
+ {
+ inst = "nz";
+ }
+ else if (!strcmp (jval, "c"))
+ {
+ inst = "c";
+ }
+ else if (!strcmp (jval, "nc"))
+ {
+ inst = "nc";
+ }
+ else
+ {
+ /* The buffer contains the bit on A that we should test */
+ inst = "nz";
+ }
}
- else {
- /* false label is present */
- jlbl = IC_FALSE(ic) ;
- if (!strcmp(jval, "a")) {
- inst = "z";
- }
- else if (!strcmp(jval, "c")) {
- inst = "nc";
- }
- else if (!strcmp(jval, "nc")) {
- inst = "c";
- }
- else {
- /* The buffer contains the bit on A that we should test */
- inst = "z";
- }
+ else
+ {
+ /* false label is present */
+ jlbl = IC_FALSE (ic);
+ if (!strcmp (jval, "a"))
+ {
+ inst = "z";
+ }
+ else if (!strcmp (jval, "c"))
+ {
+ inst = "nc";
+ }
+ else if (!strcmp (jval, "nc"))
+ {
+ inst = "c";
+ }
+ else
+ {
+ /* The buffer contains the bit on A that we should test */
+ inst = "z";
+ }
}
- /* Z80 can do a conditional long jump */
- if (!strcmp(jval, "a")) {
- emitcode("or", "a,a");
+ /* Z80 can do a conditional long jump */
+ if (!strcmp (jval, "a"))
+ {
+ emitcode ("or", "a,a");
}
- else if (!strcmp(jval, "c")) {
+ else if (!strcmp (jval, "c"))
+ {
}
- else if (!strcmp(jval, "nc")) {
+ else if (!strcmp (jval, "nc"))
+ {
}
- else {
- emitcode("bit", "%s,a", jval);
+ else
+ {
+ emitcode ("bit", "%s,a", jval);
}
- emit2("jp %s,!tlabel", inst, jlbl->key+100);
+ emit2 ("jp %s,!tlabel", inst, jlbl->key + 100);
- /* mark the icode as generated */
- ic->generated = 1;
+ /* mark the icode as generated */
+ ic->generated = 1;
}
-static const char *_getPairIdName(PAIR_ID id)
+static const char *
+_getPairIdName (PAIR_ID id)
{
- return _pairs[id].name;
+ return _pairs[id].name;
}
/** Generic compare for > or <
*/
-static void genCmp (operand *left,operand *right,
- operand *result, iCode *ifx, int sign)
+static void
+genCmp (operand * left, operand * right,
+ operand * result, iCode * ifx, int sign)
{
- int size, offset = 0 ;
- unsigned long lit = 0L;
- bool swap_sense = FALSE;
-
- /* if left & right are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- /* Cant happen on the Z80 */
- wassert(0);
- } else {
- /* subtract right from left if at the
- end the carry flag is set then we know that
- left is greater than right */
- size = max(AOP_SIZE(left),AOP_SIZE(right));
-
- /* if unsigned char cmp with lit, just compare */
- if((size == 1) &&
- (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
- emitcode("ld", "a,%s", aopGet(AOP(left), offset, FALSE));
- if (sign) {
- emit2("xor a,!immedbyte", 0x80);
- emit2("cp %s^!constbyte", aopGet(AOP(right), offset, FALSE), 0x80);
- }
- else
- emitcode("cp", "%s", aopGet(AOP(right), offset, FALSE));
- }
- else {
- /* Special cases:
- On the GB:
- If the left or the right is a lit:
- Load -lit into HL, add to right via, check sense.
- */
- if (size == 2 && (AOP_TYPE(right) == AOP_LIT || AOP_TYPE(left) == AOP_LIT)) {
- PAIR_ID id = PAIR_DE;
- asmop *lit = AOP(right);
- asmop *op = AOP(left);
- swap_sense = TRUE;
-
- if (AOP_TYPE(left) == AOP_LIT) {
- swap_sense = FALSE;
- lit = AOP(left);
- op = AOP(right);
- }
- if (sign) {
- emit2("ld e,%s", aopGet(op, 0, 0));
- emit2("ld a,%s", aopGet(op, 1, 0));
- emit2("xor a,!immedbyte", 0x80);
- emit2("ld d,a");
- }
- else {
- id = getPairId(op);
- if (id == PAIR_INVALID) {
- fetchPair(PAIR_DE, op);
- id = PAIR_DE;
- }
- }
- spillPair(PAIR_HL);
- emit2("ld hl,%s", fetchLitSpecial(lit, TRUE, sign));
- emit2("add hl,%s", _getPairIdName(id));
- goto release;
- }
- if(AOP_TYPE(right) == AOP_LIT) {
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- /* optimize if(x < 0) or if(x >= 0) */
- if (lit == 0L){
- if (!sign) {
- /* No sign so it's always false */
- CLRC;
- }
- else{
- /* Just load in the top most bit */
- MOVA(aopGet(AOP(left),AOP_SIZE(left)-1,FALSE));
- if(!(AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) && ifx) {
- genIfxJump (ifx,"7");
- return;
- }
- else
- emitcode("rlc","a");
- }
- goto release;
- }
- }
- if (sign) {
- /* First setup h and l contaning the top most bytes XORed */
- bool fDidXor = FALSE;
- if (AOP_TYPE(left) == AOP_LIT){
- unsigned long lit = (unsigned long)
- floatFromVal(AOP(left)->aopu.aop_lit);
- emit2("ld %s,!immedbyte", _fTmp[0],
- 0x80 ^ (unsigned int)((lit >> ((size-1)*8)) & 0x0FFL));
- }
- else {
- emitcode("ld", "a,%s", aopGet(AOP(left), size-1, FALSE));
- emit2("xor a,!immedbyte", 0x80);
- emitcode("ld", "%s,a", _fTmp[0]);
- fDidXor = TRUE;
- }
- if (AOP_TYPE(right) == AOP_LIT) {
- unsigned long lit = (unsigned long)
- floatFromVal(AOP(right)->aopu.aop_lit);
- emit2("ld %s,!immedbyte", _fTmp[1],
- 0x80 ^ (unsigned int)((lit >> ((size-1)*8)) & 0x0FFL));
- }
- else {
- emitcode("ld", "a,%s", aopGet(AOP(right), size-1, FALSE));
- emit2("xor a,!immedbyte", 0x80);
- emitcode("ld", "%s,a", _fTmp[1]);
- fDidXor = TRUE;
- }
- if (!fDidXor)
- CLRC;
- }
- else {
- CLRC;
- }
- while (size--) {
- /* Do a long subtract */
- if (!sign || size ) {
- MOVA(aopGet(AOP(left),offset,FALSE));
- }
- if (sign && size == 0) {
- emitcode("ld", "a,%s", _fTmp[0]);
- emitcode("sbc", "a,%s", _fTmp[1]);
- }
- else {
- /* Subtract through, propagating the carry */
- emitcode("sbc","a,%s ; 2",aopGet(AOP(right),offset++,FALSE));
+ int size, offset = 0;
+ unsigned long lit = 0L;
+ bool swap_sense = FALSE;
+
+ /* if left & right are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ /* Cant happen on the Z80 */
+ wassert (0);
}
- }
- }
+ else
+ {
+ /* subtract right from left if at the
+ end the carry flag is set then we know that
+ left is greater than right */
+ size = max (AOP_SIZE (left), AOP_SIZE (right));
+
+ /* if unsigned char cmp with lit, just compare */
+ if ((size == 1) &&
+ (AOP_TYPE (right) == AOP_LIT && AOP_TYPE (left) != AOP_DIR))
+ {
+ emitcode ("ld", "a,%s", aopGet (AOP (left), offset, FALSE));
+ if (sign)
+ {
+ emit2 ("xor a,!immedbyte", 0x80);
+ emit2 ("cp %s^!constbyte", aopGet (AOP (right), offset, FALSE), 0x80);
+ }
+ else
+ emitcode ("cp", "%s", aopGet (AOP (right), offset, FALSE));
+ }
+ else
+ {
+ /* Special cases:
+ On the GB:
+ If the left or the right is a lit:
+ Load -lit into HL, add to right via, check sense.
+ */
+ if (size == 2 && (AOP_TYPE (right) == AOP_LIT || AOP_TYPE (left) == AOP_LIT))
+ {
+ PAIR_ID id = PAIR_DE;
+ asmop *lit = AOP (right);
+ asmop *op = AOP (left);
+ swap_sense = TRUE;
+
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+ swap_sense = FALSE;
+ lit = AOP (left);
+ op = AOP (right);
+ }
+ if (sign)
+ {
+ emit2 ("ld e,%s", aopGet (op, 0, 0));
+ emit2 ("ld a,%s", aopGet (op, 1, 0));
+ emit2 ("xor a,!immedbyte", 0x80);
+ emit2 ("ld d,a");
+ }
+ else
+ {
+ id = getPairId (op);
+ if (id == PAIR_INVALID)
+ {
+ fetchPair (PAIR_DE, op);
+ id = PAIR_DE;
+ }
+ }
+ spillPair (PAIR_HL);
+ emit2 ("ld hl,%s", fetchLitSpecial (lit, TRUE, sign));
+ emit2 ("add hl,%s", _getPairIdName (id));
+ goto release;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ /* optimize if(x < 0) or if(x >= 0) */
+ if (lit == 0L)
+ {
+ if (!sign)
+ {
+ /* No sign so it's always false */
+ CLRC;
+ }
+ else
+ {
+ /* Just load in the top most bit */
+ MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE));
+ if (!(AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) && ifx)
+ {
+ genIfxJump (ifx, "7");
+ return;
+ }
+ else
+ emitcode ("rlc", "a");
+ }
+ goto release;
+ }
+ }
+ if (sign)
+ {
+ /* First setup h and l contaning the top most bytes XORed */
+ bool fDidXor = FALSE;
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long)
+ floatFromVal (AOP (left)->aopu.aop_lit);
+ emit2 ("ld %s,!immedbyte", _fTmp[0],
+ 0x80 ^ (unsigned int) ((lit >> ((size - 1) * 8)) & 0x0FFL));
+ }
+ else
+ {
+ emitcode ("ld", "a,%s", aopGet (AOP (left), size - 1, FALSE));
+ emit2 ("xor a,!immedbyte", 0x80);
+ emitcode ("ld", "%s,a", _fTmp[0]);
+ fDidXor = TRUE;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ unsigned long lit = (unsigned long)
+ floatFromVal (AOP (right)->aopu.aop_lit);
+ emit2 ("ld %s,!immedbyte", _fTmp[1],
+ 0x80 ^ (unsigned int) ((lit >> ((size - 1) * 8)) & 0x0FFL));
+ }
+ else
+ {
+ emitcode ("ld", "a,%s", aopGet (AOP (right), size - 1, FALSE));
+ emit2 ("xor a,!immedbyte", 0x80);
+ emitcode ("ld", "%s,a", _fTmp[1]);
+ fDidXor = TRUE;
+ }
+ if (!fDidXor)
+ CLRC;
+ }
+ else
+ {
+ CLRC;
+ }
+ while (size--)
+ {
+ /* Do a long subtract */
+ if (!sign || size)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ }
+ if (sign && size == 0)
+ {
+ emitcode ("ld", "a,%s", _fTmp[0]);
+ emitcode ("sbc", "a,%s", _fTmp[1]);
+ }
+ else
+ {
+ /* Subtract through, propagating the carry */
+ emitcode ("sbc", "a,%s ; 2", aopGet (AOP (right), offset++, FALSE));
+ }
+ }
+ }
}
release:
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- outBitCLong(result, swap_sense);
- } else {
- /* if the result is used in the next
- ifx conditional branch then generate
- code a little differently */
- if (ifx)
- genIfxJump(ifx, swap_sense ? "nc" : "c");
- else
- outBitCLong(result, swap_sense);
- /* leave the result in acc */
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ outBitCLong (result, swap_sense);
+ }
+ else
+ {
+ /* if the result is used in the next
+ ifx conditional branch then generate
+ code a little differently */
+ if (ifx)
+ genIfxJump (ifx, swap_sense ? "nc" : "c");
+ else
+ outBitCLong (result, swap_sense);
+ /* leave the result in acc */
}
}
/*-----------------------------------------------------------------*/
/* genCmpGt :- greater than comparison */
/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
+static void
+genCmpGt (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
-
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
-
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
- /* assign the amsops */
- aopOp (left,ic,FALSE, FALSE);
- aopOp (right,ic,FALSE, FALSE);
- aopOp (result,ic,TRUE, FALSE);
-
- genCmp(right, left, result, ifx, sign);
-
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ operand *left, *right, *result;
+ sym_link *letype, *retype;
+ int sign;
+
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
+
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
+ /* assign the amsops */
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
+ aopOp (result, ic, TRUE, FALSE);
+
+ genCmp (right, left, result, ifx, sign);
+
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genCmpLt - less than comparisons */
/*-----------------------------------------------------------------*/
-static void genCmpLt (iCode *ic, iCode *ifx)
+static void
+genCmpLt (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
+ operand *left, *right, *result;
+ sym_link *letype, *retype;
+ int sign;
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
+ left = IC_LEFT (ic);
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+ letype = getSpec (operandType (left));
+ retype = getSpec (operandType (right));
+ sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
- /* assign the amsops */
- aopOp (left,ic,FALSE, FALSE);
- aopOp (right,ic,FALSE, FALSE);
- aopOp (result,ic,TRUE, FALSE);
+ /* assign the amsops */
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
+ aopOp (result, ic, TRUE, FALSE);
- genCmp(left, right, result, ifx, sign);
+ genCmp (left, right, result, ifx, sign);
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* gencjneshort - compare and jump if not equal */
/*-----------------------------------------------------------------*/
-static void gencjneshort(operand *left, operand *right, symbol *lbl)
+static void
+gencjneshort (operand * left, operand * right, symbol * lbl)
{
- int size = max(AOP_SIZE(left),AOP_SIZE(right));
- int offset = 0;
- unsigned long lit = 0L;
+ int size = max (AOP_SIZE (left), AOP_SIZE (right));
+ int offset = 0;
+ unsigned long lit = 0L;
- /* Swap the left and right if it makes the computation easier */
- if (AOP_TYPE(left) == AOP_LIT) {
- operand *t = right;
- right = left;
- left = t;
+ /* Swap the left and right if it makes the computation easier */
+ if (AOP_TYPE (left) == AOP_LIT)
+ {
+ operand *t = right;
+ right = left;
+ left = t;
}
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
- /* if the right side is a literal then anything goes */
- if (AOP_TYPE(right) == AOP_LIT &&
- AOP_TYPE(left) != AOP_DIR ) {
- if (lit == 0) {
- emitcode("ld", "a,%s", aopGet(AOP(left), offset, FALSE));
- if (size > 1) {
- size--;
- offset++;
- while (size--) {
- emitcode("or", "a,%s", aopGet(AOP(left), offset, FALSE));
- }
- }
- else {
- emitcode("or", "a,a");
- }
- emit2("jp nz,!tlabel", lbl->key+100);
- }
- else {
- while (size--) {
- emitcode("ld", "a,%s ; 2", aopGet(AOP(left),offset,FALSE));
- if ((AOP_TYPE(right) == AOP_LIT) && lit == 0)
- emitcode("or", "a,a");
- else
- emitcode("cp", "a,%s", aopGet(AOP(right),offset,FALSE));
- emit2("jp nz,!tlabel", lbl->key+100);
- offset++;
- }
- }
+ /* if the right side is a literal then anything goes */
+ if (AOP_TYPE (right) == AOP_LIT &&
+ AOP_TYPE (left) != AOP_DIR)
+ {
+ if (lit == 0)
+ {
+ emitcode ("ld", "a,%s", aopGet (AOP (left), offset, FALSE));
+ if (size > 1)
+ {
+ size--;
+ offset++;
+ while (size--)
+ {
+ emitcode ("or", "a,%s", aopGet (AOP (left), offset, FALSE));
+ }
+ }
+ else
+ {
+ emitcode ("or", "a,a");
+ }
+ emit2 ("jp nz,!tlabel", lbl->key + 100);
+ }
+ else
+ {
+ while (size--)
+ {
+ emitcode ("ld", "a,%s ; 2", aopGet (AOP (left), offset, FALSE));
+ if ((AOP_TYPE (right) == AOP_LIT) && lit == 0)
+ emitcode ("or", "a,a");
+ else
+ emitcode ("cp", "a,%s", aopGet (AOP (right), offset, FALSE));
+ emit2 ("jp nz,!tlabel", lbl->key + 100);
+ offset++;
+ }
+ }
+ }
+ /* if the right side is in a register or in direct space or
+ if the left is a pointer register & right is not */
+ else if (AOP_TYPE (right) == AOP_REG ||
+ AOP_TYPE (right) == AOP_DIR ||
+ (AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT))
+ {
+ while (size--)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ if ((AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) &&
+ ((unsigned int) ((lit >> (offset * 8)) & 0x0FFL) == 0))
+ /* PENDING */
+ emit2 ("jp nz,!tlabel", lbl->key + 100);
+ else
+ {
+ emitcode ("cp", "%s ; 4", aopGet (AOP (right), offset, FALSE));
+ emit2 ("jp nz,!tlabel", lbl->key + 100);
+ }
+ offset++;
+ }
}
- /* if the right side is in a register or in direct space or
- if the left is a pointer register & right is not */
- else if (AOP_TYPE(right) == AOP_REG ||
- AOP_TYPE(right) == AOP_DIR ||
- (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT)) {
- while (size--) {
- MOVA(aopGet(AOP(left),offset,FALSE));
- if((AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) &&
- ((unsigned int)((lit >> (offset*8)) & 0x0FFL) == 0))
- /* PENDING */
- emit2("jp nz,!tlabel", lbl->key+100);
- else {
- emitcode("cp", "%s ; 4", aopGet(AOP(right),offset,FALSE));
- emit2("jp nz,!tlabel", lbl->key+100);
- }
- offset++;
- }
- } else {
- /* right is a pointer reg need both a & b */
- /* PENDING: is this required? */
- while(size--) {
- MOVA(aopGet(AOP(right),offset,FALSE));
- emitcode("cp", "%s ; 5", aopGet(AOP(left), offset, FALSE));
- emit2("!shortjp nz,!tlabel", lbl->key+100);
- offset++;
- }
+ else
+ {
+ /* right is a pointer reg need both a & b */
+ /* PENDING: is this required? */
+ while (size--)
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE));
+ emitcode ("cp", "%s ; 5", aopGet (AOP (left), offset, FALSE));
+ emit2 ("!shortjp nz,!tlabel", lbl->key + 100);
+ offset++;
+ }
}
}
/*-----------------------------------------------------------------*/
/* gencjne - compare and jump if not equal */
/*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, symbol *lbl)
+static void
+gencjne (operand * left, operand * right, symbol * lbl)
{
- symbol *tlbl = newiTempLabel(NULL);
+ symbol *tlbl = newiTempLabel (NULL);
- gencjneshort(left, right, lbl);
+ gencjneshort (left, right, lbl);
- /* PENDING: ?? */
- emit2("ld a,!one");
- emit2("!shortjp !tlabel", tlbl->key+100);
- emitLabel(lbl->key+100);
- emitcode("xor","a,a");
- emitLabel(tlbl->key+100);
+ /* PENDING: ?? */
+ emit2 ("ld a,!one");
+ emit2 ("!shortjp !tlabel", tlbl->key + 100);
+ emitLabel (lbl->key + 100);
+ emitcode ("xor", "a,a");
+ emitLabel (tlbl->key + 100);
}
/*-----------------------------------------------------------------*/
/* genCmpEq - generates code for equal to */
/*-----------------------------------------------------------------*/
-static void genCmpEq (iCode *ic, iCode *ifx)
+static void
+genCmpEq (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
-
- aopOp((left=IC_LEFT(ic)),ic,FALSE, FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE, FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE);
-
- /* Swap operands if it makes the operation easier. ie if:
- 1. Left is a literal.
- */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) {
- operand *t = IC_RIGHT(ic);
- IC_RIGHT(ic) = IC_LEFT(ic);
- IC_LEFT(ic) = t;
- }
-
- if (ifx && !AOP_SIZE(result)){
- symbol *tlbl;
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- wassert(0);
- } else {
- tlbl = newiTempLabel(NULL);
- gencjneshort(left, right, tlbl);
- if ( IC_TRUE(ifx) ) {
- emit2("jp !tlabel", IC_TRUE(ifx)->key+100);
- emitLabel(tlbl->key+100);
- } else {
- /* PENDING: do this better */
- symbol *lbl = newiTempLabel(NULL);
- emit2("!shortjp !tlabel", lbl->key+100);
- emitLabel(tlbl->key+100);
- emit2("jp !tlabel", IC_FALSE(ifx)->key+100);
- emitLabel(lbl->key+100);
- }
- }
- /* mark the icode as generated */
- ifx->generated = 1;
- goto release ;
- }
-
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- wassert(0);
- } else {
- gencjne(left,right,newiTempLabel(NULL));
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- wassert(0);
- }
- if (ifx) {
- genIfxJump(ifx,"a");
+ operand *left, *right, *result;
+
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE, FALSE);
+
+ /* Swap operands if it makes the operation easier. ie if:
+ 1. Left is a literal.
+ */
+ if (AOP_TYPE (IC_LEFT (ic)) == AOP_LIT)
+ {
+ operand *t = IC_RIGHT (ic);
+ IC_RIGHT (ic) = IC_LEFT (ic);
+ IC_LEFT (ic) = t;
+ }
+
+ if (ifx && !AOP_SIZE (result))
+ {
+ symbol *tlbl;
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ wassert (0);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ gencjneshort (left, right, tlbl);
+ if (IC_TRUE (ifx))
+ {
+ emit2 ("jp !tlabel", IC_TRUE (ifx)->key + 100);
+ emitLabel (tlbl->key + 100);
+ }
+ else
+ {
+ /* PENDING: do this better */
+ symbol *lbl = newiTempLabel (NULL);
+ emit2 ("!shortjp !tlabel", lbl->key + 100);
+ emitLabel (tlbl->key + 100);
+ emit2 ("jp !tlabel", IC_FALSE (ifx)->key + 100);
+ emitLabel (lbl->key + 100);
+ }
+ }
+ /* mark the icode as generated */
+ ifx->generated = 1;
goto release;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- if (AOP_TYPE(result) != AOP_CRY) {
- outAcc(result);
- }
- /* leave the result in acc */
+ }
+
+ /* if they are both bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ ((AOP_TYPE (right) == AOP_CRY) || (AOP_TYPE (right) == AOP_LIT)))
+ {
+ wassert (0);
+ }
+ else
+ {
+ gencjne (left, right, newiTempLabel (NULL));
+ if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
+ {
+ wassert (0);
+ }
+ if (ifx)
+ {
+ genIfxJump (ifx, "a");
+ goto release;
+ }
+ /* if the result is used in an arithmetic operation
+ then put the result in place */
+ if (AOP_TYPE (result) != AOP_CRY)
+ {
+ outAcc (result);
+ }
+ /* leave the result in acc */
}
release:
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* ifxForOp - returns the icode containing the ifx for operand */
/*-----------------------------------------------------------------*/
-static iCode *ifxForOp ( operand *op, iCode *ic )
+static iCode *
+ifxForOp (operand * op, iCode * ic)
{
- /* if true symbol then needs to be assigned */
- if (IS_TRUE_SYMOP(op))
- return NULL ;
-
- /* if this has register type condition and
- the next instruction is ifx with the same operand
- and live to of the operand is upto the ifx only then */
- if (ic->next &&
- ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key &&
- OP_SYMBOL(op)->liveTo <= ic->next->seq )
- return ic->next;
-
+ /* if true symbol then needs to be assigned */
+ if (IS_TRUE_SYMOP (op))
return NULL;
+
+ /* if this has register type condition and
+ the next instruction is ifx with the same operand
+ and live to of the operand is upto the ifx only then */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ IC_COND (ic->next)->key == op->key &&
+ OP_SYMBOL (op)->liveTo <= ic->next->seq)
+ return ic->next;
+
+ return NULL;
}
/*-----------------------------------------------------------------*/
/* genAndOp - for && operation */
/*-----------------------------------------------------------------*/
-static void genAndOp (iCode *ic)
+static void
+genAndOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
-
- /* note here that && operations that are in an if statement are
- taken away by backPatchLabels only those used in arthmetic
- operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE, TRUE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE, TRUE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE, FALSE);
-
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- wassert(0);
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emit2("!shortjp z,!tlabel", tlbl->key+100);
- toBoolean(right);
- emitLabel(tlbl->key+100);
- outBitAcc(result);
- }
-
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ operand *left, *right, *result;
+ symbol *tlbl;
+
+ /* note here that && operations that are in an if statement are
+ taken away by backPatchLabels only those used in arthmetic
+ operations remain */
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE, TRUE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE, TRUE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE, FALSE);
+
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ wassert (0);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emit2 ("!shortjp z,!tlabel", tlbl->key + 100);
+ toBoolean (right);
+ emitLabel (tlbl->key + 100);
+ outBitAcc (result);
+ }
+
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genOrOp - for || operation */
/*-----------------------------------------------------------------*/
-static void genOrOp (iCode *ic)
+static void
+genOrOp (iCode * ic)
{
- operand *left,*right, *result;
- symbol *tlbl;
-
- /* note here that || operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE, TRUE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE, TRUE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE, FALSE);
-
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- wassert(0);
- } else {
- tlbl = newiTempLabel(NULL);
- toBoolean(left);
- emit2("!shortjp nz,!tlabel", tlbl->key+100);
- toBoolean(right);
- emitLabel(tlbl->key+100);
- outBitAcc(result);
- }
-
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ operand *left, *right, *result;
+ symbol *tlbl;
+
+ /* note here that || operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE, TRUE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE, TRUE);
+ aopOp ((result = IC_RESULT (ic)), ic, FALSE, FALSE);
+
+ /* if both are bit variables */
+ if (AOP_TYPE (left) == AOP_CRY &&
+ AOP_TYPE (right) == AOP_CRY)
+ {
+ wassert (0);
+ }
+ else
+ {
+ tlbl = newiTempLabel (NULL);
+ toBoolean (left);
+ emit2 ("!shortjp nz,!tlabel", tlbl->key + 100);
+ toBoolean (right);
+ emitLabel (tlbl->key + 100);
+ outBitAcc (result);
+ }
+
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* isLiteralBit - test if lit == 2^n */
/*-----------------------------------------------------------------*/
-int isLiteralBit(unsigned long lit)
+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;
+ 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;
}
/*-----------------------------------------------------------------*/
/* jmpTrueOrFalse - */
/*-----------------------------------------------------------------*/
-static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
+static void
+jmpTrueOrFalse (iCode * ic, symbol * tlbl)
{
- // ugly but optimized by peephole
- if(IC_TRUE(ic)){
- symbol *nlbl = newiTempLabel(NULL);
- emit2("jp !tlabel", nlbl->key+100);
- emitLabel(tlbl->key+100);
- emit2("jp !tlabel", IC_TRUE(ic)->key+100);
- emitLabel(nlbl->key+100);
- }
- else{
- emit2("jp !tlabel", IC_FALSE(ic)->key+100);
- emitLabel(tlbl->key+100);
- }
- ic->generated = 1;
+ // ugly but optimized by peephole
+ if (IC_TRUE (ic))
+ {
+ symbol *nlbl = newiTempLabel (NULL);
+ emit2 ("jp !tlabel", nlbl->key + 100);
+ emitLabel (tlbl->key + 100);
+ emit2 ("jp !tlabel", IC_TRUE (ic)->key + 100);
+ emitLabel (nlbl->key + 100);
+ }
+ else
+ {
+ emit2 ("jp !tlabel", IC_FALSE (ic)->key + 100);
+ emitLabel (tlbl->key + 100);
+ }
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAnd - code for and */
/*-----------------------------------------------------------------*/
-static void genAnd (iCode *ic, iCode *ifx)
+static void
+genAnd (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
- int bytelit = 0;
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+ int bytelit = 0;
- aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE, FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE, FALSE);
#ifdef DEBUG_TYPE
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- if (AOP_TYPE(left) == AOP_CRY){
- wassert(0);
- goto release ;
- }
-
- // if(val & 0xZZ) - size = 0, ifx != FALSE -
- // bit = val & 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)) {
- int posbit = isLiteralBit(lit);
- /* left & 2^n */
- if(posbit){
- posbit--;
- MOVA(aopGet(AOP(left),posbit>>3,FALSE));
- // bit = left & 2^n
- if(size) {
- wassert(0);
- emitcode("mov","c,acc.%d",posbit&0x07);
- }
- // if(left & 2^n)
- else{
- if (ifx) {
- sprintf(buffer, "%d", posbit&0x07);
- genIfxJump(ifx, buffer);
- }
- else {
- wassert(0);
- }
- goto release;
- }
- } else {
- symbol *tlbl = newiTempLabel(NULL);
- int sizel = AOP_SIZE(left);
- if(size) {
- wassert(0);
- emitcode("setb","c");
- }
- while(sizel--){
- if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
- MOVA( aopGet(AOP(left),offset,FALSE));
- // byte == 2^n ?
- if((posbit = isLiteralBit(bytelit)) != 0) {
- wassert(0);
- emitcode("jb","acc.%d,%05d$",(posbit-1)&0x07,tlbl->key+100);
- }
- else{
- if(bytelit != 0x0FFL)
- emitcode("and","a,%s",
- aopGet(AOP(right),offset,FALSE));
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ wassert (0);
+ goto release;
+ }
+
+ // if(val & 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val & 0xZZ - size = 1, ifx = FALSE -
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ int posbit = isLiteralBit (lit);
+ /* left & 2^n */
+ if (posbit)
+ {
+ posbit--;
+ MOVA (aopGet (AOP (left), posbit >> 3, FALSE));
+ // bit = left & 2^n
+ if (size)
+ {
+ wassert (0);
+ emitcode ("mov", "c,acc.%d", posbit & 0x07);
+ }
+ // if(left & 2^n)
+ else
+ {
+ if (ifx)
+ {
+ sprintf (buffer, "%d", posbit & 0x07);
+ genIfxJump (ifx, buffer);
+ }
+ else
+ {
+ wassert (0);
+ }
+ goto release;
+ }
+ }
else
- /* For the flags */
- emit2("or a,a");
- emit2("!shortjp nz,!tlabel", tlbl->key+100);
- }
- }
- offset++;
- }
- // bit = left & literal
- if (size){
- emitcode("clr","c");
- emit2("!tlabeldef", tlbl->key+100);
- }
- // if(left & literal)
- else{
- if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- goto release ;
- }
- }
- outBitC(result);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if((bytelit = (int)((lit >> (offset*8)) & 0x0FFL)) == 0x0FF)
- continue;
- else {
- if (bytelit == 0)
- aopPut(AOP(result),zero,offset);
- else {
- MOVA(aopGet(AOP(left),offset,FALSE));
- emitcode("and","a,%s",
- aopGet(AOP(right),offset,FALSE));
- aopPut(AOP(left), "a", offset);
- }
- }
-
- } else {
- if (AOP_TYPE(left) == AOP_ACC) {
- wassert(0);
- }
- else {
- MOVA(aopGet(AOP(left),offset,FALSE));
- emitcode("and","a,%s",
- aopGet(AOP(right),offset,FALSE));
- aopPut(AOP(left), "a", offset);
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- wassert(0);
- } else {
- for(;(size--);offset++) {
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- if((bytelit = (int)((lit >> (offset*8)) & 0x0FFL)) == 0x0FF){
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE),
- offset);
- continue;
- } else if(bytelit == 0){
- aopPut(AOP(result),zero,offset);
- continue;
- }
- }
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("and","a,%s",aopGet(AOP(right),offset,FALSE));
- else {
- MOVA(aopGet(AOP(left),offset,FALSE));
- emitcode("and","a,%s",
- aopGet(AOP(right),offset,FALSE));
- }
- aopPut(AOP(result),"a",offset);
- }
- }
+ {
+ symbol *tlbl = newiTempLabel (NULL);
+ int sizel = AOP_SIZE (left);
+ if (size)
+ {
+ wassert (0);
+ emitcode ("setb", "c");
+ }
+ while (sizel--)
+ {
+ if ((bytelit = ((lit >> (offset * 8)) & 0x0FFL)) != 0x0L)
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ // byte == 2^n ?
+ if ((posbit = isLiteralBit (bytelit)) != 0)
+ {
+ wassert (0);
+ emitcode ("jb", "acc.%d,%05d$", (posbit - 1) & 0x07, tlbl->key + 100);
+ }
+ else
+ {
+ if (bytelit != 0x0FFL)
+ emitcode ("and", "a,%s",
+ aopGet (AOP (right), offset, FALSE));
+ else
+ /* For the flags */
+ emit2 ("or a,a");
+ emit2 ("!shortjp nz,!tlabel", tlbl->key + 100);
+ }
+ }
+ offset++;
+ }
+ // bit = left & literal
+ if (size)
+ {
+ emitcode ("clr", "c");
+ emit2 ("!tlabeldef", tlbl->key + 100);
+ }
+ // if(left & literal)
+ else
+ {
+ if (ifx)
+ jmpTrueOrFalse (ifx, tlbl);
+ goto release;
+ }
+ }
+ outBitC (result);
+ goto release;
+ }
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if ((bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL)) == 0x0FF)
+ continue;
+ else
+ {
+ if (bytelit == 0)
+ aopPut (AOP (result), zero, offset);
+ else
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ emitcode ("and", "a,%s",
+ aopGet (AOP (right), offset, FALSE));
+ aopPut (AOP (left), "a", offset);
+ }
+ }
+
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ {
+ wassert (0);
+ }
+ else
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ emitcode ("and", "a,%s",
+ aopGet (AOP (right), offset, FALSE));
+ aopPut (AOP (left), "a", offset);
+ }
+ }
+ }
}
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ wassert (0);
+ }
+ else
+ {
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if ((bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL)) == 0x0FF)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE),
+ offset);
+ continue;
+ }
+ else if (bytelit == 0)
+ {
+ aopPut (AOP (result), zero, offset);
+ continue;
+ }
+ }
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("and", "a,%s", aopGet (AOP (right), offset, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ emitcode ("and", "a,%s",
+ aopGet (AOP (right), offset, FALSE));
+ }
+ aopPut (AOP (result), "a", offset);
+ }
+ }
-release :
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ }
+
+release:
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genOr - code for or */
/*-----------------------------------------------------------------*/
-static void genOr (iCode *ic, iCode *ifx)
+static void
+genOr (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
- aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE, FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE);
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE, FALSE);
#if 1
- emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
+ emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+ AOP_TYPE (result),
+ AOP_TYPE (left), AOP_TYPE (right));
+ emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+ AOP_SIZE (result),
+ AOP_SIZE (left), AOP_SIZE (right));
#endif
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- if (AOP_TYPE(left) == AOP_CRY){
- wassert(0);
- goto release ;
- }
-
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- wassert(0);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- continue;
- else {
- MOVA(aopGet(AOP(left),offset,FALSE));
- emitcode("or","a,%s",
- aopGet(AOP(right),offset,FALSE));
- aopPut(AOP(result),"a", offset);
- }
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("or","a,%s",aopGet(AOP(right),offset,FALSE));
- else {
- MOVA(aopGet(AOP(left),offset,FALSE));
- emitcode("or","a,%s",
- aopGet(AOP(right),offset,FALSE));
- aopPut(AOP(result),"a", offset);
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- wassert(0);
- } else for(;(size--);offset++){
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L){
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE),
- offset);
- continue;
- }
- }
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("or","a,%s",aopGet(AOP(right),offset,FALSE));
- else {
- MOVA(aopGet(AOP(left),offset,FALSE));
- emitcode("or","a,%s",
- aopGet(AOP(right),offset,FALSE));
- }
- aopPut(AOP(result),"a",offset);
- /* PENDING: something weird is going on here. Add exception. */
- if (AOP_TYPE(result) == AOP_ACC)
- break;
- }
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
+
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ wassert (0);
+ goto release;
+ }
+
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ wassert (0);
+ goto release;
}
-release :
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ continue;
+ else
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ emitcode ("or", "a,%s",
+ aopGet (AOP (right), offset, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("or", "a,%s", aopGet (AOP (right), offset, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ emitcode ("or", "a,%s",
+ aopGet (AOP (right), offset, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ wassert (0);
+ }
+ else
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE),
+ offset);
+ continue;
+ }
+ }
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("or", "a,%s", aopGet (AOP (right), offset, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (left), offset, FALSE));
+ emitcode ("or", "a,%s",
+ aopGet (AOP (right), offset, FALSE));
+ }
+ aopPut (AOP (result), "a", offset);
+ /* PENDING: something weird is going on here. Add exception. */
+ if (AOP_TYPE (result) == AOP_ACC)
+ break;
+ }
+ }
+
+release:
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genXor - code for xclusive or */
/*-----------------------------------------------------------------*/
-static void genXor (iCode *ic, iCode *ifx)
+static void
+genXor (iCode * ic, iCode * ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
-
- aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE, FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE);
-
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if result = right then exchange them */
- if(sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- if (AOP_TYPE(left) == AOP_CRY){
- wassert(0);
- goto release ;
- }
-
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- wassert(0);
- goto release ;
- }
-
- /* if left is same as result */
- if(sameRegs(AOP(result),AOP(left))){
- for(;size--; offset++) {
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L)
- continue;
- else {
- MOVA(aopGet(AOP(right),offset,FALSE));
- emitcode("xor","a,%s",
- aopGet(AOP(left),offset,FALSE));
- aopPut(AOP(result),"a",0);
- }
- } else {
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("xor","a,%s",aopGet(AOP(right),offset,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE));
- emitcode("xor","a,%s",
- aopGet(AOP(left),offset,FALSE));
- aopPut(AOP(result),"a",0);
- }
- }
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- wassert(0);
- } else for(;(size--);offset++){
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- if(((lit >> (offset*8)) & 0x0FFL) == 0x00L){
- aopPut(AOP(result),
- aopGet(AOP(left),offset,FALSE),
- offset);
- continue;
- }
- }
- // faster than result <- left, anl result,right
- // and better if result is SFR
- if (AOP_TYPE(left) == AOP_ACC)
- emitcode("xor","a,%s",aopGet(AOP(right),offset,FALSE));
- else {
- MOVA(aopGet(AOP(right),offset,FALSE));
- emitcode("xor","a,%s",
- aopGet(AOP(left),offset,FALSE));
- aopPut(AOP(result),"a",0);
- }
- aopPut(AOP(result),"a",offset);
- }
+ operand *left, *right, *result;
+ int size, offset = 0;
+ unsigned long lit = 0L;
+
+ aopOp ((left = IC_LEFT (ic)), ic, FALSE, FALSE);
+ aopOp ((right = IC_RIGHT (ic)), ic, FALSE, FALSE);
+ aopOp ((result = IC_RESULT (ic)), ic, TRUE, FALSE);
+
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE (left) == AOP_LIT && AOP_TYPE (right) != AOP_LIT) ||
+ AOP_NEEDSACC (left))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if (sameRegs (AOP (result), AOP (right)))
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE (right) == AOP_CRY &&
+ AOP_TYPE (left) != AOP_CRY)
+ {
+ operand *tmp = right;
+ right = left;
+ left = tmp;
}
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ size = AOP_SIZE (result);
-release :
- freeAsmop(left,NULL,ic);
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ if (AOP_TYPE (left) == AOP_CRY)
+ {
+ wassert (0);
+ goto release;
+ }
+
+ if ((AOP_TYPE (right) == AOP_LIT) &&
+ (AOP_TYPE (result) == AOP_CRY) &&
+ (AOP_TYPE (left) != AOP_CRY))
+ {
+ wassert (0);
+ goto release;
+ }
+
+ /* if left is same as result */
+ if (sameRegs (AOP (result), AOP (left)))
+ {
+ for (; size--; offset++)
+ {
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ continue;
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE));
+ emitcode ("xor", "a,%s",
+ aopGet (AOP (left), offset, FALSE));
+ aopPut (AOP (result), "a", 0);
+ }
+ }
+ else
+ {
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("xor", "a,%s", aopGet (AOP (right), offset, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE));
+ emitcode ("xor", "a,%s",
+ aopGet (AOP (left), offset, FALSE));
+ aopPut (AOP (result), "a", 0);
+ }
+ }
+ }
+ }
+ else
+ {
+ // left & result in different registers
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ wassert (0);
+ }
+ else
+ for (; (size--); offset++)
+ {
+ // normal case
+ // result = left & right
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ if (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (left), offset, FALSE),
+ offset);
+ continue;
+ }
+ }
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE (left) == AOP_ACC)
+ emitcode ("xor", "a,%s", aopGet (AOP (right), offset, FALSE));
+ else
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE));
+ emitcode ("xor", "a,%s",
+ aopGet (AOP (left), offset, FALSE));
+ aopPut (AOP (result), "a", 0);
+ }
+ aopPut (AOP (result), "a", offset);
+ }
+ }
+
+release:
+ freeAsmop (left, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genInline - write the inline code out */
/*-----------------------------------------------------------------*/
-static void genInline (iCode *ic)
+static void
+genInline (iCode * ic)
{
- char buffer[MAX_INLINEASM];
- char *bp = buffer;
- char *bp1= buffer;
-
- inLine += (!options.asmpeep);
- strcpy(buffer,IC_INLINE(ic));
-
- /* emit each line as a code */
- while (*bp) {
- if (*bp == '\n') {
- *bp++ = '\0';
- emitcode(bp1,"");
- bp1 = bp;
- } else {
- if (*bp == ':') {
- bp++;
- *bp = '\0';
- bp++;
- emitcode(bp1,"");
- bp1 = bp;
- } else
- bp++;
- }
- }
- if (bp1 != bp)
- emitcode(bp1,"");
- /* emitcode("",buffer); */
- inLine -= (!options.asmpeep);
+ char buffer[MAX_INLINEASM];
+ char *bp = buffer;
+ char *bp1 = buffer;
+
+ inLine += (!options.asmpeep);
+ strcpy (buffer, IC_INLINE (ic));
+
+ /* emit each line as a code */
+ while (*bp)
+ {
+ if (*bp == '\n')
+ {
+ *bp++ = '\0';
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ {
+ if (*bp == ':')
+ {
+ bp++;
+ *bp = '\0';
+ bp++;
+ emitcode (bp1, "");
+ bp1 = bp;
+ }
+ else
+ bp++;
+ }
+ }
+ if (bp1 != bp)
+ emitcode (bp1, "");
+ /* emitcode("",buffer); */
+ inLine -= (!options.asmpeep);
}
/*-----------------------------------------------------------------*/
/* genRRC - rotate right with carry */
/*-----------------------------------------------------------------*/
-static void genRRC (iCode *ic)
+static void
+genRRC (iCode * ic)
{
- wassert(0);
+ wassert (0);
}
/*-----------------------------------------------------------------*/
/* genRLC - generate code for rotate left with carry */
/*-----------------------------------------------------------------*/
-static void genRLC (iCode *ic)
+static void
+genRLC (iCode * ic)
{
- wassert(0);
+ wassert (0);
}
/*-----------------------------------------------------------------*/
/* shiftR2Left2Result - shift right two bytes from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR2Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
+static void
+shiftR2Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
{
- movLeft2Result(left, offl, result, offr, 0);
- movLeft2Result(left, offl+1, result, offr+1, 0);
+ movLeft2Result (left, offl, result, offr, 0);
+ movLeft2Result (left, offl + 1, result, offr + 1, 0);
- if (sign) {
- wassert(0);
+ if (sign)
+ {
+ wassert (0);
}
- else {
- /* if (AOP(result)->type == AOP_REG) {*/
+ else
+ {
+ /* if (AOP(result)->type == AOP_REG) { */
int size = 2;
int offset = 0;
- symbol *tlbl , *tlbl1;
+ symbol *tlbl, *tlbl1;
char *l;
- tlbl = newiTempLabel(NULL);
- tlbl1 = newiTempLabel(NULL);
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
/* Left is already in result - so now do the shift */
- if (shCount>1) {
- emit2("ld a,!immedbyte+1", shCount);
- emit2("!shortjp !tlabel", tlbl1->key+100);
- emitLabel(tlbl->key+100);
- }
-
- emitcode("or", "a,a");
+ if (shCount > 1)
+ {
+ emit2 ("ld a,!immedbyte+1", shCount);
+ emit2 ("!shortjp !tlabel", tlbl1->key + 100);
+ emitLabel (tlbl->key + 100);
+ }
+
+ emitcode ("or", "a,a");
offset = size;
- while (size--) {
- l = aopGet(AOP(result), --offset, FALSE);
- emitcode("rr","%s", l);
- }
- if (shCount>1) {
- emitLabel(tlbl1->key+100);
- emitcode("dec", "a");
- emit2("!shortjp nz,!tlabel", tlbl->key+100);
- }
+ while (size--)
+ {
+ l = aopGet (AOP (result), --offset, FALSE);
+ emitcode ("rr", "%s", l);
+ }
+ if (shCount > 1)
+ {
+ emitLabel (tlbl1->key + 100);
+ emitcode ("dec", "a");
+ emit2 ("!shortjp nz,!tlabel", tlbl->key + 100);
+ }
}
}
/*-----------------------------------------------------------------*/
/* shiftL2Left2Result - shift left two bytes from left to result */
/*-----------------------------------------------------------------*/
-static void shiftL2Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftL2Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- if(sameRegs(AOP(result), AOP(left)) &&
- ((offl + MSB16) == offr)){
- wassert(0);
- } else {
- /* Copy left into result */
- movLeft2Result(left, offl, result, offr, 0);
- movLeft2Result(left, offl+1, result, offr+1, 0);
- }
- /* PENDING: for now just see if it'll work. */
- /*if (AOP(result)->type == AOP_REG) { */
- {
- int size = 2;
- int offset = 0;
- symbol *tlbl , *tlbl1;
- char *l;
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ wassert (0);
+ }
+ else
+ {
+ /* Copy left into result */
+ movLeft2Result (left, offl, result, offr, 0);
+ movLeft2Result (left, offl + 1, result, offr + 1, 0);
+ }
+ /* PENDING: for now just see if it'll work. */
+ /*if (AOP(result)->type == AOP_REG) { */
+ {
+ int size = 2;
+ int offset = 0;
+ symbol *tlbl, *tlbl1;
+ char *l;
- tlbl = newiTempLabel(NULL);
- tlbl1 = newiTempLabel(NULL);
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
- /* Left is already in result - so now do the shift */
- if (shCount>1) {
- emit2("ld a,!immedbyte+1", shCount);
- emit2("!shortjp !tlabel", tlbl1->key+100);
- emitLabel(tlbl->key+100);
- }
+ /* Left is already in result - so now do the shift */
+ if (shCount > 1)
+ {
+ emit2 ("ld a,!immedbyte+1", shCount);
+ emit2 ("!shortjp !tlabel", tlbl1->key + 100);
+ emitLabel (tlbl->key + 100);
+ }
- emitcode("or", "a,a");
- while (size--) {
- l = aopGet(AOP(result),offset++,FALSE);
- emitcode("rl","%s", l);
- }
- if (shCount>1) {
- emitLabel(tlbl1->key+100);
- emitcode("dec", "a");
- emit2("!shortjp nz,!tlabel", tlbl->key+100);
+ emitcode ("or", "a,a");
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset++, FALSE);
+ emitcode ("rl", "%s", l);
+ }
+ if (shCount > 1)
+ {
+ emitLabel (tlbl1->key + 100);
+ emitcode ("dec", "a");
+ emit2 ("!shortjp nz,!tlabel", tlbl->key + 100);
+ }
}
- }
}
/*-----------------------------------------------------------------*/
/* AccRol - rotate left accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRol (int shCount)
+static void
+AccRol (int shCount)
{
- shCount &= 0x0007; // shCount : 0..7
- switch(shCount){
- case 0 :
- break;
- case 1 :
- emitcode("rl","a");
- break;
- case 2 :
- emitcode("rl","a");
- emitcode("rl","a");
- break;
- case 3 :
- emitcode("rl","a");
- emitcode("rl","a");
- emitcode("rl","a");
- break;
- case 4 :
- emitcode("rl","a");
- emitcode("rl","a");
- emitcode("rl","a");
- emitcode("rl","a");
- break;
- case 5 :
- emitcode("rr","a");
- emitcode("rr","a");
- emitcode("rr","a");
- break;
- case 6 :
- emitcode("rr","a");
- emitcode("rr","a");
- break;
- case 7 :
- emitcode("rr","a");
- break;
+ shCount &= 0x0007; // shCount : 0..7
+
+ switch (shCount)
+ {
+ case 0:
+ break;
+ case 1:
+ emitcode ("rl", "a");
+ break;
+ case 2:
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ break;
+ case 3:
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ break;
+ case 4:
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ emitcode ("rl", "a");
+ break;
+ case 5:
+ emitcode ("rr", "a");
+ emitcode ("rr", "a");
+ emitcode ("rr", "a");
+ break;
+ case 6:
+ emitcode ("rr", "a");
+ emitcode ("rr", "a");
+ break;
+ case 7:
+ emitcode ("rr", "a");
+ break;
}
}
/*-----------------------------------------------------------------*/
/* AccLsh - left shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccLsh (int shCount)
+static void
+AccLsh (int shCount)
{
- if(shCount != 0) {
- if(shCount == 1) {
- emitcode("add","a,a");
- }
- else if(shCount == 2) {
- emitcode("add","a,a");
- emitcode("add","a,a");
- } else {
- /* rotate left accumulator */
- AccRol(shCount);
- /* and kill the lower order bits */
- emit2("and a,!immedbyte", SLMask[shCount]);
- }
+ if (shCount != 0)
+ {
+ if (shCount == 1)
+ {
+ emitcode ("add", "a,a");
+ }
+ else if (shCount == 2)
+ {
+ emitcode ("add", "a,a");
+ emitcode ("add", "a,a");
+ }
+ else
+ {
+ /* rotate left accumulator */
+ AccRol (shCount);
+ /* and kill the lower order bits */
+ emit2 ("and a,!immedbyte", SLMask[shCount]);
+ }
}
}
/*-----------------------------------------------------------------*/
/* shiftL1Left2Result - shift left one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftL1Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
+static void
+shiftL1Left2Result (operand * left, int offl,
+ operand * result, int offr, int shCount)
{
- char *l;
- l = aopGet(AOP(left),offl,FALSE);
- MOVA(l);
- /* shift left accumulator */
- AccLsh(shCount);
- aopPut(AOP(result),"a",offr);
+ char *l;
+ l = aopGet (AOP (left), offl, FALSE);
+ MOVA (l);
+ /* shift left accumulator */
+ AccLsh (shCount);
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* genlshTwo - left shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genlshTwo (operand *result,operand *left, int shCount)
+static void
+genlshTwo (operand * result, operand * left, int shCount)
{
- int size = AOP_SIZE(result);
-
- wassert(size==2);
-
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
- if (size > 1){
- if (shCount) {
- movLeft2Result(left, LSB, result, MSB16, 0);
- aopPut(AOP(result),zero, 0);
- shiftL1Left2Result(left, MSB16, result, MSB16, shCount);
- }
- else {
- movLeft2Result(left, LSB, result, MSB16, 0);
- aopPut(AOP(result),zero, 0);
- }
- }
- else {
- aopPut(AOP(result),zero,LSB);
- }
+ int size = AOP_SIZE (result);
+
+ wassert (size == 2);
+
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (size > 1)
+ {
+ if (shCount)
+ {
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ aopPut (AOP (result), zero, 0);
+ shiftL1Left2Result (left, MSB16, result, MSB16, shCount);
+ }
+ else
+ {
+ movLeft2Result (left, LSB, result, MSB16, 0);
+ aopPut (AOP (result), zero, 0);
+ }
+ }
+ else
+ {
+ aopPut (AOP (result), zero, LSB);
+ }
}
- /* 1 <= shCount <= 7 */
- else {
- if(size == 1) {
- wassert(0);
- }
- else {
- shiftL2Left2Result(left, LSB, result, LSB, shCount);
- }
+ /* 1 <= shCount <= 7 */
+ else
+ {
+ if (size == 1)
+ {
+ wassert (0);
+ }
+ else
+ {
+ shiftL2Left2Result (left, LSB, result, LSB, shCount);
+ }
}
}
/*-----------------------------------------------------------------*/
/* genlshOne - left shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
-static void genlshOne (operand *result, operand *left, int shCount)
+static void
+genlshOne (operand * result, operand * left, int shCount)
{
- shiftL1Left2Result(left, LSB, result, LSB, shCount);
+ shiftL1Left2Result (left, LSB, result, LSB, shCount);
}
/*-----------------------------------------------------------------*/
/* genLeftShiftLiteral - left shifting by known count */
/*-----------------------------------------------------------------*/
-static void genLeftShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic)
+static void
+genLeftShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- freeAsmop(right,NULL,ic);
+ freeAsmop (right, NULL, ic);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, FALSE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
- size = getSize(operandType(result));
+ size = getSize (operandType (result));
#if VIEW_SIZE
- emitcode("; shift left ","result %d, left %d",size,
- AOP_SIZE(left));
+ emitcode ("; shift left ", "result %d, left %d", size,
+ AOP_SIZE (left));
#endif
- /* I suppose that the left size >= result size */
- if (shCount == 0) {
- wassert(0);
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ wassert (0);
}
- else if(shCount >= (size * 8))
- while(size--)
- aopPut(AOP(result),zero,size);
- else{
- switch (size) {
- case 1:
- genlshOne (result,left,shCount);
- break;
- case 2:
- genlshTwo (result,left,shCount);
- break;
- case 4:
- wassert(0);
- break;
- default:
- wassert(0);
- }
- }
- freeAsmop(left,NULL,ic);
- freeAsmop(result,NULL,ic);
+ else if (shCount >= (size * 8))
+ while (size--)
+ aopPut (AOP (result), zero, size);
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genlshOne (result, left, shCount);
+ break;
+ case 2:
+ genlshTwo (result, left, shCount);
+ break;
+ case 4:
+ wassert (0);
+ break;
+ default:
+ wassert (0);
+ }
+ }
+ freeAsmop (left, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genLeftShift - generates code for left shifting */
/*-----------------------------------------------------------------*/
-static void genLeftShift (iCode *ic)
+static void
+genLeftShift (iCode * ic)
{
- int size, offset;
- char *l;
- symbol *tlbl , *tlbl1;
- operand *left,*right, *result;
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE, FALSE);
-
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genLeftShiftLiteral (left,right,result,ic);
- return ;
- }
-
- /* shift count is unknown then we have to form a loop get the loop
- count in B : Note: we take only the lower order byte since
- shifting more that 32 bits make no sense anyway, ( the largest
- size of an object can be only 32 bits ) */
- emitcode("ld","a,%s",aopGet(AOP(right),0,FALSE));
- emitcode("inc","a");
- freeAsmop (right,NULL,ic);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, FALSE);
-
- /* now move the left to the result if they are not the
- same */
+ int size, offset;
+ char *l;
+ symbol *tlbl, *tlbl1;
+ operand *left, *right, *result;
+
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
+
+ aopOp (right, ic, FALSE, FALSE);
+
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genLeftShiftLiteral (left, right, result, ic);
+ return;
+ }
+
+ /* shift count is unknown then we have to form a loop get the loop
+ count in B : Note: we take only the lower order byte since
+ shifting more that 32 bits make no sense anyway, ( the largest
+ size of an object can be only 32 bits ) */
+ emitcode ("ld", "a,%s", aopGet (AOP (right), 0, FALSE));
+ emitcode ("inc", "a");
+ freeAsmop (right, NULL, ic);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
+
+ /* now move the left to the result if they are not the
+ same */
#if 1
- if (!sameRegs(AOP(left),AOP(result))) {
+ if (!sameRegs (AOP (left), AOP (result)))
+ {
- size = AOP_SIZE(result);
- offset = 0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE);
- aopPut(AOP(result),l,offset);
- offset++;
- }
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE);
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
}
#else
- size = AOP_SIZE(result);
- offset = 0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE);
- aopPut(AOP(result),l,offset);
- offset++;
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE);
+ aopPut (AOP (result), l, offset);
+ offset++;
}
#endif
- tlbl = newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = 0 ;
- tlbl1 = newiTempLabel(NULL);
+ tlbl = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = 0;
+ tlbl1 = newiTempLabel (NULL);
- emit2("!shortjp !tlabel", tlbl1->key+100);
- emitLabel(tlbl->key+100);
- l = aopGet(AOP(result),offset,FALSE);
- emitcode("or", "a,a");
- while (size--) {
- l = aopGet(AOP(result),offset++,FALSE);
- emitcode("rl","%s", l);
+ emit2 ("!shortjp !tlabel", tlbl1->key + 100);
+ emitLabel (tlbl->key + 100);
+ l = aopGet (AOP (result), offset, FALSE);
+ emitcode ("or", "a,a");
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset++, FALSE);
+ emitcode ("rl", "%s", l);
}
- emitLabel(tlbl1->key+100);
- emitcode("dec", "a");
- emit2("!shortjp nz,!tlabel", tlbl->key+100);
+ emitLabel (tlbl1->key + 100);
+ emitcode ("dec", "a");
+ emit2 ("!shortjp nz,!tlabel", tlbl->key + 100);
- freeAsmop(left,NULL,ic);
- freeAsmop(result,NULL,ic);
+ freeAsmop (left, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genrshOne - left shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshOne (operand *result,operand *left, int shCount)
+static void
+genrshOne (operand * result, operand * left, int shCount)
{
- /* Errk */
- int size = AOP_SIZE(result);
- char *l;
+ /* Errk */
+ int size = AOP_SIZE (result);
+ char *l;
- wassert(size==1);
- wassert(shCount<8);
+ wassert (size == 1);
+ wassert (shCount < 8);
- l = aopGet(AOP(left),0,FALSE);
- if (AOP(result)->type == AOP_REG) {
- aopPut(AOP(result), l, 0);
- l = aopGet(AOP(result), 0, FALSE);
- while (shCount--)
- emitcode("srl", "%s", l);
+ l = aopGet (AOP (left), 0, FALSE);
+ if (AOP (result)->type == AOP_REG)
+ {
+ aopPut (AOP (result), l, 0);
+ l = aopGet (AOP (result), 0, FALSE);
+ while (shCount--)
+ emitcode ("srl", "%s", l);
}
- else {
- MOVA(l);
- while (shCount--) {
- emitcode("srl", "a");
- }
- aopPut(AOP(result),"a",0);
+ else
+ {
+ MOVA (l);
+ while (shCount--)
+ {
+ emitcode ("srl", "a");
+ }
+ aopPut (AOP (result), "a", 0);
}
}
/*-----------------------------------------------------------------*/
/* AccRsh - right shift accumulator by known count */
/*-----------------------------------------------------------------*/
-static void AccRsh (int shCount)
+static void
+AccRsh (int shCount)
{
- if(shCount != 0){
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- emit2("and a,!immedbyte", SRMask[shCount]);
+ if (shCount != 0)
+ {
+ /* rotate right accumulator */
+ AccRol (8 - shCount);
+ /* and kill the higher order bits */
+ emit2 ("and a,!immedbyte", SRMask[shCount]);
}
}
/*-----------------------------------------------------------------*/
/* shiftR1Left2Result - shift right one byte from left to result */
/*-----------------------------------------------------------------*/
-static void shiftR1Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
+static void
+shiftR1Left2Result (operand * left, int offl,
+ operand * result, int offr,
+ int shCount, int sign)
{
- MOVA(aopGet(AOP(left),offl,FALSE));
- if (sign) {
- wassert(0);
+ MOVA (aopGet (AOP (left), offl, FALSE));
+ if (sign)
+ {
+ wassert (0);
}
- else {
- AccRsh(shCount);
+ else
+ {
+ AccRsh (shCount);
}
- aopPut(AOP(result),"a",offr);
+ aopPut (AOP (result), "a", offr);
}
/*-----------------------------------------------------------------*/
/* genrshTwo - right shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
-static void genrshTwo (operand *result,operand *left,
- int shCount, int sign)
+static void
+genrshTwo (operand * result, operand * left,
+ int shCount, int sign)
{
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8;
- if (shCount) {
- shiftR1Left2Result(left, MSB16, result, LSB,
- shCount, sign);
- }
- else {
- movLeft2Result(left, MSB16, result, LSB, sign);
- }
- aopPut(AOP(result),zero,1);
+ /* if shCount >= 8 */
+ if (shCount >= 8)
+ {
+ shCount -= 8;
+ if (shCount)
+ {
+ shiftR1Left2Result (left, MSB16, result, LSB,
+ shCount, sign);
+ }
+ else
+ {
+ movLeft2Result (left, MSB16, result, LSB, sign);
+ }
+ aopPut (AOP (result), zero, 1);
}
- /* 1 <= shCount <= 7 */
- else {
- shiftR2Left2Result(left, LSB, result, LSB, shCount, sign);
+ /* 1 <= shCount <= 7 */
+ else
+ {
+ shiftR2Left2Result (left, LSB, result, LSB, shCount, sign);
}
}
/*-----------------------------------------------------------------*/
/* genRightShiftLiteral - left shifting by known count */
/*-----------------------------------------------------------------*/
-static void genRightShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic)
+static void
+genRightShiftLiteral (operand * left,
+ operand * right,
+ operand * result,
+ iCode * ic)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
- int size;
+ int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+ int size;
- freeAsmop(right,NULL,ic);
+ freeAsmop (right, NULL, ic);
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, FALSE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
- size = getSize(operandType(result));
+ size = getSize (operandType (result));
- emitcode("; shift right ","result %d, left %d",size,
- AOP_SIZE(left));
+ emitcode ("; shift right ", "result %d, left %d", size,
+ AOP_SIZE (left));
- /* I suppose that the left size >= result size */
- if (shCount == 0) {
- wassert(0);
+ /* I suppose that the left size >= result size */
+ if (shCount == 0)
+ {
+ wassert (0);
}
- else if(shCount >= (size * 8))
- while(size--)
- aopPut(AOP(result),zero,size);
- else{
- switch (size) {
- case 1:
- genrshOne(result, left, shCount);
- break;
- case 2:
- /* PENDING: sign support */
- genrshTwo(result, left, shCount, FALSE);
- break;
- case 4:
- wassert(0);
- break;
- default:
- wassert(0);
- }
- }
- freeAsmop(left,NULL,ic);
- freeAsmop(result,NULL,ic);
+ else if (shCount >= (size * 8))
+ while (size--)
+ aopPut (AOP (result), zero, size);
+ else
+ {
+ switch (size)
+ {
+ case 1:
+ genrshOne (result, left, shCount);
+ break;
+ case 2:
+ /* PENDING: sign support */
+ genrshTwo (result, left, shCount, FALSE);
+ break;
+ case 4:
+ wassert (0);
+ break;
+ default:
+ wassert (0);
+ }
+ }
+ freeAsmop (left, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genRightShift - generate code for right shifting */
/*-----------------------------------------------------------------*/
-static void genRightShift (iCode *ic)
+static void
+genRightShift (iCode * ic)
{
- operand *right, *left, *result;
- sym_link *retype ;
- int size, offset, first = 1;
- char *l;
- bool is_signed;
+ operand *right, *left, *result;
+ sym_link *retype;
+ int size, offset, first = 1;
+ char *l;
+ bool is_signed;
- symbol *tlbl, *tlbl1 ;
+ symbol *tlbl, *tlbl1;
- /* if signed then we do it the hard way preserve the
- sign bit moving it inwards */
- retype = getSpec(operandType(IC_RESULT(ic)));
+ /* if signed then we do it the hard way preserve the
+ sign bit moving it inwards */
+ retype = getSpec (operandType (IC_RESULT (ic)));
- is_signed = !SPEC_USIGN(retype);
+ is_signed = !SPEC_USIGN (retype);
- /* signed & unsigned types are treated the same : i.e. the
- signed is NOT propagated inwards : quoting from the
- ANSI - standard : "for E1 >> E2, is equivalent to division
- by 2**E2 if unsigned or if it has a non-negative value,
- otherwise the result is implementation defined ", MY definition
- is that the sign does not get propagated */
+ /* signed & unsigned types are treated the same : i.e. the
+ signed is NOT propagated inwards : quoting from the
+ ANSI - standard : "for E1 >> E2, is equivalent to division
+ by 2**E2 if unsigned or if it has a non-negative value,
+ otherwise the result is implementation defined ", MY definition
+ is that the sign does not get propagated */
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
+ right = IC_RIGHT (ic);
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- aopOp(right,ic,FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genRightShiftLiteral(left,right,result,ic);
- return;
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE (right) == AOP_LIT)
+ {
+ genRightShiftLiteral (left, right, result, ic);
+ return;
}
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, FALSE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
- /* now move the left to the result if they are not the
- same */
- if (!sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
+ /* now move the left to the result if they are not the
+ same */
+ if (!sameRegs (AOP (left), AOP (result)) &&
+ AOP_SIZE (result) > 1)
+ {
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE);
- aopPut(AOP(result),l,offset);
- offset++;
- }
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ l = aopGet (AOP (left), offset, FALSE);
+ aopPut (AOP (result), l, offset);
+ offset++;
+ }
}
- emitcode("ld", "a,%s",aopGet(AOP(right),0,FALSE));
- emitcode("inc","a");
- freeAsmop (right, NULL, ic);
+ emitcode ("ld", "a,%s", aopGet (AOP (right), 0, FALSE));
+ emitcode ("inc", "a");
+ freeAsmop (right, NULL, ic);
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
- size = AOP_SIZE(result);
- offset = size - 1;
+ tlbl = newiTempLabel (NULL);
+ tlbl1 = newiTempLabel (NULL);
+ size = AOP_SIZE (result);
+ offset = size - 1;
- emit2("!shortjp !tlabel", tlbl1->key+100);
- emitLabel(tlbl->key+100);
- while (size--) {
- l = aopGet(AOP(result),offset--,FALSE);
- if (first) {
- if (is_signed)
- emitcode("sra", "%s", l);
+ emit2 ("!shortjp !tlabel", tlbl1->key + 100);
+ emitLabel (tlbl->key + 100);
+ while (size--)
+ {
+ l = aopGet (AOP (result), offset--, FALSE);
+ if (first)
+ {
+ if (is_signed)
+ emitcode ("sra", "%s", l);
+ else
+ emitcode ("srl", "%s", l);
+ first = 0;
+ }
else
- emitcode("srl", "%s", l);
- first = 0;
- }
- else
- emitcode("rr", "%s", l);
+ emitcode ("rr", "%s", l);
}
- emitLabel(tlbl1->key+100);
- emitcode("dec", "a");
- emit2("!shortjp nz,!tlabel", tlbl->key+100);
+ emitLabel (tlbl1->key + 100);
+ emitcode ("dec", "a");
+ emit2 ("!shortjp nz,!tlabel", tlbl->key + 100);
- freeAsmop(left,NULL,ic);
- freeAsmop(result,NULL,ic);
+ freeAsmop (left, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genGenPointerGet - get value from generic pointer space */
/*-----------------------------------------------------------------*/
-static void genGenPointerGet (operand *left,
- operand *result, iCode *ic)
+static void
+genGenPointerGet (operand * left,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
- int pair = PAIR_HL;
+ int size, offset;
+ sym_link *retype = getSpec (operandType (result));
+ int pair = PAIR_HL;
- if (IS_GB)
- pair = PAIR_DE;
+ if (IS_GB)
+ pair = PAIR_DE;
- aopOp(left,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, FALSE);
+ aopOp (left, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
- if (isPair(AOP(left)) && AOP_SIZE(result)==1) {
- /* Just do it */
- if (isPtrPair(AOP(left)))
- {
- tsprintf(buffer, "!*pair", getPairName(AOP(left)));
- aopPut(AOP(result), buffer, 0);
- }
- else {
- emit2("ld a,!*pair", getPairName(AOP(left)));
- aopPut(AOP(result),"a", 0);
- }
- freeAsmop(left,NULL,ic);
- goto release;
+ if (isPair (AOP (left)) && AOP_SIZE (result) == 1)
+ {
+ /* Just do it */
+ if (isPtrPair (AOP (left)))
+ {
+ tsprintf (buffer, "!*pair", getPairName (AOP (left)));
+ aopPut (AOP (result), buffer, 0);
+ }
+ else
+ {
+ emit2 ("ld a,!*pair", getPairName (AOP (left)));
+ aopPut (AOP (result), "a", 0);
+ }
+ freeAsmop (left, NULL, ic);
+ goto release;
}
- /* For now we always load into IY */
- /* if this is remateriazable */
- fetchPair(pair, AOP(left));
+ /* For now we always load into IY */
+ /* if this is remateriazable */
+ fetchPair (pair, AOP (left));
- /* so iy now contains the address */
- freeAsmop(left,NULL,ic);
+ /* so iy now contains the address */
+ freeAsmop (left, NULL, ic);
- /* if bit then unpack */
- if (IS_BITVAR(retype)) {
- wassert(0);
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ {
+ wassert (0);
}
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- /* PENDING: make this better */
- if (!IS_GB && AOP(result)->type == AOP_REG) {
- aopPut(AOP(result), "!*hl", offset++);
- }
- else {
- emit2("ld a,!*pair", _pairs[pair].name);
- aopPut(AOP(result),"a",offset++);
- }
- if (size) {
- emit2("inc %s", _pairs[pair].name);
- _G.pairs[pair].offset++;
- }
- }
+ else
+ {
+ size = AOP_SIZE (result);
+ offset = 0;
+
+ while (size--)
+ {
+ /* PENDING: make this better */
+ if (!IS_GB && AOP (result)->type == AOP_REG)
+ {
+ aopPut (AOP (result), "!*hl", offset++);
+ }
+ else
+ {
+ emit2 ("ld a,!*pair", _pairs[pair].name);
+ aopPut (AOP (result), "a", offset++);
+ }
+ if (size)
+ {
+ emit2 ("inc %s", _pairs[pair].name);
+ _G.pairs[pair].offset++;
+ }
+ }
}
- release:
- freeAsmop(result,NULL,ic);
+release:
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
-static void genPointerGet (iCode *ic)
+static void
+genPointerGet (iCode * ic)
{
- operand *left, *result ;
- sym_link *type, *etype;
+ operand *left, *result;
+ sym_link *type, *etype;
- left = IC_LEFT(ic);
- result = IC_RESULT(ic) ;
+ left = IC_LEFT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(left);
- etype = getSpec(type);
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (left);
+ etype = getSpec (type);
- genGenPointerGet (left,result,ic);
+ genGenPointerGet (left, result, ic);
}
-bool isRegOrLit(asmop *aop)
+bool
+isRegOrLit (asmop * aop)
{
- if (aop->type == AOP_REG || aop->type == AOP_LIT || aop->type == AOP_IMMD)
- return TRUE;
- return FALSE;
+ if (aop->type == AOP_REG || aop->type == AOP_LIT || aop->type == AOP_IMMD)
+ return TRUE;
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* genGenPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
-static void genGenPointerSet (operand *right,
- operand *result, iCode *ic)
+static void
+genGenPointerSet (operand * right,
+ operand * result, iCode * ic)
{
- int size, offset ;
- sym_link *retype = getSpec(operandType(right));
- PAIR_ID pairId = PAIR_HL;
-
- aopOp(result,ic,FALSE, FALSE);
- aopOp(right,ic,FALSE, FALSE);
-
- if (IS_GB)
- pairId = PAIR_DE;
-
- /* Handle the exceptions first */
- if (isPair(AOP(result)) && (AOP_SIZE(right)==1)) {
- /* Just do it */
- char *l = aopGet(AOP(right), 0, FALSE);
- const char *pair = getPairName(AOP(result));
- if (canAssignToPtr(l) && isPtr(pair)) {
- emit2("ld !*pair,%s", pair, l);
- }
- else {
- MOVA(l);
- emit2("ld !*pair,a", pair);
- }
- goto release;
- }
+ int size, offset;
+ sym_link *retype = getSpec (operandType (right));
+ PAIR_ID pairId = PAIR_HL;
+
+ aopOp (result, ic, FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
+
+ if (IS_GB)
+ pairId = PAIR_DE;
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(result) != AOP_STR) {
- fetchPair(pairId, AOP(result));
+ /* Handle the exceptions first */
+ if (isPair (AOP (result)) && (AOP_SIZE (right) == 1))
+ {
+ /* Just do it */
+ char *l = aopGet (AOP (right), 0, FALSE);
+ const char *pair = getPairName (AOP (result));
+ if (canAssignToPtr (l) && isPtr (pair))
+ {
+ emit2 ("ld !*pair,%s", pair, l);
+ }
+ else
+ {
+ MOVA (l);
+ emit2 ("ld !*pair,a", pair);
+ }
+ goto release;
}
- /* so hl know contains the address */
- freeAsmop(result,NULL,ic);
- /* if bit then unpack */
- if (IS_BITVAR(retype)) {
- wassert(0);
+ /* if the operand is already in dptr
+ then we do nothing else we move the value to dptr */
+ if (AOP_TYPE (result) != AOP_STR)
+ {
+ fetchPair (pairId, AOP (result));
}
- else {
- size = AOP_SIZE(right);
- offset = 0 ;
+ /* so hl know contains the address */
+ freeAsmop (result, NULL, ic);
- while (size--) {
- char *l = aopGet(AOP(right),offset,FALSE);
- if (isRegOrLit(AOP(right)) && !IS_GB) {
- emit2("ld !*pair,%s", _pairs[pairId].name, l);
- }
- else {
- MOVA(l);
- emit2("ld !*pair,a", _pairs[pairId].name);
- }
- if (size) {
- emitcode("inc", _pairs[pairId].name);
- _G.pairs[pairId].offset++;
- }
- offset++;
- }
+ /* if bit then unpack */
+ if (IS_BITVAR (retype))
+ {
+ wassert (0);
}
- release:
- freeAsmop(right,NULL,ic);
+ else
+ {
+ size = AOP_SIZE (right);
+ offset = 0;
+
+ while (size--)
+ {
+ char *l = aopGet (AOP (right), offset, FALSE);
+ if (isRegOrLit (AOP (right)) && !IS_GB)
+ {
+ emit2 ("ld !*pair,%s", _pairs[pairId].name, l);
+ }
+ else
+ {
+ MOVA (l);
+ emit2 ("ld !*pair,a", _pairs[pairId].name);
+ }
+ if (size)
+ {
+ emitcode ("inc", _pairs[pairId].name);
+ _G.pairs[pairId].offset++;
+ }
+ offset++;
+ }
+ }
+release:
+ freeAsmop (right, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
-static void genPointerSet (iCode *ic)
+static void
+genPointerSet (iCode * ic)
{
- operand *right, *result ;
- sym_link *type, *etype;
+ operand *right, *result;
+ sym_link *type, *etype;
- right = IC_RIGHT(ic);
- result = IC_RESULT(ic) ;
+ right = IC_RIGHT (ic);
+ result = IC_RESULT (ic);
- /* depending on the type of pointer we need to
- move it to the correct pointer register */
- type = operandType(result);
- etype = getSpec(type);
+ /* depending on the type of pointer we need to
+ move it to the correct pointer register */
+ type = operandType (result);
+ etype = getSpec (type);
- genGenPointerSet (right,result,ic);
+ genGenPointerSet (right, result, ic);
}
/*-----------------------------------------------------------------*/
/* genIfx - generate code for Ifx statement */
/*-----------------------------------------------------------------*/
-static void genIfx (iCode *ic, iCode *popIc)
+static void
+genIfx (iCode * ic, iCode * popIc)
{
- operand *cond = IC_COND(ic);
- int isbit =0;
-
- aopOp(cond,ic,FALSE, TRUE);
-
- /* get the value into acc */
- if (AOP_TYPE(cond) != AOP_CRY)
- toBoolean(cond);
- else
- isbit = 1;
- /* the result is now in the accumulator */
- freeAsmop(cond,NULL,ic);
-
- /* 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);
+ operand *cond = IC_COND (ic);
+ int isbit = 0;
+
+ aopOp (cond, ic, FALSE, TRUE);
+
+ /* get the value into acc */
+ if (AOP_TYPE (cond) != AOP_CRY)
+ toBoolean (cond);
else
- genIfxJump(ic,"a");
+ isbit = 1;
+ /* the result is now in the accumulator */
+ freeAsmop (cond, NULL, ic);
+
+ /* 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");
- ic->generated = 1;
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/* genAddrOf - generates code for address of */
/*-----------------------------------------------------------------*/
-static void genAddrOf (iCode *ic)
+static void
+genAddrOf (iCode * ic)
{
- symbol *sym = OP_SYMBOL(IC_LEFT(ic));
-
- aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
-
- /* if the operand is on the stack then we
- need to get the stack offset of this
- variable */
- if (IS_GB) {
- if (sym->onStack) {
- spillCached();
- if (sym->stack <= 0) {
- emit2("!ldahlsp", sym->stack + _G.stack.pushed + _G.stack.offset);
- }
- else {
- emit2("!ldahlsp", sym->stack + _G.stack.pushed + _G.stack.offset + _G.stack.param_offset);
- }
- emitcode("ld", "d,h");
- emitcode("ld", "e,l");
- }
- else {
- emit2("ld de,!hashedstr", sym->rname);
- }
- aopPut(AOP(IC_RESULT(ic)), "e", 0);
- aopPut(AOP(IC_RESULT(ic)), "d", 1);
- }
- else {
- spillCached();
- if (sym->onStack) {
- /* if it has an offset then we need to compute it */
- if (sym->stack > 0)
- emitcode("ld", "hl,#%d+%d+%d+%d", sym->stack, _G.stack.pushed, _G.stack.offset, _G.stack.param_offset);
+ symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+
+ /* if the operand is on the stack then we
+ need to get the stack offset of this
+ variable */
+ if (IS_GB)
+ {
+ if (sym->onStack)
+ {
+ spillCached ();
+ if (sym->stack <= 0)
+ {
+ emit2 ("!ldahlsp", sym->stack + _G.stack.pushed + _G.stack.offset);
+ }
+ else
+ {
+ emit2 ("!ldahlsp", sym->stack + _G.stack.pushed + _G.stack.offset + _G.stack.param_offset);
+ }
+ emitcode ("ld", "d,h");
+ emitcode ("ld", "e,l");
+ }
else
- emitcode("ld", "hl,#%d+%d+%d", sym->stack, _G.stack.pushed, _G.stack.offset);
- emitcode("add", "hl,sp");
- }
- else {
- emitcode("ld", "hl,#%s", sym->rname);
- }
- aopPut(AOP(IC_RESULT(ic)), "l", 0);
- aopPut(AOP(IC_RESULT(ic)), "h", 1);
+ {
+ emit2 ("ld de,!hashedstr", sym->rname);
+ }
+ aopPut (AOP (IC_RESULT (ic)), "e", 0);
+ aopPut (AOP (IC_RESULT (ic)), "d", 1);
}
- freeAsmop(IC_RESULT(ic),NULL,ic);
+ else
+ {
+ spillCached ();
+ if (sym->onStack)
+ {
+ /* if it has an offset then we need to compute it */
+ if (sym->stack > 0)
+ emitcode ("ld", "hl,#%d+%d+%d+%d", sym->stack, _G.stack.pushed, _G.stack.offset, _G.stack.param_offset);
+ else
+ emitcode ("ld", "hl,#%d+%d+%d", sym->stack, _G.stack.pushed, _G.stack.offset);
+ emitcode ("add", "hl,sp");
+ }
+ else
+ {
+ emitcode ("ld", "hl,#%s", sym->rname);
+ }
+ aopPut (AOP (IC_RESULT (ic)), "l", 0);
+ aopPut (AOP (IC_RESULT (ic)), "h", 1);
+ }
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genAssign - generate code for assignment */
/*-----------------------------------------------------------------*/
-static void genAssign (iCode *ic)
+static void
+genAssign (iCode * ic)
{
- operand *result, *right;
- int size, offset ;
- unsigned long lit = 0L;
+ operand *result, *right;
+ int size, offset;
+ unsigned long lit = 0L;
- result = IC_RESULT(ic);
- right = IC_RIGHT(ic) ;
+ result = IC_RESULT (ic);
+ right = IC_RIGHT (ic);
#if 1
- /* Dont bother assigning if they are the same */
- if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic))) {
- emitcode("", "; (operands are equal %u)", operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)));
- return;
+ /* Dont bother assigning if they are the same */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ {
+ emitcode ("", "; (operands are equal %u)", operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)));
+ return;
}
#endif
- aopOp(right,ic,FALSE, FALSE);
- aopOp(result,ic,TRUE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
+ aopOp (result, ic, TRUE, FALSE);
- /* if they are the same registers */
- if (sameRegs(AOP(right),AOP(result))) {
- emitcode("", "; (registers are the same)");
- goto release;
+ /* if they are the same registers */
+ if (sameRegs (AOP (right), AOP (result)))
+ {
+ emitcode ("", "; (registers are the same)");
+ goto release;
}
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
- wassert(0);
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ wassert (0);
}
- /* general case */
- size = AOP_SIZE(result);
- offset = 0;
-
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if (isPair(AOP(result))) {
- fetchPair(getPairId(AOP(result)), AOP(right));
- }
- else if((size > 1) &&
- (AOP_TYPE(result) != AOP_REG) &&
- (AOP_TYPE(right) == AOP_LIT) &&
- !IS_FLOAT(operandType(right)) &&
- (lit < 256L)) {
- bool fXored = FALSE;
+ /* general case */
+ size = AOP_SIZE (result);
offset = 0;
- /* Work from the top down.
- Done this way so that we can use the cached copy of 0
- in A for a fast clear */
- while (size--) {
- if((unsigned int)((lit >> (offset*8)) & 0x0FFL)== 0) {
- if (!fXored && size>1) {
- emitcode("xor", "a,a");
- fXored = TRUE;
- }
- if (fXored) {
- aopPut(AOP(result),"a",offset);
- }
- else {
- aopPut(AOP(result), zero, offset);
+
+ if (AOP_TYPE (right) == AOP_LIT)
+ lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+ if (isPair (AOP (result)))
+ {
+ fetchPair (getPairId (AOP (result)), AOP (right));
}
- }
- else
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE),
- offset);
- offset++;
- }
+ else if ((size > 1) &&
+ (AOP_TYPE (result) != AOP_REG) &&
+ (AOP_TYPE (right) == AOP_LIT) &&
+ !IS_FLOAT (operandType (right)) &&
+ (lit < 256L))
+ {
+ bool fXored = FALSE;
+ offset = 0;
+ /* Work from the top down.
+ Done this way so that we can use the cached copy of 0
+ in A for a fast clear */
+ while (size--)
+ {
+ if ((unsigned int) ((lit >> (offset * 8)) & 0x0FFL) == 0)
+ {
+ if (!fXored && size > 1)
+ {
+ emitcode ("xor", "a,a");
+ fXored = TRUE;
+ }
+ if (fXored)
+ {
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ {
+ aopPut (AOP (result), zero, offset);
+ }
+ }
+ else
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE),
+ offset);
+ offset++;
+ }
+ }
+ else if (size == 2 && requiresHL (AOP (right)) && requiresHL (AOP (result)) && IS_GB)
+ {
+ /* Special case. Load into a and d, then load out. */
+ MOVA (aopGet (AOP (right), 0, FALSE));
+ emitcode ("ld", "e,%s", aopGet (AOP (right), 1, FALSE));
+ aopPut (AOP (result), "a", 0);
+ aopPut (AOP (result), "e", 1);
}
- else if (size == 2 && requiresHL(AOP(right)) && requiresHL(AOP(result)) && IS_GB) {
- /* Special case. Load into a and d, then load out. */
- MOVA(aopGet(AOP(right), 0, FALSE));
- emitcode("ld", "e,%s", aopGet(AOP(right), 1, FALSE));
- aopPut(AOP(result), "a", 0);
- aopPut(AOP(result), "e", 1);
- } else {
- while (size--) {
- /* PENDING: do this check better */
- if (requiresHL(AOP(right)) && requiresHL(AOP(result))) {
- MOVA(aopGet(AOP(right), offset, FALSE));
- aopPut(AOP(result), "a", offset);
- }
- else
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE),
- offset);
- offset++;
- }
+ else
+ {
+ while (size--)
+ {
+ /* PENDING: do this check better */
+ if (requiresHL (AOP (right)) && requiresHL (AOP (result)))
+ {
+ MOVA (aopGet (AOP (right), offset, FALSE));
+ aopPut (AOP (result), "a", offset);
+ }
+ else
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE),
+ offset);
+ offset++;
+ }
}
release:
- freeAsmop(right,NULL,ic);
- freeAsmop(result,NULL,ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genJumpTab - genrates code for jump table */
/*-----------------------------------------------------------------*/
-static void genJumpTab (iCode *ic)
+static void
+genJumpTab (iCode * ic)
{
- symbol *jtab;
- char *l;
+ symbol *jtab;
+ char *l;
- aopOp(IC_JTCOND(ic),ic,FALSE, FALSE);
- /* get the condition into accumulator */
- l = aopGet(AOP(IC_JTCOND(ic)),0,FALSE);
- if (!IS_GB)
- emitcode("push", "de");
- emitcode("ld", "e,%s", l);
- emit2("ld d,!zero");
- jtab = newiTempLabel(NULL);
- spillCached();
- emit2("ld hl,!immed!tlabel", jtab->key+100);
- emitcode("add", "hl,de");
- emitcode("add", "hl,de");
- emitcode("add", "hl,de");
- freeAsmop(IC_JTCOND(ic),NULL,ic);
- if (!IS_GB)
- emitcode("pop", "de");
- emit2("jp !*hl");
- emitLabel(jtab->key+100);
- /* now generate the jump labels */
- for (jtab = setFirstItem(IC_JTLABELS(ic)) ; jtab;
- jtab = setNextItem(IC_JTLABELS(ic)))
- emit2("jp !tlabel", jtab->key+100);
+ aopOp (IC_JTCOND (ic), ic, FALSE, FALSE);
+ /* get the condition into accumulator */
+ l = aopGet (AOP (IC_JTCOND (ic)), 0, FALSE);
+ if (!IS_GB)
+ emitcode ("push", "de");
+ emitcode ("ld", "e,%s", l);
+ emit2 ("ld d,!zero");
+ jtab = newiTempLabel (NULL);
+ spillCached ();
+ emit2 ("ld hl,!immed!tlabel", jtab->key + 100);
+ emitcode ("add", "hl,de");
+ emitcode ("add", "hl,de");
+ emitcode ("add", "hl,de");
+ freeAsmop (IC_JTCOND (ic), NULL, ic);
+ if (!IS_GB)
+ emitcode ("pop", "de");
+ emit2 ("jp !*hl");
+ emitLabel (jtab->key + 100);
+ /* now generate the jump labels */
+ for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
+ jtab = setNextItem (IC_JTLABELS (ic)))
+ emit2 ("jp !tlabel", jtab->key + 100);
}
/*-----------------------------------------------------------------*/
/* genCast - gen code for casting */
/*-----------------------------------------------------------------*/
-static void genCast (iCode *ic)
+static void
+genCast (iCode * ic)
{
- operand *result = IC_RESULT(ic);
- sym_link *ctype = operandType(IC_LEFT(ic));
- operand *right = IC_RIGHT(ic);
- int size, offset ;
+ operand *result = IC_RESULT (ic);
+ sym_link *ctype = operandType (IC_LEFT (ic));
+ operand *right = IC_RIGHT (ic);
+ int size, offset;
- /* if they are equivalent then do nothing */
- if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
+ /* if they are equivalent then do nothing */
+ if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+ return;
- aopOp(right,ic,FALSE, FALSE);
- aopOp(result,ic,FALSE, FALSE);
+ aopOp (right, ic, FALSE, FALSE);
+ aopOp (result, ic, FALSE, FALSE);
- /* if the result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
- wassert(0);
+ /* if the result is a bit */
+ if (AOP_TYPE (result) == AOP_CRY)
+ {
+ wassert (0);
}
- /* if they are the same size : or less */
- if (AOP_SIZE(result) <= AOP_SIZE(right)) {
-
- /* if they are in the same place */
- if (sameRegs(AOP(right),AOP(result)))
- goto release;
+ /* if they are the same size : or less */
+ if (AOP_SIZE (result) <= AOP_SIZE (right))
+ {
- /* if they in different places then copy */
- size = AOP_SIZE(result);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE),
- offset);
- offset++;
- }
- goto release;
+ /* if they are in the same place */
+ if (sameRegs (AOP (right), AOP (result)))
+ goto release;
+
+ /* if they in different places then copy */
+ size = AOP_SIZE (result);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE),
+ offset);
+ offset++;
+ }
+ goto release;
}
- /* PENDING: should be OK. */
+ /* PENDING: should be OK. */
#if 0
- /* if the result is of type pointer */
- if (IS_PTR(ctype)) {
- wassert(0);
+ /* if the result is of type pointer */
+ if (IS_PTR (ctype))
+ {
+ wassert (0);
}
#endif
- /* so we now know that the size of destination is greater
- than the size of the source */
- /* we move to result for the size of source */
- size = AOP_SIZE(right);
- offset = 0 ;
- while (size--) {
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE),
- offset);
- offset++;
- }
-
- /* now depending on the sign of the destination */
- size = AOP_SIZE(result) - AOP_SIZE(right);
- /* Unsigned or not an integral type - right fill with zeros */
- if (SPEC_USIGN(ctype) || !IS_SPEC(ctype)) {
- while (size--)
- aopPut(AOP(result),zero,offset++);
- } else {
- /* we need to extend the sign :{ */
- char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,
- FALSE);
- MOVA(l);
- emitcode("", "; genCast: sign extend untested.");
- emitcode("rla", "");
- emitcode("sbc", "a,a");
- while (size--)
- aopPut(AOP(result),"a",offset++);
+ /* so we now know that the size of destination is greater
+ than the size of the source */
+ /* we move to result for the size of source */
+ size = AOP_SIZE (right);
+ offset = 0;
+ while (size--)
+ {
+ aopPut (AOP (result),
+ aopGet (AOP (right), offset, FALSE),
+ offset);
+ offset++;
+ }
+
+ /* now depending on the sign of the destination */
+ size = AOP_SIZE (result) - AOP_SIZE (right);
+ /* Unsigned or not an integral type - right fill with zeros */
+ if (SPEC_USIGN (ctype) || !IS_SPEC (ctype))
+ {
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ }
+ else
+ {
+ /* we need to extend the sign :{ */
+ char *l = aopGet (AOP (right), AOP_SIZE (right) - 1,
+ FALSE);
+ MOVA (l);
+ emitcode ("", "; genCast: sign extend untested.");
+ emitcode ("rla", "");
+ emitcode ("sbc", "a,a");
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
}
release:
- freeAsmop(right, NULL, ic);
- freeAsmop(result, NULL, ic);
+ freeAsmop (right, NULL, ic);
+ freeAsmop (result, NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genReceive - generate code for a receive iCode */
/*-----------------------------------------------------------------*/
-static void genReceive (iCode *ic)
+static void
+genReceive (iCode * ic)
{
- if (isOperandInFarSpace(IC_RESULT(ic)) &&
- ( OP_SYMBOL(IC_RESULT(ic))->isspilt ||
- IS_TRUE_SYMOP(IC_RESULT(ic))) ) {
- wassert(0);
- } else {
- accInUse++;
- aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
- accInUse--;
- assignResultValue(IC_RESULT(ic));
- }
-
- freeAsmop(IC_RESULT(ic),NULL,ic);
+ if (isOperandInFarSpace (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
+ IS_TRUE_SYMOP (IC_RESULT (ic))))
+ {
+ wassert (0);
+ }
+ else
+ {
+ accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+ accInUse--;
+ assignResultValue (IC_RESULT (ic));
+ }
+
+ freeAsmop (IC_RESULT (ic), NULL, ic);
}
/*-----------------------------------------------------------------*/
/* genZ80Code - generate code for Z80 based controllers */
/*-----------------------------------------------------------------*/
-void genZ80Code (iCode *lic)
+void
+genZ80Code (iCode * lic)
{
- iCode *ic;
- int cln = 0;
+ iCode *ic;
+ int cln = 0;
- /* HACK */
- if (IS_GB) {
- _fReturn = _gbz80_return;
- _fTmp = _gbz80_return;
- }
- else {
- _fReturn = _z80_return;
- _fTmp = _z80_return;
+ /* HACK */
+ if (IS_GB)
+ {
+ _fReturn = _gbz80_return;
+ _fTmp = _gbz80_return;
}
- tsprintf(zero, "!zero");
-
- lineHead = lineCurr = NULL;
-
- /* if debug information required */
- if (options.debug && currFunc) {
- cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
- debugLine = 1;
- if (IS_STATIC(currFunc->etype))
- emitcode("","F%s$%s$0$0 ==.",moduleName,currFunc->name);
else
- emitcode("","G$%s$0$0 ==.",currFunc->name);
- debugLine = 0;
+ {
+ _fReturn = _z80_return;
+ _fTmp = _z80_return;
}
- /* stack pointer name */
- spname = "sp";
+ tsprintf (zero, "!zero");
+ lineHead = lineCurr = NULL;
- for (ic = lic ; ic ; ic = ic->next ) {
-
- if ( cln != ic->lineno ) {
- if ( options.debug ) {
- debugLine = 1;
- emitcode("","C$%s$%d$%d$%d ==.",
- FileBaseName(ic->filename),ic->lineno,
- ic->level,ic->block);
- debugLine = 0;
- }
- emitcode(";","%s %d",ic->filename,ic->lineno);
- cln = ic->lineno ;
- }
- /* if the result is marked as
- spilt and rematerializable or code for
- this has already been generated then
- do nothing */
- if (resultRemat(ic) || ic->generated )
- continue ;
-
- /* depending on the operation */
- switch (ic->op) {
- case '!' :
- emitcode("", "; genNot");
- genNot(ic);
- break;
-
- case '~' :
- emitcode("", "; genCpl");
- genCpl(ic);
- break;
-
- case UNARYMINUS:
- emitcode("", "; genUminus");
- genUminus (ic);
- break;
-
- case IPUSH:
- emitcode("", "; genIpush");
- genIpush (ic);
- break;
-
- case IPOP:
- /* IPOP happens only when trying to restore a
- spilt live range, if there is an ifx statement
- following this pop then the if statement might
- be using some of the registers being popped which
- would destory the contents of the register so
- we need to check for this condition and handle it */
- if (ic->next &&
- ic->next->op == IFX &&
- regsInCommon(IC_LEFT(ic),IC_COND(ic->next))) {
- emitcode("", "; genIfx");
- genIfx (ic->next,ic);
- }
- else {
- emitcode("", "; genIpop");
- genIpop (ic);
- }
- break;
-
- case CALL:
- emitcode("", "; genCall");
- genCall (ic);
- break;
-
- case PCALL:
- emitcode("", "; genPcall");
- genPcall (ic);
- break;
-
- case FUNCTION:
- emitcode("", "; genFunction");
- genFunction (ic);
- break;
-
- case ENDFUNCTION:
- emitcode("", "; genEndFunction");
- genEndFunction (ic);
- break;
-
- case RETURN:
- emitcode("", "; genRet");
- genRet (ic);
- break;
-
- case LABEL:
- emitcode("", "; genLabel");
- genLabel (ic);
- break;
-
- case GOTO:
- emitcode("", "; genGoto");
- genGoto (ic);
- break;
-
- case '+' :
- emitcode("", "; genPlus");
- genPlus (ic) ;
- break;
-
- case '-' :
- emitcode("", "; genMinus");
- genMinus (ic);
- break;
-
- case '*' :
- emitcode("", "; genMult");
- genMult (ic);
- break;
-
- case '/' :
- emitcode("", "; genDiv");
- genDiv (ic) ;
- break;
-
- case '%' :
- emitcode("", "; genMod");
- genMod (ic);
- break;
-
- case '>' :
- emitcode("", "; genCmpGt");
- genCmpGt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case '<' :
- emitcode("", "; genCmpLt");
- genCmpLt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case LE_OP:
- case GE_OP:
- case NE_OP:
-
- /* note these two are xlated by algebraic equivalence
- during parsing SDCC.y */
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "got '>=' or '<=' shouldn't have come here");
- break;
-
- case EQ_OP:
- emitcode("", "; genCmpEq");
- genCmpEq (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case AND_OP:
- emitcode("", "; genAndOp");
- genAndOp (ic);
- break;
-
- case OR_OP:
- emitcode("", "; genOrOp");
- genOrOp (ic);
- break;
-
- case '^' :
- emitcode("", "; genXor");
- genXor (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case '|' :
- emitcode("", "; genOr");
- genOr (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case BITWISEAND:
- emitcode("", "; genAnd");
- genAnd (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
-
- case INLINEASM:
- emitcode("", "; genInline");
- genInline (ic);
- break;
-
- case RRC:
- emitcode("", "; genRRC");
- genRRC (ic);
- break;
-
- case RLC:
- emitcode("", "; genRLC");
- genRLC (ic);
- break;
-
- case GETHBIT:
- emitcode("", "; genHBIT");
- wassert(0);
-
- case LEFT_OP:
- emitcode("", "; genLeftShift");
- genLeftShift (ic);
- break;
-
- case RIGHT_OP:
- emitcode("", "; genRightShift");
- genRightShift (ic);
- break;
-
- case GET_VALUE_AT_ADDRESS:
- emitcode("", "; genPointerGet");
- genPointerGet(ic);
- break;
-
- case '=' :
-
- if (POINTER_SET(ic)) {
- emitcode("", "; genAssign (pointer)");
- genPointerSet(ic);
- }
- else {
- emitcode("", "; genAssign");
- genAssign(ic);
- }
- break;
-
- case IFX:
- emitcode("", "; genIfx");
- genIfx (ic,NULL);
- break;
-
- case ADDRESS_OF:
- emitcode("", "; genAddrOf");
- genAddrOf (ic);
- break;
-
- case JUMPTABLE:
- emitcode("", "; genJumpTab");
- genJumpTab (ic);
- break;
-
- case CAST:
- emitcode("", "; genCast");
- genCast (ic);
- break;
-
- case RECEIVE:
- emitcode("", "; genReceive");
- genReceive(ic);
- break;
-
- case SEND:
- emitcode("", "; addSet");
- addSet(&sendSet,ic);
- break;
-
- default :
- ic = ic;
- /* piCode(ic,stdout); */
-
- }
+ /* if debug information required */
+ if (options.debug && currFunc)
+ {
+ cdbSymbol (currFunc, cdbFile, FALSE, TRUE);
+ debugLine = 1;
+ if (IS_STATIC (currFunc->etype))
+ emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
+ else
+ emitcode ("", "G$%s$0$0 ==.", currFunc->name);
+ debugLine = 0;
}
+ /* stack pointer name */
+ spname = "sp";
- /* now we are ready to call the
- peep hole optimizer */
- if (!options.nopeep)
- peepHole (&lineHead);
-
- /* This is unfortunate */
- /* now do the actual printing */
+ for (ic = lic; ic; ic = ic->next)
{
- FILE *fp = codeOutFile;
- if (isInHome() && codeOutFile == code->oFile)
+
+ if (cln != ic->lineno)
+ {
+ if (options.debug)
+ {
+ debugLine = 1;
+ emitcode ("", "C$%s$%d$%d$%d ==.",
+ FileBaseName (ic->filename), ic->lineno,
+ ic->level, ic->block);
+ debugLine = 0;
+ }
+ emitcode (";", "%s %d", ic->filename, ic->lineno);
+ cln = ic->lineno;
+ }
+ /* if the result is marked as
+ spilt and rematerializable or code for
+ this has already been generated then
+ do nothing */
+ if (resultRemat (ic) || ic->generated)
+ continue;
+
+ /* depending on the operation */
+ switch (ic->op)
+ {
+ case '!':
+ emitcode ("", "; genNot");
+ genNot (ic);
+ break;
+
+ case '~':
+ emitcode ("", "; genCpl");
+ genCpl (ic);
+ break;
+
+ case UNARYMINUS:
+ emitcode ("", "; genUminus");
+ genUminus (ic);
+ break;
+
+ case IPUSH:
+ emitcode ("", "; genIpush");
+ genIpush (ic);
+ break;
+
+ case IPOP:
+ /* IPOP happens only when trying to restore a
+ spilt live range, if there is an ifx statement
+ following this pop then the if statement might
+ be using some of the registers being popped which
+ would destory the contents of the register so
+ we need to check for this condition and handle it */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
+ {
+ emitcode ("", "; genIfx");
+ genIfx (ic->next, ic);
+ }
+ else
+ {
+ emitcode ("", "; genIpop");
+ genIpop (ic);
+ }
+ break;
+
+ case CALL:
+ emitcode ("", "; genCall");
+ genCall (ic);
+ break;
+
+ case PCALL:
+ emitcode ("", "; genPcall");
+ genPcall (ic);
+ break;
+
+ case FUNCTION:
+ emitcode ("", "; genFunction");
+ genFunction (ic);
+ break;
+
+ case ENDFUNCTION:
+ emitcode ("", "; genEndFunction");
+ genEndFunction (ic);
+ break;
+
+ case RETURN:
+ emitcode ("", "; genRet");
+ genRet (ic);
+ break;
+
+ case LABEL:
+ emitcode ("", "; genLabel");
+ genLabel (ic);
+ break;
+
+ case GOTO:
+ emitcode ("", "; genGoto");
+ genGoto (ic);
+ break;
+
+ case '+':
+ emitcode ("", "; genPlus");
+ genPlus (ic);
+ break;
+
+ case '-':
+ emitcode ("", "; genMinus");
+ genMinus (ic);
+ break;
+
+ case '*':
+ emitcode ("", "; genMult");
+ genMult (ic);
+ break;
+
+ case '/':
+ emitcode ("", "; genDiv");
+ genDiv (ic);
+ break;
+
+ case '%':
+ emitcode ("", "; genMod");
+ genMod (ic);
+ break;
+
+ case '>':
+ emitcode ("", "; genCmpGt");
+ genCmpGt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '<':
+ emitcode ("", "; genCmpLt");
+ genCmpLt (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case LE_OP:
+ case GE_OP:
+ case NE_OP:
+
+ /* note these two are xlated by algebraic equivalence
+ during parsing SDCC.y */
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "got '>=' or '<=' shouldn't have come here");
+ break;
+
+ case EQ_OP:
+ emitcode ("", "; genCmpEq");
+ genCmpEq (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case AND_OP:
+ emitcode ("", "; genAndOp");
+ genAndOp (ic);
+ break;
+
+ case OR_OP:
+ emitcode ("", "; genOrOp");
+ genOrOp (ic);
+ break;
+
+ case '^':
+ emitcode ("", "; genXor");
+ genXor (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case '|':
+ emitcode ("", "; genOr");
+ genOr (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case BITWISEAND:
+ emitcode ("", "; genAnd");
+ genAnd (ic, ifxForOp (IC_RESULT (ic), ic));
+ break;
+
+ case INLINEASM:
+ emitcode ("", "; genInline");
+ genInline (ic);
+ break;
+
+ case RRC:
+ emitcode ("", "; genRRC");
+ genRRC (ic);
+ break;
+
+ case RLC:
+ emitcode ("", "; genRLC");
+ genRLC (ic);
+ break;
+
+ case GETHBIT:
+ emitcode ("", "; genHBIT");
+ wassert (0);
+
+ case LEFT_OP:
+ emitcode ("", "; genLeftShift");
+ genLeftShift (ic);
+ break;
+
+ case RIGHT_OP:
+ emitcode ("", "; genRightShift");
+ genRightShift (ic);
+ break;
+
+ case GET_VALUE_AT_ADDRESS:
+ emitcode ("", "; genPointerGet");
+ genPointerGet (ic);
+ break;
+
+ case '=':
+
+ if (POINTER_SET (ic))
+ {
+ emitcode ("", "; genAssign (pointer)");
+ genPointerSet (ic);
+ }
+ else
+ {
+ emitcode ("", "; genAssign");
+ genAssign (ic);
+ }
+ break;
+
+ case IFX:
+ emitcode ("", "; genIfx");
+ genIfx (ic, NULL);
+ break;
+
+ case ADDRESS_OF:
+ emitcode ("", "; genAddrOf");
+ genAddrOf (ic);
+ break;
+
+ case JUMPTABLE:
+ emitcode ("", "; genJumpTab");
+ genJumpTab (ic);
+ break;
+
+ case CAST:
+ emitcode ("", "; genCast");
+ genCast (ic);
+ break;
+
+ case RECEIVE:
+ emitcode ("", "; genReceive");
+ genReceive (ic);
+ break;
+
+ case SEND:
+ emitcode ("", "; addSet");
+ addSet (&sendSet, ic);
+ break;
+
+ default:
+ ic = ic;
+ /* piCode(ic,stdout); */
+
+ }
+ }
+
+
+ /* now we are ready to call the
+ peep hole optimizer */
+ if (!options.nopeep)
+ peepHole (&lineHead);
+
+ /* This is unfortunate */
+ /* now do the actual printing */
+ {
+ FILE *fp = codeOutFile;
+ if (isInHome () && codeOutFile == code->oFile)
codeOutFile = home->oFile;
- printLine (lineHead, codeOutFile);
- if (_G.flush_statics) {
- flushStatics();
- _G.flush_statics = 0;
+ printLine (lineHead, codeOutFile);
+ if (_G.flush_statics)
+ {
+ flushStatics ();
+ _G.flush_statics = 0;
+ }
+ codeOutFile = fp;
}
- codeOutFile = fp;
- }
}
#ifndef SDCCGEN51_H
#define SDCCGEN51_H
-typedef enum {
+typedef enum
+ {
AOP_INVALID,
/* Is a literal */
AOP_LIT = 1,
/* Is in a register */
- AOP_REG,
+ AOP_REG,
/* Is in direct space */
AOP_DIR,
/* SFR space ($FF00 and above) */
AOP_SFR,
/* Is on the stack */
- AOP_STK ,
+ AOP_STK,
/* Is an immediate value */
- AOP_IMMD,
+ AOP_IMMD,
/* Is a string (?) */
AOP_STR,
/* Is in the carry register */
- AOP_CRY,
+ AOP_CRY,
/* Is pointed to by IY */
AOP_IY,
/* Is pointed to by HL */
AOP_ACC,
/* Is in H and L */
AOP_HLREG
-} AOP_TYPE;
+ }
+AOP_TYPE;
/* type asmop : a homogenised type for
all the different spaces an operand can be
in */
-typedef struct asmop {
+typedef struct asmop
+ {
AOP_TYPE type;
- short coff ; /* current offset */
- short size ; /* total size */
- unsigned code :1 ; /* is in Code space */
- unsigned paged:1 ; /* in paged memory */
- unsigned freed:1 ; /* already freed */
- union {
- value *aop_lit ; /* if literal */
- regs *aop_reg[4]; /* array of registers */
- char *aop_dir ; /* if direct */
- char *aop_immd; /* if immediate others are implied */
- int aop_stk ; /* stack offset when AOP_STK */
- char *aop_str[4]; /* just a string array containing the location */
- } aopu;
-} asmop;
+ short coff; /* current offset */
+ short size; /* total size */
+ unsigned code:1; /* is in Code space */
+ unsigned paged:1; /* in paged memory */
+ unsigned freed:1; /* already freed */
+ union
+ {
+ value *aop_lit; /* if literal */
+ regs *aop_reg[4]; /* array of registers */
+ char *aop_dir; /* if direct */
+ char *aop_immd; /* if immediate others are implied */
+ int aop_stk; /* stack offset when AOP_STK */
+ char *aop_str[4]; /* just a string array containing the location */
+ }
+ aopu;
+ }
+asmop;
void genZ80Code (iCode *);
Z80_OPTS z80_opts;
-typedef enum {
+typedef enum
+ {
/* Must be first */
ASM_TYPE_ASXXXX,
ASM_TYPE_RGBDS,
ASM_TYPE_ISAS
-} ASM_TYPE;
+ }
+ASM_TYPE;
-static struct {
+static struct
+ {
ASM_TYPE asmType;
-} _G;
+ }
+_G;
-static char *_keywords[] = {
- "sfr",
- "nonbanked",
- "banked",
- NULL
+static char *_keywords[] =
+{
+ "sfr",
+ "nonbanked",
+ "banked",
+ NULL
};
extern PORT gbz80_port;
#include "mappings.i"
-static void _z80_init(void)
+static void
+_z80_init (void)
{
- z80_opts.sub = SUB_Z80;
- asm_addTree(&_asxxxx_z80);
+ z80_opts.sub = SUB_Z80;
+ asm_addTree (&_asxxxx_z80);
}
-static void _gbz80_init(void)
+static void
+_gbz80_init (void)
{
- z80_opts.sub = SUB_GBZ80;
+ z80_opts.sub = SUB_GBZ80;
}
-static int regParmFlg = 0; /* determine if we can register a parameter */
+static int regParmFlg = 0; /* determine if we can register a parameter */
-static void _reset_regparm()
+static void
+_reset_regparm ()
{
- regParmFlg = 0;
+ regParmFlg = 0;
}
-static int _reg_parm(sym_link *l)
+static int
+_reg_parm (sym_link * l)
{
- if (regParmFlg == 2)
- return 0;
-
- regParmFlg++;
- return 1;
+ if (regParmFlg == 2)
+ return 0;
+
+ regParmFlg++;
+ return 1;
}
-static bool _startsWith(const char *sz, const char *key)
+static bool
+_startsWith (const char *sz, const char *key)
{
- return !strncmp(sz, key, strlen(key));
+ return !strncmp (sz, key, strlen (key));
}
-static void _chomp(char *sz)
+static void
+_chomp (char *sz)
{
- char *nl;
- while ((nl = strrchr(sz, '\n')))
- *nl = '\0';
+ char *nl;
+ while ((nl = strrchr (sz, '\n')))
+ *nl = '\0';
}
-static int _process_pragma(const char *sz)
+static int
+_process_pragma (const char *sz)
{
- if (_startsWith(sz, "bank=")) {
- char buffer[128];
- strcpy(buffer, sz+5);
- _chomp(buffer);
- if (isdigit(buffer[0])) {
-
+ if (_startsWith (sz, "bank="))
+ {
+ char buffer[128];
+ strcpy (buffer, sz + 5);
+ _chomp (buffer);
+ if (isdigit (buffer[0]))
+ {
+
}
- else if (!strcmp(buffer, "BASE")) {
- strcpy(buffer, "HOME");
+ else if (!strcmp (buffer, "BASE"))
+ {
+ strcpy (buffer, "HOME");
}
- if (isdigit(buffer[0])) {
- /* Arg was a bank number. Handle in an ASM independent
- way. */
- char num[128];
- strcpy(num, sz+5);
- _chomp(num);
-
- switch (_G.asmType) {
+ if (isdigit (buffer[0]))
+ {
+ /* Arg was a bank number. Handle in an ASM independent
+ way. */
+ char num[128];
+ strcpy (num, sz + 5);
+ _chomp (num);
+
+ switch (_G.asmType)
+ {
case ASM_TYPE_ASXXXX:
- sprintf(buffer, "CODE_%s", num);
- break;
+ sprintf (buffer, "CODE_%s", num);
+ break;
case ASM_TYPE_RGBDS:
- sprintf(buffer, "CODE,BANK[%s]", num);
- break;
+ sprintf (buffer, "CODE,BANK[%s]", num);
+ break;
case ASM_TYPE_ISAS:
- /* PENDING: what to use for ISAS? */
- sprintf(buffer, "CODE,BANK(%s)", num);
- break;
+ /* PENDING: what to use for ISAS? */
+ sprintf (buffer, "CODE,BANK(%s)", num);
+ break;
default:
- wassert(0);
+ wassert (0);
}
}
- gbz80_port.mem.code_name = gc_strdup(buffer);
- code->sname = gbz80_port.mem.code_name;
- return 0;
+ gbz80_port.mem.code_name = gc_strdup (buffer);
+ code->sname = gbz80_port.mem.code_name;
+ return 0;
}
- return 1;
+ return 1;
}
-static const char *_gbz80_rgbasmCmd[] = {
- "rgbasm", "-o$1.o", "$1.asm", NULL
+static const char *_gbz80_rgbasmCmd[] =
+{
+ "rgbasm", "-o$1.o", "$1.asm", NULL
};
-static const char *_gbz80_rgblinkCmd[] = {
- "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL
+static const char *_gbz80_rgblinkCmd[] =
+{
+ "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL
};
-static void _gbz80_rgblink(void)
+static void
+_gbz80_rgblink (void)
{
- FILE *lnkfile;
- const char *sz;
- char *argv[128];
-
- int i;
- sz = srcFileName;
- if (!sz)
- sz = "a";
-
- /* first we need to create the <filename>.lnk file */
- sprintf(buffer,"%s.lnk", sz);
- if (!(lnkfile = fopen(buffer,"w"))) {
- werror(E_FILE_OPEN_ERR, buffer);
- exit(1);
+ FILE *lnkfile;
+ const char *sz;
+ char *argv[128];
+
+ int i;
+ sz = srcFileName;
+ if (!sz)
+ sz = "a";
+
+ /* first we need to create the <filename>.lnk file */
+ sprintf (buffer, "%s.lnk", sz);
+ if (!(lnkfile = fopen (buffer, "w")))
+ {
+ werror (E_FILE_OPEN_ERR, buffer);
+ exit (1);
}
- fprintf(lnkfile, "[Objects]\n");
+ fprintf (lnkfile, "[Objects]\n");
- if (srcFileName)
- fprintf(lnkfile, "%s.o\n", sz);
+ if (srcFileName)
+ fprintf (lnkfile, "%s.o\n", sz);
- for (i = 0 ; i < nrelFiles ; i++ )
- fprintf (lnkfile,"%s\n",relFiles[i]);
+ for (i = 0; i < nrelFiles; i++)
+ fprintf (lnkfile, "%s\n", relFiles[i]);
- fprintf(lnkfile, "\n[Libraries]\n");
- /* additional libraries if any */
- for (i = 0 ; i < nlibFiles; i++)
- fprintf (lnkfile,"%s\n",libFiles[i]);
+ fprintf (lnkfile, "\n[Libraries]\n");
+ /* additional libraries if any */
+ for (i = 0; i < nlibFiles; i++)
+ fprintf (lnkfile, "%s\n", libFiles[i]);
- fprintf(lnkfile,"\n[Output]\n" "%s.gb",sz);
+ fprintf (lnkfile, "\n[Output]\n" "%s.gb", sz);
- fclose(lnkfile);
+ fclose (lnkfile);
- buildCmdLine(buffer, argv, port->linker.cmd, sz, NULL, NULL, NULL);
- /* call the linker */
- if (my_system(argv[0], argv)) {
- perror("Cannot exec linker");
- exit(1);
+ buildCmdLine (buffer, argv, port->linker.cmd, sz, NULL, NULL, NULL);
+ /* call the linker */
+ if (my_system (argv[0], argv))
+ {
+ perror ("Cannot exec linker");
+ exit (1);
}
}
-static bool _parseOptions(int *pargc, char **argv, int *i)
+static bool
+_parseOptions (int *pargc, char **argv, int *i)
{
- if (argv[*i][0] == '-') {
- if (argv[*i][1] == 'b' && IS_GB) {
- int bank = atoi(argv[*i] + 3);
- char buffer[128];
- switch (argv[*i][2]) {
+ if (argv[*i][0] == '-')
+ {
+ if (argv[*i][1] == 'b' && IS_GB)
+ {
+ int bank = atoi (argv[*i] + 3);
+ char buffer[128];
+ switch (argv[*i][2])
+ {
case 'o':
- /* ROM bank */
- sprintf(buffer, "CODE_%u", bank);
- gbz80_port.mem.code_name = gc_strdup(buffer);
- return TRUE;
+ /* ROM bank */
+ sprintf (buffer, "CODE_%u", bank);
+ gbz80_port.mem.code_name = gc_strdup (buffer);
+ return TRUE;
case 'a':
- /* RAM bank */
- sprintf(buffer, "DATA_%u", bank);
- gbz80_port.mem.data_name = gc_strdup(buffer);
- return TRUE;
+ /* RAM bank */
+ sprintf (buffer, "DATA_%u", bank);
+ gbz80_port.mem.data_name = gc_strdup (buffer);
+ return TRUE;
}
}
- else if (!strncmp(argv[*i], "--asm=", 6)) {
- if (!strcmp(argv[*i], "--asm=rgbds")) {
- asm_addTree(&_rgbds_gb);
- gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
- gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
- gbz80_port.linker.do_link = _gbz80_rgblink;
- _G.asmType = ASM_TYPE_RGBDS;
- return TRUE;
+ else if (!strncmp (argv[*i], "--asm=", 6))
+ {
+ if (!strcmp (argv[*i], "--asm=rgbds"))
+ {
+ asm_addTree (&_rgbds_gb);
+ gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
+ gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
+ gbz80_port.linker.do_link = _gbz80_rgblink;
+ _G.asmType = ASM_TYPE_RGBDS;
+ return TRUE;
}
- else if (!strcmp(argv[*i], "--asm=asxxxx")) {
- _G.asmType = ASM_TYPE_ASXXXX;
- return TRUE;
+ else if (!strcmp (argv[*i], "--asm=asxxxx"))
+ {
+ _G.asmType = ASM_TYPE_ASXXXX;
+ return TRUE;
}
- else if (!strcmp(argv[*i], "--asm=isas")) {
- asm_addTree(&_isas_gb);
- /* Munge the function prefix */
- gbz80_port.fun_prefix = "";
- _G.asmType = ASM_TYPE_ISAS;
- return TRUE;
+ else if (!strcmp (argv[*i], "--asm=isas"))
+ {
+ asm_addTree (&_isas_gb);
+ /* Munge the function prefix */
+ gbz80_port.fun_prefix = "";
+ _G.asmType = ASM_TYPE_ISAS;
+ return TRUE;
}
}
}
- return FALSE;
+ return FALSE;
}
-static void _finaliseOptions(void)
+static void
+_finaliseOptions (void)
{
- port->mem.default_local_map = data;
- port->mem.default_globl_map = data;
- if (_G.asmType == ASM_TYPE_ASXXXX && IS_GB)
- asm_addTree(&_asxxxx_gb);
+ port->mem.default_local_map = data;
+ port->mem.default_globl_map = data;
+ if (_G.asmType == ASM_TYPE_ASXXXX && IS_GB)
+ asm_addTree (&_asxxxx_gb);
}
-static void _setDefaultOptions(void)
-{
- options.genericPtr = 1; /* default on */
- options.nopeep = 0;
- options.stackAuto = 1;
- options.mainreturn = 1;
- options.noregparms = 1;
- options.nodebug = 1;
- /* first the options part */
- options.intlong_rent = 1;
-
- optimize.global_cse = 1;
- optimize.label1 = 1;
- optimize.label2 = 1;
- optimize.label3 = 1;
- optimize.label4 = 1;
- optimize.loopInvariant = 1;
- optimize.loopInduction = 0;
+static void
+_setDefaultOptions (void)
+{
+ options.genericPtr = 1; /* default on */
+ options.nopeep = 0;
+ options.stackAuto = 1;
+ options.mainreturn = 1;
+ options.noregparms = 1;
+ options.nodebug = 1;
+ /* first the options part */
+ options.intlong_rent = 1;
+
+ optimize.global_cse = 1;
+ optimize.label1 = 1;
+ optimize.label2 = 1;
+ optimize.label3 = 1;
+ optimize.label4 = 1;
+ optimize.loopInvariant = 1;
+ optimize.loopInduction = 0;
}
-static const char *_getRegName(struct regs *reg)
+static const char *
+_getRegName (struct regs *reg)
{
- if (reg)
- return reg->name;
- assert(0);
- return "err";
+ if (reg)
+ return reg->name;
+ assert (0);
+ return "err";
}
/** $1 is always the basename.
$l is the list of extra options that should be there somewhere...
MUST be terminated with a NULL.
*/
-static const char *_z80_linkCmd[] = {
- "link-z80", "-nf", "$1", NULL
+static const char *_z80_linkCmd[] =
+{
+ "link-z80", "-nf", "$1", NULL
};
-static const char *_z80_asmCmd[] = {
- "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
+static const char *_z80_asmCmd[] =
+{
+ "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
};
/** $1 is always the basename.
$l is the list of extra options that should be there somewhere...
MUST be terminated with a NULL.
*/
-static const char *_gbz80_linkCmd[] = {
- "link-gbz80", "-nf", "$1", NULL
+static const char *_gbz80_linkCmd[] =
+{
+ "link-gbz80", "-nf", "$1", NULL
};
-static const char *_gbz80_asmCmd[] = {
- "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
+static const char *_gbz80_asmCmd[] =
+{
+ "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
};
/* Globals */
-PORT z80_port = {
- "z80",
- "Zilog Z80", /* Target name */
- {
- FALSE,
- MODEL_MEDIUM | MODEL_SMALL,
- MODEL_SMALL
- },
- {
- _z80_asmCmd,
- "-plosgff", /* Options with debug */
- "-plosgff", /* Options without debug */
- },
- {
- _z80_linkCmd,
- NULL,
- ".o"
- },
- {
- _z80_defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
- },
- {
- "XSEG",
- "STACK",
- "CODE",
- "DATA",
- "ISEG",
- "XSEG",
- "BSEG",
- "RSEG",
- "GSINIT",
- "OVERLAY",
- "GSFINAL",
- "HOME",
- NULL,
- NULL,
- 1
- },
- {
- -1, 0, 0, 4, 0, 2
- },
+PORT z80_port =
+{
+ "z80",
+ "Zilog Z80", /* Target name */
+ {
+ FALSE,
+ MODEL_MEDIUM | MODEL_SMALL,
+ MODEL_SMALL
+ },
+ {
+ _z80_asmCmd,
+ "-plosgff", /* Options with debug */
+ "-plosgff", /* Options without debug */
+ },
+ {
+ _z80_linkCmd,
+ NULL,
+ ".o"
+ },
+ {
+ _z80_defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
+ },
+ {
+ "XSEG",
+ "STACK",
+ "CODE",
+ "DATA",
+ "ISEG",
+ "XSEG",
+ "BSEG",
+ "RSEG",
+ "GSINIT",
+ "OVERLAY",
+ "GSFINAL",
+ "HOME",
+ NULL,
+ NULL,
+ 1
+ },
+ {
+ -1, 0, 0, 4, 0, 2
+ },
/* Z80 has no native mul/div commands */
- {
- 0, 2
- },
- "_",
- _z80_init,
- _parseOptions,
- _finaliseOptions,
- _setDefaultOptions,
- z80_assignRegisters,
- _getRegName,
- _keywords,
- 0, /* no assembler preamble */
- 0, /* no local IVT generation code */
- _reset_regparm,
- _reg_parm,
- _process_pragma,
- TRUE,
- 0, /* leave lt */
- 0, /* leave gt */
- 1, /* transform <= to ! > */
- 1, /* transform >= to ! < */
- 1, /* transform != to !(a == b) */
- 0, /* leave == */
- PORT_MAGIC
+ {
+ 0, 2
+ },
+ "_",
+ _z80_init,
+ _parseOptions,
+ _finaliseOptions,
+ _setDefaultOptions,
+ z80_assignRegisters,
+ _getRegName,
+ _keywords,
+ 0, /* no assembler preamble */
+ 0, /* no local IVT generation code */
+ _reset_regparm,
+ _reg_parm,
+ _process_pragma,
+ TRUE,
+ 0, /* leave lt */
+ 0, /* leave gt */
+ 1, /* transform <= to ! > */
+ 1, /* transform >= to ! < */
+ 1, /* transform != to !(a == b) */
+ 0, /* leave == */
+ PORT_MAGIC
};
/* Globals */
-PORT gbz80_port = {
- "gbz80",
- "Gameboy Z80-like", /* Target name */
- {
- FALSE,
- MODEL_MEDIUM | MODEL_SMALL,
- MODEL_SMALL
- },
- {
- _gbz80_asmCmd,
- "-plosgff", /* Options with debug */
- "-plosgff", /* Options without debug */
- 1
- },
- {
- _gbz80_linkCmd,
- NULL,
- ".o"
- },
- {
- _gbz80_defaultRules
- },
- {
- /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
- 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
- },
- {
- "XSEG",
- "STACK",
- "CODE",
- "DATA",
- "ISEG",
- "XSEG",
- "BSEG",
- "RSEG",
- "GSINIT",
- "OVERLAY",
- "GSFINAL",
- "HOME",
- NULL,
- NULL,
- 1
- },
- {
- -1, 0, 0, 2, 0, 4
- },
+PORT gbz80_port =
+{
+ "gbz80",
+ "Gameboy Z80-like", /* Target name */
+ {
+ FALSE,
+ MODEL_MEDIUM | MODEL_SMALL,
+ MODEL_SMALL
+ },
+ {
+ _gbz80_asmCmd,
+ "-plosgff", /* Options with debug */
+ "-plosgff", /* Options without debug */
+ 1
+ },
+ {
+ _gbz80_linkCmd,
+ NULL,
+ ".o"
+ },
+ {
+ _gbz80_defaultRules
+ },
+ {
+ /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+ 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
+ },
+ {
+ "XSEG",
+ "STACK",
+ "CODE",
+ "DATA",
+ "ISEG",
+ "XSEG",
+ "BSEG",
+ "RSEG",
+ "GSINIT",
+ "OVERLAY",
+ "GSFINAL",
+ "HOME",
+ NULL,
+ NULL,
+ 1
+ },
+ {
+ -1, 0, 0, 2, 0, 4
+ },
/* gbZ80 has no native mul/div commands */
- {
- 0, 2
- },
- "_",
- _gbz80_init,
- _parseOptions,
- _finaliseOptions,
- _setDefaultOptions,
- z80_assignRegisters,
- _getRegName,
- _keywords,
- 0, /* no assembler preamble */
- 0, /* no local IVT generation code */
- _reset_regparm,
- _reg_parm,
- _process_pragma,
- TRUE,
- 0, /* leave lt */
- 0, /* leave gt */
- 1, /* transform <= to ! > */
- 1, /* transform >= to ! < */
- 1, /* transform != to !(a == b) */
- 0, /* leave == */
- PORT_MAGIC
+ {
+ 0, 2
+ },
+ "_",
+ _gbz80_init,
+ _parseOptions,
+ _finaliseOptions,
+ _setDefaultOptions,
+ z80_assignRegisters,
+ _getRegName,
+ _keywords,
+ 0, /* no assembler preamble */
+ 0, /* no local IVT generation code */
+ _reset_regparm,
+ _reg_parm,
+ _process_pragma,
+ TRUE,
+ 0, /* leave lt */
+ 0, /* leave gt */
+ 1, /* transform <= to ! > */
+ 1, /* transform >= to ! < */
+ 1, /* transform != to !(a == b) */
+ 0, /* leave == */
+ PORT_MAGIC
};
#include "z80.h"
-enum {
- DISABLE_PACK_ACC = 0,
- DISABLE_PACK_ASSIGN = 0,
+enum
+ {
+ DISABLE_PACK_ACC = 0,
+ DISABLE_PACK_ASSIGN = 0,
DISABLE_PACK_ONE_USE = 0,
- DISABLE_PACK_HL = 0,
- LIMITED_PACK_ACC = 1,
-};
+ DISABLE_PACK_HL = 0,
+ LIMITED_PACK_ACC = 1,
+ };
-enum {
- D_ALLOC = 0,
- D_ALLOC2 = 0
-};
+enum
+ {
+ D_ALLOC = 0,
+ D_ALLOC2 = 0
+ };
#if 1
#define D(_a, _s) if (_a) { printf _s; fflush(stdout); }
/* some routines are non-processor specific & can be reused when */
/* targetting other processors. The decision for this will have */
/* to be made on a routine by routine basis */
-/* routines used to pack registers are most definitely not reusable*/
+/* routines used to pack registers are most definitely not reusable */
/* since the pack the registers depending strictly on the MCU */
/*-----------------------------------------------------------------*/
-bitVect *spiltSet = NULL ;
+bitVect *spiltSet = NULL;
set *stackSpil = NULL;
bitVect *regAssigned = NULL;
short blockSpil = 0;
-int slocNum = 0 ;
-extern void genZ80Code(iCode *);
-bitVect *funcrUsed = NULL; /* registers used in a function */
+int slocNum = 0;
+extern void genZ80Code (iCode *);
+bitVect *funcrUsed = NULL; /* registers used in a function */
int stackExtend = 0;
-int dataExtend = 0;
+int dataExtend = 0;
int _nRegs;
/** Set to help debug register pressure related problems */
#define DEBUG_FAKE_EXTRA_REGS 0
-static regs _gbz80_regs[] = {
- { REG_GPR, C_IDX , "c", 1 },
- { REG_GPR, B_IDX , "b", 1 },
- { REG_CND, CND_IDX, "c", 1}
+static regs _gbz80_regs[] =
+{
+ {REG_GPR, C_IDX, "c", 1},
+ {REG_GPR, B_IDX, "b", 1},
+ {REG_CND, CND_IDX, "c", 1}
};
-static regs _z80_regs[] = {
- { REG_GPR, C_IDX , "c", 1 },
- { REG_GPR, B_IDX , "b", 1 },
- { REG_GPR, E_IDX , "e", 1 },
- { REG_GPR, D_IDX , "d", 1 },
+static regs _z80_regs[] =
+{
+ {REG_GPR, C_IDX, "c", 1},
+ {REG_GPR, B_IDX, "b", 1},
+ {REG_GPR, E_IDX, "e", 1},
+ {REG_GPR, D_IDX, "d", 1},
/* { REG_GPR, L_IDX , "l", 1 },
- { REG_GPR, H_IDX , "h", 1 },*/
+ { REG_GPR, H_IDX , "h", 1 }, */
#if DEBUG_FAKE_EXTRA_REGS
- { REG_GPR, M_IDX , "m", 1 },
- { REG_GPR, N_IDX , "n", 1 },
- { REG_GPR, O_IDX , "o", 1 },
- { REG_GPR, P_IDX , "p", 1 },
- { REG_GPR, Q_IDX , "q", 1 },
- { REG_GPR, R_IDX , "r", 1 },
- { REG_GPR, S_IDX , "s", 1 },
- { REG_GPR, T_IDX , "t", 1 },
+ {REG_GPR, M_IDX, "m", 1},
+ {REG_GPR, N_IDX, "n", 1},
+ {REG_GPR, O_IDX, "o", 1},
+ {REG_GPR, P_IDX, "p", 1},
+ {REG_GPR, Q_IDX, "q", 1},
+ {REG_GPR, R_IDX, "r", 1},
+ {REG_GPR, S_IDX, "s", 1},
+ {REG_GPR, T_IDX, "t", 1},
#endif
- { REG_CND, CND_IDX, "c", 1}
+ {REG_CND, CND_IDX, "c", 1}
};
regs *regsZ80;
@return Pointer to the newly allocated register.
*/
-static regs *allocReg (short type)
+static regs *
+allocReg (short type)
{
- int i;
-
- for ( i = 0 ; i < _nRegs ; i++ ) {
- /* For now we allocate from any free */
- if (regsZ80[i].isFree ) {
- regsZ80[i].isFree = 0;
- if (currFunc)
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- D(D_ALLOC, ("allocReg: alloced %p\n", ®sZ80[i]));
- return ®sZ80[i];
+ int i;
+
+ for (i = 0; i < _nRegs; i++)
+ {
+ /* For now we allocate from any free */
+ if (regsZ80[i].isFree)
+ {
+ regsZ80[i].isFree = 0;
+ if (currFunc)
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ D (D_ALLOC, ("allocReg: alloced %p\n", ®sZ80[i]));
+ return ®sZ80[i];
}
}
- D(D_ALLOC, ("allocReg: No free.\n"));
- return NULL;
+ D (D_ALLOC, ("allocReg: No free.\n"));
+ return NULL;
}
/** Returns pointer to register wit index number
*/
-regs *regWithIdx (int idx)
+regs *
+regWithIdx (int idx)
{
- int i;
-
- for (i=0;i < _nRegs;i++)
- if (regsZ80[i].rIdx == idx)
- return ®sZ80[i];
-
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "regWithIdx not found");
- exit(1);
+ int i;
+
+ for (i = 0; i < _nRegs; i++)
+ if (regsZ80[i].rIdx == idx)
+ return ®sZ80[i];
+
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "regWithIdx not found");
+ exit (1);
}
/** Frees a register.
*/
-static void freeReg (regs *reg)
+static void
+freeReg (regs * reg)
{
- wassert(!reg->isFree);
- reg->isFree = 1;
- D(D_ALLOC, ("freeReg: freed %p\n", reg));
+ wassert (!reg->isFree);
+ reg->isFree = 1;
+ D (D_ALLOC, ("freeReg: freed %p\n", reg));
}
/** Returns number of free registers.
*/
-static int nFreeRegs (int type)
+static int
+nFreeRegs (int type)
{
- int i;
- int nfr=0;
-
- for (i = 0 ; i < _nRegs; i++ ) {
- /* For now only one reg type */
- if (regsZ80[i].isFree)
- nfr++;
+ int i;
+ int nfr = 0;
+
+ for (i = 0; i < _nRegs; i++)
+ {
+ /* For now only one reg type */
+ if (regsZ80[i].isFree)
+ nfr++;
}
- return nfr;
+ return nfr;
}
/** Free registers with type.
*/
-static int nfreeRegsType (int type)
+static int
+nfreeRegsType (int type)
{
- int nfr ;
- if (type == REG_PTR) {
- if ((nfr = nFreeRegs(type)) == 0)
- return nFreeRegs(REG_GPR);
- }
-
- return nFreeRegs(type);
+ int nfr;
+ if (type == REG_PTR)
+ {
+ if ((nfr = nFreeRegs (type)) == 0)
+ return nFreeRegs (REG_GPR);
+ }
+
+ return nFreeRegs (type);
}
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
/*-----------------------------------------------------------------*/
-static bool allDefsOutOfRange (bitVect *defs,int fseq, int toseq)
+static bool
+allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
{
- int i ;
+ int i;
- if (!defs)
- return TRUE ;
+ if (!defs)
+ return TRUE;
+
+ for (i = 0; i < defs->size; i++)
+ {
+ iCode *ic;
- for ( i = 0 ;i < defs->size ; i++ ) {
- iCode *ic;
+ if (bitVectBitValue (defs, i) &&
+ (ic = hTabItemWithKey (iCodehTab, i)) &&
+ (ic->seq >= fseq && ic->seq <= toseq))
+
+ return FALSE;
- if (bitVectBitValue(defs,i) &&
- (ic = hTabItemWithKey(iCodehTab,i)) &&
- ( ic->seq >= fseq && ic->seq <= toseq))
-
- return FALSE;
-
}
-
- return TRUE;
+
+ return TRUE;
}
#endif
-
+
/*-----------------------------------------------------------------*/
/* computeSpillable - given a point find the spillable live ranges */
/*-----------------------------------------------------------------*/
-static bitVect *computeSpillable (iCode *ic)
+static bitVect *
+computeSpillable (iCode * ic)
{
- bitVect *spillable ;
-
- /* spillable live ranges are those that are live at this
- point . the following categories need to be subtracted
- from this set.
- a) - those that are already spilt
- b) - if being used by this one
- c) - defined by this one */
-
- spillable = bitVectCopy(ic->rlive);
- spillable =
- bitVectCplAnd(spillable,spiltSet); /* those already spilt */
- spillable =
- bitVectCplAnd(spillable,ic->uses); /* used in this one */
- bitVectUnSetBit(spillable,ic->defKey);
- spillable = bitVectIntersect(spillable,regAssigned);
- return spillable;
-
+ bitVect *spillable;
+
+ /* spillable live ranges are those that are live at this
+ point . the following categories need to be subtracted
+ from this set.
+ a) - those that are already spilt
+ b) - if being used by this one
+ c) - defined by this one */
+
+ spillable = bitVectCopy (ic->rlive);
+ spillable =
+ bitVectCplAnd (spillable, spiltSet); /* those already spilt */
+ spillable =
+ bitVectCplAnd (spillable, ic->uses); /* used in this one */
+ bitVectUnSetBit (spillable, ic->defKey);
+ spillable = bitVectIntersect (spillable, regAssigned);
+ return spillable;
+
}
/*-----------------------------------------------------------------*/
/* noSpilLoc - return true if a variable has no spil location */
/*-----------------------------------------------------------------*/
-static int noSpilLoc (symbol *sym, eBBlock *ebp,iCode *ic)
+static int
+noSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 0 : 1);
+ return (sym->usl.spillLoc ? 0 : 1);
}
/*-----------------------------------------------------------------*/
/* hasSpilLoc - will return 1 if the symbol has spil location */
/*-----------------------------------------------------------------*/
-static int hasSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return (sym->usl.spillLoc ? 1 : 0);
+ return (sym->usl.spillLoc ? 1 : 0);
}
/** Will return 1 if the remat flag is set.
into registers at creation as it can be re-created at any time -
i.e. it's constant in some way.
*/
-static int rematable (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+rematable (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return sym->remat;
+ return sym->remat;
}
/*-----------------------------------------------------------------*/
/* allLRs - return true for all */
/*-----------------------------------------------------------------*/
-static int allLRs (symbol *sym, eBBlock *ebp, iCode *ic)
+static int
+allLRs (symbol * sym, eBBlock * ebp, iCode * ic)
{
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* liveRangesWith - applies function to a given set of live range */
/*-----------------------------------------------------------------*/
-set *liveRangesWith (bitVect *lrs, int (func)(symbol *,eBBlock *, iCode *),
- eBBlock *ebp, iCode *ic)
+set *
+liveRangesWith (bitVect * lrs, int (func) (symbol *, eBBlock *, iCode *),
+ eBBlock * ebp, iCode * ic)
{
- set *rset = NULL;
- int i;
+ set *rset = NULL;
+ int i;
- if (!lrs || !lrs->size)
- return NULL;
+ if (!lrs || !lrs->size)
+ return NULL;
- for ( i = 1 ; i < lrs->size ; i++ ) {
- symbol *sym;
- if (!bitVectBitValue(lrs,i))
- continue ;
-
- /* if we don't find it in the live range
- hash table we are in serious trouble */
- if (!(sym = hTabItemWithKey(liveRanges,i))) {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
- "liveRangesWith could not find liveRange");
- exit(1);
+ for (i = 1; i < lrs->size; i++)
+ {
+ symbol *sym;
+ if (!bitVectBitValue (lrs, i))
+ continue;
+
+ /* if we don't find it in the live range
+ hash table we are in serious trouble */
+ if (!(sym = hTabItemWithKey (liveRanges, i)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "liveRangesWith could not find liveRange");
+ exit (1);
}
-
- if (func(sym,ebp,ic) && bitVectBitValue(regAssigned,sym->key))
- addSetHead(&rset,sym);
+
+ if (func (sym, ebp, ic) && bitVectBitValue (regAssigned, sym->key))
+ addSetHead (&rset, sym);
}
- return rset;
+ return rset;
}
/*-----------------------------------------------------------------*/
/* leastUsedLR - given a set determines which is the least used */
/*-----------------------------------------------------------------*/
-symbol *leastUsedLR (set *sset)
+symbol *
+leastUsedLR (set * sset)
{
- symbol *sym = NULL, *lsym = NULL ;
-
- sym = lsym = setFirstItem(sset);
+ symbol *sym = NULL, *lsym = NULL;
- if (!lsym)
- return NULL;
+ sym = lsym = setFirstItem (sset);
+
+ if (!lsym)
+ return NULL;
+
+ for (; lsym; lsym = setNextItem (sset))
+ {
- for (; lsym; lsym = setNextItem(sset)) {
-
- /* if usage is the same then prefer
- the spill the smaller of the two */
- if ( lsym->used == sym->used )
- if (getSize(lsym->type) < getSize(sym->type))
- sym = lsym;
-
- /* if less usage */
- if (lsym->used < sym->used )
- sym = lsym;
-
- }
-
- setToNull((void **)&sset);
- sym->blockSpil = 0;
- return sym;
+ /* if usage is the same then prefer
+ the spill the smaller of the two */
+ if (lsym->used == sym->used)
+ if (getSize (lsym->type) < getSize (sym->type))
+ sym = lsym;
+
+ /* if less usage */
+ if (lsym->used < sym->used)
+ sym = lsym;
+
+ }
+
+ setToNull ((void **) &sset);
+ sym->blockSpil = 0;
+ return sym;
}
/*-----------------------------------------------------------------*/
/* noOverLap - will iterate through the list looking for over lap */
/*-----------------------------------------------------------------*/
-static int noOverLap (set *itmpStack, symbol *fsym)
+static int
+noOverLap (set * itmpStack, symbol * fsym)
{
- symbol *sym;
-
- for (sym = setFirstItem(itmpStack); sym;
- sym = setNextItem(itmpStack)) {
- if (sym->liveTo > fsym->liveFrom )
- return 0;
-
+ symbol *sym;
+
+ for (sym = setFirstItem (itmpStack); sym;
+ sym = setNextItem (itmpStack))
+ {
+ if (sym->liveTo > fsym->liveFrom)
+ return 0;
+
}
- return 1;
+ return 1;
}
/*-----------------------------------------------------------------*/
/* isFree - will return 1 if the a free spil location is found */
/*-----------------------------------------------------------------*/
-DEFSETFUNC(isFree)
+DEFSETFUNC (isFree)
{
- symbol *sym = item;
- V_ARG(symbol **,sloc);
- V_ARG(symbol *,fsym);
+ symbol *sym = item;
+ V_ARG (symbol **, sloc);
+ V_ARG (symbol *, fsym);
- /* if already found */
- if (*sloc)
- return 0;
+ /* if already found */
+ if (*sloc)
+ return 0;
- /* if it is free && and the itmp assigned to
- this does not have any overlapping live ranges
- with the one currently being assigned and
- the size can be accomodated */
- if (sym->isFree &&
- noOverLap(sym->usl.itmpStack,fsym) &&
- getSize(sym->type) >= getSize(fsym->type)) {
- *sloc = sym;
- return 1;
+ /* if it is free && and the itmp assigned to
+ this does not have any overlapping live ranges
+ with the one currently being assigned and
+ the size can be accomodated */
+ if (sym->isFree &&
+ noOverLap (sym->usl.itmpStack, fsym) &&
+ getSize (sym->type) >= getSize (fsym->type))
+ {
+ *sloc = sym;
+ return 1;
}
- return 0;
+ return 0;
}
/*-----------------------------------------------------------------*/
/* createStackSpil - create a location on the stack to spil */
/*-----------------------------------------------------------------*/
-symbol *createStackSpil (symbol *sym)
+symbol *
+createStackSpil (symbol * sym)
{
- symbol *sloc= NULL;
-
- D(D_ALLOC, ("createStackSpil: for sym %p\n", sym));
-
- /* first go try and find a free one that is already
- existing on the stack */
- if (applyToSet(stackSpil,isFree,&sloc, sym)) {
- /* found a free one : just update & return */
- sym->usl.spillLoc = sloc;
- sym->stackSpil= 1;
- sloc->isFree = 0;
- addSetHead(&sloc->usl.itmpStack,sym);
- D(D_ALLOC, ("createStackSpil: found existing\n"));
- return sym;
+ symbol *sloc = NULL;
+
+ D (D_ALLOC, ("createStackSpil: for sym %p\n", sym));
+
+ /* first go try and find a free one that is already
+ existing on the stack */
+ if (applyToSet (stackSpil, isFree, &sloc, sym))
+ {
+ /* found a free one : just update & return */
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+ sloc->isFree = 0;
+ addSetHead (&sloc->usl.itmpStack, sym);
+ D (D_ALLOC, ("createStackSpil: found existing\n"));
+ return sym;
}
- /* could not then have to create one , this is the hard part
- we need to allocate this on the stack : this is really a
- hack!! but cannot think of anything better at this time */
-
- sprintf(buffer,"sloc%d",slocNum++);
- sloc = newiTemp(buffer);
-
- /* set the type to the spilling symbol */
- sloc->type = copyLinkChain(sym->type);
- sloc->etype = getSpec(sloc->type);
- SPEC_SCLS(sloc->etype) = S_AUTO ;
-
- /* we don't allow it to be allocated`
- onto the external stack since : so we
- temporarily turn it off ; we also
- turn off memory model to prevent
- the spil from going to the external storage
- and turn off overlaying
- */
- allocLocal(sloc);
-
- sloc->isref = 1; /* to prevent compiler warning */
-
- /* if it is on the stack then update the stack */
- if (IN_STACK(sloc->etype)) {
- currFunc->stack += getSize(sloc->type);
- stackExtend += getSize(sloc->type);
- } else
- dataExtend += getSize(sloc->type);
-
- /* add it to the stackSpil set */
- addSetHead(&stackSpil,sloc);
- sym->usl.spillLoc = sloc;
- sym->stackSpil = 1;
-
- /* add it to the set of itempStack set
- of the spill location */
- addSetHead(&sloc->usl.itmpStack,sym);
+ /* could not then have to create one , this is the hard part
+ we need to allocate this on the stack : this is really a
+ hack!! but cannot think of anything better at this time */
+
+ sprintf (buffer, "sloc%d", slocNum++);
+ sloc = newiTemp (buffer);
+
+ /* set the type to the spilling symbol */
+ sloc->type = copyLinkChain (sym->type);
+ sloc->etype = getSpec (sloc->type);
+ SPEC_SCLS (sloc->etype) = S_AUTO;
+
+ /* we don't allow it to be allocated`
+ onto the external stack since : so we
+ temporarily turn it off ; we also
+ turn off memory model to prevent
+ the spil from going to the external storage
+ and turn off overlaying
+ */
+ allocLocal (sloc);
+
+ sloc->isref = 1; /* to prevent compiler warning */
+
+ /* if it is on the stack then update the stack */
+ if (IN_STACK (sloc->etype))
+ {
+ currFunc->stack += getSize (sloc->type);
+ stackExtend += getSize (sloc->type);
+ }
+ else
+ dataExtend += getSize (sloc->type);
+
+ /* add it to the stackSpil set */
+ addSetHead (&stackSpil, sloc);
+ sym->usl.spillLoc = sloc;
+ sym->stackSpil = 1;
+
+ /* add it to the set of itempStack set
+ of the spill location */
+ addSetHead (&sloc->usl.itmpStack, sym);
- D(D_ALLOC, ("createStackSpil: created new\n"));
- return sym;
+ D (D_ALLOC, ("createStackSpil: created new\n"));
+ return sym;
}
/*-----------------------------------------------------------------*/
/* isSpiltOnStack - returns true if the spil location is on stack */
/*-----------------------------------------------------------------*/
-bool isSpiltOnStack (symbol *sym)
+bool
+isSpiltOnStack (symbol * sym)
{
- sym_link *etype;
+ sym_link *etype;
- if (!sym)
- return FALSE ;
-
- if (!sym->isspilt)
- return FALSE ;
+ if (!sym)
+ return FALSE;
+
+ if (!sym->isspilt)
+ return FALSE;
/* if (sym->stackSpil) */
-/* return TRUE; */
-
- if (!sym->usl.spillLoc)
- return FALSE;
+/* return TRUE; */
- etype = getSpec(sym->usl.spillLoc->type);
- if (IN_STACK(etype))
- return TRUE;
+ if (!sym->usl.spillLoc)
+ return FALSE;
- return FALSE ;
+ etype = getSpec (sym->usl.spillLoc->type);
+ if (IN_STACK (etype))
+ return TRUE;
+
+ return FALSE;
}
/*-----------------------------------------------------------------*/
/* spillThis - spils a specific operand */
/*-----------------------------------------------------------------*/
-static void spillThis (symbol *sym)
+static void
+spillThis (symbol * sym)
{
- int i;
-
- D(D_ALLOC, ("spillThis: spilling %p\n", sym));
-
- /* if this is rematerializable or has a spillLocation
- we are okay, else we need to create a spillLocation
- for it */
- if (!(sym->remat || sym->usl.spillLoc))
- createStackSpil (sym);
-
- /* mark it has spilt & put it in the spilt set */
- sym->isspilt = 1;
- spiltSet = bitVectSetBit(spiltSet,sym->key);
-
- bitVectUnSetBit(regAssigned,sym->key);
-
- for (i = 0 ; i < sym->nRegs ; i++) {
- if (sym->regs[i]) {
- freeReg(sym->regs[i]);
- sym->regs[i] = NULL;
+ int i;
+
+ D (D_ALLOC, ("spillThis: spilling %p\n", sym));
+
+ /* if this is rematerializable or has a spillLocation
+ we are okay, else we need to create a spillLocation
+ for it */
+ if (!(sym->remat || sym->usl.spillLoc))
+ createStackSpil (sym);
+
+ /* mark it has spilt & put it in the spilt set */
+ sym->isspilt = 1;
+ spiltSet = bitVectSetBit (spiltSet, sym->key);
+
+ bitVectUnSetBit (regAssigned, sym->key);
+
+ for (i = 0; i < sym->nRegs; i++)
+ {
+ if (sym->regs[i])
+ {
+ freeReg (sym->regs[i]);
+ sym->regs[i] = NULL;
}
}
-
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to some
- LIVE ranges */
- if (sym->usl.spillLoc && !sym->remat)
- sym->usl.spillLoc->allocreq = 1;
- return;
+
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to some
+ LIVE ranges */
+ if (sym->usl.spillLoc && !sym->remat)
+ sym->usl.spillLoc->allocreq = 1;
+ return;
}
/** Select a iTemp to spil : rather a simple procedure.
*/
-symbol *selectSpil (iCode *ic, eBBlock *ebp, symbol *forSym)
+symbol *
+selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- bitVect *lrcs= NULL ;
- set *selectS ;
- symbol *sym;
-
- D(D_ALLOC, ("selectSpil: finding spill for ic %p\n", ic));
- /* get the spillable live ranges */
- lrcs = computeSpillable (ic);
-
- /* get all live ranges that are rematerizable */
- if ((selectS = liveRangesWith(lrcs,rematable,ebp,ic))) {
- D(D_ALLOC, ("selectSpil: using remat.\n"));
- /* return the least used of these */
- return leastUsedLR(selectS);
+ bitVect *lrcs = NULL;
+ set *selectS;
+ symbol *sym;
+
+ D (D_ALLOC, ("selectSpil: finding spill for ic %p\n", ic));
+ /* get the spillable live ranges */
+ lrcs = computeSpillable (ic);
+
+ /* get all live ranges that are rematerizable */
+ if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
+ {
+ D (D_ALLOC, ("selectSpil: using remat.\n"));
+ /* return the least used of these */
+ return leastUsedLR (selectS);
}
#if 0
- /* get live ranges with spillLocations in direct space */
- if ((selectS = liveRangesWith(lrcs,directSpilLoc,ebp,ic))) {
- sym = leastUsedLR(selectS);
- strcpy(sym->rname,(sym->usl.spillLoc->rname[0] ?
- sym->usl.spillLoc->rname :
- sym->usl.spillLoc->name));
- sym->spildir = 1;
- /* mark it as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* get live ranges with spillLocations in direct space */
+ if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
+ sym->usl.spillLoc->rname :
+ sym->usl.spillLoc->name));
+ sym->spildir = 1;
+ /* mark it as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* if the symbol is local to the block then */
- if (forSym->liveTo < ebp->lSeq ) {
-
- /* check if there are any live ranges allocated
- to registers that are not used in this block */
- if (!blockSpil && (selectS = liveRangesWith(lrcs,notUsedInBlock,ebp,ic))) {
- sym = leastUsedLR(selectS);
- /* if this is not rematerializable */
- if (!sym->remat) {
- blockSpil++;
- sym->blockSpil = 1;
+ /* if the symbol is local to the block then */
+ if (forSym->liveTo < ebp->lSeq)
+ {
+
+ /* check if there are any live ranges allocated
+ to registers that are not used in this block */
+ if (!blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ /* if this is not rematerializable */
+ if (!sym->remat)
+ {
+ blockSpil++;
+ sym->blockSpil = 1;
}
- return sym;
- }
-
- /* check if there are any live ranges that not
- used in the remainder of the block */
- if (!blockSpil && (selectS = liveRangesWith(lrcs,notUsedInRemaining,ebp,ic))) {
- sym = leastUsedLR (selectS);
- if (sym != ForSym) {
- if (!sym->remat) {
- sym->remainSpil = 1;
- blockSpil++;
+ return sym;
+ }
+
+ /* check if there are any live ranges that not
+ used in the remainder of the block */
+ if (!blockSpil && (selectS = liveRangesWith (lrcs, notUsedInRemaining, ebp, ic)))
+ {
+ sym = leastUsedLR (selectS);
+ if (sym != ForSym)
+ {
+ if (!sym->remat)
+ {
+ sym->remainSpil = 1;
+ blockSpil++;
}
- return sym;
+ return sym;
}
}
}
- /* find live ranges with spillocation && not used as pointers */
- if ((selectS = liveRangesWith(lrcs,hasSpilLocnoUptr,ebp,ic))) {
-
- sym = leastUsedLR(selectS);
- /* mark this as allocation required */
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* find live ranges with spillocation && not used as pointers */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
+ {
+
+ sym = leastUsedLR (selectS);
+ /* mark this as allocation required */
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
-#endif
-
- /* find live ranges with spillocation */
- if ((selectS = liveRangesWith(lrcs,hasSpilLoc,ebp,ic))) {
- D(D_ALLOC, ("selectSpil: using with spill.\n"));
- sym = leastUsedLR(selectS);
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+#endif
+
+ /* find live ranges with spillocation */
+ if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
+ {
+ D (D_ALLOC, ("selectSpil: using with spill.\n"));
+ sym = leastUsedLR (selectS);
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
- /* couldn't find then we need to create a spil
- location on the stack , for which one? the least
- used ofcourse */
- if ((selectS = liveRangesWith(lrcs,noSpilLoc,ebp,ic))) {
- D(D_ALLOC, ("selectSpil: creating new spill.\n"));
- /* return a created spil location */
- sym = createStackSpil(leastUsedLR(selectS));
- sym->usl.spillLoc->allocreq = 1;
- return sym;
+ /* couldn't find then we need to create a spil
+ location on the stack , for which one? the least
+ used ofcourse */
+ if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
+ {
+ D (D_ALLOC, ("selectSpil: creating new spill.\n"));
+ /* return a created spil location */
+ sym = createStackSpil (leastUsedLR (selectS));
+ sym->usl.spillLoc->allocreq = 1;
+ return sym;
}
-
- /* this is an extreme situation we will spill
- this one : happens very rarely but it does happen */
- D(D_ALLOC, ("selectSpil: using spillThis.\n"));
- spillThis ( forSym );
- return forSym;
-
+
+ /* this is an extreme situation we will spill
+ this one : happens very rarely but it does happen */
+ D (D_ALLOC, ("selectSpil: using spillThis.\n"));
+ spillThis (forSym);
+ return forSym;
+
}
/** Spil some variable & mark registers as free.
A spill occurs when an iTemp wont fit into the available registers.
*/
-bool spilSomething (iCode *ic, eBBlock *ebp, symbol *forSym)
+bool
+spilSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
{
- symbol *ssym;
- int i ;
+ symbol *ssym;
+ int i;
- D(D_ALLOC, ("spilSomething: spilling on ic %p\n", ic));
+ D (D_ALLOC, ("spilSomething: spilling on ic %p\n", ic));
- /* get something we can spil */
- ssym = selectSpil(ic,ebp,forSym);
-
- /* mark it as spilt */
- ssym->isspilt = 1;
- spiltSet = bitVectSetBit(spiltSet,ssym->key);
-
- /* mark it as not register assigned &
- take it away from the set */
- bitVectUnSetBit(regAssigned,ssym->key);
-
- /* mark the registers as free */
- for (i = 0 ; i < ssym->nRegs ;i++ )
- if (ssym->regs[i])
- freeReg(ssym->regs[i]);
+ /* get something we can spil */
+ ssym = selectSpil (ic, ebp, forSym);
+
+ /* mark it as spilt */
+ ssym->isspilt = 1;
+ spiltSet = bitVectSetBit (spiltSet, ssym->key);
+
+ /* mark it as not register assigned &
+ take it away from the set */
+ bitVectUnSetBit (regAssigned, ssym->key);
+
+ /* mark the registers as free */
+ for (i = 0; i < ssym->nRegs; i++)
+ if (ssym->regs[i])
+ freeReg (ssym->regs[i]);
#if 0
- /* if spilt on stack then free up r0 & r1
- if they could have been assigned to as gprs */
- if (!ptrRegReq && isSpiltOnStack(ssym) ) {
- ptrRegReq++ ;
- spillLRWithPtrReg(ssym);
+ /* if spilt on stack then free up r0 & r1
+ if they could have been assigned to as gprs */
+ if (!ptrRegReq && isSpiltOnStack (ssym))
+ {
+ ptrRegReq++;
+ spillLRWithPtrReg (ssym);
}
- /* if this was a block level spil then insert push & pop
- at the start & end of block respectively */
- if (ssym->blockSpil) {
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push to the start of the block */
- addiCodeToeBBlock(ebp,nic,( ebp->sch->op == LABEL ?
+ /* if this was a block level spil then insert push & pop
+ at the start & end of block respectively */
+ if (ssym->blockSpil)
+ {
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push to the start of the block */
+ addiCodeToeBBlock (ebp, nic, (ebp->sch->op == LABEL ?
ebp->sch->next : ebp->sch));
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
- }
-
- /* if spilt because not used in the remainder of the
- block then add a push before this instruction and
- a pop at the end of the block */
- if (ssym->remainSpil) {
-
- iCode *nic = newiCode(IPUSH,operandFromSymbol(ssym),NULL);
- /* add push just before this instruction */
- addiCodeToeBBlock(ebp,nic,ic);
-
- nic = newiCode(IPOP,operandFromSymbol(ssym),NULL);
- /* add pop to the end of the block */
- addiCodeToeBBlock(ebp,nic,NULL);
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
+ }
+
+ /* if spilt because not used in the remainder of the
+ block then add a push before this instruction and
+ a pop at the end of the block */
+ if (ssym->remainSpil)
+ {
+
+ iCode *nic = newiCode (IPUSH, operandFromSymbol (ssym), NULL);
+ /* add push just before this instruction */
+ addiCodeToeBBlock (ebp, nic, ic);
+
+ nic = newiCode (IPOP, operandFromSymbol (ssym), NULL);
+ /* add pop to the end of the block */
+ addiCodeToeBBlock (ebp, nic, NULL);
}
#endif
- D(D_ALLOC, ("spilSomething: done.\n"));
+ D (D_ALLOC, ("spilSomething: done.\n"));
- if (ssym == forSym )
- return FALSE ;
- else
- return TRUE ;
+ if (ssym == forSym)
+ return FALSE;
+ else
+ return TRUE;
}
/** Will try for GPR if not spil.
*/
-regs *getRegGpr (iCode *ic, eBBlock *ebp,symbol *sym)
+regs *
+getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym)
{
- regs *reg;
-
- D(D_ALLOC, ("getRegGpr: on ic %p\n", ic));
- tryAgain:
- /* try for gpr type */
- if ((reg = allocReg(REG_GPR))) {
- D(D_ALLOC, ("getRegGpr: got a reg.\n"));
- return reg;
+ regs *reg;
+
+ D (D_ALLOC, ("getRegGpr: on ic %p\n", ic));
+tryAgain:
+ /* try for gpr type */
+ if ((reg = allocReg (REG_GPR)))
+ {
+ D (D_ALLOC, ("getRegGpr: got a reg.\n"));
+ return reg;
}
- /* we have to spil */
- if (!spilSomething (ic,ebp,sym)) {
- D(D_ALLOC, ("getRegGpr: have to spill.\n"));
- return NULL ;
+ /* we have to spil */
+ if (!spilSomething (ic, ebp, sym))
+ {
+ D (D_ALLOC, ("getRegGpr: have to spill.\n"));
+ return NULL;
}
- /* this looks like an infinite loop but
- in really selectSpil will abort */
- goto tryAgain ;
+ /* this looks like an infinite loop but
+ in really selectSpil will abort */
+ goto tryAgain;
}
/** Symbol has a given register.
*/
-static bool symHasReg(symbol *sym,regs *reg)
+static bool
+symHasReg (symbol * sym, regs * reg)
{
- int i;
+ int i;
- for ( i = 0 ; i < sym->nRegs ; i++)
- if (sym->regs[i] == reg)
- return TRUE;
-
- return FALSE;
+ for (i = 0; i < sym->nRegs; i++)
+ if (sym->regs[i] == reg)
+ return TRUE;
+
+ return FALSE;
}
/** Check the live to and if they have registers & are not spilt then
free up the registers
*/
-static void deassignLRs (iCode *ic, eBBlock *ebp)
+static void
+deassignLRs (iCode * ic, eBBlock * ebp)
{
- symbol *sym;
- int k;
- symbol *result;
-
- for (sym = hTabFirstItem(liveRanges,&k); sym;
- sym = hTabNextItem(liveRanges,&k)) {
-
- symbol *psym= NULL;
- /* if it does not end here */
- if (sym->liveTo > ic->seq )
- continue ;
-
- /* if it was spilt on stack then we can
- mark the stack spil location as free */
- if (sym->isspilt ) {
- if (sym->stackSpil) {
- sym->usl.spillLoc->isFree = 1;
- sym->stackSpil = 0;
+ symbol *sym;
+ int k;
+ symbol *result;
+
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
+
+ symbol *psym = NULL;
+ /* if it does not end here */
+ if (sym->liveTo > ic->seq)
+ continue;
+
+ /* if it was spilt on stack then we can
+ mark the stack spil location as free */
+ if (sym->isspilt)
+ {
+ if (sym->stackSpil)
+ {
+ sym->usl.spillLoc->isFree = 1;
+ sym->stackSpil = 0;
}
- continue ;
+ continue;
}
-
- if (!bitVectBitValue(regAssigned,sym->key))
- continue;
-
- /* special case check if this is an IFX &
- the privious one was a pop and the
- previous one was not spilt then keep track
- of the symbol */
- if (ic->op == IFX && ic->prev &&
- ic->prev->op == IPOP &&
- !ic->prev->parmPush &&
- !OP_SYMBOL(IC_LEFT(ic->prev))->isspilt)
- psym = OP_SYMBOL(IC_LEFT(ic->prev));
-
- D(D_ALLOC, ("deassignLRs: in loop on sym %p nregs %u\n", sym, sym->nRegs));
-
- if (sym->nRegs) {
- int i = 0;
-
- bitVectUnSetBit(regAssigned,sym->key);
-
- /* if the result of this one needs registers
- and does not have it then assign it right
- away */
- if (IC_RESULT(ic) &&
- ! (SKIP_IC2(ic) || /* not a special icode */
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP ||
- ic->op == RETURN) &&
- (result = OP_SYMBOL(IC_RESULT(ic))) && /* has a result */
- result->liveTo > ic->seq && /* and will live beyond this */
- result->liveTo <= ebp->lSeq && /* does not go beyond this block */
- result->regType == sym->regType && /* same register types */
- result->nRegs && /* which needs registers */
- ! result->isspilt && /* and does not already have them */
- ! result->remat &&
- ! bitVectBitValue(regAssigned,result->key) &&
- /* the number of free regs + number of regs in this LR
- can accomodate the what result Needs */
- ((nfreeRegsType(result->regType) +
- sym->nRegs) >= result->nRegs)
- ) {
- for (i = 0 ; i < result->nRegs ; i++) {
- if (i < sym->nRegs )
- result->regs[i] = sym->regs[i] ;
- else
- result->regs[i] = getRegGpr (ic,ebp,result);
-
- /* if the allocation falied which means
- this was spilt then break */
- if (!result->regs[i]) {
- wassert(0);
- assert(0);
- break;
+
+ if (!bitVectBitValue (regAssigned, sym->key))
+ continue;
+
+ /* special case check if this is an IFX &
+ the privious one was a pop and the
+ previous one was not spilt then keep track
+ of the symbol */
+ if (ic->op == IFX && ic->prev &&
+ ic->prev->op == IPOP &&
+ !ic->prev->parmPush &&
+ !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt)
+ psym = OP_SYMBOL (IC_LEFT (ic->prev));
+
+ D (D_ALLOC, ("deassignLRs: in loop on sym %p nregs %u\n", sym, sym->nRegs));
+
+ if (sym->nRegs)
+ {
+ int i = 0;
+
+ bitVectUnSetBit (regAssigned, sym->key);
+
+ /* if the result of this one needs registers
+ and does not have it then assign it right
+ away */
+ if (IC_RESULT (ic) &&
+ !(SKIP_IC2 (ic) || /* not a special icode */
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP ||
+ ic->op == RETURN) &&
+ (result = OP_SYMBOL (IC_RESULT (ic))) && /* has a result */
+ result->liveTo > ic->seq && /* and will live beyond this */
+ result->liveTo <= ebp->lSeq && /* does not go beyond this block */
+ result->regType == sym->regType && /* same register types */
+ result->nRegs && /* which needs registers */
+ !result->isspilt && /* and does not already have them */
+ !result->remat &&
+ !bitVectBitValue (regAssigned, result->key) &&
+ /* the number of free regs + number of regs in this LR
+ can accomodate the what result Needs */
+ ((nfreeRegsType (result->regType) +
+ sym->nRegs) >= result->nRegs)
+ )
+ {
+ for (i = 0; i < result->nRegs; i++)
+ {
+ if (i < sym->nRegs)
+ result->regs[i] = sym->regs[i];
+ else
+ result->regs[i] = getRegGpr (ic, ebp, result);
+
+ /* if the allocation falied which means
+ this was spilt then break */
+ if (!result->regs[i])
+ {
+ wassert (0);
+ assert (0);
+ break;
}
}
- regAssigned = bitVectSetBit(regAssigned,result->key);
- }
-
- /* free the remaining */
- for (; i < sym->nRegs ; i++) {
- if (psym) {
- if (!symHasReg(psym,sym->regs[i]))
- freeReg(sym->regs[i]);
- } else
- freeReg(sym->regs[i]);
- // sym->regs[i] = NULL;
+ regAssigned = bitVectSetBit (regAssigned, result->key);
+ }
+
+ /* free the remaining */
+ for (; i < sym->nRegs; i++)
+ {
+ if (psym)
+ {
+ if (!symHasReg (psym, sym->regs[i]))
+ freeReg (sym->regs[i]);
+ }
+ else
+ freeReg (sym->regs[i]);
+ // sym->regs[i] = NULL;
}
}
}
/** Reassign this to registers.
*/
-static void reassignLR (operand *op)
+static void
+reassignLR (operand * op)
{
- symbol *sym = OP_SYMBOL(op);
- int i;
+ symbol *sym = OP_SYMBOL (op);
+ int i;
+
+ D (D_ALLOC, ("reassingLR: on sym %p\n", sym));
- D(D_ALLOC, ("reassingLR: on sym %p\n", sym));
+ /* not spilt any more */
+ sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
+ bitVectUnSetBit (spiltSet, sym->key);
- /* not spilt any more */
- sym->isspilt = sym->blockSpil = sym->remainSpil = 0;
- bitVectUnSetBit(spiltSet,sym->key);
-
- regAssigned = bitVectSetBit(regAssigned,sym->key);
+ regAssigned = bitVectSetBit (regAssigned, sym->key);
- blockSpil--;
+ blockSpil--;
- for (i=0;i<sym->nRegs;i++)
- sym->regs[i]->isFree = 0;
+ for (i = 0; i < sym->nRegs; i++)
+ sym->regs[i]->isFree = 0;
}
/** Determines if allocating will cause a spill.
*/
-static int willCauseSpill ( int nr, int rt)
+static int
+willCauseSpill (int nr, int rt)
{
- /* first check if there are any avlb registers
- of te type required */
- if (nFreeRegs(0) >= nr)
- return 0;
+ /* first check if there are any avlb registers
+ of te type required */
+ if (nFreeRegs (0) >= nr)
+ return 0;
- /* it will cause a spil */
- return 1;
+ /* it will cause a spil */
+ return 1;
}
/** The allocator can allocate same registers to result and operand,
if this happens make sure they are in the same position as the operand
otherwise chaos results.
*/
-static void positionRegs (symbol *result, symbol *opsym, int lineno)
+static void
+positionRegs (symbol * result, symbol * opsym, int lineno)
{
- int count = min(result->nRegs,opsym->nRegs);
- int i , j = 0, shared = 0;
-
- D(D_ALLOC, ("positionRegs: on result %p opsum %p line %u\n", result, opsym, lineno));
-
- /* if the result has been spilt then cannot share */
- if (opsym->isspilt)
- return ;
- again:
- shared = 0;
- /* first make sure that they actually share */
- for ( i = 0 ; i < count; i++ ) {
- for (j = 0 ; j < count ; j++ ) {
- if (result->regs[i] == opsym->regs[j] && i !=j) {
- shared = 1;
- goto xchgPositions;
+ int count = min (result->nRegs, opsym->nRegs);
+ int i, j = 0, shared = 0;
+
+ D (D_ALLOC, ("positionRegs: on result %p opsum %p line %u\n", result, opsym, lineno));
+
+ /* if the result has been spilt then cannot share */
+ if (opsym->isspilt)
+ return;
+again:
+ shared = 0;
+ /* first make sure that they actually share */
+ for (i = 0; i < count; i++)
+ {
+ for (j = 0; j < count; j++)
+ {
+ if (result->regs[i] == opsym->regs[j] && i != j)
+ {
+ shared = 1;
+ goto xchgPositions;
}
}
}
- xchgPositions:
- if (shared) {
- regs *tmp = result->regs[i];
- result->regs[i] = result->regs[j];
- result->regs[j] = tmp;
- goto again;
+xchgPositions:
+ if (shared)
+ {
+ regs *tmp = result->regs[i];
+ result->regs[i] = result->regs[j];
+ result->regs[j] = tmp;
+ goto again;
}
}
/** Try to allocate a pair of registers to the symbol.
*/
-bool tryAllocatingRegPair(symbol *sym)
+bool
+tryAllocatingRegPair (symbol * sym)
{
- int i;
- wassert(sym->nRegs == 2);
- for ( i = 0 ; i < _nRegs ; i+=2 ) {
- if ((regsZ80[i].isFree)&&(regsZ80[i+1].isFree)) {
- regsZ80[i].isFree = 0;
- sym->regs[0] = ®sZ80[i];
- regsZ80[i+1].isFree = 0;
- sym->regs[1] = ®sZ80[i+1];
- if (currFunc) {
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i);
- currFunc->regsUsed =
- bitVectSetBit(currFunc->regsUsed,i+1);
+ int i;
+ wassert (sym->nRegs == 2);
+ for (i = 0; i < _nRegs; i += 2)
+ {
+ if ((regsZ80[i].isFree) && (regsZ80[i + 1].isFree))
+ {
+ regsZ80[i].isFree = 0;
+ sym->regs[0] = ®sZ80[i];
+ regsZ80[i + 1].isFree = 0;
+ sym->regs[1] = ®sZ80[i + 1];
+ if (currFunc)
+ {
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i);
+ currFunc->regsUsed =
+ bitVectSetBit (currFunc->regsUsed, i + 1);
}
- D(D_ALLOC, ("tryAllocRegPair: succeded for sym %p\n", sym));
- return TRUE;
+ D (D_ALLOC, ("tryAllocRegPair: succeded for sym %p\n", sym));
+ return TRUE;
}
}
- D(D_ALLOC, ("tryAllocRegPair: failed on sym %p\n", sym));
- return FALSE;
+ D (D_ALLOC, ("tryAllocRegPair: failed on sym %p\n", sym));
+ return FALSE;
}
/** Serially allocate registers to the variables.
This is the main register allocation function. It is called after
packing.
*/
-static void serialRegAssign (eBBlock **ebbs, int count)
+static void
+serialRegAssign (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
-
- iCode *ic;
-
- if (ebbs[i]->noPath &&
- (ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* of all instructions do */
- for (ic = ebbs[i]->sch ; ic ; ic = ic->next) {
-
- /* if this is an ipop that means some live
- range will have to be assigned again */
- if (ic->op == IPOP) {
- wassert(0);
- reassignLR (IC_LEFT(ic));
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* of all instructions do */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ /* if this is an ipop that means some live
+ range will have to be assigned again */
+ if (ic->op == IPOP)
+ {
+ wassert (0);
+ reassignLR (IC_LEFT (ic));
}
- /* if result is present && is a true symbol */
- if (IC_RESULT(ic) && ic->op != IFX &&
- IS_TRUE_SYMOP(IC_RESULT(ic)))
- OP_SYMBOL(IC_RESULT(ic))->allocreq = 1;
-
- /* take away registers from live
- ranges that end at this instruction */
- deassignLRs (ic, ebbs[i]) ;
-
- /* some don't need registers */
- /* MLH: removed RESULT and POINTER_SET condition */
- if (SKIP_IC2(ic) ||
- ic->op == JUMPTABLE ||
- ic->op == IFX ||
- ic->op == IPUSH ||
- ic->op == IPOP)
- continue;
-
- /* now we need to allocate registers only for the result */
- if (IC_RESULT(ic)) {
- symbol *sym = OP_SYMBOL(IC_RESULT(ic));
- bitVect *spillable;
- int willCS ;
- int j;
-
- D(D_ALLOC, ("serialRegAssign: in loop on result %p\n", sym));
-
- /* if it does not need or is spilt
- or is already assigned to registers
- or will not live beyond this instructions */
- if (!sym->nRegs ||
- sym->isspilt ||
- bitVectBitValue(regAssigned,sym->key) ||
- sym->liveTo <= ic->seq) {
- D(D_ALLOC, ("serialRegAssign: wont live long enough.\n"));
- continue ;
+ /* if result is present && is a true symbol */
+ if (IC_RESULT (ic) && ic->op != IFX &&
+ IS_TRUE_SYMOP (IC_RESULT (ic)))
+ OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
+
+ /* take away registers from live
+ ranges that end at this instruction */
+ deassignLRs (ic, ebbs[i]);
+
+ /* some don't need registers */
+ /* MLH: removed RESULT and POINTER_SET condition */
+ if (SKIP_IC2 (ic) ||
+ ic->op == JUMPTABLE ||
+ ic->op == IFX ||
+ ic->op == IPUSH ||
+ ic->op == IPOP)
+ continue;
+
+ /* now we need to allocate registers only for the result */
+ if (IC_RESULT (ic))
+ {
+ symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+ bitVect *spillable;
+ int willCS;
+ int j;
+
+ D (D_ALLOC, ("serialRegAssign: in loop on result %p\n", sym));
+
+ /* if it does not need or is spilt
+ or is already assigned to registers
+ or will not live beyond this instructions */
+ if (!sym->nRegs ||
+ sym->isspilt ||
+ bitVectBitValue (regAssigned, sym->key) ||
+ sym->liveTo <= ic->seq)
+ {
+ D (D_ALLOC, ("serialRegAssign: wont live long enough.\n"));
+ continue;
}
- /* if some liverange has been spilt at the block level
- and this one live beyond this block then spil this
- to be safe */
- if (blockSpil && sym->liveTo > ebbs[i]->lSeq) {
- D(D_ALLOC, ("serialRegAssign: \"spilling to be safe.\"\n"));
- spillThis (sym);
- continue ;
+ /* if some liverange has been spilt at the block level
+ and this one live beyond this block then spil this
+ to be safe */
+ if (blockSpil && sym->liveTo > ebbs[i]->lSeq)
+ {
+ D (D_ALLOC, ("serialRegAssign: \"spilling to be safe.\"\n"));
+ spillThis (sym);
+ continue;
}
- /* if trying to allocate this will cause
- a spill and there is nothing to spill
- or this one is rematerializable then
- spill this one */
- willCS = willCauseSpill(sym->nRegs,sym->regType);
- spillable = computeSpillable(ic);
- if ( sym->remat ||
- (willCS && bitVectIsZero(spillable) ) ) {
-
- D(D_ALLOC, ("serialRegAssign: \"remat spill\"\n"));
- spillThis (sym) ;
- continue ;
+ /* if trying to allocate this will cause
+ a spill and there is nothing to spill
+ or this one is rematerializable then
+ spill this one */
+ willCS = willCauseSpill (sym->nRegs, sym->regType);
+ spillable = computeSpillable (ic);
+ if (sym->remat ||
+ (willCS && bitVectIsZero (spillable)))
+ {
+
+ D (D_ALLOC, ("serialRegAssign: \"remat spill\"\n"));
+ spillThis (sym);
+ continue;
}
- /* if it has a spillocation & is used less than
- all other live ranges then spill this */
- if ( willCS && sym->usl.spillLoc ) {
-
- symbol *leastUsed =
- leastUsedLR(liveRangesWith (spillable ,
- allLRs,
- ebbs[i],
- ic));
- if (leastUsed &&
- leastUsed->used > sym->used) {
- spillThis (sym);
- continue;
+ /* if it has a spillocation & is used less than
+ all other live ranges then spill this */
+ if (willCS && sym->usl.spillLoc)
+ {
+
+ symbol *leastUsed =
+ leastUsedLR (liveRangesWith (spillable,
+ allLRs,
+ ebbs[i],
+ ic));
+ if (leastUsed &&
+ leastUsed->used > sym->used)
+ {
+ spillThis (sym);
+ continue;
}
- }
+ }
- /* else we assign registers to it */
- regAssigned = bitVectSetBit(regAssigned,sym->key);
+ /* else we assign registers to it */
+ regAssigned = bitVectSetBit (regAssigned, sym->key);
- /* Special case: Try to fit into a reg pair if
- available */
- D(D_ALLOC, ("serialRegAssign: actually allocing regs!\n"));
- if ((sym->nRegs == 2)&&tryAllocatingRegPair(sym)) {
+ /* Special case: Try to fit into a reg pair if
+ available */
+ D (D_ALLOC, ("serialRegAssign: actually allocing regs!\n"));
+ if ((sym->nRegs == 2) && tryAllocatingRegPair (sym))
+ {
}
- else {
- for (j = 0 ; j < sym->nRegs ;j++ ) {
- sym->regs[j] = getRegGpr(ic,ebbs[i],sym);
-
- /* if the allocation falied which means
- this was spilt then break */
- if (!sym->regs[j]) {
- D(D_ALLOC, ("Couldnt alloc (spill)\n"))
+ else
+ {
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
+
+ /* if the allocation falied which means
+ this was spilt then break */
+ if (!sym->regs[j])
+ {
+ D (D_ALLOC, ("Couldnt alloc (spill)\n"))
break;
}
}
}
- /* if it shares registers with operands make sure
- that they are in the same position */
- if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->nRegs && ic->op != '=')
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_LEFT(ic)),ic->lineno);
- /* do the same for the right operand */
- if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->nRegs)
- positionRegs(OP_SYMBOL(IC_RESULT(ic)),
- OP_SYMBOL(IC_RIGHT(ic)),ic->lineno);
-
- }
+ /* if it shares registers with operands make sure
+ that they are in the same position */
+ if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
+ /* do the same for the right operand */
+ if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->nRegs)
+ positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+ OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
+
+ }
}
}
}
/*-----------------------------------------------------------------*/
/* rUmaskForOp :- returns register mask for an operand */
/*-----------------------------------------------------------------*/
-bitVect *rUmaskForOp (operand *op)
+bitVect *
+rUmaskForOp (operand * op)
{
- bitVect *rumask;
- symbol *sym;
- int j;
-
- /* only temporaries are assigned registers */
- if (!IS_ITEMP(op))
- return NULL;
+ bitVect *rumask;
+ symbol *sym;
+ int j;
- sym = OP_SYMBOL(op);
-
- /* if spilt or no registers assigned to it
- then nothing */
- if (sym->isspilt || !sym->nRegs)
- return NULL;
+ /* only temporaries are assigned registers */
+ if (!IS_ITEMP (op))
+ return NULL;
+
+ sym = OP_SYMBOL (op);
- rumask = newBitVect(_nRegs);
+ /* if spilt or no registers assigned to it
+ then nothing */
+ if (sym->isspilt || !sym->nRegs)
+ return NULL;
+
+ rumask = newBitVect (_nRegs);
- for (j = 0; j < sym->nRegs; j++) {
- rumask = bitVectSetBit(rumask, sym->regs[j]->rIdx);
+ for (j = 0; j < sym->nRegs; j++)
+ {
+ rumask = bitVectSetBit (rumask, sym->regs[j]->rIdx);
}
- return rumask;
+ return rumask;
}
/** Returns bit vector of registers used in iCode.
*/
-bitVect *regsUsedIniCode (iCode *ic)
+bitVect *
+regsUsedIniCode (iCode * ic)
{
- bitVect *rmask = newBitVect(_nRegs);
+ bitVect *rmask = newBitVect (_nRegs);
- /* do the special cases first */
- if (ic->op == IFX ) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_COND(ic)));
- goto ret;
+ /* do the special cases first */
+ if (ic->op == IFX)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_COND (ic)));
+ goto ret;
}
- /* for the jumptable */
- if (ic->op == JUMPTABLE) {
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_JTCOND(ic)));
+ /* for the jumptable */
+ if (ic->op == JUMPTABLE)
+ {
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_JTCOND (ic)));
- goto ret;
+ goto ret;
}
- /* of all other cases */
- if (IC_LEFT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_LEFT(ic)));
-
-
- if (IC_RIGHT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RIGHT(ic)));
+ /* of all other cases */
+ if (IC_LEFT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_LEFT (ic)));
+
- if (IC_RESULT(ic))
- rmask = bitVectUnion(rmask,
- rUmaskForOp(IC_RESULT(ic)));
+ if (IC_RIGHT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RIGHT (ic)));
- ret:
- return rmask;
+ if (IC_RESULT (ic))
+ rmask = bitVectUnion (rmask,
+ rUmaskForOp (IC_RESULT (ic)));
+
+ret:
+ return rmask;
}
/** For each instruction will determine the regsUsed.
*/
-static void createRegMask (eBBlock **ebbs, int count)
+static void
+createRegMask (eBBlock ** ebbs, int count)
{
- int i;
-
- /* for all blocks */
- for (i = 0; i < count ; i++ ) {
- iCode *ic ;
-
- if ( ebbs[i]->noPath &&
- ( ebbs[i]->entryLabel != entryLabel &&
- ebbs[i]->entryLabel != returnLabel ))
- continue ;
-
- /* for all instructions */
- for ( ic = ebbs[i]->sch ; ic ; ic = ic->next ) {
-
- int j;
-
- if (SKIP_IC2(ic) || !ic->rlive)
- continue ;
-
- /* first mark the registers used in this
- instruction */
- ic->rUsed = regsUsedIniCode(ic);
- funcrUsed = bitVectUnion(funcrUsed,ic->rUsed);
-
- /* now create the register mask for those
- registers that are in use : this is a
- super set of ic->rUsed */
- ic->rMask = newBitVect(_nRegs+1);
-
- /* for all live Ranges alive at this point */
- for (j = 1; j < ic->rlive->size; j++ ) {
- symbol *sym;
- int k;
-
- /* if not alive then continue */
- if (!bitVectBitValue(ic->rlive,j))
- continue ;
-
- /* find the live range we are interested in */
- if (!(sym = hTabItemWithKey(liveRanges,j))) {
- werror (E_INTERNAL_ERROR,__FILE__,__LINE__,
- "createRegMask cannot find live range");
- exit(0);
+ int i;
+
+ /* for all blocks */
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+
+ if (ebbs[i]->noPath &&
+ (ebbs[i]->entryLabel != entryLabel &&
+ ebbs[i]->entryLabel != returnLabel))
+ continue;
+
+ /* for all instructions */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+
+ int j;
+
+ if (SKIP_IC2 (ic) || !ic->rlive)
+ continue;
+
+ /* first mark the registers used in this
+ instruction */
+ ic->rUsed = regsUsedIniCode (ic);
+ funcrUsed = bitVectUnion (funcrUsed, ic->rUsed);
+
+ /* now create the register mask for those
+ registers that are in use : this is a
+ super set of ic->rUsed */
+ ic->rMask = newBitVect (_nRegs + 1);
+
+ /* for all live Ranges alive at this point */
+ for (j = 1; j < ic->rlive->size; j++)
+ {
+ symbol *sym;
+ int k;
+
+ /* if not alive then continue */
+ if (!bitVectBitValue (ic->rlive, j))
+ continue;
+
+ /* find the live range we are interested in */
+ if (!(sym = hTabItemWithKey (liveRanges, j)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "createRegMask cannot find live range");
+ exit (0);
}
- /* if no register assigned to it */
- if (!sym->nRegs || sym->isspilt)
- continue ;
+ /* if no register assigned to it */
+ if (!sym->nRegs || sym->isspilt)
+ continue;
- /* for all the registers allocated to it */
- for (k = 0 ; k < sym->nRegs ;k++)
- if (sym->regs[k])
- ic->rMask =
- bitVectSetBit(ic->rMask,sym->regs[k]->rIdx);
+ /* for all the registers allocated to it */
+ for (k = 0; k < sym->nRegs; k++)
+ if (sym->regs[k])
+ ic->rMask =
+ bitVectSetBit (ic->rMask, sym->regs[k]->rIdx);
}
}
}
/** Returns the rematerialized string for a remat var.
*/
-char *rematStr (symbol *sym)
+char *
+rematStr (symbol * sym)
{
- char *s = buffer;
- iCode *ic = sym->rematiCode;
-
- while (1) {
-
- /* if plus or minus print the right hand side */
- if (ic->op == '+' || ic->op == '-') {
- sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
- ic->op );
- s += strlen(s);
- ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
- continue ;
- }
- /* we reached the end */
- sprintf(s,"%s",OP_SYMBOL(IC_LEFT(ic))->rname);
- break;
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
+
+ while (1)
+ {
+
+ /* if plus or minus print the right hand side */
+ if (ic->op == '+' || ic->op == '-')
+ {
+ sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+ ic->op);
+ s += strlen (s);
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ continue;
+ }
+ /* we reached the end */
+ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ break;
}
- return buffer ;
+ return buffer;
}
/*-----------------------------------------------------------------*/
/* regTypeNum - computes the type & number of registers required */
/*-----------------------------------------------------------------*/
-static void regTypeNum (void)
+static void
+regTypeNum (void)
{
- symbol *sym;
- int k;
-
- /* for each live range do */
- for ( sym = hTabFirstItem(liveRanges,&k); sym ;
- sym = hTabNextItem(liveRanges,&k)) {
-
- /* if used zero times then no registers needed */
- if ((sym->liveTo - sym->liveFrom) == 0)
- continue ;
-
- D(D_ALLOC, ("regTypeNum: loop on sym %p\n", sym));
-
- /* if the live range is a temporary */
- if (sym->isitmp) {
-
- /* if the type is marked as a conditional */
- if (sym->regType == REG_CND)
- continue ;
-
- /* if used in return only then we don't
- need registers */
- if (sym->ruonly || sym->accuse) {
- if (IS_AGGREGATE(sym->type) || sym->isptr)
- sym->type = aggrToPtr(sym->type,FALSE);
- continue ;
+ symbol *sym;
+ int k;
+
+ /* for each live range do */
+ for (sym = hTabFirstItem (liveRanges, &k); sym;
+ sym = hTabNextItem (liveRanges, &k))
+ {
+
+ /* if used zero times then no registers needed */
+ if ((sym->liveTo - sym->liveFrom) == 0)
+ continue;
+
+ D (D_ALLOC, ("regTypeNum: loop on sym %p\n", sym));
+
+ /* if the live range is a temporary */
+ if (sym->isitmp)
+ {
+
+ /* if the type is marked as a conditional */
+ if (sym->regType == REG_CND)
+ continue;
+
+ /* if used in return only then we don't
+ need registers */
+ if (sym->ruonly || sym->accuse)
+ {
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ sym->type = aggrToPtr (sym->type, FALSE);
+ continue;
}
- /* if not then we require registers */
- D(D_ALLOC, ("regTypeNum: isagg %u nRegs %u type %p\n", IS_AGGREGATE(sym->type) || sym->isptr, sym->nRegs, sym->type));
- sym->nRegs = ((IS_AGGREGATE(sym->type) || sym->isptr ) ?
- getSize(sym->type = aggrToPtr(sym->type,FALSE)) :
- getSize(sym->type));
- D(D_ALLOC, ("regTypeNum: setting nRegs of %s (%p) to %u\n", sym->name, sym, sym->nRegs));
-
- D(D_ALLOC, ("regTypeNum: setup to assign regs sym %p\n", sym));
-
- if (sym->nRegs > 4) {
- fprintf(stderr,"allocated more than 4 or 0 registers for type ");
- printTypeChain(sym->type,stderr);fprintf(stderr,"\n");
- }
-
- /* determine the type of register required */
- /* Always general purpose */
- sym->regType = REG_GPR ;
-
- } else {
- /* for the first run we don't provide */
- /* registers for true symbols we will */
- /* see how things go */
- D(D_ALLOC, ("regTypeNum: #2 setting num of %p to 0\n", sym));
- sym->nRegs = 0;
+ /* if not then we require registers */
+ D (D_ALLOC, ("regTypeNum: isagg %u nRegs %u type %p\n", IS_AGGREGATE (sym->type) || sym->isptr, sym->nRegs, sym->type));
+ sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
+ getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
+ getSize (sym->type));
+ D (D_ALLOC, ("regTypeNum: setting nRegs of %s (%p) to %u\n", sym->name, sym, sym->nRegs));
+
+ D (D_ALLOC, ("regTypeNum: setup to assign regs sym %p\n", sym));
+
+ if (sym->nRegs > 4)
+ {
+ fprintf (stderr, "allocated more than 4 or 0 registers for type ");
+ printTypeChain (sym->type, stderr);
+ fprintf (stderr, "\n");
+ }
+
+ /* determine the type of register required */
+ /* Always general purpose */
+ sym->regType = REG_GPR;
+
+ }
+ else
+ {
+ /* for the first run we don't provide */
+ /* registers for true symbols we will */
+ /* see how things go */
+ D (D_ALLOC, ("regTypeNum: #2 setting num of %p to 0\n", sym));
+ sym->nRegs = 0;
}
}
-
+
}
/** Mark all registers as free.
*/
-static void freeAllRegs()
+static void
+freeAllRegs ()
{
- int i;
+ int i;
- D(D_ALLOC, ("freeAllRegs: running.\n"));
+ D (D_ALLOC, ("freeAllRegs: running.\n"));
- for (i=0;i< _nRegs;i++ )
- regsZ80[i].isFree = 1;
+ for (i = 0; i < _nRegs; i++)
+ regsZ80[i].isFree = 1;
}
/*-----------------------------------------------------------------*/
/* deallocStackSpil - this will set the stack pointer back */
/*-----------------------------------------------------------------*/
-DEFSETFUNC(deallocStackSpil)
+DEFSETFUNC (deallocStackSpil)
{
- symbol *sym = item;
+ symbol *sym = item;
- deallocLocal(sym);
- return 0;
+ deallocLocal (sym);
+ return 0;
}
/** Register reduction for assignment.
*/
-static int packRegsForAssign (iCode *ic,eBBlock *ebp)
+static int
+packRegsForAssign (iCode * ic, eBBlock * ebp)
{
- iCode *dic, *sic;
+ iCode *dic, *sic;
- D(D_ALLOC, ("packRegsForAssing: running on ic %p\n", ic));
-
- if (
- /* !IS_TRUE_SYMOP(IC_RESULT(ic)) ||*/
- !IS_ITEMP(IC_RIGHT(ic)) ||
- OP_LIVETO(IC_RIGHT(ic)) > ic->seq ||
- OP_SYMBOL(IC_RIGHT(ic))->isind)
- return 0;
+ D (D_ALLOC, ("packRegsForAssing: running on ic %p\n", ic));
-#if 0
- /* if the true symbol is defined in far space or on stack
- then we should not since this will increase register pressure */
- if (isOperandInFarSpace(IC_RESULT(ic))) {
- if ((dic = farSpacePackable(ic)))
- goto pack;
- else
- return 0;
+ if (
+ /* !IS_TRUE_SYMOP(IC_RESULT(ic)) || */
+ !IS_ITEMP (IC_RIGHT (ic)) ||
+ OP_LIVETO (IC_RIGHT (ic)) > ic->seq ||
+ OP_SYMBOL (IC_RIGHT (ic))->isind)
+ return 0;
+
+#if 0
+ /* if the true symbol is defined in far space or on stack
+ then we should not since this will increase register pressure */
+ if (isOperandInFarSpace (IC_RESULT (ic)))
+ {
+ if ((dic = farSpacePackable (ic)))
+ goto pack;
+ else
+ return 0;
}
#endif
- /* find the definition of iTempNN scanning backwards if we find a
- a use of the true symbol in before we find the definition then
- we cannot */
- for ( dic = ic->prev ; dic ; dic = dic->prev) {
- /* if there is a function call and this is
- a parameter & not my parameter then don't pack it */
- if ( (dic->op == CALL || dic->op == PCALL) &&
- (OP_SYMBOL(IC_RESULT(ic))->_isparm &&
- !OP_SYMBOL(IC_RESULT(ic))->ismyparm)) {
- dic = NULL;
- break;
+ /* find the definition of iTempNN scanning backwards if we find a
+ a use of the true symbol in before we find the definition then
+ we cannot */
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
+ /* if there is a function call and this is
+ a parameter & not my parameter then don't pack it */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ (OP_SYMBOL (IC_RESULT (ic))->_isparm &&
+ !OP_SYMBOL (IC_RESULT (ic))->ismyparm))
+ {
+ dic = NULL;
+ break;
}
- if (SKIP_IC2(dic))
- continue;
+ if (SKIP_IC2 (dic))
+ continue;
- if (IS_SYMOP(IC_RESULT(dic)) &&
- IC_RESULT(dic)->key == IC_RIGHT(ic)->key) {
- break;
+ if (IS_SYMOP (IC_RESULT (dic)) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ {
+ break;
}
- if (IS_SYMOP(IC_RIGHT(dic)) &&
- (IC_RIGHT(dic)->key == IC_RESULT(ic)->key ||
- IC_RIGHT(dic)->key == IC_RIGHT(ic)->key)) {
- dic = NULL;
- break;
+ if (IS_SYMOP (IC_RIGHT (dic)) &&
+ (IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
+ IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
}
-
- if (IS_SYMOP(IC_LEFT(dic)) &&
- (IC_LEFT(dic)->key == IC_RESULT(ic)->key ||
- IC_LEFT(dic)->key == IC_RIGHT(ic)->key)) {
- dic = NULL;
- break;
+
+ if (IS_SYMOP (IC_LEFT (dic)) &&
+ (IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
+ IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
+ {
+ dic = NULL;
+ break;
}
#if 0
- if (POINTER_SET(dic) &&
- IC_RESULT(dic)->key == IC_RESULT(ic)->key ) {
- dic = NULL ;
- break;
+ if (POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == IC_RESULT (ic)->key)
+ {
+ dic = NULL;
+ break;
}
#endif
}
-
- if (!dic)
- return 0 ; /* did not find */
-
- /* if the result is on stack or iaccess then it must be
- the same atleast one of the operands */
- if (OP_SYMBOL(IC_RESULT(ic))->onStack ||
- OP_SYMBOL(IC_RESULT(ic))->iaccess ) {
-
- /* the operation has only one symbol
- operator then we can pack */
- if ((IC_LEFT(dic) && !IS_SYMOP(IC_LEFT(dic))) ||
- (IC_RIGHT(dic) && !IS_SYMOP(IC_RIGHT(dic))))
- goto pack;
-
- if (!((IC_LEFT(dic) &&
- IC_RESULT(ic)->key == IC_LEFT(dic)->key) ||
- (IC_RIGHT(dic) &&
- IC_RESULT(ic)->key == IC_RIGHT(dic)->key)))
- return 0;
+
+ if (!dic)
+ return 0; /* did not find */
+
+ /* if the result is on stack or iaccess then it must be
+ the same atleast one of the operands */
+ if (OP_SYMBOL (IC_RESULT (ic))->onStack ||
+ OP_SYMBOL (IC_RESULT (ic))->iaccess)
+ {
+
+ /* the operation has only one symbol
+ operator then we can pack */
+ if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
+ (IC_RIGHT (dic) && !IS_SYMOP (IC_RIGHT (dic))))
+ goto pack;
+
+ if (!((IC_LEFT (dic) &&
+ IC_RESULT (ic)->key == IC_LEFT (dic)->key) ||
+ (IC_RIGHT (dic) &&
+ IC_RESULT (ic)->key == IC_RIGHT (dic)->key)))
+ return 0;
}
pack:
- /* found the definition */
- /* replace the result with the result of */
- /* this assignment and remove this assignment */
- IC_RESULT(dic) = IC_RESULT(ic) ;
+ /* found the definition */
+ /* replace the result with the result of */
+ /* this assignment and remove this assignment */
+ IC_RESULT (dic) = IC_RESULT (ic);
- if (IS_ITEMP(IC_RESULT(dic)) && OP_SYMBOL(IC_RESULT(dic))->liveFrom > dic->seq) {
- OP_SYMBOL(IC_RESULT(dic))->liveFrom = dic->seq;
+ if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
+ {
+ OP_SYMBOL (IC_RESULT (dic))->liveFrom = dic->seq;
}
- /* delete from liverange table also
- delete from all the points inbetween and the new
- one */
- for ( sic = dic; sic != ic ; sic = sic->next ) {
- bitVectUnSetBit(sic->rlive,IC_RESULT(ic)->key);
- if (IS_ITEMP(IC_RESULT(dic)))
- bitVectSetBit(sic->rlive,IC_RESULT(dic)->key);
+ /* delete from liverange table also
+ delete from all the points inbetween and the new
+ one */
+ for (sic = dic; sic != ic; sic = sic->next)
+ {
+ bitVectUnSetBit (sic->rlive, IC_RESULT (ic)->key);
+ if (IS_ITEMP (IC_RESULT (dic)))
+ bitVectSetBit (sic->rlive, IC_RESULT (dic)->key);
}
-
- remiCodeFromeBBlock(ebp,ic);
- return 1;
+
+ remiCodeFromeBBlock (ebp, ic);
+ return 1;
}
/** Scanning backwards looks for first assig found.
*/
-iCode *findAssignToSym (operand *op,iCode *ic)
+iCode *
+findAssignToSym (operand * op, iCode * ic)
{
- iCode *dic;
-
- for (dic = ic->prev ; dic ; dic = dic->prev) {
-
- /* if definition by assignment */
- if (dic->op == '=' &&
- !POINTER_SET(dic) &&
- IC_RESULT(dic)->key == op->key)
- /* && IS_TRUE_SYMOP(IC_RIGHT(dic))*/
- {
-
- /* we are interested only if defined in far space */
- /* or in stack space in case of + & - */
-
- /* if assigned to a non-symbol then return
- true */
- if (!IS_SYMOP(IC_RIGHT(dic)))
- break ;
-
- /* if the symbol is in far space then
- we should not */
- if (isOperandInFarSpace(IC_RIGHT(dic)))
- return NULL ;
-
- /* for + & - operations make sure that
- if it is on the stack it is the same
- as one of the three operands */
- if ((ic->op == '+' || ic->op == '-') &&
- OP_SYMBOL(IC_RIGHT(dic))->onStack) {
-
- if ( IC_RESULT(ic)->key != IC_RIGHT(dic)->key &&
- IC_LEFT(ic)->key != IC_RIGHT(dic)->key &&
- IC_RIGHT(ic)->key != IC_RIGHT(dic)->key)
- return NULL;
- }
-
- break ;
-
- }
+ iCode *dic;
- /* if we find an usage then we cannot delete it */
- if (IC_LEFT(dic) && IC_LEFT(dic)->key == op->key)
- return NULL;
-
- if (IC_RIGHT(dic) && IC_RIGHT(dic)->key == op->key)
- return NULL;
+ for (dic = ic->prev; dic; dic = dic->prev)
+ {
- if (POINTER_SET(dic) && IC_RESULT(dic)->key == op->key)
+ /* if definition by assignment */
+ if (dic->op == '=' &&
+ !POINTER_SET (dic) &&
+ IC_RESULT (dic)->key == op->key)
+ /* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
+ {
+
+ /* we are interested only if defined in far space */
+ /* or in stack space in case of + & - */
+
+ /* if assigned to a non-symbol then return
+ true */
+ if (!IS_SYMOP (IC_RIGHT (dic)))
+ break;
+
+ /* if the symbol is in far space then
+ we should not */
+ if (isOperandInFarSpace (IC_RIGHT (dic)))
return NULL;
- }
- /* now make sure that the right side of dic
- is not defined between ic & dic */
- if (dic) {
- iCode *sic = dic->next ;
+ /* for + & - operations make sure that
+ if it is on the stack it is the same
+ as one of the three operands */
+ if ((ic->op == '+' || ic->op == '-') &&
+ OP_SYMBOL (IC_RIGHT (dic))->onStack)
+ {
- for (; sic != ic ; sic = sic->next)
- if (IC_RESULT(sic) &&
- IC_RESULT(sic)->key == IC_RIGHT(dic)->key)
+ if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
+ IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
return NULL;
+ }
+
+ break;
+
+ }
+
+ /* if we find an usage then we cannot delete it */
+ if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
+ return NULL;
+
+ if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
+ return NULL;
+
+ if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
+ return NULL;
}
- return dic;
-
-
+ /* now make sure that the right side of dic
+ is not defined between ic & dic */
+ if (dic)
+ {
+ iCode *sic = dic->next;
+
+ for (; sic != ic; sic = sic->next)
+ if (IC_RESULT (sic) &&
+ IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
+ return NULL;
+ }
+
+ return dic;
+
+
}
/*-----------------------------------------------------------------*/
/* packRegsForSupport :- reduce some registers for support calls */
/*-----------------------------------------------------------------*/
-static int packRegsForSupport (iCode *ic, eBBlock *ebp)
+static int
+packRegsForSupport (iCode * ic, eBBlock * ebp)
{
- int change = 0 ;
- /* for the left & right operand :- look to see if the
- left was assigned a true symbol in far space in that
- case replace them */
- D(D_ALLOC, ("packRegsForSupport: running on ic %p\n", ic));
-
- if (IS_ITEMP(IC_LEFT(ic)) &&
- OP_SYMBOL(IC_LEFT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_LEFT(ic),ic);
- iCode *sic;
-
- if (!dic)
- goto right ;
-
- /* found it we need to remove it from the
- block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_LEFT(ic)->key);
-
- IC_LEFT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_LEFT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
- remiCodeFromeBBlock(ebp,dic);
- change++;
+ int change = 0;
+ /* for the left & right operand :- look to see if the
+ left was assigned a true symbol in far space in that
+ case replace them */
+ D (D_ALLOC, ("packRegsForSupport: running on ic %p\n", ic));
+
+ if (IS_ITEMP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ goto right;
+
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
+
+ IC_LEFT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+ remiCodeFromeBBlock (ebp, dic);
+ change++;
}
-
- /* do the same for the right operand */
- right:
- if (!change &&
- IS_ITEMP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym(IC_RIGHT(ic),ic);
- iCode *sic;
-
- if (!dic)
- return change ;
-
- /* found it we need to remove it from the block */
- for ( sic = dic; sic != ic ; sic = sic->next )
- bitVectUnSetBit(sic->rlive,IC_RIGHT(ic)->key);
-
- IC_RIGHT(ic)->operand.symOperand =
- IC_RIGHT(dic)->operand.symOperand;
- IC_RIGHT(ic)->key = IC_RIGHT(dic)->operand.symOperand->key;
-
- remiCodeFromeBBlock(ebp,dic);
- change ++;
+
+ /* do the same for the right operand */
+right:
+ if (!change &&
+ IS_ITEMP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
+ {
+ iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ return change;
+
+ /* found it we need to remove it from the block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
+
+ IC_RIGHT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+
+ remiCodeFromeBBlock (ebp, dic);
+ change++;
}
-
- return change ;
+
+ return change;
}
#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
/** Will reduce some registers for single use.
*/
-static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp)
+static iCode *
+packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
{
- bitVect *uses ;
- iCode *dic, *sic;
+ bitVect *uses;
+ iCode *dic, *sic;
- D(D_ALLOC, ("packRegsForOneUse: running on ic %p\n", ic));
+ D (D_ALLOC, ("packRegsForOneUse: running on ic %p\n", ic));
- /* if returning a literal then do nothing */
- if (!IS_SYMOP(op))
- return NULL;
-
- /* only upto 2 bytes since we cannot predict
- the usage of b, & acc */
- if (getSize(operandType(op)) > 2 &&
- ic->op != RETURN &&
- ic->op != SEND)
- return NULL;
+ /* if returning a literal then do nothing */
+ if (!IS_SYMOP (op))
+ return NULL;
- /* this routine will mark the a symbol as used in one
- instruction use only && if the defintion is local
- (ie. within the basic block) && has only one definition &&
- that definiion is either a return value from a
- function or does not contain any variables in
- far space */
- uses = bitVectCopy(OP_USES(op));
- bitVectUnSetBit(uses,ic->key); /* take away this iCode */
- if (!bitVectIsZero(uses)) /* has other uses */
- return NULL ;
-
- /* if it has only one defintion */
- if (bitVectnBitsOn(OP_DEFS(op)) > 1)
- return NULL ; /* has more than one definition */
-
- /* get the that definition */
- if (!(dic =
- hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_DEFS(op)))))
- return NULL ;
-
- /* found the definition now check if it is local */
- if (dic->seq < ebp->fSeq ||
- dic->seq > ebp->lSeq)
- return NULL ; /* non-local */
-
- /* now check if it is the return from a function call */
- if (dic->op == CALL || dic->op == PCALL ) {
- if (ic->op != SEND && ic->op != RETURN) {
- OP_SYMBOL(op)->ruonly = 1;
- return dic;
+ /* only upto 2 bytes since we cannot predict
+ the usage of b, & acc */
+ if (getSize (operandType (op)) > 2 &&
+ ic->op != RETURN &&
+ ic->op != SEND)
+ return NULL;
+
+ /* this routine will mark the a symbol as used in one
+ instruction use only && if the defintion is local
+ (ie. within the basic block) && has only one definition &&
+ that definiion is either a return value from a
+ function or does not contain any variables in
+ far space */
+ uses = bitVectCopy (OP_USES (op));
+ bitVectUnSetBit (uses, ic->key); /* take away this iCode */
+ if (!bitVectIsZero (uses)) /* has other uses */
+ return NULL;
+
+ /* if it has only one defintion */
+ if (bitVectnBitsOn (OP_DEFS (op)) > 1)
+ return NULL; /* has more than one definition */
+
+ /* get the that definition */
+ if (!(dic =
+ hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS (op)))))
+ return NULL;
+
+ /* found the definition now check if it is local */
+ if (dic->seq < ebp->fSeq ||
+ dic->seq > ebp->lSeq)
+ return NULL; /* non-local */
+
+ /* now check if it is the return from a function call */
+ if (dic->op == CALL || dic->op == PCALL)
+ {
+ if (ic->op != SEND && ic->op != RETURN)
+ {
+ OP_SYMBOL (op)->ruonly = 1;
+ return dic;
}
- dic = dic->next ;
- }
-
- /* otherwise check that the definition does
- not contain any symbols in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(ic)) ||
- IS_OP_RUONLY(IC_RIGHT(ic)) ) {
- return NULL;
+ dic = dic->next;
}
-
- /* if pointer set then make sure the pointer is one byte */
- if (POINTER_SET(dic))
- return NULL;
- if (POINTER_GET(dic))
+ /* otherwise check that the definition does
+ not contain any symbols in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (ic)) ||
+ IS_OP_RUONLY (IC_RIGHT (ic)))
+ {
return NULL;
-
- sic = dic;
+ }
- /* also make sure the intervenening instructions
- don't have any thing in far space */
- for (dic = dic->next ; dic && dic != ic ; dic = dic->next) {
- /* if there is an intervening function call then no */
- if (dic->op == CALL || dic->op == PCALL)
- return NULL;
- /* if pointer set then make sure the pointer
- is one byte */
- if (POINTER_SET(dic))
- return NULL ;
-
- if (POINTER_GET(dic))
- return NULL ;
-
- /* if address of & the result is remat the okay */
- if (dic->op == ADDRESS_OF &&
- OP_SYMBOL(IC_RESULT(dic))->remat)
- continue ;
-
- /* if left or right or result is in far space */
- if (isOperandInFarSpace(IC_LEFT(dic)) ||
- isOperandInFarSpace(IC_RIGHT(dic)) ||
- isOperandInFarSpace(IC_RESULT(dic)) ||
- IS_OP_RUONLY(IC_LEFT(dic)) ||
- IS_OP_RUONLY(IC_RIGHT(dic)) ||
- IS_OP_RUONLY(IC_RESULT(dic)) ) {
- return NULL;
+ /* if pointer set then make sure the pointer is one byte */
+ if (POINTER_SET (dic))
+ return NULL;
+
+ if (POINTER_GET (dic))
+ return NULL;
+
+ sic = dic;
+
+ /* also make sure the intervenening instructions
+ don't have any thing in far space */
+ for (dic = dic->next; dic && dic != ic; dic = dic->next)
+ {
+ /* if there is an intervening function call then no */
+ if (dic->op == CALL || dic->op == PCALL)
+ return NULL;
+ /* if pointer set then make sure the pointer
+ is one byte */
+ if (POINTER_SET (dic))
+ return NULL;
+
+ if (POINTER_GET (dic))
+ return NULL;
+
+ /* if address of & the result is remat the okay */
+ if (dic->op == ADDRESS_OF &&
+ OP_SYMBOL (IC_RESULT (dic))->remat)
+ continue;
+
+ /* if left or right or result is in far space */
+ if (isOperandInFarSpace (IC_LEFT (dic)) ||
+ isOperandInFarSpace (IC_RIGHT (dic)) ||
+ isOperandInFarSpace (IC_RESULT (dic)) ||
+ IS_OP_RUONLY (IC_LEFT (dic)) ||
+ IS_OP_RUONLY (IC_RIGHT (dic)) ||
+ IS_OP_RUONLY (IC_RESULT (dic)))
+ {
+ return NULL;
}
}
-
- OP_SYMBOL(op)->ruonly = 1;
- return sic;
+
+ OP_SYMBOL (op)->ruonly = 1;
+ return sic;
}
/*-----------------------------------------------------------------*/
/* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
/*-----------------------------------------------------------------*/
-static bool isBitwiseOptimizable (iCode *ic)
+static bool
+isBitwiseOptimizable (iCode * ic)
{
- sym_link *rtype = getSpec(operandType(IC_RIGHT(ic)));
-
- /* bitwise operations are considered optimizable
- under the following conditions (Jean-Louis VERN)
-
- x & lit
- bit & bit
- bit & x
- bit ^ bit
- bit ^ x
- x ^ lit
- x | lit
- bit | bit
- bit | x
- */
- if (IS_LITERAL(rtype))
- return TRUE;
- return FALSE;
+ sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
+
+ /* bitwise operations are considered optimizable
+ under the following conditions (Jean-Louis VERN)
+
+ x & lit
+ bit & bit
+ bit & x
+ bit ^ bit
+ bit ^ x
+ x ^ lit
+ x | lit
+ bit | bit
+ bit | x
+ */
+ if (IS_LITERAL (rtype))
+ return TRUE;
+ return FALSE;
}
/** Optimisations:
When the result of this operation is small and short lived it may
be able to be stored in the accumelator.
*/
-static void packRegsForAccUse (iCode *ic)
+static void
+packRegsForAccUse (iCode * ic)
{
- iCode *uic;
-
- /* if + or - then it has to be one byte result */
- if ((ic->op == '+' || ic->op == '-')
- && getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (ic->op == RIGHT_OP &&
- (isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (ic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- /* has only one definition */
- if (bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) > 1)
- return ;
-
- /* has only one use */
- if (bitVectnBitsOn(OP_USES(IC_RESULT(ic))) > 1)
- return ;
-
- /* and the usage immediately follows this iCode */
- if (!(uic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_USES(IC_RESULT(ic))))))
- return ;
-
- if (ic->next != uic)
- return ;
-
- /* if it is a conditional branch then we definitely can */
- if (uic->op == IFX )
- goto accuse;
+ iCode *uic;
+
+ /* if + or - then it has to be one byte result */
+ if ((ic->op == '+' || ic->op == '-')
+ && getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (ic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ if (ic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ /* has only one definition */
+ if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
+ return;
- if ( uic->op == JUMPTABLE )
- return ;
+ /* has only one use */
+ if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
+ return;
+
+ /* and the usage immediately follows this iCode */
+ if (!(uic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
+ return;
+
+ if (ic->next != uic)
+ return;
+
+ /* if it is a conditional branch then we definitely can */
+ if (uic->op == IFX)
+ goto accuse;
+
+ if (uic->op == JUMPTABLE)
+ return;
#if 0
- /* if the usage is not is an assignment or an
- arithmetic / bitwise / shift operation then not */
- if (POINTER_SET(uic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(uic)),FALSE)) > 1)
- return;
+ /* if the usage is not is an assignment or an
+ arithmetic / bitwise / shift operation then not */
+ if (POINTER_SET (uic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
+ return;
#endif
- if (uic->op != '=' &&
- !IS_ARITHMETIC_OP(uic) &&
- !IS_BITWISE_OP(uic) &&
- uic->op != LEFT_OP &&
- uic->op != RIGHT_OP )
- return;
-
- /* if used in ^ operation then make sure right is not a
- literl */
- if (uic->op == '^' && isOperandLiteral(IC_RIGHT(uic)))
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (uic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- if (uic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
+ if (uic->op != '=' &&
+ !IS_ARITHMETIC_OP (uic) &&
+ !IS_BITWISE_OP (uic) &&
+ uic->op != LEFT_OP &&
+ uic->op != RIGHT_OP)
+ return;
+
+ /* if used in ^ operation then make sure right is not a
+ literl */
+ if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (uic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ if (uic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
#if 0
- /* make sure that the result of this icode is not on the
- stack, since acc is used to compute stack offset */
- if (IS_TRUE_SYMOP(IC_RESULT(uic)) &&
- OP_SYMBOL(IC_RESULT(uic))->onStack)
- return ;
+ /* make sure that the result of this icode is not on the
+ stack, since acc is used to compute stack offset */
+ if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
+ OP_SYMBOL (IC_RESULT (uic))->onStack)
+ return;
#endif
#if 0
- /* if either one of them in far space then we cannot */
- if ((IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- isOperandInFarSpace(IC_LEFT(uic))) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- isOperandInFarSpace(IC_RIGHT(uic))))
- return ;
+ /* if either one of them in far space then we cannot */
+ if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ isOperandInFarSpace (IC_LEFT (uic))) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ isOperandInFarSpace (IC_RIGHT (uic))))
+ return;
#endif
- /* if the usage has only one operand then we can */
- if (IC_LEFT(uic) == NULL ||
- IC_RIGHT(uic) == NULL)
- goto accuse;
-
- /* make sure this is on the left side if not
- a '+' since '+' is commutative */
- if (ic->op != '+' &&
- IC_LEFT(uic)->key != IC_RESULT(ic)->key)
- return;
-
- /* if one of them is a literal then we can */
- if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) ||
- (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) {
- goto accuse;
- return ;
+ /* if the usage has only one operand then we can */
+ if (IC_LEFT (uic) == NULL ||
+ IC_RIGHT (uic) == NULL)
+ goto accuse;
+
+ /* make sure this is on the left side if not
+ a '+' since '+' is commutative */
+ if (ic->op != '+' &&
+ IC_LEFT (uic)->key != IC_RESULT (ic)->key)
+ return;
+
+ /* if one of them is a literal then we can */
+ if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
+ (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
+ {
+ goto accuse;
+ return;
}
- /** This is confusing :) Guess for now */
- if (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_RIGHT(uic)) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)))))
- goto accuse;
-
- if (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_LEFT(uic)) ||
- (IS_TRUE_SYMOP(IC_LEFT(uic)))))
- goto accuse ;
- return ;
- accuse:
- OP_SYMBOL(IC_RESULT(ic))->accuse = ACCUSE_A;
+/** This is confusing :) Guess for now */
+ if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_RIGHT (uic)) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)))))
+ goto accuse;
+
+ if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_LEFT (uic)) ||
+ (IS_TRUE_SYMOP (IC_LEFT (uic)))))
+ goto accuse;
+ return;
+accuse:
+ OP_SYMBOL (IC_RESULT (ic))->accuse = ACCUSE_A;
}
-static void packRegsForHLUse (iCode *ic)
+static void
+packRegsForHLUse (iCode * ic)
{
- iCode *uic;
-
- if (IS_GB)
- return;
+ iCode *uic;
- /* has only one definition */
- if (bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) > 1)
- return ;
+ if (IS_GB)
+ return;
- /* has only one use */
- if (bitVectnBitsOn(OP_USES(IC_RESULT(ic))) > 1)
- return ;
+ /* has only one definition */
+ if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
+ return;
- /* and the usage immediately follows this iCode */
- if (!(uic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_USES(IC_RESULT(ic))))))
- return ;
+ /* has only one use */
+ if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
+ return;
- if (ic->next != uic)
- return ;
+ /* and the usage immediately follows this iCode */
+ if (!(uic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
+ return;
- if (ic->op == ADDRESS_OF && uic->op == IPUSH)
- goto hluse;
- if (ic->op == CALL && IC_LEFT(ic)->parmBytes == 0 && (uic->op == '-' || uic->op == '+'))
- goto hluse;
+ if (ic->next != uic)
return;
- hluse:
- OP_SYMBOL(IC_RESULT(ic))->accuse = ACCUSE_HL;
+
+ if (ic->op == ADDRESS_OF && uic->op == IPUSH)
+ goto hluse;
+ if (ic->op == CALL && IC_LEFT (ic)->parmBytes == 0 && (uic->op == '-' || uic->op == '+'))
+ goto hluse;
+ return;
+hluse:
+ OP_SYMBOL (IC_RESULT (ic))->accuse = ACCUSE_HL;
}
-bool opPreservesA(iCode *ic, iCode *uic)
+bool
+opPreservesA (iCode * ic, iCode * uic)
{
- /* if it is a conditional branch then we definitely can */
- if (uic->op == IFX )
- return FALSE;
+ /* if it is a conditional branch then we definitely can */
+ if (uic->op == IFX)
+ return FALSE;
- if ( uic->op == JUMPTABLE )
- return FALSE;
+ if (uic->op == JUMPTABLE)
+ return FALSE;
- /* if the usage has only one operand then we can */
- /* PENDING: check */
- if (IC_LEFT(uic) == NULL ||
- IC_RIGHT(uic) == NULL)
- return FALSE;
+ /* if the usage has only one operand then we can */
+ /* PENDING: check */
+ if (IC_LEFT (uic) == NULL ||
+ IC_RIGHT (uic) == NULL)
+ return FALSE;
- /* PENDING: check this rule */
- if (getSize(operandType(IC_RESULT(uic))) > 1) {
- return FALSE;
+ /* PENDING: check this rule */
+ if (getSize (operandType (IC_RESULT (uic))) > 1)
+ {
+ return FALSE;
}
- /*
- Bad:
- !IS_ARITHMETIC_OP(uic) (sub requires A)
- */
- if (
- uic->op != '+' &&
- !IS_BITWISE_OP(uic) &&
- uic->op != '=' &&
- uic->op != EQ_OP &&
- !POINTER_GET(uic) &&
- /*
- uic->op != LEFT_OP &&
- uic->op != RIGHT_OP &&*/
- 1
- ) {
- return FALSE;
+ /*
+ Bad:
+ !IS_ARITHMETIC_OP(uic) (sub requires A)
+ */
+ if (
+ uic->op != '+' &&
+ !IS_BITWISE_OP (uic) &&
+ uic->op != '=' &&
+ uic->op != EQ_OP &&
+ !POINTER_GET (uic) &&
+ /*
+ uic->op != LEFT_OP &&
+ uic->op != RIGHT_OP && */
+ 1
+ )
+ {
+ return FALSE;
}
- /* PENDING */
- if (!IC_LEFT(uic) || !IC_RESULT(ic))
- return FALSE;
+ /* PENDING */
+ if (!IC_LEFT (uic) || !IC_RESULT (ic))
+ return FALSE;
- /** This is confusing :) Guess for now */
- if (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_RIGHT(uic)) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)))))
- return TRUE;
-
- if (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_LEFT(uic)) ||
- (IS_TRUE_SYMOP(IC_LEFT(uic)))))
- return TRUE;
+/** This is confusing :) Guess for now */
+ if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_RIGHT (uic)) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)))))
+ return TRUE;
- return FALSE;
+ if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_LEFT (uic)) ||
+ (IS_TRUE_SYMOP (IC_LEFT (uic)))))
+ return TRUE;
+
+ return FALSE;
}
-static void joinPushes(iCode *ic)
+static void
+joinPushes (iCode * ic)
{
#if 0
- if (ic->op == IPUSH &&
- isOperandLiteral(IC_LEFT(ic)) &&
- getSize(operandType(IC_LEFT(ic))) == 1 &&
- ic->next->op == IPUSH &&
- isOperandLiteral(IC_LEFT(ic->next)) &&
- getSize(operandType(IC_LEFT(ic->next))) == 1) {
- /* This is a bit tricky as michaelh doesnt know what he's doing.
- */
- /* First upgrade the size of (first) to int */
- SPEC_NOUN(operandType(IC_LEFT(ic))) = V_INT;
- SPEC_SHORT(operandType(IC_LEFT(ic))) = 0;
-
- floatFromVal(AOP
- /* Now get and join the values */
- value * val = aop->aopu.aop_lit;
- /* if it is a float then it gets tricky */
- /* otherwise it is fairly simple */
- if (!IS_FLOAT(val->type)) {
- unsigned long v = floatFromVal(val);
-
- floatFrom
- printf("Size %u\n", getSize(operandType(IC_LEFT(ic))));
- ic->next = ic->next->next;
+ if (ic->op == IPUSH &&
+ isOperandLiteral (IC_LEFT (ic)) &&
+ getSize (operandType (IC_LEFT (ic))) == 1 &&
+ ic->next->op == IPUSH &&
+ isOperandLiteral (IC_LEFT (ic->next)) &&
+ getSize (operandType (IC_LEFT (ic->next))) == 1)
+ {
+ /* This is a bit tricky as michaelh doesnt know what he's doing.
+ */
+ /* First upgrade the size of (first) to int */
+ SPEC_NOUN (operandType (IC_LEFT (ic))) = V_INT;
+ SPEC_SHORT (operandType (IC_LEFT (ic))) = 0;
+
+ floatFromVal (AOP /* need some sleep ... */ );
+ /* Now get and join the values */
+ value *val = aop->aopu.aop_lit;
+ /* if it is a float then it gets tricky */
+ /* otherwise it is fairly simple */
+ if (!IS_FLOAT (val->type))
+ {
+ unsigned long v = floatFromVal (val);
+
+ floatFrom ( /* need some sleep ... */ );
+ printf ("Size %u\n", getSize (operandType (IC_LEFT (ic))));
+ ic->next = ic->next->next;
+ }
}
#endif
}
Note that the 'A preserving' list is currently emperical :)e
*/
-static void packRegsForAccUse2(iCode *ic)
+static void
+packRegsForAccUse2 (iCode * ic)
{
- iCode *uic;
-
- D(D_ALLOC, ("packRegsForAccUse2: running on ic %p\n", ic));
-
- /* Filter out all but those 'good' commands */
- if (
- !POINTER_GET(ic) &&
- ic->op != '+' &&
- !IS_BITWISE_OP(ic) &&
- ic->op != '=' &&
- ic->op != EQ_OP &&
- ic->op != CAST &&
- 1)
- return;
-
- /* if + or - then it has to be one byte result.
- MLH: Ok.
- */
- if ((ic->op == '+' || ic->op == '-')
- && getSize(operandType(IC_RESULT(ic))) > 1)
- return ;
-
- /* if shift operation make sure right side is not a literal.
- MLH: depends.
- */
+ iCode *uic;
+
+ D (D_ALLOC, ("packRegsForAccUse2: running on ic %p\n", ic));
+
+ /* Filter out all but those 'good' commands */
+ if (
+ !POINTER_GET (ic) &&
+ ic->op != '+' &&
+ !IS_BITWISE_OP (ic) &&
+ ic->op != '=' &&
+ ic->op != EQ_OP &&
+ ic->op != CAST &&
+ 1)
+ return;
+
+ /* if + or - then it has to be one byte result.
+ MLH: Ok.
+ */
+ if ((ic->op == '+' || ic->op == '-')
+ && getSize (operandType (IC_RESULT (ic))) > 1)
+ return;
+
+ /* if shift operation make sure right side is not a literal.
+ MLH: depends.
+ */
#if 0
- if (ic->op == RIGHT_OP &&
- (isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
-
- if (ic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(ic)) ||
- getSize(operandType(IC_RESULT(ic))) > 1))
- return ;
+ if (ic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
+
+ if (ic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (ic)) ||
+ getSize (operandType (IC_RESULT (ic))) > 1))
+ return;
#endif
-
- /* has only one definition */
- if (bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) > 1) {
- return;
- }
- /* Right. We may be able to propagate it through if:
- For each in the chain of uses the intermediate is OK.
- */
- /* Get next with 'uses result' bit on
- If this->next == next
- Validate use of next
- If OK, increase count
- */
- /* and the usage immediately follows this iCode */
- if (!(uic = hTabItemWithKey(iCodehTab,
- bitVectFirstBit(OP_USES(IC_RESULT(ic)))))) {
- return;
+ /* has only one definition */
+ if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1)
+ {
+ return;
}
+ /* Right. We may be able to propagate it through if:
+ For each in the chain of uses the intermediate is OK.
+ */
+ /* Get next with 'uses result' bit on
+ If this->next == next
+ Validate use of next
+ If OK, increase count
+ */
+ /* and the usage immediately follows this iCode */
+ if (!(uic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
{
- /* Create a copy of the OP_USES bit vect */
- bitVect *uses = bitVectCopy(OP_USES(IC_RESULT(ic)));
- int setBit;
- iCode *scan = ic, *next;
-
- do {
- setBit = bitVectFirstBit(uses);
- next = hTabItemWithKey(iCodehTab, setBit);
- if (scan->next == next) {
- bitVectUnSetBit(uses, setBit);
- /* Still contigous. */
- if (!opPreservesA(ic, next)) {
- return;
- }
- scan = next;
- }
- else {
- return;
- }
- } while (!bitVectIsZero(uses));
- OP_SYMBOL(IC_RESULT(ic))->accuse = ACCUSE_A;
- return;
+ return;
}
- /* OLD CODE FOLLOWS */
- /* if it is a conditional branch then we definitely can
- MLH: Depends.
- */
-#if 0
- if (uic->op == IFX )
- goto accuse;
-
- /* MLH: Depends. */
- if ( uic->op == JUMPTABLE )
- return ;
+ {
+ /* Create a copy of the OP_USES bit vect */
+ bitVect *uses = bitVectCopy (OP_USES (IC_RESULT (ic)));
+ int setBit;
+ iCode *scan = ic, *next;
+
+ do
+ {
+ setBit = bitVectFirstBit (uses);
+ next = hTabItemWithKey (iCodehTab, setBit);
+ if (scan->next == next)
+ {
+ bitVectUnSetBit (uses, setBit);
+ /* Still contigous. */
+ if (!opPreservesA (ic, next))
+ {
+ return;
+ }
+ scan = next;
+ }
+ else
+ {
+ return;
+ }
+ }
+ while (!bitVectIsZero (uses));
+ OP_SYMBOL (IC_RESULT (ic))->accuse = ACCUSE_A;
+ return;
+ }
+
+ /* OLD CODE FOLLOWS */
+ /* if it is a conditional branch then we definitely can
+ MLH: Depends.
+ */
+#if 0
+ if (uic->op == IFX)
+ goto accuse;
+
+ /* MLH: Depends. */
+ if (uic->op == JUMPTABLE)
+ return;
#endif
- /* if the usage is not is an assignment or an
- arithmetic / bitwise / shift operation then not.
- MLH: Pending: Invalid. Our pointer sets are always peechy.
- */
+ /* if the usage is not is an assignment or an
+ arithmetic / bitwise / shift operation then not.
+ MLH: Pending: Invalid. Our pointer sets are always peechy.
+ */
#if 0
- if (POINTER_SET(uic) &&
- getSize(aggrToPtr(operandType(IC_RESULT(uic)),FALSE)) > 1) {
- printf("e5 %u\n", getSize(aggrToPtr(operandType(IC_RESULT(uic)),FALSE)));
- return;
+ if (POINTER_SET (uic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
+ {
+ printf ("e5 %u\n", getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)));
+ return;
}
#endif
- printf("1\n");
- if (uic->op != '=' &&
- !IS_ARITHMETIC_OP(uic) &&
- !IS_BITWISE_OP(uic) &&
- uic->op != LEFT_OP &&
- uic->op != RIGHT_OP ) {
- printf("e6\n");
- return;
+ printf ("1\n");
+ if (uic->op != '=' &&
+ !IS_ARITHMETIC_OP (uic) &&
+ !IS_BITWISE_OP (uic) &&
+ uic->op != LEFT_OP &&
+ uic->op != RIGHT_OP)
+ {
+ printf ("e6\n");
+ return;
}
- /* if used in ^ operation then make sure right is not a
- literl */
- if (uic->op == '^' && isOperandLiteral(IC_RIGHT(uic)))
- return ;
-
- /* if shift operation make sure right side is not a literal */
- if (uic->op == RIGHT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
- if (uic->op == LEFT_OP &&
- ( isOperandLiteral(IC_RIGHT(uic)) ||
- getSize(operandType(IC_RESULT(uic))) > 1))
- return ;
-
+ /* if used in ^ operation then make sure right is not a
+ literl */
+ if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
+ return;
+
+ /* if shift operation make sure right side is not a literal */
+ if (uic->op == RIGHT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
+ if (uic->op == LEFT_OP &&
+ (isOperandLiteral (IC_RIGHT (uic)) ||
+ getSize (operandType (IC_RESULT (uic))) > 1))
+ return;
+
#if 0
- /* make sure that the result of this icode is not on the
- stack, since acc is used to compute stack offset */
- if (IS_TRUE_SYMOP(IC_RESULT(uic)) &&
- OP_SYMBOL(IC_RESULT(uic))->onStack)
- return ;
+ /* make sure that the result of this icode is not on the
+ stack, since acc is used to compute stack offset */
+ if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
+ OP_SYMBOL (IC_RESULT (uic))->onStack)
+ return;
#endif
#if 0
- /* if either one of them in far space then we cannot */
- if ((IS_TRUE_SYMOP(IC_LEFT(uic)) &&
- isOperandInFarSpace(IC_LEFT(uic))) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
- isOperandInFarSpace(IC_RIGHT(uic))))
- return ;
+ /* if either one of them in far space then we cannot */
+ if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
+ isOperandInFarSpace (IC_LEFT (uic))) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)) &&
+ isOperandInFarSpace (IC_RIGHT (uic))))
+ return;
#endif
- /* if the usage has only one operand then we can */
- if (IC_LEFT(uic) == NULL ||
- IC_RIGHT(uic) == NULL)
- goto accuse;
-
- /* make sure this is on the left side if not
- a '+' since '+' is commutative */
- if (ic->op != '+' &&
- IC_LEFT(uic)->key != IC_RESULT(ic)->key)
- return;
-
- /* if one of them is a literal then we can */
- if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) ||
- (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) {
- goto accuse;
- return ;
+ /* if the usage has only one operand then we can */
+ if (IC_LEFT (uic) == NULL ||
+ IC_RIGHT (uic) == NULL)
+ goto accuse;
+
+ /* make sure this is on the left side if not
+ a '+' since '+' is commutative */
+ if (ic->op != '+' &&
+ IC_LEFT (uic)->key != IC_RESULT (ic)->key)
+ return;
+
+ /* if one of them is a literal then we can */
+ if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
+ (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
+ {
+ goto accuse;
+ return;
}
- /** This is confusing :) Guess for now */
- if (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_RIGHT(uic)) ||
- (IS_TRUE_SYMOP(IC_RIGHT(uic)))))
- goto accuse;
-
- if (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
- (IS_ITEMP(IC_LEFT(uic)) ||
- (IS_TRUE_SYMOP(IC_LEFT(uic)))))
- goto accuse ;
- return ;
- accuse:
- printf("acc ok!\n");
- OP_SYMBOL(IC_RESULT(ic))->accuse = ACCUSE_A;
+/** This is confusing :) Guess for now */
+ if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_RIGHT (uic)) ||
+ (IS_TRUE_SYMOP (IC_RIGHT (uic)))))
+ goto accuse;
+
+ if (IC_RIGHT (uic)->key == IC_RESULT (ic)->key &&
+ (IS_ITEMP (IC_LEFT (uic)) ||
+ (IS_TRUE_SYMOP (IC_LEFT (uic)))))
+ goto accuse;
+ return;
+accuse:
+ printf ("acc ok!\n");
+ OP_SYMBOL (IC_RESULT (ic))->accuse = ACCUSE_A;
}
/** Does some transformations to reduce register pressure.
*/
-static void packRegisters (eBBlock *ebp)
+static void
+packRegisters (eBBlock * ebp)
{
- iCode *ic ;
- int change = 0 ;
+ iCode *ic;
+ int change = 0;
- D(D_ALLOC, ("packRegisters: entered.\n"));
-
- while (1 && !DISABLE_PACK_ASSIGN) {
- change = 0;
- /* look for assignments of the form */
- /* iTempNN = TRueSym (someoperation) SomeOperand */
- /* .... */
- /* TrueSym := iTempNN:1 */
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
- /* find assignment of the form TrueSym := iTempNN:1 */
- if (ic->op == '=' && !POINTER_SET(ic))
- change += packRegsForAssign(ic,ebp);
+ D (D_ALLOC, ("packRegisters: entered.\n"));
+
+ while (1 && !DISABLE_PACK_ASSIGN)
+ {
+ change = 0;
+ /* look for assignments of the form */
+ /* iTempNN = TRueSym (someoperation) SomeOperand */
+ /* .... */
+ /* TrueSym := iTempNN:1 */
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+ /* find assignment of the form TrueSym := iTempNN:1 */
+ if (ic->op == '=' && !POINTER_SET (ic))
+ change += packRegsForAssign (ic, ebp);
}
- if (!change)
- break;
+ if (!change)
+ break;
}
- for ( ic = ebp->sch ; ic ; ic = ic->next ) {
- /* Safe: address of a true sym is always constant. */
- /* if this is an itemp & result of a address of a true sym
- then mark this as rematerialisable */
- D(D_ALLOC, ("packRegisters: looping on ic %p\n", ic));
-
- if (ic->op == ADDRESS_OF &&
- IS_ITEMP(IC_RESULT(ic)) &&
- IS_TRUE_SYMOP(IC_LEFT(ic)) &&
- bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
- !OP_SYMBOL(IC_LEFT(ic))->onStack ) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat = 1;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
- OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
+ for (ic = ebp->sch; ic; ic = ic->next)
+ {
+ /* Safe: address of a true sym is always constant. */
+ /* if this is an itemp & result of a address of a true sym
+ then mark this as rematerialisable */
+ D (D_ALLOC, ("packRegisters: looping on ic %p\n", ic));
+
+ if (ic->op == ADDRESS_OF &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ IS_TRUE_SYMOP (IC_LEFT (ic)) &&
+ bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
+ !OP_SYMBOL (IC_LEFT (ic))->onStack)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat = 1;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
+ OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
}
- /* Safe: just propagates the remat flag */
- /* if straight assignment then carry remat flag if this is the
- only definition */
- if (ic->op == '=' &&
- !POINTER_SET(ic) &&
- IS_SYMOP(IC_RIGHT(ic)) &&
- OP_SYMBOL(IC_RIGHT(ic))->remat &&
- bitVectnBitsOn(OP_SYMBOL(IC_RESULT(ic))->defs) <= 1) {
-
- OP_SYMBOL(IC_RESULT(ic))->remat =
- OP_SYMBOL(IC_RIGHT(ic))->remat;
- OP_SYMBOL(IC_RESULT(ic))->rematiCode =
- OP_SYMBOL(IC_RIGHT(ic))->rematiCode ;
+ /* Safe: just propagates the remat flag */
+ /* if straight assignment then carry remat flag if this is the
+ only definition */
+ if (ic->op == '=' &&
+ !POINTER_SET (ic) &&
+ IS_SYMOP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->remat &&
+ bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->remat =
+ OP_SYMBOL (IC_RIGHT (ic))->remat;
+ OP_SYMBOL (IC_RESULT (ic))->rematiCode =
+ OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
}
- /* if the condition of an if instruction is defined in the
- previous instruction then mark the itemp as a conditional */
- if ((IS_CONDITIONAL(ic) ||
- ( ( ic->op == BITWISEAND ||
- ic->op == '|' ||
- ic->op == '^' ) &&
- isBitwiseOptimizable(ic))) &&
- ic->next && ic->next->op == IFX &&
- isOperandEqual(IC_RESULT(ic),IC_COND(ic->next)) &&
- OP_SYMBOL(IC_RESULT(ic))->liveTo <= ic->next->seq) {
-
- OP_SYMBOL(IC_RESULT(ic))->regType = REG_CND;
- continue ;
+ /* if the condition of an if instruction is defined in the
+ previous instruction then mark the itemp as a conditional */
+ if ((IS_CONDITIONAL (ic) ||
+ ((ic->op == BITWISEAND ||
+ ic->op == '|' ||
+ ic->op == '^') &&
+ isBitwiseOptimizable (ic))) &&
+ ic->next && ic->next->op == IFX &&
+ isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
+ OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
+ {
+
+ OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
+ continue;
}
#if 0
- /* reduce for support function calls */
- if (ic->supportRtn || ic->op == '+' || ic->op == '-' )
- packRegsForSupport(ic,ebp);
+ /* reduce for support function calls */
+ if (ic->supportRtn || ic->op == '+' || ic->op == '-')
+ packRegsForSupport (ic, ebp);
#endif
#if 0
- /* some cases the redundant moves can
- can be eliminated for return statements */
- if ((ic->op == RETURN || ic->op == SEND) &&
- !isOperandInFarSpace(IC_LEFT(ic)) &&
- !options.model)
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
+ /* some cases the redundant moves can
+ can be eliminated for return statements */
+ if ((ic->op == RETURN || ic->op == SEND) &&
+ !isOperandInFarSpace (IC_LEFT (ic)) &&
+ !options.model)
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
#endif
- /* if pointer set & left has a size more than
- one and right is not in far space */
- if (POINTER_SET(ic) &&
- /* MLH: no such thing.
- !isOperandInFarSpace(IC_RIGHT(ic)) && */
- !OP_SYMBOL(IC_RESULT(ic))->remat &&
- !IS_OP_RUONLY(IC_RIGHT(ic)) &&
- getSize(aggrToPtr(operandType(IC_RESULT(ic)),FALSE)) > 1 ) {
-
- packRegsForOneuse (ic,IC_RESULT(ic),ebp);
+ /* if pointer set & left has a size more than
+ one and right is not in far space */
+ if (POINTER_SET (ic) &&
+ /* MLH: no such thing.
+ !isOperandInFarSpace(IC_RIGHT(ic)) && */
+ !OP_SYMBOL (IC_RESULT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RIGHT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1)
+ {
+
+ packRegsForOneuse (ic, IC_RESULT (ic), ebp);
}
-
- /* if pointer get */
- if (!DISABLE_PACK_ONE_USE &&
- POINTER_GET(ic) &&
- /* MLH: dont have far space
- !isOperandInFarSpace(IC_RESULT(ic))&& */
- !OP_SYMBOL(IC_LEFT(ic))->remat &&
- !IS_OP_RUONLY(IC_RESULT(ic)) &&
- getSize(aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) > 1 ) {
-
- packRegsForOneuse (ic,IC_LEFT(ic),ebp);
+
+ /* if pointer get */
+ if (!DISABLE_PACK_ONE_USE &&
+ POINTER_GET (ic) &&
+ /* MLH: dont have far space
+ !isOperandInFarSpace(IC_RESULT(ic))&& */
+ !OP_SYMBOL (IC_LEFT (ic))->remat &&
+ !IS_OP_RUONLY (IC_RESULT (ic)) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1)
+ {
+
+ packRegsForOneuse (ic, IC_LEFT (ic), ebp);
}
- /* pack registers for accumulator use, when the result of an
- arithmetic or bit wise operation has only one use, that use is
- immediately following the defintion and the using iCode has
- only one operand or has two operands but one is literal & the
- result of that operation is not on stack then we can leave the
- result of this operation in acc:b combination */
-
- if (!DISABLE_PACK_HL && IS_ITEMP(IC_RESULT(ic))) {
- packRegsForHLUse(ic);
+ /* pack registers for accumulator use, when the result of an
+ arithmetic or bit wise operation has only one use, that use is
+ immediately following the defintion and the using iCode has
+ only one operand or has two operands but one is literal & the
+ result of that operation is not on stack then we can leave the
+ result of this operation in acc:b combination */
+
+ if (!DISABLE_PACK_HL && IS_ITEMP (IC_RESULT (ic)))
+ {
+ packRegsForHLUse (ic);
}
#if 0
- if ((IS_ARITHMETIC_OP(ic)
- || IS_BITWISE_OP(ic)
- || ic->op == LEFT_OP || ic->op == RIGHT_OP
- ) &&
- IS_ITEMP(IC_RESULT(ic)) &&
- getSize(operandType(IC_RESULT(ic))) <= 2)
- packRegsForAccUse (ic);
+ if ((IS_ARITHMETIC_OP (ic)
+ || IS_BITWISE_OP (ic)
+ || ic->op == LEFT_OP || ic->op == RIGHT_OP
+ ) &&
+ IS_ITEMP (IC_RESULT (ic)) &&
+ getSize (operandType (IC_RESULT (ic))) <= 2)
+ packRegsForAccUse (ic);
#else
- if (!DISABLE_PACK_ACC && IS_ITEMP(IC_RESULT(ic)) &&
- getSize(operandType(IC_RESULT(ic))) == 1) {
- packRegsForAccUse2(ic);
+ if (!DISABLE_PACK_ACC && IS_ITEMP (IC_RESULT (ic)) &&
+ getSize (operandType (IC_RESULT (ic))) == 1)
+ {
+ packRegsForAccUse2 (ic);
}
#endif
- joinPushes(ic);
+ joinPushes (ic);
}
}
-
+
/*-----------------------------------------------------------------*/
/* assignRegisters - assigns registers to each live range as need */
/*-----------------------------------------------------------------*/
-void z80_assignRegisters (eBBlock **ebbs, int count)
+void
+z80_assignRegisters (eBBlock ** ebbs, int count)
{
- iCode *ic;
- int i ;
+ iCode *ic;
+ int i;
- D(D_ALLOC, ("\n-> z80_assignRegisters: entered.\n"));
+ D (D_ALLOC, ("\n-> z80_assignRegisters: entered.\n"));
- setToNull((void *)&funcrUsed);
- stackExtend = dataExtend = 0;
+ setToNull ((void *) &funcrUsed);
+ stackExtend = dataExtend = 0;
- if (IS_GB) {
- /* DE is required for the code gen. */
- _nRegs = GBZ80_MAX_REGS;
- regsZ80 = _gbz80_regs;
+ if (IS_GB)
+ {
+ /* DE is required for the code gen. */
+ _nRegs = GBZ80_MAX_REGS;
+ regsZ80 = _gbz80_regs;
}
- else {
- _nRegs = Z80_MAX_REGS;
- regsZ80 = _z80_regs;
+ else
+ {
+ _nRegs = Z80_MAX_REGS;
+ regsZ80 = _z80_regs;
}
- /* change assignments this will remove some
- live ranges reducing some register pressure */
- for (i = 0 ; i < count ;i++ )
- packRegisters (ebbs[i]);
+ /* change assignments this will remove some
+ live ranges reducing some register pressure */
+ for (i = 0; i < count; i++)
+ packRegisters (ebbs[i]);
- if (options.dump_pack)
- dumpEbbsToFileExt(".dumppack",ebbs,count);
+ if (options.dump_pack)
+ dumpEbbsToFileExt (".dumppack", ebbs, count);
- /* first determine for each live range the number of
- registers & the type of registers required for each */
- regTypeNum ();
-
- /* and serially allocate registers */
- serialRegAssign(ebbs,count);
-
- /* if stack was extended then tell the user */
- if (stackExtend) {
-/* werror(W_TOOMANY_SPILS,"stack", */
-/* stackExtend,currFunc->name,""); */
- stackExtend = 0 ;
+ /* first determine for each live range the number of
+ registers & the type of registers required for each */
+ regTypeNum ();
+
+ /* and serially allocate registers */
+ serialRegAssign (ebbs, count);
+
+ /* if stack was extended then tell the user */
+ if (stackExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"stack", */
+/* stackExtend,currFunc->name,""); */
+ stackExtend = 0;
}
- if (dataExtend) {
-/* werror(W_TOOMANY_SPILS,"data space", */
-/* dataExtend,currFunc->name,""); */
- dataExtend = 0 ;
+ if (dataExtend)
+ {
+/* werror(W_TOOMANY_SPILS,"data space", */
+/* dataExtend,currFunc->name,""); */
+ dataExtend = 0;
}
- if (options.dump_rassgn)
- dumpEbbsToFileExt(".dumprassgn",ebbs,count);
+ if (options.dump_rassgn)
+ dumpEbbsToFileExt (".dumprassgn", ebbs, count);
- /* after that create the register mask
- for each of the instruction */
- createRegMask (ebbs,count);
+ /* after that create the register mask
+ for each of the instruction */
+ createRegMask (ebbs, count);
- /* now get back the chain */
- ic = iCodeLabelOptimize(iCodeFromeBBlock (ebbs,count));
+ /* now get back the chain */
+ ic = iCodeLabelOptimize (iCodeFromeBBlock (ebbs, count));
- /* redo that offsets for stacked automatic variables */
- redoStackOffsets ();
+ /* redo that offsets for stacked automatic variables */
+ redoStackOffsets ();
- genZ80Code(ic);
+ genZ80Code (ic);
- /* free up any stackSpil locations allocated */
- applyToSet(stackSpil,deallocStackSpil);
- slocNum = 0;
- setToNull((void **)&stackSpil);
- setToNull((void **)&spiltSet);
- /* mark all registers as free */
- freeAllRegs();
+ /* free up any stackSpil locations allocated */
+ applyToSet (stackSpil, deallocStackSpil);
+ slocNum = 0;
+ setToNull ((void **) &stackSpil);
+ setToNull ((void **) &spiltSet);
+ /* mark all registers as free */
+ freeAllRegs ();
- return ;
+ return;
}
#define DEBUG_FAKE_EXTRA_REGS 0
-enum { C_IDX = 0,
- B_IDX,
- E_IDX,
- D_IDX,
- L_IDX,
- H_IDX,
+enum
+ {
+ C_IDX = 0,
+ B_IDX,
+ E_IDX,
+ D_IDX,
+ L_IDX,
+ H_IDX,
#if DEBUG_FAKE_EXTRA_REGS
- M_IDX,
- N_IDX,
- O_IDX,
- P_IDX,
- Q_IDX,
- R_IDX,
- S_IDX,
- T_IDX,
+ M_IDX,
+ N_IDX,
+ O_IDX,
+ P_IDX,
+ Q_IDX,
+ R_IDX,
+ S_IDX,
+ T_IDX,
#endif
- CND_IDX };
+ CND_IDX
+ };
#define REG_PTR 0x01
#define REG_GPR 0x02
#define REG_CND 0x04
/* definition for the registers */
typedef struct regs
-{
- short type; /* can have value
- REG_GPR, REG_PTR or REG_CND */
- short rIdx ; /* index into register table */
- char *name ; /* name */
- unsigned isFree :1; /* is currently unassigned */
-} regs;
+ {
+ short type; /* can have value
+ REG_GPR, REG_PTR or REG_CND */
+ short rIdx; /* index into register table */
+ char *name; /* name */
+ unsigned isFree:1; /* is currently unassigned */
+ }
+regs;
extern regs *regsZ80;
-void assignRegisters (eBBlock **, int );
-regs *regWithIdx (int);
+void assignRegisters (eBBlock **, int);
+regs *regWithIdx (int);
-void z80_assignRegisters (eBBlock **ebbs, int count);
+void z80_assignRegisters (eBBlock ** ebbs, int count);
#endif
#include "z80.h"
#include <math.h>
-int convertFloat(Z80_FLOAT *f, double native)
+int
+convertFloat (Z80_FLOAT * f, double native)
{
- unsigned long mantissa, exponent;
- double f2;
- wassert(f);
- if (native!=0) {
- f2 = floor(log(fabs(native))/log(2))+1;
- mantissa = 0x1000000*fabs(native)/exp(f2*log(2));
- mantissa &= 0xffffff;
- exponent = f2 + 0x40;
- if (native<0)
- exponent |= 0x80;
+ unsigned long mantissa, exponent;
+ double f2;
+ wassert (f);
+ if (native != 0)
+ {
+ f2 = floor (log (fabs (native)) / log (2)) + 1;
+ mantissa = 0x1000000 * fabs (native) / exp (f2 * log (2));
+ mantissa &= 0xffffff;
+ exponent = f2 + 0x40;
+ if (native < 0)
+ exponent |= 0x80;
}
- else {
- mantissa = 0;
- exponent = 0;
+ else
+ {
+ mantissa = 0;
+ exponent = 0;
}
- f->w[0] = (WORD)mantissa;
- f->w[1] = (BYTE)(mantissa>>16);
- f->w[1] |= exponent << 8;
-
- f->b[0] = (BYTE)f->w[0];
- f->b[1] = (BYTE)(f->w[0]>>8);
- f->b[2] = (BYTE)f->w[1];
- f->b[3] = (BYTE)(f->w[1]>>8);
+ f->w[0] = (WORD) mantissa;
+ f->w[1] = (BYTE) (mantissa >> 16);
+ f->w[1] |= exponent << 8;
- return 0;
+ f->b[0] = (BYTE) f->w[0];
+ f->b[1] = (BYTE) (f->w[0] >> 8);
+ f->b[2] = (BYTE) f->w[1];
+ f->b[3] = (BYTE) (f->w[1] >> 8);
+
+ return 0;
}
typedef unsigned short WORD;
typedef unsigned char BYTE;
-typedef struct {
+typedef struct
+ {
WORD w[2];
BYTE b[4];
-} Z80_FLOAT;
+ }
+Z80_FLOAT;
/** Convert a native float into 'z80' format */
-int convertFloat(Z80_FLOAT *f, double native);
+int convertFloat (Z80_FLOAT * f, double native);
#endif
#include "ralloc.h"
#include "support.h"
-typedef enum {
+typedef enum
+ {
SUB_Z80,
SUB_GBZ80
-} Z80_SUB_PORT;
+ }
+Z80_SUB_PORT;
-typedef struct {
+typedef struct
+ {
Z80_SUB_PORT sub;
-} Z80_OPTS;
+ }
+Z80_OPTS;
extern Z80_OPTS z80_opts;
#define IS_GB (z80_opts.sub == SUB_GBZ80)
#define IS_Z80 (z80_opts.sub == SUB_Z80)
-enum {
+enum
+ {
ACCUSE_A = 1,
ACCUSE_HL
-};
+ };