strcpy(pcop->name,aop->aopu.aop_dir);
PCOR(pcop)->r = dirregWithName(aop->aopu.aop_dir);
if(PCOR(pcop)->r == NULL) {
- fprintf(stderr,"%d - couldn't find %s in allocated registers, size =%d\n",__LINE__,aop->aopu.aop_dir,aop->size);
+ //fprintf(stderr,"%d - couldn't find %s in allocated registers, size =%d\n",__LINE__,aop->aopu.aop_dir,aop->size);
PCOR(pcop)->r = allocRegByName (aop->aopu.aop_dir,aop->size);
}
case AOP_CRY:
pcop = newpCodeOpBit(aop->aopu.aop_dir,-1,1);
PCOR(pcop)->r = 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);
+ //if(PCOR(pcop)->r == NULL)
+ //fprintf(stderr,"%d - couldn't find %s in allocated registers\n",__LINE__,aop->aopu.aop_dir);
return pcop;
case AOP_LIT:
static void genCmp (operand *left,operand *right,
operand *result, iCode *ifx, int sign)
{
- int size, offset = 0 ;
+ int size; //, offset = 0 ;
unsigned long lit = 0L,i = 0;
resolvedIfx rFalseIfx;
// resolvedIfx rTrueIfx;
size = max(AOP_SIZE(left),AOP_SIZE(right));
/* if unsigned char cmp with lit, do cjne left,#right,zz */
- if((size == 1) && !sign &&
- (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
- symbol *lbl = newiTempLabel(NULL);
- pic14_emitcode("cjne","%s,%s,%05d_DS_",
- aopGet(AOP(left),offset,FALSE,FALSE),
- aopGet(AOP(right),offset,FALSE,FALSE),
- lbl->key+100);
- pic14_emitcode("","%05d_DS_:",lbl->key+100);
- } else {
+ //if((size == 1) && !sign &&
+ // (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
+ // symbol *lbl = newiTempLabel(NULL);
+ // pic14_emitcode("cjne","%s,%s,%05d_DS_",
+ // aopGet(AOP(left),offset,FALSE,FALSE),
+ // aopGet(AOP(right),offset,FALSE,FALSE),
+ // lbl->key+100);
+ //pic14_emitcode("","%05d_DS_:",lbl->key+100);
+ //} else
+ {
symbol *lbl = newiTempLabel(NULL);
if (*bp == '\n') {
*bp++ = '\0';
pic14_emitcode(bp1,"");
+ addpCode2pBlock(pb,newpCodeInlineP(bp1));
bp1 = bp;
} else {
if (*bp == ':') {
bp++;
}
}
- if (bp1 != bp)
+ if (bp1 != bp) {
pic14_emitcode(bp1,"");
+ addpCode2pBlock(pb,newpCodeInlineP(bp1));
+ }
/* pic14_emitcode("",buffer); */
_G.inLine -= (!options.asmpeep);
}
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- same = (left == result) || (AOP(left) == AOP(result));
+ same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);
switch(shCount) {
case 1:
}
break;
+ case 2:
+
+ emitpcode(POC_RLFW, popGet(AOP(left),offl));
+ if(same)
+ emitpcode(POC_RRF, popGet(AOP(result),offr));
+ else {
+ emitpcode(POC_RRFW, popGet(AOP(left),offl));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+ }
+ emitpcode(POC_RLFW, popGet(AOP(result),offl));
+ emitpcode(POC_RRF, popGet(AOP(result),offl));
+
+ break;
+
+ case 3:
+ if(same)
+ emitpcode(POC_SWAPF, popGet(AOP(result),offr));
+ else {
+ emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+ }
+
+ emitpcode(POC_RLFW, popGet(AOP(result),offr));
+ emitpcode(POC_RLFW, popGet(AOP(result),offr));
+ emitpcode(POC_ANDLW, popGetLit(0x1f));
+
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),3,0));
+ emitpcode(POC_IORLW, popGetLit(0xe0));
+
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+ break;
+
+ case 4:
+ emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
+ emitpcode(POC_ANDLW, popGetLit(0x0f));
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
+ emitpcode(POC_IORLW, popGetLit(0xf0));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+ break;
+ case 5:
+ if(same) {
+ emitpcode(POC_SWAPF, popGet(AOP(result),offr));
+ } else {
+ emitpcode(POC_SWAPFW, popGet(AOP(result),offr));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+ }
+ emitpcode(POC_RRFW, popGet(AOP(result),offr));
+ emitpcode(POC_ANDLW, popGetLit(0x07));
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),3,0));
+ emitpcode(POC_IORLW, popGetLit(0xf8));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+
+
+
+ break;
+
+ case 6:
+ if(same) {
+ emitpcode(POC_MOVLW, popGetLit(0x00));
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
+ emitpcode(POC_MOVLW, popGetLit(0xfe));
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),6,0));
+ emitpcode(POC_IORLW, popGetLit(0x01));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+ } else {
+ emitpcode(POC_CLRF, popGet(AOP(result),offr));
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
+ emitpcode(POC_DECF, popGet(AOP(result),offr));
+ emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),6,0));
+ emitpcode(POC_BCF, newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),0,0));
+ }
+ break;
+
+ case 7:
+ if(same) {
+ emitpcode(POC_MOVLW, popGetLit(0x00));
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
+ emitpcode(POC_MOVLW, popGetLit(0xff));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+ } else {
+ emitpcode(POC_CLRF, popGet(AOP(result),offr));
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
+ emitpcode(POC_DECF, popGet(AOP(result),offr));
+ }
default:
break;
break;
case 3:
- if(same)
+ if(same)
emitpcode(POC_SWAPF, popGet(AOP(result),offr));
else {
emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
default:
break;
}
-
-
-#if 0
-
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
-
- /* shift right accumulator */
- if(sign)
- AccSRsh(shCount);
- else
- AccRsh(shCount);
- aopPut(AOP(result),"a",offr);
-#endif
}
/*-----------------------------------------------------------------*/
static void movLeft2Result (operand *left, int offl,
operand *result, int offr, int sign)
{
- char *l;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!pic14_sameRegs(AOP(left),AOP(result)) || (offl != offr)){
- l = aopGet(AOP(left),offl,FALSE,FALSE);
+ char *l;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if(!pic14_sameRegs(AOP(left),AOP(result)) || (offl != offr)){
+ l = aopGet(AOP(left),offl,FALSE,FALSE);
- if (*l == '@' && (IS_AOP_PREG(result))) {
- pic14_emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- } else {
- if(!sign) {
- emitpcode(POC_MOVFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
-
- //aopPut(AOP(result),l,offr);
- }else{
- /* MSB sign in acc.7 ! */
- if(pic14_getDataSize(left) == offl+1){
- pic14_emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- }
- }
- }
+ if (*l == '@' && (IS_AOP_PREG(result))) {
+ pic14_emitcode("mov","a,%s",l);
+ aopPut(AOP(result),"a",offr);
+ } else {
+ //if(!sign) {
+ emitpcode(POC_MOVFW, popGet(AOP(left),offl));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+
+ //aopPut(AOP(result),l,offr);
+ //}else{
+ /* MSB sign in acc.7 ! */
+ //if(pic14_getDataSize(left) == offl+1){
+ // pic14_emitcode("mov","a,%s",l);
+ // aopPut(AOP(result),"a",offr);
+ //}
+ //}
}
+ }
}
/*-----------------------------------------------------------------*/
emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
emitpcode(POC_ADDWF, popGet(AOP(result),offr));
} else {
- emitpcode(POC_SWAPF, popGet(AOP(left),offl));
+ emitpcode(POC_SWAPFW,popGet(AOP(left),offl));
emitpcode(POC_ANDLW, popGetLit(0x0f));
emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- emitpcode(POC_SWAPF, popGet(AOP(left),offl+MSB16));
+ emitpcode(POC_SWAPFW,popGet(AOP(left),offl+MSB16));
emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16));
emitpcode(POC_ANDLW, popGetLit(0xf0));
emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
static void genrshTwo (operand *result,operand *left,
int shCount, int sign)
{
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
- if (shCount)
- shiftR1Left2Result(left, MSB16, result, LSB,
- shCount, sign);
- else
- movLeft2Result(left, MSB16, result, LSB, sign);
- if(sign)
- addSign(result, MSB16, sign);
- else
- emitpcode(POC_CLRF,popGet(AOP(result),MSB16));
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* if shCount >= 8 */
+ if (shCount >= 8) {
+ shCount -= 8 ;
+ if (shCount)
+ shiftR1Left2Result(left, MSB16, result, LSB,
+ shCount, sign);
+ else
+ movLeft2Result(left, MSB16, result, LSB, sign);
+
+ emitpcode(POC_CLRF,popGet(AOP(result),MSB16));
+ if(sign) {
+ emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
+ emitpcode(POC_DECF, popGet(AOP(result),MSB16));
}
+ }
- /* 1 <= shCount <= 7 */
- else
- shiftR2Left2Result(left, LSB, result, LSB, shCount, sign);
+ /* 1 <= shCount <= 7 */
+ else
+ shiftR2Left2Result(left, LSB, result, LSB, shCount, sign);
}
/*-----------------------------------------------------------------*/
l = aopGet(AOP(result),0,FALSE,TRUE);
size = AOP_SIZE(right);
+/*
if ( AOP_TYPE(result) == AOP_PCODE) {
fprintf(stderr,"genDataPointerSet %s, %d\n",
AOP(result)->aopu.pcop->name,
PCOI(AOP(result)->aopu.pcop)->offset);
}
+*/
// tsd, was l+1 - the underline `_' prefix was being stripped
while (size--) {
static pFile *the_pFile = NULL;
-static int peepOptimizing = 0;
+static int peepOptimizing = 1;
static int GpCodeSequenceNumber = 1;
static int GpcFlowSeq = 1;
static void pCodePrintLabel(FILE *of, pCode *pc);
static void pCodePrintFunction(FILE *of, pCode *pc);
static void pCodeOpPrint(FILE *of, pCodeOp *pcop);
-static char *get_op( pCodeInstruction *pcc);
+static char *get_op_from_instruction( pCodeInstruction *pcc);
+char *get_op( pCodeOp *pcop);
int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd);
int pCodePeepMatchRule(pCode *pc);
void pBlockStats(FILE *of, pBlock *pb);
return ( (pCode *)pcw);
+}
+
+ /*-----------------------------------------------------------------*/
+/* newPcodeInlineP - create a new pCode from a char string */
+/*-----------------------------------------------------------------*/
+
+
+pCode *newpCodeInlineP(char *cP)
+{
+
+ pCodeComment *pcc ;
+
+ pcc = Safe_calloc(1,sizeof(pCodeComment));
+
+ pcc->pc.type = PC_INLINE;
+ pcc->pc.prev = pcc->pc.next = NULL;
+ //pcc->pc.from = pcc->pc.to = pcc->pc.label = NULL;
+ pcc->pc.pb = NULL;
+
+ // pcc->pc.analyze = genericAnalyze;
+ pcc->pc.destruct = genericDestruct;
+ pcc->pc.print = genericPrint;
+
+ if(cP)
+ pcc->comment = Safe_strdup(cP);
+ else
+ pcc->comment = NULL;
+
+ return ( (pCode *)pcc);
+
}
/*-----------------------------------------------------------------*/
pcop->type = PO_IMMEDIATE;
if(name) {
pcop->name = Safe_strdup(name);
- fprintf(stderr,"%s %s %d\n",__FUNCTION__,name,offset);
+ //fprintf(stderr,"%s %s %d\n",__FUNCTION__,name,offset);
} else {
pcop->name = NULL;
}
}
-static char *get_op( pCodeInstruction *pcc)
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+char *get_op(pCodeOp *pcop)
{
regs *r;
static char buffer[50];
char *s;
int size;
- if(pcc && pcc->pcop) {
-
- switch(pcc->pcop->type) {
+ if(pcop) {
+ switch(pcop->type) {
case PO_INDF:
case PO_FSR:
//fprintf(stderr,"get_op getting register name rIdx=%d\n",PCOR(pcc->pcop)->rIdx);
//r = pic14_regWithIdx(PCOR(pcc->pcop)->rIdx);
//return r->name;
- return PCOR(pcc->pcop)->r->name;
+ return PCOR(pcop)->r->name;
break;
case PO_GPR_TEMP:
- r = pic14_regWithIdx(PCOR(pcc->pcop)->r->rIdx);
+ r = pic14_regWithIdx(PCOR(pcop)->r->rIdx);
//fprintf(stderr,"getop: getting %s\nfrom:\n",r->name); //pcc->pcop->name);
- pBlockRegs(stderr,pcc->pc.pb);
return r->name;
// case PO_GPR_BIT:
case PO_IMMEDIATE:
s = buffer;
size = sizeof(buffer);
- fprintf(stderr,"PO_IMMEDIATE name = %s offset = %d\n",pcc->pcop->name,
- PCOI(pcc->pcop)->offset);
- if(PCOI(pcc->pcop)->_const) {
+ //fprintf(stderr,"PO_IMMEDIATE name = %s offset = %d\n",pcc->pcop->name,PCOI(pcc->pcop)->offset);
+ if(PCOI(pcop)->_const) {
- if( PCOI(pcc->pcop)->offset && PCOI(pcc->pcop)->offset<4) {
+ if( PCOI(pcop)->offset && PCOI(pcop)->offset<4) {
SAFE_snprintf(&s,&size,"(((%s+%d) >> %d)&0xff)",
- pcc->pcop->name,
- PCOI(pcc->pcop)->index,
- 8 * PCOI(pcc->pcop)->offset );
+ pcop->name,
+ PCOI(pcop)->index,
+ 8 * PCOI(pcop)->offset );
} else
- SAFE_snprintf(&s,&size,"LOW(%s+%d)",pcc->pcop->name,PCOI(pcc->pcop)->index);
+ SAFE_snprintf(&s,&size,"LOW(%s+%d)",pcop->name,PCOI(pcop)->index);
} else {
- if( PCOI(pcc->pcop)->index) { // && PCOI(pcc->pcop)->offset<4) {
+ if( PCOI(pcop)->index) { // && PCOI(pcc->pcop)->offset<4) {
SAFE_snprintf(&s,&size,"(%s + %d)",
- pcc->pcop->name,
- PCOI(pcc->pcop)->index );
+ pcop->name,
+ PCOI(pcop)->index );
} else
- SAFE_snprintf(&s,&size,"%s",pcc->pcop->name);
+ SAFE_snprintf(&s,&size,"%s",pcop->name);
}
return buffer;
case PO_DIR:
s = buffer;
size = sizeof(buffer);
- if( PCOR(pcc->pcop)->instance) {
+ if( PCOR(pcop)->instance) {
SAFE_snprintf(&s,&size,"(%s + %d)",
- pcc->pcop->name,
- PCOR(pcc->pcop)->instance );
- fprintf(stderr,"PO_DIR %s\n",buffer);
+ pcop->name,
+ PCOR(pcop)->instance );
+ //fprintf(stderr,"PO_DIR %s\n",buffer);
} else
- SAFE_snprintf(&s,&size,"%s",pcc->pcop->name);
+ SAFE_snprintf(&s,&size,"%s",pcop->name);
return buffer;
default:
- if (pcc->pcop->name)
- return pcc->pcop->name;
+ if (pcop->name)
+ return pcop->name;
}
}
return "NO operand";
+
+}
+
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+static char *get_op_from_instruction( pCodeInstruction *pcc)
+{
+
+ if(pcc )
+ return get_op(pcc->pcop);
+
+ return ("ERROR Null: "__FUNCTION__);
+
}
/*-----------------------------------------------------------------*/
PCI(pc)->pcop->name ,
PCI(pc)->pcop->name );
else
- SAFE_snprintf(&s,&size,"%s,%d", get_op(PCI(pc)),
+ SAFE_snprintf(&s,&size,"%s,%d", get_op_from_instruction(PCI(pc)),
(((pCodeOpRegBit *)(PCI(pc)->pcop))->bit ));
} else if(PCI(pc)->pcop->type == PO_GPR_BIT) {
- SAFE_snprintf(&s,&size,"%s,%d", get_op(PCI(pc)),PCORB(PCI(pc)->pcop)->bit);
+ SAFE_snprintf(&s,&size,"%s,%d", get_op_from_instruction(PCI(pc)),PCORB(PCI(pc)->pcop)->bit);
}else
- SAFE_snprintf(&s,&size,"%s,0 ; ?bug", get_op(PCI(pc)));
+ SAFE_snprintf(&s,&size,"%s,0 ; ?bug", get_op_from_instruction(PCI(pc)));
//PCI(pc)->pcop->t.bit );
} else {
if(PCI(pc)->pcop->type == PO_GPR_BIT) {
if( PCI(pc)->num_ops == 2)
- SAFE_snprintf(&s,&size,"(%s >> 3),%c",get_op(PCI(pc)),((PCI(pc)->isModReg) ? 'F':'W'));
+ SAFE_snprintf(&s,&size,"(%s >> 3),%c",get_op_from_instruction(PCI(pc)),((PCI(pc)->isModReg) ? 'F':'W'));
else
- SAFE_snprintf(&s,&size,"(1 << (%s & 7))",get_op(PCI(pc)));
+ SAFE_snprintf(&s,&size,"(1 << (%s & 7))",get_op_from_instruction(PCI(pc)));
}else {
- SAFE_snprintf(&s,&size,"%s",get_op(PCI(pc)));
+ SAFE_snprintf(&s,&size,"%s",get_op_from_instruction(PCI(pc)));
if( PCI(pc)->num_ops == 2)
SAFE_snprintf(&s,&size,",%c", ( (PCI(pc)->isModReg) ? 'F':'W'));
SAFE_snprintf(&s,&size,";%s", ((pCodeComment *)pc)->comment);
break;
+ case PC_INLINE:
+ /* assuming that inline code ends with a \n */
+ SAFE_snprintf(&s,&size,"%s", ((pCodeComment *)pc)->comment);
+ break;
+
case PC_LABEL:
SAFE_snprintf(&s,&size,";label=%s, key=%d\n",PCL(pc)->label,PCL(pc)->key);
break;
fprintf(of,";%s\n", ((pCodeComment *)pc)->comment);
break;
+ case PC_INLINE:
+ fprintf(of,"%s\n", ((pCodeComment *)pc)->comment);
+ break;
+
case PC_OPCODE:
// If the opcode has a label, print that first
{
case PO_BIT:
case PO_GPR_TEMP:
- fprintf(stderr, "getRegFromInstruction - bit or temp\n");
+ //fprintf(stderr, "getRegFromInstruction - bit or temp\n");
return PCOR(PCI(pc)->pcop)->r;
case PO_IMMEDIATE:
- fprintf(stderr, "getRegFromInstruction - immediate\n");
+ //fprintf(stderr, "getRegFromInstruction - immediate\n");
return NULL; // PCOR(PCI(pc)->pcop)->r;
case PO_GPR_BIT:
return PCOR(PCI(pc)->pcop)->r;
case PO_DIR:
- fprintf(stderr, "getRegFromInstruction - dir\n");
- //return NULL; PCOR(PCI(pc)->pcop)->r;
+ //fprintf(stderr, "getRegFromInstruction - dir\n");
return PCOR(PCI(pc)->pcop)->r;
case PO_LITERAL:
- fprintf(stderr, "getRegFromInstruction - literal\n");
+ //fprintf(stderr, "getRegFromInstruction - literal\n");
break;
default:
- fprintf(stderr, "getRegFromInstruction - unknown reg type %d\n",PCI(pc)->pcop->type);
- genericPrint(stderr, pc);
+ //fprintf(stderr, "getRegFromInstruction - unknown reg type %d\n",PCI(pc)->pcop->type);
+ //genericPrint(stderr, pc);
break;
}
int cur_bank;
regs *reg;
- return;
+ // return;
if(!pb)
return;
return;
/* loop through all of the flow blocks with in one pblock */
- // fprintf(stderr,"Register banking\n");
+ //fprintf(stderr,"Register banking\n");
cur_bank = 0;
do {
/* at this point, pc should point to a PC_FLOW object */
do {
if(isPCI(pc)) {
- genericPrint(stderr, pc);
+ //genericPrint(stderr, pc);
reg = getRegFromInstruction(pc);
- //#if 0
+ #if 0
if(reg) {
fprintf(stderr, " %s ",reg->name);
fprintf(stderr, "addr = 0x%03x, bank = %d\n",reg->address,REG_BANK(reg));
}
- //#endif
+ #endif
if(reg && REG_BANK(reg)!=cur_bank) {
/* Examine the instruction before this one to make sure it is
* not a skip type instruction */
pcprev = findPrevpCode(pc->prev, PC_OPCODE);
- if(pcprev && !isPCI_SKIP(pcprev)) {
+ if(!pcprev || (pcprev && !isPCI_SKIP(pcprev))) {
int b = cur_bank ^ REG_BANK(reg);
//fprintf(stderr, "Cool! can switch banks\n");
}
- } else
- fprintf(stderr, "Bummer can't switch banks\n");
+ } else {
+ //fprintf(stderr, "Bummer can't switch banks\n");
+ ;
+ }
}
}
while(pc) {
if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL) {
- fprintf(of,"; %s\n",get_op(PCI(pc)));
+ fprintf(of,"; %s\n",get_op_from_instruction(PCI(pc)));
}
pc = setNextItem(pb->function_calls);
}
for( ; pc; pc = setNextItem(pb->function_calls)) {
if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL) {
- char *dest = get_op(PCI(pc));
+ char *dest = get_op_from_instruction(PCI(pc));
pcn = findFunction(dest);
if(pcn)
for( ; pc; pc = setNextItem(pb->function_calls)) {
if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL) {
- char *dest = get_op(PCI(pc));
+ char *dest = get_op_from_instruction(PCI(pc));
pcn = findFunction(dest);
if(pcn)
while(pc->next && !ispCodeFunction(pc->next)) {
pc = pc->next;
if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL)
- fprintf(of,"\t%s\n",get_op(PCI(pc)));
+ fprintf(of,"\t%s\n",get_op_from_instruction(PCI(pc)));
}
}
typedef enum
{
PC_COMMENT=0, /* pCode is a comment */
+ PC_INLINE, /* user's inline code */
PC_OPCODE, /* PORT dependent opcode */
PC_LABEL, /* assembly label */
PC_FLOW, /* flow analysis */
pCode *newpCode (PIC_OPCODE op, pCodeOp *pcop); // Create a new pCode given an operand
pCode *newpCodeCharP(char *cP); // Create a new pCode given a char *
+pCode *newpCodeInlineP(char *cP); // Create a new pCode given a char *
pCode *newpCodeFunction(char *g, char *f); // Create a new function
pCode *newpCodeLabel(char *name,int key); // Create a new label given a key
pBlock *newpCodeChain(memmap *cm,char c, pCode *pc); // Create a new pBlock
int getpCodePeepCommand(char *cmd);
void pBlockMergeLabels(pBlock *pb);
char *pCode2str(char *str, int size, pCode *pc);
+char *get_op( pCodeOp *pcop);
extern pCodeInstruction *pic14Mnemonics[];
return 0;
}
+/*-----------------------------------------------------------------
+ * int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
+ *
+ * Compare two pCodeOp's and return 1 if they're the same
+ *-----------------------------------------------------------------*/
+int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
+{
+
+ if(!pcops || !pcopd)
+ return 0;
+
+ fprintf(stderr," Comparing operands %s",
+ get_op( pcops));
+
+ fprintf(stderr," to %s\n",
+ get_op( pcopd));
+
+ if(pcops->type != pcopd->type) {
+ fprintf(stderr," - fail - diff types\n");
+ return 0; // different types
+ }
+
+ if(!pcops->name || !pcopd->name || strcmp(pcops->name,pcopd->name)) {
+ fprintf(stderr," - fail - diff names\n");
+ return 0; // different names
+ }
+
+ switch(pcops->type) {
+ case PO_DIR:
+ if( PCOR(pcops)->instance != PCOR(pcopd)->instance) {
+ fprintf(stderr, " - fail different instances\n");
+ return 0;
+ }
+ break;
+ default:
+ break;
+ }
+
+ fprintf(stderr," - pass\n");
+
+ return 1;
+}
+
int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
{
int labindex;
exit(1);
}
#endif
+
PCOW(PCI(pcd)->pcop)->matched = PCI(pcs)->pcop;
if(!peepBlock->target.wildpCodeOps[index]) {
peepBlock->target.wildpCodeOps[index] = PCI(pcs)->pcop;
//if(PCI(pcs)->pcop->type == PO_GPR_TEMP)
+ } else {
+ pcs->print(stderr,pcs);
+ pcd->print(stderr,pcd);
+
+ fprintf(stderr, "comparing operands of these instructions, result %d\n",
+ pCodeOpCompare(PCI(pcs)->pcop, peepBlock->target.wildpCodeOps[index])
+ );
+
+ return pCodeOpCompare(PCI(pcs)->pcop, peepBlock->target.wildpCodeOps[index]);
}
+
{
char *n;
return 1;
}
}
+
}
/* FIXME - need an else to check the case when the destination
* isn't a wild card */
pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
PCOR(pcopnew)->r = PCOR(pcop)->r;
PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx;
+ PCOR(pcopnew)->instance = PCOR(pcop)->instance;
DFPRINTF((stderr," register index %d\n", PCOR(pcop)->r->rIdx));
break;
case PO_DIR:
fprintf(stderr,"pCodeOpCopy PO_DIR\n");
pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
+ PCOR(pcopnew)->r = PCOR(pcop)->r;
+ PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx;
+ PCOR(pcopnew)->instance = PCOR(pcop)->instance;
break;
case PO_STATUS:
DFPRINTF((stderr,"pCodeOpCopy PO_STATUS\n"));
debugLog ("%s\n", __FUNCTION__);
- printf ("%s\n", s);
+ //printf ("%s\n", s);
/* if plus or minus print the right hand side */
(int) operandLitValue (IC_RIGHT (ic)));
- fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
+ //fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
psym = newSymbol (OP_SYMBOL (IC_LEFT (ric))->rname, 1);
psym->offset = (int) operandLitValue (IC_RIGHT (ic));
sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
psym = newSymbol (OP_SYMBOL (IC_LEFT (ic))->rname, 1);
- printf ("%s\n", buffer);
+ //printf ("ralloc.c:%d %s\n", __LINE__,buffer);
return psym;
}
rotate2.c \
rotate3.c \
rotate4.c \
+ rotate5.c \
struct1.c \
sub.c \
sub2.c \
--- /dev/null
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+
+signed char c1,c2,c3;
+unsigned char uc1,uc2,uc3;
+
+unsigned int ui1,ui2,ui3;
+signed int i1,i2;
+
+void done()
+{
+
+ dummy++;
+
+}
+
+void m1(void)
+{
+
+ c1 = c1*5; // char = char * lit
+
+ c2 = c1 *c3; // char = char * char
+
+ uc1= uc1*5; // uchar = uchar * lit
+ uc2=uc1*uc3; // uchar = uchar * uchar
+
+ if(c2 != 25)
+ failures++;
+}
+
+void m2(unsigned char uc)
+{
+
+ uc2 = uc1 * uc;
+
+ if(uc2 != 0x20)
+ failures++;
+}
+
+void main(void)
+{
+ dummy = 0;
+
+ c1 = 1;
+ c3 = 5;
+
+ //m1();
+
+ uc1 = 0x10;
+ m2(2);
+
+ ui1 = uc1*uc2; // uint = uchar * uchar
+
+ i1 = c1*c2; // int = char * char
+
+ ui3 = ui1*ui2; // uint = uint * unit
+
+
+ success = failures;
+ done();
+}
--- /dev/null
+// Shift bytes left and right by a constant.
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+signed int aint0 = 0;
+signed int aint1 = 0;
+signed char achar0 = 0;
+signed char achar1 = 0;
+signed char achar2 = 0;
+
+void done()
+{
+
+ dummy++;
+
+}
+
+void check(void)
+{
+ if(achar0 != achar1)
+ failures++;
+}
+
+void shift_left_1(void)
+{
+
+ achar0 <<= 1;
+
+ check();
+}
+
+void shift_left_2(void)
+{
+
+ achar0 <<= 2;
+
+ if(achar0 != achar1)
+ failures++;
+}
+
+
+void shift_left_3(void)
+{
+
+ achar0 <<= 3;
+
+ if(achar0 != achar1)
+ failures++;
+}
+
+void shift_left_4(void)
+{
+
+ achar0 <<= 4;
+
+ if(achar0 != achar1)
+ failures++;
+}
+
+void shift_left_5(void)
+{
+
+ achar0 <<= 5;
+
+ if(achar0 != achar1)
+ failures++;
+}
+
+void shift_left_6(void)
+{
+
+ achar0 <<= 6;
+
+ if(achar0 != achar1)
+ failures++;
+}
+
+void shift_left_7(void)
+{
+
+ achar0 <<= 7;
+
+ if(achar0 != achar1)
+ failures++;
+}
+
+void shift_right_1(void)
+{
+
+ achar0 >>= 1;
+
+ check();
+}
+
+void shift_right_2(void)
+{
+
+ achar0 >>= 2;
+
+ check();
+}
+
+void shift_right_3(void)
+{
+
+ achar0 >>= 3;
+
+ check();
+}
+
+void shift_right_4(void)
+{
+
+ achar0 >>= 4;
+
+ check();
+}
+
+void shift_right_5(void)
+{
+
+ achar0 >>= 5;
+
+ check();
+}
+
+void shift_right_6(void)
+{
+
+ achar0 >>= 6;
+
+ check();
+}
+
+void shift_right_7(void)
+{
+
+ achar0 >>= 7;
+
+ check();
+}
+
+
+void main(void)
+{
+
+ // call with both values zero
+ shift_left_1();
+
+ achar0 = 1;
+ achar1 = 2;
+ for(achar2=0; achar2<6; achar2++) {
+ shift_left_1();
+ achar1 <<=1;
+ }
+
+ achar0 = 1;
+ achar1 = 4;
+ shift_left_2();
+
+ achar0 = 1;
+ achar1 = 8;
+ shift_left_3();
+
+ achar0 = 1;
+ achar1 = 0x10;
+ shift_left_4();
+
+ achar0 = 1;
+ achar1 = 0x20;
+ shift_left_5();
+
+ achar0 = 1;
+ achar1 = 0x40;
+ shift_left_6();
+
+ achar0 = 1;
+ achar1 = 0x80;
+ shift_left_7();
+
+
+
+
+ achar0 = 2;
+ achar1 = 1;
+ shift_right_1();
+
+ achar0 = 4;
+ shift_right_2();
+
+ achar0 = 8;
+ shift_right_3();
+
+ achar0 = 0x10;
+ shift_right_4();
+
+ achar0 = 0x20;
+ shift_right_5();
+
+ achar0 = 0x40;
+ shift_right_6();
+
+ achar0 = 0x80;
+ achar1 = 0xff;
+ shift_right_7();
+
+ success=failures;
+ done();
+}