Added design, updated url
[fw/sdcc] / src / SDCCast.c
index e26c925e67c4d592466d36844aac1d217210349f..847bc6f5bd256ebcb5d4ab822c2bc7aca9dc94ed 100644 (file)
@@ -27,7 +27,6 @@
 int currLineno  = 0;
 set *astList = NULL ;
 set *operKeyReset = NULL;
-extern char *currFname ;
 ast *staticAutos = NULL;
 int labelKey = 1 ;
 
@@ -50,12 +49,8 @@ char  buffer[1024];
 int noLineno = 0;
 int noAlloc = 0 ;
 symbol *currFunc ;
-extern int fatalError ;
-extern int lineno;
-extern char *filename ;
-extern set *publics;
-extern ast  *createIval  (ast *, link *, initList *, ast *);
-extern ast *createIvalCharPtr (ast *, link *, ast *);
+ast  *createIval  (ast *, sym_link *, initList *, ast *);
+ast *createIvalCharPtr (ast *, sym_link *, ast *);
 ast *optimizeRRCRLC ( ast * );
 ast *optimizeGetHbit(ast *);
 ast *backPatchLabels (ast *,symbol *,symbol *);
@@ -70,6 +65,7 @@ int ptt(ast *tree) {
 /*-----------------------------------------------------------------*/
 /* newAst - creates a fresh node for an expression tree           */
 /*-----------------------------------------------------------------*/
+#if 0
 ast  *newAst (int  type, void *op )
 {
     ast  *ex ;
@@ -90,10 +86,10 @@ ast  *newAst (int  type, void *op )
        ex->opval.val = (value *) op;
        break ;
     case EX_OP     :
-       ex->opval.op   = (int) op ;
+       ex->opval.op   = (long) op ;
        break ;
     case EX_LINK   :
-       ex->opval.lnk  = (link *) op;
+       ex->opval.lnk  = (sym_link *) op;
        break ;
     case EX_STMNT  :
        ex->opval.stmnt= (unsigned) op;
@@ -101,15 +97,60 @@ ast  *newAst (int  type, void *op )
     
     return ex;
 }
+#endif
+
+static ast* newAst_(unsigned type)
+{
+    ast  *ex ;
+    static int oldLineno = 0 ;
+
+    ALLOC(ex,sizeof(ast));    
+    
+    ex->type = type ;          
+    ex->lineno = (noLineno ? oldLineno : yylineno);
+    ex->filename = currFname ;
+    ex->level = NestLevel ;
+    ex->block = currBlockno ;
+    ex->initMode = inInitMode;
+    return ex;
+}
+
+ast* newAst_VALUE(value*val)
+{
+      ast* ex = newAst_(EX_VALUE);
+      ex->opval.val = val;
+      return ex;
+}
+
+ast* newAst_OP(unsigned op)
+{
+      ast*ex = newAst_(EX_OP);
+      ex->opval.op = op;
+      return ex;
+}
+
+ast* newAst_LINK(sym_link*val)
+{
+      ast* ex = newAst_(EX_LINK);
+      ex->opval.lnk = val;
+      return ex;
+}
+
+ast* newAst_STMNT(unsigned val)
+{
+      ast* ex = newAst_(EX_STMNT);
+      ex->opval.stmnt = val;
+      return ex;
+}
 
 /*-----------------------------------------------------------------*/
 /* newNode - creates a new node                                    */
 /*-----------------------------------------------------------------*/
-ast  *newNode ( int op,   ast  *left, ast *right   )
+ast  *newNode ( long op,   ast  *left, ast *right   )
 {
     ast  *ex ;
     
-    ex = newAst (EX_OP,(void *) op) ;
+    ex = newAst_OP(op) ;
     ex->left    = left ;
     ex->right   = right;
         
@@ -128,11 +169,13 @@ ast *newIfxNode (ast *condAst, symbol *trueLabel, symbol *falseLabel)
        
        /* then depending on the expression value */
        if ( floatFromVal(condAst->opval.val) )
-           ifxNode = newNode(GOTO, newAst(EX_VALUE,
-                                          symbolVal (trueLabel )),NULL);
+             ifxNode = newNode(GOTO,
+                               newAst_VALUE(symbolVal(trueLabel)),
+                               NULL);
        else
-           ifxNode = newNode(GOTO, newAst(EX_VALUE,
-                                          symbolVal (falseLabel )),NULL);
+             ifxNode = newNode(GOTO,
+                               newAst_VALUE(symbolVal(falseLabel)),
+                               NULL);
     }
     else {
        ifxNode = newNode(IFX,condAst,NULL);
@@ -414,6 +457,9 @@ int setAstLineno ( ast *tree, int lineno)
     return 0;
 }
 
+#if 0
+/* this functions seems to be superfluous?! kmh */
+
 /*-----------------------------------------------------------------*/
 /* resolveFromTable - will return the symbal table value           */
 /*-----------------------------------------------------------------*/
@@ -439,15 +485,16 @@ value *resolveFromTable (value *val)
 
     return val;
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* funcOfType :- function of type with name                        */
 /*-----------------------------------------------------------------*/
-symbol *funcOfType (char *name, link *type, link *argType, 
+symbol *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);
        
@@ -458,6 +505,7 @@ symbol *funcOfType (char *name, link *type, link *argType,
        args = sym->args = newValue();
 
        while (nArgs--) {
+           argStack += getSize(type);
            args->type = copyLinkChain(argType);
            args->etype = getSpec(args->type);
            if (!nArgs)
@@ -476,6 +524,7 @@ symbol *funcOfType (char *name, link *type, link *argType,
     /* save it */
     addSymChain(sym);
     sym->cdef = 1;
+    sym->argStack = (rent ? argStack : 0);
     allocVariables (sym);
     return sym;
     
@@ -510,7 +559,7 @@ int processParms (ast *func, value *defParm,
                  ast *actParm, 
                  int *parmNumber)
 {
-    link *fetype = func->etype;
+    sym_link *fetype = func->etype;
     
     /* if none of them exist */
     if ( !defParm && !actParm)
@@ -569,22 +618,24 @@ int processParms (ast *func, value *defParm,
        /* now change the current one to a cast */      
        actParm->type = EX_OP ;
        actParm->opval.op = CAST ;
-       actParm->left = newAst(EX_LINK,defParm->type);
+       actParm->left = newAst_LINK(defParm->type);
        actParm->right= pTree ;
        actParm->etype= defParm->etype;
        actParm->ftype= defParm->type;
     }
     
-    actParm->argSym = resolveFromTable(defParm)->sym ;
+/*    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);
+    (*parmNumber)++;
     return 0;
 }
 /*-----------------------------------------------------------------*/
 /* createIvalType - generates ival for basic types                 */
 /*-----------------------------------------------------------------*/
-ast *createIvalType ( ast *sym,link  *type, initList *ilist)
+ast *createIvalType ( ast *sym,sym_link  *type, initList *ilist)
 {
     ast *iExpr;
 
@@ -593,13 +644,13 @@ ast *createIvalType ( ast *sym,link  *type, initList *ilist)
        ilist =  ilist->init.deep  ;
     
     iExpr = decorateType(resolveSymbols(list2expr(ilist)));
-    return newNode('=',sym,iExpr);
+    return decorateType(newNode('=',sym,iExpr));
 }
 
 /*-----------------------------------------------------------------*/
 /* createIvalStruct - generates initial value for structures       */
 /*-----------------------------------------------------------------*/
-ast *createIvalStruct (ast *sym,link *type,initList *ilist)
+ast *createIvalStruct (ast *sym,sym_link *type,initList *ilist)
 {
     ast *rast = NULL ;
     symbol   *sflds  ;
@@ -620,9 +671,9 @@ ast *createIvalStruct (ast *sym,link *type,initList *ilist)
        if (!iloop)
            break;
        sflds->implicit = 1;
-       lAst = decorateType(resolveSymbols(newNode('.',sym,
-                                                  newAst(EX_VALUE,symbolVal(sflds)))));
-       rast = createIval (lAst, sflds->type, iloop,rast);
+       lAst = newNode(PTR_OP,newNode('&',sym,NULL),newAst_VALUE(symbolVal(sflds)));
+       lAst = decorateType(resolveSymbols(lAst));
+       rast = decorateType(resolveSymbols(createIval (lAst, sflds->type, iloop,rast)));
     }
     return rast ;
 }
@@ -631,7 +682,7 @@ ast *createIvalStruct (ast *sym,link *type,initList *ilist)
 /*-----------------------------------------------------------------*/
 /* createIvalArray - generates code for array initialization       */
 /*-----------------------------------------------------------------*/
-ast *createIvalArray (ast  *sym, link *type, initList *ilist)
+ast *createIvalArray (ast  *sym, sym_link *type, initList *ilist)
 {
     ast *rast = NULL;
     initList *iloop ;
@@ -645,7 +696,7 @@ ast *createIvalArray (ast  *sym, link *type, initList *ilist)
                                       type,
                                       decorateType(resolveSymbols(list2expr(ilist))))))
            
-           return rast;
+           return decorateType(resolveSymbols(rast));
     
     /* not the special case             */
     if (ilist->type != INIT_DEEP) {
@@ -660,7 +711,7 @@ ast *createIvalArray (ast  *sym, link *type, initList *ilist)
        ast *aSym ;
        size++ ;
 
-       aSym = newNode('[',sym,newAst(EX_VALUE,valueFromLit(size-1)));
+       aSym = newNode('[',sym,newAst_VALUE(valueFromLit(size-1)));
        aSym = decorateType(resolveSymbols(aSym));
        rast = createIval (aSym,type->next,iloop,rast)   ;
        iloop = (iloop ? iloop->next : NULL) ;
@@ -681,14 +732,14 @@ ast *createIvalArray (ast  *sym, link *type, initList *ilist)
     if (!DCL_ELEM(type))
        DCL_ELEM(type) = size;
     
-    return rast;
+    return decorateType(resolveSymbols(rast));
 }
 
 
 /*-----------------------------------------------------------------*/
 /* createIvalCharPtr - generates initial values for char pointers  */
 /*-----------------------------------------------------------------*/
-ast *createIvalCharPtr (ast *sym, link *type, ast *iexpr)
+ast *createIvalCharPtr (ast *sym, sym_link *type, ast *iexpr)
 {      
     ast *rast = NULL ;
 
@@ -715,8 +766,8 @@ ast *createIvalCharPtr (ast *sym, link *type, ast *iexpr)
                           rast,
                           newNode('=',
                                   newNode('[', sym,
-                                          newAst(EX_VALUE,valueFromLit(i))),
-                                  newAst(EX_VALUE,valueFromLit(*s))));
+                                          newAst_VALUE(valueFromLit(i))),
+                                  newAst_VALUE(valueFromLit(*s))));
            i++;
            s++;
        }
