X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCast.c;h=84a6c7f1bd914cc6cefe33102ed847ab8f729bc8;hb=cd37d9c06133f6be846d2695d00e1d5b0792a085;hp=d0898d7e57991ae917bec7466355cc07a7ea8f4c;hpb=6d5732239ca066c1757ae16f69942fd4b320e612;p=fw%2Fsdcc diff --git a/src/SDCCast.c b/src/SDCCast.c index d0898d7e..84a6c7f1 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -218,6 +218,7 @@ copyAst (ast * src) dest->lineno = src->lineno; dest->level = src->level; dest->funcName = src->funcName; + dest->reversed = src->reversed; if (src->ftype) dest->etype = getSpec (dest->ftype = copyLinkChain (src->ftype)); @@ -630,11 +631,25 @@ reverseParms (ast * ptree) return; /* top down if we find a nonParm tree then quit */ - if (ptree->type == EX_OP && ptree->opval.op == PARAM) + if (ptree->type == EX_OP && ptree->opval.op == PARAM && !ptree->reversed) { + /* The various functions expect the parameter tree to be right heavy. */ + /* Rotate the tree to be left heavy so that after reversal it is */ + /* right heavy again. */ + while ((ttree = ptree->right) && ttree->type == EX_OP && + ttree->opval.op == PARAM) + { + ptree->right = ttree->right; + ttree->right = ttree->left; + ttree->left = ptree->left; + ptree->left = ttree; + } + + /* Now reverse */ ttree = ptree->left; ptree->left = ptree->right; ptree->right = ttree; + ptree->reversed = 1; reverseParms (ptree->left); reverseParms (ptree->right); } @@ -678,11 +693,15 @@ processParms (ast *func, /* if the function is being called via a pointer & */ /* it has not been defined a reentrant then we cannot */ /* have parameters */ - if (func->type != EX_VALUE && !IFFUNC_ISREENT (functype) && !options.stackAuto) + /* PIC16 port can... */ + if (!TARGET_IS_PIC16) { - werror (W_NONRENT_ARGS); - fatalError++; - return 1; + if (func->type != EX_VALUE && !IFFUNC_ISREENT (functype) && !options.stackAuto) + { + werror (W_NONRENT_ARGS); + fatalError++; + return 1; + } } /* if defined parameters ended but actual parameters */ @@ -834,8 +853,8 @@ createIvalType (ast * sym, sym_link * type, initList * ilist) if (ilist->type == INIT_DEEP) ilist = ilist->init.deep; - iExpr = decorateType (resolveSymbols (list2expr (ilist)), RESULT_CHECK); - return decorateType (newNode ('=', sym, iExpr), RESULT_CHECK); + iExpr = decorateType (resolveSymbols (list2expr (ilist)), RESULT_TYPE_NONE); + return decorateType (newNode ('=', sym, iExpr), RESULT_TYPE_NONE); } /*-----------------------------------------------------------------*/ @@ -865,8 +884,8 @@ createIvalStruct (ast * sym, sym_link * type, initList * ilist) break; sflds->implicit = 1; lAst = newNode (PTR_OP, newNode ('&', sym, NULL), newAst_VALUE (symbolVal (sflds))); - lAst = decorateType (resolveSymbols (lAst), RESULT_CHECK); - rast = decorateType (resolveSymbols (createIval (lAst, sflds->type, iloop, rast)), RESULT_CHECK); + lAst = decorateType (resolveSymbols (lAst), RESULT_TYPE_NONE); + rast = decorateType (resolveSymbols (createIval (lAst, sflds->type, iloop, rast)), RESULT_TYPE_NONE); } if (iloop) { @@ -896,9 +915,9 @@ createIvalArray (ast * sym, sym_link * type, initList * ilist) if (IS_CHAR (type->next)) if ((rast = createIvalCharPtr (sym, type, - decorateType (resolveSymbols (list2expr (ilist)), RESULT_CHECK)))) + decorateType (resolveSymbols (list2expr (ilist)), RESULT_TYPE_NONE)))) - return decorateType (resolveSymbols (rast), RESULT_CHECK); + return decorateType (resolveSymbols (rast), RESULT_TYPE_NONE); /* not the special case */ if (ilist->type != INIT_DEEP) @@ -914,7 +933,7 @@ createIvalArray (ast * sym, sym_link * type, initList * ilist) { ast *aSym; - aSym = decorateType (resolveSymbols(sym), RESULT_CHECK); + aSym = decorateType (resolveSymbols(sym), RESULT_TYPE_NONE); rast = newNode(ARRAYINIT, aSym, NULL); rast->values.constlist = literalL; @@ -943,7 +962,7 @@ createIvalArray (ast * sym, sym_link * type, initList * ilist) ast *aSym; aSym = newNode ('[', sym, newAst_VALUE (valueFromLit ((float) (size++)))); - aSym = decorateType (resolveSymbols (aSym), RESULT_CHECK); + aSym = decorateType (resolveSymbols (aSym), RESULT_TYPE_NONE); rast = createIval (aSym, type->next, iloop, rast); iloop = (iloop ? iloop->next : NULL); if (!iloop) @@ -973,7 +992,7 @@ createIvalArray (ast * sym, sym_link * type, initList * ilist) DCL_ELEM (type) = size; } - return decorateType (resolveSymbols (rast), RESULT_CHECK); + return decorateType (resolveSymbols (rast), RESULT_TYPE_NONE); } @@ -1027,7 +1046,7 @@ createIvalCharPtr (ast * sym, sym_link * type, ast * iexpr) // now WE don't need iexpr's symbol anymore freeStringSymbol(AST_SYMBOL(iexpr)); - return decorateType (resolveSymbols (rast), RESULT_CHECK); + return decorateType (resolveSymbols (rast), RESULT_TYPE_NONE); } return NULL; @@ -1046,7 +1065,7 @@ createIvalPtr (ast * sym, sym_link * type, initList * ilist) if (ilist->type == INIT_DEEP) ilist = ilist->init.deep; - iexpr = decorateType (resolveSymbols (list2expr (ilist)), RESULT_CHECK); + iexpr = decorateType (resolveSymbols (list2expr (ilist)), RESULT_TYPE_NONE); /* if character pointer */ if (IS_CHAR (type->next)) @@ -1084,9 +1103,9 @@ createIval (ast * sym, sym_link * type, initList * ilist, ast * wid) rast = createIvalType (sym, type, ilist); if (wid) - return decorateType (resolveSymbols (newNode (NULLOP, wid, rast)), RESULT_CHECK); + return decorateType (resolveSymbols (newNode (NULLOP, wid, rast)), RESULT_TYPE_NONE); else - return decorateType (resolveSymbols (rast), RESULT_CHECK); + return decorateType (resolveSymbols (rast), RESULT_TYPE_NONE); } /*-----------------------------------------------------------------*/ @@ -1115,6 +1134,21 @@ gatherAutoInit (symbol * autoChain) if (sym->ival) resolveIvalSym (sym->ival, sym->type); +#if 1 + /* if we are PIC16 port, + * and this is a static, + * and have initial value, + * and not S_CODE, don't emit in gs segment, + * but allow glue.c:pic16emitRegularMap to put symbol + * in idata section */ + if(TARGET_IS_PIC16 && + IS_STATIC (sym->etype) && sym->ival + && SPEC_SCLS(sym->etype) != S_CODE) { + SPEC_SCLS (sym->etype) = S_DATA; + continue; + } +#endif + /* if this is a static variable & has an */ /* initial value the code needs to be lifted */ /* here to the main portion since they can be */ @@ -1302,7 +1336,7 @@ bool constExprTree (ast *cexpr) { return TRUE; } - cexpr = decorateType (resolveSymbols (cexpr), RESULT_CHECK); + cexpr = decorateType (resolveSymbols (cexpr), RESULT_TYPE_NONE); switch (cexpr->type) { @@ -1366,7 +1400,7 @@ bool constExprTree (ast *cexpr) { value * constExprValue (ast * cexpr, int check) { - cexpr = decorateType (resolveSymbols (cexpr), RESULT_CHECK); + cexpr = decorateType (resolveSymbols (cexpr), RESULT_TYPE_NONE); /* if this is not a constant then */ if (!IS_LITERAL (cexpr->ftype)) @@ -1961,7 +1995,7 @@ reverseLoop (ast * loop, symbol * sym, ast * init, ast * end) rloop)))); rloop->lineno=init->lineno; - return decorateType (rloop, RESULT_CHECK); + return decorateType (rloop, RESULT_TYPE_NONE); } @@ -2563,7 +2597,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) ast *otree = optimizeGetHbit (tree); if (otree != tree) - return decorateType (otree, RESULT_CHECK); + return decorateType (otree, RESULT_TYPE_NONE); } /* if left is a literal exchange left & right */ @@ -2693,11 +2727,11 @@ decorateType (ast * tree, RESULT_TYPE resultType) { ast *wtree = optimizeRRCRLC (tree); if (wtree != tree) - return decorateType (wtree, RESULT_CHECK); + return decorateType (wtree, RESULT_TYPE_NONE); wtree = optimizeSWAP (tree); if (wtree != tree) - return decorateType (wtree, RESULT_CHECK); + return decorateType (wtree, RESULT_TYPE_NONE); } /* if left is a literal exchange left & right */ @@ -2850,7 +2884,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) else { /* litTree->left is literal: no gcse possible. - We can't call decorateType(parent, RESULT_CHECK), because + We can't call decorateType(parent, RESULT_TYPE_NONE), because this would cause an infinit loop. */ parent->decorated = 1; decorateType (litTree, resultType); @@ -3757,7 +3791,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) tree->right); /* val 0 */ tree->right->lineno = tree->lineno; tree->right->left->lineno = tree->lineno; - decorateType (tree->right, RESULT_CHECK); + decorateType (tree->right, RESULT_TYPE_NONE); } } /* if they are both literal then */ @@ -4044,7 +4078,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) goto errorTreeReturn; } - tree->right = decorateType (newNode ('+', copyAst (tree->left), tree->right), RESULT_CHECK); + tree->right = decorateType (newNode ('+', copyAst (tree->left), tree->right), RESULT_TYPE_NONE); tree->opval.op = '='; return tree; @@ -4182,7 +4216,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) decorateType (newNode (CAST, newAst_LINK (copyLinkChain (currFunc->type->next)), tree->right), - RESULT_CHECK); + RESULT_TYPE_NONE); } RRVAL (tree) = 1; @@ -4231,9 +4265,9 @@ decorateType (ast * tree, RESULT_TYPE resultType) /*----------------------------*/ case FOR: - decorateType (resolveSymbols (AST_FOR (tree, initExpr)), RESULT_CHECK); - decorateType (resolveSymbols (AST_FOR (tree, condExpr)), RESULT_CHECK); - decorateType (resolveSymbols (AST_FOR (tree, loopExpr)), RESULT_CHECK); + decorateType (resolveSymbols (AST_FOR (tree, initExpr)), RESULT_TYPE_NONE); + decorateType (resolveSymbols (AST_FOR (tree, condExpr)), RESULT_TYPE_NONE); + decorateType (resolveSymbols (AST_FOR (tree, loopExpr)), RESULT_TYPE_NONE); /* if the for loop is reversible then reverse it otherwise do what we normally @@ -4252,7 +4286,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) AST_FOR (tree, initExpr), AST_FOR (tree, condExpr), AST_FOR (tree, loopExpr), - tree->left), RESULT_CHECK); + tree->left), RESULT_TYPE_NONE); } case PARAM: werror (E_INTERNAL_ERROR, __FILE__, __LINE__, @@ -4416,7 +4450,6 @@ createBlock (symbol * decl, ast * body) ex = newNode (BLOCK, NULL, body); ex->values.sym = decl; - ex->right = ex->right;///????? ex->level++; ex->lineno = 0; return ex; @@ -4477,7 +4510,7 @@ createCase (ast * swStat, ast * caseVal, ast * stmnt) return NULL; } - caseVal = decorateType (resolveSymbols (caseVal), RESULT_CHECK); + caseVal = decorateType (resolveSymbols (caseVal), RESULT_TYPE_NONE); /* if not a constant then error */ if (!IS_LITERAL (caseVal->ftype)) { @@ -4835,7 +4868,7 @@ optimizeGetHbit (ast * tree) && !port->hasExtBitOp(GETHBIT, getSize (TTYPE (tree->left->left)))) return tree; - return decorateType (newNode (GETHBIT, tree->left->left, NULL), RESULT_CHECK); + return decorateType (newNode (GETHBIT, tree->left->left, NULL), RESULT_TYPE_NONE); } @@ -5102,7 +5135,7 @@ optimizeCompare (ast * root) break; } - return decorateType (optExpr, RESULT_CHECK); + return decorateType (optExpr, RESULT_TYPE_NONE); } vleft = (root->left->type == EX_VALUE ? @@ -5176,7 +5209,7 @@ optimizeCompare (ast * root) break; } } - return decorateType (resolveSymbols (optExpr), RESULT_CHECK); + return decorateType (resolveSymbols (optExpr), RESULT_TYPE_NONE); } /* end-of-if of BITVAR */ noOptimize: @@ -5286,14 +5319,19 @@ createFunction (symbol * name, ast * body) currFunc = name; /* set the stack pointer */ - /* PENDING: check this for the mcs51 */ - stackPtr = -port->stack.direction * port->stack.call_overhead; + stackPtr = -port->stack.direction * port->stack.call_overhead; + xstackPtr = -port->stack.direction * port->stack.call_overhead; + if (IFFUNC_ISISR (name->type)) stackPtr -= port->stack.direction * port->stack.isr_overhead; - if (IFFUNC_ISREENT (name->type) || options.stackAuto) - stackPtr -= port->stack.direction * port->stack.reent_overhead; - xstackPtr = -port->stack.direction * port->stack.call_overhead; + if (IFFUNC_ISREENT (name->type) || options.stackAuto) + { + if (options.useXstack) + xstackPtr -= port->stack.direction * port->stack.reent_overhead; + else + stackPtr -= port->stack.direction * port->stack.reent_overhead; + } fetype = getSpec (name->type); /* get the specifier for the function */ /* if this is a reentrant function then */ @@ -5354,7 +5392,7 @@ createFunction (symbol * name, ast * body) { GcurMemmap = statsg; codeOutFile = statsg->oFile; - eBBlockFromiCode (iCodeFromAst (decorateType (resolveSymbols (staticAutos), RESULT_CHECK))); + eBBlockFromiCode (iCodeFromAst (decorateType (resolveSymbols (staticAutos), RESULT_TYPE_NONE))); staticAutos = NULL; }