-#if 1
-/*-----------------------------------------------------------------*/
-/* genDataPointerGet - generates code when ptr offset is known */
-/*-----------------------------------------------------------------*/
-static void genDataPointerGet (operand *left,
- operand *result,
- iCode *ic)
-{
- int size , offset = 0;
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
-
- /* optimization - most of the time, left and result are the same
- * 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));
-
- 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++;
- }
-
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
-}
-#endif
-/*-----------------------------------------------------------------*/
-/* genNearPointerGet - pic14_emitcode for near pointer fetch */
-/*-----------------------------------------------------------------*/
-static void genNearPointerGet (operand *left,
- operand *result,
- iCode *ic)
-{
- asmop *aop = NULL;
- sym_link *ltype = operandType(left);
- sym_link *rtype = operandType(result);
- sym_link *retype= getSpec(rtype); /* bitfield type information */
- int direct = 0;
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
-
- aopOp(left,ic,FALSE);
-
- /* if left is rematerialisable and
- result is not bit variable type and
- the left is pointer to data space i.e
- lower 128 bytes of space */
- if (AOP_TYPE(left) == AOP_PCODE && //AOP_TYPE(left) == AOP_IMMD &&
- !IS_BITVAR(retype) &&
- DCL_TYPE(ltype) == POINTER) {
- genDataPointerGet (left,result,ic);
- return ;
- }
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp (result,ic,FALSE);
-
- /* Check if can access directly instead of via a pointer */
- if (PCOP(AOP(left))->type == PO_LITERAL && AOP_SIZE(result) == 1) {
- direct = 1;
- }
-
- /* If the pointer value is not in a the FSR then need to put it in */
- if (!AOP_INPREG(AOP(left)) && !direct) {
- /* otherwise get a free pointer register */
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (PCOP(AOP(result))->type == PO_LITERAL) /* XXX: check me */
- emitpcode(POC_MOVLW, popGet(AOP(left),0));
- else
- emitpcode(POC_MOVFW, popGet(AOP(left),0));
- emitpcode(POC_MOVWF, popCopyReg(&pc_fsr));
- }
-
-
-// sym_link *etype;
- /* if bitfield then unpack the bits */
- if (IS_BITFIELD(retype))
- genUnpackBits (result,left,"indf",direct?-1:POINTER,ifxForOp(IC_RESULT(ic),ic));
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- while(size--) {
- if (direct)
- emitpcode(POC_MOVWF,popGet(AOP(left),0));
- else
- emitpcode(POC_MOVFW,popCopyReg(&pc_indf));
- if (AOP_TYPE(result) == AOP_LIT) {
- emitpcode(POC_MOVLW,popGet(AOP(result),offset));
- } else {
- emitpcode(POC_MOVWF,popGet(AOP(result),offset));
- }
- if (size && !direct)
- emitpcode(POC_INCF,popCopyReg(&pc_fsr));
- offset++;
- }
- }
-
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- if size > 0 && this could be used again
- we have to point it back to where it
- belongs */
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (AOP_SIZE(result) > 1 &&
- !OP_SYMBOL(left)->remat &&
- ( OP_SYMBOL(left)->liveTo > ic->seq ||
- ic->depth )) {
- int size = AOP_SIZE(result) - 1;
- while (size--)
- emitpcode(POC_DECF, popCopyReg(&pc_fsr));
- }
- }
-
- /* done */
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
-
-}
-
-/*-----------------------------------------------------------------*/
-/* genPagedPointerGet - pic14_emitcode for paged pointer fetch */
-/*-----------------------------------------------------------------*/
-static void genPagedPointerGet (operand *left,
- operand *result,
- iCode *ic)
-{
- asmop *aop = NULL;
- regs *preg = NULL ;
- char *rname ;
- sym_link *rtype, *retype;
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- rtype = operandType(result);
- retype= getSpec(rtype);
-
- aopOp(left,ic,FALSE);
-
- /* if the value is already in a pointer register
- then don't need anything more */
- if (!AOP_INPREG(AOP(left))) {
- /* otherwise get a free pointer register */
- aop = newAsmop(0);
- preg = getFreePtr(ic,&aop,FALSE);
- pic14_emitcode("mov","%s,%s",
- preg->name,
- aopGet(AOP(left),0,FALSE,TRUE));
- rname = preg->name ;
- } else
- rname = aopGet(AOP(left),0,FALSE,FALSE);
-
- freeAsmop(left,NULL,ic,TRUE);
- aopOp (result,ic,FALSE);
-
- /* if bitfield then unpack the bits */
- if (IS_BITFIELD(retype))
- genUnpackBits (result,left,rname,PPOINTER,0);
- else {
- /* we have can just get the values */
- int size = AOP_SIZE(result);
- int offset = 0 ;
-
- while (size--) {
-
- pic14_emitcode("movx","a,@%s",rname);
- aopPut(AOP(result),"a",offset);
-
- offset++ ;
-
- if (size)
- pic14_emitcode("inc","%s",rname);
- }
- }
-
- /* now some housekeeping stuff */
- if (aop) {
- /* we had to allocate for this iCode */
- freeAsmop(NULL,aop,ic,TRUE);
- } else {
- /* we did not allocate which means left
- already in a pointer register, then
- if size > 0 && this could be used again
- we have to point it back to where it
- belongs */
- if (AOP_SIZE(result) > 1 &&
- !OP_SYMBOL(left)->remat &&
- ( OP_SYMBOL(left)->liveTo > ic->seq ||
- ic->depth )) {
- int size = AOP_SIZE(result) - 1;
- while (size--)
- pic14_emitcode("dec","%s",rname);
- }
- }
-
- /* done */
- freeAsmop(result,NULL,ic,TRUE);
-
-
-}
-
-/*-----------------------------------------------------------------*/
-/* genFarPointerGet - gget value from far space */
-/*-----------------------------------------------------------------*/
-static void genFarPointerGet (operand *left,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- aopOp(left,ic,FALSE);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- pic14_emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- pic14_emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- pic14_emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- pic14_emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITFIELD(retype))
- genUnpackBits(result,left,"dptr",FPOINTER,0);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- pic14_emitcode("movx","a,@dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- pic14_emitcode("inc","dptr");
- }
- }
-
- freeAsmop(result,NULL,ic,TRUE);
-}
-#if 0
-/*-----------------------------------------------------------------*/
-/* genCodePointerGet - get value from code space */
-/*-----------------------------------------------------------------*/
-static void genCodePointerGet (operand *left,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- aopOp(left,ic,FALSE);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD)
- pic14_emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- else { /* we need to get it byte by byte */
- pic14_emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
- pic14_emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
- if (options.model == MODEL_FLAT24)
- {
- pic14_emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
- }
- }
- }
- /* so dptr know contains the address */
- freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
-
- /* if bit then unpack */
- if (IS_BITFIELD(retype))
- genUnpackBits(result,left,"dptr",CPOINTER,0);
- else {
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while (size--) {
- pic14_emitcode("clr","a");
- pic14_emitcode("movc","a,@a+dptr");
- aopPut(AOP(result),"a",offset++);
- if (size)
- pic14_emitcode("inc","dptr");
- }
- }
-
- freeAsmop(result,NULL,ic,TRUE);
-}
-#endif
-/*-----------------------------------------------------------------*/
-/* genGenPointerGet - gget value from generic pointer space */
-/*-----------------------------------------------------------------*/
-static void genGenPointerGet (operand *left,
- operand *result, iCode *ic)
-{
- int size, offset ;
- sym_link *retype = getSpec(operandType(result));
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
-
- DEBUGpic14_AopType(__LINE__,left,NULL,result);
-
- /* if the operand is already in dptr
- then we do nothing else we move the value to dptr */
- // if (AOP_TYPE(left) != AOP_STR) {
- /* if this is remateriazable */
- if (AOP_TYPE(left) == AOP_IMMD) {
- pic14_emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
- pic14_emitcode("mov","b,#%d",pointerCode(retype));
- }
- else { /* we need to get it byte by byte */
-
- emitpcode(POC_MOVFW,popGet(AOP(left),0));
- emitpcode(POC_MOVWF,popCopyReg(&pc_fsr));
-
- size = AOP_SIZE(result);
- offset = 0 ;
-
- while(size--) {
- emitpcode(POC_MOVFW,popCopyReg(&pc_indf));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset++));
- if(size)
- emitpcode(POC_INCF,popCopyReg(&pc_fsr));
- }
- goto release;
- }
- //}
- /* so dptr know contains the address */
-
- /* if bit then unpack */
- //if (IS_BITFIELD(retype))
- // genUnpackBits(result,"dptr",GPOINTER);
-
-release:
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
-
+/*-----------------------------------------------------------------*/
+/* genNearPointerSet - pic14_emitcode for near pointer put */
+/*-----------------------------------------------------------------*/
+static void genNearPointerSet (operand *right,
+ operand *result,
+ iCode *ic)
+{
+ asmop *aop = NULL;
+ sym_link *ptype = operandType(result);
+ sym_link *retype = getSpec(operandType(right));
+ sym_link *letype = getSpec(ptype);
+ int direct = 0;
+
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ aopOp(result,ic,FALSE);
+
+#if 1
+ /* if the result is rematerializable &
+ in data space & not a bit variable */
+ //if (AOP_TYPE(result) == AOP_IMMD &&
+ if (AOP_TYPE(result) == AOP_PCODE &&
+ PIC_IS_DATA_PTR(ptype) &&
+ !IS_BITVAR (retype) &&
+ !IS_BITVAR (letype)) {
+ genDataPointerSet (right,result,ic);
+ freeAsmop(result,NULL,ic,TRUE);
+ return;
+ }
+#endif
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ aopOp(right,ic,FALSE);
+ DEBUGpic14_AopType(__LINE__,NULL,right,result);
+
+ /* Check if can access directly instead of via a pointer */
+ if (PCOP(AOP(result))->type == PO_LITERAL && AOP_SIZE(right) == 1) {
+ direct = 1;
+ }
+
+ if (IS_BITFIELD (letype))
+ {
+ genPackBits (letype, result, right, direct?-1:POINTER);
+ return;
+ }
+
+ /* If the pointer value is not in a the FSR then need to put it in */
+ /* Must set/reset IRP bit for use with FSR. */
+ /* Note only do this once - assuming that never need to cross a bank boundary at address 0x100. */
+ if (!direct)
+ setup_fsr (result);
+
+ {
+ /* we have can just get the values */
+ int size = AOP_SIZE(right);
+ int offset = 0 ;
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ while (size--) {
+ char *l = aopGet(AOP(right),offset,FALSE,TRUE);
+ if (*l == '@' ) {
+ emitpcode(POC_MOVFW,popCopyReg(&pc_indf));
+ } else {
+ if (AOP_TYPE(right) == AOP_LIT) {
+ emitpcode(POC_MOVLW,popGet(AOP(right),offset));
+ } else {
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset));
+ }
+ if (direct)
+ emitpcode(POC_MOVWF,popGet(AOP(result),0));
+ else
+ emitpcode(POC_MOVWF,popCopyReg(&pc_indf));
+ }
+ if (size && !direct)
+ emitpcode(POC_INCF,popCopyReg(&pc_fsr));
+ offset++;
+ }
+ }
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* now some housekeeping stuff */
+ if (aop) {
+ /* we had to allocate for this iCode */
+ freeAsmop(NULL,aop,ic,TRUE);
+ } else {
+ /* we did not allocate which means left
+ already in a pointer register, then
+ if size > 0 && this could be used again
+ we have to point it back to where it
+ belongs */
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if (AOP_SIZE(right) > 1 &&
+ !OP_SYMBOL(result)->remat &&
+ ( OP_SYMBOL(result)->liveTo > ic->seq ||
+ ic->depth )) {
+ int size = AOP_SIZE(right) - 1;
+ while (size--)
+ emitpcode(POC_DECF, popCopyReg(&pc_fsr));
+ }
+ }
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* done */
+
+ freeAsmop(right,NULL,ic,TRUE);
+ freeAsmop(result,NULL,ic,TRUE);