* src/SDCCast.c (decorateType): fixed bug 1124787
[fw/sdcc] / src / SDCCast.c
index f8bb4fc1105ecbe7bd4e07d54b7632253addbab1..f872f88c25fcb58d6b34ce0c6a191e919c118639 100644 (file)
@@ -633,6 +633,19 @@ reverseParms (ast * ptree)
   /* top down if we find a nonParm tree then quit */
   if (ptree->type == EX_OP && ptree->opval.op == PARAM && !ptree->reversed)
     {
+      /* The various functions expect the parameter tree to be right heavy. */
+      /* Rotate the tree to be left heavy so that after reversal it is */
+      /* right heavy again. */
+      while ((ttree = ptree->right) && ttree->type == EX_OP &&
+             ttree->opval.op == PARAM)
+        {
+          ptree->right = ttree->right;
+          ttree->right = ttree->left;
+          ttree->left = ptree->left;
+          ptree->left = ttree;
+        }
+    
+      /* Now reverse */
       ttree = ptree->left;
       ptree->left = ptree->right;
       ptree->right = ttree;
@@ -680,11 +693,15 @@ processParms (ast *func,
   /* if the function is being called via a pointer &   */
   /* it has not been defined a reentrant then we cannot */
   /* have parameters                                   */
-  if (func->type != EX_VALUE && !IFFUNC_ISREENT (functype) && !options.stackAuto)
+  /* PIC16 port can... */
+  if (!TARGET_IS_PIC16)
     {
-      werror (W_NONRENT_ARGS);
-      fatalError++;
-      return 1;
+      if (func->type != EX_VALUE && !IFFUNC_ISREENT (functype) && !options.stackAuto)
+        {
+          werror (W_NONRENT_ARGS);
+          fatalError++;
+          return 1;
+        }
     }
 
   /* if defined parameters ended but actual parameters */
@@ -1117,6 +1134,21 @@ gatherAutoInit (symbol * autoChain)
       if (sym->ival)
         resolveIvalSym (sym->ival, sym->type);
 
+#if 1
+      /* if we are PIC16 port,
+       * and this is a static,
+       * and have initial value,
+       * and not S_CODE, don't emit in gs segment,
+       * but allow glue.c:pic16emitRegularMap to put symbol
+       * in idata section */
+      if(TARGET_IS_PIC16 &&
+        IS_STATIC (sym->etype) && sym->ival
+        && SPEC_SCLS(sym->etype) != S_CODE) {
+        SPEC_SCLS (sym->etype) = S_DATA;
+        continue;
+      }
+#endif
+
       /* if this is a static variable & has an */
       /* initial value the code needs to be lifted */
       /* here to the main portion since they can be */
@@ -3901,7 +3933,8 @@ decorateType (ast * tree, RESULT_TYPE resultType)
 
     case ':':
       /* if they don't match we have a problem */
-      if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
+      if ((compareType (LTYPE (tree), RTYPE (tree)) == 0) &&
+          (compareType (RTYPE (tree), LTYPE (tree)) == 0))
         {
           werror (E_TYPE_MISMATCH, "conditional operator", " ");
           goto errorTreeReturn;
@@ -4418,7 +4451,6 @@ createBlock (symbol * decl, ast * body)
   ex = newNode (BLOCK, NULL, body);
   ex->values.sym = decl;
   
-  ex->right = ex->right;///?????
   ex->level++;
   ex->lineno = 0;
   return ex;
@@ -5288,14 +5320,19 @@ createFunction (symbol * name, ast * body)
   currFunc = name;
 
   /* set the stack pointer */
-  /* PENDING: check this for the mcs51 */
-  stackPtr = -port->stack.direction * port->stack.call_overhead;
+  stackPtr  = -port->stack.direction * port->stack.call_overhead;
+  xstackPtr = -port->stack.direction * port->stack.call_overhead;
+
   if (IFFUNC_ISISR (name->type))
     stackPtr -= port->stack.direction * port->stack.isr_overhead;
-  if (IFFUNC_ISREENT (name->type) || options.stackAuto)
-    stackPtr -= port->stack.direction * port->stack.reent_overhead;
 
-  xstackPtr = -port->stack.direction * port->stack.call_overhead;
+  if (IFFUNC_ISREENT (name->type) || options.stackAuto)
+    {
+      if (options.useXstack)
+        xstackPtr -= port->stack.direction * port->stack.reent_overhead;
+      else
+        stackPtr  -= port->stack.direction * port->stack.reent_overhead;
+    }
 
   fetype = getSpec (name->type);        /* get the specifier for the function */
   /* if this is a reentrant function then */