[PATCH/committed,8/8] sim: ppc: merge misc igen APIs

Message ID 20240101232219.3003-8-vapier@gentoo.org
State New
Headers
Series [PATCH/committed,1/8] sim: ppc: hoist igen compilation into top-level |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Mike Frysinger Jan. 1, 2024, 11:22 p.m. UTC
  The common igen code provides the same misc APIs as the ppc version,
so delete the ppc code and pull in the common one.  There is one
minor difference: the ppc code has a unique dumpf function.  The
common code switched to lf_printf for the same functionality, but
since that requires changes throughout the igen codebase, delay that
cleanup for now so we can merge the rest.
---
 sim/Makefile.in     |  15 ++--
 sim/ppc/dumpf.c     |  40 +++++++++
 sim/ppc/dumpf.h     |  25 ++++++
 sim/ppc/ld-cache.c  |   1 +
 sim/ppc/ld-decode.c |   1 +
 sim/ppc/ld-insn.c   |   1 +
 sim/ppc/local.mk    |   6 +-
 sim/ppc/misc.c      | 204 --------------------------------------------
 sim/ppc/misc.h      |  80 -----------------
 sim/ppc/table.c     |   1 +
 10 files changed, 82 insertions(+), 292 deletions(-)
 create mode 100644 sim/ppc/dumpf.c
 create mode 100644 sim/ppc/dumpf.h
 delete mode 100644 sim/ppc/misc.c
 delete mode 100644 sim/ppc/misc.h
  

Patch

diff --git a/sim/ppc/dumpf.c b/sim/ppc/dumpf.c
new file mode 100644
index 000000000000..6aaae16e62e4
--- /dev/null
+++ b/sim/ppc/dumpf.c
@@ -0,0 +1,40 @@ 
+/*  This file is part of the program psim.
+
+    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+    */
+
+/* TODO: Convert callers to lf_printf like common igen/.  */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <ctype.h>
+
+#include "dumpf.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+void
+dumpf (int indent, const char *msg, ...)
+{
+  va_list ap;
+  for (; indent > 0; indent--)
+    printf(" ");
+  va_start(ap, msg);
+  vprintf(msg, ap);
+  va_end(ap);
+}
diff --git a/sim/ppc/dumpf.h b/sim/ppc/dumpf.h
new file mode 100644
index 000000000000..91374637ae6e
--- /dev/null
+++ b/sim/ppc/dumpf.h
@@ -0,0 +1,25 @@ 
+/*  This file is part of the program psim.
+
+    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+    */
+
+/* TODO: Convert callers to lf_printf like common igen/.  */
+
+#include "ansidecl.h"
+
+extern void dumpf (int indent, const char *msg, ...)
+  ATTRIBUTE_PRINTF (2, 3);
diff --git a/sim/ppc/ld-cache.c b/sim/ppc/ld-cache.c
index a5d101daf6c9..67e60ebbb492 100644
--- a/sim/ppc/ld-cache.c
+++ b/sim/ppc/ld-cache.c
@@ -22,6 +22,7 @@ 
 #include "lf.h"
 #include "table.h"
 #include "ld-cache.h"
