* support/Util/SDCCerr.c: added warning "integer overflow in expression"
[fw/sdcc] / src / pic / gen.c
index c4a5a8bf023d0d7342aae133ad2ff34324ad7d9d..9979c39a4d4816033592a68a4ebd6f099b85a99a 100644 (file)
@@ -1,5 +1,5 @@
 /*-------------------------------------------------------------------------
-  SDCCgen51.c - source file for code generation for 8051
+  gen.c - source file for code generation for pic
   
   Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1998)
          and -  Jean-Louis VERN.jlvern@writeme.com (1999)
@@ -60,7 +60,7 @@ static int optimized_for_speed = 0;
 static int max_key=0;
 static int GpsuedoStkPtr=0;
 
-pCodeOp *popGetImmd(char *name, unsigned int offset, int index);
+pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func);
 unsigned int pic14aopLiteral (value *val, int offset);
 const char *AopType(short type);
 static iCode *ifxForOp ( operand *op, iCode *ic );
@@ -523,11 +523,19 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
 
     /* special case for a function */
     if (IS_FUNC(sym->type)) {   
+
+      sym->aop = aop = newAsmop(AOP_PCODE);
+      aop->aopu.pcop = popGetImmd(sym->rname,0,0,1);
+      PCOI(aop->aopu.pcop)->_const = IN_CODESPACE(space);
+      PCOI(aop->aopu.pcop)->_function = 1;
+      PCOI(aop->aopu.pcop)->index = 0;
+      aop->size = FPTRSIZE; 
+      /*
         sym->aop = aop = newAsmop(AOP_IMMD);    
-        //_ALLOC_ATOMIC(aop->aopu.aop_immd,strlen(sym->rname)+1);
        aop->aopu.aop_immd = Safe_calloc(1,strlen(sym->rname)+1);
         strcpy(aop->aopu.aop_immd,sym->rname);
         aop->size = FPTRSIZE; 
+      */
        DEBUGpic14_emitcode(";","%d size = %d, name =%s",__LINE__,aop->size,sym->rname);
         return aop;
     }
@@ -537,7 +545,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
     /* in which case DPTR gets the address */
     sym->aop = aop = newAsmop(AOP_PCODE);
 
-    aop->aopu.pcop = popGetImmd(sym->rname,0,0);
+    aop->aopu.pcop = popGetImmd(sym->rname,0,0,0);
     PCOI(aop->aopu.pcop)->_const = IN_CODESPACE(space);
     PCOI(aop->aopu.pcop)->index = 0;
 
@@ -592,7 +600,7 @@ static asmop *aopForRemat (operand *op) // x symbol *sym)
   }
 
   offset = OP_SYMBOL(IC_LEFT(ic))->offset;
-  aop->aopu.pcop = popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname,0,val);
+  aop->aopu.pcop = popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname,0,val,0);
   PCOI(aop->aopu.pcop)->_const = IS_PTR_CONST(operandType(op));
   PCOI(aop->aopu.pcop)->index = val;
 
@@ -1216,10 +1224,10 @@ pCodeOp *popGetLit(unsigned int lit)
 /*-----------------------------------------------------------------*/
 /* popGetImmd - asm operator to pcode immediate conversion         */
 /*-----------------------------------------------------------------*/
-pCodeOp *popGetImmd(char *name, unsigned int offset, int index)
+pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func)
 {
 
-  return newpCodeOpImmd(name, offset,index, 0);
+  return newpCodeOpImmd(name, offset,index, 0, is_func);
 }
 
 
@@ -1323,7 +1331,7 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname)
        
     case AOP_IMMD:
       DEBUGpic14_emitcode(";","%d",__LINE__);
-      return popGetImmd(aop->aopu.aop_immd,offset,0);
+      return popGetImmd(aop->aopu.aop_immd,offset,0,0);
 
     case AOP_DIR:
       return popRegFromString(aop->aopu.aop_dir, aop->size, offset);
@@ -1449,7 +1457,7 @@ void aopPut (asmop *aop, char *s, int offset)
              emitpcode(POC_CLRF,popGet(aop,offset));
              break;
            } else
-             emitpcode(POC_MOVLW,popGetImmd(s,offset,0));
+             emitpcode(POC_MOVLW,popGetImmd(s,offset,0,0));
          }
 
          emitpcode(POC_MOVWF,popGet(aop,offset));
@@ -9335,13 +9343,8 @@ static void genAssign (iCode *ic)
        emitpcode(POC_BTFSS, popGet(AOP(right),0));
        emitpcode(POC_INCF, popGet(AOP(result),0));
       }
-    } else if (AOP_TYPE(right) == AOP_IMMD) {
-           DEBUGpic14_emitcode ("; ***","%s  %d AOP_IMMD",__FUNCTION__,__LINE__);
-           emitpcode(POC_MOVLW, popGet(AOP(right),offset));
-           emitpcode(POC_MOVWF, popGet(AOP(result),offset));
     } else {
-  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-      emitpcode(POC_MOVFW, popGet(AOP(right),offset));
+      mov2w (AOP(right), offset);
       emitpcode(POC_MOVWF, popGet(AOP(result),offset));
     }
            
@@ -9868,10 +9871,10 @@ static int genDjnz (iCode *ic, iCode *ifx)
 /* genReceive - generate code for a receive iCode                  */
 /*-----------------------------------------------------------------*/
 static void genReceive (iCode *ic)
-{    
+{
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-  if (isOperandInFarSpace(IC_RESULT(ic)) && 
+  if (isOperandInFarSpace(IC_RESULT(ic)) &&
       ( OP_SYMBOL(IC_RESULT(ic))->isspilt ||
        IS_TRUE_SYMOP(IC_RESULT(ic))) ) {
 
@@ -9882,24 +9885,36 @@ static void genReceive (iCode *ic)
                                    fReturn[fReturnSizePic - offset - 1] : "acc"));
       offset++;
     }
-    aopOp(IC_RESULT(ic),ic,FALSE);  
+    aopOp(IC_RESULT(ic),ic,FALSE);
     size = AOP_SIZE(IC_RESULT(ic));
     offset = 0;
     while (size--) {
       pic14_emitcode ("pop","acc");
       aopPut (AOP(IC_RESULT(ic)),"a",offset++);
     }
-       
+
   } else {
     _G.accInUse++;
-    aopOp(IC_RESULT(ic),ic,FALSE);  
+    aopOp(IC_RESULT(ic),ic,FALSE);
     _G.accInUse--;
-    assignResultValue(IC_RESULT(ic));  
+    assignResultValue(IC_RESULT(ic));
   }
 
   freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
 }
 
+/*-----------------------------------------------------------------*/
+/* genDummyRead - generate code for dummy read of volatiles        */
+/*-----------------------------------------------------------------*/
+static void
+genDummyRead (iCode * ic)
+{
+  pic14_emitcode ("; genDummyRead","");
+  pic14_emitcode ("; not implemented","");
+
+  ic = ic;
+}
+
 /*-----------------------------------------------------------------*/
 /* genpic14Code - generate code for pic14 based controllers        */
 /*-----------------------------------------------------------------*/
@@ -10157,13 +10172,17 @@ void genpic14Code (iCode *lic)
            addSet(&_G.sendSet,ic);
            break;
 
+       case DUMMY_READ_VOLATILE:
+         genDummyRead (ic);
+         break;
+
        default :
            ic = ic;
         }
     }
-    
 
-    /* now we are ready to call the 
+
+    /* now we are ready to call the
        peep hole optimizer */
     if (!options.nopeep) {
       peepHole (&lineHead);