shithub: mc

Download patch

ref: 0754332ab1945f9dda29185966d9fd5aad99a8f5
parent: bbb470a53c1f913a80d695ddd0f81bfb07951a3b
author: Ori Bernstein <[email protected]>
date: Wed Jun 13 21:11:40 EDT 2012

Refactor duplicated code.

    Copy out the repeated set printing loops.

--- a/8/ra.c
+++ b/8/ra.c
@@ -162,11 +162,42 @@
     }
 }
 
+void setprint(FILE *fd, Bitset *s)
+{
+    char *sep;
+    size_t i;
+
+    sep = "";
+    for (i = 0; i < bsmax(s); i++) {
+	if (bshas(s, i)) {
+	    fprintf(fd, "%s%zd", sep, i);
+	    sep = ",";
+	}
+    }
+    fprintf(fd, "\n");
+}
+
+void locsetprint(FILE *fd, Bitset *s)
+{
+    char *sep;
+    size_t i;
+
+    sep = "";
+    for (i = 0; i < bsmax(s); i++) {
+	if (bshas(s, i)) {
+	    fprintf(fd, "%s", sep);
+	    locprint(fd, loctab[i]);
+	    sep = ",";
+	}
+    }
+    fprintf(fd, "\n");
+}
+
 void dumpasm(Asmbb **bbs, size_t nbb, FILE *fd)
 {
     size_t i, j;
-    Asmbb *bb;
     char *sep;
+    Asmbb *bb;
 
     fprintf(fd, "ASM -------- \n");
     for (j = 0; j < nbb; j++) {
@@ -180,69 +211,19 @@
         }
         fprintf(fd, ")\n");
 
-        /* in edges */
         fprintf(fd, "Pred: ");
-        sep = "";
-        for (i = 0; i < bsmax(bb->pred); i++) {
-            if (bshas(bb->pred, i)) {
-                fprintf(fd, "%s%zd", sep, i);
-                sep = ",";
-            }
-        }
-        fprintf(fd, "\n");
-
-        /* out edges */
+	setprint(fd, bb->pred);
         fprintf(fd, "Succ: ");
-        sep = "";
-        for (i = 0; i < bsmax(bb->succ); i++) {
-             if (bshas(bb->succ, i)) {
-                fprintf(fd, "%s%zd", sep, i);
-                sep = ",";
-             }
-        }
-        fprintf(fd, "\n");
+	setprint(fd, bb->succ);
 
         fprintf(fd, "Use: ");
-        sep = "";
-        for (i = 0; i < bsmax(bb->use); i++) {
-             if (bshas(bb->use, i)) {
-                fprintf(fd, "%s", sep);
-		locprint(fd, loctab[i]);
-                sep = ",";
-             }
-        }
-        fprintf(fd, "\n");
+	locsetprint(fd, bb->use);
         fprintf(fd, "Def: ");
-        sep = "";
-        for (i = 0; i < bsmax(bb->def); i++) {
-             if (bshas(bb->def, i)) {
-                fprintf(fd, "%s", sep);
-		locprint(fd, loctab[i]);
-                sep = ",";
-             }
-        }
-        fprintf(fd, "\n");
-
+	locsetprint(fd, bb->def);
         fprintf(fd, "Livein:  ");
-        sep = "";
-        for (i = 0; i < bsmax(bb->livein); i++) {
-             if (bshas(bb->livein, i)) {
-                fprintf(fd, "%s", sep);
-		locprint(fd, loctab[i]);
-                sep = ",";
-             }
-        }
-        fprintf(fd, "\n");
+	locsetprint(fd, bb->livein);
         fprintf(fd, "Liveout: ");
-        sep = "";
-        for (i = 0; i < bsmax(bb->liveout); i++) {
-             if (bshas(bb->liveout, i)) {
-                fprintf(fd, "%s", sep);
-		locprint(fd, loctab[i]);
-                sep = ",";
-             }
-        }
-        fprintf(fd, "\n");
+	locsetprint(fd, bb->liveout);
         for (i = 0; i < bb->ni; i++)
             iprintf(fd, bb->il[i]);
     }