]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libcpu: Remove the need of NMNES by using enum
authorYonggang Luo <luoyonggang@gmail.com>
Sat, 17 Dec 2022 16:52:02 +0000 (00:52 +0800)
committerMark Wielaard <mark@klomp.org>
Thu, 23 Feb 2023 11:47:25 +0000 (12:47 +0100)
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
libcpu/ChangeLog
libcpu/Makefile.am
libcpu/i386_disasm.c
libcpu/i386_mne.h [new file with mode: 0644]
libcpu/i386_parse.y

index 6d4b717a6114baf4d600eaf557cacef49b9d10d9..d14cd237df28aba1092d31783195dbc68882f479 100644 (file)
@@ -1,3 +1,12 @@
+2022-12-18  Yonggang Luo  <luoyonggang@gmail.com>
+
+       * i386_mne.h: New file, extracted from i386_disasm.c.
+       * Makefile.am (noinst_HEADERS): Add i386_mne.h.
+       (i386_parse_CFLAGS): Removed.
+       * i386_disasm.c: Include i386_mne.h.
+       * i386_parse.y: Include i386_mne.h.
+       (instrtable_out): Use MNE_COUNT instead of NMNES.
+
 2022-12-18  Yonggang Luo  <luoyonggang@gmail.com>
 
        * i386_disasm.c (i386_disasm): Use __asm instead of asm.
index 57d0a1641f20678dabf4d9165d09dc0205a74c26..4ba1be56d703828776b01bb456aeb29d2334d809 100644 (file)
@@ -40,7 +40,7 @@ AM_YFLAGS = -p$(<F:parse.y=)
 
 noinst_LIBRARIES = libcpu.a libcpu_pic.a
 
-noinst_HEADERS = i386_dis.h x86_64_dis.h
+noinst_HEADERS = i386_dis.h i386_mne.h x86_64_dis.h
 
 libcpu_a_SOURCES = i386_disasm.c x86_64_disasm.c bpf_disasm.c riscv_disasm.c
 
@@ -92,7 +92,6 @@ libeu = ../lib/libeu.a
 i386_lex_CFLAGS = -Wno-unused-label -Wno-unused-function -Wno-sign-compare \
                  -Wno-implicit-fallthrough
 i386_parse.o: i386_parse.c i386.mnemonics
-i386_parse_CFLAGS = -DNMNES="`wc -l < i386.mnemonics`"
 i386_lex.o: i386_parse.h
 i386_gendis_LDADD = $(libeu) -lm $(obstack_LIBS)
 
index 09946273e02874c006e25c508e6530459c9ef285..dec62bfaacff77f9829fa549e9b90e158685c588 100644 (file)
 #define MACHINE_ENCODING LITTLE_ENDIAN
 #include "memory-access.h"
 
-
-#ifndef MNEFILE
-# define MNEFILE "i386.mnemonics"
-#endif
+#include "i386_mne.h"
 
 #define MNESTRFIELD(line) MNESTRFIELD1 (line)
 #define MNESTRFIELD1(line) str##line
@@ -71,15 +68,6 @@ static const union mnestr_t
     }
   };
 
-/* 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[] =
   {
 #define MNE(name) \
diff --git a/libcpu/i386_mne.h b/libcpu/i386_mne.h
new file mode 100644 (file)
index 0000000..d515751
--- /dev/null
@@ -0,0 +1,46 @@
+/* Disassembler for x86, MNE enums.
+   Copyright (C) 2007, 2008, 2009, 2011 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils 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 copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#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 = MNE_INVALID,
+  };
+
+#endif /* i386_mne.h */
index d2236d5993543d979f48630997ca13f80638d3b8..459684c6a9dca37b2ba49e90a2f4a26b9ea3d75c 100644 (file)
@@ -46,6 +46,8 @@
 #include <libeu.h>
 #include <system.h>
 
+#include "i386_mne.h"
+
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 
@@ -1107,11 +1109,6 @@ print_op_fct (const void *nodep, VISIT value,
     }
 }
 
-
-#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 = 0; i < 3; ++i)