"ancestor" flow logic was implemented. Applied optimization patches from Frieder...
[fw/sdcc] / src / pic / pcode.h
1 /*-------------------------------------------------------------------------
2
3    pcode.h - post code generation
4    Written By -  Scott Dattalo scott@dattalo.com
5
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any
9    later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19    
20 -------------------------------------------------------------------------*/
21
22 //#include "ralloc.h"
23 struct regs;
24
25 /*
26    Post code generation
27
28    The post code generation is an assembler optimizer. The assembly code
29    produced by all of the previous steps is fully functional. This step
30    will attempt to analyze the flow of the assembly code and agressively 
31    optimize it. The peep hole optimizer attempts to do the same thing.
32    As you may recall, the peep hole optimizer replaces blocks of assembly
33    with more optimal blocks (e.g. removing redundant register loads).
34    However, the peep hole optimizer has to be somewhat conservative since
35    an assembly program has implicit state information that's unavailable 
36    when only a few instructions are examined.
37      Consider this example:
38
39    example1:
40      movwf  t1
41      movf   t1,w
42
43    The movf seems redundant since we know that the W register already
44    contains the same value of t1. So a peep hole optimizer is tempted to
45    remove the "movf". However, this is dangerous since the movf affects
46    the flags in the status register (specifically the Z flag) and subsequent
47    code may depend upon this. Look at these two examples:
48
49    example2:
50      movwf  t1
51      movf   t1,w     ; Can't remove this movf
52      skpz
53       return
54
55    example3:
56      movwf  t1
57      movf   t1,w     ; This  movf can be removed
58      xorwf  t2,w     ; since xorwf will over write Z 
59      skpz
60       return
61
62 */
63
64
65 #ifndef __PCODE_H__
66 #define __PCODE_H__
67
68 /***********************************************************************
69  * debug stuff
70  * 
71  * The DFPRINTF macro will call fprintf if PCODE_DEBUG is defined.
72  * The macro is used like:
73  *
74  * DPRINTF(("%s #%d\n","test", 1));
75  *
76  * The double parenthesis (()) are necessary
77  * 
78  ***********************************************************************/
79 //#define PCODE_DEBUG
80
81 #ifdef PCODE_DEBUG
82 #define DFPRINTF(args) (fprintf args)
83 #else
84 #define DFPRINTF(args) ;
85 #endif
86
87
88 /***********************************************************************
89  *  PIC status bits - this will move into device dependent headers
90  ***********************************************************************/
91 #define PIC_C_BIT    0
92 #define PIC_DC_BIT   1
93 #define PIC_Z_BIT    2
94 #define PIC_RP0_BIT  5   /* Register Bank select bits RP1:0 : */
95 #define PIC_RP1_BIT  6   /* 00 - bank 0, 01 - bank 1, 10 - bank 2, 11 - bank 3 */
96 #define PIC_IRP_BIT  7   /* Indirect register page select */
97
98 /***********************************************************************
99  *  PIC INTCON bits - this will move into device dependent headers
100  ***********************************************************************/
101 #define PIC_RBIF_BIT 0   /* Port B level has changed flag */
102 #define PIC_INTF_BIT 1   /* Port B bit 0 interrupt on edge flag */
103 #define PIC_T0IF_BIT 2   /* TMR0 has overflowed flag */
104 #define PIC_RBIE_BIT 3   /* Port B level has changed - Interrupt Enable */
105 #define PIC_INTE_BIT 4   /* Port B bit 0 interrupt on edge - Int Enable */
106 #define PIC_T0IE_BIT 5   /* TMR0 overflow Interrupt Enable */
107 #define PIC_PIE_BIT  6   /* Peripheral Interrupt Enable */
108 #define PIC_GIE_BIT  7   /* Global Interrupt Enable */
109
110 /***********************************************************************
111  *  Operand types 
112  ***********************************************************************/
113 #define POT_RESULT  0
114 #define POT_LEFT    1
115 #define POT_RIGHT   2
116
117
118 /***********************************************************************
119  *
120  *  PIC_OPTYPE - Operand types that are specific to the PIC architecture
121  *
122  *  If a PIC assembly instruction has an operand then here is where we
123  *  associate a type to it. For example,
124  *
125  *     movf    reg,W
126  *
127  *  The movf has two operands: 'reg' and the W register. 'reg' is some
128  *  arbitrary general purpose register, hence it has the type PO_GPR_REGISTER.
129  *  The W register, which is the PIC's accumulator, has the type PO_W.
130  *
131  ***********************************************************************/
132
133
134
135 typedef enum 
136 {
137   PO_NONE=0,         // No operand e.g. NOP
138   PO_W,              // The 'W' register
139   PO_STATUS,         // The 'STATUS' register
140   PO_FSR,            // The "file select register" (in 18c it's one of three)
141   PO_INDF,           // The Indirect register
142   PO_INTCON,         // Interrupt Control register
143   PO_GPR_REGISTER,   // A general purpose register
144   PO_GPR_BIT,        // A bit of a general purpose register
145   PO_GPR_TEMP,       // A general purpose temporary register
146   PO_SFR_REGISTER,   // A special function register (e.g. PORTA)
147   PO_PCL,            // Program counter Low register
148   PO_PCLATH,         // Program counter Latch high register
149   PO_LITERAL,        // A constant
150   PO_IMMEDIATE,      //  (8051 legacy)
151   PO_DIR,            // Direct memory (8051 legacy)
152   PO_CRY,            // bit memory (8051 legacy)
153   PO_BIT,            // bit operand.
154   PO_STR,            //  (8051 legacy)
155   PO_LABEL,
156   PO_WILD            // Wild card operand in peep optimizer
157 } PIC_OPTYPE;
158
159
160 /***********************************************************************
161  *
162  *  PIC_OPCODE
163  *
164  *  This is not a list of the PIC's opcodes per se, but instead
165  *  an enumeration of all of the different types of pic opcodes. 
166  *
167  ***********************************************************************/
168
169 typedef enum
170 {
171   POC_WILD=-1,   /* Wild card - used in the pCode peep hole optimizer
172                   * to represent ANY pic opcode */
173   POC_ADDLW=0,
174   POC_ADDWF,
175   POC_ADDFW,
176   POC_ANDLW,
177   POC_ANDWF,
178   POC_ANDFW,
179   POC_BCF,
180   POC_BSF,
181   POC_BTFSC,
182   POC_BTFSS,
183   POC_CALL,
184   POC_COMF,
185   POC_COMFW,
186   POC_CLRF,
187   POC_CLRW,
188   POC_CLRWDT,
189   POC_DECF,
190   POC_DECFW,
191   POC_DECFSZ,
192   POC_DECFSZW,
193   POC_GOTO,
194   POC_INCF,
195   POC_INCFW,
196   POC_INCFSZ,
197   POC_INCFSZW,
198   POC_IORLW,
199   POC_IORWF,
200   POC_IORFW,
201   POC_MOVF,
202   POC_MOVFW,
203   POC_MOVLW,
204   POC_MOVWF,
205   POC_NOP,
206   POC_RETLW,
207   POC_RETURN,
208   POC_RETFIE,
209   POC_RLF,
210   POC_RLFW,
211   POC_RRF,
212   POC_RRFW,
213   POC_SUBLW,
214   POC_SUBWF,
215   POC_SUBFW,
216   POC_SWAPF,
217   POC_SWAPFW,
218   POC_TRIS,
219   POC_XORLW,
220   POC_XORWF,
221   POC_XORFW
222 } PIC_OPCODE;
223
224
225 /***********************************************************************
226  *  PC_TYPE  - pCode Types
227  ***********************************************************************/
228
229 typedef enum
230 {
231   PC_COMMENT=0,   /* pCode is a comment     */
232   PC_INLINE,      /* user's inline code     */
233   PC_OPCODE,      /* PORT dependent opcode  */
234   PC_LABEL,       /* assembly label         */
235   PC_FLOW,        /* flow analysis          */
236   PC_FUNCTION,    /* Function start or end  */
237   PC_WILD,        /* wildcard - an opcode place holder used 
238                    * in the pCode peep hole optimizer */
239   PC_CSOURCE,     /* C-Source Line  */
240   PC_BAD          /* Mark the pCode object as being bad */
241 } PC_TYPE;
242
243 /************************************************/
244 /***************  Structures ********************/
245 /************************************************/
246 /* These are here as forward references - the 
247  * full definition of these are below           */
248 struct pCode;
249 struct pCodeWildBlock;
250 struct pCodeRegLives;
251
252 /*************************************************
253   pBranch
254
255   The first step in optimizing pCode is determining
256  the program flow. This information is stored in
257  single-linked lists in the for of 'from' and 'to'
258  objects with in a pcode. For example, most instructions
259  don't involve any branching. So their from branch
260  points to the pCode immediately preceding them and
261  their 'to' branch points to the pcode immediately
262  following them. A skip instruction is an example of
263  a pcode that has multiple (in this case two) elements
264  in the 'to' branch. A 'label' pcode is an where there
265  may be multiple 'from' branches.
266  *************************************************/
267
268 typedef struct pBranch
269 {
270   struct pCode   *pc;    // Next pCode in a branch
271   struct pBranch *next;  /* If more than one branch
272                           * the next one is here */
273
274 } pBranch;
275
276 /*************************************************
277   pCodeOp
278
279   pCode Operand structure.
280   For those assembly instructions that have arguments, 
281   the pCode will have a pCodeOp in which the argument
282   can be stored. For example
283
284     movf   some_register,w
285
286   'some_register' will be stored/referenced in a pCodeOp
287
288  *************************************************/
289
290 typedef struct pCodeOp
291 {
292   PIC_OPTYPE type;
293   char *name;
294   
295 } pCodeOp;
296 #if 0
297 typedef struct pCodeOpBit
298 {
299   pCodeOp pcop;
300   int bit;
301   unsigned int inBitSpace: 1; /* True if in bit space, else
302                                  just a bit of a register */
303 } pCodeOpBit;
304 #endif
305 typedef struct pCodeOpLit
306 {
307   pCodeOp pcop;
308   int lit;
309 } pCodeOpLit;
310
311 typedef struct pCodeOpImmd
312 {
313   pCodeOp pcop;
314   int offset;           /* low,med, or high byte of immediat value */
315   int index;            /* add this to the immediate value */
316   unsigned _const:1;    /* is in code space    */
317
318   int rIdx;             /* If this immd points to a register */
319   struct regs *r;       /* then this is the reg. */
320
321 } pCodeOpImmd;
322
323 typedef struct pCodeOpLabel
324 {
325   pCodeOp pcop;
326   int key;
327 } pCodeOpLabel;
328
329 typedef struct pCodeOpReg
330 {
331   pCodeOp pcop;    // Can be either GPR or SFR
332   int rIdx;        // Index into the register table
333   struct regs *r;
334   int instance;    // byte # of Multi-byte registers
335   struct pBlock *pb;
336 } pCodeOpReg;
337
338 typedef struct pCodeOpRegBit
339 {
340   pCodeOpReg  pcor;       // The Register containing this bit
341   int bit;                // 0-7 bit number.
342   PIC_OPTYPE subtype;     // The type of this register.
343   unsigned int inBitSpace: 1; /* True if in bit space, else
344                                  just a bit of a register */
345 } pCodeOpRegBit;
346
347
348 typedef struct pCodeOpWild
349 {
350   pCodeOp pcop;
351
352   struct pCodeWildBlock *pcwb;
353
354   int id;                 /* index into an array of char *'s that will match
355                            * the wild card. The array is in *pcp. */
356   pCodeOp *subtype;       /* Pointer to the Operand type into which this wild
357                            * card will be expanded */
358   pCodeOp *matched;       /* When a wild matches, we'll store a pointer to the
359                            * opcode we matched */
360
361 } pCodeOpWild;
362
363
364 /*************************************************
365     pCode
366
367     Here is the basic build block of a PIC instruction.
368     Each pic instruction will get allocated a pCode.
369     A linked list of pCodes makes a program.
370
371 **************************************************/
372
373 typedef struct pCode
374 {
375   PC_TYPE    type;
376
377   struct pCode *prev;  // The pCode objects are linked together
378   struct pCode *next;  // in doubly linked lists.
379
380   int seq;             // sequence number
381
382   struct pBlock *pb;   // The pBlock that contains this pCode.
383
384   /* "virtual functions"
385    *  The pCode structure is like a base class
386    * in C++. The subsequent structures that "inherit"
387    * the pCode structure will initialize these function
388    * pointers to something useful */
389   //  void (*analyze) (struct pCode *_this);
390   void (*destruct)(struct pCode *_this);
391   void (*print)  (FILE *of,struct pCode *_this);
392
393 } pCode;
394
395
396 /*************************************************
397     pCodeComment
398 **************************************************/
399
400 typedef struct pCodeComment
401 {
402
403   pCode  pc;
404
405   char *comment;
406
407 } pCodeComment;
408
409 /*************************************************
410     pCodeComment
411 **************************************************/
412
413 typedef struct pCodeCSource
414 {
415
416   pCode  pc;
417
418   int  line_number;
419   char *line;
420   char *file_name;
421
422 } pCodeCSource;
423
424
425 /*************************************************
426     pCodeFlow
427
428   The Flow object is used as marker to separate 
429  the assembly code into contiguous chunks. In other
430  words, everytime an instruction cause or potentially
431  causes a branch, a Flow object will be inserted into
432  the pCode chain to mark the beginning of the next
433  contiguous chunk.
434
435 **************************************************/
436
437 typedef struct pCodeFlow
438 {
439
440   pCode  pc;
441
442   pCode *end;   /* Last pCode in this flow. Note that
443                    the first pCode is pc.next */
444
445   /*  set **uses;   * map the pCode instruction inCond and outCond conditions 
446                  * in this array of set's. The reason we allocate an 
447                  * array of pointers instead of declaring each type of 
448                  * usage is because there are port dependent usage definitions */
449   //int nuses;    /* number of uses sets */
450
451   set *from;    /* flow blocks that can send control to this flow block */
452   set *to;      /* flow blocks to which this one can send control */
453   struct pCodeFlow *ancestor; /* The most immediate "single" pCodeFlow object that
454                                * executes prior to this one. In many cases, this 
455                                * will be just the previous */
456
457   int inCond;   /* Input conditions - stuff assumed defined at entry */
458   int outCond;  /* Output conditions - stuff modified by flow block */
459
460   int firstBank; /* The first and last bank flags are the first and last */
461   int lastBank;  /* register banks used within one flow object */
462
463   int FromConflicts;
464   int ToConflicts;
465
466   set *registers;/* Registers used in this flow */
467
468 } pCodeFlow;
469
470 /*************************************************
471   pCodeFlowLink
472
473   The Flow Link object is used to record information
474  about how consecutive excutive Flow objects are related.
475  The pCodeFlow objects demarcate the pCodeInstructions
476  into contiguous chunks. The FlowLink records conflicts
477  in the discontinuities. For example, if one Flow object
478  references a register in bank 0 and the next Flow object
479  references a register in bank 1, then there is a discontinuity
480  in the banking registers.
481
482 */
483 typedef struct pCodeFlowLink
484 {
485   pCodeFlow  *pcflow;   /* pointer to linked pCodeFlow object */
486
487   int bank_conflict;    /* records bank conflicts */
488
489 } pCodeFlowLink;
490
491 /*************************************************
492     pCodeInstruction
493
494     Here we describe all the facets of a PIC instruction
495     (expansion for the 18cxxx is also provided).
496
497 **************************************************/
498
499 typedef struct pCodeInstruction
500 {
501
502   pCode  pc;
503
504   PIC_OPCODE op;        // The opcode of the instruction.
505
506   char const * const mnemonic;       // Pointer to mnemonic string
507
508   pBranch *from;       // pCodes that execute before this one
509   pBranch *to;         // pCodes that execute after
510   pBranch *label;      // pCode instructions that have labels
511
512   pCodeOp *pcop;               /* Operand, if this instruction has one */
513   pCodeFlow *pcflow;           /* flow block to which this instruction belongs */
514   pCodeCSource *cline;         /* C Source from which this instruction was derived */
515
516   unsigned int num_ops;        /* Number of operands (0,1,2 for mid range pics) */
517   unsigned int isModReg:  1;   /* If destination is W or F, then 1==F */
518   unsigned int isBitInst: 1;   /* e.g. BCF */
519   unsigned int isBranch:  1;   /* True if this is a branching instruction */
520   unsigned int isSkip:    1;   /* True if this is a skip instruction */
521
522   PIC_OPCODE inverted_op;      /* Opcode of instruction that's the opposite of this one */
523   unsigned int inCond;   // Input conditions for this instruction
524   unsigned int outCond;  // Output conditions for this instruction
525
526 } pCodeInstruction;
527
528
529 /*************************************************
530     pCodeLabel
531 **************************************************/
532
533 typedef struct pCodeLabel
534 {
535
536   pCode  pc;
537
538   char *label;
539   int key;
540
541 } pCodeLabel;
542
543 /*************************************************
544     pCodeFunction
545 **************************************************/
546
547 typedef struct pCodeFunction
548 {
549
550   pCode  pc;
551
552   char *modname;
553   char *fname;     /* If NULL, then this is the end of
554                       a function. Otherwise, it's the
555                       start and the name is contained
556                       here */
557
558   pBranch *from;       // pCodes that execute before this one
559   pBranch *to;         // pCodes that execute after
560   pBranch *label;      // pCode instructions that have labels
561
562   int  ncalled;    /* Number of times function is called */
563
564 } pCodeFunction;
565
566
567 /*************************************************
568     pCodeWild
569 **************************************************/
570
571 typedef struct pCodeWild
572 {
573
574   pCodeInstruction  pci;
575
576   int    id;     /* Index into the wild card array of a peepBlock 
577                   * - this wild card will get expanded into that pCode
578                   *   that is stored at this index */
579
580   /* Conditions on wild pcode instruction */
581   int    mustBeBitSkipInst:1;
582   int    mustNotBeBitSkipInst:1;
583   int    invertBitSkipInst:1;
584
585   pCodeOp *operand;  // Optional operand
586   pCodeOp *label;    // Optional label
587
588 } pCodeWild;
589
590 /*************************************************
591     pBlock
592
593     Here are PIC program snippets. There's a strong
594     correlation between the eBBlocks and pBlocks.
595     SDCC subdivides a C program into managable chunks.
596     Each chunk becomes a eBBlock and ultimately in the
597     PIC port a pBlock.
598
599 **************************************************/
600
601 typedef struct pBlock
602 {
603   memmap *cmemmap;   /* The snippet is from this memmap */
604   char   dbName;     /* if cmemmap is NULL, then dbName will identify the block */
605   pCode *pcHead;     /* A pointer to the first pCode in a link list of pCodes */
606   pCode *pcTail;     /* A pointer to the last pCode in a link list of pCodes */
607
608   struct pBlock *next;      /* The pBlocks will form a doubly linked list */
609   struct pBlock *prev;
610
611   set *function_entries;    /* dll of functions in this pblock */
612   set *function_exits;
613   set *function_calls;
614   set *tregisters;
615
616   set *FlowTree;
617   unsigned visited:1;       /* set true if traversed in call tree */
618
619   unsigned seq;             /* sequence number of this pBlock */
620
621 } pBlock;
622
623 /*************************************************
624     pFile
625
626     The collection of pBlock program snippets are
627     placed into a linked list that is implemented
628     in the pFile structure.
629
630     The pcode optimizer will parse the pFile.
631
632 **************************************************/
633
634 typedef struct pFile
635 {
636   pBlock *pbHead;     /* A pointer to the first pBlock */
637   pBlock *pbTail;     /* A pointer to the last pBlock */
638
639   pBranch *functions; /* A SLL of functions in this pFile */
640
641 } pFile;
642
643
644
645 /*************************************************
646   pCodeWildBlock
647
648   The pCodeWildBlock object keeps track of the wild
649   variables, operands, and opcodes that exist in
650   a pBlock.
651 **************************************************/
652 typedef struct pCodeWildBlock {
653   pBlock    *pb;
654   struct pCodePeep *pcp;    // pointer back to ... I don't like this...
655
656   int       nvars;          // Number of wildcard registers in target.
657   char    **vars;           // array of pointers to them
658
659   int       nops;           // Number of wildcard operands in target.
660   pCodeOp **wildpCodeOps;   // array of pointers to the pCodeOp's.
661
662   int       nwildpCodes;    // Number of wildcard pCodes in target/replace
663   pCode   **wildpCodes;     // array of pointers to the pCode's.
664
665 } pCodeWildBlock;
666
667 /*************************************************
668   pCodePeep
669
670   The pCodePeep object mimics the peep hole optimizer
671   in the main SDCC src (e.g. SDCCpeeph.c). Essentially
672   there is a target pCode chain and a replacement
673   pCode chain. The target chain is compared to the
674   pCode that is generated by gen.c. If a match is
675   found then the pCode is replaced by the replacement
676   pCode chain.
677 **************************************************/
678 typedef struct pCodePeep {
679   pCodeWildBlock target;     // code we'd like to optimize
680   pCodeWildBlock replace;    // and this is what we'll optimize it with.
681
682   //pBlock *target;
683   //pBlock replace;            // and this is what we'll optimize it with.
684
685
686
687   /* (Note: a wildcard register is a place holder. Any register
688    * can be replaced by the wildcard when the pcode is being 
689    * compared to the target. */
690
691   /* Post Conditions. A post condition is a condition that
692    * must be either true or false before the peep rule is
693    * accepted. For example, a certain rule may be accepted
694    * if and only if the Z-bit is not used as an input to 
695    * the subsequent instructions in a pCode chain.
696    */
697   unsigned int postFalseCond;  
698   unsigned int postTrueCond;
699
700 } pCodePeep;
701
702 /*************************************************
703
704   pCode peep command definitions 
705
706  Here are some special commands that control the
707 way the peep hole optimizer behaves
708
709 **************************************************/
710
711 enum peepCommandTypes{
712   NOTBITSKIP = 0,
713   BITSKIP,
714   INVERTBITSKIP,
715   _LAST_PEEP_COMMAND_
716 };
717
718 /*************************************************
719     peepCommand structure stores the peep commands.
720
721 **************************************************/
722
723 typedef struct peepCommand {
724   int id;
725   char *cmd;
726 } peepCommand;
727
728 /*************************************************
729     pCode Macros
730
731 **************************************************/
732 #define PCODE(x)  ((pCode *)(x))
733 #define PCI(x)    ((pCodeInstruction *)(x))
734 #define PCL(x)    ((pCodeLabel *)(x))
735 #define PCF(x)    ((pCodeFunction *)(x))
736 #define PCFL(x)   ((pCodeFlow *)(x))
737 #define PCFLINK(x)((pCodeFlowLink *)(x))
738 #define PCW(x)    ((pCodeWild *)(x))
739 #define PCCS(x)   ((pCodeCSource *)(x))
740
741 #define PCOP(x)   ((pCodeOp *)(x))
742 //#define PCOB(x)   ((pCodeOpBit *)(x))
743 #define PCOL(x)   ((pCodeOpLit *)(x))
744 #define PCOI(x)   ((pCodeOpImmd *)(x))
745 #define PCOLAB(x) ((pCodeOpLabel *)(x))
746 #define PCOR(x)   ((pCodeOpReg *)(x))
747 #define PCORB(x)  ((pCodeOpRegBit *)(x))
748 #define PCOW(x)   ((pCodeOpWild *)(x))
749
750 #define PBR(x)    ((pBranch *)(x))
751
752 #define PCWB(x)   ((pCodeWildBlock *)(x))
753
754
755 /*
756   macros for checking pCode types
757 */
758 #define isPCI(x)        ((PCODE(x)->type == PC_OPCODE))
759 #define isPCI_BRANCH(x) ((PCODE(x)->type == PC_OPCODE) &&  PCI(x)->isBranch)
760 #define isPCI_SKIP(x)   ((PCODE(x)->type == PC_OPCODE) &&  PCI(x)->isSkip)
761 #define isPCI_BITSKIP(x)((PCODE(x)->type == PC_OPCODE) &&  PCI(x)->isSkip && PCI(x)->isBitInst)
762 #define isPCFL(x)       ((PCODE(x)->type == PC_FLOW))
763 #define isPCF(x)        ((PCODE(x)->type == PC_FUNCTION))
764 #define isPCL(x)        ((PCODE(x)->type == PC_LABEL))
765 #define isPCW(x)        ((PCODE(x)->type == PC_WILD))
766 #define isPCCS(x)       ((PCODE(x)->type == PC_CSOURCE))
767
768 #define isCALL(x)       ((isPCI(x)) && (PCI(x)->op == POC_CALL))
769 #define isSTATUS_REG(r) ((r)->pc_type == PO_STATUS)
770
771 #define isPCOLAB(x)     ((PCOP(x)->type) == PO_LABEL)
772
773 /*-----------------------------------------------------------------*
774  * pCode functions.
775  *-----------------------------------------------------------------*/
776
777 pCode *newpCode (PIC_OPCODE op, pCodeOp *pcop); // Create a new pCode given an operand
778 pCode *newpCodeCharP(char *cP);              // Create a new pCode given a char *
779 pCode *newpCodeInlineP(char *cP);            // Create a new pCode given a char *
780 pCode *newpCodeFunction(char *g, char *f);   // Create a new function
781 pCode *newpCodeLabel(char *name,int key);    // Create a new label given a key
782 pCode *newpCodeCSource(int ln, char *f, char *l); // Create a new symbol line 
783 pBlock *newpCodeChain(memmap *cm,char c, pCode *pc); // Create a new pBlock
784 void printpBlock(FILE *of, pBlock *pb);      // Write a pBlock to a file
785 void printpCode(FILE *of, pCode *pc);        // Write a pCode to a file
786 void addpCode2pBlock(pBlock *pb, pCode *pc); // Add a pCode to a pBlock
787 void addpBlock(pBlock *pb);                  // Add a pBlock to a pFile
788 void copypCode(FILE *of, char dbName);       // Write all pBlocks with dbName to *of
789 void movepBlock2Head(char dbName);           // move pBlocks around
790 void AnalyzepCode(char dbName);
791 int OptimizepCode(char dbName);
792 void printCallTree(FILE *of);
793 void pCodePeepInit(void);
794 void pBlockConvert2ISR(pBlock *pb);
795
796 pCodeOp *newpCodeOpLabel(char *name, int key);
797 pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space);
798 pCodeOp *newpCodeOpLit(int lit);
799 pCodeOp *newpCodeOpBit(char *name, int bit,int inBitSpace);
800 pCodeOp *newpCodeOpRegFromStr(char *name);
801 pCodeOp *newpCodeOp(char *name, PIC_OPTYPE p);
802 pCodeOp *pCodeOpCopy(pCodeOp *pcop);
803
804 pCode * findNextInstruction(pCode *pci);
805 pCode * findNextpCode(pCode *pc, PC_TYPE pct);
806 int isPCinFlow(pCode *pc, pCode *pcflow);
807 struct regs * getRegFromInstruction(pCode *pc);
808
809 extern void pcode_test(void);
810
811 /*-----------------------------------------------------------------*
812  * pCode objects.
813  *-----------------------------------------------------------------*/
814
815 extern pCodeOpReg pc_status;
816 extern pCodeOpReg pc_intcon;
817 extern pCodeOpReg pc_indf;
818 extern pCodeOpReg pc_fsr;
819 extern pCodeOpReg pc_pcl;
820 extern pCodeOpReg pc_pclath;
821 extern pCodeOpReg pc_kzero;
822 extern pCodeOpReg pc_wsave;     /* wsave and ssave are used to save W and the Status */
823 extern pCodeOpReg pc_ssave;     /* registers during an interrupt */
824
825
826 #endif // __PCODE_H__