public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH/committed 3/3] sim: ppc: unify igen filter modules
Date: Wed,  3 Jan 2024 03:37:51 -0500	[thread overview]
Message-ID: <20240103083751.12013-3-vapier@gentoo.org> (raw)
In-Reply-To: <20240103083751.12013-1-vapier@gentoo.org>

The common igen code was forked from the ppc long ago.  The filter
module is still pretty similar in API, so we can unfork them with
a little bit of effort.

The filter.c module is still here because of the unique it_is API.
The common igen code doesn't seem to have an equiv API as this only
operates on two strings and not an actual filter object, and it's
easy enough to leave behind to unfork the rest.
---
 sim/Makefile.in                    |  26 ++----
 sim/ppc/filter-ppc.c               |  41 +++++++++
 sim/ppc/{filter.h => filter-ppc.h} |  23 +----
 sim/ppc/filter.c                   | 141 -----------------------------
 sim/ppc/gen-icache.c               |   1 +
 sim/ppc/gen-idecode.c              |   1 +
 sim/ppc/gen-semantics.c            |   1 +
 sim/ppc/gen-support.c              |   1 +
 sim/ppc/igen.c                     |   2 +-
 sim/ppc/ld-insn.c                  |  13 +--
 sim/ppc/local.mk                   |   7 +-
 11 files changed, 67 insertions(+), 190 deletions(-)
 create mode 100644 sim/ppc/filter-ppc.c
 rename sim/ppc/{filter.h => filter-ppc.h} (73%)
 delete mode 100644 sim/ppc/filter.c

diff --git a/sim/ppc/filter-ppc.c b/sim/ppc/filter-ppc.c
new file mode 100644
index 000000000000..62a25d9333e6
--- /dev/null
+++ b/sim/ppc/filter-ppc.c
@@ -0,0 +1,41 @@
+/*  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 <string.h>
+
+#include "filter-ppc.h"
+
+int
+it_is(const char *flag,
+      const char *flags)
+{
+  int flag_len = strlen(flag);
+  while (*flags != '\0') {
+    if (!strncmp(flags, flag, flag_len)
+	&& (flags[flag_len] == ',' || flags[flag_len] == '\0'))
+      return 1;
+    while (*flags != ',') {
+      if (*flags == '\0')
+	return 0;
+      flags++;
+    }
+    flags++;
+  }
+  return 0;
+}
diff --git a/sim/ppc/filter.h b/sim/ppc/filter-ppc.h
similarity index 73%
rename from sim/ppc/filter.h
rename to sim/ppc/filter-ppc.h
index d4c659a1a162..d7df67428dae 100644
--- a/sim/ppc/filter.h
+++ b/sim/ppc/filter-ppc.h
@@ -11,28 +11,14 @@
     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/>.
- 
-    */
-
-
-typedef struct _filter filter;
-
 
-/* append the filter onto the end of the list */
-
-extern filter *new_filter
-(const char *filt,
- filter *filters);
-
-
-/* returns true if the flags are non empty and some are missing from the filter list */
+    */
 
-extern int is_filtered_out
-(const char *flags,
- filter *filters);
+#ifndef PPC_FILTER_H
+#define PPC_FILTER_H
 
 /* true if the flag is in the list */
 
@@ -40,3 +26,4 @@ extern int it_is
 (const char *flag,
  const char *flags);
 
