Bug 560712 - nanojit: give immediates names when printing LIR. r=edwsmith.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 27 Apr 2010 18:40:51 -0700
changeset 41813 3a5a84f83e752520d41d25a6f1624dc3606cf1e0
parent 41812 f49dca159319739302bcf51719906a5af290eb18
child 41814 4af425491baea8aabf80bc3bc7d2d0de94113921
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersedwsmith
bugs560712
milestone1.9.3a5pre
Bug 560712 - nanojit: give immediates names when printing LIR. r=edwsmith.
js/src/nanojit/LIR.cpp
js/src/nanojit/LIR.h
--- a/js/src/nanojit/LIR.cpp
+++ b/js/src/nanojit/LIR.cpp
@@ -1470,38 +1470,45 @@ namespace nanojit
         // This assertion will fail if we add a new accSet value but
         // forget to handle it here.
         NanoAssert(accSet == 0);
         buf->buf[i] = 0;
         NanoAssert(size_t(i) < buf->len);
         return buf->buf;
     }
 
-    void LInsPrinter::formatImm(RefBuf* buf, int32_t c) {
+    char* LInsPrinter::formatImmI(RefBuf* buf, int32_t c) {
         if (-10000 < c || c < 10000) {
             VMPI_snprintf(buf->buf, buf->len, "%d", c);
         } else {
 #if !defined NANOJIT_64BIT
             formatAddr(buf, (void*)c);
 #else
             VMPI_snprintf(buf->buf, buf->len, "0x%x", (unsigned int)c);
 #endif
         }
+        return buf->buf;
     }
 
-    void LInsPrinter::formatImmq(RefBuf* buf, uint64_t c) {
+    char* LInsPrinter::formatImmQ(RefBuf* buf, uint64_t c) {
         if (-10000 < (int64_t)c || c < 10000) {
             VMPI_snprintf(buf->buf, buf->len, "%dLL", (int)c);
         } else {
 #if defined NANOJIT_64BIT
             formatAddr(buf, (void*)c);
 #else
             VMPI_snprintf(buf->buf, buf->len, "0x%llxLL", c);
 #endif
         }
+        return buf->buf;
+    }
+
+    char* LInsPrinter::formatImmD(RefBuf* buf, double c) {
+        VMPI_snprintf(buf->buf, buf->len, "%g", c);
+        return buf->buf;
     }
 
     char* LInsPrinter::formatAddr(RefBuf* buf, void* p)
     {
         char*   name;
         int32_t offset;
         addrNameMap->lookupAddr(p, name, offset);
 
@@ -1513,70 +1520,76 @@ namespace nanojit
             }
         } else {
             VMPI_snprintf(buf->buf, buf->len, "%p", p);
         }
 
         return buf->buf;
     }
 
