shithub: mc

Download patch

ref: dfc57771d78d1bc4e4e9ad9494f05554f96f9841
parent: 7ec531e6ae0ff523f2232d728b8a278445343b80
author: Ori Bernstein <[email protected]>
date: Tue Dec 23 13:03:40 EST 2014

Clean up locprint(), and enable indexes.

    locprint %IDXt will print the IDXth argument of type t.

--- a/6/gengas.c
+++ b/6/gengas.c
@@ -155,7 +155,7 @@
 {
     char *p;
     int i;
-    int modeidx;
+    int idx;
 
     /* x64 has a quirk; it has no movzlq because mov zero extends. This
      * means that we need to do a movl when we really want a movzlq. Since
@@ -196,7 +196,6 @@
     }
     p = insnfmt[insn->op];
     i = 0;
-    modeidx = 0;
     for (; *p; p++) {
         if (*p !=  '%') {
             fputc(*p, fd);
@@ -205,6 +204,8 @@
 
         /* %-formating */
         p++;
+        idx = i;
+again:
         switch (*p) {
             case '\0':
                 goto done; /* skip the final p++ */
@@ -215,31 +216,19 @@
             case 'v': /* reg/mem */
             case 'u': /* reg/imm */
             case 'x': /* reg/mem/imm */
-                locprint(fd, insn->args[i], *p);
+                locprint(fd, insn->args[idx], *p);
                 i++;
                 break;
-            case 'R': /* int register */
-            case 'F': /* float register */
-            case 'M': /* memory */
-            case 'I': /* imm */
-            case 'V': /* reg/mem */
-            case 'U': /* reg/imm */
-            case 'X': /* reg/mem/imm */
-                locprint(fd, insn->args[i], *p);
-                i++;
-                break;
             case 't':
-            case 'T':
+                fputs(modenames[insn->args[idx]->mode], fd);
+                break;
             default:
                 /* the  asm description uses 1-based indexing, so that 0
                  * can be used as a sentinel. */
-                if (isdigit(*p))
-                    modeidx = strtol(p, &p, 10) - 1;
-
-                if (*p == 't')
-                    fputs(modenames[insn->args[modeidx]->mode], fd);
-                else
+                if (!isdigit(*p))
                     die("Invalid %%-specifier '%c'", *p);
+                idx = strtol(p, &p, 10) - 1;
+                goto again;
                 break;
         }
     }
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -158,7 +158,7 @@
 {
     char *p;
     int i;
-    int modeidx;
+    int idx;
 
     /* x64 has a quirk; it has no movzlq because mov zero extends. This
      * means that we need to do a movl when we really want a movzlq. Since
@@ -198,8 +198,7 @@
             break;
     }
     p = insnfmt[insn->op];
-    i = 0;
-    modeidx = 0;
+    i = 0; /* NB: this is 1 based indexing */
     for (; *p; p++) {
         if (*p !=  '%') {
             fputc(*p, fd);
@@ -208,18 +207,11 @@
 
         /* %-formating */
         p++;
+        idx = i;
+again:
         switch (*p) {
             case '\0':
                 goto done; /* skip the final p++ */
-            case 'r': /* int register */
-            case 'f': /* float register */
-            case 'm': /* memory */
-            case 'i': /* imm */
-            case 'v': /* reg/mem */
-            case 'u': /* reg/imm */
-            case 'x': /* reg/mem/imm */
-                locprint(fd, insn->args[i], *p);
-                i++;
                 break;
             case 'R': /* int register */
             case 'F': /* float register */
@@ -228,21 +220,19 @@
             case 'V': /* reg/mem */
             case 'U': /* reg/imm */
             case 'X': /* reg/mem/imm */
-                locprint(fd, insn->args[i], *p);
+                locprint(fd, insn->args[idx], *p);
                 i++;
                 break;
-            case 't':
             case 'T':
+                fputs(modenames[insn->args[idx]->mode], fd);
+                break;
             default:
                 /* the  asm description uses 1-based indexing, so that 0
                  * can be used as a sentinel. */
-                if (isdigit(*p))
-                    modeidx = strtol(p, &p, 10) - 1;
-
-                if (*p == 'T')
-                    fputs(modenames[insn->args[modeidx]->mode], fd);
-                else
+                if (!isdigit(*p))
                     die("Invalid %%-specifier '%c'", *p);
+                idx = strtol(p, &p, 10) - 1;
+                goto again;
                 break;
         }
     }
--- a/6/insns.def
+++ b/6/insns.def
@@ -151,7 +151,7 @@
     Def(None))
 Insn(Icmp,      
     "\tcmp%t  %x,%r\n",             
-    "\tCMP%T  %X,%R\n",
+    "\tCMP%T  %2R,%1X\n",
     Use(.l={1,2}),
     Def(None))