static int debug_verbose=1;
static int optimized_for_speed = 0;
+/* 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.
+*/
+static int max_key=0;
unsigned int pic14aopLiteral (value *val, int offset);
+const char *AopType(short type);
/* this is the down and dirty file with all kinds of
kludgy & hacky stuff. This is what it is all about
return -1;
}
-static void emitpLabel(int key)
-{
- addpCode2pBlock(pb,newpCodeLabel(key));
-}
-
-void emitpcode(PIC_OPCODE poc, pCodeOp *pcop)
-{
-
- addpCode2pBlock(pb,newpCode(poc,pcop));
-
-}
-/*-----------------------------------------------------------------*/
-/* pic14_emitcode - writes the code into a file : for now it is simple */
-/*-----------------------------------------------------------------*/
-void pic14_emitcode (char *inst,char *fmt, ...)
+void DEBUGpic14_emitcode (char *inst,char *fmt, ...)
{
va_list ap;
char lb[INITIAL_INLINEASM];
char *lbp = lb;
+ if(!debug_verbose)
+ return;
+
va_start(ap,fmt);
if (inst && *inst) {
lineCurr->isInline = _G.inLine;
lineCurr->isDebug = _G.debugLine;
- if(debug_verbose)
- addpCode2pBlock(pb,newpCodeCharP(lb));
+ addpCode2pBlock(pb,newpCodeCharP(lb));
va_end(ap);
}
-void DEBUGpic14_emitcode (char *inst,char *fmt, ...)
+
+static void emitpLabel(int key)
+{
+ addpCode2pBlock(pb,newpCodeLabel(key));
+}
+
+void emitpcode(PIC_OPCODE poc, pCodeOp *pcop)
+{
+
+ if(pcop)
+ addpCode2pBlock(pb,newpCode(poc,pcop));
+ else
+ DEBUGpic14_emitcode(";","%s ignoring NULL pcop",__FUNCTION__);
+}
+
+void emitpcodeNULLop(PIC_OPCODE poc)
+{
+
+ addpCode2pBlock(pb,newpCode(poc,NULL));
+
+}
+
+/*-----------------------------------------------------------------*/
+/* pic14_emitcode - writes the code into a file : for now it is simple */
+/*-----------------------------------------------------------------*/
+void pic14_emitcode (char *inst,char *fmt, ...)
{
va_list ap;
char lb[INITIAL_INLINEASM];
char *lbp = lb;
- if(!debug_verbose)
- return;
-
va_start(ap,fmt);
if (inst && *inst) {
lineCurr->isInline = _G.inLine;
lineCurr->isDebug = _G.debugLine;
- addpCode2pBlock(pb,newpCodeCharP(lb));
+ if(debug_verbose)
+ addpCode2pBlock(pb,newpCodeCharP(lb));
va_end(ap);
}
/*-----------------------------------------------------------------*/
pCodeOp *popGetLabel(unsigned int key)
{
+
+ DEBUGpic14_emitcode ("; ***","%s key=%d, label offset %d",__FUNCTION__,key, labelOffset);
+
+ if(key>max_key)
+ max_key = key;
+
return newpCodeOpLabel(key+100+labelOffset);
}
case AOP_DPTR:
case AOP_DPTR2:
case AOP_ACC:
- DEBUGpic14_emitcode(";8051 legacy","%d",__LINE__);
- pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
- pcop->type = PO_SFR_REGISTER;
+ DEBUGpic14_emitcode(";8051 legacy","%d type = %s",__LINE__,AopType(aop->type));
+ //pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
+ //pcop->type = PO_SFR_REGISTER;
- PCOR(pcop)->rIdx = -1;
- PCOR(pcop)->r = NULL;
+ //PCOR(pcop)->rIdx = -1;
+ //PCOR(pcop)->r = NULL;
// Really nasty hack to check for temporary registers
- pcop->name = Safe_strdup("BAD_REGISTER");
+ //pcop->name = Safe_strdup("BAD_REGISTER");
- return pcop;
+ return NULL;
case AOP_IMMD:
DEBUGpic14_emitcode(";","%d",__LINE__);
symbol *sym;
sym_link *fetype;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- labelOffset += FUNCTION_LABEL_INC;
+ DEBUGpic14_emitcode ("; ***","%s %d previous max_key=%d ",__FUNCTION__,__LINE__,max_key);
+
+ labelOffset += (max_key+1);
+ max_key=0;
_G.nRegsSaved = 0;
/* create the function header */
}
pic14_emitcode ("return","");
- emitpcode(POC_RETURN,NULL);
+ emitpcodeNULLop(POC_RETURN);
/* Mark the end of a function */
addpCode2pBlock(pb,newpCodeFunction(NULL,NULL));
offset = 0 ;
while (size--) {
pic14_emitcode(";","%d",__LINE__);
- aopPut(AOP(result),
- aopGet(AOP(right),offset,FALSE,FALSE),
- offset);
- offset++;
+ /* aopPut(AOP(result),
+ aopGet(AOP(right),offset,FALSE,FALSE),
+ offset); */
+ emitpcode(POC_MOVFW, popGet(AOP(right),offset,FALSE,FALSE));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
+ offset++;
}
/* now depending on the sign of the destination */
}
} else {
/* we need to extend the sign :{ */
- //char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,FALSE,FALSE);
- //MOVA(l);
- emitpcode(POC_CLRW, NULL);
- emitpcode(POC_BTFSC, popGet(AOP(right),0,FALSE,FALSE));
+ emitpcodeNULLop(POC_CLRW);
+
+ if(offset)
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),offset-1,FALSE,FALSE),7,0));
+ else
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),offset,FALSE,FALSE),7,0));
+
emitpcode(POC_MOVLW, popGetLit(0xff));
pic14_emitcode("clrw","");
pcc->pc.destruct = genericDestruct;
pcc->pc.print = genericPrint;
- pcc->comment = Safe_strdup(cP);
+ if(cP)
+ pcc->comment = Safe_strdup(cP);
+ else
+ pcc->comment = NULL;
return ( (pCode *)pcc);
pcl->key = key;
+ pcl->label = NULL;
if(key>0) {
sprintf(s,"_%05d_DS_",key);
- pcl->label = Safe_strdup(s);
- } else
- pcl->label = NULL;
+ if(s)
+ pcl->label = Safe_strdup(s);
+ }
+
return ( (pCode *)pcl);
{
pCode *pc = newpCodeLabel(-1);
- PCL(pc)->label = Safe_strdup(str);
+ if(str)
+ PCL(pc)->label = Safe_strdup(str);
+ else
+ PCL(pc)->label = NULL;
return pc;
}
pcop = Safe_calloc(1,sizeof(pCodeOpLabel) );
pcop->type = PO_LABEL;
+ pcop->name = NULL;
if(key>0) {
sprintf(s,"_%05d_DS_",key);
- pcop->name = Safe_strdup(s);
- } else
- pcop->name = NULL;
+ if(s)
+ pcop->name = Safe_strdup(s);
+ }
+
((pCodeOpLabel *)pcop)->key = key;
pcop = Safe_calloc(1,sizeof(pCodeOpLit) );
pcop->type = PO_LITERAL;
+ pcop->name = NULL;
if(lit>=0) {
sprintf(s,"0x%02x",lit);
- pcop->name = Safe_strdup(s);
- } else
- pcop->name = NULL;
+ if(s)
+ pcop->name = Safe_strdup(s);
+ }
+
((pCodeOpLit *)pcop)->lit = lit;
pcop = Safe_calloc(1,sizeof(pCodeOpBit) );
pcop->type = PO_BIT;
- pcop->name = Safe_strdup(s);
+ if(s)
+ pcop->name = Safe_strdup(s);
+ else
+ pcop->name = NULL;
PCOB(pcop)->bit = bit;
PCOB(pcop)->inBitSpace = inBitSpace;
default:
pcop = Safe_calloc(1,sizeof(pCodeOp) );
pcop->type = type;
- pcop->name = Safe_strdup(name);
+ if(name)
+ pcop->name = Safe_strdup(name);
+ else
+ pcop->name = NULL;
}
return pcop;
r1->rIdx, newreg->rIdx);
r2->rIdx = newreg->rIdx;
//if(r2->name) free(r2->name);
- r2->name = Safe_strdup(newreg->name);
+ if(newreg->name)
+ r2->name = Safe_strdup(newreg->name);
+ else
+ r2->name = NULL;
newreg->isFree = 0;
newreg->wasUsed = 1;
}
r1->rIdx, newreg->rIdx);
r2->rIdx = newreg->rIdx;
//if(r2->name) free(r2->name);
- r2->name = Safe_strdup(newreg->name);
+ if(newreg->name)
+ r2->name = Safe_strdup(newreg->name);
+ else
+ r2->name = NULL;
newreg->isFree = 0;
newreg->wasUsed = 1;
}