* src/mcs51/gen.c (leftRightUseAcc): use macro IS_OP_ACCUSE
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 13 Oct 2007 18:27:11 +0000 (18:27 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 13 Oct 2007 18:27:11 +0000 (18:27 +0000)
* src/SDCCast.c (decorateType): optimize bit=cond?1:0, RFE 1738430
* support/regression/tests/bug-223113.c,
* support/regression/tests/bug-426632.c,
* support/regression/tests/bug-468811.c,
* support/regression/tests/bug-477835.c,
* support/regression/tests/bug-478094.c,
* support/regression/tests/bug-499644.c,
* support/regression/tests/bug-524209.c,
* support/regression/tests/bug-524211.c,
* support/regression/tests/packcast.c,
* support/regression/tests/structidx.c: added empty tests
* support/regression/tests/bug-607243.c: enabled test

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

14 files changed:
ChangeLog
src/SDCCast.c
src/mcs51/gen.c
support/regression/tests/bug-223113.c
support/regression/tests/bug-426632.c
support/regression/tests/bug-468811.c
support/regression/tests/bug-477835.c
support/regression/tests/bug-478094.c
support/regression/tests/bug-499644.c
support/regression/tests/bug-524209.c
support/regression/tests/bug-524211.c
support/regression/tests/bug-607243.c
support/regression/tests/packcast.c
support/regression/tests/structidx.c

index 91d9befdd10039d40c4d6b4c614d3a7aaaf0cf4f..8f2ee13e16e02f07a76f0b801faf55af7ec99b56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2007-10-13 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/mcs51/gen.c (leftRightUseAcc): use macro IS_OP_ACCUSE
+       * src/SDCCast.c (decorateType): optimize bit=cond?1:0, RFE 1738430
+       * support/regression/tests/bug-223113.c,
+       * support/regression/tests/bug-426632.c,
+       * support/regression/tests/bug-468811.c,
+       * support/regression/tests/bug-477835.c,
+       * support/regression/tests/bug-478094.c,
+       * support/regression/tests/bug-499644.c,
+       * support/regression/tests/bug-524209.c,
+       * support/regression/tests/bug-524211.c,
+       * support/regression/tests/packcast.c,
+       * support/regression/tests/structidx.c: added empty tests
+       * support/regression/tests/bug-607243.c: enabled test
+
 2007-10-06 Borut Razem <borut.razem AT siol.net>
 
        * .version, doc/sdccman.lyx: bumped version to 2.7.4 to indicate the full
index 2fb213e94a5f090eecfe7a641646e5904089bebc..339aa2ae47025209a6fbce5880591bf167b53e4c 100644 (file)
@@ -1225,7 +1225,7 @@ ast * initAggregates (symbol * sym, initList * ival, ast * wid) {
 
 /*-----------------------------------------------------------------*/
 /* gatherAutoInit - creates assignment expressions for initial     */
-/*    values                 */
+/*                  values                                         */
 /*-----------------------------------------------------------------*/
 static ast *
 gatherAutoInit (symbol * autoChain)
@@ -2535,7 +2535,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
        upon tree->opval.op, if resultType can be propagated */
     resultTypeProp = resultTypePropagate (tree, resultType);
 
-    if (tree->opval.op == '?')
+    if ((tree->opval.op == '?') && (resultTypeProp != RESULT_TYPE_BIT))
       dtl = decorateType (tree->left, RESULT_TYPE_IFX);
     else
       dtl = decorateType (tree->left, resultTypeProp);
@@ -3650,7 +3650,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
         {
           if ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT))
             {
-              /* remove double '!!X' by 'X' */
+              /* replace double '!!X' by 'X' */
               return tree->left->left;
             }
           /* remove double '!!X' by 'X ? 1 : 0' */
@@ -4369,6 +4369,19 @@ decorateType (ast * tree, RESULT_TYPE resultType)
       /* the type is value of the colon operator (on the right) */
       assert (IS_COLON_OP (tree->right));
 
+      /* If already known then replace the tree : optimizer will do it
+         but faster to do it here. If done before decorating tree->right
+         this can save generating unused const strings. */
+      if (IS_LITERAL (LTYPE (tree)))
+        {
+          if (((int) ulFromVal (valFromType (LETYPE (tree)))) != 0)
+            return decorateType (tree->right->left, resultTypeProp);
+          else
+            return decorateType (tree->right->right, resultTypeProp);
+        }
+
+      tree->right = decorateType (tree->right,  resultTypeProp);
+
       if (IS_AST_LIT_VALUE (tree->right->left) && IS_AST_LIT_VALUE (tree->right->right))
         {
           double valTrue = AST_LIT_VALUE (tree->right->left);
@@ -4378,6 +4391,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
               ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT)))
             {
               /* assign cond to result */
+              tree->left->decorated = 0;
               return decorateType (tree->left, resultTypeProp);
             }
           else if ((valTrue == 0) && (valFalse == 1))
