A first attempt for more efficient initialisations
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 11 Sep 2001 15:22:28 +0000 (15:22 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 11 Sep 2001 15:22:28 +0000 (15:22 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1263 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/SDCCglue.c

index b5f72afdc2df0409627387daba8c2f56cfe44fb7..7421c30e0fa34bebcfbd96f6a04fda5b004fdf04 100644 (file)
@@ -892,7 +892,7 @@ createIvalArray (ast * sym, sym_link * type, initList * ilist)
            ast *aSym;
            
            aSym = newNode ('[', sym, newAst_VALUE (valueFromLit ((float) (size++))));
-           aSym = decorateType (resolveSymbols (aSym));
+           //aSym = decorateType (resolveSymbols (aSym));
            rast = createIval (aSym, type->next, iloop, rast);
            iloop = (iloop ? iloop->next : NULL);
            if (!iloop)
@@ -1022,6 +1022,7 @@ createIval (ast * sym, sym_link * type, initList * ilist, ast * wid)
     /* if type is SPECIFIER */
   if (IS_SPEC (type))
     rast = createIvalType (sym, type, ilist);
+  
   if (wid)
     return decorateType (resolveSymbols (newNode (NULLOP, wid, rast)));
   else
@@ -1031,9 +1032,74 @@ createIval (ast * sym, sym_link * type, initList * ilist, ast * wid)
 /*-----------------------------------------------------------------*/
 /* initAggregates - initialises aggregate variables with initv     */
 /*-----------------------------------------------------------------*/
-ast *
-initAggregates (symbol * sym, initList * ival, ast * wid)
-{
+
+/* this has to go */ void printIval (symbol *, sym_link *, initList *, FILE *);
+
+ast * initAggregates (symbol * sym, initList * ival, ast * wid) {
+
+  if (getenv("TRY_THE_NEW_INITIALIZER")) {
+
+    if (!TARGET_IS_MCS51 || !(options.model==MODEL_LARGE)) {
+      fprintf (stderr, "Can't \"TRY_THE_NEW_INITIALIZER\" unless "
+              "with -mmcs51 and --model-large\n");
+      exit(404);
+    }
+
+    if (SPEC_OCLS(sym->type->next)!=xdata) {
+      fprintf (stderr, "Can't \"TRY_THE_NEW_INITALIZER\" unless in xdata\n");
+      exit (405);
+    }
+    
+    if (getSize(sym->type) > 64) { // else it is'n worth it: do it the old way
+      // emit the inital values in cseg, then copy it to where it belongs
+      initList *iLoop;
+      int count, size=getSize(sym->type->next);
+      
+      if (ival->type != INIT_DEEP) {
+       werror (E_INIT_STRUCT, sym->name);
+       return NULL;
+      }
+      
+      tfprintf (code->oFile, "; initial data for %s\n", sym->name);
+      // TODO: this has to be a unique name
+      tfprintf (code->oFile, "_init_%s:", sym->name);
+      
+      for (count=0, iLoop=ival->init.deep; iLoop; iLoop=iLoop->next) {
+       count += size;
+       printIval (sym, sym->type->next, iLoop, code->oFile);
+      }
+      
+      // Now we only have to copy <count> bytes from cseg.
+      // This is VERY -mmcs51 --model-large specific for now, 
+      // in fact we should generate
+      // some icodes here that does the trick. But ok: experimental
+      // Trick: memcpy (sym->name, _init_(sym->name), count)
+      fprintf (statsg->oFile, ";       %s      %d\n", filename, sym->lineDef);
+      fprintf (statsg->oFile, ";       copy initial data from cseg _init_%s to %s\n", 
+              sym->name, sym->name);
+      fprintf (statsg->oFile, "        mov dptr,#_memcpy_PARM_2\n");
+      fprintf (statsg->oFile, "        mov a,#_%s\n", sym->name);
+      fprintf (statsg->oFile, "        movx @dptr,a\n");
+      fprintf (statsg->oFile, "        inc dptr\n");
+      fprintf (statsg->oFile, "        mov a,#(_%s>>8)\n", sym->name);
+      fprintf (statsg->oFile, "        movx @dptr,a\n");
+      fprintf (statsg->oFile, "        inc dptr\n");
+      fprintf (statsg->oFile, "        mov a,#%02x;    from cseg\n", 1);
+      fprintf (statsg->oFile, "        movx @dptr,a\n");
+      fprintf (statsg->oFile, "        mov dptr,#_memcpy_PARM_3\n");
+      fprintf (statsg->oFile, "        mov a,#(%d>>0); number of bytes\n", count);
+      fprintf (statsg->oFile, "        movx @dptr,a\n");
+      fprintf (statsg->oFile, "        inc dptr\n");
+      fprintf (statsg->oFile, "        mov a,#(%d>>8)\n", count);
+      fprintf (statsg->oFile, "        movx @dptr,a\n");
+      fprintf (statsg->oFile, "        mov dptr,#_init_%s\n", sym->name);
+      fprintf (statsg->oFile, "        mov b,#%02x;    only to xseg for now\n", 2);
+      fprintf (statsg->oFile, "        lcall _memcpy\n");
+      
+      return NULL;
+    }
+  }
+  
   return createIval (newAst_VALUE (symbolVal (sym)), sym->type, ival, wid);
 }
 
index 334e140d4149e5f6ffefa2919742e366cce177c2..bb3f4a0168741b367b8f8b4952c4f056bd7862ff 100644 (file)
@@ -245,16 +245,17 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          it is a global variable */
       if (sym->ival && sym->level == 0)
        {
-         if (IS_AGGREGATE (sym->type))
+         if (IS_AGGREGATE (sym->type)) {
            ival = initAggregates (sym, sym->ival, NULL);
-         else
+         } else {
            ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
                     decorateType (resolveSymbols (list2expr (sym->ival))));
+         }
          codeOutFile = statsg->oFile;
          allocInfo = 0;
 
          // set ival's lineno to where the symbol was defined
-         ival->lineno=sym->lineDef;
+         if (ival) ival->lineno=sym->lineDef;
 
          eBBlockFromiCode (iCodeFromAst (ival));
          allocInfo = 1;