1 /*-------------------------------------------------------------------------
2 gen.h - header file for code generation for PIC16
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
5 PIC port - T. Scott Dattalo scott@dattalo.com (2000)
6 PIC16 port - Martin Dubuc m.dubuc@rogers.com (2000)
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 In other words, you are welcome to use, share and improve this program.
23 You are forbidden to forbid anyone else to use, share and improve
24 what you give them. Help stamp out software-hoarding!
25 -------------------------------------------------------------------------*/
27 #ifndef SDCCGENPIC16_H
28 #define SDCCGENPIC16_H
42 AOP_STA // asmop on stack
45 /* type asmop : a homogenised type for
46 all the different spaces an operand can be
51 short type; /* can have values
52 AOP_LIT - operand is a literal value
53 AOP_REG - is in registers
54 AOP_DIR - direct just a name
55 AOP_STK - should be pushed on stack this
56 can happen only for the result
57 AOP_CRY - carry contains the value of this
58 AOP_STR - array of strings
59 AOP_ACC - result is in the acc:b pair
61 short coff; /* current offset */
62 short size; /* total size */
63 unsigned code:1; /* is in Code space */
64 unsigned paged:1; /* in paged memory */
65 unsigned freed:1; /* already freed */
68 value *aop_lit; /* if literal */
69 regs *aop_reg[4]; /* array of registers */
70 char *aop_dir; /* if direct */
71 regs *aop_ptr; /* either -> to r0 or r1 */
72 int aop_stk; /* stack offset when AOP_STK */
73 char *aop_str[4]; /* just a string array containing the location */
74 /* regs *aop_alloc_reg; * points to a dynamically allocated register */
85 void genpic16Code (iCode *);
87 extern unsigned pic16_fReturnSizePic;
90 #define AOP(op) op->aop
91 #define AOP_TYPE(op) AOP(op)->type
92 #define AOP_SIZE(op) AOP(op)->size
94 #define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || \
97 #define RESULTONSTACK(x) \
98 (IC_RESULT(x) && IC_RESULT(x)->aop && \
99 IC_RESULT(x)->aop->type == AOP_STK )
100 #define RESULTONSTA(x) (IC_RESULT(x) && IC_RESULT(x)->aop && IC_RESULT(x)->aop->type == AOP_STA)
103 #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) pic16_emitcode(";XXX mov","a,%s %s,%d",x,__FILE__,__LINE__);
104 #define CLRC pic16_emitcode(";XXX clr","c %s,%d",__FILE__,__LINE__);
107 #define BIT_NUMBER(x) (x & 7)
108 #define BIT_REGISTER(x) (x>>3)
117 #define FUNCTION_LABEL_INC 40
119 /*-----------------------------------------------------------------*/
120 /* Macros for emitting skip instructions */
121 /*-----------------------------------------------------------------*/
123 #define emitSKPC pic16_emitpcode(POC_BTFSS,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
124 #define emitSKPNC pic16_emitpcode(POC_BTFSC,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
125 #define emitSKPZ pic16_emitpcode(POC_BTFSS,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
126 #define emitSKPNZ pic16_emitpcode(POC_BTFSC,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
127 #define emitSKPDC pic16_emitpcode(POC_BTFSS,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
128 #define emitSKPNDC pic16_emitpcode(POC_BTFSC,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
129 #define emitCLRZ pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
130 #define emitCLRC pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
131 #define emitCLRDC pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
132 #define emitSETZ pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
133 #define emitSETC pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
134 #define emitSETDC pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
136 #define emitTOGC pic16_emitpcode(POC_BTG, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
138 int pic16_getDataSize(operand *op);
139 void pic16_emitpcode_real(PIC_OPCODE poc, pCodeOp *pcop);
140 #define pic16_emitpcode(poc,pcop) do { if (pic16_pcode_verbose) pic16_emitpcomment ("%s:%u(%s):", __FILE__, __LINE__, __FUNCTION__); pic16_emitpcode_real(poc,pcop); } while(0)
141 void pic16_emitpLabel(int key);
142 void pic16_emitcode (char *inst,char *fmt, ...);
143 void DEBUGpic16_emitcode (char *inst,char *fmt, ...);
144 void pic16_emitDebuggerSymbol (char *);
145 bool pic16_sameRegs (asmop *aop1, asmop *aop2 );
146 char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname);
147 void DEBUGpic16_pic16_AopType(int line_no, operand *left, operand *right, operand *result);
148 void DEBUGpic16_pic16_AopTypeSign(int line_no, operand *left, operand *right, operand *result);
151 bool pic16_genPlusIncr (iCode *ic);
152 void pic16_outBitAcc(operand *result);
153 void pic16_genPlusBits (iCode *ic);
154 void pic16_genPlus (iCode *ic);
155 bool pic16_genMinusDec (iCode *ic);
156 void pic16_addSign(operand *result, int offset, int sign);
157 void pic16_genMinusBits (iCode *ic);
158 void pic16_genMinus (iCode *ic);
159 void pic16_genLeftShiftLiteral (operand *left, operand *right, operand *result, iCode *ic);
161 pCodeOp *pic16_popGet2p(pCodeOp *src, pCodeOp *dst);
162 void pic16_emitpcomment (char *fmt, ...);
164 pCodeOp *pic16_popGetLabel(int key);
165 pCodeOp *pic16_popCopyReg(pCodeOpReg *pc);
166 pCodeOp *pic16_popCopyGPR2Bit(pCodeOp *pc, int bitval);
167 pCodeOp *pic16_popGetLit(int lit);
168 pCodeOp *pic16_popGetLit2(int lit, pCodeOp *arg2);
169 pCodeOp *popGetWithString(char *str);
170 pCodeOp *pic16_popGet (asmop *aop, int offset);//, bool bit16, bool dname);
171 pCodeOp *pic16_popGetTempReg(int lock);
172 pCodeOp *pic16_popGetTempRegCond(bitVect *, bitVect *, int lock);
173 void pic16_popReleaseTempReg(pCodeOp *pcop, int lock);
175 pCodeOp *pic16_popCombine2(pCodeOpReg *src, pCodeOpReg *dst, int noalloc);
177 void pic16_aopPut (asmop *aop, char *s, int offset);
178 void pic16_outAcc(operand *result);
179 void pic16_aopOp (operand *op, iCode *ic, bool result);
180 void pic16_outBitC(operand *result);
181 void pic16_toBoolean(operand *oper);
182 void pic16_freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop);
183 const char *pic16_pCodeOpType( pCodeOp *pcop);
184 int pic16_my_powof2 (unsigned long num);
186 void pic16_mov2w (asmop *aop, int offset);
187 void pic16_mov2f(asmop *dst, asmop *src, int offset);
189 bool pic16_isLitOp(operand *op);
190 bool pic16_isLitAop(asmop *aop);
192 void dumpiCode(iCode *lic);
194 int inWparamList(char *s);
198 #define DUMP_FUNCTION_ENTRY 1
199 #define DUMP_FUNCTION_EXIT 0
201 #if DUMP_FUNCTION_ENTRY
202 #define FENTRY if(pic16_options.debgen&2)pic16_emitpcomment("**{\t%d %s", __LINE__, __FUNCTION__)
203 #define FENTRY2 if(pic16_options.debgen&2)pic16_emitpcomment("**{\t%d %s", __LINE__, __FUNCTION__)
209 #if DUMP_FUNCTION_EXIT
210 #define FEXIT if(pic16_options.debgen&2)pic16_emitpcomment("; **}", "%d %s", __LINE__, __FUNCTION__)
211 #define FEXIT2 if(pic16_options.debgen&2)pic16_emitpcomment("**{\t%d %s", __LINE__, __FUNCTION__)
217 #define ERROR werror(W_POSSBUG2, __FILE__, __LINE__)