From patchwork Wed Jan 3 08:37:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 83221 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 C911738582B8 for ; Wed, 3 Jan 2024 08:39:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 2A3BC3858D28 for ; Wed, 3 Jan 2024 08:37:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A3BC3858D28 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 2A3BC3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704271084; cv=none; b=I6QbbdiSdXdbawt9OHaqaNoLSjio/ZOc0oprkQK3zVdy4NCR3vJ++Fispq0261q6G6kxJfZl9Ohy2USH9x2y1GeoFaskzybymEEsoXXxkE5R5sXwRSC63GaNFEO9T68FFKPc412tfrI75EIGEVquTd3GRufQ2NcTQworjM39jGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704271084; c=relaxed/simple; bh=xXE0kzyQe0FnG0cx3ww9NCfQMj1kfm0HufNH4RpaiGk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=HGabvTIR4dl1SfrUP1hhkXMq0gnmnN5vp4/4aMJGJbKHX1yQdUfTEjKRUAqrpK2Fr24NR+MsXlQFE87NdxQRh7hAiUUqEvqcgytyieNZ5K0n6dUvMMtEM3vzmHn0rCNDZwcQET1V4m8xRgRHUhcq1SJcfzqPTBJiC1m4C/pO64o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by smtp.gentoo.org (Postfix, from userid 559) id BBD1D342F94; Wed, 3 Jan 2024 08:37:53 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH/committed 1/3] sim: igen: clean up headers a bit Date: Wed, 3 Jan 2024 03:37:49 -0500 Message-ID: <20240103083751.12013-1-vapier@gentoo.org> X-Mailer: git-send-email 2.43.0 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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 Add standard multiple inclusion protection, and add a few missing local includes when one header uses another. This isn't complete, but fixes some short comings seen when merging the ppc igen. --- sim/igen/filter.h | 6 ++++++ sim/igen/filter_host.h | 7 ++++--- sim/igen/gen-engine.h | 5 +++++ sim/igen/gen-icache.h | 4 ++++ sim/igen/gen-idecode.h | 4 ++++ sim/igen/gen-itable.h | 5 ++++- sim/igen/gen-model.h | 5 ++++- sim/igen/gen-semantics.h | 4 ++++ sim/igen/gen-support.h | 4 ++++ sim/igen/gen.h | 4 ++++ sim/igen/igen.h | 4 ++++ sim/igen/ld-cache.h | 5 ++++- sim/igen/ld-decode.h | 4 ++++ sim/igen/ld-insn.h | 5 ++++- sim/igen/lf.h | 6 ++++++ sim/igen/misc.h | 5 ++++- sim/igen/table.h | 4 ++++ 17 files changed, 73 insertions(+), 8 deletions(-) diff --git a/sim/igen/filter.h b/sim/igen/filter.h index dd674dde26ae..b225731add0e 100644 --- a/sim/igen/filter.h +++ b/sim/igen/filter.h @@ -19,6 +19,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_FILTER_H +#define IGEN_FILTER_H + +#include "lf.h" /* NB, an empty filter is NULL */ typedef struct _filter filter; @@ -68,3 +72,5 @@ const char *filter_next (const filter *set, const char *member); extern void dump_filter (lf *file, const char *prefix, const filter *filt, const char *suffix); + +#endif /* IGEN_FILTER_H */ diff --git a/sim/igen/filter_host.h b/sim/igen/filter_host.h index 104c21063d62..b226a2111fa2 100644 --- a/sim/igen/filter_host.h +++ b/sim/igen/filter_host.h @@ -19,9 +19,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _FILTER_HOST_H -#define _FILTER_HOST_H +#ifndef IGEN_FILTER_HOST_H +#define IGEN_FILTER_HOST_H /* Remove directory part from filename */ extern const char *filter_filename (const char *filename); -#endif + +#endif /* IGEN_FILTER_HOST_H */ diff --git a/sim/igen/gen-engine.h b/sim/igen/gen-engine.h index bb46bed147d9..20f341526f46 100644 --- a/sim/igen/gen-engine.h +++ b/sim/igen/gen-engine.h @@ -19,6 +19,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_GEN_ENGINE_H +#define IGEN_GEN_ENGINE_H + extern void gen_engine_h (lf *file, const gen_table *gen, const insn_table *isa, cache_entry *cache_rules); @@ -29,3 +32,5 @@ extern void gen_engine_c extern void print_engine_run_function_header (lf *file, const char *processor, function_decl_type decl_type); + +#endif /* IGEN_GEN_ENGINE_H */ diff --git a/sim/igen/gen-icache.h b/sim/igen/gen-icache.h index de8cdfe43071..f5298e564939 100644 --- a/sim/igen/gen-icache.h +++ b/sim/igen/gen-icache.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_GEN_ICACHE_H +#define IGEN_GEN_ICACHE_H /* Output code to manipulate the instruction cache: either create it or reference it */ @@ -79,3 +81,5 @@ extern void print_icache_struct /* Output a single instructions decoder */ + +#endif /* IGEN_GEN_ICACHE_H */ diff --git a/sim/igen/gen-idecode.h b/sim/igen/gen-idecode.h index 63ae883d2192..05a7055644a9 100644 --- a/sim/igen/gen-idecode.h +++ b/sim/igen/gen-idecode.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_GEN_IDECODE_H +#define IGEN_GEN_IDECODE_H void print_idecode_issue_function_header (lf *file, @@ -45,3 +47,5 @@ extern void print_idecode_validate (lf *file, const insn_entry *instruction, const insn_opcodes *opcode_paths); + +#endif /* IGEN_GEN_IDECODE_H */ diff --git a/sim/igen/gen-itable.h b/sim/igen/gen-itable.h index 37d39fe84b85..2991d18390ba 100644 --- a/sim/igen/gen-itable.h +++ b/sim/igen/gen-itable.h @@ -19,10 +19,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#ifndef IGEN_GEN_ITABLE_H +#define IGEN_GEN_ITABLE_H /* Output a table of all the instructions */ extern void gen_itable_h (lf *file, const insn_table *table); extern void gen_itable_c (lf *file, const insn_table *table); + +#endif /* IGEN_GEN_ITABLE_H */ diff --git a/sim/igen/gen-model.h b/sim/igen/gen-model.h index 5af5d9182625..2fdea67d4dc6 100644 --- a/sim/igen/gen-model.h +++ b/sim/igen/gen-model.h @@ -19,8 +19,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#ifndef IGEN_GEN_MODEL_H +#define IGEN_GEN_MODEL_H extern void gen_model_h (lf *file, const insn_table *isa); extern void gen_model_c (lf *file, const insn_table *isa); + +#endif /* IGEN_GEN_MODEL_H */ diff --git a/sim/igen/gen-semantics.h b/sim/igen/gen-semantics.h index 115251b2287a..daf5fc8ca2f9 100644 --- a/sim/igen/gen-semantics.h +++ b/sim/igen/gen-semantics.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_GEN_SEMANTICS_H +#define IGEN_GEN_SEMANTICS_H /* Creates the files semantics.[hc]. @@ -102,3 +104,5 @@ extern void print_semantic_body const insn_entry *instruction, const opcode_bits *expanded_bits, const insn_opcodes *opcodes); + +#endif /* IGEN_GEN_SEMANTICS_H */ diff --git a/sim/igen/gen-support.h b/sim/igen/gen-support.h index fac231ed96fe..c22a89565237 100644 --- a/sim/igen/gen-support.h +++ b/sim/igen/gen-support.h @@ -19,7 +19,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_GEN_SUPPORT_H +#define IGEN_GEN_SUPPORT_H extern void gen_support_h (lf *file, const insn_table *table); extern void gen_support_c (lf *file, const insn_table *table); + +#endif /* IGEN_GEN_SUPPORT_H */ diff --git a/sim/igen/gen.h b/sim/igen/gen.h index 53225bc84298..f6a77cf80a1a 100644 --- a/sim/igen/gen.h +++ b/sim/igen/gen.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_GEN_H +#define IGEN_GEN_H typedef struct _opcode_field opcode_field; struct _opcode_field @@ -214,3 +216,5 @@ extern void print_sim_engine_abort (lf *file, const char *message); extern void print_include (lf *file, igen_module module); extern void print_include_inline (lf *file, igen_module module); extern void print_includes (lf *file); + +#endif /* IGEN_GEN_H */ diff --git a/sim/igen/igen.h b/sim/igen/igen.h index eb5c755aeda6..cc3edac5a761 100644 --- a/sim/igen/igen.h +++ b/sim/igen/igen.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_IGEN_H +#define IGEN_IGEN_H /* code-generation options: */ @@ -249,3 +251,5 @@ do { \ options.gen.icache_size = 1024; \ options.warning = warning; \ } while (0) + +#endif /* IGEN_IGEN_H */ diff --git a/sim/igen/ld-cache.h b/sim/igen/ld-cache.h index 47bf9d60dae3..a7351cd765dd 100644 --- a/sim/igen/ld-cache.h +++ b/sim/igen/ld-cache.h @@ -19,7 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#ifndef IGEN_LD_CACHE_H +#define IGEN_LD_CACHE_H /* For backward compatibility only - load a standalone cache macro table */ @@ -64,3 +65,5 @@ extern cache_entry *load_cache_table (const char *file_name); + +#endif /* IGEN_LD_CACHE_H */ diff --git a/sim/igen/ld-decode.h b/sim/igen/ld-decode.h index 739e09e5d9e6..660f3a7ccd1a 100644 --- a/sim/igen/ld-decode.h +++ b/sim/igen/ld-decode.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_LD_DECODE_H +#define IGEN_LD_DECODE_H /* Instruction decode table: @@ -242,3 +244,5 @@ extern int decode_table_max_word_nr (const decode_table *rule); extern void dump_decode_rule (lf *file, const char *prefix, const decode_table *rule, const char *suffix); + +#endif /* IGEN_LD_DECODE_H */ diff --git a/sim/igen/ld-insn.h b/sim/igen/ld-insn.h index d22b855e1ce1..661cd40a0e85 100644 --- a/sim/igen/ld-insn.h +++ b/sim/igen/ld-insn.h @@ -19,7 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#ifndef IGEN_LD_INSN_H +#define IGEN_LD_INSN_H typedef uint64_t insn_uint; @@ -705,3 +706,5 @@ void dump_cache_entries void dump_insn_table (lf *file, const char *prefix, const insn_table *isa, const char *suffix); + +#endif /* IGEN_LD_INSN_H */ diff --git a/sim/igen/lf.h b/sim/igen/lf.h index d1e2acca5480..cea86d63db13 100644 --- a/sim/igen/lf.h +++ b/sim/igen/lf.h @@ -19,7 +19,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_LF_H +#define IGEN_LF_H + #include "ansidecl.h" +#include "misc.h" /* LF: Line Numbered Output Stream */ @@ -115,3 +119,5 @@ extern int lf_print__function_type_function (lf *file, print_function * print_type, const char *prefix, const char *trailing_space); + +#endif /* IGEN_LF_H */ diff --git a/sim/igen/misc.h b/sim/igen/misc.h index 45610558a262..04a7f720b41d 100644 --- a/sim/igen/misc.h +++ b/sim/igen/misc.h @@ -19,7 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#ifndef IGEN_MISC_H +#define IGEN_MISC_H /* Frustrating header junk */ @@ -102,3 +103,5 @@ name_map; extern int name2i (const char *name, const name_map * map); extern const char *i2name (const int i, const name_map * map); + +#endif /* IGEN_MISC_H */ diff --git a/sim/igen/table.h b/sim/igen/table.h index e6f318b4e36a..13429707f2e2 100644 --- a/sim/igen/table.h +++ b/sim/igen/table.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef IGEN_TABLE_H +#define IGEN_TABLE_H /* Read a table, line by line, from a file. @@ -138,3 +140,5 @@ extern char *skip_spaces (char *chp); extern char *skip_to_separator (char *chp, char *separators); extern char *back_spaces (char *start, char *chp); + +#endif /* IGEN_TABLE_H */ From patchwork Wed Jan 3 08:37:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 83222 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 157553858421 for ; Wed, 3 Jan 2024 08:39:24 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 65EE23858C62 for ; Wed, 3 Jan 2024 08:37:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65EE23858C62 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 65EE23858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704271087; cv=none; b=FTC2kbCy0PCrPlRDd6ZUTmbOp2ZkSXli8Y6bNcvEgSgya/ld9chkg84SDGCoP9bc23iYziM9djR97ic+X3beeT+pEvDh2+HMK0YWKE0hKblfTX7uv6HVvbwN/Gh3Rpvuujw+CfMWTAu3boskB4xbsi/rjAaR+YyOm+1tRuYfNmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704271087; c=relaxed/simple; bh=MovclGWiUp6dUgrxoe/5UZ+X5CXuNHv2s9Rg3MdpXLk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Z//LY/oyvn8dt/Qc9D7laky4VdChkleHkl+NpToL3nEy/qJ3O7/y46+wqeI7Bfvmez0pJVC6DzBFiaon9S8UxGotqrCBZwYbQEYBUKmGIN3JoSEym9/c9ocgfHIzIVAGjw8RLzfp1TsgoOTNhsPxEssRtgsz3Q+Shi3A9Be5IoE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by smtp.gentoo.org (Postfix, from userid 559) id 0130E342FF7; Wed, 3 Jan 2024 08:37:55 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH/committed 2/3] sim: ppc: unify igen line number output modules Date: Wed, 3 Jan 2024 03:37:50 -0500 Message-ID: <20240103083751.12013-2-vapier@gentoo.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103083751.12013-1-vapier@gentoo.org> References: <20240103083751.12013-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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 was forked from the ppc long ago. The lf module is still pretty similar in API, so we can unfork them with a little bit of effort. Some of the generated ppc code is now slightly different, but that's because of fixes the common igen code has gained, but not the ppc igen code (e.g. fixing of #line numbers). The ppc code retains lf_print__c_code because the common igen code rewrote the logic to a new table.c API. Let's delay that in the ppc code to at least unfork all this code. --- sim/Makefile.in | 14 +- sim/ppc/gen-icache.c | 15 +- sim/ppc/gen-idecode.c | 5 +- sim/ppc/gen-model.c | 33 +-- sim/ppc/gen-semantics.c | 9 +- sim/ppc/gen-support.c | 7 +- sim/ppc/igen.c | 12 +- sim/ppc/lf-ppc.c | 66 ++++++ sim/ppc/lf-ppc.h | 33 +++ sim/ppc/lf.c | 495 ---------------------------------------- sim/ppc/lf.h | 130 ----------- sim/ppc/local.mk | 3 +- sim/ppc/table.c | 2 +- 13 files changed, 154 insertions(+), 670 deletions(-) create mode 100644 sim/ppc/lf-ppc.c create mode 100644 sim/ppc/lf-ppc.h delete mode 100644 sim/ppc/lf.c delete mode 100644 sim/ppc/lf.h diff --git a/sim/ppc/gen-icache.c b/sim/ppc/gen-icache.c index 4efc7392705a..c10735c1764b 100644 --- a/sim/ppc/gen-icache.c +++ b/sim/ppc/gen-icache.c @@ -21,6 +21,7 @@ #include "misc.h" #include "lf.h" +#include "lf-ppc.h" #include "table.h" #include "filter.h" @@ -44,7 +45,7 @@ print_icache_function_header(lf *file, int is_function_definition) { lf_printf(file, "\n"); - lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", " "); + lf_print__function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", " "); print_function_name(file, basename, expanded_bits, @@ -111,7 +112,7 @@ print_icache_extraction(lf *file, } else { if (file_name != NULL) - lf_print__external_reference(file, line_nr, file_name); + lf_print__external_ref(file, line_nr, file_name); lf_printf(file, "%s const %s ATTRIBUTE_UNUSED = ", entry_type == NULL ? "unsigned" : entry_type, entry_name); @@ -344,7 +345,7 @@ print_icache_body(lf *file, } } - lf_print__internal_reference(file); + lf_print__internal_ref(file); if ((code & generate_with_insn_in_icache)) { lf_printf(file, "\n"); @@ -499,7 +500,7 @@ print_icache_function(lf *file, /* generate code to enter decoded instruction into the icache */ lf_printf(file, "\n"); - lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", "\n"); + lf_print__function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", "\n"); indent = print_function_name(file, instruction->file_entry->fields[insn_name], expanded_bits, @@ -623,7 +624,7 @@ print_icache_internal_function_declaration(insn_table *table, ASSERT((code & generate_with_icache) != 0); if (it_is("internal", function->fields[insn_flags])) { lf_printf(file, "\n"); - lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE", + lf_print__function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE", "\n"); print_function_name(file, function->fields[insn_name], @@ -643,7 +644,7 @@ print_icache_internal_function_definition(insn_table *table, ASSERT((code & generate_with_icache) != 0); if (it_is("internal", function->fields[insn_flags])) { lf_printf(file, "\n"); - lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE", + lf_print__function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE", "\n"); print_function_name(file, function->fields[insn_name], @@ -668,7 +669,7 @@ print_icache_internal_function_definition(insn_table *table, lf_printf(file, ";\n"); } - lf_print__internal_reference(file); + lf_print__internal_ref(file); lf_indent(file, -2); lf_printf(file, "}\n"); } diff --git a/sim/ppc/gen-idecode.c b/sim/ppc/gen-idecode.c index 5d2253500594..55c62906735a 100644 --- a/sim/ppc/gen-idecode.c +++ b/sim/ppc/gen-idecode.c @@ -19,6 +19,7 @@ #include "misc.h" #include "lf.h" +#include "lf-ppc.h" #include "table.h" #include "filter.h" @@ -1217,7 +1218,7 @@ print_jump_internal_function(insn_table *table, lf_indent(file, +2); lf_printf(file, "const unsigned_word cia = nia;\n"); lf_print__c_code(file, function->annex); - lf_print__internal_reference(file); + lf_print__internal_ref(file); lf_printf(file, "error(\"Internal function must longjump\\n\");\n"); lf_indent(file, -2); lf_printf(file, "}\n"); @@ -1447,7 +1448,7 @@ print_idecode_run_function_header(lf *file, { int indent; lf_printf(file, "\n"); - lf_print_function_type(file, "void", "PSIM_INLINE_IDECODE", (is_definition ? " " : "\n")); + lf_print__function_type(file, "void", "PSIM_INLINE_IDECODE", (is_definition ? " " : "\n")); indent = lf_putstr(file, (can_stop ? "idecode_run_until_stop" : "idecode_run")); if (is_definition) lf_putstr(file, "\n"); diff --git a/sim/ppc/gen-model.c b/sim/ppc/gen-model.c index 11a533b2d93a..e763d4eadd4b 100644 --- a/sim/ppc/gen-model.c +++ b/sim/ppc/gen-model.c @@ -20,6 +20,7 @@ #include "misc.h" #include "lf.h" +#include "lf-ppc.h" #include "table.h" #include "filter.h" @@ -39,7 +40,7 @@ model_c_or_h_data(insn_table *table, if (data->annex) { table_entry_print_cpp_line_nr(file, data); lf_print__c_code(file, data->annex); - lf_print__internal_reference(file); + lf_print__internal_ref(file); lf_printf(file, "\n"); } } @@ -55,7 +56,7 @@ model_c_or_h_function(insn_table *entry, 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, " "); + lf_print__function_type(file, function->fields[function_type], prefix, " "); lf_printf(file, "%s\n(%s);\n", function->fields[function_name], function->fields[function_param]); @@ -117,42 +118,42 @@ gen_model_h(insn_table *table, lf *file) } if (!model_create_p) { - lf_print_function_type(file, "model_data *", "INLINE_MODEL", " "); + lf_print__function_type(file, "model_data *", "INLINE_MODEL", " "); lf_printf(file, "model_create\n"); lf_printf(file, "(cpu *processor);\n"); lf_printf(file, "\n"); } if (!model_init_p) { - lf_print_function_type(file, "void", "INLINE_MODEL", " "); + lf_print__function_type(file, "void", "INLINE_MODEL", " "); lf_printf(file, "model_init\n"); lf_printf(file, "(model_data *model_ptr);\n"); lf_printf(file, "\n"); } if (!model_halt_p) { - lf_print_function_type(file, "void", "INLINE_MODEL", " "); + lf_print__function_type(file, "void", "INLINE_MODEL", " "); lf_printf(file, "model_halt\n"); lf_printf(file, "(model_data *model_ptr);\n"); lf_printf(file, "\n"); } if (!model_mon_info_p) { - lf_print_function_type(file, "model_print *", "INLINE_MODEL", " "); + lf_print__function_type(file, "model_print *", "INLINE_MODEL", " "); lf_printf(file, "model_mon_info\n"); lf_printf(file, "(model_data *model_ptr);\n"); lf_printf(file, "\n"); } if (!model_mon_info_free_p) { - lf_print_function_type(file, "void", "INLINE_MODEL", " "); + lf_print__function_type(file, "void", "INLINE_MODEL", " "); lf_printf(file, "model_mon_info_free\n"); lf_printf(file, "(model_data *model_ptr,\n"); lf_printf(file, " model_print *info_ptr);\n"); lf_printf(file, "\n"); } - lf_print_function_type(file, "void", "INLINE_MODEL", " "); + lf_print__function_type(file, "void", "INLINE_MODEL", " "); lf_printf(file, "model_set\n"); lf_printf(file, "(const char *name);\n"); } @@ -207,7 +208,7 @@ model_c_function(insn_table *table, } else { lf_printf(file, "\n"); - lf_print_function_type(file, function->fields[function_type], prefix, "\n"); + lf_print__function_type(file, function->fields[function_type], prefix, "\n"); lf_printf(file, "%s(%s)\n", function->fields[function_name], function->fields[function_param]); @@ -220,7 +221,7 @@ model_c_function(insn_table *table, lf_indent(file, -2); } lf_printf(file, "}\n"); - lf_print__internal_reference(file); + lf_print__internal_ref(file); lf_printf(file, "\n"); } @@ -279,7 +280,7 @@ gen_model_c(insn_table *table, lf *file) } if (!model_create_p) { - lf_print_function_type(file, "model_data *", "INLINE_MODEL", "\n"); + lf_print__function_type(file, "model_data *", "INLINE_MODEL", "\n"); lf_printf(file, "model_create(cpu *processor)\n"); lf_printf(file, "{\n"); lf_printf(file, " return (model_data *)0;\n"); @@ -288,7 +289,7 @@ gen_model_c(insn_table *table, lf *file) } if (!model_init_p) { - lf_print_function_type(file, "void", "INLINE_MODEL", "\n"); + lf_print__function_type(file, "void", "INLINE_MODEL", "\n"); lf_printf(file, "model_init(model_data *model_ptr)\n"); lf_printf(file, "{\n"); lf_printf(file, "}\n"); @@ -296,7 +297,7 @@ gen_model_c(insn_table *table, lf *file) } if (!model_halt_p) { - lf_print_function_type(file, "void", "INLINE_MODEL", "\n"); + lf_print__function_type(file, "void", "INLINE_MODEL", "\n"); lf_printf(file, "model_halt(model_data *model_ptr)\n"); lf_printf(file, "{\n"); lf_printf(file, "}\n"); @@ -304,7 +305,7 @@ gen_model_c(insn_table *table, lf *file) } if (!model_mon_info_p) { - lf_print_function_type(file, "model_print *", "INLINE_MODEL", "\n"); + lf_print__function_type(file, "model_print *", "INLINE_MODEL", "\n"); lf_printf(file, "model_mon_info(model_data *model_ptr)\n"); lf_printf(file, "{\n"); lf_printf(file, " return (model_print *)0;\n"); @@ -313,7 +314,7 @@ gen_model_c(insn_table *table, lf *file) } if (!model_mon_info_free_p) { - lf_print_function_type(file, "void", "INLINE_MODEL", "\n"); + lf_print__function_type(file, "void", "INLINE_MODEL", "\n"); lf_printf(file, "model_mon_info_free(model_data *model_ptr,\n"); lf_printf(file, " model_print *info_ptr)\n"); lf_printf(file, "{\n"); @@ -359,7 +360,7 @@ gen_model_c(insn_table *table, lf *file) lf_printf(file, "#endif\n"); lf_printf(file, "\n"); - lf_print_function_type(file, "void", "INLINE_MODEL", "\n"); + lf_print__function_type(file, "void", "INLINE_MODEL", "\n"); lf_printf(file, "model_set(const char *name)\n"); lf_printf(file, "{\n"); if (models) { diff --git a/sim/ppc/gen-semantics.c b/sim/ppc/gen-semantics.c index b0646fa83871..587080b5f64e 100644 --- a/sim/ppc/gen-semantics.c +++ b/sim/ppc/gen-semantics.c @@ -21,6 +21,7 @@ #include "misc.h" #include "lf.h" +#include "lf-ppc.h" #include "table.h" #include "filter.h" @@ -43,7 +44,7 @@ print_semantic_function_header(lf *file, { int indent; lf_printf(file, "\n"); - lf_print_function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_EXTERN_SEMANTICS", + lf_print__function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_EXTERN_SEMANTICS", (is_function_definition ? "\n" : " ")); indent = print_function_name(file, basename, @@ -138,17 +139,17 @@ print_semantic_body(lf *file, lf_print__c_code(file, instruction->file_entry->annex); lf_indent(file, -2); lf_printf(file, "}\n"); - lf_print__internal_reference(file); + lf_print__internal_ref(file); } else if (it_is("nop", instruction->file_entry->fields[insn_flags])) { - lf_print__internal_reference(file); + lf_print__internal_ref(file); } else { /* abort so it is implemented now */ table_entry_print_cpp_line_nr(file, instruction->file_entry); lf_putstr(file, "error(\"%s:%d:0x%08lx:%s unimplemented\\n\",\n"); lf_printf(file, " itable[MY_INDEX].file, itable[MY_INDEX].line_nr, (long)cia, itable[MY_INDEX].name);\n"); - lf_print__internal_reference(file); + lf_print__internal_ref(file); } } diff --git a/sim/ppc/gen-support.c b/sim/ppc/gen-support.c index 85ab497e20e9..0c2b28a42b07 100644 --- a/sim/ppc/gen-support.c +++ b/sim/ppc/gen-support.c @@ -19,6 +19,7 @@ #include "misc.h" #include "lf.h" +#include "lf-ppc.h" #include "table.h" #include "filter.h" @@ -37,7 +38,7 @@ print_support_function_name(lf *file, int is_function_definition) { if (it_is("internal", function->fields[insn_flags])) { - lf_print_function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_INLINE_SUPPORT", + lf_print__function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_INLINE_SUPPORT", (is_function_definition ? "\n" : " ")); print_function_name(file, function->fields[function_name], @@ -49,7 +50,7 @@ print_support_function_name(lf *file, lf_printf(file, "\n"); } else { - lf_print_function_type(file, + lf_print__function_type(file, function->fields[function_type], "PSIM_INLINE_SUPPORT", (is_function_definition ? "\n" : " ")); @@ -110,7 +111,7 @@ support_c_function(insn_table *table, } lf_indent(file, -2); lf_printf(file, "}\n"); - lf_print__internal_reference(file); + lf_print__internal_ref(file); lf_printf(file, "\n"); } diff --git a/sim/ppc/igen.c b/sim/ppc/igen.c index 264d8086874a..1e6951d8e66a 100644 --- a/sim/ppc/igen.c +++ b/sim/ppc/igen.c @@ -158,12 +158,12 @@ print_itrace(lf *file, table_entry *file_entry, int idecode) { - lf_print__external_reference(file, file_entry->line_nr, file_entry->file_name); + lf_print__external_ref(file, file_entry->line_nr, file_entry->file_name); lf_printf(file, "ITRACE(trace_%s, (\"%s %s\\n\"));\n", (idecode ? "idecode" : "semantics"), (idecode ? "idecode" : "semantics"), file_entry->fields[insn_name]); - lf_print__internal_reference(file); + lf_print__internal_ref(file); } @@ -201,7 +201,7 @@ gen_semantics_h(insn_table *table, } else { - lf_print__this_file_is_empty(file); + lf_print__this_file_is_empty(file, "generating jumps"); } } @@ -250,7 +250,7 @@ gen_semantics_c(insn_table *table, } else { - lf_print__this_file_is_empty(file); + lf_print__this_file_is_empty(file, "generating jump engine"); } } @@ -287,7 +287,7 @@ gen_icache_h(insn_table *table, } else { - lf_print__this_file_is_empty(file); + lf_print__this_file_is_empty(file, "generating jump engine"); } } @@ -331,7 +331,7 @@ gen_icache_c(insn_table *table, } else { - lf_print__this_file_is_empty(file); + lf_print__this_file_is_empty(file, "generating jump engine"); } } diff --git a/sim/ppc/lf-ppc.c b/sim/ppc/lf-ppc.c new file mode 100644 index 000000000000..469f0fbe4958 --- /dev/null +++ b/sim/ppc/lf-ppc.c @@ -0,0 +1,66 @@ +/* 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 . + + */ + +#include +#include +#include +#include + +#include "lf.h" +#include "lf-ppc.h" + +int +lf_print__c_code(lf *file, + const char *code) +{ + int nr = 0; + const char *chp = code; + int in_bit_field = 0; + while (*chp != '\0') { + if (*chp == '\t') + chp++; + if (*chp == '#') + lf_indent_suppress(file); + while (*chp != '\0' && *chp != '\n') { + if (chp[0] == '{' && !isspace(chp[1])) { + in_bit_field = 1; + nr += lf_putchr(file, '_'); + } + else if (in_bit_field && chp[0] == ':') { + nr += lf_putchr(file, '_'); + } + else if (in_bit_field && *chp == '}') { + nr += lf_putchr(file, '_'); + in_bit_field = 0; + } + else { + nr += lf_putchr(file, *chp); + } + chp++; + } + if (in_bit_field) + ERROR("bit field paren miss match some where\n"); + if (*chp == '\n') { + nr += lf_putchr(file, '\n'); + chp++; + } + } + nr += lf_putchr(file, '\n'); + return nr; +} diff --git a/sim/ppc/lf-ppc.h b/sim/ppc/lf-ppc.h new file mode 100644 index 000000000000..7a31950badca --- /dev/null +++ b/sim/ppc/lf-ppc.h @@ -0,0 +1,33 @@ +/* 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 . + + */ + +#ifndef PPC_LF_H +#define PPC_LF_H + +/* LF: Line Numbered Output Stream */ + +#include "lf.h" + +/* TODO: Convert to igen/table.c table_print_code. */ + +extern int lf_print__c_code +(lf *file, + const char *code); + +#endif /* PPC_LF_H */ diff --git a/sim/ppc/lf.c b/sim/ppc/lf.c deleted file mode 100644 index 9deb2d2bb523..000000000000 --- a/sim/ppc/lf.c +++ /dev/null @@ -1,495 +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 . - - */ - -#include -#include -#include -#include - -#include "misc.h" -#include "lf.h" - -#include -#include - -struct _lf { - FILE *stream; - int line_nr; /* nr complete lines written, curr line is line_nr+1 */ - int indent; - int line_blank; - const char *name; /* Output name with diagnostics. */ - const char *filename; /* Output filename. */ - char *tmpname; /* Temporary output filename. */ - const char *program; - lf_file_references references; - lf_file_type type; -}; - - -lf * -lf_open(const char *name, - const char *real_name, - lf_file_references references, - lf_file_type type, - const char *program) -{ - /* create a file object */ - lf *new_lf = ZALLOC(lf); - ASSERT(new_lf != NULL); - new_lf->references = references; - new_lf->type = type; - new_lf->name = (real_name == NULL ? name : real_name); - new_lf->filename = name; - new_lf->program = program; - /* attach to stdout if pipe */ - if (!strcmp(name, "-")) { - new_lf->stream = stdout; - } - else { - /* create a new file */ - char *tmpname = zalloc (strlen (name) + 5); - sprintf (tmpname, "%s.tmp", name); - new_lf->filename = name; - new_lf->tmpname = tmpname; - new_lf->stream = fopen(tmpname, "w+"); - if (new_lf->stream == NULL) { - perror(name); - exit(1); - } - } - return new_lf; -} - - -void -lf_close(lf *file) -{ - FILE *fp; - bool update = true; - - /* If we wrote to stdout, no house keeping needed. */ - if (file->stream == stdout) - return; - - /* Rename the temp file to the real file if it's changed. */ - fp = fopen (file->filename, "r"); - if (fp != NULL) - { - off_t len; - - fseek (fp, 0, SEEK_END); - len = ftell (fp); - - if (len == ftell (file->stream)) - { - off_t off; - size_t cnt; - char *oldbuf = zalloc (len); - char *newbuf = zalloc (len); - - rewind (fp); - off = 0; - while ((cnt = fread (oldbuf + off, 1, len - off, fp)) > 0) - off += cnt; - ASSERT (off == len); - - rewind (file->stream); - off = 0; - while ((cnt = fread (newbuf + off, 1, len - off, file->stream)) > 0) - off += cnt; - ASSERT (off == len); - - if (memcmp (oldbuf, newbuf, len) == 0) - update = false; - } - - fclose (fp); - } - - if (fclose (file->stream)) - { - perror ("lf_close.fclose"); - exit (1); - } - - if (update) - { - if (rename (file->tmpname, file->filename) != 0) - { - perror ("lf_close.rename"); - exit (1); - } - } - else - { - if (remove (file->tmpname) != 0) - { - perror ("lf_close.unlink"); - exit (1); - } - } - - free (file->tmpname); - free (file); -} - - -int -lf_putchr(lf *file, - const char chr) -{ - int nr = 0; - if (chr == '\n') { - file->line_nr += 1; - file->line_blank = 1; - } - else if (file->line_blank) { - int pad; - for (pad = file->indent; pad > 0; pad--) - putc(' ', file->stream); - nr += file->indent; - file->line_blank = 0; - } - putc(chr, file->stream); - nr += 1; - return nr; -} - -void -lf_indent_suppress(lf *file) -{ - file->line_blank = 0; -} - - -int -lf_putstr(lf *file, - const char *string) -{ - int nr = 0; - const char *chp; - if (string != NULL) { - for (chp = string; *chp != '\0'; chp++) { - nr += lf_putchr(file, *chp); - } - } - return nr; -} - -static int -do_lf_putunsigned(lf *file, - unsigned u) -{ - int nr = 0; - if (u > 0) { - nr += do_lf_putunsigned(file, u / 10); - nr += lf_putchr(file, (u % 10) + '0'); - } - return nr; -} - - -int -lf_putint(lf *file, - int decimal) -{ - int nr = 0; - if (decimal == 0) - nr += lf_putchr(file, '0'); - else if (decimal < 0) { - nr += lf_putchr(file, '-'); - nr += do_lf_putunsigned(file, -decimal); - } - else if (decimal > 0) { - nr += do_lf_putunsigned(file, decimal); - } - else - ASSERT(0); - return nr; -} - - -int -lf_printf(lf *file, - const char *fmt, - ...) -{ - int nr = 0; - char buf[1024]; - va_list ap; - - va_start(ap, fmt); - vsprintf(buf, fmt, ap); - /* FIXME - this is really stuffed but so is vsprintf() on a sun! */ - ASSERT(strlen(buf) > 0 && strlen(buf) < sizeof(buf)); - nr += lf_putstr(file, buf); - va_end(ap); - return nr; -} - - -int -lf_print__c_code(lf *file, - const char *code) -{ - int nr = 0; - const char *chp = code; - int in_bit_field = 0; - while (*chp != '\0') { - if (*chp == '\t') - chp++; - if (*chp == '#') - lf_indent_suppress(file); - while (*chp != '\0' && *chp != '\n') { - if (chp[0] == '{' && !isspace(chp[1])) { - in_bit_field = 1; - nr += lf_putchr(file, '_'); - } - else if (in_bit_field && chp[0] == ':') { - nr += lf_putchr(file, '_'); - } - else if (in_bit_field && *chp == '}') { - nr += lf_putchr(file, '_'); - in_bit_field = 0; - } - else { - nr += lf_putchr(file, *chp); - } - chp++; - } - if (in_bit_field) - ERROR("bit field paren miss match some where\n"); - if (*chp == '\n') { - nr += lf_putchr(file, '\n'); - chp++; - } - } - nr += lf_putchr(file, '\n'); - return nr; -} - - -int -lf_print__external_reference(lf *file, - int line_nr, - const char *file_name) -{ - int nr = 0; - switch (file->references) { - case lf_include_references: - lf_indent_suppress(file); - nr += lf_putstr(file, "#line "); - nr += lf_putint(file, line_nr); - nr += lf_putstr(file, " \""); - nr += lf_putstr(file, file_name); - nr += lf_putstr(file, "\"\n"); - break; - case lf_omit_references: - break; - } - return nr; -} - -int -lf_print__internal_reference(lf *file) -{ - int nr = 0; - nr += lf_print__external_reference(file, file->line_nr+2, file->name); - /* line_nr == last_line, want to number from next */ - return nr; -} - -void -lf_indent(lf *file, int delta) -{ - file->indent += delta; -} - - -int -lf_print__gnu_copyleft(lf *file) -{ - int nr = 0; - switch (file->type) { - case lf_is_c: - case lf_is_h: - nr += lf_printf(file, "\n\ -/* This file is part of the program psim.\n\ -\n\ - Copyright (C) 1994-1995, Andrew Cagney \n\ -\n\ - This program is free software; you can redistribute it and/or modify\n\ - it under the terms of the GNU General Public License as published by\n\ - the Free Software Foundation; either version 3 of the License, or\n\ - (at your option) any later version.\n\ -\n\ - This program is distributed in the hope that it will be useful,\n\ - but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ - GNU General Public License for more details.\n\ -\n\ - You should have received a copy of the GNU General Public License\n\ - along with this program; if not, see .\n\ -\n\ - --\n\ -\n\ - This file was generated by the program %s */\n\ -", filter_filename(file->program)); - break; - default: - ASSERT(0); - break; - } - return nr; -} - - -int -lf_putbin(lf *file, int decimal, int width) -{ - int nr = 0; - int bit; - ASSERT(width > 0); - for (bit = 1 << (width-1); bit != 0; bit >>= 1) { - if (decimal & bit) - nr += lf_putchr(file, '1'); - else - nr += lf_putchr(file, '0'); - } - return nr; -} - -int -lf_print__this_file_is_empty(lf *file) -{ - int nr = 0; - switch (file->type) { - case lf_is_c: - case lf_is_h: - nr += lf_printf(file, - "/* This generated file (%s) is intentionally left blank */\n", - file->name); - break; - default: - ASSERT(0); - } - return nr; -} - -int -lf_print__ucase_filename(lf *file) -{ - int nr = 0; - const char *chp = file->name; - while (*chp != '\0') { - char ch = *chp; - if (islower(ch)) { - nr += lf_putchr(file, toupper(ch)); - } - else if (ch == '.') - nr += lf_putchr(file, '_'); - else - nr += lf_putchr(file, ch); - chp++; - } - return nr; -} - -int -lf_print__file_start(lf *file) -{ - int nr = 0; - switch (file->type) { - case lf_is_h: - case lf_is_c: - nr += lf_print__gnu_copyleft(file); - nr += lf_printf(file, "\n"); - nr += lf_printf(file, "#ifndef _"); - nr += lf_print__ucase_filename(file); - nr += lf_printf(file, "_\n"); - nr += lf_printf(file, "#define _"); - nr += lf_print__ucase_filename(file); - nr += lf_printf(file, "_\n"); - nr += lf_printf(file, "\n"); - break; - default: - ASSERT(0); - } - return nr; -} - - -int -lf_print__file_finish(lf *file) -{ - int nr = 0; - switch (file->type) { - case lf_is_h: - case lf_is_c: - nr += lf_printf(file, "\n"); - nr += lf_printf(file, "#endif /* _"); - nr += lf_print__ucase_filename(file); - nr += lf_printf(file, "_*/\n"); - break; - default: - ASSERT(0); - } - return nr; -} - - -int -lf_print_function_type(lf *file, - const char *type, - const char *prefix, - const char *trailing_space) -{ - int nr = 0; - nr += lf_printf(file, "%s\\\n(%s)", prefix, type); - if (trailing_space != NULL) - nr += lf_printf(file, "%s", trailing_space); -#if 0 - const char *type_pointer = strrchr(type, '*'); - int type_pointer_offset = (type_pointer != NULL - ? type_pointer - type - : 0); - if (type_pointer == NULL) { - lf_printf(file, "%s %s", type, prefix); - } - else { - char *munged_type = (char*)zalloc(strlen(type) - + strlen(prefix) - + strlen(" * ") - + 1); - strcpy(munged_type, type); - munged_type[type_pointer_offset] = '\0'; - if (type_pointer_offset > 0 && type[type_pointer_offset-1] != ' ') - strcat(munged_type, " "); - strcat(munged_type, prefix); - strcat(munged_type, " "); - strcat(munged_type, type + type_pointer_offset); - lf_printf(file, "%s", munged_type); - free(munged_type); - } - if (trailing_space != NULL && type_pointer_offset < strlen(type) - 1) - lf_printf(file, trailing_space); -#endif - return nr; -} - diff --git a/sim/ppc/lf.h b/sim/ppc/lf.h deleted file mode 100644 index f1c41a93c442..000000000000 --- a/sim/ppc/lf.h +++ /dev/null @@ -1,130 +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 . - - */ - - -/* LF: Line Numbered Output Stream */ - -#include "ansidecl.h" - -typedef struct _lf lf; - -typedef enum { - lf_is_h, - lf_is_c, - lf_is_text, -} lf_file_type; - - -typedef enum { - lf_include_references, - lf_omit_references, -} lf_file_references; - - -/* Open the file NAME for writing. REAL_NAME is to be included in any - line number outputs. The output of line number information can be - suppressed with LINE_NUMBERS */ - -extern lf *lf_open -(const char *name, - const char *real_name, - lf_file_references file_references, - lf_file_type type, - const char *program); - -extern void lf_close -(lf *file); - - -/* Basic output functions */ - -extern int lf_putchr -(lf *file, - const char ch); - -extern int lf_putstr -(lf *file, - const char *string); - -extern int lf_putint -(lf *file, - int decimal); - -extern int lf_putbin -(lf *file, - int decimal, - int width); - -extern int lf_printf -(lf *file, - const char *fmt, - ...) ATTRIBUTE_PRINTF_2; - - -/* Indentation control. - - lf_indent_suppress suppresses indentation on the next line (current - line if that has not yet been started) */ - -extern void lf_indent_suppress -(lf *file); - -extern void lf_indent -(lf *file, - int delta); - - -/* Print generic text: */ - - -extern int lf_print__gnu_copyleft -(lf *file); - -extern int lf_print__file_start -(lf *file); - -extern int lf_print__this_file_is_empty -(lf *file); - -extern int lf_print__file_finish -(lf *file); - -extern int lf_print__internal_reference -(lf *file); - -extern int lf_print__external_reference -(lf *file, - int line_nr, - const char *file_name); - -extern int lf_print__ucase_filename -(lf *file); - -/* Tab prefix is suppressed */ - -extern int lf_print__c_code -(lf *file, - const char *code); - - -extern int lf_print_function_type -(lf *file, - const char *type, - const char *prefix, - const char *trailing_space); diff --git a/sim/ppc/local.mk b/sim/ppc/local.mk index f6da1c213385..d872014d1b56 100644 --- a/sim/ppc/local.mk +++ b/sim/ppc/local.mk @@ -100,7 +100,7 @@ MOSTLYCLEANFILES += %D%/defines.h %D%/stamp-defines EXTRA_LIBRARIES += %D%/libigen.a %C%_libigen_a_SOURCES = \ %D%/table.c \ - %D%/lf.c \ + %D%/lf-ppc.c \ %D%/dumpf.c \ %D%/ld-decode.c \ %D%/ld-cache.c \ @@ -114,6 +114,7 @@ EXTRA_LIBRARIES += %D%/libigen.a %D%/gen-support.c %C%_libigen_a_LIBADD = \ igen/filter_host.o \ + igen/lf.o \ igen/misc.o %C%_igen_SOURCES = %D%/igen.c diff --git a/sim/ppc/table.c b/sim/ppc/table.c index 5cac56eec9b9..94f04921deb7 100644 --- a/sim/ppc/table.c +++ b/sim/ppc/table.c @@ -341,7 +341,7 @@ extern void table_entry_print_cpp_line_nr(lf *file, table_entry *entry) { - lf_print__external_reference(file, entry->line_nr, entry->file_name); + lf_print__external_ref(file, entry->line_nr, entry->file_name); } From patchwork Wed Jan 3 08:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 83223 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 1F36F3858D28 for ; Wed, 3 Jan 2024 08:39:43 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 60FE23858C2C for ; Wed, 3 Jan 2024 08:37:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60FE23858C2C 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 60FE23858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704271088; cv=none; b=xSjTqZ2XrNlJiTq0khiVwaS6NfqzDjIq2lyELxnrZlW4BXbKQxBJYrD8l2q752nGb5FscX0WEObPgNag+7xzvn5poy2/IS2b5xH7txZm2ZJHM1UAkS+xWbLQydHvKJDnboCPlew2X6kOcd2Sn5zbbkXm7TN4hqgfq9iDjYod02Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704271088; c=relaxed/simple; bh=LboyKHJbDs9Zo7vVsADnyWvMgWN1hy3H3PaHxcIw7J8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Go2uU/OK9DecgDpHTuxiw6el4YTyh8+uU5xKm94qWOoii2Q9QJLxUriBHn3KN+E+2PrzObLl8GME2h+XuCiEKoU8zvvLEdKoCAxjLH9UCuAe0Vyv0E9f33NVEtIQpiSL/RCNWwC/5zXTUEAZiA08Qk5M4vBQS1OVD7y0/wWY+mg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by smtp.gentoo.org (Postfix, from userid 559) id 0E03A342FF8; Wed, 3 Jan 2024 08:37:58 +0000 (UTC) From: Mike Frysinger 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 Message-ID: <20240103083751.12013-3-vapier@gentoo.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103083751.12013-1-vapier@gentoo.org> References: <20240103083751.12013-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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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 + + 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 "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 . - - */ - - -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 - - 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 "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 ...\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 \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