+#endif /* PPC_FILTER_H */
diff --git a/sim/ppc/filter.c b/sim/ppc/filter.c
deleted file mode 100644
index c2f28ea7b898..000000000000
--- a/sim/ppc/filter.c
+++ /dev/null
@@ -1,141 +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 <stdio.h>
-
-#include <string.h>
-
-#include "misc.h"
-#include "filter.h"
-
-struct _filter {
-  char *flag;
-  filter *next;
-};
-
-
-filter *
-new_filter(const char *filt,
-	   filter *filters)
-{
-  while (strlen(filt) > 0) {
-    filter *new_filter;
-    /* break up the filt list */
-    const char *end = strchr(filt, ',');
-    const char *next;
-    int len;
-    if (end == NULL) {
-      end = strchr(filt, '\0');
-      next = end;
-    }
-    else {
-      next = end + 1;
-    }
-    len = end - filt;
-    /* add to filter list */
-    new_filter = ZALLOC(filter);
-    new_filter->flag = (char*)zalloc(len + 1);
-    strncpy(new_filter->flag, filt, len);
-    new_filter->next = filters;
-    filters = new_filter;
-    filt = next;
-  }
-  return filters;
-}
-
-
-int
-is_filtered_out(const char *flags,
-		filter *filters)
-{
-  while (strlen(flags) > 0) {
-    int present;
-    filter *filt = filters;
-    /* break the string up */
-    const char *end = strchr(flags, ',');
-    const char *next;
-    int len;
-    if (end == NULL) {
-      end = strchr(flags, '\0');
-      next = end;
-    }
-    else {
-      next = end + 1;
-    }
-    len = end - flags;
-    /* check that it is present */
-    present = 0;
-    filt = filters;
-    while (filt != NULL) {
-      if (strncmp(flags, filt->flag, len) == 0
-	  && strlen(filt->flag) == len) {
-	present = 1;
-	break;
-      }
-      filt = filt->next;
-    }
-    if (!present)
-      return 1;
-    flags = next;
-  }
-  return 0;
-}
-
-
-int
-it_is(const char *flag,
-      const char *flags)
-{
-  int flag_len = strlen(flag);
-  while (*flags != '\0') {
-    if (!strncmp(flags, flag, flag_len)
-	&& (flags[flag_len] == ',' || flags[flag_len] == '\0'))
-      return 1;
-    while (*flags != ',') {
-      if (*flags == '\0')
-	return 0;
-      flags++;
-    }
-    flags++;
-  }
-  return 0;
-}
-
-
-#ifdef MAIN
-int
-main(int argc, char **argv)
-{
-  filter *filters = NULL;
-  int i;
-  if (argc < 2) {
-    printf("Usage: filter <flags> <filter> ...\n");
-    exit (1);
-  }
-  /* load the filter up */
-  for (i = 2; i < argc; i++) 
-    filters = new_filter(argv[i], filters);
-  if (is_filtered_out(argv[1], filters))
-    printf("fail\n");
-  else
-    printf("pass\n");
-  return 0;
-}
-#endif
diff --git a/sim/ppc/gen-icache.c b/sim/ppc/gen-icache.c
index c10735c1764b..d9b76aded984 100644
--- a/sim/ppc/gen-icache.c
+++ b/sim/ppc/gen-icache.c
@@ -25,6 +25,7 @@
 #include "table.h"
 
 #include "filter.h"
+#include "filter-ppc.h"
 
 #include "ld-decode.h"
 #include "ld-cache.h"
diff --git a/sim/ppc/gen-idecode.c b/sim/ppc/gen-idecode.c
index 55c62906735a..bbb1cc980bc5 100644
--- a/sim/ppc/gen-idecode.c
+++ b/sim/ppc/gen-idecode.c
@@ -23,6 +23,7 @@
 #include "table.h"
 
 #include "filter.h"
+#include "filter-ppc.h"
 
 #include "ld-decode.h"
 #include "ld-cache.h"
diff --git a/sim/ppc/gen-semantics.c b/sim/ppc/gen-semantics.c
index 587080b5f64e..99f5fe847c30 100644
--- a/sim/ppc/gen-semantics.c
+++ b/sim/ppc/gen-semantics.c
@@ -24,6 +24,7 @@
 #include "lf-ppc.h"
 #include "table.h"
 #include "filter.h"
+#include "filter-ppc.h"
 
 #include "ld-decode.h"
 #include "ld-cache.h"
diff --git a/sim/ppc/gen-support.c b/sim/ppc/gen-support.c
index 0c2b28a42b07..5a192fdd0002 100644
--- a/sim/ppc/gen-support.c
+++ b/sim/ppc/gen-support.c
@@ -22,6 +22,7 @@
 #include "lf-ppc.h"
 #include "table.h"
 #include "filter.h"
+#include "filter-ppc.h"
 
 #include "ld-decode.h"
 #include "ld-cache.h"
