This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] compile.c: Clean up.


Hi,

Attached is a patch to replace literals with appropriate macros.

OK to apply?

Kazu Hirata

2001-12-20  Kazu Hirata  <kazu@hxi.com>

	* compile.c: Replace register numbers with appropriate macros.

Index: compile.c
===================================================================
RCS file: /cvs/src/src/sim/h8300/compile.c,v
retrieving revision 1.8
diff -u -r1.8 compile.c
--- compile.c	2001/12/20 17:36:23	1.8
+++ compile.c	2001/12/20 21:08:06
@@ -73,6 +73,28 @@
 
 #include "inst.h"
 
+/* Register numbers.  */
+
+#define R0_REGNUM	0
+#define R1_REGNUM	1
+#define R2_REGNUM	2
+#define R3_REGNUM	3
+#define R4_REGNUM	4
+#define R5_REGNUM	5
+#define R6_REGNUM	6
+#define R7_REGNUM	7
+
+#define SP_REGNUM       R7_REGNUM	/* Contains address of top of stack */
+#define FP_REGNUM       R6_REGNUM	/* Contains address of executing
+					 * stack frame */
+
+#define CCR_REGNUM      8	/* Contains processor status */
+#define PC_REGNUM       9	/* Contains program counter */
+
+#define CYCLE_REGNUM    10
+#define INST_REGNUM     11
+#define TICK_REGNUM     12
+
 /* The rate at which to call the host's poll_quit callback.  */
 
 #define POLL_QUIT_INTERVAL 0x80000
@@ -755,7 +777,7 @@
 	  lreg[i] = &cpu.regs[i];
 	}
 
-      lreg[8] = &cpu.regs[8];
+      lreg[CCR_REGNUM] = &cpu.regs[CCR_REGNUM];
 
       /* Initialize the seg registers.  */
       if (!cpu.cache)
@@ -1266,7 +1288,7 @@
 
 	case O (O_SYSCALL, SB):
 	  {
-	    char c = cpu.regs[2];
+	    char c = cpu.regs[R2_REGNUM];
 	    sim_callback->write_stdout (sim_callback, &c, 1);
 	  }
 	  goto next;
@@ -1309,7 +1331,7 @@
 	    int tmp;
 	    pc = fetch (&code->src);
 	  call:
-	    tmp = cpu.regs[7];
+	    tmp = cpu.regs[R7_REGNUM];
 
 	    if (h8300hmode)
 	      {
@@ -1321,7 +1343,7 @@
 		tmp -= 2;
 		SET_MEMORY_W (tmp, code->next_pc);
 	      }
-	    cpu.regs[7] = tmp;
+	    cpu.regs[R7_REGNUM] = tmp;
 
 	    goto end;
 	  }
@@ -1333,7 +1355,7 @@
 	  {
 	    int tmp;
 
-	    tmp = cpu.regs[7];
+	    tmp = cpu.regs[R7_REGNUM];
 
 	    if (h8300hmode)
 	      {
@@ -1346,7 +1368,7 @@
 		tmp += 2;
 	      }
 
-	    cpu.regs[7] = tmp;
+	    cpu.regs[R7_REGNUM] = tmp;
 	    goto end;
 	  }
 
@@ -1362,7 +1384,8 @@
              the macros here instead of looking for .../sys/wait.h.  */
 #define SIM_WIFEXITED(v) (((v) & 0xff) == 0)
 #define SIM_WIFSIGNALED(v) (((v) & 0x7f) > 0 && (((v) & 0x7f) < 0x7f))
-  	  if (! SIM_WIFEXITED (cpu.regs[0]) && SIM_WIFSIGNALED (cpu.regs[0])) 
+  	  if (! SIM_WIFEXITED (cpu.regs[R0_REGNUM])
+	      && SIM_WIFSIGNALED (cpu.regs[R0_REGNUM])) 
 	    cpu.exception = SIGILL;
 	  else
 	    cpu.exception = SIGTRAP;
@@ -1505,8 +1528,8 @@
 	    firstreg &= 0xf;
 	    for (i = firstreg; i <= firstreg + nregs; i++)
 	      {
-		cpu.regs[7] -= 4;
-		SET_MEMORY_L (cpu.regs[7], cpu.regs[i]);
+		cpu.regs[R7_REGNUM] -= 4;
+		SET_MEMORY_L (cpu.regs[R7_REGNUM], cpu.regs[i]);
 	      }
 	  }
 	  goto next;
@@ -1522,8 +1545,8 @@
 	    firstreg &= 0xf;
 	    for (i = firstreg; i >= firstreg - nregs; i--)
 	      {
-		cpu.regs[i] = GET_MEMORY_L (cpu.regs[7]);
-		cpu.regs[7] += 4;
+		cpu.regs[i] = GET_MEMORY_L (cpu.regs[R7_REGNUM]);
+		cpu.regs[R7_REGNUM] += 4;
 	      }
 	  }
 	  goto next;
@@ -1698,7 +1721,7 @@
     end:
       ;
 #if 0
-      if (cpu.regs[8])
+      if (cpu.regs[CCR_REGNUM])
 	abort ();
 #endif
 
@@ -1772,28 +1795,6 @@
   return size;
 }
 
-
-#define R0_REGNUM	0
-#define R1_REGNUM	1
-#define R2_REGNUM	2
-#define R3_REGNUM	3
-#define R4_REGNUM	4
-#define R5_REGNUM	5
-#define R6_REGNUM	6
-#define R7_REGNUM	7
-
-#define SP_REGNUM       R7_REGNUM	/* Contains address of top of stack */
-#define FP_REGNUM       R6_REGNUM	/* Contains address of executing
-					 * stack frame */
-
-#define CCR_REGNUM      8	/* Contains processor status */
-#define PC_REGNUM       9	/* Contains program counter */
-
-#define CYCLE_REGNUM    10
-#define INST_REGNUM     11
-#define TICK_REGNUM     12
-
-
 int
 sim_store_register (sd, rn, value, length)
      SIM_DESC sd;
@@ -1860,10 +1861,10 @@
     {
     default:
       abort ();
-    case 8:
+    case CCR_REGNUM:
       v = cpu.ccr;
       break;
-    case 9:
+    case PC_REGNUM:
       v = cpu.pc;
       break;
     case R0_REGNUM:
@@ -1876,15 +1877,15 @@
     case R7_REGNUM:
       v = cpu.regs[rn];
       break;
-    case 10:
+    case CYCLE_REGNUM:
       v = cpu.cycles;
       longreg = 1;
       break;
-    case 11:
+    case TICK_REGNUM:
       v = cpu.ticks;
       longreg = 1;
       break;
-    case 12:
+    case INST_REGNUM:
       v = cpu.insts;
       longreg = 1;
       break;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]