added peepholes 182.d (return 0.0), 256 (range check), 257 (do while), 258.a-f ...
[fw/sdcc] / src / pic16 / pcode.h
index 3ffbd3c7ba2a6ae5cf9d3647979c44c91f109586..f6ca309a61b3e2445bfa55cbfbf3e5d6ba00afdb 100644 (file)
@@ -157,6 +157,9 @@ typedef enum
   PO_SFR_REGISTER,   // A special function register (e.g. PORTA)
   PO_PCL,            // Program counter Low register
   PO_PCLATH,         // Program counter Latch high register
+  PO_PCLATU,         // Program counter Latch upper register
+  PO_PRODL,          // Product Register Low
+  PO_PRODH,          // Product Register High
   PO_LITERAL,        // A constant
   PO_REL_ADDR,       // A relative address
   PO_IMMEDIATE,      //  (8051 legacy)
@@ -265,6 +268,14 @@ typedef enum
   POC_SWAPF,
   POC_SWAPFW,
 //  POC_TRIS , // To be removed
+  POC_TBLRD,           // patch 15
+  POC_TBLRD_POSTINC,   //
+  POC_TBLRD_POSTDEC,   //
+  POC_TBLRD_PREINC,    //
+  POC_TBLWT,           //
+  POC_TBLWT_POSTINC,   //
+  POC_TBLWT_POSTDEC,   //
+  POC_TBLWT_PREINC,    // patch 15
   POC_TSTFSZ,
   POC_XORLW,
   POC_XORWF,
@@ -360,10 +371,18 @@ typedef struct pCodeOpLit
   int lit;
 } pCodeOpLit;
 
+typedef struct pCodeOpLit2
+{
+  pCodeOp pcop;
+  int lit;
+  pCodeOp *arg2;
+} pCodeOpLit2;
+
+
 typedef struct pCodeOpImmd
 {
   pCodeOp pcop;
-  int offset;           /* low,med, or high byte of immediat value */
+  int offset;           /* low,high or upper byte of immediate value */
   int index;            /* add this to the immediate value */
   unsigned _const:1;    /* is in code space    */
 
@@ -396,11 +415,6 @@ typedef struct pCodeOpReg2
   struct pBlock *pb;
 
   pCodeOp *pcop2;      // second memory operand
-/*
-  int rIdx1;
-  struct regs *r1;
-*/
-  
 } pCodeOpReg2;
 
 typedef struct pCodeOpRegBit
@@ -426,6 +440,8 @@ typedef struct pCodeOpWild
   pCodeOp *matched;       /* When a wild matches, we'll store a pointer to the
                           * opcode we matched */
 
+  pCodeOp *pcop2;        /* second operand if exists */
+
 } pCodeOpWild;
 
 
@@ -495,15 +511,6 @@ typedef struct pCodeCSource
     pCodeAsmDir
 **************************************************/
 
-typedef struct pCodeAsmDir
-{
-  pCode pc;
-  
-  char *directive;
-  char *arg;
-} pCodeAsmDir;
-
-
 /*************************************************
     pCodeFlow
 
@@ -604,14 +611,31 @@ typedef struct pCodeInstruction
   unsigned int isAccess:   1;   /* True if this instruction has an access RAM operand */
   unsigned int isFastCall: 1;   /* True if this instruction has a fast call/return mode select operand */
   unsigned int is2MemOp: 1;    /* True is second operand is a memory operand VR - support for MOVFF */
+  unsigned int is2LitOp: 1;    /* True if instruction takes 2 literal operands VR - support for LFSR */
 
   PIC_OPCODE inverted_op;      /* Opcode of instruction that's the opposite of this one */
   unsigned int inCond;   // Input conditions for this instruction
   unsigned int outCond;  // Output conditions for this instruction
 
+#define PCI_MAGIC      0x6e12
+  unsigned int pci_magic;      // sanity check for pci initialization
 } pCodeInstruction;
 
 
+
+/*************************************************
+    pCodeAsmDir
+**************************************************/
+
+typedef struct pCodeAsmDir
+{
+  pCodeInstruction pci;
+  
+  char *directive;
+  char *arg;
+} pCodeAsmDir;
+
+
 /*************************************************
     pCodeLabel
 **************************************************/
