From: kmh Date: Thu, 1 Mar 2001 21:01:49 +0000 (+0000) Subject: Fixed PCALL and stack adjustment bug X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=54f886ab573f40c4356bbc4dc97c4196da96871b;p=fw%2Fsdcc Fixed PCALL and stack adjustment bug git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@661 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCast.c b/src/SDCCast.c index 948d57de..c76148af 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -536,7 +536,6 @@ funcOfType (char *name, sym_link * type, sym_link * argType, int nArgs, int rent) { symbol *sym; - int argStack = 0; /* create the symbol */ sym = newSymbol (name, 0); @@ -549,7 +548,6 @@ funcOfType (char *name, sym_link * type, sym_link * argType, while (nArgs--) { - argStack += getSize (type); args->type = copyLinkChain (argType); args->etype = getSpec (args->type); if (!nArgs) @@ -568,7 +566,6 @@ funcOfType (char *name, sym_link * type, sym_link * argType, /* save it */ addSymChain (sym); sym->cdef = 1; - sym->argStack = (rent ? argStack : 0); allocVariables (sym); return sym; diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 56eae7f0..85b42b16 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -579,6 +579,7 @@ copyiCode (iCode * ic) nic->filename = ic->filename; nic->block = ic->block; nic->level = ic->level; + nic->parmBytes = ic->parmBytes; /* deal with the special cases first */ switch (ic->op) @@ -1071,7 +1072,6 @@ newiTempFromOp (operand * op) nop->noSpilLoc = op->noSpilLoc; nop->usesDefs = op->usesDefs; nop->isParm = op->isParm; - nop->parmBytes = op->parmBytes; return nop; } @@ -1095,7 +1095,6 @@ operandFromOperand (operand * op) nop->noSpilLoc = op->noSpilLoc; nop->usesDefs = op->usesDefs; nop->isParm = op->isParm; - nop->parmBytes = op->parmBytes; switch (nop->type) { @@ -1157,7 +1156,6 @@ operandFromSymbol (symbol * sym) op->key = sym->key; op->isvolatile = isOperandVolatile (op, TRUE); op->isGlobal = isOperandGlobal (op); - op->parmBytes = sym->argStack; return op; } @@ -2749,7 +2747,7 @@ geniCodeCall (operand * left, ast * parms) geniCodeParms (parms, &stack, getSpec (operandType (left)), OP_SYMBOL (left)); /* now call : if symbol then pcall */ - if (IS_ITEMP (left)) + if (IS_OP_POINTER (left)) ic = newiCode (PCALL, left, NULL); else ic = newiCode (CALL, left, NULL); @@ -2763,7 +2761,7 @@ geniCodeCall (operand * left, ast * parms) ADDTOCHAIN (ic); /* stack adjustment after call */ - left->parmBytes = stack; + ic->parmBytes = stack; return result; } diff --git a/src/SDCCicode.h b/src/SDCCicode.h index ca414246..a6f656a6 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -87,7 +87,6 @@ typedef struct operand unsigned int noSpilLoc:1; /* cannot be assigned a spil location */ unsigned key; - int parmBytes; union { struct symbol *symOperand; /* operand is of type symbol */ @@ -176,6 +175,9 @@ typedef struct iCode int lineno; /* file & lineno for debug information */ char *filename; + + int parmBytes; /* if call/pcall, count of parameter bytes + on stack */ } iCode; diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 774e132a..0f532e0f 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -2086,7 +2086,6 @@ _makeRegParam (symbol * sym) while (val) { SPEC_REGPARM (val->etype) = 1; - sym->argStack -= getSize (val->type); val = val->next; } } diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 69184e9d..764aa4ef 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -265,8 +265,6 @@ typedef struct symbol int liveTo; /* live to sequence number */ int used; /* no. of times this was used */ int recvSize; /* size of first argument */ - int argStack; /* stacks used by parameters */ - } symbol; diff --git a/src/avr/gen.c b/src/avr/gen.c index b0123d65..8954f213 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -1447,15 +1447,15 @@ genCall (iCode * ic) } /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) { - if (IC_LEFT (ic)->parmBytes > 63) { - emitcode ("sbiw", "r28,%d", IC_LEFT (ic)->parmBytes); + if (ic->parmBytes) { + if (ic->parmBytes > 63) { + emitcode ("sbiw", "r28,%d", ic->parmBytes); } else { emitcode ("subi", "r28,lo8(%d)", - IC_LEFT (ic)->parmBytes); + ic->parmBytes); emitcode ("sbci", "r29,hi8(%d)", - IC_LEFT (ic)->parmBytes); + ic->parmBytes); } } @@ -1515,30 +1515,30 @@ genPcall (iCode * ic) /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) { + if (ic->parmBytes) { int i; - if (IC_LEFT (ic)->parmBytes > 3) { + if (ic->parmBytes > 3) { emitcode ("mov", "a,%s", spname); emitcode ("add", "a,#0x%02x", - (-IC_LEFT (ic)->parmBytes) & 0xff); + (-ic->parmBytes) & 0xff); emitcode ("mov", "%s,a", spname); } else - for (i = 0; i < IC_LEFT (ic)->parmBytes; i++) + for (i = 0; i < ic->parmBytes; i++) emitcode ("dec", "%s", spname); } /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) { - if (IC_LEFT (ic)->parmBytes > 63) { - emitcode ("sbiw", "r28,%d", IC_LEFT (ic)->parmBytes); + if (ic->parmBytes) { + if (ic->parmBytes > 63) { + emitcode ("sbiw", "r28,%d", ic->parmBytes); } else { emitcode ("subi", "r28,lo8(%d)", - IC_LEFT (ic)->parmBytes); + ic->parmBytes); emitcode ("sbci", "r29,hi8(%d)", - IC_LEFT (ic)->parmBytes); + ic->parmBytes); } } if (ic->regsSaved) diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 54117117..79c276c9 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -2243,17 +2243,17 @@ genCall (iCode * ic) /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) + if (ic->parmBytes) { int i; - if (IC_LEFT (ic)->parmBytes > 3) + if (ic->parmBytes > 3) { emitcode ("mov", "a,%s", spname); - emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff); + emitcode ("add", "a,#0x%02x", (-ic->parmBytes) & 0xff); emitcode ("mov", "%s,a", spname); } else - for (i = 0; i < IC_LEFT (ic)->parmBytes; i++) + for (i = 0; i < ic->parmBytes; i++) emitcode ("dec", "%s", spname); } @@ -2368,17 +2368,17 @@ genPcall (iCode * ic) /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) + if (ic->parmBytes) { int i; - if (IC_LEFT (ic)->parmBytes > 3) + if (ic->parmBytes > 3) { emitcode ("mov", "a,%s", spname); - emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff); + emitcode ("add", "a,#0x%02x", (-ic->parmBytes) & 0xff); emitcode ("mov", "%s,a", spname); } else - for (i = 0; i < IC_LEFT (ic)->parmBytes; i++) + for (i = 0; i < ic->parmBytes; i++) emitcode ("dec", "%s", spname); } diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index ac7e9033..4a1025f6 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -1975,17 +1975,17 @@ genCall (iCode * ic) /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) + if (ic->parmBytes) { int i; - if (IC_LEFT (ic)->parmBytes > 3) + if (ic->parmBytes > 3) { emitcode ("mov", "a,%s", spname); - emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff); + emitcode ("add", "a,#0x%02x", (-ic->parmBytes) & 0xff); emitcode ("mov", "%s,a", spname); } else - for (i = 0; i < IC_LEFT (ic)->parmBytes; i++) + for (i = 0; i < ic->parmBytes; i++) emitcode ("dec", "%s", spname); } @@ -2092,17 +2092,17 @@ genPcall (iCode * ic) /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) + if (ic->parmBytes) { int i; - if (IC_LEFT (ic)->parmBytes > 3) + if (ic->parmBytes > 3) { emitcode ("mov", "a,%s", spname); - emitcode ("add", "a,#0x%02x", (-IC_LEFT (ic)->parmBytes) & 0xff); + emitcode ("add", "a,#0x%02x", (-ic->parmBytes) & 0xff); emitcode ("mov", "%s,a", spname); } else - for (i = 0; i < IC_LEFT (ic)->parmBytes; i++) + for (i = 0; i < ic->parmBytes; i++) emitcode ("dec", "%s", spname); } diff --git a/src/pic/gen.c b/src/pic/gen.c index 9bd8650d..3955885c 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -2189,14 +2189,14 @@ static void genCall (iCode *ic) /* adjust the stack for parameters if required */ - if (IC_LEFT(ic)->parmBytes) { + if (ic->parmBytes) { int i; - if (IC_LEFT(ic)->parmBytes > 3) { + if (ic->parmBytes > 3) { emitcode("mov","a,%s",spname); - emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff); + emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff); emitcode("mov","%s,a",spname); } else - for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++) + for ( i = 0 ; i < ic->parmBytes ;i++) emitcode("dec","%s",spname); } @@ -2299,14 +2299,14 @@ static void genPcall (iCode *ic) /* adjust the stack for parameters if required */ - if (IC_LEFT(ic)->parmBytes) { + if (ic->parmBytes) { int i; - if (IC_LEFT(ic)->parmBytes > 3) { + if (ic->parmBytes > 3) { emitcode("mov","a,%s",spname); - emitcode("add","a,#0x%02x", (- IC_LEFT(ic)->parmBytes) & 0xff); + emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff); emitcode("mov","%s,a",spname); } else - for ( i = 0 ; i < IC_LEFT(ic)->parmBytes ;i++) + for ( i = 0 ; i < ic->parmBytes ;i++) emitcode("dec","%s",spname); } diff --git a/src/z80/gen.c b/src/z80/gen.c index f52e8e4e..81935dfc 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -2082,9 +2082,9 @@ emitCall (iCode * ic, bool ispcall) } /* adjust the stack for parameters if required */ - if (IC_LEFT (ic)->parmBytes) + if (ic->parmBytes) { - int i = IC_LEFT (ic)->parmBytes; + int i = ic->parmBytes; _G.stack.pushed -= i; if (IS_GB) { diff --git a/src/z80/ralloc.c b/src/z80/ralloc.c index 02a71f3f..6dfca4cd 100644 --- a/src/z80/ralloc.c +++ b/src/z80/ralloc.c @@ -1980,7 +1980,7 @@ packRegsForHLUse (iCode * ic) if (ic->op == ADDRESS_OF && uic->op == IPUSH) goto hluse; - if (ic->op == CALL && IC_LEFT (ic)->parmBytes == 0 && (uic->op == '-' || uic->op == '+')) + if (ic->op == CALL && ic->parmBytes == 0 && (uic->op == '-' || uic->op == '+')) goto hluse; return; hluse: