From: sandeep Date: Wed, 30 Jan 2002 04:44:24 +0000 (+0000) Subject: Added support for --parms-in-bank1 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a5874ebaad3f8220d34c2929d4fc560de1248c4f;p=fw%2Fsdcc Added support for --parms-in-bank1 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1873 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 20594893..09e25990 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -93,6 +93,10 @@ static struct } _G; +static char *rb1regs[] = { + "b1_0","b1_1","b1_2","b1_3","b1_4","b1_5","b1_6","b1_7" +}; + extern int mcs51_ptrRegReq; extern int mcs51_nRegs; extern FILE *codeOutFile; @@ -1887,6 +1891,39 @@ saveRBank (int bank, iCode * ic, bool pushPsw) } } +/*-----------------------------------------------------------------*/ +/* genSend - gen code for SEND */ +/*-----------------------------------------------------------------*/ +static void genSend(set *sendSet) +{ + iCode *sic; + int rb1_count = 0 ; + + for (sic = setFirstItem (_G.sendSet); sic; + sic = setNextItem (_G.sendSet)) { + int size, offset = 0; + aopOp (IC_LEFT (sic), sic, FALSE); + size = AOP_SIZE (IC_LEFT (sic)); + + if (sic->argreg == 1) { + while (size--) { + char *l = aopGet (AOP (IC_LEFT (sic)), offset, + FALSE, FALSE); + if (strcmp (l, fReturn[offset])) + emitcode ("mov", "%s,%s", fReturn[offset], l); + offset++; + } + rb1_count = 0; + } else { + while (size--) { + emitcode ("mov","b1_%d,%s",rb1_count++, + aopGet (AOP (IC_LEFT (sic)), offset++,FALSE, FALSE)); + } + } + freeAsmop (IC_LEFT (sic), NULL, sic, TRUE); + } +} + /*-----------------------------------------------------------------*/ /* genCall - generates a call statement */ /*-----------------------------------------------------------------*/ @@ -1899,29 +1936,16 @@ genCall (iCode * ic) D(emitcode(";", "genCall")); + dtype = operandType (IC_LEFT (ic)); /* if send set is not empty the assign */ if (_G.sendSet) { - iCode *sic; - - for (sic = setFirstItem (_G.sendSet); sic; - sic = setNextItem (_G.sendSet)) - { - int size, offset = 0; - aopOp (IC_LEFT (sic), sic, FALSE); - size = AOP_SIZE (IC_LEFT (sic)); - while (size--) - { - char *l = aopGet (AOP (IC_LEFT (sic)), offset, - FALSE, FALSE); - if (strcmp (l, fReturn[offset])) - emitcode ("mov", "%s,%s", - fReturn[offset], - l); - offset++; - } - freeAsmop (IC_LEFT (sic), NULL, sic, TRUE); + if (IFFUNC_ISREENT(dtype)) { /* need to reverse the send set */ + genSend(reverseSet(_G.sendSet)); + } else { + genSend(_G.sendSet); } + _G.sendSet = NULL; } @@ -1933,15 +1957,6 @@ genCall (iCode * ic) (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) && !IFFUNC_ISISR (dtype)) { -// if (!ic->bankSaved) -// { -// /* This is unexpected; the bank should have been saved in -// * genFunction. -// */ -// saveRBank (FUNC_REGBANK (dtype), ic, FALSE); -// restoreBank = TRUE; -// } - // need caution message to user here swapBanks = TRUE; } @@ -2055,27 +2070,8 @@ genPcall (iCode * ic) /* if send set is not empty the assign */ if (_G.sendSet) { - iCode *sic; - - for (sic = setFirstItem (_G.sendSet); sic; - sic = setNextItem (_G.sendSet)) - { - int size, offset = 0; - aopOp (IC_LEFT (sic), sic, FALSE); - size = AOP_SIZE (IC_LEFT (sic)); - while (size--) - { - char *l = aopGet (AOP (IC_LEFT (sic)), offset, - FALSE, FALSE); - if (strcmp (l, fReturn[offset])) - emitcode ("mov", "%s,%s", - fReturn[offset], - l); - offset++; - } - freeAsmop (IC_LEFT (sic), NULL, sic, TRUE); - } - _G.sendSet = NULL; + genSend(reverseSet(_G.sendSet)); + _G.sendSet = NULL; } if (swapBanks) @@ -2276,10 +2272,17 @@ genFunction (iCode * ic) } else { + /* this function has a function call cannot determines register usage so we will have to push the entire bank */ - saveRBank (0, ic, FALSE); + saveRBank (0, ic, FALSE); + if (options.parms_in_bank1) { + int i; + for (i=0; i < 8 ; i++ ) { + emitcode ("push","%s",rb1regs[i]); + } + } } } else @@ -2575,6 +2578,12 @@ genEndFunction (iCode * ic) } else { + if (options.parms_in_bank1) { + int i; + for (i = 7 ; i >= 0 ; i-- ) { + emitcode ("pop","%s",rb1regs[i]); + } + } /* this function has a function call cannot determines register usage so we will have to pop the entire bank */ @@ -2819,7 +2828,8 @@ genPlusIncr (iCode * ic) D(emitcode (";", "genPlusIncr")); /* if increment 16 bits in register */ - if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && + if (AOP_TYPE(IC_LEFT(ic)) == AOP_REG && + sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && (size > 1) && (icount == 1)) { @@ -3173,7 +3183,8 @@ genMinusDec (iCode * ic) D(emitcode (";", "genMinusDec")); /* if decrement 16 bits in register */ - if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && + if (AOP_TYPE(IC_LEFT(ic)) == AOP_REG && + sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && (size > 1) && (icount == 1)) { @@ -8737,39 +8748,43 @@ genDjnz (iCode * ic, iCode * ifx) static void genReceive (iCode * ic) { + int size = getSize (operandType (IC_RESULT (ic))); + int offset = 0; D(emitcode (";", "genReceive")); - if (isOperandInFarSpace (IC_RESULT (ic)) && - (OP_SYMBOL (IC_RESULT (ic))->isspilt || - IS_TRUE_SYMOP (IC_RESULT (ic)))) - { - - int size = getSize (operandType (IC_RESULT (ic))); - int offset = fReturnSizeMCS51 - size; - while (size--) - { - emitcode ("push", "%s", (strcmp (fReturn[fReturnSizeMCS51 - offset - 1], "a") ? - fReturn[fReturnSizeMCS51 - offset - 1] : "acc")); - offset++; - } - aopOp (IC_RESULT (ic), ic, FALSE); - size = AOP_SIZE (IC_RESULT (ic)); - offset = 0; - while (size--) - { - emitcode ("pop", "acc"); - aopPut (AOP (IC_RESULT (ic)), "a", offset++); - } - - } - else - { - _G.accInUse++; + if (ic->argreg == 1) { /* first parameter */ + if (isOperandInFarSpace (IC_RESULT (ic)) && + (OP_SYMBOL (IC_RESULT (ic))->isspilt || + IS_TRUE_SYMOP (IC_RESULT (ic)))) { + + offset = fReturnSizeMCS51 - size; + while (size--) { + emitcode ("push", "%s", (strcmp (fReturn[fReturnSizeMCS51 - offset - 1], "a") ? + fReturn[fReturnSizeMCS51 - offset - 1] : "acc")); + offset++; + } + aopOp (IC_RESULT (ic), ic, FALSE); + size = AOP_SIZE (IC_RESULT (ic)); + offset = 0; + while (size--) { + emitcode ("pop", "acc"); + aopPut (AOP (IC_RESULT (ic)), "a", offset++); + } + + } else { + _G.accInUse++; + aopOp (IC_RESULT (ic), ic, FALSE); + _G.accInUse--; + assignResultValue (IC_RESULT (ic)); + } + } else { /* second receive onwards */ + int rb1off ; aopOp (IC_RESULT (ic), ic, FALSE); - _G.accInUse--; - assignResultValue (IC_RESULT (ic)); - } - + rb1off = ic->argreg; + while (size--) { + aopPut (AOP (IC_RESULT (ic)), rb1regs[rb1off++ -5], offset++); + } + } freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); } diff --git a/src/mcs51/main.c b/src/mcs51/main.c index b91a622c..d34796b0 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -8,6 +8,8 @@ #include "main.h" #include "ralloc.h" #include "gen.h" +#include "../SDCCutil.h" +extern const char *preArgv[128]; /* pre-processor arguments */ static char _defaultRules[] = { @@ -64,13 +66,31 @@ _mcs51_reset_regparm () static int _mcs51_regparm (sym_link * l) { - /* for this processor it is simple - can pass only the first parameter in a register */ - if (regParmFlg) - return 0; + if (options.parms_in_bank1 == 0) { + /* simple can pass only the first parameter in a register */ + if (regParmFlg) + return 0; - regParmFlg = 1; - return 1; + regParmFlg = 1; + return 1; + } else { + int size = getSize(l); + int remain ; + + /* first one goes the usual way to DPTR */ + if (regParmFlg == 0) { + regParmFlg += 4 ; + return 1; + } + /* second one onwards goes to RB1_0 thru RB1_7 */ + remain = regParmFlg - 4; + if (size > (8 - remain)) { + regParmFlg = 12 ; + return 0; + } + regParmFlg += size ; + return regParmFlg - size + 1; + } } static bool @@ -94,6 +114,10 @@ _mcs51_finaliseOptions (void) port->mem.default_local_map = data; port->mem.default_globl_map = data; } + options.parms_in_bank1=1; + if (options.parms_in_bank1) { + addToList (preArgv, "-DSDCC_PARMS_IN_BANK1"); + } } static void @@ -112,6 +136,11 @@ _mcs51_getRegName (struct regs *reg) static void _mcs51_genAssemblerPreamble (FILE * of) { + if (options.parms_in_bank1) { + int i ; + for (i=0; i < 8 ; i++ ) + fprintf (of,"b1_%d = 0x%x \n",i,8+i); + } } /* Generate interrupt vector table. */ diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 18eb37a9..90ad312f 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -2077,6 +2077,8 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) !POINTER_GET (ic)) return NULL; + if (ic->op == SEND && ic->argreg != 1) return NULL; + /* this routine will mark the a symbol as used in one instruction use only && if the defintion is local (ie. within the basic block) && has only one definition && @@ -2589,7 +2591,7 @@ packRegisters (eBBlock * ebp) /* some cases the redundant moves can can be eliminated for return statements */ - if ((ic->op == RETURN || ic->op == SEND) && + if ((ic->op == RETURN || (ic->op == SEND && ic->argreg == 1)) && !isOperandInFarSpace (IC_LEFT (ic)) && options.model == MODEL_SMALL) { if (0 && options.stackAuto) {