Clean up debugging code #ifdefs (Eduardo Habkost)

Use macros to avoid #ifdefs on debugging code.

This patch doesn't try to merge logging macros from different files,
but just unify the debugging code #ifdefs onto a macro on each file. A
further cleanup can unify the debugging macros on a common header, later

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6332 c046a42c-6fe2-441c-8c8c-71466251a162
diff --git a/target-ppc/op_helper.c b/target-ppc/op_helper.c
index c931adb..a5e3a3c 100644
--- a/target-ppc/op_helper.c
+++ b/target-ppc/op_helper.c
@@ -28,6 +28,16 @@
 //#define DEBUG_EXCEPTIONS
 //#define DEBUG_SOFTWARE_TLB
 
+#ifdef DEBUG_SOFTWARE_TLB
+#  define LOG_SWTLB(...) do {            \
+     if (loglevel)                       \
+       fprintf(logfile, ## __VA_ARGS__); \
+   } while (0)
+#else
+#  define LOG_SWTLB(...) do { } while (0)
+#endif
+
+
 /*****************************************************************************/
 /* Exceptions processing helpers */
 
@@ -3564,13 +3574,9 @@
         EPN = env->spr[SPR_DMISS];
     }
     way = (env->spr[SPR_SRR1] >> 17) & 1;
-#if defined (DEBUG_SOFTWARE_TLB)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s: EPN " ADDRX " " ADDRX " PTE0 " ADDRX
+    LOG_SWTLB("%s: EPN " ADDRX " " ADDRX " PTE0 " ADDRX
                 " PTE1 " ADDRX " way %d\n",
                 __func__, new_EPN, EPN, CMP, RPN, way);
-    }
-#endif
     /* Store this TLB */
     ppc6xx_tlb_store(env, (uint32_t)(new_EPN & TARGET_PAGE_MASK),
                      way, is_code, CMP, RPN);
@@ -3596,13 +3602,9 @@
     CMP = env->spr[SPR_PTEHI];
     EPN = env->spr[SPR_TLBMISS] & ~0x3;
     way = env->spr[SPR_TLBMISS] & 0x3;
-#if defined (DEBUG_SOFTWARE_TLB)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s: EPN " ADDRX " " ADDRX " PTE0 " ADDRX
+    LOG_SWTLB("%s: EPN " ADDRX " " ADDRX " PTE0 " ADDRX
                 " PTE1 " ADDRX " way %d\n",
                 __func__, new_EPN, EPN, CMP, RPN, way);
-    }
-#endif
     /* Store this TLB */
     ppc6xx_tlb_store(env, (uint32_t)(new_EPN & TARGET_PAGE_MASK),
                      way, is_code, CMP, RPN);
@@ -3726,22 +3728,14 @@
     ppcemb_tlb_t *tlb;
     target_ulong page, end;
 
-#if defined (DEBUG_SOFTWARE_TLB)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s entry %d val " ADDRX "\n", __func__, (int)entry, val);
-    }
-#endif
+    LOG_SWTLB("%s entry %d val " ADDRX "\n", __func__, (int)entry, val);
     entry &= 0x3F;
     tlb = &env->tlb[entry].tlbe;
     /* Invalidate previous TLB (if it's valid) */
     if (tlb->prot & PAGE_VALID) {
         end = tlb->EPN + tlb->size;
-#if defined (DEBUG_SOFTWARE_TLB)
-        if (loglevel != 0) {
-            fprintf(logfile, "%s: invalidate old TLB %d start " ADDRX
+        LOG_SWTLB("%s: invalidate old TLB %d start " ADDRX
                     " end " ADDRX "\n", __func__, (int)entry, tlb->EPN, end);
-        }
-#endif
         for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
             tlb_flush_page(env, page);
     }
@@ -3766,26 +3760,18 @@
     }
     tlb->PID = env->spr[SPR_40x_PID]; /* PID */
     tlb->attr = val & 0xFF;
-#if defined (DEBUG_SOFTWARE_TLB)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX
+    LOG_SWTLB("%s: set up TLB %d RPN " PADDRX " EPN " ADDRX
                 " size " ADDRX " prot %c%c%c%c PID %d\n", __func__,
                 (int)entry, tlb->RPN, tlb->EPN, tlb->size,
                 tlb->prot & PAGE_READ ? 'r' : '-',
                 tlb->prot & PAGE_WRITE ? 'w' : '-',
                 tlb->prot & PAGE_EXEC ? 'x' : '-',
                 tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID);
-    }
-#endif
     /* Invalidate new TLB (if valid) */
     if (tlb->prot & PAGE_VALID) {
         end = tlb->EPN + tlb->size;
-#if defined (DEBUG_SOFTWARE_TLB)
-        if (loglevel != 0) {
-            fprintf(logfile, "%s: invalidate TLB %d start " ADDRX
+        LOG_SWTLB("%s: invalidate TLB %d start " ADDRX
                     " end " ADDRX "\n", __func__, (int)entry, tlb->EPN, end);
-        }
-#endif
         for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
             tlb_flush_page(env, page);
     }
@@ -3795,11 +3781,7 @@
 {
     ppcemb_tlb_t *tlb;
 
-#if defined (DEBUG_SOFTWARE_TLB)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s entry %i val " ADDRX "\n", __func__, (int)entry, val);
-    }
-#endif
+    LOG_SWTLB("%s entry %i val " ADDRX "\n", __func__, (int)entry, val);
     entry &= 0x3F;
     tlb = &env->tlb[entry].tlbe;
     tlb->RPN = val & 0xFFFFFC00;
@@ -3808,17 +3790,13 @@
         tlb->prot |= PAGE_EXEC;
     if (val & 0x100)
         tlb->prot |= PAGE_WRITE;
-#if defined (DEBUG_SOFTWARE_TLB)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX
+    LOG_SWTLB("%s: set up TLB %d RPN " PADDRX " EPN " ADDRX
                 " size " ADDRX " prot %c%c%c%c PID %d\n", __func__,
                 (int)entry, tlb->RPN, tlb->EPN, tlb->size,
                 tlb->prot & PAGE_READ ? 'r' : '-',
                 tlb->prot & PAGE_WRITE ? 'w' : '-',
                 tlb->prot & PAGE_EXEC ? 'x' : '-',
                 tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID);
-    }
-#endif
 }
 
 target_ulong helper_4xx_tlbsx (target_ulong address)
@@ -3833,12 +3811,8 @@
     target_ulong EPN, RPN, size;
     int do_flush_tlbs;
 
-#if defined (DEBUG_SOFTWARE_TLB)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s word %d entry %d value " ADDRX "\n",
+    LOG_SWTLB("%s word %d entry %d value " ADDRX "\n",
                 __func__, word, (int)entry, value);
-    }
-#endif
     do_flush_tlbs = 0;
     entry &= 0x3F;
     tlb = &env->tlb[entry].tlbe;