From 4961f9ae2f11795022166698aa15a15f48ec8c5b Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Sun, 18 Dec 2022 00:52:02 +0800 Subject: [PATCH] libcpu: Remove the need of NMNES by using enum Signed-off-by: Yonggang Luo Signed-off-by: Mark Wielaard --- libcpu/ChangeLog | 9 +++++++++ libcpu/Makefile.am | 3 +-- libcpu/i386_disasm.c | 14 +------------- libcpu/i386_mne.h | 46 ++++++++++++++++++++++++++++++++++++++++++++ libcpu/i386_parse.y | 9 +++------ 5 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 libcpu/i386_mne.h diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index 6d4b717a..d14cd237 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,3 +1,12 @@ +2022-12-18 Yonggang Luo + + * 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 * i386_disasm.c (i386_disasm): Use __asm instead of asm. diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am index 57d0a164..4ba1be56 100644 --- a/libcpu/Makefile.am +++ b/libcpu/Makefile.am @@ -40,7 +40,7 @@ AM_YFLAGS = -p$(. */ + +#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 #include +#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.39.2