@@ -623,6 +647,7 @@ typedef struct pCodeLabel
 
   char *label;
   int key;
+  int force;           /* label cannot be optimized out */
 
 } pCodeLabel;
 
@@ -647,6 +672,8 @@ typedef struct pCodeFunction
 
   int  ncalled;    /* Number of times function is called */
 
+  int absblock;    /* hack to emulate a block pCodes in absolute position
+                      but not inside a function */
 } pCodeFunction;
 
 
@@ -834,7 +861,7 @@ typedef struct peepCommand {
 #define PCOR2(x)  ((pCodeOpReg2 *)(x))
 #define PCORB(x)  ((pCodeOpRegBit *)(x))
 #define PCOW(x)   ((pCodeOpWild *)(x))
-
+#define PCOW2(x)  (PCOW(PCOW(x)->pcop2))
 #define PBR(x)    ((pBranch *)(x))
 
 #define PCWB(x)   ((pCodeWildBlock *)(x))
@@ -858,16 +885,8 @@ typedef struct peepCommand {
 #define isCALL(x)       ((isPCI(x)) && (PCI(x)->op == POC_CALL))
 #define isSTATUS_REG(r) ((r)->pc_type == PO_STATUS)
 #define isBSR_REG(r)    ((r)->pc_type == PO_BSR)
+#define isACCESS_BANK(r)       (r->accessBank)
 
-#define isACCESS_LOW(r) ((pic16_finalMapping[REG_ADDR(r)].bank == \
-                          PIC_BANK_FIRST) && (REG_ADDR(r) < 0x80))
-#define isACCESS_HI(r)  (pic16_finalMapping[REG_ADDR(r)].bank == PIC_BANK_LAST)
-
-/*
-#define isACCESS_BANK(r)(isACCESS_LOW(r) || isACCESS_HI(r))
-*/
-#define isACCESS_BANK(r)       (pic16_finalMapping[(r)->rIdx].isSFR \
-                               || (pic16_finalMapping[(r)->rIdx].reg && pic16_finalMapping[(r)->rIdx].reg->isFixed))
 
 
 #define isPCOLAB(x)     ((PCOP(x)->type) == PO_LABEL)
@@ -881,6 +900,7 @@ pCode *pic16_newpCodeCharP(char *cP);              // Create a new pCode given a
 pCode *pic16_newpCodeInlineP(char *cP);            // Create a new pCode given a char *
 pCode *pic16_newpCodeFunction(char *g, char *f);   // Create a new function
 pCode *pic16_newpCodeLabel(char *name,int key);    // Create a new label given a key
+pCode *pic16_newpCodeLabelFORCE(char *name, int key); // Same as newpCodeLabel but label cannot be optimized out
 pCode *pic16_newpCodeCSource(int ln, char *f, char *l); // Create a new symbol line 
 pBlock *pic16_newpCodeChain(memmap *cm,char c, pCode *pc); // Create a new pBlock
 void pic16_printpBlock(FILE *of, pBlock *pb);      // Write a pBlock to a file
@@ -889,13 +909,22 @@ void pic16_addpBlock(pBlock *pb);                  // Add a pBlock to a pFile
 void pic16_copypCode(FILE *of, char dbName);       // Write all pBlocks with dbName to *of
 void pic16_movepBlock2Head(char dbName);           // move pBlocks around
 void pic16_AnalyzepCode(char dbName);
+void pic16_AssignRegBanks(void);
 void pic16_printCallTree(FILE *of);
 void pCodePeepInit(void);
 void pic16_pBlockConvert2ISR(pBlock *pb);
+void pic16_pBlockConvert2Absolute(pBlock *pb);
+void pic16_initDB(void);
+void pic16_emitDB(char c, char ptype, void *p);                  // Add DB directives to a pBlock
+void pic16_emitDS(char *s, char ptype, void *p);
+void pic16_flushDB(char ptype, void *p);                         // Add pending DB data to a pBlock
+
+pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...); 
 
 pCodeOp *pic16_newpCodeOpLabel(char *name, int key);
 pCodeOp *pic16_newpCodeOpImmd(char *name, int offset, int index, int code_space);
 pCodeOp *pic16_newpCodeOpLit(int lit);
