1 /*-------------------------------------------------------------------------
2 SDCCgen51.h - header file for code generation for 8051
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
5 PIC port - T. Scott Dattalo scott@dattalo.com (2000)
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
26 #ifndef SDCCGENPIC14_H
27 #define SDCCGENPIC14_H
36 /*fprintf (stderr, "%s:%u:%s: *{*\n", __FILE__, __LINE__, __FUNCTION__);*/ \
37 if (options.debug || debug_verbose) { \
38 emitpComment ("; %s:%u:%s *{*", __FILE__, __LINE__, __FUNCTION__); \
42 /*fprintf (stderr, "%s:%u:%s: *}*\n", __FILE__, __LINE__, __FUNCTION__);*/ \
43 if (options.debug || debug.verbose) { \
44 emitpComment ("; %s:%u:%s *}*", __FILE__, __LINE__, __FUNCTION__); \
61 /* type asmop : a homogenised type for
62 all the different spaces an operand can be
67 short type; /* can have values
68 AOP_LIT - operand is a literal value
69 AOP_REG - is in registers
70 AOP_DIR - direct just a name
71 AOP_STK - should be pushed on stack this
72 can happen only for the result
73 AOP_IMMD - immediate value for eg. remateriazable
74 AOP_CRY - carry contains the value of this
75 AOP_STR - array of strings
77 short coff; /* current offset */
78 short size; /* total size */
79 unsigned code:1; /* is in Code space */
80 unsigned paged:1; /* in paged memory */
81 unsigned freed:1; /* already freed */
84 value *aop_lit; /* if literal */
85 regs *aop_reg[4]; /* array of registers */
86 char *aop_dir; /* if direct */
87 regs *aop_ptr; /* either -> to r0 or r1 */
88 char *aop_immd; /* if immediate others are implied */
89 int aop_stk; /* stack offset when AOP_STK */
90 char *aop_str[4]; /* just a string array containing the location */
97 extern unsigned fReturnSizePic;
100 #define AOP(op) op->aop
101 #define AOP_TYPE(op) AOP(op)->type
102 #define AOP_SIZE(op) AOP(op)->size
104 #define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || AOP(x)->paged))
106 #define RESULTONSTACK(x) \
107 (IC_RESULT(x) && IC_RESULT(x)->aop && \
108 IC_RESULT(x)->aop->type == AOP_STK )
110 #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) pic14_emitcode(";XXX mov","a,%s %s,%d",x,__FILE__,__LINE__);
111 #define CLRC pic14_emitcode(";XXX clr","c %s,%d",__FILE__,__LINE__);
118 /*-----------------------------------------------------------------*/
119 /* Macros for emitting skip instructions */
120 /*-----------------------------------------------------------------*/
122 #define emitSKPC emitpcode(POC_BTFSS,popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
123 #define emitSKPNC emitpcode(POC_BTFSC,popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
124 #define emitSKPZ emitpcode(POC_BTFSS,popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
125 #define emitSKPNZ emitpcode(POC_BTFSC,popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
126 #define emitSKPDC emitpcode(POC_BTFSS,popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
127 #define emitSKPNDC emitpcode(POC_BTFSC,popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
128 #define emitCLRZ emitpcode(POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
129 #define emitCLRC emitpcode(POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
130 #define emitCLRDC emitpcode(POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
131 #define emitCLRIRP emitpcode(POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_IRP_BIT))
132 #define emitSETZ emitpcode(POC_BSF, popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
133 #define emitSETC emitpcode(POC_BSF, popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
134 #define emitSETDC emitpcode(POC_BSF, popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
135 #define emitSETIRP emitpcode(POC_BSF, popCopyGPR2Bit(PCOP(&pc_status),PIC_IRP_BIT))
137 int pic14_getDataSize(operand *op);
138 void emitpcode_real(PIC_OPCODE poc, pCodeOp *pcop);
139 #define emitpcode(poc,pcop) do { if (options.debug || debug_verbose) { emitpComment (" >>> %s:%d:%s", __FILE__, __LINE__, __FUNCTION__); } emitpcode_real(poc,pcop); } while(0)
140 void emitpComment (const char *fmt, ...);
141 void emitpLabel(int key);
142 void pic14_emitcode (char *inst,char *fmt, ...);
143 void DEBUGpic14_emitcode (char *inst,char *fmt, ...);
144 void pic14_emitDebuggerSymbol (char *);
145 bool pic14_sameRegs (asmop *aop1, asmop *aop2 );
146 char *aopGet (asmop *aop, int offset, bool bit16, bool dname);
147 void DEBUGpic14_AopType(int line_no, operand *left, operand *right, operand *result);
148 void genpic14Code (iCode *lic);
151 pCodeOp *popGet (asmop *aop, int offset);//, bool bit16, bool dname);
152 pCodeOp *popGetAddr (asmop *aop, int offset, int index);
153 pCodeOp *popGetExternal (char *str, int isReg);
154 pCodeOp *popGetLabel(unsigned int key);
155 pCodeOp *popGetLit(unsigned int lit);
158 void aopPut (asmop *aop, char *s, int offset);
159 void pic14_outAcc(operand *result);
160 void aopOp (operand *op, iCode *ic, bool result);
161 void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop);
162 void mov2w (asmop *aop, int offset);
163 int op_isLitLike (operand *op);
168 const char *AopType(short type);
169 const char *pCodeOpType(pCodeOp *pcop);
170 void genPlus (iCode *ic);
171 void addSign(operand *result, int offset, int sign);
172 void genMinus (iCode *ic);