diff --git a/sim/ppc/igen.c b/sim/ppc/igen.c
index 1e6951d8e66a..635030d4a9ea 100644
--- a/sim/ppc/igen.c
+++ b/sim/ppc/igen.c
@@ -480,7 +480,7 @@ main(int argc,
       ASSERT(hi_bit_nr == insn_bit_size-1 || hi_bit_nr == 0);
       break;
     case 'F':
-      filters = new_filter(optarg, filters);
+      filter_parse(&filters, optarg);
       break;
     case 'J':
       code &= ~generate_calls;
diff --git a/sim/ppc/ld-insn.c b/sim/ppc/ld-insn.c
index 6b5402676b30..ab1c43e7939d 100644
--- a/sim/ppc/ld-insn.c
+++ b/sim/ppc/ld-insn.c
@@ -22,6 +22,7 @@
 #include "lf.h"
 #include "table.h"
 #include "filter.h"
+#include "filter-ppc.h"
 #include "ld-decode.h"
 #include "ld-cache.h"
 #include "ld-insn.h"
@@ -219,7 +220,7 @@ parse_include_entry (table *file,
   if (file_entry->nr_fields < 4)
     ERROR ("Incorrect nr fields for include record\n");
   /* process it */
-  if (!is_filtered_out(file_entry->fields[include_flags], filters))
+  if (!is_filtered_out(filters, file_entry->fields[include_flags]))
     {
       table_push (file, includes,
                 file_entry->fields[include_path],
@@ -365,7 +366,7 @@ load_insn_table(const char *file_name,
     }
     else if ((it_is("function", file_entry->fields[insn_form])
 	      || it_is("internal", file_entry->fields[insn_form]))
-	     && !is_filtered_out(file_entry->fields[insn_flags], filters)) {
+	     && !is_filtered_out(filters, file_entry->fields[insn_flags])) {
       /* Ok, this is evil.  Need to convert a new style function into
          an old style function.  Construct an old style table and then
          copy it back.  */
@@ -409,13 +410,13 @@ load_insn_table(const char *file_name,
       model_table_insert_specific(table, file_entry, &model_data, &last_model_data);
     }
     else if (it_is("include", file_entry->fields[insn_form])
-             && !is_filtered_out(file_entry->fields[insn_flags], filters)) {
+             && !is_filtered_out(filters, file_entry->fields[insn_flags])) {
       parse_include_entry (file, file_entry, filters, includes);
     }
     else if ((it_is("cache", file_entry->fields[insn_form])
 	      || it_is("compute", file_entry->fields[insn_form])
 	      || it_is("scratch", file_entry->fields[insn_form]))
-	     && !is_filtered_out(file_entry->fields[insn_flags], filters)) {
+	     && !is_filtered_out(filters, file_entry->fields[insn_flags])) {
       append_cache_rule (cache_rules,
 			 file_entry->fields[insn_form], /* type */
 			 file_entry->fields[cache_name],
@@ -427,7 +428,7 @@ load_insn_table(const char *file_name,
     else {
       insn_fields *fields;
       /* skip instructions that aren't relevant to the mode */
-      if (is_filtered_out(file_entry->fields[insn_flags], filters)) {
+      if (is_filtered_out(filters, file_entry->fields[insn_flags])) {
 	fprintf(stderr, "Dropping %s - %s\n",
 		file_entry->fields[insn_name],
 		file_entry->fields[insn_flags]);
@@ -982,7 +983,7 @@ main(int argc, char **argv)
   if (argc != 5)
     ERROR("Usage: insn <filter> <hi-bit-nr> <decode-table> <insn-table>\n");
 
-  filters = new_filter(argv[1], filters);
+  filter_parse(&filters, argv[1]);
   hi_bit_nr = a2i(argv[2]);
   ASSERT(hi_bit_nr < insn_bit_size);
   decode_rules = load_decode_table(argv[3], hi_bit_nr);
diff --git a/sim/ppc/local.mk b/sim/ppc/local.mk
index d872014d1b56..3f495cb44c0b 100644
--- a/sim/ppc/local.mk
+++ b/sim/ppc/local.mk
@@ -104,7 +104,7 @@ EXTRA_LIBRARIES += %D%/libigen.a
 	%D%/dumpf.c \
 	%D%/ld-decode.c \
 	%D%/ld-cache.c \
-	%D%/filter.c \
+	%D%/filter-ppc.c \
 	%D%/ld-insn.c \
 	%D%/gen-model.c \
 	%D%/gen-itable.c \
@@ -113,6 +113,7 @@ EXTRA_LIBRARIES += %D%/libigen.a
 	%D%/gen-idecode.c \
 	%D%/gen-support.c
 %C%_libigen_a_LIBADD = \
+	igen/filter.o \
 	igen/filter_host.o \
 	igen/lf.o \
 	igen/misc.o
@@ -199,9 +200,6 @@ $(%C%_libigen_a_OBJECTS) $(%C%_igen_OBJECTS): %D%/%.o: %D%/%.c
 %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
 
@@ -213,7 +211,6 @@ $(%C%_libigen_a_OBJECTS) $(%C%_igen_OBJECTS): %D%/%.o: %D%/%.c
 
 %C%_IGEN_TOOLS = \
 	$(PPC_IGEN) \
-	%D%/filter \
 	%D%/ld-cache \
 	%D%/ld-decode \
 	%D%/ld-insn
-- 
2.43.0


      parent reply	other threads:[~2024-01-03  8:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03  8:37 [PATCH/committed 1/3] sim: igen: clean up headers a bit Mike Frysinger
2024-01-03  8:37 ` [PATCH/committed 2/3] sim: ppc: unify igen line number output modules Mike Frysinger
2024-01-03  8:37 ` Mike Frysinger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240103083751.12013-3-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).