and - Jean-Louis VERN.jlvern@writeme.com (1999)
Bug Fixes - Wojciech Stryjewski wstryj1@tiger.lsu.edu (1999 v2.1.9a)
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- In other words, you are welcome to use, share and improve this program.
- You are forbidden to forbid anyone else to use, share and improve
- what you give them. Help stamp out software-hoarding!
-
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ In other words, you are welcome to use, share and improve this program.
+ You are forbidden to forbid anyone else to use, share and improve
+ what you give them. Help stamp out software-hoarding!
+
+ Notes:
+ 000123 mlh Moved aopLiteral to SDCCglue.c to help the split
+ Made everything static
-------------------------------------------------------------------------*/
#include <stdio.h>
#include "common.h"
#include "SDCCpeeph.h"
+#include "ralloc.h"
#include "gen.h"
+char *aopLiteral (value *val, int offset);
+
/* this is the down and dirty file with all kinds of
kludgy & hacky stuff. This is what it is all about
CODE GENERATION for a specific MCU . some of the
/*-----------------------------------------------------------------*/
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
-void emitcode (char *inst,char *fmt, ...)
+static void emitcode (char *inst,char *fmt, ...)
{
va_list ap;
char lb[MAX_INLINEASM];
if (!r0iu && !r0ou) {
ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
(*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx(R0_IDX);
}
/* if no usage of r1 then return it */
if (!r1iu && !r1ou) {
ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
(*aopp)->type = AOP_R1;
- return (*aopp)->aopu.aop_ptr = regWithIdx(R1_IDX);
+ return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx(R1_IDX);
}
/* now we know they both have usage */
/* push it if not already pushed */
if (!_G.r0Pushed) {
emitcode ("push","%s",
- regWithIdx(R0_IDX)->dname);
+ mcs51_regWithIdx(R0_IDX)->dname);
_G.r0Pushed++ ;
}
ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
(*aopp)->type = AOP_R0;
- return (*aopp)->aopu.aop_ptr = regWithIdx(R0_IDX);
+ return (*aopp)->aopu.aop_ptr = mcs51_regWithIdx(R0_IDX);
}
/* if r1 not used then */
/* push it if not already pushed */
if (!_G.r1Pushed) {
emitcode ("push","%s",
- regWithIdx(R1_IDX)->dname);
+ mcs51_regWithIdx(R1_IDX)->dname);
_G.r1Pushed++ ;
}
ic->rUsed = bitVectSetBit(ic->rUsed,R1_IDX);
(*aopp)->type = AOP_R1;
- return regWithIdx(R1_IDX);
+ return mcs51_regWithIdx(R1_IDX);
}
/*-----------------------------------------------------------------*/
/* regsInCommon - two operands have some registers in common */
/*-----------------------------------------------------------------*/
-bool regsInCommon (operand *op1, operand *op2)
+static bool regsInCommon (operand *op1, operand *op2)
{
symbol *sym1, *sym2;
int i;
/*-----------------------------------------------------------------*/
/* operandsEqu - equivalent */
/*-----------------------------------------------------------------*/
-bool operandsEqu ( operand *op1, operand *op2)
+static bool operandsEqu ( operand *op1, operand *op2)
{
symbol *sym1, *sym2;
/*-----------------------------------------------------------------*/
/* sameRegs - two asmops have the same registers */
/*-----------------------------------------------------------------*/
-bool sameRegs (asmop *aop1, asmop *aop2 )
+static bool sameRegs (asmop *aop1, asmop *aop2 )
{
int i;
}
}
-/*-----------------------------------------------------------------*/
-/* aopLiteral - string from a literal value */
-/*-----------------------------------------------------------------*/
-char *aopLiteral (value *val, int offset)
-{
- char *rs;
- union {
- float f;
- unsigned char c[4];
- } fl;
-
- /* if it is a float then it gets tricky */
- /* otherwise it is fairly simple */
- if (!IS_FLOAT(val->type)) {
- unsigned long v = floatFromVal(val);
-
- v >>= (offset * 8);
- sprintf(buffer,"#0x%02x",((char) v) & 0xff);
- ALLOC_ATOMIC(rs,strlen(buffer)+1);
- return strcpy (rs,buffer);
- }
-
- /* it is type float */
- fl.f = (float) floatFromVal(val);
-#ifdef _BIG_ENDIAN
- sprintf(buffer,"#0x%02x",fl.c[3-offset]);
-#else
- sprintf(buffer,"#0x%02x",fl.c[offset]);
-#endif
- ALLOC_ATOMIC(rs,strlen(buffer)+1);
- return strcpy (rs,buffer);
-}
-
/*-----------------------------------------------------------------*/
/* aopGet - for fetching value of the aop */
/*-----------------------------------------------------------------*/
AOP_TYPE(x) == AOP_DPTR || AOP(x)->paged))
#define AOP_INPREG(x) (x && (x->type == AOP_REG && \
- (x->aopu.aop_reg[0] == regWithIdx(R0_IDX) || \
- x->aopu.aop_reg[0] == regWithIdx(R1_IDX) )))
+ (x->aopu.aop_reg[0] == mcs51_regWithIdx(R0_IDX) || \
+ x->aopu.aop_reg[0] == mcs51_regWithIdx(R1_IDX) )))
/*-----------------------------------------------------------------*/
/* genNotFloat - generates not for float operations */
/*-----------------------------------------------------------------*/
/* getDataSize - get the operand data size */
/*-----------------------------------------------------------------*/
-int getDataSize(operand *op)
+static int getDataSize(operand *op)
{
int size;
size = AOP_SIZE(op);
/*-----------------------------------------------------------------*/
/* outAcc - output Acc */
/*-----------------------------------------------------------------*/
-void outAcc(operand *result)
+static void outAcc(operand *result)
{
int size, offset;
size = getDataSize(result);
/*-----------------------------------------------------------------*/
/* outBitC - output a bit C */
/*-----------------------------------------------------------------*/
-void outBitC(operand *result)
+static void outBitC(operand *result)
{
/* if the result is bit */
if (AOP_TYPE(result) == AOP_CRY)
/*-----------------------------------------------------------------*/
/* toBoolean - emit code for orl a,operator(sizeop) */
/*-----------------------------------------------------------------*/
-void toBoolean(operand *oper)
+static void toBoolean(operand *oper)
{
int size = AOP_SIZE(oper) - 1;
int offset = 1;
if (i == R0_IDX)
emitcode("mov","a,b");
else
- emitcode("mov","a,%s",regWithIdx(i)->name);
+ emitcode("mov","a,%s",mcs51_regWithIdx(i)->name);
emitcode("movx","@r0,a");
emitcode("inc","r0");
}
} else
for (i = 0 ; i < mcs51_nRegs ; i++) {
if (bitVectBitValue(rsave,i))
- emitcode("push","%s",regWithIdx(i)->dname);
+ emitcode("push","%s",mcs51_regWithIdx(i)->dname);
}
detype = getSpec(operandType(IC_LEFT(ic)));
if (i == R0_IDX)
emitcode("mov","b,a");
else
- emitcode("mov","%s,a",regWithIdx(i)->name);
+ emitcode("mov","%s,a",mcs51_regWithIdx(i)->name);
}
}
} else
for (i = mcs51_nRegs ; i >= 0 ; i--) {
if (bitVectBitValue(rsave,i))
- emitcode("pop","%s",regWithIdx(i)->dname);
+ emitcode("pop","%s",mcs51_regWithIdx(i)->dname);
}
}
/*-----------------------------------------------------------------*/
/* pushSide - */
/*-----------------------------------------------------------------*/
-void pushSide(operand * oper, int size)
+static void pushSide(operand * oper, int size)
{
int offset = 0;
while (size--) {
/*-----------------------------------------------------------------*/
/* assignResultValue - */
/*-----------------------------------------------------------------*/
-void assignResultValue(operand * oper)
+static void assignResultValue(operand * oper)
{
int offset = 0;
int size = AOP_SIZE(oper);
for ( i = 0 ; i < sym->regsUsed->size ; i++) {
if (bitVectBitValue(sym->regsUsed,i) ||
(mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("push","%s",regWithIdx(i)->dname);
+ emitcode("push","%s",mcs51_regWithIdx(i)->dname);
}
}
for ( i = 0 ; i < sym->regsUsed->size ; i++) {
if (bitVectBitValue(sym->regsUsed,i) ||
(mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) ) {
- emitcode("push","%s",regWithIdx(i)->dname);
+ emitcode("push","%s",mcs51_regWithIdx(i)->dname);
_G.nRegsSaved++;
}
}
for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
if (bitVectBitValue(sym->regsUsed,i) ||
(mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",regWithIdx(i)->dname);
+ emitcode("pop","%s",mcs51_regWithIdx(i)->dname);
}
}
for ( i = sym->regsUsed->size ; i >= 0 ; i--) {
if (bitVectBitValue(sym->regsUsed,i) ||
(mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)) )
- emitcode("pop","%s",regWithIdx(i)->dname);
+ emitcode("pop","%s",mcs51_regWithIdx(i)->dname);
}
}
/*-----------------------------------------------------------------*/
/* outBitAcc - output a bit in acc */
/*-----------------------------------------------------------------*/
-void outBitAcc(operand *result)
+static void outBitAcc(operand *result)
{
symbol *tlbl = newiTempLabel(NULL);
/* if the result is a bit */
/*-----------------------------------------------------------------*/
/* isLiteralBit - test if lit == 2^n */
/*-----------------------------------------------------------------*/
-int isLiteralBit(unsigned long lit)
+static int isLiteralBit(unsigned long lit)
{
unsigned long pw[32] = {1L,2L,4L,8L,16L,32L,64L,128L,
0x100L,0x200L,0x400L,0x800L,
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
-regs *allocReg (short type)
+static regs *allocReg (short type)
{
int i;
}
/*-----------------------------------------------------------------*/
-/* regWithIdx - returns pointer to register wit index number */
+/* mcs51_regWithIdx - returns pointer to register wit index number */
/*-----------------------------------------------------------------*/
-regs *regWithIdx (int idx)
+regs *mcs51_regWithIdx (int idx)
{
int i ;
/*-----------------------------------------------------------------*/
/* freeReg - frees a register */
/*-----------------------------------------------------------------*/
-void freeReg (regs *reg)
+static void freeReg (regs *reg)
{
reg->isFree = 1;
}
/*-----------------------------------------------------------------*/
/* nFreeRegs - returns number of free registers */
/*-----------------------------------------------------------------*/
-int nFreeRegs (int type)
+static int nFreeRegs (int type)
{
int i;
int nfr=0;
/*-----------------------------------------------------------------*/
/* nfreeRegsType - free registers with type */
/*-----------------------------------------------------------------*/
-int nfreeRegsType (int type)
+static int nfreeRegsType (int type)
{
int nfr ;
if (type == REG_PTR) {
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
/*-----------------------------------------------------------------*/
-bool allDefsOutOfRange (bitVect *defs,int fseq, int toseq)
+static bool allDefsOutOfRange (bitVect *defs,int fseq, int toseq)
{
int i ;
/*-----------------------------------------------------------------*/
/* computeSpillable - given a point find the spillable live ranges */
/*-----------------------------------------------------------------*/
-bitVect *computeSpillable (iCode *ic)
+static bitVect *computeSpillable (iCode *ic)
{
bitVect *spillable ;
/*-----------------------------------------------------------------*/
/* noSpilLoc - return true if a variable has no spil location */
/*-----------------------------------------------------------------*/
-int noSpilLoc (symbol *sym, eBBlock *ebp,iCode *ic)
+static int noSpilLoc (symbol *sym, eBBlock *ebp,iCode *ic)
{
return (sym->usl.spillLoc ? 0 : 1);
}
/*-----------------------------------------------------------------*/
/* hasSpilLoc - will return 1 if the symbol has spil location */
/*-----------------------------------------------------------------*/
-int hasSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int hasSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
{
return (sym->usl.spillLoc ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* directSpilLoc - will return 1 if the splilocation is in direct */
/*-----------------------------------------------------------------*/
-int directSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
+static int directSpilLoc (symbol *sym, eBBlock *ebp, iCode *ic)
{
if ( sym->usl.spillLoc &&
(IN_DIRSPACE(SPEC_OCLS(sym->usl.spillLoc->etype))))
/* hasSpilLocnoUptr - will return 1 if the symbol has spil location*/
/* but is not used as a pointer */
/*-----------------------------------------------------------------*/
-int hasSpilLocnoUptr (symbol *sym, eBBlock *ebp, iCode *ic)
+static int hasSpilLocnoUptr (symbol *sym, eBBlock *ebp, iCode *ic)
{
return ((sym->usl.spillLoc && !sym->uptr) ? 1 : 0);
}
/*-----------------------------------------------------------------*/
/* rematable - will return 1 if the remat flag is set */
/*-----------------------------------------------------------------*/
-int rematable (symbol *sym, eBBlock *ebp, iCode *ic)
+static int rematable (symbol *sym, eBBlock *ebp, iCode *ic)
{
return sym->remat;
}
/*-----------------------------------------------------------------*/
/* notUsedInBlock - not used in this block */
/*-----------------------------------------------------------------*/
-int notUsedInBlock (symbol *sym, eBBlock *ebp, iCode *ic)
+static int notUsedInBlock (symbol *sym, eBBlock *ebp, iCode *ic)
{
return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs) &&
allDefsOutOfRange (sym->defs,ebp->fSeq,ebp->lSeq));
bitVectIsZero(_G.regAssigned))
return;
- r0 = regWithIdx(R0_IDX);
- r1 = regWithIdx(R1_IDX);
+ r0 = mcs51_regWithIdx(R0_IDX);
+ r1 = mcs51_regWithIdx(R1_IDX);
/* for all live ranges */
for (lrsym = hTabFirstItem(liveRanges,&k) ; lrsym ;