-    char* LInsPrinter::formatRef(RefBuf* buf, LIns *ref)
+    char* LInsPrinter::formatRef(RefBuf* buf, LIns *ref, bool showImmValue)
     {
-        // - If 'ref' already has a name, use it.
-        // - Otherwise, if it's a constant, use the constant.
-        // - Otherwise, give it a name and use it.
+        // Give 'ref' a name if it doesn't have one.  
         const char* name = lirNameMap->lookupName(ref);
-        if (name) {
+        if (!name) {
+            name = lirNameMap->createName(ref);
+        }
+
+        // Put it in the buffer.  If it's an immediate, show the value if
+        // showImmValue==true.  (This facility allows us to print immediate
+        // values when they're used but not when they're def'd, ie. we don't
+        // want "immi1/*1*/ = immi 1".)
+        RefBuf buf2;
+        if (ref->isImmI() && showImmValue) {
+            VMPI_snprintf(buf->buf, buf->len, "%s/*%s*/", name, formatImmI(&buf2, ref->immI()));
+        }
+#ifdef NANOJIT_64BIT
+        else if (ref->isImmQ() && showImmValue) {
+            VMPI_snprintf(buf->buf, buf->len, "%s/*%s*/", name, formatImmQ(&buf2, ref->immQ()));
+        }
+#endif
+        else if (ref->isImmD() && showImmValue) {
+            VMPI_snprintf(buf->buf, buf->len, "%s/*%s*/", name, formatImmD(&buf2, ref->immD()));
+        }
+        else {
             VMPI_snprintf(buf->buf, buf->len, "%s", name);
         }
-        else if (ref->isImmI()) {
-            formatImm(buf, ref->immI());
-        }
-#ifdef NANOJIT_64BIT
-        else if (ref->isImmQ()) {
-            formatImmq(buf, ref->immQ());
-        }
-#endif
-        else if (ref->isImmD()) {
-            VMPI_snprintf(buf->buf, buf->len, "%g", ref->immD());
-        }
-        else {
-            name = lirNameMap->createName(ref);
-            VMPI_snprintf(buf->buf, buf->len, "%s", name);
-        }
+
         return buf->buf;
     }
 
     char* LInsPrinter::formatIns(InsBuf* buf, LIns* i)
     {
         char *s = buf->buf;
         size_t n = buf->len;
         RefBuf b1, b2, b3, b4;
         LOpcode op = i->opcode();
         switch (op)
         {
             case LIR_immi:
-                VMPI_snprintf(s, n, "%s = %s %d", formatRef(&b1, i), lirNames[op], i->immI());
+                VMPI_snprintf(s, n, "%s = %s %s", formatRef(&b1, i, /*showImmValue*/false),
+                              lirNames[op], formatImmI(&b2, i->immI()));
+                break;
+
+#ifdef NANOJIT_64BIT
+            case LIR_immq:
+                VMPI_snprintf(s, n, "%s = %s %s", formatRef(&b1, i, /*showImmValue*/false),
+                              lirNames[op], formatImmQ(&b2, i->immQ()));
+                break;
+#endif
+
+            case LIR_immd:
+                VMPI_snprintf(s, n, "%s = %s %s", formatRef(&b1, i, /*showImmValue*/false),
+                              lirNames[op], formatImmD(&b2, i->immD()));
                 break;
 
             case LIR_allocp:
                 VMPI_snprintf(s, n, "%s = %s %d", formatRef(&b1, i), lirNames[op], i->size());
                 break;
 
-#ifdef NANOJIT_64BIT
-            case LIR_immq:
-                VMPI_snprintf(s, n, "%s = %s %X:%X", formatRef(&b1, i), lirNames[op],
-                             i->immQorDhi(), i->immQorDlo());
-                break;
-#endif
-
-            case LIR_immd:
-                VMPI_snprintf(s, n, "%s = %s %g", formatRef(&b1, i), lirNames[op], i->immD());
-                break;
-
             case LIR_start:
             case LIR_regfence:
                 VMPI_snprintf(s, n, "%s", lirNames[op]);
                 break;
 
             case LIR_calli:
             case LIR_calld:
             CASE64(LIR_callq:) {
--- a/js/src/nanojit/LIR.h
+++ b/js/src/nanojit/LIR.h
@@ -1810,31 +1810,32 @@ namespace nanojit
         char buf[len];
     };
 
     class LInsPrinter
     {
     private:
         Allocator& alloc;
 
-        void formatImm(RefBuf* buf, int32_t c);
-        void formatImmq(RefBuf* buf, uint64_t c);
+        char *formatImmI(RefBuf* buf, int32_t c);
+        char *formatImmQ(RefBuf* buf, uint64_t c);
+        char *formatImmD(RefBuf* buf, double c);
         void formatGuard(InsBuf* buf, LInsp ins);
         void formatGuardXov(InsBuf* buf, LInsp ins);
 
     public:
         LInsPrinter(Allocator& alloc)
             : alloc(alloc)
         {
             addrNameMap = new (alloc) AddrNameMap(alloc);
             lirNameMap = new (alloc) LirNameMap(alloc);
         }
 
         char *formatAddr(RefBuf* buf, void* p);
-        char *formatRef(RefBuf* buf, LInsp ref);
+        char *formatRef(RefBuf* buf, LInsp ref, bool showImmValue = true);
         char *formatIns(InsBuf* buf, LInsp ins);
         char *formatAccSet(RefBuf* buf, AccSet accSet);
 
         AddrNameMap* addrNameMap;
         LirNameMap* lirNameMap;
     };