#include "pcode.h"
#include "gen.h"
-
extern void genUMult8X8_16 (operand *, operand *,operand *,pCodeOpReg *);
extern void genSMult8X8_16 (operand *, operand *,operand *,pCodeOpReg *);
void genMult8X8_8 (operand *, operand *,operand *);
unsigned int pic14aopLiteral (value *val, int offset);
const char *AopType(short type);
-#define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff)
+#define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0x00ff)
/* this is the down and dirty file with all kinds of
kludgy & hacky stuff. This is what it is all about
char lb[INITIAL_INLINEASM];
char *lbp = lb;
- if(!debug_verbose)
+ if(!debug_verbose && !options.debug)
return;
va_start(ap,fmt);
va_end(ap);
}
+static void Safe_vsnprintf (char *buf, size_t size, const char *fmt, va_list ap)
+{
+#if defined (HAVE_VSNPRINTF)
+ vsnprintf (buf, size, fmt, ap);
+#elif defined (HAVE_VSPRINTF)
+ vsprintf (buf, size, fmt, ap);
+ if (strlen (buf) >= size)
+ {
+ fprintf (stderr, "Safe_vsnprintf: buffer (size %u) has overflown\n", size);
+ }
+#elif defined (HAVE_SNPRINTF)
+ snprintf (buf, size, "vs(n)printf required");
+#elif defined (HAVE_SRINTF)
+ sprintf (buf, "vs(n)printf required");
+ if (strlen (buf) >= size)
+ {
+ fprintf (stderr, "Safe_vsnprintf: buffer (size %u) has overflown\n", size);
+ }
+#else
+ assert ( !"neither vsnprintf nor vsprintf is present -- unable to proceed" );
+#endif
+}
+
+void emitpComment (const char *fmt, ...)
+{
+ va_list va;
+ char buffer[4096];
+
+ va_start (va, fmt);
+ if (pb) {
+ Safe_vsnprintf (buffer, 4096, fmt, va);
+ //fprintf (stderr, "%s\n" ,buffer);
+ addpCode2pBlock (pb, newpCodeCharP (buffer));
+ }
+ va_end (va);
+}
void emitpLabel(int key)
{
//DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* offset is greater than
size then zero */
+
+ assert (offset >= 0 && offset < aop->size);
if (offset > (aop->size - 1) &&
aop->type != AOP_LIT)
*/
case AOP_PCODE:
- DEBUGpic14_emitcode(";","popGet AOP_PCODE (%s) %d %s",pCodeOpType(aop->aopu.pcop),
+ pcop = NULL;
+ DEBUGpic14_emitcode(";","popGet AOP_PCODE (%s + %i) %d %s",pCodeOpType(aop->aopu.pcop), offset,
__LINE__,
((aop->aopu.pcop->name)? (aop->aopu.pcop->name) : "no name"));
- pcop = pCodeOpCopy(aop->aopu.pcop);
- PCOI(pcop)->offset = offset;
+ emitpComment ("popGet; name %s, offset: %i\n", aop->aopu.pcop->name, offset);
+ switch (aop->aopu.pcop->type)
+ {
+ case PO_IMMEDIATE:
+ pcop = pCodeOpCopy (aop->aopu.pcop);
+ /* usually we want to access the memory at "<symbol> + offset" (using ->index),
+ * but sometimes we want to access the high byte of the symbol's address (using ->offset) */
+ PCOI(pcop)->index += offset;
+ //PCOI(pcop)->offset = 0;
+ break;
+ case PO_DIR:
+ pcop = pCodeOpCopy (aop->aopu.pcop);
+ PCOR(pcop)->instance = offset;
+ break;
+ default:
+ assert ( !"unhandled pCode type" );
+ break;
+ } // switch
return pcop;
}
"popGet got unsupported aop->type");
exit(0);
}
+
+/*-----------------------------------------------------------------*/
+/* popGetAddr - access the low/high word of a symbol (immediate) */
+/* (for non-PO_IMMEDIATEs this is the same as poGet) */
+/*-----------------------------------------------------------------*/
+pCodeOp *popGetAddr (asmop *aop, int offset)
+{
+ if (aop->type == AOP_PCODE && aop->aopu.pcop->type == PO_IMMEDIATE)
+ {
+ pCodeOp *pcop = aop->aopu.pcop;
+ emitpComment ("popGet; name %s, offset: %i\n", pcop->name, offset);
+ pcop = pCodeOpCopy (pcop);
+ /* usually we want to access the memory at "<symbol> + offset" (using ->index),
+ * but sometimes we want to access the high byte of the symbol's address (using ->offset) */
+ PCOI(pcop)->offset += offset;
+ return pcop;
+ } else {
+ return popGet (aop, offset);
+ }
+}
+
/*-----------------------------------------------------------------*/
/* aopPut - puts a string for a aop */
/*-----------------------------------------------------------------*/
{
symbol *tlbl;
int size;
+
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* assign asmOps to operand & result */
operand *left, *result;
int size, offset=0;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp((left = IC_LEFT(ic)),ic,FALSE);
int size ,offset =0 ;
char *l;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* for this we just need to flip the
first it then copy the rest in place */
int size, i;
sym_link *optype, *rtype;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* assign asmops */
bitVect *rsave;
sym_link *dtype;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* look for call */
for (ic = lic ; ic ; ic = ic->next)
int i;
bitVect *rsave;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* find the registers in use at this time
and push them away to safety */
{
int size = AOP_SIZE(oper);
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
DEBUGpic14_AopType(__LINE__,oper,NULL,NULL);
/*-----------------------------------------------------------------*/
static void genIpush (iCode *ic)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__);
#if 0
/*-----------------------------------------------------------------*/
static void genIpop (iCode *ic)
{
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__);
#if 0
int size,offset ;
/*-----------------------------------------------------------------*/
static void unsaverbank (int bank,iCode *ic,bool popPsw)
{
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__);
#if 0
int i;
/*-----------------------------------------------------------------*/
static void saverbank (int bank, iCode *ic, bool pushPsw)
{
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__);
#if 0
int i;
unsigned char *name;
int isExtern;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if caller saves & we have not saved then */
pCodeOp *pcop;
operand *left;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if caller saves & we have not saved then */
if (!ic->regsSaved)
static int resultRemat (iCode *ic)
{
// DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ FENTRY;
+
if (SKIP_IC(ic) || ic->op == IFX)
return 0;
symbol *sym;
sym_link *ftype;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d curr label offset=%dprevious max_key=%d ",__FUNCTION__,__LINE__,labelOffset,max_key);
labelOffset += (max_key+4);
{
symbol *sym = OP_SYMBOL(IC_LEFT(ic));
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if (IFFUNC_ISREENT(sym->type) || options.stackAuto)
{
int size,offset = 0 , pushed = 0;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if we have no return value then
just generate the "ret" */
AOP(IC_LEFT(ic))->aopu.pcop->type == PO_IMMEDIATE) ||
( (AOP(IC_LEFT(ic))->type) == AOP_IMMD) ||
( (AOP(IC_LEFT(ic))->type) == AOP_LIT) ) {
- emitpcode(POC_MOVLW, popGet(AOP(IC_LEFT(ic)),offset));
+ emitpcode(POC_MOVLW, popGetAddr(AOP(IC_LEFT(ic)),offset));
}else {
emitpcode(POC_MOVFW, popGet(AOP(IC_LEFT(ic)),offset));
}
/*-----------------------------------------------------------------*/
static void genLabel (iCode *ic)
{
+ FENTRY;
+
/* special case never generate */
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if (IC_LABEL(ic) == entryLabel)
//tsd
static void genGoto (iCode *ic)
{
+ FENTRY;
+
emitpcode(POC_GOTO,popGetLabel(IC_LABEL(ic)->key));
pic14_emitcode ("goto","_%05d_DS_",(IC_LABEL(ic)->key+100)+labelOffset);
}
operand *right,
operand *result)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(!pic14_sameRegs(AOP(result),AOP(right)))
// symbol *lbl ;
int size,offset;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
DEBUGpic14_AopType(__LINE__,left,right,result);
DEBUGpic14_AopTypeSign(__LINE__,left,right,result);
operand *right = IC_RIGHT(ic);
operand *result= IC_RESULT(ic);
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* assign the amsops */
aopOp (left,ic,FALSE);
char *l;
+ FENTRY;
+
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* the result must be bit */
pic14_emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
symbol *lbl ;
int size,offset;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
size = AOP_SIZE(result) - 1;
offset = 1;
operand *right = IC_RIGHT(ic);
operand *result= IC_RESULT(ic);
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* assign the amsops */
aopOp (left,ic,FALSE);
char *l;
+ FENTRY;
/* the result must be bit */
pic14_emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
l = aopGet(AOP(left),0,FALSE,FALSE);
char *l ;
symbol *lbl ;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* signed or unsigned */
if (SPEC_USIGN(opetype)) {
operand *right = IC_RIGHT(ic);
operand *result= IC_RESULT(ic);
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* assign the amsops */
aopOp (left,ic,FALSE);
static void genIfxJump (iCode *ic, char *jval)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if true label then we jump if condition
supplied is true */
/*-----------------------------------------------------------------*/
static void genSkip(iCode *ifx,int status_bit)
{
+ FENTRY;
if(!ifx)
return;
/*-----------------------------------------------------------------*/
static void genSkipc(resolvedIfx *rifx)
{
+ FENTRY;
if(!rifx)
return;
/*-----------------------------------------------------------------*/
static void genSkipz2(resolvedIfx *rifx, int invert_condition)
{
+ FENTRY;
if(!rifx)
return;
/*-----------------------------------------------------------------*/
static void genSkipz(iCode *ifx, int condition)
{
+ FENTRY;
if(!ifx)
return;
/*-----------------------------------------------------------------*/
static void genSkipCond(resolvedIfx *rifx,operand *op, int offset, int bit)
{
+ FENTRY;
if(!rifx)
return;
resolvedIfx rFalseIfx;
// resolvedIfx rTrueIfx;
symbol *truelbl;
+
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/*
if(ifx) {
sym_link *letype , *retype;
int sign ;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
left = IC_LEFT(ic);
right= IC_RIGHT(ic);
sym_link *letype , *retype;
int sign ;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
left = IC_LEFT(ic);
right= IC_RIGHT(ic);
{
int i;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d, lit = %d",__FUNCTION__,__LINE__,lit);
if( (lit&0xff) == 0)
i=1;
else
i=0;
+ emitpComment ("lit: %i, byte: %i, offset: %i, i: %i\n", lit, BYTEofLONG(lit,i), offset, i);
switch( BYTEofLONG(lit,i)) {
case 0:
emitpcode(POC_MOVFW,popGet(AOP(op),offset+i));
i ^= 1;
+ emitpComment ("lit: %i, byte: %i, offset: %i, i: %i\n", lit, BYTEofLONG(lit,i), offset, i);
switch( BYTEofLONG(lit,i)) {
case 0:
emitpcode(POC_IORFW,popGet(AOP(op),offset+i));
symbol *lbl;
unsigned long lit = 0L;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
DEBUGpic14_AopType(__LINE__,left,right,result);
if(result)
unsigned long lit = 0L;
int size,offset=0;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(ifx)
/*-----------------------------------------------------------------*/
static iCode *ifxForOp ( operand *op, iCode *ic )
{
+ FENTRY;
/* if true symbol then needs to be assigned */
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if (IS_TRUE_SYMOP(op))
operand *left,*right, *result;
/* symbol *tlbl; */
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* note here that && operations that are in an
if statement are taken away by backPatchLabels
/* note here that || operations that are in an
if statement are taken away by backPatchLabels
only those used in arthmetic operations remain */
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp((left=IC_LEFT(ic)),ic,FALSE);
aopOp((right=IC_RIGHT(ic)),ic,FALSE);
0x10000000L,0x20000000L,0x40000000L,0x80000000L};
int idx;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
for(idx = 0; idx < 32; idx++)
if(lit == pw[idx])
/*-----------------------------------------------------------------*/
static void continueIfTrue (iCode *ic)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(IC_TRUE(ic))
pic14_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
/*-----------------------------------------------------------------*/
static void jumpIfTrue (iCode *ic)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(!IC_TRUE(ic))
pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
/*-----------------------------------------------------------------*/
static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
{
+ FENTRY;
// ugly but optimized by peephole
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(IC_TRUE(ic)){
int bytelit = 0;
resolvedIfx rIfx;
-
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp((left = IC_LEFT(ic)),ic,FALSE);
aopOp((right= IC_RIGHT(ic)),ic,FALSE);
int size, offset=0;
unsigned long lit = 0L;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp((left = IC_LEFT(ic)),ic,FALSE);
int size, offset=0;
unsigned long lit = 0L;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp((left = IC_LEFT(ic)),ic,FALSE);
{
char *buffer, *bp, *bp1;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
_G.inLine += (!options.asmpeep);
operand *left , *result ;
int size, offset = 0, same;
+ FENTRY;
/* rotate right with carry */
left = IC_LEFT(ic);
result=IC_RESULT(ic);
int size, offset = 0;
int same;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* rotate right with carry */
left = IC_LEFT(ic);
aopOp (left,ic,FALSE);
aopOp (result,ic,FALSE);
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* get the highest order byte into a */
MOVA(aopGet(AOP(left),AOP_SIZE(left) - 1,FALSE,FALSE));
/*-----------------------------------------------------------------*/
static void AccRol (operand *op,int offset,int shCount)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
shCount &= 0x0007; // shCount : 0..7
switch(shCount){
/*-----------------------------------------------------------------*/
static void AccLsh (operand *op,int offset,int shCount)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(shCount != 0){
/*
/*-----------------------------------------------------------------*/
static void AccRsh (operand *op,int offset,int shCount)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(shCount != 0){
if(shCount == 1){
{
int same;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);
{
int same;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);
int same;
// char *l;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
same = ((left == result) || (AOP(left) == AOP(result))) && (offl==offr);
operand *result, int offr)
{
char *l;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(!pic14_sameRegs(AOP(left),AOP(result)) || (offl != offr)){
l = aopGet(AOP(left),offl,FALSE,FALSE);
static void shiftL2Left2Result (operand *left, int offl,
operand *result, int offr, int shCount)
{
-
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
{
int same=0;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
same = pic14_sameRegs(AOP(result), AOP(left));
static void shiftLLeftOrResult (operand *left, int offl,
operand *result, int offr, int shCount)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
/* shift left accumulator */
static void shiftRLeftOrResult (operand *left, int offl,
operand *result, int offr, int shCount)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
/* shift right accumulator */
/*-----------------------------------------------------------------*/
static void genlshOne (operand *result, operand *left, int shCount)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
shiftL1Left2Result(left, LSB, result, LSB, shCount);
}
{
int size;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
size = pic14_getDataSize(result);
char *l;
int size = AOP_SIZE(result);
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(size >= LSB+offr){
l = aopGet(AOP(left),LSB,FALSE,FALSE);
{
int size;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
size = AOP_SIZE(result);
int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
int size;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
freeAsmop(right,NULL,ic,TRUE);
int offset = 0;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(!reg)
symbol *tlbl , *tlbl1;
pCodeOp *pctemp;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
right = IC_RIGHT(ic);
static void genrshOne (operand *result, operand *left,
int shCount, int sign)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
shiftR1Left2Result(left, LSB, result, LSB, shCount, sign);
}
static void genrshTwo (operand *result,operand *left,
int shCount, int sign)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if shCount >= 8 */
if (shCount >= 8) {
static void shiftRLong (operand *left, int offl,
operand *result, int sign)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(!sign)
pic14_emitcode("clr","c");
static void genrshFour (operand *result, operand *left,
int shCount, int sign)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if shifting more that 3 bytes */
if(shCount >= 24 ) {
int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
int lsize,res_size;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
freeAsmop(right,NULL,ic,TRUE);
/* we do it the hard way put the shift count in b
and loop thru preserving the sign */
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
right = IC_RIGHT(ic);
char *l;
symbol *tlbl, *tlbl1 ;
+ FENTRY;
/* if signed then we do it the hard way preserve the
sign bit moving it inwards */
retype = getSpec(operandType(IC_RESULT(ic)));
int blen; /* bitfield length */
int bstr; /* bitfield starting bit within byte */
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
etype = getSpec(operandType(result));
rsize = getSize (operandType (result));
return ;
}
-#if 0
+#if 1
/*-----------------------------------------------------------------*/
/* genDataPointerGet - generates code when ptr offset is known */
/*-----------------------------------------------------------------*/
static void genDataPointerGet (operand *left,
- operand *result,
- iCode *ic)
+ operand *result,
+ iCode *ic)
{
int size , offset = 0;
-
-
+
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
* address, but different types. for the pic code, we could omit
* the following
*/
-
aopOp(result,ic,TRUE);
+ if (pic14_sameRegs (AOP(left), AOP(result)))
+ return;
+
DEBUGpic14_AopType(__LINE__,left,NULL,result);
- emitpcode(POC_MOVFW, popGet(AOP(left),0));
+ //emitpcode(POC_MOVFW, popGet(AOP(left),0));
size = AOP_SIZE(result);
+ if (size > AOP_SIZE(left)) size = AOP_SIZE(left);
while (size--) {
+ emitpcode(POC_MOVFW, popGet(AOP(left),offset));
emitpcode(POC_MOVWF, popGet(AOP(result),offset));
offset++;
}
sym_link *retype= getSpec(rtype); /* bitfield type information */
int direct = 0;
-
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if (AOP_TYPE(left) == AOP_PCODE && //AOP_TYPE(left) == AOP_IMMD &&
!IS_BITVAR(retype) &&
DCL_TYPE(ltype) == POINTER) {
- //genDataPointerGet (left,result,ic);
+ genDataPointerGet (left,result,ic);
return ;
}
char *rname ;
sym_link *rtype, *retype;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
rtype = operandType(result);
int size, offset ;
sym_link *retype = getSpec(operandType(result));
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(left,ic,FALSE);
int size, offset ;
sym_link *retype = getSpec(operandType(result));
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(left,ic,FALSE);
aopOp(result,ic,FALSE);
PIC_OPCODE poc;
pCodeOp *pcop;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(left,ic,FALSE);
aopOp(result,ic,FALSE);
sym_link *type, *etype;
int p_type;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
left = IC_LEFT(ic);
static void
emitPtrByteGet (char *rname, int p_type, bool preserveAinB)
{
- switch (p_type)
+ FENTRY;
+ switch (p_type)
{
case IPOINTER:
case POINTER:
static void
emitPtrByteSet (char *rname, int p_type, char *src)
{
- switch (p_type)
+ FENTRY;
+ switch (p_type)
{
case IPOINTER:
case POINTER:
int bstr; /* bitfield starting bit within byte */
int litval; /* source literal value (if AOP_LIT) */
unsigned char mask; /* bitmask within current byte */
-
+
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
blen = SPEC_BLEN (etype);
/* SetIrp - Set IRP bit */
/*-----------------------------------------------------------------*/
void SetIrp(operand *result) {
+ FENTRY;
if (AOP_TYPE(result) == AOP_LIT) {
unsigned lit = (unsigned)operandLitValue(result);
emitpcode((lit&0x100)?POC_BSF:POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_IRP_BIT));
/* genDataPointerSet - remat pointer to data space */
/*-----------------------------------------------------------------*/
static void genDataPointerSet(operand *right,
- operand *result,
- iCode *ic)
+ operand *result,
+ iCode *ic)
{
int size, offset = 0 ;
char *l, buffer[256];
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(right,ic,FALSE);
// tsd, was l+1 - the underline `_' prefix was being stripped
while (size--) {
+ emitpComment ("%s:%u: size=%i, offset=%i", __FILE__,__LINE__, size, offset);
if (offset) {
sprintf(buffer,"(%s + %d)",l,offset);
- fprintf(stderr,"oops %s\n",buffer);
+ fprintf(stderr,"%s:%i: oops %s (%i, AOP_LIT=%i)\n",__FILE__,__LINE__,buffer, AOP_TYPE(right), AOP_LIT);
} else
sprintf(buffer,"%s",l);
lit = lit >> (8*offset);
if(lit&0xff) {
emitpcode(POC_MOVLW, popGetLit(lit&0xff));
- emitpcode(POC_MOVWF, popGet(AOP(result),0));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset));
} else {
- emitpcode(POC_CLRF, popGet(AOP(result),0));
+ emitpcode(POC_CLRF, popGet(AOP(result),offset));
}
} else {
emitpcode(POC_MOVFW, popGet(AOP(right),offset));
- emitpcode(POC_MOVWF, popGet(AOP(result),0));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset));
}
offset++;
int direct = 0;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(result,ic,FALSE);
char *rname , *l;
sym_link *retype;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
retype= getSpec(operandType(right));
int size, offset ;
sym_link *retype = getSpec(operandType(right));
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(result,ic,FALSE);
sym_link *retype = getSpec(operandType(right));
sym_link *letype = getSpec (ptype);
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(result,ic,FALSE);
sym_link *type, *etype;
int p_type;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
right = IC_RIGHT(ic);
operand *cond = IC_COND(ic);
int isbit =0;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(cond,ic,FALSE);
operand *right, *result, *left;
int size, offset ;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
result = IC_RESULT(ic);
right = IC_RIGHT(ic) ;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if they are the same */
symbol *jtab;
char *l;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
aopOp(IC_JTCOND(ic),ic,FALSE);
*/
static int genMixedOperation (iCode *ic)
{
+ FENTRY;
#if 0
operand *result = IC_RESULT(ic);
sym_link *ctype = operandType(IC_LEFT(ic));
operand *right = IC_RIGHT(ic);
int size, offset ;
+ FENTRY;
DEBUGpic14_emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
/* if they are equivalent then do nothing */
if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
DEBUGpic14_emitcode ("; ***","%d - result is const pointer",__LINE__);
if ((AOP_TYPE(right) == AOP_PCODE) && AOP(right)->aopu.pcop->type == PO_IMMEDIATE) {
- emitpcode(POC_MOVLW, popGet(AOP(right),0));
+ emitpcode(POC_MOVLW, popGetAddr(AOP(right),0));
emitpcode(POC_MOVWF, popGet(AOP(result),0));
- emitpcode(POC_MOVLW, popGet(AOP(right),1));
+ emitpcode(POC_MOVLW, popGetAddr(AOP(right),1));
emitpcode(POC_MOVWF, popGet(AOP(result),1));
if(AOP_SIZE(result) <2)
fprintf(stderr,"%d -- result is not big enough to hold a ptr\n",__LINE__);
DEBUGpic14_emitcode("; ***","%s %d - pointer cast3",__FUNCTION__,__LINE__);
if ((AOP_TYPE(right) == AOP_PCODE) &&
AOP(right)->aopu.pcop->type == PO_IMMEDIATE) {
- emitpcode(POC_MOVLW, popGet(AOP(right),offset));
+ emitpcode(POC_MOVLW, popGetAddr(AOP(right),offset));
emitpcode(POC_MOVWF, popGet(AOP(result),offset));
} else {
aopPut(AOP(result),
static int genDjnz (iCode *ic, iCode *ifx)
{
symbol *lbl, *lbl1;
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if (!ifx)
/*-----------------------------------------------------------------*/
static void genReceive (iCode *ic)
{
+ FENTRY;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if (isOperandInFarSpace(IC_RESULT(ic)) &&
static void
genDummyRead (iCode * ic)
{
+ FENTRY;
pic14_emitcode ("; genDummyRead","");
pic14_emitcode ("; not implemented","");
iCode *ic;
int cln = 0;
+ FENTRY;
lineHead = lineCurr = NULL;
pb = newpCodeChain(GcurMemmap,0,newpCodeCharP("; Starting pCode block"));
for (ic = lic ; ic ; ic = ic->next ) {
- DEBUGpic14_emitcode(";ic","");
- if ( cln != ic->lineno ) {
- if ( options.debug ) {
- debugFile->writeCLine (ic);
- }
- /*
- pic14_emitcode("#CSRC","%s %d",FileBaseName(ic->filename),ic->lineno);
- pic14_emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno,
- printCLine(ic->filename, ic->lineno));
- */
- if (!options.noCcodeInAsm) {
- addpCode2pBlock(pb,
- newpCodeCSource(ic->lineno,
- ic->filename,
- printCLine(ic->filename, ic->lineno)));
- }
-
- cln = ic->lineno ;
- }
+ //DEBUGpic14_emitcode(";ic","");
+ //fprintf (stderr, "in ic loop\n");
+ //pic14_emitcode ("", ";\t%s:%d: %s", ic->filename,
+ //ic->lineno, printCLine(ic->filename, ic->lineno));
- // if you want printILine too, look at ../mcs51/gen.c, i don't understand this :)
+ if (!options.noCcodeInAsm && (cln != ic->lineno)) {
+ cln = ic->lineno;
+ //fprintf (stderr, "%s\n", printCLine (ic->filename, ic->lineno));
+ emitpComment ("[C-SRC] %s:%d: %s", ic->filename, cln, printCLine (ic->filename, cln));
+ }
+ if (options.iCodeInAsm) {
+ emitpComment ("[ICODE] %s:%d: %s", ic->filename, ic->lineno, printILine (ic));
+ }
/* if the result is marked as
spilt and rematerializable or code for
this has already been generated then