@@ -4391,27 +4405,13 @@ decorateType (ast * tree, RESULT_TYPE resultType)
         }
 
       /* if they are equal then replace the tree */
-      if (!astHasVolatile (tree->right) &&
-          isAstEqual (tree->right->left, tree->right->right))
+      if (isAstEqual (tree->right->left, tree->right->right))
         {
-          return decorateType (tree->right->left, resultTypeProp);
+          return tree->right->left;
         }
 
-      /* if already known then replace the tree : optimizer will do it
-         but faster to do it here */
-      if (IS_LITERAL (LTYPE (tree)))
-        {
-          if (((int) ulFromVal (valFromType (LETYPE (tree)))) != 0)
-            return decorateType (tree->right->left, resultTypeProp);
-          else
-            return decorateType (tree->right->right, resultTypeProp);
-        }
-      else
-        {
-          tree->right = decorateType (tree->right, resultTypeProp);
-          TTYPE (tree) = RTYPE (tree);
-          TETYPE (tree) = getSpec (TTYPE (tree));
-        }
+      TTYPE (tree) = RTYPE (tree);
+      TETYPE (tree) = getSpec (TTYPE (tree));
       return tree;
 
     case ':':
index 8a28956bfef0b9865b95b932a781f21a28fae9c1..f4016b7510b425d19bc5c4de1ddafa3f905dfba9 100644 (file)
@@ -543,7 +543,7 @@ leftRightUseAcc(iCode *ic)
   if (ic->op == IFX)
     {
       op = IC_COND (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
@@ -554,7 +554,7 @@ leftRightUseAcc(iCode *ic)
   else if (ic->op == JUMPTABLE)
     {
       op = IC_JTCOND (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
@@ -565,7 +565,7 @@ leftRightUseAcc(iCode *ic)
   else
     {
       op = IC_LEFT (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
@@ -573,7 +573,7 @@ leftRightUseAcc(iCode *ic)
             accuseSize = size;
         }
       op = IC_RIGHT (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
index aacf1387237dbefd312b8636f77fb396ec9e5d68..d064241765b4866bdd7d511f111b4184afb4d689 100644 (file)
@@ -3,23 +3,27 @@
  */
 #include <testfwk.h>
 
-int putch( int Ch ) 
-{ 
-  return( Ch ); 
-} 
+int putch( int Ch )
+{
+  return( Ch );
+}
+
+int puts( char *Str )
+{
+  char *Ptr;
 
-int puts( char *Str ) 
-{ 
-  char *Ptr; 
-   
   for( Ptr = Str; *Ptr != '\0'; Ptr++ ) {
-    putch( *Ptr ); 
-  } 
-   
-  return( (Ptr - Str) ); 
-} 
+    putch( *Ptr );
+  }
+
+  return( (Ptr - Str) );
+}
+
+void __main( void )
+{
+  puts( "hello world\n" );
+}
 
-void __main( void ) 
-{ 
-  puts( "hello world\n" ); 
+void testBug(void)
+{
 }
index ff9db32b76e00bd23b358f8c05634258f60604fc..5a89547065abdfdb3eaf87873a11a937dd8bb93b 100644 (file)
@@ -3,35 +3,39 @@
 */
 #include <testfwk.h>
 
-typedef struct { 
-    unsigned char year; /* Current year (with offset 1900) */ 
-    unsigned char month; /* Month (1 = Jan., ..., 12 = Dec.) */ 
-    unsigned char day; /* Day of month (1 to 31) */ 
-} DATE_STRUCT; 
+typedef struct {
+    unsigned char year; /* Current year (with offset 1900) */
+    unsigned char month; /* Month (1 = Jan., ..., 12 = Dec.) */
+    unsigned char day; /* Day of month (1 to 31) */
+} DATE_STRUCT;
 
-unsigned char year; 
-unsigned char month; 
-unsigned char day; 
+unsigned char year;
+unsigned char month;
+unsigned char day;
 
 void *__main()
-{ 
-    float i; 
-    float y; 
-    void *p; 
-    DATE_STRUCT d; 
-    DATE_STRUCT *date_ptr; 
-   
-    date_ptr = &d; 
-   
-    year = date_ptr->year; 
-    month = date_ptr->month; 
-    day = date_ptr->day; 
-   
-    i = 1.35; 
-    i += 2; 
-    y = 1; 
-    y = y+i; 
-    i = y; 
-    p = &y; 
-    return p; 
-} 
+{
+    float i;
+    float y;
+    void *p;
+    DATE_STRUCT d;
+    DATE_STRUCT *date_ptr;
+
+    date_ptr = &d;
+
+    year = date_ptr->year;
+    month = date_ptr->month;
+    day = date_ptr->day;
+
+    i = 1.35;
+    i += 2;
+    y = 1;
+    y = y+i;
+    i = y;
+    p = &y;
+    return p;
+}
+
+void testBug(void)
+{
+}
index c5454561cc06f5f122f5b9a46ed143de312d5c42..b0e3da65185142f047f9784c8d1ad0965b29c280 100644 (file)
@@ -18,7 +18,7 @@ set_sprite_tile(UINT8 nb, UINT8 tile)
 #define MIN_SY         5U              /* min y (char) */
 #define MAX_SY         (MIN_SY+13U)    /* max y (char) */
 
-#define DEF_SP         30U             /* sprite null char code */     
+#define DEF_SP         30U             /* sprite null char code */
 
 /* player */
 #define MIN_PX         (MIN_SX*8U+8U)  /* min x (dot) */
@@ -72,3 +72,7 @@ void enemys()
     }
   }
 }
+
+void testBug(void)
+{
+}
index 294b4198e9b35b75dbb9d48ec5c5c5a9430d749f..c8e75ea89a13f3f7468c9e556a065e76e4b16218 100644 (file)
@@ -29,3 +29,7 @@ fptr2(void (*fp)(void))
   for (i = 0; i < 50; i++)
     dummy(fp2);
 }
+
+void testBug(void)
+{
+}
index 10158421f62d3a401763bf479b67166af0488b4b..7497564561b70c29573b77696629ac1307b9093a 100644 (file)
@@ -4,36 +4,40 @@
 
 
 
-int foo = 16; 
+int foo = 16;
 
 void f( int x )
 {
   UNUSED(x);
 }
 
-void g(int bar) 
-{ 
-  int a = 0; 
-  int b = 0; 
+void g(int bar)
+{
+  int a = 0;
+  int b = 0;
+
+  while(1) {
+    switch(bar) {
+    case 0:
+      --foo;
+      f(foo);
+      break;
+    case 1:
+      ++foo;
+      f(foo);
+      break;
+    case 2:
+      ++a;
+      f(a);
+      break;
+    case 3:
+      ++b;
+      f(b);
+      break;
+    }
+  }
+}
 
-  while(1) { 
-    switch(bar) { 
-    case 0: 
-      --foo; 
-      f(foo); 
-      break; 
-    case 1: 
-      ++foo; 
-      f(foo); 
-      break; 
-    case 2: 
-      ++a; 
-      f(a); 
-      break; 
-    case 3: 
-      ++b; 
-      f(b); 
-      break; 
-    } 
-  } 
-} 
+void testBug(void)
+{
+}
index bec161145703758b2e075bc857084fb44afe726d..caf4815ea4840c962f94d98a09da89b1282949a3 100644 (file)
@@ -2,9 +2,13 @@
  */
 #include <testfwk.h>
 
-const float a = 0.0; 
+const float a = 0.0;
 
-float f(void) 
-{ 
-  return a * 5; 
-} 
+float f(void)
+{
+  return a * 5;
+}
+
+void testBug(void)
+{
+}
index a5b215e1aed8b01c291c9e80a78d4ea8cee98f72..67d2659e73d87ec16a642c37d4f78c64f06cd57c 100644 (file)
@@ -31,3 +31,6 @@ void checkCast(void *pIn)
   _scan((StringBuffer *)p);
 }
 
+void testBug(void)
+{
+}
index 0dee2d1e74755b5b030868e65c7a3749d467b515..3d3128bd0fd63d98ed7338ea4f5d3f942efa51c6 100644 (file)
@@ -28,3 +28,7 @@ void foo(void)
 {
 }
 #endif
+
+void testBug(void)
+{
+}
index 00ed648d9464033fd0e046bde132e6294729ca52..4209454a28aee446071767d4743ce465cbae5dc3 100644 (file)
@@ -2,15 +2,15 @@
 
 #include <testfwk.h>
 
-typedef unsigned int u16_t; 
+typedef unsigned int u16_t;
 
-struct myhdr { u16_t x; } h, *p; 
+struct myhdr { u16_t x; } h, *p;
 
-#define NTOHS(n) (((((u16_t)(n) & 0xff)) << 8) | (((u16_t)(n) & 0xff00) >> 8)) 
-#define IPH_V(hdr) ((u16_t)NTOHS((hdr)->x) >> 12) 
+#define NTOHS(n) (((((u16_t)(n) & 0xff)) << 8) | (((u16_t)(n) & 0xff00) >> 8))
+#define IPH_V(hdr) ((u16_t)NTOHS((hdr)->x) >> 12)
 
-void foo(void) { 
-  p = &h; 
-  p->x = 0x45; 
+void testBug(void) {
+  p = &h;
+  p->x = 0x45;
   ASSERT(IPH_V(p)==4);
-} 
+}
index f44542d28cb5fc972feb082b84f6142f26fb23c8..86b8a23b92d10d8684b3b78536dcee518724aee1 100644 (file)
@@ -23,3 +23,7 @@ testCastPack(char x)
         }
     }
 }
+
+void testBug(void)
+{
+}
index 9bfca09e3c7f28326cf799ca9c3f2b1f262c17b7..8a7fdcc77c595e759e4eee99a08b7486ace0ce97 100644 (file)
@@ -30,3 +30,7 @@ getWidth(void)
 {
   return cursors[current_cursor].w;
 }
+
+void testBug(void)
+{
+}