#include "device.h"
#include "main.h"
+/* Set the following to 1 to enable the slower/bigger
+ * but more robust generic shifting routine (which also
+ * operates correctly with negative shift values). */
+#define USE_GENERIC_SIGNED_SHIFT 1
+
+/* Set the following to 1 to enable the new
+ * stripped down genCmp version.
+ * This version should be easier to understand,
+ * more reliable and (sigh) slighly slower. */
+#define USE_SIMPLE_GENCMP 1
+
extern void pic16_genUMult8X8_16 (operand *, operand *,operand *,pCodeOpReg *);
extern void pic16_genSMult8X8_16 (operand *, operand *,operand *,pCodeOpReg *);
void pic16_genMult8X8_8 (operand *, operand *,operand *);
static asmop *newAsmop (short type);
static pCodeOp *pic16_popRegFromString(char *str, int size, int offset, operand *op);
extern pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...);
-static void mov2w (asmop *aop, int offset);
static void mov2f(asmop *dst, asmop *src, int offset);
static void mov2fp(pCodeOp *dst, asmop *src, int offset);
static pCodeOp *pic16_popRegFromIdx(int rIdx);
int pic16_labelOffset=0;
extern int pic16_debug_verbose;
+#if !(USE_GENERIC_SIGNED_SHIFT)
static int optimized_for_speed = 0;
+#endif
/*
hack hack
*/
+extern set *externs;
+
/* max_key keeps track of the largest label number used in
a function. This is then used to adjust the label offset
for the next function.
#define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff)
+/* set the following macro to 1 to enable passing the
+ * first byte of functions parameters via WREG */
+#define USE_WREG_IN_FUNC_PARAMS 0
+
+
/* this is the down and dirty file with all kinds of
kludgy & hacky stuff. This is what it is all about
CODE GENERATION for a specific MCU . some of the
/* return y; */
/* return -1; */
/*-----------------------------------------------------------------*/
-static int my_powof2 (unsigned long num)
+int pic16_my_powof2 (unsigned long num)
{
if(num) {
if( (num & (num-1)) == 0) {
// fprintf(stderr, "%s\n", lb);
}
+
+
void pic16_emitpLabel(int key)
{
pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(NULL,key+100+pic16_labelOffset));
pic16_addpCode2pBlock(pb,pic16_newpCode(poc,pcop));
else
DEBUGpic16_emitcode(";","%s ignoring NULL pcop",__FUNCTION__);
-
-// fprintf(stderr, "%s\n", pcop->name);
}
+void pic16_emitpinfo(INFO_TYPE itype, pCodeOp *pcop)
+{
+ if(pcop)
+ pic16_addpCode2pBlock(pb, pic16_newpCodeInfo(itype, pcop));
+ else
+ DEBUGpic16_emitcode(";","%s ignoring NULL pcop",__FUNCTION__);
+}
+
void pic16_emitpcodeNULLop(PIC_OPCODE poc)
{
/*-----------------------------------------------------------------*/
static void resolveIfx(resolvedIfx *resIfx, iCode *ifx)
{
-
- DEBUGpic16_emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY2;
+
+// DEBUGpic16_emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
if(!resIfx)
return;
#if 1
if(IC_TRUE(ifx))
- DEBUGpic16_emitcode("; ***","ifx true is non-null");
+ DEBUGpic16_emitcode("; +++","ifx true is non-null");
+ else
+ DEBUGpic16_emitcode("; +++","ifx true is null");
if(IC_FALSE(ifx))
- DEBUGpic16_emitcode("; ***","ifx false is non-null");
+ DEBUGpic16_emitcode("; +++","ifx false is non-null");
+ else
+ DEBUGpic16_emitcode("; +++","ifx false is null");
#endif
}
asmop *aop;
memmap *space= SPEC_OCLS(sym->etype);
- DEBUGpic16_emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
-
+ FENTRY2;
+
_G.resDirect = 0; /* clear flag that instructs the result is loaded directly from aopForSym */
// sym = OP_SYMBOL(op);
DEBUGpic16_emitcode("; +++", "%s:%d", __FILE__, __LINE__);
- pic16_DumpAop("aopForSym", AOP( IC_RESULT(ic) ));
if((ic->op == '=') && IC_RESULT(ic) && AOP( IC_RESULT(ic) )
&& (AOP_TYPE(IC_RESULT(ic)) == AOP_REG) ) {
+ pic16_DumpAop("aopForSym", AOP( IC_RESULT(ic) ));
for(i=0;i<aop->size;i++)
aop->aopu.stk.pop[i] = pcop[i] = pic16_popRegFromIdx( AOP(IC_RESULT(ic))->aopu.aop_reg[i]->rIdx);
for(i=0;i<aop->size;i++) {
/* initialise for stack access via frame pointer */
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack + i + _G.stack_lat));
-
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
- pic16_popCopyReg(&pic16_pc_plusw2), pcop[i]));
- }
+ // operands on stack are accessible via "FSR2 + index" with index
+ // starting at 2 for arguments and growing from 0 downwards for
+ // local variables (index == 0 is not assigned so we add one here)
+ {
+ int soffs = sym->stack;
+ if (soffs <= 0) {
+ assert (soffs < 0);
+ soffs++;
+ } // if
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(soffs + i /*+ _G.stack_lat*/));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+ pic16_popCopyReg( pic16_frame_plusw ), pcop[i]));
+ }
+ }
if(_G.accInUse) {
pic16_poppCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
int offset = 0;
int viaimmd=0;
-
+ FENTRY2;
+
ic = sym->rematiCode;
- DEBUGpic16_emitcode(";","%s %d",__FUNCTION__,__LINE__);
-
if(IS_OP_POINTER(op)) {
DEBUGpic16_emitcode(";","%s %d IS_OP_POINTER",__FUNCTION__,__LINE__);
}
if(IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(refop)))
|| viaimmd) {
- DEBUGpic16_emitcode(";", "%s:%d immediate", __FILE__, __LINE__);
+ DEBUGpic16_emitcode(";", "%s:%d immediate, size: %d", __FILE__, __LINE__, getSize( sym->type ));
aop->aopu.pcop = pic16_popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname, 0, val);
#endif
PCOI(aop->aopu.pcop)->index = val;
+
+ aop->size = getSize( sym->type );
} else {
- DEBUGpic16_emitcode(";", "%s:%d dir", __FILE__, __LINE__);
+ DEBUGpic16_emitcode(";", "%s:%d dir size: %d", __FILE__, __LINE__, getSize( OP_SYMBOL( IC_LEFT(ic))->type));
aop->aopu.pcop = pic16_popRegFromString(OP_SYMBOL(IC_LEFT(ic))->rname,
getSize( OP_SYMBOL( IC_LEFT(ic))->type), val, op);
-// aop->size = AOP_SIZE( IC_LEFT(ic) );
+
+ aop->size = getSize( OP_SYMBOL( IC_LEFT(ic))->type );
}
aop2->type != AOP_REG )
return FALSE ;
+ /* This is a bit too restrictive if one is a subset of the other...
if (aop1->size != aop2->size )
return FALSE ;
+ */
- for (i = 0 ; i < aop1->size ; i++ ) {
+ for (i = 0 ; i < min(aop1->size, aop2->size) ; i++ ) {
// if(aop1->aopu.aop_reg[i]->type != aop2->aopu.aop_reg[i]->type)return FALSE;
// if(aop1->aopu.aop_reg[i]->type == AOP_REG)
if (!op)
return ;
-// DEBUGpic16_emitcode(";","%s %d",__FUNCTION__, __LINE__);
+ DEBUGpic16_emitcode(";","%s %d",__FUNCTION__, __LINE__);
/* if this a literal */
if (IS_OP_LITERAL(op)) {
sym = OP_SYMBOL(op);
- DEBUGpic16_emitcode("; ***", "%d: symbol name = %s", __LINE__, sym->name);
+ DEBUGpic16_emitcode("; ***", "%d: symbol name = %s, regType = %d", __LINE__, sym->name, sym->regType);
/* if the type is a conditional */
if (sym->regType == REG_CND) {
aop = op->aop = sym->aop = newAsmop(AOP_CRY);
if (sym->remat) {
sym->aop = op->aop = aop = aopForRemat (op);
- aop->size = getSize(sym->type);
- //DEBUGpic16_emitcode(";"," %d: size %d, %s\n",__LINE__,aop->size,aop->aopu.aop_immd);
+// aop->size = getSize(sym->type);
+// DEBUGpic16_emitcode(";"," %d: size %d, %s\n",__LINE__,aop->size,aop->aopu.aop_immd);
return;
}
/* we must store the result on stack */
if((op == IC_RESULT(ic)) && RESULTONSTA(ic)) {
+ // operands on stack are accessible via "FSR2 + index" with index
+ // starting at 2 for arguments and growing from 0 downwards for
+ // local variables (index == 0 is not assigned so we add one here)
+ int soffs = OP_SYMBOL(IC_RESULT(ic))->stack;
+ if (soffs <= 0) {
+ assert (soffs < 0);
+ soffs++;
+ } // if
if(_G.accInUse)pic16_pushpCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
for(i=0;i<aop->size;i++) {
- /* initialise for stack access via frame pointer */
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(OP_SYMBOL(IC_RESULT(ic))->stack + i + _G.stack_lat));
-
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
- aop->aopu.stk.pop[i], pic16_popCopyReg(&pic16_pc_plusw2)));
- }
+ /* initialise for stack access via frame pointer */
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(soffs + i /*+ _G.stack_lat*/));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+ aop->aopu.stk.pop[i], pic16_popCopyReg(pic16_frame_plusw)));
+ }
if(_G.accInUse)pic16_poppCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
}
return (rs);
case AOP_LIT:
- sprintf(s,"0x%02x", pic16aopLiteral (aop->aopu.aop_lit,offset));
+ sprintf(s,"0X%02x", pic16aopLiteral (aop->aopu.aop_lit,offset));
rs = Safe_calloc(1,strlen(s)+1);
strcpy(rs,s);
return rs;
if(pcop->name) {
DEBUGpic16_emitcode(";","%s offset %d",pcop->name,PCOI(pcop)->offset);
//sprintf(s,"(%s+0x%02x)", pcop->name,PCOI(aop->aopu.pcop)->offset);
- sprintf(s,"%s", pcop->name);
+ if (offset) {
+ sprintf(s,"(%s + %d)", pcop->name, offset);
+ } else {
+ sprintf(s,"%s", pcop->name);
+ }
} else
sprintf(s,"0x%02x", PCOI(aop->aopu.pcop)->offset);
// DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(_TempReg_lock) {
- werror(W_POSSBUG2, __FILE__, __LINE__);
+// werror(W_POSSBUG2, __FILE__, __LINE__);
}
_TempReg_lock += lock;
// DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(_TempReg_lock) {
- werror(W_POSSBUG2, __FILE__, __LINE__);
+// werror(W_POSSBUG2, __FILE__, __LINE__);
}
_TempReg_lock += lock;
pcor->r = pc->r;
pcor->rIdx = pc->rIdx;
pcor->r->wasUsed=1;
+ pcor->instance = pc->instance;
// DEBUGpic16_emitcode ("; ***","%s , copying %s, rIdx=%d",__FUNCTION__,pc->pcop.name,pc->rIdx);
char *rs;
pCodeOp *pcop;
- //DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY2;
/* offset is greater than
size then zero */
case AOP_REG:
{
- int rIdx = aop->aopu.aop_reg[offset]->rIdx;
+ int rIdx;
+ assert (aop && aop->aopu.aop_reg[offset] != NULL);
+ rIdx = aop->aopu.aop_reg[offset]->rIdx;
DEBUGpic16_emitcode(";","%d\tAOP_REG", __LINE__);
PCOR(pcop)->instance = offset;
pcop->type = PCOR(pcop)->r->pc_type;
+
+ DEBUGpic16_emitcode(";*+*", "%d\tAOP_REG type = %s\n", __LINE__, dumpPicOptype(pcop->type));
rs = aop->aopu.aop_reg[offset]->name;
- DEBUGpic16_emitcode(";","%d regiser idx = %d name = %s",__LINE__,rIdx,rs);
+ DEBUGpic16_emitcode(";","%d register idx = %d name = %s",__LINE__,rIdx,rs);
return pcop;
}
DEBUGpic16_emitcode(";","%d\tAOP_CRY", __LINE__);
pcop = pic16_newpCodeOpBit(aop->aopu.aop_dir,-1,1, PO_GPR_REGISTER);
+ PCOR(pcop)->instance = offset;
PCOR(pcop)->r = pic16_dirregWithName(aop->aopu.aop_dir);
//if(PCOR(pcop)->r == NULL)
//fprintf(stderr,"%d - couldn't find %s in allocated registers\n",__LINE__,aop->aopu.aop_dir);
__LINE__,
((aop->aopu.pcop->name)? (aop->aopu.pcop->name) : "no name"), offset);
pcop = pic16_pCodeOpCopy(aop->aopu.pcop);
-#if 1
- switch( aop->aopu.pcop->type ) {
- case PO_DIR: PCOR(pcop)->instance += offset; break; // patch 8
- case PO_IMMEDIATE: PCOI(pcop)->offset = offset; break;
- default:
- assert( 0 ); /* should never reach here */;
- }
-#else
- PCOI(pcop)->offset = offset;
-#endif
+ switch( aop->aopu.pcop->type ) {
+ case PO_DIR: PCOR(pcop)->instance += offset; break;
+ case PO_IMMEDIATE: PCOI(pcop)->offset = offset; break;
+ default:
+ assert( 0 ); /* should never reach here */;
+ }
return pcop;
}
}
/*-----------------------------------------------------------------*/
-/* mov2w - generate either a MOVLW or MOVFW based operand type */
+/* pic16_mov2w - generate either a MOVLW or MOVFW based operand type */
/*-----------------------------------------------------------------*/
-static void mov2w (asmop *aop, int offset)
+void pic16_mov2w (asmop *aop, int offset)
{
DEBUGpic16_emitcode ("; ***","%s %d offset=%d",__FUNCTION__,__LINE__,offset);
}
}
+void pic16_testStackOverflow(void)
+{
+#define GSTACK_TEST_NAME "__gstack_test"
+
+ pic16_emitpcode(POC_CALL, pic16_popGetWithString( GSTACK_TEST_NAME ));
+
+ {
+ symbol *sym;
+
+ sym = newSymbol( GSTACK_TEST_NAME , 0 );
+ strcpy(sym->rname, GSTACK_TEST_NAME);
+ checkAddSym(&externs, sym);
+ }
+
+}
/* push pcop into stack */
void pic16_pushpCodeOp(pCodeOp *pcop)
{
// DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pcop, pic16_popCopyReg(&pic16_pc_postdec1)));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pcop, pic16_popCopyReg( pic16_stack_postdec ))); //&pic16_pc_postdec1)));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
+
}
/* pop pcop from stack */
void pic16_poppCodeOp(pCodeOp *pcop)
{
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_preinc1), pcop));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg( pic16_stack_preinc ), pcop));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
/*-----------------------------------------------------------------*/
void pushw(void)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_postdec1));
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ pic16_emitpcode(POC_MOVWF, pic16_popCopyReg( pic16_stack_postdec )); //&pic16_pc_postdec1));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
/*-----------------------------------------------------------------*/
void pushaop(asmop *aop, int offset)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2(PCOR(pic16_popGet(aop, offset)), &pic16_pc_postdec1, 0));
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ if(is_LitAOp(aop)) {
+ pic16_emitpcode(POC_MOVLW, pic16_popGet(aop, offset));
+ pic16_emitpcode(POC_MOVWF, pic16_popCopyReg( pic16_stack_postdec )); //&pic16_pc_postdec1));
+ } else {
+ pic16_emitpcode(POC_MOVFF,
+ pic16_popGet2p(pic16_popGet(aop, offset), pic16_popCopyReg( pic16_stack_postdec ))); //&pic16_pc_postdec1)));
+ }
+
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
void popaop(asmop *aop, int offset)
{
- DEBUGpic16_emitcode("; ***", "%s %d", __FUNCTION__, __LINE__);
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2(&pic16_pc_preinc1, PCOR(pic16_popGet(aop, offset)), 0));
+ DEBUGpic16_emitcode("; ***", "%s %d", __FUNCTION__, __LINE__);
+ pic16_emitpcode(POC_MOVFF, pic16_popCombine2(pic16_stack_preinc, PCOR(pic16_popGet(aop, offset)), 0));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
void popaopidx(asmop *aop, int offset, int index)
{
int ofs=1;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(STACK_MODEL_LARGE)ofs++;
+ if(STACK_MODEL_LARGE)ofs++;
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(index + ofs));
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2(&pic16_pc_plusw2, PCOR(pic16_popGet(aop, offset)), 0));
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(index + ofs));
+ pic16_emitpcode(POC_MOVFF, pic16_popCombine2(pic16_frame_plusw, PCOR(pic16_popGet(aop, offset)), 0));
+ if(pic16_options.gstack)
+ pic16_testStackOverflow();
}
+#if !(USE_GENERIC_SIGNED_SHIFT)
/*-----------------------------------------------------------------*/
/* reAdjustPreg - points a register back to where it should */
/*-----------------------------------------------------------------*/
}
}
-
+#endif
#if 0
/*-----------------------------------------------------------------*/
int i;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
/* if the result is bit */
if (AOP_TYPE(result) == AOP_CRY) {
fprintf(stderr, "%s:%d: pic16 port warning: unsupported case\n", __FILE__, __LINE__);
pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result), i));
}
pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result), 0));
-
-/*
- pic16_emitcode("clr","a ; %d", __LINE__);
- pic16_emitcode("rlc","a");
- pic16_outAcc(result);
-*/
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* pic16_outBitOp - output a bit from Op */
+/* Move to result the value of set/clr op -- VR */
+/*-----------------------------------------------------------------*/
+void pic16_outBitOp(operand *result, pCodeOp *pcop)
+{
+ int i;
+
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ /* if the result is bit */
+ if (AOP_TYPE(result) == AOP_CRY) {
+ fprintf(stderr, "%s:%d: pic16 port warning: unsupported case\n", __FILE__, __LINE__);
+ pic16_aopPut(AOP(result),"c",0);
+ } else {
+
+ i = AOP_SIZE(result);
+ while(i--) {
+ pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result), i));
+ }
+ pic16_emitpcode(POC_RRCF, pcop);
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result), 0));
}
}
symbol *tlbl;
int size;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
/* assign asmOps to operand & result */
pic16_aopOp (IC_LEFT(ic),ic,FALSE);
pic16_aopOp (IC_RESULT(ic),ic,TRUE);
/*-----------------------------------------------------------------*/
static void pic16_genCpl (iCode *ic)
{
- int offset = 0;
- int size ;
-
+ int offset = 0;
+ int size ;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
/* assign asmOps to operand & result */
pic16_aopOp (IC_LEFT(ic),ic,FALSE);
pic16_aopOp (IC_RESULT(ic),ic,TRUE);
/*-----------------------------------------------------------------*/
static void genUminusFloat(operand *op,operand *result)
{
- int size ,offset =0 ;
- char *l;
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ int size ,offset =0 ;
+
+ FENTRY;
/* for this we just need to flip the
first it then copy the rest in place */
- size = AOP_SIZE(op) - 1;
- l = pic16_aopGet(AOP(op),3,FALSE,FALSE);
-
- MOVA(l);
-
- pic16_emitcode("cpl","acc.7");
- pic16_aopPut(AOP(result),"a",3);
+ size = AOP_SIZE(op);
while(size--) {
- pic16_aopPut(AOP(result),
- pic16_aopGet(AOP(op),offset,FALSE,FALSE),
- offset);
- offset++;
- }
+ mov2f(AOP(result), AOP(op), offset);
+ offset++;
+ }
+
+ /* toggle the MSB's highest bit */
+ pic16_emitpcode(POC_BTG, pic16_popCopyGPR2Bit(pic16_popGet(AOP(result), offset-1), 7));
}
/*-----------------------------------------------------------------*/
{
int size, i;
sym_link *optype, *rtype;
+ symbol *label;
+ int needLabel=0;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- /* assign asmops */
- pic16_aopOp(IC_LEFT(ic),ic,FALSE);
- pic16_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 ) {
-
- pic16_emitpcode(POC_BCF, pic16_popGet(AOP(IC_RESULT(ic)),0));
- pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(IC_LEFT(ic)),0));
- pic16_emitpcode(POC_BSF, pic16_popGet(AOP(IC_RESULT(ic)),0));
-
- goto release;
- }
-
- optype = operandType(IC_LEFT(ic));
- rtype = operandType(IC_RESULT(ic));
+ FENTRY;
+
+ /* assign asmops */
+ pic16_aopOp(IC_LEFT(ic),ic,FALSE);
+ pic16_aopOp(IC_RESULT(ic),ic,TRUE);
- /* if float then do float stuff */
- if (IS_FLOAT(optype)) {
- genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
- 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 ) {
+
+ pic16_emitpcode(POC_BCF, pic16_popGet(AOP(IC_RESULT(ic)),0));
+ pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(IC_LEFT(ic)),0));
+ pic16_emitpcode(POC_BSF, pic16_popGet(AOP(IC_RESULT(ic)),0));
+ goto release;
+ }
- /* otherwise subtract from zero by taking the 2's complement */
- size = AOP_SIZE(IC_LEFT(ic));
+ optype = operandType(IC_LEFT(ic));
+ rtype = operandType(IC_RESULT(ic));
- for(i=0; i<size; i++) {
- if (pic16_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
- pic16_emitpcode(POC_COMF, pic16_popGet(AOP(IC_LEFT(ic)),i));
- else {
- pic16_emitpcode(POC_COMFW, pic16_popGet(AOP(IC_LEFT(ic)),i));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),i));
- }
- }
+ /* if float then do float stuff */
+ if (IS_FLOAT(optype)) {
+ genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
+ goto release;
+ }
- pic16_emitpcode(POC_INCF, pic16_popGet(AOP(IC_RESULT(ic)),0));
- for(i=1; i<size; i++) {
- emitSKPNZ;
- pic16_emitpcode(POC_INCF, pic16_popGet(AOP(IC_RESULT(ic)),i));
- }
+ /* otherwise subtract from zero by taking the 2's complement */
+ size = AOP_SIZE(IC_LEFT(ic));
+ label = newiTempLabel ( NULL );
+
+ if (pic16_sameRegs (AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
+ for (i=size-1; i > 0; i--) {
+ pic16_emitpcode (POC_COMF, pic16_popGet (AOP(IC_LEFT(ic)), i));
+ } // for
+ pic16_emitpcode (POC_NEGF, pic16_popGet (AOP(IC_LEFT(ic)), 0));
+ for (i=1; i < size; i++) {
+ if (i == size - 1) { emitSKPNZ; } else { pic16_emitpcode (POC_BNZ, pic16_popGetLabel (label->key)); needLabel++; }
+ pic16_emitpcode (POC_INCF, pic16_popGet (AOP(IC_LEFT(ic)), i));
+ } // for
+ } else {
+ for (i=size-1; i >= 0; i--) {
+ pic16_emitpcode (POC_COMFW, pic16_popGet (AOP(IC_LEFT(ic)), i));
+ pic16_emitpcode (POC_MOVWF, pic16_popGet (AOP(IC_RESULT(ic)), i));
+ } // for
+ if (size > 1) {
+ for (i=0; i < size-2; i++) {
+ pic16_emitpcode (POC_INCF, pic16_popGet (AOP(IC_RESULT(ic)),i));
+ pic16_emitpcode (POC_BNZ, pic16_popGetLabel (label->key)); needLabel++;
+ } // for
+ pic16_emitpcode (POC_INFSNZ, pic16_popGet (AOP(IC_RESULT(ic)), size-2));
+ } // if
+ pic16_emitpcode (POC_INCF, pic16_popGet(AOP(IC_RESULT(ic)), size-1));
+ }
+ if (needLabel)
+ pic16_emitpLabel (label->key);
release:
- /* release the aops */
- pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
- pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ /* release the aops */
+ pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
+ pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
}
#if 0
/*-----------------------------------------------------------------*/
/* assignResultValue - assign results to oper, rescall==1 is */
-/* called from genCall() or genPCall() */
+/* called from genCall() or genPcall() */
/*-----------------------------------------------------------------*/
static void assignResultValue(operand * oper, int rescall)
{
int size = AOP_SIZE(oper);
int offset=0;
- DEBUGpic16_emitcode ("; ***","%s %d rescall:%d size:%d",__FUNCTION__,__LINE__,rescall,size); // patch 14
+ FENTRY2;
+// DEBUGpic16_emitcode ("; ***","%s %d rescall:%d size:%d",__FUNCTION__,__LINE__,rescall,size); // patch 14
DEBUGpic16_pic16_AopType(__LINE__,oper,NULL,NULL);
if(rescall) {
/* >32-bits, result on stack, and FSR0 points to beginning.
* Fix stack when done */
/* FIXME FIXME */
+// debugf("WARNING: Possible bug when returning more than 4-bytes\n");
while (size--) {
// DEBUGpic16_emitcode("; ", "POC_MOVLW %d", GpsuedoStkPtr);
// DEBUGpic16_emitcode("; ", "POC_MOVFW PLUSW2");
/* fix stack */
pic16_emitpcode(POC_MOVLW, pic16_popGetLit( AOP_SIZE(oper) ));
- pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
+ pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( pic16_stackpnt_lo )); //&pic16_pc_fsr1l ));
if(STACK_MODEL_LARGE) {
emitSKPNC;
- pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg( pic16_stackpnt_hi )); //&pic16_pc_fsr1h ));
}
}
} else {
int areg = 0; /* matching argument register */
+// debugf("_G.useWreg = %d\tGpsuedoStkPtr = %d\n", _G.useWreg, GpsuedoStkPtr);
areg = SPEC_ARGREG( OP_SYM_ETYPE( oper ) ) - 1;
/* its called from genReceive (probably) -- VR */
+ /* I hope this code will not be called from somewhere else in the future!
+ * We manually set the pseudo stack pointer in genReceive. - dw
+ */
if(!GpsuedoStkPtr && _G.useWreg) {
// DEBUGpic16_emitcode("; ", "pop %d", GpsuedoStkPtr);
size--;
pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper), offset /*size*/));
offset++;
+// debugf("receive from WREG\n", 0);
}
+ GpsuedoStkPtr++; /* otherwise the calculation below fails (-_G.useWreg) */
}
// GpsuedoStkPtr++;
_G.stack_lat = AOP_SIZE(oper)-1;
while (size) {
size--;
GpsuedoStkPtr++;
- popaopidx(AOP(oper), offset, GpsuedoStkPtr);
+ popaopidx(AOP(oper), offset, GpsuedoStkPtr - _G.useWreg);
+// debugf("receive from STACK\n", 0);
offset++;
}
}
{
// int size, offset=0;
+ FENTRY;
DEBUGpic16_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__);
-
if(ic->parmPush) {
pic16_aopOp(IC_LEFT(ic), ic, FALSE );
/*-----------------------------------------------------------------*/
static void genIpop (iCode *ic)
{
+ FENTRY;
DEBUGpic16_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__);
#if 0
int size,offset ;
#endif /* 0 */
+static int wparamCmp(void *p1, void *p2)
+{
+ return (!strcmp((char *)p1, (char *)p2));
+}
+
+int inWparamList(char *s)
+{
+ return isinSetWith(wparamList, s, wparamCmp);
+}
+
+
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
sym_link *ftype;
int stackParms=0;
int use_wreg=0;
+ int inwparam=0;
char *fname;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
ftype = OP_SYM_TYPE(IC_LEFT(ic));
/* if caller saves & we have not saved then */
// stackParms = psuedoStkPtr;
// fprintf(stderr, "%s:%d ic parmBytes = %d\n", __FILE__, __LINE__, ic->parmBytes);
fname = OP_SYMBOL(IC_LEFT(ic))->rname[0]?OP_SYMBOL(IC_LEFT(ic))->rname:OP_SYMBOL(IC_LEFT(ic))->name;
+ inwparam = inWparamList(OP_SYMBOL(IC_LEFT(ic))->name);
#if 0
gpsimDebug_StackDump(__FILE__, __LINE__, fname );
int firstTimeThruLoop = 1;
-#if 1
/* reverse sendSet if function is not reentrant */
if(!IFFUNC_ISREENT(ftype))
_G.sendSet = reverseSet(_G.sendSet);
-#endif
/* First figure how many parameters are getting passed */
-
-/* do we really need to know this ? -- VR
- for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
- pic16_aopOp(IC_LEFT(sic),sic,FALSE);
- psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
- pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
- }
-*/
-
-
-// stackParms = psuedoStkPtr;
stackParms = 0;
use_wreg = 0;
for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
+ int size;
+// int offset = 0;
pic16_aopOp(IC_LEFT(sic),sic,FALSE);
size = AOP_SIZE(IC_LEFT(sic));
stackParms += size;
- while (size--) {
- DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
- pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
- DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
+ /* pass the last byte through WREG */
+ if(inwparam) {
- if(!firstTimeThruLoop) {
- /* If this is not the first time we've been through the loop
- * then we need to save the parameter in a temporary
- * register. The last byte of the last parameter is
- * passed in W. */
+ while (size--) {
+ DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+ pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
+ DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
- pushw();
-// --psuedoStkPtr; // sanity check
- }
+ if(!firstTimeThruLoop) {
+ /* If this is not the first time we've been through the loop
+ * then we need to save the parameter in a temporary
+ * register. The last byte of the last parameter is
+ * passed in W. */
+
+ pushw();
+// --psuedoStkPtr; // sanity check
+ use_wreg = 1;
+ }
- firstTimeThruLoop=0;
+ firstTimeThruLoop=0;
+
+ pic16_mov2w (AOP(IC_LEFT(sic)), size);
+
+// offset++;
+ }
+ } else {
+ /* all arguments are passed via stack */
+ use_wreg = 0;
- mov2w (AOP(IC_LEFT(sic)), size);
+ while (size--) {
+ DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+ pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
+ DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
- offset++;
+// pushaop(AOP(IC_LEFT(sic)), size);
+ pic16_mov2w (AOP(IC_LEFT(sic)), size);
+ pushw();
+ }
}
+
pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
}
- /* save last parameter to stack if functions has varargs */
- if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype))pushw();
- else use_wreg = 1; /* last parameter in WREG */
-
+ if(inwparam) {
+ if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype)) {
+ pushw(); /* save last parameter to stack if functions has varargs */
+ use_wreg = 0;
+ } else
+ use_wreg = 1;
+ } else use_wreg = 0;
+
_G.stackRegSet = _G.sendSet;
_G.sendSet = NULL;
}
pic16_emitpcode(POC_CALL,pic16_popGetWithString(fname));
GpsuedoStkPtr=0;
+
/* if we need to assign a result value */
if ((IS_ITEMP(IC_RESULT(ic))
&& (OP_SYMBOL(IC_RESULT(ic))->nRegs
}
stackParms -= use_wreg;
-
+
if(stackParms>0) {
if(stackParms == 1) {
- pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1l));
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg(pic16_stackpnt_lo )); //&pic16_pc_fsr1l));
} else {
pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms));
- pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
+ pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( pic16_stackpnt_lo )); //&pic16_pc_fsr1l ));
}
if(STACK_MODEL_LARGE) {
emitSKPNC;
- pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg( pic16_stackpnt_hi )); //&pic16_pc_fsr1h ));
}
}
/*-----------------------------------------------------------------*/
static void genPcall (iCode *ic)
{
- sym_link *ftype;
+ sym_link *ftype, *fntype;
int stackParms=0;
symbol *retlbl = newiTempLabel(NULL);
pCodeOp *pcop_lbl = pic16_popGetLabel(retlbl->key);
- int use_wreg=0;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
ftype = OP_SYM_TYPE(IC_LEFT(ic));
-
+ fntype = operandType( IC_LEFT(ic) )->next;
+
/* if send set is not empty the assign */
if (_G.sendSet) {
iCode *sic;
int psuedoStkPtr=-1;
- int firstTimeThruLoop = 1;
-
- /* For the Pic port, there is no data stack.
- * So parameters passed to functions are stored
- * in registers. (The pCode optimizer will get
- * rid of most of these :). */
-
-#if 1
/* reverse sendSet if function is not reentrant */
- if(!IFFUNC_ISREENT(ftype))
+ if(!IFFUNC_ISREENT(fntype))
_G.sendSet = reverseSet(_G.sendSet);
-#endif
-
- /* First figure how many parameters are getting passed */
-#if 0
- for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
- pic16_aopOp(IC_LEFT(sic),sic,FALSE);
- psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
- pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
- }
-#endif
-// stackParms = psuedoStkPtr;
stackParms = 0;
-
+
for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
- int size, offset = 0;
+ int size;
pic16_aopOp(IC_LEFT(sic),sic,FALSE);
size = AOP_SIZE(IC_LEFT(sic));
stackParms += size;
+ /* all parameters are passed via stack, since WREG is clobbered
+ * by the calling sequence */
while (size--) {
DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
- if(!firstTimeThruLoop) {
- /* If this is not the first time we've been through the loop
- * then we need to save the parameter in a temporary
- * register. The last byte of the last parameter is
- * passed in W. */
-
- pushw();
- --psuedoStkPtr; // sanity check
- }
-
- firstTimeThruLoop=0;
-
- mov2w (AOP(IC_LEFT(sic)), size);
-
- offset++;
+ pic16_mov2w (AOP(IC_LEFT(sic)), size);
+ pushw();
}
-
pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
}
- if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype))pushw();
- else use_wreg = 1; /* last parameter in WREG */
-
_G.stackRegSet = _G.sendSet;
_G.sendSet = NULL;
}
pic16_freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
}
- stackParms -= use_wreg;
+// stackParms -= use_wreg;
if(stackParms>0) {
pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms));
- pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
+ pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( pic16_stackpnt_lo ));
if(STACK_MODEL_LARGE) {
- /* this implies that stackParms < 256 !!! -- VR */
emitSKPNC;
- pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg( pic16_stackpnt_hi ));
}
}
}
symbol *sym;
sym_link *ftype;
+ FENTRY;
DEBUGpic16_emitcode ("; ***","%s %d curr label offset=%dprevious max_key=%d ",__FUNCTION__,__LINE__,pic16_labelOffset,max_key);
pic16_labelOffset += (max_key+4);
if(strcmp(sym->name, "main")) {
if(1 /*!options.ommitFramePtr || sym->regsUsed*/) {
/* setup the stack frame */
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr2l, &pic16_pc_postdec1, 0));
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr1l, &pic16_pc_fsr2l, 0));
if(STACK_MODEL_LARGE)
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr1h, &pic16_pc_fsr2h, 0));
+ pic16_pushpCodeOp(pic16_popCopyReg(pic16_framepnt_hi));
+ pic16_pushpCodeOp(pic16_popCopyReg(pic16_framepnt_lo));
+
+ pic16_emitpcode(POC_MOVFF, pic16_popCombine2( pic16_stackpnt_lo, pic16_framepnt_lo, 0));
+ if(STACK_MODEL_LARGE)
+ pic16_emitpcode(POC_MOVFF, pic16_popCombine2( pic16_stackpnt_hi, pic16_framepnt_hi, 0));
}
}
if (sym->stack > 127)werror(W_STACK_OVERFLOW, sym->name);
pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack));
- pic16_emitpcode(POC_SUBWF, pic16_popCopyReg(&pic16_pc_fsr1l));
- emitSKPNC;
- pic16_emitpcode(POC_DECF, pic16_popCopyReg(&pic16_pc_fsr1h));
+ pic16_emitpcode(POC_SUBWF, pic16_popCopyReg( pic16_stackpnt_lo )); //&pic16_pc_fsr1l));
+ emitSKPC;
+ pic16_emitpcode(POC_DECF, pic16_popCopyReg( pic16_stackpnt_hi )); //&pic16_pc_fsr1h));
}
- if(IFFUNC_HASVARARGS(sym->type) || IFFUNC_ISREENT(sym->type))
+ if(inWparamList(sym->name)) {
+ if(IFFUNC_HASVARARGS(sym->type) || IFFUNC_ISREENT(sym->type))
+ _G.useWreg = 0;
+ else
+ _G.useWreg = 1;
+ } else
_G.useWreg = 0;
- else _G.useWreg = 1;
/* if callee-save to be used for this function
* then save the registers being used in this function */
if (sym->regsUsed) {
/* save the registers used */
DEBUGpic16_emitcode("; **", "Saving used registers in stack");
+ pic16_emitpinfo(INF_LOCALREGS, pic16_newpCodeOpLocalRegs(LR_ENTRY_BEGIN));
for ( i = 0 ; i < sym->regsUsed->size ; i++) {
if (bitVectBitValue(sym->regsUsed,i)) {
pic16_pushpCodeOp( pic16_popRegFromIdx(i) );
}
}
}
+ pic16_emitpinfo(INF_LOCALREGS, pic16_newpCodeOpLocalRegs(LR_ENTRY_END));
}
}
{
symbol *sym = OP_SYMBOL(IC_LEFT(ic));
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
if(IFFUNC_ISNAKED(sym->type)) {
DEBUGpic16_emitcode("; ***", "_naked function, no epilogue");
/* TODO: add code here -- VR */
}
- if ((IFFUNC_ISREENT(sym->type) || options.stackAuto)
- && sym->stack) {
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack));
- pic16_emitpcode(POC_ADDWF, pic16_popCopyReg(&pic16_pc_fsr1l));
- emitSKPNC;
- pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1h));
- }
-
+// sym->regsUsed = _G.fregsUsed;
+
/* now we need to restore the registers */
/* if any registers used */
if (sym->regsUsed) {
int i;
+ pic16_emitpinfo(INF_LOCALREGS, pic16_newpCodeOpLocalRegs(LR_EXIT_BEGIN));
/* restore registers used */
DEBUGpic16_emitcode("; **", "Restoring used registers from stack");
for ( i = sym->regsUsed->size; i >= 0; i--) {
_G.nRegsSaved--;
}
}
+ pic16_emitpinfo(INF_LOCALREGS, pic16_newpCodeOpLocalRegs(LR_EXIT_END));
+
+ }
+
+ if ((IFFUNC_ISREENT(sym->type) || options.stackAuto)
+ && sym->stack) {
+ if (sym->stack == 1) {
+ pic16_emitpcode(POC_INFSNZ, pic16_popCopyReg( pic16_stackpnt_lo ));
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg( pic16_stackpnt_hi ));
+ } else {
+ // we have to add more than one...
+ pic16_emitpcode(POC_MOVWF, pic16_popCopyReg( pic16_stack_postinc )); // this holds a return value!
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack-1));
+ pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( pic16_stackpnt_lo ));
+ emitSKPNC;
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg( pic16_stackpnt_hi ));
+ pic16_emitpcode(POC_COMF, pic16_popCopyReg(&pic16_pc_wreg)); // WREG = -(WREG+1)!
+ pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(pic16_stack_plusw)); // this holds a retrun value!
+ }
}
if(strcmp(sym->name, "main")) {
if(1/*!options.ommitFramePtr ||*/ /*sym->regsUsed*/) {
/* restore stack frame */
if(STACK_MODEL_LARGE)
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_preinc1, &pic16_pc_fsr2h, 0));
- pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_preinc1, &pic16_pc_fsr2l, 0));
+ pic16_poppCodeOp( pic16_popCopyReg( pic16_framepnt_hi ));
+ pic16_poppCodeOp( pic16_popCopyReg( pic16_framepnt_lo ));
}
}
void pic16_storeForReturn(operand *op, int offset, pCodeOp *dest)
{
if(is_LitOp(op)) {
- pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(op), offset));
- if(dest->type != PO_WREG)pic16_emitpcode(POC_MOVWF, dest);
+ unsigned long lit = (unsigned long)floatFromVal(AOP(op)->aopu.aop_lit);
+ if(lit == 0) {
+ pic16_emitpcode(POC_CLRF, dest);
+ } else {
+ pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(op), offset));
+ if(dest->type != PO_WREG)pic16_emitpcode(POC_MOVWF, dest);
+ }
} else {
if(dest->type == PO_WREG && (offset == 0)) {
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(op), offset));
int size;
operand *left;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
/* if we have no return value then
* just generate the "ret" */
/* setup FSR0 */
pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
- pic16_popCopyReg(&pic16_pc_fsr1l), pic16_popCopyReg(&pic16_pc_fsr0l)));
+ pic16_popCopyReg( pic16_stackpnt_lo ), pic16_popCopyReg(&pic16_pc_fsr0l)));
if(STACK_MODEL_LARGE) {
pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
- pic16_popCopyReg(&pic16_pc_fsr1h), pic16_popCopyReg(&pic16_pc_fsr0h)));
+ pic16_popCopyReg( pic16_stackpnt_hi ), pic16_popCopyReg(&pic16_pc_fsr0h)));
} else {
- pic16_emitpcode(POC_CLRF, pic16_popCopyReg( &pic16_pc_fsr1h ) );
+ pic16_emitpcode(POC_CLRF, pic16_popCopyReg( pic16_stackpnt_hi ));
}
}
/*-----------------------------------------------------------------*/
static void genLabel (iCode *ic)
{
+ FENTRY;
+ /* special case never generate */
+ if (IC_LABEL(ic) == entryLabel)
+ return ;
- /* special case never generate */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (IC_LABEL(ic) == entryLabel)
- return ;
-
- pic16_emitpLabel(IC_LABEL(ic)->key);
- pic16_emitcode("","_%05d_DS_:",(IC_LABEL(ic)->key+100 + pic16_labelOffset));
+ pic16_emitpLabel(IC_LABEL(ic)->key);
+// pic16_emitcode("","_%05d_DS_:",(IC_LABEL(ic)->key+100 + pic16_labelOffset));
}
/*-----------------------------------------------------------------*/
//tsd
static void genGoto (iCode *ic)
{
+ FENTRY;
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_LABEL(ic)->key));
- pic16_emitcode ("goto","_%05d_DS_",(IC_LABEL(ic)->key+100)+pic16_labelOffset);
+// pic16_emitcode ("goto","_%05d_DS_",(IC_LABEL(ic)->key+100)+pic16_labelOffset);
}
operand *right,
operand *result)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
if(!pic16_sameRegs(AOP(result),AOP(right)))
pic16_emitpcode(POC_BSF, pic16_popGet(AOP(result),0));
operand *result)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
DEBUGpic16_pic16_AopTypeSign(__LINE__,left,right,result);
operand *right,
operand *result)
{
+ FENTRY;
+ DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
+ DEBUGpic16_pic16_AopTypeSign(__LINE__,left,right,result);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
- DEBUGpic16_pic16_AopTypeSign(__LINE__,left,right,result);
-
- /* (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 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 is checked already == 2 */
-// size = AOP_SIZE(result);
+ /* size is checked already == 2 */
+// size = AOP_SIZE(result);
- if (AOP_TYPE(right) == AOP_LIT) {
- pic16_emitpcomment("multiply lit val:%s by variable %s and store in %s",
- pic16_aopGet(AOP(right),0,FALSE,FALSE),
- pic16_aopGet(AOP(left),0,FALSE,FALSE),
- pic16_aopGet(AOP(result),0,FALSE,FALSE));
- } else {
- pic16_emitpcomment("multiply variable :%s by variable %s and store in %s",
- pic16_aopGet(AOP(right),0,FALSE,FALSE),
- pic16_aopGet(AOP(left),0,FALSE,FALSE),
- pic16_aopGet(AOP(result),0,FALSE,FALSE));
- }
+ if (AOP_TYPE(right) == AOP_LIT) {
+ pic16_emitpcomment("multiply lit val:%s by variable %s and store in %s",
+ pic16_aopGet(AOP(right),0,FALSE,FALSE),
+ pic16_aopGet(AOP(left),0,FALSE,FALSE),
+ pic16_aopGet(AOP(result),0,FALSE,FALSE));
+ } else {
+ pic16_emitpcomment("multiply variable :%s by variable %s and store in %s",
+ pic16_aopGet(AOP(right),0,FALSE,FALSE),
+ pic16_aopGet(AOP(left),0,FALSE,FALSE),
+ pic16_aopGet(AOP(result),0,FALSE,FALSE));
+ }
- pic16_genMult16X16_16(left, right,result);
+ pic16_genMult16X16_16(left, right,result);
}
/*-----------------------------------------------------------------*/
operand *right,
operand *result)
{
+ FENTRY;
+ DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
+ DEBUGpic16_pic16_AopTypeSign(__LINE__,left,right,result);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
- DEBUGpic16_pic16_AopTypeSign(__LINE__,left,right,result);
-
- /* (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 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 is checked already == 4 */
-// size = AOP_SIZE(result);
+ /* size is checked already == 4 */
+// size = AOP_SIZE(result);
- if (AOP_TYPE(right) == AOP_LIT) {
- pic16_emitpcomment("multiply lit val:%s by variable %s and store in %s",
- pic16_aopGet(AOP(right),0,FALSE,FALSE),
- pic16_aopGet(AOP(left),0,FALSE,FALSE),
- pic16_aopGet(AOP(result),0,FALSE,FALSE));
- } else {
- pic16_emitpcomment("multiply variable :%s by variable %s and store in %s",
- pic16_aopGet(AOP(right),0,FALSE,FALSE),
- pic16_aopGet(AOP(left),0,FALSE,FALSE),
- pic16_aopGet(AOP(result),0,FALSE,FALSE));
- }
+ if (AOP_TYPE(right) == AOP_LIT) {
+ pic16_emitpcomment("multiply lit val:%s by variable %s and store in %s",
+ pic16_aopGet(AOP(right),0,FALSE,FALSE),
+ pic16_aopGet(AOP(left),0,FALSE,FALSE),
+ pic16_aopGet(AOP(result),0,FALSE,FALSE));
+ } else {
+ pic16_emitpcomment("multiply variable :%s by variable %s and store in %s",
+ pic16_aopGet(AOP(right),0,FALSE,FALSE),
+ pic16_aopGet(AOP(left),0,FALSE,FALSE),
+ pic16_aopGet(AOP(result),0,FALSE,FALSE));
+ }
- pic16_genMult32X32_32(left, right,result);
+ pic16_genMult32X32_32(left, right,result);
}
operand *right = IC_RIGHT(ic);
operand *result= IC_RESULT(ic);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
/* assign the amsops */
pic16_aopOp (left,ic,FALSE);
pic16_aopOp (right,ic,FALSE);
operand *right,
operand *result)
{
+ char *l;
- char *l;
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
/* the result must be bit */
pic16_emitcode("mov","b,%s",pic16_aopGet(AOP(right),0,FALSE,FALSE));
l = pic16_aopGet(AOP(left),0,FALSE,FALSE);
operand *right,
operand *result)
{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
+ sym_link *opetype = operandType(result);
+ char *l ;
+ symbol *lbl ;
+ int size,offset;
/* result = divident / divisor
* - divident may be a register or a literal,
* In addition we must handle signed and unsigned, which
* result in 6 final different cases -- VR */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
size = AOP_SIZE(result) - 1;
offset = 1;
/* signed or unsigned */
* Division functions written here just in case someone
* wants to inline and not use the support libraries -- VR */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
/* assign the amsops */
pic16_aopOp (left,ic,FALSE);
pic16_aopOp (right,ic,FALSE);
operand *right,
operand *result)
{
+ char *l;
- char *l;
-
+ FENTRY;
+
+ werror(W_POSSBUG2, __FILE__, __LINE__);
/* the result must be bit */
pic16_emitcode("mov","b,%s",pic16_aopGet(AOP(right),0,FALSE,FALSE));
l = pic16_aopGet(AOP(left),0,FALSE,FALSE);
operand *right,
operand *result)
{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
+ sym_link *opetype = operandType(result);
+ char *l ;
+ symbol *lbl ;
+
+ FENTRY;
+ werror(W_POSSBUG2, __FILE__, __LINE__);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* signed or unsigned */
if (SPEC_USIGN(opetype)) {
/* unsigned is easy */
/*-----------------------------------------------------------------*/
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);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
/* assign the amsops */
pic16_aopOp (left,ic,FALSE);
pic16_aopOp (right,ic,FALSE);
*/
static void genIfxJump (iCode *ic, char *jval)
{
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
/* 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;
+ emitSKPNC;
else {
DEBUGpic16_emitcode ("; ***","%d - assuming %s is in bit space",__LINE__,jval);
pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(jval,-1,1, PO_GPR_REGISTER));
if(strcmp(jval,"a") == 0)
emitSKPNZ;
else if (strcmp(jval,"c") == 0)
- emitSKPNC;
+ emitSKPC;
else {
DEBUGpic16_emitcode ("; ***","%d - assuming %s is in bit space",__LINE__,jval);
pic16_emitpcode(POC_BTFSS, pic16_newpCodeOpBit(jval,-1,1, PO_GPR_REGISTER));
ic->generated = 1;
}
+static void genIfxpCOpJump (iCode *ic, pCodeOp *jop)
+{
+ FENTRY;
+
+ /* if true label then we jump if condition
+ supplied is true */
+ if ( IC_TRUE(ic) ) {
+ DEBUGpic16_emitcode ("; ***","%d - assuming is in bit space",__LINE__);
+ pic16_emitpcode(POC_BTFSC, jop);
+
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_TRUE(ic)->key));
+ pic16_emitcode(" goto","_%05d_DS_",IC_TRUE(ic)->key+100 + pic16_labelOffset);
+
+ } else {
+ /* false label is present */
+ DEBUGpic16_emitcode ("; ***","%d - assuming is in bit space",__LINE__);
+ pic16_emitpcode(POC_BTFSS, jop);
+
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ic)->key));
+ pic16_emitcode(" goto","_%05d_DS_",IC_FALSE(ic)->key+100 + pic16_labelOffset);
+ }
+
+
+ /* mark the icode as generated */
+ ic->generated = 1;
+}
+
#if 0
// not needed ATM
rifx->generated = 1;
}
+#if !(USE_SIMPLE_GENCMP)
/*-----------------------------------------------------------------*/
/* genSkipz2 */
/*-----------------------------------------------------------------*/
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(rifx->lbl->key));
rifx->generated = 1;
}
+#endif
#if 0
/*-----------------------------------------------------------------*/
}
#endif
+#if !(USE_SIMPLE_GENCMP)
/*-----------------------------------------------------------------*/
/* genSkipCond */
/*-----------------------------------------------------------------*/
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(rifx->lbl->key));
rifx->generated = 1;
}
+#endif
#if 0
/*-----------------------------------------------------------------*/
}
#endif
+#if !defined(__BORLANDC__) && !defined(_MSC_VER)
+#define DEBUGpc(fmt,...) DEBUGpic16_emitcode("; =:=", "%s:%s:%d: " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#endif
+#define isAOP_LIT(x) (AOP_TYPE(x) == AOP_LIT)
+#define isAOP_REGlike(x) (AOP_TYPE(x) == AOP_REG || AOP_TYPE(x) == AOP_DIR || AOP_TYPE(x) == AOP_PCODE || AOP_TYPE(x) == AOP_STA)
+
+/*-----------------------------------------------------------------*/
+/* mov2w_regOrLit :- move to WREG either the offset's byte from */
+/* aop (if it's NOT a literal) or from lit (if */
+/* aop is a literal) */
+/*-----------------------------------------------------------------*/
+void mov2w_regOrLit (asmop *aop, unsigned long lit, int offset) {
+ if (aop->type == AOP_LIT) {
+ pic16_emitpcode (POC_MOVLW, pic16_popGetLit(lit >> (offset*8)));
+ } else {
+ pic16_emitpcode (POC_MOVFW, pic16_popGet (aop, offset));
+ }
+}
+
/*-----------------------------------------------------------------*/
/* genCmp :- greater or less than comparison */
/*-----------------------------------------------------------------*/
-#if 1
+
+#if USE_SIMPLE_GENCMP
+
+/* genCmp performs a left < right comparison, stores
+ * the outcome in result (if != NULL) and generates
+ * control flow code for the ifx (if != NULL).
+ *
+ * This version leaves in sequences like
+ * "B[CS]F STATUS,0; BTFS[CS] STATUS,0"
+ * which should be optmized by the peephole
+ * optimizer - RN 2005-01-01 */
+static void genCmp (operand *left,operand *right,
+ operand *result, iCode *ifx, int sign)
+{
+ resolvedIfx rIfx;
+ int size;
+ int offs;
+ symbol *templbl;
+ operand *dummy;
+ unsigned long lit;
+ unsigned long mask;
+ int performedLt;
+
+ FENTRY;
+
+ assert (AOP_SIZE(left) == AOP_SIZE(right));
+ assert (left && right);
+
+ size = AOP_SIZE(right) - 1;
+ mask = (0x100UL << (size*8)) - 1;
+ // in the end CARRY holds "left < right" (performedLt == 1) or "left >= right" (performedLt == 0)
+ performedLt = 1;
+ templbl = NULL;
+ lit = 0;
+
+ resolveIfx (&rIfx, ifx);
+
+ /**********************************************************************
+ * handle bits - bit compares are promoted to int compares seemingly! *
+ **********************************************************************/
+#if 0
+ // THIS IS COMPLETELY UNTESTED!
+ if (AOP_TYPE(left) == AOP_CRY && AOP_TYPE(right) == AOP_CRY) {
+ pCodeOp *pcleft = pic16_popGet(AOP(left), 0);
+ pCodeOp *pcright = pic16_popGet(AOP(right), 0);
+ assert (pcleft->type == PO_GPR_BIT && pcright->type == PO_GPR_BIT);
+
+ emitSETC;
+ // 1 < {0,1} is false --> clear C by skipping the next instruction
+ //pic16_emitpcode (POC_BTFSS, pic16_popCopyGPR2Bit (AOP(left),0), PCORB(pcleft)->bit);
+ pic16_emitpcode (POC_BTFSS, pic16_popGet (AOP(left), 0));
+ // {0,1} < 0 is false --> clear C by NOT skipping the next instruction
+ pic16_emitpcode (POC_BTFSS, pic16_popCopyGPR2Bit (pic16_popGet(AOP(right),0), PCORB(pcright)->bit));
+ emitCLRC; // only skipped for left=0 && right=1
+
+ goto correct_result_in_carry;
+ } // if
+#endif
+
+ /*************************************************
+ * make sure that left is register (or the like) *
+ *************************************************/
+ if (!isAOP_REGlike(left)) {
+ #if !defined(__BORLANDC__) && !defined(_MSC_VER)
+ DEBUGpc ("swapping arguments (AOP_TYPEs %d/%d)", AOP_TYPE(left), AOP_TYPE(right));
+ #endif
+ assert (isAOP_LIT(left));
+ assert (isAOP_REGlike(right));
+ // swap left and right
+ // left < right <==> right > left <==> (right >= left + 1)
+ lit = (unsigned long)floatFromVal(AOP(left)->aopu.aop_lit);
+
+ if ( (!sign && (lit & mask) == mask) || (sign && (lit & mask) == (mask >> 1)) ) {
+ // MAXVALUE < right? always false
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ } // if
+
+ // This fails for lit = 0xFF (unsigned) AND lit = 0x7F (signed),
+ // that's we handled it above.
+ lit++;
+
+ dummy = left;
+ left = right;
+ right = dummy;
+
+ performedLt ^= 1; // instead of "left < right" we check for "right >= left+1"
+ } else if (isAOP_LIT(right)) {
+ lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+ } // if
+
+ assert (isAOP_REGlike(left)); // left must be register or the like
+ assert (isAOP_REGlike(right) || isAOP_LIT(right)); // right may be register-like or a literal
+
+ /*************************************************
+ * special cases go here *
+ *************************************************/
+
+ if (isAOP_LIT(right)) {
+ if (!sign) {
+ // unsigned comparison to a literal
+ #if !defined(__BORLANDC__) && !defined(_MSC_VER)
+ DEBUGpc ("unsigned compare: left %s lit(0x%X=%lu), size=%d", performedLt ? "<" : ">=", lit, lit, size+1);
+ #endif
+ if (lit == 0) {
+ // unsigned left < 0? always false
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ }
+ } else {
+ // signed comparison to a literal
+ #if !defined(__BORLANDC__) && !defined(_MSC_VER)
+ DEBUGpc ("signed compare: left %s lit(0x%X=%ld), size=%d, mask=%x", performedLt ? "<" : ">=", lit, lit, size+1, mask);
+ #endif
+ if ((lit & mask) == ((0x80 << (size*8)) & mask)) {
+ // signed left < 0x80000000? always false
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ } else if (lit == 0) {
+ // compare left < 0; set CARRY if SIGNBIT(left) is set
+ if (performedLt) emitSETC; else emitCLRC;
+ pic16_emitpcode (POC_BTFSS, pic16_popCopyGPR2Bit(pic16_popGet (AOP(left), size), 7));
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ }
+ } // if (!sign)
+ } // right is literal
+
+ /*************************************************
+ * perform a general case comparison *
+ * make sure we get CARRY==1 <==> left >= right *
+ *************************************************/
+ // compare most significant bytes
+ //DEBUGpc ("comparing bytes at offset %d", size);
+ if (!sign) {
+ // unsigned comparison
+ mov2w_regOrLit (AOP(right), lit, size);
+ pic16_emitpcode (POC_SUBFW, pic16_popGet (AOP(left), size));
+ } else {
+ // signed comparison
+ // (add 2^n to both operands then perform an unsigned comparison)
+ if (isAOP_LIT(right)) {
+ // left >= LIT <-> LIT-left <= 0 <-> LIT-left == 0 OR !(LIT-left >= 0)
+ unsigned char litbyte = (lit >> (8*size)) & 0xFF;
+
+ if (litbyte == 0x80) {
+ // left >= 0x80 -- always true, but more bytes to come
+ pic16_mov2w (AOP(left), size);
+ pic16_emitpcode (POC_XORLW, pic16_popGetLit (0x80)); // set ZERO flag
+ emitSETC;
+ } else {
+ // left >= LIT <-> left + (-LIT) >= 0 <-> left + (0x100-LIT) >= 0x100
+ pic16_mov2w (AOP(left), size);
+ pic16_emitpcode (POC_ADDLW, pic16_popGetLit (0x80));
+ pic16_emitpcode (POC_ADDLW, pic16_popGetLit ((0x100 - (litbyte + 0x80)) & 0x00FF));
+ } // if
+ } else {
+ pCodeOp *pctemp = pic16_popCopyReg(&pic16_pc_prodl);
+ //pCodeOp *pctemp = pic16_popGetTempReg(1);
+ pic16_mov2w (AOP(left), size);
+ pic16_emitpcode (POC_ADDLW, pic16_popGetLit (0x80));
+ pic16_emitpcode (POC_MOVWF, pctemp);
+ pic16_mov2w (AOP(right), size);
+ pic16_emitpcode (POC_ADDLW, pic16_popGetLit (0x80));
+ pic16_emitpcode (POC_SUBFW, pctemp);
+ //pic16_popReleaseTempReg(pctemp, 1);
+ }
+ } // if (!sign)
+
+ // compare remaining bytes (treat as unsigned case from above)
+ templbl = newiTempLabel ( NULL );
+ offs = size;
+ while (offs--) {
+ //DEBUGpc ("comparing bytes at offset %d", offs);
+ pic16_emitpcode (POC_BNZ, pic16_popGetLabel (templbl->key));
+ mov2w_regOrLit (AOP(right), lit, offs);
+ pic16_emitpcode (POC_SUBFW, pic16_popGet (AOP(left), offs));
+ } // while (offs)
+ pic16_emitpLabel (templbl->key);
+ goto result_in_carry;
+
+result_in_carry:
+
+ /****************************************************
+ * now CARRY contains the result of the comparison: *
+ * SUBWF sets CARRY iff *
+ * F-W >= 0 <==> F >= W <==> !(F < W) *
+ * (F=left, W=right)
+ ****************************************************/
+
+ if (performedLt) {
+ if (result && AOP_TYPE(result) != AOP_CRY) {
+ // value will be stored
+ emitTOGC;
+ } else {
+ // value wil only be used in the following genSkipc()
+ rIfx.condition ^= 1;
+ }
+ } // if
+
+correct_result_in_carry:
+
+ // assign result to variable (if neccessary)
+ if (result && AOP_TYPE(result) != AOP_CRY) {
+ //DEBUGpc ("assign result");
+ size = AOP_SIZE(result);
+ while (size--) {
+ pic16_emitpcode (POC_CLRF, pic16_popGet (AOP(result), size));
+ } // while
+ pic16_emitpcode (POC_RLCF, pic16_popGet (AOP(result), 0));
+ } // if (result)
+
+ // perform conditional jump
+ // genSkipc branches to rifx->label if (rifx->condition != CARRY)
+ if (ifx) {
+ //DEBUGpc ("generate control flow");
+ rIfx.condition ^= 1;
+ genSkipc (&rIfx);
+ ifx->generated = 1;
+ } // if
+}
+
+#elif 1
+ /* { */
+ /* original code */
static void genCmp (operand *left,operand *right,
operand *result, iCode *ifx, int sign)
{
}
*/
+ FENTRY;
+
resolveIfx(&rFalseIfx,ifx);
truelbl = newiTempLabel(NULL);
size = max(AOP_SIZE(left),AOP_SIZE(right));
/* if left & right are bit variables */
if (AOP_TYPE(left) == AOP_CRY &&
AOP_TYPE(right) == AOP_CRY ) {
+ assert (0 && "bit variables used in genCmp");
pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
} else {
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
pic16_emitpcode(POC_ADDLW, pic16_popGetLit( 0x80));
pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x100-i));
- rFalseIfx.condition ^= 1;
- genSkipc(&rFalseIfx);
-
-
- if(ifx) ifx->generated = 1;
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result))) {
+ emitTOGC;
+ if(ifx) ifx->generated = 1;
goto check_carry;
+ } else {
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
+ if(ifx) ifx->generated = 1;
+ }
return;
}
}
-
pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lp1 >> (size*8)) & 0xff));
pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
}
-#else /* old version of genCmp() */
+#else /* old version of genCmp() */ /* } else { */
+
+/* check all condition and return appropriate instruction, POC_CPFSGT or POC_CPFFSLT */
+static int selectCompareOp(resolvedIfx *rIfx, iCode *ifx,
+ operand *result, int offset, int invert_op)
+{
+ /* add code here */
+
+ /* check condition, > or < ?? */
+ if(rIfx->condition != 0)invert_op ^= 1;
+
+ if(ifx && IC_FALSE(ifx))invert_op ^= 1;
+
+ if(!ifx)invert_op ^= 1;
+
+ DEBUGpic16_emitcode("; +++", "%s:%d %s] rIfx->condition= %d, ifx&&IC_FALSE(ifx)= %d, invert_op = %d",
+ __FILE__, __LINE__, __FUNCTION__, rIfx->condition, (ifx && IC_FALSE(ifx)), invert_op);
+
+ /* do selection */
+ if(!invert_op)return POC_CPFSGT;
+ else return POC_CPFSLT;
+}
+
+static int compareAopfirstpass=1;
+
+static void compareAop(resolvedIfx *resIfx, iCode *ifx, symbol *falselbl,
+ operand *oper, int offset, operand *result,
+ int sign, int invert_op, pCodeOp *pcop, pCodeOp *pcop2,
+ symbol *tlbl)
+{
+ int op;
+ symbol *truelbl;
+
+ /* invert if there is a result to be loaded, in order to fit,
+ * SETC/CLRC sequence */
+ if(AOP_SIZE(result))invert_op ^= 1;
+
+// if(sign && !offset)invert_op ^= 1;
+
+// if(sign)invert_op ^= 1;
+
+ op = selectCompareOp(resIfx, ifx, result, offset, invert_op);
+
+ if(AOP_SIZE(result) && compareAopfirstpass) {
+ if(!ifx) {
+ if(pcop2)
+ pic16_emitpcode(POC_SETF, pcop2);
+ else
+ emitSETC;
+ } else {
+ if(pcop2)
+ pic16_emitpcode(POC_CLRF, pcop2);
+ else
+ emitCLRC;
+ }
+ }
+
+ compareAopfirstpass = 0;
+
+ /* there is a bug when comparing operands with size > 1,
+ * because higher bytes can be equal and test should be performed
+ * to the next lower byte, current algorithm, considers operands
+ * inequal in these cases! -- VR 20041107 */
+
+
+ if(pcop)
+ pic16_emitpcode(op, pcop);
+ else
+ pic16_emitpcode(op, pic16_popGet(AOP(oper), offset));
+
+
+ if((!sign || !offset) && AOP_SIZE(result)) {
+ if(!ifx) {
+ if(pcop2)
+ pic16_emitpcode(POC_CLRF, pcop2);
+ else
+ emitCLRC;
+ } else {
+ if(pcop2)
+ pic16_emitpcode(POC_SETF, pcop2);
+ else
+ emitSETC;
+ }
+
+ /* don't emit final branch (offset == 0) */
+ if(offset) {
+
+ if(pcop2)
+ pic16_emitpcode(POC_RRCF, pcop2);
+
+ pic16_emitpcode(POC_BNC, pic16_popGetLabel(falselbl->key));
+ }
+ } else {
+ if((ifx && (IC_TRUE(ifx)!=NULL)) || (sign && !offset)) {
+ DEBUGpic16_emitcode ("; +++","%s: %d: ifx = %p, IC_TRUE(ifx) = %d, sign = %d, offset = %d",
+ __FUNCTION__, __LINE__, ifx, (ifx&&IC_TRUE(ifx)), sign, offset);
+
+ truelbl = newiTempLabel( NULL );
+ pic16_emitpcode(POC_BRA, pic16_popGetLabel(truelbl->key));
+ if((!ifx || !IC_TRUE(ifx)) && (sign && !offset))
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(tlbl->key));
+ else
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(resIfx->lbl->key));
+ pic16_emitpLabel(truelbl->key);
+ } else {
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(resIfx->lbl->key));
+ }
+ }
+}
+
+
+
+
+#if 1 /* { */
+static void genCmp (operand *left, operand *right,
+ operand *result, iCode *ifx, int sign)
+{
+ int size, cmpop=1;
+ long lit = 0L;
+ resolvedIfx rFalseIfx;
+ symbol *falselbl, *tlbl;
+
+ FENTRY;
+
+ DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
+
+ resolveIfx(&rFalseIfx, ifx);
+ size = max(AOP_SIZE(left), AOP_SIZE(right));
+
+ /* if left & right are bit variables */
+ if(AOP_TYPE(left) == AOP_CRY
+ && AOP_TYPE(right) == AOP_CRY ) {
+
+ pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
+ pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
+
+ werror(W_POSSBUG2, __FILE__, __LINE__);
+ exit(-1);
+ }
+
+ /* if literal is on the right then swap with left */
+ if((AOP_TYPE(right) == AOP_LIT)) {
+ operand *tmp = right ;
+// unsigned long mask = (0x100 << (8*(size-1))) - 1;
+
+ lit = /*(unsigned long)*/floatFromVal(AOP(right)->aopu.aop_lit);
+
+// lit = (lit - 1) & mask;
+ right = left;
+ left = tmp;
+ rFalseIfx.condition ^= 1; /* reverse compare */
+ } else
+ if ((AOP_TYPE(left) == AOP_LIT)) {
+ /* float compares are handled by support functions */
+ lit = /*(unsigned long)*/floatFromVal(AOP(left)->aopu.aop_lit);
+ }
+
+ /* actual comparing algorithm */
+// size = AOP_SIZE( right );
+
+ falselbl = newiTempLabel( NULL );
+ if(AOP_TYPE(left) == AOP_LIT) {
+ /* compare to literal */
+ DEBUGpic16_emitcode ("; ***","%s: %d: compare to literal", __FUNCTION__, __LINE__);
+
+ if(sign) {
+ pCodeOp *pct, *pct2;
+ symbol *tlbl1;
+
+ /* signed compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: signed compare", __FUNCTION__, __LINE__);
+
+ pct = pic16_popCopyReg(&pic16_pc_prodl);
+ pct2 = pic16_popCopyReg(&pic16_pc_prodh);
+ tlbl = newiTempLabel( NULL );
+
+ /* first compare signs:
+ * a. if both are positive, compare just like unsigned
+ * b. if both are negative, invert cmpop, compare just like unsigned
+ * c. if different signs, determine the result directly */
+
+ size--;
+
+#if 1
+ /* { */
+ tlbl1 = newiTempLabel( NULL );
+// pic16_emitpcode(POC_RLCFW, pic16_popGet( AOP(right), size)); /* move sign to carry */
+
+ if(lit > 0) {
+
+ /* literal is zero or positive:
+ * a. if carry is zero, too, continue compare,
+ * b. if carry is set, then continue depending on cmpop ^ condition:
+ * 1. '<' return false (literal < variable),
+ * 2. '>' return true (literal > variable) */
+// pic16_emitpcode(POC_BNC, pic16_popGetLabel( tlbl1->key ));
+ pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
+
+
+ if(cmpop ^ rFalseIfx.condition)pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
+ else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key ));
+ } else
+ if(lit < 0) {
+
+ /* literal is negative:
+ * a. if carry is set, too, continue compare,
+ * b. if carry is zero, then continue depending on cmpop ^ condition:
+ * 1. '<' return true (literal < variable),
+ * 2. '>' return false (literal > variable) */
+// pic16_emitpcode(POC_BC, pic16_popGetLabel( tlbl1->key ));
+ pic16_emitpcode(POC_BTFSS, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
+
+ if(!(cmpop ^ rFalseIfx.condition))pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
+ else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key));
+ }
+#if 1
+ else {
+ /* lit == 0 */
+ pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
+
+ if(!(cmpop ^ rFalseIfx.condition))pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
+ else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key));
+ }
+#endif
+
+
+ pic16_emitpLabel( tlbl1->key );
+#endif /* } */
+
+ compareAopfirstpass=1;
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
+// pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_MOVWF, pct);
+
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x80));
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size)));
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, pct2, tlbl);
+
+ /* generic case */
+ while( size-- ) {
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x0));
+// pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_MOVWF, pct);
+
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x80));
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x0));
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, pct2, tlbl);
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 0, pct, pct2, tlbl);
+ }
+// }
+
+ if(ifx)ifx->generated = 1;
+
+ if(AOP_SIZE(result)) {
+ pic16_emitpLabel(tlbl->key);
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitOp( result, pct2 );
+ } else {
+ pic16_emitpLabel(tlbl->key);
+ }
+ } else {
+
+
+ /* unsigned compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: unsigned compare", __FUNCTION__, __LINE__);
+
+ compareAopfirstpass=1;
+ while(size--) {
+
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size)));
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, NULL, NULL);
+
+ }
+
+ if(ifx)ifx->generated = 1;
+
+
+ if(AOP_SIZE(result)) {
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitC( result );
+ }
+
+ }
+ } else {
+ /* compare registers */
+ DEBUGpic16_emitcode ("; ***","%s: %d: compare registers", __FUNCTION__, __LINE__);
+
+
+ if(sign) {
+ pCodeOp *pct, *pct2;
+
+ /* signed compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: signed compare", __FUNCTION__, __LINE__);
+
+ pct = pic16_popCopyReg(&pic16_pc_prodl); /* first temporary register */
+ pct2 = pic16_popCopyReg(&pic16_pc_prodh); /* second temporary register */
+ tlbl = newiTempLabel( NULL );
+
+ compareAopfirstpass=1;
+
+ size--;
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+ pic16_emitpcode(POC_MOVWF, pct);
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+
+ /* WREG already holds left + 0x80 */
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+
+ while( size-- ) {
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+ pic16_emitpcode(POC_MOVWF, pct);
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+
+ /* WREG already holds left + 0x80 */
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 0, pct, pct2, tlbl);
+ }
+
+ if(ifx)ifx->generated = 1;
+
+ if(AOP_SIZE(result)) {
+ pic16_emitpLabel(tlbl->key);
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitOp( result, pct2 );
+ } else {
+ pic16_emitpLabel(tlbl->key);
+ }
+
+ } else {
+ /* unsigned compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: unsigned compare", __FUNCTION__, __LINE__);
+
+ compareAopfirstpass=1;
+ while(size--) {
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, NULL, NULL);
+
+ }
+
+ if(ifx)ifx->generated = 1;
+ if(AOP_SIZE(result)) {
+
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitC( result );
+ }
+
+ }
+ }
+}
+
+#else /* } else { */
/* new version of genCmp -- VR 20041012 */
static void genCmp (operand *left,operand *right,
int willCheckCarry=0;
// resolvedIfx rTrueIfx;
symbol *truelbl;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
+ FENTRY;
+
/* General concept:
* subtract right from left if at the end the carry flag is set then we
* know that left is greater than right */
// lit = (lit - 1) & mask;
right = left;
left = tmp;
- rFalseIfx.condition ^= 1;
+ rFalseIfx.condition ^= 1; /* reverse compare */
} else
if ((AOP_TYPE(left) == AOP_LIT)) {
/* float compares are handled by support functions */
/* if left & right are bit variables */
if (AOP_TYPE(left) == AOP_CRY &&
AOP_TYPE(right) == AOP_CRY ) {
+
pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
else willCheckCarry = 0;
/* Special cases */
- if((lit == 0) && (sign == 0)){
-
+ if((lit == 0) && (sign == 0)) {
+ /* unsigned compare to 0 */
+ DEBUGpic16_emitcode("; unsigned compare to 0","lit = 0x%x, sign=%d",lit,sign);
+
size--;
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
while(size)
pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),--size));
genSkipz2(&rFalseIfx,0);
- if(ifx) ifx->generated = 1;
+ if(ifx)ifx->generated = 1;
return;
}
if(sign) {
/* signed comparisons to a literal byte */
+ DEBUGpic16_emitcode(";signed compare to literal","%d: lit = 0x%x, sign=%d",__LINE__, lit,sign);
int lp1 = (lit+1) & 0xff;
- DEBUGpic16_emitcode(";left lit","line = %d lit = 0x%x condition = %d",__LINE__,lit, rFalseIfx.condition);
+ DEBUGpic16_emitcode(";left lit","line = %d lit = 0x%x condition = %d lp1 = %i",__LINE__,lit, rFalseIfx.condition, lp1);
switch (lp1) {
case 0:
rFalseIfx.condition ^= 1;
}
} else {
/* unsigned comparisons to a literal byte */
+ DEBUGpic16_emitcode("; unsigned compare to literal","%d: lit = 0x%x, sign=%d",__LINE__, lit,sign);
switch(lit & 0xff ) {
+ /* special cases */
case 0:
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
genSkipz2(&rFalseIfx,0);
rFalseIfx.condition ^= 1;
genSkipCond(&rFalseIfx,right,0,7);
break;
-
default:
pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lit+1) & 0xff));
pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),0));
}
}
-#endif
+#endif /* } */
+
+
+#endif /* } */
/*-----------------------------------------------------------------*/
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 ;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
left = IC_LEFT(ic);
right= IC_RIGHT(ic);
result = IC_RESULT(ic);
/*-----------------------------------------------------------------*/
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 ;
+
+ FENTRY;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
left = IC_LEFT(ic);
right= IC_RIGHT(ic);
result = IC_RESULT(ic);
/*-----------------------------------------------------------------*/
static bool is_LitOp(operand *op)
{
- return (AOP_TYPE(op) == AOP_LIT)
+ return ((AOP_TYPE(op) == AOP_LIT)
|| ( (AOP_TYPE(op) == AOP_PCODE)
&& ( (AOP(op)->aopu.pcop->type == PO_LITERAL)
- || (AOP(op)->aopu.pcop->type == PO_IMMEDIATE) ));
+ || (AOP(op)->aopu.pcop->type == PO_IMMEDIATE) )));
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static bool is_LitAOp(asmop *aop)
{
- return (aop->type == AOP_LIT)
+ return ((aop->type == AOP_LIT)
|| ( (aop->type == AOP_PCODE)
&& ( (aop->aopu.pcop->type == PO_LITERAL)
- || (aop->aopu.pcop->type == PO_IMMEDIATE) ));
+ || (aop->aopu.pcop->type == PO_IMMEDIATE) )));
}
int generate_result = 0;
int i=0;
+ FENTRY;
+
pic16_aopOp((left=IC_LEFT(ic)),ic,FALSE);
pic16_aopOp((right=IC_RIGHT(ic)),ic,FALSE);
pic16_aopOp((result=IC_RESULT(ic)),ic,TRUE);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
if( (AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(left) == AOP_CRY) )
{
+ werror(W_POSSBUG2, __FILE__, __LINE__);
DEBUGpic16_emitcode ("; ***","%s %d -- ERROR",__FUNCTION__,__LINE__);
fprintf(stderr, "%s %d error - left/right CRY operands not supported\n",__FUNCTION__,__LINE__);
goto release;
/*-----------------------------------------------------------------*/
static iCode *ifxForOp ( operand *op, iCode *ic )
{
+ FENTRY2;
+
/* if true symbol then needs to be assigned */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if (IS_TRUE_SYMOP(op))
return NULL ;
return ic->next;
}
+ /*
if (ic->next &&
ic->next->op == IFX &&
IC_COND(ic->next)->key == op->key) {
DEBUGpic16_emitcode ("; WARNING ","%d IGNORING liveTo range in %s",__LINE__,__FUNCTION__);
return ic->next;
}
+ */
DEBUGpic16_emitcode ("; NULL :(","%d",__LINE__);
if (ic->next &&
/*-----------------------------------------------------------------*/
static void genAndOp (iCode *ic)
{
- operand *left,*right, *result;
+ operand *left,*right, *result;
/* symbol *tlbl; */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
/* note here that && operations that are in an
if statement are taken away by backPatchLabels
only those used in arthmetic operations remain */
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
+ FENTRY;
+
+ /* note here that || operations that are in an
if statement are taken away by backPatchLabels
only those used in arthmetic operations remain */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
pic16_aopOp((left=IC_LEFT(ic)),ic,FALSE);
pic16_aopOp((right=IC_RIGHT(ic)),ic,FALSE);
pic16_aopOp((result=IC_RESULT(ic)),ic,FALSE);
/*-----------------------------------------------------------------*/
static void continueIfTrue (iCode *ic)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(IC_TRUE(ic))
- pic16_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
- ic->generated = 1;
+ FENTRY;
+ if(IC_TRUE(ic))
+ pic16_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void jumpIfTrue (iCode *ic)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!IC_TRUE(ic))
- pic16_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
- ic->generated = 1;
+ FENTRY;
+ if(!IC_TRUE(ic))
+ pic16_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
{
- // ugly but optimized by peephole
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(IC_TRUE(ic)){
- symbol *nlbl = newiTempLabel(NULL);
- pic16_emitcode("sjmp","%05d_DS_",nlbl->key+100);
- pic16_emitcode("","%05d_DS_:",tlbl->key+100);
- pic16_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
- pic16_emitcode("","%05d_DS_:",nlbl->key+100);
- }
- else{
- pic16_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
- pic16_emitcode("","%05d_DS_:",tlbl->key+100);
- }
- ic->generated = 1;
+ // ugly but optimized by peephole
+ FENTRY;
+ if(IC_TRUE(ic)){
+ symbol *nlbl = newiTempLabel(NULL);
+ pic16_emitcode("sjmp","%05d_DS_",nlbl->key+100);
+ pic16_emitcode("","%05d_DS_:",tlbl->key+100);
+ pic16_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
+ pic16_emitcode("","%05d_DS_:",nlbl->key+100);
+ } else {
+ pic16_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
+ pic16_emitcode("","%05d_DS_:",tlbl->key+100);
+ }
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
int bytelit = 0;
resolvedIfx rIfx;
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
pic16_aopOp((left = IC_LEFT(ic)),ic,FALSE);
pic16_aopOp((right= IC_RIGHT(ic)),ic,FALSE);
pic16_aopOp((result=IC_RESULT(ic)),ic,TRUE);
else {
if(ifx) {
pic16_emitpcode(POC_BRA, pic16_popGetLabel(rIfx.lbl->key));
- pic16_emitpLabel(tlbl->key);
ifx->generated = 1;
}
+ pic16_emitpLabel(tlbl->key);
goto release;
}
}
default:
{
- int p = my_powof2( (~lit) & 0xff );
+ int p = pic16_my_powof2( (~lit) & 0xff );
if(p>=0) {
/* only one bit is set in the literal, so use a bcf instruction */
// pic16_emitcode("bcf","%s,%d",pic16_aopGet(AOP(left),offset,FALSE,TRUE),p);
/* or'ing with 0 has no effect */
continue;
else {
- int p = my_powof2(lit & 0xff);
+ int p = pic16_my_powof2(lit & 0xff);
if(p>=0) {
/* only one bit is set in the literal, so use a bsf instruction */
pic16_emitpcode(POC_BSF,
/*-----------------------------------------------------------------*/
/* genLeftShiftLiteral - left shifting by known count */
/*-----------------------------------------------------------------*/
-static void genLeftShiftLiteral (operand *left,
+void pic16_genLeftShiftLiteral (operand *left,
operand *right,
operand *result,
iCode *ic)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
+ int shCount = (int) abs(floatFromVal (AOP(right)->aopu.aop_lit));
int size;
- DEBUGpic16_emitcode ("; ***","%s %d shCount:%d",__FUNCTION__,__LINE__,shCount);
+ FENTRY;
+ DEBUGpic16_emitcode ("; ***","shCount:%d", shCount);
pic16_freeAsmop(right,NULL,ic,TRUE);
pic16_aopOp(left,ic,FALSE);
}
}
+
+#if !(USE_GENERIC_SIGNED_SHIFT)
/*-----------------------------------------------------------------*/
/* genLeftShift - generates code for left shifting */
/*-----------------------------------------------------------------*/
/* if the shift count is known then do it
as efficiently as possible */
if (AOP_TYPE(right) == AOP_LIT) {
- genLeftShiftLiteral (left,right,result,ic);
+ pic16_genLeftShiftLiteral (left,right,result,ic);
return ;
}
pic16_freeAsmop(left,NULL,ic,TRUE);
pic16_freeAsmop(result,NULL,ic,TRUE);
}
-
+#endif
#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);
+ pic16_genLeftShiftLiteral (left,right,result,ic);
return ;
}
iCode *ic,
int sign)
{
- int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
+ int shCount = (int) abs(floatFromVal (AOP(right)->aopu.aop_lit));
int lsize,res_size;
pic16_freeAsmop(right,NULL,ic,TRUE);
pic16_freeAsmop(result,NULL,ic,TRUE);
}
+#if !(USE_GENERIC_SIGNED_SHIFT)
/*-----------------------------------------------------------------*/
/* genSignedRightShift - right shift of signed number */
/*-----------------------------------------------------------------*/
pic16_freeAsmop(result,NULL,ic,TRUE);
pic16_freeAsmop(right,NULL,ic,TRUE);
}
+#endif
+#if !(USE_GENERIC_SIGNED_SHIFT)
+#warning This implementation of genRightShift() is incomplete!
/*-----------------------------------------------------------------*/
/* genRightShift - generate code for right shifting */
/*-----------------------------------------------------------------*/
pic16_freeAsmop (right,NULL,ic,TRUE);
pic16_freeAsmop(result,NULL,ic,TRUE);
}
+#endif
+
+#if (USE_GENERIC_SIGNED_SHIFT)
+/*-----------------------------------------------------------------*/
+/* genGenericShift - generates code for left or right shifting */
+/*-----------------------------------------------------------------*/
+static void genGenericShift (iCode *ic, int isShiftLeft) {
+ operand *left,*right, *result;
+ int offset;
+ int sign, signedCount;
+ symbol *label_complete, *label_loop_pos, *label_loop_neg, *label_negative;
+ PIC_OPCODE pos_shift, neg_shift;
+
+ FENTRY;
+
+ right = IC_RIGHT(ic);
+ left = IC_LEFT(ic);
+ result = IC_RESULT(ic);
+
+ pic16_aopOp(right,ic,FALSE);
+ pic16_aopOp(left,ic,FALSE);
+ pic16_aopOp(result,ic,FALSE);
+
+ sign = !SPEC_USIGN(operandType (left));
+ signedCount = !SPEC_USIGN(operandType (right));
+
+ /* if the shift count is known then do it
+ as efficiently as possible */
+ if (AOP_TYPE(right) == AOP_LIT) {
+ long lit = (long)floatFromVal(AOP(right)->aopu.aop_lit);
+ if (signedCount && lit < 0) { lit = -lit; isShiftLeft = !isShiftLeft; }
+ // we should modify right->aopu.aop_lit here!
+ // Instead we use abs(shCount) in genXXXShiftLiteral()...
+ // lit > 8*size is handled in pic16_genXXXShiftLiteral()
+ if (isShiftLeft)
+ pic16_genLeftShiftLiteral (left,right,result,ic);
+ else
+ genRightShiftLiteral (left,right,result,ic, sign);
+
+ goto release;
+ } // if (right is literal)
+
+ /* shift count is unknown then we have to form a loop.
+ * Note: we take only the lower order byte since shifting
+ * more than 32 bits make no sense anyway, ( the
+ * largest size of an object can be only 32 bits )
+ * Note: we perform arithmetic shifts if the left operand is
+ * signed and we do an (effective) right shift, i. e. we
+ * shift in the sign bit from the left. */
+
+ label_complete = newiTempLabel ( NULL );
+ label_loop_pos = newiTempLabel ( NULL );
+ label_loop_neg = NULL;
+ label_negative = NULL;
+ pos_shift = isShiftLeft ? POC_RLCF : POC_RRCF;
+ neg_shift = isShiftLeft ? POC_RRCF : POC_RLCF;
+
+ if (signedCount) {
+ // additional labels needed
+ label_loop_neg = newiTempLabel ( NULL );
+ label_negative = newiTempLabel ( NULL );
+ } // if
+
+ // copy source to result -- this will effectively truncate the left operand to the size of result!
+ // (e.g. char c = 0x100 << -3 will become c = 0x00 >> 3 == 0x00 instad of 0x20)
+ // This is fine, as it only occurs for left shifting with negative count which is not standardized!
+ for (offset=0; offset < min(AOP_SIZE(left), AOP_SIZE(result)); offset++) {
+ mov2f (AOP(result),AOP(left), offset);
+ } // for
+
+ // if result is longer than left, fill with zeros (or sign)
+ if (AOP_SIZE(left) < AOP_SIZE(result)) {
+ if (sign && AOP_SIZE(left) > 0) {
+ // shift signed operand -- fill with sign
+ pic16_emitpcode (POC_CLRF, pic16_popCopyReg (&pic16_pc_wreg));
+ pic16_emitpcode (POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(result), AOP_SIZE(left)-1), 7));
+ pic16_emitpcode (POC_MOVLW, pic16_popGetLit (0xFF));
+ for (offset=AOP_SIZE(left); offset < AOP_SIZE(result); offset++) {
+ pic16_emitpcode (POC_MOVWF, pic16_popGet (AOP(result), offset));
+ } // for
+ } else {
+ // shift unsigned operand -- fill result with zeros
+ for (offset=AOP_SIZE(left); offset < AOP_SIZE(result); offset++) {
+ pic16_emitpcode (POC_CLRF, pic16_popGet (AOP(result), offset));
+ } // for
+ }
+ } // if (size mismatch)
+
+ pic16_mov2w (AOP(right), 0);
+ pic16_emitpcode (POC_BZ, pic16_popGetLabel (label_complete->key));
+ if (signedCount) pic16_emitpcode (POC_BN, pic16_popGetLabel (label_negative->key));
+
+#if 0
+ // perform a shift by one (shift count is positive)
+ // cycles used for shifting {unsigned,signed} values on n bytes by [unsigned,signed] shift count c>0:
+ // 2n+[2,3]+({1,3}+n+3)c-2+[0,2]=({4,6}+n)c+2n+[0,3] ({5,7}c+[2,5] / {6,8}c+[4, 7] / {8,10}c+[ 8,11])
+ pic16_emitpLabel (label_loop_pos->key);
+ emitCLRC;
+ if (sign && (pos_shift == POC_RRCF)) {
+ pic16_emitpcode (POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(result), AOP_SIZE(result)-1), 7));
+ emitSETC;
+ } // if
+ genMultiAsm (pos_shift, result, AOP_SIZE(result), pos_shift == POC_RRCF);
+ pic16_emitpcode (POC_DECFSZ, pic16_popCopyReg (&pic16_pc_wreg));
+ pic16_emitpcode (POC_BRA, pic16_popGetLabel (label_loop_pos->key));
+#else
+ // perform a shift by one (shift count is positive)
+ // cycles used for shifting {unsigned,signed} values on n bytes by [unsigned,signed] shift count c>0:
+ // 2n+[2,3]+2+({0,2}+n+3)c-1+[0,2]=({3,5}+n)c+2n+[3,6] ({4,6}c+[5,8] / {5,7}c+[7,10] / {7, 9}c+[11,14])
+ // This variant is slower for 0<c<3, equally fast for c==3, and faster for 3<c.
+ pic16_emitpcode (POC_NEGF, pic16_popCopyReg (&pic16_pc_wreg));
+ emitCLRC;
+ pic16_emitpLabel (label_loop_pos->key);
+ if (sign && (pos_shift == POC_RRCF)) {
+ pic16_emitpcode (POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(result), AOP_SIZE(result)-1), 7));
+ emitSETC;
+ } // if
+ genMultiAsm (pos_shift, result, AOP_SIZE(result), pos_shift == POC_RRCF);
+ //pic16_emitpcode (POC_INCF, pic16_popCopyReg (&pic16_pc_wreg)); // gpsim does not like this...
+ pic16_emitpcode (POC_ADDLW, pic16_popGetLit (0x01));
+ pic16_emitpcode (POC_BNC, pic16_popGetLabel (label_loop_pos->key));
+#endif
+
+ if (signedCount) {
+ pic16_emitpcode (POC_BRA, pic16_popGetLabel (label_complete->key));
+
+ pic16_emitpLabel (label_negative->key);
+ // perform a shift by -1 (shift count is negative)
+ // 2n+4+1+({0,2}+n+3)*c-1=({3,5}+n)c+2n+4 ({4,6}c+6 / {5,7}c+8 / {7,9}c+12)
+ emitCLRC;
+ pic16_emitpLabel (label_loop_neg->key);
+ if (sign && (neg_shift == POC_RRCF)) {
+ pic16_emitpcode (POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(result), AOP_SIZE(result)-1), 7));
+ emitSETC;
+ } // if
+ genMultiAsm (neg_shift, result, AOP_SIZE(result), neg_shift == POC_RRCF);
+ //pic16_emitpcode (POC_INCF, pic16_popCopyReg (&pic16_pc_wreg)); // gpsim does not like this...
+ pic16_emitpcode (POC_ADDLW, pic16_popGetLit (0x01));
+ pic16_emitpcode (POC_BNC, pic16_popGetLabel (label_loop_neg->key));
+ } // if (signedCount)
+
+ pic16_emitpLabel (label_complete->key);
+
+release:
+ pic16_freeAsmop (right,NULL,ic,TRUE);
+ pic16_freeAsmop(left,NULL,ic,TRUE);
+ pic16_freeAsmop(result,NULL,ic,TRUE);
+}
+
+static void genLeftShift (iCode *ic) {
+ genGenericShift (ic, 1);
+}
+
+static void genRightShift (iCode *ic) {
+ genGenericShift (ic, 0);
+}
+#endif
void pic16_loadFSR0(operand *op)
/*-----------------------------------------------------------------*/
static void genUnpackBits (operand *result, operand *left, char *rname, int ptype)
{
- int shCnt ;
- int rlen = 0 ;
- sym_link *etype;
- int offset = 0 ;
+ int shCnt ;
+ int rlen = 0 ;
+ sym_link *etype, *letype;
+ int blen=0, bstr=0;
+ int lbstr;
+ int offset = 0 ;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- etype = getSpec(operandType(result));
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ etype = getSpec(operandType(result));
+ letype = getSpec(operandType(left));
+
+// if(IS_BITFIELD(etype)) {
+ blen = SPEC_BLEN(etype);
+ bstr = SPEC_BSTR(etype);
+// }
+
+ lbstr = SPEC_BSTR( letype );
+
+#if 1
+ if((blen == 1) && (bstr < 8)) {
+ /* it is a single bit, so use the appropriate bit instructions */
+ DEBUGpic16_emitcode (";","%s %d optimize bit read",__FUNCTION__,__LINE__);
+
+ pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
+
+ if((ptype == POINTER) && (result)) {
+ /* workaround to reduce the extra lfsr instruction */
+ pic16_emitpcode(POC_BTFSC,
+ pic16_popCopyGPR2Bit(pic16_popGet(AOP(left), 0), bstr));
+ } else {
+ pic16_emitpcode(POC_BTFSC,
+ pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_indf0), bstr));
+ }
+
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_wreg));
+
+ pic16_emitpcode(POC_MOVWF, pic16_popGet( AOP(result), 0 ));
+ return;
+ }
+
+#endif
/* the following call to pic16_loadFSR0 is temporary until
* optimization to handle single bit assignments is added
if(AOP(result)->aopu.pcop->type == PO_IMMEDIATE
|| AOP(left)->aopu.pcop->type == PO_IMMEDIATE) {
- mov2w(AOP(left), offset); // patch 8
+ pic16_mov2w(AOP(left), offset); // patch 8
pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), offset));
} else {
pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
operand *result,
iCode *ic)
{
- asmop *aop = NULL;
- //regs *preg = NULL ;
- sym_link *rtype, *retype;
- sym_link *ltype = operandType(left);
+ asmop *aop = NULL;
+ //regs *preg = NULL ;
+ sym_link *rtype, *retype;
+ sym_link *ltype = operandType(left);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- rtype = operandType(result);
- retype= getSpec(rtype);
+ FENTRY;
- pic16_aopOp(left,ic,FALSE);
-
-// pic16_DumpOp("(left)",left);
-// pic16_DumpOp("(result)",result);
+ rtype = operandType(result);
+ retype= getSpec(rtype);
+
+ pic16_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_PCODE
- && !IS_BITFIELD(retype)
- && DCL_TYPE(ltype) == POINTER) {
+// pic16_DumpOp("(left)",left);
+// pic16_DumpOp("(result)",result);
- genDataPointerGet (left,result,ic);
- pic16_freeAsmop(left, NULL, ic, TRUE);
- 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 */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if (AOP_TYPE(left) == AOP_PCODE
+ && !IS_BITFIELD(retype)
+ && DCL_TYPE(ltype) == POINTER) {
- /* 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 */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- /* VR -- the whole concept is to load FSR0 with the address of the symbol */
- if( (AOP_TYPE(left) == AOP_PCODE)
- && ((AOP(left)->aopu.pcop->type == PO_IMMEDIATE)
- || (AOP(left)->aopu.pcop->type == PO_DIR))) // patch 10
- {
- if(!IS_BITFIELD(retype))
- pic16_loadFSR0( left ); // patch 10
- } else {
- // set up FSR0 with address from left
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10
- }
- }
-// else
-// rname = pic16_aopGet(AOP(left),0,FALSE,FALSE);
+ genDataPointerGet (left,result,ic);
+ pic16_freeAsmop(left, NULL, ic, TRUE);
+ return ;
+ }
- pic16_aopOp (result,ic,FALSE);
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ pic16_aopOp (result,ic,FALSE);
- /* if bitfield then unpack the bits */
+ DEBUGpic16_pic16_AopType(__LINE__, left, NULL, result);
+
+#if 1
+ if(IS_BITFIELD( retype )
+ && (SPEC_BLEN(operandType(result))==1)
+ ) {
+ iCode *nextic;
+ pCodeOp *jop;
+ int bitstrt, bytestrt;
+
+ /* if this is bitfield of size 1, see if we are checking the value
+ * of a single bit in an if-statement,
+ * if yes, then don't generate usual code, but execute the
+ * genIfx directly -- VR */
+
+ nextic = ic->next;
+
+ /* CHECK: if next iCode is IFX
+ * and current result operand is nextic's conditional operand
+ * and current result operand live ranges ends at nextic's key number
+ */
+ if((nextic->op == IFX)
+ && (result == IC_COND(nextic))
+ && (OP_LIVETO(result) == nextic->seq)
+ ) {
+ /* everything is ok then */
+ /* find a way to optimize the genIfx iCode */
+
+ bytestrt = SPEC_BSTR(operandType(result))/8;
+ bitstrt = SPEC_BSTR(operandType(result))%8;
+
+ jop = pic16_popCopyGPR2Bit(pic16_popGet(AOP(left), 0), bitstrt);
+
+ genIfxpCOpJump(nextic, jop);
+
+ pic16_freeAsmop(left, NULL, ic, TRUE);
+ pic16_freeAsmop(result, NULL, ic, TRUE);
+ return;
+ }
+ }
+#endif
+
+
+ /* if the value is already in a pointer register
+ * then don't need anything more */
+ if (1 || !AOP_INPREG(AOP(left))) { // AOP_INPREG(AOP(left)) is not always correct...
+ /* otherwise get a free pointer register */
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ /* VR -- the whole concept is to load FSR0 with the address of the symbol */
+ /* bitfields will be handled by genUnpackBits */
+ if(!IS_BITFIELD(retype)) {
+
+ if(is_LitAOp( AOP(left) )) {
+ pic16_loadFSR0( left );
+ } else {
+ // set up FSR0 with address from left
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10
+ }
+ }
+ }
+
+ /* if bitfield then unpack the bits */
if (IS_BITFIELD(retype))
- genUnpackBits (result, left, NULL, POINTER);
+ genUnpackBits (result, left, NULL, POINTER);
else {
- /* we have can just get the values */
+ /* we have can just get the values */
int size = AOP_SIZE(result);
int offset = 0;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- /* fsr0 is loaded already -- VR */
-// pic16_loadFSR0( left );
+ /* fsr0 is loaded already -- VR */
+// pic16_loadFSR0( left );
// pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),0));
// pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_fsr0));
while(size--) {
-
- if(size) {
- pic16_emitpcode(POC_MOVFF,
- pic16_popGet2p(pic16_popCopyReg(&pic16_pc_postinc0),
- pic16_popGet(AOP(result), offset++)));
- } else {
- pic16_emitpcode(POC_MOVFF,
- pic16_popGet2p(pic16_popCopyReg(&pic16_pc_indf0),
- pic16_popGet(AOP(result), offset++)));
- }
+ if(size) {
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_postinc0),
+ pic16_popGet(AOP(result), offset++)));
+ } else {
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_indf0),
+ pic16_popGet(AOP(result), offset++)));
+ }
}
#if 0
-// pic16_emitpcode(POC_MOVFW,pic16_popCopyReg(&pic16_pc_postinc0));
-// pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),offset++));
- if(size)
- pic16_emitpcode(POC_INCF,pic16_popCopyReg(&pic16_pc_fsr0));
+// pic16_emitpcode(POC_MOVFW,pic16_popCopyReg(&pic16_pc_postinc0));
+// pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),offset++));
+ if(size)
+ pic16_emitpcode(POC_INCF,pic16_popCopyReg(&pic16_pc_fsr0));
#endif
/*
while (size--) {
*/
}
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- pic16_freeAsmop(NULL,aop,ic,TRUE);
+ /* now some housekeeping stuff */
+ if (aop) {
+ /* we had to allocate for this iCode */
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ pic16_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 */
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- 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--)
-// pic16_emitcode("dec","%s",rname);
+ /* 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 */
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ 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--)
+// pic16_emitcode("dec","%s",rname);
}
}
/* done */
pic16_freeAsmop(left,NULL,ic,TRUE);
pic16_freeAsmop(result,NULL,ic,TRUE);
-
}
/*-----------------------------------------------------------------*/
pic16_freeAsmop(result,NULL,ic,TRUE);
}
+
#if 0
/*-----------------------------------------------------------------*/
/* genCodePointerGet - get value from code space */
pic16_freeAsmop(result,NULL,ic,TRUE);
}
#endif
+
#if 0
/*-----------------------------------------------------------------*/
/* genGenPointerGet - gget value from generic pointer space */
}
#endif
-extern set *externs;
/*-----------------------------------------------------------------*/
/* genGenPointerGet - gget value from generic pointer space */
DEBUGpic16_pic16_AopType(__LINE__,left,NULL,result);
DEBUGpic16_emitcode ("; "," %d getting const pointer",__LINE__);
-#if 0 // patch 15
- pic16_emitpcode(POC_CALL,pic16_popGetLabel(albl->key));
- pic16_emitpcode(POC_GOTO,pic16_popGetLabel(blbl->key));
- pic16_emitpLabel(albl->key);
-
- poc = ( (AOP_TYPE(left) == AOP_PCODE) ? POC_MOVLW : POC_MOVFW);
-
- /* this performs a goto to the specified address -- Why not to use pointer? -- VR */
- pic16_emitpcode(poc,pic16_popGet(AOP(left),1));
- pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_pclath));
- pic16_emitpcode(poc,pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_pcl));
-
- pic16_emitpLabel(blbl->key);
-
- pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),0));
-#endif // patch 15
-
// set up table pointer
if( (AOP_TYPE(left) == AOP_PCODE)
&& ((AOP(left)->aopu.pcop->type == PO_IMMEDIATE)
- || (AOP(left)->aopu.pcop->type == PO_DIR))) // patch 15 ......
+ || (AOP(left)->aopu.pcop->type == PO_DIR)))
{
pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),0));
pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptrl));
pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptrh));
pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),2));
pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptru));
- }
- else
- {
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_tblptrl)));
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_tblptrh)));
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),2), pic16_popCopyReg(&pic16_pc_tblptru)));
- }
-
+ } else {
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_tblptrl)));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_tblptrh)));
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),2), pic16_popCopyReg(&pic16_pc_tblptru)));
+ }
- while(size--)
- {
- pic16_emitpcodeNULLop(POC_TBLRD_POSTINC);
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_tablat), pic16_popGet(AOP(result),offset)));
- offset++;
- }
+ while(size--) {
+ pic16_emitpcodeNULLop(POC_TBLRD_POSTINC);
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_tablat), pic16_popGet(AOP(result),offset)));
+ offset++;
+ }
pic16_freeAsmop(left,NULL,ic,TRUE);
pic16_freeAsmop(result,NULL,ic,TRUE);
-
}
/*-----------------------------------------------------------------*/
static void genPointerGet (iCode *ic)
{
- operand *left, *result ;
- sym_link *type, *etype;
- int p_type;
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ operand *left, *result ;
+ sym_link *type, *etype;
+ int p_type;
+ FENTRY;
+
left = IC_LEFT(ic);
result = IC_RESULT(ic) ;
/* if left is of type of pointer then it is simple */
if (IS_PTR(type) && !IS_FUNC(type->next))
- p_type = DCL_TYPE(type);
+ p_type = DCL_TYPE(type);
else {
- /* we have to go by the storage class */
- p_type = PTR_TYPE(SPEC_OCLS(etype));
+ /* we have to go by the storage class */
+ p_type = PTR_TYPE(SPEC_OCLS(etype));
- DEBUGpic16_emitcode ("; ***","%d - resolve pointer by storage class",__LINE__);
+ DEBUGpic16_emitcode ("; ***","%d - resolve pointer by storage class",__LINE__);
- if (SPEC_OCLS(etype)->codesp ) {
- DEBUGpic16_emitcode ("; ***","%d - cpointer",__LINE__);
- //p_type = CPOINTER ;
- }
- else
- if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged)
- DEBUGpic16_emitcode ("; ***","%d - fpointer",__LINE__);
- /*p_type = FPOINTER ;*/
- else
- if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged)
- DEBUGpic16_emitcode ("; ***","%d - ppointer",__LINE__);
-/* p_type = PPOINTER; */
- else
- if (SPEC_OCLS(etype) == idata )
- DEBUGpic16_emitcode ("; ***","%d - ipointer",__LINE__);
-/* p_type = IPOINTER; */
- else
- DEBUGpic16_emitcode ("; ***","%d - pointer",__LINE__);
-/* p_type = POINTER ; */
+ if (SPEC_OCLS(etype)->codesp ) {
+ DEBUGpic16_emitcode ("; ***","%d - cpointer",__LINE__);
+ //p_type = CPOINTER ;
+ } else
+ if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) {
+ DEBUGpic16_emitcode ("; ***","%d - fpointer",__LINE__);
+ /*p_type = FPOINTER ;*/
+ } else
+ if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) {
+ DEBUGpic16_emitcode ("; ***","%d - ppointer",__LINE__);
+ /* p_type = PPOINTER; */
+ } else
+ if (SPEC_OCLS(etype) == idata ) {
+ DEBUGpic16_emitcode ("; ***","%d - ipointer",__LINE__);
+ /* p_type = IPOINTER; */
+ } else {
+ DEBUGpic16_emitcode ("; ***","%d - pointer",__LINE__);
+ /* p_type = POINTER ; */
+ }
}
/* now that we have the pointer type we assign
the pointer values */
switch (p_type) {
-
- case POINTER:
- case IPOINTER:
+ case POINTER:
+ case IPOINTER:
genNearPointerGet (left,result,ic);
break;
- case PPOINTER:
+ case PPOINTER:
genPagedPointerGet(left,result,ic);
break;
- case FPOINTER:
+ case FPOINTER:
genFarPointerGet (left,result,ic);
break;
- case CPOINTER:
+ case CPOINTER:
genConstPointerGet (left,result,ic);
//pic16_emitcodePointerGet (left,result,ic);
break;
- case GPOINTER:
+ case GPOINTER:
#if 0
if (IS_PTR_CONST(type))
genConstPointerGet (left,result,ic);
"genPointerGet: illegal pointer type");
}
-
}
/*-----------------------------------------------------------------*/
int offset = 0 ;
int rLen = 0 ;
int blen, bstr ;
+ sym_link *retype;
char *l ;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
blen = SPEC_BLEN(etype);
bstr = SPEC_BSTR(etype);
+ retype = getSpec(operandType(right));
+
if(AOP_TYPE(right) == AOP_LIT) {
if((blen == 1) && (bstr < 8)) {
unsigned long lit;
pic16_popCopyGPR2Bit(pic16_popGet(AOP(result), 0), bstr));
}
} else {
-
+ pic16_loadFSR0( result );
if(lit) {
pic16_emitpcode(POC_BSF,
pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_indf0), bstr));
pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right), 0));
offset++;
} else
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), offset++));
+ if(IS_BITFIELD(retype)
+ && (AOP_TYPE(right) == AOP_REG || AOP_TYPE(right) == AOP_DIR)
+ && (blen == 1)) {
+ int rblen, rbstr;
+
+ rblen = SPEC_BLEN( retype );
+ rbstr = SPEC_BSTR( retype );
+
+
+ if(IS_BITFIELD(etype)) {
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(result), 0));
+ pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_wreg), bstr));
+ } else {
+ pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
+ }
+
+ pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), 0), rbstr));
+
+ if(IS_BITFIELD(etype)) {
+ pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_wreg), bstr));
+ } else {
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_wreg));
+ }
+
+ pic16_emitpcode(POC_MOVWF, pic16_popGet( AOP(result), 0));
+
+ return;
+ } else
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), offset++));
/* if the bit lenth is less than or */
/* it exactly fits a byte then */
if((shCnt=SPEC_BSTR(etype))
|| SPEC_BLEN(etype) <= 8 ) {
+ pic16_emitpcode(POC_ANDLW, pic16_popGetLit((1U << blen)-1));
+
/* shift left acc */
AccLsh(shCnt);
switch (p_type) {
case FPOINTER:
case POINTER:
- case GPOINTER:
+ pic16_loadFSR0( result );
pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_indf0));
// pic16_emitcode ("mov","b,a");
// pic16_emitcode("mov","a,@%s",rname);
break;
+
+ case GPOINTER:
+ werror(W_POSSBUG2, __FILE__, __LINE__);
+ break;
+
}
#if 1
pic16_emitpcode(POC_ANDLW, pic16_popGetLit(
while (size--) {
if (AOP_TYPE(right) == AOP_LIT) {
- unsigned int lit = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit);
-
- lit = lit >> (8*offset);
- if(lit&0xff) {
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit&0xff));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); // pstch 8
- } else {
- pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset)); // patch 8
- }
- } else {
- mov2w(AOP(right), offset);
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); // patch 8
- }
+ unsigned int lit;
+
+ if(!IS_FLOAT(operandType( right )))
+ lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
+ else {
+ union {
+ unsigned long lit_int;
+ float lit_float;
+ } info;
+
+ /* take care if literal is a float */
+ info.lit_float = floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
+ lit = info.lit_int;
+ }
+
+ lit = lit >> (8*offset);
+ if(lit&0xff) {
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit&0xff));
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); // pstch 8
+ } else {
+ pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset)); // patch 8
+ }
+ } else {
+ pic16_mov2w(AOP(right), offset);
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); // patch 8
+ }
offset++;
resoffset++;
}
/* if the value is already in a pointer register
* then don't need anything more */
- if (!AOP_INPREG(AOP(result))) {
+ if (1 || !AOP_INPREG(AOP(result))) { // AOP_INPREG(AOP(result)) is not always correct...
/* otherwise get a free pointer register */
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if( (AOP_TYPE(result) == AOP_PCODE)
- && ((AOP(result)->aopu.pcop->type == PO_IMMEDIATE)
- || (AOP(result)->aopu.pcop->type == PO_DIR))) // patch 10
+// if( (AOP_TYPE(result) == AOP_PCODE)
+// && ((AOP(result)->aopu.pcop->type == PO_IMMEDIATE)
+// || (AOP(result)->aopu.pcop->type == PO_DIR))) // patch 10
+ if(is_LitAOp( AOP(result) ))
{
if(!IS_BITFIELD(resetype))
pic16_loadFSR0( result ); // patch 10
} else {
+ if(!IS_BITFIELD(resetype)) {
// set up FSR0 with address of result
pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10
pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10
+ }
}
}
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+// pic16_loadFSR0( result );
+
/* if bitfield then unpack the bits */
if (IS_BITFIELD(resetype)) {
genPackBits (resetype, result, right, NULL, POINTER);
pic16_emitcode("movf","indf0,w ;1");
} else {
- if (AOP_TYPE(right) == AOP_LIT) { // patch 10
- pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right),offset)); //
- if (size) { //
- pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_postinc0)); //
- } else { //
- pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_indf0)); //
- } //
- } else { // no literal //
- if(size) { //
- pic16_emitpcode(POC_MOVFF, //
- pic16_popGet2p(pic16_popGet(AOP(right),offset), //
- pic16_popCopyReg(&pic16_pc_postinc0))); //
- } else { //
- pic16_emitpcode(POC_MOVFF, //
- pic16_popGet2p(pic16_popGet(AOP(right),offset), //
- pic16_popCopyReg(&pic16_pc_indf0))); //
- } //
- } // patch 10
+ if (AOP_TYPE(right) == AOP_LIT) {
+ pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right),offset));
+ if (size) {
+ pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_postinc0));
+ } else {
+ pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_indf0));
+ }
+ } else { // no literal
+ if(size) {
+ pic16_emitpcode(POC_MOVFF,
+ pic16_popGet2p(pic16_popGet(AOP(right),offset),
+ pic16_popCopyReg(&pic16_pc_postinc0)));
+ } else {
+ pic16_emitpcode(POC_MOVFF,
+ pic16_popGet2p(pic16_popGet(AOP(right),offset),
+ pic16_popCopyReg(&pic16_pc_indf0)));
+ }
+ }
}
offset++;
}
* by the support function this restoring the stack. The important
* thing is that there is no need to manually restore stack pointer
* here */
- mov2fp(pic16_popCopyReg(&pic16_pc_postdec1), AOP(right), 0);
+ pushaop(AOP(right), 0);
+// mov2fp(pic16_popCopyReg(&pic16_pc_postdec1), AOP(right), 0);
if(size>1)mov2fp(pic16_popCopyReg(&pic16_pc_prodh), AOP(right), 1);
if(size>2)mov2fp(pic16_popCopyReg(&pic16_pc_tblptrl), AOP(right), 2);
if(size>3)mov2fp(pic16_popCopyReg(&pic16_pc_tblptrh), AOP(right), 3);
/*-----------------------------------------------------------------*/
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;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
right = IC_RIGHT(ic);
result = IC_RESULT(ic) ;
/* now that we have the pointer type we assign
the pointer values */
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 FPOINTER:
- genFarPointerSet (right,result,ic);
+ case PPOINTER:
+ genPagedPointerSet (right,result,ic);
break;
- case GPOINTER:
- genGenPointerSet (right,result,ic);
- break;
+ case FPOINTER:
+ genFarPointerSet (right,result,ic);
+ break;
+
+ case GPOINTER:
+ genGenPointerSet (right,result,ic);
+ break;
- default:
- werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
- "genPointerSet: illegal pointer type");
+ default:
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "genPointerSet: illegal pointer type");
}
}
operand *cond = IC_COND(ic);
int isbit =0;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
- pic16_aopOp(cond,ic,FALSE);
+ pic16_aopOp(cond,ic,FALSE);
- /* get the value into acc */
- if (AOP_TYPE(cond) != AOP_CRY)
- pic16_toBoolean(cond);
- else
- isbit = 1;
- /* the result is now in the accumulator */
- pic16_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);
- DEBUGpic16_emitcode ("; isbit SPIL_LOC","%s",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)
+ pic16_toBoolean(cond);
else
- genIfxJump(ic,"a");
- }
- ic->generated = 1;
-
+ isbit = 1;
+ /* the result is now in the accumulator */
+ pic16_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,"c");
+ DEBUGpic16_emitcode ("; isbit SPIL_LOC","%s",SPIL_LOC(cond)->rname);
+ } else {
+ if (isbit && !IS_ITEMP(cond))
+ genIfxJump(ic,OP_SYMBOL(cond)->rname);
+ else
+ genIfxJump(ic,"a");
+ }
+ ic->generated = 1;
}
/*-----------------------------------------------------------------*/
symbol *sym; // = OP_SYMBOL(IC_LEFT(ic));
pCodeOp *pcop0, *pcop1, *pcop2;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
pic16_aopOp((result=IC_RESULT(ic)),ic,TRUE);
OP_SYMBOL(left)->name, OP_SYMBOL(left)->stack);
#endif
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
- pic16_popCopyReg(&pic16_pc_fsr2l),
- pic16_popGet(AOP(result), 0)));
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
- pic16_popCopyReg(&pic16_pc_fsr2h),
- pic16_popGet(AOP(result), 1)));
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit( OP_SYMBOL( IC_LEFT(ic))->stack ) /*+ _G.stack_lat*/);
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result), 0));
- emitSKPNC;
- pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result), 1));
+ // operands on stack are accessible via "FSR2 + index" with index
+ // starting at 2 for arguments and growing from 0 downwards for
+ // local variables (index == 0 is not assigned so we add one here)
+ {
+ int soffs = OP_SYMBOL( IC_LEFT(ic))->stack;
+ if (soffs <= 0) {
+ assert (soffs < 0);
+ soffs++;
+ } // if
+ DEBUGpic16_emitcode("*!*", "accessing stack symbol at offset=%d", soffs);
+ pic16_emitpcode(POC_MOVLW , pic16_popGetLit( soffs & 0x00FF ));
+ pic16_emitpcode(POC_ADDFW , pic16_popCopyReg(pic16_framepnt_lo));
+ pic16_emitpcode(POC_MOVWF , pic16_popGet(AOP(result), 0));
+ pic16_emitpcode(POC_MOVLW , pic16_popGetLit( (soffs >> 8) & 0x00FF ));
+ pic16_emitpcode(POC_ADDFWC, pic16_popCopyReg(pic16_framepnt_hi));
+ pic16_emitpcode(POC_MOVWF , pic16_popGet(AOP(result), 1));
+ }
goto release;
}
pic16_aopOp((left=IC_LEFT(ic)), ic, FALSE);
size = AOP_SIZE(IC_RESULT(ic));
-
- /* Assume that what we want the address of is in data space
- * since there is no stack on the PIC, yet! -- VR */
-
pcop0 = PCOP(pic16_newpCodeOpImmd(sym->rname, 0, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
pcop1 = PCOP(pic16_newpCodeOpImmd(sym->rname, 1, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
pcop2 = PCOP(pic16_newpCodeOpImmd(sym->rname, 2, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
result = IC_RESULT(ic);
right = IC_RIGHT(ic) ;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
/* if they are the same */
if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic)))
// fprintf(stderr, "%s:%d: assigning value 0x%04lx (%d:%d)\n", __FUNCTION__, __LINE__, lit,
// sizeof(unsigned long int), sizeof(float));
+
+ if (AOP_TYPE(right) == AOP_REG) {
+ DEBUGpic16_emitcode("; ", "%s:%d assign from register\n", __FUNCTION__, __LINE__);
+ while (size--) {
+
+ pic16_emitpcode (POC_MOVFF, pic16_popGet2(AOP(right), AOP(result), offset++));
+ } // while
+ goto release;
+ }
+
if(AOP_TYPE(right) != AOP_LIT
&& IN_CODESPACE(SPEC_OCLS(OP_SYMBOL(right)->etype))
&& !IS_FUNC(OP_SYM_TYPE(right))
) {
DEBUGpic16_emitcode("; ", "%s:%d symbol in code space, take special care\n", __FUNCTION__, __LINE__);
-// fprintf(stderr, "%s:%d symbol %s = [ %s ] is in code space\n", __FILE__, __LINE__, OP_SYMBOL(result)->name, OP_SYMBOL(right)->name);
+ fprintf(stderr, "%s:%d symbol %s = [ %s ] is in code space\n", __FILE__, __LINE__, OP_SYMBOL(result)->name, OP_SYMBOL(right)->name);
// set up table pointer
- if( (AOP_TYPE(right) == AOP_PCODE)
- && ((AOP(right)->aopu.pcop->type == PO_IMMEDIATE)
-// || (AOP(right)->aopu.pcop->type == PO_DIR)
- )
- )
- {
+ if(is_LitOp(right)) {
// fprintf(stderr, "%s:%d inside block 1\n", __FILE__, __LINE__);
pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(right),0));
pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptrl));
} else if (AOP_TYPE(right) == AOP_CRY) {
pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset));
if(offset == 0) {
- pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(right),0));
+ //debugf("%s: BTFSS offset == 0\n", __FUNCTION__);
+ pic16_emitpcode(POC_BTFSC, pic16_popGet(AOP(right),0));
pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),0));
}
} else if ( (AOP_TYPE(right) == AOP_PCODE) && (AOP(right)->aopu.pcop->type == PO_IMMEDIATE) ) {
/*-----------------------------------------------------------------*/
static void genJumpTab (iCode *ic)
{
- symbol *jtab;
- char *l;
+ symbol *jtab;
+ char *l;
+ pCodeOp *jt_offs;
+ pCodeOp *jt_offs_hi;
+ pCodeOp *jt_label;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
pic16_aopOp(IC_JTCOND(ic),ic,FALSE);
/* get the condition into accumulator */
pic16_emitcode("jmp","@a+dptr");
pic16_emitcode("","%05d_DS_:",jtab->key+100);
+#if 0
pic16_emitpcode(POC_MOVLW, pic16_popGetLabel(jtab->key));
pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(IC_JTCOND(ic)),0));
emitSKPNC;
pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_pcl));
pic16_emitpLabel(jtab->key);
+#else
+
+ jt_offs = pic16_popGetTempReg(0);
+ jt_offs_hi = pic16_popGetTempReg(1);
+ jt_label = pic16_popGetLabel (jtab->key);
+ //fprintf (stderr, "Creating jump table...\n");
+
+ // calculate offset into jump table (idx * sizeof (GOTO))
+ pic16_emitpcode(POC_CLRF , jt_offs_hi);
+ pic16_emitpcode(POC_RLCFW , pic16_popGet(AOP(IC_JTCOND(ic)),0));
+ pic16_emitpcode(POC_RLCF , jt_offs_hi);
+ pic16_emitpcode(POC_RLCFW , pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RLCF , jt_offs_hi);
+ pic16_emitpcode(POC_ANDLW , pic16_popGetLit (0xFC));
+ pic16_emitpcode(POC_MOVWF , jt_offs);
+
+ // prepare PCLATx (set to first entry in jump table)
+ pic16_emitpcode(POC_MOVLW , pic16_popGetImmd(jt_label->name, 2, 0));
+ pic16_emitpcode(POC_MOVWF , pic16_popCopyReg(&pic16_pc_pclatu));
+ pic16_emitpcode(POC_MOVLW , pic16_popGetImmd(jt_label->name, 1, 0));
+ pic16_emitpcode(POC_MOVWF , pic16_popCopyReg(&pic16_pc_pclath));
+ pic16_emitpcode(POC_MOVLW , pic16_popGetImmd(jt_label->name, 0, 0));
+
+ // set PCLATx to selected entry (new PCL is stored in jt_offs)
+ pic16_emitpcode(POC_ADDWF , jt_offs);
+ pic16_emitpcode(POC_MOVFW , jt_offs_hi);
+ pic16_emitpcode(POC_ADDWFC, pic16_popCopyReg(&pic16_pc_pclath));
+ emitSKPNC;
+ pic16_emitpcode(POC_INCF , pic16_popCopyReg(&pic16_pc_pclatu));
+
+ // release temporaries and prepare jump into table (new PCL --> WREG)
+ pic16_emitpcode(POC_MOVFW , jt_offs);
+ pic16_popReleaseTempReg (jt_offs_hi, 1);
+ pic16_popReleaseTempReg (jt_offs, 0);
+
+ // jump into the table
+ pic16_emitpcode(POC_MOVWF , pic16_popCopyReg(&pic16_pc_pcl));
+
+ pic16_emitpLabelFORCE(jtab->key);
+
+#endif
pic16_freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
+ pic16_emitpinfo (INF_OPTIMIZATION, pic16_newpCodeOpOpt (OPT_JUMPTABLE_BEGIN, ""));
/* now generate the jump labels */
for (jtab = setFirstItem(IC_JTLABELS(ic)) ; jtab;
jtab = setNextItem(IC_JTLABELS(ic))) {
- pic16_emitcode("ljmp","%05d_DS_",jtab->key+100);
+// pic16_emitcode("ljmp","%05d_DS_",jtab->key+100);
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(jtab->key));
}
+ pic16_emitpinfo (INF_OPTIMIZATION, pic16_newpCodeOpOpt (OPT_JUMPTABLE_END, ""));
}
operand *result = IC_RESULT(ic);
sym_link *ctype = operandType(IC_LEFT(ic));
sym_link *rtype = operandType(IC_RIGHT(ic));
+ sym_link *restype = operandType(IC_RESULT(ic));
operand *right = IC_RIGHT(ic);
int size, offset ;
- DEBUGpic16_emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ FENTRY;
+
/* 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 ;
pic16_aopOp(right,ic,FALSE) ;
pic16_aopOp(result,ic,FALSE);
DEBUGpic16_pic16_AopType(__LINE__,NULL,right,result);
+
/* if the result is a bit */
if (AOP_TYPE(result) == AOP_CRY) {
goto release;
}
+ if(IS_BITFIELD(getSpec(restype))
+ && IS_BITFIELD(getSpec(rtype))) {
+ DEBUGpic16_emitcode("***", "%d casting a bit to another bit", __LINE__);
+ }
+
/* if they are the same size : or less */
if (AOP_SIZE(result) <= AOP_SIZE(right)) {
break;
case GPOINTER:
- pic16_emitpcode(POC_MOVFF, pic16_popGet2(AOP(right), AOP(result), GPTRSIZE-1));
+ if (GPTRSIZE > AOP_SIZE(right)) {
+ // assume data pointer... THIS MIGHT BE WRONG!
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), GPTRSIZE - 1));
+ } else {
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2(AOP(right), AOP(result), GPTRSIZE-1));
+ }
break;
default:
/*-----------------------------------------------------------------*/
static void genReceive (iCode *ic)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ FENTRY;
#if 0
fprintf(stderr, "%s:%d %s for symbol %s\tonStack: %d\n", __FILE__, __LINE__, __FUNCTION__,
}
} else {
DEBUGpic16_emitcode ("; ***","2 %s %d argreg = %d",__FUNCTION__,__LINE__, SPEC_ARGREG(OP_SYM_ETYPE(IC_RESULT(ic)) ));
-
_G.accInUse++;
pic16_aopOp(IC_RESULT(ic),ic,FALSE);
_G.accInUse--;
+
+ /* set pseudo stack pointer to where it should be - dw*/
+ GpsuedoStkPtr = ic->parmBytes;
+
+ /* setting GpsuedoStkPtr has side effects here: */
assignResultValue(IC_RESULT(ic), 0);
}
void genpic16Code (iCode *lic)
{
- iCode *ic;
- int cln = 0;
+ iCode *ic;
+ int cln = 0;
lineHead = lineCurr = NULL;
/* if debug information required */
if (options.debug && currFunc) {
if (currFunc) {
- cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
+ cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
}
}
#endif
for (ic = lic ; ic ; ic = ic->next ) {
- DEBUGpic16_emitcode(";ic ", "\t%c 0x%x",ic->op, ic->op);
- if ( cln != ic->lineno ) {
- if ( options.debug ) {
- debugFile->writeCLine (ic);
- }
-
- if(!options.noCcodeInAsm) {
- pic16_addpCode2pBlock(pb,
- pic16_newpCodeCSource(ic->lineno, ic->filename,
- printCLine(ic->filename, ic->lineno)));
- }
+ DEBUGpic16_emitcode(";ic ", "\t%c 0x%x\t(%s)",ic->op, ic->op, pic16_decodeOp(ic->op));
+ if ( cln != ic->lineno ) {
+ if ( options.debug ) {
+ debugFile->writeCLine (ic);
+ }
+
+ if(!options.noCcodeInAsm) {
+ pic16_addpCode2pBlock(pb, pic16_newpCodeCSource(ic->lineno, ic->filename,
+ printCLine(ic->filename, ic->lineno)));
+ }
- cln = ic->lineno ;
- }
+ cln = ic->lineno ;
+ }
- if(options.iCodeInAsm) {
- char *l;
- /* insert here code to print iCode as comment */
- l = Safe_strdup(printILine(ic));
- pic16_emitpcomment("ic:%d: %s", ic->seq, l);
- }
+ if(options.iCodeInAsm) {
+ char *l;
+
+ /* insert here code to print iCode as comment */
+ l = Safe_strdup(printILine(ic));
+ pic16_emitpcomment("ic:%d: %s", ic->seq, l);
+ }
- /* 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 ;
+ /* 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 '!' :
- pic16_genNot(ic);
- break;
-
- case '~' :
- pic16_genCpl(ic);
- break;
-
- case UNARYMINUS:
- genUminus (ic);
- break;
-
- case IPUSH:
- genIpush (ic);
- break;
+ /* depending on the operation */
+ switch (ic->op) {
+ case '!' :
+ pic16_genNot(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 destroy 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 '~' :
+ pic16_genCpl(ic);
+ break;
- case CALL:
- genCall (ic);
- break;
+ case UNARYMINUS:
+ genUminus (ic);
+ break;
- case PCALL:
- genPcall (ic);
- break;
+ case IPUSH:
+ genIpush (ic);
+ break;
- case FUNCTION:
- genFunction (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 destroy 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 ENDFUNCTION:
- genEndFunction (ic);
- break;
+ case CALL:
+ genCall (ic);
+ break;
- case RETURN:
- genRet (ic);
- break;
+ case PCALL:
+ genPcall (ic);
+ break;
- case LABEL:
- genLabel (ic);
- break;
+ case FUNCTION:
+ genFunction (ic);
+ break;
- case GOTO:
- genGoto (ic);
- break;
+ case ENDFUNCTION:
+ genEndFunction (ic);
+ break;
- case '+' :
- pic16_genPlus (ic) ;
- break;
+ case RETURN:
+ genRet (ic);
+ break;
- case '-' :
- if ( ! genDjnz (ic,ifxForOp(IC_RESULT(ic),ic)))
- pic16_genMinus (ic);
- break;
+ case LABEL:
+ genLabel (ic);
+ break;
- case '*' :
- genMult (ic);
- break;
+ case GOTO:
+ genGoto (ic);
+ break;
- case '/' :
- genDiv (ic) ;
- break;
+ case '+' :
+ pic16_genPlus (ic) ;
+ break;
- case '%' :
- genMod (ic);
- break;
+ case '-' :
+ if ( ! genDjnz (ic,ifxForOp(IC_RESULT(ic),ic)))
+ pic16_genMinus (ic);
+ break;
+
+ case '*' :
+ genMult (ic);
+ break;
- case '>' :
- genCmpGt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ case '/' :
+ genDiv (ic) ;
+ break;
- case '<' :
- genCmpLt (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ case '%' :
+ genMod (ic);
+ break;
- case LE_OP:
- case GE_OP:
- case NE_OP:
+ case '>' :
+ genCmpGt (ic,ifxForOp(IC_RESULT(ic),ic));
+ break;
- /* 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 '<' :
+ genCmpLt (ic,ifxForOp(IC_RESULT(ic),ic));
+ break;
- case EQ_OP:
- genCmpEq (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 AND_OP:
+ genAndOp (ic);
+ break;
- case OR_OP:
- genOrOp (ic);
- break;
+ case OR_OP:
+ genOrOp (ic);
+ break;
- case '^' :
- genXor (ic,ifxForOp(IC_RESULT(ic),ic));
- break;
+ case '^' :
+ genXor (ic,ifxForOp(IC_RESULT(ic),ic));
+ break;
- case '|' :
- genOr (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 BITWISEAND:
+ genAnd (ic,ifxForOp(IC_RESULT(ic),ic));
+ break;
- case INLINEASM:
- genInline (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);
- /* create a reversed list of SEND iCodes */
-// addSetHead(&_G.sendSet, ic);
- break;
+ case SEND:
+ addSet(&_G.sendSet,ic);
+ break;
- case DUMMY_READ_VOLATILE:
- genDummyRead (ic);
- break;
+ case DUMMY_READ_VOLATILE:
+ genDummyRead (ic);
+ break;
- default :
- ic = ic;
- }
+ default :
+ ic = ic;
+ }
}
/* now we are ready to call the
peep hole optimizer */
- if (!options.nopeep) {
+ if (!options.nopeep)
peepHole (&lineHead);
- }
+
/* now do the actual printing */
printLine (lineHead, codeOutFile);