* src/SDCCopt.c (killDeadCode): change iCode type to DUMMY_READ_VOLATILE
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 9 Dec 2003 07:17:29 +0000 (07:17 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 9 Dec 2003 07:17:29 +0000 (07:17 +0000)
instead of deleting the iCode when an operand is volatile
* src/z80/gen.c (genDummyRead),
* src/mcs51/gen.c (genDummyRead),
* src/ds390/gen.c (genDummyRead),
* src/hc08/gen.c (genDummyRead): handle operands in IC_LEFT and/or IC_RIGHT,
not just IC_RIGHT
* src/SDCCicode.c (geniCodeCall): fixed bug #851607
* src/SDCC.y: fixed bug #850420

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

ChangeLog
src/SDCC.y
src/SDCCicode.c
src/SDCCopt.c
src/ds390/gen.c
src/hc08/gen.c
src/mcs51/gen.c
src/z80/gen.c

index 5949c6138d70aae1d2e02b02aaa9bae56ff5499c..19e4fa568f7ed8ea13bb6c312119b2a44fec7f30 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2003-12-08 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       * src/SDCCopt.c (killDeadCode): change iCode type to DUMMY_READ_VOLATILE
+       instead of deleting the iCode when an operand is volatile
+       * src/z80/gen.c (genDummyRead),
+       * src/mcs51/gen.c (genDummyRead),
+       * src/ds390/gen.c (genDummyRead),
+       * src/hc08/gen.c (genDummyRead): handle operands in IC_LEFT and/or IC_RIGHT,
+       not just IC_RIGHT
+       * src/SDCCicode.c (geniCodeCall): fixed bug #851607
+       * src/SDCC.y: fixed bug #850420
+
+2003-12-05 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       Applied z80 i/o port patch from Peter Townson and fixed some operators
+       to better handle operands in A register.
+       * device/include/z180.h
+       * src/SDCC.y
+       * src/SDCCglue.c
+       * src/z80/gen.c
+       * src/z80/gen.h
+       * src/z80/main.c
+       * src/z80/peeph-z80.def
+       * src/z80/peeph.def
+       * src/z80/z80.h
+
 2003-12-03 Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        * src/SDCCsymt.c (addSymChain, compareTypeExact): fixed bug #838241 again
index f4f3f0fb301fdb6d11c90869bbb4d3e516dc50c9..ffbdb32405506b909b800afa85dd120d84ed5e63 100644 (file)
@@ -97,8 +97,8 @@ bool uselessDecl = TRUE;
 %token DUMMY_READ_VOLATILE ENDCRITICAL SWAP
 
 %type <yyint>  Interrupt_storage
-%type <sym> identifier  declarator  declarator2 enumerator_list enumerator
-%type <sym> struct_declarator
+%type <sym> identifier  declarator  declarator2 declarator3 enumerator_list enumerator
+%type <sym> struct_declarator function_declarator function_declarator2
 %type <sym> struct_declarator_list  struct_declaration   struct_declaration_list
 %type <sym> declaration init_declarator_list init_declarator
 %type <sym> declaration_list identifier_list parameter_identifier_list
@@ -161,12 +161,12 @@ external_definition
    ;
 
 function_definition
-   : declarator function_body  {   /* function type not specified */
+   : function_declarator function_body  {   /* function type not specified */
                                    /* assume it to be 'int'       */
                                    addDecl($1,0,newIntLink());
                                   $$ = createFunction($1,$2); 
                                } 
-   | declaration_specifiers declarator function_body  
+   | declaration_specifiers function_declarator function_body  
                                 {   
                                    pointerTypes($2->type,copyLinkChain($1));
                                    addDecl($2,0,$1); 
@@ -227,6 +227,7 @@ function_body
    | declaration_list compound_statement
          {
             werror(E_OLD_STYLE,($1 ? $1->name: "")) ;
+           fprintf(stderr, "case 1\n");
            exit(1);
          }
    ;
@@ -942,26 +943,31 @@ opt_assign_expr
    ;
 
 declarator
-   : declarator2_function_attributes   { $$ = $1; }
-   | pointer declarator2_function_attributes
+   : declarator3                       { $$ = $1 ; } 
+   | pointer declarator3
          {
             addDecl ($2,0,reverseLink($1));
             $$ = $2 ;
          }
    ;
 
-declarator2_function_attributes
-   : declarator2                 { $$ = $1 ; } 
-   | declarator2 function_attribute  { 
-       if ((! $1) || (! IS_FUNC($1->etype)))
+declarator3
+   : declarator2_function_attributes   { $$ = $1 ; }
+   | declarator2                       { $$ = $1 ; }
+   ;
+
+function_declarator
+   : declarator2_function_attributes   { $$ = $1; }
+   | pointer declarator2_function_attributes
          {
-           // function_attribute is only allowed if declarator2 was
-           // an actual function
-           werror(E_FUNC_ATTR);
-           $$=$1;
+            addDecl ($2,0,reverseLink($1));
+            $$ = $2 ;
          }
-       else
-         {
+   ;
+   
+declarator2_function_attributes
+   : function_declarator2                { $$ = $1 ; } 
+   | function_declarator2 function_attribute  { 
            // copy the functionAttributes (not the args and hasVargs !!)
            sym_link *funcType=$1->etype;
            struct value *args=FUNC_ARGS(funcType);
@@ -978,14 +984,13 @@ declarator2_function_attributes
               sizeof($2->funcAttrs));
            
            addDecl ($1,0,$2); 
-         }
    }     
    ;
 
 declarator2
    : identifier
    | '(' declarator ')'     { $$ = $2; }
-   | declarator2 '[' ']'
+   | declarator3 '[' ']'
          {
             sym_link   *p;
 
@@ -994,7 +999,7 @@ declarator2
             DCL_ELEM(p) = 0     ;
             addDecl($1,0,p);
          }
-   | declarator2 '[' constant_expr ']'
+   | declarator3 '[' constant_expr ']'
          {
             sym_link   *p ;
                        value *tval;
@@ -1014,7 +1019,10 @@ declarator2
             }                          
             addDecl($1,0,p);
          }
-   | declarator2 '('  ')'      {  addDecl ($1,FUNCTION,NULL) ;   }
+   ;
+
+function_declarator2
+   : declarator2 '('  ')'      {  addDecl ($1,FUNCTION,NULL) ;   }
    | declarator2 '(' { NestLevel++ ; currBlockno++; } parameter_type_list ')'
          {
           
@@ -1043,13 +1051,13 @@ declarator2
    | declarator2 '(' parameter_identifier_list ')'
          {        
           werror(E_OLD_STYLE,$1->name) ;         
-          
+          fprintf(stderr, "case 2\n");
           /* assume it returns an int */
           $1->type = $1->etype = newIntLink();
           $$ = $1 ;
          }
    ;
-
+   
 pointer
    : unqualified_pointer { $$ = $1 ;}
    | unqualified_pointer type_specifier_list   
index 2672a1ab6812af6dad99c95312aeaadb6c4652d5..53efa92caf1f8eb356e4c80482e908a691aa8b77 100644 (file)
@@ -3066,7 +3066,7 @@ geniCodeCall (operand * left, ast * parms,int lvl)
   if (!IS_FUNC(OP_SYMBOL(left)->type) && 
       !IS_CODEPTR(OP_SYMBOL(left)->type)) {
     werror (E_FUNCTION_EXPECTED);
-    return NULL;
+    return operandFromValue(valueFromLit(0));
   }
 
   /* take care of parameters with side-effecting
index 1861ef2c87f0864b82781fc5a88b1d0926fdfa09..28d069c64efd320520ed570f187c39561f2ee88d 100644 (file)
@@ -763,6 +763,10 @@ killDeadCode (eBBlock ** ebbs, int count)
                   ic->op == ENDCRITICAL)
                continue;
 
+             /* Since both IFX & JUMPTABLE (in SKIP_IC) have been tested for */
+             /* it is now safe to assume IC_LEFT, IC_RIGHT, & IC_RESULT are  */
+             /* valid. */
+
              /* if the result is volatile then continue */
              if (IC_RESULT (ic) && isOperandVolatile (IC_RESULT (ic), FALSE))
                continue;
@@ -815,11 +819,14 @@ killDeadCode (eBBlock ** ebbs, int count)
              /* kill this one if required */
              if (kill)
                {
+                 bool volLeft = IS_SYMOP (IC_LEFT (ic))
+                                && isOperandVolatile (IC_LEFT (ic), FALSE);
+                 bool volRight = IS_SYMOP (IC_RIGHT (ic)) 
+                                 && isOperandVolatile (IC_RIGHT (ic), FALSE);
+
                  change = 1;
                  gchange++;
-                 /* eliminate this */
-                 remiCodeFromeBBlock (ebbs[i], ic);
-
+                 
                  /* now delete from defUseSet */
                  deleteItemIf (&ebbs[i]->outExprs, ifDiCodeIsX, ic);
                  bitVectUnSetBit (ebbs[i]->outDefs, ic->key);
@@ -827,12 +834,33 @@ killDeadCode (eBBlock ** ebbs, int count)
                  /* and defset of the block */
                  bitVectUnSetBit (ebbs[i]->defSet, ic->key);
 
-                 /* for the left & right remove the usage */
-                 if (IS_SYMOP (IC_LEFT (ic)))
-                   bitVectUnSetBit (OP_USES (IC_LEFT (ic)), ic->key);
+                 /* delete the result */
+                 IC_RESULT (ic) = NULL;
+                 
+                 if (volLeft || volRight)
+                   {
+                     /* something is volatile, so keep the iCode */
+                     /* and change the operator instead */
+                     ic->op = DUMMY_READ_VOLATILE;
+
+                     /* keep only the volatile operands */      
+                     if (!volLeft)
+                       IC_LEFT (ic) = NULL;
+                     if (!volRight)
+                       IC_RIGHT (ic) = NULL;
+                   }
+                 else
+                   {
+                     /* nothing is volatile, eliminate the iCode */
+                     remiCodeFromeBBlock (ebbs[i], ic);
 
-                 if (IS_SYMOP (IC_RIGHT (ic)))
-                   bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
+                     /* for the left & right remove the usage */
+                     if (IS_SYMOP (IC_LEFT (ic)))
+                       bitVectUnSetBit (OP_USES (IC_LEFT (ic)), ic->key);
+
+                     if (IS_SYMOP (IC_RIGHT (ic)))
+                       bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
+                   }
                }
 
            }                   /* end of all instructions */
index b75d20b30d1ba02b288d08a601eb60d6b8f3a1b5..8c570d0ca2e02c4352aedfaa3935c8bfdf03bd0e 100644 (file)
@@ -12714,34 +12714,59 @@ static void genSystemGetCurrentID(iCode *ic,int nparms, operand **parms,char *na
 static void
 genDummyRead (iCode * ic)
 {
-  operand *right;
+  operand *op;
   int size, offset;
 
   D(emitcode(";     genDummyRead",""));
 
-  right = IC_RIGHT (ic);
+  op = IC_RIGHT (ic);
+  if (op && IS_SYMOP (op))
+    {
+      aopOp (op, ic, FALSE, FALSE);
 
-  aopOp (right, ic, FALSE, FALSE);
+      /* if the result is a bit */
+      if (AOP_TYPE (op) == AOP_CRY)
+        emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+      else
+       {
+         /* bit variables done */
+         /* general case */
+         size = AOP_SIZE (op);
+         offset = 0;
+         while (size--)
+         {
+           MOVA (aopGet (AOP (op), offset, FALSE, FALSE, FALSE));
+           offset++;
+         }
+       }
 
-  /* if the result is a bit */
-  if (AOP_TYPE (right) == AOP_CRY)
-    {
-      emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
-      goto release;
+      freeAsmop (op, NULL, ic, TRUE);
     }
 
-  /* bit variables done */
-  /* general case */
-  size = AOP_SIZE (right);
-  offset = 0;
-  while (size--)
+  op = IC_LEFT (ic);
+  if (op && IS_SYMOP (op))
     {
-      MOVA (aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
-      offset++;
-    }
+      aopOp (op, ic, FALSE, FALSE);
 
-release:
-  freeAsmop (right, NULL, ic, TRUE);
+      /* if the result is a bit */
+      if (AOP_TYPE (op) == AOP_CRY)
+        emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+      else
+       {
+         /* bit variables done */
+         /* general case */
+         size = AOP_SIZE (op);
+         offset = 0;
+         while (size--)
+         {
+           MOVA (aopGet (AOP (op), offset, FALSE, FALSE, FALSE));
+           offset++;
+         }
+       }
+
+      freeAsmop (op, NULL, ic, TRUE);
+    }
+    
 }
 
 /*-----------------------------------------------------------------*/
index 9c94f3559b73891c3037ce99b0dc5e295720476e..f64453c418ace6509c5b72fa4135b56d6a11edc7 100644 (file)
@@ -7305,28 +7305,47 @@ genReceive (iCode * ic)
 static void
 genDummyRead (iCode * ic)
 {
-  operand *right;
+  operand *op;
   int size, offset;
 
   D(emitcode(";     genDummyRead",""));
 
-  right = IC_RIGHT (ic);
+  op = IC_RIGHT (ic);
+  if (op && IS_SYMOP (op))
+    {
 
-  aopOp (right, ic, FALSE);
+      aopOp (op, ic, FALSE);
 
-  /* bit variables done */
-  /* general case */
-  size = AOP_SIZE (right);
-  offset = 0;
+      size = AOP_SIZE (op);
+      offset = 0;
 
-  while (size--)
+      while (size--)
+        {
+          loadRegFromAop (hc08_reg_a, AOP (op), offset);
+          hc08_freeReg (hc08_reg_a);
+          offset++;
+        }
+
+      freeAsmop (op, NULL, ic, TRUE);
+   }
+  op = IC_LEFT (ic);
+  if (op && IS_SYMOP (op))
     {
-      loadRegFromAop (hc08_reg_a, AOP (right), offset);
-      hc08_freeReg (hc08_reg_a);
-      offset++;
-    }
 
-  freeAsmop (right, NULL, ic, TRUE);
+      aopOp (op, ic, FALSE);
+
+      size = AOP_SIZE (op);
+      offset = 0;
+
+      while (size--)
+        {
+          loadRegFromAop (hc08_reg_a, AOP (op), offset);
+          hc08_freeReg (hc08_reg_a);
+          offset++;
+        }
+
+      freeAsmop (op, NULL, ic, TRUE);
+   }
 }
 
 /*-----------------------------------------------------------------*/
index 83790a8528820978ebda6fd0b5fc6b4101a3a0fc..5927c7a3ce2e05d666e0561293b527632edf1fb3 100644 (file)
@@ -9082,34 +9082,58 @@ genReceive (iCode * ic)
 static void
 genDummyRead (iCode * ic)
 {
-  operand *right;
+  operand *op;
   int size, offset;
 
   D(emitcode(";     genDummyRead",""));
 
-  right = IC_RIGHT (ic);
+  op = IC_RIGHT (ic);
+  if (op && IS_SYMOP (op))
+    {
+      aopOp (op, ic, FALSE);
 
-  aopOp (right, ic, FALSE);
+      /* if the result is a bit */
+      if (AOP_TYPE (op) == AOP_CRY)
+        emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+      else
+       {
+         /* bit variables done */
+         /* general case */
+         size = AOP_SIZE (op);
+         offset = 0;
+         while (size--)
+         {
+           MOVA (aopGet (AOP (op), offset, FALSE, FALSE));
+           offset++;
+         }
+       }
 
-  /* if the result is a bit */
-  if (AOP_TYPE (right) == AOP_CRY)
-    {
-      emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
-      goto release;
+      freeAsmop (op, NULL, ic, TRUE);
     }
 
-  /* bit variables done */
-  /* general case */
-  size = AOP_SIZE (right);
-  offset = 0;
-  while (size--)
+  op = IC_LEFT (ic);
+  if (op && IS_SYMOP (op))
     {
-      MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
-      offset++;
-    }
+      aopOp (op, ic, FALSE);
 
-release:
-  freeAsmop (right, NULL, ic, TRUE);
+      /* if the result is a bit */
+      if (AOP_TYPE (op) == AOP_CRY)
+        emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+      else
+       {
+         /* bit variables done */
+         /* general case */
+         size = AOP_SIZE (op);
+         offset = 0;
+         while (size--)
+         {
+           MOVA (aopGet (AOP (op), offset, FALSE, FALSE));
+           offset++;
+         }
+       }
+
+      freeAsmop (op, NULL, ic, TRUE);
+    }
 }
 
 /*-----------------------------------------------------------------*/
index 00ee1a68ae2bac398f493743eda15a60f8be5630..409fb6a7af356dd00687514a3cf0e7cbe4ad2534 100644 (file)
@@ -7251,23 +7251,44 @@ genReceive (iCode * ic)
 static void
 genDummyRead (iCode * ic)
 {
-  operand *right;
+  operand *op;
   int size, offset;
 
-  right = IC_RIGHT (ic);
-  aopOp (right, ic, FALSE, FALSE);
+  op = IC_RIGHT (ic);
+  if (op && IS_SYMOP (op))
+    {
+      aopOp (op, ic, FALSE, FALSE);
   
-  /* general case */
-  size = AOP_SIZE (right);
-  offset = 0;
+      /* general case */
+      size = AOP_SIZE (op);
+      offset = 0;
 
-  while (size--)
-    {
-      _moveA (aopGet (AOP (right), offset, FALSE));
-      offset++;
+      while (size--)
+       {
+         _moveA (aopGet (AOP (op), offset, FALSE));
+         offset++;
+       }
+
+      freeAsmop (op, NULL, ic);
     }
+  
+  op = IC_LEFT (ic);
+  if (op && IS_SYMOP (op))
+    {
+      aopOp (op, ic, FALSE, FALSE);
+  
+      /* general case */
+      size = AOP_SIZE (op);
+      offset = 0;
 
-  freeAsmop (right, NULL, ic);
+      while (size--)
+       {
+         _moveA (aopGet (AOP (op), offset, FALSE));
+         offset++;
+       }
+
+      freeAsmop (op, NULL, ic);
+    }
 }
 
 enum