* src/z80/peep.c: fixed msvc warning C4047:
[fw/sdcc] / src / z80 / peep.c
index 1900dbc65ebb63cbbd3d98a6ca200e3e64a39eac..b30335c21a1eba8c7a45339514c5a0e96fc17af0 100644 (file)
@@ -29,7 +29,7 @@
 #include "SDCCpeeph.h"
 #include "gen.h"
 
-#define NOTUSEDERROR {werror(E_INTERNAL_ERROR, __FILE__, __LINE__, "error in notUsed()");}
+#define NOTUSEDERROR() do {werror(E_INTERNAL_ERROR, __FILE__, __LINE__, "error in notUsed()");} while(0)
 
 /*#define D(_s) { printf _s; fflush(stdout); }*/
 #define D(_s)
@@ -89,7 +89,7 @@ isReturned(const char *what)
       // Find size of return value.
       specifier *spec;
       if(sym->type->select.d.dcl_type != FUNCTION)
-        NOTUSEDERROR
+        NOTUSEDERROR();
       spec = &(sym->etype->select.s);
       if(spec->noun == V_VOID)
          size = 0;
@@ -109,7 +109,7 @@ isReturned(const char *what)
     }
   else
     {
-      NOTUSEDERROR
+      NOTUSEDERROR();
       size = 4;
     }
 
@@ -169,7 +169,7 @@ findLabel (const lineNode *pl)
   /* sanity check */
   if (p == pl->line)
     {
-      NOTUSEDERROR
+      NOTUSEDERROR();
       return NULL;
     }
 
@@ -192,15 +192,21 @@ findLabel (const lineNode *pl)
   return NULL;
 }
 
+/* Check if reading arg implies reading what. */
+static bool argCont(const char *arg, const char *what)
+{
+  return (arg[0] == '#') ? FALSE : strstr(arg, what) != NULL;
+}
+
 static bool
 z80MightRead(const lineNode *pl, const char *what)
 {
-  if(strcmp(pl->line, "call\t__initrleblock") == 0)
-    return TRUE;
-
   if(strcmp(what, "iyl") == 0 || strcmp(what, "iyh") == 0)
     what = "iy";
 
+  if(strcmp(pl->line, "call\t__initrleblock") == 0)
+    return TRUE;
+
   if(strncmp(pl->line, "call\t", 5) == 0 && strchr(pl->line, ',') == 0)
     return FALSE;
 
@@ -224,13 +230,24 @@ z80MightRead(const lineNode *pl, const char *what)
   if(strncmp(pl->line, "adc\t", 4) == 0 ||
     strncmp(pl->line, "add\t", 4) == 0 ||
     strncmp(pl->line, "and\t", 4) == 0 ||
-    strncmp(pl->line, "or\t", 3) == 0 ||
     strncmp(pl->line, "sbc\t", 4) == 0 ||
     strncmp(pl->line, "sub\t", 4) == 0 ||
     strncmp(pl->line, "xor\t", 4) == 0)
     {
-      if( strstr(pl->line + 3, what) == 0 && strcmp("a", what))
-        return FALSE;
+      if(argCont(pl->line + 4, what))
+        return TRUE;
+      if(strstr(pl->line + 4, "hl") == 0 && strcmp("a", what) == 0)
+        return TRUE;
+      return FALSE;
+    }
+
+  if(strncmp(pl->line, "or\t", 3) == 0)
+    {
+      if(argCont(pl->line + 3, what))
+        return TRUE;
+      if(strcmp("a", what) == 0)
+        return TRUE;
+      return FALSE;
     }
 
   if(strncmp(pl->line, "pop\t", 4) == 0)
@@ -242,18 +259,29 @@ z80MightRead(const lineNode *pl, const char *what)
   if(
     strncmp(pl->line, "dec\t", 4) == 0 ||
     strncmp(pl->line, "inc\t", 4) == 0 ||
-    strncmp(pl->line, "rl\t", 3) == 0 ||
-    strncmp(pl->line, "rr\t", 3) == 0 ||  
+    strncmp(pl->line, "rl\t", 4) == 0 ||
+    strncmp(pl->line, "rr\t", 4) == 0 ||
     strncmp(pl->line, "sla\t", 4) == 0 ||
+    strncmp(pl->line, "sra\t", 4) == 0 ||
     strncmp(pl->line, "srl\t", 4) == 0)
     {
-       return (strstr(pl->line + 3, what) != 0);
+       return (argCont(pl->line + 4, what));
+    }
+
+  if(
+    strncmp(pl->line, "rl\t", 3) == 0 ||
+    strncmp(pl->line, "rr\t", 3) == 0)
+    {
+       return (argCont(pl->line + 3, what));
     }
 
   if(strncmp(pl->line, "jp\t", 3) == 0 ||
     (bool)(strncmp(pl->line, "jr\t", 3)) == 0)
     return FALSE;
 
+  if(strncmp(pl->line, "djnz\t", 5) == 0)
+    return(strchr(what, 'b') != 0);
+
   if(strncmp(pl->line, "rla", 3) == 0 ||
     strncmp(pl->line, "rlca", 4) == 0)
     return(strcmp(what, "a") == 0);
@@ -273,8 +301,9 @@ z80UncondJump(const lineNode *pl)
 static bool
 z80CondJump(const lineNode *pl)
 {
-  if((strncmp(pl->line, "jp\t", 3) == 0 ||
-    strncmp(pl->line, "jr\t", 3) == 0) && strchr(pl->line, ',') != 0)
+  if(((strncmp(pl->line, "jp\t", 3) == 0 ||
+    strncmp(pl->line, "jr\t", 3) == 0) && strchr(pl->line, ',') != 0) ||
+    strncmp(pl->line, "djnz\t", 5) == 0)
     return TRUE;
   return FALSE;
 }