+#include "dumpf.h"
 
 
 enum {
diff --git a/sim/ppc/ld-decode.c b/sim/ppc/ld-decode.c
index a631645f54de..09ed4b198608 100644
--- a/sim/ppc/ld-decode.c
+++ b/sim/ppc/ld-decode.c
@@ -23,6 +23,7 @@ 
 #include "lf.h"
 #include "table.h"
 #include "ld-decode.h"
+#include "dumpf.h"
 
 
 enum {
diff --git a/sim/ppc/ld-insn.c b/sim/ppc/ld-insn.c
index c11b449a58c1..6b5402676b30 100644
--- a/sim/ppc/ld-insn.c
+++ b/sim/ppc/ld-insn.c
@@ -25,6 +25,7 @@ 
 #include "ld-decode.h"
 #include "ld-cache.h"
 #include "ld-insn.h"
+#include "dumpf.h"
 
 #include "igen.h"
 
diff --git a/sim/ppc/local.mk b/sim/ppc/local.mk
index c72668c69c46..8bcc7e7b9c39 100644
--- a/sim/ppc/local.mk
+++ b/sim/ppc/local.mk
@@ -47,7 +47,7 @@  EXTRA_LIBRARIES += %D%/libigen.a
 %C%_libigen_a_SOURCES = \
 	%D%/table.c \
 	%D%/lf.c \
-	%D%/misc.c \
+	%D%/dumpf.c \
 	%D%/ld-decode.c \
 	%D%/ld-cache.c \
 	%D%/filter.c \
@@ -58,7 +58,9 @@  EXTRA_LIBRARIES += %D%/libigen.a
 	%D%/gen-semantics.c \
 	%D%/gen-idecode.c \
 	%D%/gen-support.c
-%C%_libigen_a_LIBADD = igen/filter_host.o
+%C%_libigen_a_LIBADD = \
+	igen/filter_host.o \
+	igen/misc.o
 
 %C%_igen_SOURCES = %D%/igen.c
 %C%_igen_LDADD = %D%/libigen.a
diff --git a/sim/ppc/misc.c b/sim/ppc/misc.c
deleted file mode 100644
index 9499101b6029..000000000000
--- a/sim/ppc/misc.c
+++ /dev/null
@@ -1,204 +0,0 @@ 
-/*  This file is part of the program psim.
-
-    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
- 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, see <http://www.gnu.org/licenses/>.
- 
-    */
-
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <ctype.h>
-
-#include "misc.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-void
-error (const void *line, const char *msg, ...)
-{
-  va_list ap;
-  va_start(ap, msg);
-  vprintf(msg, ap);
-  va_end(ap);
-  exit (1);
-}
-
-void *
-zalloc(long size)
-{
-  void *memory = malloc(size);
-  if (memory == NULL)
-    ERROR("zalloc failed\n");
-  memset(memory, 0, size);
-  return memory;
-}
-
-void
-dumpf (int indent, const char *msg, ...)
-{
-  va_list ap;
-  for (; indent > 0; indent--)
-    printf(" ");
-  va_start(ap, msg);
-  vprintf(msg, ap);
-  va_end(ap);
-}
-
-
-unsigned
-a2i(const char *a)
-{
-  int neg = 0;
-  int base = 10;
-  unsigned num = 0;
-  int looping;
-
-  while (isspace (*a))
-    a++;
-
-  if (*a == '-') {
-    neg = 1;
-    a++;
-  }
-
-  if (*a == '0') {
-    if (a[1] == 'x' || a[1] == 'X') {
-      a += 2;
-      base = 16;
-    }
-    else
-      base = 8;
-  }
-
-  looping = 1;
-  while (looping) {
-    int ch = *a++;
-
-    switch (base) {
-    default:
-      looping = 0;
-      break;
-
-    case 10:
-      if (ch >= '0' && ch <= '9') {
-	num = (num * 10) + (ch - '0');
-      } else {
-	looping = 0;
-      }
-      break;
-
-    case 8:
-      if (ch >= '0' && ch <= '7') {
-	num = (num * 8) + (ch - '0');
-      } else {
-	looping = 0;
-      }
-      break;
-
-    case 16:
-      if (ch >= '0' && ch <= '9') {
-	num = (num * 16) + (ch - '0');
-      } else if (ch >= 'a' && ch <= 'f') {
-	num = (num * 16) + (ch - 'a' + 10);
-      } else if (ch >= 'A' && ch <= 'F') {
-	num = (num * 16) + (ch - 'A' + 10);
-      } else {
-	looping = 0;
-      }
-      break;
-    }
-  }
-
-  if (neg)
-    num = - num;
-
-  return num;
-}
-
-unsigned
-target_a2i(int ms_bit_nr,
-	   const char *a)
-{
-  if (ms_bit_nr)
-    return (ms_bit_nr - a2i(a));
-  else
-    return a2i(a);
-}
-
-unsigned
-i2target(int ms_bit_nr,
-	 unsigned bit)
-{
-  if (ms_bit_nr)
-    return ms_bit_nr - bit;
-  else
-    return bit;
-}
-
-
-int
-name2i(const char *names,
-       const name_map *map)
-{
-  const name_map *curr;
-  const char *name = names;
-  while (*name != '\0') {
-    /* find our name */
-    const char *end = strchr(name, ',');
-    const char *next;
-    int len;
-    if (end == NULL) {
-      end = strchr(name, '\0');
-      next = end;
-    }
-    else {
-      next = end + 1;
-    }
-    len = end - name;
-    /* look it up */
-    curr = map;
-    while (curr->name != NULL) {
-      if (strncmp(curr->name, name, len) == 0
-	  && strlen(curr->name) == len)
-	return curr->i;
-      curr++;
-    }
-    name = next;
-  }
-  /* nothing found, possibly return a default */
-  curr = map;
-  while (curr->name != NULL)
-    curr++;
-  if (curr->i >= 0)
-    return curr->i;
-  else
-    ERROR("%s contains no valid names\n", names);
-  return 0;
-}
-
-const char *
-i2name(const int i,
-       const name_map *map)
-{
-  while (map->name != NULL) {
-    if (map->i == i)
-      return map->name;
-    map++;
-  }
-  ERROR("map lookup failed for %d\n", i);
-  return NULL;
-}
diff --git a/sim/ppc/misc.h b/sim/ppc/misc.h
deleted file mode 100644
index 243d5c93605a..000000000000
--- a/sim/ppc/misc.h
+++ /dev/null
@@ -1,80 +0,0 @@ 
-/*  This file is part of the program psim.
-
-    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
- 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, see <http://www.gnu.org/licenses/>.
- 
-    */
-
-
-/* Frustrating header junk */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "ansidecl.h"
-#include "filter_host.h"
-
-extern void error (const void *line, const char *msg, ...)
-  ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
-
-#define ERROR(EXPRESSION, args...) \
-  error (NULL, EXPRESSION, ## args)
-
-#define ASSERT(EXPRESSION) \
-do { \
-  if (!(EXPRESSION)) { \
-    error("%s:%d: assertion failed - %s\n", \
-	  filter_filename (__FILE__), __LINE__, #EXPRESSION); \
-  } \
-} while (0)
-
-#define ZALLOC(TYPE) (TYPE*)zalloc(sizeof(TYPE))
-#define NZALLOC(TYPE,N) ((TYPE*) zalloc (sizeof(TYPE) * (N)))
-
-extern void *zalloc
-(long size);
-
-extern void dumpf (int indent, const char *msg, ...)
-  ATTRIBUTE_PRINTF (2, 3);
-
-extern unsigned target_a2i
-(int ms_bit_nr,
- const char *a);
-
-extern unsigned i2target
-(int ms_bit_nr,
- unsigned bit);
-
-extern unsigned a2i
-(const char *a);
-
-/* Try looking for name in the map table (returning the corresponding
-   integer value).  If that fails, try converting the name into an
-   integer */
-
-typedef struct _name_map {
-  const char *name;
-  int i;
-} name_map;
-
-extern int name2i
-(const char *name,
- const name_map *map);
-
-extern const char *i2name
-(const int i,
- const name_map *map);
diff --git a/sim/ppc/table.c b/sim/ppc/table.c
index 0c5b6fcd925a..5cac56eec9b9 100644
--- a/sim/ppc/table.c
+++ b/sim/ppc/table.c
@@ -27,6 +27,7 @@ 
 #include "misc.h"
 #include "lf.h"
 #include "table.h"
+#include "dumpf.h"
 
 #include <unistd.h>
 #include <stdlib.h>