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)
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 SDCCGENPIC14_H
28 #define SDCCGENPIC14_H
36 AOP_DPTR, AOP_DPTR2, AOP_R0, AOP_R1,
37 AOP_STK, AOP_IMMD, AOP_STR,
43 /* type asmop : a homogenised type for
44 all the different spaces an operand can be
49 short type; /* can have values
50 AOP_LIT - operand is a literal value
51 AOP_REG - is in registers
52 AOP_DIR - direct just a name
53 AOP_DPTR - dptr contains address of operand
54 AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
55 AOP_R0/R1 - r0/r1 contains address of operand
56 AOP_STK - should be pushed on stack this
57 can happen only for the result
58 AOP_IMMD - immediate value for eg. remateriazable
59 AOP_CRY - carry contains the value of this
60 AOP_STR - array of strings
61 AOP_ACC - result is in the acc:b pair
63 short coff; /* current offset */
64 short size; /* total size */
65 unsigned code:1; /* is in Code space */
66 unsigned paged:1; /* in paged memory */
67 unsigned freed:1; /* already freed */
70 value *aop_lit; /* if literal */
71 regs *aop_reg[4]; /* array of registers */
72 char *aop_dir; /* if direct */
73 regs *aop_ptr; /* either -> to r0 or r1 */
74 char *aop_immd; /* if immediate others are implied */
75 int aop_stk; /* stack offset when AOP_STK */
76 char *aop_str[4]; /* just a string array containing the location */
77 /* regs *aop_alloc_reg; * points to a dynamically allocated register */
84 void genpic16Code (iCode *);
86 //extern char *fReturnpic16[];
87 //extern char *fReturn390[];
88 extern unsigned pic16_fReturnSizePic;
89 //extern char **fReturn;
92 #define AOP(op) op->aop
93 #define AOP_TYPE(op) AOP(op)->type
94 #define AOP_SIZE(op) AOP(op)->size
95 #define IS_AOP_PREG(x) (AOP(x) && (AOP_TYPE(x) == AOP_R1 || \
96 AOP_TYPE(x) == AOP_R0))
98 #define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || \
99 AOP_TYPE(x) == AOP_DPTR || AOP_TYPE(x) == AOP_DPTR2 || \
102 #define AOP_INPREG(x) (x && (x->type == AOP_REG && \
103 (x->aopu.aop_reg[0] == pic16_regWithIdx(R0_IDX) || \
104 x->aopu.aop_reg[0] == pic16_regWithIdx(R1_IDX) )))
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")) pic16_emitcode(";XXX mov","a,%s %s,%d",x,__FILE__,__LINE__);
111 #define CLRC pic16_emitcode(";XXX clr","c %s,%d",__FILE__,__LINE__);
114 #define BIT_NUMBER(x) (x & 7)
115 #define BIT_REGISTER(x) (x>>3)
124 #define FUNCTION_LABEL_INC 40
126 /*-----------------------------------------------------------------*/
127 /* Macros for emitting skip instructions */
128 /*-----------------------------------------------------------------*/
130 #define emitSKPC pic16_emitpcode(POC_BTFSS,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
131 #define emitSKPNC pic16_emitpcode(POC_BTFSC,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
132 #define emitSKPZ pic16_emitpcode(POC_BTFSS,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
133 #define emitSKPNZ pic16_emitpcode(POC_BTFSC,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
134 #define emitSKPDC pic16_emitpcode(POC_BTFSS,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
135 #define emitSKPNDC pic16_emitpcode(POC_BTFSC,pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
136 #define emitCLRZ pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
137 #define emitCLRC pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
138 #define emitCLRDC pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
139 #define emitSETZ pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_Z_BIT))
140 #define emitSETC pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
141 #define emitSETDC pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
143 int pic16_getDataSize(operand *op);
144 void pic16_emitpcode(PIC_OPCODE poc, pCodeOp *pcop);
145 void pic16_emitpLabel(int key);
146 void pic16_emitcode (char *inst,char *fmt, ...);
147 void DEBUGpic16_emitcode (char *inst,char *fmt, ...);
148 bool pic16_sameRegs (asmop *aop1, asmop *aop2 );
149 char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname);
152 bool pic16_genPlusIncr (iCode *ic);
153 void pic16_outBitAcc(operand *result);
154 void pic16_genPlusBits (iCode *ic);
155 void pic16_genPlus (iCode *ic);
156 bool pic16_genMinusDec (iCode *ic);
157 void pic16_addSign(operand *result, int offset, int sign);
158 void pic16_genMinusBits (iCode *ic);
159 void pic16_genMinus (iCode *ic);
162 pCodeOp *pic16_popGetLabel(unsigned int key);
163 pCodeOp *pic16_popCopyReg(pCodeOpReg *pc);
164 pCodeOp *pic16_popCopyGPR2Bit(pCodeOp *pc, int bitval);
165 pCodeOp *pic16_popGetLit(unsigned int lit);
166 pCodeOp *popGetWithString(char *str);
167 pCodeOp *pic16_popGet (asmop *aop, int offset);//, bool bit16, bool dname);
168 pCodeOp *pic16_popGetTempReg(void);
169 void pic16_popReleaseTempReg(pCodeOp *pcop);
172 void pic16_aopPut (asmop *aop, char *s, int offset);
173 void pic16_outAcc(operand *result);
174 void pic16_aopOp (operand *op, iCode *ic, bool result);
175 void pic16_outBitC(operand *result);
176 void pic16_toBoolean(operand *oper);
177 void pic16_freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop);
178 const char *pic16_pCodeOpType( pCodeOp *pcop);
181 void dumpiCode(iCode *lic);