aboutsummaryrefslogtreecommitdiff
path: root/sim/ppc
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2024-01-01 18:14:13 -0500
committerMike Frysinger <vapier@gentoo.org>2024-01-01 18:16:38 -0500
commit1b89e2b72052e60fc7a6c0301a67070accc714e1 (patch)
tree74599de2929676a7a8d1260d0b496f79fd0b7234 /sim/ppc
parent9ddac092a831d9eb4a53959764c2d13b12964a0c (diff)
downloadbinutils-1b89e2b72052e60fc7a6c0301a67070accc714e1.zip
binutils-1b89e2b72052e60fc7a6c0301a67070accc714e1.tar.gz
binutils-1b89e2b72052e60fc7a6c0301a67070accc714e1.tar.bz2
sim: ppc: merge misc igen APIs
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.
Diffstat (limited to 'sim/ppc')
-rw-r--r--sim/ppc/dumpf.c40
-rw-r--r--sim/ppc/dumpf.h25
-rw-r--r--sim/ppc/ld-cache.c1
-rw-r--r--sim/ppc/ld-decode.c1
-rw-r--r--sim/ppc/ld-insn.c1
-rw-r--r--sim/ppc/local.mk6
-rw-r--r--sim/ppc/misc.c204
-rw-r--r--sim/ppc/misc.h80
-rw-r--r--sim/ppc/table.c1
9 files changed, 73 insertions, 286 deletions
diff --git a/sim/ppc/dumpf.c b/sim/ppc/dumpf.c
new file mode 100644
index 0000000..6aaae16
--- /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 0000000..9137463
--- /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 a5d101d..67e60eb 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 a631645..09ed4b1 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 c11b449..6b54026 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 c72668c..8bcc7e7 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 9499101..0000000
--- 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 243d5c9..0000000
--- 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 0c5b6fc..5cac56e 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>