public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level
@ 2024-01-01 23:22 Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename Mike Frysinger
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

This simplifies the build a bit (especially for deps in port subdirs),
and avoids recursive make.  This in turn speeds up the build, and lets
us reuse existing build-time vs host-time logic from Makefile.am.
---
 sim/Makefile.in     | 354 ++++++++++++++++++++++++++++++++------------
 sim/ppc/Makefile.in |  60 +-------
 sim/ppc/local.mk    |  64 +++++++-
 3 files changed, 325 insertions(+), 153 deletions(-)

diff --git a/sim/ppc/Makefile.in b/sim/ppc/Makefile.in
index ee8fb0462eb5..f7c37cc68f79 100644
--- a/sim/ppc/Makefile.in
+++ b/sim/ppc/Makefile.in
@@ -88,7 +88,6 @@ BUILD_CFLAGS	= $(CFLAGS_FOR_BUILD) $(INCLUDES) $(WARN_CFLAGS)
 
 LIBS = $(COMMON_LIBS) @LIBS@ $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
 
-COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS)
 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
 
 IGEN_OPCODE_RULES = @sim_opcode@
@@ -616,63 +615,6 @@ tmp-igen: igen $(srcdir)/powerpc.igen $(srcdir)/altivec.igen $(srcdir)/e500.igen
 $(TARGETLIB): tmp-igen
 itable.h itable.c icache.h icache.c idecode.h idecode.c semantics.h semantics.c model.h model.c support.h support.c: tmp-igen
 
