From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 16DFF3858D1E for ; Wed, 21 Dec 2022 17:56:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16DFF3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 08624300071A; Wed, 21 Dec 2022 18:56:44 +0100 (CET) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 43F0B413CD0E; Wed, 21 Dec 2022 18:56:44 +0100 (CET) Message-ID: <20b6e6b3798e69e410d16f9764f5573ce1dfb154.camel@klomp.org> Subject: Re: [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum From: Mark Wielaard To: Yonggang Luo , elfutils-devel@sourceware.org Date: Wed, 21 Dec 2022 18:56:44 +0100 In-Reply-To: <20221217165213.152-6-luoyonggang@gmail.com> References: <20221217165213.152-1-luoyonggang@gmail.com> <20221217165213.152-6-luoyonggang@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Evolution 3.28.5 (3.28.5-10.el7) Mime-Version: 1.0 X-Spam-Status: No, score=-3038.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel wrote: > Signed-off-by: Yonggang Luo > --- > libcpu/Makefile.am | 2 +- > libcpu/i386_disasm.c | 14 +------------- > libcpu/i386_mne.h | 36 ++++++++++++++++++++++++++++++++++++ > libcpu/i386_parse.y | 9 +++------ > 4 files changed, 41 insertions(+), 20 deletions(-) > create mode 100644 libcpu/i386_mne.h >=20 > diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am > index 57d0a164..259ed838 100644 > --- a/libcpu/Makefile.am > +++ b/libcpu/Makefile.am > @@ -92,7 +92,7 @@ libeu =3D ../lib/libeu.a > i386_lex_CFLAGS =3D -Wno-unused-label -Wno-unused-function -Wno-sign- > compare \ > -Wno-implicit-fallthrough > i386_parse.o: i386_parse.c i386.mnemonics > -i386_parse_CFLAGS =3D -DNMNES=3D"`wc -l < i386.mnemonics`" > +i386_parse_CFLAGS =3D > i386_lex.o: i386_parse.h > i386_gendis_LDADD =3D $(libeu) -lm $(obstack_LIBS) The new i386_mne.h file should be added to noinst_HEADERS (or it won't be included in a make dist, so make distcheck fails). > diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c > index 599d1654..c34f03d6 100644 > --- a/libcpu/i386_disasm.c > +++ b/libcpu/i386_disasm.c > @@ -46,10 +46,7 @@ > #define MACHINE_ENCODING LITTLE_ENDIAN > #include "memory-access.h" > =20 > - > -#ifndef MNEFILE > -# define MNEFILE "i386.mnemonics" > -#endif > +#include "i386_mne.h" > =20 > #define MNESTRFIELD(line) MNESTRFIELD1 (line) > #define MNESTRFIELD1(line) str##line > @@ -71,15 +68,6 @@ static const union mnestr_t > } > }; > =20 > -/* The index can be stored in the instrtab. */ > -enum > - { > -#define MNE(name) MNE_##name, > -#include MNEFILE > -#undef MNE > - MNE_INVALID > - }; > - > static const unsigned short int mneidx[] =3D > { > #define MNE(name) \ OK. > diff --git a/libcpu/i386_mne.h b/libcpu/i386_mne.h > new file mode 100644 > index 00000000..41dacf61 > --- /dev/null > +++ b/libcpu/i386_mne.h > @@ -0,0 +1,36 @@ > +/* Compute hash value for given string according to ELF standard. > + Copyright (C) 1995-2015 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it > and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later > version. > + > + The GNU C Library 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 > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ That looks like the wrong header. Just copy the one from i386_disasm.c > +#ifndef _I386_MNE_H > +#define _I386_MNE_H 1 > + > +#ifndef MNEFILE > +# define MNEFILE "i386.mnemonics" > +#endif > + > +/* The index can be stored in the instrtab. */ > +enum > + { > +#define MNE(name) MNE_##name, > +#include MNEFILE > +#undef MNE > + MNE_INVALID, > + MNE_COUNT =3D MNE_INVALID, > + }; > + > +#endif /* i386_mne.h */ OK. > diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y > index d2236d59..459684c6 100644 > --- a/libcpu/i386_parse.y > +++ b/libcpu/i386_parse.y > @@ -46,6 +46,8 @@ > #include > #include > =20 > +#include "i386_mne.h" > + > #define obstack_chunk_alloc xmalloc > #define obstack_chunk_free free > =20 > @@ -1107,11 +1109,6 @@ print_op_fct (const void *nodep, VISIT value, > } > } > =20 > - > -#if NMNES < 2 > -# error "bogus NMNES value" > -#endif > - > static void > instrtable_out (void) > { > @@ -1123,7 +1120,7 @@ instrtable_out (void) > fprintf (outfile, "#define MNEMONIC_BITS %zu\n", > best_mnemonic_bits); > #else > fprintf (outfile, "#define MNEMONIC_BITS %ld\n", > - lrint (ceil (log2 (NMNES)))); > + lrint (ceil (log2 (MNE_COUNT)))); > #endif > fprintf (outfile, "#define SUFFIX_BITS %d\n", nbitsuf); > for (int i =3D 0; i < 3; ++i) OK. Thanks, Mark