- int i;
-
- DEBUGpic14_emitcode ("; ***","%s %d, lit = %d",__FUNCTION__,__LINE__,lit);
- if( (lit&0xff) == 0)
- i=1;
- else
- i=0;
-
- switch( BYTEofLONG(lit,i)) {
- case 0:
- emitpcode(POC_MOVFW,popGet(AOP(op),offset+i));
- break;
- case 1:
- emitpcode(POC_DECFW,popGet(AOP(op),offset+i));
- break;
- case 0xff:
- emitpcode(POC_INCFW,popGet(AOP(op),offset+i));
- break;
- default:
- emitpcode(POC_MOVFW,popGet(AOP(op),offset+i));
- emitpcode(POC_XORLW,popGetLit(BYTEofLONG(lit,i)));
- }
-
- i ^= 1;
-
- switch( BYTEofLONG(lit,i)) {
- case 0:
- emitpcode(POC_IORFW,popGet(AOP(op),offset+i));
- break;
- case 1:
- emitSKPNZ;
- emitpcode(POC_DECFW,popGet(AOP(op),offset+i));
- break;
- case 0xff:
- emitSKPNZ;
- emitpcode(POC_INCFW,popGet(AOP(op),offset+i));
- break;
- default:
- emitpcode(POC_MOVLW,popGetLit(BYTEofLONG(lit,i)));
- emitSKPNZ;
- emitpcode(POC_XORFW,popGet(AOP(op),offset+i));
-
- }
-
-}
-
-/*-----------------------------------------------------------------*/
-/* gencjneshort - compare and jump if not equal */
-/*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, operand *result, iCode *ifx)
-{
- int size = max(AOP_SIZE(left),AOP_SIZE(right));
- int offset = 0;
- resolvedIfx rIfx;
- symbol *lbl;
-
- unsigned long lit = 0L;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- DEBUGpic14_AopType(__LINE__,left,right,NULL);
-
- resolveIfx(&rIfx,ifx);
- lbl = newiTempLabel(NULL);
-
-
- /* if the left side is a literal or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(left) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *t = right;
- right = left;
- left = t;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- /* if the right side is a literal then anything goes */
- if (AOP_TYPE(right) == AOP_LIT &&
- AOP_TYPE(left) != AOP_DIR ) {
- switch(size) {
- case 2:
- genc16bit2lit(left, lit, 0);
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(lbl->key));
- break;
- default:
- while (size--) {
- if(lit & 0xff) {
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_XORLW,popGetLit(lit & 0xff));
- } else {
- emitpcode(POC_MOVF,popGet(AOP(left),offset));
- }
-
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(lbl->key));
- offset++;
- lit >>= 8;
- }
- break;
- }
- }
-
- /* if the right side is in a register or in direct space or
- if the left is a pointer register & right is not */
- else if (AOP_TYPE(right) == AOP_REG ||
- AOP_TYPE(right) == AOP_DIR ||
- (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) ||
- (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) {
- switch(size) {
- case 2:
- genc16bit2lit(left, lit, 0);
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(lbl->key));
- break;
- default:
- while (size--) {
- int emit_skip=1;
- if((AOP_TYPE(left) == AOP_DIR) &&
- ((AOP_TYPE(right) == AOP_REG) || (AOP_TYPE(right) == AOP_DIR))) {
-
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_XORFW,popGet(AOP(right),offset));
-
- } else if((AOP_TYPE(left) == AOP_DIR) && (AOP_TYPE(right) == AOP_LIT)){
-
- switch (lit & 0xff) {
- case 0:
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- break;
- case 1:
- emitpcode(POC_DECFSZ,popGet(AOP(left),offset));
- emitpcode(POC_GOTO,popGetLabel(lbl->key));
- emit_skip=0;
- break;
- case 0xff:
- emitpcode(POC_INCFSZ,popGet(AOP(left),offset));
- emitpcode(POC_GOTO,popGetLabel(lbl->key));
- emit_skip=0;
- break;
- default:
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_XORLW,popGetLit(lit & 0xff));
- }
- lit >>= 8;
-
- } else {
- emitpcode(POC_MOVF,popGet(AOP(left),offset));
- }
- if(emit_skip) {
- if(AOP_TYPE(result) == AOP_CRY) {
- pic14_emitcode(";***","%s %d",__FUNCTION__,__LINE__);
- if(rIfx.condition)
- emitSKPNZ;
- else
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
- } else {
- /* fix me. probably need to check result size too */
- emitpcode(POC_CLRF,popGet(AOP(result),0));
- if(rIfx.condition)
- emitSKPNZ;
- else
- emitSKPZ;
- emitpcode(POC_INCF,popGet(AOP(result),0));
- }
- if(ifx)
- ifx->generated=1;
- }
- emit_skip++;
- offset++;
- }
- break;
- }
- } else if(AOP_TYPE(right) == AOP_REG &&
- AOP_TYPE(left) != AOP_DIR){
-
- while(size--) {
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_XORFW,popGet(AOP(right),offset));
- pic14_emitcode(";***","%s %d",__FUNCTION__,__LINE__);
- if(rIfx.condition)
- emitSKPNZ;
- else
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
- offset++;
- }
-
- }else{
- /* right is a pointer reg need both a & b */
- while(size--) {
- char *l = aopGet(AOP(left),offset,FALSE,FALSE);
- if(strcmp(l,"b"))
- pic14_emitcode("mov","b,%s",l);
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- pic14_emitcode("cjne","a,b,%05d_DS_",lbl->key+100);
- offset++;
- }
- }
- emitpLabel(lbl->key);
-
- if(ifx)
- ifx->generated = 1;
-}
-
-#if 0
-/*-----------------------------------------------------------------*/
-/* gencjne - compare and jump if not equal */
-/*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, iCode *ifx)
-{
- symbol *tlbl = newiTempLabel(NULL);
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- gencjneshort(left, right, lbl);
-
- pic14_emitcode("mov","a,%s",one);
- pic14_emitcode("sjmp","%05d_DS_",tlbl->key+100);
- pic14_emitcode("","%05d_DS_:",lbl->key+100);
- pic14_emitcode("clr","a");
- pic14_emitcode("","%05d_DS_:",tlbl->key+100);
-
- emitpLabel(lbl->key);
- emitpLabel(tlbl->key);
-
-}
-#endif
-
-/*-----------------------------------------------------------------*/
-/* genCmpEq - generates code for equal to */
-/*-----------------------------------------------------------------*/
-static void genCmpEq (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
- unsigned long lit = 0L;
- int size,offset=0;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- if(ifx)
- DEBUGpic14_emitcode ("; ifx is non-null","");
- else
- DEBUGpic14_emitcode ("; ifx is null","");
-
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
-
- size = max(AOP_SIZE(left),AOP_SIZE(right));
-
- DEBUGpic14_AopType(__LINE__,left,right,result);
-
- /* if literal, literal on the right or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
-
- if(ifx && !AOP_SIZE(result)){
- symbol *tlbl;
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if(lit == 0L){
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("cpl","c");
- } else if(lit == 1L) {
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- pic14_emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("jb","%s,%05d_DS_",AOP(right)->aopu.aop_dir,(lbl->key+100));
- pic14_emitcode("cpl","c");
- pic14_emitcode("","%05d_DS_:",(lbl->key+100));
- }
- /* if true label then we jump if condition
- supplied is true */
- tlbl = newiTempLabel(NULL);
- if ( IC_TRUE(ifx) ) {
- pic14_emitcode("jnc","%05d_DS_",tlbl->key+100);
- pic14_emitcode("ljmp","%05d_DS_",IC_TRUE(ifx)->key+100);
- } else {
- pic14_emitcode("jc","%05d_DS_",tlbl->key+100);
- pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ifx)->key+100);
- }
- pic14_emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
-
- {
- /* left and right are both bit variables, result is carry */
- resolvedIfx rIfx;
-
- resolveIfx(&rIfx,ifx);
-
- emitpcode(POC_MOVLW,popGet(AOP(left),0));
- emitpcode(POC_ANDFW,popGet(AOP(left),0));
- emitpcode(POC_BTFSC,popGet(AOP(right),0));
- emitpcode(POC_ANDLW,popGet(AOP(left),0));
- genSkipz2(&rIfx,0);
- }
- } else {
-
- /* They're not both bit variables. Is the right a literal? */
- if(AOP_TYPE(right) == AOP_LIT) {
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- switch(size) {
-
- case 1:
- switch(lit & 0xff) {
- case 1:
- if ( IC_TRUE(ifx) ) {
- emitpcode(POC_DECFW,popGet(AOP(left),offset));
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- } else {
- emitpcode(POC_DECFSZW,popGet(AOP(left),offset));
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- }
- break;
- case 0xff:
- if ( IC_TRUE(ifx) ) {
- emitpcode(POC_INCFW,popGet(AOP(left),offset));
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- } else {
- emitpcode(POC_INCFSZW,popGet(AOP(left),offset));
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- }
- break;
- default:
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- if(lit)
- emitpcode(POC_XORLW,popGetLit(lit & 0xff));
- genSkip(ifx,'z');
- }
-
-
- /* end of size == 1 */
- break;
-
- case 2:
- genc16bit2lit(left,lit,offset);
- genSkip(ifx,'z');
- break;
- /* end of size == 2 */
-
- default:
- /* size is 4 */
- if(lit==0) {
- emitpcode(POC_MOVFW,popGet(AOP(left),0));
- emitpcode(POC_IORFW,popGet(AOP(left),1));
- emitpcode(POC_IORFW,popGet(AOP(left),2));
- emitpcode(POC_IORFW,popGet(AOP(left),3));
-
- } else {
-
- /* search for patterns that can be optimized */
-
- genc16bit2lit(left,lit,0);
- lit >>= 16;
- if(lit) {
- genSkipz(ifx,IC_TRUE(ifx) == NULL);
- //genSkip(ifx,'z');
- genc16bit2lit(left,lit,2);
- } else {
- emitpcode(POC_IORFW,popGet(AOP(left),2));
- emitpcode(POC_IORFW,popGet(AOP(left),3));
-
- }
-
- }
-
- genSkip(ifx,'z');
- }
-
- ifx->generated = 1;
- goto release ;
-
-
- } else if(AOP_TYPE(right) == AOP_CRY ) {
- /* we know the left is not a bit, but that the right is */
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode( ( (IC_TRUE(ifx)) ? POC_BTFSC : POC_BTFSS),
- popGet(AOP(right),offset));
- emitpcode(POC_XORLW,popGetLit(1));
-
- /* if the two are equal, then W will be 0 and the Z bit is set
- * we could test Z now, or go ahead and check the high order bytes if
- * the variable we're comparing is larger than a byte. */
-
- while(--size)
- emitpcode(POC_IORFW,popGet(AOP(left),offset));
-
- if ( IC_TRUE(ifx) ) {
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
- } else {
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
-
- } else {
- /* They're both variables that are larger than bits */
- int s = size;
-
- tlbl = newiTempLabel(NULL);
-
- while(size--) {
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_XORFW,popGet(AOP(right),offset));
-
- if ( IC_TRUE(ifx) ) {
- if(size) {
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(tlbl->key));
- pic14_emitcode(" goto","_%05d_DS_",tlbl->key+100+labelOffset);
- } else {
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
- }
- } else {
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
- offset++;
- }
- if(s>1 && IC_TRUE(ifx)) {
- emitpLabel(tlbl->key);
- pic14_emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);
- }
- }
- }
- /* mark the icode as generated */
- ifx->generated = 1;
- goto release ;
- }
-
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if(lit == 0L){
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("cpl","c");
- } else if(lit == 1L) {
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- pic14_emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("jb","%s,%05d_DS_",AOP(right)->aopu.aop_dir,(lbl->key+100));
- pic14_emitcode("cpl","c");
- pic14_emitcode("","%05d_DS_:",(lbl->key+100));
- }
- /* c = 1 if egal */
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)){
- pic14_outBitC(result);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"c");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- pic14_outBitC(result);
- } else {
-
- gencjne(left,right,result,ifx);
-/*
- if(ifx)
- gencjne(left,right,newiTempLabel(NULL));
- else {
- if(IC_TRUE(ifx)->key)
- gencjne(left,right,IC_TRUE(ifx)->key);
- else
- gencjne(left,right,IC_FALSE(ifx)->key);
- ifx->generated = 1;
- goto release ;
- }
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- if (ifx) {
- genIfxJump (ifx,"a");
- goto release ;
- }
-*/
- /* if the result is used in an arithmetic operation
- then put the result in place */
-/*
- if (AOP_TYPE(result) != AOP_CRY)
- pic14_outAcc(result);
-*/
- /* leave the result in acc */
- }
-
-release:
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
-}
-
-/*-----------------------------------------------------------------*/
-/* ifxForOp - returns the icode containing the ifx for operand */
-/*-----------------------------------------------------------------*/
-static iCode *ifxForOp ( operand *op, iCode *ic )
-{
- /* if true symbol then needs to be assigned */
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (IS_TRUE_SYMOP(op))
- return NULL ;
-
- /* if this has register type condition and
- the next instruction is ifx with the same operand
- and live to of the operand is upto the ifx only then */
- if (ic->next &&
- ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key &&
- OP_SYMBOL(op)->liveTo <= ic->next->seq )
- return ic->next;
-
- if (ic->next &&
- ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key) {
- DEBUGpic14_emitcode ("; WARNING ","%d IGNORING liveTo range in %s",__LINE__,__FUNCTION__);
- return ic->next;
- }
-
- DEBUGpic14_emitcode ("; NULL :(","%d",__LINE__);
- if (ic->next &&
- ic->next->op == IFX)
- DEBUGpic14_emitcode ("; ic-next"," is an IFX");
-
- if (ic->next &&
- ic->next->op == IFX &&
- IC_COND(ic->next)->key == op->key) {
- DEBUGpic14_emitcode ("; "," key is okay");
- DEBUGpic14_emitcode ("; "," key liveTo %d, next->seq = %d",
- OP_SYMBOL(op)->liveTo,
- ic->next->seq);
- }
-
-
- return NULL;
-}
-/*-----------------------------------------------------------------*/
-/* genAndOp - for && operation */
-/*-----------------------------------------------------------------*/
-static void genAndOp (iCode *ic)
-{
- operand *left,*right, *result;
- symbol *tlbl;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* note here that && operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- aopOp((left=IC_LEFT(ic)),ic,FALSE);
- aopOp((right=IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,FALSE);
-
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- pic14_outBitC(result);
- } else {
- tlbl = newiTempLabel(NULL);
- pic14_toBoolean(left);
- pic14_emitcode("jz","%05d_DS_",tlbl->key+100);
- pic14_toBoolean(right);
- pic14_emitcode("","%05d_DS_:",tlbl->key+100);
- pic14_outBitAcc(result);
- }
-
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
-}