-igen: igen.o table.o lf.o misc.o filter_host.o ld-decode.o ld-cache.o filter.o ld-insn.o gen-model.o gen-itable.o gen-icache.o gen-semantics.o gen-idecode.o gen-support.o
-	$(ECHO_CCLD) $(LINK_FOR_BUILD) igen.o table.o lf.o misc.o filter_host.o ld-decode.o ld-cache.o filter.o ld-insn.o gen-model.o gen-itable.o gen-icache.o gen-semantics.o gen-idecode.o gen-support.o
-
-filter_host.o: filter_host.c $(CONFIG_H) $(FILTER_FILENAME_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/filter_host.c
-
-table.o: table.c $(CONFIG_H) $(MISC_H) $(LF_H) $(TABLE_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/table.c
-
-lf.o: lf.c $(CONFIG_H) $(MISC_H) $(LF_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/lf.c
-
-filter.o: filter.c $(CONFIG_H) $(MISC_H) $(FILTER_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/filter.c
-tmp-filter: filter.c $(MISC_H) misc.o
-	$(ECHO_CCLD) $(LINK_FOR_BUILD) -DMAIN $(srcdir)/filter.c misc.o
-
-ld-decode.o: ld-decode.c $(MISC_H) $(LF_H) $(TABLE_H) $(LD_DECODE_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/ld-decode.c
-tmp-ld-decode: ld-decode.c misc.o lf.o table.o filter_host.o 
-	$(ECHO_CCLD) $(LINK_FOR_BUILD) -DMAIN $(srcdir)/ld-decode.c misc.o lf.o table.o filter_host.o
-
-ld-cache.o: ld-cache.c $(MISC_H) $(LF_H) $(TABLE_H) $(LD_CACHE_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/ld-cache.c
-tmp-ld-cache: ld-cache.c misc.o lf.o table.o filter_host.o 
-	$(ECHO_CCLD) $(LINK_FOR_BUILD) -DMAIN $(srcdir)/ld-cache.c misc.o lf.o table.o filter_host.o
-
-ld-insn.o: ld-insn.c $(MISC_H) $(LF_H) $(TABLE_H) $(FILTER_H) $(LD_DECODE_H) $(LD_CACHE_H) $(LD_INSN_H) $(IGEN_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/ld-insn.c
-tmp-ld-insn: ld-insn.c ld-cache.o misc.o lf.o table.o ld-decode.o filter_host.o filter.o
-	$(ECHO_CCLD) $(LINK_FOR_BUILD) -DMAIN $(srcdir)/ld-insn.c ld-cache.o misc.o lf.o table.o ld-decode.o filter_host.o filter.o
-
-gen-model.o: gen-model.c $(MISC_H) $(LF_H) $(TABLE_H) $(FILTER_H) $(LD_CACHE_H) $(LD_DECODE_H) $(LD_INSN_H) $(GEN_MODEL_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/gen-model.c
-
-gen-itable.o: gen-itable.c $(MISC_H) $(LF_H) $(TABLE_H) $(FILTER_H) $(LD_CACHE_H) $(LD_DECODE_H) $(LD_INSN_H) $(IGEN_H) $(GEN_ITABLE_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/gen-itable.c
-
-gen-icache.o: gen-icache.c $(MISC_H) $(LF_H) $(TABLE_H) $(FILTER_H) $(LD_DECODE_H) $(LD_CACHE_H) $(LD_INSN_H) $(IGEN_H) $(GEN_SEMANTICS_H) $(GEN_IDECODE_H) $(GEN_ICACHE_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/gen-icache.c
-
-gen-semantics.o: gen-semantics.c $(MISC_H) $(LF_H) $(TABLE_H) $(FILTER_H) $(LD_DECODE_H) $(LD_CACHE_H) $(LD_INSN_H) $(IGEN_H) $(GEN_SEMANTICS_H) $(GEN_ICACHE_H) $(GEN_IDECODE_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/gen-semantics.c
-
-gen-idecode.o: gen-idecode.c $(MISC_H) $(LF_H) $(TABLE_H) $(FILTER_H) $(LD_DECODE_H) $(LD_CACHE_H) $(LD_INSN_H) $(IGEN_H) $(GEN_IDECODE_H) $(GEN_ICACHE_H) $(GEN_SEMANTICS_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/gen-idecode.c
-
-gen-support.o: gen-support.c $(MISC_H) $(LF_H) $(TABLE_H) $(FILTER_H) $(LD_DECODE_H) $(LD_CACHE_H) $(LD_INSN_H) $(IGEN_H) $(GEN_SEMANTICS_H) $(GEN_SUPPORT_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/gen-support.c
-
-igen.o: igen.c $(MISC_H) $(LF_H) $(TABLE_H) $(CONFIG_H) $(FILTER_H) $(LD_CACHE_H) $(LD_DECODE_H) $(LD_INSN_H) $(IGEN_H) $(GEN_MODEL_H) $(GEN_ICACHE_H) $(GEN_ITABLE_H) $(GEN_IDECODE_H) $(GEN_SEMANTICS_H) $(GEN_SUPPORT_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/igen.c
-
-misc.o: misc.c $(CONFIG_H) $(MISC_H)
-	$(ECHO_CC) $(COMPILE_FOR_BUILD) -c $(srcdir)/misc.c
-
-
 
 # real hardware
 hw.c hw.h: tmp-hw; @true
@@ -762,7 +704,7 @@ TAGS: $(BUILT_SRC)
 	etags $(srcdir)/*.h $(srcdir)/*.c $(BUILT_SRC)
 
 clean mostlyclean:
-	rm -f tmp-* *.[oasi] core igen $(BUILT_SRC_WO_CONFIG)
+	rm -f tmp-* *.[oasi] core $(BUILT_SRC_WO_CONFIG)
 
 distclean realclean: clean
 	rm -f TAGS Makefile config.cache config.status config.h defines.h stamp-h config.log
diff --git a/sim/ppc/local.mk b/sim/ppc/local.mk
index 9f55629dfe16..915642293542 100644
--- a/sim/ppc/local.mk
+++ b/sim/ppc/local.mk
@@ -28,7 +28,7 @@ SIM_ALL_RECURSIVE_DEPS += common/libcommon.a
 	$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
 
 ## Helper targets for running make from the top-level due to run's sis.o.
-%D%/%.o: %D%/%.c | %D%/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
+%D%/main.o: %D%/%.o: %D%/%.c | %D%/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
 	$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
 
 noinst_PROGRAMS += %D%/run
@@ -43,5 +43,67 @@ noinst_PROGRAMS += %D%/run
 	$(AM_V_at)$(SHELL) $(srcroot)/move-if-change $@.tmp $(srcdir)/%D%/spreg.h
 	$(AM_V_at)touch $(srcdir)/%D%/spreg.h
 
+EXTRA_LIBRARIES += %D%/libigen.a
+%C%_libigen_a_SOURCES = \
+	%D%/table.c \
+	%D%/lf.c \
+	%D%/misc.c \
+	%D%/filter_host.c \
+	%D%/ld-decode.c \
+	%D%/ld-cache.c \
+	%D%/filter.c \
+	%D%/ld-insn.c \
+	%D%/gen-model.c \
+	%D%/gen-itable.c \
+	%D%/gen-icache.c \
+	%D%/gen-semantics.c \
+	%D%/gen-idecode.c \
+	%D%/gen-support.c
+
+%C%_igen_SOURCES = %D%/igen.c
+%C%_igen_LDADD = %D%/libigen.a
+
+PPC_IGEN = %D%/igen$(EXEEXT)
+
+SIM_ALL_RECURSIVE_DEPS += $(PPC_IGEN)
+
+## These rules are copied from automake, but tweaked to use FOR_BUILD variables.
+%D%/libigen.a: $(%C%_libigen_a_OBJECTS) $(%C%_libigen_a_DEPENDENCIES) $(EXTRA_%C%_libigen_a_DEPENDENCIES) %D%/$(am__dirstamp)
+	$(AM_V_at)-rm -f $@
+	$(AM_V_AR)$(AR_FOR_BUILD) $(ARFLAGS) $@ $(%C%_libigen_a_OBJECTS) $(%C%_libigen_a_LIBADD)
+	$(AM_V_at)$(RANLIB_FOR_BUILD) $@
+
+## igen is a build-time only tool.  Override the default rules for it.
+%D%/igen$(EXEEXT): $(%C%_igen_OBJECTS) $(%C%_igen_DEPENDENCIES) %D%/$(am__dirstamp)
+	$(AM_V_CCLD)$(LINK_FOR_BUILD) $(%C%_igen_OBJECTS) $(%C%_igen_LDADD)
+
+$(%C%_libigen_a_OBJECTS) $(%C%_igen_OBJECTS): %D%/%.o: %D%/%.c
+	$(AM_V_CC)$(COMPILE_FOR_BUILD) -c $< -o $@
+
+## Build some of the files in standalone mode for developers of igen itself.
+%D%/%-main.o: %D%/%.c
+	$(AM_V_CC)$(COMPILE_FOR_BUILD) -DMAIN -c $< -o $@
+
+%C%_filter_SOURCES =
+%C%_filter_LDADD = %D%/filter-main.o %D%/libigen.a
+
+%C%_ld_cache_SOURCES =
+%C%_ld_cache_LDADD = %D%/ld-cache-main.o %D%/libigen.a
+
+%C%_ld_decode_SOURCES =
+%C%_ld_decode_LDADD = %D%/ld-decode-main.o %D%/libigen.a
+
+%C%_ld_insn_SOURCES =
+%C%_ld_insn_LDADD = %D%/ld-insn-main.o %D%/libigen.a
+
+%C%_IGEN_TOOLS = \
+	$(PPC_IGEN) \
+	%D%/filter \
+	%D%/ld-cache \
+	%D%/ld-decode \
+	%D%/ld-insn
+EXTRA_PROGRAMS += $(%C%_IGEN_TOOLS)
+MOSTLYCLEANFILES += $(%C%_IGEN_TOOLS) %D%/libigen.a
+
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/BUGS %D%/INSTALL %D%/README %D%/RUN
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename
  2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
@ 2024-01-01 23:22 ` Mike Frysinger
  2024-01-09 14:34   ` Tom Tromey
  2024-01-01 23:22 ` [PATCH/committed 3/8] sim: ppc: unify igen filter_filename implementations Mike Frysinger
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

The lbasename function from libiberty provides the same API as this
custom function.  The common/ code already made the switch, so make
the same change to the ppc code to avoid target duplication.
---
 sim/ppc/Makefile.in | 11 ++---------
 sim/ppc/debug.h     | 12 ++++++------
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/sim/ppc/Makefile.in b/sim/ppc/Makefile.in
index f7c37cc68f79..b8e7fbfd45f1 100644
--- a/sim/ppc/Makefile.in
+++ b/sim/ppc/Makefile.in
@@ -198,8 +198,7 @@ CPU_H = \
 	cpu.c
 
 DEBUG_H = \
-	debug.h \
-	$(FILTER_FILENAME_H)
+	debug.h
 
 DEVICE_H = \
 	device.h
@@ -240,9 +239,6 @@ EMUL_UNIX_H = \
 EVENTS_H = \
 	events.h
 
-FILTER_FILENAME_H = \
-	filter_filename.h
-
 FILTER_H = \
 	filter.h
 
@@ -304,8 +300,7 @@ LF_H = \
 
 MISC_H = \
 	misc.h \
-	$(CONFIG_H) \
-	$(FILTER_FILENAME_H)
+	$(CONFIG_H)
 
 MON_H = \
 	mon.h \
@@ -466,7 +461,6 @@ COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/%)
 #       first
 LIB_OBJ = \
 	debug.o \
-	filter_filename.o \
 	bits.o \
 	sim-endian.o \
 	os_emul.o \
@@ -519,7 +513,6 @@ psim.o: psim.c $(CPU_H) $(IDECODE_H) $(OPTIONS_H) $(TREE_H) $(BFD_H)
 bits.o: bits.c $(BASICS_H)
 
 debug.o: debug.c $(CONFIG_H) $(BASICS_H)
-filter_filename.o: filter_filename.c $(CONFIG_H) $(FILTER_FILENAME_H)
 
 sim-endian.o: sim-endian.c $(CONFIG_H) $(BASICS_H) $(SIM_ENDIAN_N_H)
 
diff --git a/sim/ppc/debug.h b/sim/ppc/debug.h
index 28e42c7bb753..e221ce553d36 100644
--- a/sim/ppc/debug.h
+++ b/sim/ppc/debug.h
@@ -21,7 +21,7 @@
 #ifndef _DEBUG_H_
 #define _DEBUG_H_
 
-#include "filter_filename.h"
+#include "libiberty.h"
 
 typedef enum {
   trace_invalid,
@@ -87,7 +87,7 @@ extern int ppc_trace[nr_trace_options];
 do { \
   if (WITH_TRACE) { \
     if (ppc_trace[OBJECT]) { \
-      sim_io_printf_filtered("%s:%d: ", filter_filename(__FILE__), __LINE__); \
+      sim_io_printf_filtered("%s:%d: ", lbasename(__FILE__), __LINE__); \
       sim_io_printf_filtered ARGS; \
     } \
   } \
@@ -113,7 +113,7 @@ do { \
 	|| ppc_trace[trace_##OBJECT##_device] \
 	|| trace_device) { \
       sim_io_printf_filtered("%s:%d:%s:%s%s ",					\
-			     filter_filename(__FILE__), __LINE__, #OBJECT, \
+			     lbasename(__FILE__), __LINE__, #OBJECT, \
 			     trace_device ? device_path(me) : "",	\
 			     trace_device ? ":" : "");			\
       sim_io_printf_filtered ARGS; \
@@ -131,7 +131,7 @@ do { \
 	|| ppc_trace[trace_##OBJECT##_device] \
 	|| trace_device) { \
       sim_io_printf_filtered("%s:%d:%s:%s%s ", \
-			     filter_filename(__FILE__), __LINE__, #OBJECT, \
+			     lbasename(__FILE__), __LINE__, #OBJECT, \
 			     trace_device ? device_path(_me) : "",	\
 			     trace_device ? ":" : "");			\
       sim_io_printf_filtered ARGS; \
@@ -144,7 +144,7 @@ do { \
 do { \
   if (WITH_TRACE) { \
     if (ppc_trace[trace_##OBJECT##_package]) { \
-      sim_io_printf_filtered("%s:%d:%s: ", filter_filename(__FILE__), __LINE__, #OBJECT); \
+      sim_io_printf_filtered("%s:%d:%s: ", lbasename(__FILE__), __LINE__, #OBJECT); \
       sim_io_printf_filtered ARGS; \
     } \
   } \
@@ -156,7 +156,7 @@ do { \
   if (WITH_ASSERT) { \
     if (!(EXPRESSION)) { \
       error("%s:%d: assertion failed - %s\n", \
-	    filter_filename(__FILE__), __LINE__, #EXPRESSION); \
+	    lbasename(__FILE__), __LINE__, #EXPRESSION); \
     } \
   } \
 } while (0)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH/committed 3/8] sim: ppc: unify igen filter_filename implementations
  2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename Mike Frysinger
@ 2024-01-01 23:22 ` Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 4/8] sim: igen: minor constify logic Mike Frysinger
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

Now that both igen implementations are in the top-level, we can unify
the filter_filename implementation between them since they're the same
(literally the same code).
---
 sim/Makefile.in           | 11 ++++-------
 sim/ppc/Makefile.in       |  3 +--
 sim/ppc/filter_filename.c | 35 -----------------------------------
 sim/ppc/filter_filename.h | 26 --------------------------
 sim/ppc/filter_host.c     | 18 ------------------
 sim/ppc/local.mk          |  4 ++--
 sim/ppc/misc.h            |  2 +-
 7 files changed, 8 insertions(+), 91 deletions(-)
 delete mode 100644 sim/ppc/filter_filename.c
 delete mode 100644 sim/ppc/filter_filename.h
 delete mode 100644 sim/ppc/filter_host.c

diff --git a/sim/ppc/Makefile.in b/sim/ppc/Makefile.in
index b8e7fbfd45f1..fc9e32453666 100644
--- a/sim/ppc/Makefile.in
+++ b/sim/ppc/Makefile.in
@@ -409,8 +409,7 @@ BUILT_SRC_WO_CONFIG = \
 	model.h model.c \
 	support.h support.c \
 	pk.h \
-	hw.h hw.c \
-	filter_host.c
+	hw.h hw.c
 
 BUILT_SRC = \
 	$(BUILT_SRC_WO_CONFIG) \
diff --git a/sim/ppc/filter_filename.c b/sim/ppc/filter_filename.c
deleted file mode 100644
index fb2457c0b2c2..000000000000
--- a/sim/ppc/filter_filename.c
+++ /dev/null
@@ -1,35 +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/>.
- 
-    */
-
-#include "filter_filename.h"
-
-/* Shorten traces by eliminating the directory component to filenames.  */
-extern const char *
-filter_filename (const char *filename)
-{
-  const char *p = filename;
-  const char *last = filename;
-  int ch;
-
-  while ((ch = *p++) != '\0' && ch != ':')
-    if (ch == '/')
-      last = p;
-
-  return last;
-}
diff --git a/sim/ppc/filter_filename.h b/sim/ppc/filter_filename.h
deleted file mode 100644
index 5c42e284cef2..000000000000
--- a/sim/ppc/filter_filename.h
+++ /dev/null
@@ -1,26 +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/>.
- 
-    */
-
-#ifndef _FILTER_FILENAME_H
-#define _FILTER_FILENAME_H
-
-/* Remove directory part from filename */
-extern const char *
-filter_filename(const char *filename);
-#endif
diff --git a/sim/ppc/filter_host.c b/sim/ppc/filter_host.c
deleted file mode 100644
index 87d9bbc2e222..000000000000
--- a/sim/ppc/filter_host.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Shim to share files between build & host programs.
-
-   Copyright (C) 2024 Free Software Foundation, Inc.
-
-   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 "filter_filename.c"
diff --git a/sim/ppc/local.mk b/sim/ppc/local.mk
index 915642293542..c72668c69c46 100644
--- a/sim/ppc/local.mk
+++ b/sim/ppc/local.mk
@@ -48,7 +48,6 @@ EXTRA_LIBRARIES += %D%/libigen.a
 	%D%/table.c \
 	%D%/lf.c \
 	%D%/misc.c \
-	%D%/filter_host.c \
 	%D%/ld-decode.c \
 	%D%/ld-cache.c \
 	%D%/filter.c \
@@ -59,6 +58,7 @@ 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%_igen_SOURCES = %D%/igen.c
 %C%_igen_LDADD = %D%/libigen.a
@@ -78,7 +78,7 @@ SIM_ALL_RECURSIVE_DEPS += $(PPC_IGEN)
 	$(AM_V_CCLD)$(LINK_FOR_BUILD) $(%C%_igen_OBJECTS) $(%C%_igen_LDADD)
 
 $(%C%_libigen_a_OBJECTS) $(%C%_igen_OBJECTS): %D%/%.o: %D%/%.c
-	$(AM_V_CC)$(COMPILE_FOR_BUILD) -c $< -o $@
+	$(AM_V_CC)$(COMPILE_FOR_BUILD) -I$(srcdir)/igen -I$(srcdir)/%D% -c $< -o $@
 
 ## Build some of the files in standalone mode for developers of igen itself.
 %D%/%-main.o: %D%/%.c
diff --git a/sim/ppc/misc.h b/sim/ppc/misc.h
index a9e97a003e5b..0073467863ad 100644
--- a/sim/ppc/misc.h
+++ b/sim/ppc/misc.h
@@ -26,7 +26,7 @@
 #include <stdlib.h>
 
 #include "ansidecl.h"
-#include "filter_filename.h"
+#include "filter_host.h"
 
 extern void error (const char *msg, ...)
   ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH/committed 4/8] sim: igen: minor constify logic
  2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 3/8] sim: ppc: unify igen filter_filename implementations Mike Frysinger
@ 2024-01-01 23:22 ` Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 5/8] sim: ppc: rename igen max_insn_bit_size Mike Frysinger
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

Copy some improvements from the ppc igen code.
---
 sim/igen/misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sim/igen/misc.c b/sim/igen/misc.c
index a083f6d1bbd2..fface6f66d5a 100644
--- a/sim/igen/misc.c
+++ b/sim/igen/misc.c
@@ -215,8 +215,8 @@ name2i (const char *names, const name_map * map)
   while (*name != '\0')
     {
       /* find our name */
-      char *end = strchr (name, ',');
-      char *next;
+      const char *end = strchr (name, ',');
+      const char *next;
       unsigned len;
       if (end == NULL)
 	{
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH/committed 5/8] sim: ppc: rename igen max_insn_bit_size
  2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
                   ` (2 preceding siblings ...)
  2024-01-01 23:22 ` [PATCH/committed 4/8] sim: igen: minor constify logic Mike Frysinger
@ 2024-01-01 23:22 ` Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 6/8] sim: igen: extend error to take arguments Mike Frysinger
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

We want to avoid conflicts with the common igen enums.  This should
get migrated over to the common parsing logic, but for now, switch
the name to avoid redefinition.
---
 sim/ppc/igen.c    | 4 ++--
 sim/ppc/ld-insn.c | 2 +-
 sim/ppc/ld-insn.h | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sim/ppc/igen.c b/sim/ppc/igen.c
index 4de7469b4e36..61afa491bb9e 100644
--- a/sim/ppc/igen.c
+++ b/sim/ppc/igen.c
@@ -40,7 +40,7 @@
 #include "gen-support.h"
 
 int hi_bit_nr;
-int insn_bit_size = max_insn_bit_size;
+int insn_bit_size = ppc_max_insn_bit_size;
 
 igen_code code = generate_calls;
 
@@ -472,7 +472,7 @@ main(int argc,
       break;
     case 'B':
       insn_bit_size = a2i(optarg);
-      ASSERT(insn_bit_size > 0 && insn_bit_size <= max_insn_bit_size
+      ASSERT(insn_bit_size > 0 && insn_bit_size <= ppc_max_insn_bit_size
 	     && (hi_bit_nr == insn_bit_size-1 || hi_bit_nr == 0));
       break;
     case 'H':
diff --git a/sim/ppc/ld-insn.c b/sim/ppc/ld-insn.c
index a94464d44bbf..5cb72b226226 100644
--- a/sim/ppc/ld-insn.c
+++ b/sim/ppc/ld-insn.c
@@ -966,7 +966,7 @@ dump_insn_table(insn_table *table,
   }
 }
 
-int insn_bit_size = max_insn_bit_size;
+int insn_bit_size = ppc_max_insn_bit_size;
 int hi_bit_nr;
 int generate_expanded_instructions;
 
diff --git a/sim/ppc/ld-insn.h b/sim/ppc/ld-insn.h
index 52baeaa2d846..562e6d8742b4 100644
--- a/sim/ppc/ld-insn.h
+++ b/sim/ppc/ld-insn.h
@@ -56,7 +56,7 @@
 /* Global constants */
 
 enum {
-  max_insn_bit_size = 32,
+  ppc_max_insn_bit_size = 32,
 };
 
 
@@ -77,7 +77,7 @@ struct _insn_field {
 
 typedef struct _insn_fields insn_fields;
 struct _insn_fields {
-  insn_field *bits[max_insn_bit_size];
+  insn_field *bits[ppc_max_insn_bit_size];
   insn_field *first;
   insn_field *last;
   unsigned value;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH/committed 6/8] sim: igen: extend error to take arguments
  2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
                   ` (3 preceding siblings ...)
  2024-01-01 23:22 ` [PATCH/committed 5/8] sim: ppc: rename igen max_insn_bit_size Mike Frysinger
@ 2024-01-01 23:22 ` Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 7/8] sim: ppc: rework igen error to match common Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 8/8] sim: ppc: merge misc igen APIs Mike Frysinger
  6 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

The ppc igen error helper allows arbitrary printf calls, so extend
the common one to do the same.
---
 sim/igen/misc.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sim/igen/misc.h b/sim/igen/misc.h
index eff8a203cabf..45610558a262 100644
--- a/sim/igen/misc.h
+++ b/sim/igen/misc.h
@@ -56,12 +56,12 @@ extern error_func warning;
 extern error_func notify;
 
 
-#define ERROR(EXPRESSION) \
+#define ERROR(EXPRESSION, args...) \
 do { \
   line_ref line; \
   line.file_name = filter_filename (__FILE__); \
   line.line_nr = __LINE__; \
-  error (&line, EXPRESSION "\n"); \
+  error (&line, EXPRESSION "\n", ## args); \
 } while (0)
 
 #define ASSERT(EXPRESSION) \
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH/committed 7/8] sim: ppc: rework igen error to match common
  2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
                   ` (4 preceding siblings ...)
  2024-01-01 23:22 ` [PATCH/committed 6/8] sim: igen: extend error to take arguments Mike Frysinger
@ 2024-01-01 23:22 ` Mike Frysinger
  2024-01-01 23:22 ` [PATCH/committed 8/8] sim: ppc: merge misc igen APIs Mike Frysinger
  6 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

Switch to an ERROR macro and tweak the error signature to match the
common igen version in preparation for merging the two implementations.
---
 sim/ppc/gen-idecode.c |  2 +-
 sim/ppc/gen-model.c   |  4 ++--
 sim/ppc/igen.c        |  4 ++--
 sim/ppc/ld-cache.c    |  2 +-
 sim/ppc/ld-decode.c   |  2 +-
 sim/ppc/ld-insn.c     | 14 +++++++-------
 sim/ppc/lf.c          |  2 +-
 sim/ppc/misc.c        |  8 ++++----
 sim/ppc/misc.h        |  7 +++++--
 sim/ppc/table.c       |  2 +-
 10 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/sim/ppc/gen-idecode.c b/sim/ppc/gen-idecode.c
index 256ba7586b89..5d2253500594 100644
--- a/sim/ppc/gen-idecode.c
+++ b/sim/ppc/gen-idecode.c
@@ -1543,6 +1543,6 @@ gen_idecode_c(lf *file,
 
   }
   else {
-    error("Something is wrong!\n");
+    ERROR("Something is wrong!\n");
   }
 }
diff --git a/sim/ppc/gen-model.c b/sim/ppc/gen-model.c
index a8bcc66e9f14..11a533b2d93a 100644
--- a/sim/ppc/gen-model.c
+++ b/sim/ppc/gen-model.c
@@ -52,7 +52,7 @@ model_c_or_h_function(insn_table *entry,
 {
   if (function->fields[function_type] == NULL
       || function->fields[function_type][0] == '\0') {
-    error("Model function type not specified for %s", function->fields[function_name]);
+    ERROR("Model function type not specified for %s", function->fields[function_name]);
   }
   lf_printf(file, "\n");
   lf_print_function_type(file, function->fields[function_type], prefix, " ");
@@ -203,7 +203,7 @@ model_c_function(insn_table *table,
 {
   if (function->fields[function_type] == NULL
       || function->fields[function_type][0] == '\0') {
-    error("Model function return type not specified for %s", function->fields[function_name]);
+    ERROR("Model function return type not specified for %s", function->fields[function_name]);
   }
   else {
     lf_printf(file, "\n");
diff --git a/sim/ppc/igen.c b/sim/ppc/igen.c
index 61afa491bb9e..264d8086874a 100644
--- a/sim/ppc/igen.c
+++ b/sim/ppc/igen.c
@@ -450,7 +450,7 @@ main(int argc,
 		  code &= ~generate_with_icache;
                 break;
               default:
-		error ("Expecting -Ggen-icache or -Ggen-icache=<N>\n");
+		ERROR ("Expecting -Ggen-icache or -Ggen-icache=<N>\n");
               }
           }
 	  break;
@@ -568,7 +568,7 @@ main(int argc,
       real_file_name = NULL;
       break;
     default:
-      error("unknown option\n");
+      ERROR("unknown option\n");
     }
   }
   return 0;
diff --git a/sim/ppc/ld-cache.c b/sim/ppc/ld-cache.c
index 9a78f908b05a..a5d101daf6c9 100644
--- a/sim/ppc/ld-cache.c
+++ b/sim/ppc/ld-cache.c
@@ -115,7 +115,7 @@ main(int argc, char **argv)
 {
   cache_table *rules;
   if (argc != 3)
-    error("Usage: cache <cache-file> <hi-bit-nr>\n");
+    ERROR("Usage: cache <cache-file> <hi-bit-nr>\n");
   rules = load_cache_table(argv[1], a2i(argv[2]));
   dump_cache_rules(rules, 0);
   return 0;
diff --git a/sim/ppc/ld-decode.c b/sim/ppc/ld-decode.c
index 63c2c2e53d40..a631645f54de 100644
--- a/sim/ppc/ld-decode.c
+++ b/sim/ppc/ld-decode.c
@@ -143,7 +143,7 @@ main(int argc, char **argv)
 {
   decode_table *rules;
   if (argc != 3)
-    error("Usage: decode <decode-file> <hi-bit-nr>\n");
+    ERROR("Usage: decode <decode-file> <hi-bit-nr>\n");
   rules = load_decode_table(argv[1], a2i(argv[2]));
   dump_decode_rules(rules, 0);
   return 0;
diff --git a/sim/ppc/ld-insn.c b/sim/ppc/ld-insn.c
index 5cb72b226226..c11b449a58c1 100644
--- a/sim/ppc/ld-insn.c
+++ b/sim/ppc/ld-insn.c
@@ -110,7 +110,7 @@ parse_insn_format(table_entry *entry,
 
     /* sanity check */
     if (!isdigit(*chp)) {
-      error("%s:%d: missing position field at `%s'\n",
+      ERROR("%s:%d: missing position field at `%s'\n",
 	    entry->file_name, entry->line_nr, chp);
     }
 
@@ -122,7 +122,7 @@ parse_insn_format(table_entry *entry,
     if (*chp == '.' && strlen_pos > 0)
       chp++;
     else {
-      error("%s:%d: missing field value at %s\n",
+      ERROR("%s:%d: missing field value at %s\n",
 	    entry->file_name, entry->line_nr, chp);
       break;
     }
@@ -137,7 +137,7 @@ parse_insn_format(table_entry *entry,
     if (*chp == ',')
       chp++;
     else if (*chp != '\0' || strlen_val == 0) {
-      error("%s:%d: missing field terminator at %s\n",
+      ERROR("%s:%d: missing field terminator at %s\n",
 	    entry->file_name, entry->line_nr, chp);
       break;
     }
@@ -216,7 +216,7 @@ parse_include_entry (table *file,
 {
   /* parse the include file_entry */
   if (file_entry->nr_fields < 4)
-    error ("Incorrect nr fields for include record\n");
+    ERROR ("Incorrect nr fields for include record\n");
   /* process it */
   if (!is_filtered_out(file_entry->fields[include_flags], filters))
     {
@@ -326,7 +326,7 @@ insn_table_insert_insn(insn_table *table,
     }
 
     if (!model_ptr)
-      error("%s:%d: machine model `%s' was not known about\n",
+      ERROR("%s:%d: machine model `%s' was not known about\n",
 	    file_entry->file_name, file_entry->line_nr, name);
   }
 
@@ -663,7 +663,7 @@ insn_table_find_opcode_field(insn *insns,
     curr_opcode->boolean_constant = rule->special_constant;
     break;
   default:
-    error("Something is going wrong\n");
+    ERROR("Something is going wrong\n");
   }
 
   return curr_opcode;
@@ -979,7 +979,7 @@ main(int argc, char **argv)
   cache_table *cache_rules = NULL;
 
   if (argc != 5)
-    error("Usage: insn <filter> <hi-bit-nr> <decode-table> <insn-table>\n");
+    ERROR("Usage: insn <filter> <hi-bit-nr> <decode-table> <insn-table>\n");
 
   filters = new_filter(argv[1], filters);
   hi_bit_nr = a2i(argv[2]);
diff --git a/sim/ppc/lf.c b/sim/ppc/lf.c
index 9a9d6151c6e8..9deb2d2bb523 100644
--- a/sim/ppc/lf.c
+++ b/sim/ppc/lf.c
@@ -274,7 +274,7 @@ lf_print__c_code(lf *file,
       chp++;
     }
     if (in_bit_field)
-      error("bit field paren miss match some where\n");
+      ERROR("bit field paren miss match some where\n");
     if (*chp == '\n') {
       nr += lf_putchr(file, '\n');
       chp++;
diff --git a/sim/ppc/misc.c b/sim/ppc/misc.c
index a281d62b0af1..9499101b6029 100644
--- a/sim/ppc/misc.c
+++ b/sim/ppc/misc.c
@@ -28,7 +28,7 @@
 #include <string.h>
 
 void
-error (const char *msg, ...)
+error (const void *line, const char *msg, ...)
 {
   va_list ap;
   va_start(ap, msg);
@@ -42,7 +42,7 @@ zalloc(long size)
 {
   void *memory = malloc(size);
   if (memory == NULL)
-    error("zalloc failed\n");
+    ERROR("zalloc failed\n");
   memset(memory, 0, size);
   return memory;
 }
@@ -186,7 +186,7 @@ name2i(const char *names,
   if (curr->i >= 0)
     return curr->i;
   else
-    error("%s contains no valid names\n", names);
+    ERROR("%s contains no valid names\n", names);
   return 0;
 }
 
@@ -199,6 +199,6 @@ i2name(const int i,
       return map->name;
     map++;
   }
-  error("map lookup failed for %d\n", i);
+  ERROR("map lookup failed for %d\n", i);
   return NULL;
 }
diff --git a/sim/ppc/misc.h b/sim/ppc/misc.h
index 0073467863ad..243d5c93605a 100644
--- a/sim/ppc/misc.h
+++ b/sim/ppc/misc.h
@@ -28,8 +28,11 @@
 #include "ansidecl.h"
 #include "filter_host.h"
 
-extern void error (const char *msg, ...)
-  ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
+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 { \
diff --git a/sim/ppc/table.c b/sim/ppc/table.c
index cb9a73aa8c49..0c5b6fcd925a 100644
--- a/sim/ppc/table.c
+++ b/sim/ppc/table.c
@@ -98,7 +98,7 @@ table_push (table *root,
       /* free (dup_name); */
       if (include->next == NULL)
 	{
-	  error ("Problem opening file `%s'\n", file_name);
+	  ERROR ("Problem opening file `%s'\n", file_name);
 	  perror (file_name);
 	  exit (1);
 	}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH/committed 8/8] sim: ppc: merge misc igen APIs
  2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
                   ` (5 preceding siblings ...)
  2024-01-01 23:22 ` [PATCH/committed 7/8] sim: ppc: rework igen error to match common Mike Frysinger
@ 2024-01-01 23:22 ` Mike Frysinger
  6 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-01 23:22 UTC (permalink / raw)
  To: gdb-patches

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

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>
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename
  2024-01-01 23:22 ` [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename Mike Frysinger
@ 2024-01-09 14:34   ` Tom Tromey
  2024-01-09 17:41     ` Mike Frysinger
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2024-01-09 14:34 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: gdb-patches

>>>>> "Mike" == Mike Frysinger <vapier@gentoo.org> writes:

Mike> The lbasename function from libiberty provides the same API as this
Mike> custom function.  The common/ code already made the switch, so make
Mike> the same change to the ppc code to avoid target duplication.

When updating and rebuilding in an existing tree, some patch -- I guess
probably this one, I didn't bisect -- caused a build failure in sim/ppc
because filter_filename was missing.  Removing sim/ppc/*.o and
rebuilding fixed it, but I suppose this means there is a missing
dependency somewhere.

Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename
  2024-01-09 14:34   ` Tom Tromey
@ 2024-01-09 17:41     ` Mike Frysinger
  0 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2024-01-09 17:41 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1519 bytes --]

On 09 Jan 2024 07:34, Tom Tromey wrote:
> >>>>> "Mike" == Mike Frysinger <vapier@gentoo.org> writes:
> 
> Mike> The lbasename function from libiberty provides the same API as this
> Mike> custom function.  The common/ code already made the switch, so make
> Mike> the same change to the ppc code to avoid target duplication.
> 
> When updating and rebuilding in an existing tree, some patch -- I guess
> probably this one, I didn't bisect -- caused a build failure in sim/ppc
> because filter_filename was missing.  Removing sim/ppc/*.o and
> rebuilding fixed it, but I suppose this means there is a missing
> dependency somewhere.

ppc/ used to generate a filter_host.c file in the output dir, and compile the
.o from that.  it switched to using the igen/filter_host.c in the source dir.
when i've migrated code like this, i haven't left behind clean rules to delete
files that only mattered to old builds since any new builds would never see
that stuff.  but it means bisect/incremental (re)builds across that timespan
might break.  i don't know what the general policy is in the tree for these
cases, but it seems like we just don't bother.

also a lot of sim rules rely on VPATH to locate sources.  e.g. the makefiles
write ppc/foo.c instead of $(srcdir)/ppc/foo.c.  the only time we really use
$(srcdir) is with generated files we commit to the tree.  i think this pattern
is standard in the binutils-gdb tree.  but it also contributes to incremental
(re)build failures like this.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-09 17:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-01 23:22 [PATCH/committed 1/8] sim: ppc: hoist igen compilation into top-level Mike Frysinger
2024-01-01 23:22 ` [PATCH/committed 2/8] sim: ppc: replace filter_filename with lbasename Mike Frysinger
2024-01-09 14:34   ` Tom Tromey
2024-01-09 17:41     ` Mike Frysinger
2024-01-01 23:22 ` [PATCH/committed 3/8] sim: ppc: unify igen filter_filename implementations Mike Frysinger
2024-01-01 23:22 ` [PATCH/committed 4/8] sim: igen: minor constify logic Mike Frysinger
2024-01-01 23:22 ` [PATCH/committed 5/8] sim: ppc: rename igen max_insn_bit_size Mike Frysinger
2024-01-01 23:22 ` [PATCH/committed 6/8] sim: igen: extend error to take arguments Mike Frysinger
2024-01-01 23:22 ` [PATCH/committed 7/8] sim: ppc: rework igen error to match common Mike Frysinger
2024-01-01 23:22 ` [PATCH/committed 8/8] sim: ppc: merge misc igen APIs Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).