From patchwork Mon Jan 1 23:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 83086 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A00473858436 for ; Mon, 1 Jan 2024 23:24:08 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 63943385841C for ; Mon, 1 Jan 2024 23:22:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63943385841C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 63943385841C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:ea4a:1:5054:ff:fec7:86e4 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704151361; cv=none; b=vEsJXjbsWRjgDbcC07ihgZNMh1dNuyq8ODRjXJvELpt0p5c+6mkC/XeqEHGs2R4m7xnojVMcd+v/e4vQCXi7/529c/p4/pOpEGYrbXE7Xo/ukdJiBMtF9DW5bNFP2ELufMDKNLzXZ0U92yqKEx2/4KHDvhRrML5215GNSycpgYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704151361; c=relaxed/simple; bh=+0MnCdxxEpU6YyHLzU+03zNDpQeX3N/cb6nwimKw4b8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EhZyt9uMuuUt9xvjg0VvsQ6txSO4jCQs8EMkKIAu+mRFCVND6R3nj2PE5VyKSIBlW/cSKAym30yUziyBQIk/cr7abPkcvea4o7g8h8IPI4uSVNIRTF9azLp8Iyk3446gjVJdZ8DjTrOa2CX5LrAuKSiNY/3yNSCz7oj2cw46bVU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by smtp.gentoo.org (Postfix, from userid 559) id 27D0D3406C2; Mon, 1 Jan 2024 23:22:38 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH/committed 8/8] sim: ppc: merge misc igen APIs Date: Mon, 1 Jan 2024 18:22:19 -0500 Message-ID: <20240101232219.3003-8-vapier@gentoo.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240101232219.3003-1-vapier@gentoo.org> References: <20240101232219.3003-1-vapier@gentoo.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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 + + 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 . + + */ + +/* TODO: Convert callers to lf_printf like common igen/. */ + +#include +#include +#include + +#include "dumpf.h" + +#include +#include + +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 + + 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 . + + */ + +/* 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 - - 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 . - - */ - - -#include -#include -#include - -#include "misc.h" - -#include -#include - -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 - - 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 . - - */ - - -/* Frustrating header junk */ - -#include -#include -#include -#include - -#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 #include