+pCodeOp *pic16_newpCodeOpLit2(int lit, pCodeOp *arg2);
 pCodeOp *pic16_newpCodeOpBit(char *name, int bit,int inBitSpace);
 pCodeOp *pic16_newpCodeOpRegFromStr(char *name);
 pCodeOp *pic16_newpCodeOp(char *name, PIC_OPTYPE p);
@@ -908,6 +937,8 @@ struct regs * pic16_getRegFromInstruction(pCode *pc);
 struct regs * pic16_getRegFromInstruction2(pCode *pc);
 
 extern void pic16_pcode_test(void);
+extern int pic16_debug_verbose;
+extern int pic16_pcode_verbose;
 
 /*-----------------------------------------------------------------*
  * pCode objects.
@@ -915,11 +946,48 @@ extern void pic16_pcode_test(void);
 
 extern pCodeOpReg pic16_pc_status;
 extern pCodeOpReg pic16_pc_intcon;
-extern pCodeOpReg pic16_pc_indf0;
-extern pCodeOpReg pic16_pc_fsr0;
 extern pCodeOpReg pic16_pc_pcl;
 extern pCodeOpReg pic16_pc_pclath;
+extern pCodeOpReg pic16_pc_pclatu; // patch 14
 extern pCodeOpReg pic16_pc_wreg;
+extern pCodeOpReg pic16_pc_tosl; // patch 14
+extern pCodeOpReg pic16_pc_tosh; // patch 14
+extern pCodeOpReg pic16_pc_tosu; // patch 14
+extern pCodeOpReg pic16_pc_tblptrl; // patch 15
+extern pCodeOpReg pic16_pc_tblptrh; //
+extern pCodeOpReg pic16_pc_tblptru; //
+extern pCodeOpReg pic16_pc_tablat;  // patch 15
+extern pCodeOpReg pic16_pc_bsr;
+extern pCodeOpReg pic16_pc_fsr0;
+extern pCodeOpReg pic16_pc_fsr0l;
+extern pCodeOpReg pic16_pc_fsr0h;
+extern pCodeOpReg pic16_pc_fsr1l;
+extern pCodeOpReg pic16_pc_fsr1h;
+extern pCodeOpReg pic16_pc_fsr2l;
+extern pCodeOpReg pic16_pc_fsr2h;
+extern pCodeOpReg pic16_pc_indf0;
+extern pCodeOpReg pic16_pc_postinc0;
+extern pCodeOpReg pic16_pc_postdec0;
+extern pCodeOpReg pic16_pc_preinc0;
+extern pCodeOpReg pic16_pc_plusw0;
+extern pCodeOpReg pic16_pc_indf1;
+extern pCodeOpReg pic16_pc_postinc1;
+extern pCodeOpReg pic16_pc_postdec1;
+extern pCodeOpReg pic16_pc_preinc1;
+extern pCodeOpReg pic16_pc_plusw1;
+extern pCodeOpReg pic16_pc_indf2;
+extern pCodeOpReg pic16_pc_postinc2;
+extern pCodeOpReg pic16_pc_postdec2;
+extern pCodeOpReg pic16_pc_preinc2;
+extern pCodeOpReg pic16_pc_plusw2;
+extern pCodeOpReg pic16_pc_prodl;
+extern pCodeOpReg pic16_pc_prodh;
+
+extern pCodeOpReg pic16_pc_eecon1;
+extern pCodeOpReg pic16_pc_eecon2;
+extern pCodeOpReg pic16_pc_eedata;
+extern pCodeOpReg pic16_pc_eeadr;
+
 extern pCodeOpReg pic16_pc_kzero;
 extern pCodeOpReg pic16_pc_wsave;     /* wsave and ssave are used to save W and the Status */
 extern pCodeOpReg pic16_pc_ssave;     /* registers during an interrupt */