From: johanknol Date: Mon, 22 Oct 2001 19:00:28 +0000 (+0000) Subject: Function attribute migration. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=91b0931c40c5cad20cf18aa66303f9cb850f5dbc;p=fw%2Fsdcc Function attribute migration. Now all function attributes (args, critical, interrupt etc) are in the sym_link where DECLARATOR==FUNCTION instead of scattered around in the symbol and the etype of the symbol. Now we can have multiple functions in a typechain which can have their own private attributes. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1430 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCC.y b/src/SDCC.y index 776775ba..42dd761b 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -98,11 +98,11 @@ value *cenum = NULL ; /* current enumeration type chain*/ %type struct_declarator_list struct_declaration struct_declaration_list %type declaration init_declarator_list init_declarator %type declaration_list identifier_list parameter_identifier_list -%type declarator2_using_reentrant while do for +%type declarator2_function_attributes while do for %type pointer type_specifier_list type_specifier type_name %type storage_class_specifier struct_or_union_specifier %type declaration_specifiers sfr_reg_bit type_specifier2 -%type using_reentrant using_reentrant_interrupt enum_specifier +%type function_attribute function_attributes enum_specifier %type abstract_declarator abstract_declarator2 unqualified_pointer %type parameter_type_list parameter_list parameter_declaration opt_assign_expr %type stag opt_stag @@ -128,7 +128,9 @@ file ; external_definition - : function_definition { blockNo=0;} + : function_definition { + blockNo=0; + } | declaration { if ($1 && $1->type && IS_FUNC($1->type)) @@ -167,41 +169,41 @@ function_definition } ; -using_reentrant - : using_reentrant_interrupt - | using_reentrant_interrupt using_reentrant { $$ = mergeSpec($1,$2,"using_reentrant"); } +function_attribute + : function_attributes + | function_attributes function_attribute { $$ = mergeSpec($1,$2,"function_attribute"); } ; -using_reentrant_interrupt +function_attributes : USING CONSTANT { $$ = newLink() ; $$->class = SPECIFIER ; - SPEC_BNKF($$) = 1; - SPEC_BANK($$) = (int) floatFromVal($2); + FUNC_REGBANK($$) = (int) floatFromVal($2); + //FUNC_RBANK($$) = 1; } | REENTRANT { $$ = newLink (); $$->class = SPECIFIER ; - SPEC_RENT($$) = 1; + FUNC_ISREENT($$)=1; } | CRITICAL { $$ = newLink (); $$->class = SPECIFIER ; - SPEC_CRTCL($$) = 1; + FUNC_ISCRITICAL($$) = 1; } | NAKED { $$ = newLink (); $$->class = SPECIFIER ; - SPEC_NAKED($$) = 1; + FUNC_ISNAKED($$)=1; } | NONBANKED {$$ = newLink (); $$->class = SPECIFIER ; - SPEC_NONBANKED($$) = 1; - if (SPEC_BANKED($$)) { + FUNC_NONBANKED($$) = 1; + if (FUNC_BANKED($$)) { werror(W_BANKED_WITH_NONBANKED); } } | BANKED {$$ = newLink (); $$->class = SPECIFIER ; - SPEC_BANKED($$) = 1; - if (SPEC_NONBANKED($$)) { + FUNC_BANKED($$) = 1; + if (FUNC_NONBANKED($$)) { werror(W_BANKED_WITH_NONBANKED); } if (SPEC_STAT($$)) { @@ -212,8 +214,8 @@ using_reentrant_interrupt { $$ = newLink () ; $$->class = SPECIFIER ; - SPEC_INTN($$) = $1 ; - SPEC_INTRTN($$) = 1; + FUNC_INTNO($$) = $1 ; + FUNC_ISISR($$) = 1; } ; @@ -867,17 +869,34 @@ opt_assign_expr ; declarator - : declarator2_using_reentrant { $$ = $1; } - | pointer declarator2_using_reentrant + : declarator2_function_attributes { $$ = $1; } + | pointer declarator2_function_attributes { addDecl ($2,0,reverseLink($1)); $$ = $2 ; } ; -declarator2_using_reentrant +declarator2_function_attributes : declarator2 { $$ = $1 ; } - | declarator2 using_reentrant { addDecl ($1,0,$2); } + | declarator2 function_attribute { + // do the functionAttributes (not the args and hasVargs !!) + sym_link *funcType=$1->etype; + struct value *args=FUNC_ARGS(funcType); + unsigned hasVargs=FUNC_HASVARARGS(funcType); + + memcpy (&funcType->funcAttrs, &$2->funcAttrs, + sizeof($2->funcAttrs)); + + FUNC_ARGS(funcType)=args; + FUNC_HASVARARGS(funcType)=hasVargs; + + // just to be sure + memset (&$2->funcAttrs, 0, + sizeof($2->funcAttrs)); + + addDecl ($1,0,$2); + } ; declarator2 @@ -914,20 +933,22 @@ declarator2 addDecl ($1,FUNCTION,NULL) ; - $1->hasVargs = IS_VARG($4); - $1->args = reverseVal($4) ; - + FUNC_HASVARARGS($1->type) = IS_VARG($4); + FUNC_ARGS($1->type) = reverseVal($4); /* nest level was incremented to take care of the parms */ NestLevel-- ; currBlockno--; - // if this was a pointer to a function, remove the symbol args - // (if any) - if (IS_PTR($1->type) && IS_FUNC($1->etype)) { + // if this was a pointer (to a function) + if (IS_PTR($1->type)) { + // move the args and hasVargs to the function + FUNC_ARGS($1->etype)=FUNC_ARGS($1->type); + FUNC_HASVARARGS($1->etype)=FUNC_HASVARARGS($1->type); + memset (&$1->type->funcAttrs, 0, + sizeof($1->type->funcAttrs)); + // remove the symbol args (if any) cleanUpLevel(SymbolTab,NestLevel+1); - /* fprintf (stderr, "Removed parm symbols of %s in line %d\n", - $1->name, yylineno); */ } $$ = $1; diff --git a/src/SDCCBBlock.c b/src/SDCCBBlock.c index 79126353..4e56f141 100644 --- a/src/SDCCBBlock.c +++ b/src/SDCCBBlock.c @@ -252,7 +252,7 @@ iCode2eBBlock (iCode * ic) { ebb->hasFcall = 1; if (currFunc) - currFunc->hasFcall = 1; + FUNC_HASFCALL(currFunc->type) = 1; } /* if the next one is a label */ diff --git a/src/SDCCast.c b/src/SDCCast.c index 1c79c9ea..9beec54f 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -257,7 +257,6 @@ copyAst (ast * src) dest->lineno = src->lineno; dest->level = src->level; dest->funcName = src->funcName; - dest->argSym = src->argSym; /* if this is a leaf */ /* if value */ @@ -542,12 +541,18 @@ funcOfType (char *name, sym_link * type, sym_link * argType, /* create the symbol */ sym = newSymbol (name, 0); + /* setup return value */ + sym->type = newLink (); + DCL_TYPE (sym->type) = FUNCTION; + sym->type->next = copyLinkChain (type); + sym->etype = getSpec (sym->type); + FUNC_ISREENT(sym->type) = rent; + /* if arguments required */ if (nArgs) { - value *args; - args = sym->args = newValue (); + args = FUNC_ARGS(sym->type) = newValue (); while (nArgs--) { @@ -559,13 +564,6 @@ funcOfType (char *name, sym_link * type, sym_link * argType, } } - /* setup return value */ - sym->type = newLink (); - DCL_TYPE (sym->type) = FUNCTION; - sym->type->next = copyLinkChain (type); - sym->etype = getSpec (sym->type); - SPEC_RENT (sym->etype) = rent; - /* save it */ addSymChain (sym); sym->cdef = 1; @@ -603,13 +601,11 @@ reverseParms (ast * ptree) /*-----------------------------------------------------------------*/ int processParms (ast * func, - value * defParm, + value *defParm, ast * actParm, int *parmNumber, // unused, although updated bool rightmost) // double checked? { - sym_link *fetype = func->etype; - /* if none of them exist */ if (!defParm && !actParm) return 0; @@ -625,7 +621,7 @@ 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 && !IS_RENT (fetype) && !options.stackAuto) + if (func->type != EX_VALUE && !IFFUNC_ISREENT (func->ftype) && !options.stackAuto) { werror (W_NONRENT_ARGS); return 1; @@ -633,9 +629,7 @@ processParms (ast * func, /* if defined parameters ended but actual parameters */ /* exist and this is not defined as a variable arg */ - /* also check if statckAuto option is specified */ // jwk: WHY? - if ((!defParm) && actParm && (!func->hasVargs) - /* && !options.stackAuto && !IS_RENT (fetype) */) + if (!defParm && actParm && !IFFUNC_HASVARARGS(func->ftype)) { werror (E_TOO_MANY_PARMS); return 1; @@ -649,7 +643,7 @@ processParms (ast * func, } /* If this is a varargs function... */ - if (!defParm && actParm && func->hasVargs) + if (!defParm && actParm && IFFUNC_HASVARARGS(func->ftype)) { ast *newType = NULL; sym_link *ftype; @@ -691,6 +685,7 @@ processParms (ast * func, if (IS_AGGREGATE (ftype)) { + // jwk: don't we need aggregateToPointer here? newType = newAst_LINK (copyLinkChain (ftype)); DCL_TYPE (newType->opval.lnk) = GPOINTER; } @@ -716,7 +711,7 @@ processParms (ast * func, /* if defined parameters ended but actual has not & */ /* stackAuto */ if (!defParm && actParm && - (options.stackAuto || IS_RENT (fetype))) + (options.stackAuto || IFFUNC_ISREENT (func->ftype))) return 0; resolveSymbols (actParm); @@ -734,7 +729,7 @@ processParms (ast * func, * Therefore, if there are more defined parameters, the caller didn't * supply enough. */ - if (rightmost && defParm->next) + if (0 && rightmost && defParm->next) { werror (E_TOO_FEW_PARMS); return 1; @@ -767,9 +762,6 @@ processParms (ast * func, actParm->ftype = defParm->type; } -/* actParm->argSym = resolveFromTable(defParm)->sym ; */ - - actParm->argSym = defParm->sym; /* make a copy and change the regparm type to the defined parm */ actParm->etype = getSpec (actParm->ftype = copyLinkChain (actParm->ftype)); SPEC_REGPARM (actParm->etype) = SPEC_REGPARM (defParm->etype); @@ -1915,11 +1907,6 @@ decorateType (ast * tree) /* otherwise just copy the type information */ COPYTYPE (TTYPE (tree), TETYPE (tree), tree->opval.val->type); - if (funcInChain (tree->opval.val->type)) - { - tree->hasVargs = tree->opval.val->sym->hasVargs; - tree->args = copyValueChain (tree->opval.val->sym->args); - } return tree; } @@ -1950,13 +1937,6 @@ decorateType (ast * tree) /* and mark it as referenced */ tree->opval.val->sym->isref = 1; - /* if this is of type function or function pointer */ - if (funcInChain (tree->opval.val->type)) - { - tree->hasVargs = tree->opval.val->sym->hasVargs; - tree->args = copyValueChain (tree->opval.val->sym->args); - - } } } } @@ -2044,7 +2024,7 @@ decorateType (ast * tree) } TTYPE (tree) = structElemType (LTYPE (tree), (tree->right->type == EX_VALUE ? - tree->right->opval.val : NULL), &tree->args); + tree->right->opval.val : NULL)); TETYPE (tree) = getSpec (TTYPE (tree)); return tree; @@ -2068,7 +2048,7 @@ decorateType (ast * tree) TTYPE (tree) = structElemType (LTYPE (tree)->next, (tree->right->type == EX_VALUE ? - tree->right->opval.val : NULL), &tree->args); + tree->right->opval.val : NULL)); TETYPE (tree) = getSpec (TTYPE (tree)); return tree; @@ -2356,9 +2336,7 @@ decorateType (ast * tree) } TTYPE (tree) = copyLinkChain ((IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree))) ? LTYPE (tree)->next : NULL); - TETYPE (tree) = getSpec (TTYPE (tree)); - tree->args = tree->left->args; - tree->hasVargs = tree->left->hasVargs; + TETYPE (tree) = getSpec (TTYPE (tree)); SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree)); return tree; } @@ -3149,17 +3127,17 @@ decorateType (ast * tree) parmNumber = 1; if (processParms (tree->left, - tree->left->args, + FUNC_ARGS(tree->left->ftype), tree->right, &parmNumber, TRUE)) goto errorTreeReturn; - if (options.stackAuto || IS_RENT (LETYPE (tree))) + if (options.stackAuto || IFFUNC_ISREENT (LTYPE (tree))) { - tree->left->args = reverseVal (tree->left->args); + //IFFUNC_ARGS(tree->left->ftype) = + //reverseVal (IFFUNC_ARGS(tree->left->ftype)); reverseParms (tree->right); } - tree->args = tree->left->args; TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)->next); return tree; @@ -4167,7 +4145,7 @@ createFunction (symbol * name, ast * body) iCode *piCode = NULL; /* if check function return 0 then some problem */ - if (checkFunction (name) == 0) + if (checkFunction (name, NULL) == 0) return NULL; /* create a dummy block if none exists */ @@ -4201,22 +4179,22 @@ createFunction (symbol * name, ast * body) /* set the stack pointer */ /* PENDING: check this for the mcs51 */ stackPtr = -port->stack.direction * port->stack.call_overhead; - if (IS_ISR (name->etype)) + if (IFFUNC_ISISR (name->type)) stackPtr -= port->stack.direction * port->stack.isr_overhead; - if (IS_RENT (name->etype) || options.stackAuto) + if (IFFUNC_ISREENT (name->type) || options.stackAuto) stackPtr -= port->stack.direction * port->stack.reent_overhead; xstackPtr = -port->stack.direction * port->stack.call_overhead; fetype = getSpec (name->type); /* get the specifier for the function */ /* if this is a reentrant function then */ - if (IS_RENT (fetype)) + if (IFFUNC_ISREENT (name->type)) reentrant++; - allocParms (name->args); /* allocate the parameters */ + allocParms (FUNC_ARGS(name->type)); /* allocate the parameters */ /* do processing for parameters that are passed in registers */ - processRegParms (name->args, body); + processRegParms (FUNC_ARGS(name->type), body); /* set the stack pointer */ stackPtr = 0; @@ -4239,7 +4217,7 @@ createFunction (symbol * name, ast * body) ex = newAst_VALUE (symbolVal (name)); /* create name */ ex = newNode (FUNCTION, ex, body); - ex->values.args = name->args; + ex->values.args = FUNC_ARGS(name->type); if (fatalError) { @@ -4274,16 +4252,16 @@ skipall: /* dealloc the block variables */ processBlockVars (body, &stack, DEALLOCATE); /* deallocate paramaters */ - deallocParms (name->args); + deallocParms (FUNC_ARGS(name->type)); - if (IS_RENT (fetype)) + if (IFFUNC_ISREENT (name->type)) reentrant--; /* we are done freeup memory & cleanup */ noLineno--; labelKey = 1; name->key = 0; - name->fbody = 1; + FUNC_HASBODY(name->type) = 1; addSet (&operKeyReset, name); applyToSet (operKeyReset, resetParmKey); diff --git a/src/SDCCast.h b/src/SDCCast.h index f0cbfaf6..32fe4692 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -43,7 +43,6 @@ typedef struct ast unsigned type:3; unsigned decorated:1; - unsigned hasVargs:1; unsigned isError:1; unsigned funcName:1; unsigned rvalue:1; @@ -102,7 +101,6 @@ typedef struct ast sym_link *etype; /* end of type chain for this subtree */ symbol *argSym; /* argument symbols */ - value *args; /* args of a function */ struct ast *left; /* pointer to left tree */ struct ast *right; /* pointer to right tree */ symbol *trueLabel; /* if statement trueLabel */ diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 48323bd4..1d6e0ed1 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -204,7 +204,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) (sym->_isparm && !IS_REGPARM (sym->etype))) && addPublics && !IS_STATIC (sym->etype) && - (IS_FUNC(sym->type) ? (sym->used || sym->fbody) : 1)) + (IS_FUNC(sym->type) ? (sym->used || IFFUNC_HASBODY(sym->type)) : 1)) { addSetHead (&publics, sym); } @@ -1104,7 +1104,7 @@ createInterruptVect (FILE * vFile) } /* if the main is only a prototype ie. no body then do nothing */ - if (!mainf->fbody) + if (!IFFUNC_HASBODY(mainf->type)) { /* if ! compile only then main function should be present */ if (!options.cc_only && !noAssemble) @@ -1388,7 +1388,7 @@ glue () copyFile (asmFile, ovrFile); /* create the stack segment MOF */ - if (mainf && mainf->fbody) + if (mainf && IFFUNC_HASBODY(mainf->type)) { fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; Stack segment in internal ram \n"); @@ -1410,7 +1410,7 @@ glue () copyFile (asmFile, bit->oFile); /* if external stack then reserve space of it */ - if (mainf && mainf->fbody && options.useXstack) + if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack) { fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; external stack \n"); @@ -1427,7 +1427,7 @@ glue () copyFile (asmFile, xdata->oFile); /* copy the interrupt vector table */ - if (mainf && mainf->fbody) + if (mainf && IFFUNC_HASBODY(mainf->type)) { fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; interrupt vector \n"); @@ -1450,7 +1450,7 @@ glue () tfprintf (asmFile, "\t!area\n", port->mem.post_static_name); tfprintf (asmFile, "\t!area\n", port->mem.static_name); - if (mainf && mainf->fbody) + if (mainf && IFFUNC_HASBODY(mainf->type)) { fprintf (asmFile, "__sdcc_gsinit_startup:\n"); /* if external stack is specified then the @@ -1485,7 +1485,7 @@ glue () } copyFile (asmFile, statsg->oFile); - if (port->general.glue_up_main && mainf && mainf->fbody) + if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) { /* This code is generated in the post-static area. * This area is guaranteed to follow the static area @@ -1507,7 +1507,7 @@ glue () fprintf (asmFile, "; code\n"); fprintf (asmFile, "%s", iComments2); tfprintf (asmFile, "\t!areacode\n", CODE_NAME); - if (mainf && mainf->fbody) + if (mainf && IFFUNC_HASBODY(mainf->type)) { /* entry point @ start of CSEG */ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index a7439f0c..e0678943 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1266,7 +1266,6 @@ operandFromSymbol (symbol * sym) register equivalent for a local symbol */ if (sym->level && sym->etype && SPEC_OCLS (sym->etype) && (IN_FARSPACE (SPEC_OCLS (sym->etype)) && - /* (!TARGET_IS_DS390)) && */ (!(options.model == MODEL_FLAT24)) ) && options.stackAuto == 0) ok = 0; @@ -1330,8 +1329,6 @@ operandFromSymbol (symbol * sym) else IC_RESULT (ic)->isaddr = (!IS_AGGREGATE (sym->type)); - IC_RESULT (ic)->operand.symOperand->args = sym->args; - ADDTOCHAIN (ic); return IC_RESULT (ic); @@ -1572,10 +1569,6 @@ geniCodeRValue (operand * op, bool force) /* ic->supportRtn = ((IS_GENPTR(type) | op->isGptr) & op->isaddr); */ - /* if the right is a symbol */ - if (op->type == SYMBOL) - IC_RESULT (ic)->operand.symOperand->args = - op->operand.symOperand->args; ADDTOCHAIN (ic); return IC_RESULT (ic); @@ -2701,21 +2694,32 @@ geniCodeSEParms (ast * parms,int lvl) /*-----------------------------------------------------------------*/ /* geniCodeParms - generates parameters */ /*-----------------------------------------------------------------*/ -static void -geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl) +value * +geniCodeParms (ast * parms, value *argVals, int *stack, + sym_link * fetype, symbol * func,int lvl) { iCode *ic; operand *pval; if (!parms) - return; + return argVals; + + if (argVals==NULL) { + // first argument + argVals=FUNC_ARGS(func->type); + } + + if (parms->argSym || + (parms->type!=EX_OP && parms->type!=EX_OPERAND)) { + fprintf (stderr, "What the fuck??\n"); + } /* if this is a param node then do the left & right */ if (parms->type == EX_OP && parms->opval.op == PARAM) { - geniCodeParms (parms->left, stack, fetype, func,lvl); - geniCodeParms (parms->right, stack, fetype, func,lvl); - return; + argVals=geniCodeParms (parms->left, argVals, stack, fetype, func,lvl); + argVals=geniCodeParms (parms->right, argVals, stack, fetype, func,lvl); + return argVals; } /* get the parameter value */ @@ -2737,9 +2741,13 @@ geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl pval = geniCodeRValue (ast2iCode (parms,lvl+1), FALSE); } - /* if register parm then make it a send */ - if (((parms->argSym && IS_REGPARM (parms->argSym->etype)) || - IS_REGPARM (parms->etype)) && !func->hasVargs) + /* if register arg then make it a send */ + if (((argVals->sym && IS_REGPARM (argVals->sym->etype)) || + IS_REGPARM (parms->etype)) && !IFFUNC_HASVARARGS(func->type)) + //!DECL_HASVARARGS(func->type) && + //!options.stackAuto && + //!IS_RENT(func->etype) && + //IS_REGPARM (argVals->sym->etype)) { ic = newiCode (SEND, pval, NULL); ADDTOCHAIN (ic); @@ -2747,11 +2755,11 @@ geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl else { /* now decide whether to push or assign */ - if (!(options.stackAuto || IS_RENT (fetype))) + if (!(options.stackAuto || IFFUNC_ISREENT (func->type))) { /* assign */ - operand *top = operandFromSymbol (parms->argSym); + operand *top = operandFromSymbol (argVals->sym); geniCodeAssign (top, pval, 1); } else @@ -2766,6 +2774,8 @@ geniCodeParms (ast * parms, int *stack, sym_link * fetype, symbol * func,int lvl } } + argVals=argVals->next; + return argVals; } /*-----------------------------------------------------------------*/ @@ -2791,7 +2801,7 @@ geniCodeCall (operand * left, ast * parms,int lvl) geniCodeSEParms (parms,lvl); /* first the parameters */ - geniCodeParms (parms, &stack, getSpec (operandType (left)), OP_SYMBOL (left),lvl); + geniCodeParms (parms, NULL, &stack, getSpec (operandType (left)), OP_SYMBOL (left),lvl); /* now call : if symbol then pcall */ if (IS_OP_POINTER (left) || IS_ITEMP(left)) @@ -2799,7 +2809,7 @@ geniCodeCall (operand * left, ast * parms,int lvl) else ic = newiCode (CALL, left, NULL); - IC_ARGS (ic) = left->operand.symOperand->args; + IC_ARGS (ic) = FUNC_ARGS(left->operand.symOperand->type); type = copyLinkChain (operandType (left)->next); etype = getSpec (type); SPEC_EXTR (etype) = 0; diff --git a/src/SDCCicode.h b/src/SDCCicode.h index 4156e257..a7534ecc 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -169,7 +169,7 @@ typedef struct iCode union { symbol *label; /* for a goto statement */ - value *args; + value *args; /* for a function */ } argLabel; diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 9084d1ec..883072ff 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -291,19 +291,19 @@ allocGlobal (symbol * sym) SPEC_OCLS (sym->etype) = code; /* if this is an interrupt service routine then put it in the interrupt service array */ - if (IS_ISR (sym->etype)) + if (FUNC_ISISR (sym->type)) { - if (interrupts[SPEC_INTN (sym->etype)]) + if (interrupts[FUNC_INTNO (sym->type)]) werror (E_INT_DEFINED, - SPEC_INTN (sym->etype), - interrupts[SPEC_INTN (sym->etype)]->name); + FUNC_INTNO (sym->type), + interrupts[FUNC_INTNO (sym->type)]->name); else - interrupts[SPEC_INTN (sym->etype)] = sym; + interrupts[FUNC_INTNO (sym->type)] = sym; /* automagically extend the maximum interrupts */ - if (SPEC_INTN (sym->etype) >= maxInterrupts) - maxInterrupts = SPEC_INTN (sym->etype) + 1; + if (FUNC_INTNO (sym->type) >= maxInterrupts) + maxInterrupts = FUNC_INTNO (sym->type) + 1; } /* if it is not compiler defined */ if (!sym->cdef) @@ -434,7 +434,7 @@ allocParms (value * val) /* if automatic variables r 2b stacked */ - if (options.stackAuto || IS_RENT (currFunc->etype)) + if (options.stackAuto || IFFUNC_ISREENT (currFunc->type)) { if (lval->sym) @@ -456,9 +456,9 @@ allocParms (value * val) if (port->stack.direction > 0) { SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack = - stackPtr - (SPEC_BANK (currFunc->etype) ? port->stack.bank_overhead : 0) - + stackPtr - (FUNC_REGBANK (currFunc->type) ? port->stack.bank_overhead : 0) - getSize (lval->type) - - (IS_ISR (currFunc->etype) ? port->stack.isr_overhead : 0); + (FUNC_ISISR (currFunc->type) ? port->stack.isr_overhead : 0); stackPtr -= getSize (lval->type); } else @@ -467,8 +467,8 @@ allocParms (value * val) /* PENDING: isr, bank overhead, ... */ SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack = stackPtr + - (IS_BANKEDCALL (currFunc->etype) ? port->stack.banked_overhead : 0) + - (IS_ISR (currFunc->etype) ? port->stack.isr_overhead : 0) + + ((IFFUNC_ISBANKEDCALL (currFunc->type) && !SPEC_STAT(getSpec(currFunc->etype)))? port->stack.banked_overhead : 0) + + (FUNC_ISISR (currFunc->type) ? port->stack.isr_overhead : 0) + 0; stackPtr += getSize (lval->type); } @@ -802,8 +802,8 @@ allocVariables (symbol * symChain) processFuncArgs (csym, 1); /* if register bank specified then update maxRegBank */ - if (maxRegBank < SPEC_BANK (csym->etype)) - maxRegBank = SPEC_BANK (csym->etype); + if (maxRegBank < FUNC_REGBANK (csym->type)) + maxRegBank = FUNC_REGBANK (csym->type); } /* if this is a extern variable then change the */ @@ -1002,8 +1002,8 @@ canOverlayLocals (eBBlock ** ebbs, int count) if (options.noOverlay || options.stackAuto || (currFunc && - (IS_RENT (currFunc->etype) || - IS_ISR (currFunc->etype))) || + (IFFUNC_ISREENT (currFunc->type) || + FUNC_ISISR (currFunc->type))) || elementsInSet (overlay->syms) == 0) return FALSE; diff --git a/src/SDCCopt.c b/src/SDCCopt.c index 9d390292..0ffaa5f2 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -106,28 +106,28 @@ cnvToFcall (iCode * ic, eBBlock * ebp) { /* first one */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { newic = newiCode (SEND, IC_LEFT (ic), NULL); } else { newic = newiCode ('=', NULL, IC_LEFT (ic)); - IC_RESULT (newic) = operandFromValue (func->args); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; /* second one */ - if (IS_REGPARM (func->args->next->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) { newic = newiCode (SEND, IC_LEFT (ic), NULL); } else { newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (func->args->next); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)->next); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -137,7 +137,7 @@ cnvToFcall (iCode * ic, eBBlock * ebp) { /* push right */ - if (IS_REGPARM (func->args->next->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) { newic = newiCode (SEND, right, NULL); } @@ -152,7 +152,7 @@ cnvToFcall (iCode * ic, eBBlock * ebp) newic->lineno = lineno; /* insert push left */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { newic = newiCode (SEND, left, NULL); } @@ -207,12 +207,12 @@ found: if (!options.float_rent) { /* first one */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (func->args); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = linenno; @@ -221,7 +221,7 @@ found: else { /* push the left */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { @@ -276,12 +276,12 @@ found: if (!options.float_rent) { /* first one */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (func->args); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -291,7 +291,7 @@ found: { /* push the left */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { @@ -360,23 +360,23 @@ found: if (!options.intlong_rent) { /* first one */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_LEFT (ic), NULL); else { newic = newiCode ('=', NULL, IC_LEFT (ic)); - IC_RESULT (newic) = operandFromValue (func->args); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; /* second one */ - if (IS_REGPARM (func->args->next->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (func->args->next); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)->next); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -386,7 +386,7 @@ found: { /* compiled as reentrant then push */ /* push right */ - if (IS_REGPARM (func->args->next->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) { newic = newiCode (SEND, IC_RIGHT (ic), NULL); } @@ -401,7 +401,7 @@ found: newic->lineno = lineno; /* insert push left */ - if (IS_REGPARM (func->args->etype)) + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { newic = newiCode (SEND, IC_LEFT (ic), NULL); } diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index a25a369f..b740ef1e 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -538,29 +538,8 @@ void checkTypeSanity(sym_link *etype, char *name) { sym_link * mergeSpec (sym_link * dest, sym_link * src, char *name) { - sym_link *symlink=dest; -#if 0 - if (!IS_SPEC(dest)) { - // This can happen for pointers, find the end type - while (dest && !IS_SPEC(dest)) - dest=dest->next; - } - if (!IS_SPEC(src)) { - // here we have a declarator as source, reverse them - symlink=src; - src=dest; - dest=symlink; - while (dest && !IS_SPEC(dest)) { - // and find the specifier - dest=dest->next; - } - } else { - symlink=dest; - } -#endif - if (!IS_SPEC(dest) || !IS_SPEC(src)) { werror (E_INTERNAL_ERROR, __FILE__, __LINE__, "cannot merge declarator"); exit (1); @@ -614,22 +593,24 @@ mergeSpec (sym_link * dest, sym_link * src, char *name) SPEC_STAT (dest) |= SPEC_STAT (src); SPEC_EXTR (dest) |= SPEC_EXTR (src); SPEC_ABSA (dest) |= SPEC_ABSA (src); - SPEC_RENT (dest) |= SPEC_RENT (src); - SPEC_INTN (dest) |= SPEC_INTN (src); - SPEC_BANK (dest) |= SPEC_BANK (src); SPEC_VOLATILE (dest) |= SPEC_VOLATILE (src); - SPEC_CRTCL (dest) |= SPEC_CRTCL (src); SPEC_ADDR (dest) |= SPEC_ADDR (src); SPEC_OCLS (dest) = SPEC_OCLS (src); SPEC_BLEN (dest) |= SPEC_BLEN (src); SPEC_BSTR (dest) |= SPEC_BSTR (src); SPEC_TYPEDEF (dest) |= SPEC_TYPEDEF (src); - SPEC_NONBANKED (dest) |= SPEC_NONBANKED (src); - SPEC_NAKED (dest) |= SPEC_NAKED (src); if (IS_STRUCT (dest) && SPEC_STRUCT (dest) == NULL) SPEC_STRUCT (dest) = SPEC_STRUCT (src); + /* these are the only function attributes that will be set + in a specifier while parsing */ + FUNC_NONBANKED(dest) |= FUNC_NONBANKED(src); + FUNC_BANKED(dest) |= FUNC_BANKED(src); + FUNC_ISCRITICAL(dest) |= FUNC_ISCRITICAL(src); + FUNC_ISREENT(dest) |= FUNC_ISREENT(src); + FUNC_ISNAKED(dest) |= FUNC_ISNAKED(src); + return symlink; } @@ -890,9 +871,7 @@ copySymbol (symbol * src) dest->type = copyLinkChain (src->type); dest->etype = getSpec (dest->type); dest->next = NULL; - dest->args = copyValueChain (src->args); dest->key = src->key; - dest->calleeSave = src->calleeSave; dest->allocreq = src->allocreq; return dest; } @@ -1010,7 +989,7 @@ funcInChain (sym_link * lnk) /* structElemType - returns the type info of a sturct member */ /*------------------------------------------------------------------*/ sym_link * -structElemType (sym_link * stype, value * id, value ** argsp) +structElemType (sym_link * stype, value * id) { symbol *fields = (SPEC_STRUCT (stype) ? SPEC_STRUCT (stype)->fields : NULL); sym_link *type, *etype; @@ -1024,10 +1003,6 @@ structElemType (sym_link * stype, value * id, value ** argsp) { if (strcmp (fields->rname, id->name) == 0) { - if (argsp) - { - *argsp = fields->args; - } type = copyLinkChain (fields->type); etype = getSpec (type); SPEC_SCLS (etype) = (SPEC_SCLS (petype) == S_REGISTER ? @@ -1263,7 +1238,7 @@ checkSClass (symbol * sym, int isProto) if (sym->level && SPEC_SCLS (sym->etype) == S_FIXED && !IS_STATIC(sym->etype)) { - if (options.stackAuto || (currFunc && IS_RENT (currFunc->etype))) + if (options.stackAuto || (currFunc && IFFUNC_ISREENT (currFunc->type))) { SPEC_SCLS (sym->etype) = (options.useXstack ? S_XSTACK : S_STACK); @@ -1461,8 +1436,12 @@ compareType (sym_link * dest, sym_link * src) { if (IS_DECL (src)) { - if (DCL_TYPE (src) == DCL_TYPE (dest)) + if (DCL_TYPE (src) == DCL_TYPE (dest)) { + if (IS_FUNC(src)) { + //checkFunction(src,dest); + } return compareType (dest->next, src->next); + } if (IS_PTR (src) && IS_GENPTR (dest)) return -1; if (IS_PTR (dest) && IS_ARRAY (src)) { @@ -1624,9 +1603,8 @@ aggregateToPointer (value * val) /* checkFunction - does all kinds of check on a function */ /*------------------------------------------------------------------*/ int -checkFunction (symbol * sym) +checkFunction (symbol * sym, symbol *csym) { - symbol *csym; value *exargs, *acargs; value *checkValue; int argCnt = 0; @@ -1662,21 +1640,23 @@ checkFunction (symbol * sym) /* check if this function is defined as calleeSaves then mark it as such */ - sym->calleeSave = inCalleeSaveList (sym->name); + FUNC_CALLEESAVES(sym->type) = inCalleeSaveList (sym->name); /* if interrupt service routine */ /* then it cannot have arguments */ - if (sym->args && IS_ISR (sym->etype) && !IS_VOID (sym->args->type)) + if (IFFUNC_ARGS(sym->type) && FUNC_ISISR (sym->type)) { - werror (E_INT_ARGS, sym->name); - sym->args = NULL; + if (!IS_VOID(FUNC_ARGS(sym->type)->type)) { + werror (E_INT_ARGS, sym->name); + FUNC_ARGS(sym->type)=NULL; + } } - if (!(csym = findSym (SymbolTab, sym, sym->name))) + if (!csym && !(csym = findSym (SymbolTab, sym, sym->name))) return 1; /* not defined nothing more to check */ /* check if body already present */ - if (csym && csym->fbody) + if (csym && IFFUNC_HASBODY(csym->type)) { werror (E_FUNC_BODY, sym->name); return 0; @@ -1695,24 +1675,24 @@ checkFunction (symbol * sym) return 0; } - if (SPEC_INTRTN (csym->etype) != SPEC_INTRTN (sym->etype)) + if (FUNC_ISISR (csym->type) != FUNC_ISISR (sym->type)) { werror (E_PREV_DEF_CONFLICT, csym->name, "interrupt"); } - if (SPEC_BANK (csym->etype) != SPEC_BANK (sym->etype)) + if (FUNC_REGBANK (csym->type) != FUNC_REGBANK (sym->type)) { werror (E_PREV_DEF_CONFLICT, csym->name, "using"); } - if (SPEC_NAKED (csym->etype) != SPEC_NAKED (sym->etype)) + if (IFFUNC_ISNAKED (csym->type) != IFFUNC_ISNAKED (sym->type)) { werror (E_PREV_DEF_CONFLICT, csym->name, "_naked"); } /* compare expected args with actual args */ - exargs = csym->args; - acargs = sym->args; + exargs = FUNC_ARGS(csym->type); + acargs = FUNC_ARGS(sym->type); /* for all the expected args do */ for (argCnt = 1; @@ -1774,19 +1754,20 @@ processFuncArgs (symbol * func, int ignoreName) /* if this function has variable argument list */ /* then make the function a reentrant one */ - if (func->hasVargs) - SPEC_RENT (func->etype) = 1; + if (IFFUNC_HASVARARGS(func->type)) + FUNC_ISREENT(func->type)=1; /* check if this function is defined as calleeSaves then mark it as such */ - func->calleeSave = inCalleeSaveList (func->name); + FUNC_CALLEESAVES(func->type) = inCalleeSaveList (func->name); - val = func->args; /* loop thru all the arguments */ + /* loop thru all the arguments */ + val = FUNC_ARGS(func->type); /* if it is void then remove parameters */ if (val && IS_VOID (val->type)) { - func->args = NULL; + FUNC_ARGS(func->type) = NULL; return; } @@ -1799,7 +1780,7 @@ processFuncArgs (symbol * func, int ignoreName) /* mark it as a register parameter if the function does not have VA_ARG and as port dictates */ - if (!func->hasVargs && + if (!IFFUNC_HASVARARGS(func->type) && (*port->reg_parm) (val->type)) { SPEC_REGPARM (val->etype) = 1; @@ -1817,17 +1798,17 @@ processFuncArgs (symbol * func, int ignoreName) if (func->cdef) { /* ignore --stack-auto for this one, we don't know how it is compiled */ /* simply trust on --int-long-reent or --float-reent */ - if (IS_RENT(func->etype)) { + if (IFFUNC_ISREENT(func->type)) { return; } } else { /* if this function is reentrant or */ /* automatics r 2b stacked then nothing */ - if (IS_RENT (func->etype) || options.stackAuto) + if (IFFUNC_ISREENT (func->type) || options.stackAuto) return; } - val = func->args; + val = FUNC_ARGS(func->type); pNum = 1; while (val) { @@ -2194,8 +2175,8 @@ cdbSymbol (symbol * sym, FILE * of, int isStructSym, int isFunc) if is it an interrupt routine & interrupt number and the register bank it is using */ if (isFunc) - fprintf (of, ",%d,%d,%d", SPEC_INTRTN (sym->etype), - SPEC_INTN (sym->etype), SPEC_BANK (sym->etype)); + fprintf (of, ",%d,%d,%d", FUNC_ISISR (sym->type), + FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type)); /* alternate location to find this symbol @ : eg registers or spillication */ @@ -2404,7 +2385,7 @@ initCSupport () ssu[su], sbwd[bwd]); __muldiv[muldivmod][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent); - SPEC_NONBANKED (__muldiv[muldivmod][bwd][su]->etype) = 1; + FUNC_NONBANKED (__muldiv[muldivmod][bwd][su]->type) = 1; } } } @@ -2420,7 +2401,7 @@ initCSupport () ssu[su], sbwd[bwd]); __rlrr[rlrr][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], __multypes[0][0], 2, options.intlong_rent); - SPEC_NONBANKED (__rlrr[rlrr][bwd][su]->etype) = 1; + FUNC_NONBANKED (__rlrr[rlrr][bwd][su]->type) = 1; } } } diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index b253154f..12e76466 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -102,20 +102,11 @@ typedef struct specifier unsigned _static:1; /* 1=static keyword found */ unsigned _extern:1; /* 1=extern found */ unsigned _absadr:1; /* absolute address specfied */ - unsigned _reent:1; /* function is reentrant */ - unsigned _intrtn:1; /* this is an interrupt routin */ - unsigned _rbank:1; /* seperate register bank */ unsigned _volatile:1; /* is marked as volatile */ unsigned _const:1; /* is a constant */ - unsigned _critical:1; /* critical function */ - unsigned _naked:1; /* naked function */ unsigned _typedef:1; /* is typedefed */ unsigned _isregparm:1; /* is the first parameter */ unsigned _isenum:1; /* is an enumerated type */ - unsigned nonbanked:1; /* function has the nonbanked attribute */ - unsigned banked:1; /* function has the banked attribute */ - unsigned _IntNo; /* 1=Interrupt svc routine */ - short _regbank; /* register bank 2b used */ unsigned _addr; /* address of symbol */ unsigned _stack; /* stack offset for stacked v */ unsigned _bitStart; /* bit start position */ @@ -158,7 +149,7 @@ typedef struct declarator unsigned int num_elem; /* # of elems if type==array */ short ptr_const:1; /* pointer is constant */ short ptr_volatile:1; /* pointer is volatile */ - struct sym_link *tspec; /* pointer type specifier */ + struct sym_link *tspec; /* pointer type specifier */ } declarator; @@ -174,8 +165,27 @@ typedef struct sym_link { specifier s; /* if CLASS == SPECIFIER */ declarator d; /* if CLASS == DECLARATOR */ - } - select; + } select; + + /* function attributes */ + struct { + struct value *args; /* the defined arguments */ + unsigned hasVargs:1; /* functions has varargs */ + unsigned calleeSaves:1; /* functions uses callee save */ + unsigned hasbody:1; /* function body defined */ + //unsigned ret:1; /* return statement for a function */ + unsigned hasFcall:1; /* does it call other functions */ + unsigned reent:1; /* function is reentrant */ + unsigned naked:1; /* naked function */ + + unsigned nonbanked:1; /* function has the nonbanked attribute */ + unsigned banked:1; /* function has the banked attribute */ + unsigned critical:1; /* critical function */ + unsigned intrtn:1; /* this is an interrupt routin */ + unsigned rbank:1; /* seperate register bank */ + unsigned intno; /* 1=Interrupt svc routine */ + unsigned regbank; /* register bank 2b used */ + } funcAttrs; struct sym_link *next; /* next element on the chain */ } @@ -189,11 +199,8 @@ typedef struct symbol short level; /* declration lev,fld offset */ short block; /* sequential block # of defintion */ int key; - unsigned fbody:1; /* function body defined */ unsigned implicit:1; /* implicit flag */ unsigned undefined:1; /* undefined variable */ - unsigned ret:1; /* return statement for a function */ - unsigned hasVargs:1; /* has a variable argument list */ unsigned _isparm:1; /* is a parameter */ unsigned ismyparm:1; /* is parameter of the function being generated */ unsigned isitmp:1; /* is an intermediate temp */ @@ -206,8 +213,6 @@ typedef struct symbol unsigned allocreq:1; /* allocation is required for this variable */ unsigned addrtaken:1; /* address of the symbol was taken */ unsigned isreqv:1; /* is the register quivalent of a symbol */ - unsigned hasFcall:1; /* for functions does it call other functions */ - unsigned calleeSave:1; /* for functions uses callee save paradigm */ unsigned udChked:1; /* use def checking has been already done */ /* following flags are used by the backend @@ -258,7 +263,6 @@ typedef struct symbol int lastLine; /* for functions the last line */ struct sym_link *type; /* 1st link to declator chain */ struct sym_link *etype; /* last link to declarator chn */ - struct value *args; /* arguments if function */ struct symbol *next; /* crosslink to next symbol */ struct symbol *localof; /* local variable of which function */ struct initList *ival; /* ptr to initializer if any */ @@ -278,6 +282,42 @@ symbol; #define DCL_PTR_CONST(l) l->select.d.ptr_const #define DCL_PTR_VOLATILE(l) l->select.d.ptr_volatile #define DCL_TSPEC(l) l->select.d.tspec + +#define FUNC_DEBUG //assert(IS_FUNC(x)); +#define FUNC_HASVARARGS(x) (x->funcAttrs.hasVargs) +#define IFFUNC_HASVARARGS(x) (IS_FUNC(x) && FUNC_HASVARARGS(x)) +#define FUNC_ARGS(x) (x->funcAttrs.args) +#define IFFUNC_ARGS(x) (IS_FUNC(x) && FUNC_ARGS(x)) +#define FUNC_HASFCALL(x) (x->funcAttrs.hasFcall) +#define IFFUNC_HASFCALL(x) (IS_FUNC(x) && FUNC_HASFCALL(x)) +#define FUNC_HASBODY(x) (x->funcAttrs.hasbody) +#define IFFUNC_HASBODY(x) (IS_FUNC(x) && FUNC_HASBODY(x)) +#define FUNC_CALLEESAVES(x) (x->funcAttrs.calleeSaves) +#define IFFUNC_CALLEESAVES(x) (IS_FUNC(x) && FUNC_CALLEESAVES(x)) +#define FUNC_ISISR(x) (x->funcAttrs.intrtn) +#define IFFUNC_ISISR(x) (IS_FUNC(x) && FUNC_ISISR(x)) +//#define FUNC_RBANK(x) (x->funcAttrs.rbank) +#define IFFUNC_RBANK(x) (IS_FUNC(x) && FUNC_RBANK(x)) +#define FUNC_INTNO(x) (x->funcAttrs.intno) +#define FUNC_REGBANK(x) (x->funcAttrs.regbank) + +#define FUNC_ISREENT(x) (x->funcAttrs.reent) +#define IFFUNC_ISREENT(x) (IS_FUNC(x) && FUNC_ISREENT(x)) +#define FUNC_ISNAKED(x) (x->funcAttrs.naked) +#define IFFUNC_ISNAKED(x) (IS_FUNC(x) && FUNC_ISNAKED(x)) +#define FUNC_NONBANKED(x) (x->funcAttrs.nonbanked) +#define IFFUNC_NONBANKED(x) (IS_FUNC(x) && FUNC_NONBANKED(x)) +#define FUNC_BANKED(x) (x->funcAttrs.banked) +#define IFFUNC_BANKED(x) (IS_FUNC(x) && FUNC_BANKED(x)) +#define FUNC_ISCRITICAL(x) (x->funcAttrs.critical) +#define IFFUNC_ISCRITICAL(x) (IS_FUNC(x) && FUNC_ISCRITICAL(x)) + +// jwk: I am not sure about this +#define IFFUNC_ISBANKEDCALL(x) (!IFFUNC_NONBANKED(x) && \ + (options.model == MODEL_LARGE || \ + options.model == MODEL_MEDIUM || \ + IFFUNC_BANKED(x))) + #define SPEC_NOUN(x) x->select.s.noun #define SPEC_LONG(x) x->select.s._long #define SPEC_USIGN(x) x->select.s._unsigned @@ -287,8 +327,6 @@ symbol; #define SPEC_STAT(x) x->select.s._static #define SPEC_EXTR(x) x->select.s._extern #define SPEC_CODE(x) x->select.s._codesg -#define SPEC_RENT(x) x->select.s._reent -#define SPEC_INTN(x) x->select.s._IntNo #define SPEC_ABSA(x) x->select.s._absadr #define SPEC_BANK(x) x->select.s._regbank #define SPEC_ADDR(x) x->select.s._addr @@ -303,17 +341,11 @@ symbol; * _bitStart field instead of defining a new field. */ #define SPEC_ISR_SAVED_BANKS(x) x->select.s._bitStart -#define SPEC_BNKF(x) x->select.s._rbank -#define SPEC_INTRTN(x) x->select.s._intrtn -#define SPEC_CRTCL(x) x->select.s._critical -#define SPEC_NAKED(x) x->select.s._naked #define SPEC_VOLATILE(x) x->select.s._volatile #define SPEC_CONST(x) x->select.s._const #define SPEC_STRUCT(x) x->select.s.v_struct #define SPEC_TYPEDEF(x) x->select.s._typedef #define SPEC_REGPARM(x) x->select.s._isregparm -#define SPEC_NONBANKED(x) x->select.s.nonbanked -#define SPEC_BANKED(x) x->select.s.banked /* type check macros */ #define IS_DECL(x) ( x && x->class == DECLARATOR ) @@ -357,11 +389,7 @@ symbol; #define IS_ARITHMETIC(x) (IS_INTEGRAL(x) || IS_FLOAT(x)) #define IS_AGGREGATE(x) (IS_ARRAY(x) || IS_STRUCT(x)) #define IS_LITERAL(x) (IS_SPEC(x) && x->select.s.sclass == S_LITERAL) -#define IS_ISR(x) (IS_SPEC(x) && SPEC_INTRTN(x)) #define IS_REGPARM(x) (IS_SPEC(x) && SPEC_REGPARM(x)) -#define IS_NONBANKED(x) (IS_SPEC(x) && SPEC_NONBANKED(x)) -#define IS_BANKED(x) (IS_SPEC(x) && SPEC_BANKED(x)) -#define IS_BANKEDCALL(x) (IS_SPEC(x) && !SPEC_NONBANKED(x) && !SPEC_STAT(x) && (options.model == MODEL_LARGE || options.model == MODEL_MEDIUM || SPEC_BANKED(x))) /* forward declaration for the global vars */ extern bucket *SymbolTab[]; @@ -433,12 +461,12 @@ sym_link *newIntLink (); sym_link *newCharLink (); sym_link *newLongLink (); int compareType (sym_link *, sym_link *); -int checkFunction (symbol *); +int checkFunction (symbol *, symbol *); void cleanUpLevel (bucket **, int); void cleanUpBlock (bucket **, int); int funcInChain (sym_link *); void addSymChain (symbol *); -sym_link *structElemType (sym_link *, value *, value **); +sym_link *structElemType (sym_link *, value *); symbol *getStructElement (structdef *, symbol *); sym_link *computeType (sym_link *, sym_link *); void processFuncArgs (symbol *, int); diff --git a/src/avr/gen.c b/src/avr/gen.c index faf4c36c..d43e2d6d 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -1710,7 +1710,7 @@ static void genFunction (iCode * ic) { symbol *sym; - sym_link *fetype; + sym_link *ftype; int i = 0; _G.nRegsSaved = 0; @@ -1721,13 +1721,13 @@ genFunction (iCode * ic) emitcode (";", "-----------------------------------------"); emitcode ("", "%s:", sym->rname); - fetype = getSpec (operandType (IC_LEFT (ic))); + ftype = operandType (IC_LEFT (ic)); /* if critical function then turn interrupts off */ - if (SPEC_CRTCL (fetype)) + if (IFFUNC_ISCRITICAL (ftype)) emitcode ("cli", ""); - if (IS_ISR (sym->etype)) { + if (IFFUNC_ISISR (sym->type)) { } /* save the preserved registers that are used in this function */ @@ -1821,10 +1821,10 @@ genEndFunction (iCode * ic) } } - if (SPEC_CRTCL (sym->etype)) + if (IFFUNC_ISCRITICAL (sym->type)) emitcode ("sti", ""); - if (IS_ISR (sym->etype)) { + if (IFFUNC_ISISR (sym->type)) { emitcode ("rti", ""); } else { diff --git a/src/avr/ralloc.c b/src/avr/ralloc.c index c9595247..134f6806 100644 --- a/src/avr/ralloc.c +++ b/src/avr/ralloc.c @@ -2239,7 +2239,7 @@ setDefaultRegs (eBBlock ** ebbs, int count) regsAVR[i].type = (regsAVR[i].type & ~REG_MASK) | REG_SCR; regsAVR[i].isFree = 1; } - if (!currFunc->hasFcall) { + if (!IFFUNC_HASFCALL(currFunc->type)) { preAssignParms (ebbs[0]->sch); } /* Y - is not allocated (it is the stack frame) */ diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 7b421978..8895de11 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -1774,8 +1774,8 @@ saveRegisters (iCode * lic) /* if the registers have been saved already then do nothing */ - if (ic->regsSaved || (OP_SYMBOL (IC_LEFT (ic))->calleeSave) || - SPEC_NAKED(OP_SYM_ETYPE(IC_LEFT(ic)))) + if (ic->regsSaved || IFFUNC_CALLEESAVES(OP_SYMBOL (IC_LEFT (ic))->type) || + IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(ic)))) return; /* find the registers in use at this time @@ -2186,7 +2186,7 @@ saveRBank (int bank, iCode * ic, bool pushPsw) static void genCall (iCode * ic) { - sym_link *detype; + sym_link *dtype; bool restoreBank = FALSE; bool swapBanks = FALSE; @@ -2195,17 +2195,17 @@ genCall (iCode * ic) /* 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 */ - detype = getSpec (operandType (IC_LEFT (ic))); - if (detype && !SPEC_NAKED(detype) && - (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) && - IS_ISR (currFunc->etype)) + dtype = operandType (IC_LEFT (ic)); + if (dtype && !IFFUNC_ISNAKED(dtype) && + (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) && + IFFUNC_ISISR (currFunc->type)) { if (!ic->bankSaved) { /* This is unexpected; the bank should have been saved in * genFunction. */ - saveRBank (SPEC_BANK (detype), ic, FALSE); + saveRBank (FUNC_REGBANK (dtype), ic, FALSE); restoreBank = TRUE; } swapBanks = TRUE; @@ -2273,7 +2273,7 @@ genCall (iCode * ic) if (swapBanks) { emitcode ("mov", "psw,#0x%02x", - ((SPEC_BANK(detype)) << 3) & 0xff); + ((FUNC_REGBANK(dtype)) << 3) & 0xff); } /* make the call */ @@ -2284,7 +2284,7 @@ genCall (iCode * ic) if (swapBanks) { emitcode ("mov", "psw,#0x%02x", - ((SPEC_BANK(currFunc->etype)) << 3) & 0xff); + ((FUNC_REGBANK(currFunc->type)) << 3) & 0xff); } /* if we need assign a result value */ @@ -2343,12 +2343,12 @@ genCall (iCode * ic) } /* if we hade saved some registers then unsave them */ - if (ic->regsSaved && !(OP_SYMBOL (IC_LEFT (ic))->calleeSave)) + if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype)) unsaveRegisters (ic); /* if register bank was saved then pop them */ if (restoreBank) - unsaveRBank (SPEC_BANK (detype), ic, FALSE); + unsaveRBank (FUNC_REGBANK (dtype), ic, FALSE); } /*-----------------------------------------------------------------*/ @@ -2357,7 +2357,7 @@ genCall (iCode * ic) static void genPcall (iCode * ic) { - sym_link *detype; + sym_link *dtype; symbol *rlbl = newiTempLabel (NULL); D (emitcode (";", "genPcall "); @@ -2371,11 +2371,11 @@ genPcall (iCode * ic) /* if we are calling a function that is not using the same register bank then we need to save the destination registers on the stack */ - detype = getSpec (operandType (IC_LEFT (ic))); - if (detype && - IS_ISR (currFunc->etype) && - (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype))) - saveRBank (SPEC_BANK (detype), ic, TRUE); + dtype = operandType (IC_LEFT (ic)); + if (dtype && + IFFUNC_ISISR (currFunc->type) && + (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype))) + saveRBank (FUNC_REGBANK (dtype), ic, TRUE); /* push the return address on to the stack */ @@ -2466,10 +2466,10 @@ genPcall (iCode * ic) } /* if register bank was saved then unsave them */ - if (detype && - (SPEC_BANK (currFunc->etype) != - SPEC_BANK (detype))) - unsaveRBank (SPEC_BANK (detype), ic, TRUE); + if (dtype && + (FUNC_REGBANK (currFunc->type) != + FUNC_REGBANK (dtype))) + unsaveRBank (FUNC_REGBANK (dtype), ic, TRUE); /* if we hade saved some registers then unsave them */ @@ -2531,7 +2531,7 @@ static void genFunction (iCode * ic) { symbol *sym; - sym_link *fetype; + sym_link *ftype; bool switchedPSW = FALSE; D (emitcode (";", "genFunction ");); @@ -2543,25 +2543,25 @@ genFunction (iCode * ic) emitcode (";", "-----------------------------------------"); emitcode ("", "%s:", sym->rname); - fetype = getSpec (operandType (IC_LEFT (ic))); + ftype = operandType (IC_LEFT (ic)); - if (SPEC_NAKED(fetype)) + if (IFFUNC_ISNAKED(ftype)) { emitcode(";", "naked function: no prologue."); return; } /* if critical function then turn interrupts off */ - if (SPEC_CRTCL (fetype)) + if (IFFUNC_ISCRITICAL (ftype)) emitcode ("clr", "ea"); /* here we need to generate the equates for the register bank if required */ - if (SPEC_BANK (fetype) != rbank) + if (FUNC_REGBANK (ftype) != rbank) { int i; - rbank = SPEC_BANK (fetype); + rbank = FUNC_REGBANK (ftype); for (i = 0; i < ds390_nRegs; i++) { if (strcmp (regs390[i].base, "0") == 0) @@ -2578,7 +2578,7 @@ genFunction (iCode * ic) /* if this is an interrupt service routine then save acc, b, dpl, dph */ - if (IS_ISR (sym->etype)) + if (IFFUNC_ISISR (sym->type)) { if (!inExcludeList ("acc")) @@ -2607,13 +2607,13 @@ genFunction (iCode * ic) /* if this isr has no bank i.e. is going to run with bank 0 , then we need to save more registers :-) */ - if (!SPEC_BANK (sym->etype)) + if (!FUNC_REGBANK (sym->type)) { /* if this function does not call any other function then we can be economical and save only those registers that are used */ - if (!sym->hasFcall) + if (!IFFUNC_HASFCALL(sym->type)) { int i; @@ -2650,7 +2650,7 @@ genFunction (iCode * ic) */ unsigned long banksToSave = 0; - if (sym->hasFcall) + if (IFFUNC_HASFCALL(sym->type)) { #define MAX_REGISTER_BANKS 4 @@ -2668,20 +2668,20 @@ genFunction (iCode * ic) if (i->op == CALL) { - sym_link *detype; + sym_link *dtype; - detype = getSpec(operandType (IC_LEFT(i))); - if (detype - && SPEC_BANK(detype) != SPEC_BANK(sym->etype)) + dtype = operandType (IC_LEFT(i)); + if (dtype + && FUNC_REGBANK(dtype) != FUNC_REGBANK(sym->type)) { /* Mark this bank for saving. */ - if (SPEC_BANK(detype) >= MAX_REGISTER_BANKS) + if (FUNC_REGBANK(dtype) >= MAX_REGISTER_BANKS) { - werror(E_NO_SUCH_BANK, SPEC_BANK(detype)); + werror(E_NO_SUCH_BANK, FUNC_REGBANK(dtype)); } else { - banksToSave |= (1 << SPEC_BANK(detype)); + banksToSave |= (1 << FUNC_REGBANK(dtype)); } /* And note that we don't need to do it in @@ -2713,7 +2713,7 @@ genFunction (iCode * ic) */ emitcode ("push", "psw"); emitcode ("mov", "psw,#0x%02x", - (SPEC_BANK (sym->etype) << 3) & 0x00ff); + (FUNC_REGBANK (sym->type) << 3) & 0x00ff); switchedPSW = TRUE; } @@ -2725,6 +2725,7 @@ genFunction (iCode * ic) } } } + // jwk: this needs a closer look SPEC_ISR_SAVED_BANKS(currFunc->etype) = banksToSave; } } @@ -2732,7 +2733,7 @@ genFunction (iCode * ic) { /* if callee-save to be used for this function then save the registers being used in this function */ - if (sym->calleeSave) + if (IFFUNC_CALLEESAVES(sym->type)) { int i; @@ -2754,14 +2755,14 @@ genFunction (iCode * ic) } /* set the register bank to the desired value */ - if ((SPEC_BANK (sym->etype) || IS_ISR (sym->etype)) + if ((FUNC_REGBANK (sym->type) || FUNC_ISISR (sym->type)) && !switchedPSW) { emitcode ("push", "psw"); - emitcode ("mov", "psw,#0x%02x", (SPEC_BANK (sym->etype) << 3) & 0x00ff); + emitcode ("mov", "psw,#0x%02x", (FUNC_REGBANK (sym->type) << 3) & 0x00ff); } - if (IS_RENT (sym->etype) || options.stackAuto) + if (IFFUNC_ISREENT (sym->type) || options.stackAuto) { if (options.useXstack) @@ -2820,13 +2821,13 @@ genEndFunction (iCode * ic) D (emitcode (";", "genEndFunction ");); - if (SPEC_NAKED(sym->etype)) + if (IFFUNC_ISNAKED(sym->type)) { emitcode(";", "naked function: no epilogue."); return; } - if (IS_RENT (sym->etype) || options.stackAuto) + if (IFFUNC_ISREENT (sym->type) || options.stackAuto) { emitcode ("mov", "%s,_bp", spname); } @@ -2842,7 +2843,7 @@ genEndFunction (iCode * ic) } - if ((IS_RENT (sym->etype) || options.stackAuto)) + if ((IFFUNC_ISREENT (sym->type) || options.stackAuto)) { if (options.useXstack) { @@ -2858,9 +2859,9 @@ genEndFunction (iCode * ic) } /* restore the register bank */ - if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype)) + if (FUNC_REGBANK (sym->type) || IFFUNC_ISISR (sym->type)) { - if (!SPEC_BANK (sym->etype) || !IS_ISR (sym->etype) + if (!FUNC_REGBANK (sym->type) || !IFFUNC_ISISR (sym->type) || !options.useXstack) { /* Special case of ISR using non-zero bank with useXstack @@ -2870,19 +2871,19 @@ genEndFunction (iCode * ic) } } - if (IS_ISR (sym->etype)) + if (IFFUNC_ISISR (sym->type)) { /* now we need to restore the registers */ /* if this isr has no bank i.e. is going to run with bank 0 , then we need to save more registers :-) */ - if (!SPEC_BANK (sym->etype)) + if (!FUNC_REGBANK (sym->type)) { /* if this function does not call any other function then we can be economical and save only those registers that are used */ - if (!sym->hasFcall) + if (!IFFUNC_HASFCALL(sym->type)) { int i; @@ -2914,6 +2915,7 @@ genEndFunction (iCode * ic) * Restore any register banks saved by genFunction * in reverse order. */ + // jwk: this needs a closer look unsigned savedBanks = SPEC_ISR_SAVED_BANKS(currFunc->etype); int ix; @@ -2955,7 +2957,7 @@ genEndFunction (iCode * ic) if (!inExcludeList ("acc")) emitcode ("pop", "acc"); - if (SPEC_CRTCL (sym->etype)) + if (IFFUNC_ISCRITICAL (sym->type)) emitcode ("setb", "ea"); /* if debug then send end of function */ @@ -2975,10 +2977,10 @@ genEndFunction (iCode * ic) } else { - if (SPEC_CRTCL (sym->etype)) + if (IFFUNC_ISCRITICAL (sym->type)) emitcode ("setb", "ea"); - if (sym->calleeSave) + if (IFFUNC_CALLEESAVES(sym->type)) { int i; diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 630e1192..82556db7 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -1456,8 +1456,8 @@ saveRegisters (iCode * lic) /* if the registers have been saved already or don't need to be then do nothing */ - if (ic->regsSaved || (OP_SYMBOL (IC_LEFT (ic))->calleeSave) || - SPEC_NAKED(OP_SYM_ETYPE(IC_LEFT (ic)))) + if (ic->regsSaved || IFFUNC_CALLEESAVES(OP_SYMBOL(IC_LEFT(ic))->type) || + IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT (ic)))) return; /* find the registers in use at this time @@ -1846,7 +1846,7 @@ saveRBank (int bank, iCode * ic, bool pushPsw) static void genCall (iCode * ic) { - sym_link *detype; + sym_link *dtype; bool restoreBank = FALSE; bool swapBanks = FALSE; @@ -1880,17 +1880,17 @@ genCall (iCode * ic) /* 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 */ - detype = getSpec (operandType (IC_LEFT (ic))); - if (detype && !SPEC_NAKED(detype) && - (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) && - IS_ISR (currFunc->etype)) + dtype = operandType (IC_LEFT (ic)); + if (dtype && !IFFUNC_ISNAKED(dtype) && + (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) && + IFFUNC_ISISR (currFunc->type)) { if (!ic->bankSaved) { /* This is unexpected; the bank should have been saved in * genFunction. */ - saveRBank (SPEC_BANK (detype), ic, FALSE); + saveRBank (FUNC_REGBANK (dtype), ic, FALSE); restoreBank = TRUE; } swapBanks = TRUE; @@ -1903,7 +1903,7 @@ genCall (iCode * ic) if (swapBanks) { emitcode ("mov", "psw,#0x%02x", - ((SPEC_BANK(detype)) << 3) & 0xff); + ((FUNC_REGBANK(dtype)) << 3) & 0xff); } /* make the call */ @@ -1914,7 +1914,7 @@ genCall (iCode * ic) if (swapBanks) { emitcode ("mov", "psw,#0x%02x", - ((SPEC_BANK(currFunc->etype)) << 3) & 0xff); + ((FUNC_REGBANK(currFunc->type)) << 3) & 0xff); } /* if we need assign a result value */ @@ -1950,12 +1950,12 @@ genCall (iCode * ic) } /* if we hade saved some registers then unsave them */ - if (ic->regsSaved && !(OP_SYMBOL (IC_LEFT (ic))->calleeSave)) + if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype)) unsaveRegisters (ic); /* if register bank was saved then pop them */ if (restoreBank) - unsaveRBank (SPEC_BANK (detype), ic, FALSE); + unsaveRBank (FUNC_REGBANK (dtype), ic, FALSE); } /*-----------------------------------------------------------------*/ @@ -1964,7 +1964,7 @@ genCall (iCode * ic) static void genPcall (iCode * ic) { - sym_link *detype; + sym_link *dtype; symbol *rlbl = newiTempLabel (NULL); @@ -1975,11 +1975,11 @@ genPcall (iCode * ic) /* if we are calling a function that is not using the same register bank then we need to save the destination registers on the stack */ - detype = getSpec (operandType (IC_LEFT (ic))); - if (detype && - IS_ISR (currFunc->etype) && - (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype))) - saveRBank (SPEC_BANK (detype), ic, TRUE); + dtype = operandType (IC_LEFT (ic)); + if (dtype && + IFFUNC_ISISR (currFunc->type) && + (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype))) + saveRBank (FUNC_REGBANK (dtype), ic, TRUE); /* push the return address on to the stack */ @@ -2059,16 +2059,15 @@ genPcall (iCode * ic) } /* if register bank was saved then unsave them */ - if (detype && - (SPEC_BANK (currFunc->etype) != - SPEC_BANK (detype))) - unsaveRBank (SPEC_BANK (detype), ic, TRUE); + if (dtype && + (FUNC_REGBANK (currFunc->type) != + FUNC_REGBANK (dtype))) + unsaveRBank (FUNC_REGBANK (dtype), ic, TRUE); /* if we hade saved some registers then unsave them */ if (ic->regsSaved) unsaveRegisters (ic); - } /*-----------------------------------------------------------------*/ @@ -2124,7 +2123,7 @@ static void genFunction (iCode * ic) { symbol *sym; - sym_link *fetype; + sym_link *ftype; bool switchedPSW = FALSE; _G.nRegsSaved = 0; @@ -2134,25 +2133,25 @@ genFunction (iCode * ic) emitcode (";", "-----------------------------------------"); emitcode ("", "%s:", sym->rname); - fetype = getSpec (operandType (IC_LEFT (ic))); + ftype = operandType (IC_LEFT (ic)); - if (SPEC_NAKED(fetype)) + if (IFFUNC_ISNAKED(ftype)) { emitcode(";", "naked function: no prologue."); return; } /* if critical function then turn interrupts off */ - if (SPEC_CRTCL (fetype)) + if (IFFUNC_ISCRITICAL (ftype)) emitcode ("clr", "ea"); /* here we need to generate the equates for the register bank if required */ - if (SPEC_BANK (fetype) != rbank) + if (FUNC_REGBANK (ftype) != rbank) { int i; - rbank = SPEC_BANK (fetype); + rbank = FUNC_REGBANK (ftype); for (i = 0; i < mcs51_nRegs; i++) { if (strcmp (regs8051[i].base, "0") == 0) @@ -2169,7 +2168,7 @@ genFunction (iCode * ic) /* if this is an interrupt service routine then save acc, b, dpl, dph */ - if (IS_ISR (sym->etype)) + if (IFFUNC_ISISR (sym->type)) { if (!inExcludeList ("acc")) @@ -2183,13 +2182,13 @@ genFunction (iCode * ic) /* if this isr has no bank i.e. is going to run with bank 0 , then we need to save more registers :-) */ - if (!SPEC_BANK (sym->etype)) + if (!FUNC_REGBANK (sym->type)) { /* if this function does not call any other function then we can be economical and save only those registers that are used */ - if (!sym->hasFcall) + if (!IFFUNC_HASFCALL(sym->type)) { int i; @@ -2226,7 +2225,7 @@ genFunction (iCode * ic) */ unsigned long banksToSave = 0; - if (sym->hasFcall) + if (IFFUNC_HASFCALL(sym->type)) { #define MAX_REGISTER_BANKS 4 @@ -2244,20 +2243,20 @@ genFunction (iCode * ic) if (i->op == CALL) { - sym_link *detype; + sym_link *dtype; - detype = getSpec(operandType (IC_LEFT(i))); - if (detype - && SPEC_BANK(detype) != SPEC_BANK(sym->etype)) + dtype = operandType (IC_LEFT(i)); + if (dtype + && FUNC_REGBANK(dtype) != FUNC_REGBANK(sym->type)) { /* Mark this bank for saving. */ - if (SPEC_BANK(detype) >= MAX_REGISTER_BANKS) + if (FUNC_REGBANK(dtype) >= MAX_REGISTER_BANKS) { - werror(E_NO_SUCH_BANK, SPEC_BANK(detype)); + werror(E_NO_SUCH_BANK, FUNC_REGBANK(dtype)); } else { - banksToSave |= (1 << SPEC_BANK(detype)); + banksToSave |= (1 << FUNC_REGBANK(dtype)); } /* And note that we don't need to do it in @@ -2289,7 +2288,7 @@ genFunction (iCode * ic) */ emitcode ("push", "psw"); emitcode ("mov", "psw,#0x%02x", - (SPEC_BANK (sym->etype) << 3) & 0x00ff); + (FUNC_REGBANK (sym->type) << 3) & 0x00ff); switchedPSW = TRUE; } @@ -2301,6 +2300,7 @@ genFunction (iCode * ic) } } } + // jwk: this needs a closer look SPEC_ISR_SAVED_BANKS(currFunc->etype) = banksToSave; } } @@ -2308,7 +2308,7 @@ genFunction (iCode * ic) { /* if callee-save to be used for this function then save the registers being used in this function */ - if (sym->calleeSave) + if (IFFUNC_CALLEESAVES(sym->type)) { int i; @@ -2330,14 +2330,14 @@ genFunction (iCode * ic) } /* set the register bank to the desired value */ - if ((SPEC_BANK (sym->etype) || IS_ISR (sym->etype)) + if ((FUNC_REGBANK (sym->type) || IFFUNC_ISISR (sym->type)) && !switchedPSW) { emitcode ("push", "psw"); - emitcode ("mov", "psw,#0x%02x", (SPEC_BANK (sym->etype) << 3) & 0x00ff); + emitcode ("mov", "psw,#0x%02x", (FUNC_REGBANK (sym->type) << 3) & 0x00ff); } - if (IS_RENT (sym->etype) || options.stackAuto) + if (IFFUNC_ISREENT (sym->type) || options.stackAuto) { if (options.useXstack) @@ -2394,13 +2394,13 @@ genEndFunction (iCode * ic) { symbol *sym = OP_SYMBOL (IC_LEFT (ic)); - if (SPEC_NAKED(sym->etype)) + if (IFFUNC_ISNAKED(sym->type)) { emitcode(";", "naked function: no epilogue."); return; } - if (IS_RENT (sym->etype) || options.stackAuto) + if (IFFUNC_ISREENT (sym->type) || options.stackAuto) { emitcode ("mov", "%s,_bp", spname); } @@ -2416,7 +2416,7 @@ genEndFunction (iCode * ic) } - if ((IS_RENT (sym->etype) || options.stackAuto)) + if ((IFFUNC_ISREENT (sym->type) || options.stackAuto)) { if (options.useXstack) { @@ -2432,9 +2432,9 @@ genEndFunction (iCode * ic) } /* restore the register bank */ - if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype)) + if (FUNC_REGBANK (sym->type) || IFFUNC_ISISR (sym->type)) { - if (!SPEC_BANK (sym->etype) || !IS_ISR (sym->etype) + if (!FUNC_REGBANK (sym->type) || !IFFUNC_ISISR (sym->type) || !options.useXstack) { /* Special case of ISR using non-zero bank with useXstack @@ -2444,19 +2444,19 @@ genEndFunction (iCode * ic) } } - if (IS_ISR (sym->etype)) + if (IFFUNC_ISISR (sym->type)) { /* now we need to restore the registers */ /* if this isr has no bank i.e. is going to run with bank 0 , then we need to save more registers :-) */ - if (!SPEC_BANK (sym->etype)) + if (!FUNC_REGBANK (sym->type)) { /* if this function does not call any other function then we can be economical and save only those registers that are used */ - if (!sym->hasFcall) + if (!IFFUNC_HASFCALL(sym->type)) { int i; @@ -2488,6 +2488,7 @@ genEndFunction (iCode * ic) * Restore any register banks saved by genFunction * in reverse order. */ + // jwk: this needs a closer look unsigned savedBanks = SPEC_ISR_SAVED_BANKS(currFunc->etype); int ix; @@ -2517,7 +2518,7 @@ genEndFunction (iCode * ic) if (!inExcludeList ("acc")) emitcode ("pop", "acc"); - if (SPEC_CRTCL (sym->etype)) + if (IFFUNC_ISCRITICAL (sym->type)) emitcode ("setb", "ea"); /* if debug then send end of function */ @@ -2539,10 +2540,10 @@ genEndFunction (iCode * ic) } else { - if (SPEC_CRTCL (sym->etype)) + if (IFFUNC_ISCRITICAL (sym->type)) emitcode ("setb", "ea"); - if (sym->calleeSave) + if (IFFUNC_CALLEESAVES(sym->type)) { int i; diff --git a/src/pic/gen.c b/src/pic/gen.c index 1986eea6..303a407d 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -1773,7 +1773,7 @@ static void saveRegisters(iCode *lic) int i; iCode *ic; bitVect *rsave; - sym_link *detype; + sym_link *dtype; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); /* look for call */ @@ -1788,7 +1788,7 @@ static void saveRegisters(iCode *lic) /* if the registers have been saved already then do nothing */ - if (ic->regsSaved || (OP_SYMBOL(IC_LEFT(ic))->calleeSave)) + if (ic->regsSaved || IFFUNC_CALLEESAVES(OP_SYMBOL(IC_LEFT(ic))->type)) return ; /* find the registers in use at this time @@ -1820,13 +1820,13 @@ static void saveRegisters(iCode *lic) pic14_emitcode("push","%s",pic14_regWithIdx(i)->dname); } - detype = getSpec(operandType(IC_LEFT(ic))); - if (detype && - (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) && - IS_ISR(currFunc->etype) && + dtype = operandType(IC_LEFT(ic)); + if (dtype && + (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)) && + IFFUNC_ISISR(currFunc->type) && !ic->bankSaved) - saverbank(SPEC_BANK(detype),ic,TRUE); + saverbank(FUNC_REGBANK(dtype),ic,TRUE); } /*-----------------------------------------------------------------*/ @@ -2128,7 +2128,7 @@ static void saverbank (int bank, iCode *ic, bool pushPsw) /*-----------------------------------------------------------------*/ static void genCall (iCode *ic) { - sym_link *detype; + sym_link *dtype; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); @@ -2139,13 +2139,13 @@ static void genCall (iCode *ic) /* if we are calling a function that is not using the same register bank then we need to save the destination registers on the stack */ - detype = getSpec(operandType(IC_LEFT(ic))); - if (detype && - (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype)) && - IS_ISR(currFunc->etype) && + dtype = operandType(IC_LEFT(ic)); + if (dtype && + (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)) && + IFFUNC_ISISR(currFunc->type) && !ic->bankSaved) - saverbank(SPEC_BANK(detype),ic,TRUE); + saverbank(FUNC_REGBANK(dtype),ic,TRUE); /* if send set is not empty the assign */ if (_G.sendSet) { @@ -2222,10 +2222,10 @@ static void genCall (iCode *ic) /* if register bank was saved then pop them */ if (ic->bankSaved) - unsaverbank(SPEC_BANK(detype),ic,TRUE); + unsaverbank(FUNC_REGBANK(dtype),ic,TRUE); /* if we hade saved some registers then unsave them */ - if (ic->regsSaved && !(OP_SYMBOL(IC_LEFT(ic))->calleeSave)) + if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype)) unsaveRegisters (ic); @@ -2236,7 +2236,7 @@ static void genCall (iCode *ic) /*-----------------------------------------------------------------*/ static void genPcall (iCode *ic) { - sym_link *detype; + sym_link *dtype; symbol *rlbl = newiTempLabel(NULL); @@ -2248,11 +2248,11 @@ static void genPcall (iCode *ic) /* if we are calling a function that is not using the same register bank then we need to save the destination registers on the stack */ - detype = getSpec(operandType(IC_LEFT(ic))); - if (detype && - IS_ISR(currFunc->etype) && - (SPEC_BANK(currFunc->etype) != SPEC_BANK(detype))) - saverbank(SPEC_BANK(detype),ic,TRUE); + dtype = operandType(IC_LEFT(ic)); + if (dtype && + IFFUNC_ISISR(currFunc->type) && + (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype))) + saverbank(FUNC_REGBANK(dtype),ic,TRUE); /* push the return address on to the stack */ @@ -2331,10 +2331,9 @@ static void genPcall (iCode *ic) } /* if register bank was saved then unsave them */ - if (detype && - (SPEC_BANK(currFunc->etype) != - SPEC_BANK(detype))) - unsaverbank(SPEC_BANK(detype),ic,TRUE); + if (dtype && + (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype))) + unsaverbank(FUNC_REGBANK(dtype),ic,TRUE); /* if we hade saved some registers then unsave them */ @@ -2393,7 +2392,7 @@ static bool inExcludeList(char *s) static void genFunction (iCode *ic) { symbol *sym; - sym_link *fetype; + sym_link *ftype; DEBUGpic14_emitcode ("; ***","%s %d previous max_key=%d ",__FUNCTION__,__LINE__,max_key); @@ -2409,19 +2408,19 @@ static void genFunction (iCode *ic) pic14_emitcode("","%s:",sym->rname); addpCode2pBlock(pb,newpCodeFunction(NULL,sym->rname)); - fetype = getSpec(operandType(IC_LEFT(ic))); + ftype = operandType(IC_LEFT(ic)); /* if critical function then turn interrupts off */ - if (SPEC_CRTCL(fetype)) + if (IFFUNC_ISCRITICAL(ftype)) pic14_emitcode("clr","ea"); /* here we need to generate the equates for the register bank if required */ #if 0 - if (SPEC_BANK(fetype) != rbank) { + if (FUNC_REGBANK(ftype) != rbank) { int i ; - rbank = SPEC_BANK(fetype); + rbank = FUNC_REGBANK(ftype); for ( i = 0 ; i < pic14_nRegs ; i++ ) { if (strcmp(regspic14[i].base,"0") == 0) pic14_emitcode("","%s = 0x%02x", @@ -2438,7 +2437,7 @@ static void genFunction (iCode *ic) /* if this is an interrupt service routine then save acc, b, dpl, dph */ - if (IS_ISR(sym->etype)) { + if (IFFUNC_ISISR(sym->type)) { if (!inExcludeList("acc")) pic14_emitcode ("push","acc"); @@ -2465,12 +2464,12 @@ static void genFunction (iCode *ic) /* if this isr has no bank i.e. is going to run with bank 0 , then we need to save more registers :-) */ - if (!SPEC_BANK(sym->etype)) { + if (!FUNC_REGBANK(sym->type)) { /* if this function does not call any other function then we can be economical and save only those registers that are used */ - if (! sym->hasFcall) { + if (! IFFUNC_HASFCALL(sym->type)) { int i; /* if any registers used */ @@ -2493,7 +2492,7 @@ static void genFunction (iCode *ic) } else { /* if callee-save to be used for this function then save the registers being used in this function */ - if (sym->calleeSave) { + if (IFFUNC_CALLEESAVES(sym->type)) { int i; /* if any registers used */ @@ -2511,12 +2510,12 @@ static void genFunction (iCode *ic) } /* set the register bank to the desired value */ - if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype)) { + if (FUNC_REGBANK(sym->type) || FUNC_ISISR(sym->type)) { pic14_emitcode("push","psw"); - pic14_emitcode("mov","psw,#0x%02x",(SPEC_BANK(sym->etype) << 3)&0x00ff); + pic14_emitcode("mov","psw,#0x%02x",(FUNC_REGBANK(sym->type) << 3)&0x00ff); } - if (IS_RENT(sym->etype) || options.stackAuto) { + if (IFFUNC_ISREENT(sym->type) || options.stackAuto) { if (options.useXstack) { pic14_emitcode("mov","r0,%s",spname); @@ -2569,7 +2568,7 @@ static void genEndFunction (iCode *ic) DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - if (IS_RENT(sym->etype) || options.stackAuto) + if (IFFUNC_ISREENT(sym->type) || options.stackAuto) { pic14_emitcode ("mov","%s,_bp",spname); } @@ -2584,7 +2583,7 @@ static void genEndFunction (iCode *ic) } - if ((IS_RENT(sym->etype) || options.stackAuto)) { + if ((IFFUNC_ISREENT(sym->type) || options.stackAuto)) { if (options.useXstack) { pic14_emitcode("mov","r0,%s",spname); pic14_emitcode("movx","a,@r0"); @@ -2598,21 +2597,21 @@ static void genEndFunction (iCode *ic) } /* restore the register bank */ - if (SPEC_BANK(sym->etype) || IS_ISR(sym->etype)) + if (FUNC_REGBANK(sym->type) || FUNC_ISISR(sym->type)) pic14_emitcode ("pop","psw"); - if (IS_ISR(sym->etype)) { + if (IFFUNC_ISISR(sym->type)) { /* now we need to restore the registers */ /* if this isr has no bank i.e. is going to run with bank 0 , then we need to save more registers :-) */ - if (!SPEC_BANK(sym->etype)) { + if (!FUNC_REGBANK(sym->type)) { /* if this function does not call any other function then we can be economical and save only those registers that are used */ - if (! sym->hasFcall) { + if (! IFFUNC_HASFCALL(sym->type)) { int i; /* if any registers used */ @@ -2653,7 +2652,7 @@ static void genEndFunction (iCode *ic) if (!inExcludeList("acc")) pic14_emitcode ("pop","acc"); - if (SPEC_CRTCL(sym->etype)) + if (IFFUNC_ISCRITICAL(sym->type)) pic14_emitcode("setb","ea"); /* if debug then send end of function */ @@ -2673,10 +2672,10 @@ static void genEndFunction (iCode *ic) pic14_emitcode ("reti",""); } else { - if (SPEC_CRTCL(sym->etype)) + if (IFFUNC_ISCRITICAL(sym->type)) pic14_emitcode("setb","ea"); - if (sym->calleeSave) { + if (IFFUNC_CALLEESAVES(sym->type)) { int i; /* if any registers used */ diff --git a/src/pic/genarith.c b/src/pic/genarith.c index d919602c..42cf9653 100644 --- a/src/pic/genarith.c +++ b/src/pic/genarith.c @@ -1119,7 +1119,7 @@ void genMinusBits (iCode *ic) /*-----------------------------------------------------------------*/ void genMinus (iCode *ic) { - int size, offset = 0,same; + int size, offset = 0, same=0; unsigned long lit = 0L; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); diff --git a/src/pic/glue.c b/src/pic/glue.c index 81c86b36..ff62132b 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -819,7 +819,7 @@ pic14createInterruptVect (FILE * vFile) } /* if the main is only a prototype ie. no body then do nothing */ - if (!mainf->fbody) + if (!IFFUNC_HASBODY(mainf->type)) { /* if ! compile only then main function should be present */ if (!options.cc_only) @@ -1003,7 +1003,7 @@ picglue () addSetHead(&tmpfileSet,ovrFile); - if (mainf && mainf->fbody) { + if (mainf && IFFUNC_HASBODY(mainf->type)) { pBlock *pb = newpCodeChain(NULL,'X',newpCodeCharP("; Starting pCode block")); addpBlock(pb); @@ -1145,7 +1145,7 @@ picglue () copyFile (asmFile, ovrFile); /* create the stack segment MOF */ - if (mainf && mainf->fbody) { + if (mainf && IFFUNC_HASBODY(mainf->type)) { fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; Stack segment in internal ram \n"); fprintf (asmFile, "%s", iComments2); @@ -1160,7 +1160,7 @@ picglue () copyFile (asmFile, idata->oFile); /* if external stack then reserve space of it */ - if (mainf && mainf->fbody && options.useXstack ) { + if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack ) { fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; external stack \n"); fprintf (asmFile, "%s", iComments2); @@ -1189,7 +1189,7 @@ picglue () fprintf (asmFile, "\tORG 0\n"); /* copy the interrupt vector table */ - if (mainf && mainf->fbody) { + if (mainf && IFFUNC_HASBODY(mainf->type)) { fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; interrupt vector \n"); fprintf (asmFile, "%s", iComments2); @@ -1211,7 +1211,7 @@ picglue () fprintf (asmFile, ";\t.area %s\n", port->mem.post_static_name); fprintf (asmFile, ";\t.area %s\n", port->mem.static_name); - if (mainf && mainf->fbody) { + if (mainf && IFFUNC_HASBODY(mainf->type)) { fprintf (asmFile,"__sdcc_gsinit_startup:\n"); /* if external stack is specified then the higher order byte of the xdatalocation is @@ -1226,7 +1226,7 @@ picglue () } - if (port->general.glue_up_main && mainf && mainf->fbody) + if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) { /* This code is generated in the post-static area. * This area is guaranteed to follow the static area diff --git a/src/z80/gen.c b/src/z80/gen.c index 6719b734..00b01920 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -2241,7 +2241,7 @@ _opUsesPair (operand * op, iCode * ic, PAIR_ID pairId) static void emitCall (iCode * ic, bool ispcall) { - sym_link *detype = getSpec (operandType (IC_LEFT (ic))); + sym_link *dtype = operandType (IC_LEFT (ic)); bitVect *rInUse = bitVectCplAnd (bitVectCopy (ic->rMask), ic->rUsed); @@ -2315,7 +2315,7 @@ emitCall (iCode * ic, bool ispcall) if (ispcall) { - if (IS_BANKEDCALL (detype)) + if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT(getSpec(dtype))) { werror (W_INDIR_BANKED); } @@ -2345,7 +2345,7 @@ emitCall (iCode * ic, bool ispcall) char *name = OP_SYMBOL (IC_LEFT (ic))->rname[0] ? OP_SYMBOL (IC_LEFT (ic))->rname : OP_SYMBOL (IC_LEFT (ic))->name; - if (IS_BANKEDCALL (detype)) + if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT(getSpec(dtype))) { emit2 ("call banked_call"); emit2 ("!dws", name); @@ -2511,14 +2511,14 @@ static void genFunction (iCode * ic) { symbol *sym = OP_SYMBOL (IC_LEFT (ic)); - sym_link *fetype; + sym_link *ftype; #if CALLEE_SAVES bool bcInUse = FALSE; bool deInUse = FALSE; #endif - setArea (IS_NONBANKED (sym->etype)); + setArea (IFFUNC_NONBANKED (sym->type)); /* PENDING: Reset the receive offset as it doesn't seem to get reset anywhere else. @@ -2539,14 +2539,14 @@ genFunction (iCode * ic) emit2 ("!profileenter"); } - fetype = getSpec (operandType (IC_LEFT (ic))); + ftype = operandType (IC_LEFT (ic)); /* if critical function then turn interrupts off */ - if (SPEC_CRTCL (fetype)) + if (IFFUNC_ISCRITICAL (ftype)) emit2 ("!di"); /* if this is an interrupt service routine then save all potentially used registers. */ - if (IS_ISR (sym->etype)) + if (IFFUNC_ISISR (sym->type)) { emit2 ("!pusha"); } @@ -2621,13 +2621,13 @@ genEndFunction (iCode * ic) { symbol *sym = OP_SYMBOL (IC_LEFT (ic)); - if (IS_ISR (sym->etype)) + if (IFFUNC_ISISR (sym->type)) { wassertl (0, "Tried to close an interrupt support function"); } else { - if (SPEC_CRTCL (sym->etype)) + if (IFFUNC_ISCRITICAL (sym->type)) emit2 ("!ei"); /* PENDING: calleeSave */ diff --git a/support/regression/ports/mcs51/timeout.c b/support/regression/ports/mcs51/timeout.c index a768ffe5..e828b9b4 100644 --- a/support/regression/ports/mcs51/timeout.c +++ b/support/regression/ports/mcs51/timeout.c @@ -44,6 +44,9 @@ The child will be killed. */ +#include +#include + #include #include #include