@@ -724,9 +775,9 @@ ast *createIvalCharPtr (ast *sym, link *type, ast *iexpr)
                           rast,
                           newNode('=',
                                   newNode('[', sym,
-                                          newAst(EX_VALUE,valueFromLit(i))),
-                                  newAst(EX_VALUE,valueFromLit(*s))));
-       return rast;
+                                          newAst_VALUE(valueFromLit(i))),
+                                  newAst_VALUE(valueFromLit(*s))));
+       return decorateType(resolveSymbols(rast));
     }
 
     return NULL ;
@@ -735,7 +786,7 @@ ast *createIvalCharPtr (ast *sym, link *type, ast *iexpr)
 /*-----------------------------------------------------------------*/
 /* createIvalPtr - generates initial value for pointers            */
 /*-----------------------------------------------------------------*/
-ast *createIvalPtr (ast *sym,link *type,initList *ilist)
+ast *createIvalPtr (ast *sym,sym_link *type,initList *ilist)
 {    
     ast *rast;
     ast *iexpr ;
@@ -757,7 +808,7 @@ ast *createIvalPtr (ast *sym,link *type,initList *ilist)
 /*-----------------------------------------------------------------*/
 /* createIval - generates code for initial value                   */
 /*-----------------------------------------------------------------*/
-ast  *createIval  (ast *sym, link *type, initList *ilist, ast *wid)
+ast  *createIval  (ast *sym, sym_link *type, initList *ilist, ast *wid)
 {
     ast *rast = NULL;  
 
@@ -780,17 +831,17 @@ ast  *createIval  (ast *sym, link *type, initList *ilist, ast *wid)
                if (IS_SPEC(type))
                    rast =  createIvalType (sym,type,ilist);
     if ( wid )
-       return newNode(NULLOP,wid,rast);
+       return decorateType(resolveSymbols(newNode(NULLOP,wid,rast)));
     else
-       return rast ;
+       return decorateType(resolveSymbols(rast)) ;
 }
 
 /*-----------------------------------------------------------------*/
-/* initAggregates - initialises aggregate variables with initv */
+/* initAggregates - initialises aggregate variables with initv     */
 /*-----------------------------------------------------------------*/
 ast *initAggregates ( symbol *sym, initList *ival, ast *wid)
 {
-    return createIval (newAst(EX_VALUE,symbolVal(sym)),sym->type,ival,wid);
+    return createIval (newAst_VALUE(symbolVal(sym)),sym->type,ival,wid);
 }
 
 /*-----------------------------------------------------------------*/
@@ -827,7 +878,7 @@ ast *gatherAutoInit ( symbol *autoChain )
            if (IS_AGGREGATE(sym->type))
                work = initAggregates (sym, sym->ival,NULL);
            else
-               work = newNode('=' ,newAst(EX_VALUE,symbolVal(newSym)),
+               work = newNode('=' ,newAst_VALUE(symbolVal(newSym)),
                               list2expr(sym->ival));
            
            setAstLineno(work,sym->lineDef);
@@ -846,7 +897,7 @@ ast *gatherAutoInit ( symbol *autoChain )
            if (IS_AGGREGATE(sym->type)) 
                work = initAggregates (sym,sym->ival,NULL);
            else
-               work = newNode('=' ,newAst(EX_VALUE,symbolVal(sym)),
+               work = newNode('=' ,newAst_VALUE(symbolVal(sym)),
                               list2expr(sym->ival));
            
            setAstLineno (work,sym->lineDef);
@@ -885,7 +936,7 @@ static value *stringToSymbol (value *val)
     sym->block = sym->level = 0;
     sym->isstrlit = 1;
     /* create an ival */
-    sym->ival = newiList(INIT_NODE,newAst(EX_VALUE,val));
+    sym->ival = newiList(INIT_NODE,newAst_VALUE(val));
     if (noAlloc == 0) {
        /* allocate it */
        addSymChain(sym);
@@ -1041,7 +1092,7 @@ bool isLoopCountable (ast *initExpr, ast *condExpr, ast *loopExpr,
                isSymbolEqual (*sym,AST_SYMBOL(condExpr->left->left))) {
                
                *end = newNode('+', condExpr->left->right,
-                              newAst(EX_VALUE,constVal("1")));
+                              newAst_VALUE(constVal("1")));
                break;
            }
            return FALSE ;
@@ -1224,7 +1275,12 @@ bool isConformingBody (ast *pbody, symbol *sym, ast *body)
                return FALSE;
            else
                return isConformingBody(pbody->left,sym,body) ;
-       } 
+       } else {
+           if (astHasSymbol(pbody->left,sym) ||
+               astHasSymbol(pbody->right,sym))
+               return FALSE;
+       }
+
        
        /*------------------------------------------------------------------*/
     case  '|':
@@ -1392,8 +1448,8 @@ static void replLoopSym ( ast *body, symbol *sym)
            
            body->type = EX_OP;
            body->opval.op = '-';
-           body->left = newAst(EX_VALUE,symbolVal(sym));
-           body->right= newAst(EX_VALUE,constVal("1"));
+           body->left = newAst_VALUE(symbolVal(sym));
+           body->right= newAst_VALUE(constVal("1"));
 
        }
            
