From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 5B0353AA9426 for ; Sat, 17 Dec 2022 16:52:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5B0353AA9426 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1035.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so5231137pjj.4 for ; Sat, 17 Dec 2022 08:52:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i9U5s6NQjGl/Zd1iCIVQKUJ0ZV5bXfCMr3i+nBCORC8=; b=gTH3KfqVGbepONa/3vOcYkVvTo+3COkAO4ZjBptxYKgOMIFjF4b1VxIdEKNdCWh7Kh 3f+N/O/aYs13WtdZ3ryvGiQAPFpQIboVIwiP9IvPtKunXMi7OlgJOgirYJ8bUoqOFnJi 0UBVJNG3tiQkmMhERTWjpAVfniunjq7zzeD3d0d3rf8N/H6mCaEh3T0GyVfaH3jzOlWL n+a1w5Rvs49OtjtRIAgYs9MeBPA9GzM8rA4kiZGNXmM1rmDkPQj9PDx/dPYZJM1NjOxZ eshXPWgLO4QaEx+DwgAtmd+8JEV6rGIYJKe5vyzn1AG4Wx+tDZ7HruzELIVcIOx2YWM1 gVcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i9U5s6NQjGl/Zd1iCIVQKUJ0ZV5bXfCMr3i+nBCORC8=; b=VwsbiZeKRXjgT3tsPlWZR828TeBi+O+u1hQo5lRzqg9+7I2dax9n7T0uMIV37dCF7x SSq6J8JjQLnT8XskYvyaN2AYewarP3aVVR5Zx4o+5bgz2V0josNvEMU/XvOC0Uu8NB3O aiRWYq4V5cVmY9rqhqRI97nENCebW47+DKMW4TzHQhxYF5KLo61x08Yva7yfV7GHoRUu lbuaOO380LjW0iDHBuAB9EBBrUAVTMWAlEBbGyYFsq5ZvajbEl/Nmvc/50Fnr/tC1ZUc KHgfSLqXOfoxDXirYxwo6436ZtnhIC+vdW7TzQyYueTxtwtO4LEDGAiHov7Mo5PEnrSf XB8w== X-Gm-Message-State: ANoB5pl1lGZa3MK5W77cIK/AhdPuhT/x5hzmk/2B8E8IbLYqw2wvc1IJ fYBmE6B8rRTj0xcDK0dAFv1aNjagyfk= X-Google-Smtp-Source: AA0mqf63Cemkb1su3zpH5Zs+MAblskWWH9Rfkq8M0HE1gR28it/2R9ZISSciiob6YEbJojZJZZYTvw== X-Received: by 2002:a17:90a:b908:b0:21a:8c6:c89e with SMTP id p8-20020a17090ab90800b0021a08c6c89emr37792968pjr.2.1671295963086; Sat, 17 Dec 2022 08:52:43 -0800 (PST) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id s92-20020a17090a2f6500b002191873187dsm6643229pjd.33.2022.12.17.08.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Dec 2022 08:52:42 -0800 (PST) From: Yonggang Luo To: elfutils-devel@sourceware.org Cc: Yonggang Luo Subject: [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum Date: Sun, 18 Dec 2022 00:52:02 +0800 Message-Id: <20221217165213.152-6-luoyonggang@gmail.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20221217165213.152-1-luoyonggang@gmail.com> References: <20221217165213.152-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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: 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 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-compa= re \ -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) =20 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) \ 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.=0D + Copyright (C) 1995-2015 Free Software Foundation, Inc.=0D + This file is part of the GNU C Library.=0D +=0D + The GNU C Library is free software; you can redistribute it and/or=0D + modify it under the terms of the GNU Lesser General Public=0D + License as published by the Free Software Foundation; either=0D + version 2.1 of the License, or (at your option) any later version.=0D +=0D + The GNU C Library is distributed in the hope that it will be useful,=0D + but WITHOUT ANY WARRANTY; without even the implied warranty of=0D + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU=0D + Lesser General Public License for more details.=0D +=0D + You should have received a copy of the GNU Lesser General Public=0D + License along with the GNU C Library; if not, see=0D + . */=0D +=0D +#ifndef _I386_MNE_H=0D +#define _I386_MNE_H 1=0D +=0D +#ifndef MNEFILE=0D +# define MNEFILE "i386.mnemonics"=0D +#endif=0D +=0D +/* The index can be stored in the instrtab. */=0D +enum=0D + {=0D +#define MNE(name) MNE_##name,=0D +#include MNEFILE=0D +#undef MNE=0D + MNE_INVALID,=0D + MNE_COUNT =3D MNE_INVALID,=0D + };=0D +=0D +#endif /* i386_mne.h */=0D 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) --=20 2.36.1.windows.1