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.
This commit is contained in:
Mike Frysinger 2024-01-01 18:14:13 -05:00
parent 9ddac092a8
commit 1b89e2b720
10 changed files with 82 additions and 292 deletions

View File

@ -806,10 +806,10 @@ or1k_libsim_a_OBJECTS = $(am_or1k_libsim_a_OBJECTS) \
$(nodist_or1k_libsim_a_OBJECTS) $(nodist_or1k_libsim_a_OBJECTS)
ppc_libigen_a_AR = $(AR) $(ARFLAGS) ppc_libigen_a_AR = $(AR) $(ARFLAGS)
@SIM_ENABLE_ARCH_ppc_TRUE@ppc_libigen_a_DEPENDENCIES = \ @SIM_ENABLE_ARCH_ppc_TRUE@ppc_libigen_a_DEPENDENCIES = \
@SIM_ENABLE_ARCH_ppc_TRUE@ igen/filter_host.o @SIM_ENABLE_ARCH_ppc_TRUE@ igen/filter_host.o igen/misc.o
@SIM_ENABLE_ARCH_ppc_TRUE@am_ppc_libigen_a_OBJECTS = \ @SIM_ENABLE_ARCH_ppc_TRUE@am_ppc_libigen_a_OBJECTS = \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/table.$(OBJEXT) ppc/lf.$(OBJEXT) \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/table.$(OBJEXT) ppc/lf.$(OBJEXT) \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/misc.$(OBJEXT) \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/dumpf.$(OBJEXT) \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-decode.$(OBJEXT) \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-decode.$(OBJEXT) \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-cache.$(OBJEXT) \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-cache.$(OBJEXT) \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/filter.$(OBJEXT) \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/filter.$(OBJEXT) \
@ -2908,7 +2908,7 @@ testsuite_common_CPPFLAGS = \
@SIM_ENABLE_ARCH_ppc_TRUE@ppc_libigen_a_SOURCES = \ @SIM_ENABLE_ARCH_ppc_TRUE@ppc_libigen_a_SOURCES = \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/table.c \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/table.c \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/lf.c \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/lf.c \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/misc.c \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/dumpf.c \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-decode.c \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-decode.c \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-cache.c \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/ld-cache.c \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/filter.c \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/filter.c \
@ -2920,7 +2920,10 @@ testsuite_common_CPPFLAGS = \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/gen-idecode.c \ @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/gen-idecode.c \
@SIM_ENABLE_ARCH_ppc_TRUE@ ppc/gen-support.c @SIM_ENABLE_ARCH_ppc_TRUE@ ppc/gen-support.c
@SIM_ENABLE_ARCH_ppc_TRUE@ppc_libigen_a_LIBADD = igen/filter_host.o @SIM_ENABLE_ARCH_ppc_TRUE@ppc_libigen_a_LIBADD = \
@SIM_ENABLE_ARCH_ppc_TRUE@ igen/filter_host.o \
@SIM_ENABLE_ARCH_ppc_TRUE@ igen/misc.o
@SIM_ENABLE_ARCH_ppc_TRUE@ppc_igen_SOURCES = ppc/igen.c @SIM_ENABLE_ARCH_ppc_TRUE@ppc_igen_SOURCES = ppc/igen.c
@SIM_ENABLE_ARCH_ppc_TRUE@ppc_igen_LDADD = ppc/libigen.a @SIM_ENABLE_ARCH_ppc_TRUE@ppc_igen_LDADD = ppc/libigen.a
@SIM_ENABLE_ARCH_ppc_TRUE@PPC_IGEN = ppc/igen$(EXEEXT) @SIM_ENABLE_ARCH_ppc_TRUE@PPC_IGEN = ppc/igen$(EXEEXT)
@ -3627,7 +3630,7 @@ ppc/$(DEPDIR)/$(am__dirstamp):
@: > ppc/$(DEPDIR)/$(am__dirstamp) @: > ppc/$(DEPDIR)/$(am__dirstamp)
ppc/table.$(OBJEXT): ppc/$(am__dirstamp) ppc/$(DEPDIR)/$(am__dirstamp) ppc/table.$(OBJEXT): ppc/$(am__dirstamp) ppc/$(DEPDIR)/$(am__dirstamp)
ppc/lf.$(OBJEXT): ppc/$(am__dirstamp) ppc/$(DEPDIR)/$(am__dirstamp) ppc/lf.$(OBJEXT): ppc/$(am__dirstamp) ppc/$(DEPDIR)/$(am__dirstamp)
ppc/misc.$(OBJEXT): ppc/$(am__dirstamp) ppc/$(DEPDIR)/$(am__dirstamp) ppc/dumpf.$(OBJEXT): ppc/$(am__dirstamp) ppc/$(DEPDIR)/$(am__dirstamp)
ppc/ld-decode.$(OBJEXT): ppc/$(am__dirstamp) \ ppc/ld-decode.$(OBJEXT): ppc/$(am__dirstamp) \
ppc/$(DEPDIR)/$(am__dirstamp) ppc/$(DEPDIR)/$(am__dirstamp)
ppc/ld-cache.$(OBJEXT): ppc/$(am__dirstamp) \ ppc/ld-cache.$(OBJEXT): ppc/$(am__dirstamp) \
@ -4085,6 +4088,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@moxie/$(DEPDIR)/modules.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@moxie/$(DEPDIR)/modules.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@msp430/$(DEPDIR)/modules.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@msp430/$(DEPDIR)/modules.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@or1k/$(DEPDIR)/modules.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@or1k/$(DEPDIR)/modules.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/dumpf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/filter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/filter.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/gen-icache.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/gen-icache.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/gen-idecode.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/gen-idecode.Po@am__quote@
@ -4097,7 +4101,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/ld-decode.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/ld-decode.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/ld-insn.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/ld-insn.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/lf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/lf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/misc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/table.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ppc/$(DEPDIR)/table.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@pru/$(DEPDIR)/modules.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@pru/$(DEPDIR)/modules.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@riscv/$(DEPDIR)/modules.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@riscv/$(DEPDIR)/modules.Po@am__quote@

