More enhancements to register optimization algorithms.
[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_DECF,
189   POC_DECFW,
190   POC_DECFSZ,
191   POC_DECFSZW,
192   POC_GOTO,
193   POC_INCF,
194   POC_INCFW,
195   POC_INCFSZ,
196   POC_INCFSZW,
197   POC_IORLW,
198   POC_IORWF,
199   POC_IORFW,
200   POC_MOVF,
201   POC_MOVFW,
202   POC_MOVLW,
203   POC_MOVWF,
204   POC_NOP,
205   POC_RETLW,
206   POC_RETURN,
207   POC_RETFIE,
208   POC_RLF,
209   POC_RLFW,
210   POC_RRF,
211   POC_RRFW,
212   POC_SUBLW,
213   POC_SUBWF,
214   POC_SUBFW,
215   POC_SWAPF,
216   POC_SWAPFW,
217   POC_TRIS,
218   POC_XORLW,
219   POC_XORWF,
220   POC_XORFW
221 } PIC_OPCODE;
222
223
224 /***********************************************************************
225  *  PC_TYPE  - pCode Types
226  ***********************************************************************/
227
228 typedef enum
229 {
230   PC_COMMENT=0,   /* pCode is a comment     */
231   PC_INLINE,      /* user's inline code     */
232   PC_OPCODE,      /* PORT dependent opcode  */
233   PC_LABEL,       /* assembly label         */
234   PC_FLOW,        /* flow analysis          */
235   PC_FUNCTION,    /* Function start or end  */
236   PC_WILD,        /* wildcard - an opcode place holder used 
237                    * in the pCode peep hole optimizer */
238   PC_CSOURCE,     /* C-Source Line  */
239   PC_BAD          /* Mark the pCode object as being bad */
240 } PC_TYPE;
241
242 /************************************************/
243 /***************  Structures ********************/
244 /************************************************/
245 /* These are here as forward references - the 
246  * full definition of these are below           */
247 struct pCode;
248 struct pCodeWildBlock;
249 struct pCodeRegLives;
250
251 /*************************************************
252   pBranch
253
254   The first step in optimizing pCode is determining
255  the program flow. This information is stored in
256  single-linked lists in the for of 'from' and 'to'
257  objects with in a pcode. For example, most instructions
258  don't involve any branching. So their from branch
259  points to the pCode immediately preceding them and
260  their 'to' branch points to the pcode immediately
261  following them. A skip instruction is an example of
262  a pcode that has multiple (in this case two) elements
263  in the 'to' branch. A 'label' pcode is an where there
264  may be multiple 'from' branches.
265  *************************************************/
266
267 typedef struct pBranch
268 {
269   struct pCode   *pc;    // Next pCode in a branch
270   struct pBranch *next;  /* If more than one branch
271                           * the next one is here */
272
273 } pBranch;
274
275 /*************************************************
276   pCodeOp
277
278   pCode Operand structure.
279   For those assembly instructions that have arguments, 
280   the pCode will have a pCodeOp in which the argument
281   can be stored. For example
282
283     movf   some_register,w
284
285   'some_register' will be stored/referenced in a pCodeOp
286
287  *************************************************/
288
289 typedef struct pCodeOp
290 {
291   PIC_OPTYPE type;
292   char *name;
293   
294 } pCodeOp;
295 #if 0
296 typedef struct pCodeOpBit
297 {
298   pCodeOp pcop;
299   int bit;
300   unsigned int inBitSpace: 1; /* True if in bit space, else
301                                  just a bit of a register */
302 } pCodeOpBit;
303 #endif
304 typedef struct pCodeOpLit
305 {
306   pCodeOp pcop;
307   int lit;
308 } pCodeOpLit;
309
310 typedef struct pCodeOpImmd
311 {
312   pCodeOp pcop;
313   int offset;           /* low,med, or high byte of immediat value */
314   int index;            /* add this to the immediate value */
315   unsigned _const:1;    /* is in code space    */
316
317   int rIdx;             /* If this immd points to a register */
318   struct regs *r;       /* then this is the reg. */
319
320 } pCodeOpImmd;
321
322 typedef struct pCodeOpLabel
323 {
324   pCodeOp pcop;
325   int key;
326 } pCodeOpLabel;
327
328 typedef struct pCodeOpReg
329 {
330   pCodeOp pcop;    // Can be either GPR or SFR
331   int rIdx;        // Index into the register table
332   struct regs *r;
333   int instance;    // byte # of Multi-byte registers
334   struct pBlock *pb;
335 } pCodeOpReg;
336
337 typedef struct pCodeOpRegBit
338 {
339   pCodeOpReg  pcor;       // The Register containing this bit
340   int bit;                // 0-7 bit number.
341   PIC_OPTYPE subtype;     // The type of this register.
342   unsigned int inBitSpace: 1; /* True if in bit space, else
343                                  just a bit of a register */
344 } pCodeOpRegBit;
345
346
347 typedef struct pCodeOpWild
348 {
349   pCodeOp pcop;
350
351   struct pCodeWildBlock *pcwb;
352
353   int id;                 /* index into an array of char *'s that will match
354                            * the wild card. The array is in *pcp. */
355   pCodeOp *subtype;       /* Pointer to the Operand type into which this wild
356                            * card will be expanded */
357   pCodeOp *matched;       /* When a wild matches, we'll store a pointer to the
358                            * opcode we matched */
359
360 } pCodeOpWild;
361
362
363 /*************************************************
364     pCode
365
366     Here is the basic build block of a PIC instruction.
367     Each pic instruction will get allocated a pCode.
368     A linked list of pCodes makes a program.
369
370 **************************************************/
371
372 typedef struct pCode
373 {
374   PC_TYPE    type;
375
376   struct pCode *prev;  // The pCode objects are linked together
377   struct pCode *next;  // in doubly linked lists.
378
379   int seq;             // sequence number
380
381   struct pBlock *pb;   // The pBlock that contains this pCode.
382
383   /* "virtual functions"
384    *  The pCode structure is like a base class
385    * in C++. The subsequent structures that "inherit"
386    * the pCode structure will initialize these function
387    * pointers to something useful */
388   //  void (*analyze) (struct pCode *_this);
389   void (*destruct)(struct pCode *_this);
390   void (*print)  (FILE *of,struct pCode *_this);
391
392 } pCode;
393
394
395 /*************************************************
396     pCodeComment
397 **************************************************/
398
399 typedef struct pCodeComment
400 {
401
402   pCode  pc;
403
404   char *comment;
405
406 } pCodeComment;
407
408 /*************************************************
409     pCodeComment
410 **************************************************/
411
412 typedef struct pCodeCSource
413 {
414
415   pCode  pc;
416
417   int  line_number;
418   char *line;
419   char *file_name;
420
421 } pCodeCSource;
422
423
424 /*************************************************
425     pCodeFlow
426
427   The Flow object is used as marker to separate 
428  the assembly code into contiguous chunks. In other
429  words, everytime an instruction cause or potentially
430  causes a branch, a Flow object will be inserted into
431  the pCode chain to mark the beginning of the next
432  contiguous chunk.
433
434 **************************************************/
435
436 typedef struct pCodeFlow
437 {
438
439   pCode  pc;
440
441   pCode *end;   /* Last pCode in this flow. Note that
442                    the first pCode is pc.next */
443
444   set **uses;   /* map the pCode instruction inCond and outCond conditions 
445                  * in this array of set's. The reason we allocate an 
446                  * array of pointers instead of declaring each type of 
447                  * usage is because there are port dependent usage definitions */
448   int nuses;    /* number of uses sets */
449
450   set *from;    /* flow blocks that can send control to this flow block */
451   set *to;      /* flow blocks to which this one can send control */
452
453   int inCond;   /* Input conditions - stuff assumed defined at entry */
454   int outCond;  /* Output conditions - stuff modified by flow block */
455
456   int firstBank; /* The first and last bank flags are the first and last */
457   int lastBank;  /* register banks used within one flow object */
458
459   int FromConflicts;
460   int ToConflicts;
461
462   set *registers;/* Registers used in this flow */
463
464 } pCodeFlow;
465
466 /*************************************************
467   pCodeFlowLink
468
469   The Flow Link object is used to record information
470  about how consecutive excutive Flow objects are related.
471  The pCodeFlow objects demarcate the pCodeInstructions
472  into contiguous chunks. The FlowLink records conflicts
473  in the discontinuities. For example, if one Flow object
474  references a register in bank 0 and the next Flow object
475  references a register in bank 1, then there is a discontinuity
476  in the banking registers.
477
478 */
479 typedef struct pCodeFlowLink
480 {
481   pCodeFlow  *pcflow;   /* pointer to linked pCodeFlow object */
482
483   int bank_conflict;    /* records bank conflicts */
484
485 } pCodeFlowLink;
486
487 /*************************************************
488     pCodeInstruction
489
490     Here we describe all the facets of a PIC instruction
491     (expansion for the 18cxxx is also provided).
492
493 **************************************************/
494
495 typedef struct pCodeInstruction
496 {
497
498   pCode  pc;
499
500   PIC_OPCODE op;        // The opcode of the instruction.
501
502   char const * const mnemonic;       // Pointer to mnemonic string
503
504   pBranch *from;       // pCodes that execute before this one
505   pBranch *to;         // pCodes that execute after
506   pBranch *label;      // pCode instructions that have labels
507
508   pCodeOp *pcop;               /* Operand, if this instruction has one */
509   pCodeFlow *pcflow;           /* flow block to which this instruction belongs */
510   pCodeCSource *cline;         /* C Source from which this instruction was derived */
511
512   unsigned int num_ops;        /* Number of operands (0,1,2 for mid range pics) */
513   unsigned int isModReg:  1;   /* If destination is W or F, then 1==F */
514   unsigned int isBitInst: 1;   /* e.g. BCF */
515   unsigned int isBranch:  1;   /* True if this is a branching instruction */
516   unsigned int isSkip:    1;   /* True if this is a skip instruction */
517
518   PIC_OPCODE inverted_op;      /* Opcode of instruction that's the opposite of this one */
519   unsigned int inCond;   // Input conditions for this instruction
520   unsigned int outCond;  // Output conditions for this instruction
521
522 } pCodeInstruction;
523
524
525 /*************************************************
526     pCodeLabel
527 **************************************************/
528
529 typedef struct pCodeLabel
530 {
531
532   pCode  pc;
533
534   char *label;
535   int key;
536
537 } pCodeLabel;
538
539 /*************************************************
540     pCodeFunction
541 **************************************************/
542
543 typedef struct pCodeFunction
544 {
545
546   pCode  pc;
547
548   char *modname;
549   char *fname;     /* If NULL, then this is the end of
550                       a function. Otherwise, it's the
551                       start and the name is contained
552                       here */
553
554   pBranch *from;       // pCodes that execute before this one
555   pBranch *to;         // pCodes that execute after
556   pBranch *label;      // pCode instructions that have labels
557
558   int  ncalled;    /* Number of times function is called */
559
560 } pCodeFunction;
561
562
563 /*************************************************
564     pCodeWild
565 **************************************************/
566
567 typedef struct pCodeWild
568 {
569
570   pCodeInstruction  pci;
571
572   int    id;     /* Index into the wild card array of a peepBlock 
573                   * - this wild card will get expanded into that pCode
574                   *   that is stored at this index */
575
576   /* Conditions on wild pcode instruction */
577   int    mustBeBitSkipInst:1;
578   int    mustNotBeBitSkipInst:1;
579   int    invertBitSkipInst:1;
580
581   pCodeOp *operand;  // Optional operand
582   pCodeOp *label;    // Optional label
583
584 } pCodeWild;
585
586 /*************************************************
587     pBlock
588
589     Here are PIC program snippets. There's a strong
590     correlation between the eBBlocks and pBlocks.
591     SDCC subdivides a C program into managable chunks.
592     Each chunk becomes a eBBlock and ultimately in the
593     PIC port a pBlock.
594
595 **************************************************/
596
597 typedef struct pBlock
598 {
599   memmap *cmemmap;   /* The snippet is from this memmap */
600   char   dbName;     /* if cmemmap is NULL, then dbName will identify the block */
601   pCode *pcHead;     /* A pointer to the first pCode in a link list of pCodes */
602   pCode *pcTail;     /* A pointer to the last pCode in a link list of pCodes */
603
604   struct pBlock *next;      /* The pBlocks will form a doubly linked list */
605   struct pBlock *prev;
606
607   set *function_entries;    /* dll of functions in this pblock */
608   set *function_exits;
609   set *function_calls;
610   set *tregisters;
611
612   set *FlowTree;
613   unsigned visited:1;       /* set true if traversed in call tree */
614
615   unsigned seq;             /* sequence number of this pBlock */
616
617 } pBlock;
618
619 /*************************************************
620     pFile
621
622     The collection of pBlock program snippets are
623     placed into a linked list that is implemented
624     in the pFile structure.
625
626     The pcode optimizer will parse the pFile.
627
628 **************************************************/
629
630 typedef struct pFile
631 {
632   pBlock *pbHead;     /* A pointer to the first pBlock */
633   pBlock *pbTail;     /* A pointer to the last pBlock */
634
635   pBranch *functions; /* A SLL of functions in this pFile */
636
637 } pFile;
638
639
640
641 /*************************************************
642   pCodeWildBlock
643
644   The pCodeWildBlock object keeps track of the wild
645   variables, operands, and opcodes that exist in
646   a pBlock.
647 **************************************************/
648 typedef struct pCodeWildBlock {
649   pBlock    *pb;
650   struct pCodePeep *pcp;    // pointer back to ... I don't like this...
651
652   int       nvars;          // Number of wildcard registers in target.
653   char    **vars;           // array of pointers to them
654
655   int       nops;           // Number of wildcard operands in target.
656   pCodeOp **wildpCodeOps;   // array of pointers to the pCodeOp's.
657
658   int       nwildpCodes;    // Number of wildcard pCodes in target/replace
659   pCode   **wildpCodes;     // array of pointers to the pCode's.
660
661 } pCodeWildBlock;
662
663 /*************************************************
664   pCodePeep
665
666   The pCodePeep object mimics the peep hole optimizer
667   in the main SDCC src (e.g. SDCCpeeph.c). Essentially
668   there is a target pCode chain and a replacement
669   pCode chain. The target chain is compared to the
670   pCode that is generated by gen.c. If a match is
671   found then the pCode is replaced by the replacement
672   pCode chain.
673 **************************************************/
674 typedef struct pCodePeep {
675   pCodeWildBlock target;     // code we'd like to optimize
676   pCodeWildBlock replace;    // and this is what we'll optimize it with.
677
678   //pBlock *target;
679   //pBlock replace;            // and this is what we'll optimize it with.
680
681
682
683   /* (Note: a wildcard register is a place holder. Any register
684    * can be replaced by the wildcard when the pcode is being 
685    * compared to the target. */
686
687   /* Post Conditions. A post condition is a condition that
688    * must be either true or false before the peep rule is
689    * accepted. For example, a certain rule may be accepted
690    * if and only if the Z-bit is not used as an input to 
691    * the subsequent instructions in a pCode chain.
692    */
693   unsigned int postFalseCond;  
694   unsigned int postTrueCond;
695
696 } pCodePeep;
697
698 /*************************************************
699
700   pCode peep command definitions 
701
702  Here are some special commands that control the
703 way the peep hole optimizer behaves
704
705 **************************************************/
706
707 enum peepCommandTypes{
708   NOTBITSKIP = 0,
709   BITSKIP,
710   INVERTBITSKIP,
711   _LAST_PEEP_COMMAND_
712 };
713
714 /*************************************************
715     peepCommand structure stores the peep commands.
716
717 **************************************************/
718
719 typedef struct peepCommand {
720   int id;
721   char *cmd;
722 } peepCommand;
723
724 /*************************************************
725     pCode Macros
726
727 **************************************************/
728 #define PCODE(x)  ((pCode *)(x))
729 #define PCI(x)    ((pCodeInstruction *)(x))
730 #define PCL(x)    ((pCodeLabel *)(x))
731 #define PCF(x)    ((pCodeFunction *)(x))
732 #define PCFL(x)   ((pCodeFlow *)(x))
733 #define PCW(x)    ((pCodeWild *)(x))
734 #define PCCS(x)   ((pCodeCSource *)(x))
735
736 #define PCOP(x)   ((pCodeOp *)(x))
737 //#define PCOB(x)   ((pCodeOpBit *)(x))
738 #define PCOL(x)   ((pCodeOpLit *)(x))
739 #define PCOI(x)   ((pCodeOpImmd *)(x))
740 #define PCOLAB(x) ((pCodeOpLabel *)(x))
741 #define PCOR(x)   ((pCodeOpReg *)(x))
742 #define PCORB(x)  ((pCodeOpRegBit *)(x))
743 #define PCOW(x)   ((pCodeOpWild *)(x))
744
745 #define PBR(x)    ((pBranch *)(x))
746
747 #define PCWB(x)   ((pCodeWildBlock *)(x))
748
749
750 /*
751   macros for checking pCode types
752 */
753 #define isPCI(x)        ((PCODE(x)->type == PC_OPCODE))
754 #define isPCI_BRANCH(x) ((PCODE(x)->type == PC_OPCODE) &&  PCI(x)->isBranch)
755 #define isPCI_SKIP(x)   ((PCODE(x)->type == PC_OPCODE) &&  PCI(x)->isSkip)
756 #define isPCI_BITSKIP(x)((PCODE(x)->type == PC_OPCODE) &&  PCI(x)->isSkip && PCI(x)->isBitInst)
757 #define isPCFL(x)       ((PCODE(x)->type == PC_FLOW))
758 #define isPCF(x)        ((PCODE(x)->type == PC_FUNCTION))
759 #define isPCL(x)        ((PCODE(x)->type == PC_LABEL))
760 #define isPCW(x)        ((PCODE(x)->type == PC_WILD))
761 #define isPCCS(x)       ((PCODE(x)->type == PC_CSOURCE))
762
763 #define isCALL(x)       ((isPCI(x)) && (PCI(x)->op == POC_CALL))
764 #define isSTATUS_REG(r) ((r)->pc_type == PO_STATUS)
765
766 #define isPCOLAB(x)     ((PCOP(x)->type) == PO_LABEL)
767
768 /*-----------------------------------------------------------------*
769  * pCode functions.
770  *-----------------------------------------------------------------*/
771
772 pCode *newpCode (PIC_OPCODE op, pCodeOp *pcop); // Create a new pCode given an operand
773 pCode *newpCodeCharP(char *cP);              // Create a new pCode given a char *
774 pCode *newpCodeInlineP(char *cP);            // Create a new pCode given a char *
775 pCode *newpCodeFunction(char *g, char *f);   // Create a new function
776 pCode *newpCodeLabel(char *name,int key);    // Create a new label given a key
777 pCode *newpCodeCSource(int ln, char *f, char *l); // Create a new symbol line 
778 pBlock *newpCodeChain(memmap *cm,char c, pCode *pc); // Create a new pBlock
779 void printpBlock(FILE *of, pBlock *pb);      // Write a pBlock to a file
780 void printpCode(FILE *of, pCode *pc);        // Write a pCode to a file
781 void addpCode2pBlock(pBlock *pb, pCode *pc); // Add a pCode to a pBlock
782 void addpBlock(pBlock *pb);                  // Add a pBlock to a pFile
783 void copypCode(FILE *of, char dbName);       // Write all pBlocks with dbName to *of
784 void movepBlock2Head(char dbName);           // move pBlocks around
785 void AnalyzepCode(char dbName);
786 int OptimizepCode(char dbName);
787 void printCallTree(FILE *of);
788 void pCodePeepInit(void);
789 void pBlockConvert2ISR(pBlock *pb);
790
791 pCodeOp *newpCodeOpLabel(char *name, int key);
792 pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space);
793 pCodeOp *newpCodeOpLit(int lit);
794 pCodeOp *newpCodeOpBit(char *name, int bit,int inBitSpace);
795 pCodeOp *newpCodeOpRegFromStr(char *name);
796 pCodeOp *newpCodeOp(char *name, PIC_OPTYPE p);
797 pCodeOp *pCodeOpCopy(pCodeOp *pcop);
798
799 pCode * findNextInstruction(pCode *pci);
800 pCode * findNextpCode(pCode *pc, PC_TYPE pct);
801 int isPCinFlow(pCode *pc, pCode *pcflow);
802 struct regs * getRegFromInstruction(pCode *pc);
803
804 extern void pcode_test(void);
805
806 /*-----------------------------------------------------------------*
807  * pCode objects.
808  *-----------------------------------------------------------------*/
809
810 extern pCodeOpReg pc_status;
811 extern pCodeOpReg pc_intcon;
812 extern pCodeOpReg pc_indf;
813 extern pCodeOpReg pc_fsr;
814 extern pCodeOpReg pc_pcl;
815 extern pCodeOpReg pc_pclath;
816 extern pCodeOpReg pc_kzero;
817 extern pCodeOpReg pc_wsave;     /* wsave and ssave are used to save W and the Status */
818 extern pCodeOpReg pc_ssave;     /* registers during an interrupt */
819
820
821 #endif // __PCODE_H__