__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;
}
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
}
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ pic16_aopOp (result,ic,FALSE);
+
+ 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 */
}
}
}
-// else
-// rname = pic16_aopGet(AOP(left),0,FALSE,FALSE);
-
- pic16_aopOp (result,ic,FALSE);
-
- DEBUGpic16_pic16_AopType(__LINE__, left, NULL, result);
/* if bitfield then unpack the bits */
if (IS_BITFIELD(retype))
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 */
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;
+ operand *left, *result ;
+ sym_link *type, *etype;
+ int p_type;
FENTRY;
/* 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");
}
-
}
/*-----------------------------------------------------------------*/
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++;
}
/* 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);
+ case PPOINTER:
+ genPagedPointerSet (right,result,ic);
break;
- case PPOINTER:
- genPagedPointerSet (right,result,ic);
- break;
-
- case FPOINTER:
- genFarPointerSet (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");
}
}
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))));
for (ic = lic ; ic ; ic = ic->next ) {
- DEBUGpic16_emitcode(";ic ", "\t%c 0x%x",ic->op, ic->op);
+ 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);
#endif
void _debugf(char *f, int l, char *frm, ...);
-
+#define NEWREG_DEBUG 0
//#define USE_ONSTACK
return NULL;
}
-static char *
-decodeOp (unsigned int op)
+char *
+pic16_decodeOp (unsigned int op)
{
if (op < 128 && op > ' ') {
buffer[0] = (op & 0xff);
dReg->accessBank = 0;
}
-// fprintf(stderr,"newReg: %s, rIdx = 0x%02x\taccess= %d\tregop= %p\n",dReg->name,rIdx, dReg->accessBank, refop);
-
+#if NEWREG_DEBUG
+ fprintf(stderr,"newReg: %s, rIdx = 0x%02x\taccess= %d\tregop= %p\n",dReg->name,rIdx, dReg->accessBank, refop);
+#endif
dReg->size = size;
dReg->alias = alias;
dReg->reg_alias = NULL;
debugLog ("%s of type %s for register rIdx: %d (0x%x)\n", __FUNCTION__, debugLogRegType (type), dynrIdx-1, dynrIdx-1);
-// fprintf(stderr,"%s:%d: %s\t%s addr= 0x%x\trIdx= 0x%02x isFree: %d\n",
-// __FILE__, __LINE__, __FUNCTION__, reg->name, reg->address, reg->rIdx, reg->isFree);
-
+#if 0
+ fprintf(stderr,"%s:%d: %s\t%s addr= 0x%x\trIdx= 0x%02x isFree: %d\n",
+ __FILE__, __LINE__, __FUNCTION__, reg->name, reg->address, reg->rIdx, reg->isFree);
+#endif
if(reg) {
reg->accessBank = 1; /* this is a temporary register alloc in accessBank */
reg->isLocal = 1; /* this is a local frame register */
serialRegAssign (eBBlock ** ebbs, int count)
{
int i;
-
+ iCode *ic;
+
debugLog ("%s\n", __FUNCTION__);
/* for all blocks */
for (i = 0; i < count; i++)
{
-
- iCode *ic;
-
if (ebbs[i]->noPath &&
(ebbs[i]->entryLabel != entryLabel &&
ebbs[i]->entryLabel != returnLabel))
for (ic = ebbs[i]->sch; ic; ic = ic->next)
{
- debugLog (" op: %s\n", decodeOp (ic->op));
+ debugLog (" op: %s\n", pic16_decodeOp (ic->op));
if(IC_RESULT(ic) && !IS_ITEMP( IC_RESULT(ic)))
pic16_allocDirReg(IC_RESULT(ic));
if (ic->op == RECEIVE)
debugLog ("When I get clever, I'll optimize the receive logic\n");
+ if(POINTER_GET(ic) && IS_BITFIELD(getSpec(operandType(IC_RESULT(ic))))
+ && (SPEC_BLEN(getSpec(operandType(IC_RESULT(ic))))==1)
+ && (ic->next->op == IFX)
+ && (OP_LIVETO(IC_RESULT(ic)) == ic->next->seq)) {
+
+ /* skip register allocation since none will be used */
+ for(j=0;j<sym->nRegs;j++)
+ sym->regs[j] = newReg(REG_TMP, PO_GPR_TEMP, 0, "bad", 1, 0, NULL);
+// OP_SYMBOL(IC_RESULT(ic))->nRegs = 0;
+
+ continue;
+ }
+
/* if we need ptr regs for the right side
then mark it */
if (POINTER_GET (ic) && IS_SYMOP( IC_LEFT(ic) ) && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
iCode *dic, *sic;
debugLog ("%d\t%s\n", __LINE__, __FUNCTION__);
- debugLog ("ic->op = %s\n", decodeOp( ic->op ) );
+ debugLog ("ic->op = %s\n", pic16_decodeOp( ic->op ) );
debugAopGet (" result:", IC_RESULT (ic));
debugAopGet (" left:", IC_LEFT (ic));
debugAopGet (" right:", IC_RIGHT (ic));
for (dic = ic->next; dic; dic = dic->next)
{
-
-
-
if (IC_LEFT (dic) && (IC_RESULT (ic)->key == IC_LEFT (dic)->key))
- debugLog (" used on left\n");
+ debugLog (" used on left\n");
if (IC_RIGHT (dic) && IC_RESULT (ic)->key == IC_RIGHT (dic)->key)
- debugLog (" used on right\n");
+ debugLog (" used on right\n");
if (IC_RESULT (dic) && IC_RESULT (ic)->key == IC_RESULT (dic)->key)
- debugLog (" used on result\n");
+ debugLog (" used on result\n");
if ((IC_LEFT (dic) && (IC_RESULT (ic)->key == IC_LEFT (dic)->key)) ||
- (IC_RESULT (dic) && IC_RESULT (ic)->key == IC_RESULT (dic)->key))
+ (IC_RESULT (dic) && IC_RESULT (ic)->key == IC_RESULT (dic)->key))
return;
-
}
debugLog (" hey we can remove this unnecessary assign\n");