40
sim/ppc/dumpf.c Normal file
View File

@ -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);
}

25
sim/ppc/dumpf.h Normal file
View File

@ -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);

View File

@ -22,6 +22,7 @@
#include "lf.h" #include "lf.h"
#include "table.h" #include "table.h"
#include "ld-cache.h" #include "ld-cache.h"
#include "dumpf.h"
enum { enum {

View File

@ -23,6 +23,7 @@
#include "lf.h" #include "lf.h"
#include "table.h" #include "table.h"
#include "ld-decode.h" #include "ld-decode.h"
#include "dumpf.h"
enum { enum {

View File

@ -25,6 +25,7 @@
#include "ld-decode.h" #include "ld-decode.h"
#include "ld-cache.h" #include "ld-cache.h"
#include "ld-insn.h" #include "ld-insn.h"
#include "dumpf.h"
#include "igen.h" #include "igen.h"

View File

@ -47,7 +47,7 @@ EXTRA_LIBRARIES += %D%/libigen.a
%C%_libigen_a_SOURCES = \ %C%_libigen_a_SOURCES = \
%D%/table.c \ %D%/table.c \
%D%/lf.c \ %D%/lf.c \
%D%/misc.c \ %D%/dumpf.c \
%D%/ld-decode.c \ %D%/ld-decode.c \
%D%/ld-cache.c \ %D%/ld-cache.c \
%D%/filter.c \ %D%/filter.c \
@ -58,7 +58,9 @@ EXTRA_LIBRARIES += %D%/libigen.a
%D%/gen-semantics.c \ %D%/gen-semantics.c \
%D%/gen-idecode.c \ %D%/gen-idecode.c \
%D%/gen-support.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_SOURCES = %D%/igen.c
%C%_igen_LDADD = %D%/libigen.a %C%_igen_LDADD = %D%/libigen.a

View File

@ -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;
}

View File

@ -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);

View File

@ -27,6 +27,7 @@
#include "misc.h" #include "misc.h"
#include "lf.h" #include "lf.h"
#include "table.h" #include "table.h"
#include "dumpf.h"
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>