Improved version of the experimental new initializer
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 13 Sep 2001 15:04:32 +0000 (15:04 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 13 Sep 2001 15:04:32 +0000 (15:04 +0000)
It should also work now for local's
Remember the environmental var TRY_THE_NEW_INITIALIZER

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1267 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/mcs51/gen.c

index 807ada669eb11710d23c25353b6f2eb81affb094..5607e136faf83037aa25a9fcfdd4da7eda113534 100644 (file)
@@ -1052,7 +1052,7 @@ ast * initAggregates (symbol * sym, initList * ival, ast * wid) {
 
       // copy this symbol
       newSym=copySymbol (sym);
-      SPEC_OCLS(newSym->type->next)=code;
+      SPEC_OCLS(newSym->etype)=code;
       sprintf (newSym->name, "%s_init__", sym->name);
       sprintf (newSym->rname,"%s_init__", sym->rname);
       addSym (SymbolTab, newSym, newSym->name, 0, 0, 1);
@@ -1203,8 +1203,8 @@ processBlockVars (ast * tree, int *stack, int action)
 
       if (action == ALLOCATE)
        {
-         autoInit = gatherAutoInit (tree->values.sym);
          *stack += allocVariables (tree->values.sym);
+         autoInit = gatherAutoInit (tree->values.sym);
 
          /* if there are auto inits then do them */
          if (autoInit)
index 6863646aece3409c80311520566008d7e5d28f3d..a67e54a2e870ddfac7df8a8569db98b160915f26 100644 (file)
@@ -8489,13 +8489,26 @@ void gen51AggregateAssign(iCode *ic) {
   int toSize=getSize(OP_SYMBOL(left)->type);
   int count=toSize;
 
+  if (SPEC_OCLS(OP_SYMBOL(left)->etype)!=xdata ||
+      SPEC_OCLS(OP_SYMBOL(right)->etype)!=code) {
+    // well, this code isn't used yet from anywhere else as for initialising
+    fprintf (stderr, "*** error: %s:%d can only assign aggregates from cseg to xseg for now\n", ic->filename, ic->lineno);
+    exit (457);
+  }
+
   if (fromSize!=toSize) {
-    fprintf (stderr, "*** error aggregates have different size");
-    if (fromSize<toSize)
-      count=fromSize;
+    fprintf (stderr, "*** error: %s:%d aggregates have different size\n",
+            ic->filename, ic->lineno);
+    exit (821);
   }
   
   // memcpy from cseg to xseg
+  // this could be greatly improved here for multiple instances
+  // e.g.:
+  //  mov dptr,#fromName
+  //  mov r0:r1,#toName
+  //  mov r2:r3,#count
+  //  lcall _native_memcpy_cseg_to_xseg
   emitcode (";", "initialize %s", OP_SYMBOL(IC_LEFT(ic))->name);
   emitcode ("mov", "dptr,#_memcpy_PARM_2");
   emitcode ("mov", "a,#%s", fromName);
@@ -8504,7 +8517,7 @@ void gen51AggregateAssign(iCode *ic) {
   emitcode ("mov", "a,#(%s>>8)", fromName);
   emitcode ("movx", "@dptr,a");
   emitcode ("inc", "dptr");
-  emitcode ("mov", "a,#%02x;   from cseg", 2);
+  emitcode ("mov", "a,#%02x;   only from cseg for now", 2);
   emitcode ("movx", "@dptr,a");
   emitcode ("mov", "dptr,#_memcpy_PARM_3");
   emitcode ("mov", "a,#(%d>>0);        number of bytes", count);