add start of flat24 support
[fw/sdcc] / src / SDCCsymt.c
index 51e3e844520b5e26d682207021777512c12076e7..4717bf10b60664e0e99ea3d0424ed723a9ac5f44 100644 (file)
@@ -499,7 +499,7 @@ void checkTypeSanity(sym_link *etype, char *name) {
 
   // special case for "short"
   if (etype->select.s._short) {
-    SPEC_NOUN(etype) = options.shortisint ? V_INT : V_CHAR;
+    SPEC_NOUN(etype) = options.shortis8bits ? V_CHAR : V_INT;
     etype->select.s._short = 0;
   }
 
@@ -524,10 +524,32 @@ void checkTypeSanity(sym_link *etype, char *name) {
 /*------------------------------------------------------------------*/
 /* mergeSpec - merges two specifiers and returns the new one        */
 /*------------------------------------------------------------------*/
+#define LAST_MINUTE_2_3_0_FIX
 sym_link *
 mergeSpec (sym_link * dest, sym_link * src, char *name)
 {
 
+#ifdef LAST_MINUTE_2_3_0_FIX
+  sym_link *symlink;
+
+  if (!IS_SPEC(dest)) {
+    // This should not happen
+    fprintf (stderr, "*** internal error: can't merge declarators\n");
+  }
+  if (!IS_SPEC(src)) {
+    // here we have a declarator as source, reverse them
+    symlink=src;
+    src=dest;
+    dest=symlink;
+    while (!IS_SPEC(dest)) {
+      // and find the specifier
+      dest=dest->next;
+    }
+  } else {
+    symlink=dest;
+  }
+#endif
+
   if (getenv("DEBUG_mergeSpec")) {
     fprintf (stderr, "mergeSpec: \"%s\"\n", name);
   }
@@ -592,7 +614,11 @@ mergeSpec (sym_link * dest, sym_link * src, char *name)
   if (IS_STRUCT (dest) && SPEC_STRUCT (dest) == NULL)
     SPEC_STRUCT (dest) = SPEC_STRUCT (src);
 
+#ifdef LAST_MINUTE_2_3_0_FIX
+  return symlink;
+#else
   return dest;
+#endif
 }
 
 /*------------------------------------------------------------------*/
@@ -918,48 +944,36 @@ addSymChain (symbol * symHead)
   symbol *sym = symHead;
   symbol *csym = NULL;
 
-
   for (; sym != NULL; sym = sym->next)
     {
       changePointer(sym);
+      checkTypeSanity(sym->etype, sym->name);
 
       /* if already exists in the symbol table then check if
-         the previous was an extern definition if yes then
+         one of them is an extern definition if yes then
          then check if the type match, if the types match then
          delete the current entry and add the new entry      */
       if ((csym = findSymWithLevel (SymbolTab, sym)) &&
-         csym->level == sym->level)
-       {
-
-         /* previous definition extern ? */
-         if (IS_EXTERN (csym->etype))
-           {
-             /* do types match ? */
-             if (compareType (csym->type, sym->type) != 1)
-               /* no then error */
-               werror (E_DUPLICATE, csym->name);
-
-             /* delete current entry */
-             deleteSym (SymbolTab, csym, csym->name);
-             /* add new entry */
-             addSym (SymbolTab, sym, sym->name, sym->level, sym->block, 1);
-           }
-         else                  /* not extern */
-           werror (E_DUPLICATE, sym->name);
+         csym->level == sym->level) {
+       
+       /* one definition extern ? */
+       if (IS_EXTERN (csym->etype) || IS_EXTERN (sym->etype)) {
+         /* do types match ? */
+         if (compareType (csym->type, sym->type) != 1) {
+           /* no then error */
+           werror (E_EXTERN_MISMATCH, csym->name);
+           continue;
+         }
+         /* delete current entry */
+         deleteSym (SymbolTab, csym, csym->name);
+       } else {
+         /* not extern */
+         werror (E_DUPLICATE, sym->name);
          continue;
        }
+      }
 
-      /* check if previously defined */
-      if (csym && csym->level == sym->level)
-       {
-         /* if the previous one was declared as extern */
-         /* then check the type with the current one         */
-         if (IS_EXTERN (csym->etype))
-           {
-             if (compareType (csym->type, sym->type) <= 0)
-               werror (W_EXTERN_MISMATCH, csym->name);
-           }
-       }
+      /* add new entry */
       addSym (SymbolTab, sym, sym->name, sym->level, sym->block, 1);
     }
 }
@@ -2235,22 +2249,21 @@ symbol *__muldiv[3][3][2];
 sym_link *__multypes[3][2];
 /* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */
 symbol *__conv[2][3][2];
+/* Dims: shift left/shift right, BYTE/WORD/DWORD, SIGNED/UNSIGNED */
+symbol *__rlrr[2][3][2];
 
 sym_link *floatType;
 
-static void 
-_makeRegParam (symbol * sym)
+static char *
+_mangleFunctionName(char *in)
 {
-  value *val;
-
-  val = sym->args;             /* loop thru all the arguments   */
-
-  /* reset regparm for the port */
-  (*port->reset_regparms) ();
-  while (val)
+  if (port->getMangledFunctionName) 
     {
-      SPEC_REGPARM (val->etype) = 1;
-      val = val->next;
+      return port->getMangledFunctionName(in);
+    }
+  else
+    {
+      return in;
     }
 }
 
@@ -2272,8 +2285,12 @@ initCSupport ()
   {
     "s", "u"
   };
+  const char *srlrr[] =
+  {
+    "rl", "rr"
+  };
 
-  int bwd, su, muldivmod, tofrom;
+  int bwd, su, muldivmod, tofrom, rlrr;
 
   floatType = newFloatLink ();
 
@@ -2319,12 +2336,12 @@ initCSupport ()
              if (tofrom)
                {
                  sprintf (buffer, "__fs2%s%s", ssu[su], sbwd[bwd]);
-                 __conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
+                 __conv[tofrom][bwd][su] = funcOfType (_mangleFunctionName(buffer), __multypes[bwd][su], floatType, 1, options.float_rent);
                }
              else
                {
                  sprintf (buffer, "__%s%s2fs", ssu[su], sbwd[bwd]);
-                 __conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
+                 __conv[tofrom][bwd][su] = funcOfType (_mangleFunctionName(buffer), floatType, __multypes[bwd][su], 1, options.float_rent);
                }
            }
        }
@@ -2340,10 +2357,24 @@ initCSupport ()
                       smuldivmod[muldivmod],
                       ssu[su],
                       sbwd[bwd]);
-              __muldiv[muldivmod][bwd][su] = funcOfType (buffer, __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
+              __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;
-             if (bwd < port->muldiv.force_reg_param_below)
-               _makeRegParam (__muldiv[muldivmod][bwd][su]);
+           }
+       }
+    }
+
+  for (rlrr = 0; rlrr < 2; rlrr++)
+    {
+      for (bwd = 0; bwd < 3; bwd++)
+       {
+         for (su = 0; su < 2; su++)
+           {
+             sprintf (buffer, "_%s%s%s",
+                      srlrr[rlrr],
+                      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;
            }
        }
     }