Made everything static
-------------------------------------------------------------------------*/
-//#define D(x)
-#define D(x) x
+#define D(x) do if (!options.noVerboseAsm) {x;} while(0)
#include <stdio.h>
#include <stdlib.h>
};
extern struct dbuf_s *codeOutBuf;
-static void saveRBank (int, iCode *, bool);
#define RESULTONSTACK(x) \
(IC_RESULT(x) && IC_RESULT(x)->aop && \
/* if the type is a conditional */
if (sym->regType == REG_CND)
{
- aop = op->aop = sym->aop = newAsmop (AOP_CRY);
- aop->size = 0;
+ sym->aop = op->aop = aop = newAsmop (AOP_CRY);
+ aop->size = sym->ruonly ? 1 : 0;
return;
}
if (sym->accuse)
{
int i;
- aop = op->aop = sym->aop = newAsmop (AOP_ACC);
+ sym->aop = op->aop = aop = newAsmop (AOP_ACC);
aop->size = getSize (sym->type);
for (i = 0; i < 2; i++)
aop->aopu.aop_str[i] = accUse[i];
{
unsigned i;
- aop = op->aop = sym->aop = newAsmop (AOP_STR);
+ sym->aop = op->aop = aop = newAsmop (AOP_STR);
aop->size = getSize (sym->type);
for (i = 0; i < fReturnSizeMCS51; i++)
aop->aopu.aop_str[i] = fReturn[i];
/* if the result is bit */
if (AOP_TYPE (result) == AOP_CRY)
{
- aopPut (result, "c", 0);
+ if (!OP_SYMBOL (result)->ruonly)
+ aopPut (result, "c", 0);
}
else
{
rsave = bitVectCplAnd (rsave, rsavebits);
rsave = bitVectSetBit (rsave, bitVectFirstBit (rsavebits));
}
+ freeBitVect (rsavebits);
if (count == 1)
{
}
}
}
+ freeBitVect (rsave);
}
/*-----------------------------------------------------------------*/
rsave = bitVectCplAnd (rsave, rsavebits);
rsave = bitVectSetBit (rsave, bitVectFirstBit (rsavebits));
}
+ freeBitVect (rsavebits);
if (count == 1)
{
}
}
}
+ freeBitVect (rsave);
}
saveRBank (int bank, iCode * ic, bool pushPsw)
{
int i;
- int count = 8 + ((mcs51_nRegs > 8) ? 1 : 0) + (pushPsw ? 1 : 0);
+ int count = 8 + (pushPsw ? 1 : 0);
asmop *aop = NULL;
regs *r = NULL;
if (!ic)
{
/* Assume r0 is available for use. */
- r = REG_WITH_INDEX (R0_IDX);;
+ r = REG_WITH_INDEX (R0_IDX);
}
else
{
regs8051[i].base, 8 * bank + regs8051[i].offset);
}
- if (mcs51_nRegs > 8)
- {
- if (options.useXstack)
- {
- emitcode ("mov", "a,bits");
- emitcode ("movx", "@%s,a", r->name);
- if (--count)
- emitcode ("inc", "%s", r->name);
- }
- else
- {
- emitcode ("push", "bits");
- }
- BitBankUsed = 1;
- }
-
if (pushPsw)
{
if (options.useXstack)
}
}
- if (mcs51_nRegs > 8)
- {
- if (options.useXstack)
- {
- emitcode ("dec", "%s", r->name);
- emitcode ("movx", "a,@%s", r->name);
- emitcode ("mov", "bits,a");
- }
- else
- {
- emitcode ("pop", "bits");
- }
- }
-
for (i = 7; i >= 0; i--)
{
if (options.useXstack)
/* if we are calling a not _naked function that is not using
the same register bank then we need to save the
destination registers on the stack */
- if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) &&
+ if (currFunc && dtype && !IFFUNC_ISNAKED (dtype) &&
(FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) &&
!IFFUNC_ISISR (dtype))
{
if (swapBanks)
{
emitcode ("mov", "psw,#0x%02x",
- ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+ ((FUNC_REGBANK (dtype)) << 3) & 0xff);
}
- if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT(getSpec(dtype)))
+ if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT (getSpec(dtype)))
{
- if (IFFUNC_CALLEESAVES(dtype))
+ if (IFFUNC_CALLEESAVES (dtype))
{
werror (E_BANKED_WITH_CALLEESAVES);
}
}
else
{
- if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT(getSpec(dtype)))
+ if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT (getSpec(dtype)))
{
- if (IFFUNC_CALLEESAVES(dtype))
+ if (IFFUNC_CALLEESAVES (dtype))
{
werror (E_BANKED_WITH_CALLEESAVES);
}
if (swapBanks)
{
emitcode ("mov", "psw,#0x%02x",
- ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+ ((FUNC_REGBANK (dtype)) << 3) & 0xff);
}
/* make the call */
if (swapBanks)
{
emitcode ("mov", "psw,#0x%02x",
- ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+ ((FUNC_REGBANK (dtype)) << 3) & 0xff);
}
/* make the call */
if (swapBanks)
{
emitcode ("mov", "psw,#0x%02x",
- ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+ ((FUNC_REGBANK (dtype)) << 3) & 0xff);
}
/* make the call */
}
if (swapBanks)
{
- selectRegBank (FUNC_REGBANK(currFunc->type), IS_BIT (etype));
+ selectRegBank (FUNC_REGBANK (currFunc->type), IS_BIT (etype));
}
/* if we need assign a result value */
// unsaveRBank (FUNC_REGBANK (dtype), ic, TRUE);
/* if we had saved some registers then unsave them */
- if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
+ if (ic->regsSaved && !IFFUNC_CALLEESAVES (dtype))
unsaveRegisters (ic);
if (IS_BIT (OP_SYM_ETYPE (IC_RESULT (ic))))
save acc, b, dpl, dph */
if (IFFUNC_ISISR (sym->type))
{
+ bitVect *rsavebits;
+
+ rsavebits = bitVectIntersect (bitVectCopy (mcs51_allBitregs ()), sym->regsUsed);
+ if (IFFUNC_HASFCALL(sym->type) || !bitVectIsZero (rsavebits))
+ {
+ emitcode ("push", "bits");
+ BitBankUsed = 1;
+ }
+ freeBitVect (rsavebits);
+
if (!inExcludeList ("acc"))
emitcode ("push", "acc");
if (!inExcludeList ("b"))
/* if any registers used */
if (sym->regsUsed)
{
- bool bits_pushed = FALSE;
/* save the registers used */
for (i = 0; i < sym->regsUsed->size; i++)
{
if (bitVectBitValue (sym->regsUsed, i))
- bits_pushed = pushReg (i, bits_pushed);
+ pushReg (i, TRUE);
}
}
}
if (IFFUNC_ISISR (sym->type))
{
+ bitVect *rsavebits;
/* now we need to restore the registers */
/* if this isr has no bank i.e. is going to
/* if any registers used */
if (sym->regsUsed)
{
- bool bits_popped = FALSE;
/* save the registers used */
for (i = sym->regsUsed->size; i >= 0; i--)
{
if (bitVectBitValue (sym->regsUsed, i))
- bits_popped = popReg (i, bits_popped);
+ popReg (i, TRUE);
}
}
}
emitcode ("pop","%s",rb1regs[i]);
}
}
- /* this function has a function call cannot
- determines register usage so we will have to pop the
+ /* this function has a function call. We cannot
+ determine register usage so we will have to pop the
entire bank */
unsaveRBank (0, ic, FALSE);
}
if (!inExcludeList ("acc"))
emitcode ("pop", "acc");
+ rsavebits = bitVectIntersect (bitVectCopy (mcs51_allBitregs ()), sym->regsUsed);
+ if (IFFUNC_HASFCALL(sym->type) || !bitVectIsZero (rsavebits))
+ emitcode ("pop", "bits");
+ freeBitVect (rsavebits);
+
/* if debug then send end of function */
if (options.debug && currFunc)
{
if (IS_BIT(_G.currentFunc->etype))
{
- toCarry (IC_LEFT (ic));
+ if (!OP_SYMBOL (IC_LEFT (ic))->ruonly)
+ toCarry (IC_LEFT (ic));
}
else
{
// val = c
if (size)
outBitC (result);
- // if(bit | ...)
+ // if(bit ^ ...)
else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
genIfxJump (ifx, "c", left, right, result);
goto release;