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
35 AOP_DPTR, AOP_DPTR2, AOP_R0, AOP_R1,
36 AOP_STK, AOP_IMMD, AOP_STR,
42 /* type asmop : a homogenised type for
43 all the different spaces an operand can be
48 short type; /* can have values
49 AOP_LIT - operand is a literal value
50 AOP_REG - is in registers
51 AOP_DIR - direct just a name
52 AOP_DPTR - dptr contains address of operand
53 AOP_DPTR2 - dptr2 contains address of operand (DS80C390 only).
54 AOP_R0/R1 - r0/r1 contains address of operand
55 AOP_STK - should be pushed on stack this
56 can happen only for the result
57 AOP_IMMD - immediate value for eg. remateriazable
58 AOP_CRY - carry contains the value of this
59 AOP_STR - array of strings
60 AOP_ACC - result is in the acc:b pair
62 short coff; /* current offset */
63 short size; /* total size */
64 unsigned code:1; /* is in Code space */
65 unsigned paged:1; /* in paged memory */
66 unsigned freed:1; /* already freed */
69 value *aop_lit; /* if literal */
70 regs *aop_reg[4]; /* array of registers */
71 char *aop_dir; /* if direct */
72 regs *aop_ptr; /* either -> to r0 or r1 */
73 char *aop_immd; /* if immediate others are implied */
74 int aop_stk; /* stack offset when AOP_STK */
75 char *aop_str[4]; /* just a string array containing the location */
82 void genpic14Code (iCode *);
84 extern unsigned fReturnSizePic;
87 #define AOP(op) op->aop
88 #define AOP_TYPE(op) AOP(op)->type
89 #define AOP_SIZE(op) AOP(op)->size
90 #define IS_AOP_PREG(x) (AOP(x) && (AOP_TYPE(x) == AOP_R1 || \
91 AOP_TYPE(x) == AOP_R0))
93 #define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || \
94 AOP_TYPE(x) == AOP_DPTR || AOP_TYPE(x) == AOP_DPTR2 || \
97 #define AOP_INPREG(x) (x && (x->type == AOP_REG && \
98 (x->aopu.aop_reg[0] == pic14_regWithIdx(R0_IDX) || \
99 x->aopu.aop_reg[0] == pic14_regWithIdx(R1_IDX) )))
101 #define RESULTONSTACK(x) \
102 (IC_RESULT(x) && IC_RESULT(x)->aop && \
103 IC_RESULT(x)->aop->type == AOP_STK )
105 #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) pic14_emitcode(";XXX mov","a,%s %s,%d",x,__FILE__,__LINE__);
106 #define CLRC pic14_emitcode(";XXX clr","c %s,%d",__FILE__,__LINE__);
108 #define BIT_NUMBER(x) (x & 7)
109 #define BIT_REGISTER(x) (x>>3)
118 #define FUNCTION_LABEL_INC 40
120 /*-----------------------------------------------------------------*/
121 /* Macros for emitting skip instructions */
122 /*-----------------------------------------------------------------*/
124 #define emitSKPC emitpcode(POC_BTFSS,popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
125 #define emitSKPNC emitpcode(POC_BTFSC,popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
126 #define emitSKPZ emitpcode(POC_BTFSS,popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
127 #define emitSKPNZ emitpcode(POC_BTFSC,popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
128 #define emitSKPDC emitpcode(POC_BTFSS,popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
129 #define emitSKPNDC emitpcode(POC_BTFSC,popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
130 #define emitCLRZ emitpcode(POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
131 #define emitCLRC emitpcode(POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
132 #define emitCLRDC emitpcode(POC_BCF, popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
133 #define emitSETZ emitpcode(POC_BSF, popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT))
134 #define emitSETC emitpcode(POC_BSF, popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT))
135 #define emitSETDC emitpcode(POC_BSF, popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT))
137 int pic14_getDataSize(operand *op);
138 void emitpcode(PIC_OPCODE poc, pCodeOp *pcop);
139 void emitpLabel(int key);
140 void pic14_emitcode (char *inst,char *fmt, ...);
141 void DEBUGpic14_emitcode (char *inst,char *fmt, ...);
142 void pic14_emitDebuggerSymbol (char *);
143 asmop *newAsmop (short type);
144 bool pic14_sameRegs (asmop *aop1, asmop *aop2 );
145 char *aopGet (asmop *aop, int offset, bool bit16, bool dname);
148 bool genPlusIncr (iCode *ic);
149 void pic14_outBitAcc(operand *result);
150 void genPlusBits (iCode *ic);
151 void genPlus (iCode *ic);
152 bool genMinusDec (iCode *ic);
153 void addSign(operand *result, int offset, int sign);
154 void genMinusBits (iCode *ic);
155 void genMinus (iCode *ic);
158 pCodeOp *popGetLabel(unsigned int key);
159 pCodeOp *popCopyReg(pCodeOpReg *pc);
160 pCodeOp *popCopyGPR2Bit(pCodeOp *pc, int bitval);
161 pCodeOp *popGetLit(unsigned int lit);
162 pCodeOp *popGetWithString(char *str, int isExtern);
163 pCodeOp *popRegFromString(char *str, int size, int offset);
164 pCodeOp *popGet (asmop *aop, int offset);//, bool bit16, bool dname);
165 pCodeOp *popGetTempReg(void);
166 void popReleaseTempReg(pCodeOp *pcop);
169 void aopPut (asmop *aop, char *s, int offset);
170 void pic14_outAcc(operand *result);
171 void aopOp (operand *op, iCode *ic, bool result);
172 void pic14_outBitC(operand *result);
173 void pic14_toBoolean(operand *oper);
174 void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop);
175 void mov2w (asmop *aop, int offset);
176 const char *pCodeOpType( pCodeOp *pcop);