@@ -1419,34 +1475,31 @@ ast *reverseLoop (ast *loop, symbol *sym, ast *init, ast *end)
                forbody
                <sym> -= 1;
                if (sym) goto for_continue ; 
-               <sym> = end - 1; */
+               <sym> = end */
     
     /* put it together piece by piece */
     rloop = newNode (NULLOP,
-                    createIf(newAst(EX_VALUE,symbolVal(sym)),
+                    createIf(newAst_VALUE(symbolVal(sym)),
                              newNode(GOTO,
-                                     newAst(EX_VALUE,
-                                            symbolVal(AST_FOR(loop,continueLabel))),
+                                     newAst_VALUE(symbolVal(AST_FOR(loop,continueLabel))),
                                      NULL),NULL),
                     newNode('=',
-                            newAst(EX_VALUE,symbolVal(sym)),
-                            newNode('-', end,
-                                    newAst(EX_VALUE,
-                                           constVal("1")))));
+                            newAst_VALUE(symbolVal(sym)),
+                            end));
 
     replLoopSym(loop->left, sym);
 
     rloop = newNode(NULLOP,
                    newNode('=',
-                           newAst(EX_VALUE,symbolVal(sym)),
+                           newAst_VALUE(symbolVal(sym)),
                            newNode('-',end,init)),
                    createLabel(AST_FOR(loop,continueLabel),
                                newNode(NULLOP,
                                        loop->left,
                                        newNode(NULLOP,
                                                newNode(SUB_ASSIGN,
-                                                       newAst(EX_VALUE,symbolVal(sym)),
-                                                       newAst(EX_VALUE,constVal("1"))),
+                                                       newAst_VALUE(symbolVal(sym)),
+                                                       newAst_VALUE(constVal("1"))),
                                                rloop ))));
     
     return decorateType(rloop);
@@ -1461,7 +1514,7 @@ ast *reverseLoop (ast *loop, symbol *sym, ast *init, ast *end)
 ast *decorateType (ast *tree)
 {         
     int parmNumber ;
-    link *p;
+    sym_link *p;
     
     if ( ! tree )
        return tree ;
@@ -1504,6 +1557,10 @@ ast *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 ;
        }
        
@@ -1515,7 +1572,7 @@ ast *decorateType (ast *tree)
                  TTYPE(tree) = TETYPE(tree) =
                    tree->opval.val->type = tree->opval.val->sym->type = 
                    tree->opval.val->etype = tree->opval.val->sym->etype = 
-                   copyLinkChain(intType);
+                   copyLinkChain(INTTYPE);
                }
                else {
                  
@@ -1646,7 +1703,7 @@ ast *decorateType (ast *tree)
     case  INC_OP:  /* incerement operator unary so left only */
     case  DEC_OP:
        {
-           link *ltc = (tree->right ? RTYPE(tree) : LTYPE(tree) );
+           sym_link *ltc = (tree->right ? RTYPE(tree) : LTYPE(tree) );
            COPYTYPE(TTYPE(tree),TETYPE(tree),ltc);
            if (!tree->initMode && IS_CONSTANT(TETYPE(tree)))
                werror(E_CODE_WRITE,"++/--");
@@ -1749,7 +1806,7 @@ ast *decorateType (ast *tree)
        }
        if (SPEC_SCLS(tree->left->etype) == S_CODE) {
            DCL_TYPE(p) = CPOINTER ;
-           DCL_PTR_CONST(p) = 1;
+           DCL_PTR_CONST(p) = port->mem.code_ro;
        }
        else
            if (SPEC_SCLS(tree->left->etype) == S_XDATA)
@@ -1761,7 +1818,10 @@ ast *decorateType (ast *tree)
                    if (SPEC_SCLS(tree->left->etype) == S_IDATA)
                        DCL_TYPE(p) = IPOINTER ;
                    else
-                       DCL_TYPE(p) = POINTER ;
+                       if (SPEC_SCLS(tree->left->etype) == S_EEPROM)
+                           DCL_TYPE(p) = EEPPOINTER ;
+                       else
+                           DCL_TYPE(p) = POINTER ;
 
        if (IS_AST_SYM_VALUE(tree->left)) {
            AST_SYMBOL(tree->left)->addrtaken = 1;
@@ -2208,14 +2268,18 @@ ast *decorateType (ast *tree)
            return tree;
        }
        LRVAL(tree) = RRVAL(tree) = 1;
-       COPYTYPE(TTYPE(tree),TETYPE(tree),LTYPE(tree));
+       if (IS_LITERAL(LTYPE(tree)) && !IS_LITERAL(RTYPE(tree))) {          
+           COPYTYPE(TTYPE(tree),TETYPE(tree),RTYPE(tree));     
+       } else {
+           COPYTYPE(TTYPE(tree),TETYPE(tree),LTYPE(tree));
+       }
        return tree ;
         
        /*------------------------------------------------------------------*/
        /*----------------------------*/
        /*         casting            */
        /*----------------------------*/
-    case CAST   :  /* change the type   */
+    case CAST:  /* change the type   */
        /* cannot cast to an aggregate type */
        if (IS_AGGREGATE(LTYPE(tree))) {
            werror(E_CAST_ILLEGAL);
@@ -2246,7 +2310,7 @@ ast *decorateType (ast *tree)
        /*       logical &&, ||       */
        /*----------------------------*/
     case AND_OP:
-    case OR_OP :
+    case OR_OP:
        /* each must me arithmetic type or be a pointer */
        if (!IS_PTR(LTYPE(tree)) && 
            !IS_ARRAY(LTYPE(tree)) && 
@@ -2600,8 +2664,7 @@ ast *decorateType (ast *tree)
        if (checkType(currFunc->type->next,RTYPE(tree)) < 0 ) {
            tree->right = 
                decorateType(newNode(CAST,
-                                    newAst(EX_LINK,
-                                           copyLinkChain(currFunc->type->next)),
+                                    newAst_LINK(copyLinkChain(currFunc->type->next)),
                                     tree->right));
        }
        
@@ -2689,7 +2752,7 @@ ast *decorateType (ast *tree)
 /*-----------------------------------------------------------------*/
 /* sizeofOp - processes size of operation                          */
 /*-----------------------------------------------------------------*/
-value  *sizeofOp( link  *type)
+value  *sizeofOp( sym_link  *type)
 {
        char buff[10];
 
@@ -2773,14 +2836,20 @@ ast *backPatchLabels (ast *tree, symbol *trueLabel, symbol *falseLabel )
     
     /* change not */
     if (IS_NOT(tree)) {
+       int wasnot = IS_NOT(tree->left);
        tree->left = backPatchLabels (tree->left,falseLabel,trueLabel);
        
        /* if the left is already a IFX */
        if ( ! IS_IFX(tree->left) ) 
            tree->left = newNode (IFX,tree->left,NULL);
        
-       tree->left->trueLabel = falseLabel ;
-       tree->left->falseLabel= trueLabel ;
+       if (wasnot) {
+           tree->left->trueLabel = trueLabel ;
+           tree->left->falseLabel= falseLabel ;
+       } else {
+           tree->left->trueLabel = falseLabel ;
+           tree->left->falseLabel= trueLabel ;
+       }
        return tree->left ;
     }
     
@@ -2842,7 +2911,7 @@ ast  *createLabel  ( symbol  *label,  ast  *stmnt  )
     
     label->islbl = 1;
     label->key = labelKey++ ;
-    rValue =  newNode (LABEL,newAst(EX_VALUE,symbolVal(label)),stmnt);  
+    rValue =  newNode (LABEL,newAst_VALUE(symbolVal(label)),stmnt);  
     rValue->lineno = 0;
     
     return rValue ;
@@ -2975,7 +3044,7 @@ ast *createIf ( ast *condAst, ast *ifBody, ast *elseBody )
     if ( elseBody ) {
        ifBody = newNode(NULLOP,ifBody,
                         newNode(GOTO,
-                                newAst(EX_VALUE,symbolVal(ifEnd)),             
+                                newAst_VALUE(symbolVal(ifEnd)),
                                 NULL));
        /* put the elseLabel on the else body */
        elseBody = createLabel (ifFalse,elseBody);
@@ -3092,7 +3161,7 @@ ast *createFor ( symbol *trueLabel, symbol *continueLabel ,
                           newNode(NULLOP,
                                   loopExpr,
                                   newNode(GOTO,
-                                          newAst(EX_VALUE,symbolVal(condLabel)),
+                                          newAst_VALUE(symbolVal(condLabel)),
                                           NULL)));
     /* now start putting them together */
     forTree = newNode(NULLOP,initExpr,condExpr);
@@ -3135,8 +3204,7 @@ ast *createWhile (symbol *trueLabel, symbol *continueLabel,
     whileBody = newNode(NULLOP,
                        whileBody,
                        newNode(GOTO,
-                               newAst(EX_VALUE,
-                                      symbolVal(continueLabel)),
+                               newAst_VALUE(symbolVal(continueLabel)),
                                createLabel(falseLabel,NULL)));
     
     /* put it all together */
@@ -3354,12 +3422,12 @@ ast  *optimizeCompare ( ast *root )
        case '>' :
        case '<' :
        case NE_OP :
-           optExpr = newAst(EX_VALUE,constVal("0"));
+           optExpr = newAst_VALUE(constVal("0"));
            break;
        case GE_OP :
        case LE_OP :
        case EQ_OP :
-           optExpr = newAst(EX_VALUE,constVal("1"));
+           optExpr = newAst_VALUE(constVal("1"));
            break;
        }
 
@@ -3395,16 +3463,16 @@ ast  *optimizeCompare ( ast *root )
                
            case '<' : /* bit value < 1 means 0 */
            case NE_OP :
-               optExpr = newNode('!',newAst(EX_VALUE,vleft),NULL);
+               optExpr = newNode('!',newAst_VALUE(vleft),NULL);
                break;
                
            case LE_OP : /* bit value <= 1 means no check */
-               optExpr = newAst(EX_VALUE,vright);              
+               optExpr = newAst_VALUE(vright);         
                break;
                
            case GE_OP : /* bit value >= 1 means only check for = */
            case EQ_OP :
-               optExpr = newAst(EX_VALUE,vleft);               
+               optExpr = newAst_VALUE(vleft);          
                break;
            }
        } else { /* literal is zero */
@@ -3416,7 +3484,7 @@ ast  *optimizeCompare ( ast *root )
                
            case '>' : /* bit value > 0 means 1 */
            case NE_OP :
-               optExpr = newAst(EX_VALUE,vleft);            
+               optExpr = newAst_VALUE(vleft);       
                break;
                
            case LE_OP : /* bit value <= 0 means no check */
@@ -3426,7 +3494,7 @@ ast  *optimizeCompare ( ast *root )
                break;
                
            case EQ_OP : /* bit == 0 means ! of bit */
-               optExpr = newNode('!',newAst(EX_VALUE,vleft),NULL);           
+               optExpr = newNode('!',newAst_VALUE(vleft),NULL);              
                break;
            }
        }                      
@@ -3497,7 +3565,7 @@ ast  *createFunction   (symbol  *name,   ast  *body )
     ast  *ex ;
     symbol *csym;
     int stack = 0 ;
-    link *fetype;       
+    sym_link *fetype;       
     iCode *piCode = NULL;
     
     /* if check function return 0 then some problem */
@@ -3517,8 +3585,9 @@ ast  *createFunction   (symbol  *name,   ast  *body )
           we need to add the name to the publics list : this
           actually means we are now compiling the compiler
           support routine */
-       if (name->cdef)
+       if (name->cdef) {
            addSet(&publics,name);
+       }
     }
     else {
        addSymChain(name);
@@ -3562,12 +3631,12 @@ ast  *createFunction   (symbol  *name,   ast  *body )
        name->stack = SPEC_STAK(fetype) = stack;
     
     /* name needs to be mangled */
-    sprintf (name->rname,"_%s",name->name);
+    sprintf (name->rname,"%s%s", port->fun_prefix, name->name);
     
     body = resolveSymbols(body); /* resolve the symbols */
     body = decorateType (body);  /* propagateType & do semantic checks */
     
-    ex = newAst (EX_VALUE, symbolVal(name));    /* create name       */
+    ex = newAst_VALUE(symbolVal(name));    /* create name       */
     ex = newNode (FUNCTION,ex,body);
     ex->values.args = name->args ;
     
@@ -3612,7 +3681,7 @@ ast  *createFunction   (symbol  *name,   ast  *body )
     addSet(&operKeyReset,name);
     applyToSet(operKeyReset,resetParmKey);
        
-    if (options.debug)
+    if (options.debug && !options.nodebug)
        cdbStructBlock(1,cdbFile);
 
     cleanUpLevel(LabelTab,0);