Signed-off-by: Yonggang Luo <luoyongg...@gmail.com>
---
 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 = ../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_parse_CFLAGS =
 i386_lex.o: i386_parse.h
 i386_gendis_LDADD = $(libeu) -lm $(obstack_LIBS)
 
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"
 
-
-#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
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
+   <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 */
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 <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)
-- 
2.36.1.